#include <symbol.h>

char line[ 78 ];

edit( x, y, len ) int x, y, len; { register int i, j; int t, n;
   i = 0; wdca( x, y );
   while( 1 ) {
      j = getsym( ); w_gets( x, y, line, len );
      switch( j ) {
         case RIGHT:
            if( i != len ) {
               w_printf( "\033C" ); i++;
            } else
                outb( 007 );
            break;
         case LEFT:
            if( i != 0 ) {
               w_printf( "\033D" ); i--;
            } else
                outb( 007 );
            break;
         case 0177:
            if( i != 0 ) {
               i--;
               for( j = i; j < len; j++ )
                  line[ j ] = line[ j + 1 ];
               line[ len - 1 ] = ' '; line[ len ] = '\000';
               w_printf( "\033D%s", &line[ i ] ); 
               wdca( x + i, y );
            } else
                outb( 007 );
            break;
         default:
            if( j == UP || j == DOWN || j == CR || j == CNTRLC )
               return( j );
            if( j < ' ' || j > DELETE ) {
               outb( 007 ); continue;
            }
            if( i == len )
               outb( 007 );
            else {
               for( n = i; n < len; n++ ) {
                  t = line[ n ] ;
                  line[ n ] = j;
                  j = t;
               }
               line[ len ] = '\000';
               w_printf( "%s", &line[ i ] );
               i++; wdca( x + i, y );
            }
      }
   }
}
             