String& String::operator+ (int val) // concatenate { char s[16]; itoa(val,s,10); _concat (s); return *this; }
int main (int argc, char *argv[]) { char *output; char **inputs; dsr_t newhdr; dsr_t *hdrs; uint16_t i; uint16_t ninputs; float dimsz; hdrs = NULL; startup("catimg", argc, argv, NULL, NULL); if (argc < 5) { printf("usage: catimg output dimsz input input [input ...]\n"); goto fail; } ninputs = argc-3; output = argv[1]; dimsz = atof(argv[2]); inputs = argv+3; hdrs = malloc(ninputs*sizeof(dsr_t)); if (hdrs == NULL) goto fail; for (i = 0; i < ninputs; i++) { if (analyze_load_hdr(inputs[i], hdrs+i)) { printf("Couldn't load image %s\n", inputs[i]); goto fail; } } if (analyze_hdr_compat(ninputs, hdrs, 0)) { printf("Headers aren't compatible\n"); goto fail; } _mk_hdr(&newhdr, hdrs, ninputs, dimsz); if (_concat(output, inputs, ninputs)) { printf("Cat failed, simple as that\n"); goto fail; } if (analyze_write_hdr(output, &newhdr)) { printf("Write failed to %s\n", output); goto fail; } free(hdrs); return 0; fail: printf("Cat failed\n"); if (hdrs != NULL) free(hdrs); return 1; }
RegNodePtr _or() { auto r = _concat(); if (tryConsume('|')) { r.reset(new RegNode_Or(r, _or())); } return r; }
RegNodePtr _concat() { auto r = _repeat(); if (!r) return r; if (auto n = _concat()) { r.reset(new RegNode_Concat(r, n)); } return r; }
bool write_report(CveCheckTool *self, char *filename) { autofree(gchar) *bottom, *package, *top; autofree(GError) *error = NULL; bottom = package = top = NULL; autofree(GHashTable) *macros = NULL; autofree(gchar) *aff = NULL; autofree(gchar) *output = NULL; autofree(gchar) *body = NULL; GHashTableIter iter; gchar *key = NULL; struct source_package_t *v = NULL; GList *c = NULL; struct cve_entry_t *c_entry = NULL; gint affected = 0; guint row = 0; /* Mandatory template files */ LOAD_TEMPLATE(TMPL_BOTTOM, &bottom); LOAD_TEMPLATE(TMPL_PACKAGE, &package); LOAD_TEMPLATE(TMPL_TOP, &top); macros = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, NULL); g_hash_table_insert(macros, "LNVD_CVE_URI", NVD_CVE_URI); g_hash_table_iter_init(&iter, self->db); while (g_hash_table_iter_next(&iter, (void**)&key, (void**)&v)) { bool hit = false; if (!v->issues && !v->patched && !self->show_unaffected) { continue; } if (!v->issues && self->hide_patched) { continue; } guint cve_len = 0; if (v->issues) { cve_len += g_list_length(v->issues); } if (v->patched && !self->hide_patched) { cve_len += g_list_length(v->patched); } g_hash_table_insert(macros, "PACKAGE_NAME", key); /* TODO: Collapse redundancy into helper. */ g_hash_table_insert(macros, "STATUS_CLASS", "not-patched"); g_hash_table_insert(macros, "STATUS_STRING", "Check"); for (c = v->issues; c; c = c->next) { autofree(gchar) *ent = NULL; c_entry = g_hash_table_lookup(self->cdb, (gchar*)c->data); if (self->modified > 0 && c_entry->modified > self->modified) { continue; } hit = true; g_hash_table_insert(macros, "LCVEID", c_entry->id); g_hash_table_insert(macros, "CVEID", c_entry->id); g_hash_table_insert(macros, "DESC", c_entry->summary); g_hash_table_insert(macros, "ROW_CLASS", row % 2 ? "even" : "odd"); g_hash_table_insert(macros, "SCORE", c_entry->score); /* TODO: Add links .. */ ent = g_strdup(package); ent = dotemplate(macros, ent); if (body) { body = _concat(body, ent); } else { body = g_strdup(ent); } ++row; } g_hash_table_insert(macros, "STATUS_CLASS", "patched"); g_hash_table_insert(macros, "STATUS_STRING", "Patched"); if (!self->hide_patched && v->patched) { for (c = v->patched; c; c = c->next) { autofree(gchar) *ent = NULL; c_entry = g_hash_table_lookup(self->cdb, (gchar*)c->data); if (self->modified > 0 && c_entry->modified > self->modified) { continue; } hit = true; g_hash_table_insert(macros, "LCVEID", c_entry->id); g_hash_table_insert(macros, "CVEID", c_entry->id); g_hash_table_insert(macros, "DESC", c_entry->summary); g_hash_table_insert(macros, "ROW_CLASS", row % 2 ? "even" : "odd"); g_hash_table_insert(macros, "SCORE", c_entry->score); /* TODO: Add links .. */ ent = g_strdup(package); ent = dotemplate(macros, ent); if (body) { body = _concat(body, ent); } else { body = g_strdup(ent); } ++row; } } if (hit) { ++affected; } } aff = g_strdup_printf("CVE Report for %d package%s", affected, affected > 1 ? "s" : ""); g_hash_table_insert(macros, "AFFECTED_STRING", aff); top = dotemplate(macros, top); output = g_strdup(top); output = _concat(output, body); output = _concat(output, bottom); /* Write file */ if (!g_file_set_contents(filename, output, -1, &error)) { g_printerr("Unable to write report: %s\n", error->message); return false; } return true; }
String& String::operator+ (String const & s) { _concat (s); return *this; }
String& String::operator+ (char const * s) // concatenate { _concat (s); return *this; }
int String::_concat (String const & s) { return _concat (s.c_ptr(), s.length()); }
QVariant ZStringFormatter::transform(QVariant val){ if(method() == ZFMT_METHOD_STR_CONCAT){ //! concat( with ) return _concat(val,arg("with",ZML_DEFAULT_PARAM_NAME)); }else if(method() == ZFMT_METHOD_STR_DOWNCASE){ //! downcase return _downcase(val); }else if(method() == ZFMT_METHOD_STR_ELIDE){ //! elide( [maxLength [, placeholder]] ) if(arg("placeholder").isValid()) return _elide(val, arg("maxLength",ZML_DEFAULT_PARAM_NAME).toInt(), arg("placeholder").toString()); else return _elide(val, arg("maxLength",ZML_DEFAULT_PARAM_NAME).toInt()); }else if(method() == ZFMT_METHOD_STR_LEFT){ //! left( length ) return _left(val, arg("length",ZML_DEFAULT_PARAM_NAME).toUInt()); }else if(method() == ZFMT_METHOD_STR_LEFTOF){ //! leftOf( delimiter ) return _leftOf(val, arg("delimiter",ZML_DEFAULT_PARAM_NAME).toString()); }else if(method() == ZFMT_METHOD_STR_LELIDE){ //! lelide( [maxLength [, placeholder]] ) if(arg("placeholder").isValid()) return _lelide(val, arg("maxLength",ZML_DEFAULT_PARAM_NAME).toInt(), arg("placeholder").toString()); else return _lelide(val, arg("maxLength",ZML_DEFAULT_PARAM_NAME).toInt()); }else if(method() == ZFMT_METHOD_STR_LPAD){ //! lpad( length [, symbol] ) if(arg("symbol").isValid()) return _lpad(val, arg("length",ZML_DEFAULT_PARAM_NAME).toUInt(), arg("symbol").toChar()); else return _lpad(val, arg("length",ZML_DEFAULT_PARAM_NAME).toUInt()); }else if(method() == ZFMT_METHOD_STR_LSHIFT){ //! lshift( places ) return _lshift(val, arg("places", ZML_DEFAULT_PARAM_NAME).toUInt()); }else if(method() == ZFMT_METHOD_STR_LTRIM){ //! ltrim( [pattern] ) if(arg("pattern").isValid()) return _ltrim(val, arg("pattern",ZML_DEFAULT_PARAM_NAME).toString()); else return _ltrim(val); }else if(method() == ZFMT_METHOD_STR_RELIDE){ //! relide( [maxLength [, placeholder]] ) if(arg("placeholder").isValid()) return _relide(val, arg("maxLength",ZML_DEFAULT_PARAM_NAME).toInt(), arg("placeholder").toString()); else return _relide(val, arg("maxLength",ZML_DEFAULT_PARAM_NAME).toInt()); }else if(method() == ZFMT_METHOD_STR_REPEAT){ //! repeat( times ) return _repeat(val, arg("times",ZML_DEFAULT_PARAM_NAME).toUInt()); }else if(method() == ZFMT_METHOD_STR_REVERSE){ //! reverse return _reverse(val); }else if(method() == ZFMT_METHOD_STR_RIGHT){ //! right( length ) return _right(val, arg("length",ZML_DEFAULT_PARAM_NAME).toUInt()); }else if(method() == ZFMT_METHOD_STR_RIGHTOF){ //! rightOf( delimiter ) return _rightOf(val, arg("delimiter",ZML_DEFAULT_PARAM_NAME).toString()); }else if(method() == ZFMT_METHOD_STR_RPAD){ //! rpad( length [, symbol] ) if(arg("symbol").isValid()) return _rpad(val, arg("length",ZML_DEFAULT_PARAM_NAME).toUInt(), arg("symbol").toChar()); else return _rpad(val, arg("length",ZML_DEFAULT_PARAM_NAME).toUInt()); }else if(method() == ZFMT_METHOD_STR_RSHIFT){ //! rshift( places ) return _rshift(val, arg("places",ZML_DEFAULT_PARAM_NAME).toUInt()); }else if(method() == ZFMT_METHOD_STR_RTRIM){ //! rtrim( [pattern] ) if(arg("pattern").isValid()) return _rtrim(val, arg("pattern",ZML_DEFAULT_PARAM_NAME).toString()); else return _rtrim(val); }else if(method() == ZFMT_METHOD_STR_SCASE){ //! capitalize return _sentenceCase(val); }else if(method() == ZFMT_METHOD_STR_SQUEEZE){ //! squeeze( [symbol] ) if(arg("symbol").isValid()) return _squeeze(val, arg("symbol",ZML_DEFAULT_PARAM_NAME).toChar()); else return _squeeze(val); }else if(method() == ZFMT_METHOD_STR_TCASE){ //! titleize return _titleCase(val); }else if(method() == ZFMT_METHOD_STR_TRIM){ //! trim( [pattern] ) if(arg("pattern").isValid()) return _trim(val, arg("pattern",ZML_DEFAULT_PARAM_NAME).toString()); else return _trim(val); }else if(method() == ZFMT_METHOD_STR_UPCASE){ //! upcase return _upcase(val); } return val; }