globals.pas 63 KB

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