source: trunk/athena/bin/gms/get_message.c @ 1494

Revision 1494, 2.2 KB checked in by eichin, 36 years ago (diff)
added login_p option to indicate whether or not to write the user's timestamp file.
Line 
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
12static char rcsid_get_message_c[] = "$Header: /afs/dev.mit.edu/source/repository/athena/bin/gms/get_message.c,v 1.2 1988-09-28 23:40:24 eichin Exp $";
13#endif lint
14
15#include "globalmessage.h"
16void Usage();
17
18#include <stdio.h>
19#include <sys/types.h>
20#include <syslog.h>
21char *error_message();
22
23
24main (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, login_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 if((!strcmp(xargv[0],"-login"))||(!strcmp(xargv[0],"-l"))) {
53      login_p = 1;
54    } else {
55      Usage(argv[0], xargv[0]);
56      exit(1);
57    }     
58  }
59 
60  status = get_a_message(&message);
61  if(!status) {
62    /* check if the user has seen it already */
63    status = check_viewable(message, new_p, !login_p);
64    if(status) {
65      syslog(LOG_INFO, "GMS not showing.");
66      exit(0);
67    }
68
69    /* send it off if it passes the tests */
70    if(zephyr_p) {
71      view_message_by_zephyr(message);
72    } else {
73      view_message_by_tty(message);
74    }
75  } else {
76    syslog(LOG_INFO, "GMS losing: %s", error_message(status));
77  }
78
79  exit(0);
80}
81
82void Usage(pname, errname)
83     char *pname, *errname;
84{
85  fprintf(stderr, "%s <%s>: Usage: %s [-zephyr|-z] [-new|-n]\n",
86          pname, errname, pname);
87}
Note: See TracBrowser for help on using the repository browser.