X-Git-Url: https://git.librecmc.org/?p=oweals%2Fopkg-lede.git;a=blobdiff_plain;f=libopkg%2Fopkg_message.c;h=4a24039bbd2fbdf1bcaf70c030c7c1f6ac1c9969;hp=b96e7d6982fa823c28a4c68045043643c50fcd25;hb=e0108bbf815b1806c96e3cbdc2a2dc162f7c1fe1;hpb=08a92571872aaa6d4cb8d43c6170c358f8ef0d94 diff --git a/libopkg/opkg_message.c b/libopkg/opkg_message.c index b96e7d6..4a24039 100644 --- a/libopkg/opkg_message.c +++ b/libopkg/opkg_message.c @@ -1,5 +1,6 @@ -/* opkg_message.c - the itsy package management system +/* opkg_message.c - the opkg package management system + Copyright (C) 2009 Ubiq Technologies Copyright (C) 2003 Daniele Nicolodi This program is free software; you can redistribute it and/or @@ -13,26 +14,93 @@ General Public License for more details. */ +#include -#include "opkg.h" #include "opkg_conf.h" #include "opkg_message.h" +#include "libbb/libbb.h" -#include "libopkg.h" +struct errlist { + char *errmsg; + struct errlist *next; +}; -//#define opkg_message(conf, level, fmt, arg...) opkg_cb_message(conf, level, fmt, ## arg) +static struct errlist *error_list_head, *error_list_tail; + +static void +push_error_list(char *msg) +{ + struct errlist *e; + + e = xcalloc(1, sizeof(struct errlist)); + e->errmsg = xstrdup(msg); + e->next = NULL; + + if (error_list_head) { + error_list_tail->next = e; + error_list_tail = e; + } else { + error_list_head = error_list_tail = e; + } +} + +void +free_error_list(void) +{ + struct errlist *err, *err_tmp; + + err = error_list_head; + while (err != NULL) { + free(err->errmsg); + err_tmp = err; + err = err->next; + free(err_tmp); + } +} void -opkg_message (opkg_conf_t * conf, message_level_t level, char *fmt, ...) +print_error_list(void) +{ + struct errlist *err = error_list_head; + + if (err) { + printf("Collected errors:\n"); + /* Here we print the errors collected and free the list */ + while (err != NULL) { + printf(" * %s", err->errmsg); + err = err->next; + } + } +} + +void +opkg_message (message_level_t level, const char *fmt, ...) { va_list ap; - char ts[256]; - if (opkg_cb_message) - { + if (conf->verbosity < level) + return; + + if (conf->opkg_vmessage) { + /* Pass the message to libopkg users. */ va_start (ap, fmt); - vsnprintf (ts,256,fmt, ap); + conf->opkg_vmessage(level, fmt, ap); va_end (ap); - opkg_cb_message(conf,level,ts); + return; } + + va_start (ap, fmt); + + if (level == ERROR) { +#define MSG_LEN 256 + char msg[MSG_LEN]; + if (vsnprintf(msg, MSG_LEN, fmt, ap) >= MSG_LEN) { + fprintf(stderr, "%s: Message truncated!\n", + __FUNCTION__); + } + push_error_list(msg); + } else + vprintf(fmt, ap); + + va_end (ap); }