source: trunk/athena/bin/discuss/client/discuss.c @ 22864

Revision 22864, 5.3 KB checked in by andersk, 16 years ago (diff)
Fix obsolete names for Kerberos library functions, which no longer worked on Mac OS X. Patch from broder.
Line 
1/*
2 *
3 *    Copyright (C) 1989 by the Massachusetts Institute of Technology
4 *    Developed by the MIT Student Information Processing Board (SIPB).
5 *    For copying information, see the file mit-copyright.h in this release.
6 *
7 */
8/*
9 *      $Id: discuss.c,v 1.60 2007-08-09 20:41:31 amb Exp $
10 *
11 *      A simple shell-type user interface to discuss; uses Ken Raeburn's
12 *      ss library for the command interpreter.
13 *
14 */
15
16
17#ifndef lint
18static char rcsid_discuss_c[] =
19    "$Id: discuss.c,v 1.60 2007-08-09 20:41:31 amb Exp $";
20#endif /* lint */
21
22#include <stdio.h>
23#include <stdlib.h>
24#include <sys/file.h>
25#include <signal.h>
26#include <string.h>
27#include <sys/wait.h>
28#include <pwd.h>
29#include <ss/ss.h>
30#include <discuss/discuss.h>
31#include "config.h"
32#include "globals.h"
33
34#ifdef  lint
35#define DONT_USE(var)   var=var;
36#else   /* lint */
37#define DONT_USE(var)   ;
38#endif  /* lint */
39
40#define FREE(ptr)       { if (ptr) free(ptr); }
41#define max(a, b) ((a) > (b) ? (a) : (b))
42
43extern ss_request_table discuss_cmds;
44
45char    dsc_version[] = "1.7";
46int     sci_idx;
47
48extern char *temp_file, *pgm, *user_id;
49
50/* EXTERNAL ROUTINES */
51
52tfile   unix_tfile();
53char    *local_realm();
54static char     buf[BUFSIZ];
55char    *buffer = buf;
56
57int main (argc, argv)
58        int argc;
59        char **argv;
60{
61        int code;
62        char *initial_meeting = (char *)NULL;
63        char *subsystem_name = "discuss";
64        char *argv0 = argv[0];
65        char *initial_request = (char *)NULL;
66        bool quit = FALSE;      /* quit after processing request */
67        bool flame = FALSE;     /* Have we flamed them for multiple  */
68
69        signal(SIGPIPE, SIG_IGN);
70        editor_path = getenv ("DISCUSS_EDITOR");
71
72        while (++argv, --argc) {
73                if (!strcmp(*argv, "-prompt")) {
74                        if (argc == 1) {
75                                fprintf(stderr,
76                                        "No argument supplied with -prompt\n");
77                                exit(1);
78                        }
79                        argc--; argv++;
80                        subsystem_name = *argv;
81                }
82                else if (!strcmp(*argv, "-request") || !strcmp(*argv, "-rq")) {
83                        if (argc == 1) {
84                                fprintf(stderr,
85                                        "No string supplied with -request.\n");
86                                exit(1);
87                        }
88                        argc--; argv++;
89                        initial_request = *argv;
90                }
91                else if (!strcmp(*argv, "-quit"))
92                        quit = TRUE;
93                else if (!strcmp(*argv, "-no_quit"))
94                        quit = FALSE;
95                else if (!strcmp(*argv, "-editor")) {
96                        if (argc == 1) {
97                                fprintf(stderr, "No editor name supplied with -editor\n");
98                                exit(1);
99                        }
100                        if (!use_editor) {
101                                fprintf(stderr, "Both -editor and -no_editor specified\n");
102                                exit(1);
103                        }
104                        --argc;
105                        editor_path = *(++argv);
106                }
107                else if (!strcmp(*argv, "-no_editor"))
108                        use_editor = FALSE;
109                else if (**argv == '-') {
110                        fprintf(stderr, "Unknown control argument %s\n",
111                                *argv);
112                        fprintf(stderr, "Usage: %s [ -prompt name ] [ -request name ] [ -quit ]\n\t\t[ -editor editor_path ] [ -no_editor ]\n",
113                                argv0);
114                        exit(1);
115                }
116                else {
117                        if (initial_meeting) {
118                                if (!flame) {
119                                        fprintf(stderr,
120"More than one meeting name supplied on command line; using %s\n",
121                                                initial_meeting);
122                                        flame = TRUE;
123                                }
124                        } else initial_meeting = *argv;
125                }
126        }
127
128        {
129                char *user;
130                struct passwd *user_pw = getpwuid(getuid());
131                register char *realm = local_realm();
132               
133
134                if (user_pw == NULL) {
135                     fprintf(stderr,
136                 "You do not appear in /etc/passwd.  Cannot continue.\n");
137                     exit(1);
138                }
139                user = user_pw -> pw_name;
140                user_id = malloc((unsigned)(strlen(user)+strlen(realm)+2));
141                strcpy(user_id, user);
142                strcat(user_id, "@");
143                strcat(user_id, realm);
144        }
145
146        sci_idx = ss_create_invocation(subsystem_name, dsc_version,
147                                       (char *)NULL, &discuss_cmds, &code);
148        if (code) {
149            com_err (subsystem_name, code, "creating invocation");
150            exit(1);
151        }
152        (void) ss_add_info_dir(sci_idx, INFO_DIR, &code);
153        if (code) {
154                ss_perror(sci_idx, code, INFO_DIR);
155        }
156
157        initialize_disc_error_table();
158        initialize_dsc_error_table();
159
160        temp_file = malloc(64);
161        pgm = malloc(64);
162        (void) sprintf(temp_file, "/tmp/mtg%d.%d", (int)getuid(), getpid());
163
164        if (code = find_rc_filename()) {
165             register char *prompt;
166             ss_perror(sci_idx, code, "");
167             fprintf(stderr, "\n\
168If you are using discuss for the first time, you need to run the 'dsc_setup'\n\
169command from the shell.\n\n");
170             fflush(stderr);
171             prompt = "Run dsc_setup now? (y or n) ";
172             while (getyn(prompt, 'y')) {
173                  printf("\nRunning dsc_setup...\n");
174                  system("dsc_setup");
175                  if (code = find_rc_filename()) {
176                       ss_perror(sci_idx, code, "");
177                       prompt =
178                            "\nThat didn't seem to work; try again? (y or n)";
179                  } else break;
180             }
181             if (code)
182                 exit (1);
183        }
184        else if (!quit) {
185             printf("Discuss version %s.  Type '?' for a list of commands.\n",
186                    dsc_version);
187             if (!initial_meeting)
188                  printf("\n");
189        }
190
191        if (initial_meeting != (char *)NULL) {
192                (void) sprintf(buffer, "goto %s", initial_meeting);
193                code = ss_execute_line(sci_idx, buffer);
194                if (code != 0)
195                        ss_perror(sci_idx, code, initial_meeting);
196        }
197        if (initial_request != (char *)NULL) {
198                code = ss_execute_line(sci_idx, initial_request);
199                if (code != 0)
200                        ss_perror(sci_idx, code, initial_request);
201        }
202        if (!quit || code)
203                code = ss_listen (sci_idx);
204        leave_mtg();                            /* clean up after ourselves */
205        return 0;
206}
207
208int getyn(prompt,def)
209    char *prompt, def;
210{
211        char inp[128];
212
213        for (;;) {
214                (void) printf("%s ",prompt);
215                if (fgets (inp, 128, stdin) == NULL)
216                    return FALSE;
217                else if (inp[0] == '\n')
218                    inp[0] = def;
219                if (inp[0] == 'y' || inp[0] == 'Y')
220                    return 1;
221                else if (inp[0] == 'n' || inp[0] == 'N')
222                    return 0;
223                printf("Please enter 'Yes' or 'No'\n\n");
224        }
225}
Note: See TracBrowser for help on using the repository browser.