Example #1
0
CexpSym
cexpSymTblLookupRegex(char *re, int *pmax, CexpSym s, FILE *f, CexpSymTbl t)
{
CexpSym		found;
cexp_regex	*rc;
int			max=24;

	if (!pmax)
		pmax=&max;

	if (!(rc=cexp_regcomp(re))) {
		fprintf(stderr,"unable to compile regexp '%s'\n",re);
		return 0;
	}
	found=_cexpSymTblLookupRegex(rc,pmax,s,f,t);

	if (rc) cexp_regfree(rc);
	return found;
}
Example #2
0
/* alternate entries for the lookup functions */
int
lkup(char *re)
{
extern	CexpSym _cexpSymLookupRegex();
cexp_regex		*rc=0;
CexpSym 		s;
CexpModule		m;
int				ch=0,tsaved=0;
int				nl;
struct termios	tatts,rawatts;
#ifndef HAVE_TECLA
struct winsize	win;
#endif

	if (!(rc=cexp_regcomp(re))) {
		fprintf(stderr,"unable to compile regexp '%s'\n",re);
		return -1;
	}

	/* TODO should acquire the module readlock around this ?? */
	for (s=0,m=0; !ch ;) {
		unsigned char ans;

#ifdef HAVE_TECLA
		{
		GlTerminalSize	ts;
		ts.nline   = 24;
		ts.ncolumn = 80;
		cexpResizeTerminal(&ts);
		nl = ts.nline;
		}
#else
		nl = ioctl(STDIN_FD, TIOCGWINSZ,&win) ? tgetnum("li") : win.ws_row;
#endif

		if (nl<=0)
			nl=24;

		nl--;

		if (!(s=_cexpSymLookupRegex(rc,&nl,s,stdout,&m)))
			break;

		if (!tsaved) {
			tsaved=1;
			if (tcgetattr(STDIN_FD,&tatts)) {
				tsaved=-1;
			} else {
				rawatts=tatts;
				rawatts.c_lflag    &= ~ICANON;
				rawatts.c_cc[VMIN] =  1;
			}
		}
		printf("More (Y/n)?:"); fflush(stdout);
		if (tsaved>0)
			tcsetattr(STDIN_FD,TCSANOW,&rawatts);
		ch = (1 == read(STDIN_FD,&ans,1) ? ans : 'Y');
		if ('Y'==toupper(ch) || '\n'==ch || '\r'==ch)
			ch=0;
		if (tsaved>0)
			tcsetattr(STDIN_FD,TCSANOW,&tatts);
	}
	printf("\nUSER VARIABLES:\n");
	cexpVarWalk(varprint,(void*)rc);

	if (rc) cexp_regfree(rc);
	return 0;
}