globals.pas 64 KB

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