- int i, j;
- char *str;
- int depends_count = pkg->pre_depends_count +
- pkg->depends_count +
- pkg->recommends_count +
- pkg->suggests_count;
-
- if (strlen(field) < PKG_MINIMUM_FIELD_NAME_LEN) {
- goto UNKNOWN_FMT_FIELD;
- }
-
- switch (field[0])
- {
- case 'a':
- case 'A':
- if (strcasecmp(field, "Architecture") == 0) {
- if (pkg->architecture) {
- fprintf(fp, "Architecture: %s\n", pkg->architecture);
- }
- } else if (strcasecmp(field, "Auto-Installed") == 0) {
- if (pkg->auto_installed)
- fprintf(fp, "Auto-Installed: yes\n");
- } else {
- goto UNKNOWN_FMT_FIELD;
- }
- break;
- case 'c':
- case 'C':
- if (strcasecmp(field, "Conffiles") == 0) {
- conffile_list_elt_t *iter;
-
- if (nv_pair_list_empty(&pkg->conffiles))
- return;
-
- fprintf(fp, "Conffiles:\n");
- for (iter = nv_pair_list_first(&pkg->conffiles); iter; iter = nv_pair_list_next(&pkg->conffiles, iter)) {
- if (((conffile_t *)iter->data)->name && ((conffile_t *)iter->data)->value) {
- fprintf(fp, " %s %s\n",
- ((conffile_t *)iter->data)->name,
- ((conffile_t *)iter->data)->value);
- }
- }
- } else if (strcasecmp(field, "Conflicts") == 0) {
- struct depend *cdep;
- if (pkg->conflicts_count) {
- fprintf(fp, "Conflicts:");
- for(i = 0; i < pkg->conflicts_count; i++) {
- cdep = pkg->conflicts[i].possibilities[0];
- fprintf(fp, "%s %s", i == 0 ? "" : ",",
- cdep->pkg->name);
- if (cdep->version) {
- fprintf(fp, " (%s%s)",
- constraint_to_str(cdep->constraint),
- cdep->version);
+ int i, j;
+ char *str;
+ int depends_count = pkg->pre_depends_count +
+ pkg->depends_count + pkg->recommends_count + pkg->suggests_count;
+
+ if (strlen(field) < PKG_MINIMUM_FIELD_NAME_LEN) {
+ goto UNKNOWN_FMT_FIELD;
+ }
+
+ switch (field[0]) {
+ case 'a':
+ case 'A':
+ if (strcasecmp(field, "Architecture") == 0) {
+ if (pkg->architecture) {
+ fprintf(fp, "Architecture: %s\n",
+ pkg->architecture);
+ }
+ } else if (strcasecmp(field, "Auto-Installed") == 0) {
+ if (pkg->auto_installed)
+ fprintf(fp, "Auto-Installed: yes\n");
+ } else {
+ goto UNKNOWN_FMT_FIELD;
+ }
+ break;
+ case 'c':
+ case 'C':
+ if (strcasecmp(field, "Conffiles") == 0) {
+ conffile_list_elt_t *iter;
+
+ if (nv_pair_list_empty(&pkg->conffiles))
+ return;
+
+ fprintf(fp, "Conffiles:\n");
+ for (iter = nv_pair_list_first(&pkg->conffiles); iter;
+ iter = nv_pair_list_next(&pkg->conffiles, iter)) {
+ if (((conffile_t *) iter->data)->name
+ && ((conffile_t *) iter->data)->value) {
+ fprintf(fp, " %s %s\n",
+ ((conffile_t *) iter->data)->
+ name,
+ ((conffile_t *) iter->data)->
+ value);
+ }
+ }
+ } else if (strcasecmp(field, "Conflicts") == 0) {
+ struct depend *cdep;
+ if (pkg->conflicts_count) {
+ fprintf(fp, "Conflicts:");
+ for (i = 0; i < pkg->conflicts_count; i++) {
+ cdep =
+ pkg->conflicts[i].possibilities[0];
+ fprintf(fp, "%s %s", i == 0 ? "" : ",",
+ cdep->pkg->name);
+ if (cdep->version) {
+ fprintf(fp, " (%s%s)",
+ constraint_to_str(cdep->
+ constraint),
+ cdep->version);
+ }
+ }
+ fprintf(fp, "\n");
+ }
+ } else {
+ goto UNKNOWN_FMT_FIELD;
+ }
+ break;
+ case 'd':
+ case 'D':
+ if (strcasecmp(field, "Depends") == 0) {
+ if (pkg->depends_count) {
+ fprintf(fp, "Depends:");
+ for (j = 0, i = 0; i < depends_count; i++) {
+ if (pkg->depends[i].type != DEPEND)
+ continue;
+ str = pkg_depend_str(pkg, i);
+ fprintf(fp, "%s %s", j == 0 ? "" : ",",
+ str);
+ free(str);
+ j++;
+ }
+ fprintf(fp, "\n");
+ }
+ } else if (strcasecmp(field, "Description") == 0) {
+ if (pkg->description) {
+ fprintf(fp, "Description: %s\n",
+ pkg->description);
+ }
+ } else {
+ goto UNKNOWN_FMT_FIELD;
+ }
+ break;
+ case 'e':
+ case 'E':
+ if (pkg->essential) {
+ fprintf(fp, "Essential: yes\n");
+ }
+ break;
+ case 'f':
+ case 'F':
+ if (pkg->filename) {
+ fprintf(fp, "Filename: %s\n", pkg->filename);
+ }
+ break;
+ case 'i':
+ case 'I':
+ if (strcasecmp(field, "Installed-Size") == 0) {
+ fprintf(fp, "Installed-Size: %ld\n",
+ pkg->installed_size);
+ } else if (strcasecmp(field, "Installed-Time") == 0
+ && pkg->installed_time) {
+ fprintf(fp, "Installed-Time: %lu\n",
+ pkg->installed_time);
+ }
+ break;
+ case 'm':
+ case 'M':
+ if (strcasecmp(field, "Maintainer") == 0) {
+ if (pkg->maintainer) {
+ fprintf(fp, "Maintainer: %s\n",
+ pkg->maintainer);
+ }
+ } else if (strcasecmp(field, "MD5sum") == 0) {
+ if (pkg->md5sum) {
+ fprintf(fp, "MD5Sum: %s\n", pkg->md5sum);
+ }
+ } else {
+ goto UNKNOWN_FMT_FIELD;
+ }
+ break;
+ case 'p':
+ case 'P':
+ if (strcasecmp(field, "Package") == 0) {
+ fprintf(fp, "Package: %s\n", pkg->name);
+ } else if (strcasecmp(field, "Priority") == 0) {
+ fprintf(fp, "Priority: %s\n", pkg->priority);
+ } else if (strcasecmp(field, "Provides") == 0) {
+ if (pkg->provides_count > 1) {
+ fprintf(fp, "Provides:");
+ for (i = 1; i < pkg->provides_count; i++) {
+ fprintf(fp, "%s %s", i == 1 ? "" : ",",
+ pkg->provides[i]->name);
+ }
+ fprintf(fp, "\n");
+ }
+ } else {
+ goto UNKNOWN_FMT_FIELD;
+ }
+ break;
+ case 'r':
+ case 'R':
+ if (strcasecmp(field, "Replaces") == 0) {
+ if (pkg->replaces_count) {
+ fprintf(fp, "Replaces:");
+ for (i = 0; i < pkg->replaces_count; i++) {
+ fprintf(fp, "%s %s", i == 0 ? "" : ",",
+ pkg->replaces[i]->name);
+ }
+ fprintf(fp, "\n");
+ }
+ } else if (strcasecmp(field, "Recommends") == 0) {
+ if (pkg->recommends_count) {
+ fprintf(fp, "Recommends:");
+ for (j = 0, i = 0; i < depends_count; i++) {
+ if (pkg->depends[i].type != RECOMMEND)
+ continue;
+ str = pkg_depend_str(pkg, i);
+ fprintf(fp, "%s %s", j == 0 ? "" : ",",
+ str);
+ free(str);
+ j++;
+ }
+ fprintf(fp, "\n");
+ }
+ } else {
+ goto UNKNOWN_FMT_FIELD;
+ }
+ break;
+ case 's':
+ case 'S':
+ if (strcasecmp(field, "Section") == 0) {
+ if (pkg->section) {
+ fprintf(fp, "Section: %s\n", pkg->section);