1: /*
   2:  * Copyright (c) 1983 Regents of the University of California,
   3:  * All rights reserved.  Redistribution permitted subject to
   4:  * the terms of the Berkeley Software License Agreement.
   5:  */
   6: 
   7: #ifndef lint
   8: static char sccsid[] = "@(#)save.c	1.4 11/7/85";
   9: #endif
  10: 
  11: #include "externs.h"
  12: 
  13: restore()
  14: {
  15:     char *getenv();
  16:     char *home;
  17:     char home1[100];
  18:     register int n;
  19:     int tmp;
  20:     register FILE *fp;
  21: 
  22:     home = getenv("HOME");
  23:     strcpy(home1, home);
  24:     strcat(home1, "/Bstar");
  25:     if ((fp = fopen(home1, "r")) == 0) {
  26:         perror(home1);
  27:         return;
  28:     }
  29:     fread(&WEIGHT, sizeof WEIGHT, 1, fp);
  30:     fread(&CUMBER, sizeof CUMBER, 1, fp);
  31:     fread(&clock, sizeof clock, 1, fp);
  32:     fread(&tmp, sizeof tmp, 1, fp);
  33:     location = tmp ? dayfile : nightfile;
  34:     for (n = 1; n <= NUMOFROOMS; n++) {
  35:         fread(location[n].link, sizeof location[n].link, 1, fp);
  36:         fread(location[n].objects, sizeof location[n].objects, 1, fp);
  37:     }
  38:     fread(inven, sizeof inven, 1, fp);
  39:     fread(wear, sizeof wear, 1, fp);
  40:     fread(injuries, sizeof injuries, 1, fp);
  41:     fread(notes, sizeof notes, 1, fp);
  42:     fread(&direction, sizeof direction, 1, fp);
  43:     fread(&position, sizeof position, 1, fp);
  44:     fread(&time, sizeof time, 1, fp);
  45:     fread(&fuel, sizeof fuel, 1, fp);
  46:     fread(&torps, sizeof torps, 1, fp);
  47:     fread(&carrying, sizeof carrying, 1, fp);
  48:     fread(&encumber, sizeof encumber, 1, fp);
  49:     fread(&rythmn, sizeof rythmn, 1, fp);
  50:     fread(&followfight, sizeof followfight, 1, fp);
  51:     fread(&ate, sizeof ate, 1, fp);
  52:     fread(&snooze, sizeof snooze, 1, fp);
  53:     fread(&meetgirl, sizeof meetgirl, 1, fp);
  54:     fread(&followgod, sizeof followgod, 1, fp);
  55:     fread(&godready, sizeof godready, 1, fp);
  56:     fread(&win, sizeof win, 1, fp);
  57:     fread(&wintime, sizeof wintime, 1, fp);
  58:     fread(&matchlight, sizeof matchlight, 1, fp);
  59:     fread(&matchcount, sizeof matchcount, 1, fp);
  60:     fread(&loved, sizeof loved, 1, fp);
  61:     fread(&pleasure, sizeof pleasure, 1, fp);
  62:     fread(&power, sizeof power, 1, fp);
  63:     fread(&ego, sizeof ego, 1, fp);
  64: }
  65: 
  66: save()
  67: {
  68:     char *getenv();
  69:     char *home;
  70:     char home1[100];
  71:     register int n;
  72:     int tmp;
  73:     FILE *fp;
  74: 
  75:     home = getenv("HOME");
  76:     strcpy(home1, home);
  77:     strcat(home1, "/Bstar");
  78:     if ((fp = fopen(home1, "w")) == 0) {
  79:         perror(home1);
  80:         return;
  81:     }
  82:     printf("Saved in %s.\n", home1);
  83:     fwrite(&WEIGHT, sizeof WEIGHT, 1, fp);
  84:     fwrite(&CUMBER, sizeof CUMBER, 1, fp);
  85:     fwrite(&clock, sizeof clock, 1, fp);
  86:     tmp = location == dayfile;
  87:     fwrite(&tmp, sizeof tmp, 1, fp);
  88:     for (n = 1; n <= NUMOFROOMS; n++) {
  89:         fwrite(location[n].link, sizeof location[n].link, 1, fp);
  90:         fwrite(location[n].objects, sizeof location[n].objects, 1, fp);
  91:     }
  92:     fwrite(inven, sizeof inven, 1, fp);
  93:     fwrite(wear, sizeof wear, 1, fp);
  94:     fwrite(injuries, sizeof injuries, 1, fp);
  95:     fwrite(notes, sizeof notes, 1, fp);
  96:     fwrite(&direction, sizeof direction, 1, fp);
  97:     fwrite(&position, sizeof position, 1, fp);
  98:     fwrite(&time, sizeof time, 1, fp);
  99:     fwrite(&fuel, sizeof fuel, 1, fp);
 100:     fwrite(&torps, sizeof torps, 1, fp);
 101:     fwrite(&carrying, sizeof carrying, 1, fp);
 102:     fwrite(&encumber, sizeof encumber, 1, fp);
 103:     fwrite(&rythmn, sizeof rythmn, 1, fp);
 104:     fwrite(&followfight, sizeof followfight, 1, fp);
 105:     fwrite(&ate, sizeof ate, 1, fp);
 106:     fwrite(&snooze, sizeof snooze, 1, fp);
 107:     fwrite(&meetgirl, sizeof meetgirl, 1, fp);
 108:     fwrite(&followgod, sizeof followgod, 1, fp);
 109:     fwrite(&godready, sizeof godready, 1, fp);
 110:     fwrite(&win, sizeof win, 1, fp);
 111:     fwrite(&wintime, sizeof wintime, 1, fp);
 112:     fwrite(&matchlight, sizeof matchlight, 1, fp);
 113:     fwrite(&matchcount, sizeof matchcount, 1, fp);
 114:     fwrite(&loved, sizeof loved, 1, fp);
 115:     fwrite(&pleasure, sizeof pleasure, 1, fp);
 116:     fwrite(&power, sizeof power, 1, fp);
 117:     fwrite(&ego, sizeof ego, 1, fp);
 118: }

Defined functions

restore defined in line 13; used 1 times
save defined in line 66; used 1 times

Defined variables

sccsid defined in line 8; never used
Last modified: 1985-11-11
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1206
Valid CSS Valid XHTML 1.0 Strict