int get_cd_track(int cd_id, struct current_tracks_st* dest){ MYSQL_RES* pRes; MYSQL_ROW rowData; int res, i = 0, num_tracks = 0; char qs[250]; if (!connected) return 0; memset(dest, 0, sizeof(CURRENT_TRACKS_ST)); dest->cd_id = -1; sprintf(qs, c2s("select track_id, title from track where track.cd_id = %d order by track_id"), cd_id); res = mysql_query(&mysql, qs); if (res){ fprintf(stderr, c2s("Select error %d: %s\n"), MS_ENO(&mysql), MS_EMSG(&mysql)); return 0; } else { pRes = mysql_use_result(&mysql); if (pRes){ if ( (num_tracks = (int)mysql_num_rows(pRes)) > 0){ while ((rowData = mysql_fetch_row(pRes))){ strcpy(dest->track[i], rowData[1]); i++; } dest->cd_id = cd_id; } mysql_free_result(pRes); } } return num_tracks; }
int find_cds(char* search_str, struct cd_search_st* dest){ MYSQL_RES* pRes; MYSQL_ROW rowData; int res, i = 0, num_rows = 0; char qs[250], ss[250]; if (!connected) return 0; memset(dest, -1, sizeof(CD_SEARCH_ST)); mysql_escape_string(ss, search_str, strlen(search_str)); sprintf(qs, c2s("select distinct artist.id, id.id from artist, cd where artist.id = cd.artist_id and (artist.name like '%%%s%%' or cd.title like '%%%s%%' or cd.catalogue like '%%%s%%'"),ss,ss,ss); res = mysql_query(&mysql, qs); if (res){ fprintf(stderr, c2s("Select error %d: %s\n"), MS_ENO(&mysql), MS_EMSG(&mysql)); } else { pRes = mysql_use_result(&mysql); if (pRes){ num_rows = (int)mysql_num_rows(pRes); if (num_rows > 0){ while ((rowData = mysql_fetch_row(pRes)) && i < MAX_CD_RESULT){ sscanf(rowData[1], "%d", &dest->cd_id[i]); i++; } } mysql_free_result(pRes); } } return num_rows; }
int get_cd(int cd_id, struct current_cd_st* dest){ MYSQL_RES* pRes; MYSQL_ROW rowData; int res; char qs[250]; if (!connected) return 0; memset(dest, 0, sizeof(CURRENT_CD_ST)); dest->artist_id = -1; sprintf(qs, c2s("select artist.id, cd.id, artist.name, cd.title, cd.catalogue from artist, cd where artist.id=cd.artist_id and cd.id = %d"), cd_id); res = mysql_query(&mysql, qs); if (res){ fprintf(stderr, c2s("Select error %d: %s\n"), MS_ENO(&mysql), MS_EMSG(&mysql)); return 0; } else { pRes = mysql_use_result(&mysql); if (pRes){ if (mysql_num_rows(pRes) > 0){ if ((rowData = mysql_fetch_row(pRes))){ sscanf(rowData[0], "%d", &dest->artist_id); sscanf(rowData[1], "%d", &dest->cd_id); strcpy(dest->artist_name, rowData[2]); strcpy(dest->title, rowData[3]); strcpy(dest->catalogue, rowData[4]); } } mysql_free_result(pRes); } } if (dest->artist_id != -1) return 1; return 0; }
int add_cd(char* artist, char* title, char* catalogue, int *cd_id){ MYSQL_RES* pRes; MYSQL_ROW rowData; int res, artist_id = -1, new_cd_id = -1; char is[250], es[250]; if (!connected) { return 0; } artist_id = get_artist_id(artist); mysql_escape_string(es, title, strlen(title)); sprintf(is, c2s("insert into cd(title,artist_id, catalogue) values('%s', '%d', '%s')"), es, artist_id, catalogue); res = mysql_query(&mysql, is); if (res){ fprintf(stderr, c2s("Insert error %d: %s\n"), MS_ENO(&mysql), MS_EMSG(&mysql)); return 0; } res = mysql_query(&mysql, c2s("select last_insert_id()")); if (res){ fprintf(stderr, c2s("Select error %d: %s\n"), MS_ENO(&mysql), MS_EMSG(&mysql)); return 0; } else { pRes = mysql_use_result(&mysql); if (pRes){ if ((rowData = mysql_fetch_row(pRes))){ sscanf(rowData[0], "%d", &new_cd_id); } mysql_free_result(pRes); } } *cd_id = new_cd_id; if (new_cd_id != -1) return 1; return 0; }
void solve(){ // memset(dp, INF, sizeof(dp)); std::deque<int> a; SS = c2s(S); ST = c2s(T); printf("SS = %x\n", SS); printf("ST = %x\n", ST); a.push_back(SS); printf("a.size = %d\n", (int)a.size()); dp[SS] = 1; int oo = 20000; CHESS ct, nt; int cs, ns; do { // oo --; cs = a.front(); a.pop_front(); s2c(cs, ct); if (fp[cs]) continue; fp[cs] = true; if (cs == ST) break; // print_chess(ct); // printf("step of %x: %d\n", cs, dp[cs]); for (int d=0; d<4; d++) { if (! get_nt(ct, d, nt) ) continue; int ns = c2s(nt); // print_chess(nt); if (dp[ns] == 0 or dp[cs]+1 < dp[ns]){ dp[ns] = dp[cs]+1; }; // printf("ns = %x, fp[ns]= %d\n", ns, fp[ns]); if (! fp[ns]) a.push_back(ns); }; // printf("a.size = %d\n", static_cast<int>(a.size())); } while ( oo > 0 && a.size() > 0 ); printf("oo = %d\n", oo); printf("a.size = %d\n", static_cast<int>(a.size())); printf("dp.size = %d\n", static_cast<int>(dp.size())); printf("step: %d\n", dp[cs]-1); print_chess(ct); printf("\n\n"); show_step(); }
int database_start(char* name, char*password){ if (!connected){ mysql_init(&mysql); if (!mysql_real_connect(&mysql, c2s("127.0.0.1"), name, password,c2s("blpcd"), 0, NULL, 0)){ fprintf(stderr, "Database connection failure:%d, %s\n", mysql_errno(&mysql), mysql_error(&mysql)); connected = 0; } else { connected = 1; } } return connected; }
static void emit_data_primtype(Ctype *ctype, Node *val) { switch (ctype->type) { case CTYPE_FLOAT: { float v = val->fval; emit(".long %d", *(int *)&v); break; } case CTYPE_DOUBLE: emit(".quad %ld", *(long *)&val->fval); break; case CTYPE_BOOL: emit(".byte %d", !!eval_intexpr(val)); break; case CTYPE_CHAR: emit(".byte %d", eval_intexpr(val)); break; case CTYPE_SHORT: emit(".short %d", eval_intexpr(val)); break; case CTYPE_INT: emit(".long %d", eval_intexpr(val)); break; case CTYPE_LONG: case CTYPE_LLONG: case CTYPE_PTR: if (val->type == AST_GVAR) emit(".quad %s", val->varname); else emit(".quad %d", eval_intexpr(val)); break; default: error("don't know how to handle\n <%s>\n <%s>", c2s(ctype), a2s(val)); } }
static void emit_save_literal(Node *node, Ctype *totype, int off) { switch (totype->type) { case CTYPE_BOOL: emit("movb $%d, %d(%%rbp)", !!node->ival, off); break; case CTYPE_CHAR: emit("movb $%d, %d(%%rbp)", node->ival, off); break; case CTYPE_SHORT: emit("movw $%d, %d(%%rbp)", node->ival, off); break; case CTYPE_INT: emit("movl $%d, %d(%%rbp)", node->ival, off); break; case CTYPE_LONG: case CTYPE_LLONG: case CTYPE_PTR: { unsigned long ival = node->ival; emit("movl $%lu, %d(%%rbp)", ival & ((1L << 32) - 1), off); emit("movl $%lu, %d(%%rbp)", ival >> 32, off + 4); break; } case CTYPE_FLOAT: { float fval = node->fval; int *p = (int *)&fval; emit("movl $%u, %d(%%rbp)", *p, off); break; } case CTYPE_DOUBLE: { long *p = (long *)&node->fval; emit("movl $%lu, %d(%%rbp)", *p & ((1L << 32) - 1), off); emit("movl $%lu, %d(%%rbp)", *p >> 32, off + 4); break; } default: error("internal error: <%s> <%s> <%d>", a2s(node), c2s(totype), off); } }
static SCM pg_error_msg(SCM res) { struct pg_res *pgr; scm_assert_smob_type(pg_res_tag, res); pgr = (struct pg_res *)SCM_SMOB_DATA(res); if ((pgr->status != PGRES_FATAL_ERROR) && (pgr->status != PGRES_NONFATAL_ERROR)) return SCM_BOOL_F; return c2s(PQresultErrorMessage(pgr->res)); }
void print_chess(CHESS c){ printf("chess: %x\n", c2s(c)); for (int i = 0; i < SIZE*SIZE; ++i) { printf("%d ", c[i/SIZE][i%SIZE]); if (i%SIZE == 3) printf("\n"); }; }
int exfat_find_used_sectors(const struct exfat* ef, off_t* a, off_t* b) { cluster_t ca, cb; if (*a == 0 && *b == 0) ca = cb = EXFAT_FIRST_DATA_CLUSTER - 1; else { ca = s2c(ef, *a); cb = s2c(ef, *b); } if (find_used_clusters(ef, &ca, &cb) != 0) return 1; if (*a != 0 || *b != 0) *a = c2s(ef, ca); *b = c2s(ef, cb) + (CLUSTER_SIZE(*ef->sb) - 1) / SECTOR_SIZE(*ef->sb); return 0; }
static char *get_load_inst(Ctype *ctype) { switch (ctype->size) { case 1: return "movsbq"; case 2: return "movswq"; case 4: return "movslq"; case 8: return "mov"; default: error("Unknown data size: %s: %d", c2s(ctype), ctype->size); } }
void show_step(){ int cs = ST; CHESS ct; s2c(cs, ct); int steps[dp[ST]-1]; int oo = 100; while(cs != SS && oo > 0){ oo --; for (int d = 0; d < 4; d++) { CHESS tt; get_nt(ct, d, tt); int ts = c2s(tt); if (dp[ts] == dp[cs] - 1){ // printf("%x to %x with direction: %c\n", cs, c2s(tt), DIR_NAME[d]); // print_chess(tt); steps[ dp[cs] -2 ] = REVERSE_DIR[d]; // printf("%d\n", dp[cs]); cs = c2s(tt); s2c(cs, ct); } } } cs = SS; for (int i = 0; i < dp[ST]-1; ++i) { s2c(cs, ct); int d = steps[i]; CHESS tt; get_nt(ct, d, tt); cs = c2s(tt); // printf("move: %c\n", DIR_NAME[d]); // print_chess(tt); printf("%c", DIR_NAME[d]); } printf("\n"); }
int add_tracks(struct current_tracks_st* tracks){ int res, i; char is[250], es[250]; if (!connected) return 0; i = 0; while (tracks->track[i][0]){ mysql_escape_string(es, tracks->track[i], strlen(tracks->track[i])); sprintf(is, c2s("insert into track(cd_id, track_id, title) values(%d,%d,'%s')"), tracks->cd_id, i+1, es); res = mysql_query(&mysql, is); if (res){ fprintf(stderr, c2s("Insert error %d: %s\n"), MS_ENO(&mysql), MS_EMSG(&mysql)); return 0; } i++; } return i; }
static char *get_int_reg(Ctype *ctype, char r) { assert(r == 'a' || r == 'c'); switch (ctype->size) { case 1: return (r == 'a') ? "al" : "cl"; case 2: return (r == 'a') ? "ax" : "cx"; case 4: return (r == 'a') ? "eax" : "ecx"; case 8: return (r == 'a') ? "rax" : "rcx"; default: error("Unknown data size: %s: %d", c2s(ctype), ctype->size); } }
int delete_cd(int cd_id){ int res; char qs[250]; int artist_id = -1, num_rows; MYSQL_RES* pRes; MYSQL_ROW rowData; if (!connected) return 0; sprintf(qs, c2s("select artist_id from cd where artist_id = (select artist_id from cd where id = '%d')"),cd_id); res = mysql_query(&mysql, qs); if (res){ fprintf(stderr, c2s("Select error %d: %s\n"), MS_ENO(&mysql), MS_EMSG(&mysql)); return 0; } else { pRes = mysql_use_result(&mysql); if (pRes){ num_rows = (int)mysql_num_rows(pRes); if (num_rows == 1){ rowData = mysql_fetch_row(pRes); sscanf(rowData[0], "%d", &artist_id); } mysql_free_result(pRes); } } sprintf(qs, c2s("delete from track where cd_id = '%d'"),cd_id); res = mysql_query(&mysql, qs); if (res){ fprintf(stderr, c2s("Delete error (track)%d: %s\n"), MS_ENO(&mysql), MS_EMSG(&mysql)); return 0; } sprintf(qs, c2s("delete from cd where id = '%d'"),cd_id); res = mysql_query(&mysql, qs); if (res){ fprintf(stderr, c2s("Delete error (cd)%d: %s\n"), MS_ENO(&mysql), MS_EMSG(&mysql)); return 0; } if (artist_id != -1){ sprintf(qs,c2s("Delete from artist where id = '%d'"),artist_id); res = mysql_query(&mysql, qs); if (res){ fprintf(stderr, c2s("Delete error (artist)%d: %s\n"), MS_ENO(&mysql), MS_EMSG(&mysql)); return 0; } } return 1; }
static Img *vtxt2img(Gfx *g, Txt *t, const char *fmt, va_list ap) { char s[Bufsize + 1]; vsnprintf(s, Bufsize + 1, fmt, ap); SDL_Surface *srf = TTF_RenderUTF8_Blended(t->font, s, c2s(t->color)); if (!srf) return NULL; SDL_Texture *tex = SDL_CreateTextureFromSurface(g->rend, srf); SDL_FreeSurface(srf); if (!tex) return NULL; Img *i = xalloc(1, sizeof(*i)); i->tex = tex; return i; }
bool NaiadFoamBox::Intersect(const Ray &ray, float *tHit, float *rayEpsilon, DifferentialGeometry *dg) const { if (ray.zbuffer) return false; if (ray.hitFoam) return false; //std::cout << parent.GetPtr()->FoamPlane().size() << std::endl; float t; if (bb.IntersectP(ray,&t)) { Point phit = ray(t); PerspectiveCamera * cam = PerspectiveCamera::cur_cam; Transform c2w; cam->CameraToWorld.Interpolate(0.f, &c2w); Transform w2c = Inverse(c2w); Transform c2s = cam->CameraToScreen; Transform s2r = cam->ScreenToRaster; Point cPos = w2c(phit); Point rPos = s2r(c2s(cPos)); int x = (int)(rPos.x + 0.5); int y = (int)(rPos.y + 0.5); int w = cam->film->xResolution; int h = cam->film->yResolution; if (x > 0 && y > 0 && x < w && y < h) { ray.hitFoam = true; /*printf("%i %i %i %i\n", x, y, w ,h); std::cout << parent << std::endl; std::cout << parent->parent << std::endl; std::cout << parent->parent->foamPlane[0] << std::endl; std::cout << parent->parent->foamPlane.size() << std::endl; std::cout << x + y*w << std::endl;*/ //std::cout << NaiadFoam::cur->FoamPlane().size() << std::endl; ray.alphaFoam = NaiadFoam::cur->FoamPlane()[x + y*w]; } return false; /* for (int i = 0; i < particles.size(); i+=100) { if (particles[i].Intersect(ray, tHit, rayEpsilon, dg)) { return false; } }*/ } return false; }
int get_artist_id(char* artist){ MYSQL_RES* pRes; MYSQL_ROW rowData; int res, artist_id = -1; char is[250], qs[250], es[250]; if (!connected) { return 0; } mysql_escape_string(es, artist, strlen(artist)); sprintf(qs, c2s("select id from artist where name = '%s'"), es); res = mysql_query(&mysql, qs); if (res){ fprintf(stderr, c2s("Select error %d: %s\n"), MS_ENO(&mysql), MS_EMSG(&mysql)); return 0; } else { pRes = mysql_use_result(&mysql); if (pRes){ if (mysql_num_rows(pRes) > 0){ if ((rowData = mysql_fetch_row(pRes))){ sscanf(rowData[0], "%d", &artist_id); } } mysql_free_result(pRes); } } if (artist_id != -1) return 1; sprintf(is, c2s("insert into artist(name) values ('%s')"), es); res = mysql_query(&mysql, is); if (res){ fprintf(stderr, c2s("Insert error %d: %s\n"), MS_ENO(&mysql), MS_EMSG(&mysql)); return 0; } res = mysql_query(&mysql, c2s("select last_insert_id()")); if (res){ fprintf(stderr, c2s("Select error %d: %s\n"), MS_ENO(&mysql), MS_EMSG(&mysql)); return 0; } else { pRes = mysql_use_result(&mysql); if (pRes){ if ((rowData = mysql_fetch_row(pRes))){ sscanf(rowData[0], "%d", &artist_id); } mysql_free_result(pRes); } } return artist_id; }
static SCM pg_format_sql(SCM conn, SCM obj) { struct pg_conn *pgc; SCM out; if (SCM_SMOB_PREDICATE(time_tag, obj)) { out = format_time(obj, c2s("'%Y-%m-%d %H:%M:%S'")); } else if (scm_boolean_p(obj) == SCM_BOOL_T) { if (scm_is_true(obj)) out = c2s("'t'"); else out = c2s("'f'"); } else if (scm_is_number(obj)) { out = scm_number_to_string(obj, scm_from_signed_integer(10)); } else if (scm_is_symbol(obj)) { out = pg_format_sql(conn, scm_symbol_to_string(obj)); } else if (scm_is_string(obj)) { if (scm_string_null_p(obj) == SCM_BOOL_T) out = c2s("NULL"); else { char *src = scm_to_utf8_string(obj); scm_assert_smob_type(pg_conn_tag, conn); pgc = (struct pg_conn *)SCM_SMOB_DATA(conn); scm_lock_mutex(pgc->mutex); char *sql = PQescapeLiteral(pgc->conn, src, strlen(src)); out = safe_from_utf8(sql); scm_unlock_mutex(pgc->mutex); free(src); PQfreemem(sql); } } else if (scm_is_null(obj)) out = c2s("NULL"); else out = c2s("NULL"); scm_remember_upto_here_1(out); scm_remember_upto_here_2(conn, obj); return out; }
/* * Cluster to absolute offset. */ off_t exfat_c2o(const struct exfat* ef, cluster_t cluster) { return s2o(ef, c2s(ef, cluster)); }
bool NaiadFoamParticle::Intersect(const Ray &rayInc, float *tHit, float *rayEpsilon, DifferentialGeometry *dg) const { /*const float X0 = ray.o.x; const float Y0 = ray.o.y; const float Z0 = ray.o.z; const float Xd = ray.d.x; const float Yd = ray.d.y; const float Zd = ray.d.z; const float Xc = pos.x; const float Yc = pos.y; const float Zc = pos.z; const float B = 2.0f * (Xd * (X0 - Xc) + Yd * (Y0 - Yc) + Zd * (Z0 - Zc)); const float C = (X0-Xc)*(X0-Xc) + (Y0-Yc)*(Y0-Yc) + (Z0-Zc)*(Z0-Zc) - r*r; const float discriminant = B*B - 4*C; if (discriminant < 0.0f) return false; const float t0 = (- B - sqrt(discriminant)) / 2.0f; const float t1 = (- B + sqrt(discriminant)) / 2.0f; if (t0 < 0 || t0 != t0) { return true; }*/ Matrix4x4 w2o_m; w2o_m.m[0][3] = -pos.x; w2o_m.m[1][3] = -pos.y; w2o_m.m[2][3] = -pos.z; Transform w2o = Transform(w2o_m); const float thetaMin = -M_PI; const float thetaMax = 0; const float phiMax = 2.f*M_PI; float phi; Point phit; // Transform _Ray_ to object space Ray ray; w2o(rayInc, &ray); // Compute quadratic sphere coefficients float A = ray.d.x*ray.d.x + ray.d.y*ray.d.y + ray.d.z*ray.d.z; float B = 2 * (ray.d.x*ray.o.x + ray.d.y*ray.o.y + ray.d.z*ray.o.z); float C = ray.o.x*ray.o.x + ray.o.y*ray.o.y + ray.o.z*ray.o.z - r*r; // Solve quadratic equation for _t_ values float t0, t1; if (!Quadratic(A, B, C, &t0, &t1)) return false; // Compute intersection distance along ray if (t0 > ray.maxt || t1 < ray.mint) return false; float thit = t0; if (t0 < ray.mint) { thit = t1; if (thit > ray.maxt) return false; } // Compute sphere hit position and $\phi$ phit = ray(thit); rayInc.hitFoam = true; PerspectiveCamera * cam = PerspectiveCamera::cur_cam; Transform c2w; cam->CameraToWorld.Interpolate(0.f, &c2w); Transform w2c = Inverse(c2w); Transform c2s = cam->CameraToScreen; Transform s2r = cam->ScreenToRaster; Point cPos = w2c(phit); Point rPos = s2r(c2s(cPos)); int x = (int)(rPos.x + 0.5); int y = (int)(rPos.y + 0.5); int w = cam->film->xResolution; int h = cam->film->yResolution; if (x > 0 && y > 0 && x < w && y < h) { rayInc.hitFoam = true; /*printf("%i %i %i %i\n", x, y, w ,h); std::cout << parent << std::endl; std::cout << parent->parent << std::endl; std::cout << parent->parent->foamPlane[0] << std::endl; std::cout << parent->parent->foamPlane.size() << std::endl; std::cout << x + y*w << std::endl;*/ //std::cout << NaiadFoam::cur->FoamPlane().size() << std::endl; rayInc.alphaFoam = NaiadFoam::cur->FoamPlane()[x + y*w]; } /*if (phit.x == 0.f && phit.y == 0.f) phit.x = 1e-5f * r; phi = atan2f(phit.y, phit.x); if (phi < 0.) phi += 2.f*M_PI; // Find parametric representation of sphere hit float u = phi / phiMax; float theta = acosf(Clamp(phit.z / r, -1.f, 1.f)); float v = (theta - thetaMin) / (thetaMax - thetaMin); // Compute sphere $\dpdu$ and $\dpdv$ float zradius = sqrtf(phit.x*phit.x + phit.y*phit.y); float invzradius = 1.f / zradius; float cosphi = phit.x * invzradius; float sinphi = phit.y * invzradius; Vector dpdu(-phiMax * phit.y, phiMax * phit.x, 0); Vector dpdv = (thetaMax-thetaMin) * Vector(phit.z * cosphi, phit.z * sinphi, -r * sinf(theta)); // Compute sphere $\dndu$ and $\dndv$ Vector d2Pduu = -phiMax * phiMax * Vector(phit.x, phit.y, 0); Vector d2Pduv = (thetaMax - thetaMin) * phit.z * phiMax * Vector(-sinphi, cosphi, 0.); Vector d2Pdvv = -(thetaMax - thetaMin) * (thetaMax - thetaMin) * Vector(phit.x, phit.y, phit.z); // Compute coefficients for fundamental forms float E = Dot(dpdu, dpdu); float F = Dot(dpdu, dpdv); float G = Dot(dpdv, dpdv); Vector N = Normalize(Cross(dpdu, dpdv)); float e = Dot(N, d2Pduu); float f = Dot(N, d2Pduv); float g = Dot(N, d2Pdvv); // Compute $\dndu$ and $\dndv$ from fundamental form coefficients float invEGF2 = 1.f / (E*G - F*F); Normal dndu = Normal((f*F - e*G) * invEGF2 * dpdu + (e*F - f*E) * invEGF2 * dpdv); Normal dndv = Normal((g*F - f*G) * invEGF2 * dpdu + (f*F - g*E) * invEGF2 * dpdv); //std::cout << "Got here?" << std::endl; Matrix4x4 o2w_m; o2w_m.m[0][3] = pos.x; o2w_m.m[1][3] = pos.y; o2w_m.m[2][3] = pos.z; Transform o2w = Transform(o2w_m); // Initialize _DifferentialGeometry_ from parametric information *dg = DifferentialGeometry(o2w(phit), o2w(dpdu), o2w(dpdv), o2w(dndu), o2w(dndv), u, v, parent); dg->mult = 1.f;*/ // Update _tHit_ for quadric intersection //*tHit = thit; // Compute _rayEpsilon_ for quadric intersection //*rayEpsilon = 5e-4f * *tHit; return true; }