globals.pas 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by Florian Klaempfl
  4. This unit implements some support functions and global variables
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit globals;
  19. {$i fpcdefs.inc}
  20. { Use the internal linker by default }
  21. { define INTERNALLINKER}
  22. interface
  23. uses
  24. {$ifdef win32}
  25. windows,
  26. {$endif}
  27. {$ifdef unix}
  28. {$ifdef ver1_0}
  29. linux,
  30. {$else}
  31. unix,
  32. {$endif}
  33. {$endif}
  34. {$ifdef os2}
  35. doscalls,
  36. {$endif}
  37. {$ifdef Delphi}
  38. SysUtils,
  39. dmisc,
  40. {$else}
  41. strings,
  42. dos,
  43. {$endif}
  44. cutils,cclasses,
  45. globtype,version,systems,cpuinfo;
  46. const
  47. {$ifdef Splitheap}
  48. testsplit : boolean = false;
  49. {$endif Splitheap}
  50. delphimodeswitches : tmodeswitches=
  51. [m_delphi,m_all,m_class,m_objpas,m_result,m_string_pchar,
  52. m_pointer_2_procedure,m_autoderef,m_tp_procvar,m_initfinal,m_default_ansistring,
  53. m_out,m_default_para,m_duplicate_names,m_hintdirective,m_add_pointer];
  54. fpcmodeswitches : tmodeswitches=
  55. [m_fpc,m_all,m_string_pchar,m_nested_comment,m_repeat_forward,
  56. m_cvar_support,m_initfinal,m_add_pointer,m_hintdirective];
  57. objfpcmodeswitches : tmodeswitches=
  58. [m_objfpc,m_fpc,m_all,m_class,m_objpas,m_result,m_string_pchar,m_nested_comment,
  59. m_repeat_forward,m_cvar_support,m_initfinal,m_add_pointer,m_out,m_default_para,m_hintdirective];
  60. tpmodeswitches : tmodeswitches=
  61. [m_tp7,m_all,m_tp_procvar,m_duplicate_names];
  62. gpcmodeswitches : tmodeswitches=
  63. [m_gpc,m_all];
  64. { maximum number of locals in bytes before warning is emitted }
  65. maxlocalsize = high(smallint);
  66. { maximum number of paras in bytes before warning is emitted }
  67. maxparasize = high(word);
  68. { maximum nesting of routines }
  69. maxnesting = 32;
  70. { maximum of units which are supported for a compilation }
  71. maxunits = 1024;
  72. type
  73. pfileposinfo = ^tfileposinfo;
  74. tfileposinfo = record
  75. line : longint;
  76. column : word;
  77. fileindex : word;
  78. { moduleindex : word; }
  79. end;
  80. TSearchPathList = class(TStringList)
  81. procedure AddPath(s:string;addfirst:boolean);
  82. procedure AddPath(SrcPath,s:string;addfirst:boolean);
  83. procedure AddList(list:TSearchPathList;addfirst:boolean);
  84. function FindFile(const f : string;var foundfile:string):boolean;
  85. end;
  86. tcodepagestring = string[20];
  87. { the ordinal type used when evaluating constant integer expressions }
  88. TConstExprInt = int64;
  89. { ... the same unsigned }
  90. TConstExprUInt = {$ifdef fpc}qword{$else}int64{$endif};
  91. var
  92. { specified inputfile }
  93. inputdir : dirstr;
  94. inputfile : namestr;
  95. inputextension : extstr;
  96. { specified outputfile with -o parameter }
  97. outputfile : namestr;
  98. { specified with -FE or -FU }
  99. outputexedir : dirstr;
  100. outputunitdir : dirstr;
  101. { things specified with parameters }
  102. paralinkoptions,
  103. paradynamiclinker : string;
  104. parapreprocess : boolean;
  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. {$ifdef i386}
  419. disk : byte;
  420. {$endif i386}
  421. begin
  422. {$ifdef i386}
  423. if (Length(f)=3) and (F[2]=':') and (F[3] in ['/','\']) then
  424. begin
  425. if F[1] in ['A'..'Z'] then
  426. disk:=ord(F[1])-ord('A')+1
  427. else if F[1] in ['a'..'z'] then
  428. disk:=ord(F[1])-ord('a')+1
  429. else
  430. disk:=255;
  431. if disk=255 then
  432. PathExists:=false
  433. else
  434. PathExists:=(DiskSize(disk)<>-1);
  435. exit;
  436. end;
  437. {$endif i386}
  438. if F[Length(f)] in ['/','\'] then
  439. Delete(f,length(f),1);
  440. findfirst(F,readonly+archive+hidden+directory,info);
  441. PathExists:=(doserror=0) and ((info.attr and directory)=directory);
  442. findclose(Info);
  443. end;
  444. Function RemoveFile(const f:string):boolean;
  445. var
  446. g : file;
  447. begin
  448. assign(g,f);
  449. {$I-}
  450. erase(g);
  451. {$I+}
  452. RemoveFile:=(ioresult=0);
  453. end;
  454. Function RemoveDir(d:string):boolean;
  455. begin
  456. if d[length(d)]=source_info.DirSep then
  457. Delete(d,length(d),1);
  458. {$I-}
  459. rmdir(d);
  460. {$I+}
  461. RemoveDir:=(ioresult=0);
  462. end;
  463. Function SplitPath(const s:string):string;
  464. var
  465. i : longint;
  466. begin
  467. i:=Length(s);
  468. while (i>0) and not(s[i] in ['/','\']) do
  469. dec(i);
  470. SplitPath:=Copy(s,1,i);
  471. end;
  472. Function SplitFileName(const s:string):string;
  473. var
  474. p : dirstr;
  475. n : namestr;
  476. e : extstr;
  477. begin
  478. FSplit(s,p,n,e);
  479. SplitFileName:=n+e;
  480. end;
  481. Function SplitName(const s:string):string;
  482. var
  483. i,j : longint;
  484. begin
  485. i:=Length(s);
  486. j:=Length(s);
  487. while (i>0) and not(s[i] in ['/','\']) do
  488. dec(i);
  489. while (j>0) and (s[j]<>'.') do
  490. dec(j);
  491. if j<=i then
  492. j:=255;
  493. SplitName:=Copy(s,i+1,j-(i+1));
  494. end;
  495. Function SplitExtension(Const HStr:String):String;
  496. var
  497. j : longint;
  498. begin
  499. j:=length(Hstr);
  500. while (j>0) and (Hstr[j]<>'.') do
  501. begin
  502. if hstr[j]=source_info.DirSep then
  503. j:=0
  504. else
  505. dec(j);
  506. end;
  507. if j=0 then
  508. j:=254;
  509. SplitExtension:=Copy(Hstr,j,255);
  510. end;
  511. Function AddExtension(Const HStr,ext:String):String;
  512. begin
  513. if (Ext<>'') and (SplitExtension(HStr)='') then
  514. AddExtension:=Hstr+Ext
  515. else
  516. AddExtension:=Hstr;
  517. end;
  518. Function ForceExtension(Const HStr,ext:String):String;
  519. var
  520. j : longint;
  521. begin
  522. j:=length(Hstr);
  523. while (j>0) and (Hstr[j]<>'.') do
  524. dec(j);
  525. if j=0 then
  526. j:=255;
  527. ForceExtension:=Copy(Hstr,1,j-1)+Ext;
  528. end;
  529. Function FixPath(s:string;allowdot:boolean):string;
  530. var
  531. i : longint;
  532. begin
  533. { Fix separator }
  534. for i:=1 to length(s) do
  535. if s[i] in ['/','\'] then
  536. s[i]:=source_info.DirSep;
  537. { Fix ending / }
  538. if (length(s)>0) and (s[length(s)]<>source_info.DirSep) and
  539. (s[length(s)]<>':') then
  540. s:=s+source_info.DirSep;
  541. { Remove ./ }
  542. if (not allowdot) and (s='.'+source_info.DirSep) then
  543. s:='';
  544. { return }
  545. if source_info.files_case_relevent then
  546. FixPath:=s
  547. else
  548. FixPath:=Lower(s);
  549. end;
  550. function FixFileName(const s:string):string;
  551. var
  552. i : longint;
  553. begin
  554. if source_info.files_case_relevent then
  555. begin
  556. for i:=1 to length(s) do
  557. begin
  558. case s[i] of
  559. '/','\' :
  560. FixFileName[i]:=source_info.dirsep;
  561. else
  562. FixFileName[i]:=s[i];
  563. end;
  564. end;
  565. end
  566. else
  567. begin
  568. for i:=1 to length(s) do
  569. begin
  570. case s[i] of
  571. '/','\' :
  572. FixFileName[i]:=source_info.dirsep;
  573. 'A'..'Z' :
  574. FixFileName[i]:=char(byte(s[i])+32);
  575. else
  576. FixFileName[i]:=s[i];
  577. end;
  578. end;
  579. end;
  580. FixFileName[0]:=s[0];
  581. end;
  582. Function TargetFixPath(s:string;allowdot:boolean):string;
  583. var
  584. i : longint;
  585. begin
  586. { Fix separator }
  587. for i:=1 to length(s) do
  588. if s[i] in ['/','\'] then
  589. s[i]:=target_info.DirSep;
  590. { Fix ending / }
  591. if (length(s)>0) and (s[length(s)]<>target_info.DirSep) and
  592. (s[length(s)]<>':') then
  593. s:=s+target_info.DirSep;
  594. { Remove ./ }
  595. if (not allowdot) and (s='.'+target_info.DirSep) then
  596. s:='';
  597. { return }
  598. if target_info.files_case_relevent then
  599. TargetFixPath:=s
  600. else
  601. TargetFixPath:=Lower(s);
  602. end;
  603. function TargetFixFileName(const s:string):string;
  604. var
  605. i : longint;
  606. begin
  607. if target_info.files_case_relevent then
  608. begin
  609. for i:=1 to length(s) do
  610. begin
  611. case s[i] of
  612. '/','\' :
  613. TargetFixFileName[i]:=target_info.dirsep;
  614. else
  615. TargetFixFileName[i]:=s[i];
  616. end;
  617. end;
  618. end
  619. else
  620. begin
  621. for i:=1 to length(s) do
  622. begin
  623. case s[i] of
  624. '/','\' :
  625. TargetFixFileName[i]:=target_info.dirsep;
  626. 'A'..'Z' :
  627. TargetFixFileName[i]:=char(byte(s[i])+32);
  628. else
  629. TargetFixFileName[i]:=s[i];
  630. end;
  631. end;
  632. end;
  633. TargetFixFileName[0]:=s[0];
  634. end;
  635. procedure SplitBinCmd(const s:string;var bstr,cstr:string);
  636. var
  637. i : longint;
  638. begin
  639. i:=pos(' ',s);
  640. if i>0 then
  641. begin
  642. bstr:=Copy(s,1,i-1);
  643. cstr:=Copy(s,i+1,length(s)-i);
  644. end
  645. else
  646. begin
  647. bstr:=s;
  648. cstr:='';
  649. end;
  650. end;
  651. procedure TSearchPathList.AddPath(s:string;addfirst:boolean);
  652. begin
  653. AddPath('',s,AddFirst);
  654. end;
  655. procedure TSearchPathList.AddPath(SrcPath,s:string;addfirst:boolean);
  656. var
  657. j : longint;
  658. hs,hsd,
  659. CurrentDir,
  660. CurrPath : string;
  661. subdirfound : boolean;
  662. dir : searchrec;
  663. hp : TStringListItem;
  664. procedure addcurrpath;
  665. begin
  666. if addfirst then
  667. begin
  668. Remove(currPath);
  669. Insert(currPath);
  670. end
  671. else
  672. begin
  673. { Check if already in path, then we don't add it }
  674. hp:=Find(currPath);
  675. if not assigned(hp) then
  676. Concat(currPath);
  677. end;
  678. end;
  679. begin
  680. if s='' then
  681. exit;
  682. { Support default macro's }
  683. DefaultReplacements(s);
  684. { get current dir }
  685. CurrentDir:=GetCurrentDir;
  686. repeat
  687. { get currpath }
  688. if addfirst then
  689. begin
  690. j:=length(s);
  691. while (j>0) and (s[j]<>';') do
  692. dec(j);
  693. CurrPath:=FixPath(Copy(s,j+1,length(s)-j),false);
  694. if j=0 then
  695. s:=''
  696. else
  697. System.Delete(s,j,length(s)-j+1);
  698. end
  699. else
  700. begin
  701. j:=Pos(';',s);
  702. if j=0 then
  703. j:=255;
  704. CurrPath:=SrcPath+FixPath(Copy(s,1,j-1),false);
  705. System.Delete(s,1,j);
  706. end;
  707. { fix pathname }
  708. if CurrPath='' then
  709. CurrPath:='.'+source_info.DirSep
  710. else
  711. begin
  712. CurrPath:=FixPath(FExpand(CurrPath),false);
  713. if (CurrentDir<>'') and (Copy(CurrPath,1,length(CurrentDir))=CurrentDir) then
  714. begin
  715. {$ifdef AMIGA}
  716. CurrPath:=Copy(CurrPath,length(CurrentDir)+1,255);
  717. {$else}
  718. CurrPath:='.'+source_info.DirSep+Copy(CurrPath,length(CurrentDir)+1,255);
  719. {$endif}
  720. end;
  721. end;
  722. { wildcard adding ? }
  723. if pos('*',currpath)>0 then
  724. begin
  725. if currpath[length(currpath)]=source_info.dirsep then
  726. hs:=Copy(currpath,1,length(CurrPath)-1)
  727. else
  728. hs:=currpath;
  729. hsd:=SplitPath(hs);
  730. findfirst(hs,directory,dir);
  731. subdirfound:=false;
  732. while doserror=0 do
  733. begin
  734. if (dir.name<>'.') and
  735. (dir.name<>'..') and
  736. ((dir.attr and directory)<>0) then
  737. begin
  738. subdirfound:=true;
  739. currpath:=hsd+dir.name+source_info.dirsep;
  740. hp:=Find(currPath);
  741. if not assigned(hp) then
  742. AddCurrPath;
  743. end;
  744. findnext(dir);
  745. if not subdirfound then
  746. WarnNonExistingPath(currpath);
  747. end;
  748. FindClose(dir);
  749. end
  750. else
  751. begin
  752. if PathExists(currpath) then
  753. addcurrpath
  754. else
  755. WarnNonExistingPath(currpath);
  756. end;
  757. until (s='');
  758. end;
  759. procedure TSearchPathList.AddList(list:TSearchPathList;addfirst:boolean);
  760. var
  761. s : string;
  762. hl : TSearchPathList;
  763. hp,hp2 : TStringListItem;
  764. begin
  765. if list.empty then
  766. exit;
  767. { create temp and reverse the list }
  768. if addfirst then
  769. begin
  770. hl:=TSearchPathList.Create;
  771. hp:=TStringListItem(list.first);
  772. while assigned(hp) do
  773. begin
  774. hl.insert(hp.Str);
  775. hp:=TStringListItem(hp.next);
  776. end;
  777. while not hl.empty do
  778. begin
  779. s:=hl.GetFirst;
  780. Remove(s);
  781. Insert(s);
  782. end;
  783. hl.Free;
  784. end
  785. else
  786. begin
  787. hp:=TStringListItem(list.first);
  788. while assigned(hp) do
  789. begin
  790. hp2:=Find(hp.Str);
  791. { Check if already in path, then we don't add it }
  792. if not assigned(hp2) then
  793. Concat(hp.Str);
  794. hp:=TStringListItem(hp.next);
  795. end;
  796. end;
  797. end;
  798. function TSearchPathList.FindFile(const f : string;var foundfile:string):boolean;
  799. Var
  800. p : TStringListItem;
  801. begin
  802. FindFile:=false;
  803. p:=TStringListItem(first);
  804. while assigned(p) do
  805. begin
  806. {
  807. Search order for case sensitive systems:
  808. 1. lowercase
  809. 2. NormalCase
  810. 3. UPPERCASE
  811. None case sensitive only lowercase
  812. }
  813. FoundFile:=p.Str+Lower(f);
  814. If FileExists(FoundFile) then
  815. begin
  816. FindFile:=true;
  817. exit;
  818. end;
  819. {$ifdef UNIX}
  820. FoundFile:=p.Str+f;
  821. If FileExists(FoundFile) then
  822. begin
  823. FindFile:=true;
  824. exit;
  825. end;
  826. FoundFile:=p.Str+Upper(f);
  827. If FileExists(FoundFile) then
  828. begin
  829. FindFile:=true;
  830. exit;
  831. end;
  832. {$endif UNIX}
  833. p:=TStringListItem(p.next);
  834. end;
  835. { Return original filename if not found }
  836. FoundFile:=f;
  837. end;
  838. Function GetFileTime ( Var F : File) : Longint;
  839. Var
  840. {$ifdef unix}
  841. Info : Stat;
  842. {$endif}
  843. L : longint;
  844. begin
  845. {$ifdef unix}
  846. FStat (F,Info);
  847. L:=Info.Mtime;
  848. {$else}
  849. GetFTime(f,l);
  850. {$endif}
  851. GetFileTime:=L;
  852. end;
  853. Function GetNamedFileTime (Const F : String) : Longint;
  854. begin
  855. GetNamedFileTime:=do_getnamedfiletime(F);
  856. end;
  857. function FindFile(const f : string;path : string;var foundfile:string):boolean;
  858. Var
  859. singlepathstring : string;
  860. i : longint;
  861. begin
  862. {$ifdef Unix}
  863. for i:=1 to length(path) do
  864. if path[i]=':' then
  865. path[i]:=';';
  866. {$endif Unix}
  867. FindFile:=false;
  868. repeat
  869. i:=pos(';',path);
  870. if i=0 then
  871. i:=256;
  872. singlepathstring:=FixPath(copy(path,1,i-1),false);
  873. delete(path,1,i);
  874. {
  875. Search order for case sensitive systems:
  876. 1. lowercase
  877. 2. NormalCase
  878. 3. UPPERCASE
  879. None case sensitive only lowercase
  880. }
  881. FoundFile:=singlepathstring+Lower(f);
  882. If FileExists(FoundFile) then
  883. begin
  884. FindFile:=true;
  885. exit;
  886. end;
  887. {$ifdef UNIX}
  888. FoundFile:=singlepathstring+f;
  889. If FileExists(FoundFile) then
  890. begin
  891. FindFile:=true;
  892. exit;
  893. end;
  894. FoundFile:=singlepathstring+Upper(f);
  895. If FileExists(FoundFile) then
  896. begin
  897. FindFile:=true;
  898. exit;
  899. end;
  900. {$endif UNIX}
  901. until path='';
  902. FoundFile:=f;
  903. end;
  904. function FindExe(const bin:string;var foundfile:string):boolean;
  905. begin
  906. {$ifdef delphi}
  907. FindExe:=FindFile(FixFileName(AddExtension(bin,source_info.exeext)),'.;'+exepath+';'+dmisc.getenv('PATH'),foundfile);
  908. {$else delphi}
  909. FindExe:=FindFile(FixFileName(AddExtension(bin,source_info.exeext)),'.;'+exepath+';'+dos.getenv('PATH'),foundfile);
  910. {$endif delphi}
  911. end;
  912. function GetShortName(const n:string):string;
  913. {$ifdef win32}
  914. var
  915. hs,hs2 : string;
  916. i : longint;
  917. {$endif}
  918. {$ifdef go32v2}
  919. var
  920. hs : string;
  921. {$endif}
  922. begin
  923. GetShortName:=n;
  924. {$ifdef win32}
  925. hs:=n+#0;
  926. i:=Windows.GetShortPathName(@hs[1],@hs2[1],high(hs2));
  927. if (i>0) and (i<=high(hs2)) then
  928. begin
  929. hs2[0]:=chr(strlen(@hs2[1]));
  930. GetShortName:=hs2;
  931. end;
  932. {$endif}
  933. {$ifdef go32v2}
  934. hs:=n;
  935. if Dos.GetShortName(hs) then
  936. GetShortName:=hs;
  937. {$endif}
  938. end;
  939. {****************************************************************************
  940. OS Dependent things
  941. ****************************************************************************}
  942. function GetEnvPChar(const envname:string):pchar;
  943. {$ifdef win32}
  944. var
  945. s : string;
  946. i,len : longint;
  947. hp,p,p2 : pchar;
  948. {$endif}
  949. {$ifdef os2}
  950. var
  951. P1, P2: PChar;
  952. {$endif}
  953. begin
  954. {$ifdef unix}
  955. GetEnvPchar:={$ifdef ver1_0}Linux{$else}Unix{$endif}.Getenv(envname);
  956. {$define GETENVOK}
  957. {$endif}
  958. {$ifdef win32}
  959. GetEnvPchar:=nil;
  960. p:=GetEnvironmentStrings;
  961. hp:=p;
  962. while hp^<>#0 do
  963. begin
  964. s:=strpas(hp);
  965. i:=pos('=',s);
  966. len:=strlen(hp);
  967. if upper(copy(s,1,i-1))=upper(envname) then
  968. begin
  969. GetMem(p2,len-length(envname));
  970. Move(hp[i],p2^,len-length(envname));
  971. GetEnvPchar:=p2;
  972. break;
  973. end;
  974. { next string entry}
  975. hp:=hp+len+1;
  976. end;
  977. FreeEnvironmentStrings(p);
  978. {$define GETENVOK}
  979. {$endif}
  980. {$ifdef os2}
  981. P1 := StrPNew (EnvName);
  982. if Assigned (P1) then
  983. begin
  984. if DosCalls.DosScanEnv (P1, P2) = 0 then
  985. GetEnvPChar := P2
  986. else
  987. GetEnvPChar := nil;
  988. StrDispose (P1);
  989. end else GetEnvPChar := nil;
  990. {$define GETENVOK}
  991. {$endif}
  992. {$ifdef GETENVOK}
  993. {$undef GETENVOK}
  994. {$else}
  995. GetEnvPchar:=StrPNew({$ifdef delphi}DMisc{$else}Dos{$endif}.Getenv(envname));
  996. {$endif}
  997. end;
  998. procedure FreeEnvPChar(p:pchar);
  999. begin
  1000. {$ifndef unix}
  1001. {$ifndef os2}
  1002. StrDispose(p);
  1003. {$endif}
  1004. {$endif}
  1005. end;
  1006. Procedure Shell(const command:string);
  1007. { This is already defined in the linux.ppu for linux, need for the *
  1008. expansion under linux }
  1009. {$ifdef unix}
  1010. begin
  1011. {$ifdef ver1_0}Linux{$else}Unix{$endif}.Shell(command);
  1012. end;
  1013. {$else}
  1014. {$ifdef amiga}
  1015. begin
  1016. exec('',command);
  1017. end;
  1018. {$else}
  1019. var
  1020. comspec : string;
  1021. begin
  1022. comspec:=getenv('COMSPEC');
  1023. Exec(comspec,' /C '+command);
  1024. end;
  1025. {$endif}
  1026. {$endif}
  1027. Function SetCompileMode(const s:string; changeInit: boolean):boolean;
  1028. var
  1029. b : boolean;
  1030. begin
  1031. b:=true;
  1032. if s='DEFAULT' then
  1033. aktmodeswitches:=initmodeswitches
  1034. else
  1035. if s='DELPHI' then
  1036. aktmodeswitches:=delphimodeswitches
  1037. else
  1038. if s='TP' then
  1039. aktmodeswitches:=tpmodeswitches
  1040. else
  1041. if s='FPC' then
  1042. aktmodeswitches:=fpcmodeswitches
  1043. else
  1044. if s='OBJFPC' then
  1045. aktmodeswitches:=objfpcmodeswitches
  1046. else
  1047. if s='GPC' then
  1048. aktmodeswitches:=gpcmodeswitches
  1049. else
  1050. b:=false;
  1051. if b and changeInit then
  1052. initmodeswitches := aktmodeswitches;
  1053. if b then
  1054. begin
  1055. { turn ansistrings on by default ? }
  1056. if (m_delphi in aktmodeswitches) then
  1057. begin
  1058. include(aktlocalswitches,cs_ansistrings);
  1059. if changeinit then
  1060. include(initlocalswitches,cs_ansistrings);
  1061. end
  1062. else
  1063. begin
  1064. exclude(aktlocalswitches,cs_ansistrings);
  1065. if changeinit then
  1066. exclude(initlocalswitches,cs_ansistrings);
  1067. end;
  1068. { enum packing }
  1069. if (m_tp7 in aktmodeswitches) then
  1070. aktpackenum:=1
  1071. else
  1072. aktpackenum:=4;
  1073. if changeinit then
  1074. initpackenum:=aktpackenum;
  1075. end;
  1076. SetCompileMode:=b;
  1077. end;
  1078. function SetAktProcCall(const s:string; changeInit:boolean):boolean;
  1079. const
  1080. DefProcCallName : array[tproccalloption] of string[12] = ('',
  1081. 'CDECL',
  1082. 'CPPDECL',
  1083. '', { compilerproc }
  1084. 'FAR16',
  1085. 'FPCCALL',
  1086. 'INLINE',
  1087. '', { internproc }
  1088. '', { palmossyscall }
  1089. 'PASCAL',
  1090. 'REGISTER',
  1091. 'SAFECALL',
  1092. 'STDCALL',
  1093. 'SYSTEM'
  1094. );
  1095. var
  1096. t : tproccalloption;
  1097. begin
  1098. SetAktProcCall:=false;
  1099. for t:=low(tproccalloption) to high(tproccalloption) do
  1100. if DefProcCallName[t]=s then
  1101. begin
  1102. AktDefProcCall:=t;
  1103. SetAktProcCall:=true;
  1104. break;
  1105. end;
  1106. if changeinit then
  1107. InitDefProcCall:=AktDefProcCall;
  1108. end;
  1109. { '('D1:'00000000-'D2:'0000-'D3:'0000-'D4:'0000-000000000000)' }
  1110. function string2guid(const s: string; var GUID: TGUID): boolean;
  1111. function ishexstr(const hs: string): boolean;
  1112. var
  1113. i: integer;
  1114. begin
  1115. ishexstr:=false;
  1116. for i:=1 to Length(hs) do begin
  1117. if not (hs[i] in ['0'..'9','A'..'F','a'..'f']) then
  1118. exit;
  1119. end;
  1120. ishexstr:=true;
  1121. end;
  1122. function hexstr2longint(const hexs: string): longint;
  1123. var
  1124. i: integer;
  1125. rl: longint;
  1126. begin
  1127. rl:=0;
  1128. for i:=1 to length(hexs) do begin
  1129. rl:=rl shl 4;
  1130. case hexs[i] of
  1131. '0'..'9' : inc(rl,ord(hexs[i])-ord('0'));
  1132. 'A'..'F' : inc(rl,ord(hexs[i])-ord('A')+10);
  1133. 'a'..'f' : inc(rl,ord(hexs[i])-ord('a')+10);
  1134. end
  1135. end;
  1136. hexstr2longint:=rl;
  1137. end;
  1138. var
  1139. i: integer;
  1140. begin
  1141. if (Length(s)=38) and (s[1]='{') and (s[38]='}') and
  1142. (s[10]='-') and (s[15]='-') and (s[20]='-') and (s[25]='-') and
  1143. ishexstr(copy(s,2,8)) and ishexstr(copy(s,11,4)) and
  1144. ishexstr(copy(s,16,4)) and ishexstr(copy(s,21,4)) and
  1145. ishexstr(copy(s,26,12)) then begin
  1146. GUID.D1:=dword(hexstr2longint(copy(s,2,8)));
  1147. { these values are arealdy in the correct range (4 chars = word) }
  1148. GUID.D2:=word(hexstr2longint(copy(s,11,4)));
  1149. GUID.D3:=word(hexstr2longint(copy(s,16,4)));
  1150. for i:=0 to 1 do
  1151. GUID.D4[i]:=byte(hexstr2longint(copy(s,21+i*2,2)));
  1152. for i:=2 to 7 do
  1153. GUID.D4[i]:=byte(hexstr2longint(copy(s,22+i*2,2)));
  1154. string2guid:=true;
  1155. end
  1156. else
  1157. string2guid:=false;
  1158. end;
  1159. function guid2string(const GUID: TGUID): string;
  1160. function long2hex(l, len: longint): string;
  1161. const
  1162. hextbl: array[0..15] of char = '0123456789ABCDEF';
  1163. var
  1164. rs: string;
  1165. i: integer;
  1166. begin
  1167. rs[0]:=chr(len);
  1168. for i:=len downto 1 do begin
  1169. rs[i]:=hextbl[l and $F];
  1170. l:=l shr 4;
  1171. end;
  1172. long2hex:=rs;
  1173. end;
  1174. begin
  1175. guid2string:=
  1176. '{'+long2hex(GUID.D1,8)+
  1177. '-'+long2hex(GUID.D2,4)+
  1178. '-'+long2hex(GUID.D3,4)+
  1179. '-'+long2hex(GUID.D4[0],2)+long2hex(GUID.D4[1],2)+
  1180. '-'+long2hex(GUID.D4[2],2)+long2hex(GUID.D4[3],2)+
  1181. long2hex(GUID.D4[4],2)+long2hex(GUID.D4[5],2)+
  1182. long2hex(GUID.D4[6],2)+long2hex(GUID.D4[7],2)+
  1183. '}';
  1184. end;
  1185. procedure swap_qword(var q : qword);
  1186. begin
  1187. q:=(qword(lo(q)) shl 32) or hi(q);
  1188. end;
  1189. function UpdateAlignmentStr(s:string;var a:talignmentinfo):boolean;
  1190. var
  1191. tok : string;
  1192. vstr : string;
  1193. l : longint;
  1194. code : integer;
  1195. b : talignmentinfo;
  1196. begin
  1197. UpdateAlignmentStr:=true;
  1198. uppervar(s);
  1199. fillchar(b,sizeof(b),0);
  1200. repeat
  1201. tok:=GetToken(s,'=');
  1202. if tok='' then
  1203. break;
  1204. vstr:=GetToken(s,',');
  1205. val(vstr,l,code);
  1206. if tok='PROC' then
  1207. b.procalign:=l
  1208. else if tok='JUMP' then
  1209. b.jumpalign:=l
  1210. else if tok='LOOP' then
  1211. b.loopalign:=l
  1212. else if tok='CONSTMIN' then
  1213. b.constalignmin:=l
  1214. else if tok='CONSTMAX' then
  1215. b.constalignmax:=l
  1216. else if tok='VARMIN' then
  1217. b.varalignmin:=l
  1218. else if tok='VARMAX' then
  1219. b.varalignmax:=l
  1220. else if tok='LOCALMIN' then
  1221. b.localalignmin:=l
  1222. else if tok='LOCALMAX' then
  1223. b.localalignmax:=l
  1224. else if tok='RECORDMIN' then
  1225. b.recordalignmin:=l
  1226. else if tok='RECORDMAX' then
  1227. b.recordalignmax:=l
  1228. else if tok='PARAALIGN' then
  1229. b.paraalign:=l
  1230. else { Error }
  1231. UpdateAlignmentStr:=false;
  1232. until false;
  1233. UpdateAlignment(a,b);
  1234. end;
  1235. function var_align(siz: longint): longint;
  1236. begin
  1237. siz := size_2_align(siz);
  1238. var_align := used_align(siz,aktalignment.varalignmin,aktalignment.varalignmax);
  1239. end;
  1240. function const_align(siz: longint): longint;
  1241. begin
  1242. siz := size_2_align(siz);
  1243. const_align := used_align(siz,aktalignment.constalignmin,aktalignment.constalignmax);
  1244. end;
  1245. {****************************************************************************
  1246. Init
  1247. ****************************************************************************}
  1248. {$ifdef unix}
  1249. {$define need_path_search}
  1250. {$endif unix}
  1251. {$ifdef os2}
  1252. {$define need_path_search}
  1253. {$endif os2}
  1254. procedure get_exepath;
  1255. var
  1256. hs1 : namestr;
  1257. hs2 : extstr;
  1258. begin
  1259. {$ifdef delphi}
  1260. exepath:=dmisc.getenv('PPC_EXEC_PATH');
  1261. {$else delphi}
  1262. exepath:=dos.getenv('PPC_EXEC_PATH');
  1263. {$endif delphi}
  1264. if exepath='' then
  1265. fsplit(FixFileName(system.paramstr(0)),exepath,hs1,hs2);
  1266. {$ifdef need_path_search}
  1267. if exepath='' then
  1268. begin
  1269. if pos(source_info.exeext,hs1) <>
  1270. (length(hs1) - length(source_info.exeext)+1) then
  1271. hs1 := hs1 + source_info.exeext;
  1272. {$ifdef delphi}
  1273. findfile(hs1,dmisc.getenv('PATH'),exepath);
  1274. {$else delphi}
  1275. findfile(hs1,dos.getenv('PATH'),exepath);
  1276. {$endif delphi}
  1277. exepath:=SplitPath(exepath);
  1278. end;
  1279. {$endif need_path_search}
  1280. exepath:=FixPath(exepath,false);
  1281. end;
  1282. procedure DoneGlobals;
  1283. begin
  1284. initdefines.free;
  1285. if assigned(DLLImageBase) then
  1286. StringDispose(DLLImageBase);
  1287. RelocSection:=true;
  1288. RelocSectionSetExplicitly:=false;
  1289. UseDeffileForExport:=true;
  1290. librarysearchpath.Free;
  1291. unitsearchpath.Free;
  1292. objectsearchpath.Free;
  1293. includesearchpath.Free;
  1294. end;
  1295. procedure InitGlobals;
  1296. begin
  1297. get_exepath;
  1298. { reset globals }
  1299. do_build:=false;
  1300. do_release:=false;
  1301. do_make:=true;
  1302. compile_level:=0;
  1303. DLLsource:=false;
  1304. inlining_procedure:=false;
  1305. resolving_forward:=false;
  1306. in_args:=false;
  1307. make_ref:=false;
  1308. { Output }
  1309. OutputFile:='';
  1310. OutputExeDir:='';
  1311. OutputUnitDir:='';
  1312. { Utils directory }
  1313. utilsdirectory:='';
  1314. { Search Paths }
  1315. librarysearchpath:=TSearchPathList.Create;
  1316. unitsearchpath:=TSearchPathList.Create;
  1317. includesearchpath:=TSearchPathList.Create;
  1318. objectsearchpath:=TSearchPathList.Create;
  1319. { Def file }
  1320. usewindowapi:=false;
  1321. description:='Compiled by FPC '+version_string+' - '+target_cpu_string;
  1322. dllversion:='';
  1323. nwscreenname := '';
  1324. nwthreadname := '';
  1325. nwcopyright := '';
  1326. { Init values }
  1327. initmodeswitches:=fpcmodeswitches;
  1328. initlocalswitches:=[cs_check_io,cs_typed_const_writable];
  1329. initmoduleswitches:=[cs_extsyntax,cs_implicit_exceptions];
  1330. initsourcecodepage:='8859-1';
  1331. initglobalswitches:=[cs_check_unit_name,cs_link_static{$ifdef INTERNALLINKER},cs_link_internal,cs_link_map{$endif}];
  1332. initoutputformat:=target_asm.id;
  1333. fillchar(initalignment,sizeof(talignmentinfo),0);
  1334. {$ifdef i386}
  1335. initoptprocessor:=Class386;
  1336. initspecificoptprocessor:=Class386;
  1337. initpackenum:=4;
  1338. {$IFDEF testvarsets}
  1339. initsetalloc:=0;
  1340. {$ENDIF}
  1341. initasmmode:=asmmode_i386_att;
  1342. {$endif i386}
  1343. {$ifdef m68k}
  1344. initoptprocessor:=MC68020;
  1345. initpackenum:=4;
  1346. {$IFDEF testvarsets}
  1347. initsetalloc:=0;
  1348. {$ENDIF}
  1349. initasmmode:=asmmode_standard;
  1350. {$endif m68k}
  1351. {$ifdef powerpc}
  1352. initoptprocessor:=PPC604;
  1353. initpackenum:=4;
  1354. {$IFDEF testvarsets}
  1355. initsetalloc:=0;
  1356. {$ENDIF}
  1357. initasmmode:=asmmode_direct;
  1358. {$endif powerpc}
  1359. initinterfacetype:=it_interfacecom;
  1360. initdefproccall:=pocall_none;
  1361. initdefines:=TStringList.Create;
  1362. { memory sizes, will be overriden by parameter or default for target
  1363. in options or init_parser }
  1364. stacksize:=0;
  1365. heapsize:=0;
  1366. { compile state }
  1367. in_args:=false;
  1368. { must_be_valid:=true; obsolete PM }
  1369. not_unit_proc:=true;
  1370. apptype:=app_cui;
  1371. have_local_threadvars := false;
  1372. end;
  1373. end.
  1374. {
  1375. $Log$
  1376. Revision 1.79 2002-12-25 01:26:17 peter
  1377. * delphi also has pointer archimetic
  1378. Revision 1.78 2002/12/07 14:27:07 carl
  1379. * 3% memory optimization
  1380. * changed some types
  1381. + added type checking with different size for call node and for
  1382. parameters
  1383. Revision 1.77 2002/12/06 17:50:00 peter
  1384. * amiga fixes merged
  1385. Revision 1.76 2002/12/01 22:07:41 carl
  1386. * warning of portabilitiy problems with parasize / localsize
  1387. + some added documentation
  1388. Revision 1.75 2002/11/30 23:13:48 carl
  1389. - cs_fp_emulation is no longer automatic for m68k target
  1390. Revision 1.74 2002/11/30 11:08:46 carl
  1391. * fix bug n last commit (this bug was only detected gby 1.0.x, fixed)
  1392. Revision 1.73 2002/11/30 00:34:20 pierre
  1393. * remove double in delphimodeswitches to allow compilation with -Cr option
  1394. Revision 1.72 2002/11/29 22:31:19 carl
  1395. + unimplemented hint directive added
  1396. * hint directive parsing implemented
  1397. * warning on these directives
  1398. Revision 1.71 2002/11/20 10:11:46 mazen
  1399. + TSearchPathList.AddPath supports a local path in addition to file name
  1400. Revision 1.70 2002/11/16 14:49:12 carl
  1401. - browser information is off by default
  1402. Revision 1.69 2002/11/15 01:58:47 peter
  1403. * merged changes from 1.0.7 up to 04-11
  1404. - -V option for generating bug report tracing
  1405. - more tracing for option parsing
  1406. - errors for cdecl and high()
  1407. - win32 import stabs
  1408. - win32 records<=8 are returned in eax:edx (turned off by default)
  1409. - heaptrc update
  1410. - more info for temp management in .s file with EXTDEBUG
  1411. Revision 1.68 2002/11/09 15:38:39 carl
  1412. + added var_align/const_align routines
  1413. Revision 1.67 2002/10/16 19:01:43 peter
  1414. + $IMPLICITEXCEPTIONS switch to turn on/off generation of the
  1415. implicit exception frames for procedures with initialized variables
  1416. and for constructors. The default is on for compatibility
  1417. Revision 1.66 2002/09/05 19:28:29 peter
  1418. * removed repetitive pass counting
  1419. * display heapsize also for extdebug
  1420. Revision 1.65 2002/08/19 19:36:42 peter
  1421. * More fixes for cross unit inlining, all tnodes are now implemented
  1422. * Moved pocall_internconst to po_internconst because it is not a
  1423. calling type at all and it conflicted when inlining of these small
  1424. functions was requested
  1425. Revision 1.64 2002/08/12 15:08:39 carl
  1426. + stab register indexes for powerpc (moved from gdb to cpubase)
  1427. + tprocessor enumeration moved to cpuinfo
  1428. + linker in target_info is now a class
  1429. * many many updates for m68k (will soon start to compile)
  1430. - removed some ifdef or correct them for correct cpu
  1431. Revision 1.63 2002/08/10 14:46:29 carl
  1432. + moved target_cpu_string to cpuinfo
  1433. * renamed asmmode enum.
  1434. * assembler reader has now less ifdef's
  1435. * move from nppcmem.pas -> ncgmem.pas vec. node.
  1436. Revision 1.62 2002/07/28 20:45:22 florian
  1437. + added direct assembler reader for PowerPC
  1438. Revision 1.61 2002/07/20 17:12:42 florian
  1439. + source code page support
  1440. Revision 1.60 2002/07/01 18:46:22 peter
  1441. * internal linker
  1442. * reorganized aasm layer
  1443. Revision 1.59 2002/07/01 16:23:52 peter
  1444. * cg64 patch
  1445. * basics for currency
  1446. * asnode updates for class and interface (not finished)
  1447. Revision 1.58 2002/05/18 13:34:08 peter
  1448. * readded missing revisions
  1449. Revision 1.57 2002/05/16 19:46:36 carl
  1450. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  1451. + try to fix temp allocation (still in ifdef)
  1452. + generic constructor calls
  1453. + start of tassembler / tmodulebase class cleanup
  1454. Revision 1.55 2002/04/20 21:32:23 carl
  1455. + generic FPC_CHECKPOINTER
  1456. + first parameter offset in stack now portable
  1457. * rename some constants
  1458. + move some cpu stuff to other units
  1459. - remove unused constents
  1460. * fix stacksize for some targets
  1461. * fix generic size problems which depend now on EXTEND_SIZE constant
  1462. Revision 1.54 2002/04/07 13:24:30 carl
  1463. + moved constant from cpuinfo, these are NOT cpu specific
  1464. constant, but more related to compiler functionality.
  1465. Revision 1.53 2002/04/02 17:11:28 peter
  1466. * tlocation,treference update
  1467. * LOC_CONSTANT added for better constant handling
  1468. * secondadd splitted in multiple routines
  1469. * location_force_reg added for loading a location to a register
  1470. of a specified size
  1471. * secondassignment parses now first the right and then the left node
  1472. (this is compatible with Kylix). This saves a lot of push/pop especially
  1473. with string operations
  1474. * adapted some routines to use the new cg methods
  1475. Revision 1.52 2002/03/28 16:07:52 armin
  1476. + initialize threadvars defined local in units
  1477. Revision 1.51 2002/01/24 18:25:48 peter
  1478. * implicit result variable generation for assembler routines
  1479. * removed m_tp modeswitch, use m_tp7 or not(m_fpc) instead
  1480. }