[209] | 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: lsm.c,v 1.27 2006-03-10 07:11:31 ghudson Exp $ |
---|
[209] | 10 | * |
---|
| 11 | */ |
---|
| 12 | |
---|
| 13 | #ifndef lint |
---|
[1607] | 14 | static char rcsid_lsm_c[] = |
---|
[22404] | 15 | "$Id: lsm.c,v 1.27 2006-03-10 07:11:31 ghudson Exp $"; |
---|
[12459] | 16 | #endif /* lint */ |
---|
[209] | 17 | |
---|
[1607] | 18 | #include <string.h> |
---|
[124] | 19 | #include <stdio.h> |
---|
[22404] | 20 | #include <stdlib.h> |
---|
[1636] | 21 | #include <discuss/discuss.h> |
---|
[127] | 22 | #include "globals.h" |
---|
[524] | 23 | #include <errno.h> |
---|
[8816] | 24 | #include <ss/ss.h> |
---|
[124] | 25 | |
---|
[1043] | 26 | extern void flag_interrupts(), dont_flag_interrupts(); |
---|
[124] | 27 | |
---|
[1043] | 28 | |
---|
[524] | 29 | int print_header, long_output; |
---|
| 30 | static char last_host[140], last_path[140]; |
---|
[286] | 31 | static char *auser_id; |
---|
[524] | 32 | static int fast; |
---|
[124] | 33 | |
---|
[1043] | 34 | /* this function should probably be void */ |
---|
[524] | 35 | int do_line(nbp, code, updated) |
---|
| 36 | register name_blk *nbp; |
---|
| 37 | int code, updated; |
---|
| 38 | { |
---|
[1607] | 39 | /* |
---|
| 40 | * Output format: 8-char flags field (including trailing |
---|
| 41 | * spaces), followed by a ", "-separated list of meetings |
---|
| 42 | * names, and newline. |
---|
| 43 | * |
---|
| 44 | * If an error occurred, 22+ characters of the first meeting |
---|
| 45 | * name are printed (padded with whitespace), followed by a |
---|
| 46 | * parenthesized error message. |
---|
| 47 | */ |
---|
| 48 | char **namep; |
---|
[524] | 49 | if (print_header) { |
---|
| 50 | char *fmt = "%-7s %-22s %-22s\n"; |
---|
| 51 | last_host[0] = '\0'; |
---|
| 52 | last_path[0] = '\0'; |
---|
[1607] | 53 | printf (" Flags Meeting\n"); |
---|
| 54 | printf (" ----- -------\n"); |
---|
[524] | 55 | print_header = 0; |
---|
| 56 | } |
---|
| 57 | if (code) { |
---|
[1607] | 58 | printf(" %-22s (%s %s%s)\n", nbp->aliases[0], |
---|
| 59 | error_message (code), |
---|
| 60 | (code == ECONNREFUSED) ? "by " |
---|
| 61 | : ((code == ETIMEDOUT) ? "with " : ""), |
---|
| 62 | nbp->hostname); |
---|
[524] | 63 | return 0; |
---|
| 64 | } |
---|
[593] | 65 | if(!strcmp(last_host,nbp->hostname)&&!strcmp(last_path,nbp->pathname)) |
---|
[1607] | 66 | updated = 0; |
---|
| 67 | printf (" %c %s", updated ? 'c' : ' ', nbp->aliases[0]); |
---|
| 68 | for (namep = &nbp->aliases[1]; *namep; namep++) |
---|
| 69 | printf (", %s", *namep); |
---|
| 70 | printf ("\n"); |
---|
| 71 | strcpy(last_host,nbp->hostname); |
---|
| 72 | strcpy(last_path,nbp->pathname); |
---|
[1043] | 73 | return 0; |
---|
[524] | 74 | } |
---|
| 75 | |
---|
[124] | 76 | static |
---|
| 77 | do_mtg(mtg_name) |
---|
| 78 | char *mtg_name; |
---|
| 79 | { |
---|
[522] | 80 | name_blk *set; |
---|
[124] | 81 | register name_blk *nbp; |
---|
[522] | 82 | int n_matches, i, code; |
---|
| 83 | bool updated; |
---|
[124] | 84 | |
---|
[286] | 85 | dsc_expand_mtg_set(auser_id, mtg_name, &set, &n_matches, &code); |
---|
[310] | 86 | |
---|
| 87 | if (code) { |
---|
| 88 | ss_perror(sci_idx, code, ""); |
---|
| 89 | return(0); |
---|
| 90 | } |
---|
| 91 | |
---|
[209] | 92 | if (!n_matches) |
---|
| 93 | return (0); |
---|
[286] | 94 | |
---|
[209] | 95 | for (i = 0; i < n_matches; i++) { |
---|
[405] | 96 | if (interrupt) |
---|
| 97 | break; |
---|
[524] | 98 | |
---|
[124] | 99 | nbp = &set[i]; |
---|
[524] | 100 | |
---|
| 101 | if (fast) { |
---|
| 102 | updated = 0; |
---|
[355] | 103 | } else { |
---|
[524] | 104 | /* Test to see if we are attending this meeting */ |
---|
| 105 | if (dsc_public.attending |
---|
| 106 | && !strcmp(dsc_public.host, nbp->hostname) |
---|
| 107 | && !strcmp(dsc_public.path, nbp->pathname)) { |
---|
| 108 | updated = (dsc_public.highest_seen |
---|
| 109 | < dsc_public.m_info.last); |
---|
| 110 | } else { |
---|
[1238] | 111 | dsc_updated_mtg(nbp, &updated, &code); |
---|
[524] | 112 | if (interrupt) |
---|
| 113 | break; |
---|
[1238] | 114 | if (code == NO_SUCH_TRN) { /* Meeting lost trns */ |
---|
| 115 | updated = TRUE; |
---|
| 116 | code = 0; |
---|
| 117 | } |
---|
[127] | 118 | } |
---|
| 119 | } |
---|
[524] | 120 | do_line(nbp, code, updated); |
---|
[209] | 121 | } |
---|
[996] | 122 | dsc_destroy_mtg_set(set, n_matches); |
---|
[286] | 123 | return(0); |
---|
[209] | 124 | } |
---|
| 125 | |
---|
[189] | 126 | list_meetings (argc, argv) |
---|
| 127 | int argc; |
---|
[124] | 128 | char **argv; |
---|
| 129 | { |
---|
| 130 | int have_names = 0; |
---|
| 131 | int i, *used; |
---|
[286] | 132 | char *auser; |
---|
[124] | 133 | |
---|
[286] | 134 | used = (int *)calloc(argc, sizeof(int)); |
---|
| 135 | long_output = 0; /* make dependent on arguments later */ |
---|
| 136 | auser = ""; |
---|
[124] | 137 | print_header = 1; |
---|
[524] | 138 | fast = 0; |
---|
[124] | 139 | for (i = 1; i < argc; i++) { |
---|
| 140 | if (!strcmp("-user", argv[i])) { |
---|
| 141 | if (i == argc - 1) { |
---|
| 142 | fprintf(stderr, |
---|
| 143 | "Missing argument for -user\n"); |
---|
[286] | 144 | free((char *)used); |
---|
[124] | 145 | return; |
---|
| 146 | } |
---|
[286] | 147 | if (auser[0] != '\0') { |
---|
[127] | 148 | fprintf(stderr, |
---|
| 149 | "Only one of -user, -public allowed\n"); |
---|
| 150 | goto punt; |
---|
| 151 | } |
---|
[124] | 152 | used[i] = 1; |
---|
[286] | 153 | auser = argv[++i]; |
---|
[124] | 154 | used[i] = 1; |
---|
| 155 | } |
---|
[127] | 156 | else if (!strcmp(argv[i],"-public")) { |
---|
[286] | 157 | if (auser[0] != '\0') { |
---|
[127] | 158 | fprintf(stderr, |
---|
| 159 | "Only one of -user, -public allowed\n"); |
---|
| 160 | goto punt; |
---|
| 161 | } |
---|
[286] | 162 | auser = "discuss"; |
---|
[127] | 163 | used[i] = 1; |
---|
| 164 | } |
---|
[997] | 165 | else if (!strcmp(argv[i],"-f") || !strcmp(argv[i], "-fast") || !strcmp(argv[i], "-brief") || !strcmp(argv[i], "-bf")) |
---|
[524] | 166 | fast = 1; |
---|
[124] | 167 | else if (*argv[i] == '-') { |
---|
| 168 | fprintf(stderr, |
---|
| 169 | "Unknown control argument %s\n", |
---|
| 170 | argv[i]); |
---|
[286] | 171 | free((char *)used); |
---|
[124] | 172 | return; |
---|
| 173 | } |
---|
| 174 | else { |
---|
| 175 | have_names = 1; |
---|
| 176 | } |
---|
| 177 | } |
---|
| 178 | |
---|
[286] | 179 | auser_id = malloc(128); |
---|
| 180 | if (*auser) |
---|
| 181 | (void) strcpy(auser_id, auser); |
---|
| 182 | else { |
---|
| 183 | (void) strcpy(auser_id, user_id); |
---|
| 184 | } |
---|
| 185 | |
---|
[405] | 186 | flag_interrupts(); |
---|
[124] | 187 | if (!have_names) { |
---|
| 188 | do_mtg("*"); |
---|
| 189 | } |
---|
| 190 | else for (i = 1; i < argc; i++) { |
---|
| 191 | if (!used[i]) |
---|
| 192 | do_mtg(argv[i]); |
---|
| 193 | } |
---|
[405] | 194 | dont_flag_interrupts(); |
---|
[127] | 195 | |
---|
| 196 | punt: |
---|
[1819] | 197 | free(auser_id); |
---|
[286] | 198 | free((char *)used); |
---|
[124] | 199 | } |
---|