globals.pas 63 KB

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