fptools.pas 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744
  1. {
  2. $Id$
  3. This file is part of the Free Pascal Integrated Development Environment
  4. Copyright (c) 1998 by Berczi Gabor
  5. Tool support for the IDE
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. unit FPTools;
  13. interface
  14. uses Objects,Drivers,Dialogs,Validate,
  15. FPViews;
  16. type
  17. PTool = ^TTool;
  18. TTool = object(TObject)
  19. constructor Init(const ATitle, AProgramPath, ACommandLine: string; AHotKey: word);
  20. function GetTitle: string; virtual;
  21. procedure GetParams(var ATitle, AProgramPath, ACommandLine: string; var AHotKey: word); virtual;
  22. procedure SetParams(const ATitle, AProgramPath, ACommandLine: string; const AHotKey: word); virtual;
  23. destructor Done; virtual;
  24. private
  25. Title : PString;
  26. ProgramPath : PString;
  27. CommandLine : PString;
  28. HotKey : word;
  29. end;
  30. PToolCollection = ^TToolCollection;
  31. TToolCollection = object(TCollection)
  32. function At(Index: sw_Integer): PTool;
  33. end;
  34. PToolListBox = ^TToolListBox;
  35. TToolListBox = object(TAdvancedListBox)
  36. function GetText(Item: sw_integer; MaxLen: Integer): String; virtual;
  37. end;
  38. PToolParamValidator = ^TToolParamValidator;
  39. TToolParamValidator = object(TValidator)
  40. function IsValid(const S: string): Boolean; virtual;
  41. procedure Error; virtual;
  42. private
  43. ErrorPos: integer;
  44. end;
  45. PToolItemDialog = ^TToolItemDialog;
  46. TToolItemDialog = object(TCenterDialog)
  47. constructor Init(ATool: PTool);
  48. function Execute: Word; virtual;
  49. private
  50. Tool : PTool;
  51. TitleIL : PInputLine;
  52. ProgramIL: PInputLine;
  53. ParamIL : PInputLine;
  54. HotKeyRB : PRadioButtons;
  55. end;
  56. PToolsDialog = ^TToolsDialog;
  57. TToolsDialog = object(TCenterDialog)
  58. constructor Init;
  59. function Execute: Word; virtual;
  60. procedure HandleEvent(var Event: TEvent); virtual;
  61. private
  62. ToolsLB : PToolListBox;
  63. procedure Add;
  64. procedure Edit;
  65. procedure Delete;
  66. end;
  67. procedure InitTools;
  68. function GetToolCount: integer;
  69. function GetToolName(Idx: integer): string;
  70. function AddTool(Title, ProgramPath, Params: string; HotKey: word): integer;
  71. procedure GetToolParams(Idx: integer; var Title, ProgramPath, Params: string; var HotKey: word);
  72. procedure SetToolParams(Idx: integer; Title, ProgramPath, Params: string; HotKey: word);
  73. procedure DoneTools;
  74. function GetHotKeyName(Key: word): string;
  75. function ParseToolParams(var Params: string; CheckOnly: boolean): integer;
  76. implementation
  77. uses Dos,
  78. Commands,Views,App,MsgBox,
  79. FPConst,FPVars,FPUtils;
  80. type
  81. THotKeyDef = record
  82. Name : string[12];
  83. KeyCode : word;
  84. end;
  85. const
  86. HotKeys : array[0..9] of THotKeyDef =
  87. ( (Name : '~U~nassigned' ; KeyCode : kbNoKey ),
  88. (Name : 'Shift+F~2~' ; KeyCode : kbShiftF2 ),
  89. (Name : 'Shift+F~3~' ; KeyCode : kbShiftF3 ),
  90. (Name : 'Shift+F~4~' ; KeyCode : kbShiftF4 ),
  91. (Name : 'Shift+F~5~' ; KeyCode : kbShiftF5 ),
  92. (Name : 'Shift+F~6~' ; KeyCode : kbShiftF6 ),
  93. (Name : 'Shift+F~7~' ; KeyCode : kbShiftF7 ),
  94. (Name : 'Shift+F~8~' ; KeyCode : kbShiftF8 ),
  95. (Name : 'Shift+F~9~' ; KeyCode : kbShiftF9 ),
  96. (Name : 'Shift+F~1~0' ; KeyCode : kbShiftF10));
  97. Tools : PToolCollection = nil;
  98. function GetHotKeyCount: integer;
  99. begin
  100. GetHotKeyCount:=ord(High(HotKeys))-ord(Low(HotKeys))+1;
  101. end;
  102. function GetHotKeyNameByIdx(Idx: integer): string;
  103. begin
  104. GetHotKeyNameByIdx:=HotKeys[Idx].Name;
  105. end;
  106. function HotKeyToIdx(Key: word): integer;
  107. var Count,I: integer;
  108. Found: boolean;
  109. begin
  110. Count:=GetHotKeyCount; Found:=false;
  111. I:=0;
  112. while (I<Count) and (Found=false) do
  113. begin
  114. Found:=HotKeys[I].KeyCode=Key;
  115. if Found=false then
  116. Inc(I);
  117. end;
  118. if Found=false then I:=-1;
  119. HotKeyToIdx:=I;
  120. end;
  121. function IdxToHotKey(Idx: integer): word;
  122. var Count: integer;
  123. Key: word;
  124. begin
  125. Count:=GetHotKeyCount;
  126. if (0<=Idx) and (Idx<Count) then
  127. Key:=HotKeys[Idx].KeyCode
  128. else
  129. Key:=kbNoKey;
  130. IdxToHotKey:=Key;
  131. end;
  132. function GetHotKeyName(Key: word): string;
  133. var Idx: integer;
  134. S: string;
  135. begin
  136. Idx:=HotKeyToIdx(Key);
  137. if Idx=0 then S:='' else
  138. if Idx=-1 then S:='???' else
  139. S:=GetHotKeyNameByIdx(Idx);
  140. GetHotKeyName:=S;
  141. end;
  142. constructor TTool.Init(const ATitle, AProgramPath, ACommandLine: string; AHotKey: word);
  143. begin
  144. inherited Init;
  145. SetParams(ATitle,AProgramPath,ACommandLine,AHotKey);
  146. end;
  147. function TTool.GetTitle: string;
  148. begin
  149. GetTitle:=KillTilde(GetStr(Title));
  150. end;
  151. procedure TTool.GetParams(var ATitle, AProgramPath, ACommandLine: string; var AHotKey: word);
  152. begin
  153. ATitle:=GetStr(Title); AProgramPath:=GetStr(ProgramPath);
  154. ACommandLine:=GetStr(CommandLine);
  155. AHotKey:=HotKey;
  156. end;
  157. procedure TTool.SetParams(const ATitle, AProgramPath, ACommandLine: string; const AHotKey: word);
  158. begin
  159. if Title<>nil then DisposeStr(Title); Title:=nil;
  160. if ProgramPath<>nil then DisposeStr(ProgramPath); ProgramPath:=nil;
  161. if CommandLine<>nil then DisposeStr(CommandLine); CommandLine:=nil;
  162. Title:=NewStr(ATitle); ProgramPath:=NewStr(AProgramPath);
  163. CommandLine:=NewStr(ACommandLine);
  164. HotKey:=AHotKey;
  165. end;
  166. destructor TTool.Done;
  167. begin
  168. inherited Done;
  169. if Title<>nil then DisposeStr(Title);
  170. if ProgramPath<>nil then DisposeStr(ProgramPath);
  171. if CommandLine<>nil then DisposeStr(CommandLine);
  172. end;
  173. function TToolCollection.At(Index: sw_Integer): PTool;
  174. begin
  175. At:=inherited At(Index);
  176. end;
  177. function TToolListBox.GetText(Item: sw_integer; MaxLen: Integer): String;
  178. var S: string;
  179. P: PTool;
  180. begin
  181. P:=List^.At(Item);
  182. S:=P^.GetTitle;
  183. GetText:=copy(S,1,MaxLen);
  184. end;
  185. procedure InitTools;
  186. begin
  187. if Tools<>nil then DoneTools;
  188. New(Tools, Init(10,20));
  189. end;
  190. function GetToolCount: integer;
  191. var Count: integer;
  192. begin
  193. if Tools=nil then Count:=0 else
  194. Count:=Tools^.Count;
  195. GetToolCount:=Count;
  196. end;
  197. function GetToolName(Idx: integer): string;
  198. var S1,S2: string;
  199. W: word;
  200. begin
  201. GetToolParams(Idx,S1,S2,S2,W);
  202. GetToolName:=KillTilde(S1);
  203. end;
  204. function AddTool(Title, ProgramPath, Params: string; HotKey: word): integer;
  205. var P: PTool;
  206. begin
  207. if Tools=nil then InitTools;
  208. New(P, Init(Title,ProgramPath,Params,HotKey));
  209. Tools^.Insert(P);
  210. AddTool:=Tools^.IndexOf(P);
  211. end;
  212. procedure GetToolParams(Idx: integer; var Title, ProgramPath, Params: string; var HotKey: word);
  213. var P: PTool;
  214. begin
  215. P:=Tools^.At(Idx);
  216. P^.GetParams(Title,ProgramPath,Params,HotKey);
  217. end;
  218. procedure SetToolParams(Idx: integer; Title, ProgramPath, Params: string; HotKey: word);
  219. var P: PTool;
  220. begin
  221. P:=Tools^.At(Idx);
  222. P^.GetParams(Title,ProgramPath,Params,HotKey);
  223. end;
  224. procedure DoneTools;
  225. begin
  226. if Tools<>nil then Dispose(Tools, Done); Tools:=nil;
  227. end;
  228. procedure TToolParamValidator.Error;
  229. begin
  230. MsgParms[1].Long:=ErrorPos;
  231. ErrorBox(^C'Error parsing parameters line at line position %d.',@MsgParms);
  232. end;
  233. function TToolParamValidator.IsValid(const S: string): Boolean;
  234. var P: string;
  235. begin
  236. P:=S;
  237. ErrorPos:=ParseToolParams(P,true);
  238. IsValid:=ErrorPos=0;
  239. end;
  240. constructor TToolItemDialog.Init(ATool: PTool);
  241. var R,R2,R3: TRect;
  242. Items: PSItem;
  243. I: integer;
  244. KeyCount: integer;
  245. begin
  246. KeyCount:=GetHotKeyCount;
  247. R.Assign(0,0,60,Max(3+KeyCount,12));
  248. inherited Init(R,'Modify/New Tool');
  249. Tool:=ATool;
  250. GetExtent(R); R.Grow(-3,-2); R3.Copy(R);
  251. Inc(R.A.Y); R.B.Y:=R.A.Y+1; R.B.X:=R.A.X+36;
  252. New(TitleIL, Init(R, 128)); Insert(TitleIL);
  253. R2.Copy(R); R2.Move(-1,-1); Insert(New(PLabel, Init(R2, '~T~itle', TitleIL)));
  254. R.Move(0,3);
  255. New(ProgramIL, Init(R, 128)); Insert(ProgramIL);
  256. R2.Copy(R); R2.Move(-1,-1); Insert(New(PLabel, Init(R2, 'Program ~p~ath', ProgramIL)));
  257. R.Move(0,3);
  258. New(ParamIL, Init(R, 128)); Insert(ParamIL);
  259. ParamIL^.SetValidator(New(PToolParamValidator, Init));
  260. R2.Copy(R); R2.Move(-1,-1); Insert(New(PLabel, Init(R2, 'Command ~l~ine', ParamIL)));
  261. R.Copy(R3); Inc(R.A.X,38); R.B.Y:=R.A.Y+KeyCount;
  262. Items:=nil;
  263. for I:=KeyCount-1 downto 0 do
  264. Items:=NewSItem(GetHotKeyNameByIdx(I), Items);
  265. New(HotKeyRB, Init(R, Items));
  266. Insert(HotKeyRB);
  267. InsertButtons(@Self);
  268. TitleIL^.Select;
  269. end;
  270. function TToolItemDialog.Execute: Word;
  271. var R: word;
  272. S1,S2,S3: string;
  273. W: word;
  274. L: longint;
  275. begin
  276. Tool^.GetParams(S1,S2,S3,W);
  277. TitleIL^.SetData(S1); ProgramIL^.SetData(S2); ParamIL^.SetData(S3);
  278. L:=HotKeyToIdx(W); if L=-1 then L:=255;
  279. HotKeyRB^.SetData(L);
  280. R:=inherited Execute;
  281. if R=cmOK then
  282. begin
  283. TitleIL^.GetData(S1); ProgramIL^.GetData(S2); ParamIL^.GetData(S3);
  284. HotKeyRB^.GetData(L); W:=IdxToHotKey(L);
  285. Tool^.SetParams(S1,S2,S3,W);
  286. end;
  287. Execute:=R;
  288. end;
  289. constructor TToolsDialog.Init;
  290. var R,R2,R3: TRect;
  291. SB: PScrollBar;
  292. begin
  293. R.Assign(0,0,46,16);
  294. inherited Init(R,'Tools');
  295. GetExtent(R); R.Grow(-3,-2); Inc(R.A.Y); R3.Copy(R); Dec(R.B.X,12);
  296. R2.Copy(R); R2.Move(1,0); R2.A.X:=R2.B.X-1;
  297. New(SB, Init(R2)); Insert(SB);
  298. New(ToolsLB, Init(R,1,SB));
  299. Insert(ToolsLB);
  300. R2.Copy(R); R2.Move(0,-1); R2.B.Y:=R2.A.Y+1; Dec(R2.A.X);
  301. Insert(New(PLabel, Init(R2, '~P~rogram titles', ToolsLB)));
  302. R.Copy(R3); R.A.X:=R.B.X-10; R.B.Y:=R.A.Y+2;
  303. Insert(New(PButton, Init(R, 'O~K~', cmOK, bfNormal)));
  304. R.Move(0,2);
  305. Insert(New(PButton, Init(R, '~E~dit', cmEditItem, bfDefault)));
  306. R.Move(0,2);
  307. Insert(New(PButton, Init(R, '~N~ew', cmAddItem, bfNormal)));
  308. R.Move(0,2);
  309. Insert(New(PButton, Init(R, '~D~elete', cmDeleteItem, bfNormal)));
  310. R.Move(0,2);
  311. Insert(New(PButton, Init(R, 'Cancel', cmCancel, bfNormal)));
  312. SelectNext(false);
  313. end;
  314. procedure TToolsDialog.HandleEvent(var Event: TEvent);
  315. var DontClear: boolean;
  316. begin
  317. case Event.What of
  318. evKeyDown :
  319. begin
  320. DontClear:=false;
  321. case Event.KeyCode of
  322. kbIns :
  323. Message(@Self,evCommand,cmAddItem,nil);
  324. kbDel :
  325. Message(@Self,evCommand,cmDeleteItem,nil);
  326. else DontClear:=true;
  327. end;
  328. if DontClear=false then ClearEvent(Event);
  329. end;
  330. evBroadcast :
  331. case Event.Command of
  332. cmListItemSelected :
  333. if Event.InfoPtr=pointer(ToolsLB) then
  334. Message(@Self,evCommand,cmEditItem,nil);
  335. end;
  336. evCommand :
  337. begin
  338. DontClear:=false;
  339. case Event.Command of
  340. cmAddItem : Add;
  341. cmDeleteItem : Delete;
  342. cmEditItem : Edit;
  343. else DontClear:=true;
  344. end;
  345. if DontClear=false then ClearEvent(Event);
  346. end;
  347. end;
  348. inherited HandleEvent(Event);
  349. end;
  350. function TToolsDialog.Execute: Word;
  351. var R: word;
  352. C: PToolCollection;
  353. I: integer;
  354. S1,S2,S3: string;
  355. W: word;
  356. begin
  357. New(C, Init(10,20));
  358. if Tools<>nil then
  359. for I:=0 to Tools^.Count-1 do
  360. begin
  361. Tools^.At(I)^.GetParams(S1,S2,S3,W);
  362. C^.Insert(New(PTool, Init(S1,S2,S3,W)));
  363. end;
  364. ToolsLB^.NewList(C);
  365. R:=inherited Execute;
  366. if R=cmOK then
  367. begin
  368. if Tools<>nil then Dispose(Tools, Done);
  369. Tools:=C;
  370. Message(Application,evBroadcast,cmUpdateTools,nil);
  371. end
  372. else
  373. Dispose(C, Done);
  374. Execute:=R;
  375. end;
  376. procedure TToolsDialog.Add;
  377. var P: PTool;
  378. IC: boolean;
  379. S1,S2,S3: string;
  380. W: word;
  381. begin
  382. if ToolsLB^.Range>=MaxToolCount then
  383. begin InformationBox(^C'Can''t install more tools...',nil); Exit; end;
  384. IC:=ToolsLB^.Range=0;
  385. if IC=false then
  386. begin
  387. P:=ToolsLB^.List^.At(ToolsLB^.Focused);
  388. P^.GetParams(S1,S2,S3,W);
  389. end
  390. else
  391. begin
  392. S1:=''; S2:=''; S3:=''; W:=0;
  393. end;
  394. New(P, Init(S1,S2,S3,W));
  395. if Application^.ExecuteDialog(New(PToolItemDialog, Init(P)), nil)=cmOK then
  396. begin
  397. ToolsLB^.List^.Insert(P);
  398. ToolsLB^.SetRange(ToolsLB^.List^.Count);
  399. ReDraw;
  400. end
  401. else
  402. Dispose(P, Done);
  403. end;
  404. procedure TToolsDialog.Edit;
  405. var P: PTool;
  406. begin
  407. if ToolsLB^.Range=0 then Exit;
  408. P:=ToolsLB^.List^.At(ToolsLB^.Focused);
  409. Application^.ExecuteDialog(New(PToolItemDialog, Init(P)), nil);
  410. ReDraw;
  411. end;
  412. procedure TToolsDialog.Delete;
  413. begin
  414. if ToolsLB^.Range=0 then Exit;
  415. ToolsLB^.List^.AtFree(ToolsLB^.Focused);
  416. ToolsLB^.SetRange(ToolsLB^.List^.Count);
  417. ReDraw;
  418. end;
  419. procedure ReplaceStr(var S: string; const What,NewS: string);
  420. var I : integer;
  421. begin
  422. repeat
  423. I:=Pos(What,S);
  424. if I>0 then
  425. begin
  426. Delete(S,I,length(What));
  427. Insert(NewS,S,I);
  428. end;
  429. until I=0;
  430. end;
  431. procedure ReplaceStrI(var S: string; What: string; const NewS: string);
  432. var I : integer;
  433. UpcaseS: string;
  434. begin
  435. UpcaseS:=UpcaseStr(S); What:=UpcaseStr(What);
  436. repeat
  437. I:=Pos(What,UpcaseS);
  438. if I>0 then
  439. begin
  440. Delete(S,I,length(What));
  441. Insert(NewS,S,I);
  442. end;
  443. until I=0;
  444. end;
  445. function ParseToolParams(var Params: string; CheckOnly: boolean): integer;
  446. var Err: integer;
  447. W: PSourceWindow;
  448. procedure ParseParams(Pass: integer);
  449. var I: integer;
  450. function IsAlpha(Ch: char): boolean;
  451. begin
  452. IsAlpha:=(Upcase(Ch) in['A'..'Z','_','$']);
  453. end;
  454. function ReplacePart(StartP,EndP: integer; const S: string): integer;
  455. begin
  456. Params:=copy(Params,1,StartP-1)+S+copy(Params,EndP+1,255);
  457. ReplacePart:=length(S)-(EndP-StartP+1);
  458. end;
  459. function Consume(Ch: char): boolean;
  460. var OK: boolean;
  461. begin
  462. OK:=Params[I]=Ch;
  463. if OK then Inc(I);
  464. Consume:=OK;
  465. end;
  466. function ReadTill(var S: string; C: char): boolean;
  467. var Found: boolean;
  468. begin
  469. Found:=false; S:='';
  470. while (I<=length(Params)) and (Found=false) do
  471. begin
  472. Found:=Params[I]=C;
  473. if Found=false then
  474. begin
  475. S:=S+Params[I];
  476. Inc(I);
  477. end;
  478. end;
  479. ReadTill:=Found;
  480. end;
  481. var C,PrevC: char;
  482. WordS: string;
  483. LastWordStart: integer;
  484. L: longint;
  485. S: string;
  486. D: DirStr; N: NameStr; E: ExtStr;
  487. begin
  488. I:=1; WordS:=''; LastWordStart:=I; PrevC:=' ';
  489. while (I<=length(Params)+1) and (Err=0) do
  490. begin
  491. if I<=length(Params) then C:=Params[I];
  492. if (I<=length(Params)) and IsAlpha(C) then
  493. begin
  494. if (I=1) or (IsAlpha(PrevC)=false) then
  495. begin WordS:=''; LastWordStart:=I; end;
  496. { if IsAlpha(C) then ForceConcat:=false;}
  497. WordS:=WordS+C;
  498. end
  499. else
  500. begin
  501. WordS:=UpcaseStr(Trim(WordS));
  502. if WordS<>'' then
  503. if (WordS='$COL') then
  504. begin
  505. if (Pass=1) then
  506. begin
  507. if W=nil then L:=0 else
  508. L:=W^.Editor^.CurPos.X+1;
  509. I:=I+ReplacePart(LastWordStart,I-1,IntToStr(L));
  510. end;
  511. end else
  512. if (WordS='$CONFIG') then
  513. begin
  514. if (Pass=1) then
  515. I:=I+ReplacePart(LastWordStart,I-1,INIPath);
  516. end else
  517. if (WordS='$DIR') then
  518. begin
  519. if (Pass=2) then
  520. if Consume('(')=false then Err:=I else
  521. if ReadTill(S,')')=false then Err:=I else
  522. begin
  523. Consume(')');
  524. FSplit(S,D,N,E);
  525. I:=I+ReplacePart(LastWordStart,I-1,D);
  526. end;
  527. end else
  528. if (WordS='$DRIVE') then
  529. begin
  530. if (Pass=2) then
  531. if Consume('(')=false then Err:=I else
  532. if ReadTill(S,')')=false then Err:=I else
  533. begin
  534. Consume(')');
  535. FSplit(S,D,N,E);
  536. L:=Pos(':',D); if L=0 then L:=-1;
  537. D:=copy(D,1,L+1);
  538. I:=I+ReplacePart(LastWordStart,I-1,D);
  539. end;
  540. end else
  541. if (WordS='$EDNAME') then
  542. begin
  543. if (Pass=1) then
  544. begin
  545. if W=nil then S:='' else
  546. S:=W^.Editor^.FileName;
  547. I:=I+ReplacePart(LastWordStart,I-1,S);
  548. end;
  549. end else
  550. if (WordS='$EXENAME') then
  551. begin
  552. if (Pass=1) then
  553. I:=I+ReplacePart(LastWordStart,I-1,EXEFile);
  554. end else
  555. if (WordS='$EXT') then
  556. begin
  557. if (Pass=2) then
  558. if Consume('(')=false then Err:=I else
  559. if ReadTill(S,')')=false then Err:=I else
  560. begin
  561. Consume(')');
  562. FSplit(S,D,N,E); E:=copy(E,2,255);
  563. I:=I+ReplacePart(LastWordStart,I-1,E);
  564. end;
  565. end else
  566. if (WordS='$LINE') then
  567. begin
  568. if (Pass=1) then
  569. begin
  570. if W=nil then L:=0 else
  571. L:=W^.Editor^.CurPos.Y+1;
  572. I:=I+ReplacePart(LastWordStart,I-1,IntToStr(L));
  573. end;
  574. end else
  575. if (WordS='$NAME') then
  576. begin
  577. if (Pass=2) then
  578. if Consume('(')=false then Err:=I else
  579. if ReadTill(S,')')=false then Err:=I else
  580. begin
  581. Consume(')');
  582. FSplit(S,D,N,E);
  583. I:=I+ReplacePart(LastWordStart,I-1,N);
  584. end;
  585. end else
  586. if (WordS='$NAMEEXT') then
  587. begin
  588. if (Pass=2) then
  589. if Consume('(')=false then Err:=I else
  590. if ReadTill(S,')')=false then Err:=I else
  591. begin
  592. Consume(')');
  593. FSplit(S,D,N,E);
  594. I:=I+ReplacePart(LastWordStart,I-1,N+E);
  595. end;
  596. end else
  597. if (WordS='$NOSWAP') then
  598. begin
  599. if (Pass=1) then
  600. begin
  601. I:=I+ReplacePart(LastWordStart,I-1,'');
  602. end;
  603. end else
  604. if (WordS='$PROMPT') then
  605. begin
  606. if (Pass=3) then
  607. begin
  608. I:=I+ReplacePart(LastWordStart,I-1,'');
  609. if CheckOnly=false then
  610. begin
  611. S:=copy(Params,I+1,255);
  612. if InputBox('Program Arguments', '~E~nter program argument',
  613. S,255-I+1)=cmOK then
  614. begin
  615. ReplacePart(LastWordStart,255,S);
  616. I:=255;
  617. end
  618. else
  619. Err:=-1;
  620. end;
  621. end;
  622. end else
  623. if (WordS='$SAVE') then
  624. begin
  625. if (Pass=0) then
  626. if (Params[I]=' ') and (I<=255) then Params[I]:='_';
  627. end else
  628. if (WordS='$SAVE_ALL') then
  629. begin
  630. if (Pass=2) then
  631. begin
  632. I:=I+ReplacePart(LastWordStart,I-1,'');
  633. Message(Application,evCommand,cmSaveAll,nil);
  634. end;
  635. end else
  636. if (WordS='$SAVE_CUR') then
  637. begin
  638. if (Pass=2) then
  639. begin
  640. I:=I+ReplacePart(LastWordStart,I-1,'');
  641. Message(W,evCommand,cmSave,nil);
  642. end;
  643. end else
  644. if (WordS='$SAVE_PROMPT') then
  645. begin
  646. if (Pass=2) then
  647. begin
  648. I:=I+ReplacePart(LastWordStart,I-1,'');
  649. if W<>nil then
  650. if W^.Editor^.SaveAsk=false then
  651. Err:=-1;
  652. end;
  653. end else
  654. if copy(WordS,1,1)='$' then
  655. Err:=LastWordStart;
  656. WordS:='';
  657. end;
  658. PrevC:=C;
  659. Inc(I);
  660. end;
  661. end;
  662. var Pass: integer;
  663. begin
  664. W:=FirstEditorWindow;
  665. Err:=0;
  666. for Pass:=0 to 3 do
  667. begin
  668. ParseParams(Pass);
  669. if Err<>0 then Break;
  670. end;
  671. ParseToolParams:=Err;
  672. end;
  673. END.
  674. {
  675. $Log$
  676. Revision 1.1 1999-01-21 11:54:25 peter
  677. + tools menu
  678. + speedsearch in symbolbrowser
  679. * working run command
  680. Revision 1.0 1999/01/16 10:43:31 gabor
  681. Original implementation
  682. }