Category : Batch File Utilities - mostly for DOS
Archive   : BATUTIL.ZIP
Filename : GETPATH.MOD

 
Output of file : GETPATH.MOD contained in archive : BATUTIL.ZIP
MODULE GetPath;

(*
Title: GETPATH.MOD

Author: Randall A. Maddox
12209 M Peach Crest Drive
Germantown, MD 20874
(301) 428-9581

System: LOGITECH MODULA-2, MS/PCDOS, Version 3.03, December 1987

Description: Gets current value of environment variable PATH and writes
out commands to restore that PATH at a later point. Default output is
to file RESTPATH.BAT on current default drive. RESTPATH can later be
used to restore a PATH that has been temporarily altered. Calling
format is:

GETPATH TmpPath [Output-File {including drive and path}]

where TmpPath is the path that PATH is going to be changed to. There
is no default value for TmpPath. If only one command line parameter
is passed to the program, it is assumed to be TmpPath. If no command
line parameters are passed to the program, it just exits without doing
anything. If excess parameters beyond OutPut-File are passed to the
program, they are just ignored and the program treats the first two
as TmpPath and OutPut-File.

Output written to Output File consists of the following:

echo off
set PATH={Value of PATH at first call to GETPATH}
cls

Calls to GETPATH once PATH has been changed to TmpPath will result
in no action. Calling RESTPATH will restore the value of PATH present
when GETPATH was first called. The output can be sent to any legal file.

The success or failure of GETPATH can be evaluated by inspecting the
ERRORLEVEL value maintained by DOS after calling GETPATH. The values
of ERRORLEVEL and corresponding completion status are the following:

ERRORLEVEL = 0 -> normal completion, no error
ERRORLEVEL = 1 -> unable to create specified output file
ERRORLEVEL = 2 -> missing command line parameters

ERRORLEVELs 1 and 2 are both fatal and result in failure of GETPATH
to perform its task.

Update History:
Originally written: 7/1/88
Added command line TmpPath variable: 7/3/88
Added command line OutPut-File variable: 7/4/88
*)

FROM ASCII IMPORT
nul, cr, lf;

FROM ErrorCode IMPORT
SetErrorCode, ExitToOS;

FROM FileSystem IMPORT
File, Lookup, Response, Delete, Close, SetWrite, WriteChar;

FROM Strings IMPORT
CompareStr, Length, Concat;

FROM Utility IMPORT
GetEnvVar, ParmCnt, GetCmdParm, CapStr;

CONST (* default values *)
DefFile = 'restpath.bat'; (* .BAT file to restore path *)
DefDrive = 'DK:';

VAR
CurPath : ARRAY[0..127] OF CHAR; (* initial PATH *)
TmpPath : ARRAY[0..127] OF CHAR; (* modified PATH *)
BatFile : ARRAY[0..64] OF CHAR; (* name of output file *)
f : File;
I,Parms : CARDINAL;

(**************************************************************************)

PROCEDURE WriteString(VAR f : File; Str : ARRAY OF CHAR);

BEGIN
IF (Str[0] <> nul) THEN
FOR I := 0 TO (Length(Str) - 1) DO
WriteChar(f,Str[I])
END (* for *)
END (* if *)
END WriteString; (* procedure *)


(**************************************************************************)

PROCEDURE WriteLn(VAR f : File);

BEGIN
WriteChar(f,cr);
WriteChar(f,lf)
END WriteLn; (* procedure *)


(**************************************************************************)

BEGIN (* module body *)
Parms := ParmCnt(); (* see how many parameters we got *)
IF (Parms > 0) THEN (* OK, do something *)
GetEnvVar('PATH',CurPath); (* value of PATH environment variable *)
CapStr(CurPath); (* force to caps *)
GetCmdParm(1,TmpPath); (* get value of reset PATH *)
CapStr(TmpPath); (* force to caps *)
(* if CurPath = TmpPath then do nothing *)
IF (CompareStr(TmpPath,CurPath) <> 0) THEN (* not the same *)
(* write .BAT file to restore this PATH *)
IF (Parms >= 2) THEN (* get output file from command line *)
GetCmdParm(2,BatFile);
IF NOT((BatFile[0] >= 'A') AND (BatFile[0] <= 'P') AND
(BatFile[1] = ':')) THEN (* no drive specified *)
Concat(DefDrive,BatFile,BatFile);
END (* if *)
ELSE (* use default output file *)
Concat(DefDrive,DefFile,BatFile)
END; (* if *)
Delete(BatFile,f); (* ensure file not present *)
Lookup(f,BatFile,TRUE); (* create .BAT file *)
IF (f.res = done) THEN (* created OK *)
SetWrite(f); (* and put in write mode *)
WriteString(f,'echo off');
WriteLn(f);
WriteString(f,'set PATH=');
WriteString(f,CurPath);
WriteLn(f);
WriteString(f,'cls');
WriteLn(f);
Close(f) (* and close our file *)
ELSE (* create failed *)
SetErrorCode(1);
ExitToOS
END (* if *)
END (* if *)
ELSE (* no command line parameters *)
SetErrorCode(2);
ExitToOS
END; (* if *)
(* fall through for normal exit *)
SetErrorCode(0);
ExitToOS
END GetPath.

(* end of this file *)


  3 Responses to “Category : Batch File Utilities - mostly for DOS
Archive   : BATUTIL.ZIP
Filename : GETPATH.MOD

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/