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: eichin $ |
---|
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.1 1988-09-27 00:42:58 eichin Exp $"; |
---|
13 | #endif lint |
---|
14 | |
---|
15 | #include "globalmessage.h" |
---|
16 | void Usage(); |
---|
17 | |
---|
18 | #include <stdio.h> |
---|
19 | #include <sys/types.h> |
---|
20 | #include <syslog.h> |
---|
21 | char *error_message(); |
---|
22 | |
---|
23 | |
---|
24 | main (argc, argv) |
---|
25 | int argc; |
---|
26 | char *argv[]; |
---|
27 | { |
---|
28 | char **xargv = argv; |
---|
29 | int xargc = argc; |
---|
30 | Code_t status; |
---|
31 | char *message; |
---|
32 | int zephyr_p = 0, new_p = 0; |
---|
33 | |
---|
34 | openlog(argv[0], LOG_PID, LOG_USER); |
---|
35 | syslog(LOG_INFO, "GMS client started..."); |
---|
36 | |
---|
37 | /* Argument Processing: |
---|
38 | * -z or -zephyr: send the message as a zephyrgram. |
---|
39 | * -n or -new: only send if the message is newer |
---|
40 | */ |
---|
41 | if(argc>3) { |
---|
42 | Usage(argv[0], "too many arguments"); |
---|
43 | exit(1); |
---|
44 | } |
---|
45 | /* Only one valid argument: -zephyr or -z */ |
---|
46 | while(--xargc) { |
---|
47 | xargv++; |
---|
48 | if((!strcmp(xargv[0],"-zephyr"))||(!strcmp(xargv[0],"-z"))) { |
---|
49 | zephyr_p = 1; |
---|
50 | } else if((!strcmp(xargv[0],"-new"))||(!strcmp(xargv[0],"-n"))) { |
---|
51 | new_p = 1; |
---|
52 | } else { |
---|
53 | Usage(argv[0], xargv[0]); |
---|
54 | exit(1); |
---|
55 | } |
---|
56 | } |
---|
57 | |
---|
58 | status = get_a_message(&message); |
---|
59 | if(!status) { |
---|
60 | /* check if the user has seen it already */ |
---|
61 | status = check_viewable(message, new_p); |
---|
62 | if(status) { |
---|
63 | syslog(LOG_INFO, "GMS not showing."); |
---|
64 | exit(0); |
---|
65 | } |
---|
66 | |
---|
67 | /* send it off if it passes the tests */ |
---|
68 | if(zephyr_p) { |
---|
69 | view_message_by_zephyr(message); |
---|
70 | } else { |
---|
71 | view_message_by_tty(message); |
---|
72 | } |
---|
73 | } else { |
---|
74 | syslog(LOG_INFO, "GMS losing: %s", error_message(status)); |
---|
75 | } |
---|
76 | |
---|
77 | exit(0); |
---|
78 | } |
---|
79 | |
---|
80 | void Usage(pname, errname) |
---|
81 | char *pname, *errname; |
---|
82 | { |
---|
83 | fprintf(stderr, "%s <%s>: Usage: %s [-zephyr|-z] [-new|-n]\n", |
---|
84 | pname, errname, pname); |
---|
85 | } |
---|