globals.pas 49 KB

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