summaryrefslogtreecommitdiff
path: root/src/print.c
diff options
context:
space:
mode:
authorNatanael Copa <ncopa@alpinelinux.org>2010-03-05 08:13:25 +0000
committerNatanael Copa <ncopa@alpinelinux.org>2010-06-11 07:02:18 +0000
commit3ec82a5a420fc00d38ad7dded819525a91533652 (patch)
tree84016128e65001e4aed1d45a1402b2fb2375c385 /src/print.c
parent60b537e356dfcd0ed9a3516152c6a170912efcef (diff)
downloadapk-tools-3ec82a5a420fc00d38ad7dded819525a91533652.tar.gz
apk-tools-3ec82a5a420fc00d38ad7dded819525a91533652.tar.bz2
apk-tools-3ec82a5a420fc00d38ad7dded819525a91533652.tar.xz
apk-tools-3ec82a5a420fc00d38ad7dded819525a91533652.zip
First steps for libapk
Diffstat (limited to 'src/print.c')
-rw-r--r--src/print.c70
1 files changed, 70 insertions, 0 deletions
diff --git a/src/print.c b/src/print.c
new file mode 100644
index 0000000..4b3d246
--- /dev/null
+++ b/src/print.c
@@ -0,0 +1,70 @@
+/* state.c - Alpine Package Keeper (APK)
+ *
+ * Copyright (C) 2005-2008 Natanael Copa <n@tanael.org>
+ * Copyright (C) 2008 Timo Teräs <timo.teras@iki.fi>
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published
+ * by the Free Software Foundation. See http://www.gnu.org/ for details.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <malloc.h>
+#include <errno.h>
+
+#include "apk_defines.h"
+#include "apk_print.h"
+
+int apk_print_indented(struct apk_indent *i, apk_blob_t blob)
+{
+ static const int wrap_length = 80;
+
+ if (i->x + blob.len + 1 >= wrap_length) {
+ i->x = i->indent;
+ printf("\n%*s", i->indent - 1, "");
+ }
+ i->x += printf(" %.*s", blob.len, blob.ptr);
+ return 0;
+}
+
+void apk_print_indented_words(struct apk_indent *i, const char *text)
+{
+ apk_blob_for_each_segment(APK_BLOB_STR(text), " ",
+ (apk_blob_cb) apk_print_indented, i);
+}
+
+const char *apk_error_str(int error)
+{
+ if (error < 0)
+ error = -error;
+ switch (error) {
+ case ENOKEY:
+ return "UNTRUSTED signature";
+ case EKEYREJECTED:
+ return "BAD signature";
+ case EIO:
+ return "IO ERROR";
+ case EBADMSG:
+ return "BAD archive";
+ case ENOMSG:
+ return "archive does not contain expected data";
+ default:
+ return strerror(error);
+ }
+}
+
+void apk_log(const char *prefix, const char *format, ...)
+{
+ va_list va;
+
+ if (prefix != NULL)
+ fprintf(stderr, "%s", prefix);
+ va_start(va, format);
+ vfprintf(stderr, format, va);
+ va_end(va);
+ fprintf(stderr, "\n");
+}
+