*** recover.c Sat Feb 24 19:01:55 1990 --- byteswap.c Fri May 10 18:39:06 1991 *************** *** 1,12 **** /* * - * Copyright (C) 1988, 1989 by the Massachusetts Institute of Technology - * Developed by the MIT Student Information Processing Board (SIPB). - * For copying information, see the file mit-copyright.h in this release. - * - */ - /* - * * recover -- program to recover a meeting from the transaction file. * this program is linked to a server so it can use the * privileged procedures of create_mtg, and the like. --- 1,5 ---- *************** *** 25,30 **** --- 18,41 ---- #include #include "mtg.h" + #if defined(__STDC__) + #define PROTOTYPE(x) x + #ifdef NARROW_PROTOTYPES + #define DECLARG(type, val) type val + #define OLDDECLARG(type, val) + #else + #define DECLARG(type, val) val + #define OLDDECLARG(type, val) type val; + #endif /* Narrow prototypes */ + #else + #define PROTOTYPE(x) () + #define DECLARG(type, val) val + #define OLDDECLARG(type, val) type val; + #endif /* STDC or PROTOTYPES */ + + extern int add_trn_priv PROTOTYPE((char *, tfile, char *, char *, trn_nums, + trn_nums, char *, date_times, int, + trn_nums *, int *)); #define NULL 0 #define MAX_TRNS 20000 #define min(a, b) (a < b ? a : b) *************** *** 43,53 **** tfile unix_tfile (); char *malloc(); ! static fsize(),read_trn_hdr(),read_last_trn(),save_trn(); extern char rpc_caller[]; extern int has_privs, use_zephyr; main (argc, argv) int argc; char **argv; --- 54,105 ---- tfile unix_tfile (); char *malloc(); ! static read_trn_hdr(), read_last_trn(), save_trn(), fsize(); extern char rpc_caller[]; extern int has_privs, use_zephyr; + #ifndef __GNUC__ + #define inline + #endif + + static inline short Sshort (DECLARG(short, P_s)) + OLDDECLARG(short, P_s) + { + union { + short s; + char c[2]; + } x1, x2; + x1.s = P_s; + x2.c[0] = x1.c[1]; + x2.c[1] = x1.c[0]; + return x2.s; + } + + static inline long Slong (DECLARG(long, P_l)) + OLDDECLARG(long, P_l) + { + union { + long l; + char c[4]; + } x1, x2; + x1.l = P_l; + x2.c[0] = x1.c[3]; + x2.c[1] = x1.c[2]; + x2.c[2] = x1.c[1]; + x2.c[3] = x1.c[0]; + return x2.l; + } + + #define S(X) \ + (sizeof(X)==4 \ + ? (X = Slong(X)) \ + : (sizeof(X)==2 \ + ? (X = Sshort(X)) \ + : (sizeof(X)==1 \ + ? 0 \ + : abort()))) + main (argc, argv) int argc; char **argv; *************** *** 154,159 **** --- 206,220 ---- exit(1); } + S(tb.version); + S(tb.unique); + S(tb.date_created); + S(tb.long_name_addr); + S(tb.chairman_addr); + S(tb.long_name_len); + S(tb.chairman_len); + S(tb.public_flag); + if (tb.version != TRN_BASE_1) { fprintf (stderr, "Invalid trn_base version\n"); exit(1); *************** *** 167,173 **** /* read the chairman */ if (chairman == NULL) { if (tb.chairman_len > 255) { ! fprintf (stderr, "Unreasonable chairman length\n"); exit(1); } chairman = malloc (tb.chairman_len); --- 228,235 ---- /* read the chairman */ if (chairman == NULL) { if (tb.chairman_len > 255) { ! fprintf (stderr, "Unreasonable chairman length: %d\n", ! tb.chairman_len); exit(1); } chairman = malloc (tb.chairman_len); *************** *** 232,237 **** --- 294,313 ---- if (read (trnf, &th, sizeof (th)) != sizeof (th)) goto no_read; + S(th.version); + S(th.unique); + S(th.current); + S(th.orig_pref); + S(th.date_entered); + S(th.num_lines); + S(th.num_chars); + S(th.prev_trn); + S(th.subject_addr); + S(th.author_addr); + S(th.text_addr); + S(th.subject_len); + S(th.author_len); + /* safety checks */ if (th.version != TRN_HDR_1) { fprintf (stderr, "Invalid trn_hdr version at %d\n", position); *************** *** 272,277 **** --- 348,367 ---- if (read (trnf, &th, sizeof (th)) != sizeof (th)) return (FALSE); + S(th.version); + S(th.unique); + S(th.current); + S(th.orig_pref); + S(th.date_entered); + S(th.num_lines); + S(th.num_chars); + S(th.prev_trn); + S(th.subject_addr); + S(th.author_addr); + S(th.text_addr); + S(th.subject_len); + S(th.author_len); + /* safety checks */ if (th.version != TRN_HDR_1) { return (FALSE); *************** *** 314,320 **** save_trn (position) int position; { ! char *th_subject, *th_author, *th_signature; tfile tf; int tfs,tocopy; trn_nums result_trn; --- 404,410 ---- save_trn (position) int position; { ! char *th_subject, *th_author; tfile tf; int tfs,tocopy; trn_nums result_trn; *************** *** 331,341 **** lseek (trnf, th.author_addr, 0); read (trnf, th_author, th.author_len); - th_signature = NULL; - if (strlen (th_author) + 1 != th.author_len) { - th_signature = th_author + strlen(th_author) + 1; - } - /* start temp file */ ftruncate(tempf,0); lseek(tempf,0,0); --- 421,426 ---- *************** *** 353,359 **** tf = unix_tfile (tempf); ! add_trn_priv (location, tf, th_subject, th_signature, th.orig_pref, th.current, th_author, th.date_entered, 0, &result_trn, &result); if (result != 0) { fprintf (stderr, "Couldn't add transaction %d; %s", th.current, error_message(result)); exit(1); --- 438,444 ---- tf = unix_tfile (tempf); ! add_trn_priv (location, tf, th_subject, NULL, th.orig_pref, th.current, th_author, th.date_entered, 0, &result_trn, &result); if (result != 0) { fprintf (stderr, "Couldn't add transaction %d; %s", th.current, error_message(result)); exit(1); *************** *** 365,370 **** --- 450,457 ---- printf ("Added transaction %d\n", th.current); return; } + + /* *