]>
Commit | Line | Data |
---|---|---|
402461ad | 1 | #if (!defined(lint) && !defined(SABER)) |
08345b74 | 2 | static char rcsid_module_c[] = "$Header$"; |
3 | #endif lint | |
4 | ||
0a2c64cb | 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. | |
08345b74 | 8 | * |
9 | * Created: 4/12/88 | |
10 | * By: Chris D. Peterson | |
11 | * | |
12 | * $Source$ | |
13 | * $Author$ | |
14 | * $Header$ | |
15 | * | |
0a2c64cb | 16 | * Copyright 1988 by the Massachusetts Institute of Technology. |
08345b74 | 17 | * |
18 | * For further information on copyright and distribution | |
19 | * see the file mit-copyright.h | |
20 | */ | |
21 | ||
22 | #include <pwd.h> | |
23 | #include <signal.h> | |
24 | #include <stdio.h> | |
25 | #include <strings.h> | |
461c03b6 | 26 | #include <sys/types.h> |
08345b74 | 27 | #include <sms.h> |
28 | #include <menu.h> | |
29 | ||
30 | #include "mit-copyright.h" | |
0a2c64cb | 31 | #include "defs.h" |
32 | #include "f_defs.h" | |
08345b74 | 33 | #include "globals.h" |
34 | ||
85ca828a | 35 | char * whoami; /* used by menu.c ugh!!! */ |
36 | ||
bc628e37 | 37 | extern Menu sms_top_menu, list_menu, user_menu, dcm_menu; |
85ca828a | 38 | |
402461ad | 39 | #ifndef DEBUG |
40 | static void SignalHandler(); | |
41 | #endif DEBUG | |
42 | ||
43 | static void ErrorExit(), Usage(); | |
08345b74 | 44 | char *getlogin(); |
45 | uid_t getuid(); | |
46 | struct passwd *getpwuid(); | |
47 | ||
48 | Bool use_menu = TRUE; /* whether or not we are using a menu. */ | |
49 | ||
50 | /* Function Name: main | |
219bbe64 | 51 | * Description: The main driver for the SMS Client. |
08345b74 | 52 | * Arguments: argc, argv - standard command line args. |
53 | * Returns: doesn't return. | |
54 | */ | |
55 | ||
56 | void | |
57 | main(argc, argv) | |
58 | int argc; | |
59 | char ** argv; | |
60 | { | |
461c03b6 | 61 | int status; |
ace1dd7b | 62 | Menu *menu; |
576becad | 63 | char *motd, **arg, *server; |
08345b74 | 64 | |
65 | if ((user = getlogin()) == NULL) | |
66 | user = getpwuid((int) getuid())->pw_name; | |
67 | user = (user && strlen(user)) ? Strsave(user) : ""; | |
68 | ||
e774e94c | 69 | if ((program_name = rindex(argv[0], '/')) == NULL) |
70 | program_name = argv[0]; | |
71 | else | |
72 | program_name++; | |
c2be255c | 73 | program_name = Strsave(program_name); |
74 | whoami = Strsave(program_name); /* used by menu.c, ugh !!! */ | |
75 | ||
461c03b6 | 76 | verbose = TRUE; |
576becad | 77 | arg = argv; |
78 | server = SMS_SERVER; | |
79 | ||
80 | while (++arg - argv < argc) { | |
81 | if (**arg == '-') { | |
82 | if (!strcmp(*arg, "-nomenu")) | |
83 | use_menu = FALSE; | |
84 | else if (!strcmp(*arg, "-db")) | |
85 | if (arg - argv < argc - 1) { | |
86 | ++arg; | |
87 | server = *arg; | |
88 | } else | |
89 | Usage(argv); | |
90 | else | |
91 | Usage(argv); | |
92 | } | |
08345b74 | 93 | } |
85ca828a | 94 | |
576becad | 95 | if ( status = sms_connect(server) ) |
461c03b6 | 96 | ErrorExit("\nConnection to SMS server failed", status); |
08345b74 | 97 | |
262ca740 | 98 | if ( status = sms_motd(&motd) ) |
99 | ErrorExit("\nUnable to check server status", status); | |
100 | if (motd) { | |
101 | fprintf(stderr, "The SMS server is currently unavailable:\n%s\n", motd); | |
102 | sms_disconnect(); | |
103 | exit(1); | |
104 | } | |
105 | ||
461c03b6 | 106 | if ( status = sms_auth(program_name) ) |
107 | ErrorExit("\nAuthorization failed -- please run kinit", status); | |
08345b74 | 108 | |
109 | /* | |
110 | * These signals should not be set until just before we fire up the menu | |
111 | * system. | |
112 | */ | |
85ca828a | 113 | |
114 | #ifndef DEBUG | |
461c03b6 | 115 | (void) signal(SIGHUP, SignalHandler); |
85ca828a | 116 | (void) signal(SIGINT, SignalHandler); |
461c03b6 | 117 | (void) signal(SIGQUIT, SignalHandler); |
85ca828a | 118 | #endif DEBUG |
08345b74 | 119 | |
ace1dd7b | 120 | if (!strcmp(program_name, "listmaint")) |
121 | menu = &list_menu; | |
122 | else if (!strcmp(program_name, "usermaint")) | |
123 | menu = &user_menu; | |
bc628e37 | 124 | else if (!strcmp(program_name, "dcmmaint")) |
125 | menu = &dcm_menu; | |
ace1dd7b | 126 | else |
127 | menu = &sms_top_menu; | |
128 | ||
08345b74 | 129 | if (use_menu) { /* Start menus that execute program */ |
130 | Start_paging(); | |
ace1dd7b | 131 | Start_menu(menu); |
08345b74 | 132 | Stop_paging(); |
133 | } | |
134 | else /* Start program without menus. */ | |
ace1dd7b | 135 | Start_no_menu(menu); |
08345b74 | 136 | |
137 | sms_disconnect(); | |
138 | exit(0); | |
139 | } | |
140 | ||
461c03b6 | 141 | /* Function Name: ErrorExit |
08345b74 | 142 | * Description: This function does the error handling and exits. |
143 | * Arguments: buf - the error message to print. | |
144 | * status - the error code. | |
145 | * Returns: doesn't return. | |
146 | */ | |
147 | ||
148 | static void | |
461c03b6 | 149 | ErrorExit(buf,status) |
08345b74 | 150 | int status; |
461c03b6 | 151 | char * buf; |
08345b74 | 152 | { |
153 | com_err(program_name, status, buf); | |
154 | sms_disconnect(); | |
155 | exit(1); | |
156 | } | |
157 | ||
158 | /* Function Name: usage | |
159 | * Description: Prints usage info and then exits. | |
160 | * Arguments: none | |
161 | * Returns: doesn't return. | |
162 | */ | |
163 | ||
164 | static void | |
461c03b6 | 165 | Usage() |
08345b74 | 166 | { |
167 | fprintf(stderr, "Usage: %s [-nomenu]\n", program_name); | |
168 | exit(1); | |
169 | } | |
170 | ||
402461ad | 171 | #ifndef DEBUG |
461c03b6 | 172 | /* Function Name: SignalHandler |
08345b74 | 173 | * Description: This function cleans up from a signal interrupt. |
174 | * Arguments: none. | |
175 | * Returns: doesn't | |
176 | */ | |
177 | ||
85ca828a | 178 | static void |
461c03b6 | 179 | SignalHandler() |
08345b74 | 180 | { |
181 | Put_message("Signal caught - exiting"); | |
182 | if (use_menu) | |
183 | Cleanup_menu(); | |
184 | sms_disconnect(); | |
185 | exit(1); | |
186 | } | |
402461ad | 187 | #endif DEBUG |