home *** CD-ROM | disk | FTP | other *** search
/ Bila Vrana / BILA_VRANA.iso / 005A / 4UTILS85.ZIP / GLOBALS.PAS < prev    next >
Pascal/Delphi Source File  |  1995-05-07  |  6KB  |  209 lines

  1. UNIT Globals;
  2. (* ----------------------------------------------------------------------
  3.    Part of 4FF   - 4DOS File Finder
  4.  
  5.    (c) 1992, 1993 Copyright by David Frey,
  6.                                Urdorferstrasse 30
  7.                                8952 Schlieren ZH
  8.                                Switzerland
  9.  
  10.    DISCLAIMER: This unit is freeware: you are allowed to use, copy
  11.                and change it free of charge, but you may not sell or hire
  12.                this part of 4DESC. The copyright remains in our hands.
  13.  
  14.                If you make any (considerable) changes to the source code,
  15.                please let us know. (send a copy or a listing).
  16.                We would like to see what you have done.
  17.  
  18.                We, David Frey and Tom Bowden, the authors, provide absolutely
  19.                no warranty of any kind. The user of this software takes the
  20.                entire risk of damages, failures, data losses or other
  21.                incidents.
  22.  
  23.  
  24.        Code created using Turbo Pascal 7.0 (c) Borland International 1992
  25.  
  26.    This unit provides the string handling and the date/time handling.
  27.  
  28.    ----------------------------------------------------------------------- *)
  29.  
  30. INTERFACE USES Objects, Dos, StringDateHandling;
  31.  
  32. CONST MaxFileSpecs      =   6;
  33.       DescLen           = 200;
  34.  
  35. TYPE  DescStr           = STRING[DescLen];
  36.       NameExtStr        = STRING[8+1+3];
  37.       FileSpecArrayType = ARRAY[1..MaxFileSpecs] OF NameExtStr;
  38.  
  39. (* command line flags: *)
  40.  
  41. VAR   ExactAttr                : BOOLEAN;
  42.       ScanLZHArchives          : BOOLEAN;
  43.       ScanZIPArchives          : BOOLEAN;
  44.       ScanARJArchives          : BOOLEAN;
  45.       SubDirectories           : BOOLEAN;
  46.       AllDrives, FixedDrives   : BOOLEAN;
  47.       BareOutput               : BOOLEAN;
  48.       DoPage                   : BOOLEAN;
  49.       Drive                    : CHAR;
  50.       searchdesc               : DescStr;
  51.  
  52. (* Global variables *)
  53.  
  54. VAR   Attr                     : BYTE;
  55.       DirSize,   TotalSize     : LONGINT;
  56.       FileCount, TotalFileCount: WORD;
  57.  
  58. VAR   FileName                 : NameExtStr;
  59.       Search                   : SearchRec;
  60.       Path                     : PathStr;
  61.       Name                     : NameStr;
  62.       Dir                      : DirStr;
  63.       Ext                      : ExtStr;
  64.  
  65. VAR   f                        : FILE; (* the archive *)
  66.  
  67. VAR   InfoArray                : ARRAY[0..6] OF PString;
  68.       AttrStr, FileStr, SizeStr: STRING;
  69.       Date                     : DateStr;
  70.       Time                     : TimeStr;
  71.       DateRec                  : DateTime;
  72.  
  73. VAR   csize                    : LONGINT;    (* compressed size *)
  74.       fstamp                   : DateTime;   (* last mod file date/time (turbo format) *)
  75.       s                        : STRING;
  76.  
  77. (* Templates for FormatStr *)
  78.  
  79. VAR   DateTempl : STRING[4];
  80.       TimeTempl : STRING[4];
  81.       DescTempl : STRING[5];
  82.  
  83. VAR   MaxViewLength : BYTE;
  84.  
  85. (* Buffer related variables: *)
  86.  
  87. CONST MaxBufSize = 65500;
  88.  
  89. TYPE  PBuffer = ^TBuffer;
  90.       TBuffer = ARRAY[0..MaxBufSize] OF BYTE;
  91.  
  92. VAR   BufPtr    : LONGINT;
  93.       BytesRead : WORD;
  94.       BufSize   : WORD;
  95.       FilePtr   : LONGINT;
  96.  
  97. VAR   Buffer    : PBuffer;
  98.  
  99. VAR   Line      : BYTE;
  100.       Redirected: BOOLEAN;
  101.  
  102. PROCEDURE TestForMoreMsg;
  103.  
  104. PROCEDURE InstallBuffer;
  105. PROCEDURE FreeBuffer;
  106. FUNCTION  ReadByte: BYTE;
  107.  
  108. IMPLEMENTATION USES Memory, Crt,
  109.                     HandleINIFile, DescriptionHandling;
  110.  
  111. VAR   ScreenHeight : BYTE;
  112.       HilightMore  : BOOLEAN;
  113.  
  114. FUNCTION TestIfRedirected: BOOLEAN;
  115.  
  116. TYPE TPSP = ARRAY[0..$FF] OF BYTE;
  117.  
  118. VAR  PSP  : ^TPSP;
  119.  
  120. BEGIN
  121.  PSP := Ptr(PrefixSeg,0);
  122.  TestIfRedirected := (PSP^[$19] <> 1);
  123. END;
  124.  
  125. PROCEDURE TestForMoreMsg;
  126.  
  127. VAR ch: CHAR;
  128.  
  129. BEGIN
  130.  INC(Line);
  131.  IF KeyPressed OR (Line = ScreenHeight) THEN
  132.   BEGIN
  133.    IF KeyPressed THEN ch := ReadKey;
  134.    HighVideo; Write('-- more --',#13); LowVideo;
  135.    REPEAT UNTIL KeyPressed;
  136.    ch := ReadKey;
  137.    ClrEOL;
  138.    IF Line = ScreenHeight THEN Line := 1;
  139.   END;
  140. END;
  141.  
  142. PROCEDURE InstallBuffer;
  143.  
  144. BEGIN
  145.  IF MaxAvail < MaxBufSize THEN BufSize:= WORD(MaxAvail)
  146.                           ELSE BufSize:= MaxBufSize;
  147.  
  148.  GetMem(Buffer,BufSize);
  149.  IF Buffer = NIL THEN
  150.   BEGIN
  151.    WriteLn(Output);
  152.    WriteLn(Output,'Fatal Error : Unable to allocate Buffer!');
  153.    HALT(255);
  154.   END;
  155. END; (* InstallBuffer *)
  156.  
  157. PROCEDURE FreeBuffer;
  158.  
  159. BEGIN
  160.  FreeMem(Buffer,BufSize);
  161. END; (* FreeBuffer *)
  162.  
  163. FUNCTION ReadByte: BYTE;
  164.  
  165. BEGIN
  166.  IF BufPtr >= BufSize THEN
  167.   BEGIN
  168.    BlockRead(f,Buffer^,BufSize, BytesRead);
  169.    BufPtr := 0;
  170.   END;
  171.  
  172.  ReadByte := Buffer^[BufPtr]; INC(BufPtr); INC(FilePtr);
  173. END; (* ReadByte *)
  174.  
  175. BEGIN
  176.  Str(Length(DateFormat),DateTempl); DateTempl := '%'+DateTempl+'s';
  177.  Str(Length(TimeFormat),TimeTempl); TimeTempl := '%'+TimeTempl+'s';
  178.  
  179.  Assign(Output,''); Rewrite(Output);
  180.  Redirected := TestIfRedirected; DirectVideo := NOT Redirected;
  181.  
  182.  IF Redirected THEN
  183.   BEGIN
  184.    MaxViewLength := 255; DescTempl := '%-s';
  185.    Assign(Output,''); Rewrite(Output);
  186.  
  187.    DoPage := FALSE;
  188.   END
  189.  ELSE
  190.   BEGIN
  191.    AssignCrt(Output); Rewrite(Output);
  192.  
  193.    MaxViewLength := Lo(WindMax)-33-Length(DateFormat)-Length(TimeFormat);
  194.    Str(MaxViewLength,DescTempl); DescTempl := '%-'+DescTempl+'s';
  195.    ScreenHeight := Hi(WindMax);
  196.  
  197.    InitMemory;
  198.  
  199.    INIStrings := New(PINIStrings,Init); (* Read in the .INI file(s) *)
  200.    StringDateHandling.EvaluateINIFileSettings;
  201.    DescriptionHandling.EvaluateINIFileSettings;
  202.  
  203.    HilightMore := (ReadSettingsChar('4ff','hilightmore','y') = 'y');
  204.    DoPage      := (ReadSettingsChar('4ff','dopage','n') = 'y');
  205.  
  206.    Dispose(INIStrings,Done); INIStrings := NIL;
  207.   END;
  208. END.
  209.