globals.pas 65 KB

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