|
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 s
Length: 5455 (0x154f) Types: TextFile Names: »save.c«
└─⟦b20c6495f⟧ Bits:30007238 EUUGD18: Wien-båndet, efterår 1987 └─⟦this⟧ »EUUGD18/General/Dots/save.c«
/* SAVE.C */ #include "dots.h" Save_game() { int c; FILE *fp; char buf[40]; buf[0] = 0; msg("File: %s? ", save_file); if ((c = getchar()) != 'Y' && c != 'y') { if (c != ESC) { msg("File: "); Getstr(buf, min(40, COLS - 8)); if (strlen(buf) > 1) (void) strcpy(save_file, buf); } } else (void) strcpy(buf, save_file); if (*buf) if (!(fp = fopen(buf, "w"))) { msg("Couldn't open %s: %s --more--", save_file, sys_errlist[errno]); while (getchar() != ' ') fputc(7, stderr); } else { c = save(fp, SAVE); (void) fclose(fp); if (c) fputc('\n', stdout), die(); } bottom_line(); } recover(before) bool before; { int c, xspot, yspot; FILE *fp; if (!before) { getyx(stdscr, yspot, xspot); msg("File: %s? ", save_file); if ((c = getchar()) != 'Y' && c != 'y') if (c != ESC) { char buf[40]; msg("Input Filename: "); Getstr(buf, min(40, COLS - 17)); move(LINES - 1, 0); refresh(); if (strlen(buf) < 2) { move(yspot, xspot); refresh(); return 0; } else (void) strcpy(save_file, buf); } else return 0; } if (!(fp = fopen(save_file, "r"))) if (before) perror(save_file); else msg("Couldn't open %s: %s", save_file, sys_errlist[errno]); else if (save(fp, LOAD)) { (void) fclose(fp); if (unlink(save_file) < 0) oops("Couldn't unlink savefile"), puts("Are you trying to cheat?"); return 1; } else { (void) fclose(fp); if (before) putchar('\n'), die(); } if (!before) move(yspot, xspot), refresh(); return 0; } save(fp, funct) FILE *fp; { register int x, y; int i; if (funct == LOAD) { char V[80], *p; if (fgets(V, 80, fp) && (p = index(V, '\n'))) *p = 0; if (strcmp(V, version)) { printf("Sorry, file is wrong version."); return FALSE; } if (fscanf (fp, "persontally = %d\n", &persontally) < 1 || fscanf (fp, "comptally = %d\n", &comptally) < 1 || fscanf (fp, "Length = %d\n", &Length) < 1 || fscanf (fp, "Width = %d\n", &Width) < 1) goto bad; for (x = 0; x < Length * 2; ++x) for (y = 0; y < Width * 2; ++y) { if (fscanf (fp, "board[%*d][%*d] = %d\n", &i) < 1) goto bad; board[x][y] = i; } if (fscanf (fp, "xposit = %d\n", &xposit) < 1 || fscanf (fp, "yposit = %d\n", &yposit) < 1 || fscanf (fp, "x_start = %d\n", &x_start) < 1 || fscanf (fp, "y_start = %d\n", &y_start) < 1 || fscanf (fp, "no_good_moves = %d\n", &no_good_moves) < 1 || fscanf (fp, "control_already_established = %d\n", &control_already_established) < 1 || fscanf (fp, "segtype = %d\n", &segtype) < 1 || fscanf (fp, "dX_found = %d\n", &dX_found) < 1 || fscanf (fp, "segflag = %d\n", &segflag) < 1 || fscanf (fp, "mode = %d\n", &mode) < 1 || fscanf (fp, "level = %d\n", &level) < 1 || fscanf (fp, "Bingo.x = %d, Bingo.y = %d\n", &Bingo.x, &Bingo.y) < 2 || fscanf (fp, "Initial = %2s\n", Initial) < 1 || fscanf (fp, "mover = %d\n", &mover) < 1) goto bad; if (Length < 4 || Width < 4) { bad: msg("File has been corrupted."); return FALSE; } } else { (void) fprintf(fp, "%s\n", version); fprintf (fp, "persontally = %d\n", persontally); fprintf (fp, "comptally = %d\n", comptally); fprintf (fp, "Length = %d\n", Length); fprintf (fp, "Width = %d\n", Width); for (x = 0; x < Length * 2; ++x) for (y = 0; y < Width * 2; ++y) fprintf (fp, "board[%d][%d] = %d\n", x, y, board[x][y]); fprintf (fp, "xposit = %d\n", xposit); fprintf (fp, "yposit = %d\n", yposit); fprintf (fp, "x_start = %d\n", x_start); fprintf (fp, "y_start = %d\n", y_start); fprintf (fp, "no_good_moves = %d\n", no_good_moves); fprintf (fp, "control_already_established = %d\n", control_already_established); fprintf (fp, "segtype = %d\n", segtype); fprintf (fp, "dX_found = %d\n", dX_found); fprintf (fp, "segflag = %d\n", segflag); fprintf (fp, "mode = %d\n", mode); fprintf (fp, "level = %d\n", level); fprintf (fp, "Bingo.x = %d, Bingo.y = %d\n", Bingo.x, Bingo.y); fprintf (fp, "Initial = %2s\n", Initial); fprintf (fp, "mover = %d\n", mover); } return TRUE; } #if 0 (*funct) (&persontally, sizeof(persontally), 1, fp); (*funct) (&comptally, sizeof(comptally), 1, fp); (*funct) (&Length, sizeof(Length), 1, fp); (*funct) (&Width, sizeof(Width), 1, fp); for (x = 0; x < 120; ++x) for (y = 0; y < 120; ++y) { if (funct == SAVE) i = board[x][y]; (*funct) (&i, sizeof(int), 1, fp); if (funct == SAVE) board[x][y] = i; } (*funct) (&xposit, sizeof(xposit), 1, fp); (*funct) (&yposit, sizeof(yposit), 1, fp); (*funct) (&x_start, sizeof(x_start), 1, fp); (*funct) (&y_start, sizeof(y_start), 1, fp); (*funct) (&no_good_moves, sizeof(no_good_moves), 1, fp); (*funct) (&control_already_established, sizeof(control_already_established), 1, fp); (*funct) (&segtype, sizeof(segtype), 1, fp); (*funct) (&dX_found, sizeof(dX_found), 1, fp); (*funct) (&segflag, sizeof(segflag), 1, fp); (*funct) (&mode, sizeof(mode), 1, fp); (*funct) (&level, sizeof(level), 1, fp); (*funct) (&Bingo, sizeof(Bingo), 1, fp); (*funct) (Initial, sizeof(Initial), 1, fp); (*funct) (&mover, sizeof(mover), 1, fp); #endif