Пример #1
0
/* currently, we have only very rudimentary support; just enough
 * for 'HELP'
 */
static char *
symHelp(CexpTypedVal returnVal, CexpSym sym, va_list ap)
{
CexpTypedVal v;
char *newhelp=0;
int  verbose=0;

	returnVal->type=TUCharP;
	returnVal->tv.p=sym->help;

	if ((v=va_arg(ap,CexpTypedVal))) {
		switch (v->type) {
			case TUCharP:
				newhelp = v->tv.p;
				break;
			case TUInt:
				verbose = v->tv.i;
				break;
			case TULong:
				verbose = v->tv.l;
				break;
			default:
				return "Cexp Help: Warning, invalid argument";

		}
	}
	
	if (newhelp) {
		if (sym->flags & CEXP_SYMFLG_MALLOC_HELP)
			free(sym->help);
#if defined(CONFIG_STRINGS_LIVE_FOREVER) && 0 /* might come from another module; we better make a copy */
		/* the help storage is probably an 'eternal' string */
		sym->help=newhelp;
#else
		sym->help=strdup(newhelp);
		sym->flags |= CEXP_SYMFLG_MALLOC_HELP;
#endif
	} else {
		if (verbose || !sym->help) {
			CexpSym		s;
			CexpModule	m;
			if ((s=cexpSymLkAddr(sym->value.ptv,0,0,&m)) &&
				 s==sym && m) {
				fprintf(stdout,"In module %s:\n",cexpModuleName(m));
			} else if ((s=cexpVarLookup(sym->name,0)) &&
						s==sym) {
				fprintf(stdout,"User Variable:\n");
			}
			cexpSymPrintInfo(sym,stdout);
		}
		if (sym->help)
			fprintf(stdout,"%s\n",sym->help);
		else
			fprintf(stdout,"No help available\n");
	}
	return 0;
}
Пример #2
0
	/* 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;
}

#if 0 /* obsoleted by 'help' */
int
whatis(char *name, FILE *f)
{
CexpSym			s;
int				rval=-1;
CexpModule		mod;

	if (!f) f=stdout;

	if ((s=cexpSymLookup(name,&mod))) {
		fprintf(f,"Module '%s' Symbol Table:\n", cexpModuleName(mod));
		cexpSymPrintInfo(s,f);
		rval=0;
	}
	if ((s=cexpVarLookup(name,0))) {
		fprintf(f,"User Variable:\n");
		cexpSymPrintInfo(s,f);
		rval=0;
	}
	return rval;
}
Пример #3
0
int
vars_main(int argc, char **argv)
{
char *line=0;
char *name,*v;
unsigned long value,f;
CexpSym val;
int	ch;

  cexpVarInitOnce();

  {
	CexpVar vv;
		  val=cexpVarLookup("hallo",1);
					vv = (CexpVar)((unsigned long)val - OffsetOf(CexpVar,sym));
		  printf("CexpVar size: %i, & 0x%08lx, &name: %08lx\n",
						  sizeof(*vv), (unsigned long)vv, (unsigned long)&vv->sym.name);
  }

  while (free(line),line=readline("Vars Tst>")) {

	for (name=line+1; *name && isspace(*name); name++);
	for (v=name; *v && !isspace(*v); v++);
	if (*v) {
		*v=0;
		for (v++;*v && isspace(*v); v++);
		if (*v) sscanf(v,"%li",&value);
	}
	f=0;

	switch ((ch=toupper(line[0]))) {
			default:  fprintf(stderr,"unknown command\n");
			continue; /* dont add bad commands to history */

			case 'F': cexpVarsFlush();
			break;

			case 'P': varPrintList();
			break;

			case 'T': strPrintList();
			break;

			case 'A': f=1;/* find and add */
			case 'S':     /* find and set (dont add) */
				if (!*name || !*v) {
					fprintf(stderr,"missing name and/or value\n");
					break;
				}
				val=cexpVarLookup(name,f);
				if (val) {
					val->value.type=TULong;
					val->value.ptv->l=value;
				}
			  	printf("\n%s %s\n",
						f?"adding":"setting",
						val?"success":"failure");
			break;

			case 'L':
			case 'D':
				if (!*name) {
						fprintf(stderr,"missing name\n");
						break;
				}
				if ('D'==ch) {
					printf("Deleting %s\n",
							cexpVarDelete(name) ? "success" : "failure");
				} else {
					val=cexpVarLookup(name,0);
					printf("Var %sfound: 0x%lx\n",
							val ? "" : "not ", val->value.ptv->l);
				}
			break;
	}
	add_history(line);
  }
  return 0;
}