globals.pas 65 KB

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