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: #if !defined(lint) && !defined(pdp11)
   8: static char sccsid[] = "@(#)save.c	1.4.1 1996/10/26";
   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:     fclose(fp);
  66: }
  67: 
  68: save()
  69: {
  70:     char *getenv();
  71:     char *home;
  72:     char home1[100];
  73:     register int n;
  74:     int tmp;
  75:     FILE *fp;
  76: 
  77:     home = getenv("HOME");
  78:     strcpy(home1, home);
  79:     strcat(home1, "/Bstar");
  80:     if ((fp = fopen(home1, "w")) == 0) {
  81:         perror(home1);
  82:         return;
  83:     }
  84:     printf("Saved in %s.\n", home1);
  85:     fwrite(&WEIGHT, sizeof WEIGHT, 1, fp);
  86:     fwrite(&CUMBER, sizeof CUMBER, 1, fp);
  87:     fwrite(&clock, sizeof clock, 1, fp);
  88:     tmp = location == dayfile;
  89:     fwrite(&tmp, sizeof tmp, 1, fp);
  90:     for (n = 1; n <= NUMOFROOMS; n++) {
  91:         fwrite(location[n].link, sizeof location[n].link, 1, fp);
  92:         fwrite(location[n].objects, sizeof location[n].objects, 1, fp);
  93:     }
  94:     fwrite(inven, sizeof inven, 1, fp);
  95:     fwrite(wear, sizeof wear, 1, fp);
  96:     fwrite(injuries, sizeof injuries, 1, fp);
  97:     fwrite(notes, sizeof notes, 1, fp);
  98:     fwrite(&direction, sizeof direction, 1, fp);
  99:     fwrite(&position, sizeof position, 1, fp);
 100:     fwrite(&Time, sizeof Time, 1, fp);
 101:     fwrite(&fuel, sizeof fuel, 1, fp);
 102:     fwrite(&torps, sizeof torps, 1, fp);
 103:     fwrite(&carrying, sizeof carrying, 1, fp);
 104:     fwrite(&encumber, sizeof encumber, 1, fp);
 105:     fwrite(&rythmn, sizeof rythmn, 1, fp);
 106:     fwrite(&followfight, sizeof followfight, 1, fp);
 107:     fwrite(&ate, sizeof ate, 1, fp);
 108:     fwrite(&snooze, sizeof snooze, 1, fp);
 109:     fwrite(&meetgirl, sizeof meetgirl, 1, fp);
 110:     fwrite(&followgod, sizeof followgod, 1, fp);
 111:     fwrite(&godready, sizeof godready, 1, fp);
 112:     fwrite(&win, sizeof win, 1, fp);
 113:     fwrite(&wintime, sizeof wintime, 1, fp);
 114:     fwrite(&matchlight, sizeof matchlight, 1, fp);
 115:     fwrite(&matchcount, sizeof matchcount, 1, fp);
 116:     fwrite(&loved, sizeof loved, 1, fp);
 117:     fwrite(&pleasure, sizeof pleasure, 1, fp);
 118:     fwrite(&power, sizeof power, 1, fp);
 119:     fwrite(&ego, sizeof ego, 1, fp);
 120: 
 121:     fclose(fp);
 122: }

Defined functions

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

Defined variables

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