globals.pas 66 KB

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