- %option noyywrap
- %{
- #include <stdio.h>
- void showhelp(char* argv[]);
- void translated(const char* t);
- %}
- %%
- (([\t]+)|([ ]+))+ { translated(" "); }
- %%
- void showhelp(char* argv[])
- {
- printf("Usage %s [input_filename] [output_filename]\n",argv[0]);
- }
- void translated(const char* t)
- {
- fprintf(yyout,"%s",t);
- }
- int main(int argc,char* argv[])
- {
- FILE* inputfile;
- FILE* outputfile;
-
- if(argc != 3)
- {
- showhelp(argv);
- return 0;
- }
- inputfile = fopen(argv[1],"r");
- outputfile = fopen(argv[2],"w");
-
- if(inputfile && outputfile)
- {
- yyin = inputfile;
- yyout = outputfile;
- while(yylex());
- }
- else
- {
- printf("open file failed.\n");
- }
- return 0;
- }