|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T f
Length: 4225 (0x1081) Types: TextFile Names: »file.c«
└─⟦b20c6495f⟧ Bits:30007238 EUUGD18: Wien-båndet, efterår 1987 └─⟦this⟧ »EUUGD18/X/Xgo/file.c«
/* * $Header: file.c,v 3.0 88/03/10 12:07:24 hale Exp $ */ #include "go.h" #include <strings.h> #include <sys/file.h> /* save file */ FILE *sf; int initload; char buf1[MAXBUF]; extern int beepflg, demflg, status; extern int handicaps; extern int dimensions, changeflg, myport; extern char *arg0; /* * file format: #<board dimension> #<curplr: 0/1> <0-n blank lines> '#' <options= Rxx -> right justify with x being width Bxx -> bottom justify with xx being height of data > xoooxoxox..x ..x..x...... ...x..x..xxx '#' %comments to be printed. %in the message window */ static char *cont=".@O....."; savegame() { extern char *opponent; int fd; int x,y; sprintf(buf1,"go.save.%s",opponent); fd = open ( buf1, O_CREAT | O_WRONLY, 0777); if (fd<0) badload("Can't create file."); sf = fdopen(fd,"w"); fprintf(sf, "#!%s/%s -m -l\n", BINDIR, arg0); fprintf(sf, "%d %d\n", dimensions, curplr); fprintf(sf,"#\n"); for (y=0; y<MAXY; y++) { for (x=0; x<MAXX; x++) fprintf(sf, "%c ",cont[b(x,y)]); fprintf(sf,"\n"); } fprintf(sf,"#\n"); fprintf(sf, "%d %d %d %d\n\n\n", hama[0], hama[1], cx, cy); fclose(sf); } restgame(f) char *f; { char c,*cp; int x,y,done; int lj, bj; sf = fopen(f, "r"); while (getbuf(1), buf1[0]=='#') ; if (sscanf(buf1, "%d %d", &dimensions,&curplr)==EOF) badload("bad data in file"); curplr = !curplr; if (!curplr) addmes("== Black to play."); else addmes("== White to play."); while (fgets(buf1,MAXBUF,sf) != NULL && buf1[0]!='#') ; MAXX = MAXY = lj= bj = dimensions; if (!initload) { initload=1; /* PrintBoard(&board); */ } else { SEND(MCLEAR); doclear(); } done = 0; do { getbuf(1); if (buf1[0]=='R' || buf1[0]=='r') { lj = atoi (buf1+1); if (lj < 1 || lj > dimensions) lj = dimensions; } else if (buf1[0]=='B' || buf1[0]=='b') { bj = atoi (buf1+1); if (bj < 1 || bj > dimensions) bj = dimensions; } else done++; } while (!done); SEND(MLOAD); sendint(hama[0]); sendint(hama[1]); sendint(curplr); sendint(dimensions); done = 0; x = dimensions - lj; y = dimensions - bj; cp = buf1; while (!done) { switch (*cp) { case '.': case '0': cp++; sethand(x++,y,0); break; case 'O': case 'o': case 'w': case '2': cp++; sethand(x++,y,2); break; case 'X': case 'x': case '@': case 'b': case '1': cp++; sethand(x++,y,1); break; case '\n': case ';': case '\0': getbuf(1); cp = buf1; x = dimensions - lj; y++; break; case '#': done++; break; default: cp++; break; } if (x>=dimensions) { getbuf(1); x = dimensions - lj; y++; cp = buf1; } if (y>=dimensions) done++; } getbuf(0); if (sscanf(buf1, "%d %d %d %d", &hama[0], &hama[1], &cx, &cy)!=EOF) while (fgets(buf1,MAXBUF,sf)!=NULL || buf1[0]=='%') { if (buf1[0]=='%') { char *cc; cc = index (buf1,'\n'); if (cc!=NULL) *cc = '\0'; addmes(buf1); } buf1[0]=' '; } fclose(sf); } getbuf(err) int err; { do { if (fgets(buf1,MAXBUF,sf) == NULL) if (err) badload("End of file reached early."); } while (buf1[0]=='\n' || buf1[0]=='\0' || buf1[0]==';'); } badload(s) char *s; { addmes(s); GetAKey(); SEND(MEXIT); Exit(); } doload() { extern char *loadname; int x,y; addmes("--- Loading File ---"); restgame(loadname); } /* * $Log: file.c,v $ * Revision 3.0 88/03/10 12:07:24 hale * Added save games, a few changes to the I/O, * added load and clear options. Not thouroughly tested, though, and * I think a few bugs are in the load code. A library of sample problems * has been started and saved with the working directory. * * Revision 1.3 88/02/19 13:48:41 hale * Added io changes for loading games. * Load game is cleaned up. Variable board * sizes and formats available in save game * as well as printed comments. * * Revision 1.2 88/02/14 00:22:56 hale * Added load file option during game to restore game to starting * state. Also, clear board operation. Restoring game puts current * player in sync. With the demo mode, this is invaluable. * * Revision 1.1 88/02/13 12:48:06 hale * Initial revision * */