globals.pas 64 KB

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