-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathbbslog.c
65 lines (53 loc) · 1.12 KB
/
bbslog.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "server.h"
extern char *optarg;
extern int optind;
usage(prog)
char *prog;
{
fprintf(stderr,
"Usage: %s [-d bbs-dir] [-h log-header] log-level message\n", prog);
}
main(argc, argv)
int argc;
char *argv[];
{
char *bbshome = NULL;
char *logheader = NULL;
char *msg;
int c;
int loglevel, rc;
while ((c = getopt(argc, argv, "d:h:?")) != -1)
{
switch (c)
{
case 'd':
bbshome = optarg;
break;
case 'h':
logheader = optarg;
break;
case '?':
usage(argv[0]);
return 2;
}
}
if (optind+2 > argc) {
usage(argv[0]);
return 2;
}
if (logheader == NULL) logheader = "BBSLOG";
loglevel = atoi(argv[optind++]);
msg = argv[optind];
if (home_bbs(bbshome) == -1) {
fprintf(stderr, "%s: Cannot chdir to %s\n", argv[0], bbshome);
return 1;
}
if (local_bbs_initialize(NULL) != S_OK) {
fprintf(stderr, "%s: local_bbs_initialize failed\n", argv[0]);
return 1;
}
set_log_header(logheader);
bbslog(loglevel, "%s\n", msg);
local_bbs_disconnect();
return 0;
}