home *** CD-ROM | disk | FTP | other *** search
/ Current Shareware 1994 January / SHAR194.ISO / catalogs / mtchplay.zip / MTCHPLAY.C < prev    next >
Text File  |  1993-02-13  |  29KB  |  1,057 lines

  1.  
  2. #include <conio.h>
  3. #include <ctype.h>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <string.h>
  7. #include <dos.h>
  8. #include "defines.h"
  9. #include "window.h"
  10.  
  11. PLAYER player[MAXFL][MAXSZ];       /* basic data array: names, scores, etc */
  12. short outcome[MAXSZ][MAXSZ];       /* results of matches in a given flight */
  13.  
  14. /* location of score on hole 0..17 in formatted score string */
  15. int ndx[] = {0,1,2,4,5,6,8,9,10,13,14,15,17,18,19,21,22,23};
  16.  
  17. /* par values of holes on course being played */
  18. int par[18];
  19. /* handicap order of holes 0..17 for course being played */
  20. int order[18];
  21.  
  22. /* flags for recalculation of flight */
  23. int recalc[] = {0,0,0,0,0,0,0,0,0,0};
  24.  
  25. int NP[MAXFL];        /* number of players in each flight */
  26. int numflights;       /* number of flights */
  27.  
  28. /* attributes for various screens */
  29. int norm_attr=16*3+8, high_attr=16*7+8, old_attr;
  30. int mono = 0;                 /* flag */
  31. char input_file[13];          /* name of entry list or olddata file */
  32. char datafile[13];            /* name of results file for current tournament */
  33. int desc_flag;                /* flag for display of menu descriptions */
  34. char mark[] = {176,'\0'};     /* single shaded block */
  35. char namefield[] =            /* 19 marks */
  36.     {176,176,176,176,176,176,176,176,176,176,176,176,176,176,
  37.      176,176,176,176,176,'\0'};
  38. char filefield[] =            /* 13 marks */
  39.     {176,176,176,176,176,176,176,176,176,176,176,176,176,'\0'};
  40. char hcpfield[] = {176,176,176,'\0'};   /* negative hcps are temporary */
  41. char scorefield[] = {176,176,176,45,176,176,176,45,176,176,176,45,45,
  42.                          176,176,176,45,176,176,176,45,176,176,176,'\0'};
  43.  
  44. int no_space = 0;             /* flag for get_string() */
  45. int left = 28, top = 1, right = 80, bottom = 25;   /* for data window */
  46. char data_title[81];
  47.  
  48. /* function prototypes */
  49. void
  50. enter(),
  51. check(void),
  52. display(void),
  53. print(void),
  54. call_kb_entry(int),
  55. call_list_results(void),
  56. high(int,int,int,int,int, char *),
  57. norm(int,int,int,int,int, char *),
  58. call_print_matches(void),
  59. call_print_results(void),
  60. main_menu(int),
  61. call_list_data(),
  62. normal_exit(int),
  63. rect(int,int,int,int,int,int),
  64. std_screen(void);
  65.  
  66. int
  67.   get_entries(FILE *pf),
  68.   get_old_data(FILE *fp),
  69.   get_filename(int, char *),
  70.   get_flight(int),
  71.   get_type(void),
  72.   pick_one(int,int,int *,int *),
  73.   menu_select(int,int,int,int,int,char *,int,int,int,int,int,int,
  74.                 int,int,int,int *,char **);
  75.  
  76. extern void
  77.   calc_results(int),
  78.   chk(int),
  79.   compare_two(void),
  80.   hide_cursor(void),
  81.   list_gross(int),
  82.   list_matches(void),
  83.   list_net(int),
  84.   list_results(int),
  85.   print_gross(int),
  86.   print_net(int),
  87.   print_results(int),
  88.   print_matches(int),
  89.   showcursor(void);
  90. extern int
  91.   error_msg(char *, int, int),
  92.   get_string(char *, char *, char *, int, int),
  93.   find(char *, int *),
  94.   findn(char *, int *, int *),
  95.   Getint(int, char *,int *);
  96.  
  97. /*===========================================================================*/
  98.  
  99. main()
  100. {
  101.   FILE *fp;
  102.   int i;
  103.   struct text_info oldtext;
  104.  
  105.   clrscr();
  106.   gettextinfo(&oldtext);           /* original text settings */
  107.   old_attr = oldtext.normattr;
  108.   if (oldtext.currmode == '\7') {
  109.     mono = 1;
  110.     norm_attr = 7;
  111.     high_attr = 16*7;
  112.   }
  113.   initialize();
  114.  
  115.   main_menu(0);
  116. }
  117.  
  118. /*===========================================================================*/
  119.  
  120. static void main_menu(int current)
  121. {
  122.   int scol=8,srow=5,ecol=21,erow=12,border = 2;
  123.   int tag_norm = 16*3+4;
  124.   int tag_high = 16*7+4;
  125.   char *item[] = {
  126.          "  Enter   ",
  127.          "  Display ",
  128.          "  Print   ",
  129.          "  Check   ",
  130.          "  Quit    " };
  131.   int numitems = 5; int tag_indx=2;
  132.   int selection;
  133.   int ltr[] = {'e','d','p','c','q'};
  134.  
  135.   if (mono) tag_norm = tag_high = norm_attr;
  136.   std_screen();
  137.   desc_flag = 1;
  138.   selection = menu_select(scol,srow,ecol,erow,border,"",norm_attr,high_attr,
  139.                 tag_norm,tag_high,tag_indx,numitems-1,current,2,2,ltr,item);
  140.   desc_flag = 0;
  141.   if (selection == 0) {
  142.     enter();
  143.     main_menu(0);
  144.   }
  145.   else if (selection == 1)
  146.     display();
  147.   else if (selection == 2)
  148.     print();
  149.   else if (selection == 3)
  150.     check();
  151.   else if (selection == 4 || selection == 27)
  152.     normal_exit(0);
  153. }
  154.  
  155. void
  156. std_screen()            /* set up standard screens */
  157. {
  158.   window(28,1,80,25);
  159.   textattr(norm_attr);
  160.   clrscr();
  161.   window(1,1,80,25);
  162.   textattr(7);
  163.   rect(1,1,27,25,7,1);
  164.   window(2,2,26,24);
  165.   textattr(high_attr);
  166.   clrscr();
  167. }
  168.  
  169. /* ------------------------- show menu, make selection -------------------- */
  170. menu_select(scol,srow,ecol,erow,border,title,norm_attr,high_attr,tag_norm,
  171.             tag_high,tag_indx,max,current,col0,row0,ltr,item)
  172. int scol,srow,ecol,erow,border,norm_attr,high_attr,tag_norm,tag_high,
  173.             tag_indx,max,current,col0,row0,ltr[];
  174. char *title, *item[];
  175. {
  176.   int i, c, numrows=max;
  177.   int col;
  178.  
  179.   hide_cursor();
  180.   window(scol,srow,ecol,erow);
  181.   textattr(norm_attr);
  182.   clrscr();
  183.   if (border)
  184.     rect(scol,srow,ecol,erow,norm_attr,border);
  185.   if (title[0] && strlen(title) < ecol-scol-2) {
  186.     col = (scol+ecol-strlen(title))/2 - scol + 2;
  187.     gotoxy(col,1);
  188.     cputs(title);
  189.   }
  190.   for (i=0; i<=numrows; i++) {
  191.     norm(1+col0,i+row0,norm_attr,tag_norm,tag_indx,item[i]);
  192.   }
  193.   high(1+col0,current+row0,high_attr,tag_high, tag_indx, item[current]);
  194.  
  195.   while (kbhit())
  196.     getch();                              /* clear kb buffer */
  197.   while ((c=getkey()) != ESC)             /* until Esc key pressed */
  198.     {
  199.      switch(c)
  200.       {
  201.        case UP:
  202.          norm(1+col0,current+row0,norm_attr,tag_norm,tag_indx,item[current]);
  203.          if (current == 0)
  204.            current = max;
  205.          else
  206.            current--;
  207.          high(1+col0,current+row0,high_attr,tag_high,tag_indx,item[current]);
  208.          break;
  209.        case DN:
  210.          norm(1+col0,current+row0,norm_attr,tag_norm,tag_indx,item[current]);
  211.          if (current == max)
  212.            current = 0;
  213.          else
  214.            current++;
  215.          high(1+col0,current+row0,high_attr,tag_high,tag_indx,item[current]);
  216.          break;
  217.         case 13:                   /* make selection when Enter key pressed */
  218.           return current;
  219.         default:      /* if letter command, change highlight and select */
  220.           for (i=0; i<=max; i++)
  221.             if (ltr[i] == c || ltr[i]-32 == c)
  222.               {
  223.                norm(1+col0,current+row0,norm_attr,tag_norm,tag_indx,item[current]);
  224.                current = i;
  225.                high(1+col0,current+row0,high_attr,tag_high,tag_indx,item[current]);
  226.                return current;
  227.               }
  228.         }
  229.      }
  230. }
  231.  
  232. /* -------------------------------------- */
  233. void
  234. norm(int col, int row, int attr, int tag_attr, int tag_indx, char *s)
  235. {
  236.   textattr(attr);
  237.   gotoxy(col,row);
  238.   cputs(s);
  239.   textattr(tag_attr);
  240.   gotoxy(col+tag_indx,row);
  241.   cprintf("%c",s[tag_indx]);
  242.   if (desc_flag) {
  243.     textattr(norm_attr);
  244.     window (1,1,80,25);
  245.     if (desc_flag == 1)
  246.       gotoxy(28,4+row);
  247.     else
  248.       gotoxy(28,7+row);
  249.     clreol();                       /* erase main_menu description */
  250.     if (desc_flag == 1)
  251.       window(8,5,21,12);
  252.     else
  253.       window(8,8,21,14);
  254.   }
  255. }
  256.  
  257. /* -------------------------------------- */
  258. void
  259. high(int col,int row, int attr, int tag_attr, int tag_indx, char *s)
  260. {
  261.   static char *description1[] = {  /* for main menu */
  262.          "  Enter scores ",
  263.          "  On screen display of current data ",
  264.          "  Printout of current results ",
  265.          "  Check and/or correct current data ",
  266.          "" };
  267.   char *description2[21] = {        /* for 'display()' menu */
  268.          "  Current entrants, hcps, scores",
  269.          "  Current standings",
  270.          "  Matches won/lost by specified player",
  271.          "  Match between two specified players"};
  272.   struct text_info text;
  273.   gettextinfo(&text);
  274.  
  275.   textattr(attr);
  276.   gotoxy(col,row);
  277.   cputs(s);
  278.   textattr(tag_attr);
  279.   gotoxy(col+tag_indx,row);
  280.   cprintf("%c",s[tag_indx]);
  281.   if (desc_flag) {
  282.     window (1,1,80,25);
  283.     textattr(norm_attr);
  284.     if (desc_flag == 1) {
  285.       gotoxy(28,4+row);
  286.       cputs(description1[row-2]);      /* 'current' = row - 2 */
  287.       window(8,5,21,12);
  288.     }
  289.     else {
  290.       gotoxy(28,7+row);
  291.       cputs(description2[row-2]);
  292.       window(8,8,21,14);
  293.     }
  294.   }
  295. }
  296. /* ------------------------- main_menu functions ------------------------- */
  297. void
  298. enter()
  299. {
  300.   int flight;
  301.  
  302.   if (numflights == 0)
  303.     error_msg("No data",9,9);
  304.   else
  305.     score_entry();
  306.   main_menu(0);
  307. }
  308.  
  309. void
  310. display()
  311. {
  312.   int scol=8,srow=8,ecol=21,erow=13;
  313.   int norm_attr1=WHITE+16*BROWN;
  314.   int high_attr1=WHITE+16*BLACK;
  315.   int tag_attr1=YELLOW+16*BROWN;
  316.   int tag_high1=YELLOW+16*BLACK;
  317.   char *item[] = {" Entries  ",
  318.                   " Standings",
  319.                   " Matches  ",
  320.                   " Two X Two"};
  321.   int numitems = 4, tag_indx = 1;
  322.   static int current = 0;
  323.   int selection;
  324.   int ltr[] = {'e','s','m','t'};
  325.  
  326.   if (mono) {
  327.     norm_attr1 = tag_attr1 = norm_attr;
  328.     high_attr1 = tag_high1 = high_attr;
  329.   }
  330.   desc_flag = 2;
  331.   selection = menu_select(scol,srow,ecol,erow,1,"",norm_attr1,high_attr1,
  332.            tag_attr1,tag_high1,tag_indx,numitems-1,current,2,2,ltr,item);
  333.   desc_flag = 0;
  334.   if (selection == 27)
  335.     main_menu(1);
  336.   current = selection;
  337.   switch(selection) {
  338.     case 0:
  339.       call_list_data();
  340.       break;
  341.     case 1:
  342.       call_list_results();
  343.       break;
  344.     case 2:
  345.       list_matches();
  346.       break;
  347.     case 3:
  348.       compare_two();
  349.       break;
  350.   }
  351.   main_menu(1);
  352. }
  353.  
  354. /*---------------------------------------------------------------------------*/
  355. void
  356. print()
  357. {
  358.   int scol=8,srow=9,ecol=20,erow=13;
  359.   int norm_attr1=WHITE+16*BROWN;
  360.   int high_attr1=WHITE+16*BLACK;
  361.   int tag_attr1=YELLOW+16*BROWN;
  362.   int tag_high1=YELLOW+16*BLACK;
  363.   char *item[] = {" Standings",
  364.                   " Matches  "};
  365.   int numitems = 2, tag_indx = 1, current = 0;
  366.   int selection;
  367.   int ltr[] = {'s','m'};
  368.   int printer_status;
  369.  
  370.   if (mono) {
  371.     norm_attr1 = tag_attr1 = norm_attr;
  372.     high_attr1 = tag_high1 = high_attr;
  373.   }
  374.   selection = menu_select(scol,srow,ecol,erow,1,"",norm_attr1,high_attr1,
  375.               tag_attr1,tag_high1,tag_indx,numitems-1,current,2,2,ltr,item);
  376.  
  377.   if (selection == 27)
  378.     main_menu(2);               /* Esc pressed */
  379.  
  380.   if (biosprint(2,0,0) & 8) {
  381.     error_msg("Printer not ready",scol,erow+1);
  382.     main_menu(2);
  383.   }
  384.  
  385.   switch(selection) {
  386.     case 0:
  387.       call_print_results();
  388.       break;
  389.     case 1:
  390.       call_print_matches();
  391.       break;
  392.     }
  393. }
  394.  
  395. /*---------------------------------------------------------------------------*/
  396. void
  397. check(void)
  398. {
  399.   int i,k,m,flight;
  400.   char pname[21], h[3], s[10], scores[25];
  401.   FILE *fp;
  402.   int norm_attr1=norm_attr;  /* WHITE+16*BROWN; */
  403.   int flt[10],index[10];
  404.   int left1=40,top1=3,right1=62,bottom1=4;
  405.   char *msg[] = {
  406.          "       CHECK        ",
  407.          "",
  408.          "Enter names, correct",
  409.          "data as necessary.  ",
  410.          "",
  411.          "To return to menu,  ",
  412.          "   press Esc or     ",
  413.          "enter a blank name. "};
  414.   int num_msgs = 8;
  415.  
  416.   if (mono) norm_attr1 = norm_attr;
  417.  
  418.   window(2,2,26,24);
  419.   textattr(high_attr);
  420.   clrscr();
  421.   for (i=0; i<num_msgs; i++) {
  422.     gotoxy(3,i+4);
  423.     cputs(msg[i]);
  424.   }
  425.   while(1) {
  426.     window(left,top,right,bottom);
  427.     textattr(norm_attr);
  428.     clrscr();
  429.     window(1,1,80,25);
  430.     rect(left1-1,top1-1,right1+1,bottom1+1,norm_attr1,1);
  431.     window(left1,top1,right1,bottom1);
  432.     clrscr();
  433.     gotoxy(2,1);
  434.     cprintf("Enter name:");
  435.     gotoxy(2,2);
  436.     showcursor();
  437.     i = get_string("",pname,"",2,2);
  438.     if (!i)
  439.       break;
  440.     m = findn(pname,flt,index);
  441.     if (m == -2) {
  442.       error_msg("More than ten",left1+2,top1+3);
  443.       continue;
  444.     }
  445.     if (m == -1) {
  446.       error_msg("Not found",left1+2,top1+3);
  447.       continue;
  448.     }
  449.     if (m > 0)
  450.       m = pick_one(bottom1+2, m, flt, index);
  451.     if (m == -1 || m == 27)
  452.       continue;
  453.     flight = flt[m];
  454.     correct(flt[m], index[m]);
  455.   }
  456.  
  457.   i = 0;   /* used as flag */
  458.   for (flight=0; flight<numflights; flight++)
  459.     if (recalc[flight]) {
  460.              /* if any changes were made, recalculate and store data */
  461.       i = 1;
  462.       calc_results(flight);
  463.       recalc[flight] = 0;
  464.     }
  465.     if (i) {
  466.       fp = fopen(datafile,"w");
  467.       write_data(fp);
  468.       fclose(fp);
  469.     }
  470.   main_menu(1);           /* assume 'display' next */
  471. }
  472.  
  473. /* -------------------Calls to MP functions ------------------------------ */
  474.  
  475. void
  476. call_list_data()
  477. {
  478.   int flight = 0;
  479.   if (NP[flight] == 0)
  480.     error_msg("No Data Entered",7+1,7+5);
  481.   else {
  482.     chk(flight);
  483.   }
  484.   main_menu(1);
  485. }
  486.  
  487. /*---------------------------------------------------------------------------*/
  488. void
  489. call_list_results()
  490. {
  491.   int flight=0,type;
  492.  
  493.   type = get_type();
  494.   if (type == 0)
  495.     list_results(flight);
  496.   else if (type == 1)
  497.     list_points(flight);
  498.   else if (type == 2)
  499.     list_gross(flight);
  500.   else if (type == 3)
  501.     list_net(flight);
  502.   main_menu(1);
  503. }
  504.  
  505. /*---------------------------------------------------------------------------*/
  506. void
  507. call_print_results()
  508. {
  509.   int flight,type;
  510.  
  511.   if (numflights > 1)
  512.     flight = get_flight(11);
  513.   else flight = 0;
  514.   if (NP[flight] == 0) {
  515.     error_msg("Empty flight",7+2,7+12);
  516.     main_menu(2);
  517.   }
  518.   type = get_type();
  519.   if (type == 0)
  520.     print_results(flight);
  521.   else if (type == 1)
  522.     print_points(flight);
  523.   else if (type == 2)
  524.     print_gross(flight);
  525.   else if (type == 3)
  526.     print_net(flight);
  527.   main_menu(2);
  528. }
  529.  
  530. /*---------------------------------------------------------------------------*/
  531. void
  532. call_print_matches()
  533. {
  534.   int flight;
  535.  
  536.   if (numflights > 1)
  537.     flight = get_flight(12);
  538.   else flight = 0;
  539.   if (NP[flight] == 0)
  540.     error_msg("Empty flight",7+2,7+13);
  541.   else
  542.     print_matches(flight);
  543.   main_menu(2);
  544. }
  545.  
  546.  
  547. /* ----------------------------- */
  548. int
  549. get_flight(int row)
  550. {
  551.   char s[3], mask[] = {176,'\0'};
  552.   int r, ret_val;
  553.   struct text_info text;
  554.  
  555.   gettextinfo(&text);
  556.   window(9,row,19,row);
  557.   textattr(BLACK+16*LIGHTGRAY);
  558.   clrscr();
  559.   r = get_string("Flight",s,mask,10,1);
  560.   if (!r)
  561.     ret_val = 0;
  562.   else
  563.     ret_val = atoi(s);
  564.   window(text.winleft, text.wintop, text.winright, text.winbottom);
  565.   textattr(text.attribute);
  566.   return ret_val;
  567. }
  568.  
  569. /* ----------------------------- */
  570. int
  571. get_type()
  572. {
  573.   char *item[] = {" Match Play   ",
  574.                   " Point System ",
  575.                   " Gross Scores ",
  576.                   " Net Scores    " };
  577.   int numitems = 4, tag_indx = 1, current = 0;
  578.   int selection;
  579.   int ltr[] = {'m','p','g','n'};
  580.   int tag_attr1=YELLOW+16*BLUE;
  581.   int norm_attr1 = WHITE+16*BLUE;
  582.   int high_attr1 = BLUE+16*LIGHTGRAY;
  583.   int tag_high1 = YELLOW+16*LIGHTGRAY;
  584.   struct text_info text;
  585.  
  586.   gettextinfo(&text);
  587.   if (mono) {
  588.     norm_attr1 = tag_attr1 = norm_attr;
  589.     high_attr1 = tag_high1 = high_attr;
  590.   }
  591.   textattr(norm_attr1);
  592.   selection = menu_select(8,11,24,16,1,"",norm_attr1,high_attr1,tag_attr1,
  593.                 tag_high1,tag_indx,numitems-1,current,1,2,ltr,item);
  594.   if (selection == 27)
  595.     main_menu(1);
  596.   window(text.winleft, text.wintop, text.winright, text.winbottom);
  597.   return selection;
  598. }
  599.  
  600. /* ----------------------------- */
  601. int
  602. get_filename(int row, char *filename)
  603. {
  604.   char filemask[] = {176,176,176,176,176,176,176,176,176,176,176,176,176,0};
  605.   int r;
  606.   char s[13];
  607.  
  608.   textattr(norm_attr);
  609.   window(7,row,24,row+4);
  610.   clrscr();
  611.   rect(8,row,24,row+4,norm_attr,1);
  612.   gotoxy(2,2);
  613.   if (strcmp(filename,"entrants") == 0)
  614.     cputs("Entry File:");
  615.   else
  616.     cputs("Data file:");
  617.   r = get_string("",s,filemask,2,3);
  618.   if (r)
  619.     strcpy(filename,s);
  620.   return r;
  621. }
  622.  
  623. /* ------------------------- choose player from list ------------------ */
  624. /* m = number of choices <= 10; arrays flt[], index[] must be filled to m-1 */
  625. int
  626. pick_one(int row, int m, int flt[], int index[])
  627. {
  628.   struct text_info text;
  629.   char *buf;
  630.   char *full_name[10] = {"                      ",
  631.                          "                      ",
  632.                          "                      ",
  633.                          "                      ",
  634.                          "                      ",
  635.                          "                      ",
  636.                          "                      ",
  637.                          "                      ",
  638.                          "                      ",
  639.                          "                      " };
  640.   int i,k;
  641.   int ltr[] = {0,0,0,0,0,0,0,0,0,0};
  642.   extern int high_attr, norm_attr;
  643.  
  644.   buf = (char *)malloc(2*(m+2)*22);
  645.   if (buf == NULL) {
  646.     error_msg("Not enough memory",30,5);
  647.     return -1;
  648.   }
  649.  
  650.   gettextinfo(&text);
  651.   for (i=0; i<=m; i++)
  652.     strcpy(full_name[i],player[flt[i]][index[i]].name);
  653.   window(1,1,80,25);
  654.   gettext(30,row,52,row+m+2,buf);
  655.   k = menu_select(30,row,52,row+m+2,             /* left,top,right,bottom */
  656.                   1,                             /* single border */
  657.                   " Pick One ",                  /* title */
  658.                   high_attr,norm_attr,           /* norm,high */
  659.                   high_attr,norm_attr,           /* tag,tag high */
  660.                   1,                             /* no tag */
  661.                   m,                             /* number of items */
  662.                   0,2,2,                  /* current, start col, start row */
  663.                   ltr,                           /* letters to select */
  664.                   full_name);                    /* items to select */
  665.   puttext(30,row,52,row+m+2,buf);
  666.   free(buf);
  667.   window(text.winleft,text.wintop,text.winright,text.winbottom);
  668.   textattr(text.attribute);
  669.   return k;
  670. }
  671.  
  672. /*---------------------------------------------------------------------------*/
  673. /* rectangle drawing routine for borders */
  674. /* box characters */
  675. int tlc[3]={0,218,201};
  676. int trc[3]={0,191,187};
  677. int blc[3]={0,192,200};
  678. int brc[3]={0,217,188};  /* single,double corners */
  679. int hl[3]={0,196,205};
  680. int vl[3]={0,179,186};   /* single,double horizontal, vertical lines */
  681.  
  682. void
  683. rect(int left, int top, int right, int bottom, int attr, int border)
  684. {
  685.   int i;
  686.   int width, height;
  687.  
  688.   width = right-left;
  689.   height = bottom-top;
  690.  
  691.   window(left,top,right,bottom);
  692.   gotoxy(1,1);
  693.   putch(tlc[border]);
  694.   for (i=1; i<width; i++)
  695.     putch(hl[border]);
  696.   putch(trc[border]);
  697.   for (i=0; i<height-1; i++) {
  698.     gotoxy(1,2+i);
  699.     putch(vl[border]);
  700.     gotoxy(1+width,2+i);
  701.     putch(vl[border]);
  702.   }
  703.   gotoxy(1,height+1);
  704.   putch(blc[border]);
  705.   for (i=1; i<width; i++)
  706.     putch(hl[border]);
  707.   _AH = 9;
  708.   _AL = brc[border];
  709.   _BH = 0;
  710.   _BL = attr;
  711.   _CX = 1;
  712.   geninterrupt(0x10);
  713.   window(left,top,right,bottom);
  714. }
  715.  
  716. /*---------------------------------------------------------------------------*/
  717. initialize()
  718. {
  719.   FILE *fp;
  720.   char filename[32], s[80];
  721.   char *opening[] = {
  722.              "              MATCHPLAY                     ",
  723.              "                                            ",
  724.              "        Golf Tournament Organizer           ",
  725.              "                                            ",
  726.              " A program for scoring a tournament in      ",
  727.              " which each player competes at match play   ",
  728.              " with with each other player in his flight. ",
  729.              "                                            ",
  730.              "               B. J. Ball                   ",
  731.              "           3304 Glen Rose Drive             ",
  732.              "             Austin, TX 78731               ",
  733.              NULL
  734.   };
  735.  
  736.   char *description[] = {
  737.     " This program will score a golf tournament under several formats.  ",
  738.     " Gross and Net scores are always calculated, as are the 'points'   ",
  739.     " obtained under the point system described in the documentation.   ",
  740.     " The unusual feature, however, is that the tournament may be scored",
  741.     " in match play format, with each player playing at match play with ",
  742.     " each other player in his flight, receiving one match play point   ",
  743.     " for each match won and one-half point for each match halved. In   ",
  744.     " each match, strokes are awarded the weaker player, with these     ",
  745.     " strokes taken on the on the appropriate holes, based on handicap. ",
  746.     NULL
  747.   };
  748.  
  749.   char *description1[] = {
  750.     " The program requires an entry list file, in the format described  ",
  751.     " in the documentation. This file may be created with any standard  ",
  752.     " word processor. As scores are entered, they will be stored in a   ",
  753.     " 'results' file; if the program should be interrupted for any      ",
  754.     " reason, it may be restarted by loading this file, rather than the ",
  755.     " entry list file. You will be asked for the name for this file at  ",
  756.     " the start of the program. If there is an existing file with the   ",
  757.     " same name, it will be overwritten with the new results file.      ",
  758.     NULL
  759.   };
  760.  
  761.   int left = 17, top = 3, right = 62, bottom = 15;
  762.   int left1= 6,  top1= 3, right1= 74, bottom1= 13;
  763.  
  764. /* opening display */
  765.   textattr(7);
  766.   clrscr();
  767.   establish_window(left,top,right,bottom,15,1,0);
  768.   text_window(opening,1);
  769.   window(1,1,80,25);
  770.   textattr(7);
  771.   gotoxy(left,25);
  772.   cputs("Press any key ...");
  773.   getch();
  774.   delete_window();
  775.   clrscr();
  776.   establish_window(left1,top1,right1,bottom1,15,1,0);
  777.   window_title(" MTCHPLAY ");
  778.   text_window(description,1);
  779.   window(1,1,80,25);
  780.   textattr(7);
  781.   gotoxy(left1,25);
  782.   cputs("Press any key ...");
  783.   getch();
  784.   textattr(31);
  785.   clear_window();
  786.   window_title(" MTCHPLAY ");
  787.   text_window(description1,1);
  788.   window(1,1,80,25);
  789.   textattr(7);
  790.   gotoxy(left1,25);
  791.   cputs("Press any key ...");
  792.     getch();
  793.   delete_window();
  794.   gotoxy(left1,25);
  795.   cputs("                  ");
  796.   get_start_data();
  797.   if (!numflights) {
  798.     gotoxy(19,19);
  799.     cprintf("Error in input file");
  800.     getch();
  801.     normal_exit(1);
  802.   }
  803. }
  804.  
  805. get_start_data()
  806. {
  807.   int c, olddata;
  808.   FILE *fp;
  809.  
  810.   textattr(31);
  811.   establish_window(16,15,60,21,8,3,0);
  812.   delete_window();
  813.   window(1,1,80,25);
  814.   textattr(16*3+8);
  815.   gotoxy(17,16);
  816.   showcursor();
  817.   cputs("Reload previous data (Y/N)? : ");
  818.   if (toupper(getche()) == 'Y')
  819.     olddata=1;
  820.   else olddata = 0;
  821. a:
  822.   get_string("Name of input file",input_file,filefield,37,17);
  823.   if (!input_file[0]) normal_exit(1);
  824.   if ((fp = fopen(input_file,"r")) == NULL) {
  825.     gotoxy(17,18);
  826.     cputs("File not found; please reenter ");
  827.     getch();
  828.     gotoxy(17,18); cputs("                               ");
  829.     gotoxy(17,17); cputs("                  ");
  830.     goto a;
  831.   }
  832.   gotoxy(17,18);
  833.   get_string("Name of output file",datafile,filefield,38,18);
  834.   if (!datafile[0]) normal_exit(1);
  835.   numflights = 0;
  836.   if (olddata)
  837.     get_old_data(fp);
  838.   else
  839.     get_entrants(fp);
  840.   fclose(fp);
  841.   if (numflights == 0) {
  842.     gotoxy(17,19);
  843.     cputs("Error in input file");
  844.     getch();
  845.     normal_exit(1);
  846.   }
  847. }
  848.  
  849. /*---------------------------------------------------------------------------*/
  850. /* input old (possibly incomplete) tournament data from file */
  851. get_old_data(FILE *fp)
  852. {
  853.    int i,k,n,blank=0;
  854.    char s[81];
  855.    int np=0,flight=0;
  856.    extern par[], order[];
  857.  
  858.    for (k=0; k<MAXFL; k++) 
  859.      NP[k]= 0;
  860.    numflights = 0;
  861.  
  862.    /* 1st non-blank line should be the title, if any, or else the par values */
  863.    while (getline(fp,s) == blank)
  864.      ;
  865.    for (i=0; i<strlen(s); i++)
  866.      if (s[i] != ' ') break;
  867.    if (isalpha(s[i]))
  868.      strcpy (data_title,s);
  869.    else
  870.      data_title[0] = '\0';
  871.    if (isdigit(s[0])) goto b;
  872.  
  873.    /* next non-blank line should give the par values of the holes */
  874.    while (getline(fp,s) == blank)
  875.      ;
  876. b:
  877.    if (Getint(18,s,par) != 18) {
  878.      gotoxy(17,19);
  879.      cprintf("Error in input file, '%s' ",input_file);
  880.      getch();
  881.      normal_exit(1);
  882.    }
  883.  
  884.    /* next non_blank line should give course handicap values of the holes */
  885.    while (getline(fp,s) == blank)
  886.      ;
  887.    if (Getint(18,s,order) != 18) {
  888.      gotoxy(17,19);
  889.      cprintf("Error in input file,'%s'\n",input_file);
  890.      getch();
  891.      normal_exit(1);
  892.    }
  893.    /* the line immediately after the handicap values MUST be blank */
  894.    /* hereafter, blank lines are used only to separate flights */
  895.    if (getline(fp,s) != blank)  {
  896.      gotoxy(17,19);
  897.      cprintf("Error in input file,'%s'\n",input_file);
  898.      getch();
  899.      normal_exit(1);
  900.    }
  901.   /* start of data entry */
  902.   while (!feof(fp))
  903.   {
  904.     getline(fp,s);
  905.     if (s[0] == '\0') {            /* blank line */
  906.       if (np != 0) {
  907.         NP[flight++] = np;           /* end of flight */
  908.         np = 0;
  909.         continue;
  910.       }
  911.       else
  912.         goto a;
  913.     }
  914.       strcpy(player[flight][np].name,s);
  915.       getline(fp,s);
  916.       player[flight][np].hcp = atoi(s);
  917.       getline(fp,s);
  918.       if (isdigit(s[0]))
  919.         strcpy(player[flight][np++].scores,s);
  920.       else
  921.         player[flight][np++].scores[0] = 0;
  922.   }
  923. a:
  924.   numflights = flight;
  925.   for (flight=0; flight<numflights; flight++)
  926.     set_gnp(flight);                /* calculate gross, net, points */
  927.   calc_all();                       /* calculate match play info */
  928. }
  929.  
  930. /*---------------------------------------------------------------------------*/
  931. /* input entry list (names and handicaps only */
  932. get_entrants(FILE *fp)
  933. {
  934.    int i,k,n,blank=0;
  935.    char s[81];
  936.    int np=0,flight=0;
  937.    extern par[], order[];
  938.  
  939.    for (k=0; k<MAXFL; k++) NP[k]=0;        /* clear existing data */
  940.    numflights = 0;
  941.  
  942.    /* 1st non-blank line should be the title, if any, or else the par values */
  943.    while (getline(fp,s) == blank)
  944.      ;
  945.    for (i=0; i<strlen(s); i++)
  946.      if (s[i] != ' ') break;
  947.    if (isalpha(s[i]))
  948.      strcpy (data_title,s);
  949.    else
  950.      data_title[0] = '\0';
  951.    if (isdigit(s[0])) goto b;
  952.  
  953.    /* next non-blank line should give the par values of the holes */
  954.    while (getline(fp,s) == blank)
  955.      ;
  956. b:
  957.    if (Getint(18,s,par) != 18) {
  958.      gotoxy(17,19);
  959.      cprintf("Error in input file, '%s' ",input_file);
  960.      getch();
  961.      normal_exit(1);
  962.    }
  963.  
  964.    /* next non_blank line should give course handicap values of the holes */
  965.    while (getline(fp,s) == blank)
  966.      ;
  967.    if (Getint(18,s,order) != 18) {
  968.      gotoxy(17,19);
  969.      cprintf("Error in input file,'%s'\n",input_file);
  970.      getch();
  971.      normal_exit(1);
  972.    }
  973.    /* the line immediately after the handicap values MUST be blank */
  974.    /* hereafter, blank lines are used only to separate flights */
  975.    if (getline(fp,s) != blank) {
  976.      gotoxy(17,19);
  977.      cprintf("Error in input file,'%s'\n",input_file);
  978.      getch();
  979.      normal_exit(1);
  980.    }
  981.  
  982.   /* start of data entry */
  983.   while (!feof(fp))
  984.   {
  985.     getline(fp,s);
  986.     if (s[0] == '\0') {              /* blank line */
  987.       if (np != 0) {
  988.         NP[flight++] = np;           /* end of flight */
  989.         np = 0;
  990.         continue;
  991.       }
  992.       else
  993.         goto a;
  994.     }
  995.     if (isalpha(s[0])) {
  996.       strcpy(player[flight][np].name,s);
  997.       getline(fp,s);
  998.       player[flight][np].hcp = atoi(s);
  999.       np++;
  1000.     }
  1001.   }
  1002. a:
  1003.   numflights = flight;
  1004. }
  1005.  
  1006. /* ----------------------------------- */
  1007. enter_data(char *s, int flight, int j)
  1008. {
  1009.   char pname[81],h[81],*q,*p;
  1010.   int hcp;
  1011.  
  1012.   q = s;
  1013.   p = pname;
  1014.  
  1015.   while(isalpha(*q) || isspace(*q) || ispunct(*q))
  1016.     *p++ = *q++;
  1017.   *p = pname[20] = '\0';  /* end name after 19 chars or at end of input */
  1018.  
  1019.   while(*q && !isdigit(*q));
  1020.     q++;
  1021.   if (!isdigit(*(--q))) {
  1022.     cprintf("Each player must have a handicap ");
  1023.     getch();
  1024.     normal_exit(1);
  1025.   }
  1026.   p = h;
  1027.   while(*q)
  1028.     *p++ = *q++;
  1029.   *p = '\0';
  1030.  
  1031.   hcp = atoi(h);
  1032.   if (strchr(h,'T') || strchr(h,'t'))
  1033.     hcp = -hcp;
  1034.  
  1035.   strcpy(player[flight][j].name,pname);
  1036.   player[flight][j].hcp = hcp;
  1037. }
  1038.  
  1039. /*---------------------------------------------------------------------------*/
  1040. void normal_exit(int m)
  1041. {
  1042.   int c;
  1043.  
  1044.   window(1,1,80,25);
  1045.   if (m == 0) {
  1046.     c = error_msg("Quit program (Y/N)? ",30,3);
  1047.     if (toupper(c) != 'Y') {
  1048.       main_menu(0);
  1049.     }
  1050.   }
  1051.   textattr(old_attr);
  1052.   clrscr();
  1053.   showcursor();
  1054.   exit(0);
  1055. }
  1056.  
  1057.