home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast.iso / pcmag / vol9n21.zip / DGFILE.PAS < prev    next >
Pascal/Delphi Source File  |  1990-09-25  |  8KB  |  234 lines

  1. {
  2.  ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
  3.  █                                                                         █
  4.  █        TITLE :      DGFILE.TPU                                          █
  5.  █      PURPOSE :      File handling routines.                             █
  6.  █       AUTHOR :      David Gerrold, CompuServe ID:  70307,544            █
  7.  █  _____________________________________________________________________  █
  8.  █                                                                         █
  9.  █   Written in Turbo Pascal, Version 5.5,                                 █
  10.  █   with routines from TurboPower, Object Professional.                   █
  11.  █                                                                         █
  12.  █   Turbo Pascal is a product of Borland International.                   █
  13.  █   Object Professional is a product of TurboPower Software.              █
  14.  █  _____________________________________________________________________  █
  15.  █                                                                         █
  16.  █   This is not public domain software.                                   █
  17.  █   This software is copyright 1990, by David Gerrold.                    █
  18.  █   Permission is hereby granted for personal use.                        █
  19.  █                                                                         █
  20.  █        The Brass Cannon Corporation                                     █
  21.  █        9420 Reseda Blvd., #804                                          █
  22.  █        Northridge, CA  91324-2932.                                      █
  23.  █                                                                         █
  24.  ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
  25.                                                                             }
  26. { Compiler Directives ===================================================== }
  27.  
  28. {$A-}    {Switch word alignment off, necessary for cloning}
  29. {$R-}    {Range checking off}
  30. {$B-}    {Boolean complete evaluation off}
  31. {$S-}    {Stack checking off}
  32. {$I-}    {I/O checking off}
  33. {$N+,E+} {Simulate numeric coprocessor}
  34. {$M 16384,0,327680} {stack and heap}
  35. {$V-}    {Variable range checking off}
  36.  
  37. { Name ==================================================================== }
  38.  
  39. UNIT DgFile;
  40. {
  41.   The purpose of this code is to provide additional file-handling routines.
  42. }
  43.  
  44. { Interface =============================================================== }
  45.  
  46. INTERFACE
  47.  
  48. USES
  49. { Turbo Pascal 5.5 Units }
  50.   Dos,
  51.  
  52. { Object Professional Units }
  53.   OpAbsFld,
  54.   OpCrt,
  55.   OpDos,
  56.   OpEntry,
  57.   OpString,
  58.   OpStrDev,
  59.  
  60. { Dg Units }
  61.   DgMath,
  62.   DgWryte;
  63.  
  64. { Declarations ============================================================ }
  65. { Variables --------------------------------------------------------------= }
  66.  
  67. TYPE
  68.   FileNameStr = string [12];                     { store a filename }
  69.  
  70. CONST
  71.   ProgramName    : string [16] = '';             { name + version number }
  72.  
  73.   ExeFileName    : string  = '';                 { name of executable }
  74.   LogFileName    : string  = '';                 { name of log file }
  75.   ConfigFileName : string  = '';                 { name of config file }
  76.   ProgramPath    : string  = '';                 { where to find it }
  77.  
  78. VAR
  79.   ExeFile        : file;                         { executable file }
  80.   LogFile        : text;                         { log program operations }
  81.   ConfigFile     : file;                         { configuration file }
  82.  
  83. { Functions =============================================================== }
  84.  
  85. FUNCTION DosVer : real;
  86. { Returns DOS version }
  87.  
  88. FUNCTION ExistAnyFile (FileName : String) : boolean;
  89. { Does this file exist? }
  90.  
  91. FUNCTION FileIsOpen (Var F {: File }) : boolean;
  92. { Returns true if file is open }
  93.  
  94. PROCEDURE SetProgramName (Name : FileNameStr;  Version : real);
  95. { Saves program name in variables for use by other functions. }
  96.  
  97. { ========================================================================= }
  98. { Implementation ========================================================== }
  99.  
  100. IMPLEMENTATION
  101.  
  102. { ========================================================================= }
  103. { DosVer ================================================================== }
  104.  
  105. FUNCTION DosVer : real;
  106. { returns DOS version }
  107. VAR
  108.   V : word;
  109. BEGIN
  110.   V := DosVersion;
  111.   DosVer := Hi (V) + Lo (V)/100;
  112. END;
  113.  
  114. { ExistAnyFile ============================================================ }
  115.  
  116. FUNCTION ExistAnyFile (FileName : string) : Boolean;
  117.  
  118. VAR
  119.   StoreMode : Byte;
  120.  
  121. BEGIN
  122.    StoreMode := FileMode;
  123.    FileMode  := 0;
  124.    ExistAnyFile := ExistFile (FileName);
  125.    FileMode  := StoreMode;
  126. END;
  127.  
  128. { FileIsOpen ============================================================== }
  129.  
  130. FUNCTION FileIsOpen (Var F {: File }) : boolean;
  131. { returns true if file is open }
  132.  
  133. BEGIN
  134.   Case FileRec (F).Mode of
  135.     fmInput, fmOutput, fmInOut : FileIsOpen := true;
  136.   else
  137.     FileIsOpen := false;
  138.   end;
  139. END;
  140.  
  141. { SetProgramName ========================================================== }
  142.  
  143. PROCEDURE SetProgramName (Name : FileNameStr;  Version : real);
  144. { Saves program name in variables for use by other functions. }
  145.  
  146. {
  147.   Stashes program name in a variable for use by other functions.
  148.   Also creates the names for LogFile and ConfigFile, if needed.
  149.  
  150.   NOTE:  there is no checking for valid characters.  It is up
  151.   to the programmer to make sure that the program name and the
  152.   resulting logfile name will be acceptable to DOS.
  153. }
  154. VAR
  155.   Flag : boolean;
  156.  
  157. BEGIN
  158.   Write (TpStr, ' v', Version:4:2);
  159.   ProgramName    := StUpCase (Name) + ReturnStr; { tell program its name }
  160.  
  161. {
  162.   Can't use ParamStr (0) to get program path unless Dos 3.0 is installed.
  163.   User shouldn't be running an obsolete version of Dos anyway.
  164. }
  165.   if DosVer < 3.0 then begin
  166.     WryteLn (ProgramName +
  167.              ':  Sorry.  This program requires DOS 3.0 or later.');
  168.     halt;
  169.    end;
  170.  
  171.   ExeFileName := ForceExtension (Name, 'EXE');   { name of executable }
  172.   ProgramPath := JustPathName (ParamStr (0));    { get program path }
  173.   if                                             { if needed, then }
  174.     (ProgramPath > '') and
  175.     (ProgramPath [Length (ProgramPath)] <> '\')
  176.   then
  177.     ProgramPath := ProgramPath + '\';            { add backslash }
  178.  
  179.   ExeFileName := ProgramPath + ExeFileName;      { full name of exe file }
  180.   LogFileName :=
  181.     ForceExtension (ExeFileName, 'LOG');         { where is log file }
  182.   ConfigFileName :=
  183.     ForceExtension (ExeFileName, 'CFG');         { where is cfg file }
  184.  
  185.   Assign (ExeFile, ExeFileName);                 { ready to r/w }
  186.   Assign (LogFile, LogFileName);                 { ready to r/w }
  187.   Assign (ConfigFile, ConfigFileName);           { ready to r/w }
  188. END;
  189.  
  190. { ========================================================================= }
  191. { Initialization Variables ================================================ }
  192.  
  193. VAR
  194.   ExitSave : pointer;                            { for ExitProc }
  195.  
  196. { ExitUnit ================================================================ }
  197.  
  198. {$F+} PROCEDURE ExitUnit; {$F-}
  199.  
  200. BEGIN
  201.   ExitProc := ExitSave;                          { reset original address }
  202.  
  203.   if FileIsOpen (ExeFile) then Close (ExeFile);
  204.   if FileIsOpen (LogFile) then Close (LogFile);
  205.   if FileIsOpen (ConfigFile) then Close (ConfigFile);
  206. END;
  207.  
  208. { Initialization ========================================================== }
  209.  
  210. BEGIN
  211.   ExitSave := ExitProc;                          { save old exit address }
  212.   ExitProc := @ExitUnit;                         { get new exit address }
  213.  
  214. END.
  215.  
  216. { ========================================================================= }
  217. { DgFile History ========================================================== }
  218.  
  219. VERSION HISTORY:
  220.   9005.05
  221.     Completely restructured for compatibility with Object Professional 5.5.
  222.  
  223. { DgFile Needs ============================================================ }
  224.  
  225. NEED TO ADD:
  226.   Nothing right now.
  227.  
  228. { Bugs ==================================================================== }
  229.  
  230. BUG REPORTS:
  231.   No known bugs.
  232.  
  233. { ========================================================================= }
  234.