annotate 3rdparty/packages/uucpbb/src/log.c @ 3226:9749d0dfc4a2

Changed a puls PC to rts to save cycles
author David Ladd <drencor-xeen@users.sourceforge.net>
date Sat, 20 Jan 2018 19:32:22 -0600
parents 5ba8e711a1a3
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1772
5ba8e711a1a3 source added
boisy
parents:
diff changeset
1 /* log.c Routines to manage the uulog file.
5ba8e711a1a3 source added
boisy
parents:
diff changeset
2 Copyright (C) 1994 Brad Spencer
5ba8e711a1a3 source added
boisy
parents:
diff changeset
3
5ba8e711a1a3 source added
boisy
parents:
diff changeset
4 This file is part of the OS-9 UUCP package, UUCPbb.
5ba8e711a1a3 source added
boisy
parents:
diff changeset
5
5ba8e711a1a3 source added
boisy
parents:
diff changeset
6 This program is free software; you can redistribute it and/or modify
5ba8e711a1a3 source added
boisy
parents:
diff changeset
7 it under the terms of the GNU General Public License as published by
5ba8e711a1a3 source added
boisy
parents:
diff changeset
8 the Free Software Foundation; either version 2 of the License, or
5ba8e711a1a3 source added
boisy
parents:
diff changeset
9 (at your option) any later version.
5ba8e711a1a3 source added
boisy
parents:
diff changeset
10
5ba8e711a1a3 source added
boisy
parents:
diff changeset
11 This program is distributed in the hope that it will be useful,
5ba8e711a1a3 source added
boisy
parents:
diff changeset
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
5ba8e711a1a3 source added
boisy
parents:
diff changeset
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5ba8e711a1a3 source added
boisy
parents:
diff changeset
14 GNU General Public License for more details.
5ba8e711a1a3 source added
boisy
parents:
diff changeset
15
5ba8e711a1a3 source added
boisy
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
5ba8e711a1a3 source added
boisy
parents:
diff changeset
17 along with this program; if not, write to the Free Software
5ba8e711a1a3 source added
boisy
parents:
diff changeset
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
5ba8e711a1a3 source added
boisy
parents:
diff changeset
19
5ba8e711a1a3 source added
boisy
parents:
diff changeset
20 The author of UUCPbb, Bob Billson, can be contacted at:
5ba8e711a1a3 source added
boisy
parents:
diff changeset
21 bob@kc2wz.bubble.org or uunet!kc2wz!bob or by snail mail:
5ba8e711a1a3 source added
boisy
parents:
diff changeset
22 21 Bates Way, Westfield, NJ 07090
5ba8e711a1a3 source added
boisy
parents:
diff changeset
23 */
5ba8e711a1a3 source added
boisy
parents:
diff changeset
24
5ba8e711a1a3 source added
boisy
parents:
diff changeset
25 #include "uucp.h"
5ba8e711a1a3 source added
boisy
parents:
diff changeset
26
5ba8e711a1a3 source added
boisy
parents:
diff changeset
27 static char logpath[200], fcaller[200];
5ba8e711a1a3 source added
boisy
parents:
diff changeset
28 static flag copylog = FALSE,
5ba8e711a1a3 source added
boisy
parents:
diff changeset
29 to_stderr = FALSE,
5ba8e711a1a3 source added
boisy
parents:
diff changeset
30 wval;
5ba8e711a1a3 source added
boisy
parents:
diff changeset
31
5ba8e711a1a3 source added
boisy
parents:
diff changeset
32
5ba8e711a1a3 source added
boisy
parents:
diff changeset
33 /* Initalize logpath to requested log path and others */
5ba8e711a1a3 source added
boisy
parents:
diff changeset
34
5ba8e711a1a3 source added
boisy
parents:
diff changeset
35 void inizlog (caller, where)
5ba8e711a1a3 source added
boisy
parents:
diff changeset
36 char *caller;
5ba8e711a1a3 source added
boisy
parents:
diff changeset
37 int where;
5ba8e711a1a3 source added
boisy
parents:
diff changeset
38 {
5ba8e711a1a3 source added
boisy
parents:
diff changeset
39 if (logdir == NULL)
5ba8e711a1a3 source added
boisy
parents:
diff changeset
40 if ((logdir = getenv ("LOGDIR")) != NULL)
5ba8e711a1a3 source added
boisy
parents:
diff changeset
41 logdir = strdup (logdir);
5ba8e711a1a3 source added
boisy
parents:
diff changeset
42 else
5ba8e711a1a3 source added
boisy
parents:
diff changeset
43 logdir = LOGDIR;
5ba8e711a1a3 source added
boisy
parents:
diff changeset
44
5ba8e711a1a3 source added
boisy
parents:
diff changeset
45 if (caller == NULL || *caller == '\0')
5ba8e711a1a3 source added
boisy
parents:
diff changeset
46 strcpy (fcaller, "unnamed");
5ba8e711a1a3 source added
boisy
parents:
diff changeset
47 else
5ba8e711a1a3 source added
boisy
parents:
diff changeset
48 strcpy (fcaller, caller);
5ba8e711a1a3 source added
boisy
parents:
diff changeset
49
5ba8e711a1a3 source added
boisy
parents:
diff changeset
50 switch (where)
5ba8e711a1a3 source added
boisy
parents:
diff changeset
51 {
5ba8e711a1a3 source added
boisy
parents:
diff changeset
52 /* Someone did something silly, so log to LOGDIR/uulog */
5ba8e711a1a3 source added
boisy
parents:
diff changeset
53 default:
5ba8e711a1a3 source added
boisy
parents:
diff changeset
54 where = 1;
5ba8e711a1a3 source added
boisy
parents:
diff changeset
55 /* Fall through */
5ba8e711a1a3 source added
boisy
parents:
diff changeset
56
5ba8e711a1a3 source added
boisy
parents:
diff changeset
57 /* Ok, log to the disk file LOGDIR/uulog */
5ba8e711a1a3 source added
boisy
parents:
diff changeset
58 case 1:
5ba8e711a1a3 source added
boisy
parents:
diff changeset
59 sprintf (logpath, "%s/uulog", logdir);
5ba8e711a1a3 source added
boisy
parents:
diff changeset
60 break;
5ba8e711a1a3 source added
boisy
parents:
diff changeset
61
5ba8e711a1a3 source added
boisy
parents:
diff changeset
62 /* Ok, log to the RAMDISK and copy the contents to LOGDIR/uulog
5ba8e711a1a3 source added
boisy
parents:
diff changeset
63 later */
5ba8e711a1a3 source added
boisy
parents:
diff changeset
64
5ba8e711a1a3 source added
boisy
parents:
diff changeset
65 case 2:
5ba8e711a1a3 source added
boisy
parents:
diff changeset
66 sprintf (logpath, "%s/uulog", RAMDISK);
5ba8e711a1a3 source added
boisy
parents:
diff changeset
67 copylog = TRUE;
5ba8e711a1a3 source added
boisy
parents:
diff changeset
68 break;
5ba8e711a1a3 source added
boisy
parents:
diff changeset
69
5ba8e711a1a3 source added
boisy
parents:
diff changeset
70 /* Ok, log to stderr */
5ba8e711a1a3 source added
boisy
parents:
diff changeset
71 case 3:
5ba8e711a1a3 source added
boisy
parents:
diff changeset
72 strcpy (logpath, "stderr");
5ba8e711a1a3 source added
boisy
parents:
diff changeset
73 to_stderr = TRUE;
5ba8e711a1a3 source added
boisy
parents:
diff changeset
74 break;
5ba8e711a1a3 source added
boisy
parents:
diff changeset
75 }
5ba8e711a1a3 source added
boisy
parents:
diff changeset
76 wval = where;
5ba8e711a1a3 source added
boisy
parents:
diff changeset
77
5ba8e711a1a3 source added
boisy
parents:
diff changeset
78 /* Ensure that something is in the uulog. Might as well make it useful
5ba8e711a1a3 source added
boisy
parents:
diff changeset
79 information */
5ba8e711a1a3 source added
boisy
parents:
diff changeset
80 }
5ba8e711a1a3 source added
boisy
parents:
diff changeset
81
5ba8e711a1a3 source added
boisy
parents:
diff changeset
82
5ba8e711a1a3 source added
boisy
parents:
diff changeset
83
5ba8e711a1a3 source added
boisy
parents:
diff changeset
84 /* Log will write a message to the end of the log, returning where, or -1
5ba8e711a1a3 source added
boisy
parents:
diff changeset
85 Really, varargs should be used here, but I don't know if OSK or OS-9000
5ba8e711a1a3 source added
boisy
parents:
diff changeset
86 has them */
5ba8e711a1a3 source added
boisy
parents:
diff changeset
87
5ba8e711a1a3 source added
boisy
parents:
diff changeset
88 int log (message)
5ba8e711a1a3 source added
boisy
parents:
diff changeset
89 char *message;
5ba8e711a1a3 source added
boisy
parents:
diff changeset
90 {
5ba8e711a1a3 source added
boisy
parents:
diff changeset
91 FILE *fd;
5ba8e711a1a3 source added
boisy
parents:
diff changeset
92
5ba8e711a1a3 source added
boisy
parents:
diff changeset
93 /* Need a message in order to log one */
5ba8e711a1a3 source added
boisy
parents:
diff changeset
94 if (message == NULL || *message == '\0')
5ba8e711a1a3 source added
boisy
parents:
diff changeset
95 return (wval);
5ba8e711a1a3 source added
boisy
parents:
diff changeset
96
5ba8e711a1a3 source added
boisy
parents:
diff changeset
97 if (to_stderr)
5ba8e711a1a3 source added
boisy
parents:
diff changeset
98 fd = stderr;
5ba8e711a1a3 source added
boisy
parents:
diff changeset
99 else
5ba8e711a1a3 source added
boisy
parents:
diff changeset
100 if ((fd = fopen (logpath, "a")) == NULL)
5ba8e711a1a3 source added
boisy
parents:
diff changeset
101 {
5ba8e711a1a3 source added
boisy
parents:
diff changeset
102 fprintf (stderr, "log: Couldn't open '%s', because %d\n",
5ba8e711a1a3 source added
boisy
parents:
diff changeset
103 logpath, errno);
5ba8e711a1a3 source added
boisy
parents:
diff changeset
104 return (-1);
5ba8e711a1a3 source added
boisy
parents:
diff changeset
105 }
5ba8e711a1a3 source added
boisy
parents:
diff changeset
106
5ba8e711a1a3 source added
boisy
parents:
diff changeset
107 fprintf (fd,"%s %s %s\n", fcaller, gtime(), message);
5ba8e711a1a3 source added
boisy
parents:
diff changeset
108
5ba8e711a1a3 source added
boisy
parents:
diff changeset
109 if (!to_stderr)
5ba8e711a1a3 source added
boisy
parents:
diff changeset
110 fclose (fd);
5ba8e711a1a3 source added
boisy
parents:
diff changeset
111
5ba8e711a1a3 source added
boisy
parents:
diff changeset
112 return (wval);
5ba8e711a1a3 source added
boisy
parents:
diff changeset
113 }
5ba8e711a1a3 source added
boisy
parents:
diff changeset
114
5ba8e711a1a3 source added
boisy
parents:
diff changeset
115
5ba8e711a1a3 source added
boisy
parents:
diff changeset
116
5ba8e711a1a3 source added
boisy
parents:
diff changeset
117 /* deinizlog will copy the log from RAMDISK, if needed */
5ba8e711a1a3 source added
boisy
parents:
diff changeset
118
5ba8e711a1a3 source added
boisy
parents:
diff changeset
119 int deinizlog()
5ba8e711a1a3 source added
boisy
parents:
diff changeset
120 {
5ba8e711a1a3 source added
boisy
parents:
diff changeset
121 FILE *rfd, *lfd;
5ba8e711a1a3 source added
boisy
parents:
diff changeset
122 char nlog[200], bigbuf[1024], llbuf[100];
5ba8e711a1a3 source added
boisy
parents:
diff changeset
123 int r;
5ba8e711a1a3 source added
boisy
parents:
diff changeset
124
5ba8e711a1a3 source added
boisy
parents:
diff changeset
125 /* Copy the file from the RAMDRIVE to LOGDIR/uulog, if asked to */
5ba8e711a1a3 source added
boisy
parents:
diff changeset
126 if (copylog)
5ba8e711a1a3 source added
boisy
parents:
diff changeset
127 {
5ba8e711a1a3 source added
boisy
parents:
diff changeset
128 if ((rfd = fopen (logpath, "r")) == NULL)
5ba8e711a1a3 source added
boisy
parents:
diff changeset
129 {
5ba8e711a1a3 source added
boisy
parents:
diff changeset
130 fprintf (stderr, "deinizlog: Can't open '%s', because %d\n",
5ba8e711a1a3 source added
boisy
parents:
diff changeset
131 logpath, errno);
5ba8e711a1a3 source added
boisy
parents:
diff changeset
132 return (-1);
5ba8e711a1a3 source added
boisy
parents:
diff changeset
133 }
5ba8e711a1a3 source added
boisy
parents:
diff changeset
134
5ba8e711a1a3 source added
boisy
parents:
diff changeset
135 sprintf (nlog, "%s/uulog", logdir);
5ba8e711a1a3 source added
boisy
parents:
diff changeset
136
5ba8e711a1a3 source added
boisy
parents:
diff changeset
137 if ((lfd = fopen (nlog, "a")) == NULL)
5ba8e711a1a3 source added
boisy
parents:
diff changeset
138 {
5ba8e711a1a3 source added
boisy
parents:
diff changeset
139 fprintf (stderr, "deinizlog: Can't open '%s'\n", nlog);
5ba8e711a1a3 source added
boisy
parents:
diff changeset
140 return (-1);
5ba8e711a1a3 source added
boisy
parents:
diff changeset
141 }
5ba8e711a1a3 source added
boisy
parents:
diff changeset
142
5ba8e711a1a3 source added
boisy
parents:
diff changeset
143 do
5ba8e711a1a3 source added
boisy
parents:
diff changeset
144 {
5ba8e711a1a3 source added
boisy
parents:
diff changeset
145 if ((r = fread (bigbuf, 1, sizeof (bigbuf)-1, rfd)) < 0)
5ba8e711a1a3 source added
boisy
parents:
diff changeset
146 fputs ("deinizlog: read error\n", stderr);
5ba8e711a1a3 source added
boisy
parents:
diff changeset
147 else
5ba8e711a1a3 source added
boisy
parents:
diff changeset
148 if (r != 0)
5ba8e711a1a3 source added
boisy
parents:
diff changeset
149 fwrite (bigbuf, 1, r, lfd);
5ba8e711a1a3 source added
boisy
parents:
diff changeset
150 }
5ba8e711a1a3 source added
boisy
parents:
diff changeset
151 while (r > 0);
5ba8e711a1a3 source added
boisy
parents:
diff changeset
152
5ba8e711a1a3 source added
boisy
parents:
diff changeset
153 fclose (rfd);
5ba8e711a1a3 source added
boisy
parents:
diff changeset
154 fclose (lfd);
5ba8e711a1a3 source added
boisy
parents:
diff changeset
155
5ba8e711a1a3 source added
boisy
parents:
diff changeset
156 if (r == 0)
5ba8e711a1a3 source added
boisy
parents:
diff changeset
157 unlink (logpath);
5ba8e711a1a3 source added
boisy
parents:
diff changeset
158 }
5ba8e711a1a3 source added
boisy
parents:
diff changeset
159 return (r);
5ba8e711a1a3 source added
boisy
parents:
diff changeset
160 }