1: /*
   2:  * Copyright (c) 1980 Regents of the University of California.
   3:  * All rights reserved.  The Berkeley software License Agreement
   4:  * specifies the terms and conditions for redistribution.
   5:  */
   6: 
   7: #ifndef lint
   8: static char sccsid[] = "@(#)save.c	5.1 (Berkeley) 5/29/85";
   9: #endif not lint
  10: 
  11: #include "back.h"
  12: 
  13: extern int  errno;
  14: 
  15: static char confirm[] = "Are you sure you want to leave now?";
  16: static char prompt[] = "Enter a file name:  ";
  17: static char exist1[] = "The file '";
  18: static char exist2[] =
  19:     "' already exists.\nAre you sure you want to use this file?";
  20: static char cantuse[] = "\nCan't use ";
  21: static char saved[] = "This game has been saved on the file '";
  22: static char type[] = "'.\nType \"backgammon ";
  23: static char rec[] = "\" to recover your game.\n\n";
  24: static char cantrec[] = "Can't recover file:  ";
  25: 
  26: save (n)
  27: register int    n;
  28: 
  29: {
  30:     register int    fdesc;
  31:     register char   *fs;
  32:     char        fname[50];
  33: 
  34:     if (n)  {
  35:         if (tflag)  {
  36:             curmove (20,0);
  37:             clend();
  38:         } else
  39:             writec ('\n');
  40:         writel (confirm);
  41:         if (! yorn(0))
  42:             return;
  43:     }
  44:     cflag = 1;
  45:     for (;;)  {
  46:         writel (prompt);
  47:         fs = fname;
  48:         while ((*fs = readc()) != '\n')  {
  49:             if (*fs == tty.sg_erase)  {
  50:                 if (fs > fname)  {
  51:                     fs--;
  52:                     if (tflag)
  53:                         curmove (curr,curc-1);
  54:                     else
  55:                         writec (*fs);
  56:                 } else
  57:                     writec ('\007');
  58:                 continue;
  59:             }
  60:             writec (*fs++);
  61:         }
  62:         *fs = '\0';
  63:         if ((fdesc = open(fname,2)) == -1 && errno == 2)  {
  64:             if ((fdesc = creat (fname,0700)) != -1)
  65:             break;
  66:         }
  67:         if (fdesc != -1)  {
  68:             if (tflag)  {
  69:                 curmove (18,0);
  70:                 clend();
  71:             } else
  72:                 writec ('\n');
  73:             writel (exist1);
  74:             writel (fname);
  75:             writel (exist2);
  76:             cflag = 0;
  77:             close (fdesc);
  78:             if (yorn (0))  {
  79:                 unlink (fname);
  80:                 fdesc = creat (fname,0700);
  81:                 break;
  82:             } else  {
  83:                 cflag = 1;
  84:                 continue;
  85:             }
  86:         }
  87:         writel (cantuse);
  88:         writel (fname);
  89:         writel (".\n");
  90:         close (fdesc);
  91:         cflag = 1;
  92:     }
  93:     write (fdesc,board,sizeof board);
  94:     write (fdesc,off,sizeof off);
  95:     write (fdesc,in,sizeof in);
  96:     write (fdesc,dice,sizeof dice);
  97:     write (fdesc,&cturn,sizeof cturn);
  98:     write (fdesc,&dlast,sizeof dlast);
  99:     write (fdesc,&pnum,sizeof pnum);
 100:     write (fdesc,&rscore,sizeof rscore);
 101:     write (fdesc,&wscore,sizeof wscore);
 102:     write (fdesc,&gvalue,sizeof gvalue);
 103:     write (fdesc,&raflag,sizeof raflag);
 104:     close (fdesc);
 105:     if (tflag)
 106:         curmove (18,0);
 107:     writel (saved);
 108:     writel (fname);
 109:     writel (type);
 110:     writel (fname);
 111:     writel (rec);
 112:     if (tflag)
 113:         clend();
 114:     getout ();
 115: }
 116: 
 117: recover (s)
 118: char    *s;
 119: 
 120: {
 121:     register int    i;
 122:     int     fdesc;
 123: 
 124:     if ((fdesc = open (s,0)) == -1)
 125:         norec (s);
 126:     read (fdesc,board,sizeof board);
 127:     read (fdesc,off,sizeof off);
 128:     read (fdesc,in,sizeof in);
 129:     read (fdesc,dice,sizeof dice);
 130:     read (fdesc,&cturn,sizeof cturn);
 131:     read (fdesc,&dlast,sizeof dlast);
 132:     read (fdesc,&pnum,sizeof pnum);
 133:     read (fdesc,&rscore,sizeof rscore);
 134:     read (fdesc,&wscore,sizeof wscore);
 135:     read (fdesc,&gvalue,sizeof gvalue);
 136:     read (fdesc,&raflag,sizeof raflag);
 137:     close (fdesc);
 138:     rflag = 1;
 139: }
 140: 
 141: norec (s)
 142: register char   *s;
 143: 
 144: {
 145:     register char   *c;
 146: 
 147:     tflag = 0;
 148:     writel (cantrec);
 149:     c = s;
 150:     while (*c != '\0')
 151:         writec (*c++);
 152:     getout ();
 153: }

Defined functions

norec defined in line 141; used 1 times
recover defined in line 117; used 2 times

Defined variables

cantrec defined in line 24; used 1 times
cantuse defined in line 20; used 1 times
  • in line 87
confirm defined in line 15; used 1 times
  • in line 40
exist1 defined in line 17; used 1 times
  • in line 73
exist2 defined in line 18; used 1 times
  • in line 75
prompt defined in line 16; used 1 times
  • in line 46
rec defined in line 23; used 1 times
saved defined in line 21; used 1 times
sccsid defined in line 8; never used
type defined in line 22; used 1 times
Last modified: 1985-05-29
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1277
Valid CSS Valid XHTML 1.0 Strict