globals.pas 63 KB

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