globals.pas 63 KB

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