fpswitch.pas 26 KB

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