globals.pas 63 KB

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