globals.pas 65 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305
  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. {$IFDEF MORPHOS}
  1311. {$DEFINE AMIGASHELL}
  1312. {$ENDIF}
  1313. {$IFDEF AMIGA}
  1314. {$DEFINE AMIGASHELL}
  1315. {$ENDIF}
  1316. function Shell(const command:string): longint;
  1317. { This is already defined in the linux.ppu for linux, need for the *
  1318. expansion under linux }
  1319. {$ifdef hasunix}
  1320. begin
  1321. result := {$ifdef havelinuxrtl10}Linux{$else}Unix{$endif}.Shell(command);
  1322. end;
  1323. {$else}
  1324. {$ifdef amigashell}
  1325. begin
  1326. {$IFDEF USE_SYSUTILS}
  1327. result := ExecuteProcess('',command);
  1328. {$ELSE USE_SYSUTILS}
  1329. exec('',command);
  1330. if (doserror <> 0) then
  1331. result := doserror
  1332. else
  1333. result := dosexitcode;
  1334. end;
  1335. {$ENDIF USE_SYSUTILS}
  1336. {$else}
  1337. var
  1338. comspec : string;
  1339. begin
  1340. comspec:=getenv('COMSPEC');
  1341. {$IFDEF USE_SYSUTILS}
  1342. result := ExecuteProcess(comspec,' /C '+command);
  1343. {$ELSE USE_SYSUTILS}
  1344. Exec(comspec,' /C '+command);
  1345. if (doserror <> 0) then
  1346. result := doserror
  1347. else
  1348. result := dosexitcode;
  1349. end;
  1350. {$ENDIF USE_SYSUTILS}
  1351. {$endif}
  1352. {$endif}
  1353. {$UNDEF AMIGASHELL}
  1354. {$ifdef CPUI386}
  1355. {$define HASSETFPUEXCEPTIONMASK}
  1356. { later, this should be replaced by the math unit }
  1357. const
  1358. Default8087CW : word = $1332;
  1359. procedure Set8087CW(cw:word);assembler;
  1360. asm
  1361. movw cw,%ax
  1362. movw %ax,default8087cw
  1363. fnclex
  1364. fldcw default8087cw
  1365. end;
  1366. function Get8087CW:word;assembler;
  1367. asm
  1368. pushl $0
  1369. fnstcw (%esp)
  1370. popl %eax
  1371. end;
  1372. procedure SetFPUExceptionMask(const Mask: TFPUExceptionMask);
  1373. var
  1374. CtlWord: Word;
  1375. begin
  1376. CtlWord:=Get8087CW;
  1377. Set8087CW( (CtlWord and $FFC0) or Byte(Longint(Mask)) );
  1378. end;
  1379. {$endif CPUI386}
  1380. {$ifdef CPUX86_64}
  1381. {$define HASSETFPUEXCEPTIONMASK}
  1382. { later, this should be replaced by the math unit }
  1383. const
  1384. Default8087CW : word = $1332;
  1385. procedure Set8087CW(cw:word);assembler;
  1386. asm
  1387. movw cw,%ax
  1388. movw %ax,default8087cw
  1389. fnclex
  1390. fldcw default8087cw
  1391. end;
  1392. function Get8087CW:word;assembler;
  1393. asm
  1394. pushq $0
  1395. fnstcw (%rsp)
  1396. popq %rax
  1397. end;
  1398. procedure SetFPUExceptionMask(const Mask: TFPUExceptionMask);
  1399. var
  1400. CtlWord: Word;
  1401. begin
  1402. CtlWord:=Get8087CW;
  1403. Set8087CW( (CtlWord and $FFC0) or Byte(Longint(Mask)) );
  1404. end;
  1405. {$endif CPUX86_64}
  1406. {$ifdef CPUPOWERPC}
  1407. {$define HASSETFPUEXCEPTIONMASK}
  1408. procedure SetFPUExceptionMask(const Mask: TFPUExceptionMask);
  1409. var
  1410. newmask: record
  1411. case byte of
  1412. 1: (d: double);
  1413. 2: (a,b: cardinal);
  1414. end;
  1415. begin
  1416. { load current control register contents }
  1417. asm
  1418. mffs f0
  1419. stfd f0,newmask.d
  1420. end;
  1421. { invalid operation: bit 24 (big endian, bit 0 = left-most bit) }
  1422. if (exInvalidOp in mask) then
  1423. newmask.b := newmask.b and not(1 shl (31-24))
  1424. else
  1425. newmask.b := newmask.b or (1 shl (31-24));
  1426. { denormals can not cause exceptions on the PPC }
  1427. { zero divide: bit 27 }
  1428. if (exZeroDivide in mask) then
  1429. newmask.b := newmask.b and not(1 shl (31-27))
  1430. else
  1431. newmask.b := newmask.b or (1 shl (31-27));
  1432. { overflow: bit 25 }
  1433. if (exOverflow in mask) then
  1434. newmask.b := newmask.b and not(1 shl (31-25))
  1435. else
  1436. newmask.b := newmask.b or (1 shl (31-25));
  1437. { underflow: bit 26 }
  1438. if (exUnderflow in mask) then
  1439. newmask.b := newmask.b and not(1 shl (31-26))
  1440. else
  1441. newmask.b := newmask.b or (1 shl (31-26));
  1442. { Precision (inexact result): bit 28 }
  1443. if (exPrecision in mask) then
  1444. newmask.b := newmask.b and not(1 shl (31-28))
  1445. else
  1446. newmask.b := newmask.b or (1 shl (31-28));
  1447. { update control register contents }
  1448. asm
  1449. lfd f0, newmask.d
  1450. mtfsf 255,f0
  1451. end;
  1452. end;
  1453. {$endif CPUPOWERPC}
  1454. {$ifdef CPUSPARC}
  1455. {$define HASSETFPUEXCEPTIONMASK}
  1456. procedure SetFPUExceptionMask(const Mask: TFPUExceptionMask);
  1457. var
  1458. fsr : cardinal;
  1459. begin
  1460. { load current control register contents }
  1461. asm
  1462. st %fsr,fsr
  1463. end;
  1464. { invalid operation: bit 27 }
  1465. if (exInvalidOp in mask) then
  1466. fsr:=fsr and not(1 shl 27)
  1467. else
  1468. fsr:=fsr or (1 shl 27);
  1469. { zero divide: bit 24 }
  1470. if (exZeroDivide in mask) then
  1471. fsr:=fsr and not(1 shl 24)
  1472. else
  1473. fsr:=fsr or (1 shl 24);
  1474. { overflow: bit 26 }
  1475. if (exOverflow in mask) then
  1476. fsr:=fsr and not(1 shl 26)
  1477. else
  1478. fsr:=fsr or (1 shl 26);
  1479. { underflow: bit 25 }
  1480. if (exUnderflow in mask) then
  1481. fsr:=fsr and not(1 shl 25)
  1482. else
  1483. fsr:=fsr or (1 shl 25);
  1484. { Precision (inexact result): bit 23 }
  1485. if (exPrecision in mask) then
  1486. fsr:=fsr and not(1 shl 23)
  1487. else
  1488. fsr:=fsr or (1 shl 23);
  1489. { update control register contents }
  1490. asm
  1491. ld fsr,%fsr
  1492. end;
  1493. end;
  1494. {$endif CPUSPARC}
  1495. {$ifndef HASSETFPUEXCEPTIONMASK}
  1496. procedure SetFPUExceptionMask(const Mask: TFPUExceptionMask);
  1497. begin
  1498. end;
  1499. {$endif HASSETFPUEXCEPTIONMASK}
  1500. function is_number_float(d : double) : boolean;
  1501. var
  1502. bytearray : array[0..7] of byte;
  1503. begin
  1504. move(d,bytearray,8);
  1505. { only 1.1 save, 1.0.x will use always little endian }
  1506. {$ifdef FPC_BIG_ENDIAN}
  1507. result:=((bytearray[0] and $7f)<>$7f) or ((bytearray[1] and $f0)<>$f0);
  1508. {$else FPC_BIG_ENDIAN}
  1509. result:=((bytearray[7] and $7f)<>$7f) or ((bytearray[6] and $f0)<>$f0);
  1510. {$endif FPC_BIG_ENDIAN}
  1511. end;
  1512. function convertdoublearray(d : tdoublearray) : tdoublearray;{$ifdef USEINLINE}inline;{$endif}
  1513. {$ifdef CPUARM}
  1514. var
  1515. i : longint;
  1516. begin
  1517. for i:=0 to 3 do
  1518. begin
  1519. result[i+4]:=d[i];
  1520. result[i]:=d[i+4];
  1521. end;
  1522. {$else CPUARM}
  1523. begin
  1524. result:=d;
  1525. {$endif CPUARM}
  1526. end;
  1527. Function SetCompileMode(const s:string; changeInit: boolean):boolean;
  1528. var
  1529. b : boolean;
  1530. begin
  1531. b:=true;
  1532. if s='DEFAULT' then
  1533. aktmodeswitches:=initmodeswitches
  1534. else
  1535. if s='DELPHI' then
  1536. aktmodeswitches:=delphimodeswitches
  1537. else
  1538. if s='TP' then
  1539. aktmodeswitches:=tpmodeswitches
  1540. else
  1541. if s='FPC' then
  1542. aktmodeswitches:=fpcmodeswitches
  1543. else
  1544. if s='OBJFPC' then
  1545. aktmodeswitches:=objfpcmodeswitches
  1546. else
  1547. if s='GPC' then
  1548. aktmodeswitches:=gpcmodeswitches
  1549. else
  1550. if s='MACPAS' then
  1551. aktmodeswitches:=macmodeswitches
  1552. else
  1553. b:=false;
  1554. if b and changeInit then
  1555. initmodeswitches := aktmodeswitches;
  1556. if b then
  1557. begin
  1558. { turn ansistrings on by default ? }
  1559. if (m_delphi in aktmodeswitches) then
  1560. begin
  1561. include(aktlocalswitches,cs_ansistrings);
  1562. if changeinit then
  1563. include(initlocalswitches,cs_ansistrings);
  1564. end
  1565. else
  1566. begin
  1567. exclude(aktlocalswitches,cs_ansistrings);
  1568. if changeinit then
  1569. exclude(initlocalswitches,cs_ansistrings);
  1570. end;
  1571. { Default enum packing for delphi/tp7 }
  1572. if (m_tp7 in aktmodeswitches) or
  1573. (m_delphi in aktmodeswitches) then
  1574. aktpackenum:=1
  1575. else
  1576. aktpackenum:=4;
  1577. if changeinit then
  1578. initpackenum:=aktpackenum;
  1579. {$ifdef i386}
  1580. { Default to intel assembler for delphi/tp7 on i386 }
  1581. if (m_delphi in aktmodeswitches) or
  1582. (m_tp7 in aktmodeswitches) then
  1583. aktasmmode:=asmmode_i386_intel;
  1584. if changeinit then
  1585. initasmmode:=aktasmmode;
  1586. {$endif i386}
  1587. end;
  1588. SetCompileMode:=b;
  1589. end;
  1590. function SetAktProcCall(const s:string; changeInit:boolean):boolean;
  1591. const
  1592. DefProcCallName : array[tproccalloption] of string[12] = ('',
  1593. 'CDECL',
  1594. 'CPPDECL',
  1595. '', { compilerproc }
  1596. 'FAR16',
  1597. 'FPCCALL',
  1598. 'INLINE',
  1599. '', { internproc }
  1600. '', { syscall }
  1601. 'PASCAL',
  1602. 'REGISTER',
  1603. 'SAFECALL',
  1604. 'STDCALL',
  1605. 'SOFTFLOAT'
  1606. );
  1607. var
  1608. t : tproccalloption;
  1609. begin
  1610. result:=false;
  1611. for t:=low(tproccalloption) to high(tproccalloption) do
  1612. if DefProcCallName[t]=s then
  1613. begin
  1614. AktDefProcCall:=t;
  1615. result:=true;
  1616. break;
  1617. end;
  1618. if changeinit then
  1619. InitDefProcCall:=AktDefProcCall;
  1620. end;
  1621. function SetProcessor(const s:string; changeInit: boolean):boolean;
  1622. var
  1623. t : tprocessors;
  1624. begin
  1625. SetProcessor:=false;
  1626. for t:=low(tprocessors) to high(tprocessors) do
  1627. if processorsstr[t]=s then
  1628. begin
  1629. aktspecificoptprocessor:=t;
  1630. SetProcessor:=true;
  1631. break;
  1632. end;
  1633. if changeinit then
  1634. initspecificoptprocessor:=aktspecificoptprocessor;
  1635. end;
  1636. function SetFpuType(const s:string; changeInit: boolean):boolean;
  1637. var
  1638. t : tfputype;
  1639. begin
  1640. SetFpuType:=false;
  1641. for t:=low(tfputype) to high(tfputype) do
  1642. if fputypestr[t]=s then
  1643. begin
  1644. aktfputype:=t;
  1645. SetFpuType:=true;
  1646. break;
  1647. end;
  1648. if changeinit then
  1649. initfputype:=aktfputype;
  1650. end;
  1651. { '('D1:'00000000-'D2:'0000-'D3:'0000-'D4:'0000-000000000000)' }
  1652. function string2guid(const s: string; var GUID: TGUID): boolean;
  1653. function ishexstr(const hs: string): boolean;
  1654. var
  1655. i: integer;
  1656. begin
  1657. ishexstr:=false;
  1658. for i:=1 to Length(hs) do begin
  1659. if not (hs[i] in ['0'..'9','A'..'F','a'..'f']) then
  1660. exit;
  1661. end;
  1662. ishexstr:=true;
  1663. end;
  1664. function hexstr2longint(const hexs: string): longint;
  1665. var
  1666. i: integer;
  1667. rl: longint;
  1668. begin
  1669. rl:=0;
  1670. for i:=1 to length(hexs) do begin
  1671. rl:=rl shl 4;
  1672. case hexs[i] of
  1673. '0'..'9' : inc(rl,ord(hexs[i])-ord('0'));
  1674. 'A'..'F' : inc(rl,ord(hexs[i])-ord('A')+10);
  1675. 'a'..'f' : inc(rl,ord(hexs[i])-ord('a')+10);
  1676. end
  1677. end;
  1678. hexstr2longint:=rl;
  1679. end;
  1680. var
  1681. i: integer;
  1682. begin
  1683. if (Length(s)=38) and (s[1]='{') and (s[38]='}') and
  1684. (s[10]='-') and (s[15]='-') and (s[20]='-') and (s[25]='-') and
  1685. ishexstr(copy(s,2,8)) and ishexstr(copy(s,11,4)) and
  1686. ishexstr(copy(s,16,4)) and ishexstr(copy(s,21,4)) and
  1687. ishexstr(copy(s,26,12)) then begin
  1688. GUID.D1:=dword(hexstr2longint(copy(s,2,8)));
  1689. { these values are arealdy in the correct range (4 chars = word) }
  1690. GUID.D2:=word(hexstr2longint(copy(s,11,4)));
  1691. GUID.D3:=word(hexstr2longint(copy(s,16,4)));
  1692. for i:=0 to 1 do
  1693. GUID.D4[i]:=byte(hexstr2longint(copy(s,21+i*2,2)));
  1694. for i:=2 to 7 do
  1695. GUID.D4[i]:=byte(hexstr2longint(copy(s,22+i*2,2)));
  1696. string2guid:=true;
  1697. end
  1698. else
  1699. string2guid:=false;
  1700. end;
  1701. function guid2string(const GUID: TGUID): string;
  1702. function long2hex(l, len: longint): string;
  1703. const
  1704. hextbl: array[0..15] of char = '0123456789ABCDEF';
  1705. var
  1706. rs: string;
  1707. i: integer;
  1708. begin
  1709. rs[0]:=chr(len);
  1710. for i:=len downto 1 do begin
  1711. rs[i]:=hextbl[l and $F];
  1712. l:=l shr 4;
  1713. end;
  1714. long2hex:=rs;
  1715. end;
  1716. begin
  1717. guid2string:=
  1718. '{'+long2hex(GUID.D1,8)+
  1719. '-'+long2hex(GUID.D2,4)+
  1720. '-'+long2hex(GUID.D3,4)+
  1721. '-'+long2hex(GUID.D4[0],2)+long2hex(GUID.D4[1],2)+
  1722. '-'+long2hex(GUID.D4[2],2)+long2hex(GUID.D4[3],2)+
  1723. long2hex(GUID.D4[4],2)+long2hex(GUID.D4[5],2)+
  1724. long2hex(GUID.D4[6],2)+long2hex(GUID.D4[7],2)+
  1725. '}';
  1726. end;
  1727. function UpdateAlignmentStr(s:string;var a:talignmentinfo):boolean;
  1728. var
  1729. tok : string;
  1730. vstr : string;
  1731. l : longint;
  1732. code : integer;
  1733. b : talignmentinfo;
  1734. begin
  1735. UpdateAlignmentStr:=true;
  1736. uppervar(s);
  1737. fillchar(b,sizeof(b),0);
  1738. repeat
  1739. tok:=GetToken(s,'=');
  1740. if tok='' then
  1741. break;
  1742. vstr:=GetToken(s,',');
  1743. val(vstr,l,code);
  1744. if tok='PROC' then
  1745. b.procalign:=l
  1746. else if tok='JUMP' then
  1747. b.jumpalign:=l
  1748. else if tok='LOOP' then
  1749. b.loopalign:=l
  1750. else if tok='CONSTMIN' then
  1751. b.constalignmin:=l
  1752. else if tok='CONSTMAX' then
  1753. b.constalignmax:=l
  1754. else if tok='VARMIN' then
  1755. b.varalignmin:=l
  1756. else if tok='VARMAX' then
  1757. b.varalignmax:=l
  1758. else if tok='LOCALMIN' then
  1759. b.localalignmin:=l
  1760. else if tok='LOCALMAX' then
  1761. b.localalignmax:=l
  1762. else if tok='RECORDMIN' then
  1763. b.recordalignmin:=l
  1764. else if tok='RECORDMAX' then
  1765. b.recordalignmax:=l
  1766. else { Error }
  1767. UpdateAlignmentStr:=false;
  1768. until false;
  1769. UpdateAlignment(a,b);
  1770. end;
  1771. function var_align(siz: longint): longint;
  1772. begin
  1773. siz := size_2_align(siz);
  1774. var_align := used_align(siz,aktalignment.varalignmin,aktalignment.varalignmax);
  1775. end;
  1776. function const_align(siz: longint): longint;
  1777. begin
  1778. siz := size_2_align(siz);
  1779. const_align := used_align(siz,aktalignment.constalignmin,aktalignment.constalignmax);
  1780. end;
  1781. {****************************************************************************
  1782. Init
  1783. ****************************************************************************}
  1784. {$ifdef unix}
  1785. {$define need_path_search}
  1786. {$endif unix}
  1787. {$ifdef os2}
  1788. {$define need_path_search}
  1789. {$endif os2}
  1790. {$ifdef macos}
  1791. {$define need_path_search}
  1792. {$endif macos}
  1793. procedure get_exepath;
  1794. var
  1795. hs1 : namestr;
  1796. hs2 : extstr;
  1797. {$IFDEF USE_SYSUTILS}
  1798. exeName:String;
  1799. {$ENDIF USE_SYSUTILS}
  1800. {$ifdef need_path_search}
  1801. p : pchar;
  1802. {$endif need_path_search}
  1803. begin
  1804. {$IFDEF USE_SYSUTILS}
  1805. exepath:=GetEnvironmentVariable('PPC_EXEC_PATH');
  1806. {$ELSE USE_SYSUTILS}
  1807. exepath:=dos.getenv('PPC_EXEC_PATH');
  1808. {$ENDIF USE_SYSUTILS}
  1809. if exepath='' then
  1810. {$IFDEF USE_SYSUTILS}
  1811. exeName := FixFileName(system.paramstr(0));
  1812. exepath := ExtractFilePath(exeName);
  1813. hs1 := ExtractFileName(exeName);
  1814. hs2 := ExtractFileExt(exeName);
  1815. {$ELSE USE_SYSUTILS}
  1816. fsplit(FixFileName(system.paramstr(0)),exepath,hs1,hs2);
  1817. {$ENDIF USE_SYSUTILS}
  1818. {$ifdef need_path_search}
  1819. if exepath='' then
  1820. begin
  1821. if pos(source_info.exeext,hs1) <>
  1822. (length(hs1) - length(source_info.exeext)+1) then
  1823. hs1 := hs1 + source_info.exeext;
  1824. {$ifdef macos}
  1825. p:=GetEnvPchar('Commands');
  1826. {$else macos}
  1827. p:=GetEnvPchar('PATH');
  1828. {$endif macos}
  1829. FindFilePChar(hs1,p,exepath);
  1830. FreeEnvPChar(p);
  1831. exepath:=SplitPath(exepath);
  1832. end;
  1833. {$endif need_path_search}
  1834. exepath:=FixPath(exepath,false);
  1835. end;
  1836. procedure DoneGlobals;
  1837. begin
  1838. initdefines.free;
  1839. if assigned(DLLImageBase) then
  1840. StringDispose(DLLImageBase);
  1841. librarysearchpath.Free;
  1842. unitsearchpath.Free;
  1843. objectsearchpath.Free;
  1844. includesearchpath.Free;
  1845. end;
  1846. procedure InitGlobals;
  1847. begin
  1848. get_exepath;
  1849. { reset globals }
  1850. do_build:=false;
  1851. do_release:=false;
  1852. do_make:=true;
  1853. compile_level:=0;
  1854. DLLsource:=false;
  1855. inlining_procedure:=false;
  1856. resolving_forward:=false;
  1857. make_ref:=false;
  1858. LinkTypeSetExplicitly:=false;
  1859. { Output }
  1860. OutputFile:='';
  1861. OutputPrefix:=Nil;
  1862. OutputSuffix:=Nil;
  1863. OutputExtension:='';
  1864. OutputExeDir:='';
  1865. OutputUnitDir:='';
  1866. { Utils directory }
  1867. utilsdirectory:='';
  1868. utilsprefix:='';
  1869. cshared:=false;
  1870. rlinkpath:='';
  1871. { Search Paths }
  1872. librarysearchpath:=TSearchPathList.Create;
  1873. unitsearchpath:=TSearchPathList.Create;
  1874. includesearchpath:=TSearchPathList.Create;
  1875. objectsearchpath:=TSearchPathList.Create;
  1876. { Def file }
  1877. usewindowapi:=false;
  1878. description:='Compiled by FPC '+version_string+' - '+target_cpu_string;
  1879. DescriptionSetExplicity:=false;
  1880. dllversion:='';
  1881. dllmajor:=1;
  1882. dllminor:=0;
  1883. dllrevision:=0;
  1884. nwscreenname := '';
  1885. nwthreadname := '';
  1886. nwcopyright := '';
  1887. UseDeffileForExports:=false;
  1888. UseDeffileForExportsSetExplicitly:=false;
  1889. RelocSection:=false;
  1890. RelocSectionSetExplicitly:=false;
  1891. LinkTypeSetExplicitly:=false;
  1892. { Init values }
  1893. initmodeswitches:=fpcmodeswitches;
  1894. initlocalswitches:=[cs_check_io,cs_typed_const_writable];
  1895. initmoduleswitches:=[cs_extsyntax,cs_implicit_exceptions];
  1896. initsourcecodepage:='8859-1';
  1897. initglobalswitches:=[cs_check_unit_name,cs_link_static{$ifdef INTERNALLINKER},cs_link_internal,cs_link_map{$endif}];
  1898. initoutputformat:=target_asm.id;
  1899. fillchar(initalignment,sizeof(talignmentinfo),0);
  1900. { might be overridden later }
  1901. initasmmode:=asmmode_standard;
  1902. {$ifdef i386}
  1903. initoptprocessor:=ClassPentium3;
  1904. initspecificoptprocessor:=Class386;
  1905. initfputype:=fpu_x87;
  1906. initpackenum:=4;
  1907. {$IFDEF testvarsets}
  1908. initsetalloc:=0;
  1909. {$ENDIF}
  1910. initasmmode:=asmmode_i386_att;
  1911. {$endif i386}
  1912. {$ifdef m68k}
  1913. initoptprocessor:=MC68020;
  1914. initpackenum:=4;
  1915. {$IFDEF testvarsets}
  1916. initsetalloc:=0;
  1917. {$ENDIF}
  1918. {$endif m68k}
  1919. {$ifdef powerpc}
  1920. initoptprocessor:=PPC604;
  1921. initpackenum:=4;
  1922. {$IFDEF testvarsets}
  1923. initsetalloc:=0;
  1924. {$ENDIF}
  1925. initfputype:=fpu_standard;
  1926. {$endif powerpc}
  1927. {$ifdef sparc}
  1928. initoptprocessor:=SPARC_V8;
  1929. initpackenum:=4;
  1930. {$IFDEF testvarsets}
  1931. initsetalloc:=0;
  1932. {$ENDIF}
  1933. {$endif sparc}
  1934. {$ifdef arm}
  1935. initpackenum:=4;
  1936. {$IFDEF testvarsets}
  1937. initsetalloc:=0;
  1938. {$ENDIF}
  1939. initfputype:=fpu_fpa;
  1940. {$endif arm}
  1941. {$ifdef x86_64}
  1942. initoptprocessor:=ClassAthlon64;
  1943. initspecificoptprocessor:=ClassAthlon64;
  1944. initfputype:=fpu_sse64;
  1945. initpackenum:=4;
  1946. {$IFDEF testvarsets}
  1947. initsetalloc:=0;
  1948. {$ENDIF}
  1949. initasmmode:=asmmode_x86_64_gas;
  1950. {$endif x86_64}
  1951. initinterfacetype:=it_interfacecom;
  1952. initdefproccall:=pocall_default;
  1953. initdefines:=TStringList.Create;
  1954. { memory sizes, will be overriden by parameter or default for target
  1955. in options or init_parser }
  1956. stacksize:=0;
  1957. apptype:=app_cui;
  1958. end;
  1959. end.
  1960. {
  1961. $Log$
  1962. Revision 1.159 2005-01-06 13:40:41 florian
  1963. * 1.0.10 starting patch from Peter
  1964. Revision 1.158 2005/01/06 09:20:36 karoly
  1965. * made Shell() work correctly on MorphOS
  1966. Revision 1.157 2005/01/04 17:40:33 karoly
  1967. + sysv style syscalls added for MorphOS
  1968. Revision 1.156 2005/01/04 16:20:51 florian
  1969. * fixed nan et al. handling on arm
  1970. Revision 1.155 2004/12/28 20:43:01 hajny
  1971. * 8.3 fixes (short target name in paths)
  1972. Revision 1.154 2004/12/15 16:06:47 marco
  1973. * introduction "cleanpath" (=fexpand), fixfilename(paramstr(0)) + search $PREFIX/etc/fpc.cfg
  1974. Revision 1.153 2004/11/05 13:14:30 florian
  1975. * fixed arm compilation
  1976. Revision 1.152 2004/10/31 21:45:02 peter
  1977. * generic tlocation
  1978. * move tlocation to cgutils
  1979. Revision 1.151 2004/10/31 19:09:54 peter
  1980. * default paths fixed
  1981. Revision 1.150 2004/10/31 18:54:24 peter
  1982. * $fpctarget expands to <cpu>-<os>
  1983. * allow * in middle of the path to support ../*/units/$fpctarget
  1984. Revision 1.149 2004/10/26 15:11:01 peter
  1985. * -Ch for heapsize added again
  1986. * __heapsize contains the heapsize
  1987. Revision 1.148 2004/10/25 15:38:41 peter
  1988. * heap and heapsize removed
  1989. * checkpointer fixes
  1990. Revision 1.147 2004/10/16 22:46:14 olle
  1991. * Fixed printing of filedates
  1992. Revision 1.146 2004/10/16 13:03:13 olle
  1993. + added more support for macos
  1994. Revision 1.145 2004/10/15 09:14:16 mazen
  1995. - remove $IFDEF DELPHI and related code
  1996. - remove $IFDEF FPCPROCVAR and related code
  1997. Revision 1.144 2004/10/14 18:16:17 mazen
  1998. * USE_SYSUTILS merged successfully : cycles with and without defines
  1999. * Need to be optimized in performance
  2000. Revision 1.143 2004/10/10 15:42:22 peter
  2001. * default optimization cpu changed to CLassPentium3
  2002. Revision 1.142 2004/10/09 11:27:59 olle
  2003. + Added CurDirRelPath
  2004. * Exchanged hardcoded "./" to CurDirRelPath
  2005. Revision 1.141 2004/09/21 23:33:43 hajny
  2006. * better PathExists, fix for too long command line, correction of message
  2007. Revision 1.140 2004/09/21 19:59:51 peter
  2008. * x86_64 fixes
  2009. * cleanup of fpcdefs.icn
  2010. Revision 1.139 2004/09/21 17:25:12 peter
  2011. * paraloc branch merged
  2012. Revision 1.138 2004/09/08 11:23:31 michael
  2013. + Check if outputdir exists, Fix exitcode when displaying help pages
  2014. Revision 1.137 2004/08/31 22:02:30 olle
  2015. + support for quoting of paths in TSearchPathList.AddPath so that
  2016. compiler directives which take paths, will support quotes.
  2017. * uppdated TranslateMacPath
  2018. Revision 1.136.4.2 2004/09/12 18:31:26 peter
  2019. * fpu exception support for sparc and x86_64
  2020. Revision 1.136.4.1 2004/09/12 15:30:16 peter
  2021. * cache currentdir
  2022. Revision 1.136 2004/08/28 20:25:25 peter
  2023. * optimized search for noncasesensitive names. It now searches
  2024. first for NormalCase and skips double tests
  2025. Revision 1.135 2004/08/20 10:29:31 olle
  2026. + made fpc work as an MPW tool, by itself calling asm and link.
  2027. * bugfix in fp exception flag settings routine
  2028. Revision 1.134 2004/08/02 07:15:54 michael
  2029. + Patch from Christian Iversen to implement LIBPREFIX/SUFFIX/EXTENSION directives
  2030. Revision 1.133 2004/07/17 15:51:57 jonas
  2031. * shell now returns an exitcode
  2032. * print an error if linking failed when linking was done using a script
  2033. Revision 1.132 2004/07/05 23:28:24 olle
  2034. + FixFileName now handles Mac OS paths
  2035. Revision 1.131 2004/06/20 08:55:29 florian
  2036. * logs truncated
  2037. Revision 1.130 2004/06/16 20:07:07 florian
  2038. * dwarf branch merged
  2039. Revision 1.129 2004/05/11 18:20:52 olle
  2040. * changed $mode mac to $mode macpas
  2041. * changed macmodeswitches to be more faithful to the mac dialect
  2042. Revision 1.128 2004/04/29 19:56:36 daniel
  2043. * Prepare compiler infrastructure for multiple ansistring types
  2044. Revision 1.127 2004/04/28 15:19:03 florian
  2045. + syscall directive support for MorphOS added
  2046. Revision 1.126.2.4 2004/05/09 15:47:21 peter
  2047. * fix typecast from word->set
  2048. }