globals.pas 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 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. unit globals;
  19. {$i fpcdefs.inc}
  20. { Use the internal linker by default }
  21. { define INTERNALLINKER}
  22. interface
  23. uses
  24. {$ifdef win32}
  25. windows,
  26. {$endif}
  27. {$ifdef unix}
  28. {$ifdef ver1_0}
  29. linux,
  30. {$else}
  31. unix,
  32. {$endif}
  33. {$endif}
  34. {$ifdef os2}
  35. doscalls,
  36. {$endif}
  37. {$ifdef Delphi}
  38. SysUtils,
  39. dmisc,
  40. {$else}
  41. strings,
  42. dos,
  43. {$endif}
  44. cutils,cclasses,
  45. globtype,version,systems,cpuinfo;
  46. const
  47. {$ifdef Splitheap}
  48. testsplit : boolean = false;
  49. {$endif Splitheap}
  50. delphimodeswitches : tmodeswitches=
  51. [m_delphi,m_all,m_class,m_objpas,m_result,m_string_pchar,
  52. m_pointer_2_procedure,m_autoderef,m_tp_procvar,m_initfinal,m_default_ansistring,
  53. m_out,m_default_para,m_duplicate_names,m_hintdirective];
  54. fpcmodeswitches : tmodeswitches=
  55. [m_fpc,m_all,m_string_pchar,m_nested_comment,m_repeat_forward,
  56. m_cvar_support,m_initfinal,m_add_pointer,m_hintdirective];
  57. objfpcmodeswitches : tmodeswitches=
  58. [m_objfpc,m_fpc,m_all,m_class,m_objpas,m_result,m_string_pchar,m_nested_comment,
  59. m_repeat_forward,m_cvar_support,m_initfinal,m_add_pointer,m_out,m_default_para,m_hintdirective];
  60. tpmodeswitches : tmodeswitches=
  61. [m_tp7,m_all,m_tp_procvar,m_duplicate_names];
  62. gpcmodeswitches : tmodeswitches=
  63. [m_gpc,m_all];
  64. { maximum number of locals in bytes before warning is emitted }
  65. maxlocalsize = high(smallint);
  66. { maximum number of paras in bytes before warning is emitted }
  67. maxparasize = high(word);
  68. type
  69. pfileposinfo = ^tfileposinfo;
  70. tfileposinfo = record
  71. line : longint;
  72. column : word;
  73. fileindex : word;
  74. { moduleindex : word; }
  75. end;
  76. TSearchPathList = class(TStringList)
  77. procedure AddPath(s:string;addfirst:boolean);
  78. procedure AddPath(SrcPath,s:string;addfirst:boolean);
  79. procedure AddList(list:TSearchPathList;addfirst:boolean);
  80. function FindFile(const f : string;var foundfile:string):boolean;
  81. end;
  82. tcodepagestring = string[20];
  83. { the ordinal type used when evaluating constant integer expressions }
  84. TConstExprInt = int64;
  85. { ... the same unsigned }
  86. TConstExprUInt = {$ifdef fpc}qword{$else}int64{$endif};
  87. var
  88. { specified inputfile }
  89. inputdir : dirstr;
  90. inputfile : namestr;
  91. inputextension : extstr;
  92. { specified outputfile with -o parameter }
  93. outputfile : namestr;
  94. { specified with -FE or -FU }
  95. outputexedir : dirstr;
  96. outputunitdir : dirstr;
  97. { things specified with parameters }
  98. paralinkoptions,
  99. paradynamiclinker : string;
  100. parapreprocess : boolean;
  101. { directory where the utils can be found (options -FD) }
  102. utilsdirectory : dirstr;
  103. { some flags for global compiler switches }
  104. do_build,
  105. do_release,
  106. do_make : boolean;
  107. not_unit_proc : boolean;
  108. { path for searching units, different paths can be seperated by ; }
  109. exepath : dirstr; { Path to ppc }
  110. librarysearchpath,
  111. unitsearchpath,
  112. objectsearchpath,
  113. includesearchpath : TSearchPathList;
  114. { deffile }
  115. usewindowapi : boolean;
  116. description : string;
  117. dllversion : string;
  118. dllmajor,dllminor,dllrevision : word; { revision only for netware }
  119. akttokenpos, { position of the last token }
  120. aktfilepos : tfileposinfo; { current position }
  121. { ad 18.05.2001: Screen and Threadname for Netware }
  122. nwscreenname : string;
  123. nwthreadname : string;
  124. nwcopyright : string;
  125. block_type : tblock_type; { type of currently parsed block }
  126. in_args : boolean; { arguments must be checked especially }
  127. parsing_para_level : integer; { parameter level, used to convert
  128. proc calls to proc loads in firstcalln }
  129. compile_level : word;
  130. make_ref : boolean;
  131. resolving_forward : boolean; { used to add forward reference as second ref }
  132. use_esp_stackframe : boolean; { to test for call with ESP as stack frame }
  133. inlining_procedure : boolean; { are we inlining a procedure }
  134. statement_level : integer;
  135. exceptblockcounter : integer; { each except block gets a unique number check gotos }
  136. aktexceptblock : integer; { the exceptblock number of the current block (0 if none) }
  137. have_local_threadvars : boolean; { set if a table of local threadvars-tables is present and has to be initialized }
  138. { commandline values }
  139. initdefines : tstringlist;
  140. initglobalswitches : tglobalswitches;
  141. initmoduleswitches : tmoduleswitches;
  142. initlocalswitches : tlocalswitches;
  143. initmodeswitches : tmodeswitches;
  144. {$IFDEF testvarsets}
  145. Initsetalloc, {0=fixed, 1 =var}
  146. {$ENDIF}
  147. initpackenum : longint;
  148. initalignment : talignmentinfo;
  149. initoptprocessor,
  150. initspecificoptprocessor : tprocessors;
  151. initasmmode : tasmmode;
  152. initinterfacetype : tinterfacetypes;
  153. initoutputformat : tasm;
  154. initdefproccall : tproccalloption;
  155. initsourcecodepage : tcodepagestring;
  156. { current state values }
  157. aktglobalswitches : tglobalswitches;
  158. aktmoduleswitches : tmoduleswitches;
  159. aktlocalswitches : tlocalswitches;
  160. nextaktlocalswitches : tlocalswitches;
  161. localswitcheschanged : boolean;
  162. aktmodeswitches : tmodeswitches;
  163. {$IFDEF testvarsets}
  164. aktsetalloc,
  165. {$ENDIF}
  166. aktpackenum : longint;
  167. aktmaxfpuregisters : longint;
  168. aktalignment : talignmentinfo;
  169. aktoptprocessor,
  170. aktspecificoptprocessor : tprocessors;
  171. aktasmmode : tasmmode;
  172. aktinterfacetype : tinterfacetypes;
  173. aktoutputformat : tasm;
  174. aktdefproccall : tproccalloption;
  175. aktsourcecodepage : tcodepagestring;
  176. { Memory sizes }
  177. heapsize,
  178. stacksize : longint;
  179. {$Ifdef EXTDEBUG}
  180. { parameter switches }
  181. debugstop : boolean;
  182. {$EndIf EXTDEBUG}
  183. { windows / OS/2 application type }
  184. apptype : tapptype;
  185. const
  186. RelocSection : boolean = true;
  187. RelocSectionSetExplicitly : boolean = false;
  188. LinkTypeSetExplicitly : boolean = false;
  189. DLLsource : boolean = false;
  190. DLLImageBase : pstring = nil;
  191. UseDeffileForExport : boolean = true;
  192. ForceDeffileForExport : boolean = false;
  193. { used to set all registers used for each global function
  194. this should dramatically decrease the number of
  195. recompilations needed PM }
  196. simplify_ppu : boolean = true;
  197. { should we allow non static members ? }
  198. allow_only_static : boolean = false;
  199. Inside_asm_statement : boolean = false;
  200. global_unit_count : word = 0;
  201. { for error info in pp.pas }
  202. parser_current_file : string = '';
  203. {$ifdef m68k}
  204. { PalmOS resources }
  205. palmos_applicationname : string = 'FPC Application';
  206. palmos_applicationid : string[4] = 'FPCA';
  207. {$endif m68k}
  208. procedure abstract;
  209. function bstoslash(const s : string) : string;
  210. function getdatestr:string;
  211. function gettimestr:string;
  212. function filetimestring( t : longint) : string;
  213. procedure DefaultReplacements(var s:string);
  214. function GetCurrentDir:string;
  215. function path_absolute(const s : string) : boolean;
  216. Function PathExists ( F : String) : Boolean;
  217. Function FileExists ( Const F : String) : Boolean;
  218. Function RemoveFile(const f:string):boolean;
  219. Function RemoveDir(d:string):boolean;
  220. Function GetFileTime ( Var F : File) : Longint;
  221. Function GetNamedFileTime ( Const F : String) : Longint;
  222. Function SplitPath(const s:string):string;
  223. Function SplitFileName(const s:string):string;
  224. Function SplitName(const s:string):string;
  225. Function SplitExtension(Const HStr:String):String;
  226. Function AddExtension(Const HStr,ext:String):String;
  227. Function ForceExtension(Const HStr,ext:String):String;
  228. Function FixPath(s:string;allowdot:boolean):string;
  229. function FixFileName(const s:string):string;
  230. function TargetFixPath(s:string;allowdot:boolean):string;
  231. function TargetFixFileName(const s:string):string;
  232. procedure SplitBinCmd(const s:string;var bstr,cstr:string);
  233. function FindFile(const f : string;path : string;var foundfile:string):boolean;
  234. function FindExe(const bin:string;var foundfile:string):boolean;
  235. function GetShortName(const n:string):string;
  236. Procedure Shell(const command:string);
  237. function GetEnvPChar(const envname:string):pchar;
  238. procedure FreeEnvPChar(p:pchar);
  239. Function SetCompileMode(const s:string; changeInit: boolean):boolean;
  240. function SetAktProcCall(const s:string; changeInit: boolean):boolean;
  241. procedure InitGlobals;
  242. procedure DoneGlobals;
  243. function string2guid(const s: string; var GUID: TGUID): boolean;
  244. function guid2string(const GUID: TGUID): string;
  245. procedure swap_qword(var q : qword);
  246. function UpdateAlignmentStr(s:string;var a:talignmentinfo):boolean;
  247. {# Routine to get the required alignment for size of data, which will
  248. be placed in bss segment, according to the current alignment requirements }
  249. function var_align(siz: longint): longint;
  250. {# Routine to get the required alignment for size of data, which will
  251. be placed in data/const segment, according to the current alignment requirements }
  252. function const_align(siz: longint): longint;
  253. implementation
  254. uses
  255. comphook;
  256. procedure abstract;
  257. begin
  258. do_internalerror(255);
  259. end;
  260. procedure WarnNonExistingPath(const path : string);
  261. begin
  262. if assigned({$ifndef FPCPROCVAR}@{$endif}do_comment) then
  263. do_comment(V_Hint,'Path "'+path+'" not found');
  264. end;
  265. function bstoslash(const s : string) : string;
  266. {
  267. return string s with all \ changed into /
  268. }
  269. var
  270. i : longint;
  271. begin
  272. for i:=1to length(s) do
  273. if s[i]='\' then
  274. bstoslash[i]:='/'
  275. else
  276. bstoslash[i]:=s[i];
  277. bstoslash[0]:=s[0];
  278. end;
  279. {****************************************************************************
  280. Time Handling
  281. ****************************************************************************}
  282. Function L0(l:longint):string;
  283. {
  284. return the string of value l, if l<10 then insert a zero, so
  285. the string is always at least 2 chars '01','02',etc
  286. }
  287. var
  288. s : string;
  289. begin
  290. Str(l,s);
  291. if l<10 then
  292. s:='0'+s;
  293. L0:=s;
  294. end;
  295. function gettimestr:string;
  296. {
  297. get the current time in a string HH:MM:SS
  298. }
  299. var
  300. hour,min,sec,hsec : word;
  301. begin
  302. {$ifdef delphi}
  303. dmisc.gettime(hour,min,sec,hsec);
  304. {$else delphi}
  305. dos.gettime(hour,min,sec,hsec);
  306. {$endif delphi}
  307. gettimestr:=L0(Hour)+':'+L0(min)+':'+L0(sec);
  308. end;
  309. function getdatestr:string;
  310. {
  311. get the current date in a string YY/MM/DD
  312. }
  313. var
  314. Year,Month,Day,Wday : Word;
  315. begin
  316. {$ifdef delphi}
  317. dmisc.getdate(year,month,day,wday);
  318. {$else}
  319. dos.getdate(year,month,day,wday);
  320. {$endif}
  321. getdatestr:=L0(Year)+'/'+L0(Month)+'/'+L0(Day);
  322. end;
  323. function filetimestring( t : longint) : string;
  324. {
  325. convert dos datetime t to a string YY/MM/DD HH:MM:SS
  326. }
  327. var
  328. DT : DateTime;
  329. begin
  330. if t=-1 then
  331. begin
  332. FileTimeString:='Not Found';
  333. exit;
  334. end;
  335. unpacktime(t,DT);
  336. filetimestring:=L0(dt.Year)+'/'+L0(dt.Month)+'/'+L0(dt.Day)+' '+L0(dt.Hour)+':'+L0(dt.min)+':'+L0(dt.sec);
  337. end;
  338. {****************************************************************************
  339. Default Macro Handling
  340. ****************************************************************************}
  341. procedure DefaultReplacements(var s:string);
  342. begin
  343. { Replace some macro's }
  344. Replace(s,'$FPCVER',version_string);
  345. Replace(s,'$VERSION',version_string);
  346. Replace(s,'$FULLVERSION',full_version_string);
  347. Replace(s,'$FPCDATE',date_string);
  348. Replace(s,'$FPCTARGET',target_cpu_string);
  349. Replace(s,'$FPCCPU',target_cpu_string);
  350. Replace(s,'$TARGET',target_path);
  351. Replace(s,'$FPCOS',target_path);
  352. end;
  353. {****************************************************************************
  354. File Handling
  355. ****************************************************************************}
  356. function GetCurrentDir:string;
  357. var
  358. CurrentDir : string;
  359. begin
  360. GetDir(0,CurrentDir);
  361. GetCurrentDir:=FixPath(CurrentDir,false);
  362. end;
  363. function path_absolute(const s : string) : boolean;
  364. {
  365. is path s an absolute path?
  366. }
  367. begin
  368. path_absolute:=false;
  369. {$ifdef unix}
  370. if (length(s)>0) and (s[1]='/') then
  371. path_absolute:=true;
  372. {$else unix}
  373. {$ifdef amiga}
  374. if ((length(s)>0) and ((s[1]='\') or (s[1]='/'))) or (Pos(':',s) = length(s)) then
  375. path_absolute:=true;
  376. {$else}
  377. if ((length(s)>0) and ((s[1]='\') or (s[1]='/'))) or
  378. ((length(s)>2) and (s[2]=':') and ((s[3]='\') or (s[3]='/'))) then
  379. path_absolute:=true;
  380. {$endif amiga}
  381. {$endif unix}
  382. end;
  383. {$ifndef FPC}
  384. Procedure FindClose(var Info : SearchRec);
  385. Begin
  386. End;
  387. {$endif not FPC}
  388. Function FileExists ( Const F : String) : Boolean;
  389. Var
  390. res : boolean;
  391. {$ifndef delphi}
  392. Info : SearchRec;
  393. {$endif}
  394. begin
  395. {$ifdef delphi}
  396. res:=sysutils.FileExists(f);
  397. {$else}
  398. findfirst(F,readonly+archive+hidden,info);
  399. res:=(doserror=0);
  400. findclose(Info);
  401. {$endif delphi}
  402. if assigned({$ifndef FPCPROVCAR}@{$endif}do_comment) then
  403. begin
  404. if res then
  405. do_comment(V_Tried,'Searching file '+F+'... found')
  406. else
  407. do_comment(V_Tried,'Searching file '+F+'... not found');
  408. end;
  409. FileExists:=res;
  410. end;
  411. Function PathExists ( F : String) : Boolean;
  412. Var
  413. Info : SearchRec;
  414. {$ifdef i386}
  415. disk : byte;
  416. {$endif i386}
  417. begin
  418. {$ifdef i386}
  419. if (Length(f)=3) and (F[2]=':') and (F[3] in ['/','\']) then
  420. begin
  421. if F[1] in ['A'..'Z'] then
  422. disk:=ord(F[1])-ord('A')+1
  423. else if F[1] in ['a'..'z'] then
  424. disk:=ord(F[1])-ord('a')+1
  425. else
  426. disk:=255;
  427. if disk=255 then
  428. PathExists:=false
  429. else
  430. PathExists:=(DiskSize(disk)<>-1);
  431. exit;
  432. end;
  433. {$endif i386}
  434. if F[Length(f)] in ['/','\'] then
  435. Delete(f,length(f),1);
  436. findfirst(F,readonly+archive+hidden+directory,info);
  437. PathExists:=(doserror=0) and ((info.attr and directory)=directory);
  438. findclose(Info);
  439. end;
  440. Function RemoveFile(const f:string):boolean;
  441. var
  442. g : file;
  443. begin
  444. assign(g,f);
  445. {$I-}
  446. erase(g);
  447. {$I+}
  448. RemoveFile:=(ioresult=0);
  449. end;
  450. Function RemoveDir(d:string):boolean;
  451. begin
  452. if d[length(d)]=source_info.DirSep then
  453. Delete(d,length(d),1);
  454. {$I-}
  455. rmdir(d);
  456. {$I+}
  457. RemoveDir:=(ioresult=0);
  458. end;
  459. Function SplitPath(const s:string):string;
  460. var
  461. i : longint;
  462. begin
  463. i:=Length(s);
  464. while (i>0) and not(s[i] in ['/','\']) do
  465. dec(i);
  466. SplitPath:=Copy(s,1,i);
  467. end;
  468. Function SplitFileName(const s:string):string;
  469. var
  470. p : dirstr;
  471. n : namestr;
  472. e : extstr;
  473. begin
  474. FSplit(s,p,n,e);
  475. SplitFileName:=n+e;
  476. end;
  477. Function SplitName(const s:string):string;
  478. var
  479. i,j : longint;
  480. begin
  481. i:=Length(s);
  482. j:=Length(s);
  483. while (i>0) and not(s[i] in ['/','\']) do
  484. dec(i);
  485. while (j>0) and (s[j]<>'.') do
  486. dec(j);
  487. if j<=i then
  488. j:=255;
  489. SplitName:=Copy(s,i+1,j-(i+1));
  490. end;
  491. Function SplitExtension(Const HStr:String):String;
  492. var
  493. j : longint;
  494. begin
  495. j:=length(Hstr);
  496. while (j>0) and (Hstr[j]<>'.') do
  497. begin
  498. if hstr[j]=source_info.DirSep then
  499. j:=0
  500. else
  501. dec(j);
  502. end;
  503. if j=0 then
  504. j:=254;
  505. SplitExtension:=Copy(Hstr,j,255);
  506. end;
  507. Function AddExtension(Const HStr,ext:String):String;
  508. begin
  509. if (Ext<>'') and (SplitExtension(HStr)='') then
  510. AddExtension:=Hstr+Ext
  511. else
  512. AddExtension:=Hstr;
  513. end;
  514. Function ForceExtension(Const HStr,ext:String):String;
  515. var
  516. j : longint;
  517. begin
  518. j:=length(Hstr);
  519. while (j>0) and (Hstr[j]<>'.') do
  520. dec(j);
  521. if j=0 then
  522. j:=255;
  523. ForceExtension:=Copy(Hstr,1,j-1)+Ext;
  524. end;
  525. Function FixPath(s:string;allowdot:boolean):string;
  526. var
  527. i : longint;
  528. begin
  529. { Fix separator }
  530. for i:=1 to length(s) do
  531. if s[i] in ['/','\'] then
  532. s[i]:=source_info.DirSep;
  533. { Fix ending / }
  534. if (length(s)>0) and (s[length(s)]<>source_info.DirSep) and
  535. (s[length(s)]<>':') then
  536. s:=s+source_info.DirSep;
  537. { Remove ./ }
  538. if (not allowdot) and (s='.'+source_info.DirSep) then
  539. s:='';
  540. { return }
  541. if source_info.files_case_relevent then
  542. FixPath:=s
  543. else
  544. FixPath:=Lower(s);
  545. end;
  546. function FixFileName(const s:string):string;
  547. var
  548. i : longint;
  549. begin
  550. if source_info.files_case_relevent then
  551. begin
  552. for i:=1 to length(s) do
  553. begin
  554. case s[i] of
  555. '/','\' :
  556. FixFileName[i]:=source_info.dirsep;
  557. else
  558. FixFileName[i]:=s[i];
  559. end;
  560. end;
  561. end
  562. else
  563. begin
  564. for i:=1 to length(s) do
  565. begin
  566. case s[i] of
  567. '/','\' :
  568. FixFileName[i]:=source_info.dirsep;
  569. 'A'..'Z' :
  570. FixFileName[i]:=char(byte(s[i])+32);
  571. else
  572. FixFileName[i]:=s[i];
  573. end;
  574. end;
  575. end;
  576. FixFileName[0]:=s[0];
  577. end;
  578. Function TargetFixPath(s:string;allowdot:boolean):string;
  579. var
  580. i : longint;
  581. begin
  582. { Fix separator }
  583. for i:=1 to length(s) do
  584. if s[i] in ['/','\'] then
  585. s[i]:=target_info.DirSep;
  586. { Fix ending / }
  587. if (length(s)>0) and (s[length(s)]<>target_info.DirSep) and
  588. (s[length(s)]<>':') then
  589. s:=s+target_info.DirSep;
  590. { Remove ./ }
  591. if (not allowdot) and (s='.'+target_info.DirSep) then
  592. s:='';
  593. { return }
  594. if target_info.files_case_relevent then
  595. TargetFixPath:=s
  596. else
  597. TargetFixPath:=Lower(s);
  598. end;
  599. function TargetFixFileName(const s:string):string;
  600. var
  601. i : longint;
  602. begin
  603. if target_info.files_case_relevent then
  604. begin
  605. for i:=1 to length(s) do
  606. begin
  607. case s[i] of
  608. '/','\' :
  609. TargetFixFileName[i]:=target_info.dirsep;
  610. else
  611. TargetFixFileName[i]:=s[i];
  612. end;
  613. end;
  614. end
  615. else
  616. begin
  617. for i:=1 to length(s) do
  618. begin
  619. case s[i] of
  620. '/','\' :
  621. TargetFixFileName[i]:=target_info.dirsep;
  622. 'A'..'Z' :
  623. TargetFixFileName[i]:=char(byte(s[i])+32);
  624. else
  625. TargetFixFileName[i]:=s[i];
  626. end;
  627. end;
  628. end;
  629. TargetFixFileName[0]:=s[0];
  630. end;
  631. procedure SplitBinCmd(const s:string;var bstr,cstr:string);
  632. var
  633. i : longint;
  634. begin
  635. i:=pos(' ',s);
  636. if i>0 then
  637. begin
  638. bstr:=Copy(s,1,i-1);
  639. cstr:=Copy(s,i+1,length(s)-i);
  640. end
  641. else
  642. begin
  643. bstr:=s;
  644. cstr:='';
  645. end;
  646. end;
  647. procedure TSearchPathList.AddPath(s:string;addfirst:boolean);
  648. begin
  649. AddPath('',s,AddFirst);
  650. end;
  651. procedure TSearchPathList.AddPath(SrcPath,s:string;addfirst:boolean);
  652. var
  653. j : longint;
  654. hs,hsd,
  655. CurrentDir,
  656. CurrPath : string;
  657. subdirfound : boolean;
  658. dir : searchrec;
  659. hp : TStringListItem;
  660. procedure addcurrpath;
  661. begin
  662. if addfirst then
  663. begin
  664. Remove(currPath);
  665. Insert(currPath);
  666. end
  667. else
  668. begin
  669. { Check if already in path, then we don't add it }
  670. hp:=Find(currPath);
  671. if not assigned(hp) then
  672. Concat(currPath);
  673. end;
  674. end;
  675. begin
  676. if s='' then
  677. exit;
  678. { Support default macro's }
  679. DefaultReplacements(s);
  680. { get current dir }
  681. CurrentDir:=GetCurrentDir;
  682. repeat
  683. { get currpath }
  684. if addfirst then
  685. begin
  686. j:=length(s);
  687. while (j>0) and (s[j]<>';') do
  688. dec(j);
  689. CurrPath:=FixPath(Copy(s,j+1,length(s)-j),false);
  690. if j=0 then
  691. s:=''
  692. else
  693. System.Delete(s,j,length(s)-j+1);
  694. end
  695. else
  696. begin
  697. j:=Pos(';',s);
  698. if j=0 then
  699. j:=255;
  700. CurrPath:=SrcPath+FixPath(Copy(s,1,j-1),false);
  701. System.Delete(s,1,j);
  702. end;
  703. { fix pathname }
  704. if CurrPath='' then
  705. CurrPath:='.'+source_info.DirSep
  706. else
  707. begin
  708. CurrPath:=FixPath(FExpand(CurrPath),false);
  709. if (CurrentDir<>'') and (Copy(CurrPath,1,length(CurrentDir))=CurrentDir) then
  710. begin
  711. {$ifdef AMIGA}
  712. CurrPath:=Copy(CurrPath,length(CurrentDir)+1,255);
  713. {$else}
  714. CurrPath:='.'+source_info.DirSep+Copy(CurrPath,length(CurrentDir)+1,255);
  715. {$endif}
  716. end;
  717. end;
  718. { wildcard adding ? }
  719. if pos('*',currpath)>0 then
  720. begin
  721. if currpath[length(currpath)]=source_info.dirsep then
  722. hs:=Copy(currpath,1,length(CurrPath)-1)
  723. else
  724. hs:=currpath;
  725. hsd:=SplitPath(hs);
  726. findfirst(hs,directory,dir);
  727. subdirfound:=false;
  728. while doserror=0 do
  729. begin
  730. if (dir.name<>'.') and
  731. (dir.name<>'..') and
  732. ((dir.attr and directory)<>0) then
  733. begin
  734. subdirfound:=true;
  735. currpath:=hsd+dir.name+source_info.dirsep;
  736. hp:=Find(currPath);
  737. if not assigned(hp) then
  738. AddCurrPath;
  739. end;
  740. findnext(dir);
  741. if not subdirfound then
  742. WarnNonExistingPath(currpath);
  743. end;
  744. FindClose(dir);
  745. end
  746. else
  747. begin
  748. if PathExists(currpath) then
  749. addcurrpath
  750. else
  751. WarnNonExistingPath(currpath);
  752. end;
  753. until (s='');
  754. end;
  755. procedure TSearchPathList.AddList(list:TSearchPathList;addfirst:boolean);
  756. var
  757. s : string;
  758. hl : TSearchPathList;
  759. hp,hp2 : TStringListItem;
  760. begin
  761. if list.empty then
  762. exit;
  763. { create temp and reverse the list }
  764. if addfirst then
  765. begin
  766. hl:=TSearchPathList.Create;
  767. hp:=TStringListItem(list.first);
  768. while assigned(hp) do
  769. begin
  770. hl.insert(hp.Str);
  771. hp:=TStringListItem(hp.next);
  772. end;
  773. while not hl.empty do
  774. begin
  775. s:=hl.GetFirst;
  776. Remove(s);
  777. Insert(s);
  778. end;
  779. hl.Free;
  780. end
  781. else
  782. begin
  783. hp:=TStringListItem(list.first);
  784. while assigned(hp) do
  785. begin
  786. hp2:=Find(hp.Str);
  787. { Check if already in path, then we don't add it }
  788. if not assigned(hp2) then
  789. Concat(hp.Str);
  790. hp:=TStringListItem(hp.next);
  791. end;
  792. end;
  793. end;
  794. function TSearchPathList.FindFile(const f : string;var foundfile:string):boolean;
  795. Var
  796. p : TStringListItem;
  797. begin
  798. FindFile:=false;
  799. p:=TStringListItem(first);
  800. while assigned(p) do
  801. begin
  802. {
  803. Search order for case sensitive systems:
  804. 1. lowercase
  805. 2. NormalCase
  806. 3. UPPERCASE
  807. None case sensitive only lowercase
  808. }
  809. FoundFile:=p.Str+Lower(f);
  810. If FileExists(FoundFile) then
  811. begin
  812. FindFile:=true;
  813. exit;
  814. end;
  815. {$ifdef UNIX}
  816. FoundFile:=p.Str+f;
  817. If FileExists(FoundFile) then
  818. begin
  819. FindFile:=true;
  820. exit;
  821. end;
  822. FoundFile:=p.Str+Upper(f);
  823. If FileExists(FoundFile) then
  824. begin
  825. FindFile:=true;
  826. exit;
  827. end;
  828. {$endif UNIX}
  829. p:=TStringListItem(p.next);
  830. end;
  831. { Return original filename if not found }
  832. FoundFile:=f;
  833. end;
  834. Function GetFileTime ( Var F : File) : Longint;
  835. Var
  836. {$ifdef unix}
  837. Info : Stat;
  838. {$endif}
  839. L : longint;
  840. begin
  841. {$ifdef unix}
  842. FStat (F,Info);
  843. L:=Info.Mtime;
  844. {$else}
  845. GetFTime(f,l);
  846. {$endif}
  847. GetFileTime:=L;
  848. end;
  849. Function GetNamedFileTime (Const F : String) : Longint;
  850. begin
  851. GetNamedFileTime:=do_getnamedfiletime(F);
  852. end;
  853. function FindFile(const f : string;path : string;var foundfile:string):boolean;
  854. Var
  855. singlepathstring : string;
  856. i : longint;
  857. begin
  858. {$ifdef Unix}
  859. for i:=1 to length(path) do
  860. if path[i]=':' then
  861. path[i]:=';';
  862. {$endif Unix}
  863. FindFile:=false;
  864. repeat
  865. i:=pos(';',path);
  866. if i=0 then
  867. i:=256;
  868. singlepathstring:=FixPath(copy(path,1,i-1),false);
  869. delete(path,1,i);
  870. {
  871. Search order for case sensitive systems:
  872. 1. lowercase
  873. 2. NormalCase
  874. 3. UPPERCASE
  875. None case sensitive only lowercase
  876. }
  877. FoundFile:=singlepathstring+Lower(f);
  878. If FileExists(FoundFile) then
  879. begin
  880. FindFile:=true;
  881. exit;
  882. end;
  883. {$ifdef UNIX}
  884. FoundFile:=singlepathstring+f;
  885. If FileExists(FoundFile) then
  886. begin
  887. FindFile:=true;
  888. exit;
  889. end;
  890. FoundFile:=singlepathstring+Upper(f);
  891. If FileExists(FoundFile) then
  892. begin
  893. FindFile:=true;
  894. exit;
  895. end;
  896. {$endif UNIX}
  897. until path='';
  898. FoundFile:=f;
  899. end;
  900. function FindExe(const bin:string;var foundfile:string):boolean;
  901. begin
  902. {$ifdef delphi}
  903. FindExe:=FindFile(FixFileName(AddExtension(bin,source_info.exeext)),'.;'+exepath+';'+dmisc.getenv('PATH'),foundfile);
  904. {$else delphi}
  905. FindExe:=FindFile(FixFileName(AddExtension(bin,source_info.exeext)),'.;'+exepath+';'+dos.getenv('PATH'),foundfile);
  906. {$endif delphi}
  907. end;
  908. function GetShortName(const n:string):string;
  909. {$ifdef win32}
  910. var
  911. hs,hs2 : string;
  912. i : longint;
  913. {$endif}
  914. {$ifdef go32v2}
  915. var
  916. hs : string;
  917. {$endif}
  918. begin
  919. GetShortName:=n;
  920. {$ifdef win32}
  921. hs:=n+#0;
  922. i:=Windows.GetShortPathName(@hs[1],@hs2[1],high(hs2));
  923. if (i>0) and (i<=high(hs2)) then
  924. begin
  925. hs2[0]:=chr(strlen(@hs2[1]));
  926. GetShortName:=hs2;
  927. end;
  928. {$endif}
  929. {$ifdef go32v2}
  930. hs:=n;
  931. if Dos.GetShortName(hs) then
  932. GetShortName:=hs;
  933. {$endif}
  934. end;
  935. {****************************************************************************
  936. OS Dependent things
  937. ****************************************************************************}
  938. function GetEnvPChar(const envname:string):pchar;
  939. {$ifdef win32}
  940. var
  941. s : string;
  942. i,len : longint;
  943. hp,p,p2 : pchar;
  944. {$endif}
  945. {$ifdef os2}
  946. var
  947. P1, P2: PChar;
  948. {$endif}
  949. begin
  950. {$ifdef unix}
  951. GetEnvPchar:={$ifdef ver1_0}Linux{$else}Unix{$endif}.Getenv(envname);
  952. {$define GETENVOK}
  953. {$endif}
  954. {$ifdef win32}
  955. GetEnvPchar:=nil;
  956. p:=GetEnvironmentStrings;
  957. hp:=p;
  958. while hp^<>#0 do
  959. begin
  960. s:=strpas(hp);
  961. i:=pos('=',s);
  962. len:=strlen(hp);
  963. if upper(copy(s,1,i-1))=upper(envname) then
  964. begin
  965. GetMem(p2,len-length(envname));
  966. Move(hp[i],p2^,len-length(envname));
  967. GetEnvPchar:=p2;
  968. break;
  969. end;
  970. { next string entry}
  971. hp:=hp+len+1;
  972. end;
  973. FreeEnvironmentStrings(p);
  974. {$define GETENVOK}
  975. {$endif}
  976. {$ifdef os2}
  977. P1 := StrPNew (EnvName);
  978. if Assigned (P1) then
  979. begin
  980. if DosCalls.DosScanEnv (P1, P2) = 0 then
  981. GetEnvPChar := P2
  982. else
  983. GetEnvPChar := nil;
  984. StrDispose (P1);
  985. end else GetEnvPChar := nil;
  986. {$define GETENVOK}
  987. {$endif}
  988. {$ifdef GETENVOK}
  989. {$undef GETENVOK}
  990. {$else}
  991. GetEnvPchar:=StrPNew({$ifdef delphi}DMisc{$else}Dos{$endif}.Getenv(envname));
  992. {$endif}
  993. end;
  994. procedure FreeEnvPChar(p:pchar);
  995. begin
  996. {$ifndef unix}
  997. {$ifndef os2}
  998. StrDispose(p);
  999. {$endif}
  1000. {$endif}
  1001. end;
  1002. Procedure Shell(const command:string);
  1003. { This is already defined in the linux.ppu for linux, need for the *
  1004. expansion under linux }
  1005. {$ifdef unix}
  1006. begin
  1007. {$ifdef ver1_0}Linux{$else}Unix{$endif}.Shell(command);
  1008. end;
  1009. {$else}
  1010. {$ifdef amiga}
  1011. begin
  1012. exec('',command);
  1013. end;
  1014. {$else}
  1015. var
  1016. comspec : string;
  1017. begin
  1018. comspec:=getenv('COMSPEC');
  1019. Exec(comspec,' /C '+command);
  1020. end;
  1021. {$endif}
  1022. {$endif}
  1023. Function SetCompileMode(const s:string; changeInit: boolean):boolean;
  1024. var
  1025. b : boolean;
  1026. begin
  1027. b:=true;
  1028. if s='DEFAULT' then
  1029. aktmodeswitches:=initmodeswitches
  1030. else
  1031. if s='DELPHI' then
  1032. aktmodeswitches:=delphimodeswitches
  1033. else
  1034. if s='TP' then
  1035. aktmodeswitches:=tpmodeswitches
  1036. else
  1037. if s='FPC' then
  1038. aktmodeswitches:=fpcmodeswitches
  1039. else
  1040. if s='OBJFPC' then
  1041. aktmodeswitches:=objfpcmodeswitches
  1042. else
  1043. if s='GPC' then
  1044. aktmodeswitches:=gpcmodeswitches
  1045. else
  1046. b:=false;
  1047. if b and changeInit then
  1048. initmodeswitches := aktmodeswitches;
  1049. if b then
  1050. begin
  1051. { turn ansistrings on by default ? }
  1052. if (m_delphi in aktmodeswitches) then
  1053. begin
  1054. include(aktlocalswitches,cs_ansistrings);
  1055. if changeinit then
  1056. include(initlocalswitches,cs_ansistrings);
  1057. end
  1058. else
  1059. begin
  1060. exclude(aktlocalswitches,cs_ansistrings);
  1061. if changeinit then
  1062. exclude(initlocalswitches,cs_ansistrings);
  1063. end;
  1064. { enum packing }
  1065. if (m_tp7 in aktmodeswitches) then
  1066. aktpackenum:=1
  1067. else
  1068. aktpackenum:=4;
  1069. if changeinit then
  1070. initpackenum:=aktpackenum;
  1071. end;
  1072. SetCompileMode:=b;
  1073. end;
  1074. function SetAktProcCall(const s:string; changeInit:boolean):boolean;
  1075. const
  1076. DefProcCallName : array[tproccalloption] of string[12] = ('',
  1077. 'CDECL',
  1078. 'CPPDECL',
  1079. '', { compilerproc }
  1080. 'FAR16',
  1081. 'FPCCALL',
  1082. 'INLINE',
  1083. '', { internproc }
  1084. '', { palmossyscall }
  1085. 'PASCAL',
  1086. 'REGISTER',
  1087. 'SAFECALL',
  1088. 'STDCALL',
  1089. 'SYSTEM'
  1090. );
  1091. var
  1092. t : tproccalloption;
  1093. begin
  1094. SetAktProcCall:=false;
  1095. for t:=low(tproccalloption) to high(tproccalloption) do
  1096. if DefProcCallName[t]=s then
  1097. begin
  1098. AktDefProcCall:=t;
  1099. SetAktProcCall:=true;
  1100. break;
  1101. end;
  1102. if changeinit then
  1103. InitDefProcCall:=AktDefProcCall;
  1104. end;
  1105. { '('D1:'00000000-'D2:'0000-'D3:'0000-'D4:'0000-000000000000)' }
  1106. function string2guid(const s: string; var GUID: TGUID): boolean;
  1107. function ishexstr(const hs: string): boolean;
  1108. var
  1109. i: integer;
  1110. begin
  1111. ishexstr:=false;
  1112. for i:=1 to Length(hs) do begin
  1113. if not (hs[i] in ['0'..'9','A'..'F','a'..'f']) then
  1114. exit;
  1115. end;
  1116. ishexstr:=true;
  1117. end;
  1118. function hexstr2longint(const hexs: string): longint;
  1119. var
  1120. i: integer;
  1121. rl: longint;
  1122. begin
  1123. rl:=0;
  1124. for i:=1 to length(hexs) do begin
  1125. rl:=rl shl 4;
  1126. case hexs[i] of
  1127. '0'..'9' : inc(rl,ord(hexs[i])-ord('0'));
  1128. 'A'..'F' : inc(rl,ord(hexs[i])-ord('A')+10);
  1129. 'a'..'f' : inc(rl,ord(hexs[i])-ord('a')+10);
  1130. end
  1131. end;
  1132. hexstr2longint:=rl;
  1133. end;
  1134. var
  1135. i: integer;
  1136. begin
  1137. if (Length(s)=38) and (s[1]='{') and (s[38]='}') and
  1138. (s[10]='-') and (s[15]='-') and (s[20]='-') and (s[25]='-') and
  1139. ishexstr(copy(s,2,8)) and ishexstr(copy(s,11,4)) and
  1140. ishexstr(copy(s,16,4)) and ishexstr(copy(s,21,4)) and
  1141. ishexstr(copy(s,26,12)) then begin
  1142. GUID.D1:=dword(hexstr2longint(copy(s,2,8)));
  1143. GUID.D2:=hexstr2longint(copy(s,11,4));
  1144. GUID.D3:=hexstr2longint(copy(s,16,4));
  1145. for i:=0 to 1 do
  1146. GUID.D4[i]:=hexstr2longint(copy(s,21+i*2,2));
  1147. for i:=2 to 7 do
  1148. GUID.D4[i]:=hexstr2longint(copy(s,22+i*2,2));
  1149. string2guid:=true;
  1150. end
  1151. else
  1152. string2guid:=false;
  1153. end;
  1154. function guid2string(const GUID: TGUID): string;
  1155. function long2hex(l, len: longint): string;
  1156. const
  1157. hextbl: array[0..15] of char = '0123456789ABCDEF';
  1158. var
  1159. rs: string;
  1160. i: integer;
  1161. begin
  1162. rs[0]:=chr(len);
  1163. for i:=len downto 1 do begin
  1164. rs[i]:=hextbl[l and $F];
  1165. l:=l shr 4;
  1166. end;
  1167. long2hex:=rs;
  1168. end;
  1169. begin
  1170. guid2string:=
  1171. '{'+long2hex(GUID.D1,8)+
  1172. '-'+long2hex(GUID.D2,4)+
  1173. '-'+long2hex(GUID.D3,4)+
  1174. '-'+long2hex(GUID.D4[0],2)+long2hex(GUID.D4[1],2)+
  1175. '-'+long2hex(GUID.D4[2],2)+long2hex(GUID.D4[3],2)+
  1176. long2hex(GUID.D4[4],2)+long2hex(GUID.D4[5],2)+
  1177. long2hex(GUID.D4[6],2)+long2hex(GUID.D4[7],2)+
  1178. '}';
  1179. end;
  1180. procedure swap_qword(var q : qword);
  1181. begin
  1182. q:=(qword(lo(q)) shl 32) or hi(q);
  1183. end;
  1184. function UpdateAlignmentStr(s:string;var a:talignmentinfo):boolean;
  1185. var
  1186. tok : string;
  1187. vstr : string;
  1188. l : longint;
  1189. code : integer;
  1190. b : talignmentinfo;
  1191. begin
  1192. UpdateAlignmentStr:=true;
  1193. uppervar(s);
  1194. fillchar(b,sizeof(b),0);
  1195. repeat
  1196. tok:=GetToken(s,'=');
  1197. if tok='' then
  1198. break;
  1199. vstr:=GetToken(s,',');
  1200. val(vstr,l,code);
  1201. if tok='PROC' then
  1202. b.procalign:=l
  1203. else if tok='JUMP' then
  1204. b.jumpalign:=l
  1205. else if tok='LOOP' then
  1206. b.loopalign:=l
  1207. else if tok='CONSTMIN' then
  1208. b.constalignmin:=l
  1209. else if tok='CONSTMAX' then
  1210. b.constalignmax:=l
  1211. else if tok='VARMIN' then
  1212. b.varalignmin:=l
  1213. else if tok='VARMAX' then
  1214. b.varalignmax:=l
  1215. else if tok='LOCALMIN' then
  1216. b.localalignmin:=l
  1217. else if tok='LOCALMAX' then
  1218. b.localalignmax:=l
  1219. else if tok='RECORDMIN' then
  1220. b.recordalignmin:=l
  1221. else if tok='RECORDMAX' then
  1222. b.recordalignmax:=l
  1223. else if tok='PARAALIGN' then
  1224. b.paraalign:=l
  1225. else { Error }
  1226. UpdateAlignmentStr:=false;
  1227. until false;
  1228. UpdateAlignment(a,b);
  1229. end;
  1230. function var_align(siz: longint): longint;
  1231. begin
  1232. siz := size_2_align(siz);
  1233. var_align := used_align(siz,aktalignment.varalignmin,aktalignment.varalignmax);
  1234. end;
  1235. function const_align(siz: longint): longint;
  1236. begin
  1237. siz := size_2_align(siz);
  1238. const_align := used_align(siz,aktalignment.constalignmin,aktalignment.constalignmax);
  1239. end;
  1240. {****************************************************************************
  1241. Init
  1242. ****************************************************************************}
  1243. {$ifdef unix}
  1244. {$define need_path_search}
  1245. {$endif unix}
  1246. {$ifdef os2}
  1247. {$define need_path_search}
  1248. {$endif os2}
  1249. procedure get_exepath;
  1250. var
  1251. hs1 : namestr;
  1252. hs2 : extstr;
  1253. begin
  1254. {$ifdef delphi}
  1255. exepath:=dmisc.getenv('PPC_EXEC_PATH');
  1256. {$else delphi}
  1257. exepath:=dos.getenv('PPC_EXEC_PATH');
  1258. {$endif delphi}
  1259. if exepath='' then
  1260. fsplit(FixFileName(system.paramstr(0)),exepath,hs1,hs2);
  1261. {$ifdef need_path_search}
  1262. if exepath='' then
  1263. begin
  1264. if pos(source_info.exeext,hs1) <>
  1265. (length(hs1) - length(source_info.exeext)+1) then
  1266. hs1 := hs1 + source_info.exeext;
  1267. {$ifdef delphi}
  1268. findfile(hs1,dmisc.getenv('PATH'),exepath);
  1269. {$else delphi}
  1270. findfile(hs1,dos.getenv('PATH'),exepath);
  1271. {$endif delphi}
  1272. exepath:=SplitPath(exepath);
  1273. end;
  1274. {$endif need_path_search}
  1275. exepath:=FixPath(exepath,false);
  1276. end;
  1277. procedure DoneGlobals;
  1278. begin
  1279. initdefines.free;
  1280. if assigned(DLLImageBase) then
  1281. StringDispose(DLLImageBase);
  1282. RelocSection:=true;
  1283. RelocSectionSetExplicitly:=false;
  1284. UseDeffileForExport:=true;
  1285. librarysearchpath.Free;
  1286. unitsearchpath.Free;
  1287. objectsearchpath.Free;
  1288. includesearchpath.Free;
  1289. end;
  1290. procedure InitGlobals;
  1291. begin
  1292. get_exepath;
  1293. { reset globals }
  1294. do_build:=false;
  1295. do_release:=false;
  1296. do_make:=true;
  1297. compile_level:=0;
  1298. DLLsource:=false;
  1299. inlining_procedure:=false;
  1300. resolving_forward:=false;
  1301. in_args:=false;
  1302. make_ref:=false;
  1303. { Output }
  1304. OutputFile:='';
  1305. OutputExeDir:='';
  1306. OutputUnitDir:='';
  1307. { Utils directory }
  1308. utilsdirectory:='';
  1309. { Search Paths }
  1310. librarysearchpath:=TSearchPathList.Create;
  1311. unitsearchpath:=TSearchPathList.Create;
  1312. includesearchpath:=TSearchPathList.Create;
  1313. objectsearchpath:=TSearchPathList.Create;
  1314. { Def file }
  1315. usewindowapi:=false;
  1316. description:='Compiled by FPC '+version_string+' - '+target_cpu_string;
  1317. dllversion:='';
  1318. nwscreenname := '';
  1319. nwthreadname := '';
  1320. nwcopyright := '';
  1321. { Init values }
  1322. initmodeswitches:=fpcmodeswitches;
  1323. initlocalswitches:=[cs_check_io,cs_typed_const_writable];
  1324. initmoduleswitches:=[cs_extsyntax,cs_implicit_exceptions];
  1325. initsourcecodepage:='8859-1';
  1326. initglobalswitches:=[cs_check_unit_name,cs_link_static{$ifdef INTERNALLINKER},cs_link_internal,cs_link_map{$endif}];
  1327. initoutputformat:=target_asm.id;
  1328. fillchar(initalignment,sizeof(talignmentinfo),0);
  1329. {$ifdef i386}
  1330. initoptprocessor:=Class386;
  1331. initspecificoptprocessor:=Class386;
  1332. initpackenum:=4;
  1333. {$IFDEF testvarsets}
  1334. initsetalloc:=0;
  1335. {$ENDIF}
  1336. initasmmode:=asmmode_i386_att;
  1337. {$endif i386}
  1338. {$ifdef m68k}
  1339. initoptprocessor:=MC68020;
  1340. initpackenum:=4;
  1341. {$IFDEF testvarsets}
  1342. initsetalloc:=0;
  1343. {$ENDIF}
  1344. initasmmode:=asmmode_standard;
  1345. {$endif m68k}
  1346. {$ifdef powerpc}
  1347. initoptprocessor:=PPC604;
  1348. initpackenum:=4;
  1349. {$IFDEF testvarsets}
  1350. initsetalloc:=0;
  1351. {$ENDIF}
  1352. initasmmode:=asmmode_direct;
  1353. {$endif powerpc}
  1354. initinterfacetype:=it_interfacecom;
  1355. initdefproccall:=pocall_none;
  1356. initdefines:=TStringList.Create;
  1357. { memory sizes, will be overriden by parameter or default for target
  1358. in options or init_parser }
  1359. stacksize:=0;
  1360. heapsize:=0;
  1361. { compile state }
  1362. in_args:=false;
  1363. { must_be_valid:=true; obsolete PM }
  1364. not_unit_proc:=true;
  1365. apptype:=app_cui;
  1366. have_local_threadvars := false;
  1367. end;
  1368. end.
  1369. {
  1370. $Log$
  1371. Revision 1.77 2002-12-06 17:50:00 peter
  1372. * amiga fixes merged
  1373. Revision 1.76 2002/12/01 22:07:41 carl
  1374. * warning of portabilitiy problems with parasize / localsize
  1375. + some added documentation
  1376. Revision 1.75 2002/11/30 23:13:48 carl
  1377. - cs_fp_emulation is no longer automatic for m68k target
  1378. Revision 1.74 2002/11/30 11:08:46 carl
  1379. * fix bug n last commit (this bug was only detected gby 1.0.x, fixed)
  1380. Revision 1.73 2002/11/30 00:34:20 pierre
  1381. * remove double in delphimodeswitches to allow compilation with -Cr option
  1382. Revision 1.72 2002/11/29 22:31:19 carl
  1383. + unimplemented hint directive added
  1384. * hint directive parsing implemented
  1385. * warning on these directives
  1386. Revision 1.71 2002/11/20 10:11:46 mazen
  1387. + TSearchPathList.AddPath supports a local path in addition to file name
  1388. Revision 1.70 2002/11/16 14:49:12 carl
  1389. - browser information is off by default
  1390. Revision 1.69 2002/11/15 01:58:47 peter
  1391. * merged changes from 1.0.7 up to 04-11
  1392. - -V option for generating bug report tracing
  1393. - more tracing for option parsing
  1394. - errors for cdecl and high()
  1395. - win32 import stabs
  1396. - win32 records<=8 are returned in eax:edx (turned off by default)
  1397. - heaptrc update
  1398. - more info for temp management in .s file with EXTDEBUG
  1399. Revision 1.68 2002/11/09 15:38:39 carl
  1400. + added var_align/const_align routines
  1401. Revision 1.67 2002/10/16 19:01:43 peter
  1402. + $IMPLICITEXCEPTIONS switch to turn on/off generation of the
  1403. implicit exception frames for procedures with initialized variables
  1404. and for constructors. The default is on for compatibility
  1405. Revision 1.66 2002/09/05 19:28:29 peter
  1406. * removed repetitive pass counting
  1407. * display heapsize also for extdebug
  1408. Revision 1.65 2002/08/19 19:36:42 peter
  1409. * More fixes for cross unit inlining, all tnodes are now implemented
  1410. * Moved pocall_internconst to po_internconst because it is not a
  1411. calling type at all and it conflicted when inlining of these small
  1412. functions was requested
  1413. Revision 1.64 2002/08/12 15:08:39 carl
  1414. + stab register indexes for powerpc (moved from gdb to cpubase)
  1415. + tprocessor enumeration moved to cpuinfo
  1416. + linker in target_info is now a class
  1417. * many many updates for m68k (will soon start to compile)
  1418. - removed some ifdef or correct them for correct cpu
  1419. Revision 1.63 2002/08/10 14:46:29 carl
  1420. + moved target_cpu_string to cpuinfo
  1421. * renamed asmmode enum.
  1422. * assembler reader has now less ifdef's
  1423. * move from nppcmem.pas -> ncgmem.pas vec. node.
  1424. Revision 1.62 2002/07/28 20:45:22 florian
  1425. + added direct assembler reader for PowerPC
  1426. Revision 1.61 2002/07/20 17:12:42 florian
  1427. + source code page support
  1428. Revision 1.60 2002/07/01 18:46:22 peter
  1429. * internal linker
  1430. * reorganized aasm layer
  1431. Revision 1.59 2002/07/01 16:23:52 peter
  1432. * cg64 patch
  1433. * basics for currency
  1434. * asnode updates for class and interface (not finished)
  1435. Revision 1.58 2002/05/18 13:34:08 peter
  1436. * readded missing revisions
  1437. Revision 1.57 2002/05/16 19:46:36 carl
  1438. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  1439. + try to fix temp allocation (still in ifdef)
  1440. + generic constructor calls
  1441. + start of tassembler / tmodulebase class cleanup
  1442. Revision 1.55 2002/04/20 21:32:23 carl
  1443. + generic FPC_CHECKPOINTER
  1444. + first parameter offset in stack now portable
  1445. * rename some constants
  1446. + move some cpu stuff to other units
  1447. - remove unused constents
  1448. * fix stacksize for some targets
  1449. * fix generic size problems which depend now on EXTEND_SIZE constant
  1450. Revision 1.54 2002/04/07 13:24:30 carl
  1451. + moved constant from cpuinfo, these are NOT cpu specific
  1452. constant, but more related to compiler functionality.
  1453. Revision 1.53 2002/04/02 17:11:28 peter
  1454. * tlocation,treference update
  1455. * LOC_CONSTANT added for better constant handling
  1456. * secondadd splitted in multiple routines
  1457. * location_force_reg added for loading a location to a register
  1458. of a specified size
  1459. * secondassignment parses now first the right and then the left node
  1460. (this is compatible with Kylix). This saves a lot of push/pop especially
  1461. with string operations
  1462. * adapted some routines to use the new cg methods
  1463. Revision 1.52 2002/03/28 16:07:52 armin
  1464. + initialize threadvars defined local in units
  1465. Revision 1.51 2002/01/24 18:25:48 peter
  1466. * implicit result variable generation for assembler routines
  1467. * removed m_tp modeswitch, use m_tp7 or not(m_fpc) instead
  1468. }