/*    After a bit of nudging by Jim Oliver (at least, I *think* he's the
one) and piping the supplementary data into stripraw on my own, I have
made yet another change to stripraw.c.   The program now recognizes an
addition, optional argument: supplementary info file name.  When it is
given such a file name,  it reads  all the team boards, procedural and
technical fouls, etc. information from a file more or less as it would
had you piped the file in.  The difference is that, using this option,
the file is of a more compact form and the program doesn't print quite
the amount of garbage to the screen.  The supp. info file format is as
follows:

<game number>
<team boards> <# of procedural technicals> <# of bench technicals>
<bench technical list *if* there were any bench technicals>
<1st-qtr points> <2nd-qtr points> <...>
 repeat above three lines for second team
<attendance> <time>
<referee list>
<game number>
...
<game number>
...
-1

    Items in a line may be space- or comma-delimited, or indeed any
combination of the two.  The line of per-quarter scoring is not to be
ended with a -1 as was the case with the piped-in method. The attendance
is not to have any commas within it, and the second character of the
time entry (the character between the hours and the tens of minutes)
can be anything at all, since the program will automatically change
it to a colon.
    I have tested the program and it still allows for piping in the
supplementary information, so if you prefer that, or indeed manual
entry, you should have no problems.  Complaints/suggestions solicited.

cam   */

/*####    stripraw.c, version 2.2    ####*/

#include <stdio.h>
#include <string.h>
#include <ctype.h>

struct {
    struct {
	char  name[40];
	int  stats[19];
    }  players[14];
    int  totals[19];
    int  number, wins, losses, scores[10], boards, TOs,
         proced_techs, bench_techs;
    char  bench_techs_list[81];
}  teams[2];

            /**
	         The 19 integer stats are:
	             0 => games
		     1 => minutes
		     2 => field goals made
		     3 => field goals attempted
		     4 => three-pointers made
		     5 => three-pointers attempted
		     6 => free throws made
		     7 => free throws attempted
		     8 => offensive rebounds
		     9 => total rebounds
		    10 => assists
		    11 => personal fouls
		    12 => steals
		    13 => turn-overs
		    14 => blocks
		    15 => technicals
		    16 => ejections
		    17 => flagrant fouls
		    18 => points
            **/

struct {
    int  lines;
    char  gamename[20];
}  filegames[500];

int  attend, numfilegames, teamgames[27][83];
char  inpline[181], refs[81], game_time[5],
      *teamnames[] = { "atl", "bos", "cha", "chi", "cle", "dal", "den",
		       "det", "gsw", "hou", "ind", "lac", "lal", "mia",
		       "mil", "min", "njn", "nyk", "orl", "phi", "pho",
		       "por", "sac", "san", "sea", "uta", "was", "???" },
      myteams[] = { "000000000000000000000000000" },
      mydays[] = { "0100000" };    /**  Monday - Sunday.  **/

int  days[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
            /** jan feb mar apr may jun jul aug sep oct nov dec **/
char  *months[12] = { "jan", "feb", "mar", "apr", "may", "jun",
		      "jul", "aug", "sep", "oct", "nov", "dec" };

    char  *nba_schedule[] = {
	/* 11/5  (001) */	"kaTrbTdcU0oeTphUqjVvlZumZ0snU{tTgwZixVfzW",
	/* 11/6  (002) */	"ndV4ifVhkTcoWzpUtsTmyYb{T",
	/* 11/7  (003) */	"reSlgWwuWjvZqxV",
	/* 11/8  (004) */	"obTadV6yzW",
	/* 11/9  (005) */	"ceTqfV{hTjiZulZvmZtrTksTpxVgyY",
	/* 11/10 (006) */	"doVbtU0xuWmwZazWr{T",
	/* 11/11 (007) */	"scTpjVhlZonTkqTeyY",
	/* 11/12 (008) */	"cbTeiZrkU0gmZfpUnsTavZxwZ0hzWt{T",
	/* 11/13 (009) */	"bdV4zfVigWujVxlZtqTorTayY5",
	/* 11/14 (010) */	"emZwqShvU",
	/* 11/15 (011) */	"jtT",
	/* 11/16 (012) */	"waTrfVxgWuiZckTlmZpoVjqTzsTevZdyU0",
	/* 11/17 (013) */	"qbTwcTshTznTatTrxVo{T",
	/* 11/18 (014) */	"egWmiZjkTflZdvZ4",
	/* 11/19 (015) */	"sbT{cU0xhUdmZanTwpUztTvuWfyY",
	/* 11/20 (016) */	"caT5yiZljVbkTxoWgpUsqTzrVeuWn0{T",
	/* 11/21 (017) */	"thSmqSfvZdwW",
	/* 11/22 (018) */	"k1bTnrTlxV",
	/* 11/23 (019) */	"maTlfVdjVisU0gvZc{T",
	/* 11/24 (020) */	"mcT{eTbhTtkTinTaoVqpUguWywZdxV4jzW",
	/* 11/25 (021) */	"",
	/* 11/26 (022) */	"{aTnbTocTdfV4vgWmkTypUitTjwZqzW",
	/* 11/27 (023) */	"taT5yeTqgWjlZcnTboWmpUhrGzuWfxVs{T",
	/* 11/28 (024) */	"ihSwvZ",
	/* 11/29 (025) */	"qlZkwZoxV",
	/* 11/30 (026) */	"baTudU0heTfiZojVvnTytTgzW",
	/* 12/1  (027) */	"{bTxcTklZfmZeqTvsTpwZ",
	/* 12/2  (028) */	"uhTpiZjrTkzUy{T",
	/* 12/3  (029) */	"jaTvbTofVcgZ0dnTuqTxsU0",
	/* 12/4  (030) */	"seTkiZmlZwrGxtTpyYczWv{T",
	/* 12/5  (031) */	"jeSfgWpmZuoV",
	/* 12/6  (032) */	"{yYrzW",
	/* 12/7  (033) */	"ldVveTnfVgiZcjVwkTrmZbqU0hsT",
	/* 12/8  (034) */	"wbTahTloVvpUdtTyxV{zW",
	/* 12/9  (035) */	"xaTecTyfVriZnjVskT{uW",
	/* 12/10 (036) */	"zgWohU0lpUdqTbsTwtTmvZ",
	/* 12/11 (037) */	"qcTedV4ufVziZyjVbnTtoWhpUkrTgxVa0{T",
	/* 12/12 (038) */	"imLsvUlwZ",
	/* 12/13 (039) */	"tbTnqTouWxzW",
	/* 12/14 (040) */	"pcTaeTvfU0mhT{kTjnTgrTsyY",
	/* 12/15 (041) */	"dbT4slZzpUgtTiuWowZvxV",
	/* 12/16 (042) */	"kaTxfVenTcqTmrTh{T",
	/* 12/17 (043) */	"zbTgcTrdU0plZmtTsuZ0iwZoyY",
	/* 12/18 (044) */	"gaT5xdVehTfjVqkTtnTluWpvZiyYz{T",
	/* 12/19 (045) */	"meSovZswW",
	/* 12/20 (046) */	"cdV4olZ{pUfrThtTkuW",
	/* 12/21 (047) */	"zeTugWchTviW0rqTmsTjxVkyY",
	/* 12/22 (048) */	"abT5pdV{lZfoVntT",
	/* 12/23 (049) */	"bcToeTdhT4liZgjVmnTfpUarT5qsTkvZ{wZzxVuyY",
	/* 12/24 (050) */	"",
	/* 12/25 (051) */	"sdV2juJ2",
	/* 12/26 (052) */	"keGpgWjmZwnTaqQivUbxV",
	/* 12/27 (053) */	"hcTtlZ{oVwsTbuWpzW",
	/* 12/28 (054) */	"haT5ceTgfVtiZxnTqrTjyY",
	/* 12/29 (055) */	"qdVymZasT5lvZbzWw{T",
	/* 12/30 (056) */	"dcT4igWwhTxkTblZsnTeoVjpU{rTtuW",
	/* 12/31 (057) */	"",
	/* 1/1   (058) */	"",
	/* 1/2   (059) */	"qbStgWnhTcrQzvUfwWmxV",
	/* 1/3   (060) */	"fzW",
	/* 1/4   (061) */	"caThdVmgWwiZvjVekTqnTsrTyuW0txV",
	/* 1/5   (062) */	"beTjfVylZgpUoqTdsU0mwZuzWk{T",
	/* 1/6   (063) */	"vcTxiZroV",
	/* 1/7   (064) */	"vaTebTtfVxgWlmZupU0wyYnzWd{T",
	/* 1/8   (065) */	"eaT5rcTfdVwgWkhTtjVnlZqoVbpU{sTzyY",
	/* 1/9   (066) */	"xmZvrQiuU0",
	/* 1/10  (067) */	"jsU0btT",
	/* 1/11  (068) */	"ghTimZkoV{qTlrTcuWyvZnwZpxV",
	/* 1/12  (069) */	"daT6jbTpfVniZgkTesTltT",
	/* 1/13  (070) */	"qeTrhTzoVcwZuxVj{T",
	/* 1/14  (071) */	"faTlbU0zdVyiZcmZspUgqTktTnvZ",
	/* 1/15  (072) */	"jdV4teTxfVakTsoWhrGuwZnyYl{T",
	/* 1/16  (073) */	"gbSzqQcvU",
	/* 1/17  (074) */	"oaLtdLseQzhTuiU0wmNprGx{G",
	/* 1/18  (075) */	"vgWbjVlnThoVfuWmyY",
	/* 1/19  (076) */	"iaT5tcT{dVbfVnkTpqTxrTlsTywZezW",
	/* 1/20  (077) */	"jgWumZxpU",
	/* 1/21  (078) */	"qaTibTkdVyfVelZhnTcoWrsU0mvZwzW",
	/* 1/22  (079) */	"ocTygWzjVdkTapUiqTstTvuWewZfxVh0{T",
	/* 1/23  (080) */	"{nTtrQ",
	/* 1/24  (081) */	"fbTdhT4okTyzW",
	/* 1/25  (082) */	"ejVcnTaoVurU0{sTqvZwxVlyY",
	/* 1/26  (083) */	"uaT5nbTscThiZkmZzpUftT",
	/* 1/27  (084) */	"deT4kgWwjVrlZqyYf{T",
	/* 1/28  (085) */	"acTodVhmZnsTutTpvZizU0",
	/* 1/29  (086) */	"neTwfVhgWqiZkjVplZotTaxV5ryYs{T",
	/* 1/30  (087) */	"ubF2rvZ",
	/* 1/31  (088) */	"afVehU0ilZ",
	/* 2/1   (089) */	"dgW4{kTnoVyqTbrTluWvwZmxVjzW",
	/* 2/2   (090) */	"saT5ybTkcTohTgiZfpUetTr{T",
	/* 2/3   (091) */	"xeTmjVuvZdzW",
	/* 2/4   (092) */	"raU0xbTncTmfVyhUdiZpkTosT{tTgwZ",
	/* 2/5   (093) */	"aeT5qhTckTwlZtnTyoWvzW",
	/* 2/6   (094) */	"fgWpjQzmZxqQsrG2duL2i{G",
	/* 2/7   (095) */	"haTikTrnU0ctT",
	/* 2/8   (096) */	"qeTpfVzgWdlZumZjoVwvZ{xV",
	/* 2/9   (097) */	"hbTicU0knTeqTasTrtTpuWlwZvyYmzW",
	/* 2/10  (098) */	"naT5{fVjhTdoV4irTgxV",
	/* 2/11  (099) */	"|pY0",
	/* 2/12  (100) */	"|pS0",
	/* 2/13  (101) */	"}pR2",
	/* 2/14  (102) */	"",
	/* 2/15  (103) */	"geTvfV{hTwiZajVlmZopUrqTbsTkxVtyY",
	/* 2/16  (104) */	"jcTndV4zlZgoVvuWtwZ",
	/* 2/17  (105) */	"q1bTreTkfVaiZ5ynThxVp{T",
	/* 2/18  (106) */	"ocTgdV4alZepUysU0muWtvZzwZq0{T",
	/* 2/19  (107) */	"hfVbiZujVnxVlzW",
	/* 2/20  (108) */	"ecMagWykLtmZsoL{qTdrG2bvZ",
	/* 2/21  (109) */	"cdLfhT{nTxpKwuWtzW",
	/* 2/22  (110) */	"peTgjVfkTioVnqTyrTlvZbwZ",
	/* 2/23  (111) */	"yaTidV4bgWvlZksTqtTxzWe{T",
	/* 2/24  (112) */	"fcTrjU0upUmwZ",
	/* 2/25  (113) */	"oaTieTrgWhkTwlZxmZqsTntTbyYuzWd{T4",
	/* 2/26  (114) */	"kdV4feTnhTzjV{oWatT5xvZ",
	/* 2/27  (115) */	"ylWbmZipKfqQcsF2ruP2gvZ",
	/* 2/28  (116) */	"edU0jzW",
	/* 3/1   (117) */	"paTliZsjVvkTnoVhqT{tTrwZcyY",
	/* 3/2   (118) */	"ebTmdV4vhTclZnpUzxV",
	/* 3/3   (119) */	"teTsfVuiW0qrTa{T",
	/* 3/4   (120) */	"mbU0vdVsgWqkTpuWlxV",
	/* 3/5   (121) */	"kaT5zfVciZljVtnThoWwyYm{T",
	/* 3/6   (122) */	"deG2pgWtqQzuWywWsxL2",
	/* 3/7   (123) */	"rhTbnTmoVivZ",
	/* 3/8   (124) */	"ucTadV5weTlfVgsTjxViyYpzW",
	/* 3/9   (125) */	"raT5qhTgnTkoVwpUstTzvZu{T",
	/* 3/10  (126) */	"viZyjU0fmZ",
	/* 3/11  (127) */	"daT4rbTehUflZunTwoWcpUkqTtsTyxVg{T",
	/* 3/12  (128) */	"wdVahTxjVokTcqTerV",
	/* 3/13  (129) */	"nbSjfUilWmpKusE2vyYt{G",
	/* 3/14  (130) */	"bcTxgWhwZmzW0",
	/* 3/15  (131) */	"sdU0ueT{iZvjVzlZonTtpUkrThyY",
	/* 3/16  (132) */	"dbT4acT5ukT{mZfsTqwZvxV",
	/* 3/17  (133) */	"ijVglZfnTypUorT",
	/* 3/18  (134) */	"zcTydV4wgWakTqmZesTptThuW{vZ",
	/* 3/19  (135) */	"ifVhjVzkTenTbrGquWwxV",
	/* 3/20  (136) */	"abE3ycE3{gWvlWsmLtoJdpK",
	/* 3/21  (137) */	"zaT5{jVnmZ",
	/* 3/22  (138) */	"tcTkeTogWsiZjpUlqTdrU0nuWvwZxyY",
	/* 3/23  (139) */	"caTmfVlhTekTdtTszW",
	/* 3/24  (140) */	"ngWoiZmjVrpUxwZuyYb{T",
	/* 3/25  (141) */	"laTchUrkTdqTetTfuWwvZozW",
	/* 3/26  (142) */	"naT5lcTkdV4fgWxiZzjVpyYq{T",
	/* 3/27  (143) */	"t1bTheSomZrsE2juU0xvZ",
	/* 3/28  (144) */	"lkTgyY",
	/* 3/29  (145) */	"qaTtdVleTxfVpmZhnTboVcrU0{sTyvZjwZizW",
	/* 3/30  (146) */	"kbTjiZnqT",
	/* 3/31  (147) */	"ulZvoVawZexU0myY",
	/* 4/1   (148) */	"{bThdU0cfVpiZjmZknTsqTvtTauW",
	/* 4/2   (149) */	"efVskTnrTpwZcxViyYgzWo{T",
	/* 4/3   (150) */	"dhH2jlQamZvqSbtSguW",
	/* 4/4   (151) */	"",
	/* 4/5   (152) */	"{dVceTlgWhkTrnTbqTosTuvZfwZixVzyY",
	/* 4/6   (153) */	"baT5kcTwmZlpUotTxuWn{T",
	/* 4/7   (154) */	"ygWijU0aqTerTfzW",
	/* 4/8   (155) */	"pbTqcTdkTgmZhsTrtTuwZfyYe{T",
	/* 4/9   (156) */	"{aTodV4xjL3snTipUctTmvZlzL3",
	/* 4/10  (157) */	"jgWbhG3rqG3uyL2",
	/* 4/11  (158) */	"ncTfiZbkTsrU0lwZpxV",
	/* 4/12  (159) */	"qdVoeTugWthTpjVylZimZfvZwzW",
	/* 4/13  (160) */	"eaT5hbTdnT4qoVktTmuWgxV",
	/* 4/14  (161) */	"viZwjVcsU0lyYxzWr{T",
	/* 4/15  (162) */	"sbTdcU0neTgfVvmZaoWkpUhqT{rT",
	/* 4/16  (163) */	"taT5wfVziZmlZeoWuxL3jyL3",
	/* 4/17  (164) */	"rcK2khFqnMgpKdsP2jvZb{F",
	/* 4/18  (165) */	"adV6ufVilZ",
	/* 4/19  (166) */	"obTmgWshTpnTarTqtTyuWzwZjxU0k{T",
	/* 4/20  (167) */	"{cTekTglZymZhoVpsT",
	/* 4/21  (168) */	"cbTwiZfjVanTtrTvzW",
	/* 4/22  (169) */	"bdV1{eT1jfV1zgW1tkT1roW1vpU1luW1xyY1",
	/* 4/23  (170) */	"saThcL3miL3nkToqTwuW",
	/* 4/24  (171) */	"rdG2beL3pfUgjL3xlL3zmL3qsThtGyvL3iwWc{G" };

/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/

int  main( int argc, char *argv[] )

{
    int  i, j, k, z, dogame( FILE *phile );
    FILE  *phile, *otherphile;
    void  dogamesfromfile( FILE *phile, FILE *otherphile ),
	  getgamedate( int nba_day,  char *gamedate ),
          scanfile( FILE *phile ), striplen( void );
    char  ctemp[81];

    if ( argc < 2 ) {
        printf( "   strip  stats-file-name [other-info-file]\n" );
        return (int)  1;
    }
    phile = fopen( argv[1], "r" );

    striplen();    /**  Set up the array of game numbers vs. dates.  **/

    scanfile( phile );
    if ( numfilegames == 0 )
	return (int)  1;

    if ( argc == 3 ) {
	otherphile = fopen( argv[2], "r" );
	if ( !otherphile )
	    printf( "\n Couldn't open file %s\n\n", argv[2] );
	else
	    dogamesfromfile( phile, otherphile );
    }
    else {
	while ( dogame( phile ) ) {
	    ;
	}
    }

    fclose( phile );
}

/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/

int  dogame( FILE *phile )

{
    int  i, j;
    char  ctemp[20];
    FILE  *outphile;
    void  getotherdata( void ), readrawbox( FILE *phile ),
          writetemplatefile( FILE *phile );

    for ( i=0; i<numfilegames; i++ )
	printf( " %3d: %s\n", (i+1), filegames[i].gamename );

    do {
	printf( "\n\n  Enter number of game to strip (0 to exit): " );
	i = getnum();
    }  while ( i > numfilegames );

    if ( i <= 0 )
	return  (int) 0;

    rewind( phile );
    for ( j=0; j<filegames[i-1].lines; j++ )
	fgets( inpline, 181, phile );

    readrawbox( phile );

    getotherdata();

    sprintf( ctemp, "%3.3s%3.3s.t",
	     teamnames[ teams[0].number ], teamnames[ teams[1].number ] );
    outphile = fopen( ctemp, "w" );

    writetemplatefile( outphile );

    return  (int) 1;
}

/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/

void  dogamesfromfile( FILE *phile, FILE *otherphile )

{
    int  i, j;
    char  ctemp[81];
    FILE  *outphile;
    void  getotherdatafromfile( FILE *phile ), readrawbox( FILE *phile ),
          writetemplatefile( FILE *phile );

    for ( i=0; i<numfilegames; i++ )
	printf( " %3d: %s\n", (i+1), filegames[i].gamename );
    printf( "\n" );

    while ( fgets( ctemp, 81, otherphile ) ) {
	sscanf( ctemp, "%d", &i );
	if ( (i <= 0) || (i > numfilegames) )
	    break;

	rewind( phile );
	for ( j=0; j<filegames[i-1].lines; j++ )
	    fgets( inpline, 181, phile );

	readrawbox( phile );

	getotherdatafromfile( otherphile );

	sprintf( ctemp, "%3.3s%3.3s.t",
		 teamnames[ teams[0].number ], teamnames[ teams[1].number ] );
	outphile = fopen( ctemp, "w" );

	writetemplatefile( outphile );
	printf( "Template file %8.8s written.\n", ctemp );
    }
}

/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/

void  getgamedate( int nba_day,  char *gamedate )

{
    int  i, m, d, y;
    
    d = 5;
    m = 11;
    y = 93;
    for ( i=0; i<nba_day; i++ ) {
	d++;
	if ( d > days[ m-1 ] ) {
	    d = 1;
	    m++;
	    if ( m > 12 ) {
		m = 1;
		y++;
	    }
	}
    }

    sprintf( gamedate, "%02d%3.3s%02d", d, months[m-1], y );
}

/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/

int  getnum( void )

{
    char  t_c[10];
    int  i, j, sign;

    gets( t_c );

    if ( iscntrl( t_c[0] ) )
        return( 0 );

    i = atoi( t_c );
/****
    i = j = 0;
    sign = 1;
    while ( t_c[j] != NULL ) {
        if ( (j == 0) && (t_c[j] == '-') )
            sign = -1;
        i = i * 10 + (t_c[j] - 48);
        j++;
    }
    i = i * sign;
****/

    return (i);
}

/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/

void  getotherdata( void )

{
    int  j, k, ti, getnum( void );

    for ( ti=0; ti<2; ti++ ) {
	printf( "\nFor %3.3s:\n", teamnames[ teams[ti].number ] );

        printf( "  Team rebounds: " );
        teams[ti].boards = getnum();
        printf( "  Team procedural technicals: " );
        teams[ti].proced_techs = getnum();
        printf( "  Team bench technicals: " );
        teams[ti].bench_techs = getnum();
        if ( teams[ti].bench_techs != 0 ) {
            printf( "    Input bench technicals line.\n" );
            gets( teams[ti].bench_techs_list );
        }
        printf( "  Team scoring per period. (-1 to end) \n" );
        j = 1;
        teams[ti].scores[0] = 0;    /**  Game score.  **/
        do {
            if ( j < 5 )
                printf( "    Quarter %1d: ", j );
              else
                printf( "   Overtime %1d: ", (j - 4) );
            k = getnum();
            if ( k == -1 )  break;
            teams[ti].scores[j] = k;
            teams[ti].scores[0] += k;
            j++;
        } while ( j < 10 );
	teams[ti].scores[j] = -1;
    }
    printf( "\nAttendance: " );
    attend = getnum();
    printf( "Time of game (example: 2.29): " );
    gets( game_time );
    game_time[1] = 58;
    printf( "Referees: " );
    gets( refs );
}

/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/

void  getotherdatafromfile( FILE *otherphile )

{
    int  j, k, n, ti, getnum( void );
    char  ctemp[81];

    for ( ti=0; ti<2; ti++ ) {

	    /****  Team boards, procedural techs, and bench techs.  ****/
	fgets( ctemp, 81, otherphile );
	if ( strchr( ctemp, ',' ) ) {    /**  Change commas to spaces.  **/
	    j = 0;
	    while ( ctemp[j] ) {
		if ( ctemp[j] == ',' )
		    ctemp[j] = ' ';
		j++;
	    }
	}
	sscanf( ctemp, "%d %d %d",
	        &teams[ti].boards,
	        &teams[ti].proced_techs, &teams[ti].bench_techs );
        if ( teams[ti].bench_techs != 0 ) {
            fgets( teams[ti].bench_techs_list, 81, otherphile );
	    j = strlen( teams[ti].bench_techs_list );
	    teams[ti].bench_techs_list[ j - 1 ] = 0;
	}

	    /****  Per-quarter scoring.  ****/
	fgets( ctemp, 81, otherphile );
	if ( strchr( ctemp, ',' ) ) {    /**  Change commas to spaces.  **/
	    j = 0;
	    while ( ctemp[j] ) {
		if ( ctemp[j] == ',' )
		    ctemp[j] = ' ';
		j++;
	    }
	}
        j = 1;
	k = 0;
        teams[ti].scores[0] = 0;    /**  Game score.  **/
	n = strlen( ctemp );
        while ( k <= (n - 2) ) {
	    while ( ctemp[k] == ' ' )
		k++;
	    if ( ctemp[k] == '-' )
		break;
	    teams[ti].scores[j] = 0;
	    while ( isdigit( ctemp[k] ) ) {
		teams[ti].scores[j] = teams[ti].scores[j] * 10 + ctemp[k] - 48;
		k++;
	    }
            teams[ti].scores[0] += teams[ti].scores[j];
            j++;
        }
	teams[ti].scores[j] = -1;
    }

        /****  Attendance, game time.  ****/
    fgets( ctemp, 81, otherphile );
    if ( strchr( ctemp, ',' ) ) {    /**  Change commas to spaces.  **/
	j = 0;
	while ( ctemp[j] ) {
	    if ( ctemp[j] == ',' )
		ctemp[j] = ' ';
	    j++;
	}
    }
    sscanf( ctemp, "%d %s", &attend, game_time );
    game_time[1] = 58;

        /****  Referees.  ****/
    fgets( refs, 81, otherphile );
    if ( strchr( refs, ' ' ) ) {    /**  Change spaces to commas.  **/
	j = 0;
	while ( refs[j] ) {
	    if ( refs[j] == ' ' )
		refs[j] = ',';
	    j++;
	}
    }
    refs[ strlen( refs ) - 1 ] = 0;
}

/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/

void  readrawbox( FILE *phile )

{
    int  i, j, ti, pi;
    char  ctemp[40];

    for ( i=0; i<19; i++ )
	teams[0].totals[i] = teams[1].totals[i] = 0;
	teams[0].TOs = teams[1].TOs = 0;

    for ( ti=0; ti<2; ti++ ) {
	do {
	    fgets( inpline, 181, phile );
	}  while  ( (inpline[4] != '(') || (inpline[10] != ')') );

	for ( i=0; i<3; i++ )
	    ctemp[i] = (char) tolower( (int) inpline[i] );

	for ( j=0; j<27; j++ )
	    if ( !strncmp( teamnames[j], ctemp, 3 ) )
		break;
	if ( j == 27 ) {
	    printf( "Team name is %s?\n", ctemp );
	    for ( ; ; )
		;
	}
	teams[ti].number = j;

	sprintf( ctemp, "%2.2s", &inpline[5] );
	teams[ti].wins = atoi( (int) ctemp );
	sprintf( ctemp, "%2.2s", &inpline[8] );
	teams[ti].losses = atoi( (int) ctemp );

	sprintf( ctemp, "team" );
	fgets( inpline, 181, phile );
	pi = 0;
	while( inpline[0] != '*' ) {
	    sscanf( inpline, "%s %d %d %d %d %d %d %d %d %d %d %d %d %d \
%d %d %d %d %d %d",
		   teams[ti].players[pi].name,
		   &teams[ti].players[pi].stats[1],
		   &teams[ti].players[pi].stats[2],
		   &teams[ti].players[pi].stats[3],
		   &teams[ti].players[pi].stats[4],
		   &teams[ti].players[pi].stats[5],
		   &teams[ti].players[pi].stats[6],
		   &teams[ti].players[pi].stats[7],
		   &teams[ti].players[pi].stats[8],
		   &teams[ti].players[pi].stats[9],
		   &teams[ti].players[pi].stats[10],
		   &teams[ti].players[pi].stats[11],
		   &teams[ti].players[pi].stats[12],
		   &teams[ti].players[pi].stats[13],
		   &teams[ti].players[pi].stats[14],
		   &teams[ti].players[pi].stats[15],
		   &teams[ti].players[pi].stats[16],
		   &teams[ti].players[pi].stats[17],
		   &teams[ti].players[pi].stats[18] );

	    if ( strncmp( teams[ti].players[pi].name, ctemp, 4 ) ) {
		for ( i=1; i<19; i++ )
		    teams[ti].totals[i] += teams[ti].players[pi].stats[i];
	    }
	    else {
		teams[ti].TOs = teams[ti].players[pi].stats[13];
		sprintf( teams[ti].players[pi].name, "*" );
	    }
	    pi++;
	    fgets( inpline, 181, phile );
	}
	sprintf( teams[ti].players[pi].name, "*" );
    }
}

/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/

void  scanfile( FILE *phile )

{
    int  i, j, lineindex,
         vis, visgames, home, homegames,
         getnum( void );
    void  getgamedate( int nba_day,  char *gamedate );
    char  ctemp[20];

    printf( "\n" );
    lineindex = numfilegames = 0;

    while ( fgets( inpline, 181, phile ) ) {
	lineindex++;
	if ( (inpline[4] == '(') && (inpline[10] == ')') ) {
	    filegames[numfilegames].lines = lineindex - 1;
	    for ( i=0; i<3; i++ )
		ctemp[i] = (char) tolower( (int) inpline[i] );
	    for ( vis=0; vis<27; vis++ )
		if ( !strncmp( teamnames[vis], ctemp, 3 ) )
		    break;

	    sprintf( ctemp, "%2.2s", &inpline[5] );
	    visgames = atoi( (int) ctemp );
	    sprintf( ctemp, "%2.2s", &inpline[8] );
	    visgames += atoi( (int) ctemp );

	    do {
		fgets( inpline, 181, phile );
		lineindex++;
	    }  while ( (inpline[4] != '(') && (inpline[10] != ')') );

	    for ( i=0; i<3; i++ )
		ctemp[i] = (char) tolower( (int) inpline[i] );
	    for ( home=0; home<27; home++ )
		if ( !strncmp( teamnames[home], ctemp, 3 ) )
		    break;

	    sprintf( ctemp, "%2.2s", &inpline[5] );
	    homegames = atoi( (int) ctemp );
	    sprintf( ctemp, "%2.2s", &inpline[8] );
	    homegames += atoi( (int) ctemp );

	    getgamedate( teamgames[vis][visgames], ctemp );
	    j = (teamgames[vis][visgames] + 4) % 7;

	    if ( (myteams[vis] == '1') || (myteams[home] == '1')
		                       || (mydays[j] == '1') )
		sprintf( filegames[numfilegames].gamename,
		         "*%3.3s%02d%3.3s%02d.%s",
			 teamnames[ vis ],  visgames,
			 teamnames[ home ], homegames, ctemp );
	    else
		sprintf( filegames[numfilegames].gamename,
		         " %3.3s%02d%3.3s%02d.%s",
			 teamnames[ vis ],  visgames,
			 teamnames[ home ], homegames, ctemp );
	    numfilegames++;
	}
    }
}

/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/

void  striplen( void )

{
        /****  Uses Len Carr's nba.c schedule matrix to determine the
	       day on which every game is played, so this template-making
	       program can get game dates automatically.  ****/

    int  i, nba_day, vis, home;

    for ( i=0; i<27; i++ )
	teamgames[i][0] = 0;

    for ( nba_day=0; nba_day<171; nba_day++ ) {
	if ( nba_schedule[nba_day][0] == '\0' )
	    continue;

	for ( i=0; nba_schedule[nba_day][i] != '\0'; ) {
	    vis = nba_schedule[nba_day][i++] - 'a';
	    if ( isdigit(nba_schedule[nba_day][i]) )
		i++;    /**  Alternate site.  **/
	    home = nba_schedule[nba_day][i++] - 'a';
	    i++;    /**  Tip-off time.  **/
	    if ( isdigit(nba_schedule[nba_day][i]) )
		i++;    /**  TV game.  **/

	    if ( (vis < 27) && (home < 27) ) {
		teamgames[vis][0]++;
		teamgames[vis][ teamgames[vis][0] ] = nba_day;
		teamgames[home][0]++;
		teamgames[home][ teamgames[home][0] ] = nba_day;
	    }
	}
    }
}

/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/

void  writetemplatefile( FILE *phile )

{
    int  i, j, pi, ti;
    char  ctemp[81], tc[20];
    void  getgamedate( int nba_day,  char *gamedate );

/****
    Top line: 'GAME',chi62phi61.09mar92,vscore-hscore,attend,refs,time.
****/

    getgamedate( teamgames[ teams[0].number ]
			  [ (teams[0].wins + teams[0].losses) ], ctemp );

    fprintf( phile, "GAME,%3s%02d%3s%02d.%7s,%d-%d,%d,%s,%s\n",
             teamnames[ teams[0].number ], (teams[0].wins + teams[0].losses),
             teamnames[ teams[1].number ], (teams[1].wins + teams[1].losses),
	     ctemp, teams[0].scores[0], teams[1].scores[0],
             attend, refs, game_time );

    for ( ti=0; ti<2; ti++ ) {

        if ( ti == 0 )
            fprintf( phile, "VISITOR,%d-%d\n",
                     teams[ti].wins, teams[ti].losses );
          else
            fprintf( phile, "HOME,%d-%d\n",
                     teams[ti].wins, teams[ti].losses );

	pi = 0;
	while ( teams[ti].players[pi].name[0] != '*' ) {
            fprintf( phile,
                     "%s,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n",
		    teams[ti].players[pi].name,
		    teams[ti].players[pi].stats[1],
		    teams[ti].players[pi].stats[3],
		    teams[ti].players[pi].stats[2],
		    teams[ti].players[pi].stats[5],
		    teams[ti].players[pi].stats[4],
		    teams[ti].players[pi].stats[7],
		    teams[ti].players[pi].stats[6],
		    teams[ti].players[pi].stats[8],
		    teams[ti].players[pi].stats[9],
		    teams[ti].players[pi].stats[10],
		    teams[ti].players[pi].stats[11],
		    teams[ti].players[pi].stats[12],
		    teams[ti].players[pi].stats[13],
		    teams[ti].players[pi].stats[14],
		    teams[ti].players[pi].stats[15],
		    teams[ti].players[pi].stats[16],
		    teams[ti].players[pi].stats[17] );
	    pi++;
        };

        sprintf( ctemp, "END," );
	j = 1;
	while ( teams[ti].scores[j] >= 0 ) {
            sprintf( tc, "%d,", teams[ti].scores[j] );
            strcat( ctemp, tc );
	    j++;
        }
        sprintf( tc, "-%d", teams[ti].scores[0] );
        strcat( ctemp, tc );
        fprintf( phile, "%s\n", ctemp );

        if ( teams[ti].bench_techs == 0 )
            fprintf( phile, "%d,%d,%d\n",
                     teams[ti].boards, teams[ti].TOs, teams[ti].proced_techs );
          else
            fprintf( phile, "%d,%d,%d,%s\n",
                     teams[ti].boards, teams[ti].TOs, teams[ti].proced_techs,
                     teams[ti].bench_techs_list );
    }
}

/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/

