home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / simtel / sigm / vols000 / vol022 / fclose.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1984-04-29  |  3.4 KB  |  115 lines

  1. (******************************************************
  2. ** PROGRAM TITLE:    FILE_CLOSE_DEMONSTRATION
  3. **
  4. ** WRITTEN BY:        Raymond E. Penley
  5. ** DATE WRITTEN:    22 JAN 1980
  6. **             Modified for Pascal/Z vers 3.0
  7. **            25 June 1980
  8. **
  9. ** SUMMARY:
  10. **    Demonstrate the three methods of closing files
  11. **    with Pascal.
  12. **
  13. **    1. Using a file variable in a block.
  14. **    2. Reusing a file variable with another file
  15. **       identifier (file name) to close the currently
  16. **       open file before opening the new file.
  17. **    3. Normal program termination will close ALL
  18. **       open files. (This is NOT the preferred method)
  19. **
  20. *******************************************************)
  21. PROGRAM FCLOSE;
  22. var
  23.   IX   : INTEGER;
  24.   wrk1 : TEXT;    { Global file descriptor <FCB> }
  25.  
  26. Procedure PAUSE;
  27. var    du: char;
  28. begin
  29.   write('Press return to continue');
  30.   readln(du);
  31. end;
  32.  
  33. Procedure CLEAR;
  34. var    ix: 1..25;
  35. begin
  36.   for ix:=1 to 25 do writeln;
  37. end;
  38.  
  39. PROCEDURE A;
  40. VAR    F1 : TEXT;
  41. BEGIN
  42.   CLEAR;
  43.   writeln('FILE CLOSE METHOD #1');
  44.   writeln;
  45.   writeln('USING A FILE VARIABLE LOCAL TO A "BLOCK"');
  46.   writeln('WILL CLOSE THE FILE(S) UPON EXIT OF THE BLOCK');
  47.   writeln('This is the preferred method!');
  48.   writeln;
  49.   writeln('     PROCEDURE A;');
  50.   writeln('     VAR   F1 : TEXT;');
  51.   writeln('     BEGIN');
  52.   writeln('       REWRITE(''CTESTA.$$$'',F1);');
  53.   writeln('       ... BODY OF PROCEDURE ...');
  54.   writeln('     END; { CLOSE(F1)  }');
  55.   writeln;
  56.   writeln('UPON EXITING THIS PROCEDURE WE WILL CLOSE');
  57.   writeln('THE FILE ''CTESTA.$$$'' AND FIX IT ON THE DIRECTORY');
  58.   REWRITE('CTESTA.$$$', F1);
  59.   writeln(F1, 'PROCEDURE A');
  60.   writeln;
  61.   PAUSE;
  62. END; { CLOSE(F1) }
  63.  
  64. Procedure B;
  65. begin
  66.   CLEAR;
  67.   REWRITE('CTESTQQ.$$$',WRK1);
  68.   writeln(WRK1,'CTESTQQ.$$$ THIS IS CURRENTLY OPEN FILE');
  69.   writeln('FILE CLOSE METHOD #2');
  70.   writeln;
  71.   writeln('Reusing the same file variable with a new file');
  72.   writeln('identifier <file name> will close the currently');
  73.   writeln('open file before opening the new file');
  74.   writeln;
  75.   writeln('   begin');
  76.   writeln('     REWRITE(''CTESTQQ.$$$'',WRK1);');
  77.   writeln('     writeln(WRK1,''THIS IS THE CURRENTLY OPEN FILE'');');
  78.   writeln('     writeln(''NOW TO CLOSE CTESTQQ.$$$ AND OPEN'');');
  79.   writeln('     writeln(''CTESTZZ.$$$'');');
  80.   writeln('     REWRITE(''CTESTZZ.$$$'',WRK1);');
  81.   writeln('     writeln(''CTESTZZ.$$$ IS NOW THE CURRENT FILE'');');
  82.   writeln('   end;');
  83.   writeln;
  84.   REWRITE('CTESTZZ.$$$',WRK1);
  85.   writeln(WRK1,'CTESTZZ.$$$ IS NOW THE CURRENT FILE');
  86.   writeln;
  87.   PAUSE;
  88. end;
  89.  
  90.  
  91. BEGIN
  92.   CLEAR;
  93.   writeln('FILE CLOSE DEMONSTRATION FOR PASCAL/Z');
  94.   writeln('by Raymond E. Penley');
  95.   FOR IX:=1 TO 12 DO writeln;
  96.   FOR IX:=1 TO 5000 DO {DUMMY} ;
  97.   A;    {--- Method #1 ---}
  98.   B;    {--- Method #2 ---}
  99.     {--- Method #3 ---}
  100.   CLEAR;
  101.   writeln('FILE CLOSE METHOD #3');
  102.   writeln;
  103.   writeln('This is really the simplist method.  Any files still');
  104.   writeln('open at program termination will be closed.  This is');
  105.   writeln('the most dangerous method in that a power failure or a');
  106.   writeln('disk failure while the program is running will leave');
  107.   writeln('your file nowhere.');
  108.   writeln('The file "CTESTZZ.$$$" is still open at this time.');
  109.   writeln('When this program terminates it will be fixed on the');
  110.   writeln('directory.');
  111.   writeln;
  112.   PAUSE;
  113.   writeln;writeln;writeln;writeln;
  114. End{of file close demo}{ CLOSE(wrk1) }.
  115.