2010-06-11 07:09:25 +00:00
|
|
|
/* apk_print.h - Alpine Package Keeper (APK)
|
2010-03-05 08:13:25 +00:00
|
|
|
*
|
|
|
|
* Copyright (C) 2005-2008 Natanael Copa <n@tanael.org>
|
2011-09-13 08:53:01 +00:00
|
|
|
* Copyright (C) 2008-2011 Timo Teräs <timo.teras@iki.fi>
|
2010-03-05 08:13:25 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
2020-04-22 13:33:41 +00:00
|
|
|
* SPDX-License-Identifier: GPL-2.0-only
|
2010-03-05 08:13:25 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef APK_PRINT_H
|
|
|
|
#define APK_PRINT_H
|
|
|
|
|
|
|
|
#include "apk_blob.h"
|
|
|
|
|
2020-10-05 15:52:51 +00:00
|
|
|
const char *apk_error_str(int error);
|
2021-06-02 19:35:58 +00:00
|
|
|
int apk_get_human_size_unit(apk_blob_t b);
|
2020-10-05 15:52:51 +00:00
|
|
|
const char *apk_get_human_size(off_t size, off_t *dest);
|
|
|
|
|
2020-10-05 09:58:46 +00:00
|
|
|
struct apk_url_print {
|
|
|
|
const char *url;
|
|
|
|
const char *pwmask;
|
|
|
|
const char *url_or_host;
|
|
|
|
size_t len_before_pw;
|
|
|
|
};
|
|
|
|
|
|
|
|
void apk_url_parse(struct apk_url_print *, const char *);
|
|
|
|
|
|
|
|
#define URL_FMT "%.*s%s%s"
|
2021-07-26 07:25:23 +00:00
|
|
|
#define URL_PRINTF(u) (int)u.len_before_pw, u.url, u.pwmask, u.url_or_host
|
2020-10-05 09:58:46 +00:00
|
|
|
|
2020-10-05 15:52:51 +00:00
|
|
|
struct apk_out {
|
|
|
|
int verbosity;
|
|
|
|
unsigned int width, last_change;
|
2021-02-14 15:01:02 +00:00
|
|
|
FILE *out, *err, *log;
|
2020-10-05 15:52:51 +00:00
|
|
|
};
|
2010-03-05 08:13:25 +00:00
|
|
|
|
2020-10-05 15:52:51 +00:00
|
|
|
static inline int apk_out_verbosity(struct apk_out *out) { return out->verbosity; }
|
2010-03-05 08:13:25 +00:00
|
|
|
|
2021-02-14 15:01:02 +00:00
|
|
|
// Pass this as the prefix to skip logging to the console (but still write to
|
|
|
|
// the log file).
|
|
|
|
#define APK_OUT_LOG_ONLY ((const char*)-1)
|
|
|
|
|
2020-10-05 15:52:51 +00:00
|
|
|
#define apk_err(out, args...) do { apk_out_fmt(out, "ERROR: ", args); } while (0)
|
|
|
|
#define apk_out(out, args...) do { apk_out_fmt(out, NULL, args); } while (0)
|
|
|
|
#define apk_warn(out, args...) do { if (apk_out_verbosity(out) >= 0) { apk_out_fmt(out, "WARNING: ", args); } } while (0)
|
|
|
|
#define apk_msg(out, args...) do { if (apk_out_verbosity(out) >= 1) { apk_out_fmt(out, NULL, args); } } while (0)
|
|
|
|
#define apk_dbg(out, args...) do { if (apk_out_verbosity(out) >= 2) { apk_out_fmt(out, NULL, args); } } while (0)
|
|
|
|
#define apk_dbg2(out, args...) do { if (apk_out_verbosity(out) >= 3) { apk_out_fmt(out, NULL, args); } } while (0)
|
|
|
|
|
|
|
|
void apk_out_reset(struct apk_out *);
|
2021-07-26 07:25:23 +00:00
|
|
|
void apk_out_fmt(struct apk_out *, const char *prefix, const char *format, ...)
|
|
|
|
__attribute__ ((format (printf, 3, 4)));
|
2021-02-14 15:01:02 +00:00
|
|
|
void apk_out_log_argv(struct apk_out *, char **argv);
|
2011-09-09 17:06:10 +00:00
|
|
|
|
2020-10-05 13:47:24 +00:00
|
|
|
struct apk_progress {
|
2020-10-05 15:52:51 +00:00
|
|
|
struct apk_out *out;
|
|
|
|
int fd, last_bar, last_percent;
|
|
|
|
unsigned int last_out_change;
|
2020-10-05 13:47:24 +00:00
|
|
|
size_t last_done;
|
|
|
|
const char *progress_char;
|
|
|
|
};
|
|
|
|
|
|
|
|
void apk_print_progress(struct apk_progress *p, size_t done, size_t total);
|
|
|
|
|
2011-09-09 17:06:10 +00:00
|
|
|
struct apk_indent {
|
2020-10-05 15:52:51 +00:00
|
|
|
struct apk_out *out;
|
|
|
|
int x, indent;
|
2011-09-09 17:06:10 +00:00
|
|
|
};
|
|
|
|
|
2013-06-17 13:47:49 +00:00
|
|
|
int apk_print_indented(struct apk_indent *i, apk_blob_t blob);
|
2010-03-05 08:13:25 +00:00
|
|
|
void apk_print_indented_words(struct apk_indent *i, const char *text);
|
2021-07-26 07:25:23 +00:00
|
|
|
void apk_print_indented_fmt(struct apk_indent *i, const char *fmt, ...)
|
|
|
|
__attribute__ ((format (printf, 2, 3)));
|
2010-03-05 08:13:25 +00:00
|
|
|
|
|
|
|
#endif
|