R_API PJ *pj_k(PJ *j, const char *k) { r_return_val_if_fail (j && k, NULL); j->is_key = false; pj_s (j, k); pj_raw (j, ":"); j->is_first = false; j->is_key = true; return j; }
R_API int r_core_project_list(RCore *core, int mode) { PJ *pj = NULL; RListIter *iter; RList *list; char *foo, *path = r_file_abspath (r_config_get (core->config, "dir.projects")); if (!path) { return 0; } list = r_sys_dir (path); switch (mode) { case 'j': pj = pj_new (); if (!pj) { break; } pj_a (pj); r_list_foreach (list, iter, foo) { // todo. escape string if (r_core_is_project (core, foo)) { pj_s (pj, foo); } } pj_end (pj); r_cons_printf ("%s\n", pj_string (pj)); pj_free (pj); break; default: r_list_foreach (list, iter, foo) { if (r_core_is_project (core, foo)) { r_cons_println (foo); } } break; } r_list_free (list); free (path); return 0; }
R_API char *pj_fmt(PrintfCallback p, const char *fmt, ...) { va_list ap; va_start (ap, fmt); char ch[2] = { 0 }; PJ *j = pj_new (); while (*fmt) { j->is_first = true; ch[0] = *fmt; switch (*fmt) { case '\\': fmt++; switch (*fmt) { // TODO: add \x, and \e case 'e': pj_raw (j, "\x1b"); break; case 'r': pj_raw (j, "\r"); break; case 'n': pj_raw (j, "\n"); break; case 'b': pj_raw (j, "\b"); break; } break; case '\'': pj_raw (j, "\""); break; case '%': fmt++; switch (*fmt) { case 'b': pj_b (j, va_arg (ap, int)); break; case 's': pj_s (j, va_arg (ap, const char *)); break; case 'S': { const char *s = va_arg (ap, const char *); char *es = r_base64_encode_dyn (s, -1); pj_s (j, es); free (es); } break; case 'n': pj_n (j, va_arg (ap, ut64)); break; case 'd': pj_d (j, va_arg (ap, double)); break; case 'i': pj_i (j, va_arg (ap, int)); break; default: eprintf ("Invalid format\n"); break; } break; default: ch[0] = *fmt; pj_raw (j, ch); break; } fmt++; } char *ret = NULL; if (p) { p ("%s", r_strbuf_get (j->sb)); pj_free (j); } else { ret = pj_drain (j); } va_end (ap); return ret; }
R_API PJ *pj_ks(PJ *j, const char *k, const char *v) { pj_k (j, k); pj_s (j, v); return j; }