home *** CD-ROM | disk | FTP | other *** search
/ High Voltage Shareware / high1.zip / high1 / DIR2 / CBUFF09.ZIP / SRC.ZIP / OPTION.C < prev    next >
C/C++ Source or Header  |  1993-11-16  |  3KB  |  147 lines

  1. /*  $Id$
  2.  *  
  3.  *  File    options.c
  4.  *  Part of    ChessBase utilities file format (CBUFF)
  5.  *  Author    Anjo Anjewierden, anjo@swi.psy.uva.nl
  6.  *  Purpose    Options for the various utilities
  7.  *  Works with    GNU CC 2.4.5
  8.  *  
  9.  *  Notice    Copyright (c) 1993  Anjo Anjewierden
  10.  *  
  11.  *  History    05/10/93  (Created)
  12.  *          31/10/93  (Last modified)
  13.  */ 
  14.  
  15.  
  16. /*------------------------------------------------------------
  17.  *  Directives
  18.  *------------------------------------------------------------*/
  19.  
  20. #include "cbuff.h"
  21.  
  22.  
  23. unsigned short    UserId = 0;
  24.  
  25.  
  26. /*------------------------------------------------------------
  27.  *  Functions
  28.  *------------------------------------------------------------*/
  29.  
  30. Option
  31. newOption()
  32. { Option opt;
  33.  
  34.   opt = (Option) alloc(sizeof(struct option));
  35.   opt->from = 1L;
  36.   opt->to = 999999L;
  37.   opt->database = (CBase) NULL;
  38.   opt->dump = (CBase) NULL;
  39.   opt->output = stdout;
  40.   opt->verbose = FALSE;
  41.   opt->notation = SHORT_ALGEBRAIC;
  42.  
  43.   return opt;
  44. }
  45.  
  46.  
  47. void
  48. freeOption(Option opt)
  49. { unalloc(opt);
  50. }
  51.  
  52.  
  53. /*------------------------------------------------------------
  54.  *  Generic options
  55.  *------------------------------------------------------------*/
  56.  
  57. int
  58. genericOption(Option opt, char **argv, int argc, int i)
  59. { if (strhead(argv[i], "-append"))    /* -append */
  60.   { ++i;
  61.     opt->dump = appendBaseArgument(argv[i], "-append", argc, i);
  62.     return i;
  63.   }
  64.  
  65.   if (strhead(argv[i], "-database"))    /* -database */
  66.   { ++i;
  67.     setCurrentCBase(argv[i], "-database", argc, i);
  68.     opt->database = CurrentBase;
  69.     return i;
  70.   }
  71.  
  72.   if (strhead(argv[i], "-dump"))    /* -dump */
  73.   { ++i;
  74.     opt->dump = createBaseArgument(argv[i], "-dump", argc, i);
  75.     return i;
  76.   }
  77.  
  78.   if (strhead(argv[i], "-from"))    /* -from */
  79.   { ++i;
  80.     opt->from = longArgument(argv[i], "-from", argc, i);
  81.     return i;
  82.   }
  83.  
  84.   if (strhead(argv[i], "-help"))    /* -help */
  85.   { helpUtility(stderr);
  86.     exit(0);
  87.   }
  88.  
  89.   if (strhead(argv[i], "-language"))    /* -language */
  90.   { ++i;
  91.     setLanguage(stringArgument(argv[i], "-language", argc, i));
  92.     return i;
  93.   }
  94.  
  95.   if (strhead(argv[i], "-long"))    /* -long */
  96.   { opt->notation = LONG_ALGEBRAIC;
  97.     return i;
  98.   }
  99.  
  100.   if (strhead(argv[i], "-output"))    /* -output */
  101.   { ++i;
  102.     if (opt->output != stdout)
  103.       fclose(opt->output);
  104.     opt->output = fileArgument(argv[i], "-output", argc, i, "w");
  105.     return i;
  106.   }
  107.  
  108.   if (strhead(argv[i], "-short"))    /* -short */
  109.   { opt->notation = SHORT_ALGEBRAIC;
  110.     return i;
  111.   }
  112.  
  113.   if (strhead(argv[i], "-symbols"))    /* -symbols */
  114.   { FILE *fd;
  115.  
  116.     ++i;
  117.     fd = fileArgument(argv[i], "-symbols", argc, i, "r");
  118.     loadChessSymbols(fd);
  119.     fclose(fd);
  120.     return i;
  121.   }
  122.  
  123.   if (strhead(argv[i], "-to"))        /* -to */
  124.   { ++i;
  125.     opt->to = longArgument(argv[i], "-to", argc, i);
  126.     return i;
  127.   }
  128.  
  129.   if (strhead(argv[i], "-verbose"))    /* -verbose */
  130.   { opt->verbose = TRUE;
  131.     return i;
  132.   }
  133.  
  134.   if (strhead(argv[i], "-version"))    /* -version */
  135.   { versionCBUFF(stderr);
  136.     exit(0);
  137.   }
  138.  
  139.   if (strhead(argv[i], "-uid"))        /* -uid */
  140.   { ++i;
  141.     UserId = intArgument(argv[i], "-uid", argc, i);
  142.     return i;
  143.   }
  144.  
  145.   return FALSE;
  146. }
  147.