home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / jsage / znode3 / uploads / tpatch.lbr / NAMEDDIR.IZC / NAMEDDIR.INÃ
Encoding:
Text File  |  1993-06-07  |  1.9 KB  |  60 lines

  1. (*
  2.  * NamedDir - Herbert Oppmann 8/92
  3.  * needs Z3Env.INC
  4.  *)
  5.  
  6. TYPE
  7.   FNameT = STRING[22];
  8.  
  9. (*
  10.  * Converts filenames for later use with 'assign'.
  11.  * Accepts DIR-form, DU-form, or plain filename.
  12.  * Only a DIR-form is converted to its corresponding DU-form.
  13.  * Be careful with the Turbo Pascal device names (e.g. 'LST:')!
  14.  * If you want these names not to be tried as named directories,
  15.  * remove the comments {+} that surround the comparison below.
  16.  * Erroneous forms don't cause a warning or error message here.
  17.  * They hopefully don't match a DIR entry and are thus left unchanged.
  18.  *)
  19. FUNCTION Dir2Du(fn : FNameT) : FNameT;
  20. LABEL Thatsall;
  21. VAR
  22.   p, i, d, u : INTEGER;
  23.   dir : STRING[8];
  24. BEGIN
  25.   {check that there is a ZCPR environment}
  26.   IF (Env =NIL) THEN Goto Thatsall;
  27.   p := Pos(':',fn);
  28.   {if it is only a plain filename, leave it unchanged}
  29.   IF (p =0) THEN Goto Thatsall;
  30.   {extract DU/DIR}
  31.   dir := Copy(Copy(fn,1,p-1)+'        ',1,8);
  32.   i := 0;
  33.   WHILE (i <Length(dir)) DO
  34.     BEGIN
  35.     dir[i] := UpCase(dir[i]);
  36.     i := Succ(i);
  37.     END;
  38.   {except Turbo Pascal device names}
  39. {+IF (dir = 'CON     ') OR (dir = 'TRM     ') OR
  40.      (dir = 'KBD     ') OR (dir = 'LST     ') OR
  41.      (dir = 'AUX     ') OR (dir = 'USR     ') THEN Goto Thatsall;+}
  42.   WITH Env^ DO
  43.     BEGIN
  44.     i := 0;
  45.     REPEAT
  46.       {check if there is another entry in the list of named directories}
  47.       IF (i =ndrs) OR (ndr^[i].drive =0) THEN Goto Thatsall;
  48.       i := Succ(i);
  49.     UNTIL (dir = ndr^[Pred(i)].name);
  50.     {we found a DIR entry, get the corresponding DU}
  51.     d := ndr^[Pred(i)].drive;
  52.     u := ndr^[Pred(i)].user;
  53.     Delete(fn,1,p-1);
  54.     {cut off the DIR and add the DU}
  55.     fn := Chr(d+$40)+Chr((u DIV 10)+48)+Chr((u MOD 10)+48)+fn;
  56.     END; {WITH}
  57. Thatsall:
  58.   Dir2Du := fn;
  59. END; {Dir2Du}
  60.