Blame tests/rescan_r.direct.l

Packit f00812
/*
Packit f00812
 * This file is part of flex.
Packit f00812
 *
Packit f00812
 * Redistribution and use in source and binary forms, with or without
Packit f00812
 * modification, are permitted provided that the following conditions
Packit f00812
 * are met:
Packit f00812
 *
Packit f00812
 * 1. Redistributions of source code must retain the above copyright
Packit f00812
 *    notice, this list of conditions and the following disclaimer.
Packit f00812
 * 2. Redistributions in binary form must reproduce the above copyright
Packit f00812
 *    notice, this list of conditions and the following disclaimer in the
Packit f00812
 *    documentation and/or other materials provided with the distribution.
Packit f00812
 *
Packit f00812
 * Neither the name of the University nor the names of its contributors
Packit f00812
 * may be used to endorse or promote products derived from this software
Packit f00812
 * without specific prior written permission.
Packit f00812
 *
Packit f00812
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
Packit f00812
 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
Packit f00812
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
Packit f00812
 * PURPOSE.
Packit f00812
 */
Packit f00812
Packit f00812
%{
Packit f00812
/* A template scanner file to build "scanner.c". */
Packit f00812
#include <stdio.h>
Packit f00812
#include <stdlib.h>
Packit f00812
%}
Packit f00812
Packit f00812
%option 8bit prefix="test"
Packit f00812
%option nounput nomain noyywrap noinput reentrant
Packit f00812
%option warn stack never-interactive
Packit f00812
%x STATE_1
Packit f00812
Packit f00812
%%
Packit f00812
Packit f00812
<INITIAL>{
Packit f00812
0              yy_push_state (STATE_1, yyscanner);
Packit f00812
.|\n           return 1;
Packit f00812
}
Packit f00812
<STATE_1>{
Packit f00812
1              yy_pop_state(yyscanner);
Packit f00812
.|\n           return yy_top_state(yyscanner) + 1;
Packit f00812
}
Packit f00812
Packit f00812
%%
Packit f00812
Packit f00812
int
Packit f00812
main (int argc, char* const argv[])
Packit f00812
{
Packit f00812
    FILE* fp;
Packit f00812
    int i;
Packit f00812
    yyscan_t  yyscanner;
Packit f00812
Packit f00812
    (void)argc;
Packit f00812
Packit f00812
    if ((fp = fopen(argv[1],"r")) == NULL){
Packit f00812
        perror("Failed to open input file.");
Packit f00812
        return 1;
Packit f00812
    }
Packit f00812
Packit f00812
    printf("Test 1: Reusing same scanner.\n");
Packit f00812
    yylex_init( &yyscanner );
Packit f00812
    yyset_out ( stdout, yyscanner);
Packit f00812
Packit f00812
    for (i=0; i <  4; ++i){
Packit f00812
Packit f00812
        rewind(fp);
Packit f00812
        yyset_in  ( fp, yyscanner);
Packit f00812
Packit f00812
        while( yylex(yyscanner) )
Packit f00812
            ;
Packit f00812
    }
Packit f00812
    yylex_destroy( yyscanner );
Packit f00812
    printf("Test 1 OK\n\n");
Packit f00812
Packit f00812
    printf("Test 2: Rescanning with new scanner each time.\n");
Packit f00812
Packit f00812
    memset(&yyscanner,0,sizeof(yyscanner)); // Just to be clean about it.
Packit f00812
Packit f00812
    for (i=0; i < 4; ++i){
Packit f00812
        yyscan_t  s;
Packit f00812
        yylex_init( &s );
Packit f00812
        yyset_out ( stdout, s);
Packit f00812
        rewind(fp);
Packit f00812
        yyset_in  ( fp, s);
Packit f00812
Packit f00812
        while( yylex(s) )
Packit f00812
            ;
Packit f00812
        yylex_destroy( s );
Packit f00812
    }
Packit f00812
    printf("Test 2 OK\n\n");
Packit f00812
Packit f00812
Packit f00812
    printf("TEST RETURNING OK.\n");
Packit f00812
    return 0;
Packit f00812
}