struct pkg_format_node * pkg_format_parse(const char *fmt, struct dpkg_error *err) { struct pkg_format_node *head; struct pkg_format_node *cur; const char *fmtend; head = cur = NULL; while (*fmt) { if (cur) cur = cur->next = pkg_format_node_new(); else head = cur = pkg_format_node_new(); if (fmt[0] == '$' && fmt[1] == '{') { fmtend = strchr(fmt, '}'); if (!fmtend) { dpkg_put_error(err, _("missing closing brace")); pkg_format_free(head); return NULL; } if (!parsefield(cur, fmt + 2, fmtend - 1, err)) { pkg_format_free(head); return NULL; } fmt = fmtend + 1; } else { fmtend = fmt; do { fmtend += 1; fmtend = strchr(fmtend, '$'); } while (fmtend && fmtend[1] != '{'); if (!fmtend) fmtend = fmt + strlen(fmt); if (!parsestring(cur, fmt, fmtend - 1, err)) { pkg_format_free(head); return NULL; } fmt = fmtend; } } if (!head) dpkg_put_error(err, _("may not be empty string")); return head; }
struct pkg_format_node * pkg_format_parse(const char *fmt) { struct pkg_format_node *head; struct pkg_format_node *cur; const char *fmtend; head = cur = NULL; while (*fmt) { if (cur) cur = cur->next = pkg_format_node_new(); else head = cur = pkg_format_node_new(); if (fmt[0] == '$' && fmt[1] == '{') { fmtend = strchr(fmt, '}'); if (!fmtend) { fprintf(stderr, _("Closing brace missing in format\n")); pkg_format_free(head); return NULL; } if (!parsefield(cur, fmt + 2, fmtend - 1)) { pkg_format_free(head); return NULL; } fmt = fmtend + 1; } else { fmtend = fmt; do { fmtend += 1; fmtend = strchr(fmtend, '$'); } while (fmtend && fmtend[1] != '{'); if (!fmtend) fmtend = fmt + strlen(fmt); if (!parsestring(cur, fmt, fmtend - 1)) { pkg_format_free(head); return NULL; } fmt = fmtend; } } return head; }
int do_showinfo(const char *const *argv) { const char *debar, *dir; char *controlfile; struct pkginfo *pkg; struct pkg_format_node *fmt = pkg_format_parse(showformat); if (!fmt) ohshit(_("Error in format")); info_prepare(&argv, &debar, &dir, 1); m_asprintf(&controlfile, "%s/%s", dir, CONTROLFILE); parsedb(controlfile, pdb_parse_binary | pdb_ignorefiles, &pkg); pkg_format_show(fmt, pkg, &pkg->available); pkg_format_free(fmt); free(controlfile); return 0; }