home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / simtel / sigm / vols000 / vol094 / tinit.pas < prev    next >
Pascal/Delphi Source File  |  1984-04-29  |  5KB  |  269 lines

  1.  
  2. external terms::init(5);
  3.  
  4.  
  5. {COPYRIGHT 1982 (C) BY CRAIG RUDLIN, M.D.  ALL RIGHTS RESERVED}
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12. procedure make_file_name;
  13. {$R-}
  14. {$U-}
  15. {$M-}
  16. {$F-}
  17. {$C-}
  18.  
  19. {put term_file in proper CP/M format for a file name}
  20.  
  21. begin
  22. term_file[9]:='.';
  23. term_file[10]:='T';
  24. term_file[11]:='E';
  25. term_file[12]:='R';
  26.  
  27. {now assign value to num_file and put it in proper CP/M format}
  28. num_file:=term_file;
  29. num_file[10]:='N';
  30. num_file[11]:='U';
  31. num_file[12]:='M';
  32.  
  33. end;
  34.  
  35.  
  36.  
  37.  
  38. function xvalid:boolean; {internal function to see if file is a valid one}
  39. {$R-}
  40. {$U-}
  41. {$M-}
  42. {$F-}
  43. {$C-}
  44.  
  45. begin
  46. if (term_file = 'PROTOCOLS   ') OR (term_file = 'DIAGNOSES   ') OR
  47.    (term_file = 'TESTS       ') OR (term_file = 'ACCOUNTS    ') OR
  48.    (term_file = 'DRUGS       ') OR (term_file = 'PROCEDURES  ') OR
  49.    (term_file = 'MATERIALS   ')
  50.  
  51.  
  52.  
  53.    then xvalid:= true else xvalid:= false;
  54. end;
  55.  
  56.  
  57. procedure get_file(invalid:boolean); {internal procedure to get type of file}
  58. {$R-}
  59. {$U-}
  60. {$M-}
  61. {$F-}
  62. {$C-}
  63.  
  64.  
  65. var
  66. answer:data;
  67. dummy:byte;
  68.  
  69. begin
  70.             clear_screen;
  71.  
  72.             end_of_field:=false;
  73.             end_of_record:=false;
  74.             end_of_input:=false; 
  75.             answer:=blanks;
  76.  
  77.             if invalid then
  78.             writeln('YOU HAVE ENTERED AN INVALID FILE.')
  79.                 else
  80.             writeln('YOU DID NOT SPECIFY WHICH FILE TO USE.'); 
  81.  
  82.             writeln('PLEASE ENTER EITHER:');
  83.                   writeln('PROTOCOLS':35);
  84.             writeln('DIAGNOSES':35);
  85.             writeln('TESTS':35);
  86.             writeln('ACCOUNTS':35);
  87.             writeln('PROCEDURES':35);
  88.             writeln('DRUGS':35);
  89.             writeln('MATERIALS':35);
  90.             writeln;
  91.             write('---> ');
  92.             
  93.  
  94.             answer:=input(11,11,12,ucase,letters_only,answer);
  95.  
  96.  
  97.     for dummy:= 1 to 12 do term_file[dummy]:=answer[dummy];
  98.  
  99.             if xvalid = false then get_file(true);
  100.         {was a valid type of file answerif not get valid one}
  101.  
  102.  
  103.  
  104.             
  105. end; {of internal procedure get_file}
  106.  
  107.  
  108.  
  109.  
  110. procedure initialize;
  111. {$R-}
  112. {$U-}
  113. {$M-}
  114. {$F-}
  115. {$C-}
  116.  
  117.  
  118. {this procedure first reads the command line to determine which file of terms}
  119. {to use...this allows this single program to create files of diagnoses,tests,}
  120. {protocols, etc.  If the command line is blank, then the procedure asks the  }
  121. {user to enter the appropriate file.  Next, the procedure opens the files. If}
  122. {the file is not found, it is created.                        }
  123.  
  124. const
  125. clear = '            '; {12 spaces}
  126.  
  127. var
  128. counter,dummy:byte;
  129. job:array[1..12] of char;
  130.  
  131.  
  132.  
  133.  
  134. begin {**** of procedure initialize ****}
  135.  
  136. {read the command line.  If file is specified, then continue on to initialize}
  137. {otherwise, must determine which file to enter. Check to make sure it is a   }
  138. {valid type of file }
  139.  
  140.  
  141. for b:= 1 to 80 do blanks[b]:=' '; {establish this filler}
  142.  
  143.  
  144. job:= clear;      {initialize these variables to all spaces}
  145. term_file:=clear;
  146. num_file:= clear;
  147. counter:=1;
  148.  
  149. if eoln(0) then get_file(false) else
  150.         begin
  151.             readln(command_line);
  152.  
  153.      
  154.  
  155.         {was a valid type of file entered? if not get valid one}
  156.  
  157.  
  158.         while (command_line[counter] <> ' ') and (counter < 10) do
  159.             begin
  160.             term_file[counter]:=command_line[counter];
  161.             counter:=counter + 1;
  162.             end;
  163.  
  164.         if xvalid = false THEN  get_file(true);
  165.         end;
  166.  
  167.  
  168. clear_screen;
  169. writeln('ONE MOMENT PLEASE.');
  170. writeln;
  171.  
  172. make_file_name;
  173.  
  174. dummy:=1; {counter for job's array} 
  175. counter:=counter + 1; {skip the comma in the command line, that separates}
  176.             {the file from the menu selection}
  177.  
  178.  
  179. {don't read more characters than in the array for job, ie 12}
  180.  
  181. while (dummy < 13) and (command_line[counter] <> ' ') do
  182.     begin
  183.     job[dummy]:=command_line[counter];
  184.     counter:=counter + 1;
  185.     dummy:=dummy + 1;
  186.     end;
  187.  
  188.  
  189.  
  190.  
  191. {open necessary files} 
  192.  
  193. reset(term_file,fterms);
  194. if eof(fterms) then  {create the file}
  195.     begin
  196.  
  197.     with terms do
  198.     begin
  199.  
  200.     term:='MASTER               ';
  201.     print_flag:=false;
  202.     code:=2.0;
  203.     parent:=0;
  204.     left:=0;
  205.     right:=0;
  206.  
  207.  
  208.     rewrite(term_file,fterms);
  209.     write(fterms:1,terms);
  210.  
  211.     rewrite(num_file,fnumterms);
  212.     write(fnumterms:1,terms);
  213.  
  214.     end;{of with terms}
  215.  
  216.     numrecs:=2;
  217.  
  218.     {CP/M does not write the directory listing of a newly created file}
  219.     {until it is closed. Pascal has no provision for explicitly closing}
  220.     {a file. Until the file is closed, and the dir listing is written, }
  221.     {CP/M will not permit the program to read the file...Hence it is   }
  222.     {imperative to force the CP/M to create the directory listing.  This}
  223.     {is done by "reset" the file.                      }
  224.  
  225.     reset(term_file,fterms);
  226.     reset(num_file,fnumterms);
  227.  
  228.     end {of if eof}
  229.  
  230. ELSE
  231.     BEGIN
  232.     {determine number of records in term file}
  233.     read(fterms:1,terms);
  234.     numrecs:= round(terms.code);
  235.  
  236.  
  237.     reset(num_file,fnumterms);
  238.     if eof(fnumterms) then
  239.         begin
  240.         writeln('FILE OF ',command_line:10,' CODES NOT ON DISK!');
  241.         terminate:=true;
  242.         end
  243.     END;
  244.  
  245. {if job is a valid menu selection, then go directly to that procedure and }
  246. {skip the menu at this point}
  247.  
  248.  
  249. if terminate = false then
  250. begin
  251.  
  252. clear_screen;
  253.  
  254. if ((term_file = 'TESTS   .TER') or (term_file = 'MATERIAL.TER')) then
  255.     needs_units:=true else needs_units:=false;
  256.  
  257. if job = 'ADD         ' then add(false,false) else
  258. if job = 'DELETE      ' then delete(false,false) else
  259. if job = 'FIND        ' then find(false,0)  else
  260. if job = 'CHANGE      ' then change else
  261. if job = 'DISPLAY     ' then print_terms(false) else
  262. if job = 'PRINT       ' then print_terms(true);  
  263.  
  264. end;
  265.  
  266.  
  267. end; {of procedure}
  268. . {of separate compilation}
  269.