source: trunk/athena/bin/get_message/get_message.c @ 14063

Revision 14063, 2.4 KB checked in by danw, 25 years ago (diff)
get_message, formerly in athena/bin/gms
Line 
1/* Copyright 1988, 1998 by the Massachusetts Institute of Technology.
2 *
3 * Permission to use, copy, modify, and distribute this
4 * software and its documentation for any purpose and without
5 * fee is hereby granted, provided that the above copyright
6 * notice appear in all copies and that both that copyright
7 * notice and this permission notice appear in supporting
8 * documentation, and that the name of M.I.T. not be used in
9 * advertising or publicity pertaining to distribution of the
10 * software without specific, written prior permission.
11 * M.I.T. makes no representations about the suitability of
12 * this software for any purpose.  It is provided "as is"
13 * without express or implied warranty.
14 */
15
16static const char rcsid[] = "$Id: get_message.c,v 1.1 1999-12-08 22:06:44 danw Exp $";
17
18#include "globalmessage.h"
19void Usage(char *pname, char *errname);
20
21#include <stdio.h>
22#include <sys/types.h>
23#include <syslog.h>
24#include <com_err.h>
25
26int main(int argc, 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  init_gms_err_tbl();
38
39  /* Argument Processing:
40   *    -z or -zephyr: send the message as a zephyrgram.
41   *    -n or -new: only send if the message is newer
42   */
43  if(argc>3) {
44    Usage(argv[0], "too many arguments");
45    exit(1);
46  }
47  /* Only one valid argument: -zephyr or -z */
48  while(--xargc) {
49    xargv++;
50    if((!strcmp(xargv[0],"-zephyr"))||(!strcmp(xargv[0],"-z"))) {
51      zephyr_p = 1;
52    } else if((!strcmp(xargv[0],"-new"))||(!strcmp(xargv[0],"-n"))) {
53      new_p = 1;
54    } else if((!strcmp(xargv[0],"-login"))||(!strcmp(xargv[0],"-l"))) {
55      login_p = 1;
56    } else {
57      Usage(argv[0], xargv[0]);
58      exit(1);
59    }     
60  }
61 
62  status = get_a_message(&message);
63  if(!status) {
64    /* check if the user has seen it already */
65    status = check_viewable(message, new_p, !login_p);
66    if(status) {
67      syslog(LOG_INFO, "GMS not showing.");
68      exit(0);
69    }
70
71    /* send it off if it passes the tests */
72    if(zephyr_p) {
73      view_message_by_zephyr(message);
74    } else {
75      view_message_by_tty(message);
76    }
77  } else {
78    syslog(LOG_INFO, "GMS losing: %s", error_message(status));
79  }
80
81  exit(0);
82}
83
84void Usage(char *pname, char *errname)
85{
86  fprintf(stderr, "%s <%s>: Usage: %s [-zephyr|-z] [-new|-n]\n",
87          pname, errname, pname);
88}
Note: See TracBrowser for help on using the repository browser.