/*@(#)44 1.4 src/bos/usr/bin/ate/lexer, cmdate, bos411, 9428A410j 4/18/91 10:59:46*/ 
%{
/* 
 * COMPONENT_NAME: CMDATE lexer
 * 
 * FUNCTIONS: 
 *
 * ORIGINS:  27   
 *
 * (C) COPYRIGHT International Business Machines Corp. 1985, 1989
 * All Rights Reserved
 * Licensed Materials - Property of IBM
 *
 * US Government Users Restricted Rights - Use, duplication or
 * disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
 *
 */

/*
 *  lexical scanner for the vt100 emulation 
 */

#define ERR (-1)
#define EOF (-1)

#include "lexer.h"
#include "modem.h"

extern char escbuf[];			/* hold partial escape sequences */
extern char * eb_ptr;			/* escape buffer pointer */
int rc;					/* return code */
int i,j;

%}

esc		[\033]
L 		[\037-\157]
D		[0-9]
N   		{D}*

vt52		{esc}"<"
cpr		{esc}"["{N}*;{N}*R|{esc}"[R"
cub		{esc}"["{N}*D
cud		{esc}"["{N}*B|{esc}B
cuf		{esc}"["{N}*C|{esc}C
cuu		{esc}"["{N}*A|{esc}A
cup		{esc}"["{N};{N}*H|{esc}"["{N}*H
da		{esc}"["{D}*c|{esc}Z
dca		{esc}"Y"{L}{L}
dcs		({esc}P[.])*{esc}\\
deckpam		{esc}"="
deckpnm		{esc}">"
decll		{esc}"["({D}";")*{D}*q
decparm		{esc}"["{N}(";"{N})*x
decsrc		{esc}7|{esc}8
decstbm		{esc}"["{N}*;{N}*r|{esc}"[r"
dectst		{esc}"[2;"{N}y
dsr		{esc}"["{N}n
ed		{esc}"["{N}*J|{esc}J 
el		{esc}"["{N}*K|{esc}K
hdwr		{esc}"#"{D}
hts		{esc}H
hvp		{esc}"["{N}*;{N}*f|{esc}"[f"
ind		{esc}D
nel		{esc}E
ri		{esc}M|{esc}I|{esc}"["{N}*F
ris		{esc}c
rm		{esc}"["("?")*{N}(";"("?")*{N})*l
scs		{esc}[\(\)][AB012]|{esc}[FG]
sgr		{esc}"["{D}*(";"{D}*)*m
shift		[\016\017]
sm		{esc}"["("?")*{N}(";"("?")*{N})*h
tbc		{esc}"["{D}*g
other		{esc}[^\[\<\>\=\#\(\)cA-KMOPYZ0-9]

%%

{vt52}		{ /* esc< -- enter ANSI mode from VT52 mode */
		yylval = SM;
		ps[0] = DECANM;
#ifdef DEBUG
kk=sprintf(ss,"LEX:  vt52=%s, ps[0]=%d, yylval=%d\n",yytext,ps[0],yylval);
write(fe,ss,kk);
#endif DEBUG
		return(yylval);
		}

{cub}		{ /*  esc[PnD (vt100) or escD (vt52)  -- cursor back (left) */
		yylval = CUB;
                ps[0] = 1; 
		rc = sscanf(yytext,"\033[%dD",&ps[0]);
		if (ps[0]<=0) ps[0]=1;
#ifdef DEBUG
kk=sprintf(ss,"LEX:  cub=%s, ps[0]=%d, yylval=%d\n",yytext,ps[0],yylval);
write(fe,ss,kk);
#endif DEBUG
		return(yylval);
		}

{cud}		{ /*  esc[PnB or escB -- cursor down */
		yylval = CUD;
                ps[0] = 1; 
		rc = sscanf(yytext,"\033[%dB",&ps[0]);
		if (ps[0]<=0) ps[0]=1;
#ifdef DEBUG
kk=sprintf(ss,"LEX:  cud=%s, ps[0]=%d, yylval=%d\n",yytext,ps[0],yylval);
write(fe,ss,kk);
#endif DEBUG
		return(yylval);
		}

{cuf}		{ /*  esc[PnC or escC-- cursor fwd (right) */
		yylval = CUF;
                ps[0] = 1; 
		rc = sscanf(yytext,"\033[%dC",&ps[0]);
		if (ps[0]<=0) ps[0]=1;
#ifdef DEBUG
kk=sprintf(ss,"LEX:  cuf=%s, ps[0]=%d, yylval=%d\n", yytext,ps[0],yylval);
write(fe,ss,kk);
#endif DEBUG
		return(yylval);
		}

{cuu}		{ /*  esc[PnA or escA -- cursor position up */
		yylval = CUU;
                ps[0] = 1; 
		rc = sscanf(yytext,"\033[%dA",&ps[0]);
		if (ps[0]<=0) ps[0]=1;
#ifdef DEBUG
kk=sprintf(ss,"LEX:  cuu=%s, ps[0]=%d, yylval=%d\n", yytext,ps[0],yylval);
write(fe,ss,kk);
#endif DEBUG
		return(yylval);
		}

{cup}		{ /*  esc[Pn;PnH -- set cursor position */
		yylval = CUP;
		ps[0]=ps[1]=0;
		rc = sscanf(yytext,"\033[%d;%dH",&ps[0],&ps[1]);
		if (rc < 1) rc = sscanf(yytext,"\033[;%dH",&ps[1]);
#ifdef DEBUG
kk=sprintf(ss,"LEX:  cup=%s, ps[0]=%d, ps[1]=%d, yylval=%d\n",
   yytext,ps[0],ps[1],yylval);
write(fe,ss,kk);
#endif DEBUG
		return(yylval);
		}

{cpr}		{ /*  esc[Pn;PnR -- cursor position report */
		yylval = CPR;
		ps[0]=ps[1]=0;
		rc = sscanf(yytext,"\033[%d;%dR",&ps[0],&ps[1]);
		if (rc < 1) rc = sscanf(yytext,"\033[;%dR",&ps[1]);
#ifdef DEBUG
kk=sprintf(ss,"LEX:  cpr=%s, ps[0]=%d, ps[1]=%d, yylval=%d\n",
   yytext,ps[0],ps[1],yylval);
write(fe,ss,kk);
#endif DEBUG
		return(yylval);
		}

{da} 		{ /*  esc[c or esc[0c -- device attributes */
		  /*  escZ -- identify terminal */
		if (strcmp(yytext,"\033Z")==0) yylval=DECID;
		else yylval = DEVATTR;
		ps[0]=0;
#ifdef DEBUG
kk=sprintf(ss,"LEX:  da/decid=%s, ps[0]=%d, yylval=%d\n", yytext,ps[0],yylval);
write(fe,ss,kk);
#endif DEBUG
		return(yylval);
		}

{dca}		{ /*  escYPnPn -- VT52 director cursor addressing */
		/* Pn's are letters in the range 037 to 0157 (0-80 decimal) */
		char c1,c2;

		yylval = CUP;
		ps[0]=ps[1]=0;

		rc = sscanf(yytext,"\033Y%c%c",&c1,&c2);

		if (c1>036) ps[0] = c1 - 037;
		if (c2>036) ps[1] = c2 - 037;

#ifdef DEBUG
kk=sprintf(ss,"LEX:  dca(cup)=%s, %c(%d), %c(%d), ps[0]=%d, ps[1]=%d\n",
   yytext, c1, c1, c2, c2, ps[0],ps[1]);
write(fe,ss,kk);
#endif DEBUG
		return(yylval);
		}

{dcs}		{ /* escP ... esc\ -- VT220 device control string */
		yylval = DISCARD;
#ifdef DEBUG
kk=sprintf(ss,"LEX:  dcs=%s\n",yytext);
write(fe,ss,kk);
#endif DEBUG
		}

{sm}		|
{rm}		{ /* reset mode */
		int flag[NPARAMS];
		for (j=0; j<NPARAMS; j++) flag[j]=0; 

		j=0; ps[0]=0;
		for (i=2; (yytext[i]!='l' && yytext[i]!='h'); i++)
		   {
		   if (yytext[i]==';')
		      {
		      j++;
		      if (j>=NPARAMS) break;
		      ps[j] = 0;
		      }
		   else if (yytext[i]=='?') 
		      {
                      flag[j]=1;
		      }
		   else if (yytext[i] >= '0' && yytext[i] <= '9')
 		      {
		      ps[j] = 10*ps[j] + yytext[i]-'0';
		      }
		   }

		if (yytext[i]=='l') yylval=RM;
		if (yytext[i]=='h') yylval=SM;
#ifdef DEBUG
if (yylval==RM)      kk=sprintf(ss,"LEX:  RM");
else if (yylval==SM) kk=sprintf(ss,"LEX:  SM");
else                 kk=sprintf(ss,"Bad yylval in RM/SM %s\n", yytext);
write(fe,ss,kk);
#endif DEBUG
		   
		for (j=0; ps[j]!=ERR && j<NPARAMS; j++)
		   {
        	   switch(ps[j])
   		   {
		   case  0 : /*  esc[?0h or esc[?0l -- invalid */
			     ps[j] = DISCARD;
			     break;
   		   case  1 : /*  esc[?1h or esc[?1l -- cursor appl mode */
   			     ps[j] = DECCKM;
   			     break;
   		   case  2 : /*  esc[?2h or esc[?2l -- ANSI/VT52 mode */
			     /*  esc[2h or esc[2l   -- keyboard action */
   			     if (flag[j]==1) ps[j] = DECANM;
			     else ps[j]=KAM;
   			     break;
   		   case  3 : /*  esc[?3h or esc[?3l -- 80/132 column */
   			     ps[j] = DECCOLM;
   			     break;
   		   case  4 : /*  esc[?4h or esc[?4l -- jump/smooth scroll */
			     /*  esc[4h or esc[4l   -- insert/replace */
   			     if (flag[j]==1) ps[j] = DECSCLM;
			     else ps[j] = IRM;
   			     break;
   		   case  5 : /*  esc[?5h or esc[?5l -- screen color */
   			     ps[j] = DECSCNM;
   			     break;
   		   case  6 : /*  esc[?6h or esc[?6l -- origin mode */
   			     ps[j] = DECOM;
   			     break;
   		   case  7 : /*  esc[?7h or esc[?7l -- auto wrap */
   			     ps[j] = DECAWM;
   			     break;
   		   case  8 : /*  esc[?8h or esc[?8l -- auto repeating */
   			     ps[j] = DECARM;
   			     break;
   		   case  9 : /*  esc[?9h or esc[?9l -- interlace */
   			     ps[j] = DECINLM;
   			     break;
		   case 12 : /* esc[12h or esc[12l -- send/receive */
			     ps[j] = SRM;
			     break;
		   case 18 : /* esc[18h or esc[18l -- print form feed */
			     ps[j] = DECPFF;
			     break;
		   case 19 : /* esc[19h or esc[19l -- print extent */
			     ps[j] = DECPEX;
			     break;
   		   case 20 : /*  esc[20h or esc[20l -- LF/NL */
   			     ps[j] = LNM;
   			     break;
		   case 25 : /* esc[25h or esc[25l -- text cursor enable */
			     ps[j] = DECTCEM;
			     break;
   		   default : ps[j] = DISCARD;
   			     break;
   		   } /* end of switch */
#ifdef DEBUG
kk=sprintf(ss,"  ps[%d]=%d",j,ps[j]);
write(fe,ss,kk);
#endif DEBUG
		   } /* end of 'for' */
#ifdef DEBUG
write(fe,"\n",1);
#endif DEBUG

		return(yylval);
		}

{hdwr}		{ /* hardware codes */				
		rc = sscanf(yytext,"\033#%d",&ps[0]);
		switch (ps[0])
		  {
		  case 3  : /*  esc#3 -- double height line - top half */
			    yylval = DECDHL;
 			    break;
		  case 4  : /*  esc#4 -- double height line - bottom half */
			    yylval = DECDHL;
 			    break;
		  case 5  : /*  esc#5 - single width line */
			    yylval = DECSWL;
			    break;
		  case 6  : /*  esc#6 -- double width line */
			    yylval = DECDWL;
			    break;
 		  case 8  : /*  esc#8 -- screen alignment display */
			    yylval = DECALN;
			    break;
		  default : yylval = DISCARD;
			    break;
		  }
#ifdef DEBUG
kk=sprintf(ss,"LEX:  hdwr=%s, ps[0]=%d, yylval=%d\n", yytext,ps[0],yylval);
write(fe,ss,kk);
#endif DEBUG
		return(yylval);
		}

{deckpam} 	{ /*  esc= -- keypad appl mode ON */
		yylval = DECKPAM;
#ifdef DEBUG
kk=sprintf(ss,"LEX:  deckpam=%s, yylval=%d\n", yytext,yylval);
write(fe,ss,kk);
#endif DEBUG
		return(yylval);
		}

{deckpnm} 	{ /*  esc> -- keypad numeric mode ON */
		yylval = DECKPNM;
#ifdef DEBUG
kk=sprintf(ss,"LEX:  deckpnm=%s, yylval=%d\n", yytext,yylval);
write(fe,ss,kk);
#endif DEBUG
		return(yylval);
		}

{decll}		{ /*  esc[Psq -- load LED's */
		yylval = DECLL;
#ifdef DEBUG
kk=sprintf(ss,"LEX:  decll=%s, yylval=%d\n", yytext,yylval);
write(fe,ss,kk);
#endif DEBUG
		return(yylval);
		}

{decparm}	{ /*  DECREPTPARM  esc[Psx -- request terminal params */
		  /*  DECREQPARM   esc[Ps;...;Psx -- report terminal params */
		if ( strcmp(yytext,"\033[0x")==0 ||
		     strcmp(yytext,"\033[1x")==0) yylval=DECREQPARM;
		else yylval = DECREPTPARM;
#ifdef DEBUG
kk=sprintf(ss,"LEX:  decparm=%s, yylval=%d\n", yytext,yylval);
write(fe,ss,kk);
#endif DEBUG
		return(yylval);
		}

{decsrc} 	{ /*  esc8 -- restore cursor, esc7 -- save cursor */
		if (strcmp(yytext,"\0338")==0)
		   {
		   yylval = DECRC;
#ifdef DEBUG
kk=sprintf(ss,"LEX:  decrc=%s, yylval=%d\n", yytext,yylval);
write(fe,ss,kk);
#endif DEBUG
		   }
		else 
		   {
		   yylval=DECSC;
#ifdef DEBUG
kk=sprintf(ss,"LEX:  decsc=%s, yylval=%d\n", yytext,yylval);
write(fe,ss,kk);
#endif DEBUG
		   }
		return(yylval);
		}

{decstbm} 	{ /*  esc[Pn;Pnr -- set scrolling reg */
		yylval = DECSTBM;
		ps[0]=TOP; ps[1]=Lines;   /* default region is entire screen */ 
		rc = sscanf(yytext,"\033[%d;%dr",&ps[0],&ps[1]);
		if (rc < 1) rc = sscanf(yytext,"\033[;%dr",&ps[1]);
#ifdef DEBUG
kk=sprintf(ss,"LEX:  decstbm=%s, ps[0]=%d, ps[1]=%d, yylval=%d\n",
   yytext,ps[0],ps[1],yylval);
write(fe,ss,kk);
#endif DEBUG
		return(yylval);
		}

{dectst}	{ /*  esc[2;Psy -- invoke confidence tests */
		yylval = DECTST;
#ifdef DEBUG
kk=sprintf(ss,"LEX:  dectst=%s, yylval=%d\n", yytext,yylval);
write(fe,ss,kk);
#endif DEBUG
		return(yylval);
		}

{dsr} 		{ /*  esc[Psn -- device status request */
		  /*    0   VT100-host:  ready */
		  /* 	3   VT100-host:  malfunction */
		  /* 	5   host-VT100:  send 'no malfunctions' */
		  /* 	6   host-VT100:  send cpr sequence */
		yylval = DSR;
		ps[0]=0;
		rc = sscanf(yytext,"\033[%dn",&ps[0]);
		switch (ps[0])
		  {
		  case 0  : 
		  case 3  : yylval=DISCARD;
			    break;
		  case 5  : break;
		  case 6  : break; 
		  default : yylval=DISCARD;
			    break;
		  }
#ifdef DEBUG
kk=sprintf(ss,"LEX:  dsr=%s, ps[0]=%d, yylval=%d\n", yytext,ps[0],yylval);
write(fe,ss,kk);
#endif DEBUG
		return(yylval);
		}

{ed} 		{ /*  esc[PsJ - erase in display */ 
		  /*    0   erase to bottom */
		  /*   	1   current position */
		  /*    2   clear all of display */
		yylval = ERASED;
		ps[0]=0;
		rc = sscanf(yytext,"\033[%dJ",&ps[0]);
		if (ps[0] > 2) yylval = DISCARD;
#ifdef DEBUG
kk=sprintf(ss,"LEX:  ed=%s, ps[0]=%d, yylval=%d\n", yytext,ps[0],yylval);
write(fe,ss,kk);
#endif DEBUG
		return(yylval);
		}

{el} 		{ /*  esc[PsK -- erase in line */
		  /*    0   clear to end of line */
		  /*   	1   clear to start of line */
		  /*    2   clear all of line */
		yylval = ERASEL;
		ps[0]=0;
		rc = sscanf(yytext,"\033[%dK",&ps[0]);
		if (ps[0] > 2) yylval = DISCARD;
#ifdef DEBUG
kk=sprintf(ss,"LEX:  el=%s, ps[0]=%d, yylval=%d\n", yytext,ps[0],yylval);
write(fe,ss,kk);
#endif DEBUG
		return(yylval);
		}

{hts}		{ /*  escH -- set horizontal tab */
		yylval = HTS;
#ifdef DEBUG
kk=sprintf(ss,"LEX:  hts=%s, yylval=%d\n", yytext,yylval);
write(fe,ss,kk);
#endif DEBUG
		return(yylval);
		}

{hvp}		{ /*  esc[Pn;Pnf -- set horiz/vert position */
		yylval = HVP;
		ps[0]=ps[1]=0;
		rc = sscanf(yytext,"\033[%d;%df",&ps[0],&ps[1]);
		if (rc < 1) rc = sscanf(yytext,"\033[;%df",&ps[1]);
#ifdef DEBUG
kk=sprintf(ss,"LEX:  hvp=%s, ps[0]=%d, ps[1]=%d, yylval=%d\n",
   yytext,ps[0],ps[1],yylval);
write(fe,ss,kk);
#endif DEBUG
		return(yylval);
		}

{ind}		{ /*  escD -- next line, same column */
		if (!vt52) yylval = IND;
 		else 		/* VT52 mode */
		   {
		   yylval = CUB;
		   ps[0]=1;
		   }
#ifdef DEBUG
kk=sprintf(ss,"LEX:  ind=%s, yylval=%d\n", yytext,yylval);
write(fe,ss,kk);
#endif DEBUG
		return(yylval);
		}

{nel}		{ /*  escE -- next line (col 1) */
		yylval = NEL;
#ifdef DEBUG
kk=sprintf(ss,"LEX:  nel=%s, yylval=%d\n", yytext,yylval);
write(fe,ss,kk);
#endif DEBUG
		return(yylval);
		}

{ri}		{ /*  escM or escI -- reverse index */
		  /* esc[PnF -- cursor preceding line (hft code) */
		if (strcmp(yytext,"\033M")==0 || strcmp(yytext,"\033I")==0)
		   {
		   yylval=RI;
		   ps[0]=1;
		   }
		else 
		   {
		   yylval=CPL;
		   ps[0]=0;
		   rc = sscanf(yytext,"\033[%dF",&ps[0]);
		   }
#ifdef DEBUG
kk=sprintf(ss,"LEX:  cpl/ri=%s, yylval=%d\n", yytext,yylval);
write(fe,ss,kk);
#endif DEBUG
		return(yylval);
		}

{ris}		{ /*  escc -- reset to initial state */
		yylval = RIS;
#ifdef DEBUG
kk=sprintf(ss,"LEX:  ris=%s, yylval=%d\n", yytext,yylval);
write(fe,ss,kk);
#endif DEBUG
		return(yylval);
		}

{scs}		{ /*  esc(0,escF to select special graphics */
		  /*  esc(B,escG to select ascii char set */
		yylval = SCS;
#ifdef DEBUG
kk=sprintf(ss,"LEX:  scs=%s, yylval=%d\n", yytext,yylval);
write(fe,ss,kk);
#endif DEBUG
		return(yylval);
		}

{sgr}		{ /*  esc[Ps;...;Psm -- set graphic rendition */
		  /* 	0   attributes off */
		  /* 	1   bold */
		  /*    22  normal intensity */
		  /*    24  not underlined */
		  /*    25  not blinking */
		  /*    27  positive image */
		  /* 	4   underscore */
		  /* 	5   blink */
		  /* 	7   reverse video */
		yylval = SGR;
		j = 0;
		ps[0]=0;
		for(i=2; yytext[i]!='m'&& j<NPARAMS ; i++)
		   {
		   if (yytext[i]==';') 
		      {
		      j++;
		      ps[j]=0;
		      }
		   else 
		      {
		      ps[j] = 10*ps[j] + yytext[i]-'0';
		      }
		   }
#ifdef DEBUG
for (j=0; ps[j]!=ERR && j<NPARAMS; j++)
{ kk=sprintf(ss,"LEX:  sgr=%s, ps[%d]=%d, yylval=%d\n", yytext,j,ps[j],yylval);
write(fe,ss,kk); }
#endif DEBUG
		return(yylval);
		}

{shift}		{ /* ^N,^O,esc~,escn,esc},esco,esc|,escN,escO -- lock shift*/
		yylval = SHIFT;
		if (yytext[0] == 016) ps[0]=1;  	/* G0 selected */
		else if (yytext[0] == 017) ps[0]=0;	/* G1 selected */
#ifdef DEBUG
kk=sprintf(ss, "LEX:  shift=%s(%o), ps[0]=%d, yylval=%d\n",
   yytext,yytext[0],ps[0],yylval);
write(fe,ss,kk);
#endif DEBUG
		return(yylval);
		}

{tbc} 		{ /*  esc[Psg -- tabulation clear */
		yylval = TBC;
		ps[0]=0;
		rc = sscanf(yytext,"\033[%dg",&ps[0]);
#ifdef DEBUG
kk=sprintf(ss,"LEX:  tbc=%s, ps[0]=%d, yylval=%d\n", yytext,ps[0],yylval);
write(fe,ss,kk);
#endif DEBUG
		return(yylval);
		}

{other}		{
		yylval=NORM;
#ifdef DEBUG
kk=sprintf(ss,"other:  beginning of unrecognized esc sequence %s\n",yytext);
write(fe,ss,kk); 
#endif DEBUG
		return(yylval);
		}

\n		|
.		{
		yylval = NORM;
#ifdef DEBUG
if (yyleng==1) kk=sprintf(ss,"%c",yytext[0]);
else           kk=sprintf(ss,"%s",yytext);
write(fe,ss,kk); 
#endif DEBUG
		if (yyleng==1)
		   {
		   switch(yytext[0])
		      {
		      case 0x07 : 		/* bell */
			yylval = BELL;
                        break;
                      case 0x09 : 		/* horizontal tab */
			yylval = HT;
		      case 0x0E :		/* shift out */
		      case 0x0F :		/* shift in */
			break;
                      case 0xFF : 
			yylval = SIGNAL;
			break;
		      default:
			break;
		      }
		   }  
		return(yylval);
		}

%%


/* ------------------------------------------------------------------- */
/* print error messages                                                */
/* ------------------------------------------------------------------- */
yyerror()                        
{
;
}


/*----------------------------------------------------------------------*/
/* yywrap function.  							*/
/*----------------------------------------------------------------------*/
yywrap()
{
#ifdef DEBUG
kk = sprintf(ss,"yylex wrapping up\n");
write(fe,ss,kk);
#endif DEBUG
return(1);
}


/* ------------------------------------------------------------------------- */
/* input - replaces lex routine defined below:				     */
/* define input() (
                  (
                  (yytchar=yysptr>yysbuf ? U(*--yysptr) : getc(yyin))
                  ==10  ? (yylineno++,yytchar) : yytchar)
	 	  ==EOF ? 0 : yytchar)					     */
/* ------------------------------------------------------------------------- */

input()
{
int c;

#ifdef DEBUG
kk = sprintf(ss,"INPUT:  \n");
write(fe,ss,kk);
kk = sprintf(ss,"     eb_ptr=%o,escbuf=%o  yysptr=%o,yysbuf=%o\n",
   eb_ptr,escbuf,yysptr,yysbuf);
write(fe,ss,kk);
kk = sprintf(ss,"     escbuf=");
write(fe,ss,kk);
write(fe,escbuf,eb_ptr-escbuf);
kk = sprintf(ss," yysbuf=");
write(fe,ss,kk);
write(fe,yysbuf,yysptr-yysbuf);
write(fe,"\n",1);
#endif DEBUG 

if (eb_ptr>escbuf)			/* partial escape sequence on stack */
  {
  c = *--eb_ptr;	 		/* some chars were 'ungot' */
#ifdef DEBUG
kk = sprintf(ss,"     input returning %o from escbuf\n",c);
write(fe,ss,kk);
#endif DEBUG
  }
else if (yysptr>yysbuf) 
  {
  c = *--yysptr;	 	/* some chars were 'ungot' */
  if (c == 0) c = input();	/* lex kludge for null on bottom of stack */
#ifdef DEBUG
kk = sprintf(ss,"     input returning %o from yysbuf\n",c);
write(fe,ss,kk);
#endif DEBUG
  }
else if (ptr < lndata+lnstat)   	/* still chars in buffer */
  {
  c = *ptr;
  ptr++;
  if (c == 0) c = input();		/* LEX can't handle nulls */
#ifdef DEBUG
kk = sprintf(ss,"     input returning %o from lndata\n",c);
write(fe,ss,kk);
#endif DEBUG
  }
else 					/* buffer is empty */
  {
  c = 0;
#ifdef DEBUG
kk = sprintf(ss,"     input outta data\n");
write(fe,ss,kk);
#endif DEBUG
  }	

if (c == '\n') yylineno++;
yytchar = c;
return(c);
}
