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

Revision 23271, 5.5 KB checked in by broder, 15 years ago (diff)
Add com_err support for delete and discuss on OS X.
RevLine 
[72]1/*
[1926]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/*
[22658]9 *      $Id: discuss.c,v 1.60 2007-08-09 20:41:31 amb Exp $
[72]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
[1603]18static char rcsid_discuss_c[] =
[22658]19    "$Id: discuss.c,v 1.60 2007-08-09 20:41:31 amb Exp $";
[12459]20#endif /* lint */
[72]21
[65]22#include <stdio.h>
[22404]23#include <stdlib.h>
[65]24#include <sys/file.h>
[75]25#include <signal.h>
[1603]26#include <string.h>
[82]27#include <sys/wait.h>
[281]28#include <pwd.h>
[8816]29#include <ss/ss.h>
[1632]30#include <discuss/discuss.h>
[184]31#include "config.h"
[82]32#include "globals.h"
[65]33
[82]34#ifdef  lint
[91]35#define DONT_USE(var)   var=var;
[12459]36#else   /* lint */
[91]37#define DONT_USE(var)   ;
[12459]38#endif  /* lint */
[82]39
[107]40#define FREE(ptr)       { if (ptr) free(ptr); }
[116]41#define max(a, b) ((a) > (b) ? (a) : (b))
[107]42
[65]43extern ss_request_table discuss_cmds;
[116]44
[22658]45char    dsc_version[] = "1.7";
[189]46int     sci_idx;
[82]47
[556]48extern char *temp_file, *pgm, *user_id;
49
[116]50/* EXTERNAL ROUTINES */
51
52tfile   unix_tfile();
[281]53char    *local_realm();
[556]54static char     buf[BUFSIZ];
[1603]55char    *buffer = buf;
[116]56
[1603]57int main (argc, argv)
[65]58        int argc;
59        char **argv;
60{
[82]61        int code;
[158]62        char *initial_meeting = (char *)NULL;
63        char *subsystem_name = "discuss";
[350]64        char *argv0 = argv[0];
[158]65        char *initial_request = (char *)NULL;
[281]66        bool quit = FALSE;      /* quit after processing request */
[193]67        bool flame = FALSE;     /* Have we flamed them for multiple  */
[65]68
[557]69        signal(SIGPIPE, SIG_IGN);
[1042]70        editor_path = getenv ("DISCUSS_EDITOR");
[193]71
[158]72        while (++argv, --argc) {
[284]73                if (!strcmp(*argv, "-prompt")) {
[158]74                        if (argc == 1) {
[284]75                                fprintf(stderr,
76                                        "No argument supplied with -prompt\n");
[158]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) {
[281]84                                fprintf(stderr,
85                                        "No string supplied with -request.\n");
[158]86                                exit(1);
87                        }
88                        argc--; argv++;
89                        initial_request = *argv;
90                }
91                else if (!strcmp(*argv, "-quit"))
[193]92                        quit = TRUE;
[158]93                else if (!strcmp(*argv, "-no_quit"))
[193]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                }
[192]107                else if (!strcmp(*argv, "-no_editor"))
108                        use_editor = FALSE;
[158]109                else if (**argv == '-') {
110                        fprintf(stderr, "Unknown control argument %s\n",
111                                *argv);
[284]112                        fprintf(stderr, "Usage: %s [ -prompt name ] [ -request name ] [ -quit ]\n\t\t[ -editor editor_path ] [ -no_editor ]\n",
[350]113                                argv0);
[158]114                        exit(1);
115                }
[193]116                else {
117                        if (initial_meeting) {
[1603]118                                if (!flame) {
[193]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                }
[158]126        }
127
[1043]128        {
[1601]129                char *user;
130                struct passwd *user_pw = getpwuid(getuid());
[281]131                register char *realm = local_realm();
[1601]132               
[556]133
[1601]134                if (user_pw == NULL) {
[1603]135                     fprintf(stderr,
[1643]136                 "You do not appear in /etc/passwd.  Cannot continue.\n");
[1601]137                     exit(1);
138                }
139                user = user_pw -> pw_name;
[556]140                user_id = malloc((unsigned)(strlen(user)+strlen(realm)+2));
141                strcpy(user_id, user);
142                strcat(user_id, "@");
143                strcat(user_id, realm);
[281]144        }
145
[352]146        sci_idx = ss_create_invocation(subsystem_name, dsc_version,
[82]147                                       (char *)NULL, &discuss_cmds, &code);
148        if (code) {
[1603]149            com_err (subsystem_name, code, "creating invocation");
150            exit(1);
[65]151        }
[190]152        (void) ss_add_info_dir(sci_idx, INFO_DIR, &code);
[82]153        if (code) {
154                ss_perror(sci_idx, code, INFO_DIR);
[65]155        }
156
[23271]157#if defined(__APPLE__) && defined(__MACH__)
158        add_error_table(&et_disc_error_table);
159        add_error_table(&et_dsc_error_table);
160#else
[22864]161        initialize_disc_error_table();
162        initialize_dsc_error_table();
[23271]163#endif
[65]164
[82]165        temp_file = malloc(64);
166        pgm = malloc(64);
[190]167        (void) sprintf(temp_file, "/tmp/mtg%d.%d", (int)getuid(), getpid());
[82]168
[308]169        if (code = find_rc_filename()) {
[556]170             register char *prompt;
171             ss_perror(sci_idx, code, "");
172             fprintf(stderr, "\n\
[12297]173If you are using discuss for the first time, you need to run the 'dsc_setup'\n\
[308]174command from the shell.\n\n");
[556]175             fflush(stderr);
176             prompt = "Run dsc_setup now? (y or n) ";
177             while (getyn(prompt, 'y')) {
178                  printf("\nRunning dsc_setup...\n");
179                  system("dsc_setup");
180                  if (code = find_rc_filename()) {
181                       ss_perror(sci_idx, code, "");
182                       prompt =
183                            "\nThat didn't seem to work; try again? (y or n)";
184                  } else break;
185             }
186             if (code)
[1643]187                 exit (1);
[308]188        }
[556]189        else if (!quit) {
190             printf("Discuss version %s.  Type '?' for a list of commands.\n",
191                    dsc_version);
192             if (!initial_meeting)
193                  printf("\n");
194        }
[308]195
[158]196        if (initial_meeting != (char *)NULL) {
197                (void) sprintf(buffer, "goto %s", initial_meeting);
[22404]198                code = ss_execute_line(sci_idx, buffer);
[82]199                if (code != 0)
[158]200                        ss_perror(sci_idx, code, initial_meeting);
[67]201        }
[158]202        if (initial_request != (char *)NULL) {
[22404]203                code = ss_execute_line(sci_idx, initial_request);
[158]204                if (code != 0)
205                        ss_perror(sci_idx, code, initial_request);
206        }
207        if (!quit || code)
[22404]208                code = ss_listen (sci_idx);
[116]209        leave_mtg();                            /* clean up after ourselves */
[1395]210        return 0;
[65]211}
[308]212
[1603]213int getyn(prompt,def)
214    char *prompt, def;
[308]215{
[1603]216        char inp[128];
[308]217
218        for (;;) {
219                (void) printf("%s ",prompt);
[1643]220                if (fgets (inp, 128, stdin) == NULL)
[1603]221                    return FALSE;
[1643]222                else if (inp[0] == '\n')
[1603]223                    inp[0] = def;
224                if (inp[0] == 'y' || inp[0] == 'Y')
225                    return 1;
226                else if (inp[0] == 'n' || inp[0] == 'N')
227                    return 0;
[308]228                printf("Please enter 'Yes' or 'No'\n\n");
229        }
230}
Note: See TracBrowser for help on using the repository browser.