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: lsm.c,v 1.27 2006-03-10 07:11:31 ghudson Exp $ |
---|
10 | * |
---|
11 | */ |
---|
12 | |
---|
13 | #ifndef lint |
---|
14 | static char rcsid_lsm_c[] = |
---|
15 | "$Id: lsm.c,v 1.27 2006-03-10 07:11:31 ghudson Exp $"; |
---|
16 | #endif /* lint */ |
---|
17 | |
---|
18 | #include <string.h> |
---|
19 | #include <stdio.h> |
---|
20 | #include <stdlib.h> |
---|
21 | #include <discuss/discuss.h> |
---|
22 | #include "globals.h" |
---|
23 | #include <errno.h> |
---|
24 | #include <ss/ss.h> |
---|
25 | |
---|
26 | extern void flag_interrupts(), dont_flag_interrupts(); |
---|
27 | |
---|
28 | |
---|
29 | int print_header, long_output; |
---|
30 | static char last_host[140], last_path[140]; |
---|
31 | static char *auser_id; |
---|
32 | static int fast; |
---|
33 | |
---|
34 | /* this function should probably be void */ |
---|
35 | int do_line(nbp, code, updated) |
---|
36 | register name_blk *nbp; |
---|
37 | int code, updated; |
---|
38 | { |
---|
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; |
---|
49 | if (print_header) { |
---|
50 | char *fmt = "%-7s %-22s %-22s\n"; |
---|
51 | last_host[0] = '\0'; |
---|
52 | last_path[0] = '\0'; |
---|
53 | printf (" Flags Meeting\n"); |
---|
54 | printf (" ----- -------\n"); |
---|
55 | print_header = 0; |
---|
56 | } |
---|
57 | if (code) { |
---|
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); |
---|
63 | return 0; |
---|
64 | } |
---|
65 | if(!strcmp(last_host,nbp->hostname)&&!strcmp(last_path,nbp->pathname)) |
---|
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); |
---|
73 | return 0; |
---|
74 | } |
---|
75 | |
---|
76 | static |
---|
77 | do_mtg(mtg_name) |
---|
78 | char *mtg_name; |
---|
79 | { |
---|
80 | name_blk *set; |
---|
81 | register name_blk *nbp; |
---|
82 | int n_matches, i, code; |
---|
83 | bool updated; |
---|
84 | |
---|
85 | dsc_expand_mtg_set(auser_id, mtg_name, &set, &n_matches, &code); |
---|
86 | |
---|
87 | if (code) { |
---|
88 | ss_perror(sci_idx, code, ""); |
---|
89 | return(0); |
---|
90 | } |
---|
91 | |
---|
92 | if (!n_matches) |
---|
93 | return (0); |
---|
94 | |
---|
95 | for (i = 0; i < n_matches; i++) { |
---|
96 | if (interrupt) |
---|
97 | break; |
---|
98 | |
---|
99 | nbp = &set[i]; |
---|
100 | |
---|
101 | if (fast) { |
---|
102 | updated = 0; |
---|
103 | } else { |
---|
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 { |
---|
111 | dsc_updated_mtg(nbp, &updated, &code); |
---|
112 | if (interrupt) |
---|
113 | break; |
---|
114 | if (code == NO_SUCH_TRN) { /* Meeting lost trns */ |
---|
115 | updated = TRUE; |
---|
116 | code = 0; |
---|
117 | } |
---|
118 | } |
---|
119 | } |
---|
120 | do_line(nbp, code, updated); |
---|
121 | } |
---|
122 | dsc_destroy_mtg_set(set, n_matches); |
---|
123 | return(0); |
---|
124 | } |
---|
125 | |
---|
126 | list_meetings (argc, argv) |
---|
127 | int argc; |
---|
128 | char **argv; |
---|
129 | { |
---|
130 | int have_names = 0; |
---|
131 | int i, *used; |
---|
132 | char *auser; |
---|
133 | |
---|
134 | used = (int *)calloc(argc, sizeof(int)); |
---|
135 | long_output = 0; /* make dependent on arguments later */ |
---|
136 | auser = ""; |
---|
137 | print_header = 1; |
---|
138 | fast = 0; |
---|
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"); |
---|
144 | free((char *)used); |
---|
145 | return; |
---|
146 | } |
---|
147 | if (auser[0] != '\0') { |
---|
148 | fprintf(stderr, |
---|
149 | "Only one of -user, -public allowed\n"); |
---|
150 | goto punt; |
---|
151 | } |
---|
152 | used[i] = 1; |
---|
153 | auser = argv[++i]; |
---|
154 | used[i] = 1; |
---|
155 | } |
---|
156 | else if (!strcmp(argv[i],"-public")) { |
---|
157 | if (auser[0] != '\0') { |
---|
158 | fprintf(stderr, |
---|
159 | "Only one of -user, -public allowed\n"); |
---|
160 | goto punt; |
---|
161 | } |
---|
162 | auser = "discuss"; |
---|
163 | used[i] = 1; |
---|
164 | } |
---|
165 | else if (!strcmp(argv[i],"-f") || !strcmp(argv[i], "-fast") || !strcmp(argv[i], "-brief") || !strcmp(argv[i], "-bf")) |
---|
166 | fast = 1; |
---|
167 | else if (*argv[i] == '-') { |
---|
168 | fprintf(stderr, |
---|
169 | "Unknown control argument %s\n", |
---|
170 | argv[i]); |
---|
171 | free((char *)used); |
---|
172 | return; |
---|
173 | } |
---|
174 | else { |
---|
175 | have_names = 1; |
---|
176 | } |
---|
177 | } |
---|
178 | |
---|
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 | |
---|
186 | flag_interrupts(); |
---|
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 | } |
---|
194 | dont_flag_interrupts(); |
---|
195 | |
---|
196 | punt: |
---|
197 | free(auser_id); |
---|
198 | free((char *)used); |
---|
199 | } |
---|