globals.pas 63 KB

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