| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
#include "win32.h" |
|---|
| 19 |
#include <stdio.h> |
|---|
| 20 |
#include <stdarg.h> |
|---|
| 21 |
#include <stdlib.h> |
|---|
| 22 |
#include <time.h> |
|---|
| 23 |
|
|---|
| 24 |
#include "resource.h" |
|---|
| 25 |
#include "msg.h" |
|---|
| 26 |
#include "log.h" |
|---|
| 27 |
#include "dialog.h" |
|---|
| 28 |
#include "state.h" |
|---|
| 29 |
#include "concat.h" |
|---|
| 30 |
#include "mkdir.h" |
|---|
| 31 |
#include "reginfo.h" |
|---|
| 32 |
|
|---|
| 33 |
struct LogEnt { |
|---|
| 34 |
LogEnt *next; |
|---|
| 35 |
int flags; |
|---|
| 36 |
time_t when; |
|---|
| 37 |
char msg[1]; |
|---|
| 38 |
}; |
|---|
| 39 |
|
|---|
| 40 |
static LogEnt *first_logent = 0; |
|---|
| 41 |
static LogEnt **next_logent = &first_logent; |
|---|
| 42 |
|
|---|
| 43 |
void |
|---|
| 44 |
log (int flags, char *fmt, ...) |
|---|
| 45 |
{ |
|---|
| 46 |
char buf[1000]; |
|---|
| 47 |
va_list args; |
|---|
| 48 |
va_start (args, fmt); |
|---|
| 49 |
vsprintf (buf, fmt, args); |
|---|
| 50 |
|
|---|
| 51 |
LogEnt *l = (LogEnt *) malloc (sizeof (LogEnt) + strlen (buf) + 20); |
|---|
| 52 |
l->next = 0; |
|---|
| 53 |
l->flags = flags; |
|---|
| 54 |
time (&(l->when)); |
|---|
| 55 |
*next_logent = l; |
|---|
| 56 |
next_logent = &(l->next); |
|---|
| 57 |
|
|---|
| 58 |
char *b = l->msg; |
|---|
| 59 |
if (flags & LOG_TIMESTAMP) |
|---|
| 60 |
{ |
|---|
| 61 |
struct tm *tm = localtime (&(l->when)); |
|---|
| 62 |
strftime (b, 1000, "%Y/%m/%d %H:%M:%S ", tm); |
|---|
| 63 |
b += strlen (b); |
|---|
| 64 |
} |
|---|
| 65 |
|
|---|
| 66 |
strcpy (b, buf); |
|---|
| 67 |
msg ("LOG: %d %s", l->flags, l->msg); |
|---|
| 68 |
} |
|---|
| 69 |
|
|---|
| 70 |
void |
|---|
| 71 |
log_save (int babble, char *filename, int append) |
|---|
| 72 |
{ |
|---|
| 73 |
static int been_here = 0; |
|---|
| 74 |
if (been_here) |
|---|
| 75 |
return; |
|---|
| 76 |
been_here = 1; |
|---|
| 77 |
|
|---|
| 78 |
mkdir_p (0, filename); |
|---|
| 79 |
|
|---|
| 80 |
FILE *f = fopen (filename, append ? "at" : "wt"); |
|---|
| 81 |
if (!f) |
|---|
| 82 |
{ |
|---|
| 83 |
fatal (IDS_NOLOGFILE, filename); |
|---|
| 84 |
return; |
|---|
| 85 |
} |
|---|
| 86 |
|
|---|
| 87 |
LogEnt *l; |
|---|
| 88 |
|
|---|
| 89 |
for (l=first_logent; l; l=l->next) |
|---|
| 90 |
{ |
|---|
| 91 |
if (babble || !(l->flags & LOG_BABBLE)) |
|---|
| 92 |
{ |
|---|
| 93 |
fputs (l->msg, f); |
|---|
| 94 |
if (l->msg[strlen(l->msg)-1] != '\n') |
|---|
| 95 |
fputc ('\n', f); |
|---|
| 96 |
} |
|---|
| 97 |
} |
|---|
| 98 |
|
|---|
| 99 |
fclose (f); |
|---|
| 100 |
been_here = 0; |
|---|
| 101 |
} |
|---|
| 102 |
|
|---|
| 103 |
void |
|---|
| 104 |
exit_setup (int exit_code) |
|---|
| 105 |
{ |
|---|
| 106 |
static int been_here = 0; |
|---|
| 107 |
if (been_here) |
|---|
| 108 |
ExitProcess (1); |
|---|
| 109 |
been_here = 1; |
|---|
| 110 |
|
|---|
| 111 |
if (exit_msg) |
|---|
| 112 |
note (exit_msg); |
|---|
| 113 |
|
|---|
| 114 |
log (LOG_TIMESTAMP, "Ending Meadow install"); |
|---|
| 115 |
|
|---|
| 116 |
if (source == IDC_SOURCE_DOWNLOAD || !root_dir) |
|---|
| 117 |
{ |
|---|
| 118 |
log_save (LOG_BABBLE, "setup.log.full", 0); |
|---|
| 119 |
log_save (0, "setup.log", 1); |
|---|
| 120 |
} |
|---|
| 121 |
else |
|---|
| 122 |
{ |
|---|
| 123 |
log_save (LOG_BABBLE, concat (root_dir, XEMACS_SETUP_DIR, "/setup.log.full", 0), 0); |
|---|
| 124 |
log_save (0, concat (root_dir, XEMACS_SETUP_DIR, "/setup.log", 0), 1); |
|---|
| 125 |
} |
|---|
| 126 |
|
|---|
| 127 |
ExitProcess (exit_code); |
|---|
| 128 |
} |
|---|