globals.pas 47 KB

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