-
Notifications
You must be signed in to change notification settings - Fork 5
/
CALCMACR.PAS
221 lines (205 loc) · 4.69 KB
/
CALCMACR.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
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
{ Cette unit‚ est destin‚ a effectu‚ l'ex‚cution de diff‚rentes Macro du
programme de dessin en Bitmap.
}
Unit CalcMacr{o};
INTERFACE
Uses Systex,Isatex;
Function SCChoiceMacro(Var Q:SuperCalcApp):SmallInt;
Function SCRunMacro(Var Q:SuperCalcApp;Const FileName:String):SmallInt;
Function SCExecMacro(Var Q:SuperCalcApp;Var List:ArrayList):SmallInt;
IMPLEMENTATION
Uses
Dialex,Restex,Memories,Math,Systems,ResServD,
Dials,DialPlus,MalCalc,SysPlus;
Procedure SkipSpc(Var I:Word;PC:PChr);Near;Assembler;ASM
{While PC^[I]in[#9,' ']do Inc(I);}
LES DI,I
MOV BX,ES:[DI]
LES DI,PC
DEC BX
@1:
INC BX
CMP Byte Ptr ES:[DI+BX],9
JE @1
CMP Byte Ptr ES:[DI+BX],' '
JE @1
LES DI,I
MOV ES:[DI],BX
END;
Function SCExecMacro(Var Q:SuperCalcApp;Var List:ArrayList):SmallInt;
Label
InvalidParam,Xit;
Var
LenParam:Byte;
CurrAttr:Byte;
I:SmallInt;
J:Word;
Len:Word;
SP:Byte; { Position de chaŒne de caractŠres }
JP:Integer; { Compteur de paramŠtres }
IP:Word; { Position de variable }
PC:PChr;
PCel:PCellule;
V:Array[0..7]of Variant;
Instr:DataSetInMemory;
S,S2:String;
Param:^String; { ParamŠtres }
Procedure SkipSpcInLine;Begin
While PC^[J]=' 'do Inc(J);
End;
Function XtrkWord:String;Begin
SkipSpcInLine;
XtrkWord:=StrUp(PXtrkWord(J,PC));
End;
Function XtrkNumber(Var N:Variant):Boolean;
Var
F:FormulaObject;
Begin
SkipSpcInLine;
FOInit(F);
F.Option:=[foNumberBasic,foExpBasic];
F.StopChar:=[',',':',';','''','<','=','>'];
{ F.OnWord:=LogoFormuleOnWord;
F.Context:=@Q;}
F.I:=J+1;
If FOCompute(F,StrPas(PC))Then Begin
N:=F.Result;
J:=F.I-1;
XtrkNumber:=True;
End
Else
XtrkNumber:=False;
End;
Function _Str2S(Var S:String):Boolean;
Label 0;
Var
ST:String;
Begin
_Str2S:=False;ST:='';
0:SkipSpc(J,PC);
If PC^[J]='"'Then Begin
Inc(J);
While Not(PC^[J]in[#0,'"'])do Begin
IncStr(ST,PC^[J]);
Inc(J)
End;
Inc(J)
End
Else
Begin
XtrkNumber(V[0]);
Str(VariantToReal(V[0]):0:0,ST);
End;
SkipSpc(J,PC);
If PC^[J]in['&','+']Then Begin
Inc(J);
Goto 0;
End;
S:=ST;
_Str2S:=True;
End;
Begin
SCExecMacro:=0;
CurrAttr:=CurrKrs.Dialog.Env.List.Border;
DBOpenServerName(ChantalServer,'CHANTAL:/Compilateur/Basic/Instruction.Dat');
If DBCopyToMemory(ChantalServer,Instr)Then Begin
ALSetPtr(List,0);
I:=0;
While I<=List.Count-1do Begin
PC:=_ALGetCurrBuf(List);
J:=0;
If(PC<>NIL)Then Begin
While PC^[J]<>#0do Begin
S:=XtrkWord;
If DBLocateAbsIM(Instr,2,S,[])Then Begin
Param:=Pointer(Instr.CurrRec);
_DBGotoColumnAbs(Instr.FieldRec,3,Pointer(Param));
IP:=0;SP:=0;LenParam:=Length(Param^);
For JP:=1to(LenParam)do Begin
ASM
INC Word Ptr Param
END;
Case Param^[0]of
#0:Break;
'I':Begin
If Not XtrkNumber(V[IP])Then Goto Xit;
Inc(IP);
If IP>7Then Break;
End;
'S':Begin
Case(SP)of
1:If Not _Str2S(S2)Then Goto Xit;
Else If Not _Str2S(S)Then Goto Xit;
End;
Inc(SP);
End;
Else Begin
SkipSpc(J,PC);
If PC^[J]<>Param^[0]Then Begin
Case Param^[0]of
'(':SCExecMacro:=OpenParExpected;
',':SCExecMacro:=VirguleExpected;
')':SCExecMacro:=CloseParExpected;
'-':SCExecMacro:=MinusExpected;
Else SCExecMacro:=SyntaxError;
End;
InvalidParam:
ErrMsgOk('ParamŠtre invalide … la ligne '+WordToStr(I+1));
Goto Xit;
End;
Inc(J);
End;
End;
End;
Case(Instr.CurrRec.Byte^)of
$01:Begin{ATTR}
PCel:=SCGetCurrCellule(Q);
CurrAttr:=V[0].X.DataWord+(V[1].X.DataWord shl 4);
If(PCel<>NIL)Then PCel^.Header.Attribut:=CurrAttr;
End;
$40:Begin{PRINT}
If Not _Str2S(S)Then Goto InvalidParam;
SCPushData(Q,S);
PCel:=SCGetCurrCellule(Q);
If(PCel<>NIL)Then PCel^.Header.Attribut:=CurrAttr;
SCDn(Q);
End;
Else Begin
ErrMsgOk('Erreur … la ligne '+WordToStr(I+1));
Goto Xit;
End;
End;
End
Else
Begin
ErrMsgOk('Instruction inconnu … la ligne '+WordToStr(I+1));
Goto Xit;
End;
End;
End;
Inc(I);
ALNext(List);
End;
End
Else
__OutOfMemory;
Xit:
End;
Function SCRunMacro(Var Q:SuperCalcApp;Const FileName:String):SmallInt;
Var
L:ArrayList;
Begin
If ALLoadFileASCII(L,FileName)Then Begin
SCRunMacro:=SCExecMacro(Q,L);
ALDone(L);
End;
End;
Function SCChoiceMacro(Var Q:SuperCalcApp):SmallInt;
Var
S:String;
Begin
SCChoiceMacro:=0;
S:=OpenWin('*.BAS','Ex‚cute Macro');
If S<>''Then SCChoiceMacro:=SCRunMacro(Q,S);
End;
END.