globals.pas 65 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318
  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 havelinuxrtl10}
  29. linux,
  30. {$else}
  31. Baseunix,unix,
  32. {$endif}
  33. {$endif}
  34. {$IFDEF USE_SYSUTILS}
  35. SysUtils,
  36. {$ELSE USE_SYSUTILS}
  37. strings,
  38. dos,
  39. {$ENDIF USE_SYSUTILS}
  40. cutils,cclasses,
  41. cpuinfo,
  42. globtype,version,systems;
  43. const
  44. delphimodeswitches : tmodeswitches=
  45. [m_delphi,m_all,m_class,m_objpas,m_result,m_string_pchar,
  46. m_pointer_2_procedure,m_autoderef,m_tp_procvar,m_initfinal,m_default_ansistring,
  47. m_out,m_default_para,m_duplicate_names,m_hintdirective,m_add_pointer];
  48. fpcmodeswitches : tmodeswitches=
  49. [m_fpc,m_all,m_string_pchar,m_nested_comment,m_repeat_forward,
  50. m_cvar_support,m_initfinal,m_add_pointer,m_hintdirective];
  51. objfpcmodeswitches : tmodeswitches=
  52. [m_objfpc,m_fpc,m_all,m_class,m_objpas,m_result,m_string_pchar,m_nested_comment,
  53. m_repeat_forward,m_cvar_support,m_initfinal,m_add_pointer,m_out,m_default_para,m_hintdirective];
  54. tpmodeswitches : tmodeswitches=
  55. [m_tp7,m_all,m_tp_procvar,m_duplicate_names];
  56. gpcmodeswitches : tmodeswitches=
  57. [m_gpc,m_all];
  58. macmodeswitches : tmodeswitches=
  59. [m_mac,m_all,m_result,m_repeat_forward,m_cvar_support];
  60. { maximum number of locals in bytes before warning is emitted }
  61. maxlocalsize = high(smallint);
  62. { maximum number of paras in bytes before warning is emitted }
  63. maxparasize = high(word);
  64. { maximum nesting of routines }
  65. maxnesting = 32;
  66. treelogfilename = 'tree.log';
  67. {$if defined(CPUARM) and defined(FPUFPA)}
  68. MathQNaN : tdoublearray = (0,0,252,255,0,0,0,0);
  69. MathInf : tdoublearray = (0,0,240,127,0,0,0,0);
  70. MathNegInf : tdoublearray = (0,0,240,255,0,0,0,0);
  71. MathPi : tdoublearray = (251,33,9,64,24,45,68,84);
  72. {$else}
  73. MathQNaN : tdoublearray = (0,0,0,0,0,0,252,255);
  74. MathInf : tdoublearray = (0,0,0,0,0,0,240,127);
  75. MathNegInf : tdoublearray = (0,0,0,0,0,0,240,255);
  76. MathPi : tdoublearray = (24,45,68,84,251,33,9,64);
  77. MathPiExtended : textendedarray = (53,194,104,33,162,218,15,201,0,64);
  78. {$endif}
  79. type
  80. TFPUException = (exInvalidOp, exDenormalized, exZeroDivide,
  81. exOverflow, exUnderflow, exPrecision);
  82. TFPUExceptionMask = set of TFPUException;
  83. pfileposinfo = ^tfileposinfo;
  84. tfileposinfo = record
  85. line : longint;
  86. column : word;
  87. fileindex : word;
  88. { moduleindex : word; }
  89. end;
  90. TSearchPathList = class(TStringList)
  91. procedure AddPath(s:string;addfirst:boolean);overload;
  92. procedure AddPath(SrcPath,s:string;addfirst:boolean);overload;
  93. procedure AddList(list:TSearchPathList;addfirst:boolean);
  94. function FindFile(const f : string;var foundfile:string):boolean;
  95. end;
  96. tcodepagestring = string[20];
  97. var
  98. { specified inputfile }
  99. inputdir : dirstr;
  100. inputfile : namestr;
  101. inputextension : extstr;
  102. { specified outputfile with -o parameter }
  103. outputfile : namestr;
  104. outputprefix : pstring;
  105. outputsuffix : pstring;
  106. outputextension : namestr;
  107. { specified with -FE or -FU }
  108. outputexedir : dirstr;
  109. outputunitdir : dirstr;
  110. { things specified with parameters }
  111. paralinkoptions,
  112. paradynamiclinker : string;
  113. paraprintnodetree : byte;
  114. parapreprocess : boolean;
  115. printnodefile : text;
  116. { typical cross compiling params}
  117. { directory where the utils can be found (options -FD) }
  118. utilsdirectory : dirstr;
  119. { targetname specific prefix used by these utils (options -XP<path>) }
  120. utilsprefix : dirstr;
  121. cshared : boolean; { pass --shared to ld to link C libs shared}
  122. Dontlinkstdlibpath: Boolean; { Don't add std paths to linkpath}
  123. rlinkpath : dirstr; { rpath-link linkdir override}
  124. { some flags for global compiler switches }
  125. do_build,
  126. do_release,
  127. do_make : boolean;
  128. { path for searching units, different paths can be seperated by ; }
  129. exepath : dirstr; { Path to ppc }
  130. librarysearchpath,
  131. unitsearchpath,
  132. objectsearchpath,
  133. includesearchpath : TSearchPathList;
  134. { linking }
  135. usewindowapi : boolean;
  136. description : string;
  137. DescriptionSetExplicity : boolean;
  138. dllversion : string;
  139. dllmajor,
  140. dllminor,
  141. dllrevision : word; { revision only for netware }
  142. UseDeffileForExports : boolean;
  143. UseDeffileForExportsSetExplicitly : boolean;
  144. RelocSection : boolean;
  145. RelocSectionSetExplicitly : boolean;
  146. LinkTypeSetExplicitly : boolean;
  147. akttokenpos, { position of the last token }
  148. aktfilepos : tfileposinfo; { current position }
  149. nwscreenname : string;
  150. nwthreadname : string;
  151. nwcopyright : string;
  152. codegenerror : boolean; { true if there is an error reported }
  153. block_type : tblock_type; { type of currently parsed block }
  154. parsing_para_level : integer; { parameter level, used to convert
  155. proc calls to proc loads in firstcalln }
  156. compile_level : word;
  157. make_ref : boolean;
  158. resolving_forward : boolean; { used to add forward reference as second ref }
  159. inlining_procedure : boolean; { are we inlining a procedure }
  160. exceptblockcounter : integer; { each except block gets a unique number check gotos }
  161. aktexceptblock : integer; { the exceptblock number of the current block (0 if none) }
  162. { commandline values }
  163. initglobalswitches : tglobalswitches;
  164. initmoduleswitches : tmoduleswitches;
  165. initlocalswitches : tlocalswitches;
  166. initmodeswitches : tmodeswitches;
  167. {$IFDEF testvarsets}
  168. Initsetalloc, {0=fixed, 1 =var}
  169. {$ENDIF}
  170. initpackenum : shortint;
  171. {$ifdef ansistring_bits}
  172. initansistring_bits: Tstringbits;
  173. {$endif}
  174. initalignment : talignmentinfo;
  175. initoptprocessor,
  176. initspecificoptprocessor : tprocessors;
  177. initfputype : tfputype;
  178. initasmmode : tasmmode;
  179. initinterfacetype : tinterfacetypes;
  180. initoutputformat : tasm;
  181. initdefproccall : tproccalloption;
  182. initsourcecodepage : tcodepagestring;
  183. { current state values }
  184. aktglobalswitches : tglobalswitches;
  185. aktmoduleswitches : tmoduleswitches;
  186. aktlocalswitches : tlocalswitches;
  187. nextaktlocalswitches : tlocalswitches;
  188. localswitcheschanged : boolean;
  189. aktmodeswitches : tmodeswitches;
  190. {$IFDEF testvarsets}
  191. aktsetalloc,
  192. {$ENDIF}
  193. aktpackrecords,
  194. aktpackenum : longint;
  195. {$ifdef ansistring_bits}
  196. aktansistring_bits : Tstringbits;
  197. {$endif}
  198. aktmaxfpuregisters : longint;
  199. aktalignment : talignmentinfo;
  200. aktoptprocessor,
  201. aktspecificoptprocessor : tprocessors;
  202. aktfputype : tfputype;
  203. aktasmmode : tasmmode;
  204. aktinterfacetype : tinterfacetypes;
  205. aktoutputformat : tasm;
  206. aktdefproccall : tproccalloption;
  207. aktsourcecodepage : tcodepagestring;
  208. { Memory sizes }
  209. heapsize,
  210. stacksize,
  211. jmp_buf_size : longint;
  212. {$Ifdef EXTDEBUG}
  213. { parameter switches }
  214. debugstop : boolean;
  215. {$EndIf EXTDEBUG}
  216. { windows / OS/2 application type }
  217. apptype : tapptype;
  218. const
  219. DLLsource : boolean = false;
  220. DLLImageBase : pstring = nil;
  221. { used to set all registers used for each global function
  222. this should dramatically decrease the number of
  223. recompilations needed PM }
  224. simplify_ppu : boolean = true;
  225. { should we allow non static members ? }
  226. allow_only_static : boolean = false;
  227. Inside_asm_statement : boolean = false;
  228. global_unit_count : word = 0;
  229. { for error info in pp.pas }
  230. parser_current_file : string = '';
  231. {$ifdef m68k}
  232. { PalmOS resources }
  233. palmos_applicationname : string = 'FPC Application';
  234. palmos_applicationid : string[4] = 'FPCA';
  235. {$endif m68k}
  236. {$ifdef powerpc}
  237. { default calling convention used on MorphOS }
  238. syscall_convention : string = 'LEGACY';
  239. {$endif powerpc}
  240. procedure abstract;
  241. function bstoslash(const s : string) : string;
  242. function getdatestr:string;
  243. function gettimestr:string;
  244. function filetimestring( t : longint) : string;
  245. procedure DefaultReplacements(var s:string);
  246. {Gives the absolute path to the current directory}
  247. function GetCurrentDir:string;
  248. {Gives the relative path to the current directory,
  249. with a trailing dir separator. E. g. on unix ./ }
  250. function CurDirRelPath(systeminfo: tsysteminfo): string;
  251. function path_absolute(const s : string) : boolean;
  252. Function PathExists ( F : String) : Boolean;
  253. Function FileExists ( Const F : String) : Boolean;
  254. function FileExistsNonCase(const path,fn:string;var foundfile:string):boolean;
  255. Function RemoveFile(const f:string):boolean;
  256. Function RemoveDir(d:string):boolean;
  257. Function GetFileTime ( Var F : File) : Longint;
  258. Function GetNamedFileTime ( Const F : String) : Longint;
  259. {Extracts the path without its filename, from a path.}
  260. Function SplitPath(const s:string):string;
  261. Function SplitFileName(const s:string):string;
  262. Function SplitName(const s:string):string;
  263. Function SplitExtension(Const HStr:String):String;
  264. Function AddExtension(Const HStr,ext:String):String;
  265. Function ForceExtension(Const HStr,ext:String):String;
  266. Function FixPath(s:string;allowdot:boolean):string;
  267. function FixFileName(const s:string):string;
  268. function TargetFixPath(s:string;allowdot:boolean):string;
  269. function TargetFixFileName(const s:string):string;
  270. procedure SplitBinCmd(const s:string;var bstr: String;var cstr:TCmdStr);
  271. function FindFile(const f : string;path : string;var foundfile:string):boolean;
  272. function FindFilePchar(const f : string;path : pchar;var foundfile:string):boolean;
  273. function FindExe(const bin:string;var foundfile:string):boolean;
  274. function GetShortName(const n:string):string;
  275. function cleanpath(const s:string):String;
  276. function Shell(const command:string): longint;
  277. function GetEnvPChar(const envname:string):pchar;
  278. procedure FreeEnvPChar(p:pchar);
  279. procedure SetFPUExceptionMask(const Mask: TFPUExceptionMask);
  280. function is_number_float(d : double) : boolean;
  281. Function SetCompileMode(const s:string; changeInit: boolean):boolean;
  282. function SetAktProcCall(const s:string; changeInit: boolean):boolean;
  283. function SetProcessor(const s:string; changeInit: boolean):boolean;
  284. function SetFpuType(const s:string; changeInit: boolean):boolean;
  285. procedure InitGlobals;
  286. procedure DoneGlobals;
  287. function string2guid(const s: string; var GUID: TGUID): boolean;
  288. function guid2string(const GUID: TGUID): string;
  289. function UpdateAlignmentStr(s:string;var a:talignmentinfo):boolean;
  290. {# Routine to get the required alignment for size of data, which will
  291. be placed in bss segment, according to the current alignment requirements }
  292. function var_align(siz: longint): longint;
  293. {# Routine to get the required alignment for size of data, which will
  294. be placed in data/const segment, according to the current alignment requirements }
  295. function const_align(siz: longint): longint;
  296. implementation
  297. uses
  298. {$ifdef macos}
  299. macutils,
  300. {$endif}
  301. comphook;
  302. procedure abstract;
  303. begin
  304. do_internalerror(255);
  305. end;
  306. procedure WarnNonExistingPath(const path : string);
  307. begin
  308. if assigned(do_comment) then
  309. do_comment(V_Tried,'Path "'+path+'" not found');
  310. end;
  311. function bstoslash(const s : string) : string;
  312. {
  313. return string s with all \ changed into /
  314. }
  315. var
  316. i : longint;
  317. begin
  318. for i:=1to length(s) do
  319. if s[i]='\' then
  320. bstoslash[i]:='/'
  321. else
  322. bstoslash[i]:=s[i];
  323. bstoslash[0]:=s[0];
  324. end;
  325. {****************************************************************************
  326. Time Handling
  327. ****************************************************************************}
  328. Function L0(l:longint):string;
  329. {
  330. return the string of value l, if l<10 then insert a zero, so
  331. the string is always at least 2 chars '01','02',etc
  332. }
  333. var
  334. s : string;
  335. begin
  336. Str(l,s);
  337. if l<10 then
  338. s:='0'+s;
  339. L0:=s;
  340. end;
  341. function gettimestr:string;
  342. {
  343. get the current time in a string HH:MM:SS
  344. }
  345. var
  346. hour,min,sec,hsec : word;
  347. begin
  348. {$IFDEF USE_SYSUTILS}
  349. DecodeTime(Time,hour,min,sec,hsec);
  350. {$ELSE USE_SYSUTILS}
  351. dos.gettime(hour,min,sec,hsec);
  352. {$ENDIF USE_SYSUTILS}
  353. gettimestr:=L0(Hour)+':'+L0(min)+':'+L0(sec);
  354. end;
  355. function getdatestr:string;
  356. {
  357. get the current date in a string YY/MM/DD
  358. }
  359. var
  360. {$IFDEF USE_SYSUTILS}
  361. Year,Month,Day: Word;
  362. {$ELSE USE_SYSUTILS}
  363. Year,Month,Day,Wday : Word;
  364. {$ENDIF USE_SYSUTILS}
  365. begin
  366. {$IFDEF USE_SYSUTILS}
  367. DecodeDate(Date,year,month,day);
  368. {$ELSE USE_SYSUTILS}
  369. dos.getdate(year,month,day,wday);
  370. {$ENDIF USE_SYSUTILS}
  371. getdatestr:=L0(Year)+'/'+L0(Month)+'/'+L0(Day);
  372. end;
  373. function filetimestring( t : longint) : string;
  374. {
  375. convert dos datetime t to a string YY/MM/DD HH:MM:SS
  376. }
  377. var
  378. {$IFDEF USE_SYSUTILS}
  379. DT : TDateTime;
  380. hsec : word;
  381. {$ELSE USE_SYSUTILS}
  382. DT : DateTime;
  383. {$ENDIF USE_SYSUTILS}
  384. Year,Month,Day: Word;
  385. hour,min,sec : word;
  386. begin
  387. if t=-1 then
  388. begin
  389. Result := 'Not Found';
  390. exit;
  391. end;
  392. {$IFDEF USE_SYSUTILS}
  393. DT := FileDateToDateTime(t);
  394. DecodeTime(DT,hour,min,sec,hsec);
  395. DecodeDate(DT,year,month,day);
  396. {$ELSE USE_SYSUTILS}
  397. unpacktime(t,DT);
  398. year := DT.year;
  399. month := DT.month;
  400. day := DT.day;
  401. hour := DT.hour;
  402. min := DT.min;
  403. sec := DT.sec;
  404. {$ENDIF USE_SYSUTILS}
  405. Result := L0(Year)+'/'+L0(Month)+'/'+L0(Day)+' '+L0(Hour)+':'+L0(min)+':'+L0(sec);
  406. end;
  407. {****************************************************************************
  408. Default Macro Handling
  409. ****************************************************************************}
  410. procedure DefaultReplacements(var s:string);
  411. begin
  412. { Replace some macros }
  413. Replace(s,'$FPCVERSION',version_string);
  414. Replace(s,'$FPCFULLVERSION',full_version_string);
  415. Replace(s,'$FPCDATE',date_string);
  416. Replace(s,'$FPCCPU',target_cpu_string);
  417. Replace(s,'$FPCOS',target_os_string);
  418. if tf_use_8_3 in Source_Info.Flags then
  419. Replace(s,'$FPCTARGET',target_os_string)
  420. else
  421. Replace(s,'$FPCTARGET',target_full_string);
  422. end;
  423. {****************************************************************************
  424. File Handling
  425. ****************************************************************************}
  426. var
  427. CachedCurrentDir : string;
  428. {Gives the absolute path to the current directory}
  429. function GetCurrentDir:string;
  430. begin
  431. if CachedCurrentDir='' then
  432. begin
  433. GetDir(0,CachedCurrentDir);
  434. CachedCurrentDir:=FixPath(CachedCurrentDir,false);
  435. end;
  436. result:=CachedCurrentDir;
  437. end;
  438. {Gives the relative path to the current directory,
  439. with a trailing dir separator. E. g. on unix ./ }
  440. function CurDirRelPath(systeminfo: tsysteminfo): string;
  441. begin
  442. if systeminfo.system <> system_powerpc_macos then
  443. CurDirRelPath:= '.'+systeminfo.DirSep
  444. else
  445. CurDirRelPath:= ':'
  446. end;
  447. function path_absolute(const s : string) : boolean;
  448. {
  449. is path s an absolute path?
  450. }
  451. begin
  452. path_absolute:=false;
  453. {$ifdef unix}
  454. if (length(s)>0) and (s[1]='/') then
  455. path_absolute:=true;
  456. {$else unix}
  457. {$ifdef amiga}
  458. if ((length(s)>0) and ((s[1]='\') or (s[1]='/'))) or (Pos(':',s) = length(s)) then
  459. path_absolute:=true;
  460. {$else}
  461. {$ifdef macos}
  462. if IsMacFullPath(s) then
  463. path_absolute:=true;
  464. {$else}
  465. if ((length(s)>0) and ((s[1]='\') or (s[1]='/'))) or
  466. ((length(s)>2) and (s[2]=':') and ((s[3]='\') or (s[3]='/'))) then
  467. path_absolute:=true;
  468. {$endif macos}
  469. {$endif amiga}
  470. {$endif unix}
  471. end;
  472. {$ifndef FPC}
  473. Procedure FindClose(var Info : SearchRec);
  474. Begin
  475. End;
  476. {$endif not FPC}
  477. Function FileExists ( Const F : String) : Boolean;
  478. {$IFDEF USE_SYSUTILS}
  479. {$ELSE USE_SYSUTILS}
  480. var
  481. Info : SearchRec;
  482. {$ENDIF USE_SYSUTILS}
  483. begin
  484. {$IFDEF USE_SYSUTILS}
  485. Result:=SysUtils.FileExists(f);
  486. {$ELSE USE_SYSUTILS}
  487. findfirst(F,readonly+archive+hidden,info);
  488. result:=(doserror=0);
  489. findclose(Info);
  490. {$ENDIF USE_SYSUTILS}
  491. if assigned(do_comment) then
  492. begin
  493. if Result then
  494. do_comment(V_Tried,'Searching file '+F+'... found')
  495. else
  496. do_comment(V_Tried,'Searching file '+F+'... not found');
  497. end;
  498. end;
  499. function FileExistsNonCase(const path,fn:string;var foundfile:string):boolean;
  500. var
  501. fn2 : string;
  502. begin
  503. result:=false;
  504. if source_info.files_case_relevent then
  505. begin
  506. {
  507. Search order for case sensitive systems:
  508. 1. NormalCase
  509. 2. lowercase
  510. 3. UPPERCASE
  511. }
  512. FoundFile:=path+fn;
  513. If FileExists(FoundFile) then
  514. begin
  515. result:=true;
  516. exit;
  517. end;
  518. fn2:=Lower(fn);
  519. if fn2<>fn then
  520. begin
  521. FoundFile:=path+fn2;
  522. If FileExists(FoundFile) then
  523. begin
  524. result:=true;
  525. exit;
  526. end;
  527. end;
  528. fn2:=Upper(fn);
  529. if fn2<>fn then
  530. begin
  531. FoundFile:=path+fn2;
  532. If FileExists(FoundFile) then
  533. begin
  534. result:=true;
  535. exit;
  536. end;
  537. end;
  538. end
  539. else
  540. begin
  541. { None case sensitive only lowercase }
  542. FoundFile:=path+Lower(fn);
  543. If FileExists(FoundFile) then
  544. begin
  545. result:=true;
  546. exit;
  547. end;
  548. end;
  549. { Set foundfile to something usefull }
  550. FoundFile:=fn;
  551. end;
  552. Function PathExists ( F : String) : Boolean;
  553. Var
  554. {$IFDEF USE_SYSUTILS}
  555. {$ELSE USE_SYSUTILS}
  556. FF : file;
  557. {$ENDIF USE_SYSUTILS}
  558. A: word;
  559. I: longint;
  560. begin
  561. if F = '' then
  562. begin
  563. PathExists := true;
  564. exit;
  565. end;
  566. F := FExpand (F);
  567. I := Pos (DriveSeparator, F);
  568. if (F [Length (F)] = DirectorySeparator)
  569. and (((I = 0) and (Length (F) > 1)) or (I <> Length (F) - 1))
  570. then
  571. Delete (F, Length (F), 1);
  572. {$IFDEF USE_SYSUTILS}
  573. PathExists := FileGetAttr(F) and faDirectory = faDirectory;
  574. {$ELSE USE_SYSUTILS}
  575. Assign (FF, FExpand (F));
  576. GetFAttr (FF, A);
  577. PathExists := (DosError = 0) and (A and Directory = Directory);
  578. {$ENDIF USE_SYSUTILS}
  579. end;
  580. Function RemoveFile(const f:string):boolean;
  581. var
  582. g : file;
  583. begin
  584. assign(g,f);
  585. {$I-}
  586. erase(g);
  587. {$I+}
  588. RemoveFile:=(ioresult=0);
  589. end;
  590. Function RemoveDir(d:string):boolean;
  591. begin
  592. if d[length(d)]=source_info.DirSep then
  593. Delete(d,length(d),1);
  594. {$I-}
  595. rmdir(d);
  596. {$I+}
  597. RemoveDir:=(ioresult=0);
  598. end;
  599. Function SplitPath(const s:string):string;
  600. var
  601. i : longint;
  602. begin
  603. i:=Length(s);
  604. {$ifdef macos}
  605. while (i>0) and not(s[i] in [':']) do
  606. dec(i);
  607. {$else macos}
  608. while (i>0) and not(s[i] in ['/','\']) do
  609. dec(i);
  610. {$endif macos}
  611. SplitPath:=Copy(s,1,i);
  612. end;
  613. Function SplitFileName(const s:string):string;
  614. {$IFDEF USE_SYSUTILS}
  615. {$ELSE USE_SYSUTILS}
  616. var
  617. p : dirstr;
  618. n : namestr;
  619. e : extstr;
  620. {$ENDIF USE_SYSUTILS}
  621. begin
  622. {$IFDEF USE_SYSUTILS}
  623. SplitFileName:=ExtractFileName(s);
  624. {$ELSE USE_SYSUTILS}
  625. FSplit(s,p,n,e);
  626. SplitFileName:=n+e;
  627. {$ENDIF USE_SYSUTILS}
  628. end;
  629. Function SplitName(const s:string):string;
  630. var
  631. i,j : longint;
  632. begin
  633. i:=Length(s);
  634. j:=Length(s);
  635. while (i>0) and not(s[i] in ['/','\']) do
  636. dec(i);
  637. while (j>0) and (s[j]<>'.') do
  638. dec(j);
  639. if j<=i then
  640. j:=255;
  641. SplitName:=Copy(s,i+1,j-(i+1));
  642. end;
  643. Function SplitExtension(Const HStr:String):String;
  644. var
  645. j : longint;
  646. begin
  647. j:=length(Hstr);
  648. while (j>0) and (Hstr[j]<>'.') do
  649. begin
  650. if hstr[j]=source_info.DirSep then
  651. j:=0
  652. else
  653. dec(j);
  654. end;
  655. if j=0 then
  656. j:=254;
  657. SplitExtension:=Copy(Hstr,j,255);
  658. end;
  659. Function AddExtension(Const HStr,ext:String):String;
  660. begin
  661. if (Ext<>'') and (SplitExtension(HStr)='') then
  662. AddExtension:=Hstr+Ext
  663. else
  664. AddExtension:=Hstr;
  665. end;
  666. Function ForceExtension(Const HStr,ext:String):String;
  667. var
  668. j : longint;
  669. begin
  670. j:=length(Hstr);
  671. while (j>0) and (Hstr[j]<>'.') do
  672. dec(j);
  673. if j=0 then
  674. j:=255;
  675. ForceExtension:=Copy(Hstr,1,j-1)+Ext;
  676. end;
  677. Function FixPath(s:string;allowdot:boolean):string;
  678. var
  679. i : longint;
  680. begin
  681. { Fix separator }
  682. for i:=1 to length(s) do
  683. if s[i] in ['/','\'] then
  684. s[i]:=source_info.DirSep;
  685. { Fix ending / }
  686. if (length(s)>0) and (s[length(s)]<>source_info.DirSep) and
  687. (s[length(s)]<>':') then
  688. s:=s+source_info.DirSep;
  689. { Remove ./ }
  690. if (not allowdot) and (s='.'+source_info.DirSep) then
  691. s:='';
  692. { return }
  693. if source_info.files_case_relevent then
  694. FixPath:=s
  695. else
  696. FixPath:=Lower(s);
  697. end;
  698. {Actually the version in macutils.pp could be used,
  699. but that would not work for crosscompiling, so this is a slightly modified
  700. version of it.}
  701. function TranslatePathToMac (const path: string; mpw: Boolean): string;
  702. function GetVolumeIdentifier: string;
  703. begin
  704. GetVolumeIdentifier := '{Boot}'
  705. (*
  706. if mpw then
  707. GetVolumeIdentifier := '{Boot}'
  708. else
  709. GetVolumeIdentifier := macosBootVolumeName;
  710. *)
  711. end;
  712. var
  713. slashPos, oldpos, newpos, oldlen, maxpos: Longint;
  714. begin
  715. oldpos := 1;
  716. slashPos := Pos('/', path);
  717. if (slashPos <> 0) then {its a unix path}
  718. begin
  719. if slashPos = 1 then
  720. begin {its a full path}
  721. oldpos := 2;
  722. TranslatePathToMac := GetVolumeIdentifier;
  723. end
  724. else {its a partial path}
  725. TranslatePathToMac := ':';
  726. end
  727. else
  728. begin
  729. slashPos := Pos('\', path);
  730. if (slashPos <> 0) then {its a dos path}
  731. begin
  732. if slashPos = 1 then
  733. begin {its a full path, without drive letter}
  734. oldpos := 2;
  735. TranslatePathToMac := GetVolumeIdentifier;
  736. end
  737. else if (Length(path) >= 2) and (path[2] = ':') then {its a full path, with drive letter}
  738. begin
  739. oldpos := 4;
  740. TranslatePathToMac := GetVolumeIdentifier;
  741. end
  742. else {its a partial path}
  743. TranslatePathToMac := ':';
  744. end;
  745. end;
  746. if (slashPos <> 0) then {its a unix or dos path}
  747. begin
  748. {Translate "/../" to "::" , "/./" to ":" and "/" to ":" }
  749. newpos := Length(TranslatePathToMac);
  750. oldlen := Length(path);
  751. SetLength(TranslatePathToMac, newpos + oldlen); {It will be no longer than what is already}
  752. {prepended plus length of path.}
  753. maxpos := Length(TranslatePathToMac); {Get real maxpos, can be short if String is ShortString}
  754. {There is never a slash in the beginning, because either it was an absolute path, and then the}
  755. {drive and slash was removed, or it was a relative path without a preceding slash.}
  756. while oldpos <= oldlen do
  757. begin
  758. {Check if special dirs, ./ or ../ }
  759. if path[oldPos] = '.' then
  760. if (oldpos + 1 <= oldlen) and (path[oldPos + 1] = '.') then
  761. begin
  762. if (oldpos + 2 > oldlen) or (path[oldPos + 2] in ['/', '\']) then
  763. begin
  764. {It is "../" or ".." translates to ":" }
  765. if newPos = maxPos then
  766. begin {Shouldn't actually happen, but..}
  767. Exit('');
  768. end;
  769. newPos := newPos + 1;
  770. TranslatePathToMac[newPos] := ':';
  771. oldPos := oldPos + 3;
  772. continue; {Start over again}
  773. end;
  774. end
  775. else if (oldpos + 1 > oldlen) or (path[oldPos + 1] in ['/', '\']) then
  776. begin
  777. {It is "./" or "." ignor it }
  778. oldPos := oldPos + 2;
  779. continue; {Start over again}
  780. end;
  781. {Collect file or dir name}
  782. while (oldpos <= oldlen) and not (path[oldPos] in ['/', '\']) do
  783. begin
  784. if newPos = maxPos then
  785. begin {Shouldn't actually happen, but..}
  786. Exit('');
  787. end;
  788. newPos := newPos + 1;
  789. TranslatePathToMac[newPos] := path[oldPos];
  790. oldPos := oldPos + 1;
  791. end;
  792. {When we come here there is either a slash or we are at the end.}
  793. if (oldpos <= oldlen) then
  794. begin
  795. if newPos = maxPos then
  796. begin {Shouldn't actually happen, but..}
  797. Exit('');
  798. end;
  799. newPos := newPos + 1;
  800. TranslatePathToMac[newPos] := ':';
  801. oldPos := oldPos + 1;
  802. end;
  803. end;
  804. SetLength(TranslatePathToMac, newpos);
  805. end
  806. else if (path = '.') then
  807. TranslatePathToMac := ':'
  808. else if (path = '..') then
  809. TranslatePathToMac := '::'
  810. else
  811. TranslatePathToMac := path; {its a mac path}
  812. end;
  813. function FixFileName(const s:string):string;
  814. var
  815. i : longint;
  816. begin
  817. if source_info.system = system_powerpc_MACOS then
  818. FixFileName:= TranslatePathToMac(s, true)
  819. else if source_info.files_case_relevent then
  820. begin
  821. for i:=1 to length(s) do
  822. begin
  823. case s[i] of
  824. '/','\' :
  825. FixFileName[i]:=source_info.dirsep;
  826. else
  827. FixFileName[i]:=s[i];
  828. end;
  829. end;
  830. FixFileName[0]:=s[0];
  831. end
  832. else
  833. begin
  834. for i:=1 to length(s) do
  835. begin
  836. case s[i] of
  837. '/','\' :
  838. FixFileName[i]:=source_info.dirsep;
  839. 'A'..'Z' :
  840. FixFileName[i]:=char(byte(s[i])+32);
  841. else
  842. FixFileName[i]:=s[i];
  843. end;
  844. end;
  845. FixFileName[0]:=s[0];
  846. end;
  847. end;
  848. Function TargetFixPath(s:string;allowdot:boolean):string;
  849. var
  850. i : longint;
  851. begin
  852. { Fix separator }
  853. for i:=1 to length(s) do
  854. if s[i] in ['/','\'] then
  855. s[i]:=target_info.DirSep;
  856. { Fix ending / }
  857. if (length(s)>0) and (s[length(s)]<>target_info.DirSep) and
  858. (s[length(s)]<>':') then
  859. s:=s+target_info.DirSep;
  860. { Remove ./ }
  861. if (not allowdot) and (s='.'+target_info.DirSep) then
  862. s:='';
  863. { return }
  864. if target_info.files_case_relevent then
  865. TargetFixPath:=s
  866. else
  867. TargetFixPath:=Lower(s);
  868. end;
  869. function TargetFixFileName(const s:string):string;
  870. var
  871. i : longint;
  872. begin
  873. if target_info.system = system_powerpc_MACOS then
  874. TargetFixFileName:= TranslatePathToMac(s, true)
  875. else if target_info.files_case_relevent then
  876. begin
  877. for i:=1 to length(s) do
  878. begin
  879. case s[i] of
  880. '/','\' :
  881. TargetFixFileName[i]:=target_info.dirsep;
  882. else
  883. TargetFixFileName[i]:=s[i];
  884. end;
  885. end;
  886. TargetFixFileName[0]:=s[0];
  887. end
  888. else
  889. begin
  890. for i:=1 to length(s) do
  891. begin
  892. case s[i] of
  893. '/','\' :
  894. TargetFixFileName[i]:=target_info.dirsep;
  895. 'A'..'Z' :
  896. TargetFixFileName[i]:=char(byte(s[i])+32);
  897. else
  898. TargetFixFileName[i]:=s[i];
  899. end;
  900. end;
  901. TargetFixFileName[0]:=s[0];
  902. end;
  903. end;
  904. procedure SplitBinCmd(const s:string;var bstr:String;var cstr:TCmdStr);
  905. var
  906. i : longint;
  907. begin
  908. i:=pos(' ',s);
  909. if i>0 then
  910. begin
  911. bstr:=Copy(s,1,i-1);
  912. cstr:=Copy(s,i+1,length(s)-i);
  913. end
  914. else
  915. begin
  916. bstr:=s;
  917. cstr:='';
  918. end;
  919. end;
  920. procedure TSearchPathList.AddPath(s:string;addfirst:boolean);
  921. begin
  922. AddPath('',s,AddFirst);
  923. end;
  924. procedure TSearchPathList.AddPath(SrcPath,s:string;addfirst:boolean);
  925. var
  926. staridx,
  927. j : longint;
  928. prefix,
  929. suffix,
  930. CurrentDir,
  931. currPath : string;
  932. subdirfound : boolean;
  933. {$IFDEF USE_SYSUTILS}
  934. dir : TSearchRec;
  935. {$ELSE USE_SYSUTILS}
  936. dir : searchrec;
  937. {$ENDIF USE_SYSUTILS}
  938. hp : TStringListItem;
  939. procedure AddCurrPath;
  940. begin
  941. if addfirst then
  942. begin
  943. Remove(currPath);
  944. Insert(currPath);
  945. end
  946. else
  947. begin
  948. { Check if already in path, then we don't add it }
  949. hp:=Find(currPath);
  950. if not assigned(hp) then
  951. Concat(currPath);
  952. end;
  953. end;
  954. begin
  955. if s='' then
  956. exit;
  957. { Support default macro's }
  958. DefaultReplacements(s);
  959. { get current dir }
  960. CurrentDir:=GetCurrentDir;
  961. repeat
  962. { get currpath }
  963. if addfirst then
  964. begin
  965. j:=length(s);
  966. while (j>0) and (s[j]<>';') do
  967. dec(j);
  968. currPath:= TrimSpace(Copy(s,j+1,length(s)-j));
  969. DePascalQuote(currPath);
  970. currPath:=FixPath(currPath,false);
  971. if j=0 then
  972. s:=''
  973. else
  974. System.Delete(s,j,length(s)-j+1);
  975. end
  976. else
  977. begin
  978. j:=Pos(';',s);
  979. if j=0 then
  980. j:=255;
  981. currPath:= TrimSpace(Copy(s,1,j-1));
  982. DePascalQuote(currPath);
  983. currPath:=SrcPath+FixPath(currPath,false);
  984. System.Delete(s,1,j);
  985. end;
  986. { fix pathname }
  987. if currPath='' then
  988. currPath:= CurDirRelPath(source_info)
  989. else
  990. begin
  991. currPath:=FixPath(FExpand(currPath),false);
  992. if (CurrentDir<>'') and (Copy(currPath,1,length(CurrentDir))=CurrentDir) then
  993. begin
  994. {$ifdef AMIGA}
  995. currPath:= CurrentDir+Copy(currPath,length(CurrentDir)+1,255);
  996. {$else}
  997. currPath:= CurDirRelPath(source_info)+Copy(currPath,length(CurrentDir)+1,255);
  998. {$endif}
  999. end;
  1000. end;
  1001. { wildcard adding ? }
  1002. staridx:=pos('*',currpath);
  1003. if staridx>0 then
  1004. begin
  1005. prefix:=SplitPath(Copy(currpath,1,staridx));
  1006. suffix:=Copy(currpath,staridx+1,length(currpath));
  1007. subdirfound:=false;
  1008. {$IFDEF USE_SYSUTILS}
  1009. if findfirst(prefix+'*',faDirectory,dir) = 0 then
  1010. begin
  1011. repeat
  1012. if (dir.name<>'.') and
  1013. (dir.name<>'..') and
  1014. ((dir.attr and faDirectory)<>0) then
  1015. begin
  1016. subdirfound:=true;
  1017. currpath:=prefix+dir.name+suffix;
  1018. if (suffix='') or PathExists(currpath) then
  1019. begin
  1020. hp:=Find(currPath);
  1021. if not assigned(hp) then
  1022. AddCurrPath;
  1023. end;
  1024. end;
  1025. until findnext(dir) <> 0;
  1026. end
  1027. {$ELSE USE_SYSUTILS}
  1028. findfirst(prefix+'*',directory,dir);
  1029. while doserror=0 do
  1030. begin
  1031. if (dir.name<>'.') and
  1032. (dir.name<>'..') and
  1033. ((dir.attr and directory)<>0) then
  1034. begin
  1035. subdirfound:=true;
  1036. currpath:=prefix+dir.name+suffix;
  1037. if (suffix='') or PathExists(currpath) then
  1038. begin
  1039. hp:=Find(currPath);
  1040. if not assigned(hp) then
  1041. AddCurrPath;
  1042. end;
  1043. end;
  1044. findnext(dir);
  1045. end;
  1046. {$ENDIF USE_SYSUTILS}
  1047. FindClose(dir);
  1048. if not subdirfound then
  1049. WarnNonExistingPath(currpath);
  1050. end
  1051. else
  1052. begin
  1053. if PathExists(currpath) then
  1054. AddCurrPath
  1055. else
  1056. WarnNonExistingPath(currpath);
  1057. end;
  1058. until (s='');
  1059. end;
  1060. procedure TSearchPathList.AddList(list:TSearchPathList;addfirst:boolean);
  1061. var
  1062. s : string;
  1063. hl : TSearchPathList;
  1064. hp,hp2 : TStringListItem;
  1065. begin
  1066. if list.empty then
  1067. exit;
  1068. { create temp and reverse the list }
  1069. if addfirst then
  1070. begin
  1071. hl:=TSearchPathList.Create;
  1072. hp:=TStringListItem(list.first);
  1073. while assigned(hp) do
  1074. begin
  1075. hl.insert(hp.Str);
  1076. hp:=TStringListItem(hp.next);
  1077. end;
  1078. while not hl.empty do
  1079. begin
  1080. s:=hl.GetFirst;
  1081. Remove(s);
  1082. Insert(s);
  1083. end;
  1084. hl.Free;
  1085. end
  1086. else
  1087. begin
  1088. hp:=TStringListItem(list.first);
  1089. while assigned(hp) do
  1090. begin
  1091. hp2:=Find(hp.Str);
  1092. { Check if already in path, then we don't add it }
  1093. if not assigned(hp2) then
  1094. Concat(hp.Str);
  1095. hp:=TStringListItem(hp.next);
  1096. end;
  1097. end;
  1098. end;
  1099. function TSearchPathList.FindFile(const f : string;var foundfile:string):boolean;
  1100. Var
  1101. p : TStringListItem;
  1102. begin
  1103. FindFile:=false;
  1104. p:=TStringListItem(first);
  1105. while assigned(p) do
  1106. begin
  1107. result:=FileExistsNonCase(p.Str,f,FoundFile);
  1108. if result then
  1109. exit;
  1110. p:=TStringListItem(p.next);
  1111. end;
  1112. { Return original filename if not found }
  1113. FoundFile:=f;
  1114. end;
  1115. Function GetFileTime ( Var F : File) : Longint;
  1116. Var
  1117. {$ifdef hasunix}
  1118. info: Stat;
  1119. {$endif}
  1120. L : longint;
  1121. begin
  1122. {$ifdef hasunix}
  1123. {$IFDEF havelinuxrtl10}
  1124. FStat (F,Info);
  1125. L:=Info.Mtime;
  1126. {$ELSE}
  1127. FPFStat (F,Info);
  1128. L:=Info.st_Mtime;
  1129. {$ENDIF}
  1130. {$else}
  1131. GetFTime(f,l);
  1132. {$endif}
  1133. GetFileTime:=L;
  1134. end;
  1135. Function GetNamedFileTime (Const F : String) : Longint;
  1136. begin
  1137. GetNamedFileTime:=do_getnamedfiletime(F);
  1138. end;
  1139. function FindFile(const f : string;path : string;var foundfile:string):boolean;
  1140. Var
  1141. singlepathstring : string;
  1142. i : longint;
  1143. begin
  1144. {$ifdef Unix}
  1145. for i:=1 to length(path) do
  1146. if path[i]=':' then
  1147. path[i]:=';';
  1148. {$endif Unix}
  1149. FindFile:=false;
  1150. repeat
  1151. i:=pos(';',path);
  1152. if i=0 then
  1153. i:=256;
  1154. singlepathstring:=FixPath(copy(path,1,i-1),false);
  1155. delete(path,1,i);
  1156. result:=FileExistsNonCase(singlepathstring,f,FoundFile);
  1157. if result then
  1158. exit;
  1159. until path='';
  1160. FoundFile:=f;
  1161. end;
  1162. function FindFilePchar(const f : string;path : pchar;var foundfile:string):boolean;
  1163. Var
  1164. singlepathstring : string;
  1165. startpc,pc : pchar;
  1166. sepch : char;
  1167. begin
  1168. {$ifdef Unix}
  1169. sepch:=':';
  1170. {$else}
  1171. {$ifdef macos}
  1172. sepch:=',';
  1173. {$else}
  1174. sepch:=';';
  1175. {$endif macos}
  1176. {$endif Unix}
  1177. FindFilePchar:=false;
  1178. pc:=path;
  1179. repeat
  1180. startpc:=pc;
  1181. while (pc^<>sepch) and (pc^<>';') and (pc^<>#0) do
  1182. inc(pc);
  1183. move(startpc^,singlepathstring[1],pc-startpc);
  1184. singlepathstring[0]:=char(longint(pc-startpc));
  1185. singlepathstring:=FixPath(singlepathstring,false);
  1186. result:=FileExistsNonCase(singlepathstring,f,FoundFile);
  1187. if result then
  1188. exit;
  1189. if (pc^=#0) then
  1190. break;
  1191. inc(pc);
  1192. until false;
  1193. foundfile:=f;
  1194. end;
  1195. function FindExe(const bin:string;var foundfile:string):boolean;
  1196. var
  1197. p : pchar;
  1198. found : boolean;
  1199. begin
  1200. found:=FindFile(FixFileName(AddExtension(bin,source_info.exeext)),'.;'+exepath,foundfile);
  1201. if not found then
  1202. begin
  1203. {$ifdef macos}
  1204. p:=GetEnvPchar('Commands');
  1205. {$else}
  1206. p:=GetEnvPchar('PATH');
  1207. {$endif}
  1208. found:=FindFilePChar(FixFileName(AddExtension(bin,source_info.exeext)),p,foundfile);
  1209. FreeEnvPChar(p);
  1210. end;
  1211. FindExe:=found;
  1212. end;
  1213. function GetShortName(const n:string):string;
  1214. {$ifdef win32}
  1215. var
  1216. hs,hs2 : string;
  1217. i : longint;
  1218. {$endif}
  1219. {$ifdef go32v2}
  1220. var
  1221. hs : string;
  1222. {$endif}
  1223. {$ifdef watcom}
  1224. var
  1225. hs : string;
  1226. {$endif}
  1227. begin
  1228. GetShortName:=n;
  1229. {$ifdef win32}
  1230. hs:=n+#0;
  1231. i:=Windows.GetShortPathName(@hs[1],@hs2[1],high(hs2));
  1232. if (i>0) and (i<=high(hs2)) then
  1233. begin
  1234. hs2[0]:=chr(strlen(@hs2[1]));
  1235. GetShortName:=hs2;
  1236. end;
  1237. {$endif}
  1238. {$ifdef go32v2}
  1239. hs:=n;
  1240. if Dos.GetShortName(hs) then
  1241. GetShortName:=hs;
  1242. {$endif}
  1243. {$ifdef watcom}
  1244. hs:=n;
  1245. if Dos.GetShortName(hs) then
  1246. GetShortName:=hs;
  1247. {$endif}
  1248. end;
  1249. function CleanPath(const s:string):String;
  1250. { Wrapper that encapsulate fexpand/expandfilename}
  1251. begin
  1252. {$IFDEF USE_SYSUTILS}
  1253. cleanpath:=ExpandFileName(s);
  1254. {$else}
  1255. cleanpath:=fexpand(s);
  1256. {$endif}
  1257. end;
  1258. {****************************************************************************
  1259. OS Dependent things
  1260. ****************************************************************************}
  1261. function GetEnvPChar(const envname:string):pchar;
  1262. {$ifdef win32}
  1263. var
  1264. s : string;
  1265. i,len : longint;
  1266. hp,p,p2 : pchar;
  1267. {$endif}
  1268. begin
  1269. {$ifdef hasunix}
  1270. GetEnvPchar:={$ifdef havelinuxrtl10}Linux.getenv{$else}BaseUnix.fpGetEnv{$endif}(envname);
  1271. {$define GETENVOK}
  1272. {$endif}
  1273. {$ifdef win32}
  1274. GetEnvPchar:=nil;
  1275. p:=GetEnvironmentStrings;
  1276. hp:=p;
  1277. while hp^<>#0 do
  1278. begin
  1279. s:=strpas(hp);
  1280. i:=pos('=',s);
  1281. len:=strlen(hp);
  1282. if upper(copy(s,1,i-1))=upper(envname) then
  1283. begin
  1284. GetMem(p2,len-length(envname));
  1285. Move(hp[i],p2^,len-length(envname));
  1286. GetEnvPchar:=p2;
  1287. break;
  1288. end;
  1289. { next string entry}
  1290. hp:=hp+len+1;
  1291. end;
  1292. FreeEnvironmentStrings(p);
  1293. {$define GETENVOK}
  1294. {$endif}
  1295. {$ifdef os2}
  1296. GetEnvPChar := Dos.GetEnvPChar (EnvName);
  1297. {$define GETENVOK}
  1298. {$endif}
  1299. {$ifdef GETENVOK}
  1300. {$undef GETENVOK}
  1301. {$else}
  1302. GetEnvPchar:=StrPNew(Dos.Getenv(envname));
  1303. {$endif}
  1304. end;
  1305. procedure FreeEnvPChar(p:pchar);
  1306. begin
  1307. {$ifndef hasunix}
  1308. {$ifndef os2}
  1309. StrDispose(p);
  1310. {$endif}
  1311. {$endif}
  1312. end;
  1313. {$IFDEF MORPHOS}
  1314. {$DEFINE AMIGASHELL}
  1315. {$ENDIF}
  1316. {$IFDEF AMIGA}
  1317. {$DEFINE AMIGASHELL}
  1318. {$ENDIF}
  1319. function Shell(const command:string): longint;
  1320. { This is already defined in the linux.ppu for linux, need for the *
  1321. expansion under linux }
  1322. {$ifdef hasunix}
  1323. begin
  1324. result := {$ifdef havelinuxrtl10}Linux{$else}Unix{$endif}.Shell(command);
  1325. end;
  1326. {$else}
  1327. {$ifdef amigashell}
  1328. begin
  1329. {$IFDEF USE_SYSUTILS}
  1330. result := ExecuteProcess('',command);
  1331. {$ELSE USE_SYSUTILS}
  1332. exec('',command);
  1333. if (doserror <> 0) then
  1334. result := doserror
  1335. else
  1336. result := dosexitcode;
  1337. end;
  1338. {$ENDIF USE_SYSUTILS}
  1339. {$else}
  1340. var
  1341. comspec : string;
  1342. begin
  1343. comspec:=getenv('COMSPEC');
  1344. {$IFDEF USE_SYSUTILS}
  1345. result := ExecuteProcess(comspec,' /C '+command);
  1346. {$ELSE USE_SYSUTILS}
  1347. Exec(comspec,' /C '+command);
  1348. if (doserror <> 0) then
  1349. result := doserror
  1350. else
  1351. result := dosexitcode;
  1352. end;
  1353. {$ENDIF USE_SYSUTILS}
  1354. {$endif}
  1355. {$endif}
  1356. {$UNDEF AMIGASHELL}
  1357. {$ifdef CPUI386}
  1358. {$define HASSETFPUEXCEPTIONMASK}
  1359. { later, this should be replaced by the math unit }
  1360. const
  1361. Default8087CW : word = $1332;
  1362. procedure Set8087CW(cw:word);assembler;
  1363. asm
  1364. movw cw,%ax
  1365. movw %ax,default8087cw
  1366. fnclex
  1367. fldcw default8087cw
  1368. end;
  1369. function Get8087CW:word;assembler;
  1370. asm
  1371. pushl $0
  1372. fnstcw (%esp)
  1373. popl %eax
  1374. end;
  1375. procedure SetFPUExceptionMask(const Mask: TFPUExceptionMask);
  1376. var
  1377. CtlWord: Word;
  1378. begin
  1379. CtlWord:=Get8087CW;
  1380. Set8087CW( (CtlWord and $FFC0) or Byte(Longint(Mask)) );
  1381. end;
  1382. {$endif CPUI386}
  1383. {$ifdef CPUX86_64}
  1384. {$define HASSETFPUEXCEPTIONMASK}
  1385. { later, this should be replaced by the math unit }
  1386. const
  1387. Default8087CW : word = $1332;
  1388. procedure Set8087CW(cw:word);assembler;
  1389. asm
  1390. movw cw,%ax
  1391. movw %ax,default8087cw
  1392. fnclex
  1393. fldcw default8087cw
  1394. end;
  1395. function Get8087CW:word;assembler;
  1396. asm
  1397. pushq $0
  1398. fnstcw (%rsp)
  1399. popq %rax
  1400. end;
  1401. procedure SetFPUExceptionMask(const Mask: TFPUExceptionMask);
  1402. var
  1403. CtlWord: Word;
  1404. begin
  1405. CtlWord:=Get8087CW;
  1406. Set8087CW( (CtlWord and $FFC0) or Byte(Longint(Mask)) );
  1407. end;
  1408. {$endif CPUX86_64}
  1409. {$ifdef CPUPOWERPC}
  1410. {$define HASSETFPUEXCEPTIONMASK}
  1411. procedure SetFPUExceptionMask(const Mask: TFPUExceptionMask);
  1412. var
  1413. newmask: record
  1414. case byte of
  1415. 1: (d: double);
  1416. 2: (a,b: cardinal);
  1417. end;
  1418. begin
  1419. { load current control register contents }
  1420. asm
  1421. mffs f0
  1422. stfd f0,newmask.d
  1423. end;
  1424. { invalid operation: bit 24 (big endian, bit 0 = left-most bit) }
  1425. if (exInvalidOp in mask) then
  1426. newmask.b := newmask.b and not(1 shl (31-24))
  1427. else
  1428. newmask.b := newmask.b or (1 shl (31-24));
  1429. { denormals can not cause exceptions on the PPC }
  1430. { zero divide: bit 27 }
  1431. if (exZeroDivide in mask) then
  1432. newmask.b := newmask.b and not(1 shl (31-27))
  1433. else
  1434. newmask.b := newmask.b or (1 shl (31-27));
  1435. { overflow: bit 25 }
  1436. if (exOverflow in mask) then
  1437. newmask.b := newmask.b and not(1 shl (31-25))
  1438. else
  1439. newmask.b := newmask.b or (1 shl (31-25));
  1440. { underflow: bit 26 }
  1441. if (exUnderflow in mask) then
  1442. newmask.b := newmask.b and not(1 shl (31-26))
  1443. else
  1444. newmask.b := newmask.b or (1 shl (31-26));
  1445. { Precision (inexact result): bit 28 }
  1446. if (exPrecision in mask) then
  1447. newmask.b := newmask.b and not(1 shl (31-28))
  1448. else
  1449. newmask.b := newmask.b or (1 shl (31-28));
  1450. { update control register contents }
  1451. asm
  1452. lfd f0, newmask.d
  1453. mtfsf 255,f0
  1454. end;
  1455. end;
  1456. {$endif CPUPOWERPC}
  1457. {$ifdef CPUSPARC}
  1458. {$define HASSETFPUEXCEPTIONMASK}
  1459. procedure SetFPUExceptionMask(const Mask: TFPUExceptionMask);
  1460. var
  1461. fsr : cardinal;
  1462. begin
  1463. { load current control register contents }
  1464. asm
  1465. st %fsr,fsr
  1466. end;
  1467. { invalid operation: bit 27 }
  1468. if (exInvalidOp in mask) then
  1469. fsr:=fsr and not(1 shl 27)
  1470. else
  1471. fsr:=fsr or (1 shl 27);
  1472. { zero divide: bit 24 }
  1473. if (exZeroDivide in mask) then
  1474. fsr:=fsr and not(1 shl 24)
  1475. else
  1476. fsr:=fsr or (1 shl 24);
  1477. { overflow: bit 26 }
  1478. if (exOverflow in mask) then
  1479. fsr:=fsr and not(1 shl 26)
  1480. else
  1481. fsr:=fsr or (1 shl 26);
  1482. { underflow: bit 25 }
  1483. if (exUnderflow in mask) then
  1484. fsr:=fsr and not(1 shl 25)
  1485. else
  1486. fsr:=fsr or (1 shl 25);
  1487. { Precision (inexact result): bit 23 }
  1488. if (exPrecision in mask) then
  1489. fsr:=fsr and not(1 shl 23)
  1490. else
  1491. fsr:=fsr or (1 shl 23);
  1492. { update control register contents }
  1493. asm
  1494. ld fsr,%fsr
  1495. end;
  1496. end;
  1497. {$endif CPUSPARC}
  1498. {$ifndef HASSETFPUEXCEPTIONMASK}
  1499. procedure SetFPUExceptionMask(const Mask: TFPUExceptionMask);
  1500. begin
  1501. end;
  1502. {$endif HASSETFPUEXCEPTIONMASK}
  1503. function is_number_float(d : double) : boolean;
  1504. var
  1505. bytearray : array[0..7] of byte;
  1506. begin
  1507. move(d,bytearray,8);
  1508. { only 1.1 save, 1.0.x will use always little endian }
  1509. {$ifdef FPC_BIG_ENDIAN}
  1510. result:=((bytearray[0] and $7f)<>$7f) or ((bytearray[1] and $f0)<>$f0);
  1511. {$else FPC_BIG_ENDIAN}
  1512. result:=((bytearray[7] and $7f)<>$7f) or ((bytearray[6] and $f0)<>$f0);
  1513. {$endif FPC_BIG_ENDIAN}
  1514. end;
  1515. function convertdoublearray(d : tdoublearray) : tdoublearray;{$ifdef USEINLINE}inline;{$endif}
  1516. {$ifdef CPUARM}
  1517. var
  1518. i : longint;
  1519. begin
  1520. for i:=0 to 3 do
  1521. begin
  1522. result[i+4]:=d[i];
  1523. result[i]:=d[i+4];
  1524. end;
  1525. {$else CPUARM}
  1526. begin
  1527. result:=d;
  1528. {$endif CPUARM}
  1529. end;
  1530. Function SetCompileMode(const s:string; changeInit: boolean):boolean;
  1531. var
  1532. b : boolean;
  1533. begin
  1534. b:=true;
  1535. if s='DEFAULT' then
  1536. aktmodeswitches:=initmodeswitches
  1537. else
  1538. if s='DELPHI' then
  1539. aktmodeswitches:=delphimodeswitches
  1540. else
  1541. if s='TP' then
  1542. aktmodeswitches:=tpmodeswitches
  1543. else
  1544. if s='FPC' then
  1545. aktmodeswitches:=fpcmodeswitches
  1546. else
  1547. if s='OBJFPC' then
  1548. aktmodeswitches:=objfpcmodeswitches
  1549. else
  1550. if s='GPC' then
  1551. aktmodeswitches:=gpcmodeswitches
  1552. else
  1553. if s='MACPAS' then
  1554. aktmodeswitches:=macmodeswitches
  1555. else
  1556. b:=false;
  1557. if b and changeInit then
  1558. initmodeswitches := aktmodeswitches;
  1559. if b then
  1560. begin
  1561. { turn ansistrings on by default ? }
  1562. if (m_delphi in aktmodeswitches) then
  1563. begin
  1564. include(aktlocalswitches,cs_ansistrings);
  1565. if changeinit then
  1566. include(initlocalswitches,cs_ansistrings);
  1567. end
  1568. else
  1569. begin
  1570. exclude(aktlocalswitches,cs_ansistrings);
  1571. if changeinit then
  1572. exclude(initlocalswitches,cs_ansistrings);
  1573. end;
  1574. { Default enum packing for delphi/tp7 }
  1575. if (m_tp7 in aktmodeswitches) or
  1576. (m_delphi in aktmodeswitches) then
  1577. aktpackenum:=1
  1578. else
  1579. aktpackenum:=4;
  1580. if changeinit then
  1581. initpackenum:=aktpackenum;
  1582. {$ifdef i386}
  1583. { Default to intel assembler for delphi/tp7 on i386 }
  1584. if (m_delphi in aktmodeswitches) or
  1585. (m_tp7 in aktmodeswitches) then
  1586. aktasmmode:=asmmode_i386_intel;
  1587. if changeinit then
  1588. initasmmode:=aktasmmode;
  1589. {$endif i386}
  1590. end;
  1591. SetCompileMode:=b;
  1592. end;
  1593. function SetAktProcCall(const s:string; changeInit:boolean):boolean;
  1594. const
  1595. DefProcCallName : array[tproccalloption] of string[12] = ('',
  1596. 'CDECL',
  1597. 'CPPDECL',
  1598. '', { compilerproc }
  1599. 'FAR16',
  1600. 'FPCCALL',
  1601. 'INLINE',
  1602. '', { internproc }
  1603. '', { syscall }
  1604. 'PASCAL',
  1605. 'REGISTER',
  1606. 'SAFECALL',
  1607. 'STDCALL',
  1608. 'SOFTFLOAT'
  1609. );
  1610. var
  1611. t : tproccalloption;
  1612. begin
  1613. result:=false;
  1614. for t:=low(tproccalloption) to high(tproccalloption) do
  1615. if DefProcCallName[t]=s then
  1616. begin
  1617. AktDefProcCall:=t;
  1618. result:=true;
  1619. break;
  1620. end;
  1621. if changeinit then
  1622. InitDefProcCall:=AktDefProcCall;
  1623. end;
  1624. function SetProcessor(const s:string; changeInit: boolean):boolean;
  1625. var
  1626. t : tprocessors;
  1627. begin
  1628. SetProcessor:=false;
  1629. for t:=low(tprocessors) to high(tprocessors) do
  1630. if processorsstr[t]=s then
  1631. begin
  1632. aktspecificoptprocessor:=t;
  1633. SetProcessor:=true;
  1634. break;
  1635. end;
  1636. if changeinit then
  1637. initspecificoptprocessor:=aktspecificoptprocessor;
  1638. end;
  1639. function SetFpuType(const s:string; changeInit: boolean):boolean;
  1640. var
  1641. t : tfputype;
  1642. begin
  1643. SetFpuType:=false;
  1644. for t:=low(tfputype) to high(tfputype) do
  1645. if fputypestr[t]=s then
  1646. begin
  1647. aktfputype:=t;
  1648. SetFpuType:=true;
  1649. break;
  1650. end;
  1651. if changeinit then
  1652. initfputype:=aktfputype;
  1653. end;
  1654. { '('D1:'00000000-'D2:'0000-'D3:'0000-'D4:'0000-000000000000)' }
  1655. function string2guid(const s: string; var GUID: TGUID): boolean;
  1656. function ishexstr(const hs: string): boolean;
  1657. var
  1658. i: integer;
  1659. begin
  1660. ishexstr:=false;
  1661. for i:=1 to Length(hs) do begin
  1662. if not (hs[i] in ['0'..'9','A'..'F','a'..'f']) then
  1663. exit;
  1664. end;
  1665. ishexstr:=true;
  1666. end;
  1667. function hexstr2longint(const hexs: string): longint;
  1668. var
  1669. i: integer;
  1670. rl: longint;
  1671. begin
  1672. rl:=0;
  1673. for i:=1 to length(hexs) do begin
  1674. rl:=rl shl 4;
  1675. case hexs[i] of
  1676. '0'..'9' : inc(rl,ord(hexs[i])-ord('0'));
  1677. 'A'..'F' : inc(rl,ord(hexs[i])-ord('A')+10);
  1678. 'a'..'f' : inc(rl,ord(hexs[i])-ord('a')+10);
  1679. end
  1680. end;
  1681. hexstr2longint:=rl;
  1682. end;
  1683. var
  1684. i: integer;
  1685. begin
  1686. if (Length(s)=38) and (s[1]='{') and (s[38]='}') and
  1687. (s[10]='-') and (s[15]='-') and (s[20]='-') and (s[25]='-') and
  1688. ishexstr(copy(s,2,8)) and ishexstr(copy(s,11,4)) and
  1689. ishexstr(copy(s,16,4)) and ishexstr(copy(s,21,4)) and
  1690. ishexstr(copy(s,26,12)) then begin
  1691. GUID.D1:=dword(hexstr2longint(copy(s,2,8)));
  1692. { these values are arealdy in the correct range (4 chars = word) }
  1693. GUID.D2:=word(hexstr2longint(copy(s,11,4)));
  1694. GUID.D3:=word(hexstr2longint(copy(s,16,4)));
  1695. for i:=0 to 1 do
  1696. GUID.D4[i]:=byte(hexstr2longint(copy(s,21+i*2,2)));
  1697. for i:=2 to 7 do
  1698. GUID.D4[i]:=byte(hexstr2longint(copy(s,22+i*2,2)));
  1699. string2guid:=true;
  1700. end
  1701. else
  1702. string2guid:=false;
  1703. end;
  1704. function guid2string(const GUID: TGUID): string;
  1705. function long2hex(l, len: longint): string;
  1706. const
  1707. hextbl: array[0..15] of char = '0123456789ABCDEF';
  1708. var
  1709. rs: string;
  1710. i: integer;
  1711. begin
  1712. rs[0]:=chr(len);
  1713. for i:=len downto 1 do begin
  1714. rs[i]:=hextbl[l and $F];
  1715. l:=l shr 4;
  1716. end;
  1717. long2hex:=rs;
  1718. end;
  1719. begin
  1720. guid2string:=
  1721. '{'+long2hex(GUID.D1,8)+
  1722. '-'+long2hex(GUID.D2,4)+
  1723. '-'+long2hex(GUID.D3,4)+
  1724. '-'+long2hex(GUID.D4[0],2)+long2hex(GUID.D4[1],2)+
  1725. '-'+long2hex(GUID.D4[2],2)+long2hex(GUID.D4[3],2)+
  1726. long2hex(GUID.D4[4],2)+long2hex(GUID.D4[5],2)+
  1727. long2hex(GUID.D4[6],2)+long2hex(GUID.D4[7],2)+
  1728. '}';
  1729. end;
  1730. function UpdateAlignmentStr(s:string;var a:talignmentinfo):boolean;
  1731. var
  1732. tok : string;
  1733. vstr : string;
  1734. l : longint;
  1735. code : integer;
  1736. b : talignmentinfo;
  1737. begin
  1738. UpdateAlignmentStr:=true;
  1739. uppervar(s);
  1740. fillchar(b,sizeof(b),0);
  1741. repeat
  1742. tok:=GetToken(s,'=');
  1743. if tok='' then
  1744. break;
  1745. vstr:=GetToken(s,',');
  1746. val(vstr,l,code);
  1747. if tok='PROC' then
  1748. b.procalign:=l
  1749. else if tok='JUMP' then
  1750. b.jumpalign:=l
  1751. else if tok='LOOP' then
  1752. b.loopalign:=l
  1753. else if tok='CONSTMIN' then
  1754. b.constalignmin:=l
  1755. else if tok='CONSTMAX' then
  1756. b.constalignmax:=l
  1757. else if tok='VARMIN' then
  1758. b.varalignmin:=l
  1759. else if tok='VARMAX' then
  1760. b.varalignmax:=l
  1761. else if tok='LOCALMIN' then
  1762. b.localalignmin:=l
  1763. else if tok='LOCALMAX' then
  1764. b.localalignmax:=l
  1765. else if tok='RECORDMIN' then
  1766. b.recordalignmin:=l
  1767. else if tok='RECORDMAX' then
  1768. b.recordalignmax:=l
  1769. else { Error }
  1770. UpdateAlignmentStr:=false;
  1771. until false;
  1772. UpdateAlignment(a,b);
  1773. end;
  1774. function var_align(siz: longint): longint;
  1775. begin
  1776. siz := size_2_align(siz);
  1777. var_align := used_align(siz,aktalignment.varalignmin,aktalignment.varalignmax);
  1778. end;
  1779. function const_align(siz: longint): longint;
  1780. begin
  1781. siz := size_2_align(siz);
  1782. const_align := used_align(siz,aktalignment.constalignmin,aktalignment.constalignmax);
  1783. end;
  1784. {****************************************************************************
  1785. Init
  1786. ****************************************************************************}
  1787. {$ifdef unix}
  1788. {$define need_path_search}
  1789. {$endif unix}
  1790. {$ifdef os2}
  1791. {$define need_path_search}
  1792. {$endif os2}
  1793. {$ifdef macos}
  1794. {$define need_path_search}
  1795. {$endif macos}
  1796. procedure get_exepath;
  1797. var
  1798. hs1 : namestr;
  1799. hs2 : extstr;
  1800. {$IFDEF USE_SYSUTILS}
  1801. exeName:String;
  1802. {$ENDIF USE_SYSUTILS}
  1803. {$ifdef need_path_search}
  1804. p : pchar;
  1805. {$endif need_path_search}
  1806. begin
  1807. {$IFDEF USE_SYSUTILS}
  1808. exepath:=GetEnvironmentVariable('PPC_EXEC_PATH');
  1809. {$ELSE USE_SYSUTILS}
  1810. exepath:=dos.getenv('PPC_EXEC_PATH');
  1811. {$ENDIF USE_SYSUTILS}
  1812. if exepath='' then
  1813. {$IFDEF USE_SYSUTILS}
  1814. exeName := FixFileName(system.paramstr(0));
  1815. exepath := ExtractFilePath(exeName);
  1816. hs1 := ExtractFileName(exeName);
  1817. hs2 := ExtractFileExt(exeName);
  1818. {$ELSE USE_SYSUTILS}
  1819. fsplit(FixFileName(system.paramstr(0)),exepath,hs1,hs2);
  1820. {$ENDIF USE_SYSUTILS}
  1821. {$ifdef need_path_search}
  1822. if exepath='' then
  1823. begin
  1824. if pos(source_info.exeext,hs1) <>
  1825. (length(hs1) - length(source_info.exeext)+1) then
  1826. hs1 := hs1 + source_info.exeext;
  1827. {$ifdef macos}
  1828. p:=GetEnvPchar('Commands');
  1829. {$else macos}
  1830. p:=GetEnvPchar('PATH');
  1831. {$endif macos}
  1832. FindFilePChar(hs1,p,exepath);
  1833. FreeEnvPChar(p);
  1834. exepath:=SplitPath(exepath);
  1835. end;
  1836. {$endif need_path_search}
  1837. exepath:=FixPath(exepath,false);
  1838. end;
  1839. procedure DoneGlobals;
  1840. begin
  1841. if assigned(DLLImageBase) then
  1842. StringDispose(DLLImageBase);
  1843. librarysearchpath.Free;
  1844. unitsearchpath.Free;
  1845. objectsearchpath.Free;
  1846. includesearchpath.Free;
  1847. end;
  1848. procedure InitGlobals;
  1849. begin
  1850. get_exepath;
  1851. { reset globals }
  1852. do_build:=false;
  1853. do_release:=false;
  1854. do_make:=true;
  1855. compile_level:=0;
  1856. DLLsource:=false;
  1857. inlining_procedure:=false;
  1858. resolving_forward:=false;
  1859. make_ref:=false;
  1860. LinkTypeSetExplicitly:=false;
  1861. { Output }
  1862. OutputFile:='';
  1863. OutputPrefix:=Nil;
  1864. OutputSuffix:=Nil;
  1865. OutputExtension:='';
  1866. OutputExeDir:='';
  1867. OutputUnitDir:='';
  1868. { Utils directory }
  1869. utilsdirectory:='';
  1870. utilsprefix:='';
  1871. cshared:=false;
  1872. rlinkpath:='';
  1873. { Search Paths }
  1874. librarysearchpath:=TSearchPathList.Create;
  1875. unitsearchpath:=TSearchPathList.Create;
  1876. includesearchpath:=TSearchPathList.Create;
  1877. objectsearchpath:=TSearchPathList.Create;
  1878. { Def file }
  1879. usewindowapi:=false;
  1880. description:='Compiled by FPC '+version_string+' - '+target_cpu_string;
  1881. DescriptionSetExplicity:=false;
  1882. dllversion:='';
  1883. dllmajor:=1;
  1884. dllminor:=0;
  1885. dllrevision:=0;
  1886. nwscreenname := '';
  1887. nwthreadname := '';
  1888. nwcopyright := '';
  1889. UseDeffileForExports:=false;
  1890. UseDeffileForExportsSetExplicitly:=false;
  1891. RelocSection:=false;
  1892. RelocSectionSetExplicitly:=false;
  1893. LinkTypeSetExplicitly:=false;
  1894. { Init values }
  1895. initmodeswitches:=fpcmodeswitches;
  1896. initlocalswitches:=[cs_check_io,cs_typed_const_writable];
  1897. initmoduleswitches:=[cs_extsyntax,cs_implicit_exceptions];
  1898. initsourcecodepage:='8859-1';
  1899. initglobalswitches:=[cs_check_unit_name,cs_link_static{$ifdef INTERNALLINKER},cs_link_internal,cs_link_map{$endif}];
  1900. initoutputformat:=target_asm.id;
  1901. fillchar(initalignment,sizeof(talignmentinfo),0);
  1902. { might be overridden later }
  1903. initasmmode:=asmmode_standard;
  1904. {$ifdef i386}
  1905. initoptprocessor:=ClassPentium3;
  1906. initspecificoptprocessor:=Class386;
  1907. initfputype:=fpu_x87;
  1908. initpackenum:=4;
  1909. {$IFDEF testvarsets}
  1910. initsetalloc:=0;
  1911. {$ENDIF}
  1912. initasmmode:=asmmode_i386_att;
  1913. {$endif i386}
  1914. {$ifdef m68k}
  1915. initoptprocessor:=MC68020;
  1916. initpackenum:=4;
  1917. {$IFDEF testvarsets}
  1918. initsetalloc:=0;
  1919. {$ENDIF}
  1920. {$endif m68k}
  1921. {$ifdef powerpc}
  1922. initoptprocessor:=PPC604;
  1923. initpackenum:=4;
  1924. {$IFDEF testvarsets}
  1925. initsetalloc:=0;
  1926. {$ENDIF}
  1927. initfputype:=fpu_standard;
  1928. {$endif powerpc}
  1929. {$ifdef sparc}
  1930. initoptprocessor:=SPARC_V8;
  1931. initpackenum:=4;
  1932. {$IFDEF testvarsets}
  1933. initsetalloc:=0;
  1934. {$ENDIF}
  1935. {$endif sparc}
  1936. {$ifdef arm}
  1937. initpackenum:=4;
  1938. {$IFDEF testvarsets}
  1939. initsetalloc:=0;
  1940. {$ENDIF}
  1941. initfputype:=fpu_fpa;
  1942. {$endif arm}
  1943. {$ifdef x86_64}
  1944. initoptprocessor:=ClassAthlon64;
  1945. initspecificoptprocessor:=ClassAthlon64;
  1946. initfputype:=fpu_sse64;
  1947. initpackenum:=4;
  1948. {$IFDEF testvarsets}
  1949. initsetalloc:=0;
  1950. {$ENDIF}
  1951. initasmmode:=asmmode_x86_64_gas;
  1952. {$endif x86_64}
  1953. initinterfacetype:=it_interfacecom;
  1954. initdefproccall:=pocall_default;
  1955. { memory sizes, will be overriden by parameter or default for target
  1956. in options or init_parser }
  1957. stacksize:=0;
  1958. { not initialized yet }
  1959. jmp_buf_size:=-1;
  1960. apptype:=app_cui;
  1961. end;
  1962. end.
  1963. {
  1964. $Log$
  1965. Revision 1.162 2005-01-23 21:09:11 florian
  1966. + added pi bit pattern to the compiler, so pi should always be correct
  1967. Revision 1.161 2005/01/20 16:38:45 peter
  1968. * load jmp_buf_size from system unit
  1969. Revision 1.160 2005/01/09 20:24:43 olle
  1970. * rework of macro subsystem
  1971. + exportable macros for mode macpas
  1972. Revision 1.159 2005/01/06 13:40:41 florian
  1973. * 1.0.10 starting patch from Peter
  1974. Revision 1.158 2005/01/06 09:20:36 karoly
  1975. * made Shell() work correctly on MorphOS
  1976. Revision 1.157 2005/01/04 17:40:33 karoly
  1977. + sysv style syscalls added for MorphOS
  1978. Revision 1.156 2005/01/04 16:20:51 florian
  1979. * fixed nan et al. handling on arm
  1980. Revision 1.155 2004/12/28 20:43:01 hajny
  1981. * 8.3 fixes (short target name in paths)
  1982. Revision 1.154 2004/12/15 16:06:47 marco
  1983. * introduction "cleanpath" (=fexpand), fixfilename(paramstr(0)) + search $PREFIX/etc/fpc.cfg
  1984. Revision 1.153 2004/11/05 13:14:30 florian
  1985. * fixed arm compilation
  1986. Revision 1.152 2004/10/31 21:45:02 peter
  1987. * generic tlocation
  1988. * move tlocation to cgutils
  1989. Revision 1.151 2004/10/31 19:09:54 peter
  1990. * default paths fixed
  1991. Revision 1.150 2004/10/31 18:54:24 peter
  1992. * $fpctarget expands to <cpu>-<os>
  1993. * allow * in middle of the path to support ../*/units/$fpctarget
  1994. Revision 1.149 2004/10/26 15:11:01 peter
  1995. * -Ch for heapsize added again
  1996. * __heapsize contains the heapsize
  1997. Revision 1.148 2004/10/25 15:38:41 peter
  1998. * heap and heapsize removed
  1999. * checkpointer fixes
  2000. Revision 1.147 2004/10/16 22:46:14 olle
  2001. * Fixed printing of filedates
  2002. Revision 1.146 2004/10/16 13:03:13 olle
  2003. + added more support for macos
  2004. Revision 1.145 2004/10/15 09:14:16 mazen
  2005. - remove $IFDEF DELPHI and related code
  2006. - remove $IFDEF FPCPROCVAR and related code
  2007. Revision 1.144 2004/10/14 18:16:17 mazen
  2008. * USE_SYSUTILS merged successfully : cycles with and without defines
  2009. * Need to be optimized in performance
  2010. Revision 1.143 2004/10/10 15:42:22 peter
  2011. * default optimization cpu changed to CLassPentium3
  2012. Revision 1.142 2004/10/09 11:27:59 olle
  2013. + Added CurDirRelPath
  2014. * Exchanged hardcoded "./" to CurDirRelPath
  2015. Revision 1.141 2004/09/21 23:33:43 hajny
  2016. * better PathExists, fix for too long command line, correction of message
  2017. Revision 1.140 2004/09/21 19:59:51 peter
  2018. * x86_64 fixes
  2019. * cleanup of fpcdefs.icn
  2020. Revision 1.139 2004/09/21 17:25:12 peter
  2021. * paraloc branch merged
  2022. Revision 1.138 2004/09/08 11:23:31 michael
  2023. + Check if outputdir exists, Fix exitcode when displaying help pages
  2024. Revision 1.137 2004/08/31 22:02:30 olle
  2025. + support for quoting of paths in TSearchPathList.AddPath so that
  2026. compiler directives which take paths, will support quotes.
  2027. * uppdated TranslateMacPath
  2028. Revision 1.136.4.2 2004/09/12 18:31:26 peter
  2029. * fpu exception support for sparc and x86_64
  2030. Revision 1.136.4.1 2004/09/12 15:30:16 peter
  2031. * cache currentdir
  2032. Revision 1.136 2004/08/28 20:25:25 peter
  2033. * optimized search for noncasesensitive names. It now searches
  2034. first for NormalCase and skips double tests
  2035. Revision 1.135 2004/08/20 10:29:31 olle
  2036. + made fpc work as an MPW tool, by itself calling asm and link.
  2037. * bugfix in fp exception flag settings routine
  2038. Revision 1.134 2004/08/02 07:15:54 michael
  2039. + Patch from Christian Iversen to implement LIBPREFIX/SUFFIX/EXTENSION directives
  2040. Revision 1.133 2004/07/17 15:51:57 jonas
  2041. * shell now returns an exitcode
  2042. * print an error if linking failed when linking was done using a script
  2043. Revision 1.132 2004/07/05 23:28:24 olle
  2044. + FixFileName now handles Mac OS paths
  2045. Revision 1.131 2004/06/20 08:55:29 florian
  2046. * logs truncated
  2047. Revision 1.130 2004/06/16 20:07:07 florian
  2048. * dwarf branch merged
  2049. Revision 1.129 2004/05/11 18:20:52 olle
  2050. * changed $mode mac to $mode macpas
  2051. * changed macmodeswitches to be more faithful to the mac dialect
  2052. Revision 1.128 2004/04/29 19:56:36 daniel
  2053. * Prepare compiler infrastructure for multiple ansistring types
  2054. Revision 1.127 2004/04/28 15:19:03 florian
  2055. + syscall directive support for MorphOS added
  2056. Revision 1.126.2.4 2004/05/09 15:47:21 peter
  2057. * fix typecast from word->set
  2058. }