globals.pas 62 KB

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