ATerm SSL_gti(ATerm x, ATerm y) { assert_is_int(x); assert_is_int(y); if(_get_int(x) > _get_int(y)) return((ATerm) ATempty); return NULL; }
ATerm SSL_srand(ATerm seed) { int val; assert_is_int(seed); val = _get_int(seed); srand(val); return (ATerm) ATempty; }
const char * get_int(const char *p, int *d) { assert( p != NULL ); assert( d != NULL ); p = _get_int(p, d); if(*p != '\n') return(NULL); else return(p + 1); }
extern int acct_gather_parse_freq(int type, char *freq) { int freq_int = -1; char *sub_str = NULL; if (!freq) return freq_int; switch (type) { case PROFILE_ENERGY: if ((sub_str = xstrcasestr(freq, "energy="))) freq_int = _get_int(sub_str + 7); break; case PROFILE_TASK: /* backwards compatibility for when the freq was only for task. */ freq_int = _get_int(freq); if ((freq_int == -1) && (sub_str = xstrcasestr(freq, "task="))) freq_int = _get_int(sub_str + 5); break; case PROFILE_FILESYSTEM: if ((sub_str = xstrcasestr(freq, "filesystem="))) freq_int = _get_int(sub_str + 11); break; case PROFILE_NETWORK: if ((sub_str = xstrcasestr(freq, "network="))) freq_int = _get_int(sub_str + 8); break; default: fatal("Unhandled profile option %d please update " "slurm_acct_gather.c " "(acct_gather_parse_freq)", type); } return freq_int; }
static int _define_station(lua_State *L, SpaceStationType &station) { station.id = s_currentStationFile; LUA_DEBUG_START(L); _get_string(L, "model", station.modelName); _get_int(L, "num_docking_ports", station.numDockingPorts); _get_bool(L, "dock_one_at_a_time", station.dockOneAtATimePlease, false); _get_float(L, "angular_velocity", station.angVel, 0.f); _get_float(L, "parking_distance", station.parkingDistance, 5000.f); _get_float(L, "parking_gap_size", station.parkingGapSize, 2000.f); _get_stage_durations(L, "dock_anim_stage_duration", station.numDockingStages, &station.dockAnimStageDuration); _get_stage_durations(L, "undock_anim_stage_duration", station.numUndockStages, &station.undockAnimStageDuration); _get_int(L, "ship_launch_stage", station.shipLaunchStage); station.dockAnimFunction = _set_global_function(L, "ship_dock_anim", station.id.c_str()); station.approachWaypointsFunction = _set_global_function(L, "ship_approach_waypoints", station.id.c_str()); LUA_DEBUG_END(L, 0); assert(!station.modelName.empty()); assert(!station.dockAnimFunction.empty()); assert(!station.approachWaypointsFunction.empty()); station.model = Pi::FindModel(station.modelName); return 0; }
/* Output procedures **********************/ void inc_O_r(void* cdata, _integer _V) { _put_int("r", _V); }/* Main procedure *************************/ int main(){ /* Context allocation */ int s = 0; struct inc_ctx* ctx = inc_new_ctx(NULL); /* Main loop */ ISATTY = isatty(0); while(1){ if (ISATTY) printf("## STEP %d ##########\n", s+1); else if(s) printf("\n"); fflush(stdout); ++s; inc_I_n(ctx, _get_int("n")); inc_step(ctx); } return 1; }
void sys_handler(struct evhttp_request *req, void *arg) { struct evbuffer *buf; int valid_cmd = 1; int raw_output = 0; int timeout = 2; int needs_escaped = 1; char * cmd; cmd = (char *) malloc(1024 * sizeof(char)); buf = evbuffer_new(); if (buf == NULL) err(1, "failed to create response buffer"); if (strncmp(_get_chars(req, "cmd", ""),"zing", 50) == 0) { evhttp_add_header(evhttp_request_get_output_headers(req), "Content-Type", "text/javascript"); sprintf(cmd, "zing_json_fetcher.sh \"%s\" %d", _get_chars(req, "artist", ""), _get_int(req, "page", 1) ); timeout = 10; raw_output = 1; } else if (strncmp(_get_chars(req, "cmd", ""),"m3u", 50) == 0) { evhttp_add_header(evhttp_request_get_output_headers(req), "Content-Type", "application/x-mpegurl"); sprintf(cmd, "zing_m3u_fetcher.sh \"%s\"", _get_chars(req, "artist", "")); timeout = 60; raw_output = 1; needs_escaped = 0; } else if (strncmp(_get_chars(req, "cmd", ""),"pls", 50) == 0) { evhttp_add_header(evhttp_request_get_output_headers(req), "Content-Type", "audio/x-scpls"); sprintf(cmd, "zing_pls_fetcher.sh \"%s\"", _get_chars(req, "artist", "")); timeout = 60; raw_output = 1; needs_escaped = 0; } else { valid_cmd = 0; } if (valid_cmd) { char * ret; char * ret_escaped; ret = (char *) malloc(102400 *sizeof(char)); pthread_t f; execstruct e; e.cmd = cmd; e.ret = ret; e.done = 0; int s, i; fprintf(stderr, "Trying to create a new exec thread... [%s]", cmd); pthread_create (&f, NULL, execworker, (void *) &e); for (i = 0; i < timeout; ++i) { sleep(1); if (e.done) { fprintf(stderr, " Done!\n"); break; } fprintf(stderr, "."); } s = pthread_cancel(f); if (s != ESRCH) { fprintf(stderr, " Timed out!\n"); sprintf(ret, "Request timed out\0"); } //fprintf(stderr, "%s\n", ret); ret_escaped = escape(ret); if (raw_output == 0) { evbuffer_add_printf(buf, "{\"valid\":%d,\"result\":\"%s\"}", valid_cmd, ret_escaped); } else { evbuffer_add_printf(buf, "%s", needs_escaped ? ret_escaped : ret); } free(ret_escaped); free(ret); } else { evbuffer_add_printf(buf, "{\"valid\":%d,\"result\":\"\"}", valid_cmd); } evhttp_send_reply(req, HTTP_OK, "OK", buf); free(cmd); }
ATerm SSL_modi(ATerm x, ATerm y) { assert_is_int(x); assert_is_int(y); return((ATerm) ATmakeInt(_get_int(x) % _get_int(y))); }
ATerm SSL_subti(ATerm x, ATerm y) { assert_is_int(x); assert_is_int(y); return((ATerm) ATmakeInt(_get_int(x) - _get_int(y))); }
static CMPIStatus _set_key_value(KValue* kv, KTag tag, const CMPIData* cd) { CMPISint64 x; /* Strip unused flags */ tag = KTypeOf(tag) | (tag & KTAG_ARRAY); kv->exists = 1; /* Keys cannot be arrays */ if (tag & KTAG_ARRAY) KReturn(ERR_TYPE_MISMATCH); /* Handle null case */ if (cd->state & CMPI_nullValue) { kv->null = 1; kv->u.uint64 = 0; KReturn(OK); } else kv->null = 0; /* Handle case with value */ switch (KTypeOf(tag)) { case KTYPE_BOOLEAN: { if (cd->type != CMPI_boolean) KReturn(ERR_TYPE_MISMATCH); kv->u.boolean = cd->value.boolean; KReturn(OK); } case KTYPE_UINT8: { if (!KOkay(_get_int(cd, &x))) KReturn(ERR_FAILED); kv->u.uint8 = x; KReturn(OK); } case KTYPE_SINT8: { if (!KOkay(_get_int(cd, &x))) KReturn(ERR_FAILED); kv->u.sint8 = x; KReturn(OK); } case KTYPE_UINT16: { if (!KOkay(_get_int(cd, &x))) KReturn(ERR_FAILED); kv->u.uint16 = x; KReturn(OK); } case KTYPE_SINT16: { if (!KOkay(_get_int(cd, &x))) KReturn(ERR_FAILED); kv->u.sint16 = x; KReturn(OK); } case KTYPE_UINT32: { if (!KOkay(_get_int(cd, &x))) KReturn(ERR_FAILED); kv->u.uint32 = x; KReturn(OK); } case KTYPE_SINT32: { if (!KOkay(_get_int(cd, &x))) KReturn(ERR_FAILED); kv->u.sint32 = x; KReturn(OK); } case KTYPE_UINT64: { if (!KOkay(_get_int(cd, &x))) KReturn(ERR_FAILED); kv->u.uint64 = x; KReturn(OK); } case KTYPE_SINT64: { if (!KOkay(_get_int(cd, &x))) KReturn(ERR_FAILED); kv->u.sint64 = x; KReturn(OK); } case KTYPE_STRING: { KString* ks = (KString*)kv; if (cd->type != CMPI_string) KReturn(ERR_FAILED); ks->value = cd->value.string; ks->chars = KChars(ks->value); KReturn(OK); } case KTYPE_REFERENCE: { KRef* kr = (KRef*)kv; if (cd->type != CMPI_ref) KReturn(ERR_FAILED); kr->value = cd->value.ref; KReturn(OK); } case KTYPE_DATETIME: { /* ATTN: implement! */ KReturn(ERR_TYPE_MISMATCH); } default: KReturn(ERR_TYPE_MISMATCH); } KReturn(OK); }