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: ckm.c,v 1.26 2006-03-10 07:11:30 ghudson Exp $ |
---|
10 | * |
---|
11 | */ |
---|
12 | |
---|
13 | #ifndef lint |
---|
14 | static char rcsid_ckm_c[] = |
---|
15 | "$Id: ckm.c,v 1.26 2006-03-10 07:11:30 ghudson Exp $"; |
---|
16 | #endif /* lint */ |
---|
17 | |
---|
18 | #include <string.h> |
---|
19 | #include <stdlib.h> |
---|
20 | #include <stdio.h> |
---|
21 | #include <discuss/discuss.h> |
---|
22 | #include "globals.h" |
---|
23 | |
---|
24 | extern int print_header; |
---|
25 | static int display; |
---|
26 | static int checked_meetings; |
---|
27 | |
---|
28 | static |
---|
29 | do_mtg(mtg_name) |
---|
30 | char *mtg_name; |
---|
31 | { |
---|
32 | name_blk *set = NULL; |
---|
33 | register name_blk *nbp; |
---|
34 | int n_matches, i, code; |
---|
35 | bool updated; |
---|
36 | bool cur_mtg_updated = 0; |
---|
37 | char last_host[140], last_path[140]; |
---|
38 | |
---|
39 | |
---|
40 | dsc_expand_mtg_set(user_id, mtg_name, &set, &n_matches, &code); |
---|
41 | if (!n_matches) |
---|
42 | return (0); |
---|
43 | |
---|
44 | last_host[0] = '\0'; |
---|
45 | last_path[0] = '\0'; |
---|
46 | for (i = 0; i < n_matches; i++) { |
---|
47 | code = 0; |
---|
48 | if (interrupt) |
---|
49 | break; |
---|
50 | nbp = &set[i]; |
---|
51 | /* Test to see if we are attending this meeting */ |
---|
52 | if (dsc_public.attending |
---|
53 | && !strcmp(dsc_public.path, nbp->pathname) |
---|
54 | && !strcmp(dsc_public.host, nbp ->hostname)) { |
---|
55 | dsc_destroy_mtg_info(&dsc_public.m_info); |
---|
56 | dsc_get_mtg_info(&dsc_public.nb, |
---|
57 | &dsc_public.m_info, &code); |
---|
58 | updated = (dsc_public.highest_seen < dsc_public.m_info.last); |
---|
59 | cur_mtg_updated = updated; |
---|
60 | code = 0; |
---|
61 | } else { |
---|
62 | dsc_updated_mtg(nbp, &updated, &code); |
---|
63 | if (interrupt) |
---|
64 | break; |
---|
65 | if (code == NO_SUCH_TRN) { /* Meeting lost trns */ |
---|
66 | updated = TRUE; |
---|
67 | code = 0; |
---|
68 | } |
---|
69 | } |
---|
70 | if (strcmp(last_path, nbp->pathname) || |
---|
71 | strcmp(last_host, nbp->hostname)) { |
---|
72 | strcpy(last_host,nbp->hostname); |
---|
73 | strcpy(last_path,nbp->pathname); |
---|
74 | if (updated && !code) |
---|
75 | nbp->status |= DSC_ST_CHANGED; |
---|
76 | else { |
---|
77 | nbp->status &= ~DSC_ST_CHANGED; |
---|
78 | } |
---|
79 | if (display && (updated || code)) |
---|
80 | do_line(nbp, code, updated); |
---|
81 | if (updated) |
---|
82 | print_header = 0; |
---|
83 | } |
---|
84 | } |
---|
85 | if (!interrupt) { |
---|
86 | dsc_update_mtg_set(user_id, set, n_matches, &code); |
---|
87 | if (cur_mtg_updated) |
---|
88 | dsc_public.nb.status |= DSC_ST_CHANGED; |
---|
89 | } |
---|
90 | dsc_destroy_mtg_set(set, n_matches); |
---|
91 | return(0); |
---|
92 | } |
---|
93 | |
---|
94 | check_meetings (argc, argv) |
---|
95 | int argc; |
---|
96 | char **argv; |
---|
97 | { |
---|
98 | int have_names = 0; |
---|
99 | char errbuf[BUFSIZ]; |
---|
100 | int i, *used; |
---|
101 | |
---|
102 | used = (int *)calloc(argc, sizeof(int)); |
---|
103 | print_header = 1; |
---|
104 | display = 1; |
---|
105 | |
---|
106 | for (i = 1; i < argc; i++) { |
---|
107 | if (!strcmp(argv[i], "-quiet") || !strcmp(argv[i], "-q") || !strcmp(argv[i], "-no_list") || !strcmp(argv[i], "-nls")) { |
---|
108 | display=0; used[i]=1; |
---|
109 | } else if (!strcmp(argv[i], "-list") || !strcmp(argv[i], "-ls")) { |
---|
110 | display=1; used[i]=1; |
---|
111 | } else if (*argv[i] == '-') { |
---|
112 | sprintf(errbuf, "Unknown control argument %s\n", argv[i]); |
---|
113 | ss_perror(sci_idx, 0, errbuf); |
---|
114 | free((char *)used); |
---|
115 | return; |
---|
116 | } |
---|
117 | else { |
---|
118 | have_names = 1; |
---|
119 | } |
---|
120 | } |
---|
121 | |
---|
122 | flag_interrupts(); |
---|
123 | if (!have_names) { |
---|
124 | do_mtg("*"); |
---|
125 | } else for (i = 1; i < argc; i++) { |
---|
126 | if (!used[i]) |
---|
127 | do_mtg(argv[i]); |
---|
128 | if (interrupt) |
---|
129 | break; |
---|
130 | } |
---|
131 | checked_meetings = 1; |
---|
132 | |
---|
133 | if (print_header && !interrupt) |
---|
134 | ss_perror(sci_idx, 0, "No changed meetings"); |
---|
135 | |
---|
136 | free((char *)used); |
---|
137 | dont_flag_interrupts(); |
---|
138 | } |
---|
139 | |
---|
140 | next_meeting(argc, argv) |
---|
141 | int argc; |
---|
142 | char **argv; |
---|
143 | { |
---|
144 | name_blk *set; |
---|
145 | register name_blk *nbp; |
---|
146 | int n_matches, code, i; |
---|
147 | int ls_flag = 0; |
---|
148 | |
---|
149 | ++argv; |
---|
150 | --argc; |
---|
151 | |
---|
152 | while (argc) { |
---|
153 | if (**argv == '-') { |
---|
154 | if (!strcmp(*argv, "-list") || !strcmp(*argv, "-ls")) |
---|
155 | ls_flag++; |
---|
156 | else if(!strcmp(*argv,"-no_list")||!strcmp(*argv,"-nls")) |
---|
157 | ls_flag = 0; |
---|
158 | else { |
---|
159 | ss_perror(sci_idx, 0, |
---|
160 | "Unknown control argument."); |
---|
161 | usage: |
---|
162 | printf("Usage: nm [-list]\n"); |
---|
163 | return; |
---|
164 | } |
---|
165 | } |
---|
166 | else |
---|
167 | goto usage; |
---|
168 | --argc; |
---|
169 | ++argv; |
---|
170 | } |
---|
171 | |
---|
172 | dsc_expand_mtg_set(user_id, "*", &set, &n_matches, &code); |
---|
173 | |
---|
174 | if (code) { |
---|
175 | ss_perror(sci_idx, code, "Can't get meeting names."); |
---|
176 | return; |
---|
177 | } |
---|
178 | if (!n_matches) { |
---|
179 | ss_perror(sci_idx, 0, "No meetings found."); |
---|
180 | return; |
---|
181 | } |
---|
182 | print_header = 1; |
---|
183 | |
---|
184 | for (i = 0; i < n_matches; i++) { |
---|
185 | nbp = &set[i]; |
---|
186 | if (nbp->status & DSC_ST_CHANGED) { |
---|
187 | if (ls_flag) { |
---|
188 | do_line(nbp, 0, 1); |
---|
189 | } else { |
---|
190 | switch_to_mtg_nb(nbp); |
---|
191 | dsc_public.nb.status &= ~DSC_ST_CHANGED; |
---|
192 | dsc_update_mtg_set(user_id, &dsc_public.nb, 1, &code); |
---|
193 | if (code) |
---|
194 | ss_perror(sci_idx, code, |
---|
195 | "Error updating meetings file."); |
---|
196 | goto done; |
---|
197 | } |
---|
198 | } |
---|
199 | } |
---|
200 | if (!checked_meetings && print_header) { |
---|
201 | ss_perror(sci_idx, 0, |
---|
202 | "No meetings listed as changed; use check_meetings."); |
---|
203 | } else if (print_header) |
---|
204 | ss_perror(sci_idx, 0, "No more changed meetings."); |
---|
205 | done: |
---|
206 | dsc_destroy_mtg_set(set, n_matches); |
---|
207 | } |
---|