globals.pas 64 KB

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