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