domacro.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811
  1. /*
  2. * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
  3. * See the copyright notice in the ACK home directory, in the file "Copyright".
  4. */
  5. /* $Id$ */
  6. /* PREPROCESSOR: CONTROLLINE INTERPRETER */
  7. #include "arith.h"
  8. #include "LLlex.h"
  9. #include "Lpars.h"
  10. #include "idf.h"
  11. #include "input.h"
  12. #include "ifdepth.h"
  13. #include "botch_free.h"
  14. #include "nparams.h"
  15. #include "parbufsize.h"
  16. #include "textsize.h"
  17. #include "idfsize.h"
  18. #include "debug.h"
  19. #include <assert.h>
  20. #include <alloc.h>
  21. #include "class.h"
  22. #include "macro.h"
  23. #include "bits.h"
  24. #include "macbuf.h"
  25. #include "replace.h"
  26. extern char options[];
  27. extern char **inctable; /* list of include directories */
  28. extern char *getwdir();
  29. char ifstack[IFDEPTH]; /* if-stack: the content of an entry is */
  30. /* 1 if a corresponding ELSE has been */
  31. /* encountered. */
  32. int nestlevel = -1;
  33. int svnestlevel[30] = {-1};
  34. int nestcount;
  35. extern int do_preprocess;
  36. char *
  37. GetIdentifier(skiponerr)
  38. int skiponerr; /* skip the rest of the line on error */
  39. {
  40. /* Returns a pointer to the identifier that is read from the
  41. input stream. When the input does not contain an
  42. identifier, the rest of the line is skipped when skiponerr
  43. is on, and a null-pointer is returned.
  44. The substitution of macros is disabled.
  45. Remember that on end-of-line EOF is returned.
  46. */
  47. int tmp = UnknownIdIsZero;
  48. int tok;
  49. struct token tk;
  50. UnknownIdIsZero = ReplaceMacros = 0;
  51. tok = GetToken(&tk);
  52. ReplaceMacros = 1;
  53. UnknownIdIsZero = tmp;
  54. if (tok != IDENTIFIER) {
  55. if (skiponerr && tok != EOF) SkipToNewLine();
  56. return (char *)0;
  57. }
  58. return tk.tk_str;
  59. }
  60. /* domacro() is the control line interpreter. The '#' has already
  61. been read by the lexical analyzer by which domacro() is called.
  62. The token appearing directly after the '#' is obtained by calling
  63. the basic lexical analyzing function GetToken() and is interpreted
  64. to perform the action belonging to that token.
  65. An error message is produced when the token is not recognized.
  66. Pragma's are handled by do_pragma(). They are passed on to the
  67. compiler.
  68. */
  69. domacro()
  70. {
  71. struct token tk; /* the token itself */
  72. register struct idf *id;
  73. int toknum;
  74. ReplaceMacros = 0;
  75. toknum = GetToken(&tk);
  76. ReplaceMacros = 1;
  77. switch(toknum) { /* select control line action */
  78. case IDENTIFIER: /* is it a macro keyword? */
  79. id = findidf(tk.tk_str);
  80. if (!id) {
  81. error("%s: unknown control", tk.tk_str);
  82. SkipToNewLine();
  83. free(tk.tk_str);
  84. break;
  85. }
  86. free(tk.tk_str);
  87. switch (id->id_resmac) {
  88. case K_DEFINE: /* "define" */
  89. do_define();
  90. break;
  91. case K_ELIF: /* "elif" */
  92. do_elif();
  93. break;
  94. case K_ELSE: /* "else" */
  95. do_else();
  96. break;
  97. case K_ENDIF: /* "endif" */
  98. do_endif();
  99. break;
  100. case K_IF: /* "if" */
  101. do_if();
  102. break;
  103. case K_IFDEF: /* "ifdef" */
  104. do_ifdef(1);
  105. break;
  106. case K_IFNDEF: /* "ifndef" */
  107. do_ifdef(0);
  108. break;
  109. case K_INCLUDE: /* "include" */
  110. do_include();
  111. break;
  112. case K_LINE: /* "line" */
  113. /* set LineNumber and FileName according to
  114. the arguments.
  115. */
  116. if (GetToken(&tk) != INTEGER) {
  117. error("bad #line syntax");
  118. SkipToNewLine();
  119. }
  120. else
  121. do_line((unsigned int)tk.tk_val);
  122. break;
  123. case K_ERROR: /* "error" */
  124. do_error();
  125. break;
  126. case K_PRAGMA: /* "pragma" */
  127. do_pragma();
  128. break;
  129. case K_UNDEF: /* "undef" */
  130. do_undef((char *)0);
  131. break;
  132. default:
  133. /* invalid word seen after the '#' */
  134. error("%s: unknown control", id->id_text);
  135. SkipToNewLine();
  136. }
  137. break;
  138. case INTEGER: /* # <integer> [<filespecifier>]? */
  139. do_line((unsigned int)tk.tk_val);
  140. break;
  141. case EOF: /* only `#' on this line: do nothing, ignore */
  142. break;
  143. default: /* invalid token following '#' */
  144. error("illegal # line");
  145. SkipToNewLine();
  146. }
  147. }
  148. skip_block(to_endif)
  149. int to_endif;
  150. {
  151. /* skip_block() skips the input from
  152. 1) a false #if, #ifdef, #ifndef or #elif until the
  153. corresponding #elif (resulting in true), #else or
  154. #endif is read.
  155. 2) a #else corresponding to a true #if, #ifdef,
  156. #ifndef or #elif until the corresponding #endif is
  157. seen.
  158. */
  159. register int ch;
  160. register int skiplevel = nestlevel; /* current nesting level */
  161. struct token tk;
  162. int toknum;
  163. struct idf *id;
  164. NoUnstack++;
  165. for (;;) {
  166. ch = GetChar(); /* read first character after newline */
  167. while (class(ch) == STSKIP)
  168. ch = GetChar();
  169. if (ch != '#') {
  170. if (ch == EOI) {
  171. NoUnstack--;
  172. return;
  173. }
  174. if (ch == '/') {
  175. if (ch != '*') UnGetChar();
  176. else {
  177. skipcomment();
  178. continue;
  179. }
  180. } else UnGetChar();
  181. SkipToNewLine();
  182. continue;
  183. }
  184. ReplaceMacros = 0;
  185. toknum = GetToken(&tk);
  186. ReplaceMacros = 1;
  187. if (toknum != IDENTIFIER) {
  188. if (toknum != INTEGER) {
  189. error("illegal # line");
  190. }
  191. SkipToNewLine();
  192. continue;
  193. }
  194. /* an IDENTIFIER: look for #if, #ifdef and #ifndef
  195. without interpreting them.
  196. Interpret #else, #elif and #endif if they occur
  197. on the same level.
  198. */
  199. id = findidf(tk.tk_str);
  200. if (id == (struct idf *)0) {
  201. /* invalid word seen after the '#' */
  202. warning("%s: unknown control", tk.tk_str);
  203. }
  204. free(tk.tk_str);
  205. if (id == (struct idf *)0) continue;
  206. switch(id->id_resmac) {
  207. case K_DEFINE:
  208. case K_ERROR:
  209. case K_INCLUDE:
  210. case K_LINE:
  211. case K_PRAGMA:
  212. case K_UNDEF:
  213. case K_FILE:
  214. SkipToNewLine();
  215. break;
  216. case K_IF:
  217. case K_IFDEF:
  218. case K_IFNDEF:
  219. push_if();
  220. SkipToNewLine();
  221. break;
  222. case K_ELIF:
  223. if (ifstack[nestlevel])
  224. error("#elif after #else");
  225. if (!to_endif && nestlevel == skiplevel) {
  226. nestlevel--;
  227. push_if();
  228. if (ifexpr()) {
  229. NoUnstack--;
  230. return;
  231. }
  232. }
  233. else SkipToNewLine(); /* otherwise done in ifexpr() */
  234. break;
  235. case K_ELSE:
  236. if (ifstack[nestlevel])
  237. error("#else after #else");
  238. ++(ifstack[nestlevel]);
  239. if (!to_endif && nestlevel == skiplevel) {
  240. if (SkipToNewLine()) {
  241. if (!options['o'])
  242. strict("garbage following #else");
  243. }
  244. NoUnstack--;
  245. return;
  246. }
  247. else SkipToNewLine();
  248. break;
  249. case K_ENDIF:
  250. assert(nestlevel > svnestlevel[nestcount]);
  251. if (nestlevel == skiplevel) {
  252. if (SkipToNewLine()) {
  253. if (!options['o'])
  254. strict("garbage following #endif");
  255. }
  256. nestlevel--;
  257. NoUnstack--;
  258. return;
  259. }
  260. else SkipToNewLine();
  261. nestlevel--;
  262. break;
  263. }
  264. }
  265. }
  266. ifexpr()
  267. {
  268. /* ifexpr() returns whether the restricted constant
  269. expression following #if or #elif evaluates to true. This
  270. is done by calling the LLgen generated subparser for
  271. constant expressions. The result of this expression will
  272. be given in the extern long variable "ifval".
  273. */
  274. extern arith ifval;
  275. int errors = err_occurred;
  276. ifval = (arith)0;
  277. AccDefined = 1;
  278. UnknownIdIsZero = 1;
  279. DOT = 0; /* tricky */
  280. If_expr(); /* invoke constant expression parser */
  281. AccDefined = 0;
  282. UnknownIdIsZero = 0;
  283. return (errors == err_occurred) && (ifval != (arith)0);
  284. }
  285. do_include()
  286. {
  287. /* do_include() performs the inclusion of a file.
  288. */
  289. char *filenm;
  290. char *result;
  291. int tok;
  292. struct token tk;
  293. AccFileSpecifier = 1;
  294. if (((tok = GetToken(&tk)) == FILESPECIFIER) || tok == STRING)
  295. filenm = tk.tk_str;
  296. else {
  297. error("bad include syntax");
  298. filenm = (char *)0;
  299. }
  300. AccFileSpecifier = 0;
  301. if (SkipToNewLine()) {
  302. error("bad include syntax");
  303. }
  304. inctable[0] = WorkingDir;
  305. if (filenm) {
  306. if (!InsertFile(filenm, &inctable[tok==FILESPECIFIER],&result)){
  307. if (do_preprocess) error("cannot open include file \"%s\"", filenm);
  308. else warning("cannot open include file \"%s\"", filenm);
  309. add_dependency(filenm);
  310. }
  311. else {
  312. add_dependency(result);
  313. WorkingDir = getwdir(result);
  314. svnestlevel[++nestcount] = nestlevel;
  315. FileName = result;
  316. LineNumber = 1;
  317. }
  318. }
  319. }
  320. do_define()
  321. {
  322. /* do_define() interprets a #define control line.
  323. */
  324. register char *str; /* the #defined identifier's descriptor */
  325. int nformals = -1; /* keep track of the number of formals */
  326. char *formals[NPARAMS]; /* pointers to the names of the formals */
  327. char parbuf[PARBUFSIZE]; /* names of formals */
  328. char *repl_text; /* start of the replacement text */
  329. int length; /* length of the replacement text */
  330. register ch;
  331. char *get_text();
  332. /* read the #defined macro's name */
  333. if (!(str = GetIdentifier(1))) {
  334. error("#define: illegal macro name");
  335. return;
  336. }
  337. /* there is a formal parameter list if the identifier is
  338. followed immediately by a '('.
  339. */
  340. ch = GetChar();
  341. if (ch == '(') {
  342. if ((nformals = getparams(formals, parbuf)) == -1) {
  343. SkipToNewLine();
  344. free(str);
  345. return; /* an error occurred */
  346. }
  347. ch = GetChar();
  348. }
  349. /* read the replacement text if there is any */
  350. ch = skipspaces(ch,0); /* find first character of the text */
  351. assert(ch != EOI);
  352. /* UnGetChar() is not right when replacement starts with a '/' */
  353. ChPushBack(ch);
  354. repl_text = get_text((nformals > 0) ? formals : 0, &length);
  355. macro_def(str2idf(str, 0), repl_text, nformals, length, NOFLAG);
  356. LineNumber++;
  357. }
  358. push_if()
  359. {
  360. if (nestlevel >= IFDEPTH)
  361. fatal("too many nested #if/#ifdef/#ifndef");
  362. else
  363. ifstack[++nestlevel] = 0;
  364. }
  365. do_elif()
  366. {
  367. if (nestlevel <= svnestlevel[nestcount]) {
  368. error("#elif without corresponding #if");
  369. SkipToNewLine();
  370. }
  371. else { /* restart at this level as if a #if is detected. */
  372. if (ifstack[nestlevel]) {
  373. error("#elif after #else");
  374. SkipToNewLine();
  375. }
  376. nestlevel--;
  377. push_if();
  378. skip_block(1);
  379. }
  380. }
  381. do_else()
  382. {
  383. if (SkipToNewLine()) {
  384. if (!options['o'])
  385. strict("garbage following #else");
  386. }
  387. if (nestlevel <= svnestlevel[nestcount])
  388. error("#else without corresponding #if");
  389. else { /* mark this level as else-d */
  390. if (ifstack[nestlevel]) {
  391. error("#else after #else");
  392. }
  393. ++(ifstack[nestlevel]);
  394. skip_block(1);
  395. }
  396. }
  397. do_endif()
  398. {
  399. if (SkipToNewLine()) {
  400. if (!options['o'])
  401. strict("garbage following #endif");
  402. }
  403. if (nestlevel <= svnestlevel[nestcount]) {
  404. error("#endif without corresponding #if");
  405. }
  406. else nestlevel--;
  407. }
  408. do_if()
  409. {
  410. push_if();
  411. if (!ifexpr()) /* a false #if/#elif expression */
  412. skip_block(0);
  413. }
  414. do_ifdef(how)
  415. {
  416. register struct idf *id;
  417. register char *str;
  418. /* how == 1 : ifdef; how == 0 : ifndef
  419. */
  420. push_if();
  421. if (!(str = GetIdentifier(1))) {
  422. error("illegal #ifdef construction");
  423. id = (struct idf *)0;
  424. } else {
  425. id = findidf(str);
  426. free(str);
  427. }
  428. if (SkipToNewLine()) {
  429. if (str && !options['o'])
  430. strict("garbage following #%s <identifier>",
  431. how ? "ifdef" : "ifndef");
  432. }
  433. /* The next test is a shorthand for:
  434. (how && !id->id_macro) || (!how && id->id_macro)
  435. */
  436. if (how ^ (id && id->id_macro != 0))
  437. skip_block(0);
  438. }
  439. /* argstr != NULL when the undef came from a -U option */
  440. do_undef(argstr)
  441. char *argstr;
  442. {
  443. register struct idf *id;
  444. register char *str = argstr;
  445. /* Forget a macro definition. */
  446. if (str || (str = GetIdentifier(1))) {
  447. if ((id = findidf(str)) && id->id_macro) {
  448. if (id->id_macro->mc_flag & NOUNDEF) {
  449. error("it is not allowed to #undef %s", str);
  450. } else {
  451. free(id->id_macro->mc_text);
  452. free_macro(id->id_macro);
  453. id->id_macro = (struct macro *) 0;
  454. }
  455. } /* else: don't complain */
  456. if (!argstr){
  457. free(str);
  458. if (SkipToNewLine()) {
  459. if (!options['o'])
  460. strict("garbage following #undef");
  461. }
  462. }
  463. }
  464. else
  465. error("illegal #undef construction");
  466. }
  467. do_error()
  468. {
  469. int len;
  470. char *get_text();
  471. char *bp = get_text((char **) 0, &len);
  472. error("user error: %s", bp);
  473. free(bp);
  474. LineNumber++;
  475. }
  476. int
  477. getparams(buf, parbuf)
  478. char *buf[];
  479. char parbuf[];
  480. {
  481. /* getparams() reads the formal parameter list of a macro
  482. definition.
  483. The number of parameters is returned.
  484. As a formal parameter list is expected when calling this
  485. routine, -1 is returned if an error is detected, for
  486. example:
  487. #define one(1), where 1 is not an identifier.
  488. Note that the '(' has already been eaten.
  489. The names of the formal parameters are stored into parbuf.
  490. */
  491. register char **pbuf = &buf[0];
  492. register int c;
  493. register char *ptr = &parbuf[0];
  494. register char **pbuf2;
  495. c = GetChar();
  496. c = skipspaces(c,0);
  497. if (c == ')') { /* no parameters: #define name() */
  498. *pbuf = (char *) 0;
  499. return 0;
  500. }
  501. for (;;) { /* eat the formal parameter list */
  502. if (class(c) != STIDF && class(c) != STELL) {
  503. error("#define: bad formal parameter");
  504. return -1;
  505. }
  506. *pbuf = ptr; /* name of the formal */
  507. *ptr++ = c;
  508. if (ptr >= &parbuf[PARBUFSIZE])
  509. fatal("formal parameter buffer overflow");
  510. do { /* eat the identifier name */
  511. c = GetChar();
  512. *ptr++ = c;
  513. if (ptr >= &parbuf[PARBUFSIZE])
  514. fatal("formal parameter buffer overflow");
  515. } while (in_idf(c));
  516. *(ptr - 1) = '\0'; /* mark end of the name */
  517. /* Check if this formal parameter is already used.
  518. Usually, macros do not have many parameters, so ...
  519. */
  520. for (pbuf2 = pbuf - 1; pbuf2 >= &buf[0]; pbuf2--) {
  521. if (!strcmp(*pbuf2, *pbuf)) {
  522. warning("formal parameter \"%s\" already used",
  523. *pbuf);
  524. }
  525. }
  526. pbuf++;
  527. c = skipspaces(c,0);
  528. if (c == ')') { /* end of the formal parameter list */
  529. *pbuf = (char *) 0;
  530. return pbuf - buf;
  531. }
  532. if (c != ',') {
  533. error("#define: bad formal parameter list");
  534. return -1;
  535. }
  536. c = GetChar();
  537. c = skipspaces(c,0);
  538. }
  539. /*NOTREACHED*/
  540. }
  541. macro_def(id, text, nformals, length, flags)
  542. register struct idf *id;
  543. char *text;
  544. {
  545. register struct macro *newdef = id->id_macro;
  546. /* macro_def() puts the contents and information of a macro
  547. definition into a structure and stores it into the symbol
  548. table entry belonging to the name of the macro.
  549. An error is given if there was already a definition
  550. */
  551. if (newdef) { /* is there a redefinition? */
  552. if (newdef->mc_flag & NOUNDEF) {
  553. error("it is not allowed to redefine %s", id->id_text);
  554. } else if (!macroeq(newdef->mc_text, text))
  555. error("illegal redefine of \"%s\"", id->id_text);
  556. free(text);
  557. return;
  558. } else {
  559. #ifdef DOBITS
  560. register char *p = id->id_text;
  561. #define setbit(bx) if (!*p) goto go_on; bits[*p++] |= (bx)
  562. setbit(bit0);
  563. setbit(bit1);
  564. setbit(bit2);
  565. setbit(bit3);
  566. setbit(bit4);
  567. setbit(bit5);
  568. setbit(bit6);
  569. setbit(bit7);
  570. go_on:
  571. #endif
  572. id->id_macro = newdef = new_macro();
  573. }
  574. newdef->mc_text = text; /* replacement text */
  575. newdef->mc_nps = nformals; /* nr of formals */
  576. newdef->mc_length = length; /* length of repl. text */
  577. newdef->mc_flag = flags; /* special flags */
  578. }
  579. int
  580. find_name(nm, index)
  581. char *nm, *index[];
  582. {
  583. /* find_name() returns the index of "nm" in the namelist
  584. "index" if it can be found there. 0 is returned if it is
  585. not there.
  586. */
  587. register char **ip = &index[0];
  588. while (*ip)
  589. if (strcmp(nm, *ip++) == 0)
  590. return ip - &index[0];
  591. /* arrived here, nm is not in the name list. */
  592. return 0;
  593. }
  594. #define BLANK(ch) ((ch == ' ') || (ch == '\t'))
  595. char *
  596. get_text(formals, length)
  597. char *formals[];
  598. int *length;
  599. {
  600. /* get_text() copies the replacement text of a macro
  601. definition with zero, one or more parameters, thereby
  602. substituting each formal parameter by a special character
  603. (non-ascii: 0200 & (order-number in the formal parameter
  604. list)) in order to substitute this character later by the
  605. actual parameter. The replacement text is copied into
  606. itself because the copied text will contain fewer or the
  607. same amount of characters. The length of the replacement
  608. text is returned.
  609. Implementation:
  610. finite automaton : we are interested in
  611. 1- white space, sequences must be mapped onto 1 single
  612. blank.
  613. 2- identifiers, since they might be replaced by some
  614. actual parameter.
  615. 3- strings and character constants, since replacing
  616. variables within them is illegal, and white-space is
  617. significant.
  618. 4- comment, same as for 1
  619. Other tokens will not be seen as such.
  620. */
  621. register int c;
  622. struct repl repls;
  623. register struct repl *repl = &repls;
  624. int blank = 0;
  625. c = GetChar();
  626. repl->r_ptr = repl->r_text = Malloc((unsigned)(repl->r_size = ITEXTSIZE));
  627. *repl->r_ptr = '\0';
  628. while ((c != EOI) && (class(c) != STNL)) {
  629. if (BLANK(c)) {
  630. blank++;
  631. c = GetChar();
  632. continue;
  633. }
  634. if (c == '\'' || c == '"') {
  635. register int delim = c;
  636. if (blank) {
  637. blank = 0;
  638. add2repl(repl, ' ');
  639. }
  640. do {
  641. add2repl(repl, c);
  642. if (c == '\\') add2repl(repl, GetChar());
  643. c = GetChar();
  644. } while (c != delim && c != EOI && class(c) != STNL);
  645. if (c != delim) {
  646. strict("unclosed opening %c", delim);
  647. break;
  648. }
  649. add2repl(repl, c);
  650. c = GetChar();
  651. } else if (c == '/') {
  652. c = GetChar();
  653. if (c == '*') {
  654. skipcomment();
  655. blank++;
  656. c = GetChar();
  657. continue;
  658. }
  659. if (blank) {
  660. blank = 0;
  661. add2repl(repl, ' ');
  662. }
  663. add2repl(repl, '/');
  664. } else if (formals
  665. && (class(c) == STIDF || class(c) == STELL)) {
  666. char id_buf[IDFSIZE + 1];
  667. register char *idp = id_buf;
  668. int n;
  669. /* read identifier: it may be a formal parameter */
  670. *idp++ = c;
  671. do {
  672. c = GetChar();
  673. if (idp <= &id_buf[IDFSIZE])
  674. *idp++ = c;
  675. } while (in_idf(c));
  676. *--idp = '\0';
  677. if (blank) {
  678. blank = 0;
  679. add2repl(repl, ' ');
  680. }
  681. /* construct the formal parameter mark or identifier */
  682. if (n = find_name(id_buf, formals))
  683. add2repl(repl, FORMALP | (char) n);
  684. else {
  685. idp = id_buf;
  686. while (*idp) add2repl(repl, *idp++);
  687. }
  688. } else if (class(c) == STNUM) {
  689. if (blank) {
  690. blank = 0;
  691. add2repl(repl, ' ');
  692. }
  693. add2repl(repl, c);
  694. if (c == '.') {
  695. c = GetChar();
  696. if (class(c) != STNUM) {
  697. continue;
  698. }
  699. add2repl(repl, c);
  700. }
  701. c = GetChar();
  702. while(in_idf(c) || c == '.') {
  703. add2repl(repl, c);
  704. if((c = GetChar()) == 'e' || c == 'E') {
  705. add2repl(repl, c);
  706. c = GetChar();
  707. if (c == '+' || c == '-') {
  708. add2repl(repl, c);
  709. c = GetChar();
  710. }
  711. }
  712. }
  713. } else {
  714. if (blank) {
  715. blank = 0;
  716. add2repl(repl, ' ');
  717. }
  718. add2repl(repl, c);
  719. c = GetChar();
  720. }
  721. }
  722. *length = repl->r_ptr - repl->r_text;
  723. return Realloc(repl->r_text, (unsigned)(repl->r_ptr - repl->r_text +1));
  724. }
  725. /* macroeq() decides whether two macro replacement texts are
  726. identical. This version compares the texts, which occur
  727. as strings, without taking care of the leading and trailing
  728. blanks (spaces and tabs).
  729. */
  730. macroeq(s, t)
  731. register char *s, *t;
  732. {
  733. /* skip leading spaces */
  734. while (BLANK(*s)) s++;
  735. while (BLANK(*t)) t++;
  736. /* first non-blank encountered in both strings */
  737. /* The actual comparison loop: */
  738. while (*s && *s == *t)
  739. s++, t++;
  740. /* two cases are possible when arrived here: */
  741. if (*s == '\0') { /* *s == '\0' */
  742. while (BLANK(*t)) t++;
  743. return *t == '\0';
  744. }
  745. else { /* *s != *t */
  746. while (BLANK(*s)) s++;
  747. while (BLANK(*t)) t++;
  748. return (*s == '\0') && (*t == '\0');
  749. }
  750. }
  751. do_line(l)
  752. unsigned int l;
  753. {
  754. struct token tk;
  755. int t = GetToken(&tk);
  756. if (t != EOF) SkipToNewLine();
  757. LineNumber = l; /* the number of the next input line */
  758. if (t == STRING) /* is there a filespecifier? */
  759. FileName = tk.tk_str;
  760. }