|
|
1.1 ! root 1: /* ! 2: * Copyright (c) 1980 Regents of the University of California. ! 3: * All rights reserved. ! 4: * ! 5: * Redistribution and use in source and binary forms are permitted ! 6: * provided that: (1) source distributions retain this entire copyright ! 7: * notice and comment, and (2) distributions including binaries display ! 8: * the following acknowledgement: ``This product includes software ! 9: * developed by the University of California, Berkeley and its contributors'' ! 10: * in the documentation or other materials provided with the distribution ! 11: * and in all advertising materials mentioning features or use of this ! 12: * software. Neither the name of the University nor the names of its ! 13: * contributors may be used to endorse or promote products derived ! 14: * from this software without specific prior written permission. ! 15: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR ! 16: * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED ! 17: * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ! 18: */ ! 19: ! 20: #ifndef lint ! 21: static char sccsid[] = "@(#)save.c 5.4 (Berkeley) 6/1/90"; ! 22: #endif /* not lint */ ! 23: ! 24: #include "back.h" ! 25: ! 26: extern int errno; ! 27: ! 28: static char confirm[] = "Are you sure you want to leave now?"; ! 29: static char prompt[] = "Enter a file name: "; ! 30: static char exist1[] = "The file '"; ! 31: static char exist2[] = ! 32: "' already exists.\nAre you sure you want to use this file?"; ! 33: static char cantuse[] = "\nCan't use "; ! 34: static char saved[] = "This game has been saved on the file '"; ! 35: static char type[] = "'.\nType \"backgammon "; ! 36: static char rec[] = "\" to recover your game.\n\n"; ! 37: static char cantrec[] = "Can't recover file: "; ! 38: ! 39: save (n) ! 40: register int n; ! 41: ! 42: { ! 43: register int fdesc; ! 44: register char *fs; ! 45: char fname[50]; ! 46: ! 47: if (n) { ! 48: if (tflag) { ! 49: curmove (20,0); ! 50: clend(); ! 51: } else ! 52: writec ('\n'); ! 53: writel (confirm); ! 54: if (! yorn(0)) ! 55: return; ! 56: } ! 57: cflag = 1; ! 58: for (;;) { ! 59: writel (prompt); ! 60: fs = fname; ! 61: while ((*fs = readc()) != '\n') { ! 62: if (*fs == tty.sg_erase) { ! 63: if (fs > fname) { ! 64: fs--; ! 65: if (tflag) ! 66: curmove (curr,curc-1); ! 67: else ! 68: writec (*fs); ! 69: } else ! 70: writec ('\007'); ! 71: continue; ! 72: } ! 73: writec (*fs++); ! 74: } ! 75: *fs = '\0'; ! 76: if ((fdesc = open(fname,2)) == -1 && errno == 2) { ! 77: if ((fdesc = creat (fname,0700)) != -1) ! 78: break; ! 79: } ! 80: if (fdesc != -1) { ! 81: if (tflag) { ! 82: curmove (18,0); ! 83: clend(); ! 84: } else ! 85: writec ('\n'); ! 86: writel (exist1); ! 87: writel (fname); ! 88: writel (exist2); ! 89: cflag = 0; ! 90: close (fdesc); ! 91: if (yorn (0)) { ! 92: unlink (fname); ! 93: fdesc = creat (fname,0700); ! 94: break; ! 95: } else { ! 96: cflag = 1; ! 97: continue; ! 98: } ! 99: } ! 100: writel (cantuse); ! 101: writel (fname); ! 102: writel (".\n"); ! 103: close (fdesc); ! 104: cflag = 1; ! 105: } ! 106: write (fdesc,board,sizeof board); ! 107: write (fdesc,off,sizeof off); ! 108: write (fdesc,in,sizeof in); ! 109: write (fdesc,dice,sizeof dice); ! 110: write (fdesc,&cturn,sizeof cturn); ! 111: write (fdesc,&dlast,sizeof dlast); ! 112: write (fdesc,&pnum,sizeof pnum); ! 113: write (fdesc,&rscore,sizeof rscore); ! 114: write (fdesc,&wscore,sizeof wscore); ! 115: write (fdesc,&gvalue,sizeof gvalue); ! 116: write (fdesc,&raflag,sizeof raflag); ! 117: close (fdesc); ! 118: if (tflag) ! 119: curmove (18,0); ! 120: writel (saved); ! 121: writel (fname); ! 122: writel (type); ! 123: writel (fname); ! 124: writel (rec); ! 125: if (tflag) ! 126: clend(); ! 127: getout (); ! 128: } ! 129: ! 130: recover (s) ! 131: char *s; ! 132: ! 133: { ! 134: register int i; ! 135: int fdesc; ! 136: ! 137: if ((fdesc = open (s,0)) == -1) ! 138: norec (s); ! 139: read (fdesc,board,sizeof board); ! 140: read (fdesc,off,sizeof off); ! 141: read (fdesc,in,sizeof in); ! 142: read (fdesc,dice,sizeof dice); ! 143: read (fdesc,&cturn,sizeof cturn); ! 144: read (fdesc,&dlast,sizeof dlast); ! 145: read (fdesc,&pnum,sizeof pnum); ! 146: read (fdesc,&rscore,sizeof rscore); ! 147: read (fdesc,&wscore,sizeof wscore); ! 148: read (fdesc,&gvalue,sizeof gvalue); ! 149: read (fdesc,&raflag,sizeof raflag); ! 150: close (fdesc); ! 151: rflag = 1; ! 152: } ! 153: ! 154: norec (s) ! 155: register char *s; ! 156: ! 157: { ! 158: register char *c; ! 159: ! 160: tflag = 0; ! 161: writel (cantrec); ! 162: c = s; ! 163: while (*c != '\0') ! 164: writec (*c++); ! 165: getout (); ! 166: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.