globals.pas 65 KB

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