scandir.inc 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455
  1. {
  2. $Id$
  3. Copyright (c) 1998-2000 by Peter Vreman
  4. This unit implements directive parsing for the scanner
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. const
  19. directivelen=15;
  20. type
  21. directivestr=string[directivelen];
  22. tdirectivetoken=(
  23. _DIR_NONE,
  24. _DIR_ALIGN,_DIR_APPTYPE,_DIR_ASMMODE,_DIR_ASSERTIONS,
  25. _DIR_BOOLEVAL,
  26. _DIR_D,_DIR_DEBUGINFO,_DIR_DEFINE,_DIR_DESCRIPTION,
  27. _DIR_ELSE,_DIR_ENDIF,_DIR_ERROR,_DIR_EXTENDEDSYNTAX,
  28. _DIR_FATAL,
  29. _DIR_GOTO,
  30. _DIR_HINT,_DIR_HINTS,
  31. _DIR_I,_DIR_I386_ATT,_DIR_I386_DIRECT,_DIR_I386_INTEL,_DIR_IOCHECKS,
  32. _DIR_IF,_DIR_IFDEF,_DIR_IFNDEF,_DIR_IFOPT,_DIR_INCLUDE,_DIR_INCLUDEPATH,
  33. _DIR_INFO,_DIR_INLINE,
  34. _DIR_INTERFACES,
  35. _DIR_L,_DIR_LIBRARYPATH,_DIR_LINK,_DIR_LINKLIB,_DIR_LOCALSYMBOLS,
  36. _DIR_LONGSTRINGS,
  37. _DIR_M,_DIR_MACRO,_DIR_MAXFPUREGISTERS,_DIR_MEMORY,_DIR_MESSAGE,_DIR_MINENUMSIZE,_DIR_MMX,_DIR_MODE,
  38. _DIR_NOTE,_DIR_NOTES,
  39. _DIR_OBJECTPATH,_DIR_OPENSTRINGS,_DIR_OUTPUT_FORMAT,_DIR_OVERFLOWCHECKS,
  40. _DIR_PACKENUM,_DIR_PACKRECORDS,
  41. {$IFDEF Testvarsets}
  42. _DIR_PACKSET,
  43. {$ENDIF}
  44. _DIR_R,_DIR_RANGECHECKS,_DIR_REFERENCEINFO,
  45. _DIR_SATURATION,_DIR_SMARTLINK,_DIR_STACKFRAMES,_DIR_STATIC,_DIR_STOP,
  46. _DIR_TYPEDADDRESS,_DIR_TYPEINFO,
  47. _DIR_UNDEF,_DIR_UNITPATH,
  48. _DIR_VARSTRINGCHECKS,_DIR_VERSION,
  49. _DIR_WAIT,_DIR_WARNING,_DIR_WARNINGS,
  50. _DIR_Z1,_DIR_Z2,_DIR_Z4
  51. );
  52. const
  53. firstdirective=_DIR_NONE;
  54. lastdirective=_DIR_Z4;
  55. directive:array[tdirectivetoken] of directivestr=(
  56. {12345678901234567890 (To determine longest string.)}
  57. '',
  58. 'ALIGN',
  59. 'APPTYPE',
  60. 'ASMMODE',
  61. 'ASSERTIONS',
  62. 'BOOLEVAL',
  63. 'D',
  64. 'DEBUGINFO',
  65. 'DEFINE',
  66. 'DESCRIPTION',
  67. 'ELSE',
  68. 'ENDIF',
  69. 'ERROR',
  70. 'EXTENDEDSYNTAX',
  71. 'FATAL',
  72. 'GOTO',
  73. 'HINT',
  74. 'HINTS',
  75. 'I',
  76. {12345678901234567890 (To determine longest string.)}
  77. 'I386_ATT',
  78. 'I386_DIRECT',
  79. 'I386_INTEL',
  80. 'IOCHECKS',
  81. 'IF',
  82. 'IFDEF',
  83. 'IFNDEF',
  84. 'IFOPT',
  85. 'INCLUDE',
  86. 'INCLUDEPATH',
  87. 'INFO',
  88. 'INLINE',
  89. 'INTERFACES',
  90. 'L',
  91. 'LIBRARYPATH',
  92. 'LINK',
  93. 'LINKLIB',
  94. 'LOCALSYMBOLS',
  95. 'LONGSTRINGS',
  96. 'M',
  97. {12345678901234567890 (To determine longest string.)}
  98. 'MACRO',
  99. 'MAXFPUREGISTERS',
  100. 'MEMORY',
  101. 'MESSAGE',
  102. 'MINENUMSIZE',
  103. 'MMX',
  104. 'MODE',
  105. 'NOTE',
  106. 'NOTES',
  107. 'OBJECTPATH',
  108. 'OPENSTRINGS',
  109. 'OUTPUT_FORMAT',
  110. 'OVERFLOWCHECKS',
  111. 'PACKENUM',
  112. 'PACKRECORDS',
  113. {$IFDEF testvarsets}
  114. 'PACKSET',
  115. {$ENDIF}
  116. 'R',
  117. 'RANGECHECKS',
  118. 'REFERENCEINFO',
  119. 'SATURATION',
  120. 'SMARTLINK',
  121. {12345678901234567890 (To determine longest string.)}
  122. 'STACKFRAMES',
  123. 'STATIC',
  124. 'STOP',
  125. 'TYPEDADDRESS',
  126. 'TYPEINFO',
  127. 'UNDEF',
  128. 'UNITPATH',
  129. 'VARSTRINGCHECKS',
  130. 'VERSION',
  131. 'WAIT',
  132. 'WARNING',
  133. 'WARNINGS',
  134. 'Z1',
  135. 'Z2',
  136. 'Z4'
  137. );
  138. function Get_Directive(const hs:string):tdirectivetoken;
  139. var
  140. i : tdirectivetoken;
  141. begin
  142. for i:=firstdirective to lastdirective do
  143. if directive[i]=hs then
  144. begin
  145. Get_Directive:=i;
  146. exit;
  147. end;
  148. Get_Directive:=_DIR_NONE;
  149. end;
  150. {-------------------------------------------
  151. IF Conditional Handling
  152. -------------------------------------------}
  153. var
  154. preprocpat : string;
  155. preproc_token : ttoken;
  156. procedure preproc_consume(t : ttoken);
  157. begin
  158. if t<>preproc_token then
  159. Message(scan_e_preproc_syntax_error);
  160. preproc_token:=current_scanner^.readpreproc;
  161. end;
  162. function read_expr : string;forward;
  163. function read_factor : string;
  164. var
  165. hs : string;
  166. mac : pmacro;
  167. len : byte;
  168. begin
  169. if preproc_token=_ID then
  170. begin
  171. if preprocpat='NOT' then
  172. begin
  173. preproc_consume(_ID);
  174. hs:=read_expr;
  175. if hs='0' then
  176. read_factor:='1'
  177. else
  178. read_factor:='0';
  179. end
  180. else
  181. begin
  182. mac:=pmacro(current_scanner^.macros^.search(hs));
  183. hs:=preprocpat;
  184. preproc_consume(_ID);
  185. if assigned(mac) then
  186. begin
  187. if mac^.defined and assigned(mac^.buftext) then
  188. begin
  189. if mac^.buflen>255 then
  190. begin
  191. len:=255;
  192. Message(scan_w_macro_cut_after_255_chars);
  193. end
  194. else
  195. len:=mac^.buflen;
  196. hs[0]:=char(len);
  197. move(mac^.buftext^,hs[1],len);
  198. end
  199. else
  200. read_factor:='';
  201. end
  202. else
  203. read_factor:=hs;
  204. end
  205. end
  206. else if preproc_token=_LKLAMMER then
  207. begin
  208. preproc_consume(_LKLAMMER);
  209. read_factor:=read_expr;
  210. preproc_consume(_RKLAMMER);
  211. end
  212. else
  213. Message(scan_e_error_in_preproc_expr);
  214. end;
  215. function read_term : string;
  216. var
  217. hs1,hs2 : string;
  218. begin
  219. hs1:=read_factor;
  220. while true do
  221. begin
  222. if (preproc_token=_ID) then
  223. begin
  224. if preprocpat='AND' then
  225. begin
  226. preproc_consume(_ID);
  227. hs2:=read_factor;
  228. if (hs1<>'0') and (hs2<>'0') then
  229. hs1:='1';
  230. end
  231. else
  232. break;
  233. end
  234. else
  235. break;
  236. end;
  237. read_term:=hs1;
  238. end;
  239. function read_simple_expr : string;
  240. var
  241. hs1,hs2 : string;
  242. begin
  243. hs1:=read_term;
  244. while true do
  245. begin
  246. if (preproc_token=_ID) then
  247. begin
  248. if preprocpat='OR' then
  249. begin
  250. preproc_consume(_ID);
  251. hs2:=read_term;
  252. if (hs1<>'0') or (hs2<>'0') then
  253. hs1:='1';
  254. end
  255. else
  256. break;
  257. end
  258. else
  259. break;
  260. end;
  261. read_simple_expr:=hs1;
  262. end;
  263. function read_expr : string;
  264. var
  265. hs1,hs2 : string;
  266. b : boolean;
  267. t : ttoken;
  268. w : integer;
  269. l1,l2 : longint;
  270. begin
  271. hs1:=read_simple_expr;
  272. t:=preproc_token;
  273. if not(t in [_EQUAL,_UNEQUAL,_LT,_GT,_LTE,_GTE]) then
  274. begin
  275. read_expr:=hs1;
  276. exit;
  277. end;
  278. preproc_consume(t);
  279. hs2:=read_simple_expr;
  280. if is_number(hs1) and is_number(hs2) then
  281. begin
  282. valint(hs1,l1,w);
  283. valint(hs2,l2,w);
  284. case t of
  285. _EQUAL : b:=l1=l2;
  286. _UNEQUAL : b:=l1<>l2;
  287. _LT : b:=l1<l2;
  288. _GT : b:=l1>l2;
  289. _GTE : b:=l1>=l2;
  290. _LTE : b:=l1<=l2;
  291. end;
  292. end
  293. else
  294. begin
  295. case t of
  296. _EQUAL : b:=hs1=hs2;
  297. _UNEQUAL : b:=hs1<>hs2;
  298. _LT : b:=hs1<hs2;
  299. _GT : b:=hs1>hs2;
  300. _GTE : b:=hs1>=hs2;
  301. _LTE : b:=hs1<=hs2;
  302. end;
  303. end;
  304. if b then
  305. read_expr:='1'
  306. else
  307. read_expr:='0';
  308. end;
  309. {-------------------------------------------
  310. Directives
  311. -------------------------------------------}
  312. function is_conditional(t:tdirectivetoken):boolean;
  313. begin
  314. is_conditional:=(t in [_DIR_ENDIF,_DIR_IFDEF,_DIR_IFNDEF,_DIR_IFOPT,_DIR_IF,_DIR_ELSE]);
  315. end;
  316. procedure dir_conditional(t:tdirectivetoken);
  317. var
  318. hs : string;
  319. mac : pmacro;
  320. found : boolean;
  321. state : char;
  322. oldaktfilepos : tfileposinfo;
  323. begin
  324. oldaktfilepos:=aktfilepos;
  325. while true do
  326. begin
  327. current_scanner^.gettokenpos;
  328. case t of
  329. _DIR_ENDIF : begin
  330. current_scanner^.poppreprocstack;
  331. end;
  332. _DIR_ELSE : begin
  333. current_scanner^.elsepreprocstack;
  334. end;
  335. _DIR_IFDEF : begin
  336. current_scanner^.skipspace;
  337. hs:=current_scanner^.readid;
  338. mac:=pmacro(current_scanner^.macros^.search(hs));
  339. if assigned(mac) then
  340. mac^.is_used:=true;
  341. current_scanner^.addpreprocstack(pp_ifdef,assigned(mac) and mac^.defined,hs,scan_c_ifdef_found);
  342. end;
  343. _DIR_IFOPT : begin
  344. current_scanner^.skipspace;
  345. hs:=current_scanner^.readid;
  346. if (length(hs)>1) then
  347. Message1(scan_w_illegal_switch,hs)
  348. else
  349. begin
  350. state:=current_scanner^.ReadState;
  351. if state in ['-','+'] then
  352. found:=CheckSwitch(hs[1],state);
  353. end;
  354. current_scanner^.addpreprocstack(pp_ifopt,found,hs,scan_c_ifopt_found);
  355. end;
  356. _DIR_IF : begin
  357. current_scanner^.skipspace;
  358. { start preproc expression scanner }
  359. preproc_token:=current_scanner^.readpreproc;
  360. hs:=read_expr;
  361. current_scanner^.addpreprocstack(pp_if,hs<>'0',hs,scan_c_if_found);
  362. end;
  363. _DIR_IFNDEF : begin
  364. current_scanner^.skipspace;
  365. hs:=current_scanner^.readid;
  366. mac:=pmacro(current_scanner^.macros^.search(hs));
  367. if assigned(mac) then
  368. mac^.is_used:=true;
  369. current_scanner^.addpreprocstack(pp_ifndef,not(assigned(mac) and mac^.defined),hs,scan_c_ifndef_found);
  370. end;
  371. end;
  372. { accept the text ? }
  373. if (current_scanner^.preprocstack=nil) or current_scanner^.preprocstack^.accept then
  374. break
  375. else
  376. begin
  377. current_scanner^.gettokenpos;
  378. Message(scan_c_skipping_until);
  379. repeat
  380. current_scanner^.skipuntildirective;
  381. t:=Get_Directive(current_scanner^.readid);
  382. until is_conditional(t);
  383. current_scanner^.gettokenpos;
  384. Message1(scan_d_handling_switch,'$'+directive[t]);
  385. end;
  386. end;
  387. aktfilepos:=oldaktfilepos;
  388. end;
  389. procedure dir_define(t:tdirectivetoken);
  390. var
  391. hs : string;
  392. bracketcount : longint;
  393. mac : pmacro;
  394. macropos : longint;
  395. macrobuffer : pmacrobuffer;
  396. begin
  397. current_scanner^.skipspace;
  398. hs:=current_scanner^.readid;
  399. mac:=pmacro(current_scanner^.macros^.search(hs));
  400. if not assigned(mac) then
  401. begin
  402. mac:=new(pmacro,init(hs));
  403. mac^.defined:=true;
  404. Message1(parser_m_macro_defined,mac^.name);
  405. current_scanner^.macros^.insert(mac);
  406. end
  407. else
  408. begin
  409. Message1(parser_m_macro_defined,mac^.name);
  410. mac^.defined:=true;
  411. { delete old definition }
  412. if assigned(mac^.buftext) then
  413. begin
  414. freemem(mac^.buftext,mac^.buflen);
  415. mac^.buftext:=nil;
  416. end;
  417. end;
  418. mac^.is_used:=true;
  419. if (cs_support_macro in aktmoduleswitches) then
  420. begin
  421. { key words are never substituted }
  422. if is_keyword(hs) then
  423. Message(scan_e_keyword_cant_be_a_macro);
  424. { !!!!!! handle macro params, need we this? }
  425. current_scanner^.skipspace;
  426. { may be a macro? }
  427. if c=':' then
  428. begin
  429. current_scanner^.readchar;
  430. if c='=' then
  431. begin
  432. new(macrobuffer);
  433. macropos:=0;
  434. { parse macro, brackets are counted so it's possible
  435. to have a $ifdef etc. in the macro }
  436. bracketcount:=0;
  437. repeat
  438. current_scanner^.readchar;
  439. case c of
  440. '}' :
  441. if (bracketcount=0) then
  442. break
  443. else
  444. dec(bracketcount);
  445. '{' :
  446. inc(bracketcount);
  447. #26 :
  448. current_scanner^.end_of_file;
  449. end;
  450. macrobuffer^[macropos]:=c;
  451. inc(macropos);
  452. if macropos>maxmacrolen then
  453. Message(scan_f_macro_buffer_overflow);
  454. until false;
  455. { free buffer of macro ?}
  456. if assigned(mac^.buftext) then
  457. freemem(mac^.buftext,mac^.buflen);
  458. { get new mem }
  459. getmem(mac^.buftext,macropos);
  460. mac^.buflen:=macropos;
  461. { copy the text }
  462. move(macrobuffer^,mac^.buftext^,macropos);
  463. dispose(macrobuffer);
  464. end;
  465. end;
  466. end
  467. else
  468. begin
  469. { check if there is an assignment, then we need to give a
  470. warning }
  471. current_scanner^.skipspace;
  472. if c=':' then
  473. begin
  474. current_scanner^.readchar;
  475. if c='=' then
  476. Message(scan_w_macro_support_turned_off);
  477. end;
  478. end;
  479. end;
  480. procedure dir_undef(t:tdirectivetoken);
  481. var
  482. hs : string;
  483. mac : pmacro;
  484. begin
  485. current_scanner^.skipspace;
  486. hs:=current_scanner^.readid;
  487. mac:=pmacro(current_scanner^.macros^.search(hs));
  488. if not assigned(mac) then
  489. begin
  490. mac:=new(pmacro,init(hs));
  491. Message1(parser_m_macro_undefined,mac^.name);
  492. mac^.defined:=false;
  493. current_scanner^.macros^.insert(mac);
  494. end
  495. else
  496. begin
  497. Message1(parser_m_macro_undefined,mac^.name);
  498. mac^.defined:=false;
  499. { delete old definition }
  500. if assigned(mac^.buftext) then
  501. begin
  502. freemem(mac^.buftext,mac^.buflen);
  503. mac^.buftext:=nil;
  504. end;
  505. end;
  506. mac^.is_used:=true;
  507. end;
  508. procedure dir_message(t:tdirectivetoken);
  509. var
  510. w : longint;
  511. begin
  512. case t of
  513. _DIR_STOP,
  514. _DIR_FATAL : w:=scan_f_user_defined;
  515. _DIR_ERROR : w:=scan_e_user_defined;
  516. _DIR_WARNING : w:=scan_w_user_defined;
  517. _DIR_HINT : w:=scan_h_user_defined;
  518. _DIR_NOTE : w:=scan_n_user_defined;
  519. _DIR_MESSAGE,
  520. _DIR_INFO : w:=scan_i_user_defined;
  521. end;
  522. current_scanner^.skipspace;
  523. Message1(w,current_scanner^.readcomment);
  524. end;
  525. procedure dir_moduleswitch(t:tdirectivetoken);
  526. var
  527. sw : tmoduleswitch;
  528. state : char;
  529. begin
  530. sw:=cs_modulenone;
  531. case t of
  532. _DIR_GOTO : sw:=cs_support_goto;
  533. _DIR_MACRO : sw:=cs_support_macro;
  534. _DIR_INLINE : sw:=cs_support_inline;
  535. _DIR_SMARTLINK : sw:=cs_create_smart;
  536. _DIR_STATIC : sw:=cs_static_keyword;
  537. end;
  538. state:=current_scanner^.readstate;
  539. if (sw<>cs_modulenone) and (state in ['-','+']) then
  540. begin
  541. if state='-' then
  542. aktmoduleswitches:=aktmoduleswitches-[sw]
  543. else
  544. aktmoduleswitches:=aktmoduleswitches+[sw];
  545. end;
  546. end;
  547. procedure dir_interfacesswitch(t:tdirectivetoken);
  548. var
  549. hs : string;
  550. begin
  551. {corba/com/default}
  552. current_scanner^.skipspace;
  553. hs:=current_scanner^.readid;
  554. if (hs='CORBA') then
  555. aktinterfacetype:=it_interfacecorba
  556. else if (hs='COM') then
  557. aktinterfacetype:=it_interfacecom
  558. else if (hs='DEFAULT') then
  559. aktinterfacetype:=initinterfacetype
  560. else
  561. Message(scan_e_invalid_interface_type);
  562. end;
  563. procedure dir_localswitch(t:tdirectivetoken);
  564. var
  565. sw : tlocalswitch;
  566. state : char;
  567. begin
  568. sw:=cs_localnone;
  569. {$ifdef SUPPORT_MMX}
  570. case t of
  571. _DIR_MMX : sw:=cs_mmx;
  572. _DIR_SATURATION : sw:=cs_mmx_saturation;
  573. end;
  574. {$endif}
  575. state:=current_scanner^.readstate;
  576. if (sw<>cs_localnone) and (state in ['-','+']) then
  577. begin
  578. if not localswitcheschanged then
  579. nextaktlocalswitches:=aktlocalswitches;
  580. if state='-' then
  581. nextaktlocalswitches:=nextaktlocalswitches-[sw]
  582. else
  583. nextaktlocalswitches:=nextaktlocalswitches+[sw];
  584. localswitcheschanged:=true;
  585. end;
  586. end;
  587. procedure dir_include(t:tdirectivetoken);
  588. var
  589. foundfile,
  590. hs : string;
  591. path : dirstr;
  592. name : namestr;
  593. ext : extstr;
  594. hp : tinputfile;
  595. i : longint;
  596. found : boolean;
  597. begin
  598. current_scanner^.skipspace;
  599. hs:=current_scanner^.readcomment;
  600. i:=length(hs);
  601. while (i>0) and (hs[i]=' ') do
  602. dec(i);
  603. Delete(hs,i+1,length(hs)-i);
  604. if hs='' then
  605. exit;
  606. if (hs[1]='%') then
  607. begin
  608. { case insensitive }
  609. hs:=upper(hs);
  610. { remove %'s }
  611. Delete(hs,1,1);
  612. if hs[length(hs)]='%' then
  613. Delete(hs,length(hs),1);
  614. { save old }
  615. path:=hs;
  616. { first check for internal macros }
  617. if hs='TIME' then
  618. hs:=gettimestr
  619. else
  620. if hs='DATE' then
  621. hs:=getdatestr
  622. else
  623. if hs='FILE' then
  624. hs:=current_module.sourcefiles.get_file_name(aktfilepos.fileindex)
  625. else
  626. if hs='LINE' then
  627. hs:=tostr(aktfilepos.line)
  628. else
  629. if hs='FPCVERSION' then
  630. hs:=version_string
  631. else
  632. if hs='FPCTARGET' then
  633. hs:=target_cpu_string
  634. else
  635. hs:=getenv(hs);
  636. if hs='' then
  637. Message1(scan_w_include_env_not_found,path);
  638. { make it a stringconst }
  639. hs:=''''+hs+'''';
  640. current_scanner^.insertmacro(path,@hs[1],length(hs));
  641. end
  642. else
  643. begin
  644. hs:=FixFileName(hs);
  645. fsplit(hs,path,name,ext);
  646. { look for the include file
  647. 1. specified path,path of current inputfile,current dir
  648. 2. local includepath
  649. 3. global includepath }
  650. found:=false;
  651. foundfile:='';
  652. if path<>'' then
  653. path:=path+';';
  654. found:=FindFile(name+ext,path+current_scanner^.inputfile.path^+';.'+DirSep,foundfile);
  655. if (not found) then
  656. found:=current_module.localincludesearchpath.FindFile(name+ext,foundfile);
  657. if (not found) then
  658. found:=includesearchpath.FindFile(name+ext,foundfile);
  659. { save old postion and decrease linebreak }
  660. if c=newline then
  661. dec(current_scanner^.line_no);
  662. dec(longint(current_scanner^.inputpointer));
  663. { shutdown current file }
  664. current_scanner^.tempcloseinputfile;
  665. { load new file }
  666. hp:=do_openinputfile(foundfile);
  667. current_scanner^.addfile(hp);
  668. if not current_scanner^.openinputfile then
  669. Message1(scan_f_cannot_open_includefile,hs);
  670. Message1(scan_t_start_include_file,current_scanner^.inputfile.path^+current_scanner^.inputfile.name^);
  671. current_scanner^.reload;
  672. { process first read char }
  673. case c of
  674. #26 : current_scanner^.reload;
  675. #10,
  676. #13 : current_scanner^.linebreak;
  677. end;
  678. { register for refs }
  679. current_module.sourcefiles.register_file(hp);
  680. end;
  681. end;
  682. procedure dir_description(t:tdirectivetoken);
  683. begin
  684. if not (target_info.target in [target_i386_os2,target_i386_win32,target_i386_netware]) then
  685. Message(scan_w_decription_not_support);
  686. { change description global var in all cases }
  687. { it not used but in win32, os2 and netware }
  688. current_scanner^.skipspace;
  689. description:=current_scanner^.readcomment;
  690. end;
  691. procedure dir_version(t:tdirectivetoken);
  692. var
  693. major, minor, revision : longint;
  694. error : integer;
  695. begin
  696. if not (target_info.target in [target_i386_os2,target_i386_win32,target_i386_netware]) then // AD
  697. begin
  698. Message(scan_n_version_not_support);
  699. exit;
  700. end;
  701. if (compile_level<>1) then
  702. Message(scan_n_only_exe_version)
  703. else
  704. begin
  705. { change description global var in all cases }
  706. { it not used but in win32, os2 and netware }
  707. current_scanner^.skipspace;
  708. { we should only accept Major.Minor format for win32 and os2 }
  709. current_scanner^.readnumber;
  710. major:=0;
  711. minor:=0;
  712. revision:=0;
  713. valint(pattern,major,error);
  714. if error<>0 then
  715. begin
  716. Message1(scan_w_wrong_version_ignored,pattern);
  717. exit;
  718. end;
  719. if c='.' then
  720. begin
  721. current_scanner^.readchar;
  722. current_scanner^.readnumber;
  723. valint(pattern,minor,error);
  724. if error<>0 then
  725. begin
  726. Message1(scan_w_wrong_version_ignored,tostr(major)+'.'+pattern);
  727. exit;
  728. end;
  729. if (c='.') and
  730. (target_info.target = target_i386_netware) then // AD
  731. begin
  732. current_scanner^.readchar;
  733. current_scanner^.readnumber;
  734. valint(pattern,revision,error);
  735. if error<>0 then
  736. begin
  737. Message1(scan_w_wrong_version_ignored,tostr(revision)+'.'+pattern);
  738. exit;
  739. end;
  740. dllmajor:=major;
  741. dllminor:=minor;
  742. dllrevision:=revision;
  743. dllversion:=tostr(major)+','+tostr(minor)+','+tostr(revision);
  744. end
  745. else
  746. begin
  747. dllmajor:=major;
  748. dllminor:=minor;
  749. dllversion:=tostr(major)+'.'+tostr(minor);
  750. end;
  751. end
  752. else
  753. dllversion:=tostr(major);
  754. end;
  755. end;
  756. procedure dir_linkobject(t:tdirectivetoken);
  757. var
  758. s : string;
  759. begin
  760. current_scanner^.skipspace;
  761. s:=AddExtension(FixFileName(current_scanner^.readcomment),target_info.objext);
  762. current_module.linkotherofiles.add(s,link_allways);
  763. end;
  764. procedure dir_resource(t:tdirectivetoken);
  765. var
  766. s : string;
  767. begin
  768. current_scanner^.skipspace;
  769. s:=current_scanner^.readcomment;
  770. { replace * with current module name.
  771. This should always be defined. }
  772. if s[1]='*' then
  773. if Assigned(Current_Module) then
  774. begin
  775. delete(S,1,1);
  776. insert(lower(current_module.modulename^),S,1);
  777. end;
  778. s:=AddExtension(FixFileName(s),target_info.resext);
  779. if target_info.res<>res_none then
  780. if (target_info.res = res_i386_emx) and
  781. not (Current_module.ResourceFiles.Empty) then
  782. Message(scan_w_only_one_resourcefile_supported)
  783. else
  784. current_module.resourcefiles.insert(FixFileName(s))
  785. else
  786. Message(scan_e_resourcefiles_not_supported);
  787. end;
  788. procedure dir_linklib(t:tdirectivetoken);
  789. type
  790. tLinkMode=(lm_shared,lm_static);
  791. var
  792. s : string;
  793. quote : char;
  794. libname,
  795. linkmodestr : string;
  796. p : longint;
  797. linkMode : tLinkMode;
  798. begin
  799. current_scanner^.skipspace;
  800. s:=current_scanner^.readcomment;
  801. p:=pos(',',s);
  802. if p=0 then
  803. begin
  804. libname:=TrimSpace(s);
  805. linkmodeStr:='';
  806. end
  807. else
  808. begin
  809. libname:=TrimSpace(copy(s,1,p-1));
  810. linkmodeStr:=Upper(TrimSpace(copy(s,p+1,255)));
  811. end;
  812. if (libname='') or (libname='''''') or (libname='""') then
  813. exit;
  814. { get linkmode, default is shared linking }
  815. if linkModeStr='STATIC' then
  816. linkmode:=lm_static
  817. else if (LinkModeStr='SHARED') or (LinkModeStr='') then
  818. linkmode:=lm_shared
  819. else
  820. begin
  821. Comment(V_Error,'Wrong link mode specified: "'+Linkmodestr+'"');
  822. exit;
  823. end;
  824. { create library name }
  825. if libname[1] in ['''','"'] then
  826. begin
  827. quote:=libname[1];
  828. Delete(libname,1,1);
  829. p:=pos(quote,libname);
  830. if p>0 then
  831. Delete(libname,p,1);
  832. end;
  833. { add to the list of libraries to link }
  834. if linkMode=lm_static then
  835. current_module.linkOtherStaticLibs.add(FixFileName(libname),link_allways)
  836. else
  837. current_module.linkOtherSharedLibs.add(FixFileName(libname),link_allways);
  838. end;
  839. procedure dir_outputformat(t:tdirectivetoken);
  840. begin
  841. if not current_module.in_global then
  842. Message(scan_w_switch_is_global)
  843. else
  844. begin
  845. current_scanner^.skipspace;
  846. if set_string_asm(current_scanner^.readid) then
  847. aktoutputformat:=target_asm.id
  848. else
  849. Message1(scan_w_illegal_switch,pattern);
  850. end;
  851. end;
  852. procedure dir_unitpath(t:tdirectivetoken);
  853. begin
  854. if not current_module.in_global then
  855. Message(scan_w_switch_is_global)
  856. else
  857. begin
  858. current_scanner^.skipspace;
  859. current_module.localunitsearchpath.AddPath(current_scanner^.readcomment,false);
  860. end;
  861. end;
  862. procedure dir_includepath(t:tdirectivetoken);
  863. begin
  864. if not current_module.in_global then
  865. Message(scan_w_switch_is_global)
  866. else
  867. begin
  868. current_scanner^.skipspace;
  869. current_module.localincludesearchpath.AddPath(current_scanner^.readcomment,false);
  870. end;
  871. end;
  872. procedure dir_librarypath(t:tdirectivetoken);
  873. begin
  874. if not current_module.in_global then
  875. Message(scan_w_switch_is_global)
  876. else
  877. begin
  878. current_scanner^.skipspace;
  879. current_module.locallibrarysearchpath.AddPath(current_scanner^.readcomment,false);
  880. end;
  881. end;
  882. procedure dir_objectpath(t:tdirectivetoken);
  883. begin
  884. if not current_module.in_global then
  885. Message(scan_w_switch_is_global)
  886. else
  887. begin
  888. current_scanner^.skipspace;
  889. current_module.localobjectsearchpath.AddPath(current_scanner^.readcomment,false);
  890. end;
  891. end;
  892. procedure dir_mode(t:tdirectivetoken);
  893. begin
  894. if not current_module.in_global then
  895. Message(scan_w_switch_is_global)
  896. else
  897. begin
  898. current_scanner^.skipspace;
  899. current_scanner^.readstring;
  900. if not SetCompileMode(pattern,false) then
  901. Message1(scan_w_illegal_switch,pattern);
  902. end;
  903. end;
  904. procedure dir_packrecords(t:tdirectivetoken);
  905. var
  906. hs : string;
  907. begin
  908. current_scanner^.skipspace;
  909. if not(c in ['0'..'9']) then
  910. begin
  911. hs:=current_scanner^.readid;
  912. if (hs='C') then
  913. aktpackrecords:=packrecord_C
  914. else
  915. if (hs='NORMAL') or (hs='DEFAULT') then
  916. aktpackrecords:=packrecord_2
  917. else
  918. Message(scan_w_only_pack_records);
  919. end
  920. else
  921. begin
  922. case current_scanner^.readval of
  923. 1 : aktpackrecords:=packrecord_1;
  924. 2 : aktpackrecords:=packrecord_2;
  925. 4 : aktpackrecords:=packrecord_4;
  926. 8 : aktpackrecords:=packrecord_8;
  927. 16 : aktpackrecords:=packrecord_16;
  928. 32 : aktpackrecords:=packrecord_32;
  929. else
  930. Message(scan_w_only_pack_records);
  931. end;
  932. end;
  933. end;
  934. procedure dir_maxfpuregisters(t:tdirectivetoken);
  935. var
  936. l : longint;
  937. hs : string;
  938. begin
  939. current_scanner^.skipspace;
  940. if not(c in ['0'..'9']) then
  941. begin
  942. hs:=current_scanner^.readid;
  943. if (hs='NORMAL') or (hs='DEFAULT') then
  944. aktmaxfpuregisters:=-1
  945. else
  946. Message(scan_e_invalid_maxfpureg_value);
  947. end
  948. else
  949. begin
  950. l:=current_scanner^.readval;
  951. case l of
  952. 0..8:
  953. aktmaxfpuregisters:=l;
  954. else
  955. Message(scan_e_invalid_maxfpureg_value);
  956. end;
  957. end;
  958. end;
  959. procedure dir_packenum(t:tdirectivetoken);
  960. var
  961. hs : string;
  962. begin
  963. if t in [_DIR_Z1,_DIR_Z2,_DIR_Z4] then
  964. begin
  965. aktpackenum:=ord(pattern[2])-ord('0');
  966. exit;
  967. end;
  968. current_scanner^.skipspace;
  969. if not(c in ['0'..'9']) then
  970. begin
  971. hs:=current_scanner^.readid;
  972. if (hs='NORMAL') or (hs='DEFAULT') then
  973. aktpackenum:=4
  974. else
  975. Message(scan_w_only_pack_enum);
  976. end
  977. else
  978. begin
  979. case current_scanner^.readval of
  980. 1 : aktpackenum:=1;
  981. 2 : aktpackenum:=2;
  982. 4 : aktpackenum:=4;
  983. else
  984. Message(scan_w_only_pack_enum);
  985. end;
  986. end;
  987. end;
  988. {$ifdef testvarsets}
  989. procedure dir_setalloc(t:tdirectivetoken);
  990. var
  991. hs : string;
  992. begin
  993. current_scanner^.skipspace;
  994. if not(c in ['1','2','4']) then
  995. begin
  996. hs:=current_scanner^.readid;
  997. if (hs='FIXED') or ((hs='DEFAULT') OR (hs='NORMAL')) then
  998. aktsetalloc:=0 {Fixed mode, sets are 4 or 32 bytes}
  999. else
  1000. Message(scan_w_only_packset);
  1001. end
  1002. else
  1003. begin
  1004. case current_scanner^.readval of
  1005. 1 : aktpackenum:=1;
  1006. 2 : aktpackenum:=2;
  1007. 4 : aktpackenum:=4;
  1008. else
  1009. Message(scan_w_only_packset);
  1010. end;
  1011. end;
  1012. end;
  1013. {$ENDIF}
  1014. procedure dir_apptype(t:tdirectivetoken);
  1015. var
  1016. hs : string;
  1017. begin
  1018. if (target_info.target<>target_i386_win32)
  1019. and (target_info.target<>target_i386_os2) then
  1020. Message(scan_w_app_type_not_support);
  1021. if not current_module.in_global then
  1022. Message(scan_w_switch_is_global)
  1023. else
  1024. begin
  1025. current_scanner^.skipspace;
  1026. hs:=current_scanner^.readid;
  1027. if hs='GUI' then
  1028. apptype:=app_gui
  1029. else if hs='CONSOLE' then
  1030. apptype:=app_cui
  1031. else if (hs='FS') and (target_info.target=target_i386_os2) then
  1032. apptype:=app_fs
  1033. else
  1034. Message1(scan_w_unsupported_app_type,hs);
  1035. end;
  1036. end;
  1037. procedure dir_wait(t:tdirectivetoken);
  1038. var had_info : boolean;
  1039. begin
  1040. had_info:=(status.verbosity and V_Info)<>0;
  1041. { this message should allways appear !! }
  1042. status.verbosity:=status.verbosity or V_Info;
  1043. Message(scan_i_press_enter);
  1044. readln;
  1045. If not(had_info) then
  1046. status.verbosity:=status.verbosity and (not V_Info);
  1047. end;
  1048. procedure dir_asmmode(t:tdirectivetoken);
  1049. var
  1050. s : string;
  1051. begin
  1052. current_scanner^.skipspace;
  1053. s:=current_scanner^.readid;
  1054. If Inside_asm_statement then
  1055. Message1(scan_w_no_asm_reader_switch_inside_asm,s);
  1056. if s='DEFAULT' then
  1057. aktasmmode:=initasmmode
  1058. else
  1059. if not set_string_asmmode(s,aktasmmode) then
  1060. Message1(scan_w_unsupported_asmmode_specifier,s);
  1061. end;
  1062. procedure dir_oldasmmode(t:tdirectivetoken);
  1063. begin
  1064. If Inside_asm_statement then
  1065. Message1(scan_w_no_asm_reader_switch_inside_asm,directive[t]);
  1066. {$ifdef i386}
  1067. case t of
  1068. _DIR_I386_ATT : aktasmmode:=asmmode_i386_att;
  1069. _DIR_I386_DIRECT : aktasmmode:=asmmode_i386_direct;
  1070. _DIR_I386_INTEL : aktasmmode:=asmmode_i386_intel;
  1071. end;
  1072. {$endif i386}
  1073. end;
  1074. procedure dir_delphiswitch(t:tdirectivetoken);
  1075. var
  1076. sw,state : char;
  1077. begin
  1078. case t of
  1079. _DIR_ALIGN : sw:='A';
  1080. _DIR_ASSERTIONS : sw:='C';
  1081. _DIR_BOOLEVAL : sw:='B';
  1082. _DIR_DEBUGINFO : sw:='D';
  1083. _DIR_IOCHECKS : sw:='I';
  1084. _DIR_LOCALSYMBOLS : sw:='L';
  1085. _DIR_LONGSTRINGS : sw:='H';
  1086. _DIR_OPENSTRINGS : sw:='P';
  1087. _DIR_OVERFLOWCHECKS : sw:='Q';
  1088. _DIR_RANGECHECKS : sw:='R';
  1089. _DIR_REFERENCEINFO : sw:='Y';
  1090. _DIR_STACKFRAMES : sw:='W';
  1091. _DIR_TYPEDADDRESS : sw:='T';
  1092. _DIR_TYPEINFO : sw:='M';
  1093. _DIR_VARSTRINGCHECKS : sw:='V';
  1094. else
  1095. exit;
  1096. end;
  1097. { c contains the next char, a + or - would be fine }
  1098. state:=current_scanner^.readstate;
  1099. if state in ['-','+'] then
  1100. HandleSwitch(sw,state);
  1101. end;
  1102. procedure dir_memory(t:tdirectivetoken);
  1103. var
  1104. l : longint;
  1105. begin
  1106. current_scanner^.skipspace;
  1107. l:=current_scanner^.readval;
  1108. if l>1024 then
  1109. stacksize:=l;
  1110. current_scanner^.skipspace;
  1111. if c=',' then
  1112. begin
  1113. current_scanner^.readchar;
  1114. current_scanner^.skipspace;
  1115. l:=current_scanner^.readval;
  1116. if l>1024 then
  1117. heapsize:=l;
  1118. end;
  1119. if c=',' then
  1120. begin
  1121. current_scanner^.readchar;
  1122. current_scanner^.skipspace;
  1123. l:=current_scanner^.readval;
  1124. { Ignore this value, because the limit is set by the OS
  1125. info and shouldn't be changed by the user (PFV) }
  1126. end;
  1127. end;
  1128. procedure dir_setverbose(t:tdirectivetoken);
  1129. var
  1130. flag,
  1131. state : char;
  1132. begin
  1133. case t of
  1134. _DIR_HINTS : flag:='H';
  1135. _DIR_WARNINGS : flag:='W';
  1136. _DIR_NOTES : flag:='N';
  1137. else
  1138. exit;
  1139. end;
  1140. { support ON/OFF }
  1141. state:=current_scanner^.ReadState;
  1142. SetVerbosity(flag+state);
  1143. end;
  1144. type
  1145. tdirectiveproc=procedure(t:tdirectivetoken);
  1146. const
  1147. directiveproc:array[tdirectivetoken] of tdirectiveproc=(
  1148. {_DIR_NONE} nil,
  1149. {_DIR_ALIGN} dir_delphiswitch,
  1150. {_DIR_APPTYPE} dir_apptype,
  1151. {_DIR_ASMMODE} dir_asmmode,
  1152. {_DIR_ASSERTION} dir_delphiswitch,
  1153. {_DIR_BOOLEVAL} dir_delphiswitch,
  1154. {_DIR_D} dir_description,
  1155. {_DIR_DEBUGINFO} dir_delphiswitch,
  1156. {_DIR_DEFINE} dir_define,
  1157. {_DIR_DESCRIPTION} dir_description,
  1158. {_DIR_ELSE} dir_conditional,
  1159. {_DIR_ENDIF} dir_conditional,
  1160. {_DIR_ERROR} dir_message,
  1161. {_DIR_EXTENDEDSYNTAX} dir_delphiswitch,
  1162. {_DIR_FATAL} dir_message,
  1163. {_DIR_GOTO} dir_moduleswitch,
  1164. {_DIR_HINT} dir_message,
  1165. {_DIR_HINTS} dir_setverbose,
  1166. {_DIR_I} dir_include,
  1167. {_DIR_I386_ATT} dir_oldasmmode,
  1168. {_DIR_I386_DIRECT} dir_oldasmmode,
  1169. {_DIR_I386_INTEL} dir_oldasmmode,
  1170. {_DIR_IOCHECKS} dir_delphiswitch,
  1171. {_DIR_IF} dir_conditional,
  1172. {_DIR_IFDEF} dir_conditional,
  1173. {_DIR_IFNDEF} dir_conditional,
  1174. {_DIR_IFOPT} dir_conditional,
  1175. {_DIR_INCLUDE} dir_include,
  1176. {_DIR_INCLUDEPATH} dir_includepath,
  1177. {_DIR_INFO} dir_message,
  1178. {_DIR_INLINE} dir_moduleswitch,
  1179. {_DIR_INTERFACES} dir_interfacesswitch,
  1180. {_DIR_L} dir_linkobject,
  1181. {_DIR_LIBRARYPATH} dir_librarypath,
  1182. {_DIR_LINK} dir_linkobject,
  1183. {_DIR_LINKLIB} dir_linklib,
  1184. {_DIR_LOCALSYMBOLS} dir_delphiswitch,
  1185. {_DIR_LONGSTRINGS} dir_delphiswitch,
  1186. {_DIR_M} dir_memory,
  1187. {_DIR_MACRO} dir_moduleswitch,
  1188. {_DIR_MAXFPUREGISTERS} dir_maxfpuregisters,
  1189. {_DIR_MEMORY} dir_memory,
  1190. {_DIR_MESSAGE} dir_message,
  1191. {_DIR_MINENUMSIZE} dir_packenum,
  1192. {_DIR_MMX} dir_localswitch,
  1193. {_DIR_MODE} dir_mode,
  1194. {_DIR_NOTE} dir_message,
  1195. {_DIR_NOTES} dir_setverbose,
  1196. {_DIR_OBJECTPATH} dir_objectpath,
  1197. {_DIR_OPENSTRINGS} dir_delphiswitch,
  1198. {_DIR_OUTPUT_FORMAT} dir_outputformat,
  1199. {_DIR_OVERFLOWCHECKS} dir_delphiswitch,
  1200. {_DIR_PACKENUM} dir_packenum,
  1201. {_DIR_PACKRECORDS} dir_packrecords,
  1202. {$IFDEF TestVarsets}
  1203. {_DIR_PACKSET} dir_packset,
  1204. {$ENDIF}
  1205. {_DIR_R} dir_resource,
  1206. {_DIR_RANGECHECKS} dir_delphiswitch,
  1207. {_DIR_REFERENCEINFO} dir_delphiswitch,
  1208. {_DIR_SATURATION} dir_localswitch,
  1209. {_DIR_SMARTLINK} dir_moduleswitch,
  1210. {_DIR_STACKFRAMES} dir_delphiswitch,
  1211. {_DIR_STATIC} dir_moduleswitch,
  1212. {_DIR_STOP} dir_message,
  1213. {_DIR_TYPEDADDRESS} dir_delphiswitch,
  1214. {_DIR_TYPEINFO} dir_delphiswitch,
  1215. {_DIR_UNDEF} dir_undef,
  1216. {_DIR_UNITPATH} dir_unitpath,
  1217. {_DIR_VARSTRINGCHECKS} dir_delphiswitch,
  1218. {_DIR_VERSION} dir_version,
  1219. {_DIR_WAIT} dir_wait,
  1220. {_DIR_WARNING} dir_message,
  1221. {_DIR_WARNINGS} dir_setverbose,
  1222. {_DIR_Z1} dir_packenum,
  1223. {_DIR_Z2} dir_packenum,
  1224. {_DIR_Z4} dir_packenum
  1225. );
  1226. {-------------------------------------------
  1227. Main switches handling
  1228. -------------------------------------------}
  1229. procedure handledirectives;
  1230. var
  1231. t : tdirectivetoken;
  1232. p : tdirectiveproc;
  1233. hs : string;
  1234. begin
  1235. current_scanner^.gettokenpos;
  1236. current_scanner^.readchar; {Remove the $}
  1237. hs:=current_scanner^.readid;
  1238. {$ifdef PREPROCWRITE}
  1239. if parapreprocess then
  1240. begin
  1241. t:=Get_Directive(hs);
  1242. if not(is_conditional(t) or (t=_DIR_DEFINE) or (t=_DIR_UNDEF)) then
  1243. begin
  1244. preprocfile^.AddSpace;
  1245. preprocfile^.Add('{$'+hs+current_scanner^.readcomment+'}');
  1246. exit;
  1247. end;
  1248. end;
  1249. {$endif PREPROCWRITE}
  1250. { skip this directive? }
  1251. if (current_scanner^.ignoredirectives.find(hs)<>nil) then
  1252. begin
  1253. if (current_scanner^.comment_level>0) then
  1254. current_scanner^.readcomment;
  1255. { we've read the whole comment }
  1256. aktcommentstyle:=comment_none;
  1257. exit;
  1258. end;
  1259. if hs='' then
  1260. begin
  1261. Message1(scan_w_illegal_switch,'$'+hs);
  1262. end;
  1263. { Check for compiler switches }
  1264. while (length(hs)=1) and (c in ['-','+']) do
  1265. begin
  1266. HandleSwitch(hs[1],c);
  1267. current_scanner^.readchar; {Remove + or -}
  1268. if c=',' then
  1269. begin
  1270. current_scanner^.readchar; {Remove , }
  1271. { read next switch, support $v+,$+}
  1272. hs:=current_scanner^.readid;
  1273. if (hs='') then
  1274. begin
  1275. if (c='$') and (m_fpc in aktmodeswitches) then
  1276. begin
  1277. current_scanner^.readchar; { skip $ }
  1278. hs:=current_scanner^.readid;
  1279. end;
  1280. if (hs='') then
  1281. Message1(scan_w_illegal_directive,'$'+c);
  1282. end
  1283. else
  1284. Message1(scan_d_handling_switch,'$'+hs);
  1285. end
  1286. else
  1287. hs:='';
  1288. end;
  1289. { directives may follow switches after a , }
  1290. if hs<>'' then
  1291. begin
  1292. t:=Get_Directive(hs);
  1293. if t<>_DIR_NONE then
  1294. begin
  1295. p:=directiveproc[t];
  1296. if {$ifndef FPCPROCVAR}@{$endif}p<>nil then
  1297. p(t);
  1298. end
  1299. else
  1300. begin
  1301. current_scanner^.ignoredirectives.insert(hs);
  1302. Message1(scan_w_illegal_directive,'$'+hs);
  1303. end;
  1304. { conditionals already read the comment }
  1305. if (current_scanner^.comment_level>0) then
  1306. current_scanner^.readcomment;
  1307. { we've read the whole comment }
  1308. aktcommentstyle:=comment_none;
  1309. end;
  1310. end;
  1311. {
  1312. $Log$
  1313. Revision 1.18 2001-02-20 21:41:18 peter
  1314. * new fixfilename, findfile for unix. Look first for lowercase, then
  1315. NormalCase and last for UPPERCASE names.
  1316. Revision 1.17 2001/01/20 18:32:52 hajny
  1317. + APPTYPE support under OS/2, app_fs, GetEnvPChar for OS/2
  1318. Revision 1.16 2001/01/13 00:09:21 peter
  1319. * made Pavel O. happy ;)
  1320. Revision 1.15 2000/12/25 00:07:28 peter
  1321. + new tlinkedlist class (merge of old tstringqueue,tcontainer and
  1322. tlinkedlist objects)
  1323. Revision 1.14 2000/12/24 12:24:38 peter
  1324. * moved preprocessfile into a conditional
  1325. Revision 1.13 2000/12/12 19:48:52 peter
  1326. * fixed lost char after $I directive (merged)
  1327. Revision 1.12 2000/11/12 22:17:47 peter
  1328. * some realname updates for messages
  1329. Revision 1.11 2000/11/04 14:25:21 florian
  1330. + merged Attila's changes for interfaces, not tested yet
  1331. Revision 1.10 2000/10/31 22:02:51 peter
  1332. * symtable splitted, no real code changes
  1333. Revision 1.9 2000/09/26 10:50:41 jonas
  1334. * initmodeswitches is changed is you change the compiler mode from the
  1335. command line (the -S<x> switches didn't work anymore for changing the
  1336. compiler mode) (merged from fixes branch)
  1337. Revision 1.8 2000/09/24 21:33:47 peter
  1338. * message updates merges
  1339. Revision 1.7 2000/09/24 15:06:27 peter
  1340. * use defines.inc
  1341. Revision 1.6 2000/09/11 17:00:23 florian
  1342. + first implementation of Netware Module support, thanks to
  1343. Armin Diehl ([email protected]) for providing the patches
  1344. Revision 1.5 2000/09/10 21:18:15 peter
  1345. * macro warning (merged)
  1346. Revision 1.4 2000/08/12 15:30:44 peter
  1347. * IDE patch for stream reading (merged)
  1348. Revision 1.3 2000/08/08 19:28:57 peter
  1349. * memdebug/memory patches (merged)
  1350. * only once illegal directive (merged)
  1351. Revision 1.2 2000/07/13 11:32:49 michael
  1352. + removed logs
  1353. }