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

  1. /*  $Id$
  2.  *  
  3.  *  File    pgn.c
  4.  *  Part of    ChessBase utilities file format (CBUFF)
  5.  *  Author    Anjo Anjewierden, anjo@swi.psy.uva.nl
  6.  *  Purpose    Portable Game Notation (PGN) utility
  7.  *  Works with    GNU CC 2.4.5
  8.  *  
  9.  *  Notice    Copyright (c) 1993  Anjo Anjewierden
  10.  *  
  11.  *  History    15/10/93  (Created)
  12.  *          15/10/93  (Last modified)
  13.  */ 
  14.  
  15.  
  16. /*------------------------------------------------------------
  17.  *  Directives
  18.  *------------------------------------------------------------*/
  19.  
  20. #include "cbuff.h"
  21.  
  22. char *        UTILITY_NAME = "PGN utility";
  23. char *        UTILITY_VERSION = "1.1.0";
  24.  
  25. void        helpUtility(FILE *fd);
  26.  
  27.  
  28. /*------------------------------------------------------------
  29.  *  PGN utility
  30.  *------------------------------------------------------------*/
  31.  
  32. void
  33. pgnUtility(Option opt)
  34. { Game g = newGame();
  35.   CBase cb = opt->database;
  36.   long from = opt->from;
  37.   long to = (opt->to < getNoGamesCBase(cb) ? opt->to : getNoGamesCBase(cb));
  38.   long n;
  39.  
  40.   reportCBase(cb, stderr);
  41.  
  42.   n = to-from+1;
  43.   if (n < 0)
  44.     return;
  45.   
  46.   for (n=from; n<=to; n++)
  47.   { environmentError(cb, g, n);
  48.     initialiseGame(g, n, cb);
  49.     if (foundError())
  50.     { reportError(stderr);
  51.       continue;
  52.     }
  53.     pgnGame(g, opt->output, opt->notation);
  54.     if (foundError())
  55.       reportError(stderr);
  56.   }
  57.  
  58.   freeGame(g);
  59. }
  60.  
  61.  
  62. /*------------------------------------------------------------
  63.  *  Main
  64.  *------------------------------------------------------------*/
  65.  
  66. int
  67. main(int argc, char *argv[])
  68. { int i;
  69.   Option options = newOption();
  70.  
  71.   initChessSymbols();
  72.  
  73.   for (i=1; i<argc; i++)
  74.   {
  75.     if (strhead(argv[i], "-"))
  76.     { int n;
  77.  
  78.       n = genericOption(options, argv, argc, i);
  79.       if (n == 0)
  80.       { fprintf(stderr, "Fatal: Unknown command %s\n", argv[i]);
  81.     fprintf(stderr, "Do ``%s -help'' or see the documentation\n", argv[0]);
  82.     exit(1);
  83.       }
  84.       i = n;
  85.       continue;
  86.     }
  87.  
  88.     setCurrentCBase(argv[i], "-database", argc, i);
  89.     options->database = CurrentBase;
  90.     pgnUtility(options);
  91.     freeCBase(options->database);
  92.     options->database = (CBase) NULL;
  93.   }
  94.  
  95.   if (options->database)
  96.   { pgnUtility(options);
  97.     freeCBase(options->database);
  98.   }
  99.  
  100.   exit(0);
  101. }
  102.  
  103.  
  104. /*------------------------------------------------------------
  105.  *  Help
  106.  *------------------------------------------------------------*/
  107.  
  108. void
  109. helpUtility(FILE *fd)
  110. { helpCBUFF(fd);
  111.   fprintf(fd, "%s options:\n", UTILITY_NAME);
  112. }
  113.