/* * Copyright (C) 1999 - 2003 David Essex * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this software; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, * Boston, MA 02111-1307 USA */ %{ #undef yywrap #include #include #include "cobf2f.h" int i; unsigned long columnLen; unsigned long columnCount = 1; unsigned long lineCount = 1; char lineout[80]; void lineExpand(void) ; void tabExpand(void) ; //void lexError( char * msg ) ; %} eol [\n] tab [\t] blank [ ] Quote ['"] ws [ \n] %x INITAL FREE FIXED FIXED_7 FIXED_A FIXED_LC COMMENT %% if ( globalEnvPtr->format == 0 ) { /* free == 0, fixed == 1 */ if (globalEnvPtr->linemul != 0) { fprintf(yyout, "%06d", lineCount*globalEnvPtr->linemul); } else { fprintf(yyout, " "); } BEGIN( FREE ) ;} else if ( globalEnvPtr->format == 1) BEGIN( FIXED ) ; else { assert(1); } <*>{tab} { tabExpand(); } {eol} { lineCount++; columnCount=0; if (globalEnvPtr->linemul != 0) { fprintf(yyout, "\n%06d", lineCount*globalEnvPtr->linemul); } else { fprintf(yyout, "\n "); } } {Quote}{ws}+"&"{ws}+{Quote} { /*remove for concatination */; } ^"*".*$ { ECHO; /* remove line */ ; } ^[^ ] { columnCount++; fprintf(stderr, "%s:%lu: Invaild character (%c) in" "column 7.\n" ,globalEnvPtr->ifname ,lineCount ,yytext[0] ); /* remove line */ } ^"/".*$ { /* remove line */ ; } ^"D".*$ { if ( globalEnvPtr->debug == 1 ) { yytext[0]=' '; ECHO; } /* else remove line */ } ^"$".*$ { fprintf(stderr, "%s:%lu: Warning: Directive ignored.\n" ,globalEnvPtr->ifname ,lineCount); globalEnvPtr->errFlag++; } .* { columnLen = strlen(yytext); /* Ensure that position 7 is blank */ if( columnCount == 0 ) { if( yytext[0] != ' ' ) { fprintf(yyout, " "); columnCount++; } } if ( columnLen > 66 ) { lineExpand(); } else { columnCount = columnCount + columnLen; ECHO; } } {eol} { lineCount++; columnCount=0; ECHO; BEGIN(FIXED); } {eol} { lineCount++; columnCount=0; ECHO; BEGIN(FIXED); } . { columnCount++; if ( columnCount > 72 ) { BEGIN(FIXED_LC); } else { ECHO; /* fprintf(stderr, "debug: : char=%s, columnCount=%d, lineCount=%d\n", yytext, columnCount, lineCount ); */ } } . { /* eat comments */ /*printf("*")*/ ; } {eol} { ECHO; lineCount++; columnCount=0; BEGIN(FIXED); } {eol}.{6}"-"{blank}{4,58}{Quote} { /* Continuation line remove */ lineCount++; /*columnCount=12;*/ /* columnCount=0; */ columnCount = yyleng - 1; BEGIN(FIXED_A); } ^.{6} { /* remove sequence number */ columnCount+=6 ; BEGIN(FIXED_7); /* fprintf(stderr, "debug: ^.{6}: columnCount=%d, lineCount=%d\n", columnCount, lineCount ); */ } "*" | "/" | "$" { /* comment line remove */ ECHO; columnCount++; BEGIN(COMMENT); } "D" { columnCount++; if ( globalEnvPtr->debug == 1 ) BEGIN(FIXED_A); else BEGIN(COMMENT); } [\n] { BEGIN(FIXED); lineCount++; columnCount=0; ECHO; } [ ] { columnCount++; BEGIN(FIXED_A); ECHO; } [^ \n] { globalEnvPtr->errFlag++; fprintf(stderr, "%s:%lu: Invaild character (%c) in" "column 7.\n" ,globalEnvPtr->ifname ,lineCount ,yytext[0] ); BEGIN(COMMENT); } {eol}.{6}"-"{blank}{4,58}{Quote} { /* Continuation line remove */ lineCount++; /* columnCount=0; */ columnCount = yyleng - 1; BEGIN(FIXED_A); } {Quote}{eol}.{6}"-"{blank}{4,58}{Quote} { /* Continuation line remove */ lineCount++; /* columnCount=0; */ columnCount = yyleng - 1; BEGIN(FIXED_A); } . { /* any other line */ columnCount++; /* don't echo */ if ( columnCount > 72 ) { BEGIN(FIXED_LC); } /* }else if ( columnCount > 80 ){ * lexError( "Record Exceeded 80 cols!"); } */ else { ECHO; } } %% /* * Expand line. */ void lineExpand(void) { int nlines, j; char *s = yytext, delm = '0'; for(j=0; jlinemul != 0) { fprintf(yyout, "\n%06d%s", lineCount*10, lineout); } else { fprintf(yyout, "\n %s", lineout); } } if( (j = strlen(s)) > 0) { sprintf(lineout, "- %c", delm); strncat(lineout, s, j); lineout[6 + j] = '\0'; lineCount++; if (globalEnvPtr->linemul != 0) { fprintf(yyout, "\n%06d%s", lineCount*10, lineout); } else { fprintf(yyout, "\n %s", lineout); } } /* fprintf(stderr, "%s: Character (%c) in column %d, line %lu.\n", globalEnvPtr->ifname, yytext[0], columnCount, lineCount); */ } /* print error on tab and stop. */ void tabExpand(void) { /* * Check the warning level settings * output the appropriate message. * */ /* if ( globalEnvPtr->tab2space == 0 ) { */ /* now is a tab always an error?? yes? */ /* (void)fprintf(stderr, "%s:%lu: Error tab in column %lu\n" ,globalEnvPtr->ifname , lineCount, columnCount ); globalEnvPtr->errFlag++; return; */ /* } */ globalEnvPtr->errFlag++; fprintf(stderr, "error: tabs exapntion is not supported ...aborting\n" "Hint: use expand utility to process tabs\n" ); return; } // void lexError( char * msg ) { // // (void)fprintf(stderr, // "%s:%lu: %s\n" // ,globalEnvPtr->ifname // ,lineCount // ,msg // ); // globalEnvPtr->errFlag++; // return; // } int yywrap(void) { /* yywrap will be called to open files from the List of Files in the * Global Env struct. */ return 1; }