static inline void pprint_sensor_vec(const sensors_vec_t& vec, Print *p) { char buf[16]; // No %f in sprintf? What the f**k. char buf2[16]; char buf3[16]; pprintf(p, "X: %s Y: %s Z: %s ", strf(buf, vec.x), strf(buf2, vec.y), strf(buf3, vec.z)); }
char* vec_char (vec_t *vec) { ensure_vec(vec, __func__); int count = vec->count; push(strf("[")); for (int i = 0; i < count; i++) { if (is_vec(vec_get(vec, i)[0])) push(strf("vec[]")); else if (is_map(vec_get(vec, i)[0])) push(strf("map[]")); else push(to_char(vec_get(vec, i)[0])); op_concat(); if (i < count-1) { push(strf(", ")); op_concat(); } } push(strf("]")); op_concat(); return pop(); }
void ruby_write_node_bool_to_float(node_t*n, state_t*s) { strf(s, "("); write_node(s, n->child[0]); strf(s, " ? 1.0 : 0.0"); strf(s, ")"); }
void ruby_write_node_inc_array_at_pos(node_t*n, state_t*s) { write_node(s, n->child[0]); strf(s, "["); write_node(s, n->child[1]); strf(s, "]+=1"); }
void c_write_node_array_at_pos(node_t*n, state_t*s) { write_node(s, n->child[0]); strf(s, "["); write_node(s, n->child[1]); strf(s, "]"); }
void c_write_node_sqr(node_t*n, state_t*s) { strf(s, "sqr"); if(n->child[0]->type!=&node_brackets) strf(s, "("); write_node(s, n->child[0]); if(n->child[0]->type!=&node_brackets) strf(s, ")"); }
void ruby_write_node_param(node_t*n, state_t*s) { if(s->model->sig->has_column_names) { strf(s, "%s", s->model->sig->column_names[n->value.i]); } else { strf(s, "data[%d]", n->value.i); } }
void ruby_write_node_in(node_t*n, state_t*s) { strf(s, "!!"); write_node(s, n->child[1]); strf(s, ".index("); write_node(s, n->child[0]); strf(s, ")"); }
void ruby_write_node_set_array_at_pos(node_t*n, state_t*s) { write_node(s, n->child[0]); strf(s, "["); write_node(s, n->child[1]); strf(s, "]="); write_node(s, n->child[2]); }
void c_write_node_param(node_t*n, state_t*s) { if(s->model->sig->column_names) { strf(s, "%s", s->model->sig->column_names[n->value.i]); } else { strf(s, "p%d", n->value.i); } }
void ruby_write_node_term_frequency(node_t*n, state_t*s) { strf(s, "term_frequency("); write_node(s, n->child[0]); strf(s, ","); write_node(s, n->child[1]); strf(s, ")"); }
static void ruby_write_node_arg_min_or_max(node_t*n, state_t*s, char*min_or_max) { strf(s, "(["); int t; for(t=0;t<n->num_children;t++) { if(t) strf(s, ","); write_node(s, n->child[t]); } strf(s, "].each_with_index.map.%s)[1]", min_or_max); }
void ruby_write_node_for_local_from_n_to_m(node_t*n, state_t*s) { strf(s, "("); write_node(s, n->child[0]); strf(s, ").upto(("); write_node(s, n->child[1]); strf(s, ")-1) do\n"); indent(s);write_node(s, n->child[2]);dedent(s); strf(s, "\nend"); }
void c_write_node_for_local_from_n_to_m(node_t*n, state_t*s) { strf(s, "for(v%d=", n->value.i); write_node(s, n->child[0]); strf(s, ";v%d<", n->value.i); write_node(s, n->child[1]); strf(s, ";v%d++) {\n", n->value.i); indent(s);write_node(s, n->child[2]);dedent(s); strf(s, "\n}\n"); }
void GPSSensorWriter::Write(Print *p) { float lat; float lon; unsigned long age; gps_->f_get_position(&lat, &lon, &age); char buf[16]; // No %f in sprintf? What the f**k. char buf2[16]; pprintf(p, "GPS: LAT: %s, LON: %s AGE: %lu\n", strf(buf, lat), strf(buf2, lon), age); }
void c_write_node_arg_min_i(node_t*n, state_t*s) { strf(s, "arg_min_i(%d, ", n->num_children); int t; for(t=0;t<n->num_children;t++) { if(t) strf(s, ", "); strf(s, "(int)"); write_node(s, n->child[t]); } strf(s, ")"); }
void c_write_node_in(node_t*n, state_t*s) { if(node_is_array(n->child[1])) { array_t*a = n->child[1]->value.a; if(!a->size) { strf(s, "false"); return; } else { constant_type_t etype = constant_array_subtype(&n->child[1]->value); switch(etype) { case CONSTANT_STRING: strf(s, "!!strstr(\""); int t; for(t=0;t<a->size;t++) { assert(a->entries[t].type == CONSTANT_STRING); if(t) strf(s, "\\x7f"); write_escaped_string(s, a->entries[t].s); } strf(s, "\","); write_node(s, n->child[0]); strf(s, ")"); return; } } } strf(s, "find_in("); write_node(s, n->child[0]); strf(s, ","); write_node(s, n->child[1]); strf(s, ")"); }
void c_write_node_equals(node_t*n, state_t*s) { constant_type_t type = node_type(n->child[0], s->model); if(type==CONSTANT_STRING) { strf(s, "!strcmp("); write_node(s, n->child[0]); strf(s, ","); write_node(s, n->child[1]); strf(s, ")"); } else { write_node(s, n->child[0]); strf(s, " == "); write_node(s, n->child[1]); } }
int MakeMailFile(struct GroupFolder * folder, STRPTR outbuf, LONG outlen, ULONG MsgNum, BOOL makeDir ) { int rc = ERR_OVERFLOW; DBG_ASSERT(folder != NULL); *outbuf = 0; if(AddPart( outbuf, folder->folder, outlen )) { if(AddPart( outbuf, strf("%08ld", MsgNum), outlen)) { if(makeDir) { /* make sure the folder pointing to this file exists */ MakeDir( outbuf ); } rc = ERR_NOERROR; hexdump( outbuf, 0, strlen(outbuf)+4); } } DBG_STRING(outbuf); return(rc); }
void AltitudeSensorWriter::Write(Print *p) { // TODO(mgyenik) Find clean way to update this. const float seaLevelPressure = SENSORS_PRESSURE_SEALEVELHPA; float alt = bmp_->pressureToAltitude(seaLevelPressure, event_.pressure); char buf[16]; // No %f in sprintf? What the f**k. pprintf(p, "%s %s %s\n", name_, strf(buf, alt), "ft"); }
HRESULT _logLastError(debugargs, const WCHAR *s) { DWORD le; WCHAR *msg; WCHAR *formatted; BOOL useFormatted; le = GetLastError(); useFormatted = FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, le, 0, (LPWSTR) (&formatted), 0, NULL) != 0; if (!useFormatted) formatted = L"\n"; msg = strf(L"[libui] %s:%s:%s() %s: GetLastError() == %I32u %s", file, line, func, s, le, formatted); if (useFormatted) LocalFree(formatted); // ignore error printDebug(msg); uiprivFree(msg); DebugBreak(); SetLastError(le); // a function does not have to set a last error // if the last error we get is actually 0, then HRESULT_FROM_WIN32(0) will return S_OK (0 cast to an HRESULT, since 0 <= 0), which we don't want // prevent this by returning E_FAIL if (le == 0) return E_FAIL; return HRESULT_FROM_WIN32(le); }
std::string fractal_info::to_str() const { std::string s; s += "Type: "; switch (type) { case MANDELBROT: s += "Mandelbrot"; break; case JULIA: s += "Julia"; break; }; s += "\n"; s += strf( "XMin: %s\n" "XMax: %s\n" "YMax: %s\n", dbl2str(xmin).c_str(), dbl2str(xmax).c_str(), dbl2str(ymax).c_str()); // FIXME: add Julia-specific info here return s; }
void ruby_write_header(model_t*model, state_t*s) { strf(s, "def predict("); if(s->model->sig->has_column_names) { int t; node_t*root = (node_t*)model->code; for(t=0;t<model->sig->num_inputs;t++) { if(t) strf(s, ", "); strf(s, "%s", s->model->sig->column_names[t]); } } else { strf(s, "data"); } strf(s, ")\n"); indent(s); }
void ruby_write_node_sub(node_t*n, state_t*s) { int t; for(t=0;t<n->num_children;t++) { if(t && !node_has_minus_prefix(n->child[t])) strf(s, "-"); write_node(s, n->child[t]); } }
void c_enumerate_arrays(node_t*node, state_t*s) { if(node_is_array(node)) { strf(s, "%s a%x[%d] = ", c_type_name(constant_array_subtype(&node->value)), (long)(node->value.a), node->value.a->size ); c_write_constant(&node->value, s); strf(s, ";\n"); } else { int t; for(t=0;t<node->num_children;t++) { c_enumerate_arrays(node->child[t], s); } } }
void ruby_write_node_block(node_t*n, state_t*s) { int t; for(t=0;t<n->num_children;t++) { if(t) strf(s, "\n"); write_node(s, n->child[t]); } }
static void c_write_function_sqr(state_t*s) { strf(s, "%s", "static inline double sqr(const double v)\n" "{\n" " return v*v\n" "}\n" ); }
void c_write_node_block(node_t*n, state_t*s) { int t; if(n->parent) { strf(s, "{\n"); indent(s); } for(t=0;t<n->num_children;t++) { if(t) strf(s, "\n"); write_node(s, n->child[t]); strf(s, ";"); } if(n->parent) { dedent(s); strf(s, "\n}\n"); } }
static void ruby_write_function_term_frequency(state_t*s) { strf(s, "def term_frequency(str, term)\n" " words = str.split(/\\s+/)\n" " return 0.0 if words.empty?\n" " words.select {|word| word == term}.length.to_f / words.length\n" "end\n"); }
static void c_write_function_compare_float_ptr(state_t*s) { strf(s, "%s", "static int compare_float_ptr(const void*p1, const void*p2)\n" "{\n" " const float*f1 = (const float*)p1;\n" " const float*f2 = (const float*)p2;\n" " if(*f1<*f2) return -1;\n" " if(*f1>*f2) return 1;\n" " return 0;\n" "}\n" ); }