annotate netinstall/log.cc @ 4709:db7068430402

Add explicit GPL v2 or later notices to Bill Perry's code, where such notices are missing. This is done with Bill Perry's stated permission, in private email to me.
author Jerry James <james@xemacs.org>
date Mon, 05 Oct 2009 11:08:59 -0600
parents 685b588e92d8
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
448
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
1 /*
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
2 * Copyright (c) 2000, Red Hat, Inc.
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
3 *
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
4 * This program is free software; you can redistribute it and/or modify
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
5 * it under the terms of the GNU General Public License as published by
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
6 * the Free Software Foundation; either version 2 of the License, or
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
7 * (at your option) any later version.
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
8 *
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
9 * A copy of the GNU General Public License can be found at
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
10 * http://www.gnu.org/
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
11 *
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
12 * Written by DJ Delorie <dj@redhat.com>
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
13 *
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
14 */
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
15
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
16 /* The purpose of this file is to centralize all the logging functions. */
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
17
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
18 #include "win32.h"
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
19 #include <stdio.h>
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
20 #include <stdarg.h>
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
21 #include <stdlib.h>
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
22 #include <time.h>
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
23
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
24 #include "resource.h"
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
25 #include "msg.h"
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
26 #include "log.h"
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
27 #include "dialog.h"
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
28 #include "state.h"
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
29 #include "concat.h"
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
30 #include "mkdir.h"
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
31
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
32 struct LogEnt {
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
33 LogEnt *next;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
34 int flags;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
35 time_t when;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
36 char msg[1];
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
37 };
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
38
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
39 static LogEnt *first_logent = 0;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
40 static LogEnt **next_logent = &first_logent;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
41
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
42 void
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
43 log (int flags, char *fmt, ...)
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
44 {
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
45 char buf[1000];
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
46 va_list args;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
47 va_start (args, fmt);
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
48 vsprintf (buf, fmt, args);
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
49
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
50 LogEnt *l = (LogEnt *) malloc (sizeof (LogEnt) + strlen (buf) + 20);
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
51 l->next = 0;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
52 l->flags = flags;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
53 time (&(l->when));
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
54 *next_logent = l;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
55 next_logent = &(l->next);
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
56
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
57 char *b = l->msg;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
58 if (flags & LOG_TIMESTAMP)
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
59 {
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
60 struct tm *tm = localtime (&(l->when));
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
61 strftime (b, 1000, "%Y/%m/%d %H:%M:%S ", tm);
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
62 b += strlen (b);
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
63 }
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
64
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
65 strcpy (b, buf);
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
66 msg ("LOG: %d %s", l->flags, l->msg);
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
67 }
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
68
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
69 void
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
70 log_save (int babble, char *filename, int append)
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
71 {
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
72 static int been_here = 0;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
73 if (been_here)
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
74 return;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
75 been_here = 1;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
76
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
77 mkdir_p (0, filename);
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
78
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
79 FILE *f = fopen (filename, append ? "at" : "wt");
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
80 if (!f)
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
81 {
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
82 fatal (IDS_NOLOGFILE, filename);
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
83 return;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
84 }
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
85
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
86 LogEnt *l;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
87
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
88 for (l=first_logent; l; l=l->next)
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
89 {
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
90 if (babble || !(l->flags & LOG_BABBLE))
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
91 {
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
92 fputs (l->msg, f);
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
93 if (l->msg[strlen(l->msg)-1] != '\n')
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
94 fputc ('\n', f);
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
95 }
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
96 }
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
97
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
98 fclose (f);
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
99 been_here = 0;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
100 }
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
101
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
102 void
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
103 exit_setup (int exit_code)
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
104 {
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
105 static int been_here = 0;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
106 if (been_here)
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
107 ExitProcess (1);
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
108 been_here = 1;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
109
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
110 if (exit_msg)
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
111 note (exit_msg);
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
112
673
685b588e92d8 [xemacs-hg @ 2001-10-30 05:13:26 by andyp]
andyp
parents: 448
diff changeset
113 log (LOG_TIMESTAMP, "Ending XEmacs install");
448
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
114
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
115 if (source == IDC_SOURCE_DOWNLOAD || !root_dir)
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
116 {
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
117 log_save (LOG_BABBLE, "setup.log.full", 0);
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
118 log_save (0, "setup.log", 1);
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
119 }
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
120 else
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
121 {
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
122 log_save (LOG_BABBLE, concat (root_dir, "/setup.log.full", 0), 0);
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
123 log_save (0, concat (root_dir, "/setup.log", 0), 1);
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
124 }
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
125
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
126 ExitProcess (exit_code);
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
127 }