scandir.inc 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457
  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. current_module.sourcefiles.register_file(hp);
  669. if not current_scanner^.openinputfile then
  670. Message1(scan_f_cannot_open_includefile,hs);
  671. Message1(scan_t_start_include_file,current_scanner^.inputfile.path^+current_scanner^.inputfile.name^);
  672. current_scanner^.reload;
  673. { process first read char }
  674. case c of
  675. #26 : current_scanner^.reload;
  676. #10,
  677. #13 : current_scanner^.linebreak;
  678. end;
  679. end;
  680. end;
  681. procedure dir_description(t:tdirectivetoken);
  682. begin
  683. if not (target_info.target in [target_i386_os2,target_i386_win32,target_i386_netware]) then
  684. Message(scan_w_decription_not_support);
  685. { change description global var in all cases }
  686. { it not used but in win32, os2 and netware }
  687. current_scanner^.skipspace;
  688. description:=current_scanner^.readcomment;
  689. end;
  690. procedure dir_version(t:tdirectivetoken);
  691. var
  692. major, minor, revision : longint;
  693. error : integer;
  694. begin
  695. if not (target_info.target in [target_i386_os2,target_i386_win32,target_i386_netware]) then // AD
  696. begin
  697. Message(scan_n_version_not_support);
  698. exit;
  699. end;
  700. if (compile_level<>1) then
  701. Message(scan_n_only_exe_version)
  702. else
  703. begin
  704. { change description global var in all cases }
  705. { it not used but in win32, os2 and netware }
  706. current_scanner^.skipspace;
  707. { we should only accept Major.Minor format for win32 and os2 }
  708. current_scanner^.readnumber;
  709. major:=0;
  710. minor:=0;
  711. revision:=0;
  712. valint(pattern,major,error);
  713. if error<>0 then
  714. begin
  715. Message1(scan_w_wrong_version_ignored,pattern);
  716. exit;
  717. end;
  718. if c='.' then
  719. begin
  720. current_scanner^.readchar;
  721. current_scanner^.readnumber;
  722. valint(pattern,minor,error);
  723. if error<>0 then
  724. begin
  725. Message1(scan_w_wrong_version_ignored,tostr(major)+'.'+pattern);
  726. exit;
  727. end;
  728. if (c='.') and
  729. (target_info.target = target_i386_netware) then // AD
  730. begin
  731. current_scanner^.readchar;
  732. current_scanner^.readnumber;
  733. valint(pattern,revision,error);
  734. if error<>0 then
  735. begin
  736. Message1(scan_w_wrong_version_ignored,tostr(revision)+'.'+pattern);
  737. exit;
  738. end;
  739. dllmajor:=major;
  740. dllminor:=minor;
  741. dllrevision:=revision;
  742. dllversion:=tostr(major)+','+tostr(minor)+','+tostr(revision);
  743. end
  744. else
  745. begin
  746. dllmajor:=major;
  747. dllminor:=minor;
  748. dllversion:=tostr(major)+'.'+tostr(minor);
  749. end;
  750. end
  751. else
  752. dllversion:=tostr(major);
  753. end;
  754. end;
  755. procedure dir_linkobject(t:tdirectivetoken);
  756. var
  757. s : string;
  758. begin
  759. current_scanner^.skipspace;
  760. s:=AddExtension(FixFileName(current_scanner^.readcomment),target_info.objext);
  761. current_module.linkotherofiles.add(s,link_allways);
  762. end;
  763. procedure dir_resource(t:tdirectivetoken);
  764. var
  765. s : string;
  766. begin
  767. current_scanner^.skipspace;
  768. s:=current_scanner^.readcomment;
  769. { replace * with current module name.
  770. This should always be defined. }
  771. if s[1]='*' then
  772. if Assigned(Current_Module) then
  773. begin
  774. delete(S,1,1);
  775. insert(lower(current_module.modulename^),S,1);
  776. end;
  777. s:=AddExtension(FixFileName(s),target_info.resext);
  778. if target_info.res<>res_none then
  779. if (target_info.res = res_i386_emx) and
  780. not (Current_module.ResourceFiles.Empty) then
  781. Message(scan_w_only_one_resourcefile_supported)
  782. else
  783. current_module.resourcefiles.insert(FixFileName(s))
  784. else
  785. Message(scan_e_resourcefiles_not_supported);
  786. end;
  787. procedure dir_linklib(t:tdirectivetoken);
  788. type
  789. tLinkMode=(lm_shared,lm_static);
  790. var
  791. s : string;
  792. quote : char;
  793. libname,
  794. linkmodestr : string;
  795. p : longint;
  796. linkMode : tLinkMode;
  797. begin
  798. current_scanner^.skipspace;
  799. s:=current_scanner^.readcomment;
  800. p:=pos(',',s);
  801. if p=0 then
  802. begin
  803. libname:=TrimSpace(s);
  804. linkmodeStr:='';
  805. end
  806. else
  807. begin
  808. libname:=TrimSpace(copy(s,1,p-1));
  809. linkmodeStr:=Upper(TrimSpace(copy(s,p+1,255)));
  810. end;
  811. if (libname='') or (libname='''''') or (libname='""') then
  812. exit;
  813. { get linkmode, default is shared linking }
  814. if linkModeStr='STATIC' then
  815. linkmode:=lm_static
  816. else if (LinkModeStr='SHARED') or (LinkModeStr='') then
  817. linkmode:=lm_shared
  818. else
  819. begin
  820. Comment(V_Error,'Wrong link mode specified: "'+Linkmodestr+'"');
  821. exit;
  822. end;
  823. { create library name }
  824. if libname[1] in ['''','"'] then
  825. begin
  826. quote:=libname[1];
  827. Delete(libname,1,1);
  828. p:=pos(quote,libname);
  829. if p>0 then
  830. Delete(libname,p,1);
  831. end;
  832. { add to the list of libraries to link }
  833. if linkMode=lm_static then
  834. current_module.linkOtherStaticLibs.add(FixFileName(libname),link_allways)
  835. else
  836. current_module.linkOtherSharedLibs.add(FixFileName(libname),link_allways);
  837. end;
  838. procedure dir_outputformat(t:tdirectivetoken);
  839. begin
  840. if not current_module.in_global then
  841. Message(scan_w_switch_is_global)
  842. else
  843. begin
  844. current_scanner^.skipspace;
  845. if set_string_asm(current_scanner^.readid) then
  846. aktoutputformat:=target_asm.id
  847. else
  848. Message1(scan_w_illegal_switch,pattern);
  849. end;
  850. end;
  851. procedure dir_unitpath(t:tdirectivetoken);
  852. begin
  853. if not current_module.in_global then
  854. Message(scan_w_switch_is_global)
  855. else
  856. begin
  857. current_scanner^.skipspace;
  858. current_module.localunitsearchpath.AddPath(current_scanner^.readcomment,false);
  859. end;
  860. end;
  861. procedure dir_includepath(t:tdirectivetoken);
  862. begin
  863. if not current_module.in_global then
  864. Message(scan_w_switch_is_global)
  865. else
  866. begin
  867. current_scanner^.skipspace;
  868. current_module.localincludesearchpath.AddPath(current_scanner^.readcomment,false);
  869. end;
  870. end;
  871. procedure dir_librarypath(t:tdirectivetoken);
  872. begin
  873. if not current_module.in_global then
  874. Message(scan_w_switch_is_global)
  875. else
  876. begin
  877. current_scanner^.skipspace;
  878. current_module.locallibrarysearchpath.AddPath(current_scanner^.readcomment,false);
  879. end;
  880. end;
  881. procedure dir_objectpath(t:tdirectivetoken);
  882. begin
  883. if not current_module.in_global then
  884. Message(scan_w_switch_is_global)
  885. else
  886. begin
  887. current_scanner^.skipspace;
  888. current_module.localobjectsearchpath.AddPath(current_scanner^.readcomment,false);
  889. end;
  890. end;
  891. procedure dir_mode(t:tdirectivetoken);
  892. begin
  893. if not current_module.in_global then
  894. Message(scan_w_switch_is_global)
  895. else
  896. begin
  897. current_scanner^.skipspace;
  898. current_scanner^.readstring;
  899. if not SetCompileMode(pattern,false) then
  900. Message1(scan_w_illegal_switch,pattern);
  901. end;
  902. end;
  903. procedure dir_packrecords(t:tdirectivetoken);
  904. var
  905. hs : string;
  906. begin
  907. current_scanner^.skipspace;
  908. if not(c in ['0'..'9']) then
  909. begin
  910. hs:=current_scanner^.readid;
  911. if (hs='C') then
  912. aktpackrecords:=packrecord_C
  913. else
  914. if (hs='NORMAL') or (hs='DEFAULT') then
  915. aktpackrecords:=packrecord_2
  916. else
  917. Message(scan_w_only_pack_records);
  918. end
  919. else
  920. begin
  921. case current_scanner^.readval of
  922. 1 : aktpackrecords:=packrecord_1;
  923. 2 : aktpackrecords:=packrecord_2;
  924. 4 : aktpackrecords:=packrecord_4;
  925. 8 : aktpackrecords:=packrecord_8;
  926. 16 : aktpackrecords:=packrecord_16;
  927. 32 : aktpackrecords:=packrecord_32;
  928. else
  929. Message(scan_w_only_pack_records);
  930. end;
  931. end;
  932. end;
  933. procedure dir_maxfpuregisters(t:tdirectivetoken);
  934. var
  935. l : longint;
  936. hs : string;
  937. begin
  938. current_scanner^.skipspace;
  939. if not(c in ['0'..'9']) then
  940. begin
  941. hs:=current_scanner^.readid;
  942. if (hs='NORMAL') or (hs='DEFAULT') then
  943. aktmaxfpuregisters:=-1
  944. else
  945. Message(scan_e_invalid_maxfpureg_value);
  946. end
  947. else
  948. begin
  949. l:=current_scanner^.readval;
  950. case l of
  951. 0..8:
  952. aktmaxfpuregisters:=l;
  953. else
  954. Message(scan_e_invalid_maxfpureg_value);
  955. end;
  956. end;
  957. end;
  958. procedure dir_packenum(t:tdirectivetoken);
  959. var
  960. hs : string;
  961. begin
  962. if t in [_DIR_Z1,_DIR_Z2,_DIR_Z4] then
  963. begin
  964. aktpackenum:=ord(pattern[2])-ord('0');
  965. exit;
  966. end;
  967. current_scanner^.skipspace;
  968. if not(c in ['0'..'9']) then
  969. begin
  970. hs:=current_scanner^.readid;
  971. if (hs='NORMAL') or (hs='DEFAULT') then
  972. aktpackenum:=4
  973. else
  974. Message(scan_w_only_pack_enum);
  975. end
  976. else
  977. begin
  978. case current_scanner^.readval of
  979. 1 : aktpackenum:=1;
  980. 2 : aktpackenum:=2;
  981. 4 : aktpackenum:=4;
  982. else
  983. Message(scan_w_only_pack_enum);
  984. end;
  985. end;
  986. end;
  987. {$ifdef testvarsets}
  988. procedure dir_setalloc(t:tdirectivetoken);
  989. var
  990. hs : string;
  991. begin
  992. current_scanner^.skipspace;
  993. if not(c in ['1','2','4']) then
  994. begin
  995. hs:=current_scanner^.readid;
  996. if (hs='FIXED') or ((hs='DEFAULT') OR (hs='NORMAL')) then
  997. aktsetalloc:=0 {Fixed mode, sets are 4 or 32 bytes}
  998. else
  999. Message(scan_w_only_packset);
  1000. end
  1001. else
  1002. begin
  1003. case current_scanner^.readval of
  1004. 1 : aktpackenum:=1;
  1005. 2 : aktpackenum:=2;
  1006. 4 : aktpackenum:=4;
  1007. else
  1008. Message(scan_w_only_packset);
  1009. end;
  1010. end;
  1011. end;
  1012. {$ENDIF}
  1013. procedure dir_apptype(t:tdirectivetoken);
  1014. var
  1015. hs : string;
  1016. begin
  1017. if (target_info.target<>target_i386_win32)
  1018. and (target_info.target<>target_i386_os2) then
  1019. Message(scan_w_app_type_not_support);
  1020. if not current_module.in_global then
  1021. Message(scan_w_switch_is_global)
  1022. else
  1023. begin
  1024. current_scanner^.skipspace;
  1025. hs:=current_scanner^.readid;
  1026. if hs='GUI' then
  1027. apptype:=app_gui
  1028. else if hs='CONSOLE' then
  1029. apptype:=app_cui
  1030. else if (hs='FS') and (target_info.target=target_i386_os2) then
  1031. apptype:=app_fs
  1032. else
  1033. Message1(scan_w_unsupported_app_type,hs);
  1034. end;
  1035. end;
  1036. procedure dir_wait(t:tdirectivetoken);
  1037. var had_info : boolean;
  1038. begin
  1039. had_info:=(status.verbosity and V_Info)<>0;
  1040. { this message should allways appear !! }
  1041. status.verbosity:=status.verbosity or V_Info;
  1042. Message(scan_i_press_enter);
  1043. readln;
  1044. If not(had_info) then
  1045. status.verbosity:=status.verbosity and (not V_Info);
  1046. end;
  1047. procedure dir_asmmode(t:tdirectivetoken);
  1048. var
  1049. s : string;
  1050. begin
  1051. current_scanner^.skipspace;
  1052. s:=current_scanner^.readid;
  1053. If Inside_asm_statement then
  1054. Message1(scan_w_no_asm_reader_switch_inside_asm,s);
  1055. if s='DEFAULT' then
  1056. aktasmmode:=initasmmode
  1057. else
  1058. if not set_string_asmmode(s,aktasmmode) then
  1059. Message1(scan_w_unsupported_asmmode_specifier,s);
  1060. end;
  1061. procedure dir_oldasmmode(t:tdirectivetoken);
  1062. begin
  1063. If Inside_asm_statement then
  1064. Message1(scan_w_no_asm_reader_switch_inside_asm,directive[t]);
  1065. {$ifdef i386}
  1066. case t of
  1067. _DIR_I386_ATT : aktasmmode:=asmmode_i386_att;
  1068. _DIR_I386_DIRECT : aktasmmode:=asmmode_i386_direct;
  1069. _DIR_I386_INTEL : aktasmmode:=asmmode_i386_intel;
  1070. end;
  1071. {$endif i386}
  1072. end;
  1073. procedure dir_delphiswitch(t:tdirectivetoken);
  1074. var
  1075. sw,state : char;
  1076. begin
  1077. case t of
  1078. _DIR_ALIGN : sw:='A';
  1079. _DIR_ASSERTIONS : sw:='C';
  1080. _DIR_BOOLEVAL : sw:='B';
  1081. _DIR_DEBUGINFO : sw:='D';
  1082. _DIR_IOCHECKS : sw:='I';
  1083. _DIR_LOCALSYMBOLS : sw:='L';
  1084. _DIR_LONGSTRINGS : sw:='H';
  1085. _DIR_OPENSTRINGS : sw:='P';
  1086. _DIR_OVERFLOWCHECKS : sw:='Q';
  1087. _DIR_RANGECHECKS : sw:='R';
  1088. _DIR_REFERENCEINFO : sw:='Y';
  1089. _DIR_STACKFRAMES : sw:='W';
  1090. _DIR_TYPEDADDRESS : sw:='T';
  1091. _DIR_TYPEINFO : sw:='M';
  1092. _DIR_VARSTRINGCHECKS : sw:='V';
  1093. else
  1094. exit;
  1095. end;
  1096. { c contains the next char, a + or - would be fine }
  1097. state:=current_scanner^.readstate;
  1098. if state in ['-','+'] then
  1099. HandleSwitch(sw,state);
  1100. end;
  1101. procedure dir_memory(t:tdirectivetoken);
  1102. var
  1103. l : longint;
  1104. begin
  1105. current_scanner^.skipspace;
  1106. l:=current_scanner^.readval;
  1107. if l>1024 then
  1108. stacksize:=l;
  1109. current_scanner^.skipspace;
  1110. if c=',' then
  1111. begin
  1112. current_scanner^.readchar;
  1113. current_scanner^.skipspace;
  1114. l:=current_scanner^.readval;
  1115. if l>1024 then
  1116. heapsize:=l;
  1117. end;
  1118. if c=',' then
  1119. begin
  1120. current_scanner^.readchar;
  1121. current_scanner^.skipspace;
  1122. l:=current_scanner^.readval;
  1123. { Ignore this value, because the limit is set by the OS
  1124. info and shouldn't be changed by the user (PFV) }
  1125. end;
  1126. end;
  1127. procedure dir_setverbose(t:tdirectivetoken);
  1128. var
  1129. flag,
  1130. state : char;
  1131. begin
  1132. case t of
  1133. _DIR_HINTS : flag:='H';
  1134. _DIR_WARNINGS : flag:='W';
  1135. _DIR_NOTES : flag:='N';
  1136. else
  1137. exit;
  1138. end;
  1139. { support ON/OFF }
  1140. state:=current_scanner^.ReadState;
  1141. SetVerbosity(flag+state);
  1142. end;
  1143. type
  1144. tdirectiveproc=procedure(t:tdirectivetoken);
  1145. const
  1146. directiveproc:array[tdirectivetoken] of tdirectiveproc=(
  1147. {_DIR_NONE} nil,
  1148. {_DIR_ALIGN} dir_delphiswitch,
  1149. {_DIR_APPTYPE} dir_apptype,
  1150. {_DIR_ASMMODE} dir_asmmode,
  1151. {_DIR_ASSERTION} dir_delphiswitch,
  1152. {_DIR_BOOLEVAL} dir_delphiswitch,
  1153. {_DIR_D} dir_description,
  1154. {_DIR_DEBUGINFO} dir_delphiswitch,
  1155. {_DIR_DEFINE} dir_define,
  1156. {_DIR_DESCRIPTION} dir_description,
  1157. {_DIR_ELSE} dir_conditional,
  1158. {_DIR_ENDIF} dir_conditional,
  1159. {_DIR_ERROR} dir_message,
  1160. {_DIR_EXTENDEDSYNTAX} dir_delphiswitch,
  1161. {_DIR_FATAL} dir_message,
  1162. {_DIR_GOTO} dir_moduleswitch,
  1163. {_DIR_HINT} dir_message,
  1164. {_DIR_HINTS} dir_setverbose,
  1165. {_DIR_I} dir_include,
  1166. {_DIR_I386_ATT} dir_oldasmmode,
  1167. {_DIR_I386_DIRECT} dir_oldasmmode,
  1168. {_DIR_I386_INTEL} dir_oldasmmode,
  1169. {_DIR_IOCHECKS} dir_delphiswitch,
  1170. {_DIR_IF} dir_conditional,
  1171. {_DIR_IFDEF} dir_conditional,
  1172. {_DIR_IFNDEF} dir_conditional,
  1173. {_DIR_IFOPT} dir_conditional,
  1174. {_DIR_INCLUDE} dir_include,
  1175. {_DIR_INCLUDEPATH} dir_includepath,
  1176. {_DIR_INFO} dir_message,
  1177. {_DIR_INLINE} dir_moduleswitch,
  1178. {_DIR_INTERFACES} dir_interfacesswitch,
  1179. {_DIR_L} dir_linkobject,
  1180. {_DIR_LIBRARYPATH} dir_librarypath,
  1181. {_DIR_LINK} dir_linkobject,
  1182. {_DIR_LINKLIB} dir_linklib,
  1183. {_DIR_LOCALSYMBOLS} dir_delphiswitch,
  1184. {_DIR_LONGSTRINGS} dir_delphiswitch,
  1185. {_DIR_M} dir_memory,
  1186. {_DIR_MACRO} dir_moduleswitch,
  1187. {_DIR_MAXFPUREGISTERS} dir_maxfpuregisters,
  1188. {_DIR_MEMORY} dir_memory,
  1189. {_DIR_MESSAGE} dir_message,
  1190. {_DIR_MINENUMSIZE} dir_packenum,
  1191. {_DIR_MMX} dir_localswitch,
  1192. {_DIR_MODE} dir_mode,
  1193. {_DIR_NOTE} dir_message,
  1194. {_DIR_NOTES} dir_setverbose,
  1195. {_DIR_OBJECTPATH} dir_objectpath,
  1196. {_DIR_OPENSTRINGS} dir_delphiswitch,
  1197. {_DIR_OUTPUT_FORMAT} dir_outputformat,
  1198. {_DIR_OVERFLOWCHECKS} dir_delphiswitch,
  1199. {_DIR_PACKENUM} dir_packenum,
  1200. {_DIR_PACKRECORDS} dir_packrecords,
  1201. {$IFDEF TestVarsets}
  1202. {_DIR_PACKSET} dir_packset,
  1203. {$ENDIF}
  1204. {_DIR_R} dir_resource,
  1205. {_DIR_RANGECHECKS} dir_delphiswitch,
  1206. {_DIR_REFERENCEINFO} dir_delphiswitch,
  1207. {_DIR_SATURATION} dir_localswitch,
  1208. {_DIR_SMARTLINK} dir_moduleswitch,
  1209. {_DIR_STACKFRAMES} dir_delphiswitch,
  1210. {_DIR_STATIC} dir_moduleswitch,
  1211. {_DIR_STOP} dir_message,
  1212. {_DIR_TYPEDADDRESS} dir_delphiswitch,
  1213. {_DIR_TYPEINFO} dir_delphiswitch,
  1214. {_DIR_UNDEF} dir_undef,
  1215. {_DIR_UNITPATH} dir_unitpath,
  1216. {_DIR_VARSTRINGCHECKS} dir_delphiswitch,
  1217. {_DIR_VERSION} dir_version,
  1218. {_DIR_WAIT} dir_wait,
  1219. {_DIR_WARNING} dir_message,
  1220. {_DIR_WARNINGS} dir_setverbose,
  1221. {_DIR_Z1} dir_packenum,
  1222. {_DIR_Z2} dir_packenum,
  1223. {_DIR_Z4} dir_packenum
  1224. );
  1225. {-------------------------------------------
  1226. Main switches handling
  1227. -------------------------------------------}
  1228. procedure handledirectives;
  1229. var
  1230. t : tdirectivetoken;
  1231. p : tdirectiveproc;
  1232. hs : string;
  1233. begin
  1234. current_scanner^.gettokenpos;
  1235. current_scanner^.readchar; {Remove the $}
  1236. hs:=current_scanner^.readid;
  1237. {$ifdef PREPROCWRITE}
  1238. if parapreprocess then
  1239. begin
  1240. t:=Get_Directive(hs);
  1241. if not(is_conditional(t) or (t=_DIR_DEFINE) or (t=_DIR_UNDEF)) then
  1242. begin
  1243. preprocfile^.AddSpace;
  1244. preprocfile^.Add('{$'+hs+current_scanner^.readcomment+'}');
  1245. exit;
  1246. end;
  1247. end;
  1248. {$endif PREPROCWRITE}
  1249. { skip this directive? }
  1250. if (current_scanner^.ignoredirectives.find(hs)<>nil) then
  1251. begin
  1252. if (current_scanner^.comment_level>0) then
  1253. current_scanner^.readcomment;
  1254. { we've read the whole comment }
  1255. aktcommentstyle:=comment_none;
  1256. exit;
  1257. end;
  1258. if hs='' then
  1259. begin
  1260. Message1(scan_w_illegal_switch,'$'+hs);
  1261. end;
  1262. { Check for compiler switches }
  1263. while (length(hs)=1) and (c in ['-','+']) do
  1264. begin
  1265. HandleSwitch(hs[1],c);
  1266. current_scanner^.readchar; {Remove + or -}
  1267. if c=',' then
  1268. begin
  1269. current_scanner^.readchar; {Remove , }
  1270. { read next switch, support $v+,$+}
  1271. hs:=current_scanner^.readid;
  1272. if (hs='') then
  1273. begin
  1274. if (c='$') and (m_fpc in aktmodeswitches) then
  1275. begin
  1276. current_scanner^.readchar; { skip $ }
  1277. hs:=current_scanner^.readid;
  1278. end;
  1279. if (hs='') then
  1280. Message1(scan_w_illegal_directive,'$'+c);
  1281. end
  1282. else
  1283. Message1(scan_d_handling_switch,'$'+hs);
  1284. end
  1285. else
  1286. hs:='';
  1287. end;
  1288. { directives may follow switches after a , }
  1289. if hs<>'' then
  1290. begin
  1291. t:=Get_Directive(hs);
  1292. if t<>_DIR_NONE then
  1293. begin
  1294. p:=directiveproc[t];
  1295. if {$ifndef FPCPROCVAR}@{$endif}p<>nil then
  1296. p(t);
  1297. end
  1298. else
  1299. begin
  1300. current_scanner^.ignoredirectives.insert(hs);
  1301. Message1(scan_w_illegal_directive,'$'+hs);
  1302. end;
  1303. { conditionals already read the comment }
  1304. if (current_scanner^.comment_level>0) then
  1305. current_scanner^.readcomment;
  1306. { we've read the whole comment }
  1307. aktcommentstyle:=comment_none;
  1308. end;
  1309. end;
  1310. {
  1311. $Log$
  1312. Revision 1.19 2001-03-13 18:45:07 peter
  1313. * fixed some memory leaks
  1314. Revision 1.18 2001/02/20 21:41:18 peter
  1315. * new fixfilename, findfile for unix. Look first for lowercase, then
  1316. NormalCase and last for UPPERCASE names.
  1317. Revision 1.17 2001/01/20 18:32:52 hajny
  1318. + APPTYPE support under OS/2, app_fs, GetEnvPChar for OS/2
  1319. Revision 1.16 2001/01/13 00:09:21 peter
  1320. * made Pavel O. happy ;)
  1321. Revision 1.15 2000/12/25 00:07:28 peter
  1322. + new tlinkedlist class (merge of old tstringqueue,tcontainer and
  1323. tlinkedlist objects)
  1324. Revision 1.14 2000/12/24 12:24:38 peter
  1325. * moved preprocessfile into a conditional
  1326. Revision 1.13 2000/12/12 19:48:52 peter
  1327. * fixed lost char after $I directive (merged)
  1328. Revision 1.12 2000/11/12 22:17:47 peter
  1329. * some realname updates for messages
  1330. Revision 1.11 2000/11/04 14:25:21 florian
  1331. + merged Attila's changes for interfaces, not tested yet
  1332. Revision 1.10 2000/10/31 22:02:51 peter
  1333. * symtable splitted, no real code changes
  1334. Revision 1.9 2000/09/26 10:50:41 jonas
  1335. * initmodeswitches is changed is you change the compiler mode from the
  1336. command line (the -S<x> switches didn't work anymore for changing the
  1337. compiler mode) (merged from fixes branch)
  1338. Revision 1.8 2000/09/24 21:33:47 peter
  1339. * message updates merges
  1340. Revision 1.7 2000/09/24 15:06:27 peter
  1341. * use defines.inc
  1342. Revision 1.6 2000/09/11 17:00:23 florian
  1343. + first implementation of Netware Module support, thanks to
  1344. Armin Diehl ([email protected]) for providing the patches
  1345. Revision 1.5 2000/09/10 21:18:15 peter
  1346. * macro warning (merged)
  1347. Revision 1.4 2000/08/12 15:30:44 peter
  1348. * IDE patch for stream reading (merged)
  1349. Revision 1.3 2000/08/08 19:28:57 peter
  1350. * memdebug/memory patches (merged)
  1351. * only once illegal directive (merged)
  1352. Revision 1.2 2000/07/13 11:32:49 michael
  1353. + removed logs
  1354. }