yywrap()

Matthias Andree matthias.andree at gmx.de
Mon Feb 24 18:20:59 CET 2003


Hi,

I've observed yywrap() a bit (for the master/slave approach), it can
only work if our EOF doesn't strike in the middle of a token.

Consider this "try.l" file code (note it will NOT terminate, be prepared
to kill it) -- to compile:

flex try.l
gcc -W -Wall -O -o try lex.yy.c

%{

#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define YY_INPUT(buf,result,max_size) result = yyinput(buf, max_size)

%}

%option align nounput noreject 8bit caseless debug

%%

[a-z][a-z]+			return 1;
.				return 2;

%%

int yyinput(char *buf, int max_size)
{
    static int i;
    int c;
    i = 1 - i;
    if (!max_size) return 0;
    if (i && (c = getchar()) != EOF) {
	*buf = c;
	fprintf(stderr, "> yyinput returning 1 %c\n", c);
	return 1;
    }
    fprintf(stderr, "> yyinput returning 0\n");
    return 0;
}

int yywrap(void) {
    fprintf(stderr, "# yywrap returning 0\n");
    return 0;
}

int main(void) {
    int c;
    while(c = yylex()) {
	printf("%d %d ", c, yyleng);
	fwrite(yytext, 1, yyleng, stdout);
	printf("\n");
    }
    return 0;
}

-- 
Matthias Andree




More information about the bogofilter-dev mailing list