1 #if (!defined(lint) && !defined(SABER))
2 static char rcsid_module_c[] = "$Header$";
5 /* This is the file main.c for the SMS Client, which allows a nieve
6 * user to quickly and easily maintain most parts of the SMS database.
7 * It Contains: The main driver for the SMS Client.
10 * By: Chris D. Peterson
16 * Copyright 1988 by the Massachusetts Institute of Technology.
18 * For further information on copyright and distribution
19 * see the file mit-copyright.h
26 #include <sys/types.h>
30 #include "mit-copyright.h"
35 char * whoami; /* used by menu.c ugh!!! */
37 extern Menu sms_top_menu, list_menu, user_menu, dcm_menu;
40 static void SignalHandler();
43 static void ErrorExit(), Usage();
46 struct passwd *getpwuid();
48 Bool use_menu = TRUE; /* whether or not we are using a menu. */
50 /* Function Name: main
51 * Description: The main driver for the SMS Client.
52 * Arguments: argc, argv - standard command line args.
53 * Returns: doesn't return.
65 if ((user = getlogin()) == NULL)
66 user = getpwuid((int) getuid())->pw_name;
67 user = (user && strlen(user)) ? Strsave(user) : "";
69 if ((program_name = rindex(argv[0], '/')) == NULL)
70 program_name = argv[0];
73 program_name = Strsave(program_name);
74 whoami = Strsave(program_name); /* used by menu.c, ugh !!! */
80 if (strcmp(argv[1], "-nomenu") == 0)
92 if ( status = sms_connect(SMS_SERVER) )
93 ErrorExit("\nConnection to SMS server failed", status);
95 if ( status = sms_motd(&motd) )
96 ErrorExit("\nUnable to check server status", status);
98 fprintf(stderr, "The SMS server is currently unavailable:\n%s\n", motd);
103 if ( status = sms_auth(program_name) )
104 ErrorExit("\nAuthorization failed -- please run kinit", status);
107 * These signals should not be set until just before we fire up the menu
112 (void) signal(SIGHUP, SignalHandler);
113 (void) signal(SIGINT, SignalHandler);
114 (void) signal(SIGQUIT, SignalHandler);
117 if (!strcmp(program_name, "listmaint"))
119 else if (!strcmp(program_name, "usermaint"))
121 else if (!strcmp(program_name, "dcmmaint"))
124 menu = &sms_top_menu;
126 if (use_menu) { /* Start menus that execute program */
131 else /* Start program without menus. */
138 /* Function Name: ErrorExit
139 * Description: This function does the error handling and exits.
140 * Arguments: buf - the error message to print.
141 * status - the error code.
142 * Returns: doesn't return.
146 ErrorExit(buf,status)
150 com_err(program_name, status, buf);
155 /* Function Name: usage
156 * Description: Prints usage info and then exits.
158 * Returns: doesn't return.
164 fprintf(stderr, "Usage: %s [-nomenu]\n", program_name);
169 /* Function Name: SignalHandler
170 * Description: This function cleans up from a signal interrupt.
178 Put_message("Signal caught - exiting");