scandir.inc 43 KB

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