pointer OUTB(context *ctx, int n, pointer argv[]) { int port, val; port=intval(argv[0]); val=intval(argv[1]); outb(val, port); return(argv[1]); }
/* Function: mdlCheckParameters ============================================= * Abstract: * Validate our parameters to verify they are okay. */ static void mdlCheckParameters(SimStruct *S) { unsigned int i; if ( !mxIsChar(paramHostName) || (mxGetNumberOfElements(paramHostName) < 1) || (mxGetNumberOfElements(paramHostName) > 100) ) { ssSetErrorStatus(S, "The Host Name parameter must be a nonempty string with max. 100 elements."); return; } if ( (!IS_PARAM_DOUBLE(paramImageSizeXYN)) || (mxGetNumberOfElements(paramImageSizeXYN) < 2) || (mxGetNumberOfElements(paramImageSizeXYN) > 3) ) { ssSetErrorStatus(S, "The image size must have two elements [X Y] or three elements [X Y frames]."); return; } else { for( i=0; i<mxGetNumberOfElements(paramImageSizeXYN); i++ ) { if( intval(mxGetPr(paramImageSizeXYN)[i]) <= 0 ) { ssSetErrorStatus(S, "The image dimensions have to be positive integers."); return; } } } if ( (!IS_PARAM_DOUBLE(paramPixelFormat)) || (mxGetNumberOfElements(paramPixelFormat) != 1) ) { ssSetErrorStatus(S, "Pixel format must be a scalar"); return; } else if (intval(mxGetPr(paramPixelFormat)[0]) != 1 && intval(mxGetPr(paramPixelFormat)[0]) != 5) { ssSetErrorStatus(S, "Pixel format must be Mono8(1) or Rgb24(5)"); return; } if ( (!IS_PARAM_DOUBLE(paramTimeout)) || (mxGetNumberOfElements(paramTimeout) != 1) ) { ssSetErrorStatus(S, "Timeout must be a scalar"); return; } else if (mxGetPr(paramTimeout)[0] < 0) { ssSetErrorStatus(S, "Timeout must be non-negative"); return; } if ( (!IS_PARAM_DOUBLE(paramSampleTime)) || (mxGetNumberOfElements(paramSampleTime) != 1) ) { ssSetErrorStatus(S, "Wrong sample time."); return; } if ( !((mxGetPr(paramSampleTime)[0] == -1) || (mxGetPr(paramSampleTime)[0] > 0)) ) { ssSetErrorStatus(S, "The sample time must be inherited (-1) or discrete (a positive number)."); return; } }
static void mdlSetWorkWidths(SimStruct *S) { int_T nq = 0; if( mxGetNumberOfElements(paramQuaternionIndex) == 2 ) { nq = intval(mxGetPr(paramQuaternionIndex)[1]) - intval(mxGetPr(paramQuaternionIndex)[0]) + 1; nq = nq / 4; } ssSetNumContStates(S, 0); ssSetNumDiscStates(S, 0); ssSetNumRWork(S, 0); ssSetNumIWork(S, 1); ssSetNumPWork(S, 1); ssSetNumDWork(S, (nq > 0 ? 3 : 2)); ssSetDWorkWidth(S, 0, ssGetInputPortWidth(S, 0)); ssSetDWorkWidth(S, 1, ssGetInputPortWidth(S, 0)); ssSetDWorkDataType(S, 0, SS_DOUBLE); ssSetDWorkDataType(S, 1, SS_DOUBLE); if( nq ) { ssSetDWorkWidth(S, 2, ssGetInputPortWidth(S, 0)); ssSetDWorkDataType(S, 2, SS_DOUBLE); } ssSetNumModes(S, 0); }
vector<Interval> insert(vector<Interval> &intervals, Interval newInterval) { vector<Interval> ret; size_t size = intervals.size(); if (size == 0) { ret.push_back(newInterval); return ret; } bool inserted = false; int start = newInterval.start, end = newInterval.end; if (start > end) { return intervals; } for (size_t i = 0; i < size; i++) { if (inserted || start > intervals[i].end) { ret.push_back(intervals[i]); continue; } if (end < intervals[i].start) { Interval intval(start, end); ret.push_back(intval); ret.push_back(intervals[i]); inserted = true; } else { start = min(start, intervals[i].start); end = max(end, intervals[i].end); } } if (!inserted) { Interval intval(start, end); ret.push_back(intval); } return ret; }
/* * (set-video-mode <width> <height> <bits per pixel>?) or * (set-video-mode <width> <height> <bits per pixel> <mode flags>+) * * where <symbols> are: * swsurface * hwsurface * asyncblit * anyformat * hwpalette * doublebuf * fullscreen * opengl * openglblit * resizable * noframe * */ cons_t* set_video_mode(cons_t* p, environment_t*) { assert_length_min(p, 2); assert_type(INTEGER, car(p)); assert_type(INTEGER, cadr(p)); // dimension int x = intval(car(p)); int y = intval(cadr(p)); // default values int bits = 32; uint32_t mode = 0; // bits per pixel if ( length(p) > 2 && integerp(caddr(p)) ) bits = intval(caddr(p)); // mode options if ( length(p) > 3 ) { cons_t *opts = symbolp(caddr(p))? cddr(p) : symbolp(cadddr(p))? cdddr(p) : nil();; DPRINT(opts); for ( cons_t *s = opts; !nullp(s); s = cdr(s) ) { assert_type(SYMBOL, car(s)); std::string sym = symbol_name(car(s)); for ( size_t n=0; n < num_sdl_flags; ++n ) if ( sym == sdl_flags[n].key ) { mode |= sdl_flags[n].value; goto NEXT_FLAG; } raise(runtime_exception("Unknown SDL video mode flag: " + sym)); NEXT_FLAG: continue; } } SDL_Surface *screen = SDL_SetVideoMode(x, y, bits, mode); if ( screen == NULL ) raise(runtime_exception(SDL_GetError())); return pointer( new pointer_t("sdl-surface", reinterpret_cast<void*>(screen))); }
void load_high_scores() { FILE *hiscores_file = fopen(options.full_path("hiscores"), "r"); num_high_scores = 0; if (!hiscores_file) { return; } char line[256]; char *not_empty; while (!feof(hiscores_file)) { // Get name not_empty = fgets(line, 256, hiscores_file); chop(line); if (line[0] == '\0' || !not_empty) break; strcpy(high_scores[num_high_scores].name, line); // Get score not_empty = fgets(line, 256, hiscores_file); chop(line); if (line[0] == '\0' || !not_empty) break; s32 the_score; intval(line, &the_score); high_scores[num_high_scores].score = the_score; num_high_scores++; } fclose(hiscores_file); }
struct val *parse_val(void) { next(); switch (tok->type) { case INT: return intval(atoi(tok->val)); case REAL: return realval(atof(tok->val)); case STRING: return strval(tok->val); case TRUE: return boolval(true); case FALSE: return boolval(false); case CHAR: return charval(tok->val[1]); default: syntaxerror("expected a value, not %s", tok->val); return intval(0); } }
void profile_load_profile(map <string, string> &account) { map <string, string> field; if(DB_TYPE==1) { _profile_get_fields(); redis_multi(field, "HGETALL profile_values:%d", intval(account["uid"]) ); for( map <string, string>::iterator i = profile_field.begin(), end = profile_field.end(); i != end; i++ ) { account[ i->first ] = field[ i->second ]; } } if(DB_TYPE==2) { MYSQL_RES *result; result = db_querya("SELECT f.name, f.type, v.value FROM profile_fields f INNER JOIN profile_values v ON f.fid = v.fid WHERE uid = %s", account["uid"].c_str()); while( db_fetch( result, field ) ) { if (!isset(account[field["name"]]) ) { account[field["name"]] = field["value"]; } } } }
pointer IOPERM(context *ctx, int n, pointer argv[]) { int val, stat; val= intval(argv[0]); stat= ioperm(0, 0x3ff, val); if (stat<0) { error("IOPERM failed because of insufficient priviledge");} return(T); }
nialptr to_real(nialptr x) { nialptr z, xi; nialint i, t = tally(x); int v = valence(x); double r = 0.0; /* create the result container */ z = new_create_array(realtype, v, 0, shpptr(x, v)); for (i = 0; i < t; i++) { int k; xi = fetch_array(x, i); k = kind(xi); if (k == realtype) r = *pfirstreal(xi); else /* must be boolean or integer */ if (k == inttype) r = 1.0 * intval(xi); else if (k == booltype) r = 1.0 * boolval(xi); store_real(z, i, r); } return (z); }
void print(FILE *f, value_t v) { value_t cd; switch (tag(v)) { case TAG_NUM: fprintf(f, "%d", numval(v)); break; case TAG_SYM: fprintf(f, "%s", ((symbol_t*)ptr(v))->name); break; case TAG_BUILTIN: fprintf(f, "#<builtin %s>", builtin_names[intval(v)]); break; case TAG_CONS: fprintf(f, "("); while (1) { print(f, car_(v)); cd = cdr_(v); if (!iscons(cd)) { if (cd != NIL) { fprintf(f, " . "); print(f, cd); } fprintf(f, ")"); break; } fprintf(f, " "); v = cd; } break; } }
Color Tile::parse_palette_color(const char *string) { u16 current_string_char = 2; u8 current_num_string_char = 0; char num_string[10]; u8 current_color = 0; s32 colors[3]; while (string[current_string_char]) { switch (string[current_string_char]) { case ',': case '\n': num_string[current_num_string_char] = '\0'; current_num_string_char = 0; intval(num_string, &colors[current_color]); current_color++; break; default: num_string[current_num_string_char] = string[current_string_char]; current_num_string_char++; } current_string_char++; } return RGB(colors[0], colors[1], colors[2]); }
struct expr *prefix(char *expect) { struct expr *res = NULL; int toktype = tok->type; switch (toktype) { case IDENTIFIER: return identexpr(strdup(tok->val)); case LPAREN: res = expression(0); eat(RPAREN); return res; case PLUS: case MINUS: case NOT: return unopexpr(toktype, expression(lbp(toktype) - 1)); case REAL: return expr_from_val(realval(atof(tok->val))); case INT: return expr_from_val(intval(atoi(tok->val))); case CHAR: return expr_from_val(charval(tok->val[1])); case STRING: return expr_from_val(strval(strdup(tok->val))); case TRUE: return expr_from_val(boolval(1)); case FALSE: return expr_from_val(boolval(0)); case NULLKW: return nullexpr(); default: syntaxerror("expected %s, not %s", expect, tok->val); return NULL; } }
pointer EUSPINHOLE_CAMERA_MODEL_DISPOSE(register context *ctx,int n,pointer *argv) { ckarg(1); image_geometry::PinholeCameraModel *pcm = (image_geometry::PinholeCameraModel *)(intval(argv[0])); delete(pcm); return(T); }
static void mdlSetOutputPortWidth(SimStruct *S, int_T port, int_T outputPortWidth) { if( ((ssGetInputPortWidth(S, 0) != DYNAMICALLY_SIZED) && (ssGetInputPortWidth(S, 0) != outputPortWidth)) || \ ((ssGetOutputPortWidth(S, 1) != DYNAMICALLY_SIZED) && (ssGetOutputPortWidth(S, 1) != outputPortWidth)) ) { ssSetErrorStatus(S,"xdot and x must have the same size"); return; } if( intval(mxGetScalar(paramInitialConditionSource)) > 1 ) { if( (ssGetInputPortWidth(S, 1) != DYNAMICALLY_SIZED) && (ssGetInputPortWidth(S, 1) != outputPortWidth) ) { ssSetErrorStatus(S,"xdot, x0 and x must have the same size"); return; } ssSetInputPortWidth(S, 1, outputPortWidth); } else { if( (mxGetNumberOfElements(paramInitialCondition) != 1) && (mxGetNumberOfElements(paramInitialCondition) != outputPortWidth) ) { ssSetErrorStatus(S,"xdot, x0 and x must have the same size"); return; } } ssSetInputPortWidth(S, 0, outputPortWidth); ssSetOutputPortWidth(S, 1, outputPortWidth); }
u16 global_lookup(struct global_state *gstate, const char *name, mtype *t) /* Returns: the index for global variable name in environment. If name doesn't exist yet, returns GLOBAL_INVALID Also sets *t to its type */ { struct symbol *pos; if (table_lookup(gstate->global, name, &pos)) { u16 offset = (u16)intval(pos->data); *t = intval(gstate->types->data[offset]); return offset; } return GLOBAL_INVALID; }
char *test_sort_key( struct job *job ) { char *cmpstr = 0; /* first key is DONE_TIME - done jobs come last */ cmpstr = intval(DONE_TIME,&job->info,cmpstr); /* next key is REMOVE_TIME - removed jobs come before last */ cmpstr = intval(REMOVE_TIME,&job->info,cmpstr); /* next key is ERROR - error jobs jobs come before removed */ cmpstr = strzval(ERROR,&job->info,cmpstr); /* next key is HOLD - before the error jobs */ cmpstr = intval(HOLD_CLASS,&job->info,cmpstr); cmpstr = intval(HOLD_TIME,&job->info,cmpstr); /* next key is MOVE - before the held jobs */ cmpstr = strnzval(MOVE,&job->info,cmpstr); /* now by priority */ if( Ignore_requested_user_priority_DYN == 0 ){ cmpstr = strval(PRIORITY,&job->info,cmpstr,Reverse_priority_order_DYN); } /* now we do TOPQ */ cmpstr = revintval(PRIORITY_TIME,&job->info,cmpstr); /* now we do FirstIn, FirstOut */ cmpstr = intval(JOB_TIME,&job->info,cmpstr); cmpstr = intval(JOB_TIME_USEC,&job->info,cmpstr); /* now we do by job number if two at same time (very unlikely) */ cmpstr = intval(NUMBER,&job->info,cmpstr); DEBUG4("test_sort_key: cmpstr '%s'", cmpstr ); return(cmpstr); }
/* read the flags from the list (open brace has already been read) * stop when the closing brace is found, or on eof */ static int get_flags_from_list(GScanner *scan) { GTokenType tok; int flags = 0; do { tok = g_scanner_get_next_token(scan); // d3_printf("flags "); // print_token(scan, tok); if (tok == '(') { skip_list(scan); continue; } if (tok != G_TOKEN_SYMBOL) continue; switch(intval(scan)) { case SYM_ASTROM: flags |= CAT_ASTROMET; break; case SYM_VAR: flags |= CAT_VARIABLE; break; case SYM_CENTERED: flags |= CPHOT_CENTERED; break; case SYM_NOT_FOUND: flags |= CPHOT_NOT_FOUND; break; case SYM_UNDEF_ERR: flags |= CPHOT_UNDEF_ERR; break; case SYM_HAS_BADPIX: flags |= CPHOT_BADPIX; break; case SYM_BRIGHT: flags |= CPHOT_BURNED; break; case SYM_NO_COLOR: flags |= CPHOT_NO_COLOR; break; case SYM_TRANSFORMED: flags |= CPHOT_TRANSFORMED; break; case SYM_ALL_SKY: flags |= CPHOT_ALL_SKY; break; case SYM_INVALID: flags |= CPHOT_INVALID; break; default: break; } } while (tok != ')' && tok != G_TOKEN_EOF); // d3_printf("flags is %x\n", flags / 16); return flags; }
string profile_edit() { map <string, string> item; map <string, map<string,string> > form; string fid = arg(3); if(isset( fid ) ) { if(DB_TYPE==1) { if( redis_multi( item, "HGETALL profile_fields:%d", intval(fid) ) ) { form["fid"]["#type"] = "hidden"; form["fid"]["#value"] = num( fid ); } } if(DB_TYPE==2) { MYSQL_RES *result = db_querya("SELECT * FROM profile_fields WHERE fid=%d", fid.c_str() ); if( db_fetch( result, item ) ) { form["fid"]["#type"] = "hidden"; form["fid"]["#value"] = item["fid"]; } } } form["title"]["#type"] = "textfield"; form["title"]["#title"] = "Title"; form["title"]["#description"] = "The title of the new field. The title will be shown to the user. An example title is \"Favorite color\""; form["title"]["#required"] = _TRUE; form["title"]["#value"] = item["title"]; form["title"]["#weight"] = "1"; form["name"]["#type"] = "textfield"; form["name"]["#title"] = "Form name"; form["name"]["#description"] = "The name of the field. The form name is not shown to the user but used internally in the HTML code and URLs. Unless you know what you are doing, it is highly recommended that you prefix the form name with <code>profile_</code> to avoid name clashes with other fields. Spaces or any other special characters except dash (-) and underscore (_) are not allowed. An example name is \"profile_favorite_color\" or perhaps just \"profile_color\""; form["name"]["#required"] = _TRUE; form["name"]["#value"] = item["name"]; form["name"]["#weight"] = "2"; form["explanation"]["#type"] = "textarea"; form["explanation"]["#title"] = "Explanation"; form["explanation"]["#description"] = "An optional explanation to go with the new field. The explanation will be shown to the user."; form["explanation"]["#value"] = item["explanation"]; form["explanation"]["#weight"] = "3"; form["submit"]["#type"] = "submit"; form["submit"]["#value"] = "Save field"; form["submit"]["#weight"] = "4"; return get_form("profile_edit", form); }
BallSprite *GameScene_Box2D::createSprite(Vec2 &pos, Vec2 &velocity){ std::random_device rd; std::mt19937 mt(rd()); std::uniform_real_distribution<double> intval(0,3); int val = (int)intval(mt); __String *filename; BallSprite::ballType type; switch (val) { case 0: filename = String::create("ball.png"); type = BallSprite::ballType::kRed; break; case 1: filename = String::create("pur_ball.png"); type = BallSprite::ballType::kPurple; break; case 2: filename = String::create("blue_ball.png"); type = BallSprite::ballType::kBrue; break; case 3: filename = String::create("yellow_ball.png"); type = BallSprite::ballType::kYellow; break; default: filename = String::create("ball.png"); type = BallSprite::ballType::kBrue; break; } //BallSprite *ball = BallSprite::createBallSprite(this, _world, filename->getCString()); BallSprite *ball = BallSprite::createParticleSprite(this, _world, _particleSystem, _particleGroup, filename->getCString()); //ball->setPosition(pos); ball->setParticlePpos(_particleSystem, _particleGroup, pos.x, pos.y, velocity.x, velocity.y); ball->setTag(spriteType::kBall); ball->setBallType(type); _bollArray.push_back(ball); return ball; }
pointer EUSPINHOLE_CAMERA_MODEL_FROM_CAMERA_INFO(register context *ctx,int n,pointer *argv) { ckarg(3); uint8_t* serialized_camera_info = (uint8_t *)(argv[1]->c.str.chars); uint32_t serialization_length = intval(argv[2]); image_geometry::PinholeCameraModel *pcm = (image_geometry::PinholeCameraModel *)(intval(argv[0])); sensor_msgs::CameraInfo camera_info; boost::shared_array<uint8_t> buffer(new uint8_t[serialization_length]); for(int i=0; i<serialization_length; ++i){ buffer[i] = serialized_camera_info[i]; } ros::serialization::IStream stream(buffer.get(), serialization_length); ros::serialization::Serializer<sensor_msgs::CameraInfo>::read(stream, camera_info); pcm->fromCameraInfo(camera_info); return (T); }
string profile_delete() { string fid = arg(3); if(isset( fid ) ) { if(DB_TYPE==1) { redis_command("SREM profile_fields %d", intval(fid) ); redis_command("DEL profile_fields:%d", intval(fid) ); } if(DB_TYPE==2) { db_querya("DELETE FROM profile_fields WHERE fid=%d", fid.c_str() ); } } redirect( url("admin/profile") ); return ""; }
void iloaddefs(void) { nialptr nm, x = apop(); int mode; /* get the file name as a Nial array */ if (atomic(x) || kind(x) == chartype) nm = x; else if (kind(x) == atype) nm = fetch_array(x, 0); else { buildfault("invalid file name"); freeup(x); return; } mode = 0; /* default to silent mode */ if (kind(x) == atype && tally(x) == 2) { /* argument has a mode filed, select it */ nialptr it = fetch_array(x, 1); if (kind(it) == inttype) mode = intval(it); if (kind(it) == booltype) mode = boolval(it); } /* try to put filename into gcharbuf */ if (!ngetname(nm, gcharbuf)) { buildfault("invalid file name"); freeup(x); } else { /* check the extension as .ndf */ check_ext(gcharbuf, ".ndf",NOFORCE_EXTENSION); freeup(x); /* do freeup here so file name doesn't show in iusedspace */ /* load the definition file */ if (loaddefs(true, gcharbuf, mode)) { apush(Nullexpr); } else buildfault(errmsgptr); /* this is safe since call is from iloaddefs */ } #ifdef DEBUG memchk(); #endif }
string Key::to_string() const { switch (type()) { case int_key_e: return dl_pstr ("%d", intval()); case string_key_e: return dl_pstr ("%s", strval().c_str()); case any_key_e: return "Any"; default: dl_unreachable("..."); } return "fail"; }
void aggregator_remove( map <string, string> feed ) { if(DB_TYPE==1) { string iid; REDIS_RES * result = redis_query("SMEMBERS aggregator_item:fid:%d", intval(feed["fid"]) ); while( redis_fetch( result, iid ) ) { redis_command("DEL aggregator_item:%d", intval(iid) ); redis_command("SREM aggregator_item %d", intval(iid) ); } redis_command("DEL aggregator_item:fid:%d", intval(feed["fid"]) ); redis_command("HMSET aggregator_feed:%d checked %d etag %s modified %d", intval(feed["fid"]), 0, "", 0 ); } if(DB_TYPE==2) { db_querya("DELETE FROM aggregator_item WHERE fid = %d", feed["fid"].c_str() ); db_querya("UPDATE aggregator_feed SET checked = 0, etag = '', modified = 0 WHERE fid = %d", feed["fid"].c_str() ); } set_page_message("The news items from "+feed["title"]+" have been removed."); }
BallSprite *GameScene_Chipmunk::createSprite(Vec2 &pos){ std::random_device rd; std::mt19937 mt(rd()); std::uniform_real_distribution<double> intval(0,3); int val = (int)intval(mt); __String *filename; BallSprite::ballType type; switch (val) { case 0: filename = String::create("ball.png"); type = BallSprite::ballType::kRed; break; case 1: filename = String::create("pur_ball.png"); type = BallSprite::ballType::kPurple; break; case 2: filename = String::create("blue_ball.png"); type = BallSprite::ballType::kBrue; break; case 3: filename = String::create("yellow_ball.png"); type = BallSprite::ballType::kYellow; break; default: filename = String::create("ball.png"); type = BallSprite::ballType::kBrue; break; } BallSprite *ball = BallSprite::createBallSprite(this, filename->getCString()); ball->setCenter(pos); ball->setTag(spriteType::kBall); ball->setBallType(type); _bollArray.push_back(ball); return ball; }
void translation_save() { map <string, string> node = cur_node; if(DB_TYPE==1) { redis_command("HSET node:%d language %s", intval(node["nid"]), node["language"].c_str() ); } if(DB_TYPE==2) { db_querya("UPDATE node SET language='%s' WHERE nid=%d", node["language"].c_str(), node["nid"].c_str() ); } }
/* read the position from the list (open brace has already been read) * stop when the closing brace is found, or on eof */ static int get_centroid_from_rcp(GScanner *scan, struct cat_star *cats) { GTokenType tok; int i; for (i = 0; i < NOISE_LAST; i++) cats->noise[i] = 0.0; cats->flags |= INFO_POS; do { tok = g_scanner_get_next_token(scan); // d3_printf("flags "); // print_token(scan, tok); if (tok != G_TOKEN_SYMBOL) continue; switch(intval(scan)) { case SYM_X: tok = g_scanner_get_next_token(scan); if (tok == G_TOKEN_FLOAT) cats->pos[POS_X] = floatval(scan); break; case SYM_Y: tok = g_scanner_get_next_token(scan); if (tok == G_TOKEN_FLOAT) cats->pos[POS_Y] = floatval(scan); break; case SYM_DX: tok = g_scanner_get_next_token(scan); if (tok == G_TOKEN_FLOAT) cats->pos[POS_DX] = floatval(scan); break; case SYM_DY: tok = g_scanner_get_next_token(scan); if (tok == G_TOKEN_FLOAT) cats->pos[POS_DY] = floatval(scan); break; case SYM_XERR: tok = g_scanner_get_next_token(scan); if (tok == G_TOKEN_FLOAT) cats->pos[POS_XERR] = floatval(scan); break; case SYM_YERR: tok = g_scanner_get_next_token(scan); if (tok == G_TOKEN_FLOAT) cats->pos[POS_YERR] = floatval(scan); break; default: break; } } while (tok != ')' && tok != G_TOKEN_EOF); return 0; }
void aggregator_save_item(map <string, string> edit) { if(DB_TYPE==1) { if ( isset(edit["iid"]) && isset(edit["title"]) ) { redis_command("HMSET aggregator_item:%d fid %d title %s link %s author %s description %s timestamp %d guid %s", intval(edit["iid"]), intval(edit["fid"]), edit["title"].c_str(), edit["link"].c_str(), edit["author"].c_str(), edit["description"].c_str(), intval(edit["timestamp"]), edit["guid"].c_str() ); } else if ( isset(edit["iid"]) ) { redis_command("SREM aggregator_item:fid:%d %d", redis_int("HGET aggregator_item:%d fid", intval(edit["iid"]) ), intval(edit["iid"]) ); redis_command("SREM aggregator_item %d", intval(edit["iid"]) ); redis_command("DEL aggregator_item:%d", intval(edit["iid"]) ); } else if ( isset( edit["title"] ) && isset( edit["link"] ) ) { edit["iid"] = redis_str("INCR aggregator_item:ids"); redis_command("SADD aggregator_item %d", intval(edit["iid"]) ); redis_command("SADD aggregator_item:fid:%d %d", intval(edit["fid"]), intval(edit["iid"]) ); redis_command("HMSET aggregator_item:%d fid %d title %s link %s author %s description %s timestamp %d guid %s", intval(edit["iid"]), intval(edit["fid"]), edit["title"].c_str(), edit["link"].c_str(), edit["author"].c_str(), edit["description"].c_str(), intval(edit["timestamp"]), edit["guid"].c_str() ); } } if(DB_TYPE==2) { if ( isset(edit["iid"]) && isset(edit["title"]) ) { db_querya("UPDATE aggregator_item SET title = '%s', link = '%s', author = '%s', description = '%s', guid = '%s', timestamp = %d WHERE iid = %d", edit["title"].c_str(), edit["link"].c_str(), edit["author"].c_str(), edit["description"].c_str(), edit["guid"].c_str(), edit["timestamp"].c_str(), edit["iid"].c_str() ); } else if ( isset(edit["iid"]) ) { db_querya("DELETE FROM aggregator_item WHERE iid = %d", edit["iid"].c_str() ); } else if ( isset( edit["title"] ) && isset( edit["link"] ) ) { db_querya("INSERT INTO aggregator_item (fid, title, link, author, description, timestamp, guid) VALUES (%d, '%s', '%s', '%s', '%s', %d, '%s')", edit["fid"].c_str(), edit["title"].c_str(), edit["link"].c_str(), edit["author"].c_str(), edit["description"].c_str(), edit["timestamp"].c_str(), edit["guid"].c_str() ); } edit["iid"] = db_last_insert_id(); } }
int main () { char a[3]; int i, tr; a[0] = F_QUOTE; a[1] = F_COND; a[2] = TOK_CLOSE; for (i = 0; i < 20; i++){ printf("%d:%d \n", i, intval(i)); } return 0; }