1 | *** recover.c Sat Feb 24 19:01:55 1990 |
---|
2 | --- byteswap.c Fri May 10 18:39:06 1991 |
---|
3 | *************** |
---|
4 | *** 1,12 **** |
---|
5 | /* |
---|
6 | * |
---|
7 | - * Copyright (C) 1988, 1989 by the Massachusetts Institute of Technology |
---|
8 | - * Developed by the MIT Student Information Processing Board (SIPB). |
---|
9 | - * For copying information, see the file mit-copyright.h in this release. |
---|
10 | - * |
---|
11 | - */ |
---|
12 | - /* |
---|
13 | - * |
---|
14 | * recover -- program to recover a meeting from the transaction file. |
---|
15 | * this program is linked to a server so it can use the |
---|
16 | * privileged procedures of create_mtg, and the like. |
---|
17 | --- 1,5 ---- |
---|
18 | *************** |
---|
19 | *** 25,30 **** |
---|
20 | --- 18,41 ---- |
---|
21 | #include <discuss/interface.h> |
---|
22 | #include "mtg.h" |
---|
23 | |
---|
24 | + #if defined(__STDC__) |
---|
25 | + #define PROTOTYPE(x) x |
---|
26 | + #ifdef NARROW_PROTOTYPES |
---|
27 | + #define DECLARG(type, val) type val |
---|
28 | + #define OLDDECLARG(type, val) |
---|
29 | + #else |
---|
30 | + #define DECLARG(type, val) val |
---|
31 | + #define OLDDECLARG(type, val) type val; |
---|
32 | + #endif /* Narrow prototypes */ |
---|
33 | + #else |
---|
34 | + #define PROTOTYPE(x) () |
---|
35 | + #define DECLARG(type, val) val |
---|
36 | + #define OLDDECLARG(type, val) type val; |
---|
37 | + #endif /* STDC or PROTOTYPES */ |
---|
38 | + |
---|
39 | + extern int add_trn_priv PROTOTYPE((char *, tfile, char *, char *, trn_nums, |
---|
40 | + trn_nums, char *, date_times, int, |
---|
41 | + trn_nums *, int *)); |
---|
42 | #define NULL 0 |
---|
43 | #define MAX_TRNS 20000 |
---|
44 | #define min(a, b) (a < b ? a : b) |
---|
45 | *************** |
---|
46 | *** 43,53 **** |
---|
47 | |
---|
48 | tfile unix_tfile (); |
---|
49 | char *malloc(); |
---|
50 | ! static fsize(),read_trn_hdr(),read_last_trn(),save_trn(); |
---|
51 | |
---|
52 | extern char rpc_caller[]; |
---|
53 | extern int has_privs, use_zephyr; |
---|
54 | |
---|
55 | main (argc, argv) |
---|
56 | int argc; |
---|
57 | char **argv; |
---|
58 | --- 54,105 ---- |
---|
59 | |
---|
60 | tfile unix_tfile (); |
---|
61 | char *malloc(); |
---|
62 | ! static read_trn_hdr(), read_last_trn(), save_trn(), fsize(); |
---|
63 | |
---|
64 | extern char rpc_caller[]; |
---|
65 | extern int has_privs, use_zephyr; |
---|
66 | |
---|
67 | + #ifndef __GNUC__ |
---|
68 | + #define inline |
---|
69 | + #endif |
---|
70 | + |
---|
71 | + static inline short Sshort (DECLARG(short, P_s)) |
---|
72 | + OLDDECLARG(short, P_s) |
---|
73 | + { |
---|
74 | + union { |
---|
75 | + short s; |
---|
76 | + char c[2]; |
---|
77 | + } x1, x2; |
---|
78 | + x1.s = P_s; |
---|
79 | + x2.c[0] = x1.c[1]; |
---|
80 | + x2.c[1] = x1.c[0]; |
---|
81 | + return x2.s; |
---|
82 | + } |
---|
83 | + |
---|
84 | + static inline long Slong (DECLARG(long, P_l)) |
---|
85 | + OLDDECLARG(long, P_l) |
---|
86 | + { |
---|
87 | + union { |
---|
88 | + long l; |
---|
89 | + char c[4]; |
---|
90 | + } x1, x2; |
---|
91 | + x1.l = P_l; |
---|
92 | + x2.c[0] = x1.c[3]; |
---|
93 | + x2.c[1] = x1.c[2]; |
---|
94 | + x2.c[2] = x1.c[1]; |
---|
95 | + x2.c[3] = x1.c[0]; |
---|
96 | + return x2.l; |
---|
97 | + } |
---|
98 | + |
---|
99 | + #define S(X) \ |
---|
100 | + (sizeof(X)==4 \ |
---|
101 | + ? (X = Slong(X)) \ |
---|
102 | + : (sizeof(X)==2 \ |
---|
103 | + ? (X = Sshort(X)) \ |
---|
104 | + : (sizeof(X)==1 \ |
---|
105 | + ? 0 \ |
---|
106 | + : abort()))) |
---|
107 | + |
---|
108 | main (argc, argv) |
---|
109 | int argc; |
---|
110 | char **argv; |
---|
111 | *************** |
---|
112 | *** 154,159 **** |
---|
113 | --- 206,220 ---- |
---|
114 | exit(1); |
---|
115 | } |
---|
116 | |
---|
117 | + S(tb.version); |
---|
118 | + S(tb.unique); |
---|
119 | + S(tb.date_created); |
---|
120 | + S(tb.long_name_addr); |
---|
121 | + S(tb.chairman_addr); |
---|
122 | + S(tb.long_name_len); |
---|
123 | + S(tb.chairman_len); |
---|
124 | + S(tb.public_flag); |
---|
125 | + |
---|
126 | if (tb.version != TRN_BASE_1) { |
---|
127 | fprintf (stderr, "Invalid trn_base version\n"); |
---|
128 | exit(1); |
---|
129 | *************** |
---|
130 | *** 167,173 **** |
---|
131 | /* read the chairman */ |
---|
132 | if (chairman == NULL) { |
---|
133 | if (tb.chairman_len > 255) { |
---|
134 | ! fprintf (stderr, "Unreasonable chairman length\n"); |
---|
135 | exit(1); |
---|
136 | } |
---|
137 | chairman = malloc (tb.chairman_len); |
---|
138 | --- 228,235 ---- |
---|
139 | /* read the chairman */ |
---|
140 | if (chairman == NULL) { |
---|
141 | if (tb.chairman_len > 255) { |
---|
142 | ! fprintf (stderr, "Unreasonable chairman length: %d\n", |
---|
143 | ! tb.chairman_len); |
---|
144 | exit(1); |
---|
145 | } |
---|
146 | chairman = malloc (tb.chairman_len); |
---|
147 | *************** |
---|
148 | *** 232,237 **** |
---|
149 | --- 294,313 ---- |
---|
150 | if (read (trnf, &th, sizeof (th)) != sizeof (th)) |
---|
151 | goto no_read; |
---|
152 | |
---|
153 | + S(th.version); |
---|
154 | + S(th.unique); |
---|
155 | + S(th.current); |
---|
156 | + S(th.orig_pref); |
---|
157 | + S(th.date_entered); |
---|
158 | + S(th.num_lines); |
---|
159 | + S(th.num_chars); |
---|
160 | + S(th.prev_trn); |
---|
161 | + S(th.subject_addr); |
---|
162 | + S(th.author_addr); |
---|
163 | + S(th.text_addr); |
---|
164 | + S(th.subject_len); |
---|
165 | + S(th.author_len); |
---|
166 | + |
---|
167 | /* safety checks */ |
---|
168 | if (th.version != TRN_HDR_1) { |
---|
169 | fprintf (stderr, "Invalid trn_hdr version at %d\n", position); |
---|
170 | *************** |
---|
171 | *** 272,277 **** |
---|
172 | --- 348,367 ---- |
---|
173 | if (read (trnf, &th, sizeof (th)) != sizeof (th)) |
---|
174 | return (FALSE); |
---|
175 | |
---|
176 | + S(th.version); |
---|
177 | + S(th.unique); |
---|
178 | + S(th.current); |
---|
179 | + S(th.orig_pref); |
---|
180 | + S(th.date_entered); |
---|
181 | + S(th.num_lines); |
---|
182 | + S(th.num_chars); |
---|
183 | + S(th.prev_trn); |
---|
184 | + S(th.subject_addr); |
---|
185 | + S(th.author_addr); |
---|
186 | + S(th.text_addr); |
---|
187 | + S(th.subject_len); |
---|
188 | + S(th.author_len); |
---|
189 | + |
---|
190 | /* safety checks */ |
---|
191 | if (th.version != TRN_HDR_1) { |
---|
192 | return (FALSE); |
---|
193 | *************** |
---|
194 | *** 314,320 **** |
---|
195 | save_trn (position) |
---|
196 | int position; |
---|
197 | { |
---|
198 | ! char *th_subject, *th_author, *th_signature; |
---|
199 | tfile tf; |
---|
200 | int tfs,tocopy; |
---|
201 | trn_nums result_trn; |
---|
202 | --- 404,410 ---- |
---|
203 | save_trn (position) |
---|
204 | int position; |
---|
205 | { |
---|
206 | ! char *th_subject, *th_author; |
---|
207 | tfile tf; |
---|
208 | int tfs,tocopy; |
---|
209 | trn_nums result_trn; |
---|
210 | *************** |
---|
211 | *** 331,341 **** |
---|
212 | lseek (trnf, th.author_addr, 0); |
---|
213 | read (trnf, th_author, th.author_len); |
---|
214 | |
---|
215 | - th_signature = NULL; |
---|
216 | - if (strlen (th_author) + 1 != th.author_len) { |
---|
217 | - th_signature = th_author + strlen(th_author) + 1; |
---|
218 | - } |
---|
219 | - |
---|
220 | /* start temp file */ |
---|
221 | ftruncate(tempf,0); |
---|
222 | lseek(tempf,0,0); |
---|
223 | --- 421,426 ---- |
---|
224 | *************** |
---|
225 | *** 353,359 **** |
---|
226 | |
---|
227 | tf = unix_tfile (tempf); |
---|
228 | |
---|
229 | ! add_trn_priv (location, tf, th_subject, th_signature, th.orig_pref, th.current, th_author, th.date_entered, 0, &result_trn, &result); |
---|
230 | if (result != 0) { |
---|
231 | fprintf (stderr, "Couldn't add transaction %d; %s", th.current, error_message(result)); |
---|
232 | exit(1); |
---|
233 | --- 438,444 ---- |
---|
234 | |
---|
235 | tf = unix_tfile (tempf); |
---|
236 | |
---|
237 | ! add_trn_priv (location, tf, th_subject, NULL, th.orig_pref, th.current, th_author, th.date_entered, 0, &result_trn, &result); |
---|
238 | if (result != 0) { |
---|
239 | fprintf (stderr, "Couldn't add transaction %d; %s", th.current, error_message(result)); |
---|
240 | exit(1); |
---|
241 | *************** |
---|
242 | *** 365,370 **** |
---|
243 | --- 450,457 ---- |
---|
244 | printf ("Added transaction %d\n", th.current); |
---|
245 | return; |
---|
246 | } |
---|
247 | + |
---|
248 | + |
---|
249 | |
---|
250 | /* |
---|
251 | * |
---|