globals.pas 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713
  1. {
  2. $Id$
  3. Copyright (C) 1998-2000 by Florian Klaempfl
  4. This unit implements some support functions and global variables
  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. {$ifdef tp}
  19. {$E+,N+}
  20. {$endif}
  21. unit globals;
  22. interface
  23. uses
  24. {$ifdef win32}
  25. windows,
  26. {$endif}
  27. {$ifdef linux}
  28. linux,
  29. {$endif}
  30. {$ifdef Delphi}
  31. sysutils,
  32. dmisc,
  33. {$else}
  34. strings,dos,
  35. {$endif}
  36. {$ifdef TP}
  37. objects,
  38. {$endif}
  39. globtype,version,tokens,systems,cobjects;
  40. const
  41. {$ifdef linux}
  42. DirSep = '/';
  43. {$else}
  44. {$ifdef amiga}
  45. DirSep = '/';
  46. {$else}
  47. DirSep = '\';
  48. {$endif}
  49. {$endif}
  50. {$ifdef Splitheap}
  51. testsplit : boolean = false;
  52. {$endif Splitheap}
  53. delphimodeswitches : tmodeswitches=
  54. [m_delphi,m_tp,m_all,m_class,m_objpas,m_result,m_string_pchar,
  55. m_pointer_2_procedure,m_autoderef,m_tp_procvar,m_initfinal,m_default_ansistring];
  56. fpcmodeswitches : tmodeswitches=
  57. [m_fpc,m_all,m_string_pchar,m_nested_comment,m_repeat_forward,
  58. m_cvar_support,m_initfinal,m_add_pointer];
  59. objfpcmodeswitches : tmodeswitches=
  60. [m_objfpc,m_fpc,m_all,m_class,m_objpas,m_result,m_string_pchar,m_nested_comment,
  61. m_repeat_forward,m_cvar_support,m_initfinal,m_add_pointer];
  62. tpmodeswitches : tmodeswitches=
  63. [m_tp7,m_tp,m_all,m_tp_procvar];
  64. gpcmodeswitches : tmodeswitches=
  65. [m_gpc,m_all];
  66. type
  67. TSearchPathList = object(TStringQueue)
  68. procedure AddPath(s:string;addfirst:boolean);
  69. procedure AddList(list:TSearchPathList;addfirst:boolean);
  70. function FindFile(const f : string;var b : boolean) : string;
  71. end;
  72. var
  73. { specified inputfile }
  74. inputdir : dirstr;
  75. inputfile : namestr;
  76. inputextension : extstr;
  77. { specified outputfile with -o parameter }
  78. outputfile : namestr;
  79. { specified with -FE or -FU }
  80. outputexedir : dirstr;
  81. outputunitdir : dirstr;
  82. { things specified with parameters }
  83. paralinkoptions,
  84. paradynamiclinker : string;
  85. parapreprocess : boolean;
  86. { directory where the utils can be found (options -FD) }
  87. utilsdirectory : dirstr;
  88. { some flags for global compiler switches }
  89. do_build,
  90. do_make : boolean;
  91. not_unit_proc : boolean;
  92. { path for searching units, different paths can be seperated by ; }
  93. exepath : dirstr; { Path to ppc }
  94. librarysearchpath,
  95. unitsearchpath,
  96. objectsearchpath,
  97. includesearchpath : TSearchPathList;
  98. { deffile }
  99. usewindowapi : boolean;
  100. description : string;
  101. dllversion : string;
  102. dllmajor,dllminor : word;
  103. { current position }
  104. token, { current token being parsed }
  105. idtoken : ttoken; { holds the token if the pattern is a known word }
  106. tokenpos, { last postion of the read token }
  107. aktfilepos : tfileposinfo; { current position }
  108. { type of currently parsed block }
  109. { isn't full implemented (FK) }
  110. block_type : tblock_type;
  111. in_args : boolean; { arguments must be checked especially }
  112. parsing_para_level : longint; { parameter level, used to convert
  113. proc calls to proc loads in firstcalln }
  114. { Must_be_valid : boolean; should the variable already have a value
  115. obsolete replace by set_varstate function }
  116. compile_level : word;
  117. make_ref : boolean;
  118. resolving_forward : boolean; { used to add forward reference as second ref }
  119. use_esp_stackframe : boolean; { to test for call with ESP as stack frame }
  120. inlining_procedure : boolean; { are we inlining a procedure }
  121. {$ifdef TP}
  122. use_big : boolean;
  123. {$endif}
  124. { commandline values }
  125. initdefines : tlinkedlist;
  126. initglobalswitches : tglobalswitches;
  127. initmoduleswitches : tmoduleswitches;
  128. initlocalswitches : tlocalswitches;
  129. initmodeswitches : tmodeswitches;
  130. {$IFDEF testvarsets}
  131. Initsetalloc, {0=fixed, 1 =var}
  132. {$ENDIF}
  133. initpackenum : longint;
  134. initpackrecords : tpackrecords;
  135. initoutputformat : tasm;
  136. initoptprocessor,
  137. initspecificoptprocessor : tprocessors;
  138. initasmmode : tasmmode;
  139. { current state values }
  140. aktglobalswitches : tglobalswitches;
  141. aktmoduleswitches : tmoduleswitches;
  142. aktlocalswitches : tlocalswitches;
  143. nextaktlocalswitches : tlocalswitches;
  144. localswitcheschanged : boolean;
  145. aktmodeswitches : tmodeswitches;
  146. {$IFDEF testvarsets}
  147. aktsetalloc,
  148. {$ENDIF}
  149. aktpackenum : longint;
  150. aktmaxfpuregisters: longint;
  151. aktpackrecords : tpackrecords;
  152. aktoutputformat : tasm;
  153. aktoptprocessor,
  154. aktspecificoptprocessor : tprocessors;
  155. aktasmmode : tasmmode;
  156. { Memory sizes }
  157. heapsize,
  158. maxheapsize,
  159. stacksize : longint;
  160. {$Ifdef EXTDEBUG}
  161. total_of_firstpass,
  162. firstpass_several : longint;
  163. {$ifdef FPC}
  164. EntryMemUsed : longint;
  165. {$endif FPC}
  166. { parameter switches }
  167. debugstop,
  168. only_one_pass : boolean;
  169. {$EndIf EXTDEBUG}
  170. { windows application type }
  171. apptype : tapptype;
  172. const
  173. RelocSection : boolean = true;
  174. RelocSectionSetExplicitly : boolean = false;
  175. DLLsource : boolean = false;
  176. DLLImageBase : pstring = nil;
  177. UseDeffileForExport : boolean = true;
  178. ForceDeffileForExport : boolean = false;
  179. { used to set all registers used for each global function
  180. this should dramatically decrease the number of
  181. recompilations needed PM }
  182. simplify_ppu : boolean = false;
  183. { should we allow non static members ? }
  184. allow_only_static : boolean = false;
  185. Inside_asm_statement : boolean = false;
  186. { for error info in pp.pas }
  187. const
  188. parser_current_file : string = '';
  189. {$ifdef debug}
  190. { if the pointer don't point to the heap then write an error }
  191. function assigned(p : pointer) : boolean;
  192. {$endif}
  193. function min(a,b : longint) : longint;
  194. function max(a,b : longint) : longint;
  195. function align(i,a:longint):longint;
  196. function align_from_size(datasize:longint;length:longint):longint;
  197. procedure Replace(var s:string;s1:string;const s2:string);
  198. procedure ReplaceCase(var s:string;const s1,s2:string);
  199. function upper(const s : string) : string;
  200. function lower(const s : string) : string;
  201. function trimspace(const s:string):string;
  202. {$ifdef FPC}
  203. function tostru(i:cardinal) : string;
  204. {$else}
  205. function tostru(i:longint) : string;
  206. {$endif}
  207. procedure uppervar(var s : string);
  208. function tostr(i : longint) : string;
  209. function tostr_with_plus(i : longint) : string;
  210. procedure valint(S : string;var V : longint;var code : integer);
  211. function is_number(const s : string) : boolean;
  212. function ispowerof2(value : longint;var power : longint) : boolean;
  213. { enable ansistring comparison }
  214. function compareansistrings(p1,p2 : pchar;length1,length2 : longint) : longint;
  215. function concatansistrings(p1,p2 : pchar;length1,length2 : longint) : pchar;
  216. function bstoslash(const s : string) : string;
  217. procedure abstract;
  218. function getdatestr:string;
  219. function gettimestr:string;
  220. function filetimestring( t : longint) : string;
  221. procedure DefaultReplacements(var s:string);
  222. function GetCurrentDir:string;
  223. function path_absolute(const s : string) : boolean;
  224. Function PathExists ( F : String) : Boolean;
  225. Function FileExists ( Const F : String) : Boolean;
  226. Function RemoveFile(const f:string):boolean;
  227. Function RemoveDir(d:string):boolean;
  228. Function GetFileTime ( Var F : File) : Longint;
  229. Function GetNamedFileTime ( Const F : String) : Longint;
  230. Function SplitPath(const s:string):string;
  231. Function SplitFileName(const s:string):string;
  232. Function SplitName(const s:string):string;
  233. Function SplitExtension(Const HStr:String):String;
  234. Function AddExtension(Const HStr,ext:String):String;
  235. Function ForceExtension(Const HStr,ext:String):String;
  236. Function FixPath(s:string;allowdot:boolean):string;
  237. function FixFileName(const s:string):string;
  238. procedure SplitBinCmd(const s:string;var bstr,cstr:string);
  239. procedure SynchronizeFileTime(const fn1,fn2:string);
  240. function FindFile(const f : string;path : string;var b : boolean) : string;
  241. function FindExe(bin:string;var found:boolean):string;
  242. function GetShortName(const n:string):string;
  243. Procedure Shell(const command:string);
  244. function GetEnvPChar(const envname:string):pchar;
  245. procedure FreeEnvPChar(p:pchar);
  246. procedure InitGlobals;
  247. procedure DoneGlobals;
  248. implementation
  249. uses
  250. comphook;
  251. procedure abstract;
  252. begin
  253. do_internalerror(255);
  254. end;
  255. function ngraphsearchvalue(const s1,s2 : string) : double;
  256. const
  257. n = 3;
  258. var
  259. equals,i,j : longint;
  260. hs : string;
  261. begin
  262. equals:=0;
  263. { is the string long enough ? }
  264. if min(length(s1),length(s2))-n+1<1 then
  265. begin
  266. ngraphsearchvalue:=0.0;
  267. exit;
  268. end;
  269. for i:=1 to length(s1)-n+1 do
  270. begin
  271. hs:=copy(s1,i,n);
  272. for j:=1 to length(s2)-n+1 do
  273. if hs=copy(s2,j,n) then
  274. inc(equals);
  275. end;
  276. {$ifdef fpc}
  277. ngraphsearchvalue:=equals/double(max(length(s1),length(s2))-n+1);
  278. {$else}
  279. ngraphsearchvalue:=equals/(max(length(s1),length(s2))-n+1);
  280. {$endif}
  281. end;
  282. function bstoslash(const s : string) : string;
  283. {
  284. return string s with all \ changed into /
  285. }
  286. var
  287. i : longint;
  288. begin
  289. for i:=1to length(s) do
  290. if s[i]='\' then
  291. bstoslash[i]:='/'
  292. else
  293. bstoslash[i]:=s[i];
  294. {$ifndef TP}
  295. {$ifopt H+}
  296. setlength(bstoslash,length(s));
  297. {$else}
  298. bstoslash[0]:=s[0];
  299. {$endif}
  300. {$else}
  301. bstoslash[0]:=s[0];
  302. {$endif}
  303. end;
  304. {$ifdef debug}
  305. function assigned(p : pointer) : boolean;
  306. {$ifndef FPC}
  307. {$ifndef DPMI}
  308. type
  309. ptrrec = record
  310. ofs,seg : word;
  311. end;
  312. var
  313. lp : longint;
  314. {$endif DPMI}
  315. {$endif FPC}
  316. begin
  317. {$ifdef FPC}
  318. { Assigned is used for procvar and
  319. stack stored temp records !! PM }
  320. (* if (p<>nil) {and
  321. ((p<heaporg) or
  322. (p>heapptr))} then
  323. do_internalerror(230); *)
  324. {$else}
  325. {$ifdef DPMI}
  326. assigned:=(p<>nil);
  327. exit;
  328. {$else DPMI}
  329. if p=nil then
  330. lp:=0
  331. else
  332. lp:=longint(ptrrec(p).seg)*16+longint(ptrrec(p).ofs);
  333. if (lp<>0) and
  334. ((lp<longint(seg(heaporg^))*16+longint(ofs(heaporg^))) or
  335. (lp>longint(seg(heapptr^))*16+longint(ofs(heapptr^)))) then
  336. do_internalerror(230);
  337. {$endif DPMI}
  338. {$endif FPC}
  339. assigned:=(p<>nil);
  340. end;
  341. {$endif}
  342. function min(a,b : longint) : longint;
  343. {
  344. return the minimal of a and b
  345. }
  346. begin
  347. if a>b then
  348. min:=b
  349. else
  350. min:=a;
  351. end;
  352. function max(a,b : longint) : longint;
  353. {
  354. return the maximum of a and b
  355. }
  356. begin
  357. if a<b then
  358. max:=b
  359. else
  360. max:=a;
  361. end;
  362. function align_from_size(datasize:longint;length:longint):longint;
  363. {Increases the datasize with the required alignment; i.e. on pentium
  364. words should be aligned word; and dwords should be aligned dword.
  365. So for a word (len=2), datasize is increased to the nearest multiple
  366. of 2, and for len=4, datasize is increased to the nearest multiple of
  367. 4.}
  368. var data_align:word;
  369. begin
  370. {$IFDEF I386}
  371. if length>2 then
  372. data_align:=4
  373. else if length>1 then
  374. data_align:=2
  375. else
  376. data_align:=1;
  377. {$ENDIF}
  378. {$IFDEF M68K}
  379. data_align:=2;
  380. {$ENDIF}
  381. align_from_size:=(datasize+data_align-1) and not(data_align-1);
  382. end;
  383. function align(i,a:longint):longint;
  384. {
  385. return value <i> aligned <a> boundary
  386. }
  387. begin
  388. align:=(i+a-1) and not(a-1);
  389. end;
  390. procedure Replace(var s:string;s1:string;const s2:string);
  391. var
  392. last,
  393. i : longint;
  394. begin
  395. s1:=upper(s1);
  396. last:=0;
  397. repeat
  398. i:=pos(s1,upper(s));
  399. if i=last then
  400. i:=0;
  401. if (i>0) then
  402. begin
  403. Delete(s,i,length(s1));
  404. Insert(s2,s,i);
  405. last:=i;
  406. end;
  407. until (i=0);
  408. end;
  409. procedure ReplaceCase(var s:string;const s1,s2:string);
  410. var
  411. last,
  412. i : longint;
  413. begin
  414. last:=0;
  415. repeat
  416. i:=pos(s1,s);
  417. if i=last then
  418. i:=0;
  419. if (i>0) then
  420. begin
  421. Delete(s,i,length(s1));
  422. Insert(s2,s,i);
  423. last:=i;
  424. end;
  425. until (i=0);
  426. end;
  427. function upper(const s : string) : string;
  428. {
  429. return uppercased string of s
  430. }
  431. var
  432. i : longint;
  433. begin
  434. for i:=1 to length(s) do
  435. if s[i] in ['a'..'z'] then
  436. upper[i]:=char(byte(s[i])-32)
  437. else
  438. upper[i]:=s[i];
  439. upper[0]:=s[0];
  440. end;
  441. function lower(const s : string) : string;
  442. {
  443. return lowercased string of s
  444. }
  445. var
  446. i : longint;
  447. begin
  448. for i:=1 to length(s) do
  449. if s[i] in ['A'..'Z'] then
  450. lower[i]:=char(byte(s[i])+32)
  451. else
  452. lower[i]:=s[i];
  453. lower[0]:=s[0];
  454. end;
  455. procedure uppervar(var s : string);
  456. {
  457. uppercase string s
  458. }
  459. var
  460. i : longint;
  461. begin
  462. for i:=1 to length(s) do
  463. if s[i] in ['a'..'z'] then
  464. s[i]:=char(byte(s[i])-32);
  465. end;
  466. {$ifdef FPC}
  467. function tostru(i:cardinal):string;
  468. {
  469. return string of value i, but for cardinals
  470. }
  471. var
  472. hs : string;
  473. begin
  474. str(i,hs);
  475. tostru:=hs;
  476. end;
  477. {$else FPC}
  478. function tostru(i:longint):string;
  479. begin
  480. tostru:=tostr(i);
  481. end;
  482. {$endif FPC}
  483. function trimspace(const s:string):string;
  484. {
  485. return s with all leading and ending spaces and tabs removed
  486. }
  487. var
  488. i,j : longint;
  489. begin
  490. i:=length(s);
  491. while (i>0) and (s[i] in [#9,' ']) do
  492. dec(i);
  493. j:=1;
  494. while (j<i) and (s[j] in [#9,' ']) do
  495. inc(j);
  496. trimspace:=Copy(s,j,i-j+1);
  497. end;
  498. function tostr(i : longint) : string;
  499. {
  500. return string of value i
  501. }
  502. var
  503. hs : string;
  504. begin
  505. str(i,hs);
  506. tostr:=hs;
  507. end;
  508. function tostr_with_plus(i : longint) : string;
  509. {
  510. return string of value i, but always include a + when i>=0
  511. }
  512. var
  513. hs : string;
  514. begin
  515. str(i,hs);
  516. if i>=0 then
  517. tostr_with_plus:='+'+hs
  518. else
  519. tostr_with_plus:=hs;
  520. end;
  521. procedure valint(S : string;var V : longint;var code : integer);
  522. {
  523. val() with support for octal, which is not supported under tp7
  524. }
  525. {$ifndef FPC}
  526. var
  527. vs : longint;
  528. c : byte;
  529. begin
  530. if s[1]='%' then
  531. begin
  532. vs:=0;
  533. longint(v):=0;
  534. for c:=2 to length(s) do
  535. begin
  536. if s[c]='0' then
  537. vs:=vs shl 1
  538. else
  539. if s[c]='1' then
  540. vs:=vs shl 1+1
  541. else
  542. begin
  543. code:=c;
  544. exit;
  545. end;
  546. end;
  547. code:=0;
  548. longint(v):=vs;
  549. end
  550. else
  551. system.val(S,V,code);
  552. end;
  553. {$else not FPC}
  554. begin
  555. system.val(S,V,code);
  556. end;
  557. {$endif not FPC}
  558. function is_number(const s : string) : boolean;
  559. {
  560. is string a correct number ?
  561. }
  562. var
  563. w : integer;
  564. l : longint;
  565. begin
  566. valint(s,l,w);
  567. is_number:=(w=0);
  568. end;
  569. function ispowerof2(value : longint;var power : longint) : boolean;
  570. {
  571. return if value is a power of 2. And if correct return the power
  572. }
  573. var
  574. hl : longint;
  575. i : longint;
  576. begin
  577. hl:=1;
  578. ispowerof2:=true;
  579. for i:=0 to 31 do
  580. begin
  581. if hl=value then
  582. begin
  583. power:=i;
  584. exit;
  585. end;
  586. hl:=hl shl 1;
  587. end;
  588. ispowerof2:=false;
  589. end;
  590. { enable ansistring comparison }
  591. { 0 means equal }
  592. { 1 means p1 > p2 }
  593. { -1 means p1 < p2 }
  594. function compareansistrings(p1,p2 : pchar;length1,length2 : longint) : longint;
  595. var
  596. i,j : longint;
  597. begin
  598. compareansistrings:=0;
  599. j:=min(length1,length2);
  600. i:=0;
  601. while (i<j) do
  602. begin
  603. if p1[i]>p2[i] then
  604. begin
  605. compareansistrings:=1;
  606. exit;
  607. end
  608. else
  609. if p1[i]<p2[i] then
  610. begin
  611. compareansistrings:=-1;
  612. exit;
  613. end;
  614. inc(i);
  615. end;
  616. if length1>length2 then
  617. compareansistrings:=1
  618. else
  619. if length1<length2 then
  620. compareansistrings:=-1;
  621. end;
  622. function concatansistrings(p1,p2 : pchar;length1,length2 : longint) : pchar;
  623. var
  624. p : pchar;
  625. begin
  626. getmem(p,length1+length2+1);
  627. move(p1[0],p[0],length1);
  628. move(p2[0],p[length1],length2+1);
  629. concatansistrings:=p;
  630. end;
  631. {****************************************************************************
  632. Time Handling
  633. ****************************************************************************}
  634. Function L0(l:longint):string;
  635. {
  636. return the string of value l, if l<10 then insert a zero, so
  637. the string is always at least 2 chars '01','02',etc
  638. }
  639. var
  640. s : string;
  641. begin
  642. Str(l,s);
  643. if l<10 then
  644. s:='0'+s;
  645. L0:=s;
  646. end;
  647. function gettimestr:string;
  648. {
  649. get the current time in a string HH:MM:SS
  650. }
  651. var
  652. hour,min,sec,hsec : word;
  653. begin
  654. {$ifdef delphi}
  655. dmisc.gettime(hour,min,sec,hsec);
  656. {$else delphi}
  657. dos.gettime(hour,min,sec,hsec);
  658. {$endif delphi}
  659. gettimestr:=L0(Hour)+':'+L0(min)+':'+L0(sec);
  660. end;
  661. function getdatestr:string;
  662. {
  663. get the current date in a string YY/MM/DD
  664. }
  665. var
  666. Year,Month,Day,Wday : Word;
  667. begin
  668. {$ifdef delphi}
  669. dmisc.getdate(year,month,day,wday);
  670. {$else}
  671. dos.getdate(year,month,day,wday);
  672. {$endif}
  673. getdatestr:=L0(Year)+'/'+L0(Month)+'/'+L0(Day);
  674. end;
  675. function filetimestring( t : longint) : string;
  676. {
  677. convert dos datetime t to a string YY/MM/DD HH:MM:SS
  678. }
  679. var
  680. {$ifndef linux}
  681. DT : DateTime;
  682. {$endif}
  683. Year,Month,Day,Hour,Min,Sec : Word;
  684. begin
  685. if t=-1 then
  686. begin
  687. FileTimeString:='Not Found';
  688. exit;
  689. end;
  690. {$ifndef linux}
  691. unpacktime(t,DT);
  692. Year:=dT.year;month:=dt.month;day:=dt.day;
  693. Hour:=dt.hour;min:=dt.min;sec:=dt.sec;
  694. {$else}
  695. EpochToLocal (t,year,month,day,hour,min,sec);
  696. {$endif}
  697. filetimestring:=L0(Year)+'/'+L0(Month)+'/'+L0(Day)+' '+L0(Hour)+':'+L0(min)+':'+L0(sec);
  698. end;
  699. {****************************************************************************
  700. Default Macro Handling
  701. ****************************************************************************}
  702. procedure DefaultReplacements(var s:string);
  703. begin
  704. { Replace some macro's }
  705. Replace(s,'$FPCVER',version_string);
  706. Replace(s,'$VERSION',version_string);
  707. Replace(s,'$FULLVERSION',full_version_string);
  708. Replace(s,'$FPCDATE',date_string);
  709. Replace(s,'$FPCTARGET',target_cpu_string);
  710. Replace(s,'$FPCCPU',target_cpu_string);
  711. Replace(s,'$TARGET',target_path);
  712. Replace(s,'$FPCOS',target_path);
  713. end;
  714. {****************************************************************************
  715. File Handling
  716. ****************************************************************************}
  717. function GetCurrentDir:string;
  718. var
  719. CurrentDir : string;
  720. begin
  721. GetDir(0,CurrentDir);
  722. GetCurrentDir:=FixPath(CurrentDir,false);
  723. end;
  724. function path_absolute(const s : string) : boolean;
  725. {
  726. is path s an absolute path?
  727. }
  728. begin
  729. path_absolute:=false;
  730. {$ifdef linux}
  731. if (length(s)>0) and (s[1]='/') then
  732. path_absolute:=true;
  733. {$else linux}
  734. {$ifdef amiga}
  735. if ((length(s)>0) and ((s[1]='\') or (s[1]='/'))) or (Pos(':',s) = length(s)) then
  736. path_absolute:=true;
  737. {$else}
  738. if ((length(s)>0) and ((s[1]='\') or (s[1]='/'))) or
  739. ((length(s)>2) and (s[2]=':') and ((s[3]='\') or (s[3]='/'))) then
  740. path_absolute:=true;
  741. {$endif amiga}
  742. {$endif linux}
  743. end;
  744. {$ifndef FPC}
  745. Procedure FindClose(var Info : SearchRec);
  746. Begin
  747. End;
  748. {$endif not FPC}
  749. Function FileExists ( Const F : String) : Boolean;
  750. {$ifndef delphi}
  751. Var
  752. Info : SearchRec;
  753. {$endif}
  754. begin
  755. {$ifdef delphi}
  756. FileExists:=sysutils.FileExists(f);
  757. {$else}
  758. findfirst(F,readonly+archive+hidden,info);
  759. FileExists:=(doserror=0);
  760. findclose(Info);
  761. {$endif delphi}
  762. end;
  763. Function PathExists ( F : String) : Boolean;
  764. Var
  765. Info : SearchRec;
  766. begin
  767. if F[Length(f)] in ['/','\'] then
  768. Delete(f,length(f),1);
  769. findfirst(F,readonly+archive+hidden+directory,info);
  770. PathExists:=(doserror=0) and ((info.attr and directory)=directory);
  771. findclose(Info);
  772. end;
  773. Function RemoveFile(const f:string):boolean;
  774. var
  775. g : file;
  776. begin
  777. assign(g,f);
  778. {$I-}
  779. erase(g);
  780. {$I+}
  781. RemoveFile:=(ioresult=0);
  782. end;
  783. Function RemoveDir(d:string):boolean;
  784. begin
  785. if d[length(d)]=DirSep then
  786. Delete(d,length(d),1);
  787. {$I-}
  788. rmdir(d);
  789. {$I+}
  790. RemoveDir:=(ioresult=0);
  791. end;
  792. Function SplitPath(const s:string):string;
  793. var
  794. i : longint;
  795. begin
  796. i:=Length(s);
  797. while (i>0) and not(s[i] in ['/','\']) do
  798. dec(i);
  799. SplitPath:=Copy(s,1,i);
  800. end;
  801. Function SplitFileName(const s:string):string;
  802. var
  803. p : dirstr;
  804. n : namestr;
  805. e : extstr;
  806. begin
  807. FSplit(s,p,n,e);
  808. SplitFileName:=n+e;
  809. end;
  810. Function SplitName(const s:string):string;
  811. var
  812. i,j : longint;
  813. begin
  814. i:=Length(s);
  815. j:=Length(s);
  816. while (i>0) and not(s[i] in ['/','\']) do
  817. dec(i);
  818. while (j>0) and (s[j]<>'.') do
  819. dec(j);
  820. if j<=i then
  821. j:=255;
  822. SplitName:=Copy(s,i+1,j-(i+1));
  823. end;
  824. Function SplitExtension(Const HStr:String):String;
  825. var
  826. j : longint;
  827. begin
  828. j:=length(Hstr);
  829. while (j>0) and (Hstr[j]<>'.') do
  830. begin
  831. if hstr[j]=DirSep then
  832. j:=0
  833. else
  834. dec(j);
  835. end;
  836. if j=0 then
  837. j:=254;
  838. SplitExtension:=Copy(Hstr,j,255);
  839. end;
  840. Function AddExtension(Const HStr,ext:String):String;
  841. begin
  842. if (Ext<>'') and (SplitExtension(HStr)='') then
  843. AddExtension:=Hstr+Ext
  844. else
  845. AddExtension:=Hstr;
  846. end;
  847. Function ForceExtension(Const HStr,ext:String):String;
  848. var
  849. j : longint;
  850. begin
  851. j:=length(Hstr);
  852. while (j>0) and (Hstr[j]<>'.') do
  853. dec(j);
  854. if j=0 then
  855. j:=255;
  856. ForceExtension:=Copy(Hstr,1,j-1)+Ext;
  857. end;
  858. Function FixPath(s:string;allowdot:boolean):string;
  859. var
  860. i : longint;
  861. begin
  862. { Fix separator }
  863. for i:=1 to length(s) do
  864. if s[i] in ['/','\'] then
  865. s[i]:=DirSep;
  866. { Fix ending / }
  867. if (length(s)>0) and (s[length(s)]<>DirSep) and
  868. (s[length(s)]<>':') then
  869. s:=s+DirSep;
  870. { Remove ./ }
  871. if (not allowdot) and (s='.'+DirSep) then
  872. s:='';
  873. { return }
  874. {$ifdef linux}
  875. FixPath:=s;
  876. {$else}
  877. FixPath:=Lower(s);
  878. {$endif}
  879. end;
  880. function FixFileName(const s:string):string;
  881. var
  882. i : longint;
  883. {$ifdef Linux}
  884. NoPath : boolean;
  885. {$endif Linux}
  886. begin
  887. {$ifdef Linux}
  888. NoPath:=true;
  889. {$endif Linux}
  890. for i:=length(s) downto 1 do
  891. begin
  892. case s[i] of
  893. {$ifdef Linux}
  894. '/','\' : begin
  895. FixFileName[i]:='/';
  896. NoPath:=false; {Skip lowercasing path: 'X11'<>'x11' }
  897. end;
  898. 'A'..'Z' : if NoPath then
  899. FixFileName[i]:=char(byte(s[i])+32)
  900. else
  901. FixFileName[i]:=s[i];
  902. {$else}
  903. '/' : FixFileName[i]:='\';
  904. 'A'..'Z' : FixFileName[i]:=char(byte(s[i])+32);
  905. {$endif}
  906. else
  907. FixFileName[i]:=s[i];
  908. end;
  909. end;
  910. {$ifndef TP}
  911. {$ifopt H+}
  912. SetLength(FixFileName,length(s));
  913. {$else}
  914. FixFileName[0]:=s[0];
  915. {$endif}
  916. {$else}
  917. FixFileName[0]:=s[0];
  918. {$endif}
  919. end;
  920. procedure SplitBinCmd(const s:string;var bstr,cstr:string);
  921. var
  922. i : longint;
  923. begin
  924. i:=pos(' ',s);
  925. if i>0 then
  926. begin
  927. bstr:=Copy(s,1,i-1);
  928. cstr:=Copy(s,i+1,length(s)-i);
  929. end
  930. else
  931. begin
  932. bstr:='';
  933. cstr:='';
  934. end;
  935. end;
  936. procedure TSearchPathList.AddPath(s:string;addfirst:boolean);
  937. var
  938. j : longint;
  939. hs,hsd,
  940. CurrentDir,
  941. CurrPath : string;
  942. dir : searchrec;
  943. {$IFDEF NEWST}
  944. hp : PStringItem;
  945. {$ELSE}
  946. hp : PStringQueueItem;
  947. {$ENDIF}
  948. procedure addcurrpath;
  949. begin
  950. if addfirst then
  951. begin
  952. Delete(currPath);
  953. Insert(currPath);
  954. end
  955. else
  956. begin
  957. { Check if already in path, then we don't add it }
  958. hp:=Find(currPath);
  959. if not assigned(hp) then
  960. Concat(currPath);
  961. end;
  962. end;
  963. begin
  964. if s='' then
  965. exit;
  966. { Support default macro's }
  967. DefaultReplacements(s);
  968. { get current dir }
  969. CurrentDir:=GetCurrentDir;
  970. repeat
  971. { get currpath }
  972. if addfirst then
  973. begin
  974. j:=length(s);
  975. while (j>0) and (s[j]<>';') do
  976. dec(j);
  977. CurrPath:=FixPath(Copy(s,j+1,length(s)-j),false);
  978. if j=0 then
  979. s:=''
  980. else
  981. System.Delete(s,j,length(s)-j+1);
  982. end
  983. else
  984. begin
  985. j:=Pos(';',s);
  986. if j=0 then
  987. j:=255;
  988. CurrPath:=FixPath(Copy(s,1,j-1),false);
  989. System.Delete(s,1,j);
  990. end;
  991. { fix pathname }
  992. if CurrPath='' then
  993. CurrPath:='.'+DirSep
  994. else
  995. begin
  996. CurrPath:=FixPath(FExpand(CurrPath),false);
  997. if (CurrentDir<>'') and (Copy(CurrPath,1,length(CurrentDir))=CurrentDir) then
  998. CurrPath:='.'+DirSep+Copy(CurrPath,length(CurrentDir)+1,255);
  999. end;
  1000. { wildcard adding ? }
  1001. if pos('*',currpath)>0 then
  1002. begin
  1003. if currpath[length(currpath)]=dirsep then
  1004. hs:=Copy(currpath,1,length(CurrPath)-1)
  1005. else
  1006. hs:=currpath;
  1007. hsd:=SplitPath(hs);
  1008. findfirst(hs,directory,dir);
  1009. while doserror=0 do
  1010. begin
  1011. if (dir.name<>'.') and
  1012. (dir.name<>'..') and
  1013. ((dir.attr and directory)<>0) then
  1014. begin
  1015. currpath:=hsd+dir.name+dirsep;
  1016. hp:=Find(currPath);
  1017. if not assigned(hp) then
  1018. AddCurrPath;
  1019. end;
  1020. findnext(dir);
  1021. end;
  1022. FindClose(dir);
  1023. end
  1024. else
  1025. begin
  1026. if PathExists(currpath) then
  1027. addcurrpath;
  1028. end;
  1029. until (s='');
  1030. end;
  1031. procedure TSearchPathList.AddList(list:TSearchPathList;addfirst:boolean);
  1032. var
  1033. s : string;
  1034. hl : TSearchPathList;
  1035. {$IFDEF NEWST}
  1036. hp,hp2 : PStringItem;
  1037. {$ELSE}
  1038. hp,hp2 : PStringQueueItem;
  1039. {$ENDIF}
  1040. begin
  1041. if list.empty then
  1042. exit;
  1043. { create temp and reverse the list }
  1044. if addfirst then
  1045. begin
  1046. hl.Init;
  1047. hp:=list.first;
  1048. while assigned(hp) do
  1049. begin
  1050. hl.insert(hp^.data^);
  1051. hp:=hp^.next;
  1052. end;
  1053. while not hl.empty do
  1054. begin
  1055. s:=hl.Get;
  1056. Delete(s);
  1057. Insert(s);
  1058. end;
  1059. hl.done;
  1060. end
  1061. else
  1062. begin
  1063. hp:=list.first;
  1064. while assigned(hp) do
  1065. begin
  1066. hp2:=Find(hp^.data^);
  1067. { Check if already in path, then we don't add it }
  1068. if not assigned(hp2) then
  1069. Concat(hp^.data^);
  1070. hp:=hp^.next;
  1071. end;
  1072. end;
  1073. end;
  1074. function TSearchPathList.FindFile(const f : string;var b : boolean) : string;
  1075. Var
  1076. {$IFDEF NEWST}
  1077. p : PStringItem;
  1078. {$ELSE}
  1079. p : PStringQueueItem;
  1080. {$ENDIF}
  1081. begin
  1082. FindFile:='';
  1083. b:=false;
  1084. p:=first;
  1085. while assigned(p) do
  1086. begin
  1087. If FileExists(p^.data^+f) then
  1088. begin
  1089. FindFile:=p^.data^;
  1090. b:=true;
  1091. exit;
  1092. end;
  1093. p:=p^.next;
  1094. end;
  1095. end;
  1096. Function GetFileTime ( Var F : File) : Longint;
  1097. Var
  1098. {$ifdef linux}
  1099. Info : Stat;
  1100. {$endif}
  1101. L : longint;
  1102. begin
  1103. {$ifdef linux}
  1104. FStat (F,Info);
  1105. L:=Info.Mtime;
  1106. {$else}
  1107. GetFTime(f,l);
  1108. {$endif}
  1109. GetFileTime:=L;
  1110. end;
  1111. Function GetNamedFileTime (Const F : String) : Longint;
  1112. var
  1113. L : Longint;
  1114. {$ifndef linux}
  1115. info : SearchRec;
  1116. {$else}
  1117. info : stat;
  1118. {$endif}
  1119. begin
  1120. l:=-1;
  1121. {$ifdef linux}
  1122. if FStat (F,Info) then
  1123. L:=info.mtime;
  1124. {$else}
  1125. {$ifdef delphi}
  1126. dmisc.FindFirst (F,archive+readonly+hidden,info);
  1127. {$else delphi}
  1128. FindFirst (F,archive+readonly+hidden,info);
  1129. {$endif delphi}
  1130. if DosError=0 then
  1131. l:=info.time;
  1132. {$ifdef Linux}
  1133. FindClose(info);
  1134. {$endif}
  1135. {$ifdef Win32}
  1136. FindClose(info);
  1137. {$endif}
  1138. {$endif}
  1139. GetNamedFileTime:=l;
  1140. end;
  1141. {Touch Assembler and object time to ppu time is there is a ppufilename}
  1142. procedure SynchronizeFileTime(const fn1,fn2:string);
  1143. var
  1144. f : file;
  1145. l : longint;
  1146. begin
  1147. Assign(f,fn1);
  1148. {$I-}
  1149. reset(f,1);
  1150. {$I+}
  1151. if ioresult=0 then
  1152. begin
  1153. getftime(f,l);
  1154. { just to be sure in case there are rounding errors }
  1155. setftime(f,l);
  1156. close(f);
  1157. assign(f,fn2);
  1158. {$I-}
  1159. reset(f,1);
  1160. {$I+}
  1161. if ioresult=0 then
  1162. begin
  1163. setftime(f,l);
  1164. close(f);
  1165. end;
  1166. end;
  1167. end;
  1168. function FindFile(const f : string;path : string;var b : boolean) : string;
  1169. Var
  1170. singlepathstring : string;
  1171. i : longint;
  1172. begin
  1173. {$ifdef linux}
  1174. for i:=1 to length(path) do
  1175. if path[i]=':' then
  1176. path[i]:=';';
  1177. {$endif}
  1178. b:=false;
  1179. FindFile:='';
  1180. repeat
  1181. i:=pos(';',path);
  1182. if i=0 then
  1183. i:=256;
  1184. singlepathstring:=FixPath(copy(path,1,i-1),false);
  1185. delete(path,1,i);
  1186. If FileExists (singlepathstring+f) then
  1187. begin
  1188. FindFile:=singlepathstring;
  1189. b:=true;
  1190. exit;
  1191. end;
  1192. until path='';
  1193. end;
  1194. function FindExe(bin:string;var found:boolean):string;
  1195. begin
  1196. bin:=FixFileName(bin)+source_os.exeext;
  1197. {$ifdef delphi}
  1198. FindExe:=FindFile(bin,'.;'+exepath+';'+dmisc.getenv('PATH'),found)+bin;
  1199. {$else delphi}
  1200. FindExe:=FindFile(bin,'.;'+exepath+';'+dos.getenv('PATH'),found)+bin;
  1201. {$endif delphi}
  1202. end;
  1203. function GetShortName(const n:string):string;
  1204. {$ifdef win32}
  1205. var
  1206. hs,hs2 : string;
  1207. i : longint;
  1208. {$endif}
  1209. {$ifdef go32v2}
  1210. var
  1211. hs : string;
  1212. {$endif}
  1213. begin
  1214. GetShortName:=n;
  1215. {$ifdef win32}
  1216. hs:=n+#0;
  1217. i:=Windows.GetShortPathName(@hs[1],@hs2[1],high(hs2));
  1218. if (i>0) and (i<=high(hs2)) then
  1219. begin
  1220. hs2[0]:=chr(strlen(@hs2[1]));
  1221. GetShortName:=hs2;
  1222. end;
  1223. {$endif}
  1224. {$ifdef go32v2}
  1225. hs:=n;
  1226. if Dos.GetShortName(hs) then
  1227. GetShortName:=hs;
  1228. {$endif}
  1229. end;
  1230. {****************************************************************************
  1231. OS Dependent things
  1232. ****************************************************************************}
  1233. function GetEnvPChar(const envname:string):pchar;
  1234. {$ifdef win32}
  1235. var
  1236. s : string;
  1237. i,len : longint;
  1238. hp,p,p2 : pchar;
  1239. {$endif}
  1240. begin
  1241. {$ifdef linux}
  1242. GetEnvPchar:=Linux.Getenv(envname);
  1243. {$define GETENVOK}
  1244. {$endif}
  1245. {$ifdef win32}
  1246. GetEnvPchar:=nil;
  1247. p:=GetEnvironmentStrings;
  1248. hp:=p;
  1249. while hp^<>#0 do
  1250. begin
  1251. s:=strpas(hp);
  1252. i:=pos('=',s);
  1253. len:=strlen(hp);
  1254. if upper(copy(s,1,i-1))=upper(envname) then
  1255. begin
  1256. GetMem(p2,len-length(envname));
  1257. Move(hp[i],p2^,len-length(envname));
  1258. GetEnvPchar:=p2;
  1259. break;
  1260. end;
  1261. { next string entry}
  1262. hp:=hp+len+1;
  1263. end;
  1264. FreeEnvironmentStrings(p);
  1265. {$define GETENVOK}
  1266. {$endif}
  1267. {$ifdef GETENVOK}
  1268. {$undef GETENVOK}
  1269. {$else}
  1270. GetEnvPchar:=StrPNew(Dos.Getenv(envname));
  1271. {$endif}
  1272. end;
  1273. procedure FreeEnvPChar(p:pchar);
  1274. begin
  1275. {$ifndef linux}
  1276. StrDispose(p);
  1277. {$endif}
  1278. end;
  1279. Procedure Shell(const command:string);
  1280. { This is already defined in the linux.ppu for linux, need for the *
  1281. expansion under linux }
  1282. {$ifdef linux}
  1283. begin
  1284. Linux.Shell(command);
  1285. end;
  1286. {$else}
  1287. var
  1288. comspec : string;
  1289. begin
  1290. comspec:=getenv('COMSPEC');
  1291. Exec(comspec,' /C '+command);
  1292. end;
  1293. {$endif}
  1294. {****************************************************************************
  1295. Init
  1296. ****************************************************************************}
  1297. procedure get_exepath;
  1298. var
  1299. hs1 : namestr;
  1300. hs2 : extstr;
  1301. begin
  1302. {$ifdef delphi}
  1303. exepath:=dmisc.getenv('PPC_EXEC_PATH');
  1304. {$else delphi}
  1305. exepath:=dos.getenv('PPC_EXEC_PATH');
  1306. {$endif delphi}
  1307. if exepath='' then
  1308. fsplit(FixFileName(paramstr(0)),exepath,hs1,hs2);
  1309. {$ifndef VER0_99_15}
  1310. {$ifdef linux}
  1311. if exepath='' then
  1312. fsearch(hs1,dos.getenv('PATH'));
  1313. {$endif}
  1314. {$endif}
  1315. exepath:=FixPath(exepath,false);
  1316. end;
  1317. procedure DoneGlobals;
  1318. begin
  1319. initdefines.done;
  1320. if assigned(DLLImageBase) then
  1321. StringDispose(DLLImageBase);
  1322. RelocSection:=true;
  1323. RelocSectionSetExplicitly:=false;
  1324. DLLsource:=false;
  1325. UseDeffileForExport:=true;
  1326. librarysearchpath.Done;
  1327. unitsearchpath.Done;
  1328. objectsearchpath.Done;
  1329. includesearchpath.Done;
  1330. end;
  1331. procedure InitGlobals;
  1332. begin
  1333. { set global switches }
  1334. do_build:=false;
  1335. do_make:=true;
  1336. {$ifdef tp}
  1337. use_big:=false;
  1338. {$endif tp}
  1339. compile_level:=0;
  1340. { Output }
  1341. OutputFile:='';
  1342. OutputExeDir:='';
  1343. OutputUnitDir:='';
  1344. { Utils directory }
  1345. utilsdirectory:='';
  1346. { Search Paths }
  1347. librarysearchpath.Init;
  1348. unitsearchpath.Init;
  1349. includesearchpath.Init;
  1350. objectsearchpath.Init;
  1351. { Def file }
  1352. usewindowapi:=false;
  1353. description:='Compiled by FPC '+version_string+' - '+target_cpu_string;
  1354. dllversion:='';
  1355. { Init values }
  1356. initmodeswitches:=fpcmodeswitches;
  1357. initlocalswitches:=[cs_check_io];
  1358. initmoduleswitches:=[cs_extsyntax,cs_browser];
  1359. initglobalswitches:=[cs_check_unit_name,cs_link_static];
  1360. {$ifdef i386}
  1361. initoptprocessor:=Class386;
  1362. initspecificoptprocessor:=Class386;
  1363. initpackenum:=4;
  1364. {$IFDEF testvarsets}
  1365. initsetalloc:=0;
  1366. {$ENDIF}
  1367. initpackrecords:=packrecord_2;
  1368. initoutputformat:=target_asm.id;
  1369. initasmmode:=asmmode_i386_att;
  1370. {$else not i386}
  1371. {$ifdef m68k}
  1372. initoptprocessor:=MC68000;
  1373. include(initmoduleswitches,cs_fp_emulation);
  1374. initpackenum:=4;
  1375. {$IFDEF testvarsets}
  1376. initsetalloc:=0;
  1377. {$ENDIF}
  1378. initpackrecords:=packrecord_2;
  1379. initoutputformat:=as_m68k_as;
  1380. initasmmode:=asmmode_m68k_mot;
  1381. {$endif m68k}
  1382. {$endif i386}
  1383. initdefines.init;
  1384. { memory sizes, will be overriden by parameter or default for target
  1385. in options or init_parser }
  1386. stacksize:=0;
  1387. heapsize:=0;
  1388. maxheapsize:=0;
  1389. { compile state }
  1390. in_args:=false;
  1391. { must_be_valid:=true; obsolete PM }
  1392. not_unit_proc:=true;
  1393. apptype:=at_cui;
  1394. end;
  1395. begin
  1396. get_exepath;
  1397. {$ifdef EXTDEBUG}
  1398. {$ifdef FPC}
  1399. EntryMemUsed:=system.HeapSize-MemAvail;
  1400. {$endif FPC}
  1401. {$endif}
  1402. end.
  1403. {
  1404. $Log$
  1405. Revision 1.65 2000-06-15 18:10:11 peter
  1406. * first look for ppu in cwd and outputpath and after that for source
  1407. in cwd
  1408. * fixpath() for not linux makes path now lowercase so comparing paths
  1409. with different cases (sometimes a drive letter could be
  1410. uppercased) gives the expected results
  1411. * sources_checked flag if there was already a full search for sources
  1412. which aren't found, so another scan isn't done when checking for the
  1413. sources only when recompile is needed
  1414. Revision 1.64 2000/06/11 07:00:21 peter
  1415. * fixed pchar->string conversion for delphi mode
  1416. Revision 1.63 2000/05/12 08:58:51 pierre
  1417. * adapted to Delphi 3
  1418. Revision 1.62 2000/05/12 05:55:04 pierre
  1419. * * get it to compile with Delphi by Kovacs Attila Zoltan
  1420. Revision 1.61 2000/05/11 09:37:25 pierre
  1421. * do not use upcase for strings, reported by Kovacs Attila Zoltan
  1422. Revision 1.60 2000/05/04 20:46:17 peter
  1423. * ansistrings are now default on for delphi mode, as most ppl expect
  1424. this
  1425. Revision 1.59 2000/05/03 14:36:57 pierre
  1426. * fix for tests/test/testrang.pp bug
  1427. Revision 1.58 2000/04/14 12:27:57 pierre
  1428. * setfiletime to both files in synchronize
  1429. Revision 1.57 2000/03/23 15:35:47 peter
  1430. * $VERSION is now version_string
  1431. + $FULLVERSION is now full_version_string
  1432. Revision 1.56 2000/03/20 16:04:05 pierre
  1433. * probably a fix for bug 615
  1434. Revision 1.55 2000/03/08 15:39:45 daniel
  1435. + Added align_from_size function as suggested by Peter.
  1436. Revision 1.54 2000/02/28 17:23:57 daniel
  1437. * Current work of symtable integration committed. The symtable can be
  1438. activated by defining 'newst', but doesn't compile yet. Changes in type
  1439. checking and oop are completed. What is left is to write a new
  1440. symtablestack and adapt the parser to use it.
  1441. Revision 1.53 2000/02/14 20:58:44 marco
  1442. * Basic structures for new sethandling implemented.
  1443. Revision 1.52 2000/02/10 11:45:48 peter
  1444. * addpath fixed with list of paths when inserting at the beginning
  1445. * if exepath=currentdir then it's not inserted in path list
  1446. * searchpaths in ppc386.cfg are now added at the beginning of the
  1447. list instead of at the end. (commandline is not changed)
  1448. * check paths before inserting in list
  1449. Revision 1.51 2000/02/09 13:22:53 peter
  1450. * log truncated
  1451. Revision 1.50 2000/01/26 14:31:03 marco
  1452. * $VERSION is now also substituted in -F paths (that have subst active)
  1453. Revision 1.49 2000/01/23 21:29:14 florian
  1454. * CMOV support in optimizer (in define USECMOV)
  1455. + start of support of exceptions in constructors
  1456. Revision 1.48 2000/01/23 16:36:37 peter
  1457. * better auto RTL dir detection
  1458. Revision 1.47 2000/01/20 00:23:03 pierre
  1459. * fix for GetShortName, now checks results from Win32
  1460. Revision 1.46 2000/01/07 01:14:27 peter
  1461. * updated copyright to 2000
  1462. Revision 1.45 2000/01/07 00:08:09 peter
  1463. * tp7 fix
  1464. Revision 1.44 2000/01/06 15:48:59 peter
  1465. * wildcard support for directory adding, this allows the use of units/*
  1466. in ppc386.cfg
  1467. Revision 1.43 2000/01/04 15:15:50 florian
  1468. + added compiler switch $maxfpuregisters
  1469. + fixed a small problem in secondvecn
  1470. Revision 1.42 1999/12/22 01:01:48 peter
  1471. - removed freelabel()
  1472. * added undefined label detection in internal assembler, this prevents
  1473. a lot of ld crashes and wrong .o files
  1474. * .o files aren't written anymore if errors have occured
  1475. * inlining of assembler labels is now correct
  1476. Revision 1.41 1999/12/20 23:23:28 pierre
  1477. + $description $version
  1478. Revision 1.40 1999/12/20 21:42:34 pierre
  1479. + dllversion global variable
  1480. * FPC_USE_CPREFIX code removed, not necessary anymore
  1481. as we use .edata direct writing by default now.
  1482. Revision 1.39 1999/12/08 10:40:00 pierre
  1483. + allow use of unit var in exports of DLL for win32
  1484. by using direct export writing by default instead of use of DEFFILE
  1485. that does not allow assembler labels that do not
  1486. start with an underscore.
  1487. Use -WD to force use of Deffile for Win32 DLL
  1488. Revision 1.38 1999/12/06 18:21:03 peter
  1489. * support !ENVVAR for long commandlines
  1490. * win32/go32v2 write short pathnames to link.res so c:\Program Files\ is
  1491. finally supported as installdir.
  1492. Revision 1.37 1999/12/02 17:34:34 peter
  1493. * preprocessor support. But it fails on the caret in type blocks
  1494. Revision 1.36 1999/11/18 15:34:45 pierre
  1495. * Notes/Hints for local syms changed to
  1496. Set_varstate function
  1497. Revision 1.35 1999/11/17 17:04:59 pierre
  1498. * Notes/hints changes
  1499. Revision 1.34 1999/11/15 17:42:41 pierre
  1500. * -g disables reloc section for win32
  1501. Revision 1.33 1999/11/12 11:03:50 peter
  1502. * searchpaths changed to stringqueue object
  1503. Revision 1.32 1999/11/09 23:34:46 pierre
  1504. + resolving_forward boolean used for references
  1505. Revision 1.31 1999/11/09 13:00:38 peter
  1506. * define FPC_DELPHI,FPC_OBJFPC,FPC_TP,FPC_GPC
  1507. * initial support for ansistring default with modes
  1508. }