home *** CD-ROM | disk | FTP | other *** search
/ Giga Games 1 / Giga Games.iso / net / go / prog / sg2ps.sh < prev    next >
Encoding:
Linux/UNIX/POSIX Shell Script  |  1993-06-20  |  36.4 KB  |  1,241 lines

  1. #! /bin/sh
  2. # This is a shell archive, meaning:
  3. # 1. Remove everything above the #! /bin/sh line.
  4. # 2. Save the resulting text in a file.
  5. # 3. Execute the file with /bin/sh (not csh) to create:
  6. #    COPYING
  7. #    README
  8. #    go.ps
  9. #    makefile
  10. #    partie.l
  11. #    partie.y
  12. # This archive created: Sat Mar 21 11:42:18 1992
  13. export PATH; PATH=/bin:/usr/bin:$PATH
  14. if test -f 'COPYING'
  15. then
  16.     echo shar: "will not over-write existing file 'COPYING'"
  17. else
  18. cat << \SHAR_EOF > 'COPYING'
  19.  
  20.             GNU GENERAL PUBLIC LICENSE
  21.              Version 1, February 1989
  22.  
  23.  Copyright (C) 1989 Free Software Foundation, Inc.
  24.                     675 Mass Ave, Cambridge, MA 02139, USA
  25.  Everyone is permitted to copy and distribute verbatim copies
  26.  of this license document, but changing it is not allowed.
  27.  
  28.                 Preamble
  29.  
  30.   The license agreements of most software companies try to keep users
  31. at the mercy of those companies.  By contrast, our General Public
  32. License is intended to guarantee your freedom to share and change free
  33. software--to make sure the software is free for all its users.  The
  34. General Public License applies to the Free Software Foundation's
  35. software and to any other program whose authors commit to using it.
  36. You can use it for your programs, too.
  37.  
  38.   When we speak of free software, we are referring to freedom, not
  39. price.  Specifically, the General Public License is designed to make
  40. sure that you have the freedom to give away or sell copies of free
  41. software, that you receive source code or can get it if you want it,
  42. that you can change the software or use pieces of it in new free
  43. programs; and that you know you can do these things.
  44.  
  45.   To protect your rights, we need to make restrictions that forbid
  46. anyone to deny you these rights or to ask you to surrender the rights.
  47. These restrictions translate to certain responsibilities for you if you
  48. distribute copies of the software, or if you modify it.
  49.  
  50.   For example, if you distribute copies of a such a program, whether
  51. gratis or for a fee, you must give the recipients all the rights that
  52. you have.  You must make sure that they, too, receive or can get the
  53. source code.  And you must tell them their rights.
  54.  
  55.   We protect your rights with two steps: (1) copyright the software, and
  56. (2) offer you this license which gives you legal permission to copy,
  57. distribute and/or modify the software.
  58.  
  59.   Also, for each author's protection and ours, we want to make certain
  60. that everyone understands that there is no warranty for this free
  61. software.  If the software is modified by someone else and passed on, we
  62. want its recipients to know that what they have is not the original, so
  63. that any problems introduced by others will not reflect on the original
  64. authors' reputations.
  65.  
  66.   The precise terms and conditions for copying, distribution and
  67. modification follow.
  68.  
  69.             GNU GENERAL PUBLIC LICENSE
  70.    TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
  71.  
  72.   0. This License Agreement applies to any program or other work which
  73. contains a notice placed by the copyright holder saying it may be
  74. distributed under the terms of this General Public License.  The
  75. "Program", below, refers to any such program or work, and a "work based
  76. on the Program" means either the Program or any work containing the
  77. Program or a portion of it, either verbatim or with modifications.  Each
  78. licensee is addressed as "you".
  79.  
  80.   1. You may copy and distribute verbatim copies of the Program's source
  81. code as you receive it, in any medium, provided that you conspicuously and
  82. appropriately publish on each copy an appropriate copyright notice and
  83. disclaimer of warranty; keep intact all the notices that refer to this
  84. General Public License and to the absence of any warranty; and give any
  85. other recipients of the Program a copy of this General Public License
  86. along with the Program.  You may charge a fee for the physical act of
  87. transferring a copy.
  88.  
  89.   2. You may modify your copy or copies of the Program or any portion of
  90. it, and copy and distribute such modifications under the terms of Paragraph
  91. 1 above, provided that you also do the following:
  92.  
  93.     a) cause the modified files to carry prominent notices stating that
  94.     you changed the files and the date of any change; and
  95.  
  96.     b) cause the whole of any work that you distribute or publish, that
  97.     in whole or in part contains the Program or any part thereof, either
  98.     with or without modifications, to be licensed at no charge to all
  99.     third parties under the terms of this General Public License (except
  100.     that you may choose to grant warranty protection to some or all
  101.     third parties, at your option).
  102.  
  103.     c) If the modified program normally reads commands interactively when
  104.     run, you must cause it, when started running for such interactive use
  105.     in the simplest and most usual way, to print or display an
  106.     announcement including an appropriate copyright notice and a notice
  107.     that there is no warranty (or else, saying that you provide a
  108.     warranty) and that users may redistribute the program under these
  109.     conditions, and telling the user how to view a copy of this General
  110.     Public License.
  111.  
  112.     d) You may charge a fee for the physical act of transferring a
  113.     copy, and you may at your option offer warranty protection in
  114.     exchange for a fee.
  115.  
  116. Mere aggregation of another independent work with the Program (or its
  117. derivative) on a volume of a storage or distribution medium does not bring
  118. the other work under the scope of these terms.
  119.  
  120.   3. You may copy and distribute the Program (or a portion or derivative of
  121. it, under Paragraph 2) in object code or executable form under the terms of
  122. Paragraphs 1 and 2 above provided that you also do one of the following:
  123.  
  124.     a) accompany it with the complete corresponding machine-readable
  125.     source code, which must be distributed under the terms of
  126.     Paragraphs 1 and 2 above; or,
  127.  
  128.     b) accompany it with a written offer, valid for at least three
  129.     years, to give any third party free (except for a nominal charge
  130.     for the cost of distribution) a complete machine-readable copy of the
  131.     corresponding source code, to be distributed under the terms of
  132.     Paragraphs 1 and 2 above; or,
  133.  
  134.     c) accompany it with the information you received as to where the
  135.     corresponding source code may be obtained.  (This alternative is
  136.     allowed only for noncommercial distribution and only if you
  137.     received the program in object code or executable form alone.)
  138.  
  139. Source code for a work means the preferred form of the work for making
  140. modifications to it.  For an executable file, complete source code means
  141. all the source code for all modules it contains; but, as a special
  142. exception, it need not include source code for modules which are standard
  143. libraries that accompany the operating system on which the executable
  144. file runs, or for standard header files or definitions files that
  145. accompany that operating system.
  146.  
  147.   4. You may not copy, modify, sublicense, distribute or transfer the
  148. Program except as expressly provided under this General Public License.
  149. Any attempt otherwise to copy, modify, sublicense, distribute or transfer
  150. the Program is void, and will automatically terminate your rights to use
  151. the Program under this License.  However, parties who have received
  152. copies, or rights to use copies, from you under this General Public
  153. License will not have their licenses terminated so long as such parties
  154. remain in full compliance.
  155.  
  156.   5. By copying, distributing or modifying the Program (or any work based
  157. on the Program) you indicate your acceptance of this license to do so,
  158. and all its terms and conditions.
  159.  
  160.   6. Each time you redistribute the Program (or any work based on the
  161. Program), the recipient automatically receives a license from the original
  162. licensor to copy, distribute or modify the Program subject to these
  163. terms and conditions.  You may not impose any further restrictions on the
  164. recipients' exercise of the rights granted herein.
  165.  
  166.   7. The Free Software Foundation may publish revised and/or new versions
  167. of the General Public License from time to time.  Such new versions will
  168. be similar in spirit to the present version, but may differ in detail to
  169. address new problems or concerns.
  170.  
  171. Each version is given a distinguishing version number.  If the Program
  172. specifies a version number of the license which applies to it and "any
  173. later version", you have the option of following the terms and conditions
  174. either of that version or of any later version published by the Free
  175. Software Foundation.  If the Program does not specify a version number of
  176. the license, you may choose any version ever published by the Free Software
  177. Foundation.
  178.  
  179.   8. If you wish to incorporate parts of the Program into other free
  180. programs whose distribution conditions are different, write to the author
  181. to ask for permission.  For software which is copyrighted by the Free
  182. Software Foundation, write to the Free Software Foundation; we sometimes
  183. make exceptions for this.  Our decision will be guided by the two goals
  184. of preserving the free status of all derivatives of our free software and
  185. of promoting the sharing and reuse of software generally.
  186.  
  187.                 NO WARRANTY
  188.  
  189.   9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
  190. FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
  191. OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
  192. PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
  193. OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  194. MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
  195. TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
  196. PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
  197. REPAIR OR CORRECTION.
  198.  
  199.   10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
  200. WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
  201. REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
  202. INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
  203. OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
  204. TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
  205. YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
  206. PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
  207. POSSIBILITY OF SUCH DAMAGES.
  208.  
  209.              END OF TERMS AND CONDITIONS
  210. SHAR_EOF
  211. fi
  212. if test -f 'README'
  213. then
  214.     echo shar: "will not over-write existing file 'README'"
  215. else
  216. cat << \SHAR_EOF > 'README'
  217.  
  218. Here comes the program to convert go games in the mgt format to
  219. a postscript program. I looked in the archive in september 1990
  220. and found nothing to do the same job.
  221.  
  222. I used this program to convert the games of Shusaku and Go Seigen
  223. stored in the archive. All went well, except for a few files which
  224. contained what i supposed being typing errors not recognized by
  225. mgt.
  226.  
  227. The postcript programming style is definitely poor, when seeing
  228. what is recommended by the green book.
  229.  
  230. If you want to make modifications to the program, it would be nice
  231. to send them to me. It is heavily commented ; that will be useful
  232. for those who speak french.
  233.  
  234. Jean Mehat.
  235.  
  236.  
  237.  
  238. ------------
  239.  
  240. To use this program on a unix system, type
  241.    make
  242. to compile the program.
  243.  
  244. Then run with
  245.    mgt2ps < inputfile > outputfile.ps
  246.  
  247. SHAR_EOF
  248. fi
  249. if test -f 'go.ps'
  250. then
  251.     echo shar: "will not over-write existing file 'go.ps'"
  252. else
  253. cat << \SHAR_EOF > 'go.ps'
  254. %!PS-Adobe-1.0
  255. %%Creator: mgt2ps
  256. %%Title: une partie de go
  257. %%Pages: (atend)
  258. %%DomumentFonts: Times-Roman
  259. %%EndComments
  260.  
  261. % Afficher un goban, avec son titre, ses recouvrements, ses kos,
  262. % ses commentaires, comme produit par mgt2ps
  263. %                    jm, octobre 1990
  264. % (c) Jean Mehat, Octobre 1990
  265. % De'partement d'informatique, universite de Paris 8, 2 rue de la liberte,
  266. %    St Denis, 93526 cedex 02, France
  267. % jm@aristote.univ-paris8.fr ou
  268. % jm@geocub.greco-prog.fr
  269. %
  270. %    This program is free software; you can redistribute it and/or modify
  271. %    it under the terms of the GNU General Public License as published by
  272. %    the Free Software Foundation; either version 1, or (at your option)
  273. %    any later version.
  274. %
  275. %    This program is distributed in the hope that it will be useful,
  276. %    but WITHOUT ANY WARRANTY; without even the implied warranty of
  277. %    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  278. %    GNU General Public License for more details.
  279. %
  280. %    You should have received a copy of the GNU General Public License
  281. %    along with this program; if not, write to the Free Software
  282. %    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  283.  
  284. % decembre 1990 : re-ecrit centrer pour qu'il mesure vraiment les caracteres
  285. % qu'il centre
  286.  
  287.     % la taille du goban
  288. /gobantaille 19 def        % taille du goban
  289. /h1 4 def            % h1, h2, h3 : les hoshis
  290. /h2 gobantaille 1 add h1 sub def
  291. /h3 gobantaille 1 add 2 div def
  292.  
  293.     % le dessin du goban
  294. /epaisseur 1 def        % epaisseur du trait du goban
  295. /vespace 22 def            % ecart entre les traits vertical et horizontal
  296. /hespace 20 def
  297.  
  298.     % le dessin des pierres
  299. /prayon hespace 1 sub 2 div def    % rayon d'une pierre : (hespace-1)/2
  300.                 % fonte pour etiqueter les pierres
  301. /eticar /Times-Roman findfont prayon scalefont def
  302.  
  303.     % l'e'criture des notes et commentaires
  304. /noteEchelle 12 def        % echelle de la fonte
  305.                 % fonte pour commenter les coups
  306. /notecar /Times-Roman findfont noteEchelle scalefont def
  307. /notespace prayon dup 2 add add def
  308. /pierrechelle             % echelle pour avoir une pierre de meme taille
  309.                 %   que du texte
  310.    noteEchelle prayon dup add div
  311.  def
  312.  
  313.     % dessiner des pierres (en 0 0) : noire00, blanche00
  314. /noire00
  315.   { 0 setgray newpath 0 0 prayon 0 360 arc fill
  316.   } def
  317. /blanche00
  318.   { newpath 0 0 prayon 0 360 arc
  319.      gsave 1 setgray fill grestore 0 setgray stroke
  320.   } def
  321.  
  322.     % dessiner un goban
  323. /goban00 {
  324.   epaisseur setlinewidth
  325.   newpath
  326.     1 1 gobantaille {
  327.       dup dup dup            % i i i i
  328.       1 goban2coord moveto        % i i i
  329.       gobantaille goban2coord lineto    % i i
  330.       1 exch goban2coord moveto        % i
  331.       gobantaille exch goban2coord lineto
  332.     } for
  333.   stroke
  334.  
  335.   newpath
  336.    [ h1 h2 h3 ]
  337.    {                 % n
  338.      dup dup            % n n n
  339.      [ h1 h2 h3 ] {        % --- n m
  340.     goban2coord        % --- x y
  341.     2 copy moveto
  342.     3 0 360 arc   
  343.       } forall
  344.     } forall
  345.   fill
  346. } def
  347.  
  348.  
  349. /centrer    % (nom) -> (nom) mais il a fait un moveto, (nom) sera centre
  350. {
  351.   gsave
  352.     newpath 0 0 moveto dup true charpath flattenpath pathbbox
  353.                 % (nom) xmin ymin xmax ymax
  354.     2 index sub            % (nom) xmin ymin xmax haut
  355.     exch 3 index sub        % (nom) xmin ymin haut large
  356.                 % (nom) xmin ymin -large/2 -haut/2
  357.     2 div neg exch 2 div neg
  358.   grestore
  359.   moveto            % (nom) xmin ymin
  360.   pop pop            % (nom)
  361. } def
  362.  
  363. /tpierre {    % (nom) couleur -> - ; affiche une pierre a la show
  364.   gsave
  365.     currentpoint translate
  366.     1 prayon add noteEchelle 2 div translate
  367.     2 eq { noire00 1 } { blanche00 0 } ifelse
  368.     setgray eticar setfont centrer show
  369.   grestore
  370.   prayon dup add 2 add 0 rmoveto    % deplace le point courant a la show
  371. } def
  372.  
  373.     % parametrer l'organisation de la page
  374. /Mg 50 def            % marges gauche et droite
  375. /Md 8.5 72 mul Mg Mg add sub def
  376. /Mb 1 72 mul def        % marges basses et hautes
  377. /Mh 11 72 mul Mb sub def
  378.  
  379. /initHaut {
  380.   /hautx Mg def            % le plus haut point courant a utiliser
  381.   /hauty Mh def            %   (modifie par titre et utilise par goban)
  382. } def
  383.  
  384. /goban {
  385.   /gobanx hautx def            % coordonne'es du goban
  386.   /gobany hauty vespace gobantaille mul sub def
  387.   goban00
  388.                     % coord. des reprises : "12 en 5"
  389.   /couvrex gobanx hespace gobantaille 1 add mul add def
  390.   /couvrey gobany vespace gobantaille 2 sub mul add def
  391.                     % coordonne'es des commentaires et, si
  392.   /comx gobanx def            % il faut, des kos : "12, 15, 17 en 5"
  393.   /comy gobany notespace 2 mul sub def
  394. } def
  395.  
  396. /goban2coord    % n m -> x y
  397.  {
  398.     exch
  399.     1 sub exch gobantaille exch    sub    % x-1 gobantaille-y
  400.     vespace mul exch hespace mul exch    % (x-1)hespace (gbt-y)vespace
  401.     gobany add exch gobanx add exch    % (x-1)hespace+gobanx (gbt-y)vespace+gobany
  402.  } def
  403.  
  404.     % justification a la hache : on pose les mots, si on a depasse la
  405.     % marge droite, on va a la ligne, si on a depasse la marge basse
  406.     % on passe a la ligne suivante
  407. /lignespace notespace def    % espace entre deux lignes
  408.  
  409. /addpierre {        % (nom) couleur ->
  410.   tpierre
  411.   currentpoint pop        % (n) c x
  412.   Md gt { comalaligne } if
  413. } def
  414.  
  415. /addchaine {        % string ->
  416.   ( ) search            % post match pre true OU string false
  417.   { addmot show addchaine } { addmot } ifelse
  418. } def
  419.  
  420. /addmot {        % mot ->
  421.   show                % mot
  422.   currentpoint pop        % mot w+y
  423.   Md gt { comalaligne } if
  424. } def
  425.  
  426. /comalaligne {
  427.   /comy comy lignespace sub def
  428.   comy Mb le { showpage /comy Mh def } if
  429.   comx comy moveto
  430. } def
  431.   
  432. %
  433. % titres    traite un tableau de chaines qui servent de titre
  434. % coups        traite un tableau de coups ( = [nom) couleur ligne col ])
  435. % couvres      ... un tableau de pierres qui en recouvrent d'autres :
  436. %                ( = [(sous) couleur [ (sur) couleur ]])
  437. % kos          ... un tableau de liste de pierres qui en recouvrent d'autres
  438. %                ( = [(sous) c [ (sur1) c1 (sur2) c2 ... ]])
  439. % commentaires       ... un tableau de commentaires ( = [ (nom) couleur (comm) ] )
  440. %
  441.  
  442. /titres        % [ (chaine) (chaine) ... ]
  443. { initHaut
  444.   {
  445.     hautx hauty moveto notecar setfont show
  446.     /hauty hauty noteEchelle sub def
  447.   } forall
  448. } def
  449.  
  450. /coups        % [ [ (nom) coul n m ] [ (nom) coul n m ] ... ]
  451. { {                % --- [ (nom) coul n m ]
  452.     aload pop            % --- (nom) coul n m
  453.     gsave
  454.       goban2coord translate
  455.       2 eq { noire00 1 } { blanche00 0 } ifelse
  456.       setgray eticar setfont centrer show
  457.     grestore
  458.   } forall
  459. } def
  460.  
  461. /couvres            % [ [ (sous) couleur [ (sur) couleur ] ] --- ]
  462. {
  463.   gsave
  464.     couvrex couvrey moveto
  465.     {                % --- [ (sous) c [ (sur) c ]]
  466.       aload pop            % --- (sous) c [ (sur) c ]
  467.       aload pop            % --- (sous) c (sur) c
  468.       tpierre ( en ) show tpierre
  469.       couvrex couvrey notespace sub dup /couvrey exch def
  470.       moveto
  471.     } forall
  472.     /couvrey couvrey notespace sub def
  473.   grestore
  474. } def
  475.  
  476. /kos {            % [[ko] [ko] ...]
  477.   comx comy moveto
  478.   lignespace notespace def
  479.   {                % ... ko=[(nom) couleur [(nom) couleur ... ]]
  480.     aload pop            % (sous) c [coups]
  481.     true exch            % (sous) c flag [coups]
  482.     {
  483.       exch            % (sous) c (nom) true
  484.                 %  ou bien (nom) c false
  485.       { false } { addpierre true } ifelse
  486.     } forall
  487.     pop                % (sous) c
  488.     ( en ) addchaine
  489.     addpierre
  490.     comalaligne
  491.   } forall
  492.   comalaligne
  493. } def
  494.  
  495. /commentaires        % [ [ (nom) couleur (commentaire) ] --- ]
  496. {
  497.   comx comy moveto
  498.   lignespace noteEchelle def
  499.   { aload pop                % -> (n) couleur (com)
  500.     3 1 roll            % -> (com) (n) couleur
  501.     dup dup            % -> (com) (n) couleur couleur couleur
  502.     1 eq            % -> (com) (n) couleur couleur bool
  503.     exch            % -> (com) (n) couleur bool couleur
  504.     2 eq            % -> (com) (n) couleur bool bool
  505.     or {  pierrechelle dup scale
  506.       addpierre
  507.       1 pierrechelle div dup scale
  508.       ( ) show
  509.        } { pop pop } ifelse    % com
  510. %    or { addpierre ( ) show } { pop pop } ifelse
  511.     addchaine            % ->
  512.     comalaligne
  513.   } forall
  514. } def
  515.  
  516. %%EndProlog
  517. SHAR_EOF
  518. fi
  519. if test -f 'makefile'
  520. then
  521.     echo shar: "will not over-write existing file 'makefile'"
  522. else
  523. cat << \SHAR_EOF > 'makefile'
  524. #
  525. # mgt2ps : traduit une partie note'e dans le format mgt en programme postscript
  526. # (c) Jean Mehat, Octobre 1990
  527. # De'partement d'informatique, universite de Paris 8, 2 rue de la liberte,
  528. #    St Denis, 93526 cedex 02, France
  529. # jm@aristote.univ-paris8.fr ou
  530. # jm@geocub.greco-prog.fr
  531. #
  532. #    This program is free software; you can redistribute it and/or modify
  533. #    it under the terms of the GNU General Public License as published by
  534. #    the Free Software Foundation; either version 1, or (at your option)
  535. #    any later version.
  536. #
  537. #    This program is distributed in the hope that it will be useful,
  538. #    but WITHOUT ANY WARRANTY; without even the implied warranty of
  539. #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  540. #    GNU General Public License for more details.
  541. #
  542. #    You should have received a copy of the GNU General Public License
  543. #    along with this program; if not, write to the Free Software
  544. #    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  545. #
  546. CC = gcc
  547. CFLAGS = -g -O -o mgt2ps
  548. BINDIR = /usr/local/bin
  549. PSLIBDIR = `pwd`
  550.  
  551. mgt2ps : partie.tab.c lex.yy.c
  552.     $(CC) $(CFLAGS) -DYYDEBUG -DPSFILE=\"$(PSLIBDIR)/go.ps\" partie.tab.c
  553.  
  554. clean :
  555.     rm -f partie.tab.c lex.yy.c *.o a.out core *~
  556.  
  557.  
  558. lex.yy.c : partie.l
  559.     flex partie.l
  560.  
  561. partie.tab.c : partie.y
  562.     bison partie.y
  563.  
  564. install: mgt2ps
  565.     mv mgt2ps $(BINDIR)/mgt2ps
  566. SHAR_EOF
  567. fi
  568. if test -f 'partie.l'
  569. then
  570.     echo shar: "will not over-write existing file 'partie.l'"
  571. else
  572. cat << \SHAR_EOF > 'partie.l'
  573.   /* partie.l
  574.    decouper un fichier mgt en lexemes
  575.  
  576.  (c) Jean Mehat, Octobre 1990
  577.  De'partement d'Informatique, Universite de Paris 8, 2 rue de la liberte,
  578.     St Denis, 93526, Cedex 02, France
  579.  jm@geocub.greco-prog.fr
  580.  
  581.     This program is free software; you can redistribute it and/or modify
  582.     it under the terms of the GNU General Public License as published by
  583.     the Free Software Foundation; either version 1, or (at your option)
  584.     any later version.
  585.  
  586.     This program is distributed in the hope that it will be useful,
  587.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  588.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  589.     GNU General Public License for more details.
  590.  
  591.     You should have received a copy of the GNU General Public License
  592.     along with this program; if not, write to the Free Software
  593.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  594.    */
  595.   int lino = 1;
  596. PASDECROCHETFERMANT        ([^\][])
  597. %%
  598. Name                { return NAME; }
  599. PLayer                { return PLAYER; }
  600. GaMe                { return GAME; }
  601. Si[zZ]e                { return SIZE; }
  602. VieW                { return VIEW; }
  603. WhiteSpec            { return WHITESPEC; }
  604. BlackSpec            { return BLACKSPEC; }
  605. PlaCe                { return PLACE; }
  606. DaTe                { return DATE; }
  607. FileFormat            { return FILEFORMAT; }
  608. GameName            { return GAMENAME; }
  609. K[oO]                { return KO; }
  610. AddBlack            { return ADDBLACK; }
  611. AddWhite            { return ADDWHITE; }
  612. AddEmpty            { return ADDEMPTY; }
  613. Letter                { return LETTER; }
  614. Mark                { return MARK; }
  615. Comment                { return COMMENT; }
  616. Black                { return BLACK; }
  617. White                { return WHITE; }
  618. "["    { /* Pour les args, c'est la merde parce qu'on a parfois des \[ et \]
  619.          et parfois des [] imbrique's ; il faut escaper ( et ) */
  620.       static char * monarg = 0;
  621.       static int place = 0;
  622.       int nivo, prev, c;
  623.       int i;
  624.       static int input();        /* pour eviter un warning de gcc */
  625.  
  626.       if (monarg == 0 && (monarg = (char *)calloc(place = 1024, 1)) == 0)
  627.         merror();
  628.  
  629.       for(nivo = i = 0;;){
  630.         c = input();
  631.                 /* on s'arrete ? */
  632.         if (c == ']' && (i == 0 || monarg[i - 1] != '\\') && nivo == 0)
  633.           break;
  634.                 /* allouew ou realloue si necessaire */
  635.         if (i >= place - 1
  636.         && (monarg = (char *)realloc(monarg, place += 1024)) == 0)
  637.           merror();
  638.                 /* compte les returns */
  639.         if (c == '\n')
  640.           lino += 1;
  641.                 /* transforme les () en \(\)*/
  642.         if ((c == '(' || c == ')') && (i == 0 || monarg[i - 1] != '\\'))
  643.           monarg[i++] = '\\';
  644.                 /* compte les [] sans \,
  645.                    transforme les en \[\]*/
  646.         if ((c == '[' || c == ']') && (i == 0 || monarg[i - 1] != '\\')){
  647.           if (c == '[')
  648.         nivo += 1;
  649.           else if (c == ']')
  650.         nivo -= 1;
  651.           monarg[i++] = '\\';
  652.         }
  653.                 /* maintenant, ajoute le caractere */
  654.         monarg[i++] = c;
  655.       }
  656.       monarg[i] = 0;
  657.       yylval.pcar = monarg;
  658.       return ARG;
  659.     }
  660. [;()]                { return yytext[0]; }
  661. [ \t]                ;
  662. \n                { lino += 1; }
  663. .                { extern char * file; printf("%s:%d: %c\n",
  664.                      file, lino, yytext[0]); }
  665. %%
  666. SHAR_EOF
  667. fi
  668. if test -f 'partie.y'
  669. then
  670.     echo shar: "will not over-write existing file 'partie.y'"
  671. else
  672. cat << \SHAR_EOF > 'partie.y'
  673. /* partie.y  --  comvertit du format mgt (Smart Go ?) en postscript
  674.  
  675.  (c) Jean Mehat, Octobre 1990
  676.  De'partement d'informatique, universite de Paris 8, 2 rue de la liberte,
  677.     St Denis, 93526 cedex 02, France
  678.  jm@aristote.univ-paris8.fr ou
  679.  jm@geocub.greco-prog.fr
  680.  
  681.     This program is free software; you can redistribute it and/or modify
  682.     it under the terms of the GNU General Public License as published by
  683.     the Free Software Foundation; either version 1, or (at your option)
  684.     any later version.
  685.  
  686.     This program is distributed in the hope that it will be useful,
  687.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  688.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  689.     GNU General Public License for more details.
  690.  
  691.     You should have received a copy of the GNU General Public License
  692.     along with this program; if not, write to the Free Software
  693.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  694.  */
  695.  
  696. /*
  697.  En general, convertit le format mgt (Smart Go ?) en suite de commandes
  698.  postscript. Quoiqu'en dise main, ca ne marche qu'avec 0 ou 1 partie (le
  699.  probleme est peut etre dans l'input() de flex ?
  700.                 jm, octobre&novembre 1990
  701. 7 novembre 90 : affiche aussi les pierres de handicap
  702. 12 novembre 90 : affiche le goban et les pierres sur la meme page,
  703.     meme s'il y a beaucoup de kos. Libere la memoire des kos.
  704.  */
  705. %token GAME SIZE VIEW BLACKSPEC WHITESPEC FILEFORMAT GAMENAME KO PLACE
  706. %token DATE LETTER NAME PLAYER
  707. %token ADDEMPTY MARK ADDBLACK ADDWHITE
  708. %token COMMENT WHITE BLACK
  709.  
  710. %token <pcar> ARG
  711.  
  712. %union {
  713.   char *    pcar;    
  714.   struct noeud *n;
  715. }
  716.  
  717. %type <n> coup liste variante
  718.  
  719. %{
  720. # include <assert.h>
  721.  
  722. # define BLANC 1
  723. # define NOIR 2
  724.  
  725. # define VARIANTE 1
  726. # define COUP    2
  727. # define HANDICAP 3
  728.  
  729. # define GOBAN 19
  730.  
  731. typedef struct point { int x, y; } Point;
  732.  
  733. typedef struct noeud {
  734.   int flag;
  735.   struct noeud * next;
  736.   struct noeud * fils;
  737.   char * commentaire;
  738.   int couleur;
  739.   Point position;
  740.   int numcoup;
  741.   int ndessus;
  742.   struct noeud * dessous;
  743. } Noeud;
  744.                 /* gcc les fera inline */
  745. static Point Pt(a, b){ Point p; p.x = a; p.y = b; return p; }
  746. static Noeud * courant;
  747. static Noeud * nouvo(){ Noeud * n;
  748.   if ((n = (Noeud *)calloc(1, sizeof n[0])) == 0)
  749.     merror();
  750.   return courant = n;
  751. }
  752. static void ancien(n) Noeud *n; {
  753.   if (n->commentaire != 0)
  754.     free(n->commentaire);
  755.   if (n->fils != 0)
  756.     ancien(n->fils);
  757.   if (n->next != 0)
  758.     ancien(n->next);
  759.   free(n);
  760. }
  761. static char * interne(s) char * s; { char * d;
  762.   if ((d = (char *)malloc(strlen(s) + 1)) == 0)
  763.     merror();
  764.   else
  765.     strcpy(d, s);
  766.   return d;
  767. }
  768.  
  769.  
  770. Noeud * racine;            /* On trouve la partie parse'e ici */
  771. %}
  772.  
  773. %%
  774. racine    : '(' ';' 
  775.         { $<n>$ = nouvo(); }
  776.       props1 liste ')'
  777.         { racine = $<n>3;
  778.           racine->next = $5;
  779.         }
  780.     ;
  781.  
  782. variante
  783.     : '(' liste ')'
  784.         { $$ = nouvo();
  785.           $$->flag = VARIANTE;
  786.           $$->fils = $2;
  787.         }
  788.     ;
  789.  
  790. liste    : coup liste
  791.         { goto chainer; }
  792.     | coup
  793.       | variante liste
  794.         { chainer:
  795.             $1->next = $2;
  796.             $$ = $1;
  797.         }
  798.     | variante
  799.     ;
  800.  
  801. coup    : ';'
  802.         { $<n>$ = nouvo(); }
  803.       props
  804.         { $$ = $<n>2;
  805.           $$->flag = COUP;
  806.         }
  807.     ;
  808.  
  809. props    : prop props
  810.     | /* rien */
  811.     ;
  812.  
  813. prop    : GAME ARG
  814.     | PLAYER ARG
  815.     | KO ARG
  816.     | MARK liste_arg
  817.     | ADDBLACK liste_arg
  818.         { noparse(); }
  819.     | ADDWHITE liste_arg
  820.         { noparse(); }
  821.     | ADDEMPTY liste_arg
  822.         { noparse(); }
  823.     | LETTER liste_arg
  824.     | COMMENT ARG
  825.         { courant->commentaire = interne($2); }
  826.     | WHITE ARG
  827.         { courant->couleur = BLANC;
  828.         addcourant:
  829.           assert($2[0] >= 'a' && $2[0] <= 's'
  830.              && $2[1] >= 'a' && $2[1] <= 's'
  831.              && $2[2] == 0);
  832.           courant->position = Pt($2[0] - 'a' + 1, $2[1] - 'a' + 1);
  833.         }
  834.     | BLACK ARG
  835.           { courant->couleur = NOIR;
  836.           goto addcourant;
  837.         }
  838.     | NAME ARG
  839.     ;
  840.  
  841. /* Les proprietes qu'on ne trouve que sur le premier noeud */
  842. props1    : prop1 props1
  843.     | prop props1
  844.     | /* rien */
  845.     ;
  846. prop1    : SIZE ARG
  847.     | PLACE ARG
  848.     | DATE ARG
  849.     | FILEFORMAT ARG
  850.     | GAMENAME ARG
  851.     | VIEW ARG
  852.     | BLACKSPEC ARG
  853.     | WHITESPEC ARG
  854.     ;
  855.  
  856. liste_arg
  857.     : ARG liste_arg
  858.         { ; }
  859.     | ARG
  860.         { ; }
  861.     ;
  862. %%
  863. tfaire(courant, s) Noeud * courant; char * s; {
  864.   courant->position = Pt(s[0] - 'a' + 1, s[1] - 'a' + 1);
  865. }
  866.  
  867. # include "lex.yy.c"
  868. # include <ctype.h>
  869.  
  870. # ifndef PSFILE
  871. #    define PSFILE    "go.ps"
  872. # endif
  873.  
  874. char * file = "stdin";
  875.  
  876. main(ac, av)
  877.      char * av[];
  878. {
  879.   int compte = 1;
  880.   void arbre2ps();
  881.  
  882.  {                /* d'abord la preface PostScript */
  883.    char * filenom = PSFILE;
  884.    FILE * file;
  885.    char t[1024];
  886.  
  887.    if ((file = fopen(filenom, "r")) == 0){
  888.      perror(filenom);
  889.      exit(0);
  890.    }
  891.    while((compte = fread(t, sizeof t[0], sizeof t, file)) > 0)
  892.      fwrite(t, sizeof t[0], compte, stdout);
  893.    if (compte != 0)
  894.      perror(filenom);
  895.  }
  896.                 /* parser les args ou stdin */
  897.   if (ac == 1){
  898.     if (yyparse() == 0){
  899.       arbre2ps(racine);
  900.       ancien(racine);
  901.     }
  902.   } else
  903.     for(compte = 0; --ac > 0; compte += 1)
  904.       if (strcmp((++ av)[0], "-") != 0 && freopen(av[0], "r", stdin) != NULL){
  905.     file = av[0];
  906.     lino = 1;
  907.     if (yyparse() == 0){
  908.       arbre2ps(racine);
  909.       ancien(racine);
  910.     }
  911.       } else
  912.     perror(av[0]);
  913.   psfinir(compte);
  914. }
  915.  
  916. yyerror(){
  917.   fprintf(stderr, "%s:%d: le parseur a un probleme avec %s\n",
  918.       file, lino, yytext);
  919. }
  920. noparse(){
  921.   fprintf(stderr, "%s:%d: je ne parse pas %s\n", file, lino, yytext);
  922. }
  923. merror(){
  924.   fprintf(stderr, "Plus de memoire\n");
  925. }
  926.  
  927. /* strcherche  --  brutal, mais c'est fait une seule fois par partie */
  928. static char * strcherche(modele, texte) char * modele, * texte; {
  929.   int i, lm, lt;
  930.  
  931.   lm = strlen(modele);
  932.   lt = strlen(texte);
  933.   if (lm > lt)
  934.     return 0;
  935.   else {
  936.     for(i = 0; texte[i + lm] != 0; i += 1)
  937.       if (strncmp(modele, &texte[i], lm) == 0)
  938.     return & texte[i];
  939.     return strcmp(modele, & texte[i]) == 0 ? & texte[i] : 0;
  940.   }
  941. }
  942.  
  943. int nnoeud, ncoup, nvariante, ncommentaire;
  944. /* compter  --  compter et nmeroter coups et variantes */
  945. void compter(n) Noeud * n; {
  946.   nnoeud += 1;
  947.   n->numcoup = (ncoup += (n->couleur == BLANC || n->couleur == NOIR));
  948.   nvariante += (n->flag == VARIANTE);
  949.   ncommentaire += (n->commentaire != 0);
  950. }
  951.  
  952. /* handicap_compter  --  ajouter les pierres de handicap et les compter */
  953. void handicap_compter(n) Noeud * n; {
  954.   char * p;
  955.  
  956.   if (n->commentaire && (p = strcherche("Handicap: ", n->commentaire)) != 0){
  957.     int npierres = atoi(p + strlen("Handicap: "));
  958.     static int huit[][2] = { { 16, 4}, { 4,  16}, {  16, 16}, { 4, 4},
  959.                  { 16, 10}, { 4, 10}, { 10, 16}, { 10, 4} };
  960.     static int cinq[][2] = { { 10, 10} };
  961.     int i;
  962.  
  963.     if (npierres > 9  || npierres < 0)
  964.       fprintf(stderr, "%d pierres de handicap : je ne sais pas les poser\n", npierres);
  965.     if (npierres > 4 && npierres % 2 == 1){
  966.       ajoute_pierre(n, cinq[0][0], cinq[0][1]);
  967.       npierres -= 1;
  968.     }
  969.     for(i =  1; i <= npierres && i <= sizeof huit / sizeof huit[0]; i += 1)
  970.       ajoute_pierre(n, huit[i - 1][0], huit[i - 1][1]);
  971.   }
  972. }
  973. ajoute_pierre(r, n, m) Noeud * r; int n, m; {
  974.   Noeud * x;
  975.  
  976.   ncoup += 1;
  977.   x = nouvo();
  978.   x->flag = HANDICAP;
  979.   x->numcoup = 0;
  980.   x->position = Pt(n, m);
  981.   x->couleur = NOIR;
  982.  
  983.   x->next = r->next;
  984.   r->next = x;
  985. }
  986.  
  987. Noeud * pose[1+GOBAN][1+GOBAN];
  988. int ndessus;
  989. int ndessous;
  990. int maxdessus;
  991.  
  992. /* couvrir  --  marque, pour chaque pierre, celle qui est dessous, combien elle en a dessus */
  993. void couvrir(n) Noeud * n; {
  994.   if (n->flag == HANDICAP){
  995.     assert(pose[n->position.x][n->position.y] == 0);
  996.     pose[n->position.x][n->position.y] = n;
  997.   } else
  998.     if (n->couleur == BLANC || n->couleur == NOIR)
  999.       if (pose[n->position.x][n->position.y] == 0)
  1000.     pose[n->position.x][n->position.y] = n;
  1001.       else {
  1002.     ndessus += 1;
  1003.     n->dessous = pose[n->position.x][n->position.y];
  1004.     if ((n->dessous->ndessus += 1) > maxdessus)
  1005.       maxdessus = n->dessous->ndessus;
  1006.     if (n->dessous->ndessus == 1)
  1007.       ndessous += 1;
  1008.       }
  1009. }
  1010. /* handicap_couvrir  --  numerote *negativement* les pierres de handicap recouvertes */
  1011. handicap_couvrir(n) Noeud * n; {
  1012.   int compte = -1;
  1013.  
  1014.   for(n = n->next; n->flag == HANDICAP; n = n->next)
  1015.     if (n->ndessus != 0)
  1016.       n->numcoup = compte--;
  1017. }  
  1018.  
  1019.  
  1020. /* nomme  --  renvoie le nom d'un coup sous forme de char *, a utiliser vite */
  1021. char * nomme(n) Noeud * n; {
  1022. # define MAXNOMME 4        /* apres on ecrase */
  1023.   static char noms[MAXNOMME][4];
  1024.   static int inoms = 0;;
  1025.  
  1026.   assert(n->couleur == BLANC || n->couleur == NOIR);
  1027.  
  1028.   inoms %= MAXNOMME;
  1029.   if (n->numcoup > 0)
  1030.     sprintf(noms[inoms], "%d", n->numcoup);
  1031.   else if (n->numcoup < 0)
  1032.     sprintf(noms[inoms], "%c", 'a' - (n->numcoup + 1));
  1033.   else
  1034.     noms[inoms][0] = 0;
  1035.  
  1036.   return noms[inoms++];
  1037. }
  1038.  
  1039. /* applique  --  applique la fonction f au noeud, a son fils, au suivant */
  1040. void applique(n, f) Noeud * n; void (*f)(); {
  1041.   f(n);
  1042.   if (n->fils != 0)
  1043.     applique(n->fils, f);
  1044.   if (n->next != 0)
  1045.     applique(n->next, f);
  1046. }
  1047.  
  1048. static int npages;
  1049.  
  1050. /* arbre2ps  --  traduit l'arbre de coups en p*stscript */
  1051. void
  1052. arbre2ps(n)
  1053.      Noeud * n;
  1054. {
  1055.   int pscouvre(), pscoups(), pscommentaires(), koprep();
  1056.  
  1057.                 /* compte noeuds, coups et variantes */
  1058.   nnoeud = ncoup = nvariante = 0;
  1059.   applique(n, compter);
  1060.   handicap_compter(n);
  1061.   printf("%% %d noeuds, %d coups, %d variantes %d commentaires\n",
  1062.      nnoeud, ncoup, nvariante, ncommentaire);
  1063.   if (nvariante > 0)
  1064.     printf("%% Il y a %d variantes; je ne sais pas traiter les variantes\n",
  1065.        nvariante);
  1066.                 /* compte les recouvrements */
  1067.   { int i, j;
  1068.  
  1069.     for(i = 1; i <= GOBAN; i += 1)
  1070.       for(j = 1; j < GOBAN; j += 1)
  1071.     pose[i][j] = 0;
  1072.     ndessous = ndessus = maxdessus = 0;
  1073.     applique(n, couvrir);
  1074.     handicap_couvrir(n);
  1075. printf("%% %d pierres en pile (hauteur max : %d) sur %d endroits\n",
  1076.        ndessus, maxdessus, ndessous);
  1077.   }    
  1078.  
  1079.   printf("%%%%Page %d %d\n\nsave\ninitHaut\n", npages, npages + 1);
  1080.   npages += 1;
  1081.  
  1082.   /* titre */
  1083.   if (racine->commentaire != 0){
  1084.     printf("[ ");
  1085.     pschaine(racine->commentaire, "");
  1086.     printf(" ] titres\n\n");
  1087.   }
  1088.  
  1089.   /* le goban (ca place aussi les coordoonnees pour le reste) */
  1090.   printf("goban\n\n");
  1091.  
  1092.   /* pierres sur le goban */
  1093.   printf("[ ");
  1094.   applique(racine, pscoups);
  1095.   printf(" ] coups\n\n");
  1096.  
  1097.   /*
  1098.     se debrouiller avec les pierres recouvertes les unes par les autres :
  1099.     s'il y en a moins de 18, on peut les placer a droite du goban
  1100.     sinon, on traite les repetitions les plus frequentes comme des kos
  1101.    */
  1102.   if (ndessus != 0){
  1103.     extern int kolim;
  1104.  
  1105.     if (ndessus > 18){
  1106.  
  1107.       kolim = 3;
  1108.       applique(racine, koprep);
  1109.       printf("[ ");
  1110.       psko();
  1111.       printf(" ] kos\n");
  1112.       kofin();
  1113.     } else
  1114.       kolim = maxdessus;    /* pas de limite */
  1115.  
  1116.     printf("[ ");
  1117.     applique(racine, pscouvre);
  1118.     printf(" ] couvres\n\n");
  1119.   }
  1120.  
  1121.   /* commentaires */
  1122.   printf("[ ");
  1123.   applique(racine, pscommentaires);
  1124.   printf(" ] commentaires\n\n");
  1125.  
  1126.   printf("\n\nshowpage\n\nrestore\n\n");
  1127. }
  1128.  
  1129. /* psfinir  --  terminer le traitement d'un fichier */
  1130. psfinir(n) int n; {
  1131.   printf("%%%%Pages: %d\n", n);
  1132. }
  1133.  
  1134. /* pschaine  --  applique psfonc a toutes les lignes contenues dans s */
  1135. pschaine(s, psfonc) char * s, * psfonc; {
  1136.   char sauvecar = s[0];
  1137.  
  1138.   while(sauvecar != 0){
  1139.     char * p, * pp;
  1140.                 /* avance p jusqu'a la fin de la ligne */
  1141.     for(p = s; *p != 0 && *p != '\n'; p += 1)
  1142.       ;
  1143.     sauvecar = *p;
  1144.     *p = 0;
  1145. /* ad'hoc : n'affiche pas les lignes qui se terminent par ':' */
  1146.                 /* recule pp jusqu'au dernier car. */
  1147.     for(pp = p - 1; pp != s && *pp == ' '; pp -= 1)
  1148.       ;
  1149.     if (pp != s && *pp != ':')
  1150. /* fin du ad'hoc */
  1151.       printf("(%s) %s\n", s, psfonc);
  1152.     s = p + 1;
  1153.   }
  1154. }
  1155.  
  1156. /*
  1157.  Traitement des pierres recouvertes les unes par les autres
  1158.  */
  1159. int kolim;            /* hauteur de la pile avant de faire un ko */
  1160.  
  1161. /* pscouvre  --  le cas echeant, affiche le noeud comme "X en Y" */
  1162. pscouvre(n) Noeud * n; {
  1163.   if (n->dessous != 0 && n->dessous->ndessus <= kolim)
  1164.     printf("[ (%s) %d [ (%s) %d] ]\n",
  1165.        nomme(n->dessous), n->dessous->couleur, nomme(n), n->couleur);
  1166. }  
  1167.  
  1168. /* les piles de pierres pose'es quelquepart */
  1169. struct ko {
  1170.   Noeud * dessous;        /* qui est dessous */
  1171.   int ndessus;            /* combien il y en a dessus */
  1172.   Noeud ** dessus;        /* (les adresses de) ceux qui sont dessus */
  1173. } * kos;
  1174.  
  1175. /* koprep  --  le cas echeant, empile sur la pile des X en Y */
  1176. koprep(n) Noeud * n; {
  1177.   if (n->dessous != 0)
  1178.     if (n->dessous->ndessus > kolim){
  1179.       Noeud * sous = n->dessous;
  1180.       int i;
  1181.                 /* alloue si necessaire */
  1182.       if (kos == 0 && (kos = (struct ko *)calloc(ndessous, sizeof kos[0])) == 0)
  1183.     merror();
  1184.       for(i = 0; kos[i].dessous != 0; i += 1)
  1185.     if (kos[i].dessous == sous)
  1186.       break;
  1187.       if (kos[i].dessous == 0){
  1188.     kos[i].dessous = sous;
  1189.     if ((kos[i].dessus
  1190.          = (Noeud **)calloc(sous->ndessus, sizeof kos[0].dessus[0])) == 0)
  1191.       merror();
  1192.     kos[i].ndessus = 0;
  1193.       }
  1194.                 /* ajoute sur la pile */
  1195.       kos[i].dessus[kos[i].ndessus++] = n;
  1196.     }
  1197. }
  1198.  
  1199. /* psko  --  affiche les empilements */
  1200. psko(){
  1201.  int i, j;
  1202.  
  1203.  for(i = 0; i < ndessous && kos[i].dessous != 0; i += 1){
  1204.    printf("[ (%s) %d [", nomme(kos[i].dessous), kos[i].dessous->couleur);
  1205.    for(j = 0; j < kos[i].ndessus; j += 1)
  1206.      printf(" (%s) %d", nomme(kos[i].dessus[j]), kos[i].dessus[j]->couleur);
  1207.    printf("] ]\n");
  1208.  }
  1209. }
  1210.  
  1211. /* kofin  --  libere la memoire es empilements */
  1212. kofin(){
  1213.   if (kos != 0){
  1214.     int i;
  1215.  
  1216.     for(i = 0; i < ndessous; i += 1)
  1217.       free(kos[i].dessus);
  1218.     free(kos);
  1219.     kos = 0;
  1220.   }
  1221. }
  1222.  
  1223. /* pscoups  --  affiche un coup */
  1224. pscoups(n) Noeud * n; {
  1225.   if ((n->couleur == BLANC || n->couleur == NOIR) && n->dessous == 0)
  1226.     printf("[ (%s) %d %d %d ]\n", nomme(n), n->couleur, n->position.x,
  1227.        n->position.y);
  1228. }
  1229.  
  1230. /* pscommentaires  --  affiche un commentaire, avec son coup */
  1231. pscommentaires(n) Noeud * n; {
  1232.   if (n->commentaire != 0 && n != racine){
  1233.     printf("[ (%s) %d (%s) ]\n", nomme(n), n->couleur, n->commentaire);
  1234.   }
  1235. }
  1236. SHAR_EOF
  1237. fi
  1238. exit 0
  1239. #    End of shell archive
  1240.