globals.pas 65 KB

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