globals.pas 67 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by Florian Klaempfl
  4. This unit implements some support functions and global variables
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit globals;
  19. {$i fpcdefs.inc}
  20. { Use the internal linker by default }
  21. { define INTERNALLINKER}
  22. interface
  23. uses
  24. {$ifdef win32}
  25. windows,
  26. {$endif}
  27. {$ifdef hasunix}
  28. {$ifdef havelinuxrtl10}
  29. linux,
  30. {$else}
  31. Baseunix,unix,
  32. {$endif}
  33. {$endif}
  34. {$IFDEF USE_SYSUTILS}
  35. 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];
  58. macmodeswitches : tmodeswitches=
  59. [m_mac,m_all,m_result,m_repeat_forward,m_cvar_support,m_tp_procvar];
  60. { maximum number of locals in bytes before warning is emitted }
  61. maxlocalsize = high(smallint);
  62. { maximum number of paras in bytes before warning is emitted }
  63. maxparasize = high(word);
  64. { maximum nesting of routines }
  65. maxnesting = 32;
  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 CPU_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 CPU_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 CPU_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. paralinkoptions,
  120. paradynamiclinker : string;
  121. paraprintnodetree : byte;
  122. parapreprocess : boolean;
  123. printnodefile : text;
  124. { typical cross compiling params}
  125. { directory where the utils can be found (options -FD) }
  126. utilsdirectory : dirstr;
  127. { targetname specific prefix used by these utils (options -XP<path>) }
  128. utilsprefix : dirstr;
  129. cshared : boolean; { pass --shared to ld to link C libs shared}
  130. Dontlinkstdlibpath: Boolean; { Don't add std paths to linkpath}
  131. rlinkpath : dirstr; { rpath-link linkdir override}
  132. { some flags for global compiler switches }
  133. do_build,
  134. do_release,
  135. do_make : boolean;
  136. { path for searching units, different paths can be seperated by ; }
  137. exepath : dirstr; { Path to ppc }
  138. librarysearchpath,
  139. unitsearchpath,
  140. objectsearchpath,
  141. includesearchpath : TSearchPathList;
  142. { linking }
  143. usewindowapi : boolean;
  144. description : string;
  145. DescriptionSetExplicity : boolean;
  146. dllversion : string;
  147. dllmajor,
  148. dllminor,
  149. dllrevision : word; { revision only for netware }
  150. UseDeffileForExports : boolean;
  151. UseDeffileForExportsSetExplicitly : boolean;
  152. RelocSection : boolean;
  153. RelocSectionSetExplicitly : boolean;
  154. LinkTypeSetExplicitly : boolean;
  155. akttokenpos, { position of the last token }
  156. aktfilepos : tfileposinfo; { current position }
  157. nwscreenname : string;
  158. nwthreadname : string;
  159. nwcopyright : string;
  160. codegenerror : boolean; { true if there is an error reported }
  161. block_type : tblock_type; { type of currently parsed block }
  162. parsing_para_level : integer; { parameter level, used to convert
  163. proc calls to proc loads in firstcalln }
  164. compile_level : word;
  165. make_ref : boolean;
  166. resolving_forward : boolean; { used to add forward reference as second ref }
  167. inlining_procedure : boolean; { are we inlining a procedure }
  168. exceptblockcounter : integer; { each except block gets a unique number check gotos }
  169. aktexceptblock : integer; { the exceptblock number of the current block (0 if none) }
  170. { commandline values }
  171. initglobalswitches : tglobalswitches;
  172. initmoduleswitches : tmoduleswitches;
  173. initlocalswitches : tlocalswitches;
  174. initmodeswitches : tmodeswitches;
  175. {$IFDEF testvarsets}
  176. Initsetalloc, {0=fixed, 1 =var}
  177. {$ENDIF}
  178. initpackenum : shortint;
  179. {$ifdef ansistring_bits}
  180. initansistring_bits: Tstringbits;
  181. {$endif}
  182. initalignment : talignmentinfo;
  183. initoptprocessor,
  184. initspecificoptprocessor : tprocessors;
  185. initfputype : tfputype;
  186. initasmmode : tasmmode;
  187. initinterfacetype : tinterfacetypes;
  188. initoutputformat : tasm;
  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. {$ifdef ansistring_bits}
  204. aktansistring_bits : Tstringbits;
  205. {$endif}
  206. aktmaxfpuregisters : longint;
  207. aktalignment : talignmentinfo;
  208. aktoptprocessor,
  209. aktspecificoptprocessor : tprocessors;
  210. aktfputype : tfputype;
  211. aktasmmode : tasmmode;
  212. aktinterfacetype : tinterfacetypes;
  213. aktoutputformat : tasm;
  214. aktdefproccall : tproccalloption;
  215. aktsourcecodepage : tcodepagestring;
  216. { Memory sizes }
  217. heapsize,
  218. stacksize,
  219. jmp_buf_size : longint;
  220. {$Ifdef EXTDEBUG}
  221. { parameter switches }
  222. debugstop : boolean;
  223. {$EndIf EXTDEBUG}
  224. { windows / OS/2 application type }
  225. apptype : tapptype;
  226. const
  227. DLLsource : boolean = false;
  228. DLLImageBase : pstring = nil;
  229. { used to set all registers used for each global function
  230. this should dramatically decrease the number of
  231. recompilations needed PM }
  232. simplify_ppu : boolean = true;
  233. { should we allow non static members ? }
  234. allow_only_static : boolean = false;
  235. Inside_asm_statement : boolean = false;
  236. global_unit_count : word = 0;
  237. { for error info in pp.pas }
  238. parser_current_file : string = '';
  239. {$ifdef m68k}
  240. { PalmOS resources }
  241. palmos_applicationname : string = 'FPC Application';
  242. palmos_applicationid : string[4] = 'FPCA';
  243. {$endif m68k}
  244. {$ifdef powerpc}
  245. { default calling convention used on MorphOS }
  246. syscall_convention : string = 'LEGACY';
  247. {$endif powerpc}
  248. procedure abstract;
  249. function bstoslash(const s : string) : string;
  250. function getdatestr:string;
  251. function gettimestr:string;
  252. function filetimestring( t : longint) : string;
  253. procedure DefaultReplacements(var s:string);
  254. {Gives the absolute path to the current directory}
  255. function GetCurrentDir:string;
  256. {Gives the relative path to the current directory,
  257. with a trailing dir separator. E. g. on unix ./ }
  258. function CurDirRelPath(systeminfo: tsysteminfo): string;
  259. function path_absolute(const s : string) : boolean;
  260. Function PathExists ( F : String) : Boolean;
  261. Function FileExists ( 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. Function SetCompileMode(const s:string; changeInit: boolean):boolean;
  290. function SetAktProcCall(const s:string; changeInit: boolean):boolean;
  291. function SetProcessor(const s:string; changeInit: boolean):boolean;
  292. function SetFpuType(const s:string; changeInit: boolean):boolean;
  293. procedure InitGlobals;
  294. procedure DoneGlobals;
  295. function string2guid(const s: string; var GUID: TGUID): boolean;
  296. function guid2string(const GUID: TGUID): string;
  297. function UpdateAlignmentStr(s:string;var a:talignmentinfo):boolean;
  298. {# Routine to get the required alignment for size of data, which will
  299. be placed in bss segment, according to the current alignment requirements }
  300. function var_align(siz: longint): longint;
  301. {# Routine to get the required alignment for size of data, which will
  302. be placed in data/const segment, according to the current alignment requirements }
  303. function const_align(siz: longint): longint;
  304. {$IFDEF MACOS}
  305. {Since SysUtils is not yet available for MacOS, fake
  306. Exceptions classes are included here.}
  307. {$DEFINE MACOS_USE_FAKE_SYSUTILS}
  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}
  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 FileExistsNonCase(const path,fn:string;var foundfile:string):boolean;
  528. var
  529. fn2 : string;
  530. begin
  531. result:=false;
  532. if source_info.files_case_relevent then
  533. begin
  534. {
  535. Search order for case sensitive systems:
  536. 1. NormalCase
  537. 2. lowercase
  538. 3. UPPERCASE
  539. }
  540. FoundFile:=path+fn;
  541. If FileExists(FoundFile) then
  542. begin
  543. result:=true;
  544. exit;
  545. end;
  546. fn2:=Lower(fn);
  547. if fn2<>fn then
  548. begin
  549. FoundFile:=path+fn2;
  550. If FileExists(FoundFile) then
  551. begin
  552. result:=true;
  553. exit;
  554. end;
  555. end;
  556. fn2:=Upper(fn);
  557. if fn2<>fn then
  558. begin
  559. FoundFile:=path+fn2;
  560. If FileExists(FoundFile) then
  561. begin
  562. result:=true;
  563. exit;
  564. end;
  565. end;
  566. end
  567. else
  568. begin
  569. { None case sensitive only lowercase }
  570. FoundFile:=path+Lower(fn);
  571. If FileExists(FoundFile) then
  572. begin
  573. result:=true;
  574. exit;
  575. end;
  576. end;
  577. { Set foundfile to something usefull }
  578. FoundFile:=fn;
  579. end;
  580. Function PathExists ( F : String) : Boolean;
  581. Var
  582. {$IFDEF USE_SYSUTILS}
  583. {$ELSE USE_SYSUTILS}
  584. FF : file;
  585. {$ENDIF USE_SYSUTILS}
  586. A: word;
  587. I: longint;
  588. begin
  589. if F = '' then
  590. begin
  591. PathExists := true;
  592. exit;
  593. end;
  594. F := FExpand (F);
  595. I := Pos (DriveSeparator, F);
  596. if (F [Length (F)] = DirectorySeparator)
  597. and (((I = 0) and (Length (F) > 1)) or (I <> Length (F) - 1))
  598. then
  599. Delete (F, Length (F), 1);
  600. {$IFDEF USE_SYSUTILS}
  601. PathExists := FileGetAttr(F) and faDirectory = faDirectory;
  602. {$ELSE USE_SYSUTILS}
  603. Assign (FF, FExpand (F));
  604. GetFAttr (FF, A);
  605. PathExists := (DosError = 0) and (A and Directory = Directory);
  606. {$ENDIF USE_SYSUTILS}
  607. end;
  608. Function RemoveFile(const f:string):boolean;
  609. var
  610. g : file;
  611. begin
  612. assign(g,f);
  613. {$I-}
  614. erase(g);
  615. {$I+}
  616. RemoveFile:=(ioresult=0);
  617. end;
  618. Function RemoveDir(d:string):boolean;
  619. begin
  620. if d[length(d)]=source_info.DirSep then
  621. Delete(d,length(d),1);
  622. {$I-}
  623. rmdir(d);
  624. {$I+}
  625. RemoveDir:=(ioresult=0);
  626. end;
  627. Function SplitPath(const s:string):string;
  628. var
  629. i : longint;
  630. begin
  631. i:=Length(s);
  632. {$ifdef macos}
  633. while (i>0) and not(s[i] in [':']) do
  634. dec(i);
  635. {$else macos}
  636. while (i>0) and not(s[i] in ['/','\']) do
  637. dec(i);
  638. {$endif macos}
  639. SplitPath:=Copy(s,1,i);
  640. end;
  641. Function SplitFileName(const s:string):string;
  642. {$IFDEF USE_SYSUTILS}
  643. {$ELSE USE_SYSUTILS}
  644. var
  645. p : dirstr;
  646. n : namestr;
  647. e : extstr;
  648. {$ENDIF USE_SYSUTILS}
  649. begin
  650. {$IFDEF USE_SYSUTILS}
  651. SplitFileName:=ExtractFileName(s);
  652. {$ELSE USE_SYSUTILS}
  653. FSplit(s,p,n,e);
  654. SplitFileName:=n+e;
  655. {$ENDIF USE_SYSUTILS}
  656. end;
  657. Function SplitName(const s:string):string;
  658. var
  659. i,j : longint;
  660. begin
  661. i:=Length(s);
  662. j:=Length(s);
  663. while (i>0) and not(s[i] in ['/','\']) do
  664. dec(i);
  665. while (j>0) and (s[j]<>'.') do
  666. dec(j);
  667. if j<=i then
  668. j:=255;
  669. SplitName:=Copy(s,i+1,j-(i+1));
  670. end;
  671. Function SplitExtension(Const HStr:String):String;
  672. var
  673. j : longint;
  674. begin
  675. j:=length(Hstr);
  676. while (j>0) and (Hstr[j]<>'.') do
  677. begin
  678. if hstr[j]=source_info.DirSep then
  679. j:=0
  680. else
  681. dec(j);
  682. end;
  683. if j=0 then
  684. j:=254;
  685. SplitExtension:=Copy(Hstr,j,255);
  686. end;
  687. Function AddExtension(Const HStr,ext:String):String;
  688. begin
  689. if (Ext<>'') and (SplitExtension(HStr)='') then
  690. AddExtension:=Hstr+Ext
  691. else
  692. AddExtension:=Hstr;
  693. end;
  694. Function ForceExtension(Const HStr,ext:String):String;
  695. var
  696. j : longint;
  697. begin
  698. j:=length(Hstr);
  699. while (j>0) and (Hstr[j]<>'.') do
  700. dec(j);
  701. if j=0 then
  702. j:=255;
  703. ForceExtension:=Copy(Hstr,1,j-1)+Ext;
  704. end;
  705. Function FixPath(s:string;allowdot:boolean):string;
  706. var
  707. i : longint;
  708. begin
  709. { Fix separator }
  710. for i:=1 to length(s) do
  711. if s[i] in ['/','\'] then
  712. s[i]:=source_info.DirSep;
  713. { Fix ending / }
  714. if (length(s)>0) and (s[length(s)]<>source_info.DirSep) and
  715. (s[length(s)]<>':') then
  716. s:=s+source_info.DirSep;
  717. { Remove ./ }
  718. if (not allowdot) and (s='.'+source_info.DirSep) then
  719. s:='';
  720. { return }
  721. if source_info.files_case_relevent then
  722. FixPath:=s
  723. else
  724. FixPath:=Lower(s);
  725. end;
  726. {Actually the version in macutils.pp could be used,
  727. but that would not work for crosscompiling, so this is a slightly modified
  728. version of it.}
  729. function TranslatePathToMac (const path: string; mpw: Boolean): string;
  730. function GetVolumeIdentifier: string;
  731. begin
  732. GetVolumeIdentifier := '{Boot}'
  733. (*
  734. if mpw then
  735. GetVolumeIdentifier := '{Boot}'
  736. else
  737. GetVolumeIdentifier := macosBootVolumeName;
  738. *)
  739. end;
  740. var
  741. slashPos, oldpos, newpos, oldlen, maxpos: Longint;
  742. begin
  743. oldpos := 1;
  744. slashPos := Pos('/', path);
  745. if (slashPos <> 0) then {its a unix path}
  746. begin
  747. if slashPos = 1 then
  748. begin {its a full path}
  749. oldpos := 2;
  750. TranslatePathToMac := GetVolumeIdentifier;
  751. end
  752. else {its a partial path}
  753. TranslatePathToMac := ':';
  754. end
  755. else
  756. begin
  757. slashPos := Pos('\', path);
  758. if (slashPos <> 0) then {its a dos path}
  759. begin
  760. if slashPos = 1 then
  761. begin {its a full path, without drive letter}
  762. oldpos := 2;
  763. TranslatePathToMac := GetVolumeIdentifier;
  764. end
  765. else if (Length(path) >= 2) and (path[2] = ':') then {its a full path, with drive letter}
  766. begin
  767. oldpos := 4;
  768. TranslatePathToMac := GetVolumeIdentifier;
  769. end
  770. else {its a partial path}
  771. TranslatePathToMac := ':';
  772. end;
  773. end;
  774. if (slashPos <> 0) then {its a unix or dos path}
  775. begin
  776. {Translate "/../" to "::" , "/./" to ":" and "/" to ":" }
  777. newpos := Length(TranslatePathToMac);
  778. oldlen := Length(path);
  779. SetLength(TranslatePathToMac, newpos + oldlen); {It will be no longer than what is already}
  780. {prepended plus length of path.}
  781. maxpos := Length(TranslatePathToMac); {Get real maxpos, can be short if String is ShortString}
  782. {There is never a slash in the beginning, because either it was an absolute path, and then the}
  783. {drive and slash was removed, or it was a relative path without a preceding slash.}
  784. while oldpos <= oldlen do
  785. begin
  786. {Check if special dirs, ./ or ../ }
  787. if path[oldPos] = '.' then
  788. if (oldpos + 1 <= oldlen) and (path[oldPos + 1] = '.') then
  789. begin
  790. if (oldpos + 2 > oldlen) or (path[oldPos + 2] in ['/', '\']) then
  791. begin
  792. {It is "../" or ".." translates to ":" }
  793. if newPos = maxPos then
  794. begin {Shouldn't actually happen, but..}
  795. Exit('');
  796. end;
  797. newPos := newPos + 1;
  798. TranslatePathToMac[newPos] := ':';
  799. oldPos := oldPos + 3;
  800. continue; {Start over again}
  801. end;
  802. end
  803. else if (oldpos + 1 > oldlen) or (path[oldPos + 1] in ['/', '\']) then
  804. begin
  805. {It is "./" or "." ignor it }
  806. oldPos := oldPos + 2;
  807. continue; {Start over again}
  808. end;
  809. {Collect file or dir name}
  810. while (oldpos <= oldlen) and not (path[oldPos] in ['/', '\']) do
  811. begin
  812. if newPos = maxPos then
  813. begin {Shouldn't actually happen, but..}
  814. Exit('');
  815. end;
  816. newPos := newPos + 1;
  817. TranslatePathToMac[newPos] := path[oldPos];
  818. oldPos := oldPos + 1;
  819. end;
  820. {When we come here there is either a slash or we are at the end.}
  821. if (oldpos <= oldlen) then
  822. begin
  823. if newPos = maxPos then
  824. begin {Shouldn't actually happen, but..}
  825. Exit('');
  826. end;
  827. newPos := newPos + 1;
  828. TranslatePathToMac[newPos] := ':';
  829. oldPos := oldPos + 1;
  830. end;
  831. end;
  832. SetLength(TranslatePathToMac, newpos);
  833. end
  834. else if (path = '.') then
  835. TranslatePathToMac := ':'
  836. else if (path = '..') then
  837. TranslatePathToMac := '::'
  838. else
  839. TranslatePathToMac := path; {its a mac path}
  840. end;
  841. function FixFileName(const s:string):string;
  842. var
  843. i : longint;
  844. begin
  845. if source_info.system = system_powerpc_MACOS then
  846. FixFileName:= TranslatePathToMac(s, true)
  847. else if source_info.files_case_relevent then
  848. begin
  849. for i:=1 to length(s) do
  850. begin
  851. case s[i] of
  852. '/','\' :
  853. FixFileName[i]:=source_info.dirsep;
  854. else
  855. FixFileName[i]:=s[i];
  856. end;
  857. end;
  858. FixFileName[0]:=s[0];
  859. end
  860. else
  861. begin
  862. for i:=1 to length(s) do
  863. begin
  864. case s[i] of
  865. '/','\' :
  866. FixFileName[i]:=source_info.dirsep;
  867. 'A'..'Z' :
  868. FixFileName[i]:=char(byte(s[i])+32);
  869. else
  870. FixFileName[i]:=s[i];
  871. end;
  872. end;
  873. FixFileName[0]:=s[0];
  874. end;
  875. end;
  876. Function TargetFixPath(s:string;allowdot:boolean):string;
  877. var
  878. i : longint;
  879. begin
  880. { Fix separator }
  881. for i:=1 to length(s) do
  882. if s[i] in ['/','\'] then
  883. s[i]:=target_info.DirSep;
  884. { Fix ending / }
  885. if (length(s)>0) and (s[length(s)]<>target_info.DirSep) and
  886. (s[length(s)]<>':') then
  887. s:=s+target_info.DirSep;
  888. { Remove ./ }
  889. if (not allowdot) and (s='.'+target_info.DirSep) then
  890. s:='';
  891. { return }
  892. if target_info.files_case_relevent then
  893. TargetFixPath:=s
  894. else
  895. TargetFixPath:=Lower(s);
  896. end;
  897. function TargetFixFileName(const s:string):string;
  898. var
  899. i : longint;
  900. begin
  901. if target_info.system = system_powerpc_MACOS then
  902. TargetFixFileName:= TranslatePathToMac(s, true)
  903. else if target_info.files_case_relevent then
  904. begin
  905. for i:=1 to length(s) do
  906. begin
  907. case s[i] of
  908. '/','\' :
  909. TargetFixFileName[i]:=target_info.dirsep;
  910. else
  911. TargetFixFileName[i]:=s[i];
  912. end;
  913. end;
  914. TargetFixFileName[0]:=s[0];
  915. end
  916. else
  917. begin
  918. for i:=1 to length(s) do
  919. begin
  920. case s[i] of
  921. '/','\' :
  922. TargetFixFileName[i]:=target_info.dirsep;
  923. 'A'..'Z' :
  924. TargetFixFileName[i]:=char(byte(s[i])+32);
  925. else
  926. TargetFixFileName[i]:=s[i];
  927. end;
  928. end;
  929. TargetFixFileName[0]:=s[0];
  930. end;
  931. end;
  932. procedure SplitBinCmd(const s:string;var bstr:String;var cstr:TCmdStr);
  933. var
  934. i : longint;
  935. begin
  936. i:=pos(' ',s);
  937. if i>0 then
  938. begin
  939. bstr:=Copy(s,1,i-1);
  940. cstr:=Copy(s,i+1,length(s)-i);
  941. end
  942. else
  943. begin
  944. bstr:=s;
  945. cstr:='';
  946. end;
  947. end;
  948. procedure TSearchPathList.AddPath(s:string;addfirst:boolean);
  949. begin
  950. AddPath('',s,AddFirst);
  951. end;
  952. procedure TSearchPathList.AddPath(SrcPath,s:string;addfirst:boolean);
  953. var
  954. staridx,
  955. j : longint;
  956. prefix,
  957. suffix,
  958. CurrentDir,
  959. currPath : string;
  960. subdirfound : boolean;
  961. {$IFDEF USE_SYSUTILS}
  962. dir : TSearchRec;
  963. {$ELSE USE_SYSUTILS}
  964. dir : searchrec;
  965. {$ENDIF USE_SYSUTILS}
  966. hp : TStringListItem;
  967. procedure AddCurrPath;
  968. begin
  969. if addfirst then
  970. begin
  971. Remove(currPath);
  972. Insert(currPath);
  973. end
  974. else
  975. begin
  976. { Check if already in path, then we don't add it }
  977. hp:=Find(currPath);
  978. if not assigned(hp) then
  979. Concat(currPath);
  980. end;
  981. end;
  982. begin
  983. if s='' then
  984. exit;
  985. { Support default macro's }
  986. DefaultReplacements(s);
  987. { get current dir }
  988. CurrentDir:=GetCurrentDir;
  989. repeat
  990. { get currpath }
  991. if addfirst then
  992. begin
  993. j:=length(s);
  994. while (j>0) and (s[j]<>';') do
  995. dec(j);
  996. currPath:= TrimSpace(Copy(s,j+1,length(s)-j));
  997. DePascalQuote(currPath);
  998. currPath:=FixPath(currPath,false);
  999. if j=0 then
  1000. s:=''
  1001. else
  1002. System.Delete(s,j,length(s)-j+1);
  1003. end
  1004. else
  1005. begin
  1006. j:=Pos(';',s);
  1007. if j=0 then
  1008. j:=255;
  1009. currPath:= TrimSpace(Copy(s,1,j-1));
  1010. DePascalQuote(currPath);
  1011. currPath:=SrcPath+FixPath(currPath,false);
  1012. System.Delete(s,1,j);
  1013. end;
  1014. { fix pathname }
  1015. if currPath='' then
  1016. currPath:= CurDirRelPath(source_info)
  1017. else
  1018. begin
  1019. currPath:=FixPath(FExpand(currPath),false);
  1020. if (CurrentDir<>'') and (Copy(currPath,1,length(CurrentDir))=CurrentDir) then
  1021. begin
  1022. {$ifdef AMIGA}
  1023. currPath:= CurrentDir+Copy(currPath,length(CurrentDir)+1,255);
  1024. {$else}
  1025. currPath:= CurDirRelPath(source_info)+Copy(currPath,length(CurrentDir)+1,255);
  1026. {$endif}
  1027. end;
  1028. end;
  1029. { wildcard adding ? }
  1030. staridx:=pos('*',currpath);
  1031. if staridx>0 then
  1032. begin
  1033. prefix:=SplitPath(Copy(currpath,1,staridx));
  1034. suffix:=Copy(currpath,staridx+1,length(currpath));
  1035. subdirfound:=false;
  1036. {$IFDEF USE_SYSUTILS}
  1037. if findfirst(prefix+'*',faDirectory,dir) = 0 then
  1038. begin
  1039. repeat
  1040. if (dir.name<>'.') and
  1041. (dir.name<>'..') and
  1042. ((dir.attr and faDirectory)<>0) then
  1043. begin
  1044. subdirfound:=true;
  1045. currpath:=prefix+dir.name+suffix;
  1046. if (suffix='') or PathExists(currpath) then
  1047. begin
  1048. hp:=Find(currPath);
  1049. if not assigned(hp) then
  1050. AddCurrPath;
  1051. end;
  1052. end;
  1053. until findnext(dir) <> 0;
  1054. end
  1055. {$ELSE USE_SYSUTILS}
  1056. findfirst(prefix+'*',directory,dir);
  1057. while doserror=0 do
  1058. begin
  1059. if (dir.name<>'.') and
  1060. (dir.name<>'..') and
  1061. ((dir.attr and directory)<>0) then
  1062. begin
  1063. subdirfound:=true;
  1064. currpath:=prefix+dir.name+suffix;
  1065. if (suffix='') or PathExists(currpath) then
  1066. begin
  1067. hp:=Find(currPath);
  1068. if not assigned(hp) then
  1069. AddCurrPath;
  1070. end;
  1071. end;
  1072. findnext(dir);
  1073. end;
  1074. {$ENDIF USE_SYSUTILS}
  1075. FindClose(dir);
  1076. if not subdirfound then
  1077. WarnNonExistingPath(currpath);
  1078. end
  1079. else
  1080. begin
  1081. if PathExists(currpath) then
  1082. AddCurrPath
  1083. else
  1084. WarnNonExistingPath(currpath);
  1085. end;
  1086. until (s='');
  1087. end;
  1088. procedure TSearchPathList.AddList(list:TSearchPathList;addfirst:boolean);
  1089. var
  1090. s : string;
  1091. hl : TSearchPathList;
  1092. hp,hp2 : TStringListItem;
  1093. begin
  1094. if list.empty then
  1095. exit;
  1096. { create temp and reverse the list }
  1097. if addfirst then
  1098. begin
  1099. hl:=TSearchPathList.Create;
  1100. hp:=TStringListItem(list.first);
  1101. while assigned(hp) do
  1102. begin
  1103. hl.insert(hp.Str);
  1104. hp:=TStringListItem(hp.next);
  1105. end;
  1106. while not hl.empty do
  1107. begin
  1108. s:=hl.GetFirst;
  1109. Remove(s);
  1110. Insert(s);
  1111. end;
  1112. hl.Free;
  1113. end
  1114. else
  1115. begin
  1116. hp:=TStringListItem(list.first);
  1117. while assigned(hp) do
  1118. begin
  1119. hp2:=Find(hp.Str);
  1120. { Check if already in path, then we don't add it }
  1121. if not assigned(hp2) then
  1122. Concat(hp.Str);
  1123. hp:=TStringListItem(hp.next);
  1124. end;
  1125. end;
  1126. end;
  1127. function TSearchPathList.FindFile(const f : string;var foundfile:string):boolean;
  1128. Var
  1129. p : TStringListItem;
  1130. begin
  1131. FindFile:=false;
  1132. p:=TStringListItem(first);
  1133. while assigned(p) do
  1134. begin
  1135. result:=FileExistsNonCase(p.Str,f,FoundFile);
  1136. if result then
  1137. exit;
  1138. p:=TStringListItem(p.next);
  1139. end;
  1140. { Return original filename if not found }
  1141. FoundFile:=f;
  1142. end;
  1143. Function GetFileTime ( Var F : File) : Longint;
  1144. Var
  1145. {$ifdef hasunix}
  1146. info: Stat;
  1147. {$endif}
  1148. L : longint;
  1149. begin
  1150. {$ifdef hasunix}
  1151. {$IFDEF havelinuxrtl10}
  1152. FStat (F,Info);
  1153. L:=Info.Mtime;
  1154. {$ELSE}
  1155. FPFStat (F,Info);
  1156. L:=Info.st_Mtime;
  1157. {$ENDIF}
  1158. {$else}
  1159. GetFTime(f,l);
  1160. {$endif}
  1161. GetFileTime:=L;
  1162. end;
  1163. Function GetNamedFileTime (Const F : String) : Longint;
  1164. begin
  1165. GetNamedFileTime:=do_getnamedfiletime(F);
  1166. end;
  1167. function FindFile(const f : string;path : string;var foundfile:string):boolean;
  1168. Var
  1169. singlepathstring : string;
  1170. i : longint;
  1171. begin
  1172. {$ifdef Unix}
  1173. for i:=1 to length(path) do
  1174. if path[i]=':' then
  1175. path[i]:=';';
  1176. {$endif Unix}
  1177. FindFile:=false;
  1178. repeat
  1179. i:=pos(';',path);
  1180. if i=0 then
  1181. i:=256;
  1182. singlepathstring:=FixPath(copy(path,1,i-1),false);
  1183. delete(path,1,i);
  1184. result:=FileExistsNonCase(singlepathstring,f,FoundFile);
  1185. if result then
  1186. exit;
  1187. until path='';
  1188. FoundFile:=f;
  1189. end;
  1190. function FindFilePchar(const f : string;path : pchar;var foundfile:string):boolean;
  1191. Var
  1192. singlepathstring : string;
  1193. startpc,pc : pchar;
  1194. sepch : char;
  1195. begin
  1196. {$ifdef Unix}
  1197. sepch:=':';
  1198. {$else}
  1199. {$ifdef macos}
  1200. sepch:=',';
  1201. {$else}
  1202. sepch:=';';
  1203. {$endif macos}
  1204. {$endif Unix}
  1205. FindFilePchar:=false;
  1206. pc:=path;
  1207. repeat
  1208. startpc:=pc;
  1209. while (pc^<>sepch) and (pc^<>';') and (pc^<>#0) do
  1210. inc(pc);
  1211. move(startpc^,singlepathstring[1],pc-startpc);
  1212. singlepathstring[0]:=char(longint(pc-startpc));
  1213. singlepathstring:=FixPath(singlepathstring,false);
  1214. result:=FileExistsNonCase(singlepathstring,f,FoundFile);
  1215. if result then
  1216. exit;
  1217. if (pc^=#0) then
  1218. break;
  1219. inc(pc);
  1220. until false;
  1221. foundfile:=f;
  1222. end;
  1223. function FindExe(const bin:string;var foundfile:string):boolean;
  1224. var
  1225. p : pchar;
  1226. found : boolean;
  1227. begin
  1228. found:=FindFile(FixFileName(AddExtension(bin,source_info.exeext)),'.;'+exepath,foundfile);
  1229. if not found then
  1230. begin
  1231. {$ifdef macos}
  1232. p:=GetEnvPchar('Commands');
  1233. {$else}
  1234. p:=GetEnvPchar('PATH');
  1235. {$endif}
  1236. found:=FindFilePChar(FixFileName(AddExtension(bin,source_info.exeext)),p,foundfile);
  1237. FreeEnvPChar(p);
  1238. end;
  1239. FindExe:=found;
  1240. end;
  1241. function GetShortName(const n:string):string;
  1242. {$ifdef win32}
  1243. var
  1244. hs,hs2 : string;
  1245. i : longint;
  1246. {$endif}
  1247. {$ifdef go32v2}
  1248. var
  1249. hs : string;
  1250. {$endif}
  1251. {$ifdef watcom}
  1252. var
  1253. hs : string;
  1254. {$endif}
  1255. begin
  1256. GetShortName:=n;
  1257. {$ifdef win32}
  1258. hs:=n+#0;
  1259. i:=Windows.GetShortPathName(@hs[1],@hs2[1],high(hs2));
  1260. if (i>0) and (i<=high(hs2)) then
  1261. begin
  1262. hs2[0]:=chr(strlen(@hs2[1]));
  1263. GetShortName:=hs2;
  1264. end;
  1265. {$endif}
  1266. {$ifdef go32v2}
  1267. hs:=n;
  1268. if Dos.GetShortName(hs) then
  1269. GetShortName:=hs;
  1270. {$endif}
  1271. {$ifdef watcom}
  1272. hs:=n;
  1273. if Dos.GetShortName(hs) then
  1274. GetShortName:=hs;
  1275. {$endif}
  1276. end;
  1277. function CleanPath(const s:string):String;
  1278. { Wrapper that encapsulate fexpand/expandfilename}
  1279. begin
  1280. {$IFDEF USE_SYSUTILS}
  1281. cleanpath:=ExpandFileName(s);
  1282. {$else}
  1283. cleanpath:=fexpand(s);
  1284. {$endif}
  1285. end;
  1286. {****************************************************************************
  1287. OS Dependent things
  1288. ****************************************************************************}
  1289. function GetEnvPChar(const envname:string):pchar;
  1290. {$ifdef win32}
  1291. var
  1292. s : string;
  1293. i,len : longint;
  1294. hp,p,p2 : pchar;
  1295. {$endif}
  1296. begin
  1297. {$ifdef hasunix}
  1298. GetEnvPchar:={$ifdef havelinuxrtl10}Linux.getenv{$else}BaseUnix.fpGetEnv{$endif}(envname);
  1299. {$define GETENVOK}
  1300. {$endif}
  1301. {$ifdef win32}
  1302. GetEnvPchar:=nil;
  1303. p:=GetEnvironmentStrings;
  1304. hp:=p;
  1305. while hp^<>#0 do
  1306. begin
  1307. s:=strpas(hp);
  1308. i:=pos('=',s);
  1309. len:=strlen(hp);
  1310. if upper(copy(s,1,i-1))=upper(envname) then
  1311. begin
  1312. GetMem(p2,len-length(envname));
  1313. Move(hp[i],p2^,len-length(envname));
  1314. GetEnvPchar:=p2;
  1315. break;
  1316. end;
  1317. { next string entry}
  1318. hp:=hp+len+1;
  1319. end;
  1320. FreeEnvironmentStrings(p);
  1321. {$define GETENVOK}
  1322. {$endif}
  1323. {$ifdef os2}
  1324. GetEnvPChar := Dos.GetEnvPChar (EnvName);
  1325. {$define GETENVOK}
  1326. {$endif}
  1327. {$ifdef GETENVOK}
  1328. {$undef GETENVOK}
  1329. {$else}
  1330. GetEnvPchar:=StrPNew(Dos.Getenv(envname));
  1331. {$endif}
  1332. end;
  1333. procedure FreeEnvPChar(p:pchar);
  1334. begin
  1335. {$ifndef hasunix}
  1336. {$ifndef os2}
  1337. StrDispose(p);
  1338. {$endif}
  1339. {$endif}
  1340. end;
  1341. {$IFDEF MORPHOS}
  1342. {$DEFINE AMIGASHELL}
  1343. {$ENDIF}
  1344. {$IFDEF AMIGA}
  1345. {$DEFINE AMIGASHELL}
  1346. {$ENDIF}
  1347. function Shell(const command:string): longint;
  1348. { This is already defined in the linux.ppu for linux, need for the *
  1349. expansion under linux }
  1350. {$ifdef hasunix}
  1351. begin
  1352. result := {$ifdef havelinuxrtl10}Linux{$else}Unix{$endif}.Shell(command);
  1353. end;
  1354. {$else}
  1355. {$ifdef amigashell}
  1356. begin
  1357. {$IFDEF USE_SYSUTILS}
  1358. result := ExecuteProcess('',command);
  1359. {$ELSE USE_SYSUTILS}
  1360. exec('',command);
  1361. if (doserror <> 0) then
  1362. result := doserror
  1363. else
  1364. result := dosexitcode;
  1365. end;
  1366. {$ENDIF USE_SYSUTILS}
  1367. {$else}
  1368. var
  1369. comspec : string;
  1370. begin
  1371. comspec:=getenv('COMSPEC');
  1372. {$IFDEF USE_SYSUTILS}
  1373. result := ExecuteProcess(comspec,' /C '+command);
  1374. {$ELSE USE_SYSUTILS}
  1375. Exec(comspec,' /C '+command);
  1376. if (doserror <> 0) then
  1377. result := doserror
  1378. else
  1379. result := dosexitcode;
  1380. end;
  1381. {$ENDIF USE_SYSUTILS}
  1382. {$endif}
  1383. {$endif}
  1384. {$UNDEF AMIGASHELL}
  1385. {$ifdef CPUI386}
  1386. {$define HASSETFPUEXCEPTIONMASK}
  1387. { later, this should be replaced by the math unit }
  1388. const
  1389. Default8087CW : word = $1332;
  1390. procedure Set8087CW(cw:word);assembler;
  1391. asm
  1392. movw cw,%ax
  1393. movw %ax,default8087cw
  1394. fnclex
  1395. fldcw default8087cw
  1396. end;
  1397. function Get8087CW:word;assembler;
  1398. asm
  1399. pushl $0
  1400. fnstcw (%esp)
  1401. popl %eax
  1402. end;
  1403. procedure SetFPUExceptionMask(const Mask: TFPUExceptionMask);
  1404. var
  1405. CtlWord: Word;
  1406. begin
  1407. CtlWord:=Get8087CW;
  1408. Set8087CW( (CtlWord and $FFC0) or Byte(Longint(Mask)) );
  1409. end;
  1410. {$endif CPUI386}
  1411. {$ifdef CPUX86_64}
  1412. {$define HASSETFPUEXCEPTIONMASK}
  1413. { later, this should be replaced by the math unit }
  1414. const
  1415. Default8087CW : word = $1332;
  1416. procedure Set8087CW(cw:word);assembler;
  1417. asm
  1418. movw cw,%ax
  1419. movw %ax,default8087cw
  1420. fnclex
  1421. fldcw default8087cw
  1422. end;
  1423. function Get8087CW:word;assembler;
  1424. asm
  1425. pushq $0
  1426. fnstcw (%rsp)
  1427. popq %rax
  1428. end;
  1429. procedure SetFPUExceptionMask(const Mask: TFPUExceptionMask);
  1430. var
  1431. CtlWord: Word;
  1432. begin
  1433. CtlWord:=Get8087CW;
  1434. Set8087CW( (CtlWord and $FFC0) or Byte(Longint(Mask)) );
  1435. end;
  1436. {$endif CPUX86_64}
  1437. {$ifdef CPUPOWERPC}
  1438. {$define HASSETFPUEXCEPTIONMASK}
  1439. procedure SetFPUExceptionMask(const Mask: TFPUExceptionMask);
  1440. var
  1441. newmask: record
  1442. case byte of
  1443. 1: (d: double);
  1444. 2: (a,b: cardinal);
  1445. end;
  1446. begin
  1447. { load current control register contents }
  1448. asm
  1449. mffs f0
  1450. stfd f0,newmask.d
  1451. end;
  1452. { invalid operation: bit 24 (big endian, bit 0 = left-most bit) }
  1453. if (exInvalidOp in mask) then
  1454. newmask.b := newmask.b and not(1 shl (31-24))
  1455. else
  1456. newmask.b := newmask.b or (1 shl (31-24));
  1457. { denormals can not cause exceptions on the PPC }
  1458. { zero divide: bit 27 }
  1459. if (exZeroDivide in mask) then
  1460. newmask.b := newmask.b and not(1 shl (31-27))
  1461. else
  1462. newmask.b := newmask.b or (1 shl (31-27));
  1463. { overflow: bit 25 }
  1464. if (exOverflow in mask) then
  1465. newmask.b := newmask.b and not(1 shl (31-25))
  1466. else
  1467. newmask.b := newmask.b or (1 shl (31-25));
  1468. { underflow: bit 26 }
  1469. if (exUnderflow in mask) then
  1470. newmask.b := newmask.b and not(1 shl (31-26))
  1471. else
  1472. newmask.b := newmask.b or (1 shl (31-26));
  1473. { Precision (inexact result): bit 28 }
  1474. if (exPrecision in mask) then
  1475. newmask.b := newmask.b and not(1 shl (31-28))
  1476. else
  1477. newmask.b := newmask.b or (1 shl (31-28));
  1478. { update control register contents }
  1479. asm
  1480. lfd f0, newmask.d
  1481. mtfsf 255,f0
  1482. end;
  1483. end;
  1484. {$endif CPUPOWERPC}
  1485. {$ifdef CPUSPARC}
  1486. {$define HASSETFPUEXCEPTIONMASK}
  1487. procedure SetFPUExceptionMask(const Mask: TFPUExceptionMask);
  1488. var
  1489. fsr : cardinal;
  1490. begin
  1491. { load current control register contents }
  1492. asm
  1493. st %fsr,fsr
  1494. end;
  1495. { invalid operation: bit 27 }
  1496. if (exInvalidOp in mask) then
  1497. fsr:=fsr and not(1 shl 27)
  1498. else
  1499. fsr:=fsr or (1 shl 27);
  1500. { zero divide: bit 24 }
  1501. if (exZeroDivide in mask) then
  1502. fsr:=fsr and not(1 shl 24)
  1503. else
  1504. fsr:=fsr or (1 shl 24);
  1505. { overflow: bit 26 }
  1506. if (exOverflow in mask) then
  1507. fsr:=fsr and not(1 shl 26)
  1508. else
  1509. fsr:=fsr or (1 shl 26);
  1510. { underflow: bit 25 }
  1511. if (exUnderflow in mask) then
  1512. fsr:=fsr and not(1 shl 25)
  1513. else
  1514. fsr:=fsr or (1 shl 25);
  1515. { Precision (inexact result): bit 23 }
  1516. if (exPrecision in mask) then
  1517. fsr:=fsr and not(1 shl 23)
  1518. else
  1519. fsr:=fsr or (1 shl 23);
  1520. { update control register contents }
  1521. asm
  1522. ld fsr,%fsr
  1523. end;
  1524. end;
  1525. {$endif CPUSPARC}
  1526. {$ifndef HASSETFPUEXCEPTIONMASK}
  1527. procedure SetFPUExceptionMask(const Mask: TFPUExceptionMask);
  1528. begin
  1529. end;
  1530. {$endif HASSETFPUEXCEPTIONMASK}
  1531. function is_number_float(d : double) : boolean;
  1532. var
  1533. bytearray : array[0..7] of byte;
  1534. begin
  1535. move(d,bytearray,8);
  1536. { only 1.1 save, 1.0.x will use always little endian }
  1537. {$ifdef FPC_BIG_ENDIAN}
  1538. result:=((bytearray[0] and $7f)<>$7f) or ((bytearray[1] and $f0)<>$f0);
  1539. {$else FPC_BIG_ENDIAN}
  1540. result:=((bytearray[7] and $7f)<>$7f) or ((bytearray[6] and $f0)<>$f0);
  1541. {$endif FPC_BIG_ENDIAN}
  1542. end;
  1543. function convertdoublearray(d : tdoublearray) : tdoublearray;{$ifdef USEINLINE}inline;{$endif}
  1544. {$ifdef CPUARM}
  1545. var
  1546. i : longint;
  1547. begin
  1548. for i:=0 to 3 do
  1549. begin
  1550. result[i+4]:=d[i];
  1551. result[i]:=d[i+4];
  1552. end;
  1553. {$else CPUARM}
  1554. begin
  1555. result:=d;
  1556. {$endif CPUARM}
  1557. end;
  1558. Function SetCompileMode(const s:string; changeInit: boolean):boolean;
  1559. var
  1560. b : boolean;
  1561. begin
  1562. b:=true;
  1563. if s='DEFAULT' then
  1564. aktmodeswitches:=initmodeswitches
  1565. else
  1566. if s='DELPHI' then
  1567. aktmodeswitches:=delphimodeswitches
  1568. else
  1569. if s='TP' then
  1570. aktmodeswitches:=tpmodeswitches
  1571. else
  1572. if s='FPC' then
  1573. aktmodeswitches:=fpcmodeswitches
  1574. else
  1575. if s='OBJFPC' then
  1576. aktmodeswitches:=objfpcmodeswitches
  1577. else
  1578. if s='GPC' then
  1579. aktmodeswitches:=gpcmodeswitches
  1580. else
  1581. if s='MACPAS' then
  1582. aktmodeswitches:=macmodeswitches
  1583. else
  1584. b:=false;
  1585. if b and changeInit then
  1586. initmodeswitches := aktmodeswitches;
  1587. if b then
  1588. begin
  1589. { turn ansistrings on by default ? }
  1590. if (m_delphi in aktmodeswitches) then
  1591. begin
  1592. include(aktlocalswitches,cs_ansistrings);
  1593. if changeinit then
  1594. include(initlocalswitches,cs_ansistrings);
  1595. end
  1596. else
  1597. begin
  1598. exclude(aktlocalswitches,cs_ansistrings);
  1599. if changeinit then
  1600. exclude(initlocalswitches,cs_ansistrings);
  1601. end;
  1602. { Default enum packing for delphi/tp7 }
  1603. if (m_tp7 in aktmodeswitches) or
  1604. (m_delphi in aktmodeswitches) then
  1605. aktpackenum:=1
  1606. else
  1607. aktpackenum:=4;
  1608. if changeinit then
  1609. initpackenum:=aktpackenum;
  1610. {$ifdef i386}
  1611. { Default to intel assembler for delphi/tp7 on i386 }
  1612. if (m_delphi in aktmodeswitches) or
  1613. (m_tp7 in aktmodeswitches) then
  1614. aktasmmode:=asmmode_i386_intel;
  1615. if changeinit then
  1616. initasmmode:=aktasmmode;
  1617. {$endif i386}
  1618. end;
  1619. SetCompileMode:=b;
  1620. end;
  1621. function SetAktProcCall(const s:string; changeInit:boolean):boolean;
  1622. const
  1623. DefProcCallName : array[tproccalloption] of string[12] = ('',
  1624. 'CDECL',
  1625. 'CPPDECL',
  1626. '', { compilerproc }
  1627. 'FAR16',
  1628. 'FPCCALL',
  1629. 'INLINE',
  1630. '', { internproc }
  1631. '', { syscall }
  1632. 'PASCAL',
  1633. 'REGISTER',
  1634. 'SAFECALL',
  1635. 'STDCALL',
  1636. 'SOFTFLOAT'
  1637. );
  1638. var
  1639. t : tproccalloption;
  1640. begin
  1641. result:=false;
  1642. for t:=low(tproccalloption) to high(tproccalloption) do
  1643. if DefProcCallName[t]=s then
  1644. begin
  1645. AktDefProcCall:=t;
  1646. result:=true;
  1647. break;
  1648. end;
  1649. if changeinit then
  1650. InitDefProcCall:=AktDefProcCall;
  1651. end;
  1652. function SetProcessor(const s:string; changeInit: boolean):boolean;
  1653. var
  1654. t : tprocessors;
  1655. begin
  1656. SetProcessor:=false;
  1657. for t:=low(tprocessors) to high(tprocessors) do
  1658. if processorsstr[t]=s then
  1659. begin
  1660. aktspecificoptprocessor:=t;
  1661. SetProcessor:=true;
  1662. break;
  1663. end;
  1664. if changeinit then
  1665. initspecificoptprocessor:=aktspecificoptprocessor;
  1666. end;
  1667. function SetFpuType(const s:string; changeInit: boolean):boolean;
  1668. var
  1669. t : tfputype;
  1670. begin
  1671. SetFpuType:=false;
  1672. for t:=low(tfputype) to high(tfputype) do
  1673. if fputypestr[t]=s then
  1674. begin
  1675. aktfputype:=t;
  1676. SetFpuType:=true;
  1677. break;
  1678. end;
  1679. if changeinit then
  1680. initfputype:=aktfputype;
  1681. end;
  1682. { '('D1:'00000000-'D2:'0000-'D3:'0000-'D4:'0000-000000000000)' }
  1683. function string2guid(const s: string; var GUID: TGUID): boolean;
  1684. function ishexstr(const hs: string): boolean;
  1685. var
  1686. i: integer;
  1687. begin
  1688. ishexstr:=false;
  1689. for i:=1 to Length(hs) do begin
  1690. if not (hs[i] in ['0'..'9','A'..'F','a'..'f']) then
  1691. exit;
  1692. end;
  1693. ishexstr:=true;
  1694. end;
  1695. function hexstr2longint(const hexs: string): longint;
  1696. var
  1697. i: integer;
  1698. rl: longint;
  1699. begin
  1700. rl:=0;
  1701. for i:=1 to length(hexs) do begin
  1702. rl:=rl shl 4;
  1703. case hexs[i] of
  1704. '0'..'9' : inc(rl,ord(hexs[i])-ord('0'));
  1705. 'A'..'F' : inc(rl,ord(hexs[i])-ord('A')+10);
  1706. 'a'..'f' : inc(rl,ord(hexs[i])-ord('a')+10);
  1707. end
  1708. end;
  1709. hexstr2longint:=rl;
  1710. end;
  1711. var
  1712. i: integer;
  1713. begin
  1714. if (Length(s)=38) and (s[1]='{') and (s[38]='}') and
  1715. (s[10]='-') and (s[15]='-') and (s[20]='-') and (s[25]='-') and
  1716. ishexstr(copy(s,2,8)) and ishexstr(copy(s,11,4)) and
  1717. ishexstr(copy(s,16,4)) and ishexstr(copy(s,21,4)) and
  1718. ishexstr(copy(s,26,12)) then begin
  1719. GUID.D1:=dword(hexstr2longint(copy(s,2,8)));
  1720. { these values are arealdy in the correct range (4 chars = word) }
  1721. GUID.D2:=word(hexstr2longint(copy(s,11,4)));
  1722. GUID.D3:=word(hexstr2longint(copy(s,16,4)));
  1723. for i:=0 to 1 do
  1724. GUID.D4[i]:=byte(hexstr2longint(copy(s,21+i*2,2)));
  1725. for i:=2 to 7 do
  1726. GUID.D4[i]:=byte(hexstr2longint(copy(s,22+i*2,2)));
  1727. string2guid:=true;
  1728. end
  1729. else
  1730. string2guid:=false;
  1731. end;
  1732. function guid2string(const GUID: TGUID): string;
  1733. function long2hex(l, len: longint): string;
  1734. const
  1735. hextbl: array[0..15] of char = '0123456789ABCDEF';
  1736. var
  1737. rs: string;
  1738. i: integer;
  1739. begin
  1740. rs[0]:=chr(len);
  1741. for i:=len downto 1 do begin
  1742. rs[i]:=hextbl[l and $F];
  1743. l:=l shr 4;
  1744. end;
  1745. long2hex:=rs;
  1746. end;
  1747. begin
  1748. guid2string:=
  1749. '{'+long2hex(GUID.D1,8)+
  1750. '-'+long2hex(GUID.D2,4)+
  1751. '-'+long2hex(GUID.D3,4)+
  1752. '-'+long2hex(GUID.D4[0],2)+long2hex(GUID.D4[1],2)+
  1753. '-'+long2hex(GUID.D4[2],2)+long2hex(GUID.D4[3],2)+
  1754. long2hex(GUID.D4[4],2)+long2hex(GUID.D4[5],2)+
  1755. long2hex(GUID.D4[6],2)+long2hex(GUID.D4[7],2)+
  1756. '}';
  1757. end;
  1758. function UpdateAlignmentStr(s:string;var a:talignmentinfo):boolean;
  1759. var
  1760. tok : string;
  1761. vstr : string;
  1762. l : longint;
  1763. code : integer;
  1764. b : talignmentinfo;
  1765. begin
  1766. UpdateAlignmentStr:=true;
  1767. uppervar(s);
  1768. fillchar(b,sizeof(b),0);
  1769. repeat
  1770. tok:=GetToken(s,'=');
  1771. if tok='' then
  1772. break;
  1773. vstr:=GetToken(s,',');
  1774. val(vstr,l,code);
  1775. if tok='PROC' then
  1776. b.procalign:=l
  1777. else if tok='JUMP' then
  1778. b.jumpalign:=l
  1779. else if tok='LOOP' then
  1780. b.loopalign:=l
  1781. else if tok='CONSTMIN' then
  1782. b.constalignmin:=l
  1783. else if tok='CONSTMAX' then
  1784. b.constalignmax:=l
  1785. else if tok='VARMIN' then
  1786. b.varalignmin:=l
  1787. else if tok='VARMAX' then
  1788. b.varalignmax:=l
  1789. else if tok='LOCALMIN' then
  1790. b.localalignmin:=l
  1791. else if tok='LOCALMAX' then
  1792. b.localalignmax:=l
  1793. else if tok='RECORDMIN' then
  1794. b.recordalignmin:=l
  1795. else if tok='RECORDMAX' then
  1796. b.recordalignmax:=l
  1797. else { Error }
  1798. UpdateAlignmentStr:=false;
  1799. until false;
  1800. UpdateAlignment(a,b);
  1801. end;
  1802. function var_align(siz: longint): longint;
  1803. begin
  1804. siz := size_2_align(siz);
  1805. var_align := used_align(siz,aktalignment.varalignmin,aktalignment.varalignmax);
  1806. end;
  1807. function const_align(siz: longint): longint;
  1808. begin
  1809. siz := size_2_align(siz);
  1810. const_align := used_align(siz,aktalignment.constalignmin,aktalignment.constalignmax);
  1811. end;
  1812. {****************************************************************************
  1813. Init
  1814. ****************************************************************************}
  1815. {$ifdef unix}
  1816. {$define need_path_search}
  1817. {$endif unix}
  1818. {$ifdef os2}
  1819. {$define need_path_search}
  1820. {$endif os2}
  1821. {$ifdef macos}
  1822. {$define need_path_search}
  1823. {$endif macos}
  1824. procedure get_exepath;
  1825. var
  1826. hs1 : namestr;
  1827. hs2 : extstr;
  1828. {$IFDEF USE_SYSUTILS}
  1829. exeName:String;
  1830. {$ENDIF USE_SYSUTILS}
  1831. {$ifdef need_path_search}
  1832. p : pchar;
  1833. {$endif need_path_search}
  1834. begin
  1835. {$IFDEF USE_SYSUTILS}
  1836. exepath:=GetEnvironmentVariable('PPC_EXEC_PATH');
  1837. {$ELSE USE_SYSUTILS}
  1838. exepath:=dos.getenv('PPC_EXEC_PATH');
  1839. {$ENDIF USE_SYSUTILS}
  1840. if exepath='' then
  1841. {$IFDEF USE_SYSUTILS}
  1842. exeName := FixFileName(system.paramstr(0));
  1843. exepath := ExtractFilePath(exeName);
  1844. hs1 := ExtractFileName(exeName);
  1845. hs2 := ExtractFileExt(exeName);
  1846. {$ELSE USE_SYSUTILS}
  1847. fsplit(FixFileName(system.paramstr(0)),exepath,hs1,hs2);
  1848. {$ENDIF USE_SYSUTILS}
  1849. {$ifdef need_path_search}
  1850. if exepath='' then
  1851. begin
  1852. if pos(source_info.exeext,hs1) <>
  1853. (length(hs1) - length(source_info.exeext)+1) then
  1854. hs1 := hs1 + source_info.exeext;
  1855. {$ifdef macos}
  1856. p:=GetEnvPchar('Commands');
  1857. {$else macos}
  1858. p:=GetEnvPchar('PATH');
  1859. {$endif macos}
  1860. FindFilePChar(hs1,p,exepath);
  1861. FreeEnvPChar(p);
  1862. exepath:=SplitPath(exepath);
  1863. end;
  1864. {$endif need_path_search}
  1865. exepath:=FixPath(exepath,false);
  1866. end;
  1867. procedure DoneGlobals;
  1868. begin
  1869. if assigned(DLLImageBase) then
  1870. StringDispose(DLLImageBase);
  1871. librarysearchpath.Free;
  1872. unitsearchpath.Free;
  1873. objectsearchpath.Free;
  1874. includesearchpath.Free;
  1875. end;
  1876. procedure InitGlobals;
  1877. begin
  1878. get_exepath;
  1879. { reset globals }
  1880. do_build:=false;
  1881. do_release:=false;
  1882. do_make:=true;
  1883. compile_level:=0;
  1884. DLLsource:=false;
  1885. inlining_procedure:=false;
  1886. resolving_forward:=false;
  1887. make_ref:=false;
  1888. LinkTypeSetExplicitly:=false;
  1889. { Output }
  1890. OutputFile:='';
  1891. OutputPrefix:=Nil;
  1892. OutputSuffix:=Nil;
  1893. OutputExtension:='';
  1894. OutputExeDir:='';
  1895. OutputUnitDir:='';
  1896. { Utils directory }
  1897. utilsdirectory:='';
  1898. utilsprefix:='';
  1899. cshared:=false;
  1900. rlinkpath:='';
  1901. { Search Paths }
  1902. librarysearchpath:=TSearchPathList.Create;
  1903. unitsearchpath:=TSearchPathList.Create;
  1904. includesearchpath:=TSearchPathList.Create;
  1905. objectsearchpath:=TSearchPathList.Create;
  1906. { Def file }
  1907. usewindowapi:=false;
  1908. description:='Compiled by FPC '+version_string+' - '+target_cpu_string;
  1909. DescriptionSetExplicity:=false;
  1910. dllversion:='';
  1911. dllmajor:=1;
  1912. dllminor:=0;
  1913. dllrevision:=0;
  1914. nwscreenname := '';
  1915. nwthreadname := '';
  1916. nwcopyright := '';
  1917. UseDeffileForExports:=false;
  1918. UseDeffileForExportsSetExplicitly:=false;
  1919. RelocSection:=false;
  1920. RelocSectionSetExplicitly:=false;
  1921. LinkTypeSetExplicitly:=false;
  1922. { Init values }
  1923. initmodeswitches:=fpcmodeswitches;
  1924. initlocalswitches:=[cs_check_io,cs_typed_const_writable];
  1925. initmoduleswitches:=[cs_extsyntax,cs_implicit_exceptions];
  1926. initsourcecodepage:='8859-1';
  1927. initglobalswitches:=[cs_check_unit_name,cs_link_static{$ifdef INTERNALLINKER},cs_link_internal,cs_link_map{$endif}];
  1928. initoutputformat:=target_asm.id;
  1929. fillchar(initalignment,sizeof(talignmentinfo),0);
  1930. { might be overridden later }
  1931. initasmmode:=asmmode_standard;
  1932. {$ifdef i386}
  1933. initoptprocessor:=ClassPentium3;
  1934. initspecificoptprocessor:=Class386;
  1935. initfputype:=fpu_x87;
  1936. initpackenum:=4;
  1937. {$IFDEF testvarsets}
  1938. initsetalloc:=0;
  1939. {$ENDIF}
  1940. initasmmode:=asmmode_i386_att;
  1941. {$endif i386}
  1942. {$ifdef m68k}
  1943. initoptprocessor:=MC68020;
  1944. initpackenum:=4;
  1945. {$IFDEF testvarsets}
  1946. initsetalloc:=0;
  1947. {$ENDIF}
  1948. {$endif m68k}
  1949. {$ifdef powerpc}
  1950. initoptprocessor:=PPC604;
  1951. initpackenum:=4;
  1952. {$IFDEF testvarsets}
  1953. initsetalloc:=0;
  1954. {$ENDIF}
  1955. initfputype:=fpu_standard;
  1956. {$endif powerpc}
  1957. {$ifdef sparc}
  1958. initoptprocessor:=SPARC_V8;
  1959. initpackenum:=4;
  1960. {$IFDEF testvarsets}
  1961. initsetalloc:=0;
  1962. {$ENDIF}
  1963. {$endif sparc}
  1964. {$ifdef arm}
  1965. initpackenum:=4;
  1966. {$IFDEF testvarsets}
  1967. initsetalloc:=0;
  1968. {$ENDIF}
  1969. initfputype:=fpu_fpa;
  1970. {$endif arm}
  1971. {$ifdef x86_64}
  1972. initoptprocessor:=ClassAthlon64;
  1973. initspecificoptprocessor:=ClassAthlon64;
  1974. initfputype:=fpu_sse64;
  1975. initpackenum:=4;
  1976. {$IFDEF testvarsets}
  1977. initsetalloc:=0;
  1978. {$ENDIF}
  1979. initasmmode:=asmmode_x86_64_gas;
  1980. {$endif x86_64}
  1981. initinterfacetype:=it_interfacecom;
  1982. initdefproccall:=pocall_default;
  1983. { memory sizes, will be overriden by parameter or default for target
  1984. in options or init_parser }
  1985. stacksize:=0;
  1986. { not initialized yet }
  1987. jmp_buf_size:=-1;
  1988. apptype:=app_cui;
  1989. end;
  1990. end.
  1991. {
  1992. $Log$
  1993. Revision 1.166 2005-02-01 17:57:30 olle
  1994. * macpas now uses tp style proc params
  1995. Revision 1.165 2005/02/01 08:46:13 michael
  1996. * Patch from peter: fix macpas anonymous function procvar
  1997. Revision 1.164 2005/01/31 21:30:56 olle
  1998. + Added fake Exception classes, only for MACOS.
  1999. Revision 1.163 2005/01/23 22:13:50 florian
  2000. * fixed math constants for big endian cpus
  2001. Revision 1.162 2005/01/23 21:09:11 florian
  2002. + added pi bit pattern to the compiler, so pi should always be correct
  2003. Revision 1.161 2005/01/20 16:38:45 peter
  2004. * load jmp_buf_size from system unit
  2005. Revision 1.160 2005/01/09 20:24:43 olle
  2006. * rework of macro subsystem
  2007. + exportable macros for mode macpas
  2008. Revision 1.159 2005/01/06 13:40:41 florian
  2009. * 1.0.10 starting patch from Peter
  2010. Revision 1.158 2005/01/06 09:20:36 karoly
  2011. * made Shell() work correctly on MorphOS
  2012. Revision 1.157 2005/01/04 17:40:33 karoly
  2013. + sysv style syscalls added for MorphOS
  2014. Revision 1.156 2005/01/04 16:20:51 florian
  2015. * fixed nan et al. handling on arm
  2016. Revision 1.155 2004/12/28 20:43:01 hajny
  2017. * 8.3 fixes (short target name in paths)
  2018. Revision 1.154 2004/12/15 16:06:47 marco
  2019. * introduction "cleanpath" (=fexpand), fixfilename(paramstr(0)) + search $PREFIX/etc/fpc.cfg
  2020. Revision 1.153 2004/11/05 13:14:30 florian
  2021. * fixed arm compilation
  2022. Revision 1.152 2004/10/31 21:45:02 peter
  2023. * generic tlocation
  2024. * move tlocation to cgutils
  2025. Revision 1.151 2004/10/31 19:09:54 peter
  2026. * default paths fixed
  2027. Revision 1.150 2004/10/31 18:54:24 peter
  2028. * $fpctarget expands to <cpu>-<os>
  2029. * allow * in middle of the path to support ../*/units/$fpctarget
  2030. Revision 1.149 2004/10/26 15:11:01 peter
  2031. * -Ch for heapsize added again
  2032. * __heapsize contains the heapsize
  2033. Revision 1.148 2004/10/25 15:38:41 peter
  2034. * heap and heapsize removed
  2035. * checkpointer fixes
  2036. Revision 1.147 2004/10/16 22:46:14 olle
  2037. * Fixed printing of filedates
  2038. Revision 1.146 2004/10/16 13:03:13 olle
  2039. + added more support for macos
  2040. Revision 1.145 2004/10/15 09:14:16 mazen
  2041. - remove $IFDEF DELPHI and related code
  2042. - remove $IFDEF FPCPROCVAR and related code
  2043. Revision 1.144 2004/10/14 18:16:17 mazen
  2044. * USE_SYSUTILS merged successfully : cycles with and without defines
  2045. * Need to be optimized in performance
  2046. Revision 1.143 2004/10/10 15:42:22 peter
  2047. * default optimization cpu changed to CLassPentium3
  2048. Revision 1.142 2004/10/09 11:27:59 olle
  2049. + Added CurDirRelPath
  2050. * Exchanged hardcoded "./" to CurDirRelPath
  2051. Revision 1.141 2004/09/21 23:33:43 hajny
  2052. * better PathExists, fix for too long command line, correction of message
  2053. Revision 1.140 2004/09/21 19:59:51 peter
  2054. * x86_64 fixes
  2055. * cleanup of fpcdefs.icn
  2056. Revision 1.139 2004/09/21 17:25:12 peter
  2057. * paraloc branch merged
  2058. Revision 1.138 2004/09/08 11:23:31 michael
  2059. + Check if outputdir exists, Fix exitcode when displaying help pages
  2060. Revision 1.137 2004/08/31 22:02:30 olle
  2061. + support for quoting of paths in TSearchPathList.AddPath so that
  2062. compiler directives which take paths, will support quotes.
  2063. * uppdated TranslateMacPath
  2064. Revision 1.136.4.2 2004/09/12 18:31:26 peter
  2065. * fpu exception support for sparc and x86_64
  2066. Revision 1.136.4.1 2004/09/12 15:30:16 peter
  2067. * cache currentdir
  2068. Revision 1.136 2004/08/28 20:25:25 peter
  2069. * optimized search for noncasesensitive names. It now searches
  2070. first for NormalCase and skips double tests
  2071. Revision 1.135 2004/08/20 10:29:31 olle
  2072. + made fpc work as an MPW tool, by itself calling asm and link.
  2073. * bugfix in fp exception flag settings routine
  2074. Revision 1.134 2004/08/02 07:15:54 michael
  2075. + Patch from Christian Iversen to implement LIBPREFIX/SUFFIX/EXTENSION directives
  2076. Revision 1.133 2004/07/17 15:51:57 jonas
  2077. * shell now returns an exitcode
  2078. * print an error if linking failed when linking was done using a script
  2079. Revision 1.132 2004/07/05 23:28:24 olle
  2080. + FixFileName now handles Mac OS paths
  2081. Revision 1.131 2004/06/20 08:55:29 florian
  2082. * logs truncated
  2083. Revision 1.130 2004/06/16 20:07:07 florian
  2084. * dwarf branch merged
  2085. Revision 1.129 2004/05/11 18:20:52 olle
  2086. * changed $mode mac to $mode macpas
  2087. * changed macmodeswitches to be more faithful to the mac dialect
  2088. Revision 1.128 2004/04/29 19:56:36 daniel
  2089. * Prepare compiler infrastructure for multiple ansistring types
  2090. Revision 1.127 2004/04/28 15:19:03 florian
  2091. + syscall directive support for MorphOS added
  2092. Revision 1.126.2.4 2004/05/09 15:47:21 peter
  2093. * fix typecast from word->set
  2094. }