home *** CD-ROM | disk | FTP | other *** search
/ Sunny 1,000 Collection / SUNNY1000.iso / Files / Dos / Sport / GOLF43.ZIP / G_FILE.PAS < prev    next >
Pascal/Delphi Source File  |  1994-07-15  |  6KB  |  229 lines

  1. Program g_file;
  2.  
  3. {This program is intended to read a "random" golf file, and write a text file
  4. of the same name, with the .txt suffix, OR read the .txt file and write the
  5. corresponding "random" file.  This will allow me to use text editors on the
  6. converted file, thus effectively edit the "random" file}
  7.  
  8. uses dos,crt;
  9.  
  10. {$I convspec}
  11.  
  12. var
  13.     game      : game_type;
  14.     P1,P2     : Pathstr;
  15.     D         : Dirstr;
  16.     N         : Namestr;
  17.     E         : Extstr;
  18.     Tfile     : text;
  19.     ans       : char;
  20.     Golfr_id  : char;
  21.     space     : char;
  22.     count     : byte;
  23.     tname     : string;
  24.     index     : shortint;
  25.     filsiz    : shortint;
  26.     courses   : course_file_type;
  27.     club      : course_type;
  28.     golfers   : golfer_file_type;
  29.     golfer    : golfer_type;
  30.     game_file : game_file_type;
  31.     hole      : byte;
  32.   const
  33.     string20  : string[20] = '                    ';
  34.     string32  : string[32] = '                                ';
  35. begin
  36.     clrscr;
  37.     writeln('1 - courses to courses.txt');
  38.     writeln('2 - courses.txt to courses');
  39.     writeln('3 - Golfers to Golfers.txt');
  40.     writeln('4 - Golfers.txt to Golfers');
  41.     writeln('5 - game to game.txt');
  42.     writeln('6 - game.txt to game');
  43.     writeln('0 or escape - quit');
  44.     readln(ans);
  45.     Repeat
  46.     case ans of
  47.     '0',#27,'n','N' : exit;
  48.  
  49.     '1':
  50.       begin
  51.       assign (courses, 'courses');
  52.       assign (Tfile, 'courses.txt');
  53. {$I-}
  54.       reset (courses);
  55.       If IOResult <> 0 then
  56.         begin
  57.           writeln('No Courses file exists');
  58.           exit;
  59.         end;
  60. {$I-}
  61.       rewrite(Tfile);
  62.       filsiz := filesize(courses);
  63.       with club do
  64.         begin
  65.         repeat
  66.           read(courses,club);
  67.           write(Tfile, id:3,' ',rated_par:4:1,slope:4);
  68.  
  69.           for hole := 1 to 18 do
  70.           write(Tfile,card_par[hole]:2);
  71.           writeln(Tfile,' ',name);
  72.         until eof(courses);
  73.         end;
  74.       close(Tfile);
  75.       close(courses);
  76.       end; {end 1:}
  77.  
  78.     '2':
  79.       begin
  80.       assign (courses, 'courses');
  81.       assign (Tfile, 'courses.txt');
  82. {$I-}
  83.       reset (Tfile);
  84.       If IOResult <> 0 then
  85.         begin
  86.           writeln('No Courses.txt file exists');
  87.           exit;
  88.         end;
  89. {$I-}
  90.       rewrite(courses);
  91.       with club do
  92.         repeat
  93.           name := string32;
  94.           read(Tfile,id,rated_par,slope);
  95.           for hole := 1 to 18 do
  96.             read(Tfile,card_par[hole]);
  97.           readln(Tfile,space,name);
  98.           write(courses,club);
  99.         until eof(Tfile);
  100.       close(Tfile);
  101.       close(courses);
  102.       end; {end 2:}
  103.  
  104.     '3':
  105.       begin
  106.       assign (Golfers,'Golfers');
  107.       assign (Tfile,'Golfers' + '.txt');
  108. {$I-}
  109.       reset (Golfers);
  110.       If IOResult <> 0 then
  111.         begin
  112.           writeln('No Golfers file exists');
  113.           exit;
  114.         end;
  115. {$I-}
  116.       rewrite(Tfile);
  117.       with Golfer do
  118.       repeat
  119.         read(Golfers,Golfer);
  120.         write(Tfile,id:3,no_of_games:5,hcp:6:2);
  121.         for count := 1 to 20 do
  122.           write(Tfile,last_20[count]:5:1);
  123.         writeln(Tfile,' ',name);
  124.       until eof(Golfers);
  125.       close (Tfile);
  126.       close (Golfers);
  127.       end; {end 3:}
  128.  
  129.     '4':
  130.       begin
  131.       assign (Golfers,'Golfers');
  132.       assign (Tfile,'Golfers' + '.txt');
  133. {$I-}
  134.       reset (Tfile);
  135.       If IOResult <> 0 then
  136.         begin
  137.           writeln('No Golfers.txt file exists');
  138.           exit;
  139.         end;
  140. {$I-}
  141.       rewrite(Golfers);
  142.       with Golfer do
  143.       repeat
  144.         name := string20;
  145.         read(Tfile,id,no_of_games,hcp);
  146.         for count := 0 to 19 do
  147.           read(Tfile,last_20[count]);
  148.         readln(Tfile,space,name);
  149.         write(Golfers,Golfer);
  150.       until eof(Tfile);
  151.       close (Tfile);
  152.       close (Golfers);
  153.       end;  {end 4:}
  154.  
  155.     '5':
  156.       repeat
  157.         writeln('Golfer # ');
  158.         readln(Golfr_id);
  159.         assign(Tfile,'Golfr' + Golfr_id + '.txt');
  160.         assign(game_file,'Golfr' + Golfr_id);
  161. {$I-}
  162.         reset(game_file);
  163.         if ioresult <> 0 then
  164.           begin
  165.             writeln('No Golfr' + Golfr_id,' game file exists.');
  166.             Golfr_id := #27;
  167.           end
  168.         else
  169. {$I+}
  170.         begin
  171.           rewrite(TFile);
  172.           repeat
  173.             read(game_file,game);
  174.             with game do
  175.             write(Tfile,game_no:3,hcp:3,course_id:4,month:3,day:3,year:3);
  176.             for count := 1 to 18 do
  177.               write(Tfile,' ',game.score[count]:3);
  178.             writeln(Tfile);
  179.           until eof(game_file);
  180.           close(Tfile);
  181.           close(game_file);
  182.           writeln('Another Golfer''s game file?');
  183.           readln(Golfr_id);
  184.         end;
  185.       until Golfr_id in [#27,'N','n']; {5:}
  186.  
  187.     '6':
  188.       repeat
  189.         writeln('Golfer # ');
  190.         readln(Golfr_id);
  191.         assign(game_file,'Golfr' + Golfr_id);
  192.         assign(Tfile,'Golfr' + Golfr_id + '.txt');
  193. {$I-}
  194.         reset(TFile);
  195.         if ioresult <> 0 then
  196.           begin
  197.             Writeln('No Golfr' + Golfr_id +'.txt file exists');
  198.             Golfr_id := #27;
  199.           end
  200.         else
  201. {$I+}
  202.           begin
  203.             rewrite(game_file);
  204.             with game do
  205.             repeat
  206.               read(Tfile,game_no,hcp,course_id,month,day,year);
  207.               for count := 1 to 18 do
  208.                 read(Tfile,score[count]);
  209.               readln(Tfile);
  210.               write(game_file,game);
  211.             until eof(Tfile);
  212.             close(game_file);
  213.             close(Tfile);
  214.             writeln('Another Golfer''s game.txt file?');
  215.             readln(Golfr_id);
  216.           end;
  217.       until Golfr_id in [#27,'N','n']; {6:}
  218.  
  219.     end; {end case}
  220.     writeln('Next conversion?');
  221.     readln(ans);
  222.     until ans in ['0','N','n',#27];
  223. end.
  224.  
  225.  
  226.  
  227.  
  228.  
  229.