globals.pas 42 KB

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