home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / games / volume15 / reversi2 / part01 < prev    next >
Encoding:
Internet Message Format  |  1993-01-26  |  54.8 KB

  1. Path: uunet!ogicse!news.u.washington.edu!uw-beaver!zephyr.ens.tek.com!master!saab!billr
  2. From: billr@saab.CNA.TEK.COM (Bill Randle)
  3. Newsgroups: comp.sources.games
  4. Subject: v15i018:  reversi2 - another reversi game, Part01/02
  5. Message-ID: <3833@master.CNA.TEK.COM>
  6. Date: 29 Oct 92 16:26:06 GMT
  7. Article-I.D.: master.3833
  8. Sender: news@master.CNA.TEK.COM
  9. Lines: 2228
  10. Approved: billr@saab.CNA.TEK.COM
  11. Xref: uunet comp.sources.games:1517
  12.  
  13. Submitted-by: esafern@shearson.COM (Eric Safern)
  14. Posting-number: Volume 15, Issue 18
  15. Archive-name: reversi2/Part01
  16. Environment: curses
  17.  
  18.     [Although this was submitted by Eric, he didn't write it. I couldn't
  19.      find any author information so if you recognize this, please send
  20.      me a note so I can give proper credit. I pieced together the README
  21.      file from looking at the code.  -br]
  22.  
  23. #! /bin/sh
  24. # This is a shell archive.  Remove anything before this line, then unpack
  25. # it by saving it into a file and typing "sh file".  To overwrite existing
  26. # files, type "sh file -c".  You can also feed this as standard input via
  27. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  28. # will see the following message at the end:
  29. #        "End of archive 1 (of 2)."
  30. # Contents:  README MANIFEST makeedge.c makeedge.y ulex.l user.y
  31. # Wrapped by billr@saab on Thu Oct 29 08:20:57 1992
  32. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  33. if test -f 'README' -a "${1}" != "-c" ; then 
  34.   echo shar: Will not clobber existing file \"'README'\"
  35. else
  36. echo shar: Extracting \"'README'\" \(1233 characters\)
  37. sed "s/^X//" >'README' <<'END_OF_FILE'
  38. XReversi plays a game of reversi between a computer and human player, between
  39. Xtwo computer players or two human players.
  40. X
  41. XCommand line arguments accepted are:
  42. X    -b computer is black
  43. X    -w computer is white
  44. X    -11 first player (human) is white
  45. X    -10 first player (human) is black
  46. X    -s show the score file
  47. X
  48. XOnce the game is started, help can be obtained by entering "help" at the
  49. Xprompt. "nohelp" removes the help text. Moves are entered as two numbers
  50. X(row column) seperated by a space and/or comma. Other commands are:
  51. X
  52. X    [no] grid            turn the grid on or off
  53. X    hint                provide a hint for the next move
  54. X    play white|black|both|none    selects which side the computer plays
  55. X    white|black first        selects which color goes first
  56. X    white|black second        selects which color goes second
  57. X    level number            selects the difficulty level
  58. X    [no] score            display (don't display) the score
  59. X    new                start a new game
  60. X    eval                give white's score at the current state
  61. X    record filename            record plays into a file
  62. X    replay filename            replay a previously recorded game
  63. X    save filename            save the game into a file
  64. X    undo                undo the previous move
  65. X    quit                quit the game
  66. X    debug <str>            where <str> is one or more of:
  67. X                        'm', 's' or '!'
  68. X    [no] help            turn help display on or off
  69. X
  70. END_OF_FILE
  71. if test 1233 -ne `wc -c <'README'`; then
  72.     echo shar: \"'README'\" unpacked with wrong size!
  73. fi
  74. # end of 'README'
  75. fi
  76. if test -f 'MANIFEST' -a "${1}" != "-c" ; then 
  77.   echo shar: Will not clobber existing file \"'MANIFEST'\"
  78. else
  79. echo shar: Extracting \"'MANIFEST'\" \(672 characters\)
  80. sed "s/^X//" >'MANIFEST' <<'END_OF_FILE'
  81. X   File Name        Archive #    Description
  82. X-----------------------------------------------------------
  83. X MANIFEST                   1    This shipping list
  84. X README                     1    
  85. X corners.c                  2    
  86. X count.c                    2    
  87. X display.c                  2    
  88. X edges.c                    2    
  89. X fini.c                     2    
  90. X genedge.c                  2    
  91. X hasmove.c                  2    
  92. X makeedge.c                 1    
  93. X makeedge.y                 1    
  94. X makefile                   2    
  95. X minmax.c                   2    
  96. X move.c                     2    
  97. X reversi.h                  2    
  98. X score.c                    2    
  99. X ulex.l                     1    
  100. X user.y                     1    
  101. END_OF_FILE
  102. if test 672 -ne `wc -c <'MANIFEST'`; then
  103.     echo shar: \"'MANIFEST'\" unpacked with wrong size!
  104. fi
  105. # end of 'MANIFEST'
  106. fi
  107. if test -f 'makeedge.c' -a "${1}" != "-c" ; then 
  108.   echo shar: Will not clobber existing file \"'makeedge.c'\"
  109. else
  110. echo shar: Extracting \"'makeedge.c'\" \(30399 characters\)
  111. sed "s/^X//" >'makeedge.c' <<'END_OF_FILE'
  112. Xextern char *malloc(), *realloc();
  113. X
  114. X# line 2 "makeedge.y"
  115. X/*
  116. X *    ex:set ts=8 sw=8:
  117. X */
  118. Xint    score;
  119. Xextern int    position;
  120. X
  121. X# line 8 "makeedge.y"
  122. Xtypedef union  {
  123. X    struct {
  124. X        int    width;
  125. X        int    position;
  126. X        int    base;
  127. X    } field;
  128. X    int    ival;
  129. X} YYSTYPE;
  130. X# define WHITE 257
  131. X# define BLACK 258
  132. X# define EMPTY 259
  133. X# define NL 260
  134. X#define yyclearin yychar = -1
  135. X#define yyerrok yyerrflag = 0
  136. Xextern int yychar;
  137. Xextern int yyerrflag;
  138. X#ifndef YYMAXDEPTH
  139. X#define YYMAXDEPTH 150
  140. X#endif
  141. XYYSTYPE yylval, yyval;
  142. X# define YYERRCODE 256
  143. X
  144. X# line 381 "makeedge.y"
  145. X
  146. X
  147. X# include    <stdio.h>
  148. X
  149. Xmain ()
  150. X{
  151. X    return yyparse ();
  152. X}
  153. X
  154. Xchar    line[80];
  155. Xchar    *lp = line;
  156. X
  157. Xyyerror (s)
  158. Xchar *s;
  159. X{
  160. X    fprintf (stderr, "%s in %s\n", s, line);
  161. X}
  162. X
  163. Xyywrap ()
  164. X{
  165. X    return 1;
  166. X}
  167. X
  168. Xint position = 1;
  169. X
  170. Xint base[] = { 0, 20, -30, 15, -5, -5, 15, -30, 20, 0 };
  171. X
  172. Xyylex ()
  173. X{
  174. X    char *gets();
  175. X
  176. X    if (*lp == '\0')
  177. X        if (fgets (line, 80, stdin) == 0)
  178. X            return -1;
  179. X        else
  180. X            lp = line;
  181. X    for (;;) {
  182. X        switch (*lp++) {
  183. X        case ' ':
  184. X        case '\t':
  185. X            break;
  186. X        case '\n':
  187. X            lp[-1] = '\0';
  188. X            position = 1;
  189. X            return NL;
  190. X        case 'O':
  191. X            yylval.field.base = -
  192. X                base[yylval.field.position = position++];
  193. X            yylval.field.width = 1;
  194. X            return BLACK;
  195. X        case '*':
  196. X            yylval.field.base =
  197. X                base[yylval.field.position = position++];
  198. X            yylval.field.width = 1;
  199. X            return WHITE;
  200. X        case '-':
  201. X            yylval.field.base = 0;
  202. X            yylval.field.position = position++;
  203. X            yylval.field.width = 1;
  204. X            return EMPTY;
  205. X        }
  206. X    }
  207. X}
  208. Xint yyexca[] ={
  209. X-1, 1,
  210. X    0, -1,
  211. X    -2, 0,
  212. X    };
  213. X# define YYNPROD 50
  214. X# define YYLAST 189
  215. Xint yyact[]={
  216. X
  217. X     6,    14,    12,     9,     7,    12,     6,     7,    26,     6,
  218. X    14,    50,     9,     7,    47,     6,    14,    41,     9,     7,
  219. X    38,     6,     7,    12,     6,     7,     5,    14,    12,     9,
  220. X    56,    12,    25,    36,    32,    22,     6,     7,     6,    26,
  221. X     7,    59,     1,    31,    30,    27,    29,    60,     4,    35,
  222. X    10,    37,    20,    21,    17,     2,     0,    46,     8,     0,
  223. X     0,     0,    33,     0,    13,     0,    39,    55,     0,     0,
  224. X    10,     0,     0,     0,     0,    49,     0,    66,     0,    69,
  225. X     0,    68,    45,     0,    72,    65,    74,    62,    63,    10,
  226. X    62,     0,     0,     0,    28,     0,     3,    71,    54,    15,
  227. X    19,    64,    78,     0,    58,    23,    80,     0,    39,     0,
  228. X    83,     0,    84,     0,     0,    42,     0,    81,    82,     0,
  229. X     0,     0,    62,    62,    52,    70,     0,     0,    15,    11,
  230. X    16,    18,    73,    57,    15,    61,    24,    75,    61,     0,
  231. X     0,    34,    67,    76,     0,    40,    43,    77,     0,    44,
  232. X     0,    79,     0,     0,    48,    51,     0,    42,     0,    53,
  233. X     0,     0,     0,     0,     0,    16,     0,     0,    11,     0,
  234. X    61,    61,     0,     0,     0,     0,     0,     0,     0,     0,
  235. X     0,     0,     0,     0,     0,     0,     0,    40,    43 };
  236. Xint yypact[]={
  237. X
  238. X -1000,  -233, -1000,  -254,  -257,  -236, -1000, -1000,  -225, -1000,
  239. X  -257,  -251, -1000,  -226, -1000,  -254,  -251,  -227,  -251,  -239,
  240. X  -242, -1000, -1000,  -254,  -251, -1000, -1000, -1000,  -245,  -248,
  241. X -1000, -1000, -1000,  -257,  -251, -1000, -1000,  -230,  -219,  -257,
  242. X  -251,  -218,  -254,  -251,  -251, -1000, -1000,  -219,  -251,  -231,
  243. X  -218,  -251,  -228,  -251, -1000, -1000, -1000,  -228, -1000, -1000,
  244. X -1000,  -254,  -257,  -231, -1000, -1000, -1000,  -228, -1000,  -221,
  245. X  -220,  -231, -1000,  -221, -1000,  -221,  -221,  -221, -1000,  -221,
  246. X -1000, -1000, -1000, -1000, -1000 };
  247. Xint yypgo[]={
  248. X
  249. X     0,    55,    94,    46,   125,    79,    58,    64,    41,    47,
  250. X    54,    32,    45,    44,    43,    42 };
  251. Xint yyr1[]={
  252. X
  253. X     0,    15,    15,     1,     1,     1,     1,     6,     6,     6,
  254. X     6,     6,     6,     7,     7,     7,     7,     7,     7,    11,
  255. X    11,     2,     2,     3,     3,     4,     4,     8,     8,    10,
  256. X    10,    10,     9,     9,     9,     9,     9,     9,    12,    12,
  257. X    12,    12,    12,    12,    12,    12,    13,    14,     5,     5 };
  258. Xint yyr2[]={
  259. X
  260. X     0,     5,     0,     7,     7,     7,     9,     9,     7,     7,
  261. X     3,     5,     1,     9,     7,     7,     3,     5,     1,     3,
  262. X     1,     5,     3,     5,     3,     5,     3,     3,     1,    11,
  263. X    11,     2,     7,     7,     7,     7,     3,     3,    11,     7,
  264. X    11,     7,     3,     3,     3,     3,     9,     9,     3,     1 };
  265. Xint yychk[]={
  266. X
  267. X -1000,   -15,    -1,    -2,    -3,   259,   257,   258,    -6,   257,
  268. X    -3,    -4,   259,    -7,   258,    -2,    -4,   -10,    -4,    -2,
  269. X    -3,    -9,   260,    -2,    -4,   -11,   259,   -12,    -2,    -3,
  270. X   -13,   -14,   260,    -3,    -4,   -11,   260,   -11,   259,    -3,
  271. X    -4,   259,    -2,    -4,    -4,    -6,   -11,   259,    -4,    -3,
  272. X   259,    -4,    -2,    -4,    -7,   -11,   260,    -2,    -7,    -8,
  273. X    -9,    -2,    -3,    -3,    -6,    -8,   -11,    -2,   -11,    -5,
  274. X    -4,    -3,   -11,    -5,   -11,    -5,    -5,    -5,   -11,    -5,
  275. X   -11,    -8,    -8,   -11,   -11 };
  276. Xint yydef[]={
  277. X
  278. X     2,    -2,     1,    12,    18,     0,    22,    24,     0,    21,
  279. X    10,    20,    26,     0,    23,    16,    20,     0,    20,    36,
  280. X    37,    31,     3,    12,    20,    11,    25,    19,    42,    43,
  281. X    44,    45,     4,    18,    20,    17,     5,     0,    26,    18,
  282. X    28,    26,    12,    28,    20,     8,     9,    26,    20,    49,
  283. X    26,    20,    49,    20,    14,    15,     6,    49,    32,    34,
  284. X    27,    36,    37,    49,    33,    35,     7,    49,    39,    20,
  285. X    48,    49,    41,    20,    13,    28,    28,    20,    46,    20,
  286. X    47,    29,    30,    38,    40 };
  287. Xtypedef struct { char *t_name; int t_val; } yytoktype;
  288. X#ifndef YYDEBUG
  289. X#    define YYDEBUG    0    /* don't allow debugging */
  290. X#endif
  291. X
  292. X#if YYDEBUG
  293. X
  294. Xyytoktype yytoks[] =
  295. X{
  296. X    "WHITE",    257,
  297. X    "BLACK",    258,
  298. X    "EMPTY",    259,
  299. X    "NL",    260,
  300. X    "-unknown-",    -1    /* ends search */
  301. X};
  302. X
  303. Xchar * yyreds[] =
  304. X{
  305. X    "-no such reduction-",
  306. X    "lines : lines line",
  307. X    "lines : /* empty */",
  308. X    "line : whites type1 NL",
  309. X    "line : blacks type2 NL",
  310. X    "line : EMPTY type3 NL",
  311. X    "line : EMPTY empties otype4 NL",
  312. X    "type1 : blacks whites empties otype4",
  313. X    "type1 : blacks whites type1",
  314. X    "type1 : blacks empties otype4",
  315. X    "type1 : blacks",
  316. X    "type1 : empties otype4",
  317. X    "type1 : /* empty */",
  318. X    "type2 : whites blacks empties otype4",
  319. X    "type2 : whites blacks type2",
  320. X    "type2 : whites empties otype4",
  321. X    "type2 : whites",
  322. X    "type2 : empties otype4",
  323. X    "type2 : /* empty */",
  324. X    "otype4 : type4",
  325. X    "otype4 : /* empty */",
  326. X    "whites : whites WHITE",
  327. X    "whites : WHITE",
  328. X    "blacks : blacks BLACK",
  329. X    "blacks : BLACK",
  330. X    "empties : empties EMPTY",
  331. X    "empties : EMPTY",
  332. X    "otype3e : type3e",
  333. X    "otype3e : /* empty */",
  334. X    "type3 : whites EMPTY whites oempties otype3e",
  335. X    "type3 : blacks EMPTY blacks oempties otype3e",
  336. X    "type3 : type3e",
  337. X    "type3e : whites blacks type2",
  338. X    "type3e : blacks whites type1",
  339. X    "type3e : whites empties otype3e",
  340. X    "type3e : blacks empties otype3e",
  341. X    "type3e : whites",
  342. X    "type3e : blacks",
  343. X    "type4 : whites EMPTY whites oempties otype4",
  344. X    "type4 : whites empties otype4",
  345. X    "type4 : blacks EMPTY blacks oempties otype4",
  346. X    "type4 : blacks empties otype4",
  347. X    "type4 : whites",
  348. X    "type4 : blacks",
  349. X    "type4 : type4.w",
  350. X    "type4 : type4.b",
  351. X    "type4.w : whites blacks oempties otype4",
  352. X    "type4.b : blacks whites oempties otype4",
  353. X    "oempties : empties",
  354. X    "oempties : /* empty */",
  355. X};
  356. X#endif /* YYDEBUG */
  357. X#line 1 "/usr/lib/yaccpar"
  358. X/*    @(#)yaccpar 1.10 89/04/04 SMI; from S5R3 1.10    */
  359. X
  360. X/*
  361. X** Skeleton parser driver for yacc output
  362. X*/
  363. X
  364. X/*
  365. X** yacc user known macros and defines
  366. X*/
  367. X#define YYERROR        goto yyerrlab
  368. X#define YYACCEPT    { free(yys); free(yyv); return(0); }
  369. X#define YYABORT        { free(yys); free(yyv); return(1); }
  370. X#define YYBACKUP( newtoken, newvalue )\
  371. X{\
  372. X    if ( yychar >= 0 || ( yyr2[ yytmp ] >> 1 ) != 1 )\
  373. X    {\
  374. X        yyerror( "syntax error - cannot backup" );\
  375. X        goto yyerrlab;\
  376. X    }\
  377. X    yychar = newtoken;\
  378. X    yystate = *yyps;\
  379. X    yylval = newvalue;\
  380. X    goto yynewstate;\
  381. X}
  382. X#define YYRECOVERING()    (!!yyerrflag)
  383. X#ifndef YYDEBUG
  384. X#    define YYDEBUG    1    /* make debugging available */
  385. X#endif
  386. X
  387. X/*
  388. X** user known globals
  389. X*/
  390. Xint yydebug;            /* set to 1 to get debugging */
  391. X
  392. X/*
  393. X** driver internal defines
  394. X*/
  395. X#define YYFLAG        (-1000)
  396. X
  397. X/*
  398. X** static variables used by the parser
  399. X*/
  400. Xstatic YYSTYPE *yyv;            /* value stack */
  401. Xstatic int *yys;            /* state stack */
  402. X
  403. Xstatic YYSTYPE *yypv;            /* top of value stack */
  404. Xstatic int *yyps;            /* top of state stack */
  405. X
  406. Xstatic int yystate;            /* current state */
  407. Xstatic int yytmp;            /* extra var (lasts between blocks) */
  408. X
  409. Xint yynerrs;            /* number of errors */
  410. X
  411. Xint yyerrflag;            /* error recovery flag */
  412. Xint yychar;            /* current input token number */
  413. X
  414. X
  415. X/*
  416. X** yyparse - return 0 if worked, 1 if syntax error not recovered from
  417. X*/
  418. Xint
  419. Xyyparse()
  420. X{
  421. X    register YYSTYPE *yypvt;    /* top of value stack for $vars */
  422. X    unsigned yymaxdepth = YYMAXDEPTH;
  423. X
  424. X    /*
  425. X    ** Initialize externals - yyparse may be called more than once
  426. X    */
  427. X    yyv = (YYSTYPE*)malloc(yymaxdepth*sizeof(YYSTYPE));
  428. X    yys = (int*)malloc(yymaxdepth*sizeof(int));
  429. X    if (!yyv || !yys)
  430. X    {
  431. X        yyerror( "out of memory" );
  432. X        return(1);
  433. X    }
  434. X    yypv = &yyv[-1];
  435. X    yyps = &yys[-1];
  436. X    yystate = 0;
  437. X    yytmp = 0;
  438. X    yynerrs = 0;
  439. X    yyerrflag = 0;
  440. X    yychar = -1;
  441. X
  442. X    goto yystack;
  443. X    {
  444. X        register YYSTYPE *yy_pv;    /* top of value stack */
  445. X        register int *yy_ps;        /* top of state stack */
  446. X        register int yy_state;        /* current state */
  447. X        register int  yy_n;        /* internal state number info */
  448. X
  449. X        /*
  450. X        ** get globals into registers.
  451. X        ** branch to here only if YYBACKUP was called.
  452. X        */
  453. X    yynewstate:
  454. X        yy_pv = yypv;
  455. X        yy_ps = yyps;
  456. X        yy_state = yystate;
  457. X        goto yy_newstate;
  458. X
  459. X        /*
  460. X        ** get globals into registers.
  461. X        ** either we just started, or we just finished a reduction
  462. X        */
  463. X    yystack:
  464. X        yy_pv = yypv;
  465. X        yy_ps = yyps;
  466. X        yy_state = yystate;
  467. X
  468. X        /*
  469. X        ** top of for (;;) loop while no reductions done
  470. X        */
  471. X    yy_stack:
  472. X        /*
  473. X        ** put a state and value onto the stacks
  474. X        */
  475. X#if YYDEBUG
  476. X        /*
  477. X        ** if debugging, look up token value in list of value vs.
  478. X        ** name pairs.  0 and negative (-1) are special values.
  479. X        ** Note: linear search is used since time is not a real
  480. X        ** consideration while debugging.
  481. X        */
  482. X        if ( yydebug )
  483. X        {
  484. X            register int yy_i;
  485. X
  486. X            (void)printf( "State %d, token ", yy_state );
  487. X            if ( yychar == 0 )
  488. X                (void)printf( "end-of-file\n" );
  489. X            else if ( yychar < 0 )
  490. X                (void)printf( "-none-\n" );
  491. X            else
  492. X            {
  493. X                for ( yy_i = 0; yytoks[yy_i].t_val >= 0;
  494. X                    yy_i++ )
  495. X                {
  496. X                    if ( yytoks[yy_i].t_val == yychar )
  497. X                        break;
  498. X                }
  499. X                (void)printf( "%s\n", yytoks[yy_i].t_name );
  500. X            }
  501. X        }
  502. X#endif /* YYDEBUG */
  503. X        if ( ++yy_ps >= &yys[ yymaxdepth ] )    /* room on stack? */
  504. X        {
  505. X            /*
  506. X            ** reallocate and recover.  Note that pointers
  507. X            ** have to be reset, or bad things will happen
  508. X            */
  509. X            int yyps_index = (yy_ps - yys);
  510. X            int yypv_index = (yy_pv - yyv);
  511. X            int yypvt_index = (yypvt - yyv);
  512. X            yymaxdepth += YYMAXDEPTH;
  513. X            yyv = (YYSTYPE*)realloc((char*)yyv,
  514. X                yymaxdepth * sizeof(YYSTYPE));
  515. X            yys = (int*)realloc((char*)yys,
  516. X                yymaxdepth * sizeof(int));
  517. X            if (!yyv || !yys)
  518. X            {
  519. X                yyerror( "yacc stack overflow" );
  520. X                return(1);
  521. X            }
  522. X            yy_ps = yys + yyps_index;
  523. X            yy_pv = yyv + yypv_index;
  524. X            yypvt = yyv + yypvt_index;
  525. X        }
  526. X        *yy_ps = yy_state;
  527. X        *++yy_pv = yyval;
  528. X
  529. X        /*
  530. X        ** we have a new state - find out what to do
  531. X        */
  532. X    yy_newstate:
  533. X        if ( ( yy_n = yypact[ yy_state ] ) <= YYFLAG )
  534. X            goto yydefault;        /* simple state */
  535. X#if YYDEBUG
  536. X        /*
  537. X        ** if debugging, need to mark whether new token grabbed
  538. X        */
  539. X        yytmp = yychar < 0;
  540. X#endif
  541. X        if ( ( yychar < 0 ) && ( ( yychar = yylex() ) < 0 ) )
  542. X            yychar = 0;        /* reached EOF */
  543. X#if YYDEBUG
  544. X        if ( yydebug && yytmp )
  545. X        {
  546. X            register int yy_i;
  547. X
  548. X            (void)printf( "Received token " );
  549. X            if ( yychar == 0 )
  550. X                (void)printf( "end-of-file\n" );
  551. X            else if ( yychar < 0 )
  552. X                (void)printf( "-none-\n" );
  553. X            else
  554. X            {
  555. X                for ( yy_i = 0; yytoks[yy_i].t_val >= 0;
  556. X                    yy_i++ )
  557. X                {
  558. X                    if ( yytoks[yy_i].t_val == yychar )
  559. X                        break;
  560. X                }
  561. X                (void)printf( "%s\n", yytoks[yy_i].t_name );
  562. X            }
  563. X        }
  564. X#endif /* YYDEBUG */
  565. X        if ( ( ( yy_n += yychar ) < 0 ) || ( yy_n >= YYLAST ) )
  566. X            goto yydefault;
  567. X        if ( yychk[ yy_n = yyact[ yy_n ] ] == yychar )    /*valid shift*/
  568. X        {
  569. X            yychar = -1;
  570. X            yyval = yylval;
  571. X            yy_state = yy_n;
  572. X            if ( yyerrflag > 0 )
  573. X                yyerrflag--;
  574. X            goto yy_stack;
  575. X        }
  576. X
  577. X    yydefault:
  578. X        if ( ( yy_n = yydef[ yy_state ] ) == -2 )
  579. X        {
  580. X#if YYDEBUG
  581. X            yytmp = yychar < 0;
  582. X#endif
  583. X            if ( ( yychar < 0 ) && ( ( yychar = yylex() ) < 0 ) )
  584. X                yychar = 0;        /* reached EOF */
  585. X#if YYDEBUG
  586. X            if ( yydebug && yytmp )
  587. X            {
  588. X                register int yy_i;
  589. X
  590. X                (void)printf( "Received token " );
  591. X                if ( yychar == 0 )
  592. X                    (void)printf( "end-of-file\n" );
  593. X                else if ( yychar < 0 )
  594. X                    (void)printf( "-none-\n" );
  595. X                else
  596. X                {
  597. X                    for ( yy_i = 0;
  598. X                        yytoks[yy_i].t_val >= 0;
  599. X                        yy_i++ )
  600. X                    {
  601. X                        if ( yytoks[yy_i].t_val
  602. X                            == yychar )
  603. X                        {
  604. X                            break;
  605. X                        }
  606. X                    }
  607. X                    (void)printf( "%s\n", yytoks[yy_i].t_name );
  608. X                }
  609. X            }
  610. X#endif /* YYDEBUG */
  611. X            /*
  612. X            ** look through exception table
  613. X            */
  614. X            {
  615. X                register int *yyxi = yyexca;
  616. X
  617. X                while ( ( *yyxi != -1 ) ||
  618. X                    ( yyxi[1] != yy_state ) )
  619. X                {
  620. X                    yyxi += 2;
  621. X                }
  622. X                while ( ( *(yyxi += 2) >= 0 ) &&
  623. X                    ( *yyxi != yychar ) )
  624. X                    ;
  625. X                if ( ( yy_n = yyxi[1] ) < 0 )
  626. X                    YYACCEPT;
  627. X            }
  628. X        }
  629. X
  630. X        /*
  631. X        ** check for syntax error
  632. X        */
  633. X        if ( yy_n == 0 )    /* have an error */
  634. X        {
  635. X            /* no worry about speed here! */
  636. X            switch ( yyerrflag )
  637. X            {
  638. X            case 0:        /* new error */
  639. X                yyerror( "syntax error" );
  640. X                goto skip_init;
  641. X            yyerrlab:
  642. X                /*
  643. X                ** get globals into registers.
  644. X                ** we have a user generated syntax type error
  645. X                */
  646. X                yy_pv = yypv;
  647. X                yy_ps = yyps;
  648. X                yy_state = yystate;
  649. X                yynerrs++;
  650. X            skip_init:
  651. X            case 1:
  652. X            case 2:        /* incompletely recovered error */
  653. X                    /* try again... */
  654. X                yyerrflag = 3;
  655. X                /*
  656. X                ** find state where "error" is a legal
  657. X                ** shift action
  658. X                */
  659. X                while ( yy_ps >= yys )
  660. X                {
  661. X                    yy_n = yypact[ *yy_ps ] + YYERRCODE;
  662. X                    if ( yy_n >= 0 && yy_n < YYLAST &&
  663. X                        yychk[yyact[yy_n]] == YYERRCODE)                    {
  664. X                        /*
  665. X                        ** simulate shift of "error"
  666. X                        */
  667. X                        yy_state = yyact[ yy_n ];
  668. X                        goto yy_stack;
  669. X                    }
  670. X                    /*
  671. X                    ** current state has no shift on
  672. X                    ** "error", pop stack
  673. X                    */
  674. X#if YYDEBUG
  675. X#    define _POP_ "Error recovery pops state %d, uncovers state %d\n"
  676. X                    if ( yydebug )
  677. X                        (void)printf( _POP_, *yy_ps,
  678. X                            yy_ps[-1] );
  679. X#    undef _POP_
  680. X#endif
  681. X                    yy_ps--;
  682. X                    yy_pv--;
  683. X                }
  684. X                /*
  685. X                ** there is no state on stack with "error" as
  686. X                ** a valid shift.  give up.
  687. X                */
  688. X                YYABORT;
  689. X            case 3:        /* no shift yet; eat a token */
  690. X#if YYDEBUG
  691. X                /*
  692. X                ** if debugging, look up token in list of
  693. X                ** pairs.  0 and negative shouldn't occur,
  694. X                ** but since timing doesn't matter when
  695. X                ** debugging, it doesn't hurt to leave the
  696. X                ** tests here.
  697. X                */
  698. X                if ( yydebug )
  699. X                {
  700. X                    register int yy_i;
  701. X
  702. X                    (void)printf( "Error recovery discards " );
  703. X                    if ( yychar == 0 )
  704. X                        (void)printf( "token end-of-file\n" );
  705. X                    else if ( yychar < 0 )
  706. X                        (void)printf( "token -none-\n" );
  707. X                    else
  708. X                    {
  709. X                        for ( yy_i = 0;
  710. X                            yytoks[yy_i].t_val >= 0;
  711. X                            yy_i++ )
  712. X                        {
  713. X                            if ( yytoks[yy_i].t_val
  714. X                                == yychar )
  715. X                            {
  716. X                                break;
  717. X                            }
  718. X                        }
  719. X                        (void)printf( "token %s\n",
  720. X                            yytoks[yy_i].t_name );
  721. X                    }
  722. X                }
  723. X#endif /* YYDEBUG */
  724. X                if ( yychar == 0 )    /* reached EOF. quit */
  725. X                    YYABORT;
  726. X                yychar = -1;
  727. X                goto yy_newstate;
  728. X            }
  729. X        }/* end if ( yy_n == 0 ) */
  730. X        /*
  731. X        ** reduction by production yy_n
  732. X        ** put stack tops, etc. so things right after switch
  733. X        */
  734. X#if YYDEBUG
  735. X        /*
  736. X        ** if debugging, print the string that is the user's
  737. X        ** specification of the reduction which is just about
  738. X        ** to be done.
  739. X        */
  740. X        if ( yydebug )
  741. X            (void)printf( "Reduce by (%d) \"%s\"\n",
  742. X                yy_n, yyreds[ yy_n ] );
  743. X#endif
  744. X        yytmp = yy_n;            /* value to switch over */
  745. X        yypvt = yy_pv;            /* $vars top of value stack */
  746. X        /*
  747. X        ** Look in goto table for next state
  748. X        ** Sorry about using yy_state here as temporary
  749. X        ** register variable, but why not, if it works...
  750. X        ** If yyr2[ yy_n ] doesn't have the low order bit
  751. X        ** set, then there is no action to be done for
  752. X        ** this reduction.  So, no saving & unsaving of
  753. X        ** registers done.  The only difference between the
  754. X        ** code just after the if and the body of the if is
  755. X        ** the goto yy_stack in the body.  This way the test
  756. X        ** can be made before the choice of what to do is needed.
  757. X        */
  758. X        {
  759. X            /* length of production doubled with extra bit */
  760. X            register int yy_len = yyr2[ yy_n ];
  761. X
  762. X            if ( !( yy_len & 01 ) )
  763. X            {
  764. X                yy_len >>= 1;
  765. X                yyval = ( yy_pv -= yy_len )[1];    /* $$ = $1 */
  766. X                yy_state = yypgo[ yy_n = yyr1[ yy_n ] ] +
  767. X                    *( yy_ps -= yy_len ) + 1;
  768. X                if ( yy_state >= YYLAST ||
  769. X                    yychk[ yy_state =
  770. X                    yyact[ yy_state ] ] != -yy_n )
  771. X                {
  772. X                    yy_state = yyact[ yypgo[ yy_n ] ];
  773. X                }
  774. X                goto yy_stack;
  775. X            }
  776. X            yy_len >>= 1;
  777. X            yyval = ( yy_pv -= yy_len )[1];    /* $$ = $1 */
  778. X            yy_state = yypgo[ yy_n = yyr1[ yy_n ] ] +
  779. X                *( yy_ps -= yy_len ) + 1;
  780. X            if ( yy_state >= YYLAST ||
  781. X                yychk[ yy_state = yyact[ yy_state ] ] != -yy_n )
  782. X            {
  783. X                yy_state = yyact[ yypgo[ yy_n ] ];
  784. X            }
  785. X        }
  786. X                    /* save until reenter driver code */
  787. X        yystate = yy_state;
  788. X        yyps = yy_ps;
  789. X        yypv = yy_pv;
  790. X    }
  791. X    /*
  792. X    ** code supplied by user is placed in this switch
  793. X    */
  794. X    switch( yytmp )
  795. X    {
  796. X        
  797. Xcase 1:
  798. X# line 22 "makeedge.y"
  799. X{ printf ("\t%5d,\t/*%s */\n", yypvt[-0].field.base, line); } break;
  800. Xcase 3:
  801. X# line 26 "makeedge.y"
  802. X{ yyval.field.base = 20 * yypvt[-2].field.width + yypvt[-1].field.base; } break;
  803. Xcase 4:
  804. X# line 28 "makeedge.y"
  805. X{ yyval.field.base = -20 * yypvt[-2].field.width + yypvt[-1].field.base; } break;
  806. Xcase 5:
  807. X# line 30 "makeedge.y"
  808. X{ yyval.field.base = yypvt[-1].field.base; } break;
  809. Xcase 6:
  810. X# line 32 "makeedge.y"
  811. X{ yyval.field.base = yypvt[-1].field.base; } break;
  812. Xcase 7:
  813. X# line 35 "makeedge.y"
  814. X{
  815. X                yyval.field.base = yypvt[-0].field.base;
  816. X                switch (yypvt[-2].field.position) {
  817. X                case 7:
  818. X                    yyval.field.base -= (yypvt[-2].field.width + yypvt[-3].field.width+1) * 15;
  819. X                    break;
  820. X                default:
  821. X                    if (yypvt[-1].field.width == 1)
  822. X                        yyval.field.base -=
  823. X                        (yypvt[-3].field.width + yypvt[-2].field.width+1) * 15;
  824. X                    else
  825. X                        yyval.field.base +=
  826. X                        (yypvt[-2].field.width - yypvt[-3].field.width) * 20;
  827. X                    break;
  828. X                }
  829. X                yyval.field.position = yypvt[-0].field.position;
  830. X                yyval.field.width = yypvt[-3].field.width + yypvt[-2].field.width + yypvt[-1].field.width;
  831. X            } break;
  832. Xcase 8:
  833. X# line 54 "makeedge.y"
  834. X{
  835. X                yyval.field.base = yypvt[-0].field.base;
  836. X                yyval.field.base -= (yypvt[-2].field.width - yypvt[-1].field.width) * 20;
  837. X                yyval.field.position = yypvt[-0].field.position;
  838. X                yyval.field.width = yypvt[-2].field.width + yypvt[-1].field.width + yypvt[-0].field.width;
  839. X            } break;
  840. Xcase 9:
  841. X# line 61 "makeedge.y"
  842. X{
  843. X                yyval.field.base = (yypvt[-2].field.width + 1) * 15 + yypvt[-0].field.base;
  844. X                yyval.field.width = yypvt[-2].field.width + yypvt[-1].field.width + yypvt[-0].field.width;
  845. X                yyval.field.position = yypvt[-0].field.position;
  846. X            } break;
  847. Xcase 10:
  848. X# line 67 "makeedge.y"
  849. X{
  850. X                yyval.field = yypvt[-0].field;
  851. X                yyval.field.base = - yypvt[-0].field.width * 20;
  852. X            } break;
  853. Xcase 11:
  854. X# line 72 "makeedge.y"
  855. X{
  856. X                yyval.field.position = yypvt[-0].field.position;
  857. X                yyval.field.width = yypvt[-1].field.width+yypvt[-0].field.width;
  858. X                yyval.field.base = yypvt[-0].field.base;
  859. X            } break;
  860. Xcase 12:
  861. X# line 78 "makeedge.y"
  862. X{ yyval.field.position = position; yyval.field.width = 0; yyval.field.base = 0; } break;
  863. Xcase 13:
  864. X# line 81 "makeedge.y"
  865. X{
  866. X                yyval.field.base = yypvt[-0].field.base;
  867. X                switch (yypvt[-2].field.position) {
  868. X                case 7:
  869. X                    yyval.field.base += (yypvt[-2].field.width + yypvt[-3].field.width+1) * 15;
  870. X                    break;
  871. X                default:
  872. X                    if (yypvt[-1].field.width == 1)
  873. X                        yyval.field.base +=
  874. X                        (yypvt[-3].field.width + yypvt[-2].field.width+1) * 15;
  875. X                    else
  876. X                        yyval.field.base -=
  877. X                        (yypvt[-2].field.width - yypvt[-3].field.width) * 20;
  878. X                    break;
  879. X                }
  880. X                yyval.field.position = yypvt[-0].field.position;
  881. X                yyval.field.width = yypvt[-3].field.width + yypvt[-2].field.width + yypvt[-1].field.width
  882. X                     + yypvt[-0].field.width;
  883. X            } break;
  884. Xcase 14:
  885. X# line 101 "makeedge.y"
  886. X{
  887. X                yyval.field.base = yypvt[-0].field.base;
  888. X                yyval.field.base += (yypvt[-2].field.width - yypvt[-1].field.width) * 20;
  889. X                yyval.field.position = yypvt[-0].field.position;
  890. X                yyval.field.width = yypvt[-2].field.width + yypvt[-1].field.width + yypvt[-0].field.width;
  891. X            } break;
  892. Xcase 15:
  893. X# line 108 "makeedge.y"
  894. X{
  895. X                yyval.field.base = - (yypvt[-2].field.width + 1) * 15 + yypvt[-0].field.base;
  896. X                yyval.field.width = yypvt[-2].field.width + yypvt[-1].field.width + yypvt[-0].field.width;
  897. X                yyval.field.position = yypvt[-0].field.position;
  898. X            } break;
  899. Xcase 16:
  900. X# line 114 "makeedge.y"
  901. X{
  902. X                yyval.field = yypvt[-0].field;
  903. X                yyval.field.base = yypvt[-0].field.width * 20;
  904. X            } break;
  905. Xcase 17:
  906. X# line 119 "makeedge.y"
  907. X{
  908. X                yyval.field.position = yypvt[-0].field.position;
  909. X                yyval.field.width = yypvt[-1].field.width+yypvt[-0].field.width;
  910. X                yyval.field.base = yypvt[-0].field.base;
  911. X            } break;
  912. Xcase 18:
  913. X# line 125 "makeedge.y"
  914. X{ yyval.field.position = 0; yyval.field.width = 0; yyval.field.base = 0; } break;
  915. Xcase 19:
  916. X# line 128 "makeedge.y"
  917. X{ yyval.field = yypvt[-0].field; } break;
  918. Xcase 20:
  919. X# line 130 "makeedge.y"
  920. X{ yyval.field.position = position; yyval.field.width = 0; yyval.field.base = 0; } break;
  921. Xcase 21:
  922. X# line 133 "makeedge.y"
  923. X{
  924. X                yyval.field.position = yypvt[-0].field.position;
  925. X                yyval.field.width = yypvt[-1].field.width + yypvt[-0].field.width;
  926. X                yyval.field.base = yypvt[-1].field.base + yypvt[-0].field.base;
  927. X            } break;
  928. Xcase 22:
  929. X# line 139 "makeedge.y"
  930. X{ yyval.field = yypvt[-0].field; } break;
  931. Xcase 23:
  932. X# line 142 "makeedge.y"
  933. X{
  934. X                yyval.field.position = yypvt[-0].field.position;
  935. X                yyval.field.width = yypvt[-1].field.width + yypvt[-0].field.width;
  936. X                yyval.field.base = yypvt[-1].field.base + yypvt[-0].field.base;
  937. X            } break;
  938. Xcase 24:
  939. X# line 148 "makeedge.y"
  940. X{ yyval.field = yypvt[-0].field; } break;
  941. Xcase 25:
  942. X# line 151 "makeedge.y"
  943. X{
  944. X                yyval.field.position = yypvt[-0].field.position;
  945. X                yyval.field.width = yypvt[-1].field.width + yypvt[-0].field.width;
  946. X                yyval.field.base = yypvt[-1].field.base + yypvt[-0].field.base;
  947. X            } break;
  948. Xcase 26:
  949. X# line 157 "makeedge.y"
  950. X{ yyval.field = yypvt[-0].field; } break;
  951. Xcase 27:
  952. X# line 160 "makeedge.y"
  953. X{ yyval.field = yypvt[-0].field; } break;
  954. Xcase 28:
  955. X# line 162 "makeedge.y"
  956. X{ yyval.field.position = position; yyval.field.width = 0; yyval.field.base = 0; } break;
  957. Xcase 29:
  958. X# line 165 "makeedge.y"
  959. X{
  960. X                yyval.field.base = -(yypvt[-4].field.width + yypvt[-2].field.width + 2) * 15 +
  961. X                    yypvt[-0].field.base;
  962. X                yyval.field.width = yypvt[-4].field.width + yypvt[-3].field.width + yypvt[-2].field.width 
  963. X                     + yypvt[-1].field.width + yypvt[-0].field.width;
  964. X                yyval.field.position = yypvt[-0].field.position;
  965. X            } break;
  966. Xcase 30:
  967. X# line 173 "makeedge.y"
  968. X{
  969. X                yyval.field.base = (yypvt[-4].field.width + yypvt[-2].field.width + 2) * 15 +
  970. X                    yypvt[-0].field.base;
  971. X                yyval.field.width = yypvt[-4].field.width + yypvt[-3].field.width + yypvt[-2].field.width 
  972. X                     + yypvt[-1].field.width + yypvt[-0].field.width;
  973. X                yyval.field.position = yypvt[-0].field.position;
  974. X            } break;
  975. Xcase 32:
  976. X# line 183 "makeedge.y"
  977. X{
  978. X                yyval.field.base = -15 * (yypvt[-2].field.width + yypvt[-1].field.width + 1);
  979. X                yyval.field.width = yypvt[-2].field.width + yypvt[-1].field.width + yypvt[-0].field.width;
  980. X                yyval.field.position = yypvt[-0].field.position;
  981. X            } break;
  982. Xcase 33:
  983. X# line 189 "makeedge.y"
  984. X{
  985. X                yyval.field.base = 15 * (yypvt[-2].field.width + yypvt[-1].field.width + 1);
  986. X                yyval.field.width = yypvt[-2].field.width + yypvt[-1].field.width + yypvt[-0].field.width;
  987. X                yyval.field.position = yypvt[-0].field.position;
  988. X            } break;
  989. Xcase 34:
  990. X# line 195 "makeedge.y"
  991. X{
  992. X                if (yypvt[-2].field.position - yypvt[-2].field.width == 1) {
  993. X                    switch (yypvt[-2].field.width) {
  994. X                    case 1:
  995. X                        yyval.field.base = -30;
  996. X                        break;
  997. X                    case 6:
  998. X                        yyval.field.base = -20;
  999. X                        break;
  1000. X                    case 2:
  1001. X                        yyval.field.base = -15;
  1002. X                        break;
  1003. X                    case 3:
  1004. X                        yyval.field.base = -10;
  1005. X                        break;
  1006. X                    case 4:
  1007. X                        yyval.field.base = -5;
  1008. X                        break;
  1009. X                    case 5:
  1010. X                        yyval.field.base = 10;
  1011. X                        break;
  1012. X                    default:
  1013. X                        yyerror ("weirdo");
  1014. X                        break;
  1015. X                    }
  1016. X                } else {
  1017. X                    yyval.field.base = yypvt[-2].field.base;
  1018. X                }
  1019. X                yyval.field.base += yypvt[-0].field.base;
  1020. X                yyval.field.position = yypvt[-0].field.position;
  1021. X                yyval.field.width = yypvt[-2].field.width + yypvt[-1].field.width + yypvt[-0].field.width;
  1022. X            } break;
  1023. Xcase 35:
  1024. X# line 228 "makeedge.y"
  1025. X{
  1026. X                if (yypvt[-2].field.position - yypvt[-2].field.width == 1) {
  1027. X                    switch (yypvt[-2].field.width) {
  1028. X                    case 1:
  1029. X                        yyval.field.base = 30;
  1030. X                        break;
  1031. X                    case 6:
  1032. X                        yyval.field.base = 20;
  1033. X                    break;
  1034. X                    case 2:
  1035. X                        yyval.field.base = 15;
  1036. X                        break;
  1037. X                    case 3:
  1038. X                        yyval.field.base = 10;
  1039. X                        break;
  1040. X                    case 4:
  1041. X                        yyval.field.base = 5;
  1042. X                        break;
  1043. X                    case 5:
  1044. X                        yyval.field.base = -10;
  1045. X                        break;
  1046. X                    default:
  1047. X                        yyerror ("weirdo");
  1048. X                        break;
  1049. X                    }
  1050. X                } else {
  1051. X                    yyval.field.base = yypvt[-2].field.base;
  1052. X                }
  1053. X                yyval.field.base += yypvt[-0].field.base;
  1054. X                yyval.field.position = yypvt[-0].field.position;
  1055. X                yyval.field.width = yypvt[-2].field.width + yypvt[-1].field.width + yypvt[-0].field.width;
  1056. X            } break;
  1057. Xcase 36:
  1058. X# line 261 "makeedge.y"
  1059. X{
  1060. X                yyval.field.base = 20 * yypvt[-0].field.width;
  1061. X                yyval.field.position = yypvt[-0].field.position;
  1062. X                yyval.field.width = yypvt[-0].field.width;
  1063. X            } break;
  1064. Xcase 37:
  1065. X# line 267 "makeedge.y"
  1066. X{
  1067. X                yyval.field.base = -20 * yypvt[-0].field.width;
  1068. X                yyval.field.position = yypvt[-0].field.position;
  1069. X                yyval.field.width = yypvt[-0].field.width;
  1070. X            } break;
  1071. Xcase 38:
  1072. X# line 274 "makeedge.y"
  1073. X{
  1074. X            if (yypvt[-1].field.position == 8) {
  1075. X                yyval.field.base = -(yypvt[-4].field.width + yypvt[-2].field.width + 2) * 15;
  1076. X            } else {
  1077. X                yyval.field.base = 0;
  1078. X                if (yypvt[-4].field.position - yypvt[-4].field.width + 1 == 3)
  1079. X                    yyval.field.base = yypvt[-4].field.width * 15;
  1080. X                else
  1081. X                    yyval.field.base = yypvt[-4].field.base;
  1082. X                if (yypvt[-2].field.position == 6)
  1083. X                    yyval.field.base += yypvt[-2].field.width * 15;
  1084. X                else
  1085. X                    yyval.field.base += yypvt[-2].field.base;
  1086. X                yyval.field.base += yypvt[-0].field.base;
  1087. X            }
  1088. X            yyval.field.width = yypvt[-4].field.width + yypvt[-3].field.width + yypvt[-2].field.width
  1089. X                 + yypvt[-1].field.width + yypvt[-0].field.width;
  1090. X            yyval.field.position = yypvt[-0].field.position;
  1091. X        } break;
  1092. Xcase 39:
  1093. X# line 294 "makeedge.y"
  1094. X{
  1095. X                if (yypvt[-2].field.position - yypvt[-2].field.width + 1 == 3)
  1096. X                    yyval.field.base = yypvt[-2].field.width * 15 + yypvt[-0].field.base;
  1097. X                else if (yypvt[-2].field.position == 6)
  1098. X                    yyval.field.base = yypvt[-2].field.width * 15 + yypvt[-0].field.base;
  1099. X                else
  1100. X                    yyval.field.base = yypvt[-2].field.base + yypvt[-0].field.base;
  1101. X                yyval.field.position = yypvt[-0].field.position;
  1102. X                yyval.field.width = yypvt[-2].field.width + yypvt[-1].field.width + yypvt[-0].field.width;
  1103. X            } break;
  1104. Xcase 40:
  1105. X# line 305 "makeedge.y"
  1106. X{
  1107. X            if (yypvt[-1].field.position == 8) {
  1108. X                yyval.field.base = (yypvt[-4].field.width + yypvt[-2].field.width + 2) * 15;
  1109. X            } else {
  1110. X                yyval.field.base = 0;
  1111. X                if (yypvt[-4].field.position - yypvt[-4].field.width + 1 == 3)
  1112. X                    yyval.field.base = -yypvt[-4].field.width * 15;
  1113. X                else
  1114. X                    yyval.field.base = yypvt[-4].field.base;
  1115. X                if (yypvt[-2].field.position == 6)
  1116. X                    yyval.field.base +=  -yypvt[-2].field.width * 15;
  1117. X                else
  1118. X                    yyval.field.base += yypvt[-2].field.base;
  1119. X                yyval.field.base += yypvt[-0].field.base;
  1120. X            }
  1121. X            yyval.field.width = yypvt[-4].field.width + yypvt[-3].field.width + yypvt[-2].field.width
  1122. X                 + yypvt[-1].field.width + yypvt[-0].field.width;
  1123. X            yyval.field.position = yypvt[-0].field.position;
  1124. X        } break;
  1125. Xcase 41:
  1126. X# line 325 "makeedge.y"
  1127. X{
  1128. X                if (yypvt[-2].field.position - yypvt[-2].field.width + 1 == 3)
  1129. X                    yyval.field.base = -yypvt[-2].field.width * 15 + yypvt[-0].field.base;
  1130. X                else if (yypvt[-2].field.position == 6)
  1131. X                    yyval.field.base = -yypvt[-2].field.width * 15 + yypvt[-0].field.base;
  1132. X                else
  1133. X                    yyval.field.base = yypvt[-2].field.base + yypvt[-0].field.base;
  1134. X                yyval.field.position = yypvt[-0].field.position;
  1135. X                yyval.field.width = yypvt[-2].field.width + yypvt[-1].field.width + yypvt[-0].field.width;
  1136. X            } break;
  1137. Xcase 42:
  1138. X# line 336 "makeedge.y"
  1139. X{
  1140. X                yyval.field.base = 20 * yypvt[-0].field.width;
  1141. X                yyval.field.position = yypvt[-0].field.position;
  1142. X                yyval.field.width = yypvt[-0].field.width;
  1143. X            } break;
  1144. Xcase 43:
  1145. X# line 342 "makeedge.y"
  1146. X{
  1147. X                yyval.field.base = -20 * yypvt[-0].field.width;
  1148. X                yyval.field.position = yypvt[-0].field.position;
  1149. X                yyval.field.width = yypvt[-0].field.width;
  1150. X            } break;
  1151. Xcase 44:
  1152. X# line 348 "makeedge.y"
  1153. X{ yyval.field = yypvt[-0].field; } break;
  1154. Xcase 45:
  1155. X# line 350 "makeedge.y"
  1156. X{ yyval.field = yypvt[-0].field; } break;
  1157. Xcase 46:
  1158. X# line 353 "makeedge.y"
  1159. X{
  1160. X            if (yypvt[-2].field.position == 8)
  1161. X                yyval.field.base = - (yypvt[-3].field.width + yypvt[-2].field.width + 1) * 15;
  1162. X            else if (yypvt[-1].field.position == 8 && yypvt[-1].field.width == 1)
  1163. X                yyval.field.base = (yypvt[-3].field.width + yypvt[-2].field.width + 1) * 10;
  1164. X            else
  1165. X                yyval.field.base = yypvt[-3].field.base + yypvt[-2].field.base + yypvt[-0].field.base;
  1166. X            yyval.field.position = yypvt[-0].field.position;
  1167. X            yyval.field.width = yypvt[-3].field.width + yypvt[-2].field.width + yypvt[-1].field.width + yypvt[-0].field.width;
  1168. X        } break;
  1169. Xcase 47:
  1170. X# line 365 "makeedge.y"
  1171. X{
  1172. X            if (yypvt[-2].field.position == 8)
  1173. X                yyval.field.base = (yypvt[-3].field.width + yypvt[-2].field.width + 1) * 15;
  1174. X            else if (yypvt[-1].field.position == 8 && yypvt[-1].field.width == 1)
  1175. X                yyval.field.base = - (yypvt[-3].field.width + yypvt[-2].field.width + 1) * 10;
  1176. X            else
  1177. X                yyval.field.base = yypvt[-3].field.base + yypvt[-2].field.base + yypvt[-0].field.base;
  1178. X            yyval.field.position = yypvt[-0].field.position;
  1179. X            yyval.field.width = yypvt[-3].field.width + yypvt[-2].field.width + yypvt[-1].field.width + yypvt[-0].field.width;
  1180. X        } break;
  1181. Xcase 48:
  1182. X# line 377 "makeedge.y"
  1183. X{ yyval.field = yypvt[-0].field; } break;
  1184. Xcase 49:
  1185. X# line 379 "makeedge.y"
  1186. X{ yyval.field.position = position; yyval.field.width = 0; yyval.field.base = 0; } break;
  1187. X    }
  1188. X    goto yystack;        /* reset registers in driver code */
  1189. X}
  1190. END_OF_FILE
  1191. if test 30399 -ne `wc -c <'makeedge.c'`; then
  1192.     echo shar: \"'makeedge.c'\" unpacked with wrong size!
  1193. fi
  1194. # end of 'makeedge.c'
  1195. fi
  1196. if test -f 'makeedge.y' -a "${1}" != "-c" ; then 
  1197.   echo shar: Will not clobber existing file \"'makeedge.y'\"
  1198. else
  1199. echo shar: Extracting \"'makeedge.y'\" \(9001 characters\)
  1200. sed "s/^X//" >'makeedge.y' <<'END_OF_FILE'
  1201. X%{
  1202. X/*
  1203. X *    ex:set ts=8 sw=8:
  1204. X */
  1205. Xint    score;
  1206. Xextern int    position;
  1207. X%}
  1208. X%union {
  1209. X    struct {
  1210. X        int    width;
  1211. X        int    position;
  1212. X        int    base;
  1213. X    } field;
  1214. X    int    ival;
  1215. X}
  1216. X%type  <field>    line whites blacks empties oempties
  1217. X%type  <field>    type1 type2 otype3e type3e type3 otype4 type4 type4.w type4.b
  1218. X%token <field>    WHITE BLACK EMPTY
  1219. X%token <ival>    NL
  1220. X%%
  1221. Xlines    :    lines line
  1222. X            { printf ("\t%5d,\t/*%s */\n", $2.base, line); }
  1223. X    |
  1224. X    ;
  1225. Xline    :    whites type1 NL
  1226. X            { $$.base = 20 * $1.width + $2.base; }
  1227. X    |    blacks type2 NL
  1228. X            { $$.base = -20 * $1.width + $2.base; }
  1229. X    |    EMPTY type3 NL
  1230. X            { $$.base = $2.base; }
  1231. X    |    EMPTY empties otype4 NL
  1232. X            { $$.base = $3.base; }
  1233. X    ;
  1234. Xtype1    :    blacks whites empties otype4
  1235. X            {
  1236. X                $$.base = $4.base;
  1237. X                switch ($2.position) {
  1238. X                case 7:
  1239. X                    $$.base -= ($2.width + $1.width+1) * 15;
  1240. X                    break;
  1241. X                default:
  1242. X                    if ($3.width == 1)
  1243. X                        $$.base -=
  1244. X                        ($1.width + $2.width+1) * 15;
  1245. X                    else
  1246. X                        $$.base +=
  1247. X                        ($2.width - $1.width) * 20;
  1248. X                    break;
  1249. X                }
  1250. X                $$.position = $4.position;
  1251. X                $$.width = $1.width + $2.width + $3.width;
  1252. X            }
  1253. X    |    blacks whites type1
  1254. X            {
  1255. X                $$.base = $3.base;
  1256. X                $$.base -= ($1.width - $2.width) * 20;
  1257. X                $$.position = $3.position;
  1258. X                $$.width = $1.width + $2.width + $3.width;
  1259. X            }
  1260. X    |    blacks empties otype4
  1261. X            {
  1262. X                $$.base = ($1.width + 1) * 15 + $3.base;
  1263. X                $$.width = $1.width + $2.width + $3.width;
  1264. X                $$.position = $3.position;
  1265. X            }
  1266. X    |    blacks
  1267. X            {
  1268. X                $$ = $1;
  1269. X                $$.base = - $1.width * 20;
  1270. X            }
  1271. X    |    empties otype4
  1272. X            {
  1273. X                $$.position = $2.position;
  1274. X                $$.width = $1.width+$2.width;
  1275. X                $$.base = $2.base;
  1276. X            }
  1277. X    |
  1278. X            { $$.position = position; $$.width = 0; $$.base = 0; }
  1279. X    ;
  1280. Xtype2    :    whites blacks empties otype4
  1281. X            {
  1282. X                $$.base = $4.base;
  1283. X                switch ($2.position) {
  1284. X                case 7:
  1285. X                    $$.base += ($2.width + $1.width+1) * 15;
  1286. X                    break;
  1287. X                default:
  1288. X                    if ($3.width == 1)
  1289. X                        $$.base +=
  1290. X                        ($1.width + $2.width+1) * 15;
  1291. X                    else
  1292. X                        $$.base -=
  1293. X                        ($2.width - $1.width) * 20;
  1294. X                    break;
  1295. X                }
  1296. X                $$.position = $4.position;
  1297. X                $$.width = $1.width + $2.width + $3.width
  1298. X                     + $4.width;
  1299. X            }
  1300. X    |    whites blacks type2
  1301. X            {
  1302. X                $$.base = $3.base;
  1303. X                $$.base += ($1.width - $2.width) * 20;
  1304. X                $$.position = $3.position;
  1305. X                $$.width = $1.width + $2.width + $3.width;
  1306. X            }
  1307. X    |    whites empties otype4
  1308. X            {
  1309. X                $$.base = - ($1.width + 1) * 15 + $3.base;
  1310. X                $$.width = $1.width + $2.width + $3.width;
  1311. X                $$.position = $3.position;
  1312. X            }
  1313. X    |    whites
  1314. X            {
  1315. X                $$ = $1;
  1316. X                $$.base = $1.width * 20;
  1317. X            }
  1318. X    |    empties otype4
  1319. X            {
  1320. X                $$.position = $2.position;
  1321. X                $$.width = $1.width+$2.width;
  1322. X                $$.base = $2.base;
  1323. X            }
  1324. X    |
  1325. X        { $$.position = 0; $$.width = 0; $$.base = 0; }
  1326. X    ;
  1327. Xotype4    :    type4
  1328. X            { $$ = $1; }
  1329. X    |
  1330. X            { $$.position = position; $$.width = 0; $$.base = 0; }
  1331. X    ;
  1332. Xwhites    :    whites WHITE
  1333. X            {
  1334. X                $$.position = $2.position;
  1335. X                $$.width = $1.width + $2.width;
  1336. X                $$.base = $1.base + $2.base;
  1337. X            }
  1338. X    |    WHITE
  1339. X            { $$ = $1; }
  1340. X    ;
  1341. Xblacks    :    blacks BLACK
  1342. X            {
  1343. X                $$.position = $2.position;
  1344. X                $$.width = $1.width + $2.width;
  1345. X                $$.base = $1.base + $2.base;
  1346. X            }
  1347. X    |    BLACK
  1348. X            { $$ = $1; }
  1349. X    ;
  1350. Xempties    :    empties EMPTY
  1351. X            {
  1352. X                $$.position = $2.position;
  1353. X                $$.width = $1.width + $2.width;
  1354. X                $$.base = $1.base + $2.base;
  1355. X            }
  1356. X    |    EMPTY
  1357. X            { $$ = $1; }
  1358. X    ;
  1359. Xotype3e    :    type3e
  1360. X            { $$ = $1; }
  1361. X    |
  1362. X            { $$.position = position; $$.width = 0; $$.base = 0; }
  1363. X    ;
  1364. Xtype3    :    whites EMPTY whites oempties otype3e
  1365. X            {
  1366. X                $$.base = -($1.width + $3.width + 2) * 15 +
  1367. X                    $5.base;
  1368. X                $$.width = $1.width + $2.width + $3.width 
  1369. X                     + $4.width + $5.width;
  1370. X                $$.position = $5.position;
  1371. X            }
  1372. X    |    blacks EMPTY blacks oempties otype3e
  1373. X            {
  1374. X                $$.base = ($1.width + $3.width + 2) * 15 +
  1375. X                    $5.base;
  1376. X                $$.width = $1.width + $2.width + $3.width 
  1377. X                     + $4.width + $5.width;
  1378. X                $$.position = $5.position;
  1379. X            }
  1380. X    |    type3e
  1381. X    ;
  1382. Xtype3e    :    whites blacks type2
  1383. X            {
  1384. X                $$.base = -15 * ($1.width + $2.width + 1);
  1385. X                $$.width = $1.width + $2.width + $3.width;
  1386. X                $$.position = $3.position;
  1387. X            }
  1388. X    |    blacks whites type1
  1389. X            {
  1390. X                $$.base = 15 * ($1.width + $2.width + 1);
  1391. X                $$.width = $1.width + $2.width + $3.width;
  1392. X                $$.position = $3.position;
  1393. X            }
  1394. X    |    whites empties otype3e
  1395. X            {
  1396. X                if ($1.position - $1.width == 1) {
  1397. X                    switch ($1.width) {
  1398. X                    case 1:
  1399. X                        $$.base = -30;
  1400. X                        break;
  1401. X                    case 6:
  1402. X                        $$.base = -20;
  1403. X                        break;
  1404. X                    case 2:
  1405. X                        $$.base = -15;
  1406. X                        break;
  1407. X                    case 3:
  1408. X                        $$.base = -10;
  1409. X                        break;
  1410. X                    case 4:
  1411. X                        $$.base = -5;
  1412. X                        break;
  1413. X                    case 5:
  1414. X                        $$.base = 10;
  1415. X                        break;
  1416. X                    default:
  1417. X                        yyerror ("weirdo");
  1418. X                        break;
  1419. X                    }
  1420. X                } else {
  1421. X                    $$.base = $1.base;
  1422. X                }
  1423. X                $$.base += $3.base;
  1424. X                $$.position = $3.position;
  1425. X                $$.width = $1.width + $2.width + $3.width;
  1426. X            }
  1427. X    |    blacks empties otype3e
  1428. X            {
  1429. X                if ($1.position - $1.width == 1) {
  1430. X                    switch ($1.width) {
  1431. X                    case 1:
  1432. X                        $$.base = 30;
  1433. X                        break;
  1434. X                    case 6:
  1435. X                        $$.base = 20;
  1436. X                    break;
  1437. X                    case 2:
  1438. X                        $$.base = 15;
  1439. X                        break;
  1440. X                    case 3:
  1441. X                        $$.base = 10;
  1442. X                        break;
  1443. X                    case 4:
  1444. X                        $$.base = 5;
  1445. X                        break;
  1446. X                    case 5:
  1447. X                        $$.base = -10;
  1448. X                        break;
  1449. X                    default:
  1450. X                        yyerror ("weirdo");
  1451. X                        break;
  1452. X                    }
  1453. X                } else {
  1454. X                    $$.base = $1.base;
  1455. X                }
  1456. X                $$.base += $3.base;
  1457. X                $$.position = $3.position;
  1458. X                $$.width = $1.width + $2.width + $3.width;
  1459. X            }
  1460. X    |    whites
  1461. X            {
  1462. X                $$.base = 20 * $1.width;
  1463. X                $$.position = $1.position;
  1464. X                $$.width = $1.width;
  1465. X            }
  1466. X    |    blacks
  1467. X            {
  1468. X                $$.base = -20 * $1.width;
  1469. X                $$.position = $1.position;
  1470. X                $$.width = $1.width;
  1471. X            }
  1472. X    ;
  1473. Xtype4    :    whites EMPTY whites oempties otype4
  1474. X        {
  1475. X            if ($4.position == 8) {
  1476. X                $$.base = -($1.width + $3.width + 2) * 15;
  1477. X            } else {
  1478. X                $$.base = 0;
  1479. X                if ($1.position - $1.width + 1 == 3)
  1480. X                    $$.base = $1.width * 15;
  1481. X                else
  1482. X                    $$.base = $1.base;
  1483. X                if ($3.position == 6)
  1484. X                    $$.base += $3.width * 15;
  1485. X                else
  1486. X                    $$.base += $3.base;
  1487. X                $$.base += $5.base;
  1488. X            }
  1489. X            $$.width = $1.width + $2.width + $3.width
  1490. X                 + $4.width + $5.width;
  1491. X            $$.position = $5.position;
  1492. X        }
  1493. X    |    whites empties otype4
  1494. X            {
  1495. X                if ($1.position - $1.width + 1 == 3)
  1496. X                    $$.base = $1.width * 15 + $3.base;
  1497. X                else if ($1.position == 6)
  1498. X                    $$.base = $1.width * 15 + $3.base;
  1499. X                else
  1500. X                    $$.base = $1.base + $3.base;
  1501. X                $$.position = $3.position;
  1502. X                $$.width = $1.width + $2.width + $3.width;
  1503. X            }
  1504. X    |    blacks EMPTY blacks oempties otype4
  1505. X        {
  1506. X            if ($4.position == 8) {
  1507. X                $$.base = ($1.width + $3.width + 2) * 15;
  1508. X            } else {
  1509. X                $$.base = 0;
  1510. X                if ($1.position - $1.width + 1 == 3)
  1511. X                    $$.base = -$1.width * 15;
  1512. X                else
  1513. X                    $$.base = $1.base;
  1514. X                if ($3.position == 6)
  1515. X                    $$.base +=  -$3.width * 15;
  1516. X                else
  1517. X                    $$.base += $3.base;
  1518. X                $$.base += $5.base;
  1519. X            }
  1520. X            $$.width = $1.width + $2.width + $3.width
  1521. X                 + $4.width + $5.width;
  1522. X            $$.position = $5.position;
  1523. X        }
  1524. X    |    blacks empties otype4
  1525. X            {
  1526. X                if ($1.position - $1.width + 1 == 3)
  1527. X                    $$.base = -$1.width * 15 + $3.base;
  1528. X                else if ($1.position == 6)
  1529. X                    $$.base = -$1.width * 15 + $3.base;
  1530. X                else
  1531. X                    $$.base = $1.base + $3.base;
  1532. X                $$.position = $3.position;
  1533. X                $$.width = $1.width + $2.width + $3.width;
  1534. X            }
  1535. X    |    whites
  1536. X            {
  1537. X                $$.base = 20 * $1.width;
  1538. X                $$.position = $1.position;
  1539. X                $$.width = $1.width;
  1540. X            }
  1541. X    |    blacks
  1542. X            {
  1543. X                $$.base = -20 * $1.width;
  1544. X                $$.position = $1.position;
  1545. X                $$.width = $1.width;
  1546. X            }
  1547. X    |    type4.w
  1548. X            { $$ = $1; }
  1549. X    |    type4.b
  1550. X            { $$ = $1; }
  1551. X    ;
  1552. Xtype4.w    :    whites blacks oempties otype4
  1553. X        {
  1554. X            if ($2.position == 8)
  1555. X                $$.base = - ($1.width + $2.width + 1) * 15;
  1556. X            else if ($3.position == 8 && $3.width == 1)
  1557. X                $$.base = ($1.width + $2.width + 1) * 10;
  1558. X            else
  1559. X                $$.base = $1.base + $2.base + $4.base;
  1560. X            $$.position = $4.position;
  1561. X            $$.width = $1.width + $2.width + $3.width + $4.width;
  1562. X        }
  1563. X    ;
  1564. Xtype4.b    :    blacks whites oempties otype4
  1565. X        {
  1566. X            if ($2.position == 8)
  1567. X                $$.base = ($1.width + $2.width + 1) * 15;
  1568. X            else if ($3.position == 8 && $3.width == 1)
  1569. X                $$.base = - ($1.width + $2.width + 1) * 10;
  1570. X            else
  1571. X                $$.base = $1.base + $2.base + $4.base;
  1572. X            $$.position = $4.position;
  1573. X            $$.width = $1.width + $2.width + $3.width + $4.width;
  1574. X        }
  1575. X    ;
  1576. Xoempties:    empties
  1577. X            { $$ = $1; }
  1578. X    |
  1579. X            { $$.position = position; $$.width = 0; $$.base = 0; }
  1580. X    ;
  1581. X%%
  1582. X
  1583. X# include    <stdio.h>
  1584. X
  1585. Xmain ()
  1586. X{
  1587. X    return yyparse ();
  1588. X}
  1589. X
  1590. Xchar    line[80];
  1591. Xchar    *lp = line;
  1592. X
  1593. Xyyerror (s)
  1594. Xchar *s;
  1595. X{
  1596. X    fprintf (stderr, "%s in %s\n", s, line);
  1597. X}
  1598. X
  1599. Xyywrap ()
  1600. X{
  1601. X    return 1;
  1602. X}
  1603. X
  1604. Xint position = 1;
  1605. X
  1606. Xint base[] = { 0, 20, -30, 15, -5, -5, 15, -30, 20, 0 };
  1607. X
  1608. Xyylex ()
  1609. X{
  1610. X    char *gets();
  1611. X
  1612. X    if (*lp == '\0')
  1613. X        if (fgets (line, 80, stdin) == 0)
  1614. X            return -1;
  1615. X        else
  1616. X            lp = line;
  1617. X    for (;;) {
  1618. X        switch (*lp++) {
  1619. X        case ' ':
  1620. X        case '\t':
  1621. X            break;
  1622. X        case '\n':
  1623. X            lp[-1] = '\0';
  1624. X            position = 1;
  1625. X            return NL;
  1626. X        case 'O':
  1627. X            yylval.field.base = -
  1628. X                base[yylval.field.position = position++];
  1629. X            yylval.field.width = 1;
  1630. X            return BLACK;
  1631. X        case '*':
  1632. X            yylval.field.base =
  1633. X                base[yylval.field.position = position++];
  1634. X            yylval.field.width = 1;
  1635. X            return WHITE;
  1636. X        case '-':
  1637. X            yylval.field.base = 0;
  1638. X            yylval.field.position = position++;
  1639. X            yylval.field.width = 1;
  1640. X            return EMPTY;
  1641. X        }
  1642. X    }
  1643. X}
  1644. END_OF_FILE
  1645. if test 9001 -ne `wc -c <'makeedge.y'`; then
  1646.     echo shar: \"'makeedge.y'\" unpacked with wrong size!
  1647. fi
  1648. # end of 'makeedge.y'
  1649. fi
  1650. if test -f 'ulex.l' -a "${1}" != "-c" ; then 
  1651.   echo shar: Will not clobber existing file \"'ulex.l'\"
  1652. else
  1653. echo shar: Extracting \"'ulex.l'\" \(1162 characters\)
  1654. sed "s/^X//" >'ulex.l' <<'END_OF_FILE'
  1655. X%{
  1656. X/*
  1657. X *    ex:set ts=8 sw=8:
  1658. X */
  1659. X# include    "y.tab.h"
  1660. Xextern int    yylval;
  1661. Xextern char    sbuf[];
  1662. X#undef input
  1663. X#define input()    lexgetc()
  1664. X#undef unput
  1665. X#define unput(c)    lexungetc(c)
  1666. X%}
  1667. X%%
  1668. X[ \t]        ;
  1669. X\004        return EOG;
  1670. Xblack        { yylval = -1; return BL; }
  1671. Xboth        return BOTH;
  1672. Xcomputer    return COMPUTER;
  1673. Xdebug        return DEBUG;
  1674. Xeval        return EVAL;
  1675. Xfile        return FILEe;
  1676. Xfirst        return FIRST;
  1677. Xfrom        return FROM;
  1678. Xgame        return GAME;
  1679. Xgrid        return GRID;
  1680. Xhelp        return HELP;
  1681. Xhint        return HINT;
  1682. Xhuman        return HUMAN;
  1683. Xinto        return INTO;
  1684. Xlevel        return LEVEL;
  1685. Xme        return HUMAN;
  1686. Xmove        return MOVE;
  1687. Xnew        return NEW;
  1688. Xneither        return NEITHER;
  1689. Xno        return NO;
  1690. Xnogrid        return NOGRID;
  1691. Xnohelp        return NOHELP;
  1692. Xnoscore        return NOSCORE;
  1693. Xnone        return NONE;
  1694. Xplay        return PLAY;
  1695. Xquit        return QUIT;
  1696. Xrecord        return RECORD;
  1697. Xreplay        return REPLAY;
  1698. Xrestart        return RESTART;
  1699. Xsave        return SAVE;
  1700. Xscore        return SCORE;
  1701. Xsecond        return SECOND;
  1702. Xto        return TO;
  1703. Xundo        return UNDO;
  1704. Xwhite        { yylval =  1; return WH; }
  1705. Xyou        return COMPUTER;
  1706. X\n        return NL;
  1707. X[0-9]+        { yylval = atoi (yytext); return NUMBER; }
  1708. X","        return COMMA;
  1709. X";"        return SEMI;
  1710. X\"[^"]*\"    { strcpy (sbuf, yytext+1); sbuf[yyleng-2]='\0'; return STRING; }
  1711. X.        return ERR;
  1712. END_OF_FILE
  1713. if test 1162 -ne `wc -c <'ulex.l'`; then
  1714.     echo shar: \"'ulex.l'\" unpacked with wrong size!
  1715. fi
  1716. # end of 'ulex.l'
  1717. fi
  1718. if test -f 'user.y' -a "${1}" != "-c" ; then 
  1719.   echo shar: Will not clobber existing file \"'user.y'\"
  1720. else
  1721. echo shar: Extracting \"'user.y'\" \(7739 characters\)
  1722. sed "s/^X//" >'user.y' <<'END_OF_FILE'
  1723. X%{
  1724. X/*
  1725. X *    ex:set ts=8 sw=8:
  1726. X *    user interface
  1727. X */
  1728. X
  1729. X# include    "reversi.h"
  1730. X# include    <stdio.h>
  1731. X# include    <signal.h>
  1732. X
  1733. XboardT    board, saveBoard;
  1734. Xint    saved;
  1735. Xint    savePlayer;
  1736. Xint    atend;
  1737. Xint    atbegin;
  1738. Xint    level;
  1739. Xint    player;
  1740. Xextern int    maxlev, movex, movey;
  1741. Xint    com;
  1742. Xint    gotsignal;
  1743. Xchar    sbuf[80];
  1744. Xchar    ebuf[80];
  1745. Xint    sdebug = 0, mdebug = 0;
  1746. Xint    record = 0;
  1747. XFILE    *rfile;
  1748. Xint    first = WHITE;
  1749. Xint    defcom = BLACK;
  1750. Xint    showScore = 1;
  1751. X
  1752. Xstruct move {
  1753. X    int    p, x, y;
  1754. X};
  1755. X
  1756. Xstruct move    saveGame[64];
  1757. Xstruct move    *saveP;
  1758. X
  1759. X%}
  1760. X%token    MOVE LEVEL COMPUTER UNDO HINT PLAY
  1761. X%token    RECORD REPLAY SAVE
  1762. X%token    RESTART NEW GAME QUIT
  1763. X%token    GRID NOGRID HELP NOHELP SCORE NOSCORE
  1764. X%token    DEBUG EVAL
  1765. X%token    FROM INTO TO FILEe NO
  1766. X%token    NUMBER COMMA NL STRING SEMI EOG ERR
  1767. X%token    WH BL HUMAN BOTH NEITHER NONE FIRST SECOND
  1768. X%%
  1769. Xgame    :    game commands NL prompt
  1770. X    |    prompt
  1771. X    ;
  1772. Xprompt    :
  1773. X    {
  1774. X        if (!atend) {
  1775. X            loop:    ;
  1776. X            dispTurn (player);
  1777. X            if (!hasmove (player, board)) {
  1778. X                if (!hasmove (-player, board)) {
  1779. X                    fini (board);
  1780. X                    if (com == 0)
  1781. X                        com = BLACK;
  1782. X                    ++atend;
  1783. X                    dispTurn (EMPTY);
  1784. X                    goto nomove;
  1785. X                } else {
  1786. X                    if (player == WHITE)
  1787. X                        dispError ("white has no move");
  1788. X                    else
  1789. X                        dispError ("black has no move");
  1790. X                    player = -player;
  1791. X                }
  1792. X            }
  1793. X            if (com == 0 || com == player) {
  1794. X                dispError ("thinking...");
  1795. X                if (computer (player, board, level)) {
  1796. X                    atbegin = 0;
  1797. X                    sprintf (ebuf, "I move to %d, %d\n",
  1798. X                        movex, movey);
  1799. X                    dispError (ebuf);
  1800. X                    saveP->x = movex;
  1801. X                    saveP->y = movey;
  1802. X                    saveP->p = player;
  1803. X                    ++saveP;
  1804. X                    if (record)
  1805. X                        fprintf (rfile, "%d: %d,%d\n",
  1806. X                            player, movex, movey);
  1807. X                    player = -player;
  1808. X                    display (board);
  1809. X                    if (gotsignal && com != 0)
  1810. X                        gotsignal = 0;
  1811. X                }
  1812. X                if (gotsignal && com == 0) {
  1813. X                    com = -player;
  1814. X                    gotsignal = 0;
  1815. X                }
  1816. X                goto loop;
  1817. X            }
  1818. X        }
  1819. X    nomove:    ;
  1820. X        readLine ();
  1821. X    }
  1822. X    ;
  1823. Xcommands:    commands SEMI command
  1824. X    |    command
  1825. X    |    error oerror
  1826. X        {
  1827. X            dispHelp ();
  1828. X        }
  1829. X    ;
  1830. Xcommand    :    
  1831. X    |    EOG
  1832. X        {
  1833. X            YYACCEPT;
  1834. X        }
  1835. X    |    omove NUMBER ocomma NUMBER
  1836. X        {
  1837. X            if (1 <= $2 && $2 <= SIZE &&
  1838. X                1 <= $4 && $4 <= SIZE &&
  1839. X                legal (player, $2, $4, board)) {
  1840. X                copy (saveBoard, board);
  1841. X                savePlayer = player;
  1842. X                ++saved;
  1843. X                move (player, $2, $4, board);
  1844. X                atbegin = 0;
  1845. X                if (record)
  1846. X                    fprintf (rfile, "%d: %d,%d\n",
  1847. X                        player, $2, $4);
  1848. X                saveP->x = $2;
  1849. X                saveP->y = $4;
  1850. X                saveP->p = player;
  1851. X                ++saveP;
  1852. X                player = -player;
  1853. X                display (board);
  1854. X            } else {
  1855. X                sprintf (ebuf, "illegal move: %d, %d", $2, $4);
  1856. X                dispError (ebuf);
  1857. X            }
  1858. X        }
  1859. X    |    DEBUG STRING
  1860. X        {
  1861. X            register char    *s;
  1862. X            register int    v;
  1863. X
  1864. X            v = 1;
  1865. X            for (s = sbuf; *s; ++s)
  1866. X                switch (*s) {
  1867. X                case 'm':
  1868. X                    mdebug = v;
  1869. X                    break;
  1870. X                case 's':
  1871. X                    sdebug = v;
  1872. X                    break;
  1873. X                case '!':
  1874. X                    v = !v;
  1875. X                    break;
  1876. X                }
  1877. X        }
  1878. X    |    GRID
  1879. X        {
  1880. X            dispGrid ();
  1881. X        }
  1882. X    |    NO GRID
  1883. X        {
  1884. X            dispNoGrid ();
  1885. X        }
  1886. X    |    NOGRID
  1887. X        {
  1888. X            dispNoGrid ();
  1889. X        }
  1890. X    |    SCORE
  1891. X        {
  1892. X            showScore = 1;
  1893. X            dispScore (board);
  1894. X        }
  1895. X    |    NOSCORE
  1896. X        {
  1897. X            showScore = 0;
  1898. X            dispNoScore ();
  1899. X        }
  1900. X    |    NO SCORE
  1901. X        {
  1902. X            showScore = 0;
  1903. X            dispNoScore ();
  1904. X        }
  1905. X    |    LEVEL NUMBER
  1906. X        {
  1907. X            level = $2;
  1908. X        }
  1909. X    |    LEVEL oerror
  1910. X        {
  1911. X            sprintf (ebuf, "current level is %d", level);
  1912. X            dispError (ebuf);
  1913. X        }
  1914. X    |    PLAY whichp
  1915. X        {
  1916. X            if ($2 == WHITE || $2 == BLACK) 
  1917. X                defcom = $2;
  1918. X            com = $2;
  1919. X        }
  1920. X    |    PLAY oerror
  1921. X        {
  1922. X            dispError ("play (white black both none)");
  1923. X        }
  1924. X    |    whichp FIRST
  1925. X        {
  1926. X            if ($1 == WHITE || $1 == BLACK)
  1927. X                first = $1;
  1928. X            if (atbegin)
  1929. X                player = first;
  1930. X        }
  1931. X    |    FIRST oerror
  1932. X        {
  1933. X            dispError ("(white black you me) first");
  1934. X        }
  1935. X    |    whichp SECOND
  1936. X        {
  1937. X            if ($1 == WHITE || $1 == BLACK)
  1938. X                first = - $1;
  1939. X            if (atbegin)
  1940. X                player = first;
  1941. X        }
  1942. X    |    SECOND oerror
  1943. X        {
  1944. X            dispError ("(white black you me) second");
  1945. X        }
  1946. X    |    HELP
  1947. X        {
  1948. X            dispHelp ();
  1949. X        }
  1950. X    |    NOHELP
  1951. X        {
  1952. X            dispNoHelp ();
  1953. X        }
  1954. X    |    NO HELP
  1955. X        {
  1956. X            dispNoHelp ();
  1957. X        }
  1958. X    |    QUIT
  1959. X        {
  1960. X            YYACCEPT;
  1961. X        }
  1962. X    |    UNDO
  1963. X        {
  1964. X            if (saved) {
  1965. X                copy (board, saveBoard);
  1966. X                player = savePlayer;
  1967. X                saved = 0;
  1968. X                display (board);
  1969. X            }
  1970. X        }
  1971. X    |    NEW ogame eoc
  1972. X        {
  1973. X            YYABORT;
  1974. X        }
  1975. X    |    RESTART eoc
  1976. X        {
  1977. X            YYABORT;
  1978. X        }
  1979. X    |    EVAL
  1980. X        {
  1981. X            sprintf (ebuf, "score: %d\n", score (board, WHITE));
  1982. X            dispError (ebuf);
  1983. X        }
  1984. X    |    RECORD ointo ofile STRING
  1985. X        {
  1986. X            if ((rfile = fopen (sbuf, "w")) == NULL) {
  1987. X                sprintf (ebuf, "could not open %s", sbuf);
  1988. X                dispError (ebuf);
  1989. X                record = 0;
  1990. X            } else
  1991. X                ++record;
  1992. X        }
  1993. X    |    RECORD oerror
  1994. X        {
  1995. X            dispError ("record \"file\"");
  1996. X        }
  1997. X    |    REPLAY whichp ofrom ofile STRING
  1998. X        {
  1999. X            replay ($2, sbuf);
  2000. X        }
  2001. X    |    REPLAY oerror
  2002. X        {
  2003. X            dispError ("replay (both white black) \"file\"");
  2004. X        }
  2005. X    |    SAVE ointo ofile STRING
  2006. X        {
  2007. X            struct move    *m;
  2008. X
  2009. X            if ((rfile = fopen (sbuf, "w")) == NULL) {
  2010. X                sprintf (ebuf, "could not open %s", sbuf);
  2011. X                dispError (ebuf);
  2012. X            } else {
  2013. X                m = saveGame;
  2014. X                fprintf (rfile, "%d: -1,-1\n", m->p);
  2015. X                for (; m != saveP; m++)
  2016. X                    fprintf (rfile, "%d: %d,%d\n",
  2017. X                        m->p, m->x, m->y);
  2018. X                fclose (rfile);
  2019. X                rfile = 0;
  2020. X            }
  2021. X        }
  2022. X    |    SAVE oerror
  2023. X        {
  2024. X            dispError ("save \"file\"");
  2025. X        }
  2026. X    |    HINT
  2027. X        {
  2028. X            if (hasmove (player, board)) {
  2029. X                char    buf[80];
  2030. X                hint (player, board, level);
  2031. X                sprintf (buf, "I suggest %d, %d", movex, movey);
  2032. X                dispError (buf);
  2033. X            }
  2034. X        }
  2035. X    ;
  2036. Xeoc    :    SEMI
  2037. X    |    NL
  2038. X    ;
  2039. Xomove    :    MOVE
  2040. X    |
  2041. X    ;
  2042. Xogame    :    GAME
  2043. X    |
  2044. X    ;
  2045. Xocomma    :    COMMA
  2046. X    |
  2047. X    ;
  2048. Xoerror    :    oerror error
  2049. X        {
  2050. X            yyerrok;
  2051. X        }
  2052. X    |    oerror ERR
  2053. X    |
  2054. X    ;
  2055. Xointo    :    TO
  2056. X    |    INTO
  2057. X    |
  2058. X    ;
  2059. Xofrom    :    FROM
  2060. X    |
  2061. X    ;
  2062. Xofile    :    FILEe
  2063. X    |
  2064. X    ;
  2065. Xwhichp    :    WH
  2066. X        { $$ = WHITE; }
  2067. X    |    BL
  2068. X        { $$ = BLACK; }
  2069. X    |    COMPUTER
  2070. X        { $$ = com==WHITE?WHITE:BLACK; }
  2071. X    |    HUMAN
  2072. X        { $$ = com==WHITE?BLACK:WHITE; }
  2073. X    |    BOTH
  2074. X        { $$ = 0; }
  2075. X    |    none
  2076. X        { $$ = 2; }
  2077. X    ;
  2078. Xnone    :    NONE
  2079. X    |    NEITHER
  2080. X    ;
  2081. X%%
  2082. Xyyerror (s)
  2083. Xchar    *s;
  2084. X{
  2085. X    dispError (s);
  2086. X}
  2087. X
  2088. Xcaught ()
  2089. X{
  2090. X    gotsignal++;
  2091. X    signal (SIGINT, caught);
  2092. X}
  2093. X
  2094. Xmain (argc, argv)
  2095. Xchar **argv;
  2096. X{
  2097. X    signal (SIGINT, caught);
  2098. X    level = 2;
  2099. X    dispInit ();
  2100. X    srand (getpid());
  2101. X    while (*++argv && **argv == '-') {
  2102. X        while (*++*argv) {
  2103. X            switch (**argv) {
  2104. X            case 'b':
  2105. X                defcom = BLACK;
  2106. X                break;
  2107. X            case 'w':
  2108. X                defcom = WHITE;
  2109. X                break;
  2110. X            case '1':
  2111. X                if (!*++*argv)
  2112. X                    continue;
  2113. X                if (**argv == WHITE)
  2114. X                    first = WHITE;
  2115. X                else
  2116. X                    first = BLACK;
  2117. X                break;
  2118. X            case 'g':
  2119. X                dispGrid ();
  2120. X                break;
  2121. X            case 's':
  2122. X                showScore = 1;
  2123. X            }
  2124. X        }
  2125. X    }
  2126. X    do {
  2127. X        if (rfile)
  2128. X            fclose (rfile);
  2129. X        rfile = 0;
  2130. X        player = first;
  2131. X        com = defcom;
  2132. X        atend = 0;
  2133. X        atbegin = 1;
  2134. X        setup ();
  2135. X        saved = 0;
  2136. X        saveP = saveGame;
  2137. X        display (board);
  2138. X        if (*argv) {
  2139. X            replay (0, *argv);
  2140. X            ++argv;
  2141. X        }
  2142. X    } while (yyparse ());
  2143. X    dispEnd ();
  2144. X}
  2145. X
  2146. Xyywrap ()
  2147. X{
  2148. X    return 1;
  2149. X}
  2150. X
  2151. Xsetup ()
  2152. X{
  2153. X    register int    i,j;
  2154. X
  2155. X    for (i = 1; i <= SIZE; i++)
  2156. X        for (j = 1; j <= SIZE; j++)
  2157. X            board[i][j] = 0;
  2158. X    board[4][4] = WHITE;
  2159. X    board[4][5] = BLACK;
  2160. X    board[5][4] = BLACK;
  2161. X    board[5][5] = WHITE;
  2162. X}
  2163. X
  2164. Xreplay (who, file)
  2165. Xchar *file;
  2166. X{
  2167. X    int    x, y, p;
  2168. X    if (rfile)
  2169. X        fclose (rfile);
  2170. X    if ((rfile = fopen (file, "r")) == NULL) {
  2171. X        sprintf (ebuf, "could not open %s", file);
  2172. X        dispError (ebuf);
  2173. X        return;
  2174. X    }
  2175. X    while (fscanf (rfile, "%d: %d, %d\n", &p, &x, &y) == 3) {
  2176. X        if (x == -1 && y == -1) {
  2177. X            player = p;
  2178. X            continue;
  2179. X        }
  2180. X        if (!hasmove (player, board)) {
  2181. X            player = -player;
  2182. X            if (!hasmove (player, board))
  2183. X                return;
  2184. X        }
  2185. X        if (p != player) {
  2186. X            sprintf (ebuf, "not %s's turn\n",
  2187. X                player == WHITE? "white":"black");
  2188. X            dispError (ebuf);
  2189. X            return;
  2190. X        }
  2191. X        if (who == 0 || p == who) {
  2192. X            if (!legal (p, x, y, board)) {
  2193. X                sprintf(ebuf, "illegal move: %d, %d\n", x, y);
  2194. X                dispError (ebuf);
  2195. X                return;
  2196. X            }
  2197. X            move (p, x, y, board);
  2198. X            atbegin = 0;
  2199. X            player = -player;
  2200. X            display (board);
  2201. X        }
  2202. X        else if (player == com) {
  2203. X            if (hasmove (player, board)) {
  2204. X                dispError ("thinking...");
  2205. X                dispTurn (EMPTY);
  2206. X                if (computer (player, board, level)) {
  2207. X                    dispError ("");
  2208. X                    atbegin = 0;
  2209. X                    player = -player;
  2210. X                    display (board);
  2211. X                }
  2212. X            }
  2213. X        }
  2214. X    }
  2215. X    fclose (rfile);
  2216. X    rfile = 0;
  2217. X}
  2218. END_OF_FILE
  2219. if test 7739 -ne `wc -c <'user.y'`; then
  2220.     echo shar: \"'user.y'\" unpacked with wrong size!
  2221. fi
  2222. # end of 'user.y'
  2223. fi
  2224. echo shar: End of archive 1 \(of 2\).
  2225. cp /dev/null ark1isdone
  2226. MISSING=""
  2227. for I in 1 2 ; do
  2228.     if test ! -f ark${I}isdone ; then
  2229.     MISSING="${MISSING} ${I}"
  2230.     fi
  2231. done
  2232. if test "${MISSING}" = "" ; then
  2233.     echo You have unpacked both archives.
  2234.     rm -f ark[1-9]isdone
  2235. else
  2236.     echo You still need to unpack the following archives:
  2237.     echo "        " ${MISSING}
  2238. fi
  2239. ##  End of shell archive.
  2240. exit 0
  2241.