Beispiel #1
0
struct wok_module *
mod_load(const char *path, const char *opts, char *errbuf,
    size_t errlen)
{
	int (*loadf)(struct pscfs *);
	struct wok_module *wm;
	void *h;
	int rc;

	h = dlopen(path, RTLD_NOW);
	if (h == NULL) {
		snprintf(errbuf, LINE_MAX, "%s\n", dlerror()); 
		fprintf(stderr, errbuf);
		return (NULL);
	}

	loadf = dlsym(h, "pscfs_module_load");
	if (loadf == NULL) {
		dlclose(h);
		snprintf(errbuf, LINE_MAX,
		    "symbol pscfs_module_load undefined.\n");
		fprintf(stderr, errbuf);
		return (NULL);
	}

	wm = PSCALLOC(sizeof(*wm));
	wm->wm_path = pfl_strdup(path);
	wm->wm_handle = h;
	wm->wm_opts = pfl_strdup(opts);
	wm->wm_module.pf_private = wm;
	pflfs_module_init(&wm->wm_module, opts);
	rc = loadf(&wm->wm_module);

	/*
	 * XXX XXX XXX
	 * This is a complete hack but this flush somehow avoids a bunch
	 * of zeroes from ending up in the log...
	 * XXX XXX XXX
	 */
	fflush(stderr);

	if (rc) {
		wm->wm_module.pf_handle_destroy = NULL;
		pflfs_module_destroy(&wm->wm_module);

		dlclose(h);
		PSCFREE(wm->wm_path);
		PSCFREE(wm);
		psclog_warnx("module failed to load: rc=%d module=%s",
		    rc, path);
		strlcpy(errbuf, strerror(rc), errlen);
		return (NULL);
	}
	return (wm);
}
Beispiel #2
0
inline float GetInvXRes() {
  return loadf( 0, TRAX_INV_XRES );
}
Beispiel #3
0
inline float GetInvYRes() {
  return loadf( 0, TRAX_INV_YRES );
}
Beispiel #4
0
Datei: tree.c Projekt: kahrs/cda
Value
eval(Node *tp)
{

	switch(tp->code) {
	case 0:
		return ~0L;
	case ELIST:
		if(tp->t1 != 0)
			eval(tp->t1);
		if(tp->t2 != 0)
			eval(tp->t2);
		return(~0L);
	case ASSIGN:
		fprintf(stderr, "eval: case ASSIGN\n");
		return(~0L);
	case DONTCARE:
		fprintf(stderr, "eval: case DONTCARE\n");
		return(~0L);
	case LAND:
		return(eval(tp->t1) && eval(tp->t2));
	case LOR:
		return(eval(tp->t1) || eval(tp->t2));
	case AND:
		return(eval(tp->t1) & eval(tp->t2));
	case OR:
		return(eval(tp->t1) | eval(tp->t2));
	case XOR:
		return(eval(tp->t1) ^ eval(tp->t2));
	case FLONE:
		return(flone(eval(tp->t1)));
	case FRONE:
		return(frone(eval(tp->t1)));
	case GREY:
		return(btog(eval(tp->t1)));
	case NEG:
		return(-eval(tp->t1));
	case NOT:
		return(!eval(tp->t1));
	case COM:
		return(~eval(tp->t1));
	case ADD:
		return(eval(tp->t1) + eval(tp->t2));
	case SUB:
		return(eval(tp->t1) - eval(tp->t2));
	case MUL:
		return(eval(tp->t1) * eval(tp->t2));
	case DIV:
		return(eval(tp->t1) / eval(tp->t2));
	case MOD:
		return(eval(tp->t1) % eval(tp->t2));
	case LT:
		return(eval(tp->t1) < eval(tp->t2));
	case GT:
		return(eval(tp->t1) > eval(tp->t2));
	case EQ:
		return(eval(tp->t1) == eval(tp->t2));
	case NE:
		return(eval(tp->t1) != eval(tp->t2));
	case GE:
		return(eval(tp->t1) >= eval(tp->t2));
	case LE:
		return(eval(tp->t1) <= eval(tp->t2));
	case LS:
		return(eval(tp->t1) << eval(tp->t2));
	case RS:
		return(eval(tp->t1) >> eval(tp->t2));
	case CND:
		if (eval(tp->t1)) {
			tp = tp->t2;
			return(eval(tp->t1));
		}
		tp = tp->t2;
		return(eval(tp->t2));
	case SWITCH:
	{
		Value val, i;
		Node *def;

		def = 0;
		val = eval(tp->t1);
		i = 0;
		for(tp = tp->t2; tp; tp = tp->t2) {
			if(tp->code == ALT) {
				if(tp->t1) {
					i = eval(tp->t1);
					continue;
				}
				if(def != 0) {
					fprintf(stderr, "more than one default\n");
					exits("error");;
				}
				tp = tp->t2;
				if(tp == 0)
					break;
				if(tp->code != CASE)
					break;
				def = tp->t1;
				continue;
			}
			if(tp->code != CASE)
				break;
			if(i == val)
				return eval(tp->t1);
			i++;
		}
		if(def != 0)
			return eval(def);
		fprintf(stderr, "decimal selector value %ld\n",val);
		exits("error");;
	}
	case EQN:
	case INPUT:
		hp = (Hshtab*)tp->t1;
		return(hp->val);
	case FIELD:
		hp = (Hshtab*)tp->t1;
		return(loadf(hp));
	case NUMBER:
		return((Value)tp->t1);
	default:
		fprintf(stderr,"unknown eval op %d\n", tp->code);
		exits("error");;
	}
	return ~0;
}