+void show_note(struct zpm_note *n) {
+ printf("Note %" PRId64 " %s\n", n->id, n->ts);
+ if (n->pkgid) {
+ printf("Package: %s\n", n->pkgid);
+ }
+ if (n->file) {
+ printf("Hash: %s\n", n->file);
+ }
+
+ printf("%s\n", n->note);
+}
+
+void jstring(char *field, char *value, int indent, int final) {
+ while (indent--) {
+ putchar('\t');
+ }
+ printf("\"%s\": ", field);
+ if (value) {
+ printf("\"%s\": ", value);
+ } else {
+ printf("null");
+ }
+ if (!final) {
+ printf(",");
+ }
+ putchar('\n');
+}
+
+void show_json(struct zpm_note *n) {
+ size_t len = 0;
+
+ if (n->pkgid) {
+ len = strcspn(n->note, "\n\r");
+ }
+
+ printf("{\n\t\"id\": %" PRId64 ",\n", n->id);
+ jstring("package", n->pkgid, 1, 0);
+ jstring("hash", n->file, 1, 0);
+
+ if (len) {
+ printf("\t\"subject\": \"%.*s\",\n", (int)len, n->note);
+ } else {
+ printf("\t\"subject\": null,\n");
+ }
+ jstring("note", n->note, 1, 1);
+ printf("}\n");
+}
+