1 | /* |
---|
2 | * |
---|
3 | * Copyright (C) 1988, 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 | * |
---|
10 | * pmtg.c -- Program to print out a entire meeting. |
---|
11 | * |
---|
12 | */ |
---|
13 | |
---|
14 | #include <discuss/discuss.h> |
---|
15 | #include <sys/types.h> |
---|
16 | #include <sys/file.h> |
---|
17 | #include <stdio.h> |
---|
18 | #include <string.h> |
---|
19 | |
---|
20 | tfile unix_tfile(); |
---|
21 | mtg_info minfo; |
---|
22 | |
---|
23 | #ifndef lint |
---|
24 | static char rcsid_pmtg_c[] = |
---|
25 | "$Id: pmtg.c,v 1.7 1999-02-02 20:40:33 kcr Exp $"; |
---|
26 | #endif |
---|
27 | |
---|
28 | int main (argc,argv) |
---|
29 | int argc; |
---|
30 | char **argv; |
---|
31 | { |
---|
32 | int result; |
---|
33 | trn_nums trn; |
---|
34 | trn_info tinfo; |
---|
35 | tfile tfstdout; |
---|
36 | char machine [50],mtg_name[100]; |
---|
37 | |
---|
38 | #if defined(__APPLE__) && defined(__MACH__) |
---|
39 | add_error_table(&et_dsc_error_table); |
---|
40 | #else |
---|
41 | initialize_dsc_error_table(); |
---|
42 | #endif |
---|
43 | argc--; argv++; |
---|
44 | if (argc != 1) |
---|
45 | goto lusage; |
---|
46 | |
---|
47 | resolve_mtg(*argv, machine, mtg_name); |
---|
48 | |
---|
49 | init_rpc(); |
---|
50 | if (open_rpc (machine, "discuss", &result) == 0) { |
---|
51 | (void) fprintf (stderr, "%s\n", error_message(result)); |
---|
52 | exit(1); |
---|
53 | } |
---|
54 | if (result) { |
---|
55 | (void) fprintf (stderr, "Warning: %s\n", error_message(result)); |
---|
56 | } |
---|
57 | |
---|
58 | get_mtg_info (mtg_name, &minfo, &result); |
---|
59 | if (result != 0) { |
---|
60 | (void) fprintf (stderr, "%s\n", error_message (result)); |
---|
61 | exit(1); |
---|
62 | } |
---|
63 | |
---|
64 | /* set up stdout tfile */ |
---|
65 | tfstdout = unix_tfile (1); |
---|
66 | |
---|
67 | trn = minfo.first; |
---|
68 | while (trn != 0) { |
---|
69 | get_trn_info (mtg_name, trn, &tinfo, &result); |
---|
70 | if (result != 0) { |
---|
71 | if (result != DELETED_TRN) { |
---|
72 | (void) fprintf (stderr, "%s\n", |
---|
73 | error_message (result)); |
---|
74 | exit (1); |
---|
75 | } |
---|
76 | } else { |
---|
77 | write_header (&tinfo, tfstdout); |
---|
78 | get_trn (mtg_name, trn, tfstdout, &result); |
---|
79 | if (result != 0) { |
---|
80 | (void) fprintf (stderr, "%s\n", |
---|
81 | error_message(result)); |
---|
82 | exit (1); |
---|
83 | } |
---|
84 | write_trailer (&tinfo, tfstdout); |
---|
85 | } |
---|
86 | trn = tinfo.next; |
---|
87 | free (tinfo.author); |
---|
88 | free (tinfo.subject); |
---|
89 | } |
---|
90 | |
---|
91 | tdestroy (tfstdout); |
---|
92 | term_rpc (); |
---|
93 | return 0; |
---|
94 | |
---|
95 | lusage: |
---|
96 | (void) fprintf (stderr, "Usage: pmtg {mtg_name}\n"); |
---|
97 | exit (1); |
---|
98 | } |
---|
99 | |
---|
100 | char *ctime(); |
---|
101 | |
---|
102 | write_header(info, tf) |
---|
103 | trn_info *info; |
---|
104 | tfile tf; |
---|
105 | { |
---|
106 | char line [255]; |
---|
107 | char newtime [26]; |
---|
108 | char *plural; |
---|
109 | int dummy; |
---|
110 | |
---|
111 | (void) strcpy (newtime, ctime ((time_t *)&(info -> date_entered))); |
---|
112 | newtime [24] = '\0'; /* get rid of \n */ |
---|
113 | |
---|
114 | if (info -> num_lines != 1) |
---|
115 | plural = "s"; |
---|
116 | else |
---|
117 | plural = ""; |
---|
118 | |
---|
119 | (void) sprintf (line, "[%04d] %s %s %s (%d line%s)\n", |
---|
120 | info -> current, info -> author, minfo.long_name, |
---|
121 | &newtime[4], info -> num_lines, plural); |
---|
122 | twrite (tf, line, strlen (line),&dummy); |
---|
123 | if (info -> subject [0] != '\0') { |
---|
124 | twrite (tf, "Subject: ", 9, &dummy); |
---|
125 | twrite (tf, info -> subject, strlen (info -> subject), &dummy); |
---|
126 | twrite (tf, "\n", 1, &dummy); |
---|
127 | } |
---|
128 | return; |
---|
129 | } |
---|
130 | |
---|
131 | write_trailer (info, tf) |
---|
132 | trn_info *info; |
---|
133 | tfile tf; |
---|
134 | { |
---|
135 | char line [255]; |
---|
136 | int dummy; |
---|
137 | |
---|
138 | if (info -> pref == 0 && info -> nref == 0) |
---|
139 | sprintf (line, "--[%04d]--\n\n", info -> current); |
---|
140 | else if (info -> pref == 0) |
---|
141 | sprintf (line, "--[%04d]-- (nref = [%04d])\n\n", info -> current, |
---|
142 | info -> nref); |
---|
143 | else if (info -> nref == 0) |
---|
144 | sprintf (line, "--[%04d]-- (pref = [%04d])\n\n", info -> current, |
---|
145 | info -> pref); |
---|
146 | else |
---|
147 | sprintf (line, "--[%04d]-- (pref = [%04d], nref = [%04d])\n\n", |
---|
148 | info -> current, info -> pref, info -> nref); |
---|
149 | twrite (tf, line, strlen (line),&dummy); |
---|
150 | } |
---|
151 | /* |
---|
152 | * |
---|
153 | * resolve_mtg: Procedure to resolve a user meeting name into its host |
---|
154 | * an pathname. |
---|
155 | * |
---|
156 | */ |
---|
157 | resolve_mtg (usr_string, machine, mtg_name) |
---|
158 | char *usr_string,*machine,*mtg_name; |
---|
159 | { |
---|
160 | char *colon; |
---|
161 | int machine_len; |
---|
162 | |
---|
163 | colon = strchr (usr_string, ':'); |
---|
164 | |
---|
165 | if (colon == 0) { |
---|
166 | strcpy (mtg_name, usr_string); |
---|
167 | gethostname (machine, 50); |
---|
168 | return; |
---|
169 | } |
---|
170 | |
---|
171 | machine_len = colon - usr_string; |
---|
172 | memcpy (machine, usr_string, machine_len); |
---|
173 | machine [machine_len] = '\0'; |
---|
174 | strcpy (mtg_name, colon+1); |
---|
175 | return; |
---|
176 | } |
---|