]> andersk Git - moira.git/blob - clients/moira/main.c
set program name before usage message is printed
[moira.git] / clients / moira / main.c
1 #if (!defined(lint) && !defined(SABER))
2   static char rcsid_module_c[] = "$Header$";
3 #endif lint
4
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.
8  *      
9  *      Created:        4/12/88
10  *      By:             Chris D. Peterson
11  *
12  *      $Source$
13  *      $Author$
14  *      $Header$
15  *      
16  *      Copyright 1988 by the Massachusetts Institute of Technology.
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>
26 #include <sys/types.h>
27 #include <sms.h>
28 #include <menu.h>
29
30 #include "mit-copyright.h"
31 #include "defs.h"
32 #include "f_defs.h"
33 #include "globals.h"
34
35 char * whoami;                  /* used by menu.c ugh!!! */
36
37 extern Menu sms_top_menu, list_menu, user_menu, dcm_menu;
38
39 #ifndef DEBUG
40 static void SignalHandler();
41 #endif DEBUG
42
43 static void ErrorExit(), Usage();
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
51  *      Description: The main driver for the SMS Client.
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 {
61     int status;
62     Menu *menu;
63
64     if ((user = getlogin()) == NULL) 
65         user = getpwuid((int) getuid())->pw_name;
66     user = (user && strlen(user)) ? Strsave(user) : "";
67
68     program_name = Strsave(program_name);
69     whoami = Strsave(program_name); /* used by menu.c,  ugh !!! */
70
71     init_sms_err_tbl();
72     init_krb_err_tbl();
73     verbose = TRUE;
74
75     switch (argc) {
76     case 2:
77       if (strcmp(argv[1], "-nomenu") == 0)
78         use_menu = FALSE;
79       else 
80         Usage();
81                                 /* Fall Through. */
82     case 1:
83       if ((program_name = rindex(argv[0], '/')) == NULL)
84         program_name = argv[0];
85       else
86         program_name++;
87       break;
88     default:
89       Usage();
90       break;
91     }
92
93     if ( status = sms_connect() ) 
94         ErrorExit("\nConnection to SMS server failed", status);
95
96     if ( status = sms_auth(program_name) ) 
97         ErrorExit("\nAuthorization failed -- please run kinit", status);
98
99 /*
100  * These signals should not be set until just before we fire up the menu
101  * system. 
102  */
103
104 #ifndef DEBUG
105     (void) signal(SIGHUP, SignalHandler);
106     (void) signal(SIGINT, SignalHandler); 
107     (void) signal(SIGQUIT, SignalHandler);
108 #endif DEBUG
109
110     if (!strcmp(program_name, "listmaint"))
111       menu = &list_menu;
112     else if (!strcmp(program_name, "usermaint"))
113       menu = &user_menu;
114     else if (!strcmp(program_name, "dcmmaint"))
115       menu = &dcm_menu;
116     else
117       menu = &sms_top_menu;
118
119     if (use_menu) {             /* Start menus that execute program */
120         Start_paging();
121         Start_menu(menu);
122         Stop_paging();
123     }
124     else                        /* Start program without menus. */
125         Start_no_menu(menu);
126
127     sms_disconnect();
128     exit(0);
129 }
130
131 /*      Function Name: ErrorExit
132  *      Description: This function does the error handling and exits.
133  *      Arguments: buf - the error message to print.
134  *                 status - the error code.
135  *      Returns: doesn't return.
136  */
137
138 static void
139 ErrorExit(buf,status)
140 int status;
141 char * buf;    
142 {
143     com_err(program_name, status, buf);
144     sms_disconnect();
145     exit(1);
146 }
147
148 /*      Function Name: usage
149  *      Description: Prints usage info and then exits.
150  *      Arguments: none
151  *      Returns: doesn't return.
152  */
153
154 static void
155 Usage()
156 {
157     fprintf(stderr, "Usage: %s [-nomenu]\n", program_name);
158     exit(1);
159 }
160
161 #ifndef DEBUG
162 /*      Function Name: SignalHandler
163  *      Description: This function cleans up from a signal interrupt.
164  *      Arguments: none.
165  *      Returns: doesn't
166  */
167
168 static void
169 SignalHandler()
170 {
171     Put_message("Signal caught - exiting");
172     if (use_menu)
173       Cleanup_menu();
174     sms_disconnect();
175     exit(1);
176 }
177 #endif DEBUG
This page took 2.299335 seconds and 5 git commands to generate.