int main(int argc, char **argv) { size_t rawlen; uint8_t *rawdata; if (argc != 2) { fprintf(stderr, "Usage: %s <HEXDATA>\n", argv[0]); return (EXIT_FAILURE); } if (!hex_decode(argv[1], &rawdata, &rawlen)) { fprintf(stderr, "Error: unable to decode hex\n"); return (EXIT_FAILURE); } if (loadfunc(rawdata, rawlen)) { testfunc(); freefunc(); } else { free(rawdata); fprintf(stderr, "Error: load function failed\n"); return (EXIT_FAILURE); } free(rawdata); return (EXIT_SUCCESS); }
static int searcher_Croot(lua_State *L) { const wchar_t *filename; const char *name = luaL_checkstring(L, 1); const char *p = strchr(name, '.'); int stat; if(p == NULL) return 0; /* is root */ lua_pushlstring(L, name, p - name); filename = findfile(L, lua_tostring(L, -1), "cpath", LUA_CSUBSEP); if(filename == NULL) return 1; /* root not found */ if((stat = loadfunc(L, filename, name)) != 0) { if(stat != ERRFUNC) return checkload(L, 0, filename); /* real error */ else /* open function not found */ { push_utf8_string(L, filename, -1); lua_pushfstring(L, "\n\tno module " LUA_QS " in file " LUA_QS, name, lua_tostring(L, -1)); return 1; } } push_utf8_string(L, filename, -1); /* will be 2nd argument to module */ return 2; }
int searcher_dll(lua_State *L) { size_t size = 0; const char *name = luaL_checklstring(L, 1, &size); const char *filename = findfile(L, name, "cpath", false); if (filename == NULL) return 1; return checkload(L, (loadfunc(L, filename, name) == 0), filename); }
static int loader_C (lua_State *L) { const char *name = luaL_checkstring(L, 1); const char *filename = findfile(L, name, "cpath"); if (filename == NULL) return 1; /* library not found in this path */ if (loadfunc(L, filename, name) != 0) loaderror(L, filename); return 1; /* library loaded successfully */ }
static int searcher_C(lua_State *L) { const char *name = luaL_checkstring(L, 1); const wchar_t *filename = findfile(L, name, "cpath", LUA_CSUBSEP); if(filename == NULL) return 1; /* module not found in this path */ return checkload(L, (loadfunc(L, filename, name) == 0), filename); }
static BOOL init_func_ptrs(void) { HMODULE module = GetModuleHandleA("ntdll.dll"); #define loadfunc(name) if (!(p##name = (void *)GetProcAddress(module, #name))) { \ trace("GetProcAddress(%s) failed\n", #name); \ return FALSE; \ } loadfunc(NtFsControlFile) loadfunc(NtCreateNamedPipeFile) loadfunc(NtQueryInformationFile) loadfunc(NtCancelIoFile) loadfunc(RtlInitUnicodeString) /* not fatal */ module = GetModuleHandleA("kernel32.dll"); pOpenThread = (void *)GetProcAddress(module, "OpenThread"); pQueueUserAPC = (void *)GetProcAddress(module, "QueueUserAPC"); return TRUE; }
static int loader_Croot (lua_State *L) { const char *filename; const char *name = luaL_checkstring(L, 1); const char *p = strchr(name, '.'); int stat; if (p == NULL) return 0; /* is root */ lua_pushlstring(L, name, p - name); filename = findfile(L, lua_tostring(L, -1), "cpath"); if (filename == NULL) return 1; /* root not found */ if ((stat = loadfunc(L, filename, name)) != 0) { if (stat != ERRFUNC) loaderror(L, filename); /* real error */ lua_pushfstring(L, "\n\tno module " LUA_QS " in file " LUA_QS, name, filename); return 1; /* function not found */ } return 1; }
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 *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 '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, binval, bincnt); break; case 'M': /* modifier file */ check(2,"s"); addmodfile(argv[++i], curout, 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][-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 }