1 | /* This file is part of the Project Athena Global Message System. |
---|
2 | * Created by: Mark W. Eichin <eichin@athena.mit.edu> |
---|
3 | * $Source: /afs/dev.mit.edu/source/repository/athena/bin/gms/get_message.c,v $ |
---|
4 | * $Author: ghudson $ |
---|
5 | * |
---|
6 | * Copyright (c) 1988 by the Massachusetts Institute of Technology. |
---|
7 | * For copying and distribution information, see the file |
---|
8 | * "mit-copyright.h". |
---|
9 | */ |
---|
10 | #include <mit-copyright.h> |
---|
11 | #ifndef lint |
---|
12 | static char rcsid_get_message_c[] = "$Header: /afs/dev.mit.edu/source/repository/athena/bin/gms/get_message.c,v 1.5 1997-04-22 00:37:54 ghudson Exp $"; |
---|
13 | #endif lint |
---|
14 | |
---|
15 | #include "globalmessage.h" |
---|
16 | void Usage(); |
---|
17 | |
---|
18 | #include <stdio.h> |
---|
19 | #include <sys/types.h> |
---|
20 | #ifndef ultrix |
---|
21 | #include <syslog.h> |
---|
22 | #else |
---|
23 | #include <nsyslog.h> |
---|
24 | #endif |
---|
25 | char *error_message(); |
---|
26 | |
---|
27 | |
---|
28 | main (argc, argv) |
---|
29 | int argc; |
---|
30 | char *argv[]; |
---|
31 | { |
---|
32 | char **xargv = argv; |
---|
33 | int xargc = argc; |
---|
34 | Code_t status; |
---|
35 | char *message; |
---|
36 | int zephyr_p = 0, new_p = 0, login_p = 0; |
---|
37 | |
---|
38 | #ifdef LOG_USER |
---|
39 | openlog(argv[0], LOG_PID, LOG_USER); |
---|
40 | #else |
---|
41 | openlog(argv[0], LOG_PID); |
---|
42 | #endif |
---|
43 | syslog(LOG_INFO, "GMS client started..."); |
---|
44 | |
---|
45 | init_gms_err_tbl(); |
---|
46 | |
---|
47 | /* Argument Processing: |
---|
48 | * -z or -zephyr: send the message as a zephyrgram. |
---|
49 | * -n or -new: only send if the message is newer |
---|
50 | */ |
---|
51 | if(argc>3) { |
---|
52 | Usage(argv[0], "too many arguments"); |
---|
53 | exit(1); |
---|
54 | } |
---|
55 | /* Only one valid argument: -zephyr or -z */ |
---|
56 | while(--xargc) { |
---|
57 | xargv++; |
---|
58 | if((!strcmp(xargv[0],"-zephyr"))||(!strcmp(xargv[0],"-z"))) { |
---|
59 | zephyr_p = 1; |
---|
60 | } else if((!strcmp(xargv[0],"-new"))||(!strcmp(xargv[0],"-n"))) { |
---|
61 | new_p = 1; |
---|
62 | } else if((!strcmp(xargv[0],"-login"))||(!strcmp(xargv[0],"-l"))) { |
---|
63 | login_p = 1; |
---|
64 | } else { |
---|
65 | Usage(argv[0], xargv[0]); |
---|
66 | exit(1); |
---|
67 | } |
---|
68 | } |
---|
69 | |
---|
70 | status = get_a_message(&message); |
---|
71 | if(!status) { |
---|
72 | /* check if the user has seen it already */ |
---|
73 | status = check_viewable(message, new_p, !login_p); |
---|
74 | if(status) { |
---|
75 | syslog(LOG_INFO, "GMS not showing."); |
---|
76 | exit(0); |
---|
77 | } |
---|
78 | |
---|
79 | /* send it off if it passes the tests */ |
---|
80 | if(zephyr_p) { |
---|
81 | view_message_by_zephyr(message); |
---|
82 | } else { |
---|
83 | view_message_by_tty(message); |
---|
84 | } |
---|
85 | } else { |
---|
86 | syslog(LOG_INFO, "GMS losing: %s", error_message(status)); |
---|
87 | } |
---|
88 | |
---|
89 | exit(0); |
---|
90 | } |
---|
91 | |
---|
92 | void Usage(pname, errname) |
---|
93 | char *pname, *errname; |
---|
94 | { |
---|
95 | fprintf(stderr, "%s <%s>: Usage: %s [-zephyr|-z] [-new|-n]\n", |
---|
96 | pname, errname, pname); |
---|
97 | } |
---|