%{
/************************************************************************
 *									*
 *			Copyright (c) 1982, Fred Fish			*
 *			    All Rights Reserved				*
 *									*
 *	This software and/or documentation is released for public	*
 *	distribution for personal, non-commercial use only.		*
 *	Limited rights to use, modify, and redistribute are hereby	*
 *	granted for non-commercial purposes, provided that all		*
 *	copyright notices remain intact and all changes are clearly	*
 *	documented.  The author makes no warranty of any kind with	*
 *	respect to this product and explicitly disclaims any implied	*
 *	warranties of merchantability or fitness for any particular	*
 *	purpose.							*
 *									*
 ************************************************************************
 */


/*
 *  FILE
 *
 *	dex.l   lex specification for documentation extraction utility
 *
 *  KEY WORDS
 *
 *	lex specification
 *	dex
 *
 *  SYNOPSIS
 *
 *	lex dex.l
 *	mv lex.yy.c dex.lo
 *
 *  DESCRIPTION
 *
 *	This file contains the lex specification for the "dex"
 *	documentation extraction utility.  It is used with the file
 *	"dex.y", which is the yacc specification, to generate the
 *	source file parser.
 *
 *  AUTHOR
 *
 *	Fred Fish
 *
 */
%}

cch	[*#;|]
ncch    [^*#;|]
blank	" "
tab	\t
white	({tab}|{blank})

%START DLINE

%%
%{
extern int debug;
%}

^{white}*{cch}{blank}{blank}+	{
			BEGIN DLINE;
			if (debug) {printf("yylex: HSTART \"%s\"\n",yytext);}
			return(HSTART);
		}

^{white}*{cch}{tab}	{
			BEGIN DLINE;
			if (debug) {printf("yylex: FSTART \"%s\"\n",yytext);}
			return(FSTART);
		}

^{white}*{cch}{tab}{tab}	{
			BEGIN DLINE;
			if (debug) {printf("yylex: UFSTART \"%s\"\n",yytext);}
			return(UFSTART);
		}

^{white}*{cch}[\t ]*$	{
			BEGIN 0;
			if (debug) {printf("yylex: BSTART \"%s\"\n",yytext);}
			return(BSTART);
		}

<DLINE>[^\n]*	{
			if (debug) {printf("yylex: TEXT \"%s\"\n",yytext);}
			return(TEXT);
		}

\n		{
			BEGIN 0;
			if (debug) {printf("yylex: NEWLINE \"%s\"\n",yytext);}
			return(NEWLINE);
		}
^{white}+$	{
			BEGIN 0;
			if (debug) {printf("yylex: JUNK1 \"%s\"\n",yytext);}
			return(JUNK);
		}
^{white}*[^*#;| \t\n][^\n]* {
			BEGIN 0;
			if (debug) {printf("yylex: JUNK2 \"%s\"\n",yytext);}
			return(JUNK);
		}
^{white}*{cch}[^ \t\n][^\n]* {
			BEGIN 0;
			if (debug) {printf("yylex: JUNK3 \"%s\"\n",yytext);}
			return(JUNK);
		}

[\001-\177]	{
			BEGIN 0;
			if (debug) {printf("yylex: JUNK4 \"%s\"\n",yytext);}
			return(JUNK);
		}

%%
extern FILE *infp;

#undef input			/* Make preprocessor forget macro */
input()
{
    char ch;

    ch = fgetc(infp);
    switch(ch) {
    case EOF:
	ch = NULL;
	break;
    case NULL:
	ch = '\n';
        break;
    }
    ch &= '\177';
    return(ch);
}

#undef unput			/* Make preprocessor forget macro */
unput(ch)
char ch;
{
    if (ch == NULL) {
	ch = EOF;
    }
    ungetc(ch,infp);
}
