Develop and Download Open Source Software

Browse Subversion Repository

Contents of /chain.pas

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (show annotations) (download) (as text)
Mon Nov 7 12:03:00 2011 UTC (12 years, 4 months ago) by shiraishikazuo
File MIME type: text/x-pascal
File size: 5891 byte(s)


1 unit chain;
2
3 {$IFDEF FPC}
4 {$MODE DELPHI}{$H+}
5 {$ENDIF}
6
7 interface
8
9 implementation
10 uses
11 SysUtils, Forms, Process,
12 listcoll,base,base0,variabl,struct,express,
13 helpctex,texthand,control,sconsts,statemen;
14
15
16 function ShellExec(s1,s2:string; opWaitFor:boolean):boolean;
17 var
18 AProcess: TProcess;
19 begin
20 result:=false;
21 AProcess := TProcess.Create(nil);
22 AProcess.CommandLine :=s1 + ' ' +s2;
23 if opWaitFor then
24 AProcess.Options := AProcess.Options + [poWaitOnExit];
25 try
26 try
27 AProcess.Execute;
28 result:=true;
29 finally
30 AProcess.Free;
31 end;
32 except
33 end;
34 end;
35
36 type
37 TEXECUTE=class(TStatement)
38 exp1:TPrincipal;
39 params:TListCollection;
40 opWaitFor:boolean;
41 ChainSt:boolean;
42
43 constructor create(prev,eld:TStatement; opWaitFor0:boolean);
44 //procedure exec;override;
45 destructor destroy;override;
46 function Code:ansistring;override;
47 end;
48
49
50 constructor TEXECUTE.create(prev,eld:TStatement; opWaitFor0:boolean);
51 begin
52 inherited create(prev,eld);
53 opWaitFor:=opWaitFor0;
54 if token='NOWAIT' then
55 begin opWaitFor:=false; gettoken end;
56 exp1:=SExpression;
57 params:=TListCollection.create;
58 if token='WITH' then
59 begin
60 gettoken;
61 check('(',IDH_CHAIN);
62 repeat
63 params.insert(article);
64 until test(',')=false;
65 check(')',IDH_CHAIN);
66 end;
67 end;
68
69 destructor TEXECUTE.destroy;
70 begin
71 exp1.free;
72 params.free;
73 inherited destroy;
74 end;
75 (*
76 procedure TEXECUTE.exec;
77 var
78 s1,s2,s:AnsiString;
79 i:integer;
80 ToChain:boolean;
81 begin
82 ToChain:=Chainst;
83 s1:=exp1.evalS;
84 s2:='';
85 if not FileExists(s1) and (ExtractFileExt(s1)='') then
86 s1:=s1 + BASExt;
87 if not FileExists(s1) then
88 begin
89 s:=ExtractFilePath(Application.ExeName)+s1;
90 if FileExists(s) then
91 s1:=s
92 else
93 s1:=FileSearch(s1,GetEnvironmentVariable('PATH'))
94 ;
95 end;
96 if (s1<>'') and FileExists(s1) then
97 begin
98 if (ExtractFileExt(s1)=BASExt) then
99 begin
100 s2:=s1;
101 s1:=Application.ExeName;
102 end
103 else
104 ToChain:=false;
105 i:=0;
106 if ToChain then
107 begin
108 ChainFile:=s2;
109 with params do
110 while i<count do
111 begin
112 ChainParams.Add(TPrincipal(items[i]).str);
113 inc(i)
114 end;
115 end
116 else
117 begin
118 if s2<>'' then
119 s2:=AnsiQuotedStr(s2,'"')+' ';
120 with params do
121 while i<count do
122 begin
123 s2:=s2 + TPrincipal(items[i]).str2 +' ' ;
124 inc(i)
125 end;
126 s2:=TrimRight(s2);
127 if ShellExec(PChar(s1),PChar(s2),opWaitFor) then
128 else
129 setexception(10005);
130 end;
131 end
132 else
133 setexception(10005);
134 end;
135 *)
136 function EXECUTEst(prev,eld:TStatement):TStatement;
137 begin
138 EXECUTEst:=TEXECUTE.CREATE(prev,eld, true);
139 end;
140
141 type
142 TCHAIN=class(TEXECUTE)
143 constructor create(prev,eld:TStatement);
144 //procedure exec;override;
145 end;
146
147 function CHAINst(prev,eld:TStatement):TStatement;
148 begin
149 CHAINst:=TCHAIN.CREATE(prev,eld);
150 end;
151
152 constructor TCHAIN.create(prev,eld:TStatement);
153 begin
154 inherited create(prev,eld,false);
155 Chainst:=true;
156 end;
157 (*
158 procedure TCHAIN.exec;
159 begin
160 inherited exec ;
161 raise EStop.create;
162 end;
163 *)
164 function TExecute.Code:ansistring;
165 var
166 i:integer;
167 s2:string;
168 begin
169 s2:='';
170 with params do
171 for i:=0 to Count-1 do
172 begin
173 if i>0 then s2:=s2+',';
174 s2:=s2+TPrincipal(items[i]).code
175 end;
176 result:='ShellExec('+exp1.code+',['+s2+']'+','+TruthLiteral(opWaitfor) +');';
177 if chainst then
178 result:=result+'raise ESTOP.create;';
179 end;
180
181 type
182 TPlay=Class(TExecute)
183 function code:ansistring;override;
184 end;
185
186 function TPlay.code:ansistring;
187 begin
188 result:='Play(' + exp1.code + ',' + TruthLiteral(opWaitfor) +');';
189 end;
190
191 function PLAYst(prev,eld:TStatement):TStatement;far;
192 begin
193 PLAYst:=TPlay.CREATE(prev,eld,true);
194 end;
195
196
197 {*********}
198 {PLAYSOUND}
199 {*********}
200 {$IFDEF WINDOWS}
201 type
202 TPlaySound=class(TStatement)
203 exp1:TPrincipal;
204 Async:boolean;
205 constructor create(prev,eld:TStatement);
206 destructor destroy;override;
207 function Code:ansistring;override;
208 end;
209
210 constructor TPlaySound.create(prev,eld:TStatement);
211 begin
212 inherited create(prev, eld);
213 exp1:=SExpression;
214 if test(',') then
215 begin
216 CheckToken('ASYNC',IDH_EXTENSION_MS);
217 Async:=true
218 end;
219 end;
220
221 destructor TPlaySound.destroy;
222 begin
223 exp1.Free;
224 inherited destroy;
225 end;
226
227
228 function TPlaySound.Code:ansistring;
229 begin
230 result:='PlaySound('+ exp1.code +',' +TruthLiteral(async) +');'
231 end;
232
233 function PLAYSOUNDst(prev,eld:TStatement):TStatement;far;
234 begin
235 PLAYSoundst:=TPLAYSOUND.CREATE(prev,eld);
236 end;
237 {$ENDIF}
238
239 {*************}
240 {registeration}
241 {*************}
242
243 procedure statementTableinit;
244 begin
245 StatementTableInitImperative('CHAIN',CHAINst);
246 StatementTableInitImperative('EXECUTE',EXECUTEst);
247 {$IFDEF WINDOWS}
248 StatementTableInitImperative('PLAY',PLAYst);
249 StatementTableInitImperative('PLAYSOUND',PLAYSOUNDst);
250 //StatementTableInitImperative('ASSOC',ASSOCPRINTst);
251 {$ENDIF}
252 end;
253
254 procedure functiontableInit;
255 begin
256 end;
257
258
259 begin
260 tableInitProcs.accept(statementTableinit);
261 tableInitProcs.accept(FunctionTableInit);
262 end.

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26