globals.pas 64 KB

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