-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCPP.PAS
131 lines (122 loc) · 2.54 KB
/
CPP.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
121
122
123
124
125
126
127
128
129
130
131
{ @author: Sylvain Maltais ([email protected])
@created: 2021
@website(https://www.gladir.com/linux-0)
@abstract(Target: Turbo Pascal, Free Pascal)
}
Program CPP(Input,Output);
Type
StrPointer=^String;
Var
FileSource,FileTarget:Text;
P:StrPointer;
I,J:Integer;
CurrKey,CurrValue,S:String;
_Index:Integer;
K,V:Array[1..1000] of StrPointer;
Procedure PushKey(_Key,_Value:String);
Var
P:StrPointer;
Type
StrPointer=^String;
Begin
Inc(_Index);
GetMem(P,Length(_Key)+1);
P^:=_Key;
K[_Index]:=P;
GetMem(P,Length(_Value)+1);
P^:=_Value;
V[_Index]:=P;
WriteLn(_Key,'=',_Value,'!!!');
End;
Function FindValue(_Key:String):String;
Var
I:Integer;
Begin
FindValue:='';
If _Index=0Then Exit;
For I:=1 to _Index do Begin
If K[I]^=_Key Then Begin
FindValue:=V[I]^;
Exit;
End;
End;
End;
Function FindKey(_Name:String):String;
Var
I:Integer;
Begin
FindKey:='';
If _Index=0Then Exit;
For I:=1 to _Index do Begin
If V[I]^=_Name Then Begin
FindKey:=K[I]^;
Exit;
End;
End;
End;
BEGIN
If(ParamStr(1)='/?')or(ParamStr(1)='--help')or(ParamStr(1)='-h')Then Begin
WriteLn('CPP : Cette commande permet d''effectuer un traitement preprocesseur du langage de programmation C.');
WriteLn;
WriteLn('Syntaxe : CPP source.c target.c');
End
Else
If ParamCount>=1Then Begin
_Index:=0;
Assign(FileSource,ParamStr(1));
Reset(FileSource);
Assign(FileTarget,ParamStr(2));
Rewrite(FileTarget);
While Not EOF(FileSource) do Begin
I:=1;
ReadLn(FileSource,S);
While(I<=Length(S))do Begin
If Copy(S,I,7)='#define'Then Begin
J:=I+7;
CurrKey:='';
While J<=Length(S)do Begin
If S[J]in[' ',#9]Then Inc(J)
Else Break;
End;
While J<=Length(S)do Begin
If S[J]in['A'..'Z','a'..'z','0'..'9','_']Then Begin
CurrKey:=CurrKey+S[J];
Inc(J);
End
Else
Break;
CurrValue:=Copy(S,J+1,255);
End;
PushKey(CurrKey,CurrValue);
I:=Length(S)+1;
Break;
End
Else
If S[I]in['A'..'Z','a'..'z','_']Then Begin
J:=I+1;
CurrKey:=S[I];
While J<=Length(S)do Begin
If S[J]in['A'..'Z','a'..'z','0'..'9','_']Then Begin
CurrKey:=CurrKey+S[J];
Inc(J);
End
Else
Break;
End;
CurrValue:=FindValue(CurrKey);
If CurrValue<>''Then Write(FileTarget,CurrValue)
Else Write(FileTarget,CurrKey);
I:=J;
End
Else
Begin
Write(FileTarget,S[I]);
Inc(I);
End;
End;
WriteLn(FileTarget);
End;
Close(FileTarget);
Close(FileSource);
End;
END.