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. {$IFNDEF USE_FAKE_SYSUTILS}
  34. sysutils,
  35. {$ELSE}
  36. fksysutl,
  37. {$ENDIF}
  38. { comphook pulls in sysutils anyways }
  39. {$IFDEF USE_SYSUTILS}
  40. {$ELSE USE_SYSUTILS}
  41. strings,
  42. dos,
  43. {$ENDIF USE_SYSUTILS}
  44. cutils,cclasses,
  45. cpuinfo,
  46. globtype,version,systems;
  47. const
  48. delphimodeswitches : tmodeswitches=
  49. [m_delphi,m_all,m_class,m_objpas,m_result,m_string_pchar,
  50. m_pointer_2_procedure,m_autoderef,m_tp_procvar,m_initfinal,m_default_ansistring,
  51. m_out,m_default_para,m_duplicate_names,m_hintdirective,m_add_pointer,
  52. m_property];
  53. fpcmodeswitches : tmodeswitches=
  54. [m_fpc,m_all,m_string_pchar,m_nested_comment,m_repeat_forward,
  55. m_cvar_support,m_initfinal,m_add_pointer,m_hintdirective,
  56. m_property];
  57. objfpcmodeswitches : tmodeswitches=
  58. [m_objfpc,m_fpc,m_all,m_class,m_objpas,m_result,m_string_pchar,m_nested_comment,
  59. m_repeat_forward,m_cvar_support,m_initfinal,m_add_pointer,m_out,m_default_para,m_hintdirective,
  60. m_property];
  61. tpmodeswitches : tmodeswitches=
  62. [m_tp7,m_all,m_tp_procvar,m_duplicate_names];
  63. gpcmodeswitches : tmodeswitches=
  64. [m_gpc,m_all,m_tp_procvar];
  65. macmodeswitches : tmodeswitches=
  66. [m_mac,m_all,m_result,m_cvar_support,m_mac_procvar];
  67. { maximum nesting of routines }
  68. maxnesting = 32;
  69. { Filenames and extensions }
  70. sourceext = '.pp';
  71. pasext = '.pas';
  72. pext = '.p';
  73. treelogfilename = 'tree.log';
  74. {$if defined(CPUARM) and defined(FPUFPA)}
  75. MathQNaN : tdoublearray = (0,0,252,255,0,0,0,0);
  76. MathInf : tdoublearray = (0,0,240,127,0,0,0,0);
  77. MathNegInf : tdoublearray = (0,0,240,255,0,0,0,0);
  78. MathPi : tdoublearray = (251,33,9,64,24,45,68,84);
  79. {$else}
  80. {$ifdef FPC_LITTLE_ENDIAN}
  81. MathQNaN : tdoublearray = (0,0,0,0,0,0,252,255);
  82. MathInf : tdoublearray = (0,0,0,0,0,0,240,127);
  83. MathNegInf : tdoublearray = (0,0,0,0,0,0,240,255);
  84. MathPi : tdoublearray = (24,45,68,84,251,33,9,64);
  85. MathPiExtended : textendedarray = (53,194,104,33,162,218,15,201,0,64);
  86. {$else FPC_LITTLE_ENDIAN}
  87. MathQNaN : tdoublearray = (255,252,0,0,0,0,0,0);
  88. MathInf : tdoublearray = (127,240,0,0,0,0,0,0);
  89. MathNegInf : tdoublearray = (255,240,0,0,0,0,0,0);
  90. MathPi : tdoublearray = (64,9,33,251,84,68,45,24);
  91. MathPiExtended : textendedarray = (64,0,201,15,218,162,33,104,194,53);
  92. {$endif FPC_LITTLE_ENDIAN}
  93. {$endif}
  94. type
  95. TFPUException = (exInvalidOp, exDenormalized, exZeroDivide,
  96. exOverflow, exUnderflow, exPrecision);
  97. TFPUExceptionMask = set of TFPUException;
  98. pfileposinfo = ^tfileposinfo;
  99. tfileposinfo = record
  100. line : longint;
  101. column : word;
  102. fileindex : word;
  103. { moduleindex : word; }
  104. end;
  105. TSearchPathList = class(TStringList)
  106. procedure AddPath(s:string;addfirst:boolean);overload;
  107. procedure AddPath(SrcPath,s:string;addfirst:boolean);overload;
  108. procedure AddList(list:TSearchPathList;addfirst:boolean);
  109. function FindFile(const f : string;var foundfile:string):boolean;
  110. end;
  111. tcodepagestring = string[20];
  112. var
  113. { specified inputfile }
  114. inputdir : dirstr;
  115. inputfile : namestr;
  116. inputextension : extstr;
  117. { specified outputfile with -o parameter }
  118. outputfile : namestr;
  119. outputprefix : pstring;
  120. outputsuffix : pstring;
  121. outputextension : namestr;
  122. { specified with -FE or -FU }
  123. outputexedir : dirstr;
  124. outputunitdir : dirstr;
  125. { things specified with parameters }
  126. paralinkoptions,
  127. paradynamiclinker : string;
  128. paraprintnodetree : byte;
  129. parapreprocess : boolean;
  130. printnodefile : text;
  131. { typical cross compiling params}
  132. { directory where the utils can be found (options -FD) }
  133. utilsdirectory : dirstr;
  134. { targetname specific prefix used by these utils (options -XP<path>) }
  135. utilsprefix : dirstr;
  136. cshared : boolean; { pass --shared to ld to link C libs shared}
  137. Dontlinkstdlibpath: Boolean; { Don't add std paths to linkpath}
  138. rlinkpath : dirstr; { rpath-link linkdir override}
  139. { some flags for global compiler switches }
  140. do_build,
  141. do_release,
  142. do_make : boolean;
  143. { path for searching units, different paths can be seperated by ; }
  144. exepath : dirstr; { Path to ppc }
  145. librarysearchpath,
  146. unitsearchpath,
  147. objectsearchpath,
  148. includesearchpath : TSearchPathList;
  149. autoloadunits : string;
  150. { linking }
  151. usewindowapi : boolean;
  152. description : string;
  153. DescriptionSetExplicity : boolean;
  154. dllversion : string;
  155. dllmajor,
  156. dllminor,
  157. dllrevision : word; { revision only for netware }
  158. UseDeffileForExports : boolean;
  159. UseDeffileForExportsSetExplicitly : boolean;
  160. RelocSection : boolean;
  161. RelocSectionSetExplicitly : boolean;
  162. LinkTypeSetExplicitly : boolean;
  163. akttokenpos, { position of the last token }
  164. aktfilepos : tfileposinfo; { current position }
  165. nwscreenname : string;
  166. nwthreadname : string;
  167. nwcopyright : string;
  168. codegenerror : boolean; { true if there is an error reported }
  169. block_type : tblock_type; { type of currently parsed block }
  170. parsing_para_level : integer; { parameter level, used to convert
  171. proc calls to proc loads in firstcalln }
  172. compile_level : word;
  173. make_ref : boolean;
  174. resolving_forward : boolean; { used to add forward reference as second ref }
  175. inlining_procedure : boolean; { are we inlining a procedure }
  176. exceptblockcounter : integer; { each except block gets a unique number check gotos }
  177. aktexceptblock : integer; { the exceptblock number of the current block (0 if none) }
  178. LinkLibraryAliases : TLinkStrMap;
  179. LinkLibraryOrder : TLinkStrMap;
  180. { commandline values }
  181. initglobalswitches : tglobalswitches;
  182. initmoduleswitches : tmoduleswitches;
  183. initlocalswitches : tlocalswitches;
  184. initmodeswitches : tmodeswitches;
  185. {$IFDEF testvarsets}
  186. Initsetalloc, {0=fixed, 1 =var}
  187. {$ENDIF}
  188. initpackenum : shortint;
  189. {$ifdef ansistring_bits}
  190. initansistring_bits: Tstringbits;
  191. {$endif}
  192. initalignment : talignmentinfo;
  193. initoptprocessor,
  194. initspecificoptprocessor : tprocessors;
  195. initfputype : tfputype;
  196. initasmmode : tasmmode;
  197. initinterfacetype : tinterfacetypes;
  198. initoutputformat : tasm;
  199. initdefproccall : tproccalloption;
  200. initsourcecodepage : tcodepagestring;
  201. { current state values }
  202. aktglobalswitches : tglobalswitches;
  203. aktmoduleswitches : tmoduleswitches;
  204. aktlocalswitches : tlocalswitches;
  205. nextaktlocalswitches : tlocalswitches;
  206. localswitcheschanged : boolean;
  207. aktmodeswitches : tmodeswitches;
  208. {$IFDEF testvarsets}
  209. aktsetalloc,
  210. {$ENDIF}
  211. aktpackrecords,
  212. aktpackenum : shortint;
  213. {$ifdef ansistring_bits}
  214. aktansistring_bits : Tstringbits;
  215. {$endif}
  216. aktmaxfpuregisters : longint;
  217. aktalignment : talignmentinfo;
  218. aktoptprocessor,
  219. aktspecificoptprocessor : tprocessors;
  220. aktfputype : tfputype;
  221. aktasmmode : tasmmode;
  222. aktinterfacetype : tinterfacetypes;
  223. aktoutputformat : tasm;
  224. aktdefproccall : tproccalloption;
  225. aktsourcecodepage : tcodepagestring;
  226. { Memory sizes }
  227. heapsize,
  228. stacksize,
  229. jmp_buf_size : longint;
  230. {$Ifdef EXTDEBUG}
  231. { parameter switches }
  232. debugstop : boolean;
  233. {$EndIf EXTDEBUG}
  234. { windows / OS/2 application type }
  235. apptype : tapptype;
  236. const
  237. DLLsource : boolean = false;
  238. DLLImageBase : pstring = nil;
  239. { used to set all registers used for each global function
  240. this should dramatically decrease the number of
  241. recompilations needed PM }
  242. simplify_ppu : boolean = true;
  243. { should we allow non static members ? }
  244. allow_only_static : boolean = false;
  245. Inside_asm_statement : boolean = false;
  246. global_unit_count : word = 0;
  247. { for error info in pp.pas }
  248. parser_current_file : string = '';
  249. {$ifdef m68k}
  250. { PalmOS resources }
  251. palmos_applicationname : string = 'FPC Application';
  252. palmos_applicationid : string[4] = 'FPCA';
  253. {$endif m68k}
  254. {$ifdef powerpc}
  255. { default calling convention used on MorphOS }
  256. syscall_convention : string = 'LEGACY';
  257. {$endif powerpc}
  258. { default name of the C-style "main" procedure of the library/program }
  259. { (this will be prefixed with the target_info.cprefix) }
  260. mainaliasname : string = 'main';
  261. procedure abstract;
  262. function bstoslash(const s : string) : string;
  263. function getdatestr:string;
  264. function gettimestr:string;
  265. function filetimestring( t : longint) : string;
  266. procedure DefaultReplacements(var s:string);
  267. {Gives the absolute path to the current directory}
  268. function GetCurrentDir:string;
  269. {Gives the relative path to the current directory,
  270. with a trailing dir separator. E. g. on unix ./ }
  271. function CurDirRelPath(systeminfo: tsysteminfo): string;
  272. function path_absolute(const s : string) : boolean;
  273. Function PathExists ( F : String) : Boolean;
  274. Function FileExists ( Const F : String) : Boolean;
  275. Function DirectoryExists ( Const F : String) : Boolean;
  276. function FileExistsNonCase(const path,fn:string;var foundfile:string):boolean;
  277. Function RemoveFile(const f:string):boolean;
  278. Function RemoveDir(d:string):boolean;
  279. Function GetFileTime ( Var F : File) : Longint;
  280. Function GetNamedFileTime ( Const F : String) : Longint;
  281. {Extracts the path without its filename, from a path.}
  282. Function SplitPath(const s:string):string;
  283. Function SplitFileName(const s:string):string;
  284. Function SplitName(const s:string):string;
  285. Function SplitExtension(Const HStr:String):String;
  286. Function AddExtension(Const HStr,ext:String):String;
  287. Function ForceExtension(Const HStr,ext:String):String;
  288. Function FixPath(s:string;allowdot:boolean):string;
  289. function FixFileName(const s:string):string;
  290. function TargetFixPath(s:string;allowdot:boolean):string;
  291. function TargetFixFileName(const s:string):string;
  292. procedure SplitBinCmd(const s:string;var bstr: String;var cstr:TCmdStr);
  293. function FindFile(const f : string;path : string;var foundfile:string):boolean;
  294. function FindFilePchar(const f : string;path : pchar;var foundfile:string):boolean;
  295. function FindExe(const bin:string;var foundfile:string):boolean;
  296. function GetShortName(const n:string):string;
  297. function cleanpath(const s:string):String;
  298. function Shell(const command:string): longint;
  299. function GetEnvPChar(const envname:string):pchar;
  300. procedure FreeEnvPChar(p:pchar);
  301. procedure SetFPUExceptionMask(const Mask: TFPUExceptionMask);
  302. function is_number_float(d : double) : boolean;
  303. { discern +0.0 and -0.0 }
  304. function get_real_sign(r: bestreal): longint;
  305. function SetAktProcCall(const s:string; changeInit: boolean):boolean;
  306. function SetProcessor(const s:string; changeInit: boolean):boolean;
  307. function SetFpuType(const s:string; changeInit: boolean):boolean;
  308. procedure InitGlobals;
  309. procedure DoneGlobals;
  310. function string2guid(const s: string; var GUID: TGUID): boolean;
  311. function guid2string(const GUID: TGUID): string;
  312. function UpdateAlignmentStr(s:string;var a:talignmentinfo):boolean;
  313. {# Routine to get the required alignment for size of data, which will
  314. be placed in bss segment, according to the current alignment requirements }
  315. function var_align(siz: longint): longint;
  316. {# Routine to get the required alignment for size of data, which will
  317. be placed in data/const segment, according to the current alignment requirements }
  318. function const_align(siz: longint): longint;
  319. implementation
  320. uses
  321. {$ifdef macos}
  322. macutils,
  323. {$endif}
  324. comphook;
  325. procedure abstract;
  326. begin
  327. do_internalerror(255);
  328. end;
  329. procedure WarnNonExistingPath(const path : string);
  330. begin
  331. if assigned(do_comment) then
  332. do_comment(V_Tried,'Path "'+path+'" not found');
  333. end;
  334. function bstoslash(const s : string) : string;
  335. {
  336. return string s with all \ changed into /
  337. }
  338. var
  339. i : longint;
  340. begin
  341. for i:=1to length(s) do
  342. if s[i]='\' then
  343. bstoslash[i]:='/'
  344. else
  345. bstoslash[i]:=s[i];
  346. bstoslash[0]:=s[0];
  347. end;
  348. {****************************************************************************
  349. Time Handling
  350. ****************************************************************************}
  351. Function L0(l:longint):string;
  352. {
  353. return the string of value l, if l<10 then insert a zero, so
  354. the string is always at least 2 chars '01','02',etc
  355. }
  356. var
  357. s : string;
  358. begin
  359. Str(l,s);
  360. if l<10 then
  361. s:='0'+s;
  362. L0:=s;
  363. end;
  364. function gettimestr:string;
  365. {
  366. get the current time in a string HH:MM:SS
  367. }
  368. var
  369. hour,min,sec,hsec : word;
  370. begin
  371. {$IFDEF USE_SYSUTILS}
  372. DecodeTime(Time,hour,min,sec,hsec);
  373. {$ELSE USE_SYSUTILS}
  374. dos.gettime(hour,min,sec,hsec);
  375. {$ENDIF USE_SYSUTILS}
  376. gettimestr:=L0(Hour)+':'+L0(min)+':'+L0(sec);
  377. end;
  378. function getdatestr:string;
  379. {
  380. get the current date in a string YY/MM/DD
  381. }
  382. var
  383. {$IFDEF USE_SYSUTILS}
  384. Year,Month,Day: Word;
  385. {$ELSE USE_SYSUTILS}
  386. Year,Month,Day,Wday : Word;
  387. {$ENDIF USE_SYSUTILS}
  388. begin
  389. {$IFDEF USE_SYSUTILS}
  390. DecodeDate(Date,year,month,day);
  391. {$ELSE USE_SYSUTILS}
  392. dos.getdate(year,month,day,wday);
  393. {$ENDIF USE_SYSUTILS}
  394. getdatestr:=L0(Year)+'/'+L0(Month)+'/'+L0(Day);
  395. end;
  396. function filetimestring( t : longint) : string;
  397. {
  398. convert dos datetime t to a string YY/MM/DD HH:MM:SS
  399. }
  400. var
  401. {$IFDEF USE_SYSUTILS}
  402. DT : TDateTime;
  403. hsec : word;
  404. {$ELSE USE_SYSUTILS}
  405. DT : DateTime;
  406. {$ENDIF USE_SYSUTILS}
  407. Year,Month,Day: Word;
  408. hour,min,sec : word;
  409. begin
  410. if t=-1 then
  411. begin
  412. Result := 'Not Found';
  413. exit;
  414. end;
  415. {$IFDEF USE_SYSUTILS}
  416. DT := FileDateToDateTime(t);
  417. DecodeTime(DT,hour,min,sec,hsec);
  418. DecodeDate(DT,year,month,day);
  419. {$ELSE USE_SYSUTILS}
  420. unpacktime(t,DT);
  421. year := DT.year;
  422. month := DT.month;
  423. day := DT.day;
  424. hour := DT.hour;
  425. min := DT.min;
  426. sec := DT.sec;
  427. {$ENDIF USE_SYSUTILS}
  428. Result := L0(Year)+'/'+L0(Month)+'/'+L0(Day)+' '+L0(Hour)+':'+L0(min)+':'+L0(sec);
  429. end;
  430. {****************************************************************************
  431. Default Macro Handling
  432. ****************************************************************************}
  433. procedure DefaultReplacements(var s:string);
  434. begin
  435. { Replace some macros }
  436. Replace(s,'$FPCVERSION',version_string);
  437. Replace(s,'$FPCFULLVERSION',full_version_string);
  438. Replace(s,'$FPCDATE',date_string);
  439. Replace(s,'$FPCCPU',target_cpu_string);
  440. Replace(s,'$FPCOS',target_os_string);
  441. if tf_use_8_3 in Source_Info.Flags then
  442. Replace(s,'$FPCTARGET',target_os_string)
  443. else
  444. Replace(s,'$FPCTARGET',target_full_string);
  445. end;
  446. {****************************************************************************
  447. File Handling
  448. ****************************************************************************}
  449. var
  450. CachedCurrentDir : string;
  451. {Gives the absolute path to the current directory}
  452. function GetCurrentDir:string;
  453. begin
  454. if CachedCurrentDir='' then
  455. begin
  456. GetDir(0,CachedCurrentDir);
  457. CachedCurrentDir:=FixPath(CachedCurrentDir,false);
  458. end;
  459. result:=CachedCurrentDir;
  460. end;
  461. {Gives the relative path to the current directory,
  462. with a trailing dir separator. E. g. on unix ./ }
  463. function CurDirRelPath(systeminfo: tsysteminfo): string;
  464. begin
  465. if systeminfo.system <> system_powerpc_macos then
  466. CurDirRelPath:= '.'+systeminfo.DirSep
  467. else
  468. CurDirRelPath:= ':'
  469. end;
  470. function path_absolute(const s : string) : boolean;
  471. {
  472. is path s an absolute path?
  473. }
  474. begin
  475. path_absolute:=false;
  476. {$ifdef unix}
  477. if (length(s)>0) and (s[1]='/') then
  478. path_absolute:=true;
  479. {$else unix}
  480. {$ifdef amiga}
  481. if ((length(s)>0) and ((s[1]='\') or (s[1]='/'))) or (Pos(':',s) = length(s)) then
  482. path_absolute:=true;
  483. {$else}
  484. {$ifdef macos}
  485. if IsMacFullPath(s) then
  486. path_absolute:=true;
  487. {$else}
  488. if ((length(s)>0) and ((s[1]='\') or (s[1]='/'))) or
  489. ((length(s)>2) and (s[2]=':') and ((s[3]='\') or (s[3]='/'))) then
  490. path_absolute:=true;
  491. {$endif macos}
  492. {$endif amiga}
  493. {$endif unix}
  494. end;
  495. {$ifndef FPC}
  496. Procedure FindClose(var Info : SearchRec);
  497. Begin
  498. End;
  499. {$endif not FPC}
  500. Function FileExists ( Const F : String) : Boolean;
  501. {$IFDEF USE_SYSUTILS}
  502. {$ELSE USE_SYSUTILS}
  503. var
  504. Info : SearchRec;
  505. {$ENDIF USE_SYSUTILS}
  506. begin
  507. {$IFDEF USE_SYSUTILS}
  508. Result:=SysUtils.FileExists(f);
  509. {$ELSE USE_SYSUTILS}
  510. findfirst(F,readonly+archive+hidden,info);
  511. result:=(doserror=0);
  512. findclose(Info);
  513. {$ENDIF USE_SYSUTILS}
  514. if assigned(do_comment) then
  515. begin
  516. if Result then
  517. do_comment(V_Tried,'Searching file '+F+'... found')
  518. else
  519. do_comment(V_Tried,'Searching file '+F+'... not found');
  520. end;
  521. end;
  522. Function DirectoryExists ( Const F : String) : Boolean;
  523. begin
  524. {$IFNDEF USE_FAKE_SYSUTILS}
  525. Result:=SysUtils.DirectoryExists(f);
  526. {$ELSE}
  527. Result:=fksysutl.DirectoryExists(f);
  528. {$ENDIF}
  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. I := FileGetAttr(F);
  609. PathExists := (I <> -1) and (I and faDirectory = faDirectory);
  610. {$ELSE USE_SYSUTILS}
  611. Assign (FF, FExpand (F));
  612. GetFAttr (FF, A);
  613. PathExists := (DosError = 0) and (A and Directory = Directory);
  614. {$ENDIF USE_SYSUTILS}
  615. end;
  616. Function RemoveFile(const f:string):boolean;
  617. var
  618. g : file;
  619. begin
  620. assign(g,f);
  621. {$I-}
  622. erase(g);
  623. {$I+}
  624. RemoveFile:=(ioresult=0);
  625. end;
  626. Function RemoveDir(d:string):boolean;
  627. begin
  628. if d[length(d)]=source_info.DirSep then
  629. Delete(d,length(d),1);
  630. {$I-}
  631. rmdir(d);
  632. {$I+}
  633. RemoveDir:=(ioresult=0);
  634. end;
  635. Function SplitPath(const s:string):string;
  636. var
  637. i : longint;
  638. begin
  639. i:=Length(s);
  640. {$ifdef macos}
  641. while (i>0) and not(s[i] in [':']) do
  642. dec(i);
  643. {$else macos}
  644. while (i>0) and not(s[i] in ['/','\']) do
  645. dec(i);
  646. {$endif macos}
  647. SplitPath:=Copy(s,1,i);
  648. end;
  649. Function SplitFileName(const s:string):string;
  650. {$IFDEF USE_SYSUTILS}
  651. {$ELSE USE_SYSUTILS}
  652. var
  653. p : dirstr;
  654. n : namestr;
  655. e : extstr;
  656. {$ENDIF USE_SYSUTILS}
  657. begin
  658. {$IFDEF USE_SYSUTILS}
  659. SplitFileName:=ExtractFileName(s);
  660. {$ELSE USE_SYSUTILS}
  661. FSplit(s,p,n,e);
  662. SplitFileName:=n+e;
  663. {$ENDIF USE_SYSUTILS}
  664. end;
  665. Function SplitName(const s:string):string;
  666. var
  667. i,j : longint;
  668. begin
  669. i:=Length(s);
  670. j:=Length(s);
  671. while (i>0) and not(s[i] in ['/','\']) do
  672. dec(i);
  673. while (j>0) and (s[j]<>'.') do
  674. dec(j);
  675. if j<=i then
  676. j:=255;
  677. SplitName:=Copy(s,i+1,j-(i+1));
  678. end;
  679. Function SplitExtension(Const HStr:String):String;
  680. var
  681. j : longint;
  682. begin
  683. j:=length(Hstr);
  684. while (j>0) and (Hstr[j]<>'.') do
  685. begin
  686. if hstr[j]=source_info.DirSep then
  687. j:=0
  688. else
  689. dec(j);
  690. end;
  691. if j=0 then
  692. j:=254;
  693. SplitExtension:=Copy(Hstr,j,255);
  694. end;
  695. Function AddExtension(Const HStr,ext:String):String;
  696. begin
  697. if (Ext<>'') and (SplitExtension(HStr)='') then
  698. AddExtension:=Hstr+Ext
  699. else
  700. AddExtension:=Hstr;
  701. end;
  702. Function ForceExtension(Const HStr,ext:String):String;
  703. var
  704. j : longint;
  705. begin
  706. j:=length(Hstr);
  707. while (j>0) and (Hstr[j]<>'.') do
  708. dec(j);
  709. if j=0 then
  710. j:=255;
  711. ForceExtension:=Copy(Hstr,1,j-1)+Ext;
  712. end;
  713. Function FixPath(s:string;allowdot:boolean):string;
  714. var
  715. i : longint;
  716. begin
  717. { Fix separator }
  718. for i:=1 to length(s) do
  719. if s[i] in ['/','\'] then
  720. s[i]:=source_info.DirSep;
  721. { Fix ending / }
  722. if (length(s)>0) and (s[length(s)]<>source_info.DirSep) and
  723. (s[length(s)]<>':') then
  724. s:=s+source_info.DirSep;
  725. { Remove ./ }
  726. if (not allowdot) and (s='.'+source_info.DirSep) then
  727. s:='';
  728. { return }
  729. if source_info.files_case_relevent then
  730. FixPath:=s
  731. else
  732. FixPath:=Lower(s);
  733. end;
  734. {Actually the version in macutils.pp could be used,
  735. but that would not work for crosscompiling, so this is a slightly modified
  736. version of it.}
  737. function TranslatePathToMac (const path: string; mpw: Boolean): string;
  738. function GetVolumeIdentifier: string;
  739. begin
  740. GetVolumeIdentifier := '{Boot}'
  741. (*
  742. if mpw then
  743. GetVolumeIdentifier := '{Boot}'
  744. else
  745. GetVolumeIdentifier := macosBootVolumeName;
  746. *)
  747. end;
  748. var
  749. slashPos, oldpos, newpos, oldlen, maxpos: Longint;
  750. begin
  751. oldpos := 1;
  752. slashPos := Pos('/', path);
  753. if (slashPos <> 0) then {its a unix path}
  754. begin
  755. if slashPos = 1 then
  756. begin {its a full path}
  757. oldpos := 2;
  758. TranslatePathToMac := GetVolumeIdentifier;
  759. end
  760. else {its a partial path}
  761. TranslatePathToMac := ':';
  762. end
  763. else
  764. begin
  765. slashPos := Pos('\', path);
  766. if (slashPos <> 0) then {its a dos path}
  767. begin
  768. if slashPos = 1 then
  769. begin {its a full path, without drive letter}
  770. oldpos := 2;
  771. TranslatePathToMac := GetVolumeIdentifier;
  772. end
  773. else if (Length(path) >= 2) and (path[2] = ':') then {its a full path, with drive letter}
  774. begin
  775. oldpos := 4;
  776. TranslatePathToMac := GetVolumeIdentifier;
  777. end
  778. else {its a partial path}
  779. TranslatePathToMac := ':';
  780. end;
  781. end;
  782. if (slashPos <> 0) then {its a unix or dos path}
  783. begin
  784. {Translate "/../" to "::" , "/./" to ":" and "/" to ":" }
  785. newpos := Length(TranslatePathToMac);
  786. oldlen := Length(path);
  787. SetLength(TranslatePathToMac, newpos + oldlen); {It will be no longer than what is already}
  788. {prepended plus length of path.}
  789. maxpos := Length(TranslatePathToMac); {Get real maxpos, can be short if String is ShortString}
  790. {There is never a slash in the beginning, because either it was an absolute path, and then the}
  791. {drive and slash was removed, or it was a relative path without a preceding slash.}
  792. while oldpos <= oldlen do
  793. begin
  794. {Check if special dirs, ./ or ../ }
  795. if path[oldPos] = '.' then
  796. if (oldpos + 1 <= oldlen) and (path[oldPos + 1] = '.') then
  797. begin
  798. if (oldpos + 2 > oldlen) or (path[oldPos + 2] in ['/', '\']) then
  799. begin
  800. {It is "../" or ".." translates to ":" }
  801. if newPos = maxPos then
  802. begin {Shouldn't actually happen, but..}
  803. Exit('');
  804. end;
  805. newPos := newPos + 1;
  806. TranslatePathToMac[newPos] := ':';
  807. oldPos := oldPos + 3;
  808. continue; {Start over again}
  809. end;
  810. end
  811. else if (oldpos + 1 > oldlen) or (path[oldPos + 1] in ['/', '\']) then
  812. begin
  813. {It is "./" or "." ignor it }
  814. oldPos := oldPos + 2;
  815. continue; {Start over again}
  816. end;
  817. {Collect file or dir name}
  818. while (oldpos <= oldlen) and not (path[oldPos] in ['/', '\']) do
  819. begin
  820. if newPos = maxPos then
  821. begin {Shouldn't actually happen, but..}
  822. Exit('');
  823. end;
  824. newPos := newPos + 1;
  825. TranslatePathToMac[newPos] := path[oldPos];
  826. oldPos := oldPos + 1;
  827. end;
  828. {When we come here there is either a slash or we are at the end.}
  829. if (oldpos <= oldlen) then
  830. begin
  831. if newPos = maxPos then
  832. begin {Shouldn't actually happen, but..}
  833. Exit('');
  834. end;
  835. newPos := newPos + 1;
  836. TranslatePathToMac[newPos] := ':';
  837. oldPos := oldPos + 1;
  838. end;
  839. end;
  840. SetLength(TranslatePathToMac, newpos);
  841. end
  842. else if (path = '.') then
  843. TranslatePathToMac := ':'
  844. else if (path = '..') then
  845. TranslatePathToMac := '::'
  846. else
  847. TranslatePathToMac := path; {its a mac path}
  848. end;
  849. function FixFileName(const s:string):string;
  850. var
  851. i : longint;
  852. begin
  853. if source_info.system = system_powerpc_MACOS then
  854. FixFileName:= TranslatePathToMac(s, true)
  855. else if source_info.files_case_relevent then
  856. begin
  857. for i:=1 to length(s) do
  858. begin
  859. case s[i] of
  860. '/','\' :
  861. FixFileName[i]:=source_info.dirsep;
  862. else
  863. FixFileName[i]:=s[i];
  864. end;
  865. end;
  866. FixFileName[0]:=s[0];
  867. end
  868. else
  869. begin
  870. for i:=1 to length(s) do
  871. begin
  872. case s[i] of
  873. '/','\' :
  874. FixFileName[i]:=source_info.dirsep;
  875. 'A'..'Z' :
  876. FixFileName[i]:=char(byte(s[i])+32);
  877. else
  878. FixFileName[i]:=s[i];
  879. end;
  880. end;
  881. FixFileName[0]:=s[0];
  882. end;
  883. end;
  884. Function TargetFixPath(s:string;allowdot:boolean):string;
  885. var
  886. i : longint;
  887. begin
  888. { Fix separator }
  889. for i:=1 to length(s) do
  890. if s[i] in ['/','\'] then
  891. s[i]:=target_info.DirSep;
  892. { Fix ending / }
  893. if (length(s)>0) and (s[length(s)]<>target_info.DirSep) and
  894. (s[length(s)]<>':') then
  895. s:=s+target_info.DirSep;
  896. { Remove ./ }
  897. if (not allowdot) and (s='.'+target_info.DirSep) then
  898. s:='';
  899. { return }
  900. if target_info.files_case_relevent then
  901. TargetFixPath:=s
  902. else
  903. TargetFixPath:=Lower(s);
  904. end;
  905. function TargetFixFileName(const s:string):string;
  906. var
  907. i : longint;
  908. begin
  909. if target_info.system = system_powerpc_MACOS then
  910. TargetFixFileName:= TranslatePathToMac(s, true)
  911. else if target_info.files_case_relevent then
  912. begin
  913. for i:=1 to length(s) do
  914. begin
  915. case s[i] of
  916. '/','\' :
  917. TargetFixFileName[i]:=target_info.dirsep;
  918. else
  919. TargetFixFileName[i]:=s[i];
  920. end;
  921. end;
  922. TargetFixFileName[0]:=s[0];
  923. end
  924. else
  925. begin
  926. for i:=1 to length(s) do
  927. begin
  928. case s[i] of
  929. '/','\' :
  930. TargetFixFileName[i]:=target_info.dirsep;
  931. 'A'..'Z' :
  932. TargetFixFileName[i]:=char(byte(s[i])+32);
  933. else
  934. TargetFixFileName[i]:=s[i];
  935. end;
  936. end;
  937. TargetFixFileName[0]:=s[0];
  938. end;
  939. end;
  940. procedure SplitBinCmd(const s:string;var bstr:String;var cstr:TCmdStr);
  941. var
  942. i : longint;
  943. begin
  944. i:=pos(' ',s);
  945. if i>0 then
  946. begin
  947. bstr:=Copy(s,1,i-1);
  948. cstr:=Copy(s,i+1,length(s)-i);
  949. end
  950. else
  951. begin
  952. bstr:=s;
  953. cstr:='';
  954. end;
  955. end;
  956. procedure TSearchPathList.AddPath(s:string;addfirst:boolean);
  957. begin
  958. AddPath('',s,AddFirst);
  959. end;
  960. procedure TSearchPathList.AddPath(SrcPath,s:string;addfirst:boolean);
  961. var
  962. staridx,
  963. j : longint;
  964. prefix,
  965. suffix,
  966. CurrentDir,
  967. currPath : string;
  968. subdirfound : boolean;
  969. {$IFDEF USE_SYSUTILS}
  970. dir : TSearchRec;
  971. {$ELSE USE_SYSUTILS}
  972. dir : searchrec;
  973. {$ENDIF USE_SYSUTILS}
  974. hp : TStringListItem;
  975. procedure AddCurrPath;
  976. begin
  977. if addfirst then
  978. begin
  979. Remove(currPath);
  980. Insert(currPath);
  981. end
  982. else
  983. begin
  984. { Check if already in path, then we don't add it }
  985. hp:=Find(currPath);
  986. if not assigned(hp) then
  987. Concat(currPath);
  988. end;
  989. end;
  990. begin
  991. if s='' then
  992. exit;
  993. { Support default macro's }
  994. DefaultReplacements(s);
  995. { get current dir }
  996. CurrentDir:=GetCurrentDir;
  997. repeat
  998. { get currpath }
  999. if addfirst then
  1000. begin
  1001. j:=length(s);
  1002. while (j>0) and (s[j]<>';') do
  1003. dec(j);
  1004. currPath:= TrimSpace(Copy(s,j+1,length(s)-j));
  1005. DePascalQuote(currPath);
  1006. currPath:=FixPath(currPath,false);
  1007. if j=0 then
  1008. s:=''
  1009. else
  1010. System.Delete(s,j,length(s)-j+1);
  1011. end
  1012. else
  1013. begin
  1014. j:=Pos(';',s);
  1015. if j=0 then
  1016. j:=255;
  1017. currPath:= TrimSpace(Copy(s,1,j-1));
  1018. DePascalQuote(currPath);
  1019. currPath:=SrcPath+FixPath(currPath,false);
  1020. System.Delete(s,1,j);
  1021. end;
  1022. { fix pathname }
  1023. if currPath='' then
  1024. currPath:= CurDirRelPath(source_info)
  1025. else
  1026. begin
  1027. {$ifdef USE_SYSUTILS}
  1028. currPath:=FixPath(ExpandFileName(currpath),false);
  1029. {$else USE_SYSUTILS}
  1030. currPath:=FixPath(FExpand(currPath),false);
  1031. {$endif USE_SYSUTILS}
  1032. if (CurrentDir<>'') and (Copy(currPath,1,length(CurrentDir))=CurrentDir) then
  1033. begin
  1034. {$ifdef AMIGA}
  1035. currPath:= CurrentDir+Copy(currPath,length(CurrentDir)+1,255);
  1036. {$else}
  1037. currPath:= CurDirRelPath(source_info)+Copy(currPath,length(CurrentDir)+1,255);
  1038. {$endif}
  1039. end;
  1040. end;
  1041. { wildcard adding ? }
  1042. staridx:=pos('*',currpath);
  1043. if staridx>0 then
  1044. begin
  1045. prefix:=SplitPath(Copy(currpath,1,staridx));
  1046. suffix:=Copy(currpath,staridx+1,length(currpath));
  1047. subdirfound:=false;
  1048. {$IFDEF USE_SYSUTILS}
  1049. if findfirst(prefix+'*',faDirectory,dir) = 0 then
  1050. begin
  1051. repeat
  1052. if (dir.name<>'.') and
  1053. (dir.name<>'..') and
  1054. ((dir.attr and faDirectory)<>0) then
  1055. begin
  1056. subdirfound:=true;
  1057. currpath:=prefix+dir.name+suffix;
  1058. if (suffix='') or PathExists(currpath) then
  1059. begin
  1060. hp:=Find(currPath);
  1061. if not assigned(hp) then
  1062. AddCurrPath;
  1063. end;
  1064. end;
  1065. until findnext(dir) <> 0;
  1066. end;
  1067. {$ELSE USE_SYSUTILS}
  1068. findfirst(prefix+'*',directory,dir);
  1069. while doserror=0 do
  1070. begin
  1071. if (dir.name<>'.') and
  1072. (dir.name<>'..') and
  1073. ((dir.attr and directory)<>0) then
  1074. begin
  1075. subdirfound:=true;
  1076. currpath:=prefix+dir.name+suffix;
  1077. if (suffix='') or PathExists(currpath) then
  1078. begin
  1079. hp:=Find(currPath);
  1080. if not assigned(hp) then
  1081. AddCurrPath;
  1082. end;
  1083. end;
  1084. findnext(dir);
  1085. end;
  1086. {$ENDIF USE_SYSUTILS}
  1087. FindClose(dir);
  1088. if not subdirfound then
  1089. WarnNonExistingPath(currpath);
  1090. end
  1091. else
  1092. begin
  1093. if PathExists(currpath) then
  1094. AddCurrPath
  1095. else
  1096. WarnNonExistingPath(currpath);
  1097. end;
  1098. until (s='');
  1099. end;
  1100. procedure TSearchPathList.AddList(list:TSearchPathList;addfirst:boolean);
  1101. var
  1102. s : string;
  1103. hl : TSearchPathList;
  1104. hp,hp2 : TStringListItem;
  1105. begin
  1106. if list.empty then
  1107. exit;
  1108. { create temp and reverse the list }
  1109. if addfirst then
  1110. begin
  1111. hl:=TSearchPathList.Create;
  1112. hp:=TStringListItem(list.first);
  1113. while assigned(hp) do
  1114. begin
  1115. hl.insert(hp.Str);
  1116. hp:=TStringListItem(hp.next);
  1117. end;
  1118. while not hl.empty do
  1119. begin
  1120. s:=hl.GetFirst;
  1121. Remove(s);
  1122. Insert(s);
  1123. end;
  1124. hl.Free;
  1125. end
  1126. else
  1127. begin
  1128. hp:=TStringListItem(list.first);
  1129. while assigned(hp) do
  1130. begin
  1131. hp2:=Find(hp.Str);
  1132. { Check if already in path, then we don't add it }
  1133. if not assigned(hp2) then
  1134. Concat(hp.Str);
  1135. hp:=TStringListItem(hp.next);
  1136. end;
  1137. end;
  1138. end;
  1139. function TSearchPathList.FindFile(const f : string;var foundfile:string):boolean;
  1140. Var
  1141. p : TStringListItem;
  1142. begin
  1143. FindFile:=false;
  1144. p:=TStringListItem(first);
  1145. while assigned(p) do
  1146. begin
  1147. result:=FileExistsNonCase(p.Str,f,FoundFile);
  1148. if result then
  1149. exit;
  1150. p:=TStringListItem(p.next);
  1151. end;
  1152. { Return original filename if not found }
  1153. FoundFile:=f;
  1154. end;
  1155. Function GetFileTime ( Var F : File) : Longint;
  1156. Var
  1157. {$ifdef hasunix}
  1158. info: Stat;
  1159. {$endif}
  1160. L : longint;
  1161. begin
  1162. {$ifdef hasunix}
  1163. {$IFDEF havelinuxrtl10}
  1164. FStat (F,Info);
  1165. L:=Info.Mtime;
  1166. {$ELSE}
  1167. FPFStat (F,Info);
  1168. L:=Info.st_Mtime;
  1169. {$ENDIF}
  1170. {$else}
  1171. GetFTime(f,l);
  1172. {$endif}
  1173. GetFileTime:=L;
  1174. end;
  1175. Function GetNamedFileTime (Const F : String) : Longint;
  1176. begin
  1177. GetNamedFileTime:=do_getnamedfiletime(F);
  1178. end;
  1179. function FindFile(const f : string;path : string;var foundfile:string):boolean;
  1180. Var
  1181. singlepathstring : string;
  1182. i : longint;
  1183. begin
  1184. {$ifdef Unix}
  1185. for i:=1 to length(path) do
  1186. if path[i]=':' then
  1187. path[i]:=';';
  1188. {$endif Unix}
  1189. FindFile:=false;
  1190. repeat
  1191. i:=pos(';',path);
  1192. if i=0 then
  1193. i:=256;
  1194. singlepathstring:=FixPath(copy(path,1,i-1),false);
  1195. delete(path,1,i);
  1196. result:=FileExistsNonCase(singlepathstring,f,FoundFile);
  1197. if result then
  1198. exit;
  1199. until path='';
  1200. FoundFile:=f;
  1201. end;
  1202. function FindFilePchar(const f : string;path : pchar;var foundfile:string):boolean;
  1203. Var
  1204. singlepathstring : string;
  1205. startpc,pc : pchar;
  1206. sepch : char;
  1207. begin
  1208. FindFilePchar:=false;
  1209. if Assigned (Path) then
  1210. begin
  1211. {$ifdef Unix}
  1212. sepch:=':';
  1213. {$else}
  1214. {$ifdef macos}
  1215. sepch:=',';
  1216. {$else}
  1217. sepch:=';';
  1218. {$endif macos}
  1219. {$endif Unix}
  1220. pc:=path;
  1221. repeat
  1222. startpc:=pc;
  1223. while (pc^<>sepch) and (pc^<>';') and (pc^<>#0) do
  1224. inc(pc);
  1225. move(startpc^,singlepathstring[1],pc-startpc);
  1226. singlepathstring[0]:=char(longint(pc-startpc));
  1227. singlepathstring:=FixPath(singlepathstring,false);
  1228. result:=FileExistsNonCase(singlepathstring,f,FoundFile);
  1229. if result then
  1230. exit;
  1231. if (pc^=#0) then
  1232. break;
  1233. inc(pc);
  1234. until false;
  1235. end;
  1236. foundfile:=f;
  1237. end;
  1238. function FindExe(const bin:string;var foundfile:string):boolean;
  1239. var
  1240. p : pchar;
  1241. found : boolean;
  1242. begin
  1243. found:=FindFile(FixFileName(AddExtension(bin,source_info.exeext)),'.;'+exepath,foundfile);
  1244. if not found then
  1245. begin
  1246. {$ifdef macos}
  1247. p:=GetEnvPchar('Commands');
  1248. {$else}
  1249. p:=GetEnvPchar('PATH');
  1250. {$endif}
  1251. found:=FindFilePChar(FixFileName(AddExtension(bin,source_info.exeext)),p,foundfile);
  1252. FreeEnvPChar(p);
  1253. end;
  1254. FindExe:=found;
  1255. end;
  1256. function GetShortName(const n:string):string;
  1257. {$ifdef win32}
  1258. var
  1259. hs,hs2 : string;
  1260. i : longint;
  1261. {$endif}
  1262. {$ifdef go32v2}
  1263. var
  1264. hs : string;
  1265. {$endif}
  1266. {$ifdef watcom}
  1267. var
  1268. hs : string;
  1269. {$endif}
  1270. begin
  1271. GetShortName:=n;
  1272. {$ifdef win32}
  1273. hs:=n+#0;
  1274. i:=Windows.GetShortPathName(@hs[1],@hs2[1],high(hs2));
  1275. if (i>0) and (i<=high(hs2)) then
  1276. begin
  1277. hs2[0]:=chr(strlen(@hs2[1]));
  1278. GetShortName:=hs2;
  1279. end;
  1280. {$endif}
  1281. {$ifdef go32v2}
  1282. hs:=n;
  1283. if Dos.GetShortName(hs) then
  1284. GetShortName:=hs;
  1285. {$endif}
  1286. {$ifdef watcom}
  1287. hs:=n;
  1288. if Dos.GetShortName(hs) then
  1289. GetShortName:=hs;
  1290. {$endif}
  1291. end;
  1292. function CleanPath(const s:string):String;
  1293. { Wrapper that encapsulate fexpand/expandfilename}
  1294. begin
  1295. {$IFDEF USE_SYSUTILS}
  1296. cleanpath:=ExpandFileName(s);
  1297. {$else}
  1298. cleanpath:=fexpand(s);
  1299. {$endif}
  1300. end;
  1301. {****************************************************************************
  1302. OS Dependent things
  1303. ****************************************************************************}
  1304. function GetEnvPChar(const envname:string):pchar;
  1305. {$ifdef win32}
  1306. var
  1307. s : string;
  1308. i,len : longint;
  1309. hp,p,p2 : pchar;
  1310. {$endif}
  1311. begin
  1312. {$ifdef hasunix}
  1313. GetEnvPchar:={$ifdef havelinuxrtl10}Linux.getenv{$else}BaseUnix.fpGetEnv{$endif}(envname);
  1314. {$define GETENVOK}
  1315. {$endif}
  1316. {$ifdef win32}
  1317. GetEnvPchar:=nil;
  1318. p:=GetEnvironmentStrings;
  1319. hp:=p;
  1320. while hp^<>#0 do
  1321. begin
  1322. s:=strpas(hp);
  1323. i:=pos('=',s);
  1324. len:=strlen(hp);
  1325. if upper(copy(s,1,i-1))=upper(envname) then
  1326. begin
  1327. GetMem(p2,len-length(envname));
  1328. Move(hp[i],p2^,len-length(envname));
  1329. GetEnvPchar:=p2;
  1330. break;
  1331. end;
  1332. { next string entry}
  1333. hp:=hp+len+1;
  1334. end;
  1335. FreeEnvironmentStrings(p);
  1336. {$define GETENVOK}
  1337. {$endif}
  1338. {$ifdef os2}
  1339. GetEnvPChar := Dos.GetEnvPChar (EnvName);
  1340. {$define GETENVOK}
  1341. {$endif}
  1342. {$ifdef GETENVOK}
  1343. {$undef GETENVOK}
  1344. {$else}
  1345. GetEnvPchar:=StrPNew(Dos.Getenv(envname));
  1346. {$endif}
  1347. end;
  1348. procedure FreeEnvPChar(p:pchar);
  1349. begin
  1350. {$ifndef hasunix}
  1351. {$ifndef os2}
  1352. StrDispose(p);
  1353. {$endif}
  1354. {$endif}
  1355. end;
  1356. {$IFDEF MORPHOS}
  1357. {$DEFINE AMIGASHELL}
  1358. {$ENDIF}
  1359. {$IFDEF AMIGA}
  1360. {$DEFINE AMIGASHELL}
  1361. {$ENDIF}
  1362. function Shell(const command:string): longint;
  1363. { This is already defined in the linux.ppu for linux, need for the *
  1364. expansion under linux }
  1365. {$ifdef hasunix}
  1366. begin
  1367. result := {$ifdef havelinuxrtl10}Linux{$else}Unix{$endif}.Shell(command);
  1368. end;
  1369. {$else}
  1370. {$ifdef amigashell}
  1371. begin
  1372. {$IFDEF USE_SYSUTILS}
  1373. result := ExecuteProcess('',command);
  1374. {$ELSE USE_SYSUTILS}
  1375. exec('',command);
  1376. if (doserror <> 0) then
  1377. result := doserror
  1378. else
  1379. result := dosexitcode;
  1380. end;
  1381. {$ENDIF USE_SYSUTILS}
  1382. {$else}
  1383. var
  1384. comspec : string;
  1385. begin
  1386. comspec:=getenv('COMSPEC');
  1387. {$IFDEF USE_SYSUTILS}
  1388. result := ExecuteProcess(comspec,' /C '+command);
  1389. {$ELSE USE_SYSUTILS}
  1390. Exec(comspec,' /C '+command);
  1391. if (doserror <> 0) then
  1392. result := doserror
  1393. else
  1394. result := dosexitcode;
  1395. end;
  1396. {$ENDIF USE_SYSUTILS}
  1397. {$endif}
  1398. {$endif}
  1399. {$UNDEF AMIGASHELL}
  1400. {$ifdef CPUI386}
  1401. {$asmmode att}
  1402. {$define HASSETFPUEXCEPTIONMASK}
  1403. { later, this should be replaced by the math unit }
  1404. const
  1405. Default8087CW : word = $1332;
  1406. procedure Set8087CW(cw:word);assembler;
  1407. asm
  1408. movw cw,%ax
  1409. movw %ax,default8087cw
  1410. fnclex
  1411. fldcw default8087cw
  1412. end;
  1413. function Get8087CW:word;assembler;
  1414. asm
  1415. pushl $0
  1416. fnstcw (%esp)
  1417. popl %eax
  1418. end;
  1419. procedure SetFPUExceptionMask(const Mask: TFPUExceptionMask);
  1420. var
  1421. CtlWord: Word;
  1422. begin
  1423. CtlWord:=Get8087CW;
  1424. Set8087CW( (CtlWord and $FFC0) or Byte(Longint(Mask)) );
  1425. end;
  1426. {$endif CPUI386}
  1427. {$ifdef CPUX86_64}
  1428. {$define HASSETFPUEXCEPTIONMASK}
  1429. { later, this should be replaced by the math unit }
  1430. const
  1431. Default8087CW : word = $1332;
  1432. procedure Set8087CW(cw:word);assembler;
  1433. asm
  1434. movw cw,%ax
  1435. movw %ax,default8087cw
  1436. fnclex
  1437. fldcw default8087cw
  1438. end;
  1439. function Get8087CW:word;assembler;
  1440. asm
  1441. pushq $0
  1442. fnstcw (%rsp)
  1443. popq %rax
  1444. end;
  1445. procedure SetSSECSR(w : dword);
  1446. var
  1447. _w : dword;
  1448. begin
  1449. _w:=w;
  1450. asm
  1451. ldmxcsr _w
  1452. end;
  1453. end;
  1454. function GetSSECSR : dword;
  1455. var
  1456. _w : dword;
  1457. begin
  1458. asm
  1459. stmxcsr _w
  1460. end;
  1461. result:=_w;
  1462. end;
  1463. procedure SetFPUExceptionMask(const Mask: TFPUExceptionMask);
  1464. var
  1465. CtlWord: Word;
  1466. newmask : dword;
  1467. const
  1468. MM_MaskInvalidOp = %0000000010000000;
  1469. MM_MaskDenorm = %0000000100000000;
  1470. MM_MaskDivZero = %0000001000000000;
  1471. MM_MaskOverflow = %0000010000000000;
  1472. MM_MaskUnderflow = %0000100000000000;
  1473. MM_MaskPrecision = %0001000000000000;
  1474. begin
  1475. { classic FPU }
  1476. CtlWord:=Get8087CW;
  1477. Set8087CW( (CtlWord and $FFC0) or Byte(Longint(Mask)) );
  1478. { SSE }
  1479. newmask:=GetSSECSR;
  1480. { invalid operation }
  1481. if (exInvalidOp in mask) then
  1482. newmask:=newmask or MM_MaskInvalidOp
  1483. else
  1484. newmask:=newmask and not(MM_MaskInvalidOp);
  1485. { denormals }
  1486. if (exDenormalized in mask) then
  1487. newmask:=newmask or MM_MaskDenorm
  1488. else
  1489. newmask:=newmask and not(MM_MaskDenorm);
  1490. { zero divide }
  1491. if (exZeroDivide in mask) then
  1492. newmask:=newmask or MM_MaskDivZero
  1493. else
  1494. newmask:=newmask and not(MM_MaskDivZero);
  1495. { overflow }
  1496. if (exOverflow in mask) then
  1497. newmask:=newmask or MM_MaskOverflow
  1498. else
  1499. newmask:=newmask and not(MM_MaskOverflow);
  1500. { underflow }
  1501. if (exUnderflow in mask) then
  1502. newmask:=newmask or MM_MaskUnderflow
  1503. else
  1504. newmask:=newmask and not(MM_MaskUnderflow);
  1505. { Precision (inexact result) }
  1506. if (exPrecision in mask) then
  1507. newmask:=newmask or MM_MaskPrecision
  1508. else
  1509. newmask:=newmask and not(MM_MaskPrecision);
  1510. SetSSECSR(newmask);
  1511. end;
  1512. {$endif CPUX86_64}
  1513. {$ifdef CPUPOWERPC}
  1514. {$define HASSETFPUEXCEPTIONMASK}
  1515. procedure SetFPUExceptionMask(const Mask: TFPUExceptionMask);
  1516. var
  1517. newmask: record
  1518. case byte of
  1519. 1: (d: double);
  1520. 2: (a,b: cardinal);
  1521. end;
  1522. begin
  1523. { load current control register contents }
  1524. asm
  1525. mffs f0
  1526. stfd f0,newmask.d
  1527. end;
  1528. { invalid operation: bit 24 (big endian, bit 0 = left-most bit) }
  1529. if (exInvalidOp in mask) then
  1530. newmask.b := newmask.b and not(1 shl (31-24))
  1531. else
  1532. newmask.b := newmask.b or (1 shl (31-24));
  1533. { denormals can not cause exceptions on the PPC }
  1534. { zero divide: bit 27 }
  1535. if (exZeroDivide in mask) then
  1536. newmask.b := newmask.b and not(1 shl (31-27))
  1537. else
  1538. newmask.b := newmask.b or (1 shl (31-27));
  1539. { overflow: bit 25 }
  1540. if (exOverflow in mask) then
  1541. newmask.b := newmask.b and not(1 shl (31-25))
  1542. else
  1543. newmask.b := newmask.b or (1 shl (31-25));
  1544. { underflow: bit 26 }
  1545. if (exUnderflow in mask) then
  1546. newmask.b := newmask.b and not(1 shl (31-26))
  1547. else
  1548. newmask.b := newmask.b or (1 shl (31-26));
  1549. { Precision (inexact result): bit 28 }
  1550. if (exPrecision in mask) then
  1551. newmask.b := newmask.b and not(1 shl (31-28))
  1552. else
  1553. newmask.b := newmask.b or (1 shl (31-28));
  1554. { update control register contents }
  1555. asm
  1556. lfd f0, newmask.d
  1557. mtfsf 255,f0
  1558. end;
  1559. end;
  1560. {$endif CPUPOWERPC}
  1561. {$ifdef CPUSPARC}
  1562. {$define HASSETFPUEXCEPTIONMASK}
  1563. procedure SetFPUExceptionMask(const Mask: TFPUExceptionMask);
  1564. var
  1565. fsr : cardinal;
  1566. begin
  1567. { load current control register contents }
  1568. asm
  1569. st %fsr,fsr
  1570. end;
  1571. { invalid operation: bit 27 }
  1572. if (exInvalidOp in mask) then
  1573. fsr:=fsr and not(1 shl 27)
  1574. else
  1575. fsr:=fsr or (1 shl 27);
  1576. { zero divide: bit 24 }
  1577. if (exZeroDivide in mask) then
  1578. fsr:=fsr and not(1 shl 24)
  1579. else
  1580. fsr:=fsr or (1 shl 24);
  1581. { overflow: bit 26 }
  1582. if (exOverflow in mask) then
  1583. fsr:=fsr and not(1 shl 26)
  1584. else
  1585. fsr:=fsr or (1 shl 26);
  1586. { underflow: bit 25 }
  1587. if (exUnderflow in mask) then
  1588. fsr:=fsr and not(1 shl 25)
  1589. else
  1590. fsr:=fsr or (1 shl 25);
  1591. { Precision (inexact result): bit 23 }
  1592. if (exPrecision in mask) then
  1593. fsr:=fsr and not(1 shl 23)
  1594. else
  1595. fsr:=fsr or (1 shl 23);
  1596. { update control register contents }
  1597. asm
  1598. ld fsr,%fsr
  1599. end;
  1600. end;
  1601. {$endif CPUSPARC}
  1602. {$ifndef HASSETFPUEXCEPTIONMASK}
  1603. procedure SetFPUExceptionMask(const Mask: TFPUExceptionMask);
  1604. begin
  1605. end;
  1606. {$endif HASSETFPUEXCEPTIONMASK}
  1607. function is_number_float(d : double) : boolean;
  1608. var
  1609. bytearray : array[0..7] of byte;
  1610. begin
  1611. move(d,bytearray,8);
  1612. { only 1.1 save, 1.0.x will use always little endian }
  1613. {$ifdef FPC_BIG_ENDIAN}
  1614. result:=((bytearray[0] and $7f)<>$7f) or ((bytearray[1] and $f0)<>$f0);
  1615. {$else FPC_BIG_ENDIAN}
  1616. result:=((bytearray[7] and $7f)<>$7f) or ((bytearray[6] and $f0)<>$f0);
  1617. {$endif FPC_BIG_ENDIAN}
  1618. end;
  1619. function get_real_sign(r: bestreal): longint;
  1620. var
  1621. p: pbyte;
  1622. begin
  1623. p := @r;
  1624. {$ifdef CPU_ARM}
  1625. inc(p,4);
  1626. {$else}
  1627. {$ifdef FPC_LITTLE_ENDIAN}
  1628. inc(p,sizeof(r)-1);
  1629. {$endif}
  1630. {$endif}
  1631. if (p^ and $80) = 0 then
  1632. result := 1
  1633. else
  1634. result := -1;
  1635. end;
  1636. function convertdoublearray(d : tdoublearray) : tdoublearray;{$ifdef USEINLINE}inline;{$endif}
  1637. {$ifdef CPUARM}
  1638. var
  1639. i : longint;
  1640. begin
  1641. for i:=0 to 3 do
  1642. begin
  1643. result[i+4]:=d[i];
  1644. result[i]:=d[i+4];
  1645. end;
  1646. {$else CPUARM}
  1647. begin
  1648. result:=d;
  1649. {$endif CPUARM}
  1650. end;
  1651. function SetAktProcCall(const s:string; changeInit:boolean):boolean;
  1652. const
  1653. DefProcCallName : array[tproccalloption] of string[12] = ('',
  1654. 'CDECL',
  1655. 'CPPDECL',
  1656. 'FAR16',
  1657. 'OLDFPCCALL',
  1658. '', { internproc }
  1659. '', { syscall }
  1660. 'PASCAL',
  1661. 'REGISTER',
  1662. 'SAFECALL',
  1663. 'STDCALL',
  1664. 'SOFTFLOAT',
  1665. 'MWPASCAL'
  1666. );
  1667. var
  1668. t : tproccalloption;
  1669. begin
  1670. result:=false;
  1671. if (s = '') then
  1672. exit;
  1673. if (s = 'DEFAULT') then
  1674. begin
  1675. AktDefProcCall := pocall_default;
  1676. result := true;
  1677. exit;
  1678. end;
  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. LinkLibraryAliases :=TLinkStrMap.Create;
  2027. LinkLibraryOrder :=TLinkStrMap.Create;
  2028. end;
  2029. end.