-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathNL.PAS
120 lines (115 loc) · 3.17 KB
/
NL.PAS
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
{ @author: Sylvain Maltais ([email protected])
@created: 2023
@website(https://www.gladir.com/linux-0)
@abstract(Target: Turbo Pascal 7, Free Pascal 3.2)
}
Program NL;
Var
Mode:(_None,_Inc,_Start,_SepLine,_Number,_Width);
LineMode:(_ln,_rn,_rz);
SourceFile:Text;
FileName,CurrLine,SepLine:String;
IncLine,LineNumber:LongInt;
WidthNumber:Word;
I:Integer;
Err:Word;
Function PadRight(Value:Integer;Space:Byte):String;
Var
I:Byte;
S:String;
Begin
Str(Value,S);
If Length(S)<Space Then For I:=Length(S)+1 to Space do S:=S+' ';
PadRight:=S;
End;
Function PadZeroLeft(Value:Integer;Space:Byte):String;
Var
S:String;
Begin
Str(Value,S);
While Length(S)<Space do S:='0'+S;
PadZeroLeft:=S;
End;
BEGIN
If(ParamStr(1)='/?')or(ParamStr(1)='--help')or(ParamStr(1)='-h')or
(ParamStr(1)='/h')or(ParamStr(1)='/H')Then Begin
WriteLn('NL : Cette commande permet d''afficher du texte avec des ',
'num‚ros de ligne.');
WriteLn;
WriteLn('Syntaxe : NL fichier [parametres]');
WriteLn;
WriteLn(' fichier Nom du fichier … visualiser');
WriteLn(' -i Incr‚mentation en chaque ligne');
WriteLn(' -n [ln|rn|rz] Format du num‚ro de ligne');
WriteLn(' -s S‚parateur entre le num‚ro de ligne et la ligne');
WriteLn(' -v Num‚ro de ligne de d‚but');
WriteLn(' -w Largeur d''un num‚ro de ligne');
WriteLn;
End
Else
Begin
Mode:=_None;
LineMode:=_rn;
SepLine:=' ';
WidthNumber:=6;
IncLine:=1;
LineNumber:=1;
For I:=1 to ParamCount do Begin
Case(Mode)of
_Inc:Begin
Val(ParamStr(I),IncLine,Err);
Mode:=_None;
End;
_Number:Begin
If ParamStr(I)='ln'Then LineMode:=_ln Else
If ParamStr(I)='rn'Then LineMode:=_rn Else
If ParamStr(I)='rz'Then LineMode:=_rz;
Mode:=_None;
End;
_SepLine:Begin
SepLine:=ParamStr(I);
Mode:=_None;
End;
_Start:Begin
Val(ParamStr(I),LineNumber,Err);
Mode:=_None;
End;
_Width:Begin
Val(ParamStr(I),WidthNumber,Err);
Mode:=_None;
End;
Else Begin
If ParamStr(I)='-w'Then Mode:=_Width Else
If(ParamStr(I)='-v')or
(ParamStr(I)='--starting-line-number')Then Mode:=_Start Else
If(ParamStr(I)='-s')or
(ParamStr(I)='--number-separator')Then Mode:=_SepLine Else
If ParamStr(I)='-n'Then Mode:=_Number Else
If ParamStr(I)='-i'Then Mode:=_Inc Else
If(Copy(ParamStr(I),1,Length('--number-separator='))='--number-separator=')Then Begin
SepLine:=Copy(ParamStr(I),Length('--number-separator=')+1,255);
End
Else
If(Copy(ParamStr(I),1,Length('--starting-line-number='))='--starting-line-number=')Then Begin
Val(Copy(ParamStr(I),Length('--starting-line-number=')+1,255),LineNumber,Err);
End
Else
FileName:=ParamStr(I);
End;
End;
End;
{$I-}Assign(SourceFile,FileName);
Reset(SourceFile);{$I-}
While Not EOF(SourceFile)do Begin
ReadLn(SourceFile,CurrLine);
Case LineMode of
_ln: Write(PadRight(LineNumber,WidthNumber));
_rz: Write(PadZeroLeft(LineNumber,WidthNumber));
Else Write(LineNumber:WidthNumber);
End;
WriteLn(SepLine,CurrLine);
Inc(LineNumber,IncLine);
End;
Close(SourceFile);
End;
END.