Removed the non-LOCALE character code and the #ifdefs and simplified.
[mmh] / sbr / fmt_compile.c
1 /*
2 ** fmt_compile.c -- "compile" format strings for fmt_scan
3 **
4 ** This code is Copyright (c) 2002, by the authors of nmh.  See the
5 ** COPYRIGHT file in the root directory of the nmh distribution for
6 ** complete copyright information.
7 */
8
9 #include <h/mh.h>
10 #include <h/addrsbr.h>
11 #include <h/tws.h>
12 #include <h/fmt_scan.h>
13 #include <h/fmt_compile.h>
14
15 #ifdef TIME_WITH_SYS_TIME
16 # include <sys/time.h>
17 # include <time.h>
18 #else
19 # ifdef TM_IN_SYS_TIME
20 #  include <sys/time.h>
21 # else
22 #  include <time.h>
23 # endif
24 #endif
25
26 /*
27 ** hash table for deciding if a component is "interesting"
28 */
29 struct comp *wantcomp[128];
30
31 static struct format *formatvec;  /* array to hold formats */
32 static struct format *next_fp;    /* next free format slot */
33 static struct format *fp;         /* current format slot   */
34 static struct comp *cm;           /* most recent comp ref  */
35 static struct ftable *ftbl;       /* most recent func ref  */
36 static int ncomp;
37 static int infunction;            /* function nesting cnt  */
38
39 extern struct mailname fmt_mnull;
40
41 /* ftable->type (argument type) */
42 #define TF_COMP    0  /* component expected                 */
43 #define TF_NUM     1  /* number expected                    */
44 #define TF_STR     2  /* string expected                    */
45 #define TF_EXPR    3  /* component or func. expected        */
46 #define TF_NONE    4  /* no argument                        */
47 #define TF_MYBOX   5  /* special - get current user's mbox  */
48 #define TF_NOW     6  /* special - get current unix time    */
49 #define TF_EXPR_SV 7  /* like expr but save current str reg */
50 #define TF_NOP     8  /* like expr but no result            */
51
52 /* ftable->flags */
53 /*
54 ** NB that TFL_PUTS is also used to decide whether the test
55 ** in a "%<(function)..." should be a string or numeric one.
56 */
57 #define TFL_PUTS   1  /* implicit putstr if top level */
58 #define TFL_PUTN   2  /* implicit putnum if top level */
59
60 struct ftable {
61         char *name;  /* function name */
62         char type;   /* argument type */
63         char f_type; /* fmt type */
64         char extra;  /* arg. type dependent extra info */
65         char flags;
66 };
67
68 static struct ftable functable[] = {
69         { "nonzero",    TF_EXPR,  FT_V_NE,  FT_IF_V_NE,  0 },
70         { "zero",       TF_EXPR,  FT_V_EQ,  FT_IF_V_EQ,  0 },
71         { "eq",         TF_NUM, FT_V_EQ, FT_IF_V_EQ, 0 },
72         { "ne",         TF_NUM, FT_V_NE, FT_IF_V_NE, 0 },
73         { "gt",         TF_NUM, FT_V_GT, FT_IF_V_GT, 0 },
74         { "null",       TF_EXPR, FT_S_NULL, FT_IF_S_NULL, 0 },
75         { "nonnull",    TF_EXPR, FT_S_NONNULL, FT_IF_S, 0 },
76         { "match",      TF_STR, FT_V_MATCH, FT_IF_MATCH, 0 },
77         { "amatch",     TF_STR, FT_V_AMATCH, FT_IF_AMATCH, 0 },
78
79         { "putstr",     TF_EXPR, FT_STR, 0, 0 },
80         { "putstrf",    TF_EXPR, FT_STRF, 0, 0 },
81         { "putnum",     TF_EXPR, FT_NUM, 0, 0 },
82         { "putnumf",    TF_EXPR, FT_NUMF, 0, 0 },
83         { "putaddr",    TF_STR, FT_PUTADDR, 0, 0 },
84         { "void",       TF_NOP, 0, 0, 0 },
85
86         { "comp",       TF_COMP, FT_LS_COMP, 0, TFL_PUTS },
87         { "lit",        TF_STR, FT_LS_LIT, 0, TFL_PUTS },
88         { "getenv",     TF_STR, FT_LS_GETENV, 0, TFL_PUTS },
89         { "profile",    TF_STR, FT_LS_CFIND, 0, TFL_PUTS },
90         { "decodecomp", TF_COMP, FT_LS_DECODECOMP,  0, TFL_PUTS },
91         { "decode",     TF_EXPR, FT_LS_DECODE, 0, TFL_PUTS },
92         { "trim",       TF_EXPR, FT_LS_TRIM, 0, 0 },
93         { "compval",    TF_COMP, FT_LV_COMP, 0, TFL_PUTN },
94         { "compflag",   TF_COMP, FT_LV_COMPFLAG, 0, TFL_PUTN },
95         { "num",        TF_NUM, FT_LV_LIT, 0, TFL_PUTN },
96         { "msg",        TF_NONE, FT_LV_DAT, 0, TFL_PUTN },
97         { "cur",        TF_NONE, FT_LV_DAT, 1, TFL_PUTN },
98         { "size",       TF_NONE, FT_LV_DAT, 2, TFL_PUTN },
99         { "width",      TF_NONE, FT_LV_DAT, 3, TFL_PUTN },
100         { "unseen",     TF_NONE, FT_LV_DAT, 4, TFL_PUTN },
101         { "dat",        TF_NUM, FT_LV_DAT, 0, TFL_PUTN },
102         { "strlen",     TF_NONE, FT_LV_STRLEN, 0, TFL_PUTN },
103         { "me",         TF_MYBOX, FT_LS_LIT, 0, TFL_PUTS },
104         { "plus",       TF_NUM, FT_LV_PLUS_L, 0, TFL_PUTN },
105         { "minus",      TF_NUM, FT_LV_MINUS_L, 0, TFL_PUTN },
106         { "divide",     TF_NUM, FT_LV_DIVIDE_L, 0, TFL_PUTN },
107         { "modulo",     TF_NUM, FT_LV_MODULO_L, 0, TFL_PUTN },
108         { "charleft",   TF_NONE, FT_LV_CHAR_LEFT,  0, TFL_PUTN },
109         { "timenow",    TF_NOW, FT_LV_LIT, 0, TFL_PUTN },
110
111         { "month",      TF_COMP, FT_LS_MONTH, FT_PARSEDATE, TFL_PUTS },
112         { "lmonth",     TF_COMP, FT_LS_LMONTH, FT_PARSEDATE, TFL_PUTS },
113         { "tzone",      TF_COMP, FT_LS_ZONE, FT_PARSEDATE, TFL_PUTS },
114         { "day",        TF_COMP, FT_LS_DAY, FT_PARSEDATE, TFL_PUTS },
115         { "weekday",    TF_COMP, FT_LS_WEEKDAY, FT_PARSEDATE, TFL_PUTS },
116         { "tws",        TF_COMP, FT_LS_822DATE, FT_PARSEDATE, TFL_PUTS },
117         { "sec",        TF_COMP, FT_LV_SEC, FT_PARSEDATE, TFL_PUTN },
118         { "min",        TF_COMP, FT_LV_MIN, FT_PARSEDATE, TFL_PUTN },
119         { "hour",       TF_COMP, FT_LV_HOUR, FT_PARSEDATE, TFL_PUTN },
120         { "mday",       TF_COMP, FT_LV_MDAY, FT_PARSEDATE, TFL_PUTN },
121         { "mon",        TF_COMP, FT_LV_MON, FT_PARSEDATE, TFL_PUTN },
122         { "year",       TF_COMP, FT_LV_YEAR, FT_PARSEDATE, TFL_PUTN },
123         { "yday",       TF_COMP, FT_LV_YDAY, FT_PARSEDATE, TFL_PUTN },
124         { "wday",       TF_COMP, FT_LV_WDAY, FT_PARSEDATE, TFL_PUTN },
125         { "zone",       TF_COMP, FT_LV_ZONE, FT_PARSEDATE, TFL_PUTN },
126         { "clock",      TF_COMP, FT_LV_CLOCK, FT_PARSEDATE, TFL_PUTN },
127         { "rclock",     TF_COMP, FT_LV_RCLOCK, FT_PARSEDATE, TFL_PUTN },
128         { "sday",       TF_COMP, FT_LV_DAYF, FT_PARSEDATE, TFL_PUTN },
129         { "szone",      TF_COMP, FT_LV_ZONEF, FT_PARSEDATE, TFL_PUTN },
130         { "dst",        TF_COMP, FT_LV_DST, FT_PARSEDATE, TFL_PUTN },
131         { "pretty",     TF_COMP, FT_LS_PRETTY, FT_PARSEDATE, TFL_PUTS },
132         { "nodate",     TF_COMP, FT_LV_COMPFLAG, FT_PARSEDATE, TFL_PUTN },
133         { "date2local", TF_COMP, FT_LOCALDATE, FT_PARSEDATE, 0 },
134         { "date2gmt",   TF_COMP, FT_GMTDATE, FT_PARSEDATE, 0 },
135
136         { "pers",       TF_COMP, FT_LS_PERS, FT_PARSEADDR, TFL_PUTS },
137         { "mbox",       TF_COMP, FT_LS_MBOX, FT_PARSEADDR, TFL_PUTS },
138         { "host",       TF_COMP, FT_LS_HOST, FT_PARSEADDR, TFL_PUTS },
139         { "path",       TF_COMP, FT_LS_PATH, FT_PARSEADDR, TFL_PUTS },
140         { "gname",      TF_COMP, FT_LS_GNAME, FT_PARSEADDR, TFL_PUTS },
141         { "note",       TF_COMP, FT_LS_NOTE, FT_PARSEADDR, TFL_PUTS },
142         { "addr",       TF_COMP, FT_LS_ADDR, FT_PARSEADDR, TFL_PUTS },
143         { "proper",     TF_COMP, FT_LS_822ADDR, FT_PARSEADDR, TFL_PUTS },
144         { "type",       TF_COMP, FT_LV_HOSTTYPE, FT_PARSEADDR, TFL_PUTN },
145         { "ingrp",      TF_COMP, FT_LV_INGRPF, FT_PARSEADDR, TFL_PUTN },
146         { "nohost",     TF_COMP, FT_LV_NOHOSTF, FT_PARSEADDR, TFL_PUTN },
147         { "formataddr", TF_EXPR_SV, FT_FORMATADDR, FT_FORMATADDR, 0 },
148         { "friendly",   TF_COMP,    FT_LS_FRIENDLY, FT_PARSEADDR, TFL_PUTS },
149
150         { "mymbox",     TF_COMP,    FT_LV_COMPFLAG, FT_MYMBOX, TFL_PUTN },
151         { "addtoseq",   TF_STR,     FT_ADDTOSEQ, 0, 0 },
152
153         { "unquote",    TF_EXPR,    FT_LS_UNQUOTE, 0, TFL_PUTS},
154
155         { NULL,         0,          0, 0, 0 }
156 };
157
158 /* Add new component to the hash table */
159 #define NEWCOMP(cm,name) do { \
160                 cm = ((struct comp *) calloc(1, sizeof (struct comp)));\
161                 cm->c_name = name;\
162                 ncomp++;\
163                 i = CHASH(name);\
164                 cm->c_next = wantcomp[i];\
165                 wantcomp[i] = cm; \
166         } while (0)
167
168 #define NEWFMT (next_fp++)
169 #define NEW(type,fill,wid) do {\
170                 fp=NEWFMT; fp->f_type=(type); fp->f_fill=(fill); fp->f_width=(wid); \
171         } while (0)
172
173 /* Add (possibly new) component to the hash table */
174 #define ADDC(name) do { \
175                 FINDCOMP(cm, name);\
176                 if (!cm) {\
177                         NEWCOMP(cm,name);\
178                 }\
179                 fp->f_comp = cm; \
180         } while (0)
181
182 #define LV(type, value)  do { NEW(type,0,0); fp->f_value = (value); } while (0)
183 #define LS(type, str)  do { NEW(type,0,0); fp->f_text = (str); } while (0)
184
185 #define PUTCOMP(comp)  do { NEW(FT_COMP,0,0); ADDC(comp); } while (0)
186 #define PUTLIT(str)  do { NEW(FT_LIT,0,0); fp->f_text = (str); } while (0)
187 #define PUTC(c)  do { NEW(FT_CHAR,0,0); fp->f_char = (c); } while (0)
188
189 static char *format_string;
190 static unsigned char *usr_fstring;  /* for CERROR */
191
192 #define CERROR(str) compile_error(str, cp)
193
194 /*
195 ** external prototypes
196 */
197 extern char *getusername(void);
198
199 /*
200 ** static prototypes
201 */
202 static struct ftable *lookup(char *);
203 static void compile_error(char *, char *);
204 static char *compile(char *);
205 static char *do_spec(char *);
206 static char *do_name(char *, int);
207 static char *do_func(char *);
208 static char *do_expr(char *, int);
209 static char *do_loop(char *);
210 static char *do_if(char *);
211
212
213 static struct ftable *
214 lookup(char *name)
215 {
216         register struct ftable *t = functable;
217         register char *nm;
218         register char c = *name;
219
220         while ((nm = t->name)) {
221                 if (*nm == c && strcmp(nm, name) == 0)
222                         return (ftbl = t);
223
224                 t++;
225         }
226         return (struct ftable *) 0;
227 }
228
229
230 static void
231 compile_error(char *str, char *cp)
232 {
233         int i, errpos, errctx;
234
235         errpos = cp - format_string;
236         errctx = errpos > 20 ? 20 : errpos;
237         usr_fstring[errpos] = '\0';
238
239         for (i = errpos-errctx; i < errpos; i++) {
240                 if (iscntrl(usr_fstring[i]))
241                         usr_fstring[i] = '_';
242         }
243
244         advise(NULL, "\"%s\": format compile error - %s",
245                    &usr_fstring[errpos-errctx], str);
246         adios(NULL, "%*s", errctx+1, "^");
247 }
248
249 /*
250 ** Compile format string "fstring" into format list "fmt".
251 ** Return the number of header components found in the format
252 ** string.
253 */
254
255 int
256 fmt_compile(char *fstring, struct format **fmt)
257 {
258         register char *cp;
259         int i;
260
261         if (format_string)
262                 free(format_string);
263         format_string = getcpy(fstring);
264         usr_fstring = fstring;
265
266         /* init the component hash table. */
267         for (i = 0; i < sizeof(wantcomp)/sizeof(wantcomp[0]); i++)
268                 wantcomp[i] = 0;
269
270         memset((char *) &fmt_mnull, 0, sizeof(fmt_mnull));
271
272         /*
273         ** it takes at least 4 char to generate one format so we
274         ** allocate a worst-case format array using 1/4 the length
275         ** of the format string.  We actually need twice this much
276         ** to handle both pre-processing (e.g., address parsing) and
277         ** normal processing.
278         */
279         i = strlen(fstring)/2 + 1;
280         if (i == 1)
281                 i++;
282         next_fp = formatvec = (struct format *)calloc((size_t) i,
283                 sizeof(struct format));
284         if (next_fp == NULL)
285                 adios(NULL, "unable to allocate format storage");
286
287         ncomp = 0;
288         infunction = 0;
289
290         cp = compile(format_string);
291         if (*cp) {
292                 CERROR("extra '%>', '%|' or '%?'");
293         }
294         LV(FT_DONE, 0);  /* really done */
295         *fmt = formatvec;
296
297         return (ncomp);
298 }
299
300 static char *
301 compile(char *sp)
302 {
303         register char *cp = sp;
304         register int  c;
305
306         for (;;) {
307                 sp = cp;
308                 while ((c = *cp) && c != '%')
309                         cp++;
310                 *cp = 0;
311                 switch (cp-sp) {
312                 case 0:
313                         break;
314                 case 1:
315                         PUTC(*sp);
316                         break;
317                 default:
318                         PUTLIT(sp);
319                         break;
320                 }
321                 if (c == 0)
322                         return (cp);
323
324                 switch (c = *++cp) {
325                 case '%':
326                         PUTC(*cp);
327                         cp++;
328                         break;
329
330                 case '|':
331                 case '>':
332                 case '?':
333                 case ']':
334                         return (cp);
335
336                 case '<':
337                         cp = do_if(++cp);
338                         break;
339
340                 case '[':  /* ] */
341                         cp = do_loop(++cp);
342                         break;
343
344                 case ';':  /* comment line */
345                         cp++;
346                         while ((c = *cp++) && c != '\n')
347                                 continue;
348                         break;
349
350                 default:
351                         cp = do_spec(cp);
352                         break;
353                 }
354         }
355 }
356
357
358 static char *
359 do_spec(char *sp)
360 {
361         register char *cp = sp;
362         register int c;
363 #ifndef lint
364         register int ljust = 0;
365 #endif /* not lint */
366         register int wid = 0;
367         register char fill = ' ';
368
369         c = *cp++;
370         if (c == '-') {
371                 ljust++;
372                 c = *cp++;
373         }
374         if (c == '0') {
375                 fill = c;
376                 c = *cp++;
377         }
378         while (isdigit(c)) {
379                 wid = wid*10 + (c - '0');
380                 c = *cp++;
381         }
382         if (c == '{') {
383                 cp = do_name(cp, 0);
384                 if (! infunction)
385                         fp->f_type = wid? FT_COMPF : FT_COMP;
386         } else if (c == '(') {
387                 cp = do_func(cp);
388                 if (! infunction) {
389                         if (ftbl->flags & TFL_PUTS) {
390                                 LV( wid? FT_STRF : FT_STR, ftbl->extra);
391                         } else if (ftbl->flags & TFL_PUTN) {
392                                 LV( wid? FT_NUMF : FT_NUM, ftbl->extra);
393                         }
394                 }
395         } else {
396                 CERROR("component or function name expected");
397         }
398         if (ljust)
399                 wid = -wid;
400         fp->f_width = wid;
401         fp->f_fill = fill;
402
403         return (cp);
404 }
405
406 static char *
407 do_name(char *sp, int preprocess)
408 {
409         register char *cp = sp;
410         register int c;
411         register int i;
412         static int primed = 0;
413
414         while (isalnum(c = *cp++) || c == '-' || c == '_')
415                 ;
416         if (c != '}') {
417                 CERROR("'}' expected");
418         }
419         cp[-1] = '\0';
420         PUTCOMP(sp);
421         switch (preprocess) {
422
423         case FT_PARSEDATE:
424                 if (cm->c_type & CT_ADDR) {
425                         CERROR("component used as both date and address");
426                 }
427                 cm->c_tws = (struct tws *)
428                         calloc((size_t) 1, sizeof(*cm->c_tws));
429                 fp->f_type = preprocess;
430                 PUTCOMP(sp);
431                 cm->c_type |= CT_DATE;
432                 break;
433
434         case FT_MYMBOX:
435                 if (!primed) {
436                         ismymbox((struct mailname *) 0);
437                         primed++;
438                 }
439                 /* fall through */
440         case FT_PARSEADDR:
441                 if (cm->c_type & CT_DATE) {
442                         CERROR("component used as both date and address");
443                 }
444                 cm->c_mn = &fmt_mnull;
445                 fp->f_type = preprocess;
446                 PUTCOMP(sp);
447                 cm->c_type |= CT_ADDR;
448                 break;
449
450         case FT_FORMATADDR:
451                 if (cm->c_type & CT_DATE) {
452                         CERROR("component used as both date and address");
453                 }
454                 cm->c_type |= CT_ADDR;
455                 break;
456         }
457         return (cp);
458 }
459
460 static char *
461 do_func(char *sp)
462 {
463         register char *cp = sp;
464         register int c;
465         register struct ftable *t;
466         register int n;
467         int mflag;  /* minus sign in NUM */
468
469         infunction++;
470
471         while (isalnum(c = *cp++))
472                 ;
473         if (c != '(' && c != '{' && c != ' ' && c != ')') {
474                 CERROR("'(', '{', ' ' or ')' expected");
475         }
476         cp[-1] = '\0';
477         if ((t = lookup(sp)) == 0) {
478                 CERROR("unknown function");
479         }
480         if (isspace(c))
481                 c = *cp++;
482
483         switch (t->type) {
484
485         case TF_COMP:
486                 if (c != '{') {
487                         CERROR("component name expected");
488                 }
489                 cp = do_name(cp, t->extra);
490                 fp->f_type = t->f_type;
491                 c = *cp++;
492                 break;
493
494         case TF_NUM:
495                 if ((mflag = (c == '-')))
496                         c = *cp++;
497                 n = 0;
498                 while (isdigit(c)) {
499                         n = n*10 + (c - '0');
500                         c = *cp++;
501                 }
502                 if (mflag)
503                         n = (-n);
504                 LV(t->f_type,n);
505                 break;
506
507         case TF_STR:
508                 sp = cp - 1;
509                 while (c && c != ')')
510                         c = *cp++;
511                 cp[-1] = '\0';
512                 LS(t->f_type,sp);
513                 break;
514
515         case TF_NONE:
516                 LV(t->f_type,t->extra);
517                 break;
518
519         case TF_MYBOX:
520                 LS(t->f_type, getusername());
521                 break;
522
523         case TF_NOW:
524                 LV(t->f_type, time((time_t *) 0));
525                 break;
526
527         case TF_EXPR_SV:
528                 LV(FT_SAVESTR, 0);
529                 /* fall through */
530         case TF_EXPR:
531                 *--cp = c;
532                 cp = do_expr(cp, t->extra);
533                 LV(t->f_type, 0);
534                 c = *cp++;
535                 ftbl = t;
536                 break;
537
538         case TF_NOP:
539                 *--cp = c;
540                 cp = do_expr(cp, t->extra);
541                 c = *cp++;
542                 ftbl = t;
543                 break;
544         }
545         if (c != ')') {
546                 CERROR("')' expected");
547         }
548         --infunction;
549         return (cp);
550 }
551
552 static char *
553 do_expr(char *sp, int preprocess)
554 {
555         register char *cp = sp;
556         register int  c;
557
558         if ((c = *cp++) == '{') {
559                 cp = do_name(cp, preprocess);
560                 fp->f_type = FT_LS_COMP;
561         } else if (c == '(') {
562                 cp = do_func(cp);
563         } else if (c == ')') {
564                 return (--cp);
565         } else if (c == '%' && *cp == '<') {
566                 cp = do_if(cp+1);
567         } else {
568                 CERROR("'(', '{', '%<' or ')' expected");
569         }
570         return (cp);
571 }
572
573 static char *
574 do_loop(char *sp)
575 {
576         register char *cp = sp;
577         struct format *floop;
578
579         floop = next_fp;
580         cp = compile(cp);
581         if (*cp++ != ']')
582                 CERROR("']' expected");
583
584         LV(FT_DONE, 1);  /* not yet done */
585         LV(FT_GOTO, 0);
586         fp->f_skip = floop - fp;  /* skip backwards */
587
588         return cp;
589 }
590
591 static char *
592 do_if(char *sp)
593 {
594         register char *cp = sp;
595         register struct format *fexpr, *fif = (struct format *)NULL;
596         register int c = '<';
597
598         for (;;) {
599                 if (c == '<') {  /* doing an IF */
600                         if ((c = *cp++) == '{') /*}*/{
601                                 cp = do_name(cp, 0);
602                                 fp->f_type = FT_LS_COMP;
603                                 LV(FT_IF_S, 0);
604                         } else if (c == '(') {
605                                 cp = do_func(cp);
606                                 /* see if we can merge the load and the "if" */
607                                 if (ftbl->f_type >= IF_FUNCS)
608                                         fp->f_type = ftbl->extra;
609                                 else {
610                                         /*
611                                         ** Put out a string test or a value
612                                         ** test depending on what this
613                                         ** function 's return type is.
614                                         */
615                                         if (ftbl->flags & TFL_PUTS) {
616                                                 LV(FT_IF_S, 0);
617                                         } else {
618                                                 LV(FT_IF_V_NE, 0);
619                                         }
620                                 }
621                         } else {
622                                 CERROR("'(' or '{' expected");  /*}*/
623                         }
624                 }
625
626                 fexpr = fp;  /* loc of [ELS]IF */
627                 cp = compile(cp);  /* compile IF TRUE stmts */
628                 if (fif)
629                         fif->f_skip = next_fp - fif;
630
631                 if ((c = *cp++) == '|') {  /* the last ELSE */
632                         LV(FT_GOTO, 0);
633                         fif = fp;  /* loc of GOTO */
634                         fexpr->f_skip = next_fp - fexpr;
635
636                         fexpr = (struct format *)NULL;/* no extra ENDIF */
637
638                         cp = compile(cp);  /* compile ELSE stmts */
639                         fif->f_skip = next_fp - fif;
640                         c = *cp++;
641                 } else if (c == '?') {  /* another ELSIF */
642                         LV(FT_GOTO, 0);
643                         fif = fp;  /* loc of GOTO */
644                         fexpr->f_skip = next_fp - fexpr;
645
646                         c = '<';  /* impersonate an IF */
647                         continue;
648                 }
649                 break;
650         }
651
652         if (c != '>') {
653                 CERROR("'>' expected.");
654         }
655
656         if (fexpr)  /* IF ... [ELSIF ...] ENDIF */
657                 fexpr->f_skip = next_fp - fexpr;
658
659         return (cp);
660 }