fpswitch.pas 28 KB

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