globals.pas 44 KB

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