[comp.sources.games] v12i086: mgt2 - display/edit Smart-Go Game Records

billr@saab.CNA.TEK.COM (Bill Randle) (06/05/91)

Submitted-by: adrian@milton.u.washington.edu (Adrian Mariano)
Posting-number: Volume 12, Issue 86
Archive-name: mgt2/Part04
Supersedes: mgt: Volume 8, Issue 88-92
Environment: Unix, MSDOS, VMS, curses



#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of archive 4 (of 4)."
# Contents:  Build.com Sample.01 asc_unix.inc comment.c mailgo.6 mgt.c
#   mgt.h proto.h
# Wrapped by billr@saab on Tue Jun  4 12:33:10 1991
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'Build.com' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'Build.com'\"
else
echo shar: Extracting \"'Build.com'\" \(2863 characters\)
sed "s/^X//" >'Build.com' <<'END_OF_FILE'
X$!
X$!	BUILD.COM for VMS, by Eric Osman (osman@hannah.enet.dec.com)
X$!
X$!	This procedure checks all .C files in the current directory, and
X$!	compiles any whose .OBJ file is older.  Then, all files are
X$!	linked.
X$!
X$!	CAUTION:	.H files are not checked, so if you change one,
X$!			you'll need to delete the .OBJ files of any .C
X$!			files that depend on that .H file.  That will allow
X$!			this BUILD.COM to recompile those .C files.
X$!
X$!	Usage:
X$!
X$!		@build [-Dname[=value]] [-g]
X$!
X$!	If -D is given, a corresponding /DEFINE is fed to the C compiler.
X$!
X$!	If -g is given, the linker is told to link a debug version.
X$!
X$!	Author:  Eric Osman   8-8-90
X$!
X$ on warning then exit
X$ on control_y then goto hey_stop
X$ cpl = "call do_cpl"
X
X	!! Find macro definitions and link switches
X
X$ n = 1
X$ macros = ""
X$ link_switches = ""
X$ plup: if n .le. 8
X$ then	next = p'n'
X$	n = n + 1
X$	qual = f$edit (f$extr(0,2,next),"upcase")
X$	if qual .eqs. "-D"
X$	then	definition = f$extr(2,f$len(next)-2,next)
X$		macros = macros + "/define=""" + definition + """"
X$	else if qual .eqs. "-G"
X$	then	link_switches = link_switches + "/debug"
X$	endif
X$	endif
X$	goto plup
X$ endif
X
X	!! Get all dates
X
X$ write sys$output "[Getting list of sources and objects]"
X$ dir/date/col=1/nohead/notrail/out=temp.txt *.c.0,*.obj.0/exclude=foo.*
X$ write sys$output "[Examining dates]"
X$ close/nolog b_chan
X$ close/nolog link_chan
X$ open b_chan temp.txt
X$ open/write link_chan temp.opt
X$ num = 0
X$ slup:
X$ read/end=nomore b_chan file_line
X$ read/end=nomore b_chan date_line
X$ type = f$parse (file_line,,,"type")
X$ name = f$parse (file_line,,,"name")
X$ if "''type'" .eqs. ".C"
X$ then	src_'num' = "''name'"
X$	num = num + 1
X$	write link_chan name + ".obj"
X$	date_tag = name + "_SRC_DATE"
X$ else date_tag = name + "_OBJ_DATE"
X$ endif
X$ date = f$edit(date_line,"trim")
X$ 'date_tag' = f$cvt(f$el(0," ",date) + ":" + f$el(1," ",date))
X$ goto slup
X$ nomore: close b_chan
X$ close link_chan
X$ n_srces = num
X$ num = 0
X$ dlup:
X$ src_name = src_'num'
X$ src_date = 'src_name'_src_date
X$ if f$type ('src_name'_obj_date) .eqs. ""
X$ then obj_date = ""
X$ else obj_date = 'src_name'_obj_date
X$ endif
X$ cpl 'src_name' "''src_date'" "''obj_date'"
X$ num = num + 1
X$ if num .lt. n_srces then goto dlup
X$ delete temp.txt.
X$
X	!! Link objects
X
X$ app sys$input temp.opt
Xsys$share:vaxcrtl.exe/share
X$ set verify
X$ link /exe=mgt temp/opt 'link_switches'
X$ delete temp.opt. ! 'f$ver(0)'
X$ exit
X$ hey_stop:
X$ set noverify
X$ exit
X
X$ do_cpl:
X$ subroutine
X$ on warning then exit
X$ src = p1 + ".c"
X$ obj = p1 + ".obj"
X$ if f$search (obj) .eqs. "" then goto cpl_it
X$ if p2 .lts. p3
X$ then
X$	write sys$output "[''obj' already o.k.]"
X$	exit
X$ endif
X$ cpl_it:
X$ def/user sys sys$library:
X$ set verify
X$ cc 'src' 'macros'/include=(decw$include:,sys$library:)/deb/mach/obj=temp.obj
X$ rename temp.obj 'obj' ! 'f$ver(0)'
X$ exit
X$ endsubroutine
X
END_OF_FILE
if test 2863 -ne `wc -c <'Build.com'`; then
    echo shar: \"'Build.com'\" unpacked with wrong size!
fi
# end of 'Build.com'
fi
if test -f 'Sample.01' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'Sample.01'\"
else
echo shar: Extracting \"'Sample.01'\" \(2382 characters\)
sed "s/^X//" >'Sample.01' <<'END_OF_FILE'
X(
X;
XGaMe[1]
XVieW[]
XSiZe[19]
XComment[A game between two amateurs both ranked betwen 10 kyu and 15 kyu
X    
X
XResult:  with no komi, black wins by 4]
X;
XBlack[pd]
X;
XWhite[qp]
X;
XBlack[dp]
X;
XWhite[dc]
X;
XBlack[op]
X;
XWhite[po]
X;
XBlack[lp]
X;
XWhite[pl]
X;
XBlack[de]
X;
XWhite[cd]
X;
XBlack[ed]
X;
XWhite[ce]
X;
XBlack[cf]
X;
XWhite[ec]
X;
XBlack[ci]
X;
XWhite[fd]
X;
XBlack[fe]
X;
XWhite[gd]
X;
XBlack[ph]
X;
XWhite[qi]
X;
XBlack[nc]
X;
XWhite[cn]
X;
XBlack[dn]
X;
XWhite[cp]
X;
XBlack[co]
X;
XWhite[bo]
X;
XBlack[do]
X;
XWhite[dq]
X;
XBlack[bp]
X;
XWhite[bq]
X;
XBlack[ap]
X;
XWhite[cq]
X;
XBlack[bn]
X;
XWhite[ep]
X;
XBlack[eo]
X;
XWhite[fq]
X;
XBlack[fp]
X;
XWhite[eq]
X;
XBlack[gp]
X;
XWhite[gq]
X;
XBlack[hq]
X;
XWhite[hp]
X;
XBlack[ho]
X;
XWhite[iq]
X;
XBlack[ip]
X;
XWhite[hr]
X;
XBlack[jq]
X;
XWhite[ir]
X;
XBlack[jr]
X;
XWhite[go]
X;
XBlack[gn]
X;
XWhite[io]
X;
XBlack[hn]
X;
XWhite[hp]
X;
XBlack[fo]
X;
XWhite[jp]
X;
XBlack[kq]
X;
XWhite[jn]
X;
XBlack[kd]
X;
XWhite[jc]
X;
XBlack[kc]
X;
XWhite[jd]
X;
XBlack[lg]
X;
XWhite[ke]
X;
XBlack[le]
X;
XWhite[kf]
X;
XBlack[lf]
X;
XWhite[if]
X;
XBlack[gg]
X;
XWhite[ge]
X;
XBlack[ff]
X;
XWhite[jh]
X;
XBlack[hj]
X;
XWhite[jk]
X;
XBlack[mk]
X;
XWhite[pq]
X;
XBlack[oq]
X;
XWhite[qh]
X;
XBlack[qg]
X;
XWhite[pi]
X;
XBlack[oh]
X;
XWhite[oi]
X;
XBlack[ni]
X;
XWhite[nh]
X;
XBlack[ng]
X;
XWhite[nj]
X;
XBlack[mh]
X;
XWhite[mj]
X;
XBlack[lm]
X;
XWhite[kp]
X;
XBlack[lo]
X;
XWhite[lq]
X;
XBlack[lr]
X;
XWhite[js]
X;
XBlack[mq]
X;
XWhite[oo]
X;
XBlack[no]
X;
XWhite[nn]
X;
XBlack[nm]
X;
XWhite[mn]
X;
XBlack[lj]
X;
XWhite[mi]
X;
XBlack[li]
X;
XWhite[mo]
X;
XBlack[np]
X;
XWhite[nk]
X;
XBlack[ml]
X;
XWhite[nl]
X;
XBlack[mm]
X;
XWhite[om]
X;
XBlack[il]
X;
XWhite[hh]
X;
XBlack[gh]
X;
XWhite[gf]
X;
XBlack[kg]
X;
XWhite[jg]
X;
XBlack[ii]
X;
XWhite[bf]
X;
XBlack[df]
X;
XWhite[cg]
X;
XBlack[dg]
X;
XWhite[bh]
X;
XBlack[ch]
X;
XWhite[bg]
X;
XBlack[bi]
X;
XWhite[gi]
X;
XBlack[hi]
X;
XWhite[dd]
X;
XBlack[ee]
X;
XWhite[hg]
X;
XBlack[fg]
X;
XWhite[ji]
X;
XBlack[gj]
X;
XWhite[nh]
X;
XBlack[pg]
X;
XWhite[aq]
X;
XBlack[ao]
X;
XWhite[jl]
X;
XBlack[kl]
X;
XWhite[im]
X;
XBlack[hl]
X;
XWhite[ln]
X;
XBlack[pr]
X;
XWhite[qr]
X;
XBlack[ps]
X;
XWhite[qs]
X;
XBlack[or]
X;
XWhite[km]
X;
XBlack[ko]
X;
XWhite[lk]
X;
XBlack[kk]
X;
XWhite[ll]
X;
XBlack[kj]
X;
XWhite[jj]
X;
XBlack[jo]
X;
XWhite[rg]
X;
XBlack[rf]
X;
XWhite[rh]
X;
XBlack[ip]
X;
XWhite[hq]
X;
XBlack[in]
X;
XWhite[kn]
X;
XBlack[hm]
X;
XWhite[kb]
X;
XBlack[lb]
X;
XWhite[ka]
X;
XBlack[la]
X;
XWhite[jb]
X;
XBlack[lc]
X;
XWhite[ih]
X;
XBlack[ah]
X;
XWhite[ag]
X;
XBlack[ai]
X;
XWhite[be]
X;
XBlack[sg]
X;
XWhite[sh]
X;
XBlack[ks]
X;
XWhite[is]
X;
XBlack[ik]
X;
XWhite[kh]
X;
XBlack[lh]
X;
XWhite[jm]
X;
XBlack[sf]
X;
XWhite[ni]
X;
XBlack[pp]
X;
XWhite[qq]
X)
X
END_OF_FILE
if test 2382 -ne `wc -c <'Sample.01'`; then
    echo shar: \"'Sample.01'\" unpacked with wrong size!
fi
# end of 'Sample.01'
fi
if test -f 'asc_unix.inc' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'asc_unix.inc'\"
else
echo shar: Extracting \"'asc_unix.inc'\" \(2560 characters\)
sed "s/^X//" >'asc_unix.inc' <<'END_OF_FILE'
X/* "mgt" Copyright (c) 1991 Shodan  */
X
X
X#include <curses.h>
X
Xchar envAscii[] = "q><.,eb}{][gkijuwzxv!lm#^cdns&prf123467890X@O=+-.+|-++++";
X
X
X#define NEWLINE "\n"
X#define openwin() WINDOW *win; notifyMessageAscii(EDHELP) ; win=newwin(WINHIGH+1,WINWIDE+1,WINTOP,WINLEFT)
X#define fixcursor()
X#define specialKeysEdit(c) (c)
X#define closewin() delwin(win)
X#define getKey() getch()
X#define preserveScreen() int j,k;char *screen;\
X        screen=(char *)malloc(24*(RIGHT+1));\
X        for(k=0,i=0;i<24;i++)\
X          for(j=0;j<=RIGHT;j++,k++)\
X            screen[k]=(char)mvinch(i,j);
X#define restoreScreen() for(k=0,i=0;i<24;i++)\
X                          for(j=0;j<=RIGHT;j++,k++){\
X			  if (i>TOP-2 && i< TOP+boardsize+1)\
X                            {\
X                              if (j==LEFT-1) set_inverse();\
X                              if (j==LEFT+boardsize*2) unset_inverse();\
X                            }\
X                          mvaddch(i,j,screen[k]);}\
X                          refresh();\
X                          free(screen);\
X                          unset_inverse()
X
X
X
Xstatic void saveScreen()
X{
X   int i, j;
X   char filename[33];
X   FILE *ft;
X
X   if (!(getLine("Save screen as? ", filename, 32) &&
X	 (ft = fopen(filename, "a"))))
X      getLine("Error opening file.  Hit return.", filename, 1);
X   else {
X      highlightLast();
X      for (i = 0; i < 24; i++) {
X	 for (j = 0; j < 80; j++) {
X	    fputc(mvinch(i, j) & 127, ft);
X	 }
X	 fputc('\n', ft);
X      }
X      fclose(ft);
X   }
X}
X
X
Xstatic void initAscii()
X{
X   initscr();
X   noecho();
X   crmode();
X}
X
X
X
Xstatic void plotMarkAscii(b, i, j)
X    pBoard b;
X    int i, j;
X{
X   void drawPiece();
X   piece p;
X   p = boardGet(b, i, j);
X   inverseFlag = !inverseFlag;
X
X   drawPiece(i, j, (p == P_NOTHING ? boardPiece(i, j) :
X		    (p == P_BLACK ? envAscii[(int) ASC_CHAR_BLACK] :
X		     envAscii[(int) ASC_CHAR_WHITE])));
X   inverseFlag = !inverseFlag;
X}
X
X
Xstatic int xpos(win)
X    WINDOW *win;
X{
X   int x, y;
X   getyx(win, y, x);
X   return x;
X}
X
X
Xstatic int ypos(win)
X    WINDOW *win;
X{
X   int y, x;
X   getyx(win, y, x);
X   return y;
X}
X
X
Xstatic command specialKeysIdle(c)
X    char c;
X{
X   return (command) 0;
X}
X
Xstatic void set_inverse()
X{
X
X   if (inverseFlag)
X      standout();
X}
X
Xstatic void unset_inverse()
X{
X   standend();
X}
X
X
Xstatic void initboard()
X{
X   int i, j;
X
X   clear();
X   if (inverseFlag) {
X      set_inverse();
X      for (i = LEFT + 1; i < LEFT + boardsize * 2 - 2; i += 2)
X	 for (j = TOP; j < TOP + boardsize; j++)
X	    mvaddch(j, i, ' ' + 128);
X      unset_inverse();
X   }
X}
END_OF_FILE
if test 2560 -ne `wc -c <'asc_unix.inc'`; then
    echo shar: \"'asc_unix.inc'\" unpacked with wrong size!
fi
# end of 'asc_unix.inc'
fi
if test -f 'comment.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'comment.c'\"
else
echo shar: Extracting \"'comment.c'\" \(2848 characters\)
sed "s/^X//" >'comment.c' <<'END_OF_FILE'
X/* "mgt" Copyright (c) 1991 Shodan  */
X
X#include "mgt.h"
X#include <string.h>
X#include <ctype.h>
X
X
Xshort clines;
Xchar cbuf[MAXCOMMENTLINES][MAXCOMMENTWIDTH];
Xchar *empty = "";
X
XFUNCTION char *commentGet(line)	/* int */
X    int line;
X{
X   if (line < clines)
X      return cbuf[line];
X   else
X      return empty;
X}
X
XFUNCTION int commentLines()
X{
X   return clines;
X}
X
X
XFUNCTION int wordLength(word)	/* char * */
X    char *word;
X{
X   int len;
X   len = 0;
X   while (*word && !isspace(*word++))
X      len++;
X   return MIN(len, 1);
X}
X
XFUNCTION int commentLineLength(comment, width)	/* char *, int */
X    char *comment;
X    int width;
X{
X   int len, wlen;
X
X   len = 0;
X   while (wlen = wordLength(comment), *comment && wlen + len < width)
X      len += wlen, comment += wlen;
X
X   return len ? len : MIN(wlen, width);
X}
X
XFUNCTION void formatComment(comment, width)
X    char *comment;
X    int width;
X{
X   char *partstart, *dest, c;
X   int len, partlen, wordlen;
X
X   clines = 0;
X   width = MIN(width, MAXCOMMENTWIDTH - 1);
X   partlen = len = 0;
X   dest = cbuf[0];
X   if (*comment == '\n')
X      comment++;
X   partstart = comment;
X   do {
X      c = *(comment++);
X      len++;
X      partlen++;
X      wordlen++;
X      if (c == ' ')
X	 wordlen = 0;
X      else if (c == '\n' && *(comment - 2) != '\n' &&
X	       *comment != '\n' && *comment != ' ') {
X	 *(comment - 1) = ' ';
X	 while (partlen > 2 && *(partstart + partlen - 2) == ' ')
X	    partlen--, len--;
X	 strncpy(dest, partstart, partlen);
X	 dest += partlen;
X	 partstart = comment;
X	 wordlen = partlen = 0;
X      } else if (c == '\n' || !c) {
X	 strncpy(dest, partstart, partlen - 1);
X	 *(dest + partlen - 1) = 0;
X	 len = partlen = wordlen = 0;
X	 dest = cbuf[++clines];
X	 partstart = comment;
X      }
X      if (len == width) {
X	 len = len - wordlen ? partlen - wordlen : partlen;
X	 strncpy(dest, partstart, len);
X	 partstart += len;
X	 *(dest + len) = 0;
X	 len = partlen = wordlen;
X	 dest = cbuf[++clines];
X      }
X   } while (c && clines < MAXCOMMENTLINES);
X
X}
X
X
X#if 0
X
X
X
XFUNCTION void formatComment(comment, width)	/* char *, int */
X    char *comment;
X    int width;
X{
X   char c;
X
X   clines = 0;
X   width = MIN(width, MAXCOMMENTWIDTH - 1);
X   do {
X      short len, srch;
X
X      len = srch = 0;
X
X      do {
X	 c = comment[srch++];
X	 if (c == ' ') {
X	    len = srch;
X	 } else if (c == '\n' &&
X		    comment[srch - 2] != '\n' &&
X		    comment[srch] != '\n' && comment[srch] != ' ') {
X	    comment[srch - 1] = ' ';
X	    len = srch;
X	 } else if (c == '\n' || !c) {
X	    len = srch - 1;
X	    break;
X	 }
X	 if (srch == width) {
X	    len = len ? len : srch;
X	    break;
X	 }
X      }
X      while (c);
X
X      if (len)
X	 strncpy(cbuf[clines], comment, len);
X      cbuf[clines++][len] = '\0';
X
X      comment += len + (c == '\n');
X      while (*comment == ' ')
X	 comment++;
X   }
X   while (c && clines < MAXCOMMENTLINES);
X}
X
X#endif
END_OF_FILE
if test 2848 -ne `wc -c <'comment.c'`; then
    echo shar: \"'comment.c'\" unpacked with wrong size!
fi
# end of 'comment.c'
fi
if test -f 'mailgo.6' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'mailgo.6'\"
else
echo shar: Extracting \"'mailgo.6'\" \(2302 characters\)
sed "s/^X//" >'mailgo.6' <<'END_OF_FILE'
X.TH MAILGO 6  "5 April 1991"
X.SH NAME
Xmailgo - shell script for using mgt to automate email go games
X.SH SYNOPSIS
X.B mailgo [\-r] [\-n] [filename]
X.SH DESCRIPTION
X.B mailgo
Xhelps manage email games by processing Smart-Go game records received by
Xmail, invoking mgt, and automatically sending your next move back.
X.LP
XInvoking 
X.B mailgo 
Xwith no flags instructs the program to search the specified file for a
Xgo game, ignoring mail headers or other such garbage.  
X.B mailgo 
Xwill invoke the game processor specified in the environment variable
XMAILGO or of this variable is undefined, will attempt to run 
X.B mgt
Xfrom the inherited path.
X.LP
XIf your opponent loses your move, you can resend the game with the \-r
Xswitch.
X.LP
XTo start a new game, use the \-n switch.  Without a file, you will be 
Xprompted for your address, your opponent's address, and the filename for
Xboth your and your opponent's local game record.  The game processor will
Xthen be invoked for you to make the first move.  If a filename is specified,
Xthe address and filename data is taken from that file.
X.SH FILE FORMAT
X.LP
X.sp
X.if
X Leading garbage ignored
X
X ---GoGaMeStArT---
X TO: opponent@hissite
X TOFILE: his_game_record
X FROM: me@mysite
X FROMFILE: my_game_record
X (
X Smart\-Go game data
X )
X ---GoGaMeEnD---
X
X Trailing garbage ignored
X.fi
X.LP
XThe game data file contains a leading tag to indicate the start of 
Xthe data.  It contains both addresses, as should be used to mail the
Xgame files, and it contains the files to store the games in.  In the
Xexample above, you are playing opponent@hissite, and the game is being
Xstored in my_game_record.
X.LP
XWhen 
X.B mailgo
Xis used normally, the file specified on the command line is removed at
Xsuccessful completion, and the new game is saved to the file specified in
Xthe received game record.  If the destination file does not look like
Xa mailgo file, 
X.B mailgo
Xwill query for confirmation.
X.SH FILES
Xmgt
X.LP
XSmart-Go.def, the Smart\-Go format definition.
X.sp
X.SH BUGS
X.LP
XIf you attempt to start a new game, but are not the first player to make a 
Xreal move, then you will have to convince mgt that you have changed the game 
Xrecord.  Do this by pressing z twice on a blank spot to set and remove a black 
Xstone.
X.fi
X.sp
X.SH AUTHOR
XAdrian Mariano (adrian@milton.u.washington.edu)
X
END_OF_FILE
if test 2302 -ne `wc -c <'mailgo.6'`; then
    echo shar: \"'mailgo.6'\" unpacked with wrong size!
fi
# end of 'mailgo.6'
fi
if test -f 'mgt.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'mgt.c'\"
else
echo shar: Extracting \"'mgt.c'\" \(3347 characters\)
sed "s/^X//" >'mgt.c' <<'END_OF_FILE'
X/* "mgt" Copyright (c) 1991 Shodan  */
X
X#include <signal.h>
X#include "mgt.h"
X
Xint retVal = 0;
Xinterface *io;			/* current interface routines */
Xint boardsize;			/* global for board size */
Xchar *commentBuf;		/* pointer to current node's comment */
Xextern interface asciiInterface;
Xint prisoners[2];
XFILE *input = 0;
Xchar name_buf[512];
Xchar *files[MAX_FILES];
Xint filecount, currentfile;
X
X#ifdef MGT_IBM
Xextern int _stklen = 20000;
X#endif
X
X
Xtypedef struct {
X   char *arg;
X   int *flag;
X   char **str;
X}  argType;
X
X
Xint mailFlag = 0;
Xint saveShort = 0;
Xchar *saveName;
X
X
X
Xstatic argType argTable[] =
X{
X   {"-m", &mailFlag, &saveName},
X   {"-s", &saveShort, NULL}
X};
X
X
XFUNCTION main(argc, argv)
X    int argc;
X    char **argv;
X{
X   io = &asciiInterface;
X   input = stdin;
X   init(argv, &argc);
X   parseLine(argc, argv);
X   doit();
X   myexit();
X}
X
X
X
XFUNCTION void die()
X{
X   signal(SIGINT, SIG_DFL);
X   myexit();
X}
X
X
XFUNCTION void myexit()
X{
X   (*io->clearScreen) ();
X   (*io->refreshIO) ();
X   (*io->close) ();
X   (*io->clearScreen) ();
X   printf("Thank you for using mgt\n");
X   exit(retVal);
X}
X
X
X
XFUNCTION void openfile(f)
X    char *f;
X{
X#ifdef MGT_LIB
X   char game_lib[] = MGT_LIB;
X#endif				/* MGT_LIB */
X   strcpy(name_buf, f);
X   if (!(input = fopen(f, "r")))
X      strcpy(name_buf, "");
X#ifdef MGT_LIB
X   /* if not in local directory, try library */
X   if (!input) {
X      strcpy(name_buf, game_lib);
X      strcat(name_buf, f);
X      input = fopen(name_buf, "r");
X   }
X#endif				/* MGT_LIB */
X}
X
X
XFUNCTION void barf(s)
X    char *s;
X{
X   int i;
X   for (i = 24; i--;)
X      fprintf(stderr, "\n");
X   fprintf(stderr, "%s\n", s);
X   exit(1);
X}
X
X
XFUNCTION void initEnv()
X{
X   extern char *getenv();
X   char *env;
X
X   if (env = getenv("MGT"))
X      while (*env) {
X	 while (*env && *env != '_')
X	    env++;
X	 if (*env)
X	    env++;
X	 if (*env)
X	    (*io->readEnv) (&env);
X      }
X}
X
X
XFUNCTION void init(argv, argc)
X    char *argv[];
X    int *argc;
X{
X   (*io->open) (argv, argc);
X   initEnv();
X   signal(SIGINT, die);
X   readInit();
X   boardsize = 19;
X}
X
X
X
XFUNCTION void helpCommandLine(errMesg)
X    char *errMesg;
X{
X   (*io->close) ();
X   fprintf(stderr, "\nERROR: %s\n\n", errMesg);
X   fprintf(stderr, "                   MGT %s\n", VERSION);
X   fprintf(stderr, "\nUsage: mgt [opts] [files]\n");
X   fprintf(stderr, "[opts] is any of:\n");
X   fprintf(stderr, "-m filename        mail mode.  Autosave on quit.\n");
X   fprintf(stderr, "-s                 use short format when saving.\n\n");
X   exit(2);
X}
X
X
XFUNCTION void parseLine(argc, argv)
X    int argc;
X    char **argv;
X{
X   int i;
X
X   filecount = 0;
X
X   while (++argv, --argc > 0) {
X      if (**argv != '-') {
X	 files[filecount++] = *argv;
X	 if (filecount == MAX_FILES)
X	    helpCommandLine("Too many files specified");
X      } else {
X	 for (i = 0; i < sizeof(argTable) / sizeof(argType); i++)
X	    if (!strcmp(argTable[i].arg, *argv)) {
X	       if (argTable[i].str)
X		  if (--argc)
X		     *(argTable[i].str) = (*++argv);
X		  else
X		     helpCommandLine("String expected on option");
X	       (*(argTable[i].flag))--;
X	       break;
X	    }
X	 if (i == sizeof(argTable) / sizeof(argType))
X	    helpCommandLine("Bad option");
X      }
X   }
X   if (!filecount)
X      input = stdin;
X   else {
X      currentfile = 0;
X      openfile(files[0]);
X      if (!input)
X	 helpCommandLine("File not found");
X   }
X
X}
END_OF_FILE
if test 3347 -ne `wc -c <'mgt.c'`; then
    echo shar: \"'mgt.c'\" unpacked with wrong size!
fi
# end of 'mgt.c'
fi
if test -f 'mgt.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'mgt.h'\"
else
echo shar: Extracting \"'mgt.h'\" \(2912 characters\)
sed "s/^X//" >'mgt.h' <<'END_OF_FILE'
X/* "mgt" Copyright (c) 1991 Shodan  */
X
X#define VERSION "2.1"
X
X#ifdef DEBUG
X#define BUG(s) fprintf(debug,s)
X#else
X#define BUG(s)
X#endif
X
X#define FUNCTION
X#define false 0
X#define true 1
X
X#define MAX(a,b) ((a)>(b)?a:b)
X#define MIN(a,b) ((a)<(b)?a:b)
X
X#define MAX_FILES 200
X#define MAX_LETTERS 12
X#define MAXCOMMENT 4097
X#define MAXCOMMENTLINES 300
X#define MAXCOMMENTWIDTH 50
X
Xtypedef int boolean;
X
Xtypedef enum {
X   C_QUIT = 0,
X   C_DOWN, C_UP,
X   C_WALKDOWN, C_WALKUP,
X   C_END, C_BEGINNING,
X   C_SEARCHCOMMENT, C_SEARCHBACKCOMMENT,
X   C_DOWNFORK, C_UPFORK,
X   C_GOTO,
X   C_COMMENTSCROLLDOWN, C_COMMENTSCROLLUP,
X   C_TREESCROLLDOWN, C_TREESCROLLUP,
X   C_WRITE,
X   C_ADDBLACK, C_ADDWHITE,
X   C_ADDVAR,
X   C_TREECUT,
X   C_ADDLETTER, C_ADDMARK,
X   C_LOAD, C_PASTE,
X   C_EDCOMMENT,
X   C_DELNODE, C_ADDNAME, C_SCORE, C_VIDEO, C_PASS, C_BACKFILE, C_NEXTFILE,
X   C_DOWNLEFT, C_CURDOWN, C_DOWNRIGHT, C_CURLEFT,
X   C_CURRIGHT, C_UPLEFT, C_CURUP, C_UPRIGHT, C_MOVE,
X   C_REDRAW,			/* last supported key command in environments */
X   C_NOTHING, C_CHOSECHILD,
X}  command;
X
X#define C_NEXTCMD ((command)( ((int)C_CHOSECHILD) + 128 ))
X/* ^^  fix compilers that don't allow enum { x, y = x + 5 }; 2/15/90 */
X
X
X
Xtypedef int commandIndex;
X
X
Xtypedef enum {
X   t_White,
X   t_Black,
X   t_Open,
X   t_Close,
X   t_NewNode,
X   t_Comment,
X   t_AddWhite,
X   t_AddBlack,
X   t_Letter,
X   t_Mark,
X   t_AddEmpty,
X   t_Name,
X   t_Size,
X   t_WS,
X   t_EOF
X}
X   Token;
X
Xtypedef enum {
X   P_NOTHING = 0, P_BLACK, P_WHITE, P_DAME, P_BLACKTERR, P_WHITETERR, P_CHECKED
X}
X   piece;
X
Xtypedef piece boardType[19][19];
X
Xtypedef struct {
X   boardType b;
X}
X   board, *pBoard;
X
X
Xtypedef int (*pfi) ();
X
Xtypedef struct {
X   char *name;
X   char *option;
X   char *storage;
X   pfi open, close, refreshIO, plotPiece, displayComment, clearComment, clearBoard,
X      clearScreen, idle, drawTree, highlightLast, readEnv, notifyMessage,
X      notifyClear, queryStr, setCursor, plotMark, plotLetter, getPoint, editComment,
X      askYN;
X}
X   interface, *interfaceP;
X
Xtypedef struct {
X   int x, y;
X}
X   coord;
X
Xtypedef struct {
X   char b[46];
X}
X   coordList, *coordListP;
X
X
Xtypedef union {
X   coordList addBlack, addWhite, remove;
X   coord letter[MAX_LETTERS];
X   char comment;
X}
X   data;
X
Xtypedef struct propertyRec {
X   struct propertyRec *next;
X   Token t;
X   data *d;
X}
X   property;
X
X
Xtypedef struct noderec {
X   property *p;
X   int nodeNum;
X   struct noderec *parent, *child, *nextSibling, *lastSibling;
X}
X   node, *nodep;
X
X
X#include "proto.h"
X#include <stdio.h>
X
X#ifdef MGT_IBM
X#include <alloc.h>
X#endif
X
Xextern interface *io;
Xextern int boardsize;
Xextern FILE *input;
Xextern int xcur, ycur;
Xextern Token curPlayer;
Xextern int mailFlag;
Xextern int saveShort;
Xextern char *saveName;
Xextern int retVal;
Xextern char name_buf[512];
Xextern filecount, currentfile;
Xextern char *files[MAX_FILES];
X
X#ifdef DEBUG
Xextern FILE *debug;
Xextern unsigned long totalmemory;
X#endif
END_OF_FILE
if test 2912 -ne `wc -c <'mgt.h'`; then
    echo shar: \"'mgt.h'\" unpacked with wrong size!
fi
# end of 'mgt.h'
fi
if test -f 'proto.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'proto.h'\"
else
echo shar: Extracting \"'proto.h'\" \(2452 characters\)
sed "s/^X//" >'proto.h' <<'END_OF_FILE'
Xextern void clearLast();
Xextern void highlightLast();
Xextern void doPlace();
Xextern void doProps();
Xextern void doPropComment();
Xextern void buildTree0();
Xextern void buildTree();
Xextern void setPiece();
Xextern void updateBoard();
Xextern char *commentGet();	/* int */
Xextern int commentLines();
Xextern int wordLength();	/* char * */
Xextern int commentLineLength();	/* char *, int */
Xextern void formatComment();
Xextern void formatComment();	/* char *, int */
Xextern int okChange();
Xextern int okExit();
Xextern nodep search();
Xextern void step();
Xextern void stepDown();
Xextern void doScore();
Xextern void doit();
Xextern void writeStrEscaped();
Xextern void writeNode();
Xextern void WriteSubTree();
Xextern int writeCoordList();
Xextern int writeCoordArray();
Xextern int writeTree();
Xextern void clearArray();
Xextern int addMark();
Xextern void addStone();
Xextern int makeMove();
Xextern void makeVariation();
Xextern void cutTree();
Xextern void pasteTree();
Xextern void edComment();
Xextern void deleteNode();
Xextern void makeName();
Xextern void replaceComment();
Xextern main();
Xextern void die();
Xextern void myexit();
Xextern void openfile();
Xextern void barf();
Xextern void initEnv();
Xextern void init();
Xextern void helpCommandLine();
Xextern void parseLine();
Xextern void readInit();
Xextern void addChild();		/* add child c to node n */
Xextern nodep parse();
Xextern int legal();
Xextern boolean inRange();
Xextern int lib0();
Xextern int liberties();		/* count the # of liberties for group at i,j */
Xextern void removeStones();
Xextern boolean tryKill();
Xextern boolean placeStone();
Xextern void boardSet();
Xextern piece boardGet();
Xextern void boardClear();
Xextern void copyBoard();
Xextern void scoreBoard();
Xextern piece Owner();
Xextern int Owner0();
Xextern int New();		/* 3= undetermined, 4=p1, 5=p2, -1=shared */
Xextern boolean getCoord();
Xextern void setCoord();
Xextern void clearCoord();
Xextern void initNodes();
Xextern nodep newNode();
Xextern void freeNode();
Xextern char *dupStr();
Xextern void freeProps();
Xextern void delNode();
Xextern void addprop();
Xextern property *getprop();
Xextern int treeCountSiblings();
Xextern nodep nthChild();	/* nodep, int */
Xextern nodep parent();
Xextern nodep child();
Xextern nodep lastSibling();
Xextern nodep nextSibling();
Xextern nodep treeLastSibling();
Xextern nodep treeDown();
Xextern nodep treeUp();
Xextern nodep treeNextUp();
Xextern nodep treeNext();
Xextern nodep lastChildOfLastSibling();
Xextern nodep treeLast();
END_OF_FILE
if test 2452 -ne `wc -c <'proto.h'`; then
    echo shar: \"'proto.h'\" unpacked with wrong size!
fi
# end of 'proto.h'
fi
echo shar: End of archive 4 \(of 4\).
cp /dev/null ark4isdone
MISSING=""
for I in 1 2 3 4 ; do
    if test ! -f ark${I}isdone ; then
	MISSING="${MISSING} ${I}"
    fi
done
if test "${MISSING}" = "" ; then
    echo You have unpacked all 4 archives.
    rm -f ark[1-9]isdone
else
    echo You still need to unpack the following archives:
    echo "        " ${MISSING}
fi
##  End of shell archive.
exit 0