games@tekred.CNA.TEK.COM (04/02/89)
Submitted-by: ching@pepsi.amd.com (Mike Ching) Posting-number: Volume 6, Issue 41 Archive-name: ega-sokoban/Part02 #! /bin/sh # This is a shell archive. Remove anything before this line, then unpack # it by saving it into a file and typing "sh file". To overwrite existing # files, type "sh file -c". You can also feed this as standard input via # unshar, or by typing "sh <file", e.g.. If this archive is complete, you # will see the following message at the end: # "End of archive 2 (of 2)." # Contents: makefile readscre.c sok.c # Wrapped by billr@saab on Sat Apr 1 09:45:57 1989 PATH=/bin:/usr/bin:/usr/ucb ; export PATH if test -f 'makefile' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'makefile'\" else echo shar: Extracting \"'makefile'\" \(517 characters\) sed "s/^X//" >'makefile' <<'END_OF_FILE' XCCOPT= -O -ml XOBJECTS= sok.obj readscrn.obj showscrn.obj play.obj save.obj score.obj X Xsok.exe: $(OBJECTS) X tcc -ml $(OBJECTS) lcurses.lib graphics.lib \tc\lib\egavgaf.obj X Xsok.obj: sok.c sokoban.h X tcc $(CCOPT) -c sok.c X Xreadscrn.obj: readscrn.c sokoban.h X tcc $(CCOPT) -c readscrn.c X Xshowscrn.obj: showscrn.c sokoban.h bitmaps.h X tcc $(CCOPT) -c showscrn.c X Xplay.obj: play.c sokoban.h X tcc $(CCOPT) -c play.c X Xsave.obj: save.c sokoban.h X tcc $(CCOPT) -c save.c X Xscore.obj: score.c sokoban.h X tcc $(CCOPT) -c score.c END_OF_FILE if test 517 -ne `wc -c <'makefile'`; then echo shar: \"'makefile'\" unpacked with wrong size! fi # end of 'makefile' fi if test -f 'readscre.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'readscre.c'\" else echo shar: Extracting \"'readscre.c'\" \(1492 characters\) sed "s/^X//" >'readscre.c' <<'END_OF_FILE' X#include <stdio.h> X#include "sokoban.h" X Xextern char *malloc(); Xextern FILE *fopen(); X Xextern short level, packets, savepack, rows, cols; Xextern char map[MAXROW+1][MAXCOL+1]; Xextern POS ppos; X Xshort readscreen() { X X FILE *screen; X char *fnam; X short j, c, ret = 0; X X fnam = malloc( strlen( SCREENPATH) + 12); X sprintf( fnam, "%s/screen.%d", SCREENPATH, level); X if( (screen = fopen( fnam, "r")) == NULL) X ret = E_FOPENSCREEN; X else { X packets = savepack = rows = j = cols = 0; X ppos.x = -1; ppos.y = -1; X while( (ret == 0) && ((c = getc( screen)) != EOF)) { X if( c == '\n') { X map[rows++][j] = '\0'; X if( rows > MAXROW) X ret = E_TOMUCHROWS; X else { X if( j > cols) cols = j; X j = 0; X } X } X else if( (c == player.obj_intern) || (c == playerstore.obj_intern)) { X if( ppos.x != -1) X ret = E_PLAYPOS1; X else { X ppos.x = rows; ppos.y = j; X map[rows][j++] = c; X if( j > MAXCOL) ret = E_TOMUCHCOLS; X } X } X else if( (c == save.obj_intern) || (c == packet.obj_intern) || X (c == wall.obj_intern) || (c == store.obj_intern) || X (c == ground.obj_intern)) { X if( c == save.obj_intern) { savepack++; packets++; } X if( c == packet.obj_intern) packets++; X map[rows][j++] = c; X if( j > MAXCOL) ret = E_TOMUCHCOLS; X } X else ret = E_ILLCHAR; X } X fclose( screen); X if( (ret == 0) && (ppos.x == -1)) ret = E_PLAYPOS2; X } X return( ret); X} END_OF_FILE if test 1492 -ne `wc -c <'readscre.c'`; then echo shar: \"'readscre.c'\" unpacked with wrong size! fi # end of 'readscre.c' fi if test -f 'sok.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'sok.c'\" else echo shar: Extracting \"'sok.c'\" \(5450 characters\) sed "s/^X//" >'sok.c' <<'END_OF_FILE' X#include <stdio.h> X#include <curses.h> X#include "sokoban.h" X#ifdef __MSDOS__ X#if __TURBOC__ X#include <graphics.h> X#endif Xchar * getlogin() X{ static char loginname[MAXUSERNAME]; X fputs("\nName? ", stdout); X fgets(loginname, MAXUSERNAME, stdin); X loginname[strlen(loginname)-1] = 0; X return(loginname); X} X#endif X Xextern char *strrchr(), *getlogin(), *getpass(); Xextern short readscreen(), play(), outputscore(), getuserlevel(), X makenewscore(), restoregame(), score(); X Xshort curses = 1; Xshort scoring = 1; Xshort level, packets, savepack, moves, pushes, rows, cols; Xshort scorelevel, scoremoves, scorepushes; Xchar map[MAXROW+1][MAXCOL+1]; XPOS ppos; Xchar *username, *prgname; X Xstatic short optshowscore = 0, X optmakescore = 0, X optrestore = 0, X optlevel = 0; Xstatic short superuser = 0; X Xstatic short userlevel; X Xmain( argc, argv) Xshort argc; Xchar *argv[]; X{ X short ret, ret2; X#if __TURBOC__ X static int gd = DETECT, gm; X detectgraph(&gd, &gm); X if (gd != -2) X curses = 0; X if (registerfarbgidriver(EGAVGA_driver_far) < 0) X curses = 1; X#endif X X scorelevel = 0; X moves = pushes = packets = savepack = 0; X if( (prgname = strrchr( argv[0], '\\')) == NULL) X prgname = argv[0]; X else prgname++; X if( (ret = checkcmdline( argc, argv)) == 0) { X if( optshowscore) X ret = outputscore(); X else { X if( (username = getlogin()) == NULL) X ret = E_NOUSER; X else { X superuser = (strcmp( username, SUPERUSER) == 0); X if( optmakescore) { X if( superuser) { X if( (ret = getpassword()) == 0) X ret = makenewscore(); X } X else ret = E_NOSUPER; X } X else if( optrestore) { X ret = restoregame(); X } X else if( (ret = getuserlevel( &userlevel)) == 0) { X if( optlevel > 0) { X if( superuser) { X level = optlevel; X scoring = 0; X } X else if( userlevel < optlevel) X ret = E_LEVELTOOHIGH; X else level = optlevel; X } X else level = userlevel; X } X } X } X } X#if __TURBOC__ X if( ret == 0) X { if (!curses) X initgraph(&gd, &gm, ""); X ret = gameloop(); X if (!curses) X closegraph(); X } X#else X if( ret == 0) X ret = gameloop(); X#endif X errmess( ret); X if( scorelevel && scoring) { X ret2 = score(); X errmess( ret2); X } X exit( ret); X} X Xcheckcmdline( argc, argv) Xshort argc; Xchar *argv[]; X{ X short ret = 0; X X if( argc > 1) X if( (argc == 2) && (argv[1][0] == '-')) { X if( (argv[1][1] == 's') && (argv[1][2] == '\0')) X optshowscore = 1; X else if( (argv[1][1] == 'c') && (argv[1][2] == '\0')) X optmakescore = 1; X else if( (argv[1][1] == 'r') && (argv[1][2] == '\0')) X optrestore = 1; X else if( (optlevel = atoi( &(argv[1][1]))) == 0) X ret = E_USAGE; X } X else ret = E_USAGE; X return( ret); X} X Xgameloop() { X X short ret = 0; X X initscr(); crmode(); noecho(); X if( ! optrestore) ret = readscreen(); X while( ret == 0) { X if( (ret = play()) == 0) { X level++; X moves = pushes = packets = savepack = 0; X ret = readscreen(); X } X } X clear(); X if (curses) X refresh(); X nocrmode(); echo(); endwin(); X return( ret); X} X Xgetpassword() { X X return( (strcmp(getpass("Password: "), PASSWORD) == 0) ? 0 : E_ILLPASSWORD); X} X Xchar *message[] = { X "illegal error number", X "cannot open screen file", X "more than one player position in screen file", X "illegal char in screen file", X "no player position in screenfile", X "too much rows in screen file", X "too much columns in screenfile", X "quit the game", X NULL, /* errmessage deleted */ X "cannot get your username", X "cannot open savefile", X "error writing to savefile", X "cannot stat savefile", X "error reading savefile", X "cannot restore, your savefile has been altered", X "game saved", X "too much users in score table", X "cannot open score file", X "error reading scorefile", X "error writing scorefile", X "illegal command line syntax", X "illegal password", X "level number too big in command line", X "only superuser is allowed to make a new score table", X "cannot find file to restore" X}; X Xerrmess( ret) Xregister short ret; X{ X if( ret != E_ENDGAME) { X fprintf( stderr, "%s: ", prgname); X switch( ret) { X case E_FOPENSCREEN: case E_PLAYPOS1: case E_ILLCHAR: X case E_PLAYPOS2: case E_TOMUCHROWS: case E_TOMUCHCOLS: X case E_ENDGAME: case E_NOUSER: X case E_FOPENSAVE: case E_WRITESAVE: case E_STATSAVE: X case E_READSAVE: case E_ALTERSAVE: case E_SAVED: X case E_TOMUCHSE: case E_FOPENSCORE: case E_READSCORE: X case E_WRITESCORE: case E_USAGE: case E_ILLPASSWORD: X case E_LEVELTOOHIGH: case E_NOSUPER: case E_NOSAVEFILE: X fprintf( stderr, "%s\n", message[ret]); X break; X default: fprintf( stderr, "%s\n", message[0]); X break; X } X if( ret == E_USAGE) usage(); X } X} X Xstatic char *usagestr[] = { X " -c: create new score table (superuser only)\n", X " -r: restore saved game\n", X " -s: show score table\n", X " -<nn>: play this level (<nn> must be greater 0)\n", X NULL X}; X Xusage() { X X register short i; X X fprintf( stderr, "Usage: %s [-{s|c|r|<nn>}]\n\n", prgname); X for( i = 0; usagestr[i] != NULL; i++) X fprintf( stderr, "%s", usagestr[i]); X} END_OF_FILE if test 5450 -ne `wc -c <'sok.c'`; then echo shar: \"'sok.c'\" unpacked with wrong size! fi # end of 'sok.c' fi echo shar: End of archive 2 \(of 2\). cp /dev/null ark2isdone MISSING="" for I in 1 2 ; do if test ! -f ark${I}isdone ; then MISSING="${MISSING} ${I}" fi done if test "${MISSING}" = "" ; then echo You have unpacked both archives. rm -f ark[1-9]isdone else echo You still need to unpack the following archives: echo " " ${MISSING} fi ## End of shell archive. exit 0