const char * pool_solvable2str(Pool *pool, Solvable *s) { const char *n, *e, *a; int nl, el, al; char *p; n = pool_id2str(pool, s->name); e = pool_id2str(pool, s->evr); /* XXX: may want to skip the epoch here */ a = pool_id2str(pool, s->arch); nl = strlen(n); el = strlen(e); al = strlen(a); if (pool->havedistepoch) { /* strip the distepoch from the evr */ const char *de = strrchr(e, '-'); if (de && (de = strchr(de, ':')) != 0) el = de - e; } p = pool_alloctmpspace(pool, nl + el + al + 3); strcpy(p, n); if (el) { p[nl++] = '-'; strncpy(p + nl, e, el); p[nl + el] = 0; } if (al) { p[nl + el] = pool->disttype == DISTTYPE_HAIKU ? '-' : '.'; strcpy(p + nl + el + 1, a); } return p; }
const char * pool_dep2str(Pool *pool, Id id) { char *p; if (!ISRELDEP(id)) return pool->ss.stringspace + pool->ss.strings[id]; p = pool_alloctmpspace(pool, dep2strlen(pool, id) + 1); dep2strcpy(pool, p, id, 0); return p; }
static const char * jsonstring(Pool *pool, const char *s) { int needed = 0; const unsigned char *s1; char *r, *rp; for (s1 = (const unsigned char *)s; *s1; s1++) { if (*s1 < 32) needed += *s1 == '\n' ? 2 : 6; else if (*s1 == '\\' || *s1 == '\"') needed += 2; else needed++; } r = rp = pool_alloctmpspace(pool, needed + 3); *rp++ = '\"'; for (s1 = (const unsigned char *)s; *s1; s1++) { if (*s1 < 32) { int x; if (*s1 == '\n') { *rp++ = '\\'; *rp++ = 'n'; continue; } *rp++ = '\\'; *rp++ = 'u'; *rp++ = '0'; *rp++ = '0'; x = *s1 / 16; *rp++ = (x < 10 ? '0' : 'a' - 10) + x; x = *s1 & 15; *rp++ = (x < 10 ? '0' : 'a' - 10) + x; } else if (*s1 == '\\' || *s1 == '\"') { *rp++ = '\\'; *rp++ = *s1; } else *rp++ = *s1; } *rp++ = '\"'; *rp = 0; return r; }
const char * pool_solvable2str(Pool *pool, Solvable *s) { const char *n, *e, *a; int nl, el, al; char *p; n = pool_id2str(pool, s->name); e = s->evr ? pool_id2str(pool, s->evr) : ""; /* XXX: may want to skip the epoch here */ a = s->arch ? pool_id2str(pool, s->arch) : ""; nl = strlen(n); el = strlen(e); al = strlen(a); if (pool->havedistepoch) { /* strip the distepoch from the evr */ const char *de = strrchr(e, '-'); if (de && (de = strchr(de, ':')) != 0) el = de - e; } p = pool_alloctmpspace(pool, nl + el + al + 3); strcpy(p, n); if (el) { p[nl++] = '-'; strncpy(p + nl, e, el); p[nl + el] = 0; } if (al) { p[nl + el] = pool->disttype == DISTTYPE_HAIKU ? '-' : '.'; strcpy(p + nl + el + 1, a); } if (pool->disttype == DISTTYPE_CONDA && solvable_lookup_type(s, SOLVABLE_BUILDFLAVOR)) { Queue flavorq; int i; queue_init(&flavorq); solvable_lookup_idarray(s, SOLVABLE_BUILDFLAVOR, &flavorq); for (i = 0; i < flavorq.count; i++) p = pool_tmpappend(pool, p, "-", pool_id2str(pool, flavorq.elements[i])); queue_free(&flavorq); } return p; }