globals.pas 63 KB

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