diff -Naur oxDistG1.04.orig/source/agc1.l oxDistG1.04/source/agc1.l
--- oxDistG1.04.orig/source/agc1.l	2004-04-30 15:26:24.000000000 +0200
+++ oxDistG1.04/source/agc1.l	2004-04-30 15:29:49.000000000 +0200
@@ -1,4 +1,5 @@
 %start YD YDSI ADECL MH MB LVA ADSL UU CC TRDECL 
+%option yylineno 
  
  
 %{
@@ -69,6 +70,7 @@
 #include "outMgr.h"
 #include "symTrans.h"
 #include "ctc.h"
+#define YY_USER_ACTION ptext=yytext;
 %}
  
  
@@ -247,7 +249,7 @@
 
 void beginCC() {BEGIN CC;}   
 
-int yyScnState() {return (yybgin-yysvec-1);}
+int yyScnState() {return YY_START;}
 
 yywrap() 
   {
diff -Naur oxDistG1.04.orig/source/agc2.l oxDistG1.04/source/agc2.l
--- oxDistG1.04.orig/source/agc2.l	2004-04-30 15:26:24.000000000 +0200
+++ oxDistG1.04/source/agc2.l	2004-04-30 15:29:50.000000000 +0200
@@ -1,6 +1,7 @@
 %start YR YR1 AA LAAA LAAA1 
 %start DL CL TT MUI TRAV1 TRVACT TRVCOND
-%start EOSFRET  
+%start EOSFRET SKIP
+%option yylineno
 
 %{
 /* $Header: agc2.l,v 5.10 94/04/16 20:23:56 bischoff Exp $ */ 
@@ -77,6 +78,7 @@
 int startCondTempT; 
 int nLparensT;
 enum {oCond,dCond,action} travState;
+#define YY_USER_ACTION ptext=yytext;
 %}
  
  
@@ -92,7 +94,10 @@
 
 IDENT ([a-zA-Z][a-zA-Z0-9]*)
 %%
-<EOSFRET>x             {scanScanInit(); return(EOSF);}
+<SKIP>^{OPTWS}%%{OPTWS}$    BEGIN YR;
+<SKIP>.   |
+<SKIP>\n ;
+<EOSFRET><<EOF>>             {scanScanInit(); return(EOSF);}
 <YR>[ \t\n\f]          {flushLAbuffer(LA1,outG); charOut(*yytext,outG);}  
 <YR>\/\*               {flushLAbuffer(LA1,outG); eatCommentAndEcho(outG,1);}
 <YR>\/\/.*\n           {flushLAbuffer(LA1,outG); lexemeOut(outG);}
@@ -343,13 +348,14 @@
 
 
 void scanInit2() 
-  {whichScanner = 2; 
-   yylineno = *plineno; 
+  {whichScanner = 2;
+   yylineno=0; 
    plineno = &yylineno; 
    ptext = (char *)yytext; 
    pleng = &yyleng; 
-   BEGIN YR; 
+   BEGIN SKIP; 
    yyin = yoxInG; 
+   rewind(yyin);
   } 
 
 
@@ -357,7 +363,7 @@
 void beginAA() {BEGIN AA;}   
 void beginTT() {BEGIN TT;}   
  
-int yyScnState() {return (yybgin-yysvec-1);} 
+int yyScnState() {return YY_START;} 
 
 yywrap() 
   {
@@ -368,7 +374,7 @@
       } 
    unput('x');
    BEGIN EOSFRET; 
-   return 0; 
+   return 1; 
 
 err1: 
    rmTempFiles();
diff -Naur oxDistG1.04.orig/source/agc3.l oxDistG1.04/source/agc3.l
--- oxDistG1.04.orig/source/agc3.l	2004-04-30 15:26:24.000000000 +0200
+++ oxDistG1.04/source/agc3.l	2004-04-30 15:29:51.000000000 +0200
@@ -1,4 +1,5 @@
 %start EOSFRET LD LRP LRRE LRRE1 LRA LRAAD LRAAR LRAAR1 LRAAD1 LUS MUI 
+%option yylineno 
  
 %{
 /* $Header: agc3.l,v 5.10 94/04/16 20:23:59 bischoff Exp $ */ 
@@ -78,6 +79,7 @@
 static int nLparMac; 
 static FILE *tempForTrash;
 int yyStartCondTemp; 
+#define YY_USER_ACTION ptext=yytext;
 %}
  
  
@@ -92,7 +94,7 @@
  
 IDENT ([a-zA-Z][a-zA-Z0-9]*)
 %%
-<EOSFRET>x             {scanScanInit(); return EOSF;}
+<EOSFRET><<EOF>>             {scanScanInit(); return EOSF;}
 <LD>^\%\%(.*)          {BEGIN LRP; 
                         if (!buildHeaderFile) 
                            {fprintf(Lfile[currentLfile].outPtr,"\n%%{\n"); 
@@ -338,7 +340,7 @@
   } 
 
 
-int yyScnState() {return (yybgin-yysvec-1);} 
+int yyScnState() {return YY_START;} 
 
 
 
@@ -356,9 +358,8 @@
       }  
    if (yyScnState() == LRAAR) 
       yerror("error: identifier expected after \"return\".\n");   
-   unput('x');
    BEGIN EOSFRET;
-   return 0;
+   return 1;
 
 err1:
    rmTempFiles();
diff -Naur oxDistG1.04.orig/source/agc4.l oxDistG1.04/source/agc4.l
--- oxDistG1.04.orig/source/agc4.l	2004-04-30 15:26:24.000000000 +0200
+++ oxDistG1.04/source/agc4.l	2004-04-30 15:29:52.000000000 +0200
@@ -1,5 +1,6 @@
 %start GEN ADECL AADECL ADS MAC TRDECL
 %start LD LRP LRRE LRRE1 LRA LRAAD LUS  
+%option yylineno 
  
 %{
 /* $Header: agc4.l,v 5.10 94/04/16 20:24:02 bischoff Exp $ */
@@ -68,6 +69,7 @@
 #include "opts.hh"
 #include "opts.h"
 #include "outMgr.h"
+#define YY_USER_ACTION ptext=yytext;
 %}
 
 WS		[ \t\f]+
@@ -164,7 +166,7 @@
    inFileStr = yoxInFileStrG; 
   } 
 
-int yyScnState() {return (yybgin-yysvec-1);}
+int yyScnState() {return YY_START;}
 
 int yywrap()
   {
diff -Naur oxDistG1.04.orig/source/agc5.l oxDistG1.04/source/agc5.l
--- oxDistG1.04.orig/source/agc5.l	2004-04-30 15:26:24.000000000 +0200
+++ oxDistG1.04/source/agc5.l	2004-04-30 15:29:54.000000000 +0200
@@ -1,4 +1,5 @@
 %start EOSFRET LRA LRAAD LRAAR LRAAR1 LRAAD1 LUS MUI 
+%option yylineno 
  
 %{
 /* $Header: agc5.l,v 5.10 94/04/16 20:24:04 bischoff Exp $ */ 
@@ -78,6 +79,7 @@
 static int nLparMac; 
 static FILE *tempForTrash;
 int yyStartCondTemp; 
+#define YY_USER_ACTION ptext=yytext;
 %}
  
  
@@ -92,7 +94,7 @@
  
 IDENT ([a-zA-Z][a-zA-Z0-9]*)
 %%
-<EOSFRET>x             {scanScanInit(); return(EOSF);}
+<EOSFRET><<EOF>>             {scanScanInit(); return(EOSF);}
 <LRA>\/\*              eatCommentAndEcho(outL,1); 
 <LRA>\/\/.*\n          lexemeOut(outL);
 <LRA>\"                eatStringAndEcho(outL); 
@@ -281,7 +283,7 @@
   } 
 
 
-int yyScnState() {return (yybgin-yysvec-1);} 
+int yyScnState() {return YY_START;} 
 
 
 
@@ -291,7 +293,7 @@
       yerror("error: identifier expected after \"return\".\n");   
    unput('x');
    BEGIN EOSFRET;
-   return 0;
+   return 1;
 
 err1:
    rmTempFiles();
diff -Naur oxDistG1.04.orig/source/mac.c oxDistG1.04/source/mac.c
--- oxDistG1.04.orig/source/mac.c	2004-04-30 15:26:25.000000000 +0200
+++ oxDistG1.04/source/mac.c	2004-04-30 15:29:55.000000000 +0200
@@ -440,7 +440,8 @@
   {char c;
 
    c = *(macStackTop->nextChar)++; 
-   if (!makeReadyInputFromMacro()) switchInputStreamFromMacro();  
+   if (!makeReadyInputFromMacro()) switchInputStreamFromMacro(); 
+   if(c=='\n')c='\t'; 
    return c;
   }
 
diff -Naur oxDistG1.04.orig/source/Makefile oxDistG1.04/source/Makefile
--- oxDistG1.04.orig/source/Makefile	2004-04-30 15:26:24.000000000 +0200
+++ oxDistG1.04/source/Makefile	2004-04-30 15:34:54.000000000 +0200
@@ -6,6 +6,7 @@
 # or software environment.
  
 CC=cc
+LEX=flex -l
 
 SHELL= /bin/sh
 
@@ -17,25 +18,25 @@
 	mac.o trav.o treeShow.o xtreeshw.o
 
 medyy : medyy.l 
-	lex medyy.l; $(CC) -o medyy lex.yy.c -ll 
+	$(LEX) medyy.l; $(CC) -o medyy lex.yy.c -ll 
 
 medi : medi.l 
-	lex medi.l; $(CC) -o medi lex.yy.c -ll  
+	$(LEX) medi.l; $(CC) -o medi lex.yy.c -ll  
 
 lexyy1.c : agc1.l medyy 
-	lex agc1.l; ./medyy lex.yy.c lexyy1.c 1 
+	$(LEX) agc1.l; ./medyy lex.yy.c lexyy1.c 1 
 
 lexyy2.c : agc2.l medyy medi  
-	lex agc2.l; ./medi lex.yy.c lex.yyM2.c ; ./medyy lex.yyM2.c lexyy2.c 2
+	$(LEX) agc2.l; ./medi lex.yy.c lex.yyM2.c ; ./medyy lex.yyM2.c lexyy2.c 2
 
 lexyy3.c : agc3.l medyy medi  
-	lex agc3.l; ./medi lex.yy.c lex.yyM3.c ; ./medyy lex.yyM3.c lexyy3.c 3
+	$(LEX) agc3.l; ./medi lex.yy.c lex.yyM3.c ; ./medyy lex.yyM3.c lexyy3.c 3
 
 lexyy4.c : agc4.l medyy medi  
-	lex agc4.l; ./medyy lex.yy.c lexyy4.c 4  
+	$(LEX) agc4.l; ./medyy lex.yy.c lexyy4.c 4  
 
 lexyy5.c : agc5.l medyy medi  
-	lex agc5.l; ./medi lex.yy.c lex.yyM5.c ; ./medyy lex.yyM5.c lexyy5.c 5
+	$(LEX) agc5.l; ./medi lex.yy.c lex.yyM5.c ; ./medyy lex.yyM5.c lexyy5.c 5
 
 lexyy1.o : lexyy1.c glob.h scan.h opts.h outMgr.h symTrans.h ctc.h
 	$(CC) -c lexyy1.c   
diff -Naur oxDistG1.04.orig/source/medi.l oxDistG1.04/source/medi.l
--- oxDistG1.04.orig/source/medi.l	2004-04-30 15:26:25.000000000 +0200
+++ oxDistG1.04/source/medi.l	2004-04-30 15:30:28.000000000 +0200
@@ -121,10 +121,10 @@
 char *substIText[] = { 
 "extern int inFromMac;\n", 
 "extern char inputFromMacro();\n", 
-"#define input() (inFromMac?((yysptr>yysbuf)?(*--yysptr):\\\n",
+"#define myinput() (inFromMac?((yysptr>yysbuf)?(*--yysptr):\\\n",
 "                                              inputFromMacro()\\\n",
 "                           ):\\\n",
-"                           inputM()\\\n", 
+"                           getc(yyin)\\\n", 
 "                )\n",
 }; 
 
@@ -144,7 +144,7 @@
 "#define unput(c) {if (inFromMac) \\\n",
 "                     {yytchar= (c);*yysptr++=yytchar;} \\\n",
 "                     else \\\n",
-"                     unputM(c) \\\n",
+"                     unputM(c); \\\n",
 "                 }\n",
 }; 
 
@@ -170,6 +170,13 @@
 if ((outFile = fopen(argv[2],"w")) == (FILE *)NULL)
    fprintf(stderr,"error when trying to open output file for med\n");
 yyout = outFile;
+fprintf(outFile,"#include <stdio.h>\nchar yytchar,yysbuf[BUFSIZ]={0},*yysptr=&yysbuf[0];\n");
+fprintf(outFile,"#define YY_INPUT(buf,result,max_size) "
+"         { "
+"         int c = myinput(); "
+"         result = (c == EOF) ? YY_NULL : (buf[0] = c, 1); "
+"         }\n");
+substInputDef(outFile);
 yylex();
 fclose(inFile);
 fclose(outFile);
diff -Naur oxDistG1.04.orig/source/medyy.l oxDistG1.04/source/medyy.l
--- oxDistG1.04.orig/source/medyy.l	2004-04-30 15:26:25.000000000 +0200
+++ oxDistG1.04/source/medyy.l	2004-04-30 15:29:57.000000000 +0200
@@ -105,6 +105,7 @@
 yyout = outFile;
 modString = argv[3];
 yylex();
+fprintf(outFile,"int yy%sinput(){return input();}\n",modString);
 fclose(inFile);
 fclose(outFile);
 erasf(argv[1]);
diff -Naur oxDistG1.04.orig/source/opts.c oxDistG1.04/source/opts.c
--- oxDistG1.04.orig/source/opts.c	2004-04-30 15:26:25.000000000 +0200
+++ oxDistG1.04/source/opts.c	2004-04-30 15:29:58.000000000 +0200
@@ -488,9 +488,9 @@
    fclose(yoxOutG);   
    for (i=0;i<nLfiles;i++) 
      {fclose(Lfile[i].inPtr); 
-      fclose(Lfile[i].outPtr); 
+     fclose(Lfile[i].outPtr);Lfile[i].outPtr=0; 
      } 
-   fclose(yoxOutH);   
+   fclose(yoxOutH);yoxOutH=0;   
   } 
 
 
@@ -501,11 +501,11 @@
    fclose(yoxOutG); 
    erasf(yoxOutFileStrG); 
    for (i=0;i<nLfiles;i++) 
-       {fclose(Lfile[i].outPtr); 
+       {if(Lfile[i].outPtr)fclose(Lfile[i].outPtr); 
         erasf(Lfile[i].outName); 
        }
    if (buildHeaderFile) 
-      {fclose(yoxOutH); 
+      {if(yoxOutH)fclose(yoxOutH); 
        erasf(yoxOutFileStrH); 
       }
    fprintf(stderr,"ox did not generate output.\n"); 
