options.pas 61 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by Florian Klaempfl and Peter Vreman
  4. Reads command line options and config files
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit options;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. globtype,globals,verbose,systems,cpuinfo;
  23. type
  24. TOption=class
  25. FirstPass,
  26. NoPressEnter,
  27. DoWriteLogo : boolean;
  28. FileLevel : longint;
  29. QuickInfo : string;
  30. ParaIncludePath,
  31. ParaUnitPath,
  32. ParaObjectPath,
  33. ParaLibraryPath : TSearchPathList;
  34. ParaAlignment : TAlignmentInfo;
  35. Constructor Create;
  36. Destructor Destroy;override;
  37. procedure WriteLogo;
  38. procedure WriteInfo;
  39. procedure WriteHelpPages;
  40. procedure WriteQuickInfo;
  41. procedure IllegalPara(const opt:string);
  42. function Unsetbool(var Opts:string; Pos: Longint):boolean;
  43. procedure interpret_proc_specific_options(const opt:string);virtual;
  44. procedure interpret_option(const opt :string;ispara:boolean);
  45. procedure Interpret_envvar(const envname : string);
  46. procedure Interpret_file(const filename : string);
  47. procedure Read_Parameters;
  48. procedure parsecmd(cmd:string);
  49. procedure TargetDefines(def:boolean);
  50. end;
  51. TOptionClass=class of toption;
  52. var
  53. coption : TOptionClass;
  54. procedure read_arguments(cmd:string);
  55. implementation
  56. uses
  57. widestr,
  58. {$ifdef Delphi}
  59. dmisc,
  60. {$else Delphi}
  61. dos,
  62. {$endif Delphi}
  63. version,
  64. cutils,cmsgs
  65. {$ifdef BrowserLog}
  66. ,browlog
  67. {$endif BrowserLog}
  68. ;
  69. const
  70. page_size = 24;
  71. var
  72. option : toption;
  73. read_configfile, { read config file, set when a cfgfile is found }
  74. disable_configfile,
  75. target_is_set : boolean; { do not allow contradictory target settings }
  76. asm_is_set : boolean; { -T also change initoutputformat if not set idrectly }
  77. fpcdir,
  78. ppccfg,
  79. ppcaltcfg,
  80. param_file : string; { file to compile specified on the commandline }
  81. {****************************************************************************
  82. Defines
  83. ****************************************************************************}
  84. procedure def_symbol(const s : string);
  85. begin
  86. if s='' then
  87. exit;
  88. initdefines.insert(upper(s));
  89. Message1(option_defining_symbol,s);
  90. end;
  91. procedure undef_symbol(const s : string);
  92. begin
  93. if s='' then
  94. exit;
  95. InitDefines.Remove(s);
  96. Message1(option_undefining_symbol,s);
  97. end;
  98. function check_symbol(const s:string):boolean;
  99. begin
  100. check_symbol:=(initdefines.find(s)<>nil);
  101. end;
  102. procedure set_default_link_type;
  103. begin
  104. if (target_info.system in [system_i386_win32,system_i386_wdosx]) then
  105. begin
  106. def_symbol('FPC_LINK_SMART');
  107. undef_symbol('FPC_LINK_STATIC');
  108. undef_symbol('FPC_LINK_DYNAMIC');
  109. initglobalswitches:=initglobalswitches+[cs_link_smart];
  110. initglobalswitches:=initglobalswitches-[cs_link_shared,cs_link_static];
  111. end
  112. else
  113. begin
  114. undef_symbol('FPC_LINK_SMART');
  115. def_symbol('FPC_LINK_STATIC');
  116. undef_symbol('FPC_LINK_DYNAMIC');
  117. initglobalswitches:=initglobalswitches+[cs_link_static];
  118. initglobalswitches:=initglobalswitches-[cs_link_shared,cs_link_smart];
  119. end;
  120. end;
  121. {****************************************************************************
  122. Toption
  123. ****************************************************************************}
  124. procedure StopOptions;
  125. begin
  126. if assigned(Option) then
  127. begin
  128. Option.free;
  129. Option:=nil;
  130. end;
  131. DoneVerbose;
  132. Stop;
  133. end;
  134. procedure Toption.WriteLogo;
  135. var
  136. p : pchar;
  137. begin
  138. p:=MessagePchar(option_logo);
  139. while assigned(p) do
  140. Comment(V_Normal,GetMsgLine(p));
  141. end;
  142. procedure Toption.WriteInfo;
  143. var
  144. p : pchar;
  145. hs,hs1,s : string;
  146. target : tsystem;
  147. begin
  148. p:=MessagePchar(option_info);
  149. while assigned(p) do
  150. begin
  151. s:=GetMsgLine(p);
  152. { list OS Targets }
  153. if pos('$OSTARGETS',s)>0 then
  154. begin
  155. for target:=low(tsystem) to high(tsystem) do
  156. if assigned(targetinfos[target]) then
  157. begin
  158. hs:=s;
  159. hs1:=targetinfos[target]^.name;
  160. if tf_under_development in targetinfos[target]^.flags then
  161. hs1:=hs1+' (under development)';
  162. Replace(hs,'$OSTARGETS',hs1);
  163. Comment(V_Normal,hs);
  164. end;
  165. end
  166. else
  167. Comment(V_Normal,s);
  168. end;
  169. StopOptions;
  170. end;
  171. procedure Toption.WriteHelpPages;
  172. function PadEnd(s:string;i:longint):string;
  173. begin
  174. while (length(s)<i) do
  175. s:=s+' ';
  176. PadEnd:=s;
  177. end;
  178. var
  179. lastident,
  180. j,outline,
  181. ident,
  182. lines : longint;
  183. show : boolean;
  184. opt : string[32];
  185. input,
  186. s : string;
  187. p : pchar;
  188. begin
  189. WriteLogo;
  190. Lines:=4;
  191. Message1(option_usage,system.paramstr(0));
  192. lastident:=0;
  193. p:=MessagePChar(option_help_pages);
  194. while assigned(p) do
  195. begin
  196. { get a line and reset }
  197. s:=GetMsgLine(p);
  198. ident:=0;
  199. show:=false;
  200. { parse options }
  201. case s[1] of
  202. {$ifdef UNITALIASES}
  203. 'a',
  204. {$endif}
  205. {$ifdef EXTDEBUG}
  206. 'e',
  207. {$endif EXTDEBUG}
  208. {$ifdef i386}
  209. '3',
  210. {$endif}
  211. {$ifdef powerpc}
  212. 'P',
  213. {$endif}
  214. {$ifdef vis}
  215. 'V',
  216. {$endif}
  217. {$ifdef sparc}
  218. 'S',
  219. {$endif}
  220. {$ifdef m68k}
  221. '6',
  222. {$endif}
  223. '*' : show:=true;
  224. end;
  225. if show then
  226. begin
  227. case s[2] of
  228. {$ifdef GDB}
  229. 'g',
  230. {$endif}
  231. {$ifdef Unix}
  232. 'L',
  233. {$endif}
  234. {$ifdef os2}
  235. 'O',
  236. {$endif}
  237. '*' : show:=true;
  238. else
  239. show:=false;
  240. end;
  241. end;
  242. { now we may show the message or not }
  243. if show then
  244. begin
  245. case s[3] of
  246. '0' : begin
  247. ident:=0;
  248. outline:=0;
  249. end;
  250. '1' : begin
  251. ident:=2;
  252. outline:=7;
  253. end;
  254. '2' : begin
  255. ident:=6;
  256. outline:=11;
  257. end;
  258. '3' : begin
  259. ident:=9;
  260. outline:=6;
  261. end;
  262. end;
  263. j:=pos('_',s);
  264. opt:=Copy(s,4,j-4);
  265. if opt='*' then
  266. opt:=''
  267. else
  268. if opt=' ' then
  269. opt:=PadEnd(opt,outline)
  270. else
  271. opt:=PadEnd('-'+opt,outline);
  272. if (ident=0) and (lastident<>0) then
  273. begin
  274. Comment(V_Normal,'');
  275. inc(Lines);
  276. end;
  277. { page full ? }
  278. if (lines >= page_size - 1) then
  279. begin
  280. if not NoPressEnter then
  281. begin
  282. Message(option_help_press_enter);
  283. readln(input);
  284. if upper(input)='Q' then
  285. StopOptions;
  286. end;
  287. lines:=0;
  288. end;
  289. Comment(V_Normal,PadEnd('',ident)+opt+Copy(s,j+1,255));
  290. LastIdent:=Ident;
  291. inc(Lines);
  292. end;
  293. end;
  294. StopOptions;
  295. end;
  296. procedure Toption.IllegalPara(const opt:string);
  297. begin
  298. Message1(option_illegal_para,opt);
  299. Message(option_help_pages_para);
  300. StopOptions;
  301. end;
  302. function Toption.Unsetbool(var Opts:string; Pos: Longint):boolean;
  303. { checks if the character after pos in Opts is a + or a - and returns resp.
  304. false or true. If it is another character (or none), it also returns false }
  305. begin
  306. UnsetBool := false;
  307. if Length(Opts)>Pos then
  308. begin
  309. inc(Pos);
  310. UnsetBool := Opts[Pos] = '-';
  311. if Opts[Pos] in ['-','+']then
  312. delete(Opts,Pos,1);
  313. end;
  314. end;
  315. procedure TOption.interpret_proc_specific_options(const opt:string);
  316. begin
  317. end;
  318. procedure TOption.interpret_option(const opt:string;ispara:boolean);
  319. var
  320. code : integer;
  321. c : char;
  322. more : string;
  323. major,minor : longint;
  324. error : integer;
  325. j,l : longint;
  326. d : DirStr;
  327. e : ExtStr;
  328. s : string;
  329. forceasm : tasm;
  330. begin
  331. if opt='' then
  332. exit;
  333. { only parse define,undef,target,verbosity and link options the firsttime }
  334. if firstpass and
  335. not((opt[1]='-') and (opt[2] in ['i','d','v','V','T','u','n','X'])) then
  336. exit;
  337. Message1(option_handling_option,opt);
  338. case opt[1] of
  339. '-' :
  340. begin
  341. more:=Copy(opt,3,255);
  342. if firstpass then
  343. Message1(option_interpreting_firstpass_option,opt)
  344. else
  345. Message1(option_interpreting_option,opt);
  346. case opt[2] of
  347. '?' :
  348. WriteHelpPages;
  349. 'a' :
  350. begin
  351. include(initglobalswitches,cs_asm_leave);
  352. j:=1;
  353. while j<=length(more) do
  354. begin
  355. case more[j] of
  356. 'l' :
  357. include(initglobalswitches,cs_asm_source);
  358. 'r' :
  359. include(initglobalswitches,cs_asm_regalloc);
  360. 't' :
  361. include(initglobalswitches,cs_asm_tempalloc);
  362. 'n' :
  363. include(initglobalswitches,cs_asm_nodes);
  364. '-' :
  365. initglobalswitches:=initglobalswitches -
  366. [cs_asm_leave, cs_asm_source,cs_asm_regalloc, cs_asm_tempalloc, cs_asm_nodes];
  367. else
  368. IllegalPara(opt);
  369. end;
  370. inc(j);
  371. end;
  372. end;
  373. 'A' :
  374. begin
  375. if set_target_asm_by_string(More) then
  376. asm_is_set:=true
  377. else
  378. IllegalPara(opt);
  379. end;
  380. 'b' :
  381. begin
  382. if UnsetBool(More,0) then
  383. begin
  384. exclude(initmoduleswitches,cs_browser);
  385. exclude(initmoduleswitches,cs_local_browser);
  386. {$ifdef BrowserLog}
  387. exclude(initglobalswitches,cs_browser_log);
  388. {$endif}
  389. end
  390. else
  391. begin
  392. include(initmoduleswitches,cs_browser);
  393. {$ifdef BrowserLog}
  394. include(initglobalswitches,cs_browser_log);
  395. {$endif}
  396. end;
  397. if More<>'' then
  398. if (More='l') or (More='l+') then
  399. include(initmoduleswitches,cs_local_browser)
  400. else
  401. if More='l-' then
  402. exclude(initmoduleswitches,cs_local_browser)
  403. else
  404. {$ifdef BrowserLog}
  405. browserlog.elements_to_list.insert(more);
  406. {$else}
  407. IllegalPara(opt);
  408. {$endif}
  409. end;
  410. 'B' :
  411. do_build:=not UnSetBool(more,0);
  412. 'C' :
  413. begin
  414. j:=1;
  415. while j<=length(more) do
  416. begin
  417. case more[j] of
  418. 'a' :
  419. Message2(option_obsolete_switch_use_new,'-Ca','-Or');
  420. 'c' :
  421. begin
  422. if not SetAktProcCall(upper(copy(more,j+1,length(more)-j)),true) then
  423. IllegalPara(opt);
  424. break;
  425. end;
  426. {$ifdef cpufpemu}
  427. 'e' :
  428. begin
  429. If UnsetBool(More, j) then
  430. exclude(initmoduleswitches,cs_fp_emulation)
  431. Else
  432. include(initmoduleswitches,cs_fp_emulation);
  433. end;
  434. {$endif cpufpemu}
  435. {$ifdef arm}
  436. 'f' :
  437. begin
  438. s:=upper(copy(more,j+1,length(more)-j));
  439. if s='SOFT' then
  440. initfputype:=fpu_soft
  441. else if s='FPA' then
  442. initfputype:=fpu_fpa
  443. else if s='FPA10' then
  444. initfputype:=fpu_fpa10
  445. else if s='FPA11' then
  446. initfputype:=fpu_fpa11
  447. else if s='VFP' then
  448. initfputype:=fpu_vfp
  449. else
  450. IllegalPara(opt);
  451. break;
  452. end;
  453. {$endif arm}
  454. 'h' :
  455. begin
  456. val(copy(more,j+1,length(more)-j),heapsize,code);
  457. if (code<>0) or (heapsize>=67107840) or (heapsize<1024) then
  458. IllegalPara(opt);
  459. break;
  460. end;
  461. 'i' :
  462. If UnsetBool(More, j) then
  463. exclude(initlocalswitches,cs_check_io)
  464. else
  465. include(initlocalswitches,cs_check_io);
  466. 'n' :
  467. If UnsetBool(More, j) then
  468. exclude(initglobalswitches,cs_link_extern)
  469. Else
  470. include(initglobalswitches,cs_link_extern);
  471. 'o' :
  472. If UnsetBool(More, j) then
  473. exclude(initlocalswitches,cs_check_overflow)
  474. Else
  475. include(initlocalswitches,cs_check_overflow);
  476. 'r' :
  477. If UnsetBool(More, j) then
  478. exclude(initlocalswitches,cs_check_range)
  479. Else
  480. include(initlocalswitches,cs_check_range);
  481. 'R' :
  482. If UnsetBool(More, j) then
  483. begin
  484. exclude(initlocalswitches,cs_check_range);
  485. exclude(initlocalswitches,cs_check_object);
  486. end
  487. Else
  488. begin
  489. include(initlocalswitches,cs_check_range);
  490. include(initlocalswitches,cs_check_object);
  491. end;
  492. 's' :
  493. begin
  494. val(copy(more,j+1,length(more)-j),stacksize,code);
  495. if (code<>0) or (stacksize>=67107840) or (stacksize<1024) then
  496. IllegalPara(opt);
  497. break;
  498. end;
  499. 't' :
  500. If UnsetBool(More, j) then
  501. exclude(initlocalswitches,cs_check_stack)
  502. Else
  503. include(initlocalswitches,cs_check_stack);
  504. 'D' :
  505. If UnsetBool(More, j) then
  506. exclude(initmoduleswitches,cs_create_dynamic)
  507. Else
  508. include(initmoduleswitches,cs_create_dynamic);
  509. 'X' :
  510. If UnsetBool(More, j) then
  511. exclude(initmoduleswitches,cs_create_smart)
  512. Else
  513. include(initmoduleswitches,cs_create_smart);
  514. else
  515. IllegalPara(opt);
  516. end;
  517. inc(j);
  518. end;
  519. end;
  520. 'd' :
  521. def_symbol(more);
  522. 'D' :
  523. begin
  524. include(initglobalswitches,cs_link_deffile);
  525. j:=1;
  526. while j<=length(more) do
  527. begin
  528. case more[j] of
  529. 'd' :
  530. begin
  531. description:=Copy(more,j+1,255);
  532. break;
  533. end;
  534. 'v' :
  535. begin
  536. dllversion:=Copy(more,j+1,255);
  537. l:=pos('.',dllversion);
  538. dllminor:=0;
  539. error:=0;
  540. if l>0 then
  541. begin
  542. valint(copy(dllversion,l+1,255),minor,error);
  543. if (error=0) and
  544. (minor>=0) and (minor<=$ffff) then
  545. dllminor:=minor
  546. else
  547. if error=0 then
  548. error:=1;
  549. end;
  550. if l=0 then
  551. l:=256;
  552. dllmajor:=1;
  553. if error=0 then
  554. valint(copy(dllversion,1,l-1),major,error);
  555. if (error=0) and (major>=0) and (major<=$ffff) then
  556. dllmajor:=major
  557. else
  558. if error=0 then
  559. error:=1;
  560. if error<>0 then
  561. Message1(scan_w_wrong_version_ignored,dllversion);
  562. break;
  563. end;
  564. 'w' :
  565. usewindowapi:=true;
  566. '-' :
  567. begin
  568. exclude(initglobalswitches,cs_link_deffile);
  569. usewindowapi:=false;
  570. end;
  571. else
  572. IllegalPara(opt);
  573. end;
  574. inc(j);
  575. end;
  576. end;
  577. 'e' :
  578. exepath:=FixPath(More,true);
  579. 'E' :
  580. begin
  581. if UnsetBool(More, 0) then
  582. exclude(initglobalswitches,cs_link_extern)
  583. else
  584. include(initglobalswitches,cs_link_extern);
  585. end;
  586. 'F' :
  587. begin
  588. c:=more[1];
  589. Delete(more,1,1);
  590. DefaultReplacements(More);
  591. case c of
  592. 'c' :
  593. begin
  594. if not(cpavailable(more)) then
  595. Message1(option_code_page_not_available,more)
  596. else
  597. initsourcecodepage:=more;
  598. end;
  599. 'D' :
  600. utilsdirectory:=FixPath(More,true);
  601. 'e' :
  602. SetRedirectFile(More);
  603. 'E' :
  604. OutputExeDir:=FixPath(More,true);
  605. 'i' :
  606. begin
  607. if ispara then
  608. ParaIncludePath.AddPath(More,false)
  609. else
  610. includesearchpath.AddPath(More,true);
  611. end;
  612. 'g' :
  613. Message2(option_obsolete_switch_use_new,'-Fg','-Fl');
  614. 'l' :
  615. begin
  616. if ispara then
  617. ParaLibraryPath.AddPath(More,false)
  618. else
  619. LibrarySearchPath.AddPath(More,true);
  620. end;
  621. 'L' :
  622. begin
  623. if More<>'' then
  624. ParaDynamicLinker:=More
  625. else
  626. IllegalPara(opt);
  627. end;
  628. 'o' :
  629. begin
  630. if ispara then
  631. ParaObjectPath.AddPath(More,false)
  632. else
  633. ObjectSearchPath.AddPath(More,true);
  634. end;
  635. 'r' :
  636. Msgfilename:=More;
  637. 'u' :
  638. begin
  639. if ispara then
  640. ParaUnitPath.AddPath(More,false)
  641. else
  642. unitsearchpath.AddPath(More,true);
  643. end;
  644. 'U' :
  645. OutputUnitDir:=FixPath(More,true);
  646. else
  647. IllegalPara(opt);
  648. end;
  649. end;
  650. 'g' : begin
  651. if UnsetBool(More, 0) then
  652. begin
  653. exclude(initmoduleswitches,cs_debuginfo);
  654. exclude(initglobalswitches,cs_gdb_dbx);
  655. exclude(initglobalswitches,cs_gdb_gsym);
  656. exclude(initglobalswitches,cs_gdb_heaptrc);
  657. exclude(initglobalswitches,cs_gdb_lineinfo);
  658. exclude(initglobalswitches,cs_checkpointer);
  659. end
  660. else
  661. begin
  662. {$ifdef GDB}
  663. include(initmoduleswitches,cs_debuginfo);
  664. if not RelocSectionSetExplicitly then
  665. RelocSection:=false;
  666. j:=1;
  667. while j<=length(more) do
  668. begin
  669. case more[j] of
  670. 'd' :
  671. begin
  672. if UnsetBool(More, j) then
  673. exclude(initglobalswitches,cs_gdb_dbx)
  674. else
  675. include(initglobalswitches,cs_gdb_dbx);
  676. end;
  677. 'g' :
  678. begin
  679. if UnsetBool(More, j) then
  680. exclude(initglobalswitches,cs_gdb_gsym)
  681. else
  682. include(initglobalswitches,cs_gdb_gsym);
  683. end;
  684. 'h' :
  685. begin
  686. if UnsetBool(More, j) then
  687. exclude(initglobalswitches,cs_gdb_heaptrc)
  688. else
  689. include(initglobalswitches,cs_gdb_heaptrc);
  690. end;
  691. 'l' :
  692. begin
  693. if UnsetBool(More, j) then
  694. exclude(initglobalswitches,cs_gdb_lineinfo)
  695. else
  696. include(initglobalswitches,cs_gdb_lineinfo);
  697. end;
  698. 'c' :
  699. begin
  700. if UnsetBool(More, j) then
  701. exclude(initglobalswitches,cs_checkpointer)
  702. else
  703. include(initglobalswitches,cs_checkpointer);
  704. end;
  705. else
  706. IllegalPara(opt);
  707. end;
  708. inc(j);
  709. end;
  710. {$else GDB}
  711. Message(option_no_debug_support);
  712. Message(option_no_debug_support_recompile_fpc);
  713. {$endif GDB}
  714. end;
  715. end;
  716. 'h' :
  717. begin
  718. NoPressEnter:=true;
  719. WriteHelpPages;
  720. end;
  721. 'i' :
  722. begin
  723. if More='' then
  724. WriteInfo
  725. else
  726. QuickInfo:=QuickInfo+More;
  727. end;
  728. 'I' :
  729. begin
  730. if ispara then
  731. ParaIncludePath.AddPath(More,false)
  732. else
  733. includesearchpath.AddPath(More,false);
  734. end;
  735. 'k' :
  736. begin
  737. if more<>'' then
  738. ParaLinkOptions:=ParaLinkOptions+' '+More
  739. else
  740. IllegalPara(opt);
  741. end;
  742. 'l' :
  743. DoWriteLogo:=not UnSetBool(more,0);
  744. 'm' :
  745. parapreprocess:=not UnSetBool(more,0);
  746. 'n' :
  747. begin
  748. if More='' then
  749. disable_configfile:=true
  750. else
  751. IllegalPara(opt);
  752. end;
  753. 'o' :
  754. begin
  755. if More<>'' then
  756. Fsplit(More,d,OutputFile,e)
  757. else
  758. IllegalPara(opt);
  759. end;
  760. 'p' :
  761. begin
  762. if UnsetBool(More, 0) then
  763. begin
  764. initmoduleswitches:=initmoduleswitches-[cs_profile];
  765. undef_symbol('FPC_PROFILE');
  766. end
  767. else
  768. if Length(More)=0 then
  769. IllegalPara(opt)
  770. else
  771. case more[1] of
  772. 'g' : if UnsetBool(more, 1) then
  773. begin
  774. exclude(initmoduleswitches,cs_profile);
  775. undef_symbol('FPC_PROFILE');
  776. end
  777. else
  778. begin
  779. include(initmoduleswitches,cs_profile);
  780. def_symbol('FPC_PROFILE');
  781. end;
  782. else
  783. IllegalPara(opt);
  784. end;
  785. end;
  786. {$ifdef Unix}
  787. 'P' :
  788. begin
  789. if UnsetBool(More, 0) then
  790. exclude(initglobalswitches,cs_asm_pipe)
  791. else
  792. include(initglobalswitches,cs_asm_pipe);
  793. end;
  794. {$endif Unix}
  795. 's' :
  796. begin
  797. if UnsetBool(More, 0) then
  798. begin
  799. initglobalswitches:=initglobalswitches-[cs_asm_extern,cs_link_extern];
  800. if more<>'' then
  801. IllegalPara(opt);
  802. end
  803. else
  804. begin
  805. initglobalswitches:=initglobalswitches+[cs_asm_extern,cs_link_extern];
  806. if more='h' then
  807. initglobalswitches:=initglobalswitches-[cs_link_on_target]
  808. else if more='t' then
  809. initglobalswitches:=initglobalswitches+[cs_link_on_target]
  810. else if more='r' then
  811. initglobalswitches:=initglobalswitches+[cs_asm_leave,cs_no_regalloc]
  812. else if more<>'' then
  813. IllegalPara(opt);
  814. end;
  815. end;
  816. 'S' :
  817. begin
  818. if more[1]='I' then
  819. begin
  820. if upper(more)='ICOM' then
  821. initinterfacetype:=it_interfacecom
  822. else if upper(more)='ICORBA' then
  823. initinterfacetype:=it_interfacecorba
  824. else
  825. IllegalPara(opt);
  826. end
  827. else
  828. begin
  829. j:=1;
  830. while j<=length(more) do
  831. begin
  832. case more[j] of
  833. '2' :
  834. SetCompileMode('OBJFPC',true);
  835. 'a' :
  836. include(initlocalswitches,cs_do_assertion);
  837. 'c' :
  838. include(initmoduleswitches,cs_support_c_operators);
  839. 'd' :
  840. SetCompileMode('DELPHI',true);
  841. 'e' :
  842. begin
  843. SetErrorFlags(copy(more,j+1,length(more)));
  844. break;
  845. end;
  846. 'g' :
  847. include(initmoduleswitches,cs_support_goto);
  848. 'h' :
  849. include(initlocalswitches,cs_ansistrings);
  850. 'i' :
  851. include(initmoduleswitches,cs_support_inline);
  852. 'm' :
  853. include(initmoduleswitches,cs_support_macro);
  854. 'o' :
  855. SetCompileMode('TP',true);
  856. 'p' :
  857. SetCompileMode('GPC',true);
  858. 's' :
  859. include(initglobalswitches,cs_constructor_name);
  860. 't' :
  861. include(initmoduleswitches,cs_static_keyword);
  862. '-' :
  863. begin
  864. exclude(initglobalswitches,cs_constructor_name);
  865. initlocalswitches:=InitLocalswitches - [cs_do_assertion, cs_ansistrings];
  866. initmoduleswitches:=initmoduleswitches - [cs_support_c_operators, cs_support_goto,
  867. cs_support_inline, cs_support_macro,
  868. cs_static_keyword];
  869. end;
  870. else
  871. IllegalPara(opt);
  872. end;
  873. inc(j);
  874. end;
  875. end;
  876. end;
  877. 'T' :
  878. begin
  879. more:=Upper(More);
  880. if not target_is_set then
  881. begin
  882. { remove old target define }
  883. TargetDefines(false);
  884. { Save assembler if set }
  885. if asm_is_set then
  886. forceasm:=target_asm.id;
  887. { load new target }
  888. if not(set_target_by_string(More)) then
  889. IllegalPara(opt);
  890. { also initialize assembler if not explicitly set }
  891. if asm_is_set then
  892. set_target_asm(forceasm);
  893. { set new define }
  894. TargetDefines(true);
  895. target_is_set:=true;
  896. end
  897. else
  898. if More<>upper(target_info.shortname) then
  899. Message1(option_target_is_already_set,target_info.shortname);
  900. end;
  901. 'u' :
  902. undef_symbol(upper(More));
  903. 'U' :
  904. begin
  905. j:=1;
  906. while j<=length(more) do
  907. begin
  908. case more[j] of
  909. {$ifdef UNITALIASES}
  910. 'a' :
  911. begin
  912. AddUnitAlias(Copy(More,j+1,255));
  913. break;
  914. end;
  915. {$endif UNITALIASES}
  916. 'n' :
  917. exclude(initglobalswitches,cs_check_unit_name);
  918. 'p' :
  919. begin
  920. Message2(option_obsolete_switch_use_new,'-Up','-Fu');
  921. break;
  922. end;
  923. 'r' :
  924. do_release:=true;
  925. 's' :
  926. include(initmoduleswitches,cs_compilesystem);
  927. '-' :
  928. begin
  929. exclude(initmoduleswitches,cs_compilesystem);
  930. exclude(initglobalswitches,cs_check_unit_name);
  931. end;
  932. else
  933. IllegalPara(opt);
  934. end;
  935. inc(j);
  936. end;
  937. end;
  938. 'v' :
  939. begin
  940. if not setverbosity(More) then
  941. IllegalPara(opt);
  942. end;
  943. 'V' :
  944. PrepareReport;
  945. 'W' :
  946. begin
  947. j:=1;
  948. while j<=length(More) do
  949. begin
  950. case More[j] of
  951. 'B':
  952. begin
  953. { -WB200000 means set trefered base address
  954. to $200000, but does not change relocsection boolean
  955. this way we can create both relocatble and
  956. non relocatable DLL at a specific base address PM }
  957. if (length(More)>j) then
  958. begin
  959. if DLLImageBase=nil then
  960. DLLImageBase:=StringDup(Copy(More,j+1,255));
  961. end
  962. else
  963. begin
  964. RelocSection:=true;
  965. RelocSectionSetExplicitly:=true;
  966. end;
  967. break;
  968. end;
  969. 'C':
  970. begin
  971. if UnsetBool(More, j) then
  972. apptype:=app_gui
  973. else
  974. apptype:=app_cui;
  975. end;
  976. 'D':
  977. ForceDeffileForExport:=not UnsetBool(More, j);
  978. 'F':
  979. begin
  980. if UnsetBool(More, j) then
  981. apptype:=app_cui
  982. else
  983. apptype:=app_fs;
  984. end;
  985. 'G':
  986. begin
  987. if UnsetBool(More, j) then
  988. apptype:=app_cui
  989. else
  990. apptype:=app_gui;
  991. end;
  992. 'N':
  993. begin
  994. RelocSection:=UnsetBool(More,j);
  995. RelocSectionSetExplicitly:=true;
  996. end;
  997. 'R':
  998. begin
  999. { support -WR+ / -WR- as synonyms to -WR / -WN }
  1000. RelocSection:=not UnsetBool(More,j);
  1001. RelocSectionSetExplicitly:=true;
  1002. end;
  1003. else
  1004. IllegalPara(opt);
  1005. end;
  1006. inc(j);
  1007. end;
  1008. end;
  1009. 'X' :
  1010. begin
  1011. j:=1;
  1012. while j<=length(more) do
  1013. begin
  1014. case More[j] of
  1015. 'i' :
  1016. include(initglobalswitches,cs_link_internal);
  1017. 'm' :
  1018. include(initglobalswitches,cs_link_map);
  1019. 's' :
  1020. include(initglobalswitches,cs_link_strip);
  1021. 't' :
  1022. include(initglobalswitches,cs_link_staticflag);
  1023. 'D' :
  1024. begin
  1025. def_symbol('FPC_LINK_DYNAMIC');
  1026. undef_symbol('FPC_LINK_SMART');
  1027. undef_symbol('FPC_LINK_STATIC');
  1028. exclude(initglobalswitches,cs_link_static);
  1029. exclude(initglobalswitches,cs_link_smart);
  1030. include(initglobalswitches,cs_link_shared);
  1031. LinkTypeSetExplicitly:=true;
  1032. end;
  1033. 'S' :
  1034. begin
  1035. def_symbol('FPC_LINK_STATIC');
  1036. undef_symbol('FPC_LINK_SMART');
  1037. undef_symbol('FPC_LINK_DYNAMIC');
  1038. include(initglobalswitches,cs_link_static);
  1039. exclude(initglobalswitches,cs_link_smart);
  1040. exclude(initglobalswitches,cs_link_shared);
  1041. LinkTypeSetExplicitly:=true;
  1042. end;
  1043. 'X' :
  1044. begin
  1045. def_symbol('FPC_LINK_SMART');
  1046. undef_symbol('FPC_LINK_STATIC');
  1047. undef_symbol('FPC_LINK_DYNAMIC');
  1048. exclude(initglobalswitches,cs_link_static);
  1049. include(initglobalswitches,cs_link_smart);
  1050. exclude(initglobalswitches,cs_link_shared);
  1051. LinkTypeSetExplicitly:=true;
  1052. end;
  1053. '-' :
  1054. begin
  1055. exclude(initglobalswitches,cs_link_staticflag);
  1056. exclude(initglobalswitches,cs_link_strip);
  1057. exclude(initglobalswitches,cs_link_map);
  1058. set_default_link_type;
  1059. end;
  1060. else
  1061. IllegalPara(opt);
  1062. end;
  1063. inc(j);
  1064. end;
  1065. end;
  1066. { give processor specific options a chance }
  1067. else
  1068. interpret_proc_specific_options(opt);
  1069. end;
  1070. end;
  1071. '@' :
  1072. begin
  1073. Message(option_no_nested_response_file);
  1074. StopOptions;
  1075. end;
  1076. else
  1077. begin
  1078. if (length(param_file)<>0) then
  1079. Message(option_only_one_source_support);
  1080. param_file:=opt;
  1081. Message1(option_found_file,opt);
  1082. end;
  1083. end;
  1084. end;
  1085. procedure Toption.Interpret_file(const filename : string);
  1086. procedure RemoveSep(var fn:string);
  1087. var
  1088. i : longint;
  1089. begin
  1090. i:=0;
  1091. while (i<length(fn)) and (fn[i+1] in [',',' ',#9]) do
  1092. inc(i);
  1093. Delete(fn,1,i);
  1094. i:=length(fn);
  1095. while (i>0) and (fn[i] in [',',' ',#9]) do
  1096. dec(i);
  1097. fn:=copy(fn,1,i);
  1098. end;
  1099. function GetName(var fn:string):string;
  1100. var
  1101. i : longint;
  1102. begin
  1103. i:=0;
  1104. while (i<length(fn)) and (fn[i+1] in ['a'..'z','A'..'Z','0'..'9','_','-']) do
  1105. inc(i);
  1106. GetName:=Copy(fn,1,i);
  1107. Delete(fn,1,i);
  1108. end;
  1109. const
  1110. maxlevel=16;
  1111. var
  1112. f : text;
  1113. s,
  1114. opts : string;
  1115. skip : array[0..maxlevel-1] of boolean;
  1116. level : longint;
  1117. option_read : boolean;
  1118. begin
  1119. { avoid infinite loop }
  1120. Inc(FileLevel);
  1121. Option_read:=false;
  1122. If FileLevel>MaxLevel then
  1123. Message(option_too_many_cfg_files);
  1124. { open file }
  1125. Message1(option_using_file,filename);
  1126. assign(f,filename);
  1127. {$I-}
  1128. reset(f);
  1129. {$I+}
  1130. if ioresult<>0 then
  1131. begin
  1132. Message1(option_unable_open_file,filename);
  1133. exit;
  1134. end;
  1135. Message1(option_start_reading_configfile,filename);
  1136. fillchar(skip,sizeof(skip),0);
  1137. level:=0;
  1138. while not eof(f) do
  1139. begin
  1140. readln(f,opts);
  1141. RemoveSep(opts);
  1142. if (opts<>'') and (opts[1]<>';') then
  1143. begin
  1144. if opts[1]='#' then
  1145. begin
  1146. Message1(option_interpreting_file_option,opts);
  1147. Delete(opts,1,1);
  1148. s:=upper(GetName(opts));
  1149. if (s='SECTION') then
  1150. begin
  1151. RemoveSep(opts);
  1152. s:=upper(GetName(opts));
  1153. if level=0 then
  1154. skip[level]:=not (check_symbol(s) or (s='COMMON'));
  1155. end
  1156. else
  1157. if (s='IFDEF') then
  1158. begin
  1159. RemoveSep(opts);
  1160. if Level>=maxlevel then
  1161. begin
  1162. Message(option_too_many_ifdef);
  1163. stopOptions;
  1164. end;
  1165. inc(Level);
  1166. skip[level]:=(skip[level-1] or (not check_symbol(upper(GetName(opts)))));
  1167. end
  1168. else
  1169. if (s='IFNDEF') then
  1170. begin
  1171. RemoveSep(opts);
  1172. if Level>=maxlevel then
  1173. begin
  1174. Message(option_too_many_ifdef);
  1175. stopOptions;
  1176. end;
  1177. inc(Level);
  1178. skip[level]:=(skip[level-1] or (check_symbol(upper(GetName(opts)))));
  1179. end
  1180. else
  1181. if (s='ELSE') then
  1182. skip[level]:=skip[level-1] or (not skip[level])
  1183. else
  1184. if (s='ENDIF') then
  1185. begin
  1186. skip[level]:=false;
  1187. if Level=0 then
  1188. begin
  1189. Message(option_too_many_endif);
  1190. stopOptions;
  1191. end;
  1192. dec(level);
  1193. end
  1194. else
  1195. if (not skip[level]) then
  1196. begin
  1197. if (s='DEFINE') then
  1198. begin
  1199. RemoveSep(opts);
  1200. def_symbol(upper(GetName(opts)));
  1201. end
  1202. else
  1203. if (s='UNDEF') then
  1204. begin
  1205. RemoveSep(opts);
  1206. undef_symbol(upper(GetName(opts)));
  1207. end
  1208. else
  1209. if (s='WRITE') then
  1210. begin
  1211. Delete(opts,1,1);
  1212. WriteLn(opts);
  1213. end
  1214. else
  1215. if (s='INCLUDE') then
  1216. begin
  1217. Delete(opts,1,1);
  1218. Interpret_file(opts);
  1219. end;
  1220. end;
  1221. end
  1222. else
  1223. begin
  1224. if (opts[1]='-') or (opts[1]='@') then
  1225. begin
  1226. if (not skip[level]) then
  1227. interpret_option(opts,false);
  1228. Option_read:=true;
  1229. end
  1230. else
  1231. Message1(option_illegal_para,opts);
  1232. end;
  1233. end;
  1234. end;
  1235. if Level>0 then
  1236. Message(option_too_less_endif);
  1237. if Not Option_read then
  1238. Message1(option_no_option_found,filename)
  1239. else
  1240. Message1(option_end_reading_configfile,filename);
  1241. Close(f);
  1242. Dec(FileLevel);
  1243. end;
  1244. procedure Toption.Interpret_envvar(const envname : string);
  1245. var
  1246. argstart,
  1247. env,
  1248. pc : pchar;
  1249. arglen : longint;
  1250. quote : set of char;
  1251. hs : string;
  1252. begin
  1253. Message1(option_using_env,envname);
  1254. env:=GetEnvPChar(envname);
  1255. pc:=env;
  1256. if assigned(pc) then
  1257. begin
  1258. repeat
  1259. { skip leading spaces }
  1260. while pc^ in [' ',#9,#13] do
  1261. inc(pc);
  1262. case pc^ of
  1263. #0 :
  1264. break;
  1265. '"' :
  1266. begin
  1267. quote:=['"'];
  1268. inc(pc);
  1269. end;
  1270. '''' :
  1271. begin
  1272. quote:=[''''];
  1273. inc(pc);
  1274. end;
  1275. else
  1276. quote:=[' ',#9,#13];
  1277. end;
  1278. { scan until the end of the argument }
  1279. argstart:=pc;
  1280. while (pc^<>#0) and not(pc^ in quote) do
  1281. inc(pc);
  1282. { create argument }
  1283. arglen:=pc-argstart;
  1284. hs[0]:=chr(arglen);
  1285. move(argstart^,hs[1],arglen);
  1286. interpret_option(hs,true);
  1287. { skip quote }
  1288. if pc^ in quote then
  1289. inc(pc);
  1290. until false;
  1291. end
  1292. else
  1293. Message1(option_no_option_found,'(env) '+envname);
  1294. FreeEnvPChar(env);
  1295. end;
  1296. procedure toption.read_parameters;
  1297. var
  1298. opts : string;
  1299. paramindex : longint;
  1300. begin
  1301. paramindex:=0;
  1302. while paramindex<paramcount do
  1303. begin
  1304. inc(paramindex);
  1305. opts:=system.paramstr(paramindex);
  1306. case opts[1] of
  1307. '@' :
  1308. if not firstpass then
  1309. begin
  1310. Delete(opts,1,1);
  1311. Message1(option_reading_further_from,opts);
  1312. interpret_file(opts);
  1313. end;
  1314. '!' :
  1315. if not firstpass then
  1316. begin
  1317. Delete(opts,1,1);
  1318. Message1(option_reading_further_from,'(env) '+opts);
  1319. interpret_envvar(opts);
  1320. end;
  1321. else
  1322. interpret_option(opts,true);
  1323. end;
  1324. end;
  1325. end;
  1326. procedure toption.parsecmd(cmd:string);
  1327. var
  1328. i,ps : longint;
  1329. opts : string;
  1330. begin
  1331. while (cmd<>'') do
  1332. begin
  1333. while cmd[1]=' ' do
  1334. delete(cmd,1,1);
  1335. i:=pos(' ',cmd);
  1336. if i=0 then
  1337. i:=256;
  1338. opts:=Copy(cmd,1,i-1);
  1339. Delete(cmd,1,i);
  1340. case opts[1] of
  1341. '@' :
  1342. if not firstpass then
  1343. begin
  1344. Delete(opts,1,1);
  1345. Message1(option_reading_further_from,opts);
  1346. interpret_file(opts);
  1347. end;
  1348. '!' :
  1349. if not firstpass then
  1350. begin
  1351. Delete(opts,1,1);
  1352. Message1(option_reading_further_from,'(env) '+opts);
  1353. interpret_envvar(opts);
  1354. end;
  1355. '"' :
  1356. begin
  1357. Delete(opts,1,1);
  1358. ps:=pos('"',cmd);
  1359. if (i<>256) and (ps>0) then
  1360. begin
  1361. opts:=opts + ' '+ copy(cmd,1,ps-1);
  1362. cmd:=copy(cmd,ps+1,255);
  1363. end;
  1364. interpret_option(opts,true);
  1365. end;
  1366. else
  1367. interpret_option(opts,true);
  1368. end;
  1369. end;
  1370. end;
  1371. procedure toption.writequickinfo;
  1372. var
  1373. s : string;
  1374. i : longint;
  1375. procedure addinfo(const hs:string);
  1376. begin
  1377. if s<>'' then
  1378. s:=s+' '+hs
  1379. else
  1380. s:=hs;
  1381. end;
  1382. begin
  1383. s:='';
  1384. i:=0;
  1385. while (i<length(quickinfo)) do
  1386. begin
  1387. inc(i);
  1388. case quickinfo[i] of
  1389. 'S' :
  1390. begin
  1391. inc(i);
  1392. case quickinfo[i] of
  1393. 'O' :
  1394. addinfo(lower(source_info.shortname));
  1395. {$ifdef Delphi}
  1396. 'P' :
  1397. addinfo('i386');
  1398. {$else Delphi}
  1399. 'P' :
  1400. addinfo(source_cpu_string);
  1401. {$endif Delphi}
  1402. else
  1403. IllegalPara('-iS'+QuickInfo);
  1404. end;
  1405. end;
  1406. 'T' :
  1407. begin
  1408. inc(i);
  1409. case quickinfo[i] of
  1410. 'O' :
  1411. addinfo(lower(target_info.shortname));
  1412. 'P' :
  1413. AddInfo(target_cpu_string);
  1414. else
  1415. IllegalPara('-iT'+QuickInfo);
  1416. end;
  1417. end;
  1418. 'V' :
  1419. AddInfo(version_string);
  1420. 'D' :
  1421. AddInfo(date_string);
  1422. '_' :
  1423. ;
  1424. else
  1425. IllegalPara('-i'+QuickInfo);
  1426. end;
  1427. end;
  1428. if s<>'' then
  1429. begin
  1430. writeln(s);
  1431. stopoptions;
  1432. end;
  1433. end;
  1434. procedure TOption.TargetDefines(def:boolean);
  1435. var
  1436. s : string;
  1437. i : integer;
  1438. begin
  1439. if def then
  1440. def_symbol(upper(target_info.shortname))
  1441. else
  1442. undef_symbol(upper(target_info.shortname));
  1443. s:=target_info.extradefines;
  1444. while (s<>'') do
  1445. begin
  1446. i:=pos(';',s);
  1447. if i=0 then
  1448. i:=length(s)+1;
  1449. if def then
  1450. def_symbol(Copy(s,1,i-1))
  1451. else
  1452. undef_symbol(Copy(s,1,i-1));
  1453. delete(s,1,i);
  1454. end;
  1455. end;
  1456. constructor TOption.create;
  1457. begin
  1458. DoWriteLogo:=false;
  1459. NoPressEnter:=false;
  1460. FirstPass:=false;
  1461. FileLevel:=0;
  1462. Quickinfo:='';
  1463. ParaIncludePath:=TSearchPathList.Create;
  1464. ParaObjectPath:=TSearchPathList.Create;
  1465. ParaUnitPath:=TSearchPathList.Create;
  1466. ParaLibraryPath:=TSearchPathList.Create;
  1467. FillChar(ParaAlignment,sizeof(ParaAlignment),0);
  1468. end;
  1469. destructor TOption.destroy;
  1470. begin
  1471. ParaIncludePath.Free;
  1472. ParaObjectPath.Free;
  1473. ParaUnitPath.Free;
  1474. ParaLibraryPath.Free;
  1475. end;
  1476. {****************************************************************************
  1477. Callable Routines
  1478. ****************************************************************************}
  1479. function check_configfile(const fn:string;var foundfn:string):boolean;
  1480. function CfgFileExists(const fn:string):boolean;
  1481. begin
  1482. Comment(V_Tried,'Configfile search: '+fn);
  1483. CfgFileExists:=FileExists(fn);
  1484. end;
  1485. var
  1486. configpath : pathstr;
  1487. begin
  1488. foundfn:=fn;
  1489. check_configfile:=true;
  1490. { retrieve configpath }
  1491. {$ifdef Delphi}
  1492. configpath:=FixPath(dmisc.getenv('PPC_CONFIG_PATH'),false);
  1493. {$else Delphi}
  1494. configpath:=FixPath(dos.getenv('PPC_CONFIG_PATH'),false);
  1495. {$endif Delphi}
  1496. {$ifdef Unix}
  1497. if configpath='' then
  1498. configpath:='/etc/';
  1499. {$endif}
  1500. {
  1501. Order to read configuration file :
  1502. try reading fpc.cfg in :
  1503. 1 - current dir
  1504. 2 - configpath
  1505. 3 - compiler path
  1506. }
  1507. if not FileExists(fn) then
  1508. begin
  1509. {$ifdef Unix}
  1510. if (dos.getenv('HOME')<>'') and CfgFileExists(FixPath(dos.getenv('HOME'),false)+'.'+fn) then
  1511. foundfn:=FixPath(dos.getenv('HOME'),false)+'.'+fn
  1512. else
  1513. {$endif}
  1514. if CfgFileExists(configpath+fn) then
  1515. foundfn:=configpath+fn
  1516. else
  1517. {$ifndef Unix}
  1518. if CfgFileExists(exepath+fn) then
  1519. foundfn:=exepath+fn
  1520. else
  1521. {$endif}
  1522. check_configfile:=false;
  1523. end;
  1524. end;
  1525. procedure read_arguments(cmd:string);
  1526. begin
  1527. option:=coption.create;
  1528. disable_configfile:=false;
  1529. { default defines }
  1530. def_symbol(upper(target_info.shortname));
  1531. def_symbol('FPC');
  1532. def_symbol('VER'+version_nr);
  1533. def_symbol('VER'+version_nr+'_'+release_nr);
  1534. def_symbol('VER'+version_nr+'_'+release_nr+'_'+patch_nr);
  1535. { Temporary defines, until things settle down }
  1536. def_symbol('HASWIDECHAR');
  1537. def_symbol('HASWIDESTRING');
  1538. def_symbol('HASOUT');
  1539. { for now, the PowerPC doesn't support variants and interfaces }
  1540. {$ifdef i386}
  1541. def_symbol('HASINTF');
  1542. def_symbol('HASVARIANT');
  1543. {$endif i386}
  1544. def_symbol('INTERNSETLENGTH');
  1545. def_symbol('INTERNLENGTH');
  1546. def_symbol('INTERNCOPY');
  1547. def_symbol('INT64FUNCRESOK');
  1548. def_symbol('HAS_ADDR_STACK_ON_STACK');
  1549. def_symbol('NOBOUNDCHECK');
  1550. def_symbol('HASCOMPILERPROC');
  1551. def_symbol('VALUEGETMEM');
  1552. def_symbol('VALUEFREEMEM');
  1553. def_symbol('HASCURRENCY');
  1554. def_symbol('HASTHREADVAR');
  1555. def_symbol('HAS_GENERICCONSTRUCTOR');
  1556. def_symbol('NOCLASSHELPERS');
  1557. { using a case is pretty useless here (FK) }
  1558. { some stuff for TP compatibility }
  1559. {$ifdef i386}
  1560. def_symbol('CPU86');
  1561. def_symbol('CPU87');
  1562. {$endif}
  1563. {$ifdef m68k}
  1564. def_symbol('CPU68');
  1565. {$endif}
  1566. { new processor stuff }
  1567. {$ifdef i386}
  1568. def_symbol('CPUI386');
  1569. def_symbol('CPU32');
  1570. def_symbol('FPC_HAS_TYPE_EXTENDED');
  1571. def_symbol('FPC_HAS_TYPE_DOUBLE');
  1572. def_symbol('FPC_HAS_TYPE_SINGLE');
  1573. {$endif}
  1574. {$ifdef m68k}
  1575. def_symbol('CPU68K');
  1576. def_symbol('CPU32');
  1577. {$endif}
  1578. {$ifdef ALPHA}
  1579. def_symbol('CPUALPHA');
  1580. def_symbol('CPU64');
  1581. {$endif}
  1582. {$ifdef powerpc}
  1583. def_symbol('CPUPOWERPC');
  1584. def_symbol('CPUPOWERPC32');
  1585. def_symbol('CPU32');
  1586. def_symbol('FPC_HAS_TYPE_DOUBLE');
  1587. def_symbol('FPC_HAS_TYPE_SINGLE');
  1588. {$endif}
  1589. {$ifdef iA64}
  1590. def_symbol('CPUIA64');
  1591. def_symbol('CPU64');
  1592. {$endif}
  1593. {$ifdef x86_64}
  1594. def_symbol('CPUX86_64');
  1595. def_symbol('CPU64');
  1596. def_symbol('FPC_HAS_TYPE_FLOAT128');
  1597. def_symbol('FPC_HAS_TYPE_EXTENDED');
  1598. def_symbol('FPC_HAS_TYPE_DOUBLE');
  1599. def_symbol('FPC_HAS_TYPE_SINGLE');
  1600. {$endif}
  1601. {$ifdef sparc}
  1602. def_symbol('CPUSPARC');
  1603. def_symbol('CPUSPARC32');
  1604. def_symbol('CPU32');
  1605. def_symbol('FPC_HAS_TYPE_DOUBLE');
  1606. def_symbol('FPC_HAS_TYPE_SINGLE');
  1607. def_symbol('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  1608. {$endif}
  1609. {$ifdef vis}
  1610. def_symbol('CPUVIS');
  1611. def_symbol('CPU32');
  1612. {$endif}
  1613. {$ifdef arm}
  1614. def_symbol('CPUARM');
  1615. def_symbol('CPU32');
  1616. def_symbol('FPC_HAS_TYPE_DOUBLE');
  1617. def_symbol('FPC_HAS_TYPE_SINGLE');
  1618. {$endif arm}
  1619. { get default messagefile }
  1620. {$ifdef Delphi}
  1621. msgfilename:=dmisc.getenv('PPC_ERROR_FILE');
  1622. {$else Delphi}
  1623. msgfilename:=dos.getenv('PPC_ERROR_FILE');
  1624. {$endif Delphi}
  1625. { default configfile can be specified on the commandline,
  1626. remove it first }
  1627. if (cmd<>'') and (cmd[1]='[') then
  1628. begin
  1629. ppccfg:=Copy(cmd,2,pos(']',cmd)-2);
  1630. Delete(cmd,1,pos(']',cmd));
  1631. end
  1632. else
  1633. begin
  1634. ppccfg:='fpc.cfg';
  1635. ppcaltcfg:='ppc386.cfg';
  1636. end;
  1637. { read the parameters quick, only -i -v -T }
  1638. option.firstpass:=true;
  1639. if cmd<>'' then
  1640. option.parsecmd(cmd)
  1641. else
  1642. begin
  1643. option.read_parameters;
  1644. { Write only quickinfo }
  1645. if option.quickinfo<>'' then
  1646. option.writequickinfo;
  1647. end;
  1648. option.firstpass:=false;
  1649. { read configuration file }
  1650. if (not disable_configfile) and
  1651. (ppccfg<>'') then
  1652. begin
  1653. read_configfile:=check_configfile(ppccfg,ppccfg);
  1654. { Maybe alternative configfile ? }
  1655. if (not read_configfile) and
  1656. (ppcaltcfg<>'') then
  1657. read_configfile:=check_configfile(ppcaltcfg,ppccfg);
  1658. end
  1659. else
  1660. read_configfile := false;
  1661. { Read commandline and configfile }
  1662. target_is_set:=false;
  1663. asm_is_set:=false;
  1664. param_file:='';
  1665. { read configfile }
  1666. if read_configfile then
  1667. option.interpret_file(ppccfg);
  1668. { read parameters again to override config file }
  1669. if cmd<>'' then
  1670. option.parsecmd(cmd)
  1671. else
  1672. begin
  1673. option.read_parameters;
  1674. { Write only quickinfo }
  1675. if option.quickinfo<>'' then
  1676. option.writequickinfo;
  1677. end;
  1678. { Write help pages }
  1679. if (cmd='') and (paramcount=0) then
  1680. Option.WriteHelpPages;
  1681. { Stop if errors in options }
  1682. if ErrorCount>0 then
  1683. StopOptions;
  1684. { Non-core target defines }
  1685. Option.TargetDefines(true);
  1686. { endian define }
  1687. case target_info.endian of
  1688. endian_little :
  1689. begin
  1690. def_symbol('ENDIAN_LITTLE');
  1691. def_symbol('FPC_LITTLE_ENDIAN');
  1692. end;
  1693. endian_big :
  1694. begin
  1695. def_symbol('ENDIAN_BIG');
  1696. def_symbol('FPC_BIG_ENDIAN');
  1697. end;
  1698. end;
  1699. {$ifdef m68k}
  1700. if initoptprocessor=MC68020 then
  1701. def_symbol('CPUM68020');
  1702. {$endif m68k}
  1703. { write logo if set }
  1704. if option.DoWriteLogo then
  1705. option.WriteLogo;
  1706. { Check file to compile }
  1707. if param_file='' then
  1708. begin
  1709. Message(option_no_source_found);
  1710. StopOptions;
  1711. end;
  1712. {$ifndef Unix}
  1713. param_file:=FixFileName(param_file);
  1714. {$endif}
  1715. fsplit(param_file,inputdir,inputfile,inputextension);
  1716. if inputextension='' then
  1717. begin
  1718. if FileExists(inputdir+inputfile+target_info.sourceext) then
  1719. inputextension:=target_info.sourceext
  1720. else
  1721. if FileExists(inputdir+inputfile+target_info.pasext) then
  1722. inputextension:=target_info.pasext;
  1723. end;
  1724. { Add paths specified with parameters to the searchpaths }
  1725. UnitSearchPath.AddList(option.ParaUnitPath,true);
  1726. ObjectSearchPath.AddList(option.ParaObjectPath,true);
  1727. IncludeSearchPath.AddList(option.ParaIncludePath,true);
  1728. LibrarySearchPath.AddList(option.ParaLibraryPath,true);
  1729. { add unit environment and exepath to the unit search path }
  1730. if inputdir<>'' then
  1731. Unitsearchpath.AddPath(inputdir,true);
  1732. if not disable_configfile then
  1733. begin
  1734. {$ifdef Delphi}
  1735. UnitSearchPath.AddPath(dmisc.getenv(target_info.unit_env),false);
  1736. {$else}
  1737. UnitSearchPath.AddPath(dos.getenv(target_info.unit_env),false);
  1738. {$endif Delphi}
  1739. end;
  1740. {$ifdef Unix}
  1741. fpcdir:=FixPath(getenv('FPCDIR'),false);
  1742. if fpcdir='' then
  1743. begin
  1744. if PathExists('/usr/local/lib/fpc/'+version_string) then
  1745. fpcdir:='/usr/local/lib/fpc/'+version_string+'/'
  1746. else
  1747. fpcdir:='/usr/lib/fpc/'+version_string+'/';
  1748. end;
  1749. {$else}
  1750. fpcdir:=FixPath(getenv('FPCDIR'),false);
  1751. if fpcdir='' then
  1752. begin
  1753. fpcdir:=ExePath+'../';
  1754. if not(PathExists(fpcdir+'/units')) and
  1755. not(PathExists(fpcdir+'/rtl')) then
  1756. fpcdir:=fpcdir+'../';
  1757. end;
  1758. {$endif}
  1759. { first try development RTL, else use the default installation path }
  1760. if not disable_configfile then
  1761. begin
  1762. if PathExists(FpcDir+'rtl/'+lower(target_info.shortname)) then
  1763. UnitSearchPath.AddPath(FpcDir+'rtl/'+lower(target_info.shortname),false)
  1764. else
  1765. begin
  1766. UnitSearchPath.AddPath(FpcDir+'units/'+lower(target_info.shortname),false);
  1767. UnitSearchPath.AddPath(FpcDir+'units/'+lower(target_info.shortname)+'/rtl',false);
  1768. end;
  1769. end;
  1770. { Add exepath if the exe is not in the current dir, because that is always searched already }
  1771. if ExePath<>GetCurrentDir then
  1772. UnitSearchPath.AddPath(ExePath,false);
  1773. { Add unit dir to the object and library path }
  1774. objectsearchpath.AddList(unitsearchpath,false);
  1775. librarysearchpath.AddList(unitsearchpath,false);
  1776. { switch assembler if it's binary and we got -a on the cmdline }
  1777. if (cs_asm_leave in initglobalswitches) and
  1778. (target_asm.outputbinary) then
  1779. begin
  1780. Message(option_switch_bin_to_src_assembler);
  1781. set_target_asm(target_info.assemextern);
  1782. end;
  1783. if (target_asm.supported_target <> system_any) and
  1784. (target_asm.supported_target <> target_info.system) then
  1785. begin
  1786. Message2(option_incompatible_asm,target_asm.idtxt,target_info.name);
  1787. set_target_asm(target_info.assemextern);
  1788. Message1(option_asm_forced,target_asm.idtxt);
  1789. end;
  1790. { turn off stripping if compiling with debuginfo or profile }
  1791. if (cs_debuginfo in initmoduleswitches) or
  1792. (cs_profile in initmoduleswitches) then
  1793. exclude(initglobalswitches,cs_link_strip);
  1794. if not LinkTypeSetExplicitly then
  1795. set_default_link_type;
  1796. { Default alignment settings,
  1797. 1. load the defaults for the target
  1798. 2. override with generic optimizer setting (little size)
  1799. 3. override with the user specified -Oa }
  1800. UpdateAlignment(initalignment,target_info.alignment);
  1801. if (cs_littlesize in aktglobalswitches) then
  1802. begin
  1803. initalignment.procalign:=1;
  1804. initalignment.jumpalign:=1;
  1805. initalignment.loopalign:=1;
  1806. end;
  1807. UpdateAlignment(initalignment,option.paraalignment);
  1808. option.free;
  1809. Option:=nil;
  1810. end;
  1811. initialization
  1812. coption:=toption;
  1813. finalization
  1814. if assigned(option) then
  1815. option.free;
  1816. end.
  1817. {
  1818. $Log$
  1819. Revision 1.101 2003-09-03 15:55:01 peter
  1820. * NEWRA branch merged
  1821. Revision 1.100 2003/09/03 11:18:37 florian
  1822. * fixed arm concatcopy
  1823. + arm support in the common compiler sources added
  1824. * moved some generic cg code around
  1825. + tfputype added
  1826. * ...
  1827. Revision 1.99.2.4 2003/09/02 17:48:42 peter
  1828. * sparc need software int64 to double
  1829. Revision 1.99.2.3 2003/09/01 21:02:55 peter
  1830. * sparc updates for new tregister
  1831. Revision 1.99.2.2 2003/08/31 16:18:05 peter
  1832. * more fixes
  1833. Revision 1.99.2.1 2003/08/31 13:50:15 daniel
  1834. * Remove sorting and use pregenerated indexes
  1835. * Some work on making things compile
  1836. Revision 1.99 2003/05/13 19:14:41 peter
  1837. * failn removed
  1838. * inherited result code check moven to pexpr
  1839. Revision 1.98 2003/05/11 19:17:16 florian
  1840. * FPC_LITTLE_ENDIAN and FPC_BIG_ENDIAN is now defined as well
  1841. Revision 1.97 2003/05/01 07:59:42 florian
  1842. * introduced defaultordconsttype to decribe the default size of ordinal constants
  1843. on 64 bit CPUs it's equal to cs64bitdef while on 32 bit CPUs it's equal to s32bitdef
  1844. + added defines CPU32 and CPU64 for 32 bit and 64 bit CPUs
  1845. * int64s/qwords are allowed as for loop counter on 64 bit CPUs
  1846. Revision 1.96 2003/04/30 16:35:00 florian
  1847. * fixed defines for x86-64
  1848. Revision 1.95 2003/04/24 11:21:45 florian
  1849. + HAS_TYPE_* defines for floats on i386 and powerpc added
  1850. Revision 1.94 2003/03/28 19:16:56 peter
  1851. * generic constructor working for i386
  1852. * remove fixed self register
  1853. * esi added as address register for i386
  1854. Revision 1.93 2003/03/23 23:20:38 hajny
  1855. + emx target added
  1856. Revision 1.92 2003/03/08 08:59:07 daniel
  1857. + $define newra will enable new register allocator
  1858. + getregisterint will return imaginary registers with $newra
  1859. + -sr switch added, will skip register allocation so you can see
  1860. the direct output of the code generator before register allocation
  1861. Revision 1.91 2002/12/06 16:56:58 peter
  1862. * only compile cs_fp_emulation support when cpufpuemu is defined
  1863. * define cpufpuemu for m68k only
  1864. Revision 1.90 2002/11/30 23:14:55 carl
  1865. - removed cs_fp_emulation checking for m68k, its now controled
  1866. by a global switch
  1867. + added powerpc/sparc/vis message options support
  1868. Revision 1.89 2002/11/30 21:29:56 carl
  1869. + -Ce for softfpu
  1870. Revision 1.88 2002/11/15 01:58:52 peter
  1871. * merged changes from 1.0.7 up to 04-11
  1872. - -V option for generating bug report tracing
  1873. - more tracing for option parsing
  1874. - errors for cdecl and high()
  1875. - win32 import stabs
  1876. - win32 records<=8 are returned in eax:edx (turned off by default)
  1877. - heaptrc update
  1878. - more info for temp management in .s file with EXTDEBUG
  1879. Revision 1.87 2002/10/23 17:07:40 peter
  1880. * fix -n that was broken in the previous commit
  1881. Revision 1.86 2002/10/23 16:57:16 peter
  1882. * first search for fpc.cfg instead of deprecated ppc386.cfg
  1883. * parse commandline options first before searching configfile so -vt
  1884. can be used to display the searched files
  1885. Revision 1.85 2002/10/13 21:33:01 peter
  1886. * define HASTHREADVAR
  1887. Revision 1.84 2002/10/02 18:20:52 peter
  1888. * Copy() is now internal syssym that calls compilerprocs
  1889. Revision 1.83 2002/09/22 14:02:35 carl
  1890. * stack checking cannot be called before system unit is initialized
  1891. * MC68020 define
  1892. Revision 1.82 2002/08/12 15:08:40 carl
  1893. + stab register indexes for powerpc (moved from gdb to cpubase)
  1894. + tprocessor enumeration moved to cpuinfo
  1895. + linker in target_info is now a class
  1896. * many many updates for m68k (will soon start to compile)
  1897. - removed some ifdef or correct them for correct cpu
  1898. Revision 1.81 2002/08/10 14:46:29 carl
  1899. + moved target_cpu_string to cpuinfo
  1900. * renamed asmmode enum.
  1901. * assembler reader has now less ifdef's
  1902. * move from nppcmem.pas -> ncgmem.pas vec. node.
  1903. Revision 1.80 2002/08/09 19:15:41 carl
  1904. - removed newcg define
  1905. Revision 1.79 2002/07/26 22:22:10 florian
  1906. * several PowerPC related fixes to get forward with system unit compilation
  1907. Revision 1.78 2002/07/26 21:15:39 florian
  1908. * rewrote the system handling
  1909. Revision 1.77 2002/07/20 17:16:03 florian
  1910. + source code page support
  1911. Revision 1.76 2002/07/04 20:43:01 florian
  1912. * first x86-64 patches
  1913. Revision 1.75 2002/07/01 18:46:24 peter
  1914. * internal linker
  1915. * reorganized aasm layer
  1916. Revision 1.74 2002/07/01 16:23:53 peter
  1917. * cg64 patch
  1918. * basics for currency
  1919. * asnode updates for class and interface (not finished)
  1920. Revision 1.73 2002/05/18 13:34:11 peter
  1921. * readded missing revisions
  1922. Revision 1.72 2002/05/16 19:46:41 carl
  1923. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  1924. + try to fix temp allocation (still in ifdef)
  1925. + generic constructor calls
  1926. + start of tassembler / tmodulebase class cleanup
  1927. Revision 1.70 2002/05/12 16:53:08 peter
  1928. * moved entry and exitcode to ncgutil and cgobj
  1929. * foreach gets extra argument for passing local data to the
  1930. iterator function
  1931. * -CR checks also class typecasts at runtime by changing them
  1932. into as
  1933. * fixed compiler to cycle with the -CR option
  1934. * fixed stabs with elf writer, finally the global variables can
  1935. be watched
  1936. * removed a lot of routines from cga unit and replaced them by
  1937. calls to cgobj
  1938. * u32bit-s32bit updates for and,or,xor nodes. When one element is
  1939. u32bit then the other is typecasted also to u32bit without giving
  1940. a rangecheck warning/error.
  1941. * fixed pascal calling method with reversing also the high tree in
  1942. the parast, detected by tcalcst3 test
  1943. Revision 1.69 2002/04/21 19:02:04 peter
  1944. * removed newn and disposen nodes, the code is now directly
  1945. inlined from pexpr
  1946. * -an option that will write the secondpass nodes to the .s file, this
  1947. requires EXTDEBUG define to actually write the info
  1948. * fixed various internal errors and crashes due recent code changes
  1949. Revision 1.68 2002/04/20 21:32:24 carl
  1950. + generic FPC_CHECKPOINTER
  1951. + first parameter offset in stack now portable
  1952. * rename some constants
  1953. + move some cpu stuff to other units
  1954. - remove unused constents
  1955. * fix stacksize for some targets
  1956. * fix generic size problems which depend now on EXTEND_SIZE constant
  1957. Revision 1.67 2002/04/07 10:22:35 carl
  1958. + CPU defines now depends on current target
  1959. Revision 1.66 2002/04/04 19:05:58 peter
  1960. * removed unused units
  1961. * use tlocation.size in cg.a_*loc*() routines
  1962. Revision 1.65 2002/04/04 18:39:45 carl
  1963. + added wdosx support (patch from Pavel)
  1964. }