-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathCREF.PAS
More file actions
168 lines (155 loc) · 3.92 KB
/
Copy pathCREF.PAS
File metadata and controls
168 lines (155 loc) · 3.92 KB
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
{ @author: Sylvain Maltais (support@gladir.com)
@created: 2025
@website(https://www.gladir.com/msdos0)
@abstract(Target: Turbo Pascal 7, Free Pascal 3.2)
}
Program CREF;
Uses DOS;
Const
MAX_SYMBOLS=100;
MAX_REFS_PER_SYMBOL=50;
Type
TReference=Record
LineNumber:Word;
DefinedHere:Boolean;
End;
TSymbol=Record
Name:String[31];
RefCount:Integer;
References:Array[1..MAX_REFS_PER_SYMBOL] of TReference;
End;
Var
Symbols:Array[1..MAX_SYMBOLS] of TSymbol;
SymbolCount:Integer;
CRFFile,REFFile:Text;
CRFName,REFName:String;
Function AddSymbol(Const Name:String):Integer;
Var
i:Integer;
Begin
{ Rechercher si le symbole existe d‚j… }
For i:=1 to SymbolCount do If Symbols[i].Name=Name Then Begin
AddSymbol:=i;
Exit;
End;
{ Ajouter nouveau symbole }
If SymbolCount<MAX_SYMBOLS Then Begin
Inc(SymbolCount);
With Symbols[SymbolCount] do Begin
Name:=Name;
RefCount:=0;
End;
AddSymbol:=SymbolCount;
End
Else
AddSymbol:=0;
End;
Procedure AddReference(SymbolIndex:Integer;LineNum:Word;IsDefined:Boolean);Begin
With Symbols[SymbolIndex] do If RefCount < MAX_REFS_PER_SYMBOL Then Begin
Inc(RefCount);
References[RefCount].LineNumber:=LineNum;
References[RefCount].DefinedHere:=IsDefined;
End;
End;
Procedure SortSymbols;
Var
i,j:Integer;
Temp:TSymbol;
Begin
For i:=1 to SymbolCount-1 do For j:=i+1 to SymbolCount do
If Symbols[i].Name>Symbols[j].Name Then Begin
Temp:=Symbols[i];
Symbols[i]:=Symbols[j];
Symbols[j]:=Temp;
End;
End;
Procedure ProcessCRFFile;
Var
Line:String;
SymbolName:String;
LineNum:Word;
SymIndex:Integer;
IsDefined:Boolean;
Err:Word;
Begin
While Not Eof(CRFFile) do Begin
ReadLn(CRFFile,Line);
If Length(Line)>0 Then Begin
{ Format typique: SYMBOLE 0001:D 0002 0003 }
{ o— D indique une d‚finition }
SymbolName:=Copy(Line,1,Pos(' ',Line)-1);
SymIndex:=AddSymbol(SymbolName);
{ Traiter chaque r‚f‚rence sur la ligne }
While Length(Line)>0 do Begin
Line:=Copy(Line,Pos(' ',Line)+1,Length(Line));
If Length(Line)=0 Then Break;
IsDefined:=Pos('D',Line)>0;
Val(Copy(Line,1,4),LineNum,Err);
If SymIndex>0 Then AddReference(SymIndex,LineNum,IsDefined);
End;
End;
End;
End;
Procedure WriteREFFile;
Var
i,j:Integer;
Symbol:TSymbol;
Begin
WriteLn(REFFile, 'Liste de r‚f‚rence crois‚');
WriteLn(REFFile, '-------------------------');
WriteLn(REFFile);
For i:=1 to SymbolCount do Begin
Symbol:=Symbols[i];
Write(REFFile,Symbol.Name:20);
For j:=1 to Symbol.RefCount do With Symbol.References[j] do Begin
If DefinedHere Then Write(REFFile,' #',LineNumber:4)
Else Write(REFFile, ' ', LineNumber:4);
End;
WriteLn(REFFile);
End;
End;
BEGIN
If(ParamStr(1)='/?')or(ParamStr(1)='--help')or(ParamStr(1)='-h')or
(ParamStr(1)='/h')or(ParamStr(1)='/H')Then Begin
WriteLn('CREF - Cette commande permet de produire une liste de symboles crois‚s');
WriteLn;
WriteLn('Syntaxe : CREF crf_file[,ref_file]');
WriteLn;
WriteLn(' crf_file Fichier d''entr‚e (extension par d‚faut .CRF)');
WriteLn(' ref_file Fichier de sortie (extension par d‚faut .REF)');
Halt;
End;
{ Obtenir les noms de fichiers }
CRFName:=ParamStr(1);
If Pos('.',CRFName)=0 Then CRFName:=CRFName+'.CRF';
If ParamCount>1 Then REFName:=ParamStr(2)
Else REFName:=Copy(CRFName,1,Length(CRFName)-4)+'.REF';
{ Ouvrir les fichiers }
{$I-}
Assign(CRFFile, CRFName);
Reset(CRFFile);
If IOResult<>0 Then Begin
WriteLn('Erreur: Impossible d''ouvrir le fichier d''entr‚e');
Exit;
End;
Assign(REFFile,REFName);
Rewrite(REFFile);
If IOResult<>0 then Begin
WriteLn('Erreur: Impossible de cr‚er le fichier de sortie.');
Close(CRFFile);
Halt(1);
End;
{$I+}
{ Initialiser }
SymbolCount := 0;
{ Traiter le fichier CRF }
ProcessCRFFile;
{ Trier les symboles }
SortSymbols;
{ G‚n‚rer le fichier REF }
WriteREFFile;
{ Fermer les fichiers }
Close(CRFFile);
Close(REFFile);
WriteLn('R‚f‚rence crois‚ cr‚e : ', REFName);
END.