char* squeeze( char* cstr, const char* filter )
{
    if( cstr != NULL && filter != NULL )
    {
        size_t pos = 0 ;
        while( cstr[pos] != 0 )
        {
            if( has_char( filter, cstr[pos] ) ) remove_char_at( cstr, pos ) ;
            else ++pos ;
        }
    }

    return cstr ;
}
Example #2
0
int readline(lua_State *L) {
	int		rc;
	char	*temp;
	char	*termtype = getenv("TERM");

	if(!termtype) {
		fprintf(stderr, "no TERM defined!\n");
		exit(1);
	}

	ioctl(0, TCGETS, &old_termio);
	new_termio = old_termio;
	new_termio.c_lflag &= ~ECHO;
	new_termio.c_lflag &= ~ICANON;

	ioctl(0, TCSETS, &new_termio);
	

	signal(SIGQUIT, int_handler);
	signal(SIGINT, int_handler);
	signal(SIGWINCH, winch_handler);
	printf(sample);
	printf("\n");

	// Setup terminfo stuff...
	rc = setupterm((char *)0, 1, (int *)0);
	fprintf(stderr, "rc=%d\n", rc);
	
//	rc = tgetent(NULL, termtype);
//	fprintf(stderr, "rc=%d\n", rc);
//
/*	int y;
	for(y=0; strnames[y]; y++) {
		fprintf(stderr, "%d: %s\n", y, strnames[y]);
	}
	fprintf(stderr, "lines=%s\n", cursor_down);
*/
	height = lines;
	width = columns;
	printf("w=%d h=%d\n", width, height);

	col = 0;
	row = 0;

	init_terminfo_data();

	int t;
	char *x = parm_down_cursor;
	printf("p=%p (%d)\n", x, strlen(x));
//	for(t=0; t < strlen(x); t++) {
//		printf("> %d  [%c] %d\n", t, x[t], x[t]);
//	}

	printf("arm=%d, eng=%d\n",  auto_right_margin, eat_newline_glitch);

//	printf(tparm(setb, 4));
	printf("HELLO\n");
//	printf(tparm(setb, 0));

	line = malloc(8192);
	strcpy(line, sample);
	line_len = strlen(line);

	int c;

	move_to((line_len/width), line_len%width);

//	show_line();
//	fflush(stdout);

	int redraw = 1;

	while(1) {
		if(redraw) {
			redraw_line();
			redraw = 0;
		}
		fflush(stdout);


		c = read_key();

		switch(c) {

		case KEY_LEFT:
			if(((row * width)+col) > 0) move_back();
			break;

		case KEY_RIGHT:
			if(((row * width)+col) < line_len) move_on();
			break;

		case KEY_DC:
			if(((row * width)+col) < line_len) {
				remove_char_at((row * width) + col);
				redraw = 1;
			}
			break;

		case 27:
			printf("X");
			break;

		case 127:
		case 8:
			// if we are the first char of the screen then we need to backup to the
			// end of the previous line
			//
			if(((row * width)+col) > 0) {
				move_back();
				remove_char_at((row * width) + col);
				redraw = 1;
			}
			break;

		default:
			insert_char_at((row * width) + col, c);
			move_on();
			redraw = 1;
		}
	}

	return 0;
}