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