DataMuseum.dk

Presents historical artifacts from the history of:

DKUUG/EUUG Conference tapes

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about DKUUG/EUUG Conference tapes

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - metrics - download
Index: T m

⟦688fd3952⟧ TextFile

    Length: 6750 (0x1a5e)
    Types: TextFile
    Names: »m.c.orig«

Derivation

└─⟦b20c6495f⟧ Bits:30007238 EUUGD18: Wien-båndet, efterår 1987
    └─⟦this⟧ »EUUGD18/X/Xwanderer/m.c.orig« 

TextFile

#include "wand_head.h"

#ifdef GAMEDEV
char *scrname = "screen";
#endif


#ifdef XWANDER
#    include <ctype.h>
#    define PROGNAME "sample program"
#    define ICON_LABEL "sample"
#    include "icons/wanderer_bm"
#    define BITMAPDEPTH  1
extern int do_repaint;
extern tinymode;
Window win;			/* window ID */
Display *dpy;		/* structure with display and screen info */
GC globgc;
int scr;			/* screen number */
int endgame;
#endif

extern char *playscreen();

extern int rscreen();

#ifndef GAMEDEV
extern int savescore();
#endif

#ifdef XWANDER
usage()
{
    fprintf(stderr,"usage: xwander -s -d display_name\n");
    fprintf(stderr,"\t-s\tprints high score table\n");
    fprintf(stderr,"\t-d\tspecify display name\n");
}
#endif

main(argc,argv)
int  argc;
char *argv[];
{
char screen[NOOFROWS][ROWLEN+1];
char (*frow)[ROWLEN+1] = screen;
int num = 1,score = 0,bell = 1,maxmoves = 0;
char howdead[25],
     *name,*keys,*dead;
char *malloc();
#ifdef XWANDER
    int win_width, win_height, win_x, win_y;	
    int border_width = 2;
    int display_width, display_height;
    unsigned int icon_width, icon_height;
    char *window_name = PROGNAME;
    char *icon_name = ICON_LABEL;
    Pixmap icon_pixmap;
    XSizeHints size_hints;	/* window manager hints */
    XIconSize *size_list;
    int count;			/* number of icon sizes set by wm */
    XEvent report;
    char *display_name = NULL;
    char *p;

    argc--; argv++;		/* skip program name */
    while (argc > 0 && **argv == '-')	/* until there are no more args */
    {
        p = *argv;
	if (strcmp("-display", p) == 0) {
	    display_name = *++argv;
	    printf("display = \"%s\"\n",display_name);
	    argc--;
	} else {
	    for (p++; *p;p++)
	    {
		switch(*p) {
		case 'd':		/* set display name */
		    display_name = *++argv;
		    printf("display = \"%s\"\n",display_name);
		    --argc;
		    break;
#ifndef GAMEDEV
		case 's':		/* print scores */
		    savescore("-",0,0,"-");
		    return 0;
		    break;
#endif
#ifdef GAMEDEV
		case 'n':		/* name of screen to test */
		     scrname = *++argv;
		     break;
#endif
		default:
		    printf("xwanderer: bad option '%c'\n", *p);
		    usage();
		    break;
		}
	    }
	    argv++;
	    argc--;
	}
    }

    /* try to connect to display server */
    if (( dpy = XOpenDisplay(display_name)) == NULL)
    {
	fprintf(stderr,"Cannot Connect to display server!\n");
	exit(-1);
    }

    /* get screen and size from display structure macros */
    scr = DefaultScreen(dpy);

    display_width = DisplayWidth(dpy,scr);
    display_height = DisplayHeight(dpy,scr);

    win_x = 0; win_y = 0;
    win_width = 1100; win_height = ICON_HIGH * 7 + 75;

    /* make window */
    win = XCreateSimpleWindow(dpy,RootWindow(dpy,scr), win_x, win_y,
	win_width, win_height, border_width, WhitePixel(dpy,scr), 
	BlackPixel(dpy,scr));

    /* get available icon sizes from window manager */
    /* if (XGetIconSizes(dpy,RootWindow(dpy,scr),&size_list,&count)==0) */
    /* I don't care if your window manager doesn't support 64x64--mine does. */
	icon_width = wanderer_bm_width; icon_height = wanderer_bm_height;
    /* else
    {
	icon_width = size_list->min_width; icon_height = size_list->min_height;
    } */
    /* create pixmap from bitmap data */
    icon_pixmap = MakePixmap(dpy,RootWindow(dpy,scr),wanderer_bm_bits, 
	icon_width, icon_height);

    /* initalize the hint prop. for wm */
    size_hints.flags = PPosition | PSize | PMinSize; 
    size_hints.x = win_x;
    size_hints.y = win_y;
    size_hints.width = win_width;
    size_hints.height = win_height;
    size_hints.min_width = 350;
    size_hints.min_height = 100;

    /* set props. for wm (always before mapping) */
    XSetStandardProperties(dpy,win,window_name,icon_name,icon_pixmap,
	argv,argc,&size_hints);

    /*select event types wanted */
    XSelectInput(dpy,win,ExposureMask | KeyPressMask);

    /* build the pixmaps for the game */
    build_pixmaps();	

    /* display the window! */
    XMapWindow(dpy,win);

#else
#  ifndef GAMEDEV
if(argc > 1)
    {
    savescore("-",0,0,"-");
    return 0;
    }
#  else
if (argc > 1)
    {
    scrname = argv[1];
    }
#  endif
#endif

if((name = (char *)getenv("NEWNAME")) == NULL)
    if((name = (char *)getenv("NAME")) == NULL)
        if((name = (char *)getenv("FULLNAME")) == NULL)
            if((name = (char *)getenv("USER")) == NULL)
	        name = "noname";

if((keys = (char *)getenv("NEWKEYS")) == NULL)
    {
    keys = malloc(5);
    strcpy(keys,"kjhl");
    }

#ifndef XWANDER
initscr();

/* MAIN PROGRAM HERE */

crmode(); noecho();
#endif

for (;;)
    {
    int ch;

#ifndef GAMEDEV
    if (rscreen(num,frow,&maxmoves))
	{
	strcpy(howdead,"a non-existant screen");
	break;	/* really game over- leave the program and all! */
	}
#else
    if (rscreen(scrname,frow, &maxmoves))
	{
	fprintf(stderr,"dev: Can't find file `%s'\n",scrname);
#ifndef XWANDER
	echo();
	nocrmode();
	endwin();
#endif
	exit(0);
	};
#endif
#ifdef XWANDER
    do_repaint = 1;
    tinymode = 0;
#endif
    dead = playscreen(num,screen,&score,&bell,maxmoves,keys);
#ifdef GAMEDEV
    if ((dead != NULL) && (*dead == '~'))
	dead = NULL;
#else
    if ((dead != NULL) && (*dead == '~'))
	{
	num = (int)(dead[1]) - 1;
	dead = NULL;
	}
#endif
    if (dead != NULL)
	{
	strcpy(howdead,dead);
#ifdef XWANDER
	/* we can't have this window based program going away every time
	 * we die.  Ask the user if he wants to play again, but first
	 * do the end of game clean up type stuff 
	 */
	erase_message(0);
	erase_message(1);
	message(0,"%s killed by %s with a score of %d on level %d.",
		name,howdead,score,num);
	endgame = 0;
	XClearArea(dpy, win, 5, 5, ICON_WIDE * 11, ICON_HIGH * 7, 0);
#  ifndef GAMEDEV
	if((savescore(howdead,score,num,name) == 0)&&(score != 0))
	     printf("\nWARNING: newgame error: score not saved!\n\n");
#  endif
	message(1,"Would you like to play again? (Y/N)");
	while (1) {
	    ch = getchar(-1);
	    if (islower(ch)) ch = toupper(ch);
	    if (ch == 'Y' || ch == 'N') 
		break;
	    erase_message(1);
	    message(1,"You dolt, type `Y' or `N':          ");
	    dobeep();
	}
	if (ch == 'N') break; else {
	    num = 0; score = 0; maxmoves = 0;
	    howdead[0] = 0;
	    erase_message(0);
	    erase_message(1);
	}
#else
        break;
#endif
        }
    num++;
    };
#ifdef XWANDER
    endgame = 1;
#endif

printf("\n\n%s killed by %s with a score of %d on level %d.\n",name,howdead,score,num);

/* END OF MAIN PROGRAM */

/* SAVE ROUTINES FOR SCORES */

#ifndef GAMEDEV
if((savescore(howdead,score,num,name) == 0)&&(score != 0))
     printf("\nWARNING: newgame error: score not saved!\n\n");
#endif

#ifndef XWANDER
echo();
nocrmode();
endwin();
#endif
printf("WANDERER (C)1988 S. Shipway\n");
return 0;
}