Skip to content
This repository has been archived by the owner on Dec 25, 2023. It is now read-only.

Commit

Permalink
DLL Projects:
Browse files Browse the repository at this point in the history
- LOGGER.DLL: Fixed console print messages (FYI, first prints, before reach max lines, use wrong y coordinate).
- Now prints the full date time expression on first entry. All entries only prints time value.
- Updated LOGGER.PRG.
  • Loading branch information
José Miguel Sánchez Fernández committed Jun 4, 2020
1 parent 8c97cce commit bccb9a3
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 36 deletions.
Binary file modified DLL/LOGGER.DLL
Binary file not shown.
61 changes: 34 additions & 27 deletions DLL/LOGGER/LOGGER.CPP
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ void init()
separator = strAlloc(consoleStrLen);
memset(separator, '=', consoleStrLen);

struct tm *now = getDateTime();

if (fileEnable)
{
// Log filename format: "LOGS\yyyyMMdd\HHmmss.LOG"
char filename[12];
struct tm *now = getDateTime();

// Move or create base log's folder:
mkdir(log_folder);
Expand Down Expand Up @@ -60,12 +61,14 @@ void init()
if (consoleEnable)
{
consoleBuffer = strAlloc(console_buffer_size);
consoleLineIndex = 0;
clearBuffer();
cclear();
}
consoleVisible = 0;

_log("Log started!");
char* timeStamp = strAlloc(consoleStrLen);
strftime(timeStamp, consoleStrLen, "Log started on %c", now);
_log(timeStamp);
div_free(timeStamp);
_log(separator);

retval(RESULT_OK);
Expand All @@ -81,26 +84,32 @@ void isConsoleEnabled()
retval(consoleEnable);
}

void cwrite(int index, char* text)
{
int len = _min(strlen(text), consoleStrLen);
memmove(&consoleBuffer[index * console_full_line_len], text, len);
consoleBuffer[(index * console_full_line_len) + len] = '\0';
}

char* cread(int index)
{
return &consoleBuffer[index * console_full_line_len];
}

void cclear()
{
memset(consoleBuffer, '\0', console_buffer_size);
consoleWriteIndex = 0;
}

void _log(char* message)
{
if (fileEnable)
{
// "[dd/MM/yyyy HH:mm:ss] %message%"
struct tm *now = getDateTime();

/* This method print wrong value in Watcom/DOS:
char timeStamp[14];
strftime(timeStamp, 14, "[%x %X]\n", now);
fprintf(file,
"%s %s\n",
timeStamp,
message); */

// "[dd/MM/yyyy HH:mm:ss]: %message%"
fprintf(file,
"[%02i/%02i/%04i %02i:%02i:%02i]: %s\n",
now->tm_mday,
now->tm_mon + 1,
now->tm_year + 1900,
"[%02i:%02i:%02i] %s\n",
now->tm_hour,
now->tm_min,
now->tm_sec,
Expand All @@ -109,17 +118,16 @@ void _log(char* message)

if (consoleEnable)
{
if (console_write_index == consoleMaxLines - 1)
if (consoleWriteIndex == consoleMaxLines - 1)
{
for (int i = 1; i < consoleMaxLines; i++)
for (int x = 0, y = 1; y < consoleMaxLines; x++, y++)
{
memcpy(line(i - 1), line(i), console_full_line_len);
cwrite(x, cread(y));
}
}

memcpy(line(console_write_index),
message,
_min(strlen(message), consoleStrLen));
cwrite(consoleWriteIndex, message);
consoleWriteIndex = _min(++consoleWriteIndex, consoleMaxLines - 1);
}
}

Expand Down Expand Up @@ -154,8 +162,7 @@ void clear()
{
if (consoleEnable)
{
clearBuffer();
consoleLineIndex = 0;
cclear();
}
retval(RESULT_OK);
}
Expand All @@ -169,7 +176,7 @@ void post_process_buffer(void)

for (int i = 0; i < consoleMaxLines; i++)
{
div_text_out(line(i), 0, i * 10);
div_text_out(cread(i), 0, i * 10);
}
}
}
Expand Down
10 changes: 4 additions & 6 deletions DLL/LOGGER/LOGGER.H
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@
#define console_full_line_len consoleStrLen + 1 // strlen + \0
#define console_buffer_size console_full_line_len * consoleMaxLines

#define clearBuffer() memset(consoleBuffer, '\0', console_buffer_size)
#define line(i) &consoleBuffer[i * console_full_line_len]

#define console_write_index _min(++consoleLineIndex, consoleMaxLines - 1)

int fileEnable;
FILE* file;

Expand All @@ -30,10 +25,13 @@ int consoleVisible;
int consoleStrLen;
int consoleMaxLines; // Max lines to show.
char* consoleBuffer; // (strLength + 1) * maxLines.
int consoleLineIndex; // Line to write.
int consoleWriteIndex; // Line to write.

void _log(char* message);
void createLogFolder();
void cwrite(int index, char* text);
char* cread(int index);
void cclear();

void init();
void isFileEnabled();
Expand Down
22 changes: 19 additions & 3 deletions PRG/TESTS/DLLTESTS/LOGGER.PRG
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,24 @@ program LOGGER_DLL_TEST;

import "logger.dll";

global
int fpg;
string message;

begin
fpg = load_fpg("help\help.fpg");
put_screen(fpg, 1);

setup_logger(true, true, 80, 10);

log("Test log...");
log("Anther test log...");
log("One more time testing log...");
//log("Test log...");
//log("Another test log...");
//log("One more time testing log...");

//for (x = 0; x < 15; x++)
// message = "Test iteration: " + itoa(x);
// log(message);
//end

loop
if (key(_s))
Expand All @@ -18,6 +30,10 @@ begin
hide_log_console();
end

if (key(_space))
log(itoa(timer[0]));
end

frame;
end
end

0 comments on commit bccb9a3

Please sign in to comment.