Archived
1
0

Initial commit

This commit is contained in:
2001-11-30 12:14:44 +01:00
commit bc7c109b0c
380 changed files with 26247 additions and 0 deletions

236
PPDIR/PPDIR.PAS Normal file
View File

@ -0,0 +1,236 @@
program PushPopDir;
{$M 8192,0,0}
uses Dos;
const TmpFile='dirmem.$$$';
var where: string;
what: string;
debug: boolean;
function UC(str: string): string;
var i: integer;
tmp: string;
begin
tmp := '';
for i:=1 to Length(str) do begin
tmp := tmp + UpCase(str[i]);
end;
UC := tmp;
end;
function Contains(str, what: string): boolean;
var i,sl: integer;
begin
sl := Length(what);
what := UC(what);
for i:=Length(str) downto 1 do begin
if UC(Copy(str,i,sl))=what then begin
if debug then WriteLn('<27> Contains result: ''',what,''' in ParamStr(0): true');
Contains := true;
Exit;
end;
end;
if debug then WriteLn('<27> Contains result: ''',what,''' in ParamStr(0): false');
Contains := false;
end;
function GetTempFile: string;
var td: string;
begin
td := GetEnv('TEMP');
if td='' then td := GetEnv('TMP');
if td='' then td := 'C:\';
if Copy(td,Length(td)-1,1)='\' then td := td+TmpFile else td := td+'\'+TmpFile;
if debug then WriteLn('<27> GetTempFile result: ',td);
GetTempFile := td;
end;
procedure PopDir;
var tmp: text;
dir: string;
begin
dir := '';
if debug then WriteLn('<27> Assigning GetTempFile to tmp');
Assign(tmp,GetTempFile);
{$I-}
if debug then WriteLn('<27> Resetting tmp');
Reset(tmp);
if debug then WriteLn('<27> IOResult check');
if IOResult<>0 then begin
WriteLn('No directory in memory!');
Halt;
end;
{$I+}
if debug then WriteLn('<27> Read pushed dir, if NOT Eof(tmp)');
if NOT Eof(tmp) then ReadLn(tmp,dir);
if debug then WriteLn('<27> Closing tmp');
Close(tmp);
if debug then WriteLn('<27> Erasing tmp');
Erase(tmp);
if debug then WriteLn('<27> Result check');
if dir='' then begin
WriteLn('No directory in memory! [2]');
Halt;
end;
if debug then WriteLn('<27> Changing to directory ''',dir,'');
ChDir(dir);
WriteLn('Changed directory to ',dir,'.');
Halt;
end;
procedure PushDir;
var tmp: text;
begin
if debug then WriteLn('<27> Assigning GetTempFile to tmp');
Assign(tmp,GetTempFile);
{$I-}
if debug then WriteLn('<27> Rewriting tmp');
Rewrite(tmp);
if debug then WriteLn('<27> Writing ''',where,''' to tmp');
WriteLn(tmp,where);
if debug then WriteLn('<27> Closing tmp');
Close(tmp);
if debug then WriteLn('<27> IOResult check');
if IOResult<>0 then begin
WriteLn('There was an error!');
Halt;
end;
{$I+}
WriteLn('Pushed current directory into memory.');
Halt;
end;
procedure SwapDir;
var tmp: text;
dir: string;
begin
dir := '';
if debug then WriteLn('<27> Assigning GetTempFile to tmp');
Assign(tmp,GetTempFile);
{$I-}
if debug then WriteLn('<27> Resetting tmp');
Reset(tmp);
if debug then WriteLn('<27> IOResult check');
if IOResult<>0 then begin
WriteLn('No directory in memory!');
Halt;
end;
{$I+}
if debug then WriteLn('<27> Read pushed dir, if NOT Eof(tmp)');
if NOT Eof(tmp) then ReadLn(tmp,dir);
if debug then WriteLn('<27> Closing tmp');
Close(tmp);
if debug then WriteLn('<27> Erasing tmp');
Erase(tmp);
if debug then WriteLn('<27> Result check');
if dir='' then begin
WriteLn('No directory in memory! [2]');
Halt;
end;
if debug then WriteLn('<27> Changing to directory ''',dir,'');
ChDir(dir);
{$I-}
if debug then WriteLn('<27> Rewriting tmp');
Rewrite(tmp);
if debug then WriteLn('<27> Writing ''',where,''' to tmp');
WriteLn(tmp,where);
if debug then WriteLn('<27> Closing tmp');
Close(tmp);
if debug then WriteLn('<27> IOResult check');
if IOResult<>0 then begin
WriteLn('There was an error!');
Halt;
end;
{$I+}
WriteLn('Swapped directory with those in memory.');
end;
procedure ShowDir;
var tmp: text;
dir: string;
begin
dir := '';
if debug then WriteLn('<27> Assigning GetTempFile to tmp');
Assign(tmp,GetTempFile);
{$I-}
if debug then WriteLn('<27> Resetting tmp');
Reset(tmp);
if debug then WriteLn('<27> IOResult check');
if IOResult<>0 then begin
WriteLn('No directory in memory!');
Halt;
end;
if debug then WriteLn('<27> Read pushed dir, if NOT Eof(tmp)');
if NOT Eof(tmp) then ReadLn(tmp,dir);
if debug then WriteLn('<27> Closing tmp');
Close(tmp);
if dir='' then begin
if debug then WriteLn('<27> No valid dir in mem ==> Erasing tmp');
Erase(tmp);
WriteLn('No directory in memory! [2]');
Halt;
end;
WriteLn('Pushed directory: ',dir);
Halt;
end;
procedure CreatePackage;
var tmp: text;
begin
if debug then WriteLn('<27> Assigning $$_cp_$$.bat to tmp');
Assign(tmp,'$$_cp_$$.bat');
{$I-}
if debug then WriteLn('<27> Rewriting tmp');
Rewrite(tmp);
if debug then WriteLn('<27> Writing commands to tmp');
WriteLn(tmp,'@echo off');
WriteLn(tmp,'ECHO Building package of %1 ...');
WriteLn(tmp,'DEL popd.exe >NUL');
WriteLn(tmp,'DEL pushd.exe >NUL');
WriteLn(tmp,'DEL swapd.exe >NUL');
WriteLn(tmp,'COPY %1 popd.exe >NUL');
WriteLn(tmp,'COPY %1 pushd.exe >NUL');
WriteLn(tmp,'COPY %1 swapd.exe >NUL');
WriteLn(tmp,'DEL %1 >NUL');
if debug then WriteLn('<27> Closing tmp');
Close(tmp);
if debug then WriteLn('<27> IOResult check');
if IOResult<>0 then begin
WriteLn('There was an error! Could not create package. Make sure, that there is no');
WriteLn('file named $$_cp_$$.bat in this directory and try again.');
Halt;
end;
{$I+}
if debug then WriteLn('<27> Swapping Vectors out');
SwapVectors;
if debug then WriteLn('<27> Execing anti-packager');
Exec(GetEnv('COMSPEC'),'/C $$_cp_$$.bat '+ParamStr(0));
if debug then WriteLn('<27> Swapping Vectors in');
SwapVectors;
if debug then WriteLn('<27> Checking DOSError');
if DOSError<>0 then begin
WriteLn('There was an error during the building of the package. Make sure your environ-');
WriteLn('ment variable COMSPEC points to your command-interpreter.');
Halt;
end;
if debug then WriteLn('<27> Erasing tmp');
Erase(tmp);
WriteLn;
WriteLn('Now you''re ready to use PushPopDir. Read the PPDIR.TXT for further instructions.');
Halt;
end;
begin
debug := false;
GetDir(0,where);
what := ParamStr(0);
if ((ParamStr(1)<>'') AND (ParamStr(1)='debug')) then debug:=true;
if (((NOT debug) AND (ParamCount>0)) OR ((debug) AND (ParamCount>1))) then ShowDir;
if Contains(what,'popd') then PopDir;
if Contains(what,'pushd') then PushDir;
if Contains(what,'swapd') then SwapDir;
CreatePackage;
end.

31
PPDIR/PPDIR.TXT Normal file
View File

@ -0,0 +1,31 @@
PushPopDir - an add-on for the command line written by Markus Birth
-------------------------------------------------------------------------------
(c)1998 by Markus Birth <M.Birth@ThePentagon.com>
To install PPDir, just copy the executable PPDIR.EXE to a directory which is
in your path and run it there. It will extract itself into 3 parts:
PUSHD.EXE
POPD.EXE
and SWAPD.EXE
PUSHD is used to save the current directory into the temporary buffer. The
buffer-file is stored in the TEMP-directory so that it survives
system reboots.
POPD is used to change to the directory which is stored in the buffer. The
buffer will be deleted after the chdir succeeds.
SWAPD will save the current directory into the buffer and then switch to
the directory which was in the buffer before. If you run SWAPD again
you will have the same state as before the first run.
To see what's in the buffer, just type any parameter after any command. If you
use 'debug' as parameter (without quotation marks) you will get into the
debug-mode which will show things happening during the performance of the
commands.
Now have your phun!
-------------------------------------------------------------------------------
Bug report to M.Birth@ThePentagon.com