Skip to content

Commit

Permalink
Correctif mineurs
Browse files Browse the repository at this point in the history
  • Loading branch information
Sylvain Maltais committed Aug 14, 2022
1 parent 9ba68df commit 0253eb2
Show file tree
Hide file tree
Showing 3 changed files with 192 additions and 13 deletions.
4 changes: 2 additions & 2 deletions BASH.PAS
Original file line number Diff line number Diff line change
Expand Up @@ -308,11 +308,11 @@ Begin
K:=ReadKey;
Case K of
#0:Case ReadKey of
#72:Begin
#72:If NumberHistory>0 Then Begin
S:=History[CurrHistory]^; { Up }
If CurrHistory>1 Then Dec(CurrHistory);
End;
#80:Begin
#80:If NumberHistory>0 Then Begin
S:=History[CurrHistory]^; { Down }
If CurrHistory<NumberHistory Then Inc(CurrHistory);
End;
Expand Down
195 changes: 187 additions & 8 deletions CSH.PAS
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,16 @@ Const
'unalias','unhash','unlimit','unset','unsetenv','wait','while'
);

MaxStackDirectory=50;
MaxHistory=100;

Type
StrPointer=^String;

Var
StackDirectory:Array[1..MaxStackDirectory] of StrPointer;
History:Array[1..MaxHistory] of StrPointer;
NumberHistory,NumberDirectory:Integer;
CommandFound,Terminated:Boolean;
CmdStr:String;
CurrCommand,ParamList:String;
Expand All @@ -36,6 +45,55 @@ Begin
TrimL:=S;
End;

Function AddHistory(S:String):Boolean;
Var
I:Word;
P:StrPointer;
Begin
If NumberHistory>=MaxHistory Then Begin
FreeMem(History[1],Length(History[1]^)+1);
For I:=1 to MaxHistory-1 do History[I]:=History[I+1];
GetMem(P,Length(S)+1);
P^:=S;
History[MaxHistory]:=P;
AddHistory:=True;
Exit;
End
Else
Begin
Inc(NumberHistory);
GetMem(P,Length(S)+1);
P^:=S;
History[NumberHistory]:=P;
AddHistory:=True;
End;
End;

Function PushDirectory(Directory:String):Boolean;
Var
P:StrPointer;
Begin
If NumberDirectory>=MaxStackDirectory Then Begin
WriteLn('Pile de r‚pertoire pleine');
PushDirectory:=False;
Exit;
End;
Inc(NumberDirectory);
GetMem(P,Length(Directory)+1);
P^:=Directory;
StackDirectory[NumberDirectory]:=P;
PushDirectory:=True;
End;

Function PopDirectory:String;Begin
PopDirectory:='';
If NumberDirectory>0Then Begin
PopDirectory:=StackDirectory[NumberDirectory]^;
FreeMem(History[NumberDirectory],Length(History[NumberDirectory]^)+1);
Dec(NumberDirectory);
End;
End;

Procedure ExtractCommand;
Var
I:Byte;
Expand All @@ -51,6 +109,35 @@ Begin
ParamList:='';
End;

Function ExtractParam(Index:Byte):String;
Var
Count:Word;
LocalIndex:Word;
l:Byte;
Temp:String;
Begin
Temp:='';Count:=1;LocalIndex:=1;l:=0;
While Count<=Length(ParamList)do Begin
If Not(ParamList[Count] in [' ',#9])then Begin
If LocalIndex=Index Then Begin
While (Count<=Length(ParamList)) and (Not(ParamList[count] in[' ',#9])) and (l < 256) do Begin
Temp:=Temp+ParamList[count];
Inc(l);
Inc(Count);
end;
Temp[0]:=Char(l);
ExtractParam:=Temp;
Exit;
End;
While (Count<=Length(ParamList)) and (Not(ParamList[count] in [' ',#9])) do Inc(Count);
Inc(LocalIndex);
End;
If Count>=Length(ParamList)Then Break;
Inc(Count);
End;
ExtractParam:=Temp;
End;

Procedure HomeMessage;Begin
WriteLn;
WriteLn('csh - C Shell');
Expand All @@ -69,8 +156,34 @@ Procedure BgCommand;Begin
WriteLn('Cette commande n''est pas mise en oeuvre');
End;

Procedure ChdirCommand;Begin
ChDir(ParamList);
Procedure ChdirCommand;
Var
Error:Word;
FirstParam,Dir:String;
Begin
FirstParam:=ExtractParam(1);
If FirstParam='-h'Then Begin
WriteLn('chdir Cette commande permet de fixer ou de demander le repertoire courant.');
WriteLn;
WriteLn('Syntaxe:');
WriteLn;
WriteLn('cd [-h] chemin');
WriteLn('chdir [-h] chemin');
WriteLn;
WriteLn(' -h Ce parametre permet d''afficher l''aide sur cette commande');
WriteLn(' chemin Ce parametre permet d''indiquer le chemin du repertoire.');
End
Else
If Length(FirstParam)>0Then Begin
{$I-} ChDir(FirstParam);{$I+}
Error:=IoResult;
If Error<>0Then WriteLn('Impossible de changer de repertoire');
End
Else
Begin
GetDir(0,Dir);
WriteLn(Dir);
End;
End;

Procedure DirsCommand;Begin
Expand Down Expand Up @@ -127,8 +240,23 @@ Procedure HashstatCommand;Begin
WriteLn('Cette commande n''est pas mise en oeuvre');
End;

Procedure HistoryCommand;Begin
WriteLn('Cette commande n''est pas mise en oeuvre');
Procedure HistoryCommand;
Var
I:Integer;
FirstParam:String;
Begin
FirstParam:=ExtractParam(1);
If FirstParam='-h'Then Begin
WriteLn('history Cette commande permet d''afficher l''historique des commandes.');
WriteLn;
WriteLn('Syntaxe:');
WriteLn;
WriteLn('history [-h]');
WriteLn;
WriteLn(' -h Ce parametre permet d''afficher l''aide sur cette commande');
End
Else
For I:=1 to NumberHistory do WriteLn(History[I]^);
End;

Procedure JobsCommand;Begin
Expand Down Expand Up @@ -172,12 +300,58 @@ Procedure NotifyCommand;Begin
WriteLn('Cette commande n''est pas mise en oeuvre');
End;

Procedure PopdCommand;Begin
WriteLn('Cette commande n''est pas mise en oeuvre');
Procedure PopdCommand;
Var
Error:Word;
FirstParam,Dir:String;
Begin
FirstParam:=ExtractParam(1);
If FirstParam='-h'Then Begin
WriteLn('popd Cette commande permet de restaurer le repertoire.');
WriteLn;
WriteLn('Syntaxe:');
WriteLn;
WriteLn('popd [-h]');
WriteLn;
WriteLn(' -h Ce parametre permet d''afficher l''aide sur cette commande');
End
Else
Begin
Dir:=PopDirectory;
{$I-} ChDir(Dir);{$I+}
Error:=IoResult;
If Error<>0Then WriteLn('Impossible de changer de repertoire');
End;
End;

Procedure PushdCommand;Begin
WriteLn('Cette commande n''est pas mise en oeuvre');
Procedure PushdCommand;
Var
Error:Word;
FirstParam,Dir:String;
Begin
FirstParam:=ExtractParam(1);
If FirstParam='-h'Then Begin
WriteLn('pushd Cette commande permet de sauver le repertoire.');
WriteLn;
WriteLn('Syntaxe:');
WriteLn;
WriteLn('pushd [-h] [chemin]');
WriteLn;
WriteLn(' -h Ce parametre permet d''afficher l''aide sur cette commande');
WriteLn(' chemin Ce parametre permet d''indiquer le repertoire a mettre a la place.');
End
Else
If Length(FirstParam)>0Then Begin
If Not(PushDirectory(FExpand(FirstParam)))Then WriteLn('Pile pleine');
{$I-} ChDir(FirstParam);{$I+}
Error:=IoResult;
If Error<>0Then WriteLn('Impossible de changer de repertoire');
End
Else
Begin
GetDir(0,Dir);
If Not(PushDirectory(Dir))Then WriteLn('Pile pleine');
End;
End;

Procedure RehashCommand;Begin
Expand Down Expand Up @@ -250,11 +424,16 @@ Procedure UnknownCommand;Begin
End;

BEGIN
FillChar(History,SizeOf(History),0);
NumberHistory:=0;
FillChar(StackDirectory,SizeOf(StackDirectory),0);
NumberDirectory:=0;
Terminated:=False;
HomeMessage;
Repeat
ShowPrompt;
ReadLn(CmdStr);
AddHistory(CmdStr);
ExtractCommand;
CommandFound:=False;
For J:=Low(CommandList) to High(CommandList) do Begin
Expand Down
6 changes: 3 additions & 3 deletions SH.PAS
Original file line number Diff line number Diff line change
Expand Up @@ -1248,11 +1248,11 @@ Begin
K:=ReadKey;
Case K of
#0:Case ReadKey of
#72:Begin
#72:If NumberHistory>0 Then Begin
S:=History[CurrHistory]^; { Up }
If CurrHistory>1 Then Dec(CurrHistory);
End;
#80:Begin
#80:If NumberHistory>0 Then Begin
S:=History[CurrHistory]^; { Down }
If CurrHistory<NumberHistory Then Inc(CurrHistory);
End;
Expand Down Expand Up @@ -1385,4 +1385,4 @@ BEGIN
If Not(CommandFound)Then UnknownCommand;
Until Terminated;
End;
END.
END.

0 comments on commit 0253eb2

Please sign in to comment.