globals.pas 63 KB

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