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

  1. PROGRAM FileDescEditor;
  2. {$A+,B-,D-,E-,F-,G+,L+,N-,O-,R+,S+,V-,X-}
  3. {$M 8192,0,655360}
  4.  
  5. (* ----------------------------------------------------------------------
  6.    A Simple 4DOS File Description Editor
  7.  
  8.    (c) 1992, 1993 Copyright by
  9.  
  10.        David Frey,         & Tom Bowden
  11.        Urdorferstrasse 30    1575 Canberra Drive
  12.        8952 Schlieren ZH     Stone Mountain, GA 30088-3629
  13.        Switzerland           USA
  14.  
  15.        Code created using Turbo Pascal 7.0, (c) Borland International 1992
  16.  
  17.    DISCLAIMER: This program is freeware: you are allowed to use, copy
  18.                and change it free of charge, but you may not sell or hire
  19.                4DESC. The copyright remains in our hands.
  20.  
  21.                If you make any (considerable) changes to the source code,
  22.                please let us know. (send a copy or a listing).
  23.                We would like to see what you have done.
  24.  
  25.                We, David Frey and Tom Bowden, the authors, provide absolutely
  26.                no warranty of any kind. The user of this software takes the
  27.                entire risk of damages, failures, data losses or other
  28.                incidents.
  29.  
  30.    ----------------------------------------------------------------------- *)
  31.  
  32. USES {$IFOPT G+} Test286, {$ENDIF}
  33.      Fix, Crt, Dos, Memory, Drivers,
  34.      StringDateHandling, DisplayKeyboardAndCursor, HandleINIFile,
  35.      DescriptionHandling, dmouse;
  36.  
  37. CONST DelimiterTable : STRING = ',.();:-!?/[]{}+*=''`"@%&$_£';
  38.  
  39. VAR  EdStart     : BYTE;      (* column where the description starts     *)
  40.  
  41.      ActDir      : DirStr;    (* current directory                       *)
  42.      StartDir    : DirStr;    (* directory where we started from         *)
  43.      ResetDir    : BOOLEAN;   (* TRUE = return to StartDir on exit       *)
  44.  
  45.      StartIndex  : INTEGER;   (* index of entry at the top of the screen *)
  46.      Index       : INTEGER;   (* index of entry we are editing           *)
  47.  
  48.      CutPasteDesc: DescStr;   (* cut, resp. pasted description           *)
  49.      Changed     : BOOLEAN;   (* TRUE=the descriptions have been edited  *)
  50.      IORes       : INTEGER;
  51.  
  52.      NewDir      : DirStr;    (* temporary storage for a directory path, *)
  53.      NewName     : NameExtStr;(* used by view and others                 *)
  54.  
  55.      FirstParam  : STRING[8];
  56.      i           : BYTE;      (* variable for counting (index etc)       *)
  57.      ShowHelp    : BOOLEAN;   (* TRUE = start in help mode [/h]          *)
  58.      Querier     : BOOLEAN;   (* TRUE = ask user if he wants to save
  59.                                         the descriptions   [/dontask]    *)
  60.      PasteMovesToNextIndex: BOOLEAN; (* TRUE = Paste advances to next index *)
  61.      Overwrite   : BOOLEAN;   (* overwrite / Insert mode                 *)
  62.  
  63.      s           : STRING;    (* temporary string variable               *)
  64.  
  65. (*-------------------------------------------------------- Display-Routines *)
  66. PROCEDURE DisplayFileEntry(Index: INTEGER; ox, x: BYTE;
  67.                            Selection, Hilighted: BOOLEAN);
  68. (* Displays the Index'th file entry. If the description is longer than
  69.    DispLen characters, DispLen characters - starting at character x of the
  70.    description - will be shown. (this feature is needed for scrolling).
  71.    Hilighted = TRUE will hilight the description.
  72.  
  73.    When Selection is TRUE, we want to display the text we just put into
  74.    the buffer, ox (old x) gives us the start of the selection.
  75.  
  76.    P.S. Scrolling implies hilighting, but this fact has not been exploited. *)
  77.  
  78.  VAR FileEntry : PFileData;
  79.      xs,oxs,t  : BYTE;
  80.      y,l       : BYTE;
  81.      s         : STRING;
  82.  
  83.  BEGIN
  84.   y := 3+Index-StartIndex;
  85.   IF (Index >= 0) AND (Index < FileList^.Count) THEN
  86.    BEGIN
  87.     FileEntry := NILCheck(FileList^.At(Index));
  88.  
  89.     IF x <=   DispLen THEN xs := 1
  90.     ELSE
  91.     IF x <= 2*DispLen THEN xs := DispLen+1
  92.     ELSE
  93.     IF x <= 3*DispLen THEN xs := 2*DispLen+1
  94.     ELSE
  95.     IF x <= 4*DispLen THEN xs := 3*DispLen+1
  96.                       ELSE xs := 4*DispLen+1;
  97.     (* I haven't found a simple formula yet, so I'm doing the
  98.        job with a table. That's the lazy's man solution .... *)
  99.  
  100.     IF ox <=   DispLen THEN oxs := 1
  101.     ELSE
  102.     IF ox <= 2*DispLen THEN oxs := DispLen+1
  103.     ELSE
  104.     IF ox <= 3*DispLen THEN oxs := 2*DispLen+1
  105.     ELSE
  106.     IF ox <= 4*DispLen THEN oxs := 3*DispLen+1
  107.                        ELSE oxs := 4*DispLen+1;
  108.  
  109.     IF Hilighted THEN
  110.      BEGIN TextColor(SelectFg); TextBackGround(SelectBg); END
  111.     ELSE
  112.      BEGIN
  113.       TextBackGround(NormBg);
  114.  
  115.       IF FileEntry^.IsADir THEN TextColor(DirFg)
  116.                            ELSE TextColor(NormFg)
  117.      END;
  118.  
  119.     GotoXY(1,y);
  120.  
  121.     s := FileEntry^.FormatScrollableDescription(xs,DispLen);
  122.     IF Selection THEN
  123.      BEGIN
  124.        IF ox > x  THEN BEGIN t := x; x := ox; ox := t; END
  125.                   ELSE t := x;
  126.        IF ox < xs THEN ox := xs;
  127.  
  128.        Write(Copy(s,1,EdStart+ox-xs-1));
  129.        TextBackGround(NormFg);  TextColor(NormBg);   Write(Copy(s,EdStart+ox-xs,x-ox));
  130.        TextBackGround(SelectBg);TextColor(SelectFg); Write(Copy(s,EdStart+x-xs,255));
  131.  
  132.        x := t;
  133.      END
  134.     ELSE Write(s);
  135.  
  136.     l := Length(FileEntry^.GetDesc);
  137.     IF l-xs < DispLen THEN
  138.      ClrEol
  139.     ELSE
  140.      BEGIN
  141.       TextColor(WarnFg); Write(Chr(16)); TextColor(NormFg);
  142.      END;
  143.  
  144. (*    IF x <= DispLen THEN GotoXY(EdStart+x-1,y)
  145.                     ELSE GotoXY(EdStart+DispLen-1,y) *)
  146.     GotoXY(EdStart+x-xs,y);
  147.    END
  148.   ELSE BEGIN GotoXY(1,y); ClrEol; END;
  149.  END;  (* DisplayFileEntry *)
  150.  
  151. PROCEDURE DrawDirLine(UpdateDir: BOOLEAN);
  152. (* Draw the line, which tells us where in the directory tree we are. *)
  153.  
  154. BEGIN
  155.  IF UpdateDir THEN
  156.   BEGIN
  157.    GetDir(0,ActDir);
  158.    IF ActDir[Length(ActDir)] <> '\' THEN ActDir := ActDir + '\';
  159.    UpString(ActDir);
  160.   END;
  161.  TextColor(DirFg); TextBackGround(NormBg);
  162.  GotoXY(1,2); Write(ActDir); ClrEol;
  163. END; (* DrawDirLine *)
  164.  
  165. PROCEDURE ReDrawScreen;
  166. (* Redraws the full screen, needed after shelling out or after printing
  167.    the help screen.                                                     *)
  168.  
  169. VAR Index: INTEGER;
  170.  
  171. BEGIN
  172. (* GetDir(0,ActDir); *)
  173.  FOR Index := StartIndex TO StartIndex+MaxLines-4 DO
  174.   DisplayFileEntry(Index,0,1,FALSE,FALSE);
  175. END; (* ReDrawScreen *)
  176.  
  177.  
  178. (*-------------------------------------------------------- Read-Directory *)
  179. PROCEDURE ReadFiles;
  180. (* Scan the current directory and read in the DESCRIPT.ION file. Build a
  181.    file list database and associate the right description.
  182.  
  183.    Warn the user if there are too long descriptions or if there are too
  184.    much descriptions.                                                     *)
  185.  
  186. VAR i   : BYTE;
  187.     ch  : WORD;
  188.     Dir : PathStr;
  189.  
  190. BEGIN
  191.  Changed    := FALSE;
  192.  DescLong   := FALSE;
  193.  Index      := 0;
  194.  StartIndex := 0;
  195.  Dir := FExpand('.');
  196.  
  197.  IF FileList <> NIL THEN
  198.   BEGIN
  199.    Dispose(FileList,Done); FileList := NIL;
  200.   END;
  201.  
  202.  TextColor(StatusFg); TextBackGround(StatusBg);
  203.  GotoXY(1,MaxLines);
  204.  IF (ScreenWidth-39-Length(Dir)) > 0 THEN
  205.    Write(Chars(' ',(ScreenWidth-39-Length(Dir)) DIV 2));
  206.  Write('Scanning directory ',Dir,' ..... please wait.');
  207.  ClrEol;
  208.  
  209.  FileList := NIL; FileList := New(PFileList,Init(Dir,'*.*',0));
  210.  IF FileList = NIL THEN Abort('Unable to allocate FileList');
  211.  
  212.  IF (FileList^.Status = ListTooManyFiles) OR
  213.     (FileList^.Status = ListOutofMem) THEN
  214.   BEGIN
  215.    TextColor(NormFg); TextBackGround(NormBg);
  216.    FOR i := 3 TO MaxLines-1 DO
  217.     BEGIN
  218.      GotoXY(1,i); ClrEol;
  219.     END;
  220.    IF FileList^.Status = ListTooManyFiles THEN
  221.     ReportError('Warning! Too many files in directory, description file will be truncated! (Key)',(CutPasteDesc <> ''),Changed)
  222.    ELSE
  223.     ReportError('Warning! Out of memory, description file will be truncated! (Key)',(CutPasteDesc <> ''),Changed);
  224.   END;
  225.  
  226.  IF FileList^.Count > 0 THEN
  227.   BEGIN
  228.    DrawMainScreen(Index,FileList^.Count,1,0); DrawDirLine(TRUE);
  229.   END;
  230.  
  231.  IF DescLong THEN
  232.   BEGIN
  233.    TextColor(NormFg); TextBackGround(NormBg);
  234.    FOR i := 3 TO MaxLines-1 DO
  235.     BEGIN
  236.      GotoXY(1,i); ClrEol;
  237.     END;
  238.