Esempio n. 1
0
static void
slc_init(void)
{
	struct spc *spcp;

	localchars = 1;
	for (spcp = spc_data; spcp < &spc_data[NSLC+1]; spcp++) {
		spcp->val = 0;
		spcp->valp = NULL;
		spcp->flags = spcp->mylevel = SLC_NOSUPPORT;
	}

#define	initfunc(func, flags) { \
					spcp = &spc_data[func]; \
					if ((spcp->valp = tcval(func))) { \
					    spcp->val = *spcp->valp; \
					    spcp->mylevel = SLC_VARIABLE|flags; \
					} else { \
					    spcp->val = 0; \
					    spcp->mylevel = SLC_DEFAULT; \
					} \
				    }

	initfunc(SLC_SYNCH, 0);
	/* No BRK */
	initfunc(SLC_AO, 0);
	initfunc(SLC_AYT, 0);
	/* No EOR */
	initfunc(SLC_ABORT, SLC_FLUSHIN|SLC_FLUSHOUT);
	initfunc(SLC_EOF, 0);
	initfunc(SLC_SUSP, SLC_FLUSHIN);
	initfunc(SLC_EC, 0);
	initfunc(SLC_EL, 0);
	initfunc(SLC_EW, 0);
	initfunc(SLC_RP, 0);
	initfunc(SLC_LNEXT, 0);
	initfunc(SLC_XON, 0);
	initfunc(SLC_XOFF, 0);
	initfunc(SLC_FORW1, 0);
	initfunc(SLC_FORW2, 0);
	/* No FORW2 */

	initfunc(SLC_IP, SLC_FLUSHIN|SLC_FLUSHOUT);
#undef	initfunc

	if (slc_mode == SLC_EXPORT)
		slc_export();
	else
		slc_import(1);

}
Esempio n. 2
0
int
main(int argc, char *argv[])
{
#define	 check(ol,al)		if (argv[i][ol] || \
				badarg(argc-i-1,argv+i+1,al)) \
				goto badopt
#define	 bool(olen,var)		switch (argv[i][olen]) { \
				case '\0': var = !var; break; \
				case 'y': case 'Y': case 't': case 'T': \
				case '+': case '1': var = 1; break; \
				case 'n': case 'N': case 'f': case 'F': \
				case '-': case '0': var = 0; break; \
				default: goto badopt; }
	char	*curout = NULL;
	char	*prms = NULL;
	char	*binval = NULL;
	int	bincnt = 0;
	int	rval;
	int	i;
					/* global program name */
	progname = argv[0] = fixargv0(argv[0]);
	gargv = argv;
	gargc = argc;
					/* initialize calcomp routines early */
	initfunc();
	setcontext(RCCONTEXT);
					/* option city */
	for (i = 1; i < argc; i++) {
						/* expand arguments */
		while ((rval = expandarg(&argc, &argv, i)) > 0)
			;
		if (rval < 0) {
			sprintf(errmsg, "cannot expand '%s'", argv[i]);
			error(SYSTEM, errmsg);
		}
		if (argv[i] == NULL || argv[i][0] != '-')
			break;			/* break from options */
		if (!strcmp(argv[i], "-version")) {
			puts(VersionID);
			quit(0);
		}
		if (!strcmp(argv[i], "-defaults") ||
				!strcmp(argv[i], "-help")) {
			override_options();
			printdefaults();
			quit(0);
		}
		rval = getrenderopt(argc-i, argv+i);
		if (rval >= 0) {
			i += rval;
			continue;
		}
		switch (argv[i][1]) {
		case 'n':			/* number of cores */
			check(2,"i");
			nproc = atoi(argv[++i]);
			if (nproc <= 0)
				error(USER, "bad number of processes");
			break;
		case 'V':			/* output contributions */
			bool(2,contrib);
			break;
		case 'x':			/* x resolution */
			check(2,"i");
			xres = atoi(argv[++i]);
			break;
		case 'y':			/* y resolution */
			check(2,"i");
			yres = atoi(argv[++i]);
			break;
		case 'w':			/* warnings */
			rval = (erract[WARNING].pf != NULL);
			bool(2,rval);
			if (rval) erract[WARNING].pf = wputs;
			else erract[WARNING].pf = NULL;
			break;
		case 'e':			/* expression */
			check(2,"s");
			scompile(argv[++i], NULL, 0);
			break;
		case 'l':			/* limit distance */
			if (argv[i][2] != 'd')
				goto badopt;
			bool(3,lim_dist);
			break;
		case 'I':			/* immed. irradiance */
			bool(2,imm_irrad);
			break;
		case 'f':			/* file or force or format */
			if (!argv[i][2]) {
				check(2,"s");
				loadfunc(argv[++i]);
				break;
			}
			if (argv[i][2] == 'o') {
				bool(3,force_open);
				break;
			}
			setformat(argv[i]+2);
			break;
		case 'o':			/* output */
			check(2,"s");
			curout = argv[++i];
			break;
		case 'c':			/* input rays per output */
			check(2,"i");
			accumulate = atoi(argv[++i]);
			break;
		case 'r':			/* recover output */
			bool(2,recover);
			break;
		case 'h':			/* header output */
			bool(2,header);
			break;
		case 'p':			/* parameter setting(s) */
			check(2,"s");
			set_eparams(prms = argv[++i]);
			break;
		case 'b':			/* bin expression/count */
			if (argv[i][2] == 'n') {
				check(3,"s");
				bincnt = (int)(eval(argv[++i]) + .5);
				break;
			}
			check(2,"s");
			binval = argv[++i];
			break;
		case 'm':			/* modifier name */
			check(2,"s");
			addmodifier(argv[++i], curout, prms, binval, bincnt);
			break;
		case 'M':			/* modifier file */
			check(2,"s");
			addmodfile(argv[++i], curout, prms, binval, bincnt);
			break;
		default:
			goto badopt;
		}
	}
	if (nmods <= 0)
		error(USER, "missing required modifier argument");
					/* override some option settings */
	override_options();
					/* initialize object types */
	initotypes();
					/* initialize urand */
	if (rand_samp) {
		srandom((long)time(0));
		initurand(0);
	} else {
		srandom(0L);
		initurand(2048);
	}
					/* set up signal handling */
	sigdie(SIGINT, "Interrupt");
#ifdef SIGHUP
	sigdie(SIGHUP, "Hangup");
#endif
	sigdie(SIGTERM, "Terminate");
#ifdef SIGPIPE
	sigdie(SIGPIPE, "Broken pipe");
#endif
#ifdef SIGALRM
	sigdie(SIGALRM, "Alarm clock");
#endif
#ifdef	SIGXCPU
	sigdie(SIGXCPU, "CPU limit exceeded");
	sigdie(SIGXFSZ, "File size exceeded");
#endif
#ifdef	NICE
	nice(NICE);			/* lower priority */
#endif
					/* get octree */
	if (i == argc)
		octname = NULL;
	else if (i == argc-1)
		octname = argv[i];
	else
		goto badopt;
	if (octname == NULL)
		error(USER, "missing octree argument");

	readoct(octname, ~(IO_FILES|IO_INFO), &thescene, NULL);
	nsceneobjs = nobjects;

	marksources();			/* find and mark sources */

	setambient();			/* initialize ambient calculation */

	rcontrib();			/* trace ray contributions (loop) */

	ambsync();			/* flush ambient file */

	quit(0);	/* exit clean */

badopt:
	fprintf(stderr,
"Usage: %s [-n nprocs][-V][-r][-e expr][-f source][-o ospec][-p p1=V1,p2=V2][-b binv][-bn N] {-m mod | -M file} [rtrace options] octree\n",
			progname);
	sprintf(errmsg, "command line error at '%s'", argv[i]);
	error(USER, errmsg);
	return(1);	/* pro forma return */

#undef	check
#undef	bool
}
Esempio n. 3
0
const void*
dlopen(const char* filename, int flags)
{
    static char has_callback = 0;
    if (!has_callback) {
        _dyld_register_func_for_add_image(dlshim_image_callback);
    }
    if (!filename) {
        return &dl_self;
    } else {
        const struct mach_header* img = NULL;
        if (!img)
            img = NSAddImage(filename, NSADDIMAGE_OPTION_RETURN_ON_ERROR);
        if (!img)
            img = NSAddImage(filename,
                             NSADDIMAGE_OPTION_RETURN_ON_ERROR |
                             NSADDIMAGE_OPTION_WITH_SEARCHING);
        if (!img) {
            NSObjectFileImage fileImage;
            callback_count = 0;
            last_header = NULL;
            if (NSCreateObjectFileImageFromFile(filename, &fileImage)
                == NSObjectFileImageSuccess) {
                NSLinkModule(fileImage, filename,
                             NSLINKMODULE_OPTION_BINDNOW |
                             ((flags & RTLD_GLOBAL)?NSLINKMODULE_OPTION_PRIVATE:0) |
                             NSLINKMODULE_OPTION_RETURN_ON_ERROR);
                if (callback_count && last_header)
                    img = last_header;
            }
        }
        if (!img) {
            NSObjectFileImage fileImage;
            int i, maxi;
            const char* prefixfilename;
            maxi = lib_path_count();
            for (i = 0; i < maxi && !img; i++) {
                prefixfilename = lib_path_prefixify(i, filename);
                callback_count = 0;
                last_header = NULL;
                if (NSCreateObjectFileImageFromFile(prefixfilename, &fileImage)
                    == NSObjectFileImageSuccess) {
                    NSLinkModule(fileImage, filename,
                                 NSLINKMODULE_OPTION_BINDNOW |
                                 ((flags & RTLD_GLOBAL)?NSLINKMODULE_OPTION_PRIVATE:0) |
                                 NSLINKMODULE_OPTION_RETURN_ON_ERROR);
                    if (callback_count && last_header)
                        img = last_header;
                }
            }
        }
        if (img) {
            if (flags & RTLD_NOW) {
                NSLookupSymbolInImage(img, "",
                                      NSLOOKUPSYMBOLINIMAGE_OPTION_BIND_FULLY |
                                      NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR);
            }
            if (NSIsSymbolNameDefinedInImage(img, "__init")) {
                NSSymbol initsymbol;
                void (*initfunc) (void);
                initsymbol = NSLookupSymbolInImage(img, "__init", 0);
                initfunc = NSAddressOfSymbol(initsymbol);
                initfunc();
            }
        } else
            last_error = DLOPEN_ERROR;
        return img;
    }
}
Esempio n. 4
0
LWS_VISIBLE int
lws_plat_plugins_init(struct lws_context *context, const char * const *d)
{
	struct lws_plugin_capability lcaps;
	struct lws_plugin *plugin;
	lws_plugin_init_func initfunc;
	int m, ret = 0;
	void *v;
	uv_dirent_t dent;
	uv_fs_t req;
	char path[256];
	uv_lib_t lib;
	int pofs = 0;

#if  defined(__MINGW32__) || !defined(WIN32)
	pofs = 3;
#endif

	lib.errmsg = NULL;
	lib.handle = NULL;

	uv_loop_init(&context->pu_loop);

	lwsl_notice("  Plugins:\n");

	while (d && *d) {

		lwsl_notice("  Scanning %s\n", *d);
		m =uv_fs_scandir(&context->pu_loop, &req, *d, 0, NULL);
		if (m < 1) {
			lwsl_err("Scandir on %s failed\n", *d);
			return 1;
		}

		while (uv_fs_scandir_next(&req, &dent) != UV_EOF) {
			if (strlen(dent.name) < 7)
				continue;

			lwsl_notice("   %s\n", dent.name);

			lws_snprintf(path, sizeof(path) - 1, "%s/%s", *d,
				     dent.name);
			if (uv_dlopen(path, &lib)) {
				uv_dlerror(&lib);
				lwsl_err("Error loading DSO: %s\n", lib.errmsg);
				uv_dlclose(&lib);
				goto bail;
			}

			/* we could open it, can we get his init function? */

#if !defined(WIN32) && !defined(__MINGW32__)
			m = lws_snprintf(path, sizeof(path) - 1, "init_%s",
				     dent.name + pofs /* snip lib... */);
			path[m - 3] = '\0'; /* snip the .so */
#else
			m = lws_snprintf(path, sizeof(path) - 1, "init_%s",
				     dent.name + pofs);
			path[m - 4] = '\0'; /* snip the .dll */
#endif
			if (uv_dlsym(&lib, path, &v)) {
				uv_dlerror(&lib);
				lwsl_err("Failed to get %s on %s: %s", path,
						dent.name, lib.errmsg);
				uv_dlclose(&lib);
				goto bail;
			}
			initfunc = (lws_plugin_init_func)v;
			lcaps.api_magic = LWS_PLUGIN_API_MAGIC;
			m = initfunc(context, &lcaps);
			if (m) {
				lwsl_err("Init %s failed %d\n", dent.name, m);
				goto skip;
			}

			plugin = lws_malloc(sizeof(*plugin));
			if (!plugin) {
				uv_dlclose(&lib);
				lwsl_err("OOM\n");
				goto bail;
			}
			plugin->list = context->plugin_list;
			context->plugin_list = plugin;
			strncpy(plugin->name, dent.name, sizeof(plugin->name) - 1);
			plugin->name[sizeof(plugin->name) - 1] = '\0';
			plugin->lib = lib;
			plugin->caps = lcaps;
			context->plugin_protocol_count += lcaps.count_protocols;
			context->plugin_extension_count += lcaps.count_extensions;

			continue;

skip:
			uv_dlclose(&lib);
		}
bail:
		uv_fs_req_cleanup(&req);
		d++;
	}

	return ret;
}
Esempio n. 5
0
LWS_VISIBLE int
lws_plat_plugins_init(struct lws_context * context, const char * const *d)
{
	struct lws_plugin_capability lcaps;
	struct lws_plugin *plugin;
	lws_plugin_init_func initfunc;
	struct dirent **namelist;
	int n, i, m, ret = 0;
	char path[256];
	void *l;

	lwsl_notice("  Plugins:\n");

	while (d && *d) {
		n = scandir(*d, &namelist, filter, alphasort);
		if (n < 0) {
			lwsl_err("Scandir on %s failed\n", *d);
			return 1;
		}

		for (i = 0; i < n; i++) {
			if (strlen(namelist[i]->d_name) < 7)
				goto inval;

			lwsl_notice("   %s\n", namelist[i]->d_name);

			snprintf(path, sizeof(path) - 1, "%s/%s", *d,
				 namelist[i]->d_name);
			l = dlopen(path, RTLD_NOW);
			if (!l) {
				lwsl_err("Error loading DSO: %s\n", dlerror());
				while (i++ < n)
					free(namelist[i]);
				goto bail;
			}
			/* we could open it, can we get his init function? */
			m = snprintf(path, sizeof(path) - 1, "init_%s",
				     namelist[i]->d_name + 3 /* snip lib... */);
			path[m - 3] = '\0'; /* snip the .so */
			initfunc = dlsym(l, path);
			if (!initfunc) {
				lwsl_err("Failed to get init on %s: %s",
						namelist[i]->d_name, dlerror());
				dlclose(l);
			}
			lcaps.api_magic = LWS_PLUGIN_API_MAGIC;
			m = initfunc(context, &lcaps);
			if (m) {
				lwsl_err("Initializing %s failed %d\n",
					namelist[i]->d_name, m);
				dlclose(l);
				goto skip;
			}

			plugin = lws_malloc(sizeof(*plugin));
			if (!plugin) {
				lwsl_err("OOM\n");
				goto bail;
			}
			plugin->list = context->plugin_list;
			context->plugin_list = plugin;
			strncpy(plugin->name, namelist[i]->d_name, sizeof(plugin->name) - 1);
			plugin->name[sizeof(plugin->name) - 1] = '\0';
			plugin->l = l;
			plugin->caps = lcaps;
			context->plugin_protocol_count += lcaps.count_protocols;
			context->plugin_extension_count += lcaps.count_extensions;

			free(namelist[i]);
			continue;

	skip:
			dlclose(l);
	inval:
			free(namelist[i]);
		}
		free(namelist);
		d++;
	}

bail:
	free(namelist);

	return ret;
}
Esempio n. 6
0
void __start(void (*initfunc)()) {
    //std::set_terminate(terminate_handler);
    initfunc();
}
Esempio n. 7
0
/**
 * Initializes a plugin known by its filename.
 * @param pluginfile The plugin filename. */
void init_plugin(const char *pluginfile)
{
	int i;
	LIBPTRTYPE ptr;
	f_plug_api eventfunc, propfunc;
	f_plug_init initfunc;
	f_plug_pinit pinitfunc;
	atrinik_plugin *plugin;

	ptr = plugins_dlopen(pluginfile);

	if (!ptr)
	{
		LOG(llevBug, "BUG: Error while trying to load %s, returned: %s\n", pluginfile, plugins_dlerror());
		return;
	}

	initfunc = (f_plug_init) (plugins_dlsym(ptr, "initPlugin"));

	if (!initfunc)
	{
		LOG(llevBug, "BUG: Error while requesting 'initPlugin' from %s: %s\n", pluginfile, plugins_dlerror());
		plugins_dlclose(ptr);
		return;
	}

	eventfunc = (f_plug_api) (plugins_dlsym(ptr, "triggerEvent"));

	if (!eventfunc)
	{
		LOG(llevBug, "BUG: Error while requesting 'triggerEvent' from %s: %s\n", pluginfile, plugins_dlerror());
		plugins_dlclose(ptr);
		return;
	}

	pinitfunc = (f_plug_pinit) (plugins_dlsym(ptr, "postinitPlugin"));

	if (!pinitfunc)
	{
		LOG(llevBug, "BUG: Error while requesting 'postinitPlugin' from %s: %s\n", pluginfile, plugins_dlerror());
		plugins_dlclose(ptr);
		return;
	}

	propfunc = (f_plug_api) (plugins_dlsym(ptr, "getPluginProperty"));

	if (!propfunc)
	{
		LOG(llevBug, "BUG: Error while requesting 'getPluginProperty' from %s: %s\n", pluginfile, plugins_dlerror());
		plugins_dlclose(ptr);
		return;
	}

	plugin = malloc(sizeof(atrinik_plugin));

	for (i = 0; i < NR_EVENTS; i++)
	{
		plugin->gevent[i] = 0;
	}

	plugin->eventfunc = eventfunc;
	plugin->propfunc = propfunc;
	plugin->libptr = ptr;
	plugin->next = NULL;

	initfunc(&hooklist);
	propfunc(0, "Identification", plugin->id, sizeof(plugin->id));
	propfunc(0, "FullName", plugin->fullname, sizeof(plugin->fullname));
	LOG(llevInfo, "Plugin name: %s, known as %s\n", plugin->fullname, plugin->id);

	if (!plugins_list)
	{
		plugins_list = plugin;
	}
	else
	{
		plugin->next = plugins_list;
		plugins_list = plugin;
	}

	pinitfunc();
	LOG(llevInfo, "[Done]\n");
}