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

⟦7b59fe2af⟧ TextFile

    Length: 13495 (0x34b7)
    Types: TextFile
    Names: »main.c.orig«

Derivation

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

TextFile

/******************************************************************************
* Dragon - a version of Mah-Jongg for X Windows
*
* Author: Gary E. Barnes	March 1989
*
* main.c - The mainline code.
******************************************************************************/

#define _MAIN_C_

#include "main.h"
#include <X11/ShellP.h>
#include "ic/background.ic"
#include "ic/gray.ic"
#include "ic/shadow.ic"

extern void Icon_Setup();
extern void Board_Setup();

\f


/******************************************************************************
* Dragon Resources
******************************************************************************/

static int		def_DCTime	= 250;	/* ms for double click */
static Boolean		def_FALSE	= FALSE;
static Boolean		def_TRUE	= TRUE;

#define offset(field)	XtOffset( Dragon_Resources_Ptr, field )
#define BOOLEAN(name,class,field,default) \
    {name, class, XtRBoolean, sizeof(Boolean), offset(field), XtRBoolean, \
     (caddr_t)default}
#define CURSOR(name,class,field,default) \
    {name, class, XtRCursor, sizeof(Cursor), offset(field), \
     XtRString, (caddr_t)default}
#define FONT(name,class,field,default) \
    {name, class, XtRFontStruct, sizeof(XFontStruct*), offset(field), \
     XtRString, (caddr_t)default}
#define INT(name,class,field,default) \
    {name, class, XtRInt, sizeof(int), offset(field), XtRInt, (caddr_t)default}
#define STRING(name,class,field,default) \
    {name, class, XtRString, sizeof(String), offset(field), XtRString, \
     (caddr_t)default}

static XtResource dragon_resources[] = {
  CURSOR ( "cursor",        XtCCursor,       Cursor,	         "hand2"     ),
  BOOLEAN( "debug",	    "Debug",	     Debug,		 &def_FALSE  ),
  INT    ( "doubleClick",   "DoubleClick",   Double_Click_Time,  &def_DCTime ),
  STRING ( XtNgeometry,     XtCGeometry,     Geometry,		 "444x339"   ),
  STRING ( "iconGeometry",  "IconGeometry",  Icon_Geometry,      "64x64"     ),
  BOOLEAN( "iconic",        "Iconic",        Iconic,             &def_FALSE  ),
  STRING ( XtNiconName,	    XtCIconName,     Icon_Name,		 NULL 	     ),
  BOOLEAN( XtNreverseVideo, XtCReverseVideo, Reverse_Video,      &def_FALSE  ),
  BOOLEAN( "tileShadows",   "TileShadows",   Tile_Shadows,	 &def_TRUE  ),
  STRING ( "tileSides",	    "TileSides",     Tile_Sides,	 "gray"	     ),
};

#undef offset
#undef BOOLEAN
#undef FONT
#undef INT
#undef STRING

\f


/******************************************************************************
* Dragon Command Line Options
******************************************************************************/

static XrmOptionDescRec command_line_options[] = {
{"-cursor",      ".cursor",          XrmoptionSepArg,  (caddr_t)NULL  },
{"-debug",	 ".debug",	     XrmoptionNoArg,   (caddr_t)"on"  },
{"-double",      ".doubleClick",     XrmoptionSepArg,  (caddr_t)NULL  },
{"-geometry",    ".geometry", 	     XrmoptionSepArg,  (caddr_t)NULL  },
{"-icongeometry",".iconGeometry",    XrmoptionSepArg,  (caddr_t)NULL  },
{"-iconic",      ".iconic",	     XrmoptionNoArg,   (caddr_t)"on"  },
{"+iconic",      ".iconic",	     XrmoptionNoArg,   (caddr_t)"off" },
{"-iconname",	 ".iconName",	     XrmoptionSepArg,  (caddr_t)NULL  },
{"-reverse",     "*reverseVideo",    XrmoptionNoArg,   (caddr_t)"on"  },
{"+reverse",     "*reverseVideo",    XrmoptionNoArg,   (caddr_t)"off" },
{"-shadows",	 ".tileShadows",     XrmoptionNoArg,   (caddr_t)"off"  },
{"+shadows",	 ".tileShadows",     XrmoptionNoArg,   (caddr_t)"on" },
{"-sides",	 ".tileSides",	     XrmoptionSepArg,  (caddr_t)"line"},
};

typedef struct {
  String	name;
  String	desc;
} Option_Help;

static Option_Help command_line_help[] = {
{"-help",      		 "print out this message"},
{"-display displayname", "X server to contact"},
{"-cursor name",	 "name of the cursor to use"},
{"-double time",	 "double-click time limit in milliseconds"},
{"-font name",		 "font to use for buttons and messages"},
{"-geometry WxH+X+Y",	 "size (in pixels) and position of the board"},
{"-icongeometry WxH+X+Y","size (in pixels) and position of the program icon"},
{"-/+iconic",            "begin program as an icon"},
{"-iconname name",	 "name to use with the program icon"},
{"-/+reverse",		 "turn on/off reverse video"},
{"-/+shadows",		 "turn on/off tile shadows"},
{"-sides line/black/gray","set the style for tile sides"},
{ NULL, NULL }
};

\f


static void Command_Line_Usage( Bad_Option )
     String	Bad_Option;
/******************************************************************************
*   Bad_Option	- Specifies the unfathomable command line option we received
*
* Called when we find an unrecognized command line option.  We spit out a
* Unix-sytle usage message and die.
******************************************************************************/
{
    Option_Help	*opt;
    int		 col;

    (void)fprintf( stderr, "%s:  unrecognized command line option [%s]\n\n",
		   Program_Name, Bad_Option );

    (void)fprintf( stderr, "usage:  %s", Program_Name );
    col = 8 + strlen(Program_Name);
    for (opt = command_line_help; opt->name; opt++) {
	int len = 3 + strlen(opt->name);	/* space[string] */
	if (col + len > 79) {
	    (void)fprintf (stderr, "\n   ");	/* 3 spaces */
	    col = 3;
	}
	(void)fprintf (stderr, " [%s]", opt->name);
	col += len;
    }

    (void)fprintf( stderr, "\n\nType %s -help for a more help.\n",
		   Program_Name );
    exit( 1 );

} /* Command_Line_Usage */

\f


static void Command_Line_Help()
/******************************************************************************
* Called when the -help switch is used.  Put out our extended help message.
******************************************************************************/
{
    Option_Help	*opt;

    (void)fprintf( stderr, "usage:\n        %s [options]\n\n",
		   Program_Name);
    (void)fprintf( stderr, "Where the options are:\n");
    for (opt = command_line_help; opt->name; opt++) {
	(void)fprintf( stderr, "    %-24s %s\n", opt->name, opt->desc );
    }
    (void)fprintf( stderr, "\n" );
    exit( 0 );

} /* Command_Line_Help */

\f


Pixmap XCreateTile( display, d, data, width, height )
     Display	    *display;
     Drawable	     d;
     char	    *data;
     unsigned int    width, height;
/******************************************************************************
* Converted form of XCreatePixmapFromBitmapData.  Use our GC and don't bother
* the Server for another one.
******************************************************************************/
{
    XImage ximage;
    Pixmap pix;

    pix = XCreatePixmap( display, d, width, height, 1 );
    if (pix == (Pixmap)0) return (Pixmap)0;

    ximage.height = height;
    ximage.width = width;
    ximage.depth = 1;
    ximage.xoffset = 0;
    ximage.format = XYBitmap;
    ximage.data = data;
    ximage.byte_order = LSBFirst;
    ximage.bitmap_unit = 8;
    ximage.bitmap_bit_order = LSBFirst;
    ximage.bitmap_pad = 8;
    ximage.bytes_per_line = (width+7)/8;

    XPutImage( display, pix, Normal_GC, &ximage, 0, 0, 0, 0, width, height );
    return pix;
} /* XCreateTile */

\f


static void GC_Setup()
/******************************************************************************
* Set up the GC's that we will be using for drawing.
******************************************************************************/
{
    XGCValues	gcv;
    Pixel	pix;

/*--Xor_GC - fg = black, bg = white, func = xor */

    gcv.function = GXxor;
    gcv.foreground = BlackPixelOfScreen(XtScreen(Dragon));
    gcv.background = WhitePixelOfScreen(XtScreen(Dragon));
    Xor_GC = XtGetGC( Dragon,
		      GCFunction|GCForeground|GCBackground,
		      &gcv );

/*--Normal_GC - fg = black, bg = white, func = copy */

    gcv.function = GXcopy;
    if (Dragon_Resources.Reverse_Video) {
	gcv.background = BlackPixelOfScreen(XtScreen(Dragon));
	gcv.foreground = WhitePixelOfScreen(XtScreen(Dragon));
    }
    Normal_GC = XtGetGC( Dragon, GCFunction|GCForeground|GCBackground, &gcv );

/*--Gray_GC - fg = black, bg = white, func = copy, tile = Gray */

    gcv.tile = XCreateTile( XtDisplay(Board), XtWindow(Board),
			    gray_bits, gray_width, gray_height );
    if (gcv.tile == None) {
	fprintf( stderr, "Can't allocate gray pixmap.\n" );
	exit(1);
    }
    gcv.fill_style = FillTiled;
    Gray_GC = XtGetGC( Dragon,
		       GCFunction|GCForeground|GCBackground|GCTile|GCFillStyle,
		       &gcv );

/*--Over_GC - fg = black, bg = white, func = or */

    if (Dragon_Resources.Reverse_Video) {
	gcv.function = GXand;
    } else {
	gcv.function = GXor;
    }
    gcv.tile =
      XCreateTile( XtDisplay(Board), XtWindow(Board),
		   shadow_bits, shadow_width, shadow_height );
    if (gcv.tile == None) {
	fprintf( stderr, "Can't allocate shadow pixmap.\n" );
	exit(1);
    }
    gcv.fill_style = FillTiled;
    Over_GC = XtGetGC( Dragon,
		       GCFunction|GCForeground|GCBackground|GCTile|GCFillStyle,
		       &gcv );

/*--Reverse_GC - fg = white, bg = black, func = copy */

    gcv.function = GXcopy;
    pix = gcv.background;
    gcv.background = gcv.foreground;
    gcv.foreground = pix;
    Reverse_GC = XtGetGC( Dragon, GCFunction|GCForeground|GCBackground, &gcv );

} /* GC_Setup */

\f


int main (argc, argv)
     int	 argc;
     String	*argv;
/******************************************************************************
* Our Main-Line Code.
******************************************************************************/
{
    Arg		 args[40];
    int		 argi = 0;

#undef SETARG
#define SETARG(name,value) \
    if (argi >= XtNumber(args)) {fprintf(stderr,"main, args overrun!\n");} \
    XtSetArg( args[argi], name,  value ); ++argi;

/*--Start up the toolkit.  This creates a shell widget.  Unfortunately the
 *  only way the toolkit allows you to specify default application resources
 *  is by having a /usr/lib/X11/app-defaults/Application resouce file.  I'm
 *  not interested in doing this.  If some site wants to create one in order
 *  to customize the program then that is fine.  However, I want my program
 *  to be "standalone"; ie. if you have the binary executable then you have
 *  all you *must-have*.  So, I will Destroy this widget shortly. */

    Program_Name = argv[0];
    Dragon =
      XtInitialize ( "dragon", "Dragon",
		     command_line_options, XtNumber(command_line_options),
		     &argc, argv );

/*--See if there is anything left on the command line. */

    for (++argv, --argc; argc > 0; ++argv, --argc) {
	if (strcmp( argv[0], "-help" ) == 0) { Command_Line_Help(); }
	Command_Line_Usage( argv[0] );
    }

/*--Now get the application resources. */

    DEBUG_OTHER(main,XtGetApplicationResources);
    XtGetApplicationResources( Dragon, (caddr_t)&Dragon_Resources,
			       dragon_resources, XtNumber(dragon_resources),
			       (ArgList)NULL, (Cardinal)0 );
			  
/*--Set up our icon. */

    DEBUG_OTHER(main,Icon_Setup);
    Icon_Setup( args, (int)XtNumber(args), &argi );

/*--Now set up our "real" application shell. */

    DEBUG_OTHER(main,XtDestroyWidget);
    XtDestroyWidget( Dragon );

/*--Set up various other controls on our top level widget that we require. */

    SETARG( XtNminWidth,	450 );
    SETARG( XtNminHeight,	340 );
    SETARG( XtNwidthInc,	210 );
    SETARG( XtNheightInc,	160 );
    SETARG( XtNminAspectX,	1333 );
    SETARG( XtNminAspectY,	1000 );
    SETARG( XtNmaxAspectX,	1333 );
    SETARG( XtNmaxAspectY,	1000 );
    SETARG( XtNgeometry,	Dragon_Resources.Geometry );
    if (Dragon_Resources.Reverse_Video) {
	SETARG( XtNbackground, BlackPixelOfScreen(XtScreen(Dragon)) );
	SETARG( XtNforeground, WhitePixelOfScreen(XtScreen(Dragon)) );
    } else {
	SETARG( XtNforeground, BlackPixelOfScreen(XtScreen(Dragon)) );
	SETARG( XtNbackground, WhitePixelOfScreen(XtScreen(Dragon)) );
    }

    SETARG( XtNallowShellResize, TRUE );
    SETARG( XtNinput,		 TRUE );
    if (argi > XtNumber(args)) {
	(void)fprintf(stderr, "assert: args?\n");
	exit(1);
    }
    DEBUG_OTHER(main,XtCreateApplicationShell);
    Dragon = XtCreateApplicationShell( "dragon", 
				       topLevelShellWidgetClass,
				       args, (Cardinal)argi );
    argi = 0;

/*--Check the tile controls. */

    Tile_Control = 0;
    if (Dragon_Resources.Tile_Shadows) { Tile_Control |= SHADOW; }
    if (strcmp( Dragon_Resources.Tile_Sides, "black" ) == 0) {
	Tile_Control |= BLACKSIDE;
    } else if (strcmp( Dragon_Resources.Tile_Sides, "gray" ) == 0) {
	Tile_Control |= BLACKSIDE | GRAYSIDE;
    } else if (strcmp( Dragon_Resources.Tile_Sides, "line" ) != 0) {
	fprintf(stderr,"-side option not given line, gray, or black value.\n");
    }

/*--Create the board that we will be using; realize it too. */

    DEBUG_OTHER(main,Board_Setup);
    Board_Setup();

/*--Set up our GC's. */

    DEBUG_OTHER(main,GC_Setup);
    GC_Setup();

/*--Now make it all appear in front of the user. */

    {	Pixmap	pix;
	pix = XCreateTile( XtDisplay(Board), XtWindow(Board),
			   background_bits, background_width,
			   background_height);
	if (pix == None) {
	    fprintf( stderr, "Can't allocate background pixmap.\n" );
	    exit(1);
	}
	XSetWindowBackgroundPixmap( XtDisplay(Board), XtWindow(Board), pix );
    }

/*--Now do the real thing. */

    DEBUG_OTHER(main,XtMainLoop);
    XtMainLoop();

} /* main */

#if 0
*/* print out the name of a widget; NOTE: no \n printed so printout is not
* * flushed until our caller does one. */
*
*void spit(w)
*     Widget	w;
*{
*    if (w == NULL) return;
*    spit( w->core.parent );
*    fprintf( stderr, ".%s", w->core.name );
*}
#endif /* 0 */