home *** CD-ROM | disk | FTP | other *** search
- Path: uunet!zaphod.mps.ohio-state.edu!usc!news.service.uci.edu!unogate!mvb.saic.com!dayton.saic.com!dayvd.dayton.saic.com!ake
- From: ake@dayvd.dayton.saic.com (Earle Ake)
- Newsgroups: vmsnet.sources.games
- Subject: ldb - Long Distance Backgammon [13/16]
- Date: 8 Apr 93 11:04:09 EST
- Organization: Science Applications Intl Corp - Dayton, OH
- Lines: 1291
- Message-ID: <1993Apr8.110409.1@dayvd.dayton.saic.com>
- NNTP-Posting-Host: dayvd.dayton.saic.com
- Xref: uunet vmsnet.sources.games:674
-
- -+-+-+-+-+-+-+-+ START OF PART 13 -+-+-+-+-+-+-+-+
- X`20*`20Note`20that`20the`20file`20argument`20can`20be`20actually`20be`20a`20pa
- Vttern,`20causing
- X`20*`20all`20matching`20files`20to`20be`20scanned.`20`20On`20UNIX`20systems,
- V`20patterns`20are
- X`20*`20interpreted`20in`20the`20same`20manner`20as`20the`20shell.`20`20On`20VM
- VS,`20they
- X`20*`20are`20interpreted`20in`20the`20same`20manner`20as`20DCL.
- X`20*----------------------------------------------------------------------
- X`20*/
- X
- Xreadmail(file)
- Xchar`20*file;
- X`7B
- Xstruct`20flist`20*fl,`20*t;
- X
- Xfl`20=`20filelist(file);`09`09/*`20generate`20a`20list`20of`20all`20matching
- V`20files`20*/
- Xwhile`20(fl`20!=`20NULL)`20`7B`09`09/*`20for`20each`20matching`20file`20found
- V`20*/
- X`09readfile(fl->name);`09/*`20scan`20it`20*/
- X`09free(fl->name);`09`09/*`20free`20the`20string`20*/
- X`09t`20=`20fl;`09`09`09/*`20keep`20a`20pointer`20to`20the`20struct`20*/
- X`09fl`20=`20fl->next;`09`09/*`20advance`20fl`20pointer`20*/
- X`09free(t);`09`09/*`20free`20the`20previous`20struct`20*/
- X`09`7D
- X`7D
- X
- X
- X/*----------------------------------------------------------------------
- X`20*`09readfile`20--`20scan`20a`20file`20looking`20for`20incoming`20messages
- X`20*
- X`20*`20This`20function`20is`20called`20by`20readmail`20to`20scan`20a`20file
- V`20that`20matches
- X`20*`20the`20pattern.
- X`20*----------------------------------------------------------------------
- X`20*/
- X
- Xreadfile(name)
- Xchar`20*name;
- X`7B
- XFILE`20*fp;
- Xint`20d,`20c1,`20c2;
- Xint`20flags`20=`200,`20match`20=`200;
- Xstruct`20people`20*p;
- Xstruct`20game`20*g;
- X
- Xif`20(`20(fp`20=`20fopen(name,"r"))`20==`20NULL)
- X`09return;
- Xif`20(rc.debug`20`26`20DB_READFILE)
- X`09message("DB-readfile:`20scanning`20%s`5Cn",name);
- Xwhile`20(getpkt(fp)`20>`200)`20`7B`09/*`20as`20long`20as`20we`20found`20a`20va
- Vlid`20packet`20*/
- X`09if`20(P.gameptr`20==`20NULL)`20`7B
- X`09`09if`20(rc.debug`20`26`20DB_READFILE)
- X`09`09`09message("DB-readfile:`20found`20packet`20for`20<unknown>`5Cn");
- X`09`09if`20(P.opcode`20==`20START)`20`7B
- X`09`09`09if`20(`20((p`20=`20findppl(P.addr,P_ADDR))`20!=`20NULL)`20`26`26
- X`09`09`09`20`20`20`20`20(p->fence`20>=`20P.timestamp)`20)
- X`09`09`09`09continue;`09/*`20ignore`20old`20start`20packets`20*/
- X`09`09`09P.gameptr`20=`20addgame();`20/*`20init`20later`20in`20start()`20*/
- X`09`09`09P.gameptr->ppl`20=`20p;
- X`09`09`09P.gameptr->gameid`20=`20P.gameid;
- X`09`09`09P.gameptr->state`20=`20ST_OPSTART;
- X`09`09`09`7D
- X`09`09else`20if`20(P.opcode`20==`20RSTART)`20`7B`09/*`20remote`20start`20packe
- Vt`20*/
- X`09`09`09if`20(rc.debug`20`26`20DB_RSTART)
- X`09`09`09`09message("DB-readfile:`20remstart`20to`20%s`5Cn",P.addr);
- X`09`09`09if`20(`20(p`20=`20findppl(P.addr,P_ADDR))`20!=`20NULL)
- X`09`09`09`09P.addr`20=`20p->addr;`09/*`20use`20real`20addr`20*/
- X`09`09`09for`20(g`20=`20ghead;`20g`20!=`20NULL;`20g`20=`20g->next)
- X`09`09`09`09if`20(`20(P.timestamp`20==`20g->starttime)`20`26`26
- X`09`09`09`09`20`20`20`20`20(strcmp(P.addr,g->opaddr)`20==`200)`20)
- X`09`09`09`09`09break;`09/*`20already`20seen`20this`20packet`20*/
- X`09`09`09if`20(g`20!=`20NULL)
- X`09`09`09`09continue;
- X`09`09`09if`20(`20(p`20!=`20NULL)`20`26`26`20(p->fence`20>=`20P.timestamp)`20)
- V
- X`09`09`09`09continue;`09/*`20this`20game`20already`20played`20*/
- X`09`09`09if`20(rc.debug`20`26`20DB_RSTART)
- X`09`09`09`09message("DB-readfile:`20address`20is`20%s`5Cn",P.addr);
- X`09`09`09if`20(P.dir`20==`20NULL)`09/*`20if`20no`20direction`20was`20given`20*
- V/
- X`09`09`09`09d`20=`20cr_mydir;`09/*`20use`20my`20default`20*/
- X`09`09`09else`09`09`09/*`20dir`20was`20given,`20grab`20it`20*/
- X`09`09`09`09d`20=`20(*P.dir`20==`20'u')`20?`201`20:`20-1;
- X`09`09`09if`20(P.colors`20==`20NULL)`20`7B`09/*`20if`20no`20colors`20were`20gi
- Vven`20*/
- X`09`09`09`09c1`20=`20cr_mycolor;`09/*`20use`20my`20defaults`20*/
- X`09`09`09`09c2`20=`20cr_opcolor;
- X`09`09`09`09`7D
- X`09`09`09else`20`7B`09`09`09`09/*`20colors`20were`20given`20*/
- X`09`09`09`09c1`20=`20*P.colors;`09`09/*`20use`20them`20*/
- X`09`09`09`09c2`20=`20P.colors`5B1`5D;
- X`09`09`09`09`7D
- X`09`09`09if`20(P.jacoby`20!=`20NULL)
- X`09`09`09`09flags`20`7C=`20F_JACOBY;
- X`09`09`09if`20(P.crawford`20!=`20NULL)
- X`09`09`09`09flags`20`7C=`20F_CRAWFORD;
- X`09`09`09if`20(P.european`20!=`20NULL)
- X`09`09`09`09flags`20`7C=`20F_EUROPE;
- X`09`09`09if`20(P.perm`20!=`20NULL)
- X`09`09`09`09flags`20`7C=`20F_PERM;
- X`09`09`09if`20(P.match`20!=`20NULL)
- X`09`09`09`09match`20=`20atoi(P.match);
- X`09`09`09notify`20=`20P.notify;`09/*`20store`20notify`20address`20*/
- X`09`09`09startgame(P.addr,d,c1,c2,flags,match,P.timestamp);
- X`09`09`09continue;`09/*`20game`20started,`20discard`20this`20packet`20*/
- X`09`09`09`7D
- X`09`09else`20`7B
- X`09`09`09message("ERROR:`20no`20such`20gameid:`20%s`20(ignored)`5Cn",
- X`09`09`09`09P.gameid);
- X`09`09`09continue;
- X`09`09`09`7D
- X`09`09`7D
- X`09if`20(rc.debug`20`26`20DB_READFILE)
- X`09`09message("DB-readfile:`20found`20packet`20for`20%s`5Cn",
- X`09`09`09P.gameptr->gameid);
- X`09if`20(P.gameptr->state`20>=`20OPSTATES)`20`7B`09/*`20hey,`20it's`20still
- V`20my`20turn`20*/
- X`09`09message("ERROR:`20move`20out`20of`20turn:`20%s`20(ignored)`5Cn",P.gameid
- V);
- X`09`09continue;
- X`09`09`7D
- X`09if`20(P.name`20!=`20NULL)`20`7B`09`09/*`20snarf`20opponent's`20name`20*/
- X`09`09P.gameptr->opname`20=`20P.name;
- X`09`09if`20(P.gameptr->ppl`20!=`20NULL)
- X`09`09`09P.gameptr->ppl->name`20=`20save(P.name);
- X`09`09`7D
- X`09if`20(P.notify`20!=`20NULL)
- X`09`09P.gameptr->notify`20=`20P.notify;
- X`09(*func`5BP.gameptr->state`5D`5BP.opcode`5D)(P.gameptr);`09/*`20call`20handl
- Ver`20*/
- X`09`7D
- Xfclose(fp);
- Xif`20(`20((*rc.delmail`20==`20'y')`20`7C`7C`20(*rc.delmail`20==`20'Y'))
- X#ifndef`20VMS
- X`09`09`26`26`20(*name`20!=`20'/')`09/*`20absolute`20paths`20not`20deleted`20*/
- V
- X#endif
- X`09)`20`7B
- X`09if`20(rc.debug`20`26`20DB_READFILE)
- X`09`09message("DB-readfile:`20deleting`20mail`20file`20%s`5Cn",name);
- X`09unlink(name);
- X`09`7D
- X`7D
- X
- X
- X/*---------------------------------------------------------------------------
- X`20*`09getpkt`20--`20read`20one`20packet`20from`20a`20file
- X`20*
- X`20*`20This`20function`20reads`20the`20next`20packet`20from`20the`20specified
- V`20file.
- X`20*`20Getpkt()`20is`20passed`20a`20open`20file`20pointer`20to`20the`20file
- V`20it`20is`20to`20scan.
- X`20*`20Lines`20are`20read`20and`20discarded`20until`20a`20line`20is`20found
- V`20that`20contains`20only:
- X`20*`09`09<<<===LDB===>>>
- X`20*`20Subsequent`20lines`20should`20contain`20name/value`20pairs`20as`20speci
- Vfied
- X`20*`20in`20nv_packet.`20`20The`20packet`20ends`20with`20end`20of`20file`20or
- V`20a`20line`20beginning
- X`20*`20with`20"end=".`20`20Getpkt`20reads`20from`20the`20input`20file`20until
- V`20one
- X`20*`20packet`20has`20been`20found`20and`20processed,`20then`20returns.`20`20S
- Vubsequent`20calls
- X`20*`20to`20getpkt`20with`20the`20same`20file`20pointer`20will`20process`20add
- Vitional`20packets.
- X`20*`20Getpkt`20returns`201`20if`20a`20valid`20packet`20was`20read,`200`20if
- V`20EOF`20was`20encountered.
- X`20*`20Getpkt`20ignores`20incoming`20packets`20with`20the`20incorrect`20sequen
- Vce`20number.
- X`20*
- X`20*`20As`20a`20compatibility`20hook`20with`20old`20versions,`20getpkt`20check
- Vs`20that`20the
- X`20*`20version`20field`20on`20the`20incoming`20packet`20is`20high`20enough`20t
- Vo`20support
- X`20*`20the`20following`20features`20if`20they`20are`20enabled`20in`20the`20gam
- Ve:
- X`20*`09feature`09`09need`20at`20least`20version
- X`20*`09-------------------------------------
- X`20*`09match`20play`09`091.1
- X`20*`09jacoby`20rule`09`091.1
- X`20*`09crawford`20rule`09`091.1
- X`20*`09european`20rule`09`091.1
- X`20*`09permanent`20games`09`091.1
- X`20*`20If`20the`20incoming`20packet`20indicates`20a`20feature`20is`20not`20sup
- Vported`20by`20the
- X`20*`20remote`20ldb,`20it`20is`20disabled`20and`20the`20game`20continues`20as
- V`20if`20it`20had
- X`20*`20never`20been`20set.`20`20The`20Crawford`20rule`20contained`20a`20bug
- V`20in`20pre-1.3`20games,
- X`20*`20so`201.3`20will`20print`20a`20warning`20if`20an`20older`20version`20tri
- Ves`20to`20start
- X`20*`20a`20game`20with`20the`20crawford`20rule`20enabled.
- X`20*
- X`20*`20Getpkt`20handles`20RESEND`20packets`20itself,`20performing`20a`20resend
- V`20and
- X`20*`20discarding`20the`20packet.
- X`20*--------------------------------------------------------------------------
- V-
- X`20*/
- X
- Xgetpkt(fp)
- XFILE`20*fp;
- X`7B
- Xstatic`20char`20buf`5B128`5D;
- Xint`20i;
- X
- Xwhile`20(fgets(buf,sizeof(buf),fp)`20!=`20NULL)`20`7B
- X`09if`20(strcmp(buf,"<<<===LDB===>>>`5Cn"))/*`20skip`20all`20other`20lines`20*
- V/
- X`09`09continue;
- X`09P.gameid`20=`20NULL;`09/*`20init`20P`20structure`20*/
- X`09P.version`20=`20100;`09/*`20default`20to`20oldest`20version`20*/
- X`09P.timestamp`20=`200L;
- X`09P.opcode`20=`20-1;
- X`09P.name`20=`20NULL;
- X`09P.addr`20=`20NULL;
- X`09P.comment`20=`20NULL;
- X`09P.comment2`20=`20NULL;
- X`09P.seq`20=`20-1;
- X`09P.autodbl`20=`20NULL;
- X`09P.jacoby`20=`20NULL;`09/*`20jacoby`20is`20off`20by`20default`20*/
- X`09P.crawford`20=`20NULL;`09/*`20so`20is`20crawford`20*/
- X`09P.perm`20=`20NULL;`09`09/*`20so`20is`20permanent`20option`20*/
- X`09P.european`20=`20NULL;`09/*`20so`20is`20european`20rule`20*/
- X`09P.match`20=`20NULL;`09`09/*`20so`20is`20match`20play`20*/
- X`09clearmvs(P.mvs);
- X`09P.gameptr`20=`20NULL;
- X`09P.notify`20=`20NULL;
- X`09nvscan(fp,nv_packet,`26P);`09/*`20scan`20the`20packet`20into`20P`20*/
- X`09if`20(P.gameid`20==`20NULL)`20`7B`09`09/*`20didn't`20get`20a`20gameid`20*/
- X`09`09message("ERROR:`20missing`20gameid`20in`20packet`20--`20ignored`5Cn");
- X`09`09continue;
- X`09`09`7D
- X`09if`20(P.version`20>`20100)`20`7B`09`09/*`20versions`20after`201.0`20rot13
- V`20comments`20*/
- X`09`09if`20(P.comment`20!=`20NULL)
- X`09`09`09rotate(P.comment);
- X`09`09if`20(P.comment2`20!=`20NULL)
- X`09`09`09rotate(P.comment2);
- X`09`09`7D
- X`09if`20(`20(P.gameptr`20=`20findgame(P.gameid))`20==`20NULL)`20`7B/*`20doesn'
- Vt`20exist`20*/
- X`09`09if`20(`20(P.opcode`20!=`20START)`20`26`26`20(P.opcode`20!=`20RSTART)`20)
- V
- X`09`09`09continue;`09/*`20ignore`20pkts`20for`20dead`20games`20*/
- X`09`09i`20=`201;`09`09`09/*`20initial`20seq`20==`201`20*/
- X`09`09`7D
- X`09else`20`7B
- X`09`09if`20(P.opcode`20==`20RESEND)`20`7B`09/*`20resend`20request`20*/
- X`09`09`09if`20((P.seq`20+`201)`20!=`20P.gameptr->seq)
- X`09`09`09`09continue;`09/*`20old`20resend`20request,`20ignore`20*/
- X`09`09`09if`20(P.timestamp`20<`20P.gameptr->lastacc)
- X`09`09`09`09continue;`09/*`20old`20resend`20request,`20ignore`20*/
- X`09`09`09message(
- X`09`09`09`09"Resend`20requested`20for`20game`20%s`20--`20sending...`5Cn",
- X`09`09`09`09P.gameid);
- X`09`09`09resendpkt(P.gameptr);`09/*`20resend`20*/
- X`09`09`09P.gameptr->lastacc`20=`20time(`20(long`20*)`200);`09/*set`20lastacc*/
- V
- X`09`09`09if`20(P.timestamp`20>`20P.gameptr->lastacc)
- X`09`09`09`09P.gameptr->lastacc`20=`20P.timestamp;
- X`09`09`09continue;`09`09/*`20and`20ignore`20packet`20*/
- X`09`09`09`7D
- X`09`09i`20=`20P.gameptr->seq+1;`09/*`20get`20current`20seq`20*/
- X`09`09`7D
- X`09if`20(P.seq`20!=`20i)`20`7B`09`09/*`20sequence`20number`20is`20wrong`20*/
- X`09`09if`20(P.seq`20>`20i)`09`09/*`20rec'd`20seq`20#`20is`20too`20big`20*/
- X`09`09`09message(`09`09/*`20shouldn't`20happen`20*/
- X`09`09`09"WARNING:`20game`20%s,`20seq`20no.`20is`20%d,`20s/b`20%d`20--`20ignor
- Ved.`5Cn"
- X`09`09`09,P.gameid,P.seq,i);
- X`09`09continue;`09`09/*`20ignore`20pkts`20with`20bad`20sequence`20#s`20*/
- X`09`09`7D
- X`09if`20(`20(P.opcode`20<`200)`20`7C`7C`20(P.opcode`20>=`20NOP)`20)`20`7B`09/*
- V`20bad`20opcode`20*/
- X`09`09message("ERROR:`20bad`20opcode`20for`20game`20%s:`20%d`20--`20ignored.
- V`5Cn",
- X`09`09`09P.gameid,P.opcode);
- X`09`09continue;
- X`09`09`7D
- X`09if`20(P.gameptr`20!=`20NULL)`20`7B
- X`09`09P.gameptr->seq`20+=`202;`09/*`20bump`20sequence`20number`20*/
- X`09`09P.gameptr->lastacc`20=`20time(`20(long`20*)`200);`09/*set`20lastacc*/
- X`09`09if`20(P.timestamp`20>`20P.gameptr->lastacc)
- X`09`09`09P.gameptr->lastacc`20=`20P.timestamp;
- X`09`09if`20(P.gameptr->opcmt`20!=`20NULL)
- X`09`09`09free(P.gameptr->opcmt);`09/*`20discard`20old`20comment`20*/
- X`09`09P.gameptr->opcmt`20=`20P.comment;`09/*`20copy`20new`20comment`20*/
- X`09`09if`20(P.gameptr->opcmt2`20!=`20NULL)
- X`09`09`09free(P.gameptr->opcmt2);/*`20discard`20old`20comment`20*/
- X`09`09P.gameptr->opcmt2`20=`20P.comment2;`09/*`20copy`20new`20comment`20*/
- X`09`09P.gameptr->opver`20=`20P.version;`09/*in`20case`20he`20changed`20version
- Vs*/
- X`09`09`7D
- X`09if`20(P.gameptr`20==`20NULL)`09`09/*`20everything`20after`20here`20needs
- V`20ptr`20*/
- X`09`09return(1);`09`09/*`20to`20game`20structure`20*/
- X
- X`09`09`09/*`20any`201.1`20features`20used`20with`201.0?`20*/
- X`09if`20(`20(P.version`20<`20110)`20`26`26`20(`20(P.gameptr->mtotal`20>`200)
- V`20`7C`7C
- X`09`20`20`20`20`20(P.gameptr->flags`20`26`20(F_JACOBY`7CF_CRAWFORD`7CF_PERM
- V`7CF_EUROPE)))`20)`20`7B
- X`09`09message("Warning:`20in`20game`20%s:`5Cn",P.gameid);
- X`09`09message(
- X"The`20following`20features`20are`20not`20supported`20by`20your`20opponent's
- V`20version`20of`20ldb:`5Cn"
- X`09`09);
- X`09`09if`20(P.gameptr->flags`20`26`20F_JACOBY)
- X`09`09`09message("`5CtJacoby`20rule.`5Cn");
- X`09`09if`20(P.gameptr->flags`20`26`20F_CRAWFORD)
- X`09`09`09message("`5CtCrawford`20rule.`5Cn");
- X`09`09if`20(P.gameptr->flags`20`26`20F_EUROPE)
- X`09`09`09message("`5CtEuropean`20rule.`5Cn");
- X`09`09if`20(P.gameptr->flags`20`26`20F_PERM)
- X`09`09`09message("`5CtPermanent`20games.`5Cn");
- X`09`09if`20(P.gameptr->mtotal`20>`200)
- X`09`09`09message("`5CtMatch`20play.`5Cn");
- X`09`09P.gameptr->flags`20`26=
- X`09`09`09`7E(F_CRAWFORD`7CF_JACOBY`7CF_PERM`7CF_EUROPE);
- X`09`09P.gameptr->mtotal`20=`200;
- X`09`09message(
- X"This`20game`20will`20continue`20as`20if`20those`20features`20had`20not`20been
- V`20used.`5Cn");
- X`09`09`7D
- X`09if`20(`20(P.version`20<`20130)`20`26`26`20(P.gameptr->flags`20`26`20F_CRAWF
- VORD)`20)
- X`09`09message(
- X"Warning:`20opponent`20using`20pre-1.3`20ldb`20--`20using`20Crawford`20rule
- V`20not`20recommended!`5Cn"
- X`09`09);
- X`09return(1);`09`09`09/*`20return`20success`20*/
- X`09`7D
- Xreturn(0);`09`09/*`20return`20this`20to`20mean`20end`20of`20file`20*/
- X`7D
- $ call unpack READMAIL.C;1 2020022216 ""
- $!
- $ create 'f'
- X/*`09rename.c`09`094/10/92
- X`20*
- X`20*`20Copyright`201991`20`20Perry`20R.`20Ross
- X`20*
- X`20*`20Permission`20to`20use,`20copy,`20modify,`20and`20distribute`20this`20so
- Vftware`20and`20its
- X`20*`20documentation`20without`20fee`20is`20hereby`20granted,`20subject`20to
- V`20the`20restrictions
- X`20*`20detailed`20in`20the`20README`20file,`20which`20is`20included`20here`20b
- Vy`20reference.
- X`20*`20Any`20other`20use`20requires`20written`20permission`20from`20the`20auth
- Vor.`20`20This`20software
- X`20*`20is`20distributed`20"as`20is"`20without`20any`20warranty,`20including
- V`20any`20implied
- X`20*`20warranties`20of`20merchantability`20or`20fitness`20for`20a`20particular
- V`20purpose.
- X`20*`20The`20author`20shall`20not`20be`20liable`20for`20any`20damages`20result
- Ving`20from`20the
- X`20*`20use`20of`20this`20software.`20`20By`20using`20this`20software,`20the
- V`20user`20agrees
- X`20*`20to`20these`20terms.
- X`20*/
- X
- X#include`20"ldb.h"
- X
- X
- X/*----------------------------------------------------------------------
- X`20*`09rename`20--`20rename`20a`20file
- X`20*
- X`20*`20This`20function`20may`20be`20used`20to`20rename`20a`20file`20if`20the
- V`20local`20C`20library
- X`20*`20does`20not`20have`20such`20a`20function.`20`20It`20uses`20the`20link
- V`20and`20unlink`20calls,
- X`20*`20which`20should`20be`20on`20all`20systems,`20but`20is`20not`20atomic`20l
- Vike`20real`20rename's.
- X`20*`20This`20rename`20is`20not`20meant`20for`20general`20use,`20as`20it`20doe
- Vs`20no`20error`20checking.
- X`20*`20Since`20it`20is`20only`20used`20to`20save`20the`20old`20copy`20of`20a
- V`20file`20as`20a`20backup,
- X`20*`20it`20is`20better`20to`20fail`20silently`20than`20complain`20about`20som
- Vething`20the`20user
- X`20*`20can't`20do`20anything`20about`20anyway.`20`20The`20old`20file`20is`20al
- Vways`20unlinked,
- X`20*`20even`20if`20the`20link`20to`20the`20new`20name`20succeeded,`20since`20t
- Vhe`20next`20thing
- X`20*`20we`20are`20going`20to`20do`20is`20write`20over`20the`20old`20file`20any
- Vway.
- X`20*----------------------------------------------------------------------
- X`20*/
- X
- Xrename(old,new)
- Xchar`20*old;
- Xchar`20*new;
- X`7B
- X
- Xunlink(new);`09`09/*`20get`20rid`20of`20existing`20file`20named`20NEW`20*/
- Xlink(old,new);`09`09/*`20make`20link`20from`20OLD`20to`20NEW`20*/
- Xunlink(old);`09`09/*`20get`20rid`20of`20link`20to`20OLD`20*/
- X`7D
- $ call unpack RENAME.C;1 1866027360 ""
- $!
- $ create 'f'
- X/*`09r_xrand.c
- X`20*/
- X
- X#include`20"ldb.h"
- X#include`20<math.h>
- X
- Xlong`20rnd_ri();
- X
- X/*======================================================================
- X`20*`20This`20file`20contains`20the`20random`20number`20generator.`20`20It`20i
- Vs`20accessed`20by
- X`20*`20calling`20RandomInit`20with`20a`2032-bit`20seed,`20then`20calling`20Rol
- Vldie()`20to
- X`20*`20generate`20integers`20in`20the`20range`20`5B1-6`5D.`20`20This`20particu
- Vlar`20implementation
- X`20*`20was`20taken`20from`20xrand`20in`20volume`202`20of`20comp.sources.misc.
- V`20`20It`20was
- X`20*`20written`20by`20Andreas`20Nowatzyk,`20then`20of`20Carnegie-Mellon`20Univ
- Versity,`20and
- X`20*`20is`20reproduced`20here`20essentially`20unchanged`20(although`20I`20omit
- Vted
- X`20*`20all`20routines`20but`20the`20ones`20needed`20for`20integers`20in`20`5B1
- V-6`5D).
- X`20*`20It`20is`20used`20by`20permission`20of`20the`20author,`20whose`20origina
- Vl`20copyright
- X`20*`20and`20permission-to-use`20appears`20below.
- X`20*======================================================================
- X`20*/
- X
- X
- X
- X/*----------------------------------------------------------------------
- X`20*`09Rolldie`20--`20return`20a`20random`20number`20between`201`20and`206
- X`20*----------------------------------------------------------------------
- X`20*/
- X
- XRolldie()
- X`7B
- X
- Xreturn(`20(`20(int)`20rnd_ri(6L)`20)`20+`201);
- X`7D
- X
- X
- X
- X/*----------------------------------------------------------------------
- X`20*`09RandomInit`20--`20initialize`20the`20random`20number`20generator
- X`20*
- X`20*`20This`20function`20should`20be`20called`20once,`20before`20Rolldie`20is
- V`20called.
- X`20*`20The`20seed`20may`20be`20any`20more`20or`20less`20random`20number;`20the
- V`20time`20seems
- X`20*`20to`20be`20conventional.
- X`20*----------------------------------------------------------------------
- X`20*/
- X
- XRandomInit(seed)
- Xlong`20seed;
- X`7B
- X
- Xrnd_init(seed);
- X`7D
- X
- X
- X
- X/*----------------------------------------------------------------------
- X`20*From:`09EMF780::WINS%"Andreas.Nowatzyk@eng.sun.com"`2020-NOV-1991`2017:50:
- V38.73
- X`20*To:`09ROSS
- X`20*CC:`09
- X`20*Subj:`09Re:`20`20xrand
- X`20*
- X`20*Return-Path:`20<Andreas.Nowatzyk@eng.sun.com>
- X`20*Received:`20from`20everest.den.mmc.com`20by`20emf780.den.mmc.com`20with
- V`20SMTP`20;`20
- X`20*`20`20`20`20`20`20`20`20`20`20Wed,`2020`20Nov`2091`2016:50:29`20MDT
- X`20*Received:`20from`20Sun.COM`20by`20everest.den.mmc.com`20(4.1/1.34.a)
- X`20*`09id`20AA27426;`20Wed,`2020`20Nov`2091`2017:52:10`20MST
- X`20*Received:`20from`20Eng.Sun.COM`20(zigzag-bb.Corp.Sun.COM)`20by`20Sun.COM
- V`20(4.1/SMI-4.1)
- X`20*`09id`20AA07190;`20Wed,`2020`20Nov`2091`2016:50:53`20PST
- X`20*Received:`20from`20bovic.Eng.Sun.COM`20by`20Eng.Sun.COM`20(4.1/SMI-4.1)
- X`20*`09id`20AA21474;`20Wed,`2020`20Nov`2091`2016:49:44`20PST
- X`20*Received:`20by`20bovic.Eng.Sun.COM`20(4.1/SMI-4.1)
- X`20*`09id`20AA02462;`20Wed,`2020`20Nov`2091`2016:49:16`20PST
- X`20*Date:`20Wed,`2020`20Nov`2091`2016:49:16`20PST
- X`20*From:`20Andreas.Nowatzyk@eng.sun.com`20(Andreas`20G.`20Nowatzyk)
- X`20*Message-Id:`20<9111210049.AA02462@bovic.Eng.Sun.COM>
- X`20*To:`20ross@emf780.den.mmc.com
- X`20*Subject:`20Re:`20`20xrand
- X`20*
- X`20*I`20have`20no`20objection`20to`20distributing`20xrand,`20provided`20that
- V`20this`20is`20not`20done
- X`20*for`20profit`20and`20that`20the`20source`20is`20credited.
- X`20*
- X`20*`20`20--`20`20Andreas
- X`20*
- X`20*PS:`20There`20was`20a`20bug`20is`20some`20version`20of`20xrand.c:`20The
- V`20constant`20for`20the`20most
- X`20*`20`20`20`20positive`20integer`20(0x7fffffff)`20had`20an`20'f'`20missing
- V`20in`20two`20places.`20It`20should
- X`20*`20`20`20`20have`20used`20a`20#define`20MAX_INT`20with`20apropriate`20valu
- Ve`20instead`20of`20hardwiring
- X`20*`20`20`20`20an`20hex-constant.
- X`20*----------------------------------------------------------------------
- X`20*/
- X
- X#define`20MAX_INT`200x7fffffff
- X
- X/*`20Random`20number`20generators:
- X`20*
- X`20*`20`20rnd_init`20(unsigned`20seed)`20
- X`20*`09`09`09:`20initializes`20the`20generator
- X`20*
- X`20*`20`20rnd_i`20()`09`09:`20returns`20positive`20integers`20`5B0,0x7fffffff
- V`5D
- X`20*`20`20rnd_ri`20(long`20n)`09:`20returns`20positive`20integers`20`5B0,n-1
- V`5D
- X`20*
- X`20*`20`20Algorithm`20M`20as`20describes`20in`20Knuth's`20"Art`20of`20Computer
- V`20Programming",`20Vol`202.`201969
- X`20*`20`20is`20used`20with`20a`20linear`20congruential`20generator`20(to`20get
- V`20a`20good`20uniform
- X`20*`20`20distribution)`20that`20is`20permuted`20with`20a`20Fibonacci`20additi
- Vve`20congruential
- X`20*`20`20generator`20to`20get`20good`20independence.
- X`20*
- X`20*`20`20Bit,`20byte,`20and`20word`20distributions`20were`20extensively`20tes
- Vted`20and`20pass
- X`20*`20`20Chi-squared`20test`20near`20perfect`20scores`20(>7E8`20numbers`20tes
- Vted,`20Uniformity
- X`20*`20`20assumption`20holds`20with`20probability`20>`200.999)
- X`20*
- X`20*`20`20Run-up`20tests`20for`20on`207E8`20numbers`20confirm`20independence
- V`20with
- X`20*`20`20probability`20>`200.97.
- X`20*
- X`20*`20`20Plotting`20random`20points`20in`202d`20reveals`20no`20apparent`20str
- Vucture.
- X`20*
- X`20*`20`20Autocorrelation`20on`20sequences`20of`205E5`20numbers`20(A(i)`20=
- V`20SUM`20X(n)*X(n-i),`20i=1..512)
- X`20*`20`20results`20in`20no`20obvious`20structure`20(A(i)`20`7E`20const).
- X`20*
- X`20*`20`20On`20a`20SUN`203/60,`20rnd_u()`20takes`20about`2019.4`20usec`20per
- V`20call,`20which`20is`20about`2044%
- X`20*`20`20slower`20than`20Berkeley's`20random()`20(13.5`20usec/call).
- X`20*
- X`20*`20`20Except`20for`20speed`20and`20memory`20requirements,`20this`20generat
- Vor`20outperforms
- X`20*`20`20random()`20for`20all`20tests.`20(random()`20scored`20rather`20low
- V`20on`20uniformity`20tests,
- X`20*`20`20while`20independence`20test`20differences`20were`20less`20dramatic).
- V
- X`20*
- X`20*`20`20Thanks`20to`20M.Mauldin,`20H.Walker,`20J.Saxe`20and`20M.Molloy`20for
- V`20inspiration`20`26`20help.
- X`20*
- X`20*`20`20(c)`20Copyright`201988`20by`20A.`20Nowatzyk
- X`20*
- X`20*/
- X
- X/*`20LC-parameter`20selection`20follows`20recommendations`20in`20
- X`20*`20"Handbook`20of`20Mathematical`20Functions"`20by`20Abramowitz`20`26`20St
- Vegun`2010th,`20edi.
- X`20*/
- X#define`20LC_A`2066049L`09`09`20`20`20`20/*`20=`20251`5E2,`20`7E=`20sqrt(2`5E3
- V2)`09`09`09*/
- X#define`20LC_C`20390786457L`09/*`20result`20of`20a`20long`20trial`20`26`20erro
- Vr`20series`20`20`20`20*/
- X
- X/*
- X#define`20Xrnd(x)`20(long)((long)x`20*`20LC_A`20+`20LC_C)`20*/`20`20`20/*`20th
- Ve`20LC`20polynomial`09`09`09*/
- X`09`09`09
- Xstatic`20unsigned`20long`20Fib`5B55`5D;`09`20`20`20`20/*`20will`20use`20X(n)
- V`20=`20X(n-55)`20-`20X(n-24)`09*/
- Xstatic`20int`20Fib_ind;`09`09`20`20`20`20/*`20current`20index`20in`20circular
- V`20buffer`09`09*/
- Xstatic`20unsigned`20long`20Xrnd_var;`09`20`20`20`20/*`20LCA`20-`20recurrence
- V`20variable`09`09*/
- Xstatic`20unsigned`20long`20auxtab`5B256`5D;`20`20`20/*`20temporal`20permutatio
- Vn`20table`09`09*/
- Xstatic`20unsigned`20long`20prmtab`5B64`5D`20=`20`7B`20/*`20spatial`20permutati
- Von`20table`09`09*/
- X`20`20`20`200xffffffff,`200x00000000,`20`200x00000000,`20`200x00000000,`20`20/
- V*`203210`20*/
- X`20`20`20`200x0000ffff,`200x00ff0000,`20`200x00000000,`20`200xff000000,`20`20/
- V*`202310`20*/
- X`20`20`20`200xff0000ff,`200x0000ff00,`20`200x00000000,`20`200x00ff0000,`20`20/
- V*`203120`20*/
- X`20`20`20`200x00ff00ff,`200x00000000,`20`200xff00ff00,`20`200x00000000,`20`20/
- V*`201230`20*/
- X
- X`20`20`20`200xffff0000,`200x000000ff,`20`200x00000000,`20`200x0000ff00,`20`20/
- V*`203201`20*/
- X`20`20`20`200x00000000,`200x00ff00ff,`20`200x00000000,`20`200xff00ff00,`20`20/
- V*`202301`20*/
- X`20`20`20`200xff000000,`200x00000000,`20`200x000000ff,`20`200x00ffff00,`20`20/
- V*`203102`20*/
- X`20`20`20`200x00000000,`200x00000000,`20`200x00000000,`20`200xffffffff,`20`20/
- V*`202103`20*/
- X
- X`20`20`20`200xff00ff00,`200x00000000,`20`200x00ff00ff,`20`200x00000000,`20`20/
- V*`203012`20*/
- X`20`20`20`200x0000ff00,`200x00000000,`20`200x00ff0000,`20`200xff0000ff,`20`20/
- V*`202013`20*/
- X`20`20`20`200x00000000,`200x00000000,`20`200xffffffff,`20`200x00000000,`20`20/
- V*`201032`20*/
- X`20`20`20`200x00000000,`200x0000ff00,`20`200xffff0000,`20`200x000000ff,`20`20/
- V*`201023`20*/
- X
- X`20`20`20`200x00000000,`200xffffffff,`20`200x00000000,`20`200x00000000,`20`20/
- V*`200321`20*/
- X`20`20`20`200x00ffff00,`200xff000000,`20`200x00000000,`20`200x000000ff,`20`20/
- V*`200213`20*/
- X`20`20`20`200x00000000,`200xff000000,`20`200x0000ffff,`20`200x00ff0000,`20`20/
- V*`200132`20*/
- X`20`20`20`200x00000000,`200xff00ff00,`20`200x00000000,`20`200x00ff00ff`20`20
- V`20/*`200123`20*/
- X`7D;
- X
- Xunion`20hack`20`7B`09`09`09`20`20`20`20/*`20used`20to`20access`20doubles`20as
- V`20unsigneds`09*/
- X`20`20`20`20double`20d;
- X`20`20`20`20unsigned`20long`20u`5B2`5D;
- X`7D;
- X
- Xstatic`20union`20hack`20man;`09`09`20`20`20`20/*`20mantissa`20bit`20vector`09
- V`09`09*/
- X
- Xlong`20Xrnd(x)`20
- Xlong`20x;
- X`7B
- X`09long`20tmp;
- X
- X`09tmp`20=`20x*`20LC_A;
- X`09tmp`20+=`20LC_C;
- X`09return`20tmp;
- X`7D
- X
- Xrnd_init`20(seed)`09`09`09`20`20`20`20/*`20modified:`20seed`200-31`20use`20pre
- Vcomputed`20stuff`20*/
- X`20`20`20`20unsigned`20seed;
- X`7B
- X`20`20`20`20register`20unsigned`20long`20u;
- X`20`20`20`20register`20int`20i;
- X`20`20`20`20double`20x,`20y;
- X`20`20`20`20union`20hack`20t;
- X
- X`20`20`20`20static`20unsigned`20seed_tab`5B32`5D`20=`20`7B
- X`09`090xbdcc47e5,`200x54aea45d,`200xec0df859,`200xda84637b,
- X`09`090xc8c6cb4f,`200x35574b01,`200x28260b7d,`200x0d07fdbf,
- X`09`090x9faaeeb0,`200x613dd169,`200x5ce2d818,`200x85b9e706,
- X`09`090xab2469db,`200xda02b0dc,`200x45c60d6e,`200xffe49d10,
- X`09`090x7224fea3,`200xf9684fc9,`200xfc7ee074,`200x326ce92a,
- X`09`090x366d13b5,`200x17aaa731,`200xeb83a675,`200x7781cb32,
- X`09`090x4ec7c92d,`200x7f187521,`200x2cf346b4,`200xad13310f,
- X`09`090xb89cff2b,`200x12164de1,`200xa865168d,`200x32b56cdf`20`20`7D;
- X
- X`20`20`20`20if`20(seed`20<`2032)
- X`09u`20=`20seed_tab`5Bseed`5D;
- X`20`20`20`20else
- X`09u`20=`20seed`20`5E`20seed_tab`5Bseed`20`26`2031`5D;
- X
- X`20`20`20`20for`20(i`20=`2055;`20i--;)`09`09`20`20`20`20/*`20set`20up`20Fibona
- Vcci`20additive`20congruential`09*/
- X`09Fib`5Bi`5D`20=`20u`20=`20Xrnd(u);
- X
- X`20`20`20`20for`20(i`20=`20256;`20i--;)
- X`09auxtab`5Bi`5D`20=`20u`20=`20Xrnd(u);
- X
- X`20`20`20`20Fib_ind`20=`20u`20%`2055;`09`09`20`20`20`20/*`20select`20a`20start
- Ving`20point`09`09`09*/
- X
- X`20`20`20`20Xrnd_var`20=`20u;
- X
- X`09/*`09The`20following`20tests`20to`20see`20if`20a`20double`20fits`20into
- X`09`092`20unsigned`20longs.`20`20If`20not,`20rnd_01d`20will`20not`20work
- X`09`09on`20this`20machine.`09`09`09`09`09*/
- X
- X`20`20`20`20if`20(sizeof(x)`20!=`202`20*`20sizeof(unsigned`20long))
- X`09fatal("ERROR:`20xrand`20roller`20does`20not`20work`20on`20this`20machine!")
- V;
- X
- X`20`20`20`20x`20=`201.0;
- X`20`20`20`20y`20=`200.5;
- X`20`20`20`20do`20`7B`09`09`09`20`20`20`20/*`20find`20largest`20fp-number`20<
- V`202.0`09*/
- X`09t.d`20=`20x;
- X`09x`20+=`20y;
- X`09y`20*=`200.5;
- X`20`20`20`20`7D`20while`20(x`20!=`20t.d`20`26`26`20x`20<`202.0);
- X
- X`20`20`20`20man.d`20=`201.0;
- X`20`20`20`20man.u`5B0`5D`20`5E=`20t.u`5B0`5D;
- X`20`20`20`20man.u`5B1`5D`20`5E=`20t.u`5B1`5D;`09`09`20`20`20`20/*`20man`20is
- V`20now`201`20for`20each`20mantissa`20bit`09*/
- X`7D
- X
- Xlong`20rnd_i`20()
- X/*
- X`20*`20returns`20a`20positive,`20uniformly`20distributed`20random`20number`20i
- Vn`20`5B0,0x7fffffff`5D
- X`20*/
- X`7B`20
- X`20`20`20`20register`20unsigned`20long`20i,`20j,`20*t`20=`20Fib;
- X
- X`20`20`20`20i`20=`20Fib_ind;
- X`20`20`20`20j`20=`20t`5Bi`5D;`09`09`09`09`20`20`20`20/*`20=`20X(n-55)`20*/
- X`20`20`20`20j`20-=`20(i`20>=`2024)`20?`20t`5Bi`20-`2024`5D`20:`20t`5Bi`20+`202
- V1`5D;`20/*`20=`20X(n-24)`20*/
- X`20`20`20`20t`5Bi`5D`20=`20j;
- X`20`20`20`20if`20(++i`20>=`2055)`20i`20=`200;
- X`20`20`20`20Fib_ind`20=`20i;
- X
- X`20`20`20`20t`20=`20`26auxtab`5B(j`20>>`2024)`20`26`200xff`5D;
- X`20`20`20`20i`20=`20*t;
- X`20`20`20`20Xrnd_var`20=`20*t`20=`20Xrnd(Xrnd_var);
- X`20`20`20`20t`20=`20`26prmtab`5Bj`20`26`200x3c`5D;
- X
- X`20`20`20`20j`20=`20`20*t++`20`26`20i;
- X`20`20`20`20j`20`7C=`20*t++`20`26`20((i`20<<`2024)`20`7C`20((i`20>>`20`208)
- V`20`26`200x00ffffff));
- X`20`20`20`20j`20`7C=`20*t++`20`26`20((i`20<<`2016)`20`7C`20((i`20>>`2016)`20
- V`26`200x0000ffff));
- X`20`20`20`20j`20`7C=`20*t`20`20`20`26`20((i`20<<`20`208)`20`7C`20((i`20>>`2024
- V)`20`26`200x000000ff));
- X`20`20`20`20
- X`20`20`20`20return`20j`20`26`20MAX_INT;
- X`7D
- X
- X
- Xlong`20rnd_ri`20(rng)
- X`20`20`20`20long`20rng;
- X/*
- X`20*`20randint:`20Return`20a`20random`20integer`20in`20a`20given`20Range`20
- V`5B0..rng-1`5D
- X`20*`20`20`20`20`20`20`20`20`20`20Note:`20`200`20<`20rng
- X`20*/
- X`7B
- X`20`20`20`20register`20unsigned`20long`20`20r,`20a;
- X
- X`20`20`20`20do`20`7B
- X`09r`20=`20rnd_i();
- X`09a`20=`20(r`20/`20rng)`20+`201;
- X`09a`20*=`20rng;
- X`20`20`20`20`7D`20while`20(a`20>=`20MAX_INT);
- X`20`20`20`20
- X`20`20`20`20a--;
- X`20`20`20`20return`20a`20-`20r;
- X`7D
- $ call unpack R_XRAND.C;1 172441753 ""
- $!
- $ create 'f'
- X/*`09save.c`09`098/4/91
- X`20*
- X`20*`20Copyright`201991`20`20Perry`20R.`20Ross
- X`20*
- X`20*`20Permission`20to`20use,`20copy,`20modify,`20and`20distribute`20this`20so
- Vftware`20and`20its
- X`20*`20documentation`20without`20fee`20is`20hereby`20granted,`20subject`20to
- V`20the`20restrictions
- X`20*`20detailed`20in`20the`20README`20file,`20which`20is`20included`20here`20b
- Vy`20reference.
- X`20*`20Any`20other`20use`20requires`20written`20permission`20from`20the`20auth
- Vor.`20`20This`20software
- X`20*`20is`20distributed`20"as`20is"`20without`20any`20warranty,`20including
- V`20any`20implied
- X`20*`20warranties`20of`20merchantability`20or`20fitness`20for`20a`20particular
- V`20purpose.
- X`20*`20The`20author`20shall`20not`20be`20liable`20for`20any`20damages`20result
- Ving`20from`20the
- X`20*`20use`20of`20this`20software.`20`20By`20using`20this`20software,`20the
- V`20user`20agrees
- X`20*`20to`20these`20terms.
- X`20*/
- X
- X#include`20"ldb.h"
- X
- X/*===========================================================================
- X`20*`20This`20file`20contains`20miscellaneous`20functions`20that`20save`20and
- V`20load`20things.
- X`20*==========================================================================
- V=
- X`20*/
- X
- X/*---------------------------------------------------------------------------
- X`20*`09save`20--`20make`20a`20copy`20of`20a`20string
- X`20*
- X`20*`20This`20function`20makes`20a`20copy`20of`20a`20string`20in`20malloc`20me
- Vmory,`20and`20returns
- X`20*`20a`20pointer`20to`20the`20copy.
- X`20*--------------------------------------------------------------------------
- V-
- X`20*/
- X
- Xchar`20*save(s)
- Xchar`20*s;
- X`7B
- Xchar`20*n;
- X
- Xif`20(s`20==`20NULL)`20`7B
- X`09return(NULL);
- X`09`7D
- Xelse`20`7B
- X`09if`20(`20(n`20=`20calloc(strlen(s)+1,1))`20==`20NULL)
- X`09`09fatal("Out`20of`20memory!");
- X`09strcpy(n,s);
- X`09return(n);
- X`09`7D
- X`7D
- X
- X
- X/*---------------------------------------------------------------------------
- X`20*`09readldbrc`20--`20read`20in`20the`20.ldbrc`20file
- X`20*
- X`20*`20This`20function`20reads`20the`20.ldbrc`20file,`20which`20contains`20the
- V`20setup`20info
- X`20*`20for`20this`20user.`20`20If`20the`20HOME`20environment`20variable`20is
- V`20set,`20we`20chdir`20to`20it.
- X`20*`20If`20the`20LDBRC`20environment`20variable`20is`20set,`20it`20is`20used
- V`20as`20the`20file`20to
- X`20*`20read`20instead`20of`20.ldbrc.
- X`20*--------------------------------------------------------------------------
- V-
- X`20*/
- X
- Xreadldbrc()
- X`7B
- XFILE`20*fp;
- Xchar`20*s,`20*n,`20*getenv();
- Xchar`20buf`5B80`5D;
- X
- Xif`20(`20(s`20=`20getenv("HOME"))`20!=`20NULL)`09/*`20if`20we`20have`20a`20hom
- Ve`20*/
- X`09chdir(s);`09`09`09/*`20go`20there`20*/
- Xif`20(`20(s`20=`20getenv("LDBRC"))`20==`20NULL)`09/*`20LDBRC`20not`20set`20*/
- X#ifdef`20VMS
- X`09s`20=`20"ldb.rc";`09`09`09/*`20use`20default`20file`20name`20*/
- X#else
- X`09s`20=`20".ldbrc";`09`09`09/*`20use`20default`20file`20name`20*/
- X#endif
- Xif`20(`20(fp`20=`20fopen(s,"r"))`20==`20NULL)`20`7B
- X`09printf("'%s'`20does`20not`20exist.`20`20Do`20you`20want`20to`20create`20it?
- V",s);
- X`09if`20(`20(fgets(buf,sizeof(buf),stdin)`20==`20NULL)
- X`09`20`20`20`20`20`7C`7C`20(`20(*buf`20!=`20'y')`20`26`26`20(*buf`20!=`20'Y')
- V`20)`20)
- X`09`09fatal("ldb`20aborted.");
- X`09if`20(`20(fp`20=`20fopen(s,"w"))`20==`20NULL)`20`7B
- X`09`09printf("Sorry,`20could`20not`20create`20%s.`5Cn",s);
- X`09`09ldbexit(STAT_ABORT);
- X`09`09`7D
- X`09printf("Please`20enter`20your`20personal`20name:`20");
- X`09if`20(fgets(buf,sizeof(buf),stdin)`20==`20NULL)`20`7B
- X`09`09fclose(fp);
- X`09`09unlink(s);
- X`09`09printf("ldb`20aborted.`5Cn");
- X`09`09ldbexit(STAT_ABORT);
- X`09`09`7D
- X`09buf`5Bstrlen(buf)-1`5D`20=`20'`5C0';`09/*`20clobber`20the`20newline`20char
- V`20*/
- X`09fprintf(fp,"myname=%s`5Cn",buf);
- X`09printf("Please`20enter`20your`20e-mail`20address:`20");
- X`09if`20(fgets(buf,sizeof(buf),stdin)`20==`20NULL)`20`7B
- X`09`09fclose(fp);
- X`09`09unlink(s);
- X`09`09printf("ldb`20aborted.`5Cn");
- X`09`09ldbexit(STAT_ABORT);
- X`09`09`7D
- X`09buf`5Bstrlen(buf)-1`5D`20=`20'`5C0';`09/*`20clobber`20the`20newline`20char
- V`20*/
- X`09fprintf(fp,"myaddr=%s`5Cn",buf);
- X`09fprintf(fp,"mailfile=ldb.rcv`5Cn");
- X#ifdef`20VMS
- X`09fprintf(fp,"sendcmd=mail/subject=`5C"$s`5C"`20$f`20IN%%`5C"`5C"`5C"$a`5C"
- V`5C"`5C"`5Cn");
- X`09fprintf(fp,"gamefile=ldb.data`5Cn");
- X`09fprintf(fp,"backupfile=ldb.olddata`5Cn");
- X`09fprintf(fp,"peoplefile=ldb.people`5Cn");
- X`09fprintf(fp,"lockfile=ldb.lock`5Cn");
- X`09fprintf(fp,"supercmd=`5Cn");
- X#else
- X`09fprintf(fp,"sendcmd=mail`20-s`20'$s'`20$a`20<`20$f`5Cn");
- X`09fprintf(fp,"gamefile=.ldbdata`5Cn");
- X`09fprintf(fp,"backupfile=.oldldbdata`5Cn");
- X`09fprintf(fp,"peoplefile=.ldbpeople`5Cn");
- X`09fprintf(fp,"lockfile=.ldb_lock`5Cn");
- X`09fprintf(fp,"supercmd=sh`5Cn");
- X#endif
- X`09fprintf(fp,"delmail=no`5Cn");
- X`09fprintf(fp,"tempfile=ldb.tmp`5Cn");
- X`09fprintf(fp,"colors=rw`5Cn");
- X`09fprintf(fp,"direction=up`5Cn");
- X`09fprintf(fp,"initialboard=current`5Cn");
- X`09fprintf(fp,"autoroll=yes`5Cn");
- X`09fprintf(fp,"automove=no`5Cn");
- X`09fprintf(fp,"autodouble=0`5Cn");
- X`09fprintf(fp,"superkey=0`5Cn");
- X`09fprintf(fp,"checkpoint=yes`5Cn");
- X`09fprintf(fp,"timeout=7`5Cn");
- X`09fprintf(fp,"keepold=7`5Cn");
- X`09fprintf(fp,"debug=0`5Cn");
- X`09fclose(fp);
- X`09printf("`5CnYour`20%s`20file`20was`20created.`20`20You`20may`20want`20to
- V`20read`20the`5Cn",s);
- X`09printf("manual`20for`20additional`20options`20available`20in`20this`20file.
- V`5Cn`5Cn");
- X#ifdef`20VMS
- X`09printf("VMS`20users`20should`20edit`20the`20sendcmd`20command`20in`20%s`20t
- Vo`20use`5Cn",s);
- X`09printf("the`20appropriate`20mailer.`20`20The`20IN%%`20mailer`20is`20assumed
- V.`5Cn`5Cn");
- X#endif
- X`09if`20(`20(fp`20=`20fopen(s,"r"))`20==`20NULL)`20`7B
- X`09`09printf("I`20can't`20re-open`20your`20%s`20file!`5Cn",s);
- X`09`09ldbexit(STAT_ABORT);
- X`09`09`7D
- X`09`7D
- Xrc.myname`20=`20NULL;`09`09/*`20these`20fields`20are`20required`20*/
- Xrc.myaddr`20=`20NULL;
- X#ifdef`20VMS
- Xrc.gfile`20=`20"ldb.data";`09/*`20default`20game`20storage`20file`20*/
- Xrc.pfile`20=`20"ldb.people";`09/*`20default`20opponent`20file`20*/
- Xrc.gbackup`20=`20"ldb.olddata";`09/*`20game`20backup`20file`20*/
- Xrc.sendcmd`20=`20"mail/subject=`5C"$s`5C"`20$f`20IN%%`5C"`5C"`5C"$a`5C"`5C"
- V`5C"";`20/*`20dflt`20mail`20cmd`20*/
- Xrc.lockfile`20=`20"ldb.lock";`09/*`20default`20lock`20file`20*/
- Xrc.supercmd`20=`20"";`09`09/*`20command`20to`20run`20when`20we`20have`20compan
- Vy`20*/
- X#else
- Xrc.gfile`20=`20".ldbdata";`09/*`20default`20game`20storage`20file`20*/
- Xrc.pfile`20=`20".ldbpeople";`09/*`20default`20opponent`20file`20*/
- Xrc.gbackup`20=`20".oldldbdata";`09/*`20game`20backup`20file`20*/
- Xrc.sendcmd`20=`20"mail`20-s`20'$s'`20$a`20<`20$f";`09/*`20default`20mail`20com
- Vmand`20*/
- Xrc.lockfile`20=`20".ldb_lock";`09/*`20default`20lock`20file`20*/
- Xrc.supercmd`20=`20"sh";`09`09/*`20command`20to`20run`20when`20we`20have`20comp
- Vany`20*/
- X#endif
- Xrc.mfile`20=`20"ldb.rcv";`09/*`20default`20file`20for`20received`20mail`20*/
- Xrc.delmail`20=`20"no";`09`09`09/*`20don't`20delete`20mail`20by`20default`20*/
- Xrc.tempfile`20=`20"ldb.tmp";`09`09/*`20default`20temp`20file`20*/
- Xrc.defclrs`20=`20"rw";`09`09`09/*`20"default"`20default`20colors`20*/
- Xrc.defdir`20=`20"u";`09`09`09/*`20and`20direction`20*/
- Xrc.initboard`20=`20"c";`09`09`09/*`20show`20current`20board`20by`20default`20*
- V/
- Xrc.autoroll`20=`20"y";`09`09`09/*`20enable`20autoroll`20by`20default`20*/
- Xrc.automove`20=`20"n";`09`09/*`20disabled`20by`20default`20(it's`20really`20an
- Vnoying`20*/
- Xrc.autodouble`20=`200;`09`09/*`20disable`20autodouble`20by`20default`20*/
- Xrc.superkey`20=`200;`09`09/*`20key`20to`20activate`20supercmd`20(dflt=disabled
- V)`20*/
- Xrc.chkpt`20=`20"y";`09`09`09/*`20checkpoint`20is`20enabled`20by`20default`20*/
- V
- Xrc.acctime`20=`207;`09`09`09/*`20access`20timeout`20in`207`20days`20by`20defau
- Vlt`20*/
- Xrc.keepold`20=`207;`09`09`09/*`20keep`20dead`20games`207`20days`20by`20default
- V`20*/
- Xrc.debug`20=`200;`09`09`09/*`20default`20to`20no`20debug`20*/
- Xif`20(`20(n`20=`20nvscan(fp,nv_rcfile,`26rc))`20!=`20NULL)`20`7B
- X`09fprintf(stderr,"Invalid`20line`20in`20.ldbrc:`20%s`5Cn",n);
- X`09ldbexit(STAT_ABORT);
- X`09`7D
- Xfclose(fp);
- Xif`20(rc.myname`20==`20NULL)`20`7B
- X`09fprintf(stderr,"ERROR:`20missing`20'myname'`20line`20in`20%s`5Cn",s);
- X`09ldbexit(STAT_ABORT);
- X`09`7D
- Xif`20(rc.myaddr`20==`20NULL)`20`7B
- X`09fprintf(stderr,"ERROR:`20missing`20'myaddr'`20line`20in`20%s`5Cn",s);
- X`09ldbexit(STAT_ABORT);
- X`09`7D
- Xif`20(`20(strlen(rc.defclrs)`20!=`202)`20`7C`7C`20(!`20isalpha(rc.defclrs`5B0
- V`5D))`20`7C`7C
- X`20`20`20`20`20(!`20isalpha(rc.defclrs`5B1`5D))`20`7C`7C`20(rc.defclrs`5B0`5D
- V`20==`20rc.defclrs`5B1`5D)`20)`20`7B
- X`09fprintf(stderr,"ERROR:`20invalid`20color`20string`20in`20%s:`20%s",s,rc.def
- Vclrs);
- X`09ldbexit(STAT_ABORT);
- X`09`7D
- Xif`20(strchr("ud",*rc.defdir)`20==`20NULL)`20`7B
- X`09fprintf(stderr,"ERROR:`20direction`20must`20be`20'up'`20or`20'down'`20in
- V`20%s`5Cn",s);
- X`09ldbexit(STAT_ABORT);
- X`09`7D
- Xif`20(strchr("bac",*rc.initboard)`20==`20NULL)`20`7B
- X`09fprintf(stderr,
- X`09`20"ERROR:`20initialboard`20must`20be`20'before',`20'after',`20or`20'curren
- Vt'`20in`20%s`5Cn"
- X`09`20,s);
- X`09ldbexit(STAT_ABORT);
- X`09`7D
- Xif`20(strchr("yn",*rc.autoroll)`20==`20NULL)`20`7B
- X`09fprintf(stderr,"ERROR:`20autoroll`20must`20be`20'yes'`20or`20'no'`20in`20%s
- V`5Cn",s);
- X`09ldbexit(STAT_ABORT);
- X`09`7D
- Xif`20(strchr("yn",*rc.automove)`20==`20NULL)`20`7B
- X`09fprintf(stderr,"ERROR:`20automove`20must`20be`20'yes'`20or`20'no'`20in`20%s
- V`5Cn",s);
- X`09ldbexit(STAT_ABORT);
- X`09`7D
- Xif`20(strchr("yn",*rc.chkpt)`20==`20NULL)`20`7B
- X`09fprintf(stderr,"ERROR:`20checkpoint`20must`20be`20'yes'`20or`20'no'`20in
- V`20%s`5Cn",s);
- X`09ldbexit(STAT_ABORT);
- X`09`7D
- X`7D
- X
- X
- X/*---------------------------------------------------------------------------
- X`20*`09readgames`20--`20read`20in`20games`20in`20progress
- X`20*
- X`20*`20This`20function`20reads`20the`20games`20file`20specified`20in`20.ldbrc
- V`20and`20loads
- X`20*`20the`20games`20into`20the`20games`20list`20(ghead/gtail).
- X`20*--------------------------------------------------------------------------
- V-
- X`20*/
- X
- Xreadgames()
- X`7B
- XFILE`20*fp;
- Xchar`20c,`20*s;
- Xstruct`20game`20*g;
- Xlong`20old;
- X
- Xreadpeople();
- Xif`20(`20(fp`20=`20fopen(rc.gfile,"r"))`20==`20NULL)
- X`09return;`09`09`09`09/*`20no`20games`20*/
- Xold`20=`20time(`20(long`20*)`200);
- Xif`20(rc.keepold`20>`200)`09`09/*`20if`20keeping`20old`20games`20is`20enabled
- V`20*/
- X`09old`20-=`20(rc.keepold`20*`2086400);`09/*`20how`20old`20is`20too`20old?`20*
- V/
- Xwhile`20(`20(c`20=`20getc(fp))`20!=`20EOF)`20`7B
- X`09ungetc(c,fp);`09/*`20put`20char`20back`20*/
- X`09g`20=`20addgame();`09`09/*`20insert`20a`20new`20game`20*/
- X`09g->opaddr`20=`20NULL;
- X`09g->opname`20=`20NULL;
- X`09g->myaddr`20=`20NULL;
- X`09g->mycmt`20=`20NULL;
- X`09g->mycmt2`20=`20NULL;
- X`09g->opcmt`20=`20NULL;
- X`09g->opcmt2`20=`20NULL;
- X`09g->dispmsg`20=`20NULL;
- X`09g->hiused`20=`200;
- X`09g->maxused`20=`200;
- X`09g->opver`20=`20100;`09`09/*`20default`20to`20version`201.0`20*/
- X`09g->starttime`20=`200L;
- X`09clearmvs(g->opmvs);
- X`09clearmvs(g->mvs);
- X`09if`20(`20(s`20=`20nvscan(fp,nv_gfile,g))`20!=`20NULL)`20`7B`09/*`20read`20g
- Vame`20*/
- X`09`09FeFinishSession();`09/*`20close`20down`20front-end`20*/
- X`09`09TFinishSession();`09/*`20close`20down`20transport`20*/
- X`09`09fprintf(stderr,"ERROR:`20invalid`20line`20in`20%s:`20%s`5Cn",`20rc.gfile
- V,`20s);
- X`09`09ldbexit(STAT_ABORT);
- X`09`09`7D
- X`09if`20(g->gameid`20==`20NULL)`20`7B`09`09/*`20empty`20game`20(prob.`20EOF)
- V`20*/
- X`09`09deletegame(g);
- X`09`09continue;
- X`09`09`7D
- X`09if`20(g->myaddr`20==`20NULL)`09`09/*`20no`20myaddr`20line`20*/
- X`09`09g->myaddr`20=`20save(rc.myaddr);`09/*`20dflt`20to`20ldbrc`20setting`20*/
- V
- X`09if`20(`20(g->ppl`20=`20findppl(g->opaddr,P_ADDR))`20==`20NULL)
- X`09`09newppl(g);
- X`09if`20(
- X`09`20`20`20(g->state`20==`20ST_GAMEOVER)`09`26`26
- X`09`20`20`20(g->flags`20`26`20F_DISPLAYED)`09`26`26
- X`09`20`20`20(g->lastacc`20<`20old)`20)
- X`09`09g->flags`20`7C=`20F_DELETE;`09/*`20game`20is`20old,`20mark`20it`20for
- V`20deletion`20*/
- X`09if`20(rc.debug`20`26`20DB_RWGAMES)
- X`09`09message("DB-readgames:`20read`20game`20%s`5Cn",g->gameid);
- X`09`7D
- Xfclose(fp);
- X`7D
- X
- X
- X/*----------------------------------------------------------------------
- X`20*`09writegames`20--`20save`20the`20game`20list`20to`20a`20file
- X`20*
- X`20*`20This`20function`20writes`20each`20game`20in`20the`20game`20list`20to
- V`20the`20specified
- X`20*`20file.`20`20Games`20with`20F_DELETE`20set`20in`20their`20flags`20are`20s
- Vkipped,`20and
- X`20*`20are`20thus`20effectively`20deleted.`20`20If`20the`20bkup`20arg`20is`20n
- Vot`20NULL`20and
- X`20*`20is`20not`20an`20empty`20string,`20the`20old`20file`20is`20renamed`20to
- V`20the`20string
- X`20*`20specified`20in`20bkup`20before`20the`20new`20file`20is`20created.
- X`20*----------------------------------------------------------------------
- X`20*/
- X
- Xwritegames(file,bkup,pfile)
- Xchar`20*file,`20*bkup,`20*pfile;
- X`7B
- XFILE`20*fp;
- Xstruct`20game`20*g;
- X
- Xwritepeople(pfile);`09`09`09/*`20save`20the`20people`20file`20*/
- Xif`20(`20(bkup`20!=`20NULL)`20`26`26`20(*bkup`20!=`20'`5C0')`20)`20`7B
- X`09unlink(bkup);`09`09/*`20prevent`20multiple`20versions`20on`20VMS`20*/
- X`09rename(file,bkup);`09/*`20save`20old`20game`20file`20*/
- X`09`7D
- Xelse
- X`09unlink(file);`09`09/*`20prevent`20multiple`20versions`20on`20VMS`20*/
- Xif`20(`20(fp`20=`20fopen(file,"w"))`20==`20NULL)`20`7B
- X`09message("ERROR:`20can't`20save`20games`20in`20%s!`5Cn",file);
- X`09return;`09`09`09/*`20should`20do`20something`20to`20save`20games...`20*/
- X`09`7D
- Xfor`20(g`20=`20ghead;`20g`20!=`20NULL;`20g`20=`20g->next)`20`7B
- X`09if`20(g->flags`20`26`20F_DELETE)
- X`09`09continue;`09`09`09/*`20game`20is`20over,`20delete`20it`20*/
- X`09if`20(g->state`20==`20ST_GAMEOVER)
- X`09`09continue;`09`09`09/*`20skip`20complete`20games`204`20now`20*/
- X`09nvwrite(fp,nv_gfile,g);`09/*`20write`20the`20struct`20*/
- X`09if`20(rc.debug`20`26`20DB_RWGAMES)
- X`09`09message("DB-writegames:`20write`20game`20%s`5Cn",g->gameid);
- X`09`7D
- Xfor`20(g`20=`20ghead;`20g`20!=`20NULL;`20g`20=`20g->next)`20`7B
- X`09if`20(g->flags`20`26`20F_DELETE)
- X`09`09continue;`09`09/*`20game`20is`20over,`20delete`20it`20*/
- X`09if`20(g->state`20!=`20ST_GAMEOVER)
- X`09`09continue;`09`09/*`20put`20complete`20games`20@`20end`20*/
- X`09nvwrite(fp,nv_gfile,g);`09/*`20write`20the`20struct`20*/
- X`09if`20(rc.debug`20`26`20DB_RWGAMES)
- X`09`09message("DB-writegames:`20write`20game`20%s`5Cn",g->gameid);
- X`09`7D
- Xfclose(fp);
- X`7D
- X
- X
- X/*---------------------------------------------------------------------------
- X`20*`09readpeople`20--`20read`20in`20the`20people`20file
- X`20*
- X`20*`20This`20function`20reads`20the`20"people"`20file,`20which`20is`20the`20l
- Vist`20of`20all`20of`20the
- X`20*`20opponents`20we`20have`20ever`20played.`20`20The`20people`20file`20serve
- Vs`20three`20purposes:
- X`20*`091.`20It`20keeps`20a`20record`20of`20games/gammons/backgammons/matches
- V`20won/lost
- X`20*`09`20`20`20to`20each`20person.
- X`20*`092.`20It`20stores`20the`20mail`20address`20so`20you`20don't`20have`20to
- V`20remember,
- X`20*`09`20`20`20and`20allows`20you`20to`20assign`20an`20alias`20to`20each`20pe
- Vrson.`20`20This
- X`20*`09`20`20`20alias`20can`20be`20used`20in`20the`20-start`20argument`20inste
- Vad`20of`20the
- X`20*`09`20`20`20mail`20address.
- X`20*`093.`20It`20stores`20the`20"fence"`20time,`20which`20is`20the`20time`20th
- Vat`20the
- X`20*`09`20`20`20(newest`20game`20played`20with`20that`20person`20that`20has
- V`20finished)
- X`20*`09`20`20`20was`20started.`20`20(Read`20it`20again,`20it`20makes`20sense).
- V
- X`20*`09`20`20`20This`20information`20allows`20us`20to`20discard`20START`20pack
- Vets`20that
- X`20*`09`20`20`20have`20remained`20in`20our`20mail`20(that`20we`20should`20have
- V`20deleted,
- X`20*`09`20`20`20but`20didn't)`20by`20discarding`20START`20packets`20that`20are
- V`20not`20newer
- X`20*`09`20`20`20than`20the`20fence`20time.
- X`20*--------------------------------------------------------------------------
- V-
- X`20*/
- X
- Xreadpeople()
- X`7B
- XFILE`20*fp;
- Xchar`20c,`20*s;
- Xstruct`20people`20*p;
- X
- Xif`20(`20(fp`20=`20fopen(rc.pfile,"r"))`20==`20NULL)
- X`09return;`09`09`09`09/*`20no`20people`20file`20*/
- Xwhile`20(`20(c`20=`20getc(fp))`20!=`20EOF)`20`7B
- X`09ungetc(c,fp);`09/*`20put`20char`20back`20*/
- X`09p`20=`20addppl();`09`09/*`20insert`20a`20new`20record`20*/
- X`09p->name`20=`20NULL;`09`09
- X`09p->addr`20=`20NULL;
- X`09p->alias`20=`20NULL;
- X`09p->myaddr`20=`20NULL;
- X`09p->equiv`20=`20NULL;
- X`09p->fence`20=`200L;
- X`09if`20(`20(s`20=`20nvscan(fp,nv_pfile,p))`20!=`20NULL)`20`7B`09/*`20read`20r
- Vecord`20*/
- X`09`09FeFinishSession();`09/*`20close`20down`20front-end`20*/
- X`09`09TFinishSession();`09/*`20close`20down`20transport`20*/
- X`09`09fprintf(stderr,"ERROR:`20invalid`20line`20in`20%s:`20%s`5Cn",`20rc.pfile
- V,`20s);
- X`09`09ldbexit(STAT_ABORT);
- X`09`09`7D
- X`09if`20(p->equiv`20!=`20NULL)`09`09/*`20an`20equiv`20record`20*/
- X`09`09continue;`09`09/*`20no`20other`20fields`20*/
- X`09if`20(p->myaddr`20==`20NULL)`09`09`09/*`20if`20no`20myaddr`20line`20*/
- X`09`09p->myaddr`20=`20save(rc.myaddr);`09/*`20dflt`20to`20ldbrc`20setting`20*/
- V
- X`09if`20(rc.debug`20`26`20DB_RWGAMES)
- X`09`09message("DB-readpeople:`20read`20'%s'`5Cn",p->name);
- X`09`7D
- Xfclose(fp);
- X`7D
- X
- X
- X/*----------------------------------------------------------------------
- X`20*`09writepeople`20--`20save`20the`20people`20list`20to`20a`20file
- X`20*
- X`20*`20This`20function`20writes`20the`20people`20list`20to`20rc.pfile.
- X`20*----------------------------------------------------------------------
- X`20*/
- X
- Xwritepeople(file)
- Xchar`20*file;
- X`7B
- XFILE`20*fp;
- Xstruct`20people`20*p;
- X
- Xunlink(file);`09`09/*`20prevent`20multiple`20versions`20on`20VMS`20*/
- Xif`20(`20(fp`20=`20fopen(file,"w"))`20==`20NULL)`20`7B
- X`09message("ERROR:`20can't`20save`20people`20in`20%s!`5Cn",file);
- X`09return;`09`09`09/*`20should`20do`20something`20to`20save`20people`20list
- V`20*/
- X`09`7D
- Xfor`20(p`20=`20phead;`20p`20!=`20NULL;`20p`20=`20p->next)`20`7B
- X`09if`20(p->equiv`20==`20NULL)`20`7B
- X`09`09nvwrite(fp,nv_pfile,p);`09/*`20write`20the`20struct`20*/
- X`09`09if`20(rc.debug`20`26`20DB_RWGAMES)
- X`09`09`09message("DB-writepeople:`20write`20'%s'`5Cn",p->name);
- X`09`09`7D
- X`09else
- X`09`09nvwrite(fp,nv_pequiv,p);`09/*`20write`20an`20equiv`20record`20*/
- X`09`7D
- Xfclose(fp);
- X`7D
- X
- X
- X
- X/*----------------------------------------------------------------------
- X`20*`09boardstr`20--`20generate`20an`20ascii`20representation`20of`20a`20board
- V
- X`20*
- X`20*`20This`20function`20produces`20a`20visible`20representation`20of`20a`20bo
- Vard.`20`20Each`20point
- X`20*`20on`20the`20board`20takes`20two`20characters;`20the`20quantity`20is`20of
- Vfset`20by`2065,
- X`20*`20putting`20it`20in`20the`20range`20`5BA-P`5D,`20and`20the`20color`20is
- V`20unchanged`20since`20it
- X`20*`20is`20already`20a`20printable`20character.`20`20This`20results`20in`20a
- V`20string`20of
- X`20*`2028`20character`20pairs,`20one`20for`20each`20point`20on`20the`20board.
- V`20`20These`20are
- X`20*`20in`20the`20order:
- X`20*`090:`09BAR`20point`20for`20upbound`20player
- X`20*`091-24:`09board`20points
- X`20*`0925:`09BAR`20point`20for`20downbound`20player
- X`20*`0926:`09OFF`20point`20for`20upbound`20player
- X`20*`0927:`09OFF`20point`20for`20downbound`20player
- X`20*----------------------------------------------------------------------
- X`20*/
- X
- Xchar`20*boardstr(b)
- Xboard`20b;
- X`7B
- Xstatic`20char`20buf`5BBOARDSIZE*2+1`5D;
- Xchar`20*s,`20c;
- Xint`20i;
- X
- Xs`20=`20buf;
- Xfor`20(i`20=`200;`20i`20<`20BOARDSIZE;`20i++)`20`7B
- X`09*s++`20=`20b`5Bi`5D.qty`20+`20'A';`09`09/*`20offset`20qty`20into`20u.c.`20l
- Vetters`20*/
- X`09c`20=`20b`5Bi`5D.color;
- X`09if`20(!`20isalpha(c))
- X`09`09c`20=`20'-';`09`09/*`20use`20printing`20chars`20*/
- X`09*s++`20=`20c;
- X`09`7D
- X*s`20=`20'`5C0';
- Xreturn(buf);
- X`7D
- X
- X
- +-+-+-+-+-+-+-+- END OF PART 13 +-+-+-+-+-+-+-+-
-