home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume20 / notation / part03 / drivers.c next >
Encoding:
C/C++ Source or Header  |  1991-06-18  |  19.6 KB  |  818 lines

  1. /*
  2.   Notation program
  3.   @(#)drivers.c    3.1 (C) Henry Thomas\tVersion 3.1\tDated 6/16/91
  4.  */
  5.  
  6. #ifdef __STDC__
  7. #include <stdlib.h>
  8. #endif
  9. #include<stdio.h>
  10.  
  11. #include <ctype.h>
  12. #include "chesstype.h"
  13. #include "notation.h"
  14. #include "drivers.h"
  15.  
  16. /* postscript characters translation table
  17.    one entry per piece
  18.    each entry has four fields:
  19.    - white piece on white case
  20.    - white piece on black case
  21.    - black piece on ...
  22.    ..
  23.  */
  24. #define PSINDEX(a,b) ((((a)==WHITE)?0:2)+(((b)%2)?0:1))
  25.  
  26. static char * postscript_table[][4] = {
  27.   { " ", "x",     " ", "x"     }, /* void */
  28.   { "k", "\\373", "K", "\\360" }, /* king */
  29.   { "q", "\\317", "Q", "\\316" }, /* queen */
  30.   { "r", "\\250", "R", "\\345" }, /* rook */
  31.   { "b", "\\272", "B", "\\365" }, /* bishop */
  32.   { "n", "\\265", "N", "\\366" }, /* knight */
  33.   { "p", "\\271", "P", "\\270" }  /* pawn */
  34. };
  35.  
  36. /* TeX table for using the chess figure in board design */
  37. static char * metafont_table[][4] = {
  38.   /*   W/W      W/B      B/W      B/B */
  39.   { "\\WWW", "\\DDD", "\\WWW", "\\DDD" }, /* void */
  40.   { "\\WKW", "\\WKB", "\\BKW", "\\BKB" }, /* king */
  41.   { "\\WQW", "\\WQB", "\\BQW", "\\BQB" }, /* queen */
  42.   { "\\WRW", "\\WRB", "\\BRW", "\\BRB" }, /* rook */
  43.   { "\\WBW", "\\WBB", "\\BBW", "\\BBB" }, /* bishop */
  44.   { "\\WNW", "\\WNB", "\\BNW", "\\BNB" }, /* knight */
  45.   { "\\WPW", "\\WPB", "\\BPW", "\\BPB" }  /* pawn */
  46. };
  47.  
  48. /* TeX table for using the chess figures in move description */
  49. static char * latex_table[] = {
  50.   "\\FigVoid", "\\FigK", "\\FigQ", "\\FigR", "\\FigB", "\\FigN", "\\FigP"
  51. };
  52.  
  53. /* various tex symbols */
  54. static char FigDash[] = "\\FigDash";
  55. static char FigCapt[] = "\\FigCapt";
  56. static char FigDots[] = "\\FigDots";
  57. static char FigDot[] = "\\FigDot";
  58.  
  59. #define G_ROQUE  "O-O-O" 
  60. #define P_ROQUE  "O-O" 
  61.  
  62. /* variation symbols */
  63. static char varsymb[][2] = { { '[', ']' }, { '(', ')' } };
  64.  
  65. static char * com_tex[] = {
  66. #define CHESSSYMB(LET,LASC,SASC,TEX,PS,ENG,FRA) TEX,
  67. #include "chesssymb.def"
  68.  ""
  69.  };
  70. #undef CHESSSYMB
  71.  
  72. static char * com_ps[] = {
  73. #define CHESSSYMB(LET,LASC,SASC,TEX,PS,ENG,FRA) PS,
  74. #include "chesssymb.def"
  75.  ""
  76.  };
  77. #undef CHESSSYMB
  78.  
  79. static FILE * ftmp ;
  80.  
  81.  
  82. /* ---------------- output functions ---------------- */
  83.  
  84. /* convert a roque in term of king's move */
  85. #ifdef __STDC__
  86. static int roque_to_move(depl *m)
  87. #else
  88. static int roque_to_move(m)
  89.      depl * m;
  90. #endif
  91. {
  92.  
  93.   m->piece = KING;
  94.   m->fromcol   = 5;
  95.   if (m->type == GRANDROQUE)  
  96.     m->tocol = 3;
  97.   else
  98.     m->tocol = 7;
  99.  
  100.   if (m->whiteturn)
  101.     m->fromlig = m->tolig = 1;
  102.   else
  103.     m->fromlig = m->tolig = 8;
  104.  
  105.   return(TRUE);
  106. }
  107.  
  108. /* (kind of) buffering of output */
  109. #ifdef __STDC__
  110. static void init_buffer(format *d, int side)
  111. #else
  112. static void init_buffer(d,side)
  113.      format * d;
  114.      int side ;
  115. #endif
  116. {
  117.   switch (d->type) {
  118.   case D_ASCII:
  119.     if (side != BLACK) (void) sprintf(d->white_buffer,"...");
  120.     if (side != WHITE) (void) sprintf(d->black_buffer,"   ");
  121.     break;
  122.   case D_TEX:
  123.     if (side != BLACK) (void) sprintf(d->white_buffer,"%s",FigDots);
  124.     if (side != WHITE) (void) sprintf(d->black_buffer,"~");
  125.     break;
  126.   default:
  127.     if (side != BLACK) d->white_buffer[0] = '\0' ;
  128.     if (side != WHITE) d->black_buffer[0] = '\0' ;
  129.     break;
  130.   }
  131. }
  132.  
  133. /* this procedure is responsible for PRINTING the move */
  134. #ifdef __STDC__
  135. static void flush_buffer(format *d)
  136. #else
  137. static void flush_buffer(d)
  138.      format * d;
  139. #endif
  140. {
  141.   
  142.   /* if we have been inteerupted (by a comment, a board display etc...
  143.      if the move is black
  144.      we display <movenumber> ... <blackmove>
  145.      */
  146.   if ((d->interrupt == TRUE) && (d->iswhiteturn == FALSE)) {
  147.     switch (d->type) {
  148.     case D_TEX:
  149.       (void) fprintf(d->outfile,
  150.              "\\MoveNumber{%s}\\WhiteMove{%s}\\BlackMove{%s}\n", 
  151.              d->move_buffer,FigDots,d->black_buffer);
  152.       break;
  153.     case D_GNU:
  154.     case D_XCHESS:
  155.       /* no special case for GNU */
  156.       (void) fprintf(d->outfile,"\t%s\n",d->black_buffer);
  157.       break;    
  158.     default:
  159.       (void) fprintf(d->outfile,"\n%3s.%9s%9s", 
  160.              d->move_buffer,"...",d->black_buffer);
  161.       break;
  162.     }
  163.     d->interrupt = FALSE ;
  164.   } else {
  165.   /* else (no interrupt)
  166.      we display either white or black move 
  167.      */
  168.     switch (d->type) {
  169.     case D_TEX:
  170.       if (d->iswhiteturn)
  171.     (void) fprintf(d->outfile,
  172.                "\\MoveNumber{%s}\\WhiteMove{%s}", d->move_buffer,d->white_buffer);
  173.       else
  174.     (void) fprintf(d->outfile,
  175.                "\\BlackMove{%s}\n",d->black_buffer);
  176.       break;
  177.     case D_XCHESS:
  178.       if (d->iswhiteturn)
  179.     (void) fprintf(d->outfile,"%3s.", d->move_buffer);
  180.     case D_GNU:
  181.       if (d->iswhiteturn)
  182.     (void) fprintf(d->outfile,"\t%s",d-> white_buffer);
  183.       else
  184.     (void) fprintf(d->outfile,"\t%s\n",d->black_buffer);
  185.       break;    
  186.     default:
  187.       if (d->iswhiteturn)
  188.     (void) fprintf(d->outfile,"\n%3s.%9s", d->move_buffer,d->white_buffer);
  189.       else
  190.     (void) fprintf(d->outfile,"%9s", d->black_buffer);
  191.       break;
  192.     }
  193.   } /* end printing */
  194.  
  195.   /* reset buffer */
  196.   if (! d->iswhiteturn)
  197.     init_buffer(d,VOID);
  198.   d->interrupt = FALSE;
  199. }
  200.  
  201. /* a generic parametrised driver for move output
  202.    */
  203. #ifdef __STDC__
  204. static void output_move_generic(format *dr, depl *d)
  205. #else
  206. static void output_move_generic(dr,d)
  207.      format * dr;
  208.      depl *d;
  209. #endif
  210. {
  211.   char ligne[128] ;
  212.   char themove[128] ;
  213.   char thepiece[16]  ;
  214.   char debcol[16];
  215.   char frommove[16]  ;
  216.   char tomove[16] ;
  217.   char captsymb[16] ;
  218.   char lie[16] ;
  219.   char prom[16];
  220.  
  221.   int ambigue = FALSE ;
  222.  
  223.   ligne[0] = themove[0] = thepiece[0] = debcol[0]  = '\0';
  224.   frommove[0] = tomove[0] = lie[0] = prom[0] = '\0' ;
  225.  
  226.   if (dr->type == D_TEX) 
  227.     (void) sprintf(captsymb,"{%s}", FigCapt);
  228.   else
  229.     (void) sprintf(captsymb,"%s", "x" );
  230.  
  231.   if (dr->type == D_TEX) {
  232.     if (dr->variation == 0)
  233.       (void) sprintf (dr->move_buffer,"{\\bf %d\\FigDot}",d->move);
  234.     else 
  235.       (void) sprintf (dr->move_buffer,"{%d\\FigDot}",d->move);
  236.   } else 
  237.     (void) sprintf (dr->move_buffer,"%d",d->move);
  238.  
  239.   if ((d->type == PETITROQUE) && !dr->roque_alg)
  240.     (void) sprintf (themove,"%s",P_ROQUE);
  241.   if ((d->type == GRANDROQUE) && !dr->roque_alg)
  242.     (void) sprintf (themove,"%s",G_ROQUE);
  243.   if (dr->roque_alg && 
  244.       ((d->type == GRANDROQUE) || (d->type == PETITROQUE)))
  245.     (void) roque_to_move(d);
  246.  
  247.   if (dr-> roque_alg || 
  248.       ((d->type != GRANDROQUE) && (d->type != PETITROQUE))) {
  249.  
  250.     /* we check here for ambiguous move */
  251.     if ((d->type != GRANDROQUE) && (d->type != PETITROQUE)) {
  252.       ambigue = ambiguity (d->piece, d->tolig,d->tocol);
  253.       /* if ( (ambigue ) && (d->piece != PAWN ))
  254.        * (void) fprintf (stderr,"ambiguity at move %d",tos->move);
  255.        */
  256.     }
  257.     themove[0] = '\0' ;
  258.     if ((dr->output_move_format == SHORTENED) 
  259.     && (d->type == PRISE) && (d->piece == PAWN))
  260.       (void) sprintf (debcol, "%c",coltoletter(d->fromcol));
  261.  
  262.     if (dr->print_piece)
  263.       if (d->piece != PAWN || dr->print_pawn) {
  264.     if (dr->type == D_TEX )
  265.       (void) sprintf(thepiece,"%s ",latex_table[d->piece]);
  266.     else
  267.       (void) sprintf(thepiece,"%c",dr->out_table[d->piece]);
  268.       }
  269.  
  270.     if ((dr->output_move_format == ALGEBRAIC))
  271.       (void)sprintf(frommove,"%c%c",
  272.             coltoletter(d->fromcol),ligtoletter(d->fromlig));
  273.     if ( ambigue && dr->print_liaison ) {
  274.       (void) sprintf(lie,"-");
  275.       (void)sprintf(frommove,"%c%c",
  276.             coltoletter(d->fromcol),ligtoletter(d->fromlig));
  277.       debcol[0] = '\0' ;
  278.     }
  279.     if (d->promotion) {
  280.       if (dr->print_piece) {
  281.     if (dr->type == D_TEX )
  282.       (void) sprintf(prom,"=%s ",latex_table[d->promotion]);
  283.       else
  284.         (void) sprintf(prom,"=%c",dr->out_table[d->promotion]);
  285.       }
  286.     }
  287.           
  288.     if (dr->print_liaison) {
  289.       if ((d->type == PRISE) || (d->type == PROM_ET_PRISE) 
  290.       || (d->type == EN_PASSANT) )
  291.     (void) sprintf(lie,"%s",captsymb);
  292.       else
  293.     if ((dr->output_move_format == ALGEBRAIC))
  294.       (void) sprintf(lie,"%c",'-');
  295.     }
  296.     
  297.     (void) sprintf(tomove,"%c%c",coltoletter(d->tocol),ligtoletter(d->tolig));
  298.  
  299.     (void) sprintf (themove,"%s%s%s%s%s%s",
  300.             thepiece,debcol,frommove,lie, tomove,prom);
  301.   }
  302.  
  303.   if (d->whiteturn)
  304.     (void) sprintf (dr->white_buffer, "%s",themove);
  305.   else
  306.     (void) sprintf (dr->black_buffer, "%s",themove);
  307.  
  308.   dr->iswhiteturn = d->whiteturn; 
  309.  
  310.   /*fprintf(dr->outfile, "=%d=%d= ",d->move,d->whiteturn);*/
  311.   flush_buffer(dr); 
  312. }
  313.  
  314. /* variation handler */
  315. #ifdef __STDC__
  316. static void output_variation_generic (format *dr, int inout)
  317. #else
  318. static void output_variation_generic (dr,inout)
  319.      format * dr;
  320.      int inout;
  321. #endif
  322. {
  323.   char symbol;
  324.  
  325.   if (dr->variation > 1)
  326.     symbol = varsymb[1][inout];
  327.   else
  328.     symbol = varsymb[0][inout];
  329.     
  330.   switch (dr->type) {
  331.   case D_TEX:
  332.     /* we must boldface the brackets for level 1 */
  333.     if (dr->variation == 1 ) {
  334.       (void) fprintf(dr->outfile, " {\\bf %c} ",symbol);
  335.       if (inout == 0 )
  336.     (void) fprintf(dr->outfile, "\\VariationLine");
  337.       else
  338.     (void) fprintf(dr->outfile, "\\MainLine");
  339.     } else
  340.       (void) fprintf(dr->outfile, " %c ",symbol);
  341.     break;
  342.   default:
  343.     (void) fprintf(dr->outfile, "  %c",symbol);
  344.     break;
  345.   };
  346. }
  347.  
  348. #ifdef __STDC__
  349. static void output_text_generic(format *dr, int type, char *string, int code)
  350. #else
  351. static void output_text_generic(dr, type, string, code)
  352.      format *dr ;
  353.      int type;
  354.      char * string;
  355.      int code;
  356. #endif
  357. {
  358.   switch (type) {
  359.   case T_COMMENT:
  360.     if (com_short[code] != '\0' )
  361.       (void) fprintf(dr->outfile," %s ",com_short[code]);
  362.     else
  363.       (void) fprintf(dr->outfile," %s ",com_long[code]);
  364.       break;
  365.   case T_TEXT:
  366.     (void) fprintf(dr->outfile," %s ",string);
  367.     break;
  368.   case T_TITLE:
  369.     (void) fprintf(dr->outfile,"\n  %s\n",string);
  370.     break;
  371.   case T_SUBTITLE:
  372.     (void) fprintf(dr->outfile,"    %s\n",string);
  373.     break;
  374.   case T_SCORE:
  375.     (void) fprintf(dr->outfile,"  %s\n",string);
  376.   default:
  377.     break;
  378.   }
  379. }
  380.  
  381.  
  382. /* ---------------- ascii driver ----------  */
  383. #ifdef __STDC__
  384. static void output_init_ascii(format *dr) 
  385. #else
  386. static void output_init_ascii(dr) 
  387. format *dr;
  388. #endif
  389. {}
  390.     
  391. #ifdef __STDC__
  392. static void output_board_ascii(format *dr,game *g)
  393. #else
  394. static void output_board_ascii(dr,g)
  395.      format * dr;
  396.      game * g;
  397. #endif
  398. {
  399.   register int i,j;
  400.  
  401.   dr->interrupt = TRUE;
  402.  
  403.   (void) fprintf(dr->outfile,"\n\n");
  404.   for (i=8 ; i >=1 ; i--) {
  405.     if (dr->coordinates)
  406.       (void) fprintf(dr->outfile,"%d ",i);
  407.     (void) fputc('|',dr->outfile);
  408.     for (j=1 ; j<9 ; j++) {
  409.       if (g->board[i][j] != VOID) {
  410.     if (g->color[i][j] == WHITE) 
  411.      (void) fputc(dr->out_table[g->board[i][j]], dr->outfile);
  412.     else 
  413.       (void) fputc(tolower(dr->out_table[g->board[i][j]]),dr->outfile);
  414.       } else
  415.     (void) fputc ( ((i+j)% 2)?' ':'/', dr->outfile);
  416.       (void) fputc('|', dr->outfile);
  417.     }
  418.     (void) fputc('\n', dr->outfile);
  419.   }
  420.   if (dr->coordinates)
  421.     (void) fprintf(dr->outfile,"   a b c d e f g h\n");
  422.   (void) fprintf(dr->outfile,"\n");
  423. }
  424.  
  425. /* ---------------- postscript --------- */
  426.  
  427. #ifdef __STDC__
  428. static void output_board_ps(format *dr,game *g)
  429. #else
  430. static void output_board_ps(dr,g)
  431.      format *dr;
  432.      game * g;
  433. #endif
  434. {
  435.   register int i,j;
  436.   register int c;
  437.   char chaine[MAXTOKLEN];
  438.  
  439.   /* header file */
  440.   (void) strcpy(chaine,LIB_DIR);
  441.   if ((ftmp = fopen(strcat(chaine,PS_HEADER),"r")) == NULL)
  442.     message((stderr,"Can't open ps header file.\n"));
  443.   else {
  444.     while ((c = getc(ftmp)) != EOF)
  445.       (void) fputc(c,dr->outfile);
  446.     (void) fclose(ftmp);
  447.   }
  448.  
  449.   (void) fprintf(dr->outfile,"( ________) 72 714 T\n");
  450.   for (i=8 ; i >=1 ; i--) {
  451.     (void) fprintf(dr->outfile,"(/");
  452.     for (j=1 ; j<9 ; j++) {
  453.     (void) fprintf(dr->outfile,"%s",
  454.            postscript_table[g->board[i][j]][PSINDEX(g->color[i][j],(i+j))]);
  455.     }
  456.     (void) fprintf(dr->outfile,"\\\\) 72 %d T\n",474 + (i-1)*30);
  457.   }
  458.   (void) fprintf(dr->outfile,"( --------) 72 444 T\n");
  459.  
  460.   /* footer file */
  461.   (void) strcpy(chaine,LIB_DIR);
  462.   if ((ftmp = fopen(strcat(chaine,PS_FOOTER),"r")) == NULL)
  463.     message((stderr,"Can't open ps footer file.\n"));
  464.   else {
  465.     while ((c = getc(ftmp)) != EOF)
  466.       (void) fputc(c,dr->outfile);
  467.     (void) fclose(ftmp);
  468.   }
  469. }
  470.  
  471. /* ---------------- nroff --------------- */
  472. #ifdef __STDC__
  473. static void output_init_roff(format *dr)
  474. #else
  475. static void output_init_roff(dr)
  476.      format *dr;
  477. #endif
  478. {
  479. }
  480.  
  481. #ifdef __STDC__
  482. static void output_board_roff(format *dr,game *g)
  483. #else
  484. static void output_board_roff(dr, g)
  485.      format *dr;
  486.      game * g;
  487. #endif
  488. {
  489.   register int i,j;
  490.  
  491.   dr->interrupt = TRUE;
  492.  
  493.   (void) fprintf(dr->outfile,".br\n");
  494.   for (i=8 ; i >=1 ; i--) {
  495.     (void) fprintf(dr->outfile,".ce\n  ");
  496.     for (j=1 ; j<9 ; j++) {
  497.       if (g->board[i][j] != VOID) {
  498.     if (g->color[i][j] == WHITE) 
  499.      (void) fputc(dr->out_table[g->board[i][j]], dr->outfile);
  500.     else 
  501.       (void) fputc(tolower(dr->out_table[g->board[i][j]]),dr->outfile);
  502.       } else
  503.     /*(void) fputc ( ((i+j)% 2)?' ':'/', dr->outfile);*/
  504.     (void) fprintf(dr->outfile,".");
  505.     }
  506.     (void) fprintf(dr->outfile,"\n.br\n");
  507.   }
  508.   (void) fprintf(dr->outfile,"\n");
  509. }
  510.  
  511. /* ---------------- tex -------------------- */
  512. #ifdef __STDC__
  513. static void output_init_tex(format *dr)
  514. #else
  515. static void output_init_tex(dr)
  516.      format *dr;
  517. #endif
  518. {
  519.   register int c;
  520.   char chaine[MAXTOKLEN];
  521.  
  522.   /* header file */
  523.   (void) strcpy(chaine,LIB_DIR);
  524.   if ((ftmp = fopen(strcat(chaine,TEX_HEADER),"r")) == NULL)
  525.     message((stderr,"Can't open tex header file.\n"));
  526.   else {
  527.     while ((c = getc(ftmp)) != EOF)
  528.       (void) fputc(c,dr->outfile);
  529.     (void) fclose(ftmp);
  530.   }
  531. }
  532.  
  533. #ifdef __STDC__
  534. static void output_text_tex(format *dr, int type, char * string, int code)
  535. #else
  536. static void output_text_tex(dr, type, string, code)
  537.      format *dr ;
  538.      int type;
  539.      char * string;
  540.      int code;
  541. #endif
  542. {
  543.   switch (type) {
  544.   case T_COMMENT:
  545.     if (com_tex[code] != '\0' )
  546.       (void) fprintf(dr->outfile,"%s\\ ",com_tex[code]);
  547.     else
  548.       (void) fprintf(dr->outfile,"%s\\ ",com_short[code]);
  549.       break;
  550.   case T_TEXT:
  551.     (void) fprintf(dr->outfile," %s \n",string);
  552.     break;
  553.   case T_TITLE:
  554.     (void) fprintf(dr->outfile,"\\ChessTitle{%s}\n",string);
  555.     break;
  556.   case T_SUBTITLE:
  557.     (void) fprintf(dr->outfile,"\\ChessSubTitle{%s}\n",string);
  558.     break;
  559.   case T_SCORE:
  560.     (void) fprintf(dr->outfile,"\\ChessScore{%s}\n",string);
  561.   default:
  562.     break;
  563.   };
  564. }
  565.  
  566. #ifdef __STDC__
  567. static void output_board_tex(format *dr,game *g)
  568. #else
  569. static void output_board_tex(dr,g)
  570.      format *dr;
  571.      game * g;
  572. #endif
  573. {
  574.   register int i,j;
  575.  
  576.   dr->interrupt = TRUE;
  577.  
  578.   (void) fprintf(dr->outfile,"\n\n");
  579.   (void)fprintf(dr->outfile,"$$\\vbox{\\bigskip\\offinterlineskip\\tabskip=0pt\n");
  580.   (void) fprintf(dr->outfile,"\\halign{#\\vvrule &#&#&#&#&#&#&#&#&#\\vvrule \\cr\n");
  581.   (void) fprintf(dr->outfile,"\\noalign{\\hhrule}\n");
  582.   for (i=8 ; i >=1 ; i--) {
  583.     (void) fprintf(dr->outfile,"&");
  584.     for (j=1 ; j < 9 ; j++) {
  585.     (void) fprintf(dr->outfile,"%s",
  586.            metafont_table[g->board[i][j]][PSINDEX(g->color[i][j],(i+j))]);
  587.       (void) fprintf(dr->outfile,"&");
  588.     }
  589.     (void) fprintf(dr->outfile,"\\cr \n");
  590.   }
  591.   (void) fprintf(dr->outfile,"\\noalign{\\hhrule}}}$$");
  592.   (void) fprintf(dr->outfile,"");
  593.   (void) fprintf(dr->outfile,"\n\n");
  594. }
  595.  
  596. #ifdef __STDC__
  597. static void output_end_tex(format *dr)
  598. #else
  599. static void output_end_tex(dr)
  600.      format *dr;
  601. #endif
  602.   (void) fprintf(dr->outfile, "~\n\n\n\\end{document}\n");
  603. }
  604.  
  605. /* ------------------ gnu - xchess ---------- */
  606.  
  607. #ifdef __STDC__
  608. static void output_init_gnu(format *dr)
  609. #else
  610. static void output_init_gnu(dr)
  611.      format *dr;
  612. #endif
  613. {
  614.   (void) fprintf(dr->outfile, "X Chess -- Mon Dec 10 11:47:18 MET 1990\n");
  615.   (void) fprintf(dr->outfile,"\tGame played on dumbkopft.irisa.fr:0.0\n");
  616.   (void) fprintf(dr->outfile,"\talgebraic\n");
  617. }
  618.  
  619. /* ---------------- driver handler ---------- */
  620. /* dummy driver */
  621. #ifdef __STDC__
  622. static void null_driver(void) {}
  623. #else
  624. static void null_driver() {}
  625. #endif
  626.  
  627. /* the drivers */
  628. #ifdef __STDC__
  629. void output_init(format *dr)
  630. #else
  631. void output_init(dr)
  632.      format *dr ;
  633. #endif
  634. {
  635.   if (dr->print_headers)
  636.     dr->out_init(dr);
  637. }
  638.  
  639. #ifdef __STDC__
  640. void output_move(format *dr,depl *d)
  641. #else
  642. void output_move(dr,d)
  643.      format *dr ;
  644.      depl *d;
  645. #endif
  646. {
  647.   if (! (((dr->type == D_GNU) || (dr->type == D_XCHESS))
  648.     && (dr->variation > 0)))
  649.     dr->out_move(dr,d);
  650. }
  651.  
  652. #ifdef __STDC__
  653. void output_variation(format *dr, int inout)
  654. #else
  655. void output_variation(dr, inout)
  656.      format *dr ;
  657.      int inout;
  658. #endif
  659. {
  660.   dr->out_variation(dr,inout);
  661. }
  662.  
  663. #ifdef __STDC__
  664. void output_text(format *dr, int type, char *string, int code)
  665. #else
  666. void output_text(dr, type, string, code)
  667.      format *dr ;
  668.      int type;
  669.      char * string;
  670.      int code;
  671. #endif
  672. {
  673.   if ((dr->type != D_GNU) && (dr->type != D_XCHESS))
  674.     dr->out_text(dr, type, string, code);
  675. }
  676.  
  677. #ifdef __STDC__
  678. void output_board(format *dr, game *g)
  679. #else
  680. void output_board(dr,g)
  681.      format *dr ;
  682.      game *g ;
  683. #endif
  684. {
  685.   dr->out_board(dr,g);
  686. }
  687.  
  688. #ifdef __STDC__
  689. void output_end(format *dr)
  690. #else
  691. void output_end(dr)
  692.      format *dr ;
  693. #endif
  694. {
  695.   if (dr->print_headers)
  696.     dr->out_end(dr);
  697.   (void) fprintf(dr->outfile,"\n");
  698. }
  699.  
  700.  
  701. #ifdef __STDC__
  702. format * new_driver(void)
  703. #else
  704. format * new_driver()
  705. #endif
  706. {
  707.   format * tmp;
  708.   int i; 
  709.  
  710.   tmp = (format *) malloc (sizeof(format));
  711.   ALLOCP(tmp);
  712.   for (i=0; i < ((sizeof (format))/ sizeof (int)) ; i++)
  713.     ((int *) tmp)[i] = 0;
  714.   tmp->output_move_format = SHORTENED;
  715.   tmp->print_headers = TRUE;
  716.   return(tmp);
  717. }
  718.  
  719. #ifdef __STDC__
  720. void init_driver(format *dr,int driver)
  721. #else
  722. void init_driver(dr,driver)
  723.      format * dr;
  724.      int driver;
  725. #endif
  726. {
  727.   dr->type = driver ;
  728.  
  729.   init_buffer(dr, VOID);
  730.   switch (dr->type) {
  731.   case D_ASCII:
  732.     dr->print_move = TRUE;
  733.     dr->print_piece = TRUE;
  734.     dr->print_pawn = FALSE;
  735.     dr->roque_alg = FALSE;
  736.     dr->print_liaison = TRUE;
  737.     dr->out_init = output_init_ascii;
  738.     dr->out_move = output_move_generic;
  739.     dr->out_variation = output_variation_generic;
  740.     dr->out_text = output_text_generic;
  741.     dr->out_board = output_board_ascii;
  742.     dr->out_end = null_driver;
  743.     break;
  744.   case D_POST:
  745.     dr->out_init = null_driver;
  746.     dr->out_move = null_driver;
  747.     dr->out_variation = null_driver;
  748.     dr->out_text = null_driver;
  749.     dr->out_board = output_board_ps;
  750.     dr->out_end = null_driver;
  751.     break;
  752.   case D_TEX:
  753.     dr->print_move = TRUE;
  754.     dr->print_piece = TRUE;
  755.     dr->print_pawn = FALSE;
  756.     dr->roque_alg = FALSE;
  757.     dr->print_liaison = TRUE;
  758.     dr->out_init = output_init_tex;
  759.     dr->out_move = output_move_generic;
  760.     dr->out_variation = output_variation_generic;
  761.     dr->out_text = output_text_tex;
  762.     dr->out_board = output_board_tex;
  763.     dr->out_end = output_end_tex;
  764.     break;
  765.   case D_ROFF:
  766.     dr->print_move = TRUE;
  767.     dr->print_piece = TRUE;
  768.     dr->print_pawn = FALSE;
  769.     dr->roque_alg = FALSE;
  770.     dr->print_liaison = TRUE;
  771.     dr->out_init = output_init_roff;
  772.     dr->out_move = output_move_generic;
  773.     dr->out_variation = output_variation_generic;
  774.     dr->out_text = output_text_generic;
  775.     dr->out_board = output_board_roff;
  776.     dr->out_end = null_driver;
  777.     break;
  778.   case D_XCHESS:
  779.     dr->output_move_format = ALGEBRAIC;
  780.     dr->print_move = TRUE;
  781.     dr->print_piece = FALSE;
  782.     dr->print_pawn = FALSE;
  783.     dr->roque_alg = TRUE;
  784.     dr->print_liaison = FALSE;
  785.     dr->out_init = output_init_gnu;
  786.     dr->out_move = output_move_generic;
  787.     dr->out_variation = null_driver;
  788.     dr->out_text = null_driver;
  789.     dr->out_board = null_driver;
  790.     dr->out_end = null_driver;
  791.     break;
  792.   case D_GNU:
  793.     dr->output_move_format = ALGEBRAIC;
  794.     dr->print_move = FALSE;
  795.     dr->print_piece = FALSE;
  796.     dr->print_pawn = FALSE;
  797.     dr->roque_alg = TRUE;
  798.     dr->print_liaison = FALSE;
  799.     dr->out_init = null_driver;
  800.     dr->out_move = output_move_generic;
  801.     dr->out_variation = null_driver;
  802.     dr->out_text = null_driver;
  803.     dr->out_board = null_driver;
  804.     dr->out_end = null_driver;
  805.     break;
  806.   default:
  807.     error((stderr,"unknown driver"));
  808.     break;
  809.   }
  810.   if (dr->only_board)
  811.     dr->out_move = null_driver ;
  812.  
  813.   dr->variation = 0;
  814.   dr->iswhiteturn = FALSE ;
  815.   dr->interrupt = FALSE;
  816. }
  817.