int Cadmin_all::get_admin_alllist(uint32_t index,uint32_t *p_count, admin_all_item ** pp_list) { sprintf( this->sqlstr, "select adminid, flag, nick\ from %s order by adminid limit %u, 200 ", this->get_table_name(), index); STD_QUERY_WHILE_BEGIN( this->sqlstr,pp_list, p_count ) ; (*pp_list+i)->adminid= atoi_safe(NEXT_FIELD); (*pp_list+i)-> flag=atoi_safe(NEXT_FIELD); strncpy((*pp_list+i)->nick,NEXT_FIELD,NICK_LEN); STD_QUERY_WHILE_END(); }
int Cmsg_attime::get( su_get_msg_attime_all_in *p_in ,su_get_msg_attime_all_out *p_out ) { sprintf( this->sqlstr, "select deal_date, deal_hour, deal_minute, flag,pic_id,deal_msg from %s \ Limit %u,1", this->get_table_name(), p_in->index ); STD_QUERY_ONE_BEGIN(this-> sqlstr,NO_DEFINE_ERR ); p_out->deal_date =atoi_safe(NEXT_FIELD); p_out->deal_hour=atoi_safe(NEXT_FIELD); p_out->deal_minute=atoi_safe(NEXT_FIELD); p_out->flag=atoi_safe(NEXT_FIELD); p_out->pic_id=atoi_safe(NEXT_FIELD); BIN_CPY_NEXT_FIELD (&(p_out->msglen), 4004); STD_QUERY_ONE_END(); }
void check_atoi_safe() { char buffer[2] = "5"; buffer[1] = '\0'; int a = 5; int b = atoi_safe(buffer); printf("%d\n", b); assert(a == b); char buffer2[3] = "-5\0"; buffer[1] = '\0'; int a2 = -5; int b2 = atoi_safe(buffer2); printf("%d", b2); assert(a2 == b2); }
int Cadmin_all::get_flag(userid_t adminid ,const char * flag_type , uint32_t * flag) { sprintf( this->sqlstr, "select %s from %s where adminid=%u ", flag_type, this->get_table_name(),adminid); STD_QUERY_ONE_BEGIN(this-> sqlstr,USER_ID_NOFIND_ERR); *flag=atoi_safe(NEXT_FIELD); STD_QUERY_ONE_END(); }
int Cuser_through_time_mail::get_mails_sendtime(userid_t userid, uint32_t **pp_list, uint32_t *p_count) { sprintf(this->sqlstr, "select sendtime from %s where userid = %u", this->get_table_name(userid), userid ); STD_QUERY_WHILE_BEGIN(this->sqlstr,pp_list,p_count ); *(*pp_list+i) = atoi_safe(NEXT_FIELD); STD_QUERY_WHILE_END(); }
int Cuser_ocean_attire::get_count(userid_t userid, uint32_t itemid, uint32_t &count) { sprintf(this->sqlstr, "select count from %s where userid = %u and itemid = %u", this->get_table_name(userid), userid, itemid ); STD_QUERY_ONE_BEGIN(this->sqlstr,USER_ID_NOFIND_ERR) ; count=atoi_safe(NEXT_FIELD); STD_QUERY_ONE_END(); }
int Cuser_as_common::get_one(userid_t userid, uint32_t type, uint32_t *data) { sprintf(this->sqlstr, "select data from %s where userid = %u and type = %u", this->get_table_name(userid), userid, type ); STD_QUERY_ONE_BEGIN(this->sqlstr,USER_ID_NOFIND_ERR) ; *data=atoi_safe(NEXT_FIELD); STD_QUERY_ONE_END(); }
int Cuser_through_time_mail::get_non_dig_cnt(userid_t userid, uint32_t *count) { uint32_t now = time(0) - 24 *3600; sprintf(this->sqlstr, "select count(*) from %s where userid = %u and sendtime < %u", this->get_table_name(userid), userid, now ); STD_QUERY_ONE_BEGIN(this->sqlstr,USER_ID_NOFIND_ERR); *count = atoi_safe(NEXT_FIELD); STD_QUERY_ONE_END(); }
int Cadmin_all::get_adminid_by_nick(char *nick, uint32_t * p_adminid ) { char nick_mysql[mysql_str_len(NICK_LEN)]; set_mysql_string(nick_mysql,nick,NICK_LEN); sprintf( this->sqlstr, "select adminid \ from %s where nick='%s'", this->get_table_name(),nick_mysql); STD_QUERY_ONE_BEGIN(this-> sqlstr,USER_ID_NOFIND_ERR); *p_adminid=atoi_safe(NEXT_FIELD); STD_QUERY_ONE_END(); }
int Cuser_through_time_mail::get_mails(userid_t userid, roominfo_thr_tim_mail_t **pp_list, uint32_t *p_count) { uint32_t now = time(0) - 24 * 3600; sprintf(this->sqlstr, "select sendtime, msg from %s where userid = %u and sendtime < %u", this->get_table_name(userid), userid, now ); STD_QUERY_WHILE_BEGIN(this->sqlstr,pp_list,p_count ); (*pp_list+i)->time = atoi_safe(NEXT_FIELD); BIN_CPY_NEXT_FIELD((*pp_list + i)->msg, THROUGH_TIME_MAIL_LEN); STD_QUERY_WHILE_END(); }
int32_t loadsetup(const char *fn) { BFILE *fp; #define VL 1024 char val[VL]; int32_t i; if ((fp = Bfopen(fn, "rt")) == NULL) return -1; if (readconfig(fp, "forcesetup", val, VL) > 0) { if (atoi_safe(val) != 0) forcesetup = 1; else forcesetup = 0; } if (readconfig(fp, "fullscreen", val, VL) > 0) { if (atoi_safe(val) != 0) fullscreen = 1; else fullscreen = 0; } if (readconfig(fp, "resolution", val, VL) > 0) { i = atoi_safe(val) & 0x0f; if ((unsigned)i<13) { xdimgame = xdim2d = vesares[i][0]; ydimgame = ydim2d = vesares[i][1]; } } if (readconfig(fp, "2dresolution", val, VL) > 0) { i = atoi_safe(val) & 0x0f; if ((unsigned)i<13) { xdim2d = vesares[i][0]; ydim2d = vesares[i][1]; } } if (readconfig(fp, "xdim2d", val, VL) > 0) xdim2d = atoi_safe(val); if (readconfig(fp, "ydim2d", val, VL) > 0) ydim2d = atoi_safe(val); if (readconfig(fp, "xdim3d", val, VL) > 0) xdimgame = atoi_safe(val); if (readconfig(fp, "ydim3d", val, VL) > 0) ydimgame = atoi_safe(val); // if (readconfig(fp, "samplerate", val, VL) > 0) option[7] = (atoi_safe(val) & 0x0f) << 4; // if (readconfig(fp, "music", val, VL) > 0) { if (atoi_safe(val) != 0) option[2] = 1; else option[2] = 0; } // if (readconfig(fp, "mouse", val, VL) > 0) { if (atoi_safe(val) != 0) option[3] = 1; else option[3] = 0; } if (readconfig(fp, "bpp", val, VL) > 0) bppgame = atoi_safe(val); if (readconfig(fp, "vsync", val, VL) > 0) vsync = !!atoi_safe(val); if (readconfig(fp, "editorgridextent", val, VL) > 0) { int32_t tmp = atoi_safe(val); editorgridextent = clamp(tmp, 65536, BXY_MAX); } if (readconfig(fp, "grid", val, VL) > 0) { grid = atoi_safe(val); default_grid = grid; autogrid = (grid==9); grid = clamp(grid, 0, 8); } #ifdef POLYMER if (readconfig(fp, "rendmode", val, VL) > 0) { i = atoi_safe(val); glrendmode = i; } #endif if (readconfig(fp, "vid_gamma", val, VL) > 0) vid_gamma = clampd(Bstrtod(val, NULL), 0.0, 10.0); if (readconfig(fp, "vid_brightness", val, VL) > 0) vid_brightness = clampd(Bstrtod(val, NULL), 0.0, 10.0); if (readconfig(fp, "vid_contrast", val, VL) > 0) vid_contrast = clampd(Bstrtod(val, NULL), 0.0, 10.0); #ifdef RENDERTYPEWIN if (readconfig(fp, "maxrefreshfreq", val, VL) > 0) maxrefreshfreq = atoi_safe(val); #endif #ifdef USE_OPENGL if (readconfig(fp, "usemodels", val, VL) > 0) usemodels = !!atoi_safe(val); if (readconfig(fp, "usehightile", val, VL) > 0) usehightile = !!atoi_safe(val); if (readconfig(fp, "lazytileselector", val, VL) > 0) g_lazy_tileselector = !!atoi_safe(val); glusetexcache = -1; if (readconfig(fp, "glusetexcache", val, VL) > 0) { glusetexcache = clamp(atoi_safe(val), 0, 2); } if (readconfig(fp, "glusememcache", val, VL) > 0) { glusememcache = !!atoi_safe(val); } if (readconfig(fp, "gltexfiltermode", val, VL) > 0) { gltexfiltermode = atoi_safe(val); } if (readconfig(fp, "glanisotropy", val, VL) > 0) { glanisotropy = atoi_safe(val); } if (readconfig(fp, "r_downsize", val, VL) > 0) { r_downsize = atoi_safe(val); r_downsize = clamp(r_downsize, 0, 5); r_downsizevar = r_downsize; } if (readconfig(fp, "r_texcompr", val, VL) > 0) glusetexcompr = !!atoi_safe(val); if (readconfig(fp, "r_shadescale", val, VL) > 0) shadescale = clampd(Bstrtod(val, NULL), 0.0, 10.0); if (readconfig(fp, "r_usenewshading", val, VL) > 0) r_usenewshading = clamp(atoi_safe(val), 0, 2); #endif if (readconfig(fp, "r_usenewaspect", val, VL) > 0) r_usenewaspect = !!atoi_safe(val); #ifndef RENDERTYPEWIN if (readconfig(fp, "r_screenxy", val, VL) > 0) { r_screenxy = clamp(atoi_safe(val), 0, 9999); if (r_screenxy/100==0 || r_screenxy%100==0) r_screenxy = 403; } #endif if (readconfig(fp, "gameexecutable", val, VL) > 0) Bstrcpy(game_executable, val); // option[0] = 1; // vesa all the way... // option[1] = 1; // sound all the way... // option[4] = 0; // no multiplayer // option[5] = 0; #if 1 if (readconfig(fp, "keyforward", val, VL) > 0) keys[0] = Bstrtol(val, NULL, 16); if (readconfig(fp, "keybackward", val, VL) > 0) keys[1] = Bstrtol(val, NULL, 16); if (readconfig(fp, "keyturnleft", val, VL) > 0) keys[2] = Bstrtol(val, NULL, 16); if (readconfig(fp, "keyturnright", val, VL) > 0) keys[3] = Bstrtol(val, NULL, 16); if (readconfig(fp, "keyrun", val, VL) > 0) keys[4] = Bstrtol(val, NULL, 16); if (readconfig(fp, "keystrafe", val, VL) > 0) keys[5] = Bstrtol(val, NULL, 16); if (readconfig(fp, "keyfire", val, VL) > 0) keys[6] = Bstrtol(val, NULL, 16); if (readconfig(fp, "keyuse", val, VL) > 0) keys[7] = Bstrtol(val, NULL, 16); if (readconfig(fp, "keystandhigh", val, VL) > 0) keys[8] = Bstrtol(val, NULL, 16); if (readconfig(fp, "keystandlow", val, VL) > 0) keys[9] = Bstrtol(val, NULL, 16); if (readconfig(fp, "keylookup", val, VL) > 0) keys[10] = Bstrtol(val, NULL, 16); if (readconfig(fp, "keylookdown", val, VL) > 0) keys[11] = Bstrtol(val, NULL, 16); if (readconfig(fp, "keystrafeleft", val, VL) > 0) keys[12] = Bstrtol(val, NULL, 16); if (readconfig(fp, "keystraferight", val, VL) > 0) keys[13] = Bstrtol(val, NULL, 16); if (readconfig(fp, "key2dmode", val, VL) > 0) keys[14] = Bstrtol(val, NULL, 16); if (readconfig(fp, "keyviewcycle", val, VL) > 0) keys[15] = Bstrtol(val, NULL, 16); if (readconfig(fp, "key2dzoomin", val, VL) > 0) keys[16] = Bstrtol(val, NULL, 16); if (readconfig(fp, "key2dzoomout", val, VL) > 0) keys[17] = Bstrtol(val, NULL, 16); if (readconfig(fp, "keychat", val, VL) > 0) keys[18] = Bstrtol(val, NULL, 16); #endif #ifdef RENDERTYPEWIN if (readconfig(fp, "windowpositioning", val, VL) > 0) windowpos = atoi_safe(val); windowx = -1; if (readconfig(fp, "windowposx", val, VL) > 0) windowx = atoi_safe(val); windowy = -1; if (readconfig(fp, "windowposy", val, VL) > 0) windowy = atoi_safe(val); #endif if (readconfig(fp, "keyconsole", val, VL) > 0) { keys[19] = Bstrtol(val, NULL, 16); OSD_CaptureKey(keys[19]); } if (readconfig(fp, "mousesensitivity", val, VL) > 0) msens = Bstrtod(val, NULL); if (readconfig(fp, "mousenavigation", val, VL) > 0) unrealedlook = !!atoi_safe(val); if (readconfig(fp, "mousenavigationaccel", val, VL) > 0) pk_uedaccel = atoi_safe(val); if (readconfig(fp, "quickmapcycling", val, VL) > 0) quickmapcycling = !!atoi_safe(val); if (readconfig(fp, "sideview_reversehorizrot", val, VL) > 0) sideview_reversehrot = !!atoi_safe(val); if (readconfig(fp, "revertCTRL", val, VL) > 0) revertCTRL = !!atoi_safe(val); if (readconfig(fp, "scrollamount", val, VL) > 0) scrollamount = atoi_safe(val); if (readconfig(fp, "turnaccel", val, VL) > 0) pk_turnaccel = atoi_safe(val); if (readconfig(fp, "turndecel", val, VL) > 0) pk_turndecel = atoi_safe(val); if (readconfig(fp, "autosavesec", val, VL) > 0) autosave = max(0, atoi_safe(val)); if (readconfig(fp, "autocorruptchecksec", val, VL) > 0) autocorruptcheck = max(0, atoi_safe(val)); if (readconfig(fp, "corruptcheck_noalreadyrefd", val, VL) > 0) corruptcheck_noalreadyrefd = !!atoi_safe(val); if (readconfig(fp, "fixmaponsave_sprites", val, VL) > 0) fixmaponsave_sprites = !!atoi_safe(val); if (readconfig(fp, "keeptexturestretch", val, VL) > 0) keeptexturestretch = !!atoi_safe(val); if (readconfig(fp, "showheightindicators", val, VL) > 0) showheightindicators = clamp(atoi_safe(val), 0, 2); if (readconfig(fp, "showambiencesounds", val, VL) > 0) showambiencesounds = clamp(atoi_safe(val), 0, 2); if (readconfig(fp, "autogray", val, VL) > 0) autogray = !!atoi_safe(val); // if (readconfig(fp, "showinnergray", val, VL) > 0) // showinnergray = !!atoi_safe(val); if (readconfig(fp, "graphicsmode", val, VL) > 0) graphicsmode = clamp(atoi_safe(val), 0, 2); if (readconfig(fp, "samplerate", val, VL) > 0) MixRate = clamp(atoi_safe(val), 8000, 48000); if (readconfig(fp, "ambiencetoggle", val, VL) > 0) AmbienceToggle = !!atoi_safe(val); if (readconfig(fp, "parlock", val, VL) > 0) ParentalLock = !!atoi_safe(val); if (readconfig(fp, "osdtryscript", val, VL) > 0) m32_osd_tryscript = !!atoi_safe(val); for (i=0; i<256; i++) remap[i]=i; remapinit=1; if (readconfig(fp, "remap", val, VL) > 0) { char *p=val; int32_t v1,v2; while (*p) { if (!sscanf(p,"%x",&v1))break; if ((p=strchr(p,'-'))==0)break; p++; if (!sscanf(p,"%x",&v2))break; remap[v1]=v2; initprintf("Remap %X key to %X\n",v1,v2); if ((p=strchr(p,','))==0)break; p++; } } // load m32script history for (i=0; i<SCRIPTHISTSIZ; i++) { Bsprintf(val, "hist%d", i); if (readconfig(fp, val, val, VL) <= 0) break; scripthist[i] = Bstrdup(val); } scripthistend = i; // copy script history into OSD history for (i=0; i<min(scripthistend, OSD_HISTORYDEPTH); i++) { Bstrncpyz(osdhistorybuf[i], scripthist[scripthistend-1-i], OSD_EDITLENGTH+1); osdhistorysize++; osdhistorytotal++; } scripthistend %= SCRIPTHISTSIZ; Bfclose(fp); return 0; }
int main (int argc, char *argv[]) { spawn_term((argc >= 2) ? argv[1] : NULL); char cmd[51]; // stores the command that was entered char* token[MAX_TOKENS]; // points to parts of the command unsigned i; int pwm, motor_num, target_setting; for (;;) { printf (LINE_START); cmd_ok = 0; assert(fgets (cmd, 50, stdin)); // use strtok to grab each part of the command token[0] = strtok (cmd, " \n"); for (i = 1; i < MAX_TOKENS; i++) token[i] = strtok (NULL, " \n"); if (token[0] == NULL) help (); else if (!strcmp(token[0], "q") || !strcmp(token[0], "exit")) exit_safe(); else if (!strcmp(token[0], ":q")) printf ("this isnt vim lol\n"); else if (!strcmp(token[0], "help")) { if (token[1] == NULL) help (); else if (!strcmp(token[1],"motor") || !strcmp(token[1],"m")) help_motor(); else if (!strcmp(token[1],"dyn") || !strcmp(token[1],"d")) help_dyn(); else if (!strcmp(token[1],"power") || !strcmp(token[1],"p")) help_power(); } else if (!strcmp(token[0], "motor") || !strcmp(token[0], "m")) { if (token[1] == NULL || !strcmp (token[1], "status")) motor_status(); else if (!strcmp (token[1], "all")) { pwm = atoi_safe(token[2]); // note an invalid token will cause pwm = 0, which is ok motor_set (pwm, H_ALL); } else if (!strcmp (token[1], "fwd")) { pwm = atoi_safe(token[2]); // note an invalid token will cause pwm = 0, which is ok motor_set (pwm, H_FWD); } else if (!strcmp (token[1], "rise")) { pwm = atoi_safe(token[2]); // note an invalid token will cause pwm = 0, which is ok motor_set (pwm, H_RISE); } else { motor_num = atoi_safe (token[1]); // 1-indexed motor_num--; // Internally, this is 0-indexed pwm = atoi_safe (token[2]); switch (motor_num) { case M_FRONT_LEFT: motor_set (pwm, H_FRONT_LEFT); break; case M_FRONT_RIGHT: motor_set (pwm, H_FRONT_RIGHT); break; case M_FWD_LEFT: motor_set (pwm, H_FWD_LEFT); break; case M_FWD_RIGHT: motor_set (pwm, H_FWD_RIGHT); break; case M_REAR: motor_set (pwm, H_REAR); break; default: printf ("**** Invalid motor number.\n"); } } } else if (!strcmp(token[0], "power") || !strcmp(token[0], "p")) { if (token[1] == NULL || !strcmp (token[1], "status")) power_status(); else if (!strcmp (token[1], "on") || !strcmp (token[1], "1")) { power_on(); } else if (!strcmp (token[1], "start") || !strcmp (token[1], "2")) { startup_sequence(); } else if (!strcmp (token[1], "off") || !strcmp (token[1], "0")) { power_off(); } } else if (!strcmp(token[0], "dyn") || !strcmp(token[0], "d")) { if (token[1] == NULL) dyn_status(); else if (!strcmp (token[1], "depth")) { target_setting = atoi_safe(token[2]); // Note an invalid token will cause target_setting = 0, which is ok dyn_set_target_depth(target_setting); } } if (cmd_ok != 1) cmd_error(); } }
#include "proto.h" #include "benchapi.h" //#define INIT_SHM_FLAG -100 //create Ctempgs::Ctempgs (mysql_interface * db ) :CtableRoute100( db, "TEMPGS_DB","t_tempgs","userid" ) { } int Ctempgs::get_value(userid_t userid, stru_tempgs* p_tempgs ) { sprintf( this->sqlstr, "select task, count\ from %s where userid=%u ", this->get_table_name(userid),userid); STD_QUERY_ONE_BEGIN(this-> sqlstr,USER_ID_NOFIND_ERR); p_tempgs->task=atoi_safe(NEXT_FIELD); p_tempgs->count=atoi_safe(NEXT_FIELD); STD_QUERY_ONE_END(); } int Ctempgs::update_task(userid_t userid, uint32_t task ) { sprintf( this->sqlstr, " update %s set \ task=%u \ where userid=%u " , this->get_table_name(userid), task, userid ); STD_SET_RETURN(this->sqlstr,userid,USER_ID_NOFIND_ERR ); } int Ctempgs::add_count(userid_t userid)
p_out->deal_minute=atoi_safe(NEXT_FIELD); p_out->flag=atoi_safe(NEXT_FIELD); p_out->pic_id=atoi_safe(NEXT_FIELD); BIN_CPY_NEXT_FIELD (&(p_out->msglen), 4004); STD_QUERY_ONE_END(); } int Cmsg_attime::get_by_date( su_get_msg_attime_by_date_in *p_in, su_get_msg_attime_all_out *p_out ) { sprintf( this->sqlstr, "select deal_date, deal_hour, deal_minute, flag,pic_id, deal_msg from %s \ where ( deal_date=0 or deal_date=%u) and deal_hour=%u and deal_minute=%u limit %u,1 ", this->get_table_name(), p_in->deal_date, p_in->deal_hour,p_in->deal_minute,p_in->index ); STD_QUERY_ONE_BEGIN(this-> sqlstr,NO_DEFINE_ERR ); p_out->deal_date =atoi_safe(NEXT_FIELD); p_out->deal_hour=atoi_safe(NEXT_FIELD); p_out->deal_minute=atoi_safe(NEXT_FIELD); p_out->flag=atoi_safe(NEXT_FIELD); p_out->pic_id=atoi_safe(NEXT_FIELD); BIN_CPY_NEXT_FIELD (&(p_out->msglen), 4004); STD_QUERY_ONE_END(); } int Cmsg_attime::remove( uint32_t deal_date, uint32_t deal_hour, uint32_t deal_minute ) { sprintf( this->sqlstr, "delete from %s \ where deal_date=%u and deal_hour=%u and deal_minute=%u", this->get_table_name(), deal_date,deal_hour,deal_minute ); STD_SET_RETURN_EX(this->sqlstr ,NO_DEFINE_ERR);