home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / x / xcu16.zip / clients / xcell / xcell.c < prev    next >
C/C++ Source or Header  |  1991-10-03  |  7KB  |  193 lines

  1. /*
  2.  * Copyright 1991 Cornell University
  3.  *
  4.  * Permission to use, copy, modify, and distribute this software and its
  5.  * documentation for any purpose and without fee is hereby granted, provided
  6.  * that the above copyright notice appear in all copies and that both that
  7.  * copyright notice and this permission notice appear in supporting
  8.  * documentation, and that the name of Cornell U. not be used in advertising
  9.  * or publicity pertaining to distribution of the software without specific,
  10.  * written prior permission.  Cornell U. makes no representations about the
  11.  * suitability of this software for any purpose.  It is provided "as is"
  12.  * without express or implied warranty.
  13.  *
  14.  * CORNELL UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  15.  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  16.  * EVENT SHALL CORNELL UNIVERSITY BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  17.  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
  18.  * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  19.  * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  20.  * PERFORMANCE OF THIS SOFTWARE.
  21.  *
  22.  * Author:  Gene W. Dykes, Program of Computer Graphics
  23.  *          580 Theory Center, Cornell University, Ithaca, NY 14853
  24.  *          (607) 255-6713   gwd@graphics.cornell.edu
  25.  */
  26.  
  27.  
  28. #define CDEBUG
  29. #include <stdio.h>
  30. #include <X11/Intrinsic.h>
  31. #include <X11/Xaw/Cardinals.h>
  32. #include <X11/StringDefs.h>
  33. #include <X11/Shell.h>
  34. #include "Cell.h"
  35.  
  36. /* This allows your window to be resized */
  37. static Arg toplevel_args[] = { {XtNallowShellResize, (XtArgVal) True} } ;
  38.  
  39. #ifdef CDEBUG
  40. XtErrorHandler handler () ;
  41. #endif
  42. static Widget    toplevel, cell_widget ;
  43. static void usage () ;
  44.  
  45. main (argc, argv)
  46.     int argc ;
  47.     char **argv ;
  48. {
  49. int i ;
  50. static XrmOptionDescRec options[] =
  51.  {
  52.   {"-colors", "*Cell.colors", XrmoptionSepArg, "black,white,blue,green,red,yellow" }
  53.  ,{"-directory","*Cell.directory",    XrmoptionSepArg, NULL }
  54.  ,{"-ignore",    "*Cell.ignoreColors",    XrmoptionSepArg, NULL }
  55.  ,{"-rules",    "*Cell.rulesFile",    XrmoptionSepArg, NULL }
  56.  ,{"-alternate","*Cell.alternating",    XrmoptionNoArg, "TRUE" }
  57.  ,{"-perturb",    "*Cell.perturb",    XrmoptionNoArg, "TRUE" }
  58.  ,{"-pick",    "*Cell.pickFile",    XrmoptionSepArg, NULL }
  59.  ,{"-index",    "*Cell.ruleIndex",    XrmoptionSepArg, NULL }
  60.  ,{"-ncolors",    "*Cell.nColors",    XrmoptionSepArg, NULL }
  61.  ,{"-seed",    "*Cell.seed",        XrmoptionSepArg, NULL }
  62.  ,{"-lcr3",    "*Cell.cellType",    XrmoptionNoArg, "lcr3" }
  63.  ,{"-lcr4",    "*Cell.cellType",    XrmoptionNoArg, "lcr4" }
  64.  ,{"-lcr5",    "*Cell.cellType",    XrmoptionNoArg, "lcr5" }
  65.  ,{"-lcr6",    "*Cell.cellType",    XrmoptionNoArg, "lcr6" }
  66.  ,{"-lccr4",    "*Cell.cellType",    XrmoptionNoArg, "lccr4" }
  67.  ,{"-lccrrr4",    "*Cell.cellType",    XrmoptionNoArg, "lccrrr4" }
  68.  ,{"-klcrt3",    "*Cell.cellType",    XrmoptionNoArg, "klcrt3" }
  69.  ,{"-klcrt4",    "*Cell.cellType",    XrmoptionNoArg, "klcrt4" }
  70.  ,{"-klcrt5",    "*Cell.cellType",    XrmoptionNoArg, "klcrt5" }
  71.  ,{"-cols",    "*Cell.perRow",        XrmoptionSepArg, NULL }
  72.  ,{"-rows",    "*Cell.perCol",        XrmoptionSepArg, NULL }
  73.  ,{"-ordered_rules","*Cell.orderedRules",XrmoptionNoArg,  "TRUE" }
  74.  ,{"-vmerge",    "*Cell.verticalMerge",    XrmoptionNoArg,  "TRUE" }    
  75.  ,{"-hmerge",    "*Cell.horizontalMerge",XrmoptionNoArg,  "TRUE" }    
  76.  ,{"-iwidth",    "*Cell.internalWidth",    XrmoptionSepArg, NULL }    
  77.  ,{"-iheight",    "*Cell.internalHeight",    XrmoptionSepArg, NULL }    
  78.  ,{"-bg",    "*Background",        XrmoptionSepArg, NULL }    
  79.  ,{"-shadow",    "*Cell.shadow",        XrmoptionNoArg, "TRUE" }    
  80.  ,{"-fwidth",    "*FacetWidth",        XrmoptionSepArg, NULL }    
  81.  ,{"-ordered_color_permutations",    "*Cell.sequence",    XrmoptionNoArg,  "ordered_permute" }
  82.  ,{"-random_color_permutations","*Cell.sequence",    XrmoptionNoArg, "random_permute" }
  83.  ,{"-random_colors","*Cell.sequence",    XrmoptionNoArg,  "RANDOM_COLOR" }
  84.  ,{"-fixed_colors","*Cell.frequency",    XrmoptionNoArg,  "FIXED_FREQUENCY" }
  85.  ,{"-page_colors","*Cell.frequency",    XrmoptionNoArg,  "PAGE_FREQUENCY" }
  86.  ,{"-rule_colors","*Cell.frequency",    XrmoptionNoArg,  "RULE_FREQUENCY" }
  87.  ,{"-line_colors","*Cell.frequency",    XrmoptionNoArg,  "LINE_FREQUENCY" }
  88.  ,{"-no_beep",    "*Cell.beep",        XrmoptionNoArg,  "FALSE" }
  89.  ,{"-mutate",    "*Cell.mutate",        XrmoptionNoArg,  "TRUE" }
  90.  } ;
  91.  
  92. toplevel = XtInitialize("main", "XCell", options, XtNumber(options),
  93.             &argc, argv);
  94. #ifdef CDEBUG
  95. XtSetErrorHandler (handler) ;
  96. XSetIOErrorHandler (handler) ;
  97. #endif
  98.  
  99. for (i=1;  i < argc;  i++)
  100.     {
  101.     /*
  102.      * Might as well do a half-baked usage check at least
  103.      */
  104.     int found = 0 ;
  105.     if (argv[i][0] != '-')
  106.     continue ;
  107.     if (!found)
  108.     {
  109.     int j ;
  110.     for (j=0;  j < XtNumber(options);  j++)
  111.         {
  112.         if (strcmp (options[j].option, argv[i]) == 0)
  113.         break ;
  114.         }
  115.     if (
  116.        j == XtNumber(options) &&
  117.        strcmp(argv[i], "-geometry") &&
  118.        strcmp(argv[i], "-synchronize")
  119.        )
  120.     if ( j == XtNumber(options) )
  121.         {
  122.         usage () ;
  123.         exit (1) ;
  124.         }
  125.     }
  126.     }
  127.  
  128. /* Perhaps this shouldn't be done? */
  129. XtSetValues (toplevel, toplevel_args, XtNumber(toplevel_args)) ;
  130.  
  131. /* Create the cell widget */
  132. cell_widget = XtCreateManagedWidget("cell", xcuCellWidgetClass, toplevel,
  133.                     NULL, 0);
  134.  
  135. /* Realize the widget tree */
  136. XtRealizeWidget (toplevel) ;
  137.  
  138. for (;;)
  139.     {
  140.     XtInputMask mask ;
  141.     mask = XtPending () ;
  142.     if (mask)
  143.     {
  144.     XEvent event ;
  145.     XtNextEvent (&event) ;
  146.     XtDispatchEvent (&event) ;
  147.     }
  148.     XcuCellStep (cell_widget) ;
  149.     }
  150. }
  151.  
  152. static void
  153. usage ()
  154. {
  155. fprintf (stderr, "-colors color1,color2,...\n") ;
  156. fprintf (stderr, "-ncolors %%d\n") ;
  157. fprintf (stderr, "-ignore index,...\n") ;
  158. fprintf (stderr, "-rules filename\n") ;
  159. fprintf (stderr, "-index %%d\n") ;
  160. fprintf (stderr, "-ordered_rules\n") ;
  161. fprintf (stderr, "-alternate\n") ;
  162. fprintf (stderr, "-perturb\n") ;
  163. fprintf (stderr, "-lcr3 | -lcr4 | -lcr5 | -lcr6 | -lccr4 | -lccrrr4 \n") ;
  164. fprintf (stderr, "      | -klcrt3 | -klcrt4 | -klcrt5\n") ;
  165. fprintf (stderr, "-ordered_color_permutations | -random_color_permutations | -random_colors\n") ;
  166. fprintf (stderr, "-fixed_colors | -page_colors | -rule_colors | -line_colors\n") ;
  167. fprintf (stderr, "-pick filename\n") ;
  168. fprintf (stderr, "-directory path\n") ;
  169. fprintf (stderr, "-seed %%d\n") ;
  170. fprintf (stderr, "-cols %%d\n") ;
  171. fprintf (stderr, "-rows %%d\n") ;
  172. fprintf (stderr, "-vmerge\n") ;
  173. fprintf (stderr, "-hmerge\n") ;
  174. fprintf (stderr, "-iwidth %%d\n") ;
  175. fprintf (stderr, "-iheight %%d\n") ;
  176. fprintf (stderr, "-bg color\n") ;
  177. fprintf (stderr, "-shadow\n") ;
  178. fprintf (stderr, "-fwidth %%d\n") ;
  179. fprintf (stderr, "-no_beep\n") ;
  180. fprintf (stderr, "-mutate\n") ;
  181. return ;
  182. }
  183. #ifdef CDEBUG
  184. XtErrorHandler
  185. handler (message)
  186.     char *message ;
  187. {
  188. fprintf (stderr, "\nHANDLER\n%s\n", message) ;
  189. abort () ;
  190. }
  191. #endif
  192.  
  193.