globals.pas 64 KB

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