globals.pas 47 KB

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