home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / MADTRB3.ZIP / TEMPLATE.GEN < prev    next >
Encoding:
Text File  |  1985-10-17  |  6.7 KB  |  211 lines

  1. Program TemplateGenerator;
  2.  
  3.  
  4. Procedure TemplateGeneratorModule;
  5. { *************************************************************************** }
  6. { *                     Screen Template Generator Module                    * }
  7. { *                                                                         * }
  8. { *                         Written By Chris Maeder                         * }
  9. { *                                                                         * }
  10. { *  This module reads the record entries out of a file, places the entries * }
  11. { *  in an array, allows you to inspect the entries and change them if so   * }
  12. { *  desired, and then writes the record entries back to the file.  This    * }
  13. { *  procedure is used to edit screen templates.                            * }
  14. { *                                                                         * }
  15. { *************************************************************************** }
  16.  
  17. Const
  18.   RECORD_LIMIT=20;
  19.   FILE_NAME='CONFIG.PRN';
  20.  
  21. Type
  22.   FileRecord=
  23.     Record
  24.       PromptCol,PromptRow:Integer;
  25.       InputCol:Integer;
  26.       UpKeyPointer,DownKeyPointer:Integer;
  27.       LeftKeyPointer,RightKeyPointer:Integer;
  28.       OnCode1,OnCode2,OnCode3,OffCode1,OffCode2,OffCode3:Integer;
  29.       ToggleSwitch:Integer;
  30.       Prompt:String[50];
  31.     End;  { Record }
  32.  
  33. Var
  34.   Template:Array[1..RECORD_LIMIT] of FileRecord;
  35.   ConfigurationFile:File Of FileRecord;
  36.   I:Integer;
  37.   RecordOK:Char;
  38.  
  39.  
  40.  
  41.   Procedure InitializeTemplateEntries;
  42.  
  43.   { This procedure initializes the entries in the template array of records.  This is required
  44.     when generating a non-existant file since you cannot allow the program to read a file that
  45.     has not yet been generated (and thus you want to skip the procedure ReadFileEntries the first
  46.     time thru).  This procedure removes any garbage that might have been in the memory loacations
  47.     that the template array uses. }
  48.  
  49.   Var
  50.     I:Integer;
  51.  
  52.   Begin   { InitializeTemplateEntries }
  53.     For I:=1 To RECORD_LIMIT Do
  54.       With Template[I] Do
  55.         Begin
  56.           PromptCol:=0;
  57.           PromptRow:=0;
  58.           InputCol:=0;
  59.           UpKeyPointer:=0;
  60.           DownKeyPointer:=0;
  61.           LeftKeyPointer:=0;
  62.           RightKeyPointer:=0;
  63.           OnCode1:=0;
  64.           OnCode2:=0;
  65.           OnCode3:=0;
  66.           OffCode1:=0;
  67.           OffCode2:=0;
  68.           OffCode3:=0;
  69.           ToggleSwitch:=0;
  70.           Prompt:='';
  71.         End;  { With Template }
  72.   End;    { InitializeTemplateEntries }
  73.  
  74.  
  75.  
  76.   Procedure ReadFileEntries;
  77.  
  78.   { This procedure reads the entries out of the file named above and
  79.     stores the entries into the proper array record. }
  80.  
  81.   Var
  82.     I:Integer;
  83.  
  84.   Begin   { ReadFileEntries }
  85.     { $I- }
  86.     Assign(ConfigurationFile,FILE_NAME);                 { assign to a disk file }
  87.     Reset(ConfigurationFile);                            { open the file for reading }
  88.     For I:=1 to RECORD_LIMIT Do
  89.       Read(ConfigurationFile,Template[I]);               { read record off of disk }
  90.     Close(ConfigurationFile);
  91.     { $I+ }
  92.   End;    { ReadFileEntries }
  93.  
  94.  
  95.  
  96.   Procedure WriteFileEntries;
  97.  
  98.   { This procedure takes the entrys stored in the array records
  99.     and writes them to the file named above. }
  100.  
  101.   Var
  102.     I:Integer;
  103.  
  104.   Begin   { WriteFileEntries }
  105.     Assign(ConfigurationFile,FILE_NAME);                 { assign to a file on disk }
  106.     Rewrite(ConfigurationFile);                          { open the file for writing, removes any previous entries }
  107.     For I:=1 To RECORD_LIMIT Do
  108.       Write(ConfigurationFile,Template[I]);              { put the next record out }
  109.     Close(ConfigurationFile);
  110.   End;    { WriteFileEntries }
  111.  
  112.  
  113.  
  114.   Procedure ShowFileRecord;
  115.  
  116.   { This procedure shows the operator the entries in the Record[I] of the array }
  117.  
  118.   Begin   { ShowFileRecord }
  119.     With Template[I] Do
  120.       Begin
  121.         WriteLn('Record Number=    ',I);
  122.         WriteLn;
  123.         WriteLn('PromptCol=        ',PromptCol);
  124.         WriteLn('PromptRow=        ',PromptRow);
  125.         WriteLn('InputCol=         ',InputCol);
  126.         WriteLn('UpKeyPointer=     ',UpKeyPointer);
  127.         WriteLn('DownKeyPointer=   ',DownKeyPointer);
  128.         WriteLn('LeftKeyPointer=   ',LeftKeyPointer);
  129.         WriteLn('RightKeyPointer=  ',RightKeyPointer);
  130.         WriteLn('OnCode1=          ',OnCode1);
  131.         WriteLn('OnCode2=          ',OnCode2);
  132.         WriteLn('OnCode3=          ',OnCode3);
  133.         WriteLn('OffCode1=         ',OffCode1);
  134.         WriteLn('OffCode2=         ',OffCode2);
  135.         WriteLn('OffCode3=         ',OffCode3);
  136.         WriteLn('ToggleSwitch=     ',ToggleSwitch);
  137.         WriteLn('Prompt=           ',Prompt);
  138.       End;  { With Template }
  139.   End;    { ShowFileRecord }
  140.  
  141.  
  142.  
  143.   Procedure EnterFileRecord;
  144.  
  145.   { This procedure reads keyboard entries and places them into an array record. }
  146.  
  147.   Begin   { EnterFileRecord }
  148.     With Template[I] Do
  149.       Begin
  150.         WriteLn('Record Number=',I);
  151.         WriteLn;
  152.         Write('PromptCol=        ?');
  153.           ReadLn(PromptCol);
  154.         Write('PromptRow=        ?');
  155.           ReadLn(PromptRow);
  156.         Write('InputCol=         ?');
  157.           ReadLn(InputCol);
  158.         Write('UpKeyPointer=     ?');
  159.           ReadLn(UpKeyPointer);
  160.         Write('DownKeyPointer=   ?');
  161.           ReadLn(DownKeyPointer);
  162.         Write('LeftKeyPointer=   ?');
  163.           ReadLn(LeftKeyPointer);
  164.         Write('RightKeyPointer=  ?');
  165.           ReadLn(RightKeyPointer);
  166.         Write('OnCode1=          ?');
  167.           ReadLn(OnCode1);
  168.         Write('OnCode2=          ?');
  169.           ReadLn(OnCode2);
  170.         Write('OnCode3=          ?');
  171.           ReadLn(OnCode3);
  172.         Write('OffCode1=         ?');
  173.           ReadLn(OffCode1);
  174.         Write('OffCode2=         ?');
  175.           ReadLn(OffCode2);
  176.         Write('OffCode3=         ?');
  177.           ReadLn(OffCode3);
  178.         Write('ToggleSwitch=     ?');
  179.           ReadLn(ToggleSwitch);
  180.         Write('Prompt=           ?');
  181.           ReadLn(Prompt);
  182.       End;   { With Template }
  183.   End;    { EnterFileRecord }
  184.  
  185.  
  186.  
  187.  
  188. Begin     { TemplateGeneratorModule }
  189.   I:=1;
  190.   InitializeTemplateEntries;
  191.   ReadFileEntries;                     (* require { } the first time thru in generating non-existant file *)
  192.   Repeat
  193.     ClrScr;
  194.     ShowFileRecord;
  195.     WriteLn; Write('Are the above entries correct (Y or N) ?');
  196.     ReadLn(RecordOK);
  197.     If (RecordOK<>'Y') And (RecordOK<>'y') Then
  198.       Begin
  199.         ClrScr;
  200.         EnterFileRecord;
  201.       End { If RecordOK }
  202.     Else I:=I+1;
  203.   Until I=RECORD_LIMIT+1;
  204.   WriteFileEntries;
  205. End;      { TemplateGeneratorModule }
  206.  
  207.  
  208.  
  209. Begin     { Main program }
  210.   TemplateGeneratorModule;
  211. End.      { Main program }