globals.pas 63 KB

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