1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
* This is GNU GO, a Go program. Contact gnugo@gnu.org, or see *
* http://www.gnu.org/software/gnugo/ for more information. *
* *
* Copyright 1999 by the Free Software Foundation. *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
* as published by the Free Software Foundation - version 2. *
* *
* This program is distributed in the hope that it will be *
* useful, but WITHOUT ANY WARRANTY; without even the implied *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR *
* PURPOSE. See the GNU General Public License in file COPYING *
* for more details. *
* *
* You should have received a copy of the GNU General Public *
* License along with this program; if not, write to the Free *
* Software Foundation, Inc., 59 Temple Place - Suite 330, *
* Boston, MA 02111, USA *
\* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/*
* A little program to convert the SGF Spec into something usable in a
* parser- basically, the two letters moved into a 'short'
*/
/* This tells Alpha OSF/1 not to define a getopt prototype in <stdio.h>.
* Ditto for AIX 3.2 and <stdlib.h>.
*/
#ifndef _NO_PROTO
#define _NO_PROTO
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "../utils/getopt.h"
#define MAX_LINE 128
static short str2short(char *);
static short str2short(char *str)
{ return (str[0] | str[1] << 8); }
int
main(void)
{
char instring[MAX_LINE];
char sgf_tag[MAX_LINE];
char comment[MAX_LINE];
int i;
while(fgets(instring, MAX_LINE, stdin))
{
i= strlen(instring)-1;
/* remove trailing newline and spaces */
while(instring[i]== ' ' || instring[i] == 10)
{ instring[i--]=0; }
/* blank lines stay blank lines */
if(strcmp(instring,"")==0)
{
fprintf(stdout, "\n");
continue;
}
sscanf(instring, "%4s %75s", sgf_tag, comment);
strncpy(sgf_tag, instring, 4);
if(strlen(instring)>4) strncpy(comment, instring+4, MAX_LINE-4);
else(strcpy(comment, ""));
/* outdated and modified notations */
/* just shift everything over */
if((sgf_tag[0]== '*') || (sgf_tag[0]=='!'))
{
sgf_tag[0] = sgf_tag[1];
sgf_tag[1] = sgf_tag[2];
sgf_tag[2] = sgf_tag[3];
}
/* if its not a real tag, just take it as a comment */
if((sgf_tag[0]<'A') || (sgf_tag[0]>'Z'))
{
fprintf(stdout, "/* %s */\n", instring);
continue;
}
/* otherwise, write the tag and value to the file */
else
{
if(strlen(comment)) fprintf(stdout, " /* %s */\n", comment);
fprintf(stdout, "#define SGF%s %5d\n",
sgf_tag, str2short(sgf_tag));
}
}
/* need 0 exit status or else make fails */
return 0;
}
|