%{ /* * unpar.l: substitute indentation for parenthesization. * Version 0.1 * (unpar recognizes some \tree definitions as correct which tree * rejects.) * -- Greg Lee, lee@uhccux.uhcc.hawaii.edu, 6/24/90 */ #define TRUE 1 #define FALSE 0 int tex_opt = FALSE; int level = 0; int havename = 0; int wait = 0; int i; %} %s T X C %% ^".tr" { printf("\\tree"); havename = 1; BEGIN(T); } \\tree[ \t]*(-([tuvLTOIFER]+|[bg][0-9]+)[ \t]*)* { ECHO; havename = 1; if (tex_opt) BEGIN(X); else BEGIN(T); } ^[ \t]+ ; [ \t]+$ ; \n ; \\\( { havename = 1; ECHO; } [^ \t\n\(\)]/\( { havename = 1; ECHO; putchar(' '); } "("([^\)\(]|\\\)|\\\()+"("([^\)\(]|\\\)|\\\()+")"([^\)\(]|\\\)|\\\()*")" { wait = 2; REJECT; } "("[ \t\n]* { level++; if (wait == 1) printf(" - "); else { if (!havename) printf("\\Z\n"); else putchar('\n'); indent(); } havename = 0; if (wait) wait--; } ")"[^\)\(]+ { if (level == 1) {REJECT;} else level--; } ")" { level--; if (!level) { printf("\n"); BEGIN(0); } } \$_[0-9ijkxyz]\$ { havename = 1; printf("[%c]", yytext[2]); } \$\\overline\{\\rm\ [NAVP]\}\$ { havename = 1; printf(" %c'", yytext[15]); } \\[%\(\)] { havename = 1; ECHO; } % { BEGIN(C); } \n { if (tex_opt) BEGIN(X); else BEGIN(T); } . ; . { havename = 1; ECHO; } %% indent() { int i; for (i = 0; i < 2*(level-1); i++) putchar(' '); } extern char *optarg; /* from getopt */ extern int optind; main(argc, argv) int argc; char *argv[]; { int c; char *progname = NULL, *basename(); progname = basename (argv[0]); while ((c = getopt (argc, argv, "ht")) != EOF) switch (c) { case 't': tex_opt = TRUE; break; case 'h': default: fprintf(stderr, "Usage: %s [options] [files]\n", progname); fprintf(stderr, "options = -t\t(remove TeX code)\n"); fprintf(stderr, " -h\t(print this information)\n"); exit(1); } if (optind >= argc) { (void) yylex (); } else for (; (optind < argc); optind++) { if (yyin == NULL) yyin = stdin; if (freopen (argv[optind], "r", stdin) != NULL) { #ifdef FLEX_SCANNER /* to get flex to look at > 1 file */ yy_init = 1; #endif (void) yylex (); } else { (void) fprintf (stderr, "Couldn't open file: %s\n", argv[optind]); exit (1); } } } char *basename (s) char *s; { char *p, *strrchr(); if (p = strrchr(s, '/')) return(++p); else return(s); }