globals.pas 64 KB

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