globals.pas 48 KB

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