[324] | 1 | /* |
---|
[1927] | 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 | /* |
---|
[22404] | 9 | * $Id: anm.c,v 1.12 2006-03-10 07:11:30 ghudson Exp $ |
---|
[324] | 10 | * |
---|
| 11 | */ |
---|
| 12 | |
---|
| 13 | #ifndef lint |
---|
[1639] | 14 | static char rcsid_anm_c[] = |
---|
[22404] | 15 | "$Id: anm.c,v 1.12 2006-03-10 07:11:30 ghudson Exp $"; |
---|
[12459] | 16 | #endif /* lint */ |
---|
[324] | 17 | |
---|
[1639] | 18 | #include <stdio.h> |
---|
| 19 | #include <sys/file.h> |
---|
[12439] | 20 | #if HAVE_FCNTL_H |
---|
[6528] | 21 | #include <fcntl.h> |
---|
| 22 | #endif |
---|
[8816] | 23 | #include <ss/ss.h> |
---|
[1639] | 24 | #include <discuss/discuss.h> |
---|
[324] | 25 | #include "config.h" |
---|
| 26 | #include "globals.h" |
---|
| 27 | |
---|
[329] | 28 | extern tfile unix_tfile(); |
---|
| 29 | |
---|
[324] | 30 | announce_mtg (argc, argv) |
---|
| 31 | int argc; |
---|
| 32 | char **argv; |
---|
| 33 | { |
---|
[346] | 34 | char temp_file[100],*src_mtg,*dest_mtg; |
---|
[324] | 35 | char *editor = NULL; |
---|
| 36 | int code,fd,public,i,txn_no; |
---|
| 37 | tfile tf; |
---|
| 38 | name_blk nbsrc, nbdest; |
---|
| 39 | |
---|
| 40 | if (argc < 3) { |
---|
| 41 | (void) fprintf(stderr, "Usage: %s {-private | -public} mtg_to_announce mtg_to_announce_in\n", argv[0]); |
---|
| 42 | return; |
---|
| 43 | } |
---|
| 44 | |
---|
| 45 | public = 1; |
---|
| 46 | src_mtg = dest_mtg = NULL; |
---|
| 47 | |
---|
| 48 | i = 0; |
---|
| 49 | while (i++,--argc > 0) { |
---|
| 50 | if (*argv[i] == '-') { |
---|
| 51 | if (!strcmp(argv[i],"-public")) { |
---|
| 52 | public = 1; |
---|
| 53 | continue; |
---|
| 54 | } |
---|
| 55 | else if (!strcmp(argv[i],"-private")) { |
---|
| 56 | public = 0; |
---|
| 57 | continue; |
---|
| 58 | } |
---|
| 59 | else if (!strcmp(argv[i], "-editor") || |
---|
| 60 | !strcmp(argv[i], "-ed")) { |
---|
| 61 | if (argc == 1) { |
---|
| 62 | (void) fprintf(stderr, |
---|
| 63 | "No argument to %s.\n", argv[i]); |
---|
| 64 | return; |
---|
| 65 | } |
---|
| 66 | editor = argv[++i]; |
---|
| 67 | argc--; |
---|
| 68 | continue; |
---|
| 69 | } |
---|
| 70 | else if (!strcmp(argv[i], "-no_editor")) { |
---|
| 71 | editor = ""; |
---|
| 72 | continue; |
---|
| 73 | } |
---|
| 74 | else { |
---|
| 75 | fprintf(stderr, |
---|
| 76 | "Unknown control argument %s\n", |
---|
| 77 | argv[i]); |
---|
| 78 | return; |
---|
| 79 | } |
---|
| 80 | } |
---|
| 81 | if (src_mtg) |
---|
| 82 | if (dest_mtg) { |
---|
| 83 | fprintf(stderr, |
---|
| 84 | "Extra arguments specified: %s\n", |
---|
| 85 | argv[i]); |
---|
| 86 | return; |
---|
| 87 | } |
---|
| 88 | else |
---|
| 89 | dest_mtg = argv[i]; |
---|
| 90 | else |
---|
| 91 | src_mtg = argv[i]; |
---|
| 92 | } |
---|
| 93 | |
---|
| 94 | if (!src_mtg || !dest_mtg) { |
---|
| 95 | fprintf (stderr, |
---|
| 96 | "Two meeting names must be specified\n"); |
---|
| 97 | return; |
---|
| 98 | } |
---|
| 99 | |
---|
| 100 | dsc_get_mtg (user_id, src_mtg, &nbsrc, &code); |
---|
| 101 | if (code != 0) { |
---|
| 102 | (void) fprintf (stderr, |
---|
| 103 | "%s: Meeting not found in search path.\n", |
---|
| 104 | src_mtg); |
---|
| 105 | return; |
---|
| 106 | } |
---|
| 107 | |
---|
| 108 | dsc_get_mtg (user_id, dest_mtg, &nbdest, &code); |
---|
| 109 | if (code != 0) { |
---|
| 110 | (void) fprintf (stderr, |
---|
| 111 | "%s: Meeting not found in search path.\n", |
---|
| 112 | dest_mtg); |
---|
| 113 | return; |
---|
| 114 | } |
---|
| 115 | |
---|
| 116 | printf("Please enter the body of the meeting announcement.\n"); |
---|
| 117 | |
---|
| 118 | (void) sprintf(temp_file,"/tmp/mtg%d.%d",getuid(),getpid()); |
---|
| 119 | (void) unlink(temp_file); |
---|
| 120 | |
---|
| 121 | if (edit(temp_file, editor)) { |
---|
| 122 | (void) fprintf(stderr, |
---|
| 123 | "Error during edit; meeting not announced.\n"); |
---|
| 124 | return; |
---|
| 125 | } |
---|
| 126 | |
---|
| 127 | fd = open(temp_file,O_RDONLY,0); |
---|
| 128 | if (fd < 0) { |
---|
| 129 | (void) fprintf(stderr,"Temporary file disappeared!\n"); |
---|
| 130 | return; |
---|
| 131 | } |
---|
| 132 | |
---|
| 133 | tf = unix_tfile(fd); |
---|
| 134 | |
---|
| 135 | dsc_announce_mtg(&nbsrc, &nbdest, public, tf, &txn_no, &code); |
---|
| 136 | |
---|
| 137 | if (code) { |
---|
| 138 | (void) fprintf(stderr,"Error adding transation: %s\n", |
---|
| 139 | error_message(code)); |
---|
| 140 | return; |
---|
| 141 | } |
---|
| 142 | |
---|
| 143 | (void) printf("Transaction [%04d] entered in the %s meeting.\n", |
---|
| 144 | txn_no, nbdest.aliases[0]); |
---|
| 145 | |
---|
| 146 | (void) close(fd); |
---|
| 147 | |
---|
| 148 | } |
---|