globals.pas 65 KB

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