fpswitch.pas 27 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027
  1. {
  2. $Id$
  3. This file is part of the Free Pascal Integrated Development Environment
  4. Copyright (c) 1998 by Berczi Gabor
  5. Compiler switches routines 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 FPSwitch;
  13. interface
  14. uses
  15. Objects,
  16. Systems,
  17. FPConst;
  18. const
  19. MinMemSize = 1024; { min. local heap and stack size }
  20. MaxMemSize = 67107840; { max. local heap and stack size }
  21. type
  22. TSwitchMode = (om_Normal,om_Debug,om_Release);
  23. TSwitchItemTyp = (ot_Select,ot_Boolean,ot_String,ot_Longint);
  24. PSwitchItem = ^TSwitchItem;
  25. TSwitchItem = object(TObject)
  26. Typ : TSwitchItemTyp;
  27. Name : string[50];
  28. Param : string[10];
  29. constructor Init(const n,p:string);
  30. function NeedParam:boolean;virtual;
  31. function ParamValue:string;virtual;
  32. procedure Reset;virtual;
  33. end;
  34. PSelectItem = ^TSelectItem;
  35. TSelectItem = object(TSwitchItem)
  36. constructor Init(const n,p:string);
  37. end;
  38. PBooleanItem = ^TBooleanItem;
  39. TBooleanItem = object(TSwitchItem)
  40. IsSet : array[TSwitchMode] of boolean;
  41. constructor Init(const n,p:string);
  42. function NeedParam:boolean;virtual;
  43. procedure Reset;virtual;
  44. end;
  45. PStringItem = ^TStringItem;
  46. TStringItem = object(TSwitchItem)
  47. Str : array[TSwitchMode] of string;
  48. multiple : boolean;
  49. constructor Init(const n,p:string;mult:boolean);
  50. function NeedParam:boolean;virtual;
  51. function ParamValue:string;virtual;
  52. procedure Reset;virtual;
  53. end;
  54. PLongintItem = ^TLongintItem;
  55. TLongintItem = object(TSwitchItem)
  56. Val : array[TSwitchMode] of longint;
  57. constructor Init(const n,p:string);
  58. function NeedParam:boolean;virtual;
  59. function ParamValue:string;virtual;
  60. procedure Reset;virtual;
  61. end;
  62. PSwitches = ^TSwitches;
  63. TSwitches = object
  64. constructor Init(ch:char);
  65. constructor InitSelect(ch:char);
  66. destructor Done;
  67. { general items }
  68. function ItemCount:integer;
  69. function ItemName(index:integer):string;
  70. function ItemParam(index:integer):string;
  71. { type specific }
  72. procedure AddSelectItem(const name,param:string);
  73. procedure AddBooleanItem(const name,param:string);
  74. procedure AddLongintItem(const name,param:string);
  75. procedure AddStringItem(const name,param:string;mult:boolean);
  76. function GetCurrSel:integer;
  77. function GetCurrSelParam : String;
  78. function GetBooleanItem(index:integer):boolean;
  79. function GetLongintItem(index:integer):longint;
  80. function GetStringItem(index:integer):string;
  81. procedure SetCurrSel(index:integer);
  82. function SetCurrSelParam(const s : String) : boolean;
  83. procedure SetBooleanItem(index:integer;b:boolean);
  84. procedure SetLongintItem(index:integer;l:longint);
  85. procedure SetStringItem(index:integer;const s:string);
  86. { read / write to cfgfile which must be open }
  87. procedure WriteItemsCfg;
  88. function ReadItemsCfg(const s:string):boolean;
  89. private
  90. IsSel : boolean;
  91. Prefix : char;
  92. SelNr : array[TSwitchMode] of integer;
  93. Items : PCollection;
  94. end;
  95. const
  96. SwitchesMode : TSwitchMode = om_Normal;
  97. SwitchesModeName : array[TSwitchMode] of string[10]=
  98. ('~N~ormal','~D~ebug','~R~elease');
  99. SwitchesModeStr : array[TSwitchMode] of string[8]=
  100. ('NORMAL','DEBUG','RELEASE');
  101. CustomArg : array[TSwitchMode] of string{$ifndef FPC}[128]{$endif}=
  102. ('','','');
  103. var
  104. LibLinkerSwitches,
  105. DebugInfoSwitches,
  106. ProfileInfoSwitches,
  107. {MemorySizeSwitches, doubled !! }
  108. SyntaxSwitches,
  109. VerboseSwitches,
  110. CodegenSwitches,
  111. OptimizationSwitches,
  112. OptimizingGoalSwitches,
  113. ProcessorSwitches,
  114. AsmReaderSwitches,
  115. TargetSwitches,
  116. ConditionalSwitches,
  117. MemorySwitches,
  118. BrowserSwitches,
  119. DirectorySwitches : PSwitches;
  120. { write/read the Switches to ppc.cfg file }
  121. procedure WriteSwitches(const fn:string);
  122. procedure ReadSwitches(const fn:string);
  123. { initialize }
  124. procedure InitSwitches;
  125. procedure SetDefaultSwitches;
  126. procedure DoneSwitches;
  127. function GetSourceDirectories : string;
  128. implementation
  129. uses
  130. Dos,
  131. GlobType,Tokens,Compiler,
  132. FPUtils,FPVars;
  133. var
  134. CfgFile : text;
  135. {*****************************************************************************
  136. TSwitchItem
  137. *****************************************************************************}
  138. constructor TSwitchItem.Init(const n,p:string);
  139. begin
  140. Inherited Init;
  141. Name:=n;
  142. Param:=p;
  143. end;
  144. function TSwitchItem.NeedParam:boolean;
  145. begin
  146. NeedParam:=false;
  147. end;
  148. function TSwitchItem.ParamValue:string;
  149. begin
  150. ParamValue:='';
  151. end;
  152. procedure TSwitchItem.Reset;
  153. begin
  154. end;
  155. {*****************************************************************************
  156. TSelectItem
  157. *****************************************************************************}
  158. constructor TSelectItem.Init(const n,p:string);
  159. begin
  160. Inherited Init(n,p);
  161. Typ:=ot_Select;
  162. end;
  163. {*****************************************************************************
  164. TBooleanItem
  165. *****************************************************************************}
  166. constructor TBooleanItem.Init(const n,p:string);
  167. begin
  168. Inherited Init(n,p);
  169. Typ:=ot_Boolean;
  170. Reset;
  171. end;
  172. function TBooleanItem.NeedParam:boolean;
  173. begin
  174. NeedParam:=IsSet[SwitchesMode];
  175. end;
  176. procedure TBooleanItem.Reset;
  177. begin
  178. FillChar(IsSet,sizeof(IsSet),0);
  179. end;
  180. {*****************************************************************************
  181. TStringItem
  182. *****************************************************************************}
  183. constructor TStringItem.Init(const n,p:string;mult:boolean);
  184. begin
  185. Inherited Init(n,p);
  186. Typ:=ot_String;
  187. Multiple:=mult;
  188. Reset;
  189. end;
  190. function TStringItem.NeedParam:boolean;
  191. begin
  192. NeedParam:=(Str[SwitchesMode]<>'');
  193. end;
  194. function TStringItem.ParamValue:string;
  195. begin
  196. ParamValue:=Str[SwitchesMode];
  197. end;
  198. procedure TStringItem.Reset;
  199. begin
  200. FillChar(Str,sizeof(Str),0);
  201. end;
  202. {*****************************************************************************
  203. TLongintItem
  204. *****************************************************************************}
  205. constructor TLongintItem.Init(const n,p:string);
  206. begin
  207. Inherited Init(n,p);
  208. Typ:=ot_Longint;
  209. Reset;
  210. end;
  211. function TLongintItem.NeedParam:boolean;
  212. begin
  213. NeedParam:=(Val[SwitchesMode]<>0);
  214. end;
  215. function TLongintItem.ParamValue:string;
  216. var
  217. s : string;
  218. begin
  219. Str(Val[SwitchesMode],s);
  220. ParamValue:=s;
  221. end;
  222. procedure TLongintItem.Reset;
  223. begin
  224. FillChar(Val,sizeof(Val),0);
  225. end;
  226. {*****************************************************************************
  227. TSwitch
  228. *****************************************************************************}
  229. constructor TSwitches.Init(ch:char);
  230. begin
  231. new(Items,Init(10,5));
  232. Prefix:=ch;
  233. FillChar(SelNr,SizeOf(SelNr),#0);
  234. IsSel:=false;
  235. end;
  236. constructor TSwitches.InitSelect(ch:char);
  237. begin
  238. new(Items,Init(10,5));
  239. Prefix:=ch;
  240. FillChar(SelNr,SizeOf(SelNr),#0);
  241. IsSel:=true;
  242. end;
  243. destructor TSwitches.Done;
  244. begin
  245. dispose(Items,Done);
  246. end;
  247. procedure TSwitches.AddSelectItem(const name,param:string);
  248. begin
  249. Items^.Insert(New(PSelectItem,Init(name,Param)));
  250. end;
  251. procedure TSwitches.AddBooleanItem(const name,param:string);
  252. begin
  253. Items^.Insert(New(PBooleanItem,Init(name,Param)));
  254. end;
  255. procedure TSwitches.AddLongintItem(const name,param:string);
  256. begin
  257. Items^.Insert(New(PLongintItem,Init(name,Param)));
  258. end;
  259. procedure TSwitches.AddStringItem(const name,param:string;mult:boolean);
  260. begin
  261. Items^.Insert(New(PStringItem,Init(name,Param,mult)));
  262. end;
  263. function TSwitches.ItemCount:integer;
  264. begin
  265. ItemCount:=Items^.Count;
  266. end;
  267. function TSwitches.ItemName(index:integer):string;
  268. var
  269. P : PSwitchItem;
  270. begin
  271. P:=Items^.At(Index);
  272. if assigned(P) then
  273. ItemName:=P^.Name
  274. else
  275. ItemName:='';
  276. end;
  277. function TSwitches.ItemParam(index:integer):string;
  278. var
  279. P : PSwitchItem;
  280. begin
  281. P:=Items^.At(Index);
  282. if assigned(P) then
  283. ItemParam:='-'+Prefix+P^.Param
  284. else
  285. ItemParam:='';
  286. end;
  287. function TSwitches.GetBooleanItem(index:integer):boolean;
  288. var
  289. P : PBooleanItem;
  290. begin
  291. P:=Items^.At(Index);
  292. if assigned(P) and (P^.Typ=ot_boolean) then
  293. GetBooleanItem:=P^.IsSet[SwitchesMode]
  294. else
  295. GetBooleanItem:=false;
  296. end;
  297. function TSwitches.GetLongintItem(index:integer):longint;
  298. var
  299. P : PLongintItem;
  300. begin
  301. P:=Items^.At(Index);
  302. if assigned(P) and (P^.Typ=ot_longint) then
  303. GetLongintItem:=P^.Val[SwitchesMode]
  304. else
  305. GetLongintItem:=0;
  306. end;
  307. function TSwitches.GetStringItem(index:integer):string;
  308. var
  309. P : PStringItem;
  310. begin
  311. P:=Items^.At(Index);
  312. if assigned(P) and (P^.Typ=ot_string) then
  313. GetStringItem:=P^.Str[SwitchesMode]
  314. else
  315. GetStringItem:='';
  316. end;
  317. procedure TSwitches.SetBooleanItem(index:integer;b:boolean);
  318. var
  319. P : PBooleanItem;
  320. begin
  321. P:=Items^.At(Index);
  322. if assigned(P) and (P^.Typ=ot_boolean) then
  323. P^.IsSet[SwitchesMode]:=b;
  324. end;
  325. procedure TSwitches.SetLongintItem(index:integer;l:longint);
  326. var
  327. P : PLongintItem;
  328. begin
  329. P:=Items^.At(Index);
  330. if assigned(P) and (P^.Typ=ot_longint) then
  331. P^.Val[SwitchesMode]:=l;
  332. end;
  333. procedure TSwitches.SetStringItem(index:integer;const s:string);
  334. var
  335. P : PStringItem;
  336. begin
  337. P:=Items^.At(Index);
  338. if assigned(P) and (P^.Typ=ot_string) then
  339. P^.Str[SwitchesMode]:=s;
  340. end;
  341. function TSwitches.GetCurrSel:integer;
  342. begin
  343. if IsSel then
  344. GetCurrSel:=SelNr[SwitchesMode]
  345. else
  346. GetCurrSel:=-1;
  347. end;
  348. function TSwitches.GetCurrSelParam : String;
  349. begin
  350. if IsSel then
  351. GetCurrSelParam:=PSwitchItem(Items^.At(SelNr[SwitchesMode]))^.Param
  352. else
  353. GetCurrSelParam:='';
  354. end;
  355. procedure TSwitches.SetCurrSel(index:integer);
  356. begin
  357. if IsSel then
  358. SelNr[SwitchesMode]:=index;
  359. end;
  360. function TSwitches.SetCurrSelParam(const s : String) : boolean;
  361. function checkitem(P:PSwitchItem):boolean;{$ifndef FPC}far;{$endif}
  362. begin
  363. { empty items are not equivalent to others !! }
  364. CheckItem:=((S='') and (P^.Param='')) or
  365. ((Length(S)>0) and (P^.Param=s));
  366. end;
  367. var
  368. FoundP : PSwitchItem;
  369. begin
  370. FoundP:=Items^.FirstThat(@CheckItem);
  371. if Assigned(FoundP) then
  372. begin
  373. SetCurrSelParam:=true;
  374. SelNr[SwitchesMode]:=Items^.IndexOf(FoundP);
  375. end
  376. else
  377. SetCurrSelParam:=false;
  378. end;
  379. procedure TSwitches.WriteItemsCfg;
  380. var
  381. Pref : char;
  382. procedure writeitem(P:PSwitchItem);{$ifndef FPC}far;{$endif}
  383. var
  384. s,s1 : string;
  385. i,j : integer;
  386. begin
  387. if P^.NeedParam then
  388. begin
  389. if (P^.Typ=ot_string) and (PStringItem(P)^.Multiple) then
  390. begin
  391. s:=PStringItem(P)^.Str[SwitchesMode];
  392. repeat
  393. i:=pos(';',s);
  394. j:=pos(' ',s);
  395. if i=0 then
  396. i:=256;
  397. if (j>0) and (j<i) then
  398. i:=j;
  399. s1:=Copy(s,1,i-1);
  400. if s1<>'' then
  401. writeln(CfgFile,' -'+Pref+P^.Param+s1);
  402. Delete(s,1,i);
  403. until s='';
  404. end
  405. else
  406. Writeln(CfgFile,' -'+Pref+P^.Param+P^.ParamValue);
  407. end;
  408. end;
  409. begin
  410. Pref:=Prefix;
  411. if IsSel then
  412. writeln(CfgFile,' '+ItemParam(SelNr[SwitchesMode]))
  413. else
  414. Items^.ForEach(@writeitem);
  415. end;
  416. procedure WriteCustom;
  417. var
  418. s : string;
  419. i : longint;
  420. begin
  421. s:=CustomArg[SwitchesMode];
  422. While s<>'' do
  423. begin
  424. i:=pos(' ',s);
  425. if i=0 then i:=256;
  426. writeln(CfgFile,' '+Copy(s,1,i-1));
  427. if i=256 then
  428. s:=''
  429. else
  430. s:=copy(s,i+1,255);
  431. end;
  432. end;
  433. function TSwitches.ReadItemsCfg(const s:string):boolean;
  434. function checkitem(P:PSwitchItem):boolean;{$ifndef FPC}far;{$endif}
  435. begin
  436. { empty items are not equivalent to others !! }
  437. CheckItem:=((S='') and (P^.Param='')) or
  438. ((Length(S)>0) and (P^.Param=Copy(s,1,length(P^.Param))));
  439. end;
  440. var
  441. FoundP : PSwitchItem;
  442. code : integer;
  443. begin
  444. FoundP:=Items^.FirstThat(@checkitem);
  445. if assigned(FoundP) then
  446. begin
  447. case FoundP^.Typ of
  448. ot_Select : SelNr[SwitchesMode]:=Items^.IndexOf(FoundP);
  449. ot_Boolean : PBooleanItem(FoundP)^.IsSet[SwitchesMode]:=true;
  450. ot_String : begin
  451. if (PStringItem(FoundP)^.Multiple) and (PStringItem(FoundP)^.Str[SwitchesMode]<>'') then
  452. PStringItem(FoundP)^.Str[SwitchesMode]:=PStringItem(FoundP)^.Str[SwitchesMode]+';'+
  453. Copy(s,length(FoundP^.Param)+1,255)
  454. else
  455. PStringItem(FoundP)^.Str[SwitchesMode]:=Copy(s,length(FoundP^.Param)+1,255);
  456. end;
  457. ot_Longint : Val(Copy(s,length(FoundP^.Param)+1,255),PLongintItem(FoundP)^.Val[SwitchesMode],code);
  458. end;
  459. ReadItemsCfg:=true;
  460. end
  461. else
  462. ReadItemsCfg:=false;
  463. end;
  464. {*****************************************************************************
  465. Read / Write
  466. *****************************************************************************}
  467. procedure WriteSwitches(const fn:string);
  468. var
  469. OldSwitchesMode : TSwitchMode;
  470. begin
  471. { create the switches }
  472. assign(CfgFile,fn);
  473. {$I-}
  474. rewrite(CfgFile);
  475. {$I+}
  476. if ioresult<>0 then
  477. exit;
  478. writeln(CfgFile,'# Automaticly created file, don''t edit.');
  479. OldSwitchesMode:=SwitchesMode;
  480. for SwitchesMode:=low(TSwitchMode) to high(TSwitchMode) do
  481. begin
  482. Writeln(CfgFile,'#IFDEF '+SwitchesModeStr[SwitchesMode]);
  483. TargetSwitches^.WriteItemsCfg;
  484. VerboseSwitches^.WriteItemsCfg;
  485. SyntaxSwitches^.WriteItemsCfg;
  486. CodegenSwitches^.WriteItemsCfg;
  487. OptimizationSwitches^.WriteItemsCfg;
  488. OptimizingGoalSwitches^.WriteItemsCfg;
  489. ProcessorSwitches^.WriteItemsCfg;
  490. AsmReaderSwitches^.WriteItemsCfg;
  491. DirectorySwitches^.WriteItemsCfg;
  492. MemorySwitches^.WriteItemsCfg;
  493. ConditionalSwitches^.WriteItemsCfg;
  494. LibLinkerSwitches^.WriteItemsCfg;
  495. DebugInfoSwitches^.WriteItemsCfg;
  496. ProfileInfoSwitches^.WriteItemsCfg;
  497. BrowserSwitches^.WriteItemsCfg;
  498. {MemorySizeSwitches^.WriteItemsCfg;}
  499. WriteCustom;
  500. Writeln(CfgFile,'#ENDIF');
  501. Writeln(CfgFile,'');
  502. end;
  503. close(CfgFile);
  504. SwitchesMode:=OldSwitchesMode;
  505. end;
  506. procedure ReadSwitches(const fn:string);
  507. var
  508. c : char;
  509. s : string;
  510. res : boolean;
  511. OldSwitchesMode,i : TSwitchMode;
  512. begin
  513. assign(CfgFile,fn);
  514. {$I-}
  515. reset(CfgFile);
  516. {$I+}
  517. if ioresult<>0 then
  518. begin
  519. SetDefaultSwitches;
  520. exit;
  521. end;
  522. OldSwitchesMode:=SwitchesMode;
  523. SwitchesMode:=om_Normal;
  524. while not eof(CfgFile) do
  525. begin
  526. readln(CfgFile,s);
  527. s:=LTrim(s);
  528. if (length(s)>=2) and (s[1]='-') then
  529. begin
  530. c:=s[2];
  531. res:=false;
  532. Delete(s,1,2);
  533. case c of
  534. 'd' : res:=ConditionalSwitches^.ReadItemsCfg(s);
  535. 'X' : res:=LibLinkerSwitches^.ReadItemsCfg(s);
  536. 'g' : res:=DebugInfoSwitches^.ReadItemsCfg(s);
  537. 'p' : res:=ProfileInfoSwitches^.ReadItemsCfg(s);
  538. 'S' : res:=SyntaxSwitches^.ReadItemsCfg(s);
  539. 'F' : res:=DirectorySwitches^.ReadItemsCfg(s);
  540. 'T' : res:=TargetSwitches^.ReadItemsCfg(s);
  541. 'R' : res:=AsmReaderSwitches^.ReadItemsCfg(s);
  542. 'C' : begin
  543. res:=CodegenSwitches^.ReadItemsCfg(s);
  544. if not res then
  545. res:=MemorySwitches^.ReadItemsCfg(s);
  546. end;
  547. 'v' : res:=VerboseSwitches^.ReadItemsCfg(s);
  548. 'O' : begin
  549. res:=true;
  550. if not OptimizationSwitches^.ReadItemsCfg(s) then
  551. if not ProcessorSwitches^.ReadItemsCfg(s) then
  552. res:=OptimizingGoalSwitches^.ReadItemsCfg(s);
  553. end;
  554. 'b' : res:=BrowserSwitches^.ReadItemsCfg(s);
  555. end;
  556. { keep all others as a string }
  557. if not res then
  558. CustomArg[SwitchesMode]:=CustomArg[SwitchesMode]+' -'+c+s;
  559. end
  560. else
  561. if (Copy(s,1,7)='#IFDEF ') then
  562. begin
  563. Delete(s,1,7);
  564. for i:=low(TSwitchMode) to high(TSwitchMode) do
  565. if s=SwitchesModeStr[i] then
  566. begin
  567. SwitchesMode:=i;
  568. break;
  569. end;
  570. end
  571. else;
  572. end;
  573. close(CfgFile);
  574. SwitchesMode:=OldSwitchesMode;
  575. end;
  576. function GetSourceDirectories : string;
  577. var
  578. P : PStringItem;
  579. S : String;
  580. c : char;
  581. function checkitem(P:PSwitchItem):boolean;{$ifndef FPC}far;{$endif}
  582. begin
  583. CheckItem:=(P^.Typ=ot_string) and (P^.Param=c);
  584. end;
  585. begin
  586. GetSourceDirectories:='';
  587. c:='u';
  588. P:=DirectorySwitches^.Items^.FirstThat(@CheckItem);
  589. S:='';
  590. if assigned(P) then
  591. S:=P^.Str[SwitchesMode];
  592. c:='i';
  593. P:=DirectorySwitches^.Items^.FirstThat(@CheckItem);
  594. if assigned(P) then
  595. S:=P^.Str[SwitchesMode]+';'+S;
  596. if S='' then
  597. GetSourceDirectories:=SourceDirs+';'
  598. else
  599. GetSourceDirectories:=SourceDirs+';'+S+';';
  600. end;
  601. {*****************************************************************************
  602. Initialize
  603. *****************************************************************************}
  604. procedure InitSwitches;
  605. begin
  606. New(SyntaxSwitches,Init('S'));
  607. with SyntaxSwitches^ do
  608. begin
  609. AddBooleanItem('~D~elphi 2 extensions on','2');
  610. AddBooleanItem('~C~-like operators','c');
  611. AddBooleanItem('S~t~op after first error','e');
  612. AddBooleanItem('Allo~w~ LABEL and GOTO','g');
  613. AddBooleanItem('C++ styled ~i~nline','i');
  614. AddBooleanItem('Global C ~m~acros','m');
  615. AddBooleanItem('TP/BP ~7~.0 compatibility','o');
  616. AddBooleanItem('Del~p~hi compatibility','d');
  617. AddBooleanItem('A~l~low STATIC in objects','s');
  618. end;
  619. New(VerboseSwitches,Init('v'));
  620. with VerboseSwitches^ do
  621. begin
  622. AddBooleanItem('~W~arnings','w');
  623. AddBooleanItem('N~o~tes','n');
  624. AddBooleanItem('~H~ints','h');
  625. AddBooleanItem('General ~I~nfo','i');
  626. AddBooleanItem('~U~sed,tried info','ut');
  627. AddBooleanItem('~A~ll','a');
  628. AddBooleanItem('Show all ~P~rocedures if error','b');
  629. end;
  630. New(CodegenSwitches,Init('C'));
  631. with CodegenSwitches^ do
  632. begin
  633. AddBooleanItem('~R~ange checking','r');
  634. AddBooleanItem('~S~tack checking','t');
  635. AddBooleanItem('~I~/O checking','i');
  636. AddBooleanItem('Integer ~o~verflow checking','o');
  637. end;
  638. New(OptimizingGoalSwitches,InitSelect('O'));
  639. with OptimizingGoalSwitches^ do
  640. begin
  641. AddSelectItem('Generate ~f~aster code','G');
  642. AddSelectItem('Generate s~m~aller code','g');
  643. end;
  644. New(OptimizationSwitches,Init('O'));
  645. with OptimizationSwitches^ do
  646. begin
  647. AddBooleanItem('Use regis~t~er-variables','r');
  648. AddBooleanItem('~U~ncertain optimizations','u');
  649. AddBooleanItem('Level ~1~ optimizations','1');
  650. AddBooleanItem('Level ~2~ optimizations','2');
  651. end;
  652. New(ProcessorSwitches,InitSelect('O'));
  653. with ProcessorSwitches^ do
  654. begin
  655. AddSelectItem('i~3~86/i486','p1');
  656. AddSelectItem('Pentium/PentiumMM~X~ (tm)','p2');
  657. AddSelectItem('P~P~ro/PII/c6x86/K6 (tm)','p3');
  658. end;
  659. New(TargetSwitches,InitSelect('T'));
  660. with TargetSwitches^ do
  661. begin
  662. AddSelectItem('DOS (GO32V~1~)','go32v1');
  663. AddSelectItem('~D~OS (GO32V2)','go32v2');
  664. AddSelectItem('~L~inux','linux');
  665. AddSelectItem('~O~S/2','os2');
  666. AddSelectItem('~W~IN32','win32');
  667. end;
  668. New(AsmReaderSwitches,InitSelect('R'));
  669. with AsmReaderSwitches^ do
  670. begin
  671. AddSelectItem('Di~r~ect assembler','direct');
  672. AddSelectItem('~A~T&T style assembler','att');
  673. AddSelectItem('Int~e~l style assembler','intel');
  674. end;
  675. New(BrowserSwitches,InitSelect('b'));
  676. with BrowserSwitches^ do
  677. begin
  678. AddSelectItem('N~o~ browser','-');
  679. AddSelectItem('Only Glob~a~l browser','+');
  680. AddSelectItem('~L~ocal and global browser','l');
  681. end;
  682. New(ConditionalSwitches,Init('d'));
  683. with ConditionalSwitches^ do
  684. begin
  685. AddStringItem('Conditio~n~al defines','',true);
  686. end;
  687. New(MemorySwitches,Init('C'));
  688. with MemorySwitches^ do
  689. begin
  690. AddLongintItem('~S~tack size','s');
  691. AddLongintItem('~H~eap size','h');
  692. end;
  693. New(DirectorySwitches,Init('F'));
  694. with DirectorySwitches^ do
  695. begin
  696. AddStringItem('~U~nit directories','u',true);
  697. AddStringItem('~I~nclude directories','i',true);
  698. AddStringItem('~L~ibrary directories','l',true);
  699. AddStringItem('~O~bject directories','o',true);
  700. AddStringItem('~E~XE & PPU directories','E',true);
  701. end;
  702. New(LibLinkerSwitches,InitSelect('X'));
  703. with LibLinkerSwitches^ do
  704. begin
  705. AddSelectItem('~D~ynamic libraries','D');
  706. AddSelectItem('~S~tatic libraries','S');
  707. end;
  708. New(DebugInfoSwitches,InitSelect('g'));
  709. with DebugInfoSwitches^ do
  710. begin
  711. AddSelectItem('~S~trip all debug symbols from executable','-');
  712. AddSelectItem('Generate ~d~ebug symbol information','');
  713. { AddSelectItem('Generate ~d~bx symbol information','d');
  714. does not work anyhow (PM) }
  715. end;
  716. New(ProfileInfoSwitches,InitSelect('p'));
  717. with ProfileInfoSwitches^ do
  718. begin
  719. AddSelectItem('~N~o profile information','-');
  720. AddSelectItem('Generate profile code for g~p~rof','g');
  721. end;
  722. {New(MemorySizeSwitches,Init('C'));
  723. with MemorySizeSwitches^ do
  724. begin
  725. AddLongIntItem('~S~tack size','s');
  726. AddLongIntItem('Local ~h~eap size','h');
  727. end;}
  728. SwitchesPath:=LocateFile(SwitchesName);
  729. if SwitchesPath='' then
  730. SwitchesPath:=SwitchesName;
  731. SwitchesPath:=FExpand(SwitchesPath);
  732. end;
  733. procedure SetDefaultSwitches;
  734. var
  735. i,OldSwitchesMode : TSwitchMode;
  736. begin
  737. { setup some useful defaults }
  738. OldSwitchesMode:=SwitchesMode;
  739. for i:=low(TSwitchMode) to high(TSwitchMode) do
  740. begin
  741. SwitchesMode:=i;
  742. { default is Pentium }
  743. ProcessorSwitches^.SetCurrSel(1);
  744. { AT&T reader }
  745. AsmReaderSwitches^.SetCurrSel(1);
  746. { 128k stack }
  747. MemorySwitches^.SetLongintItem(0,65536*2);
  748. { 2 MB heap }
  749. MemorySwitches^.SetLongintItem(1,1024*1024*2);
  750. { goto/lable allowed }
  751. SyntaxSwitches^.SetBooleanItem(3,true);
  752. case i of
  753. om_debug:
  754. begin
  755. { debugging info on }
  756. DebugInfoSwitches^.SetCurrSel(1);
  757. { range checking }
  758. CodegenSwitches^.SetBooleanItem(0,true);
  759. { io checking }
  760. CodegenSwitches^.SetBooleanItem(2,true);
  761. { overflow checking }
  762. CodegenSwitches^.SetBooleanItem(3,true);
  763. end;
  764. om_normal:
  765. begin
  766. OptimizationSwitches^.SetBooleanItem(2,true);
  767. end;
  768. om_release:
  769. begin
  770. OptimizationSwitches^.SetBooleanItem(2,true);
  771. OptimizationSwitches^.SetBooleanItem(3,true);
  772. end;
  773. end;
  774. { set appriopriate default target }
  775. {$ifdef go32v2}
  776. TargetSwitches^.SetCurrSel(1);
  777. {$endif}
  778. {$ifdef linux}
  779. TargetSwitches^.SetCurrSel(2);
  780. {$endif}
  781. {$ifdef win32}
  782. TargetSwitches^.SetCurrSel(4);
  783. {$endif}
  784. {$ifdef os2}
  785. TargetSwitches^.SetCurrSel(3);
  786. {$endif}
  787. end;
  788. SwitchesMode:=OldSwitchesMode;
  789. end;
  790. procedure DoneSwitches;
  791. begin
  792. dispose(SyntaxSwitches,Done);
  793. dispose(VerboseSwitches,Done);
  794. dispose(CodegenSwitches,Done);
  795. dispose(OptimizationSwitches,Done);
  796. dispose(OptimizingGoalSwitches,Done);
  797. dispose(ProcessorSwitches,Done);
  798. dispose(BrowserSwitches,Done);
  799. dispose(TargetSwitches,Done);
  800. dispose(AsmReaderSwitches,Done);
  801. dispose(ConditionalSwitches,Done);
  802. dispose(MemorySwitches,Done);
  803. {dispose(MemorySizeSwitches,Done);}
  804. dispose(DirectorySwitches,Done);
  805. dispose(DebugInfoSwitches,Done);
  806. dispose(LibLinkerSwitches,Done);
  807. dispose(ProfileInfoSwitches,Done);
  808. end;
  809. end.
  810. {
  811. $Log$
  812. Revision 1.17 2000-02-04 14:34:47 pierre
  813. readme.txt
  814. Revision 1.16 2000/02/04 00:05:20 pierre
  815. * -Fi must also be used for GetSourceDirectories
  816. Revision 1.15 2000/01/10 15:52:53 pierre
  817. * use default command line switches only if fp.cfg not found
  818. Revision 1.14 1999/10/14 14:22:23 florian
  819. * if no ini file is found the ide uses some useful defaults
  820. Revision 1.13 1999/04/29 09:36:12 peter
  821. * fixed hotkeys with Compiler switches
  822. * fixed compiler status dialog
  823. * Run shows again the output
  824. Revision 1.12 1999/03/23 15:11:34 peter
  825. * desktop saving things
  826. * vesa mode
  827. * preferences dialog
  828. Revision 1.11 1999/03/12 01:14:01 peter
  829. * flag if trytoopen should look for other extensions
  830. + browser tab in the tools-compiler
  831. Revision 1.10 1999/02/16 12:46:38 pierre
  832. * String items can also be separated by spaces
  833. Revision 1.9 1999/02/10 09:45:55 pierre
  834. * MemorySizeSwitches Removed (was duplicate of MemorySwitches !)
  835. * Added missing disposes at exit
  836. Revision 1.8 1999/02/08 17:38:52 pierre
  837. + added CustomArg
  838. Revision 1.7 1999/02/06 00:07:48 florian
  839. * speed/size optimization is now a radio button
  840. Revision 1.6 1999/02/05 13:51:44 peter
  841. * unit name of FPSwitches -> FPSwitch which is easier to use
  842. * some fixes for tp7 compiling
  843. Revision 1.5 1999/02/05 12:12:00 pierre
  844. + SourceDir that stores directories for sources that the
  845. compiler should not know about
  846. Automatically asked for addition when a new file that
  847. needed filedialog to be found is in an unknown directory
  848. Stored and retrieved from INIFile
  849. + Breakpoints conditions added to INIFile
  850. * Breakpoints insterted and removed at debin and end of debug session
  851. Revision 1.4 1999/02/04 13:32:10 pierre
  852. * Several things added (I cannot commit them independently !)
  853. + added TBreakpoint and TBreakpointCollection
  854. + added cmResetDebugger,cmGrep,CmToggleBreakpoint
  855. + Breakpoint list in INIFile
  856. * Select items now also depend of SwitchMode
  857. * Reading of option '-g' was not possible !
  858. + added search for -Fu args pathes in TryToOpen
  859. + added code for automatic opening of FileDialog
  860. if source not found
  861. Revision 1.3 1999/01/12 14:29:39 peter
  862. + Implemented still missing 'switch' entries in Options menu
  863. + Pressing Ctrl-B sets ASCII mode in editor, after which keypresses (even
  864. ones with ASCII < 32 ; entered with Alt+<###>) are interpreted always as
  865. ASCII chars and inserted directly in the text.
  866. + Added symbol browser
  867. * splitted fp.pas to fpide.pas
  868. Revision 1.2 1999/01/04 11:49:50 peter
  869. * 'Use tab characters' now works correctly
  870. + Syntax highlight now acts on File|Save As...
  871. + Added a new class to syntax highlight: 'hex numbers'.
  872. * There was something very wrong with the palette managment. Now fixed.
  873. + Added output directory (-FE<xxx>) support to 'Directories' dialog...
  874. * Fixed some possible bugs in Running/Compiling, and the compilation/run
  875. process revised
  876. Revision 1.1 1998/12/28 15:47:52 peter
  877. + Added user screen support, display & window
  878. + Implemented Editor,Mouse Options dialog
  879. + Added location of .INI and .CFG file
  880. + Option (INI) file managment implemented (see bottom of Options Menu)
  881. + Switches updated
  882. + Run program
  883. }