globals.pas 64 KB

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