From 0253eb28122f70d71931ec8a2d021e5451d3b8d3 Mon Sep 17 00:00:00 2001 From: Sylvain Maltais Date: Sun, 14 Aug 2022 10:08:27 -0400 Subject: [PATCH] Correctif mineurs --- BASH.PAS | 4 +- CSH.PAS | 195 ++++++++++++++++++++++++++++++++++++++++++++++++++++--- SH.PAS | 6 +- 3 files changed, 192 insertions(+), 13 deletions(-) diff --git a/BASH.PAS b/BASH.PAS index f2a4188..b1b0c69 100644 --- a/BASH.PAS +++ b/BASH.PAS @@ -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=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; @@ -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'); @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/SH.PAS b/SH.PAS index a87d8f7..4af136b 100644 --- a/SH.PAS +++ b/SH.PAS @@ -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