globals.pas 64 KB

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