/* This is the lexical analyser - it returns tokens to the parsers.
   This is used by both parsers - one for the build-time config files
   and one for the run-time config files. Note the included file "parse.h"
   is a symlink to the relevant header file. */

%{
#include <string.h>
#include <stdlib.h>
#include <stdio.h>

/*#define YYSTYPE char * - YYSTYPE is defined in zparse.tab.h */
#include "zparse.tab.h"

/* forward declarations for std functions not picked up. */
/*int fileno(FILE *);*/
/*char *strdup(char *);*/

int lineno=1;
%}

%option noyywrap

COMMENT  \#.*(\n|\r)

%x  STRINGCOND
%%
	char *string;
	int string_len;

{COMMENT}		lineno++;/*yylval.string=yytext;*/yyleng=0;
,			return (',');
:			return (':');
\_			return ('_');
\[GSDL[0-9]+\.[0-9]+\] yylval.string=yytext;return(GSDLVERSION);
\[General\]		return (GENERAL_SECTION);
\[Search\ [fF]ields\]	return (SEARCH_SECTION);
\[Browse\ [fF]ields\]	return (BROWSE_SECTION);
\[Macros\]		return (MACROS_SECTION);
maintainer		return (MAINTAINER);
Languages		return(LANGUAGES);
About			return(ABOUT);
Browse			return(BROWSE);
Date[lL]ist		return(DATELIST);
Document[aA]rrows[bB]ottom return(DOCUMENTARROWSBOTTOM);
Document[bB]uttons	return(DOCUMENTBUTTONS);
Document[hH]eader	return(DOCUMENTHEADER);
Document[iI]mages	return(DOCUMENTIMAGES);
Document[tT]ext		return(DOCUMENTTEXT);
Icon[lL]ink		return(ICONLINK);
List			return(LIST);
Format			return(FORMAT);
Name			return(NAME);
Search[tT]ext		return(SEARCHTEXT);
Section[lL]ist		return(SECTIONLIST);
Sorted[lL]ist		return(SORTEDLIST);
Sorted[sS]ection[lL]ist	return(SORTEDSECTIONLIST);
Text[lL]ink		return(TEXTLINK);
Type			return(TYPE);
public			return (PUBLIC);
true			return (TRUE);
false			return (FALSE);
^document		return (DOCUMENT);
^section		return (SECTION);
[iI]con			return (ICON);
[sS]mall[iI]con		return (SMALLICON);
\"			{string=NULL;BEGIN(STRINGCOND);}
<STRINGCOND>{
  ([^\"\\\n])*		{/* append this to our current string EXC NEWLINE */
			if (string==NULL) string_len=0; else
			string_len=strlen(string);
			string=realloc(string,string_len+strlen(yytext)+1);
			/* +1 is for trailing \0 */
			strcpy(string+string_len,yytext);
			}
  ([^\"\\])*\n		{/* append this to our current string - INC NEWLINE */
			lineno++;
			if (string==NULL) string_len=0; else
			string_len=strlen(string);
			string=realloc(string,string_len+strlen(yytext)+1);
			/* +1 is for trailing \0 */
			strcpy(string+string_len,yytext);
			}
  "\\"\"		|
  \"\"		{       /*replace quoted quote with one quote*/
			string_len=strlen(string);
			string=realloc(string,string_len+2);
			string[string_len]='\"';
			string[string_len+1]='\0';
			}
  \"		{
			BEGIN(INITIAL);
			yylval.string=string;
			return(STRING);
			  /* note that the string may have long bits of 
			     whitespace in it that we could remove. */
			}
}
[[:alnum:]@\.-]+	yylval.string=strdup(yytext);return (DATA);
(" "|\t)		;
(\n|\r)			lineno++;
%%
/******** deleted rules: *******
en			return(EN);
fr			return(FR);
mi			return(MI);
zh			return(ZH);
de			return(DE);
***************/




