|
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 |
f * 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 scanner file to build "scanner.c".
|
|
Packit |
f00812 |
Input language is any text.
|
|
Packit |
f00812 |
"#include <filename>" causes a buffer switch.
|
|
Packit |
f00812 |
*/
|
|
Packit |
f00812 |
#include <stdio.h>
|
|
Packit |
f00812 |
#include <stdlib.h>
|
|
Packit |
f00812 |
#include "config.h"
|
|
Packit |
f00812 |
%}
|
|
Packit |
f00812 |
|
|
Packit |
f00812 |
%option 8bit prefix="test"
|
|
Packit |
f00812 |
%option nounput nomain noyywrap noinput
|
|
Packit |
f00812 |
%option warn
|
|
Packit |
f00812 |
|
|
Packit |
f00812 |
%x GET_FILENAME
|
|
Packit |
f00812 |
%{
|
|
Packit |
f00812 |
|
|
Packit |
f00812 |
#define MAX_INCLUDE_DEPTH 10
|
|
Packit |
f00812 |
YY_BUFFER_STATE include_stack[MAX_INCLUDE_DEPTH];
|
|
Packit |
f00812 |
int include_stack_ptr = 0;
|
|
Packit |
f00812 |
%}
|
|
Packit |
f00812 |
%%
|
|
Packit |
f00812 |
|
|
Packit |
f00812 |
<INITIAL>{
|
|
Packit |
f00812 |
^"#include"[[:blank:]]+"<" { BEGIN(GET_FILENAME); }
|
|
Packit |
f00812 |
.|\n { ECHO; }
|
|
Packit |
f00812 |
}
|
|
Packit |
f00812 |
|
|
Packit |
f00812 |
<GET_FILENAME>{
|
|
Packit |
f00812 |
[[:alnum:]_.-]+> {
|
|
Packit |
f00812 |
/* recurse */
|
|
Packit |
f00812 |
yytext[yyleng-1]='\0';
|
|
Packit |
f00812 |
include_stack[include_stack_ptr++] = YY_CURRENT_BUFFER;
|
|
Packit |
f00812 |
if((yyin=fopen(yytext,"r"))==NULL) {
|
|
Packit |
f00812 |
fprintf(stderr,"*** Error: Could not open include file \"%s\".\n",yytext);
|
|
Packit |
f00812 |
yyterminate();
|
|
Packit |
f00812 |
}
|
|
Packit |
f00812 |
yy_switch_to_buffer( yy_create_buffer( yyin, YY_BUF_SIZE ));
|
|
Packit |
f00812 |
BEGIN(0);
|
|
Packit |
f00812 |
}
|
|
Packit |
f00812 |
.|\n {
|
|
Packit |
f00812 |
fprintf(stderr,"Invalid input \"%s\".\n", yytext);
|
|
Packit |
f00812 |
yyterminate();
|
|
Packit |
f00812 |
}
|
|
Packit |
f00812 |
}
|
|
Packit |
f00812 |
|
|
Packit |
f00812 |
<<EOF>> {
|
|
Packit |
f00812 |
if ( --include_stack_ptr < 0 ) {
|
|
Packit |
f00812 |
yyterminate();
|
|
Packit |
f00812 |
}
|
|
Packit |
f00812 |
else {
|
|
Packit |
f00812 |
fclose(yyin);
|
|
Packit |
f00812 |
yy_delete_buffer( YY_CURRENT_BUFFER );
|
|
Packit |
f00812 |
yy_switch_to_buffer( include_stack[include_stack_ptr] );
|
|
Packit |
f00812 |
}
|
|
Packit |
f00812 |
}
|
|
Packit |
f00812 |
|
|
Packit |
f00812 |
%%
|
|
Packit |
f00812 |
|
|
Packit |
f00812 |
int main(int argc, char** argv);
|
|
Packit |
f00812 |
|
|
Packit |
f00812 |
int
|
|
Packit |
f00812 |
main ( int argc, char** argv )
|
|
Packit |
f00812 |
{
|
|
Packit |
f00812 |
FILE * fp;
|
|
Packit |
f00812 |
if( argc != 2 ) {
|
|
Packit |
f00812 |
fprintf(stderr,"*** Error: Must specify one filename.\n");
|
|
Packit |
f00812 |
exit(-1);
|
|
Packit |
f00812 |
}
|
|
Packit |
f00812 |
if((fp=fopen(argv[1],"r"))==NULL) {
|
|
Packit |
f00812 |
fprintf(stderr,"*** Error: fopen(%s) failed.\n",argv[1]);
|
|
Packit |
f00812 |
exit(-1);
|
|
Packit |
f00812 |
}
|
|
Packit |
f00812 |
yyin = fp;
|
|
Packit |
f00812 |
yyout = stdout;
|
|
Packit |
f00812 |
yylex();
|
|
Packit |
f00812 |
printf("TEST RETURNING OK.\n");
|
|
Packit |
f00812 |
return 0;
|
|
Packit |
f00812 |
}
|