Improve message functions to support message formating in printf style.

This commit is contained in:
Vreixo Formoso 2007-12-17 21:12:51 +01:00
parent f279676b6b
commit 159b775d22
6 changed files with 92 additions and 49 deletions

View File

@ -71,7 +71,6 @@ int main(int argc, char **argv)
int result;
IsoImage *image;
Ecma119Image *ecma119;
Ecma119Node *tree;
if (argc != 2) {
printf ("You need to specify a valid path\n");
@ -93,9 +92,10 @@ int main(int argc, char **argv)
ecma119 = calloc(1, sizeof(Ecma119Image));
ecma119->iso_level = 1;
ecma119->image = image;
/* create low level tree */
result = ecma119_tree_create(ecma119, (IsoNode*)iso_image_get_root(image));
result = ecma119_tree_create(ecma119, iso_image_get_root(image));
if (result < 0) {
printf ("Error creating ecma-119 tree: %d\n", result);
return 1;

View File

@ -17,6 +17,7 @@
#include "libburn/libburn.h"
#include <stdlib.h>
#include <time.h>
static
int ecma119_image_new(IsoImage *src, Ecma119WriteOpts *opts,
@ -31,6 +32,11 @@ int ecma119_image_new(IsoImage *src, Ecma119WriteOpts *opts,
return ISO_MEM_ERROR;
}
target->image = src;
target->iso_level = opts->level;
target->now = time(NULL);
ret = ecma119_tree_create(target, src->root);
if (ret < 0) {
// TODO free image data

View File

@ -175,10 +175,9 @@ int create_tree(Ecma119Image *image, IsoNode *iso, Ecma119Node **tree,
max_path = pathlen + 1 + (iso_name ? strlen(iso_name) : 0);
if (1) { //TODO !rockridge && !relaxed_paths
if (depth > 8 || max_path > 255) {
// char msg[512];
// sprintf(msg, "File %s can't be added, because depth > 8 "
// "or path length over 255\n", iso_name);
// iso_msg_note(image, LIBISO_FILE_IGNORED, msg);
iso_msg_note(image->image, LIBISO_FILE_IGNORED,
"File \"%s\" can't be added, because depth > 8 "
"or path length over 255", iso->name);
free(iso_name);
return 0;
}
@ -188,17 +187,23 @@ int create_tree(Ecma119Image *image, IsoNode *iso, Ecma119Node **tree,
case LIBISO_FILE:
ret = create_file(image, (IsoFile*)iso, &node);
if (ret == ISO_FILE_TOO_BIG) {
iso_msg_note(image->image, LIBISO_FILE_IGNORED,
"File \"%s\" can't be added to image because is "
"greater than 4GB", iso->name);
free(iso_name);
// TODO log
return 0;
}
break;
case LIBISO_SYMLINK:
//TODO only supported with RR
iso_msg_note(image->image, LIBISO_FILE_IGNORED, "File \"%s\" ignored. "
"Symlinks need RockRidge extensions.", iso->name);
free(iso_name);
return 0;
break;
case LIBISO_SPECIAL:
iso_msg_note(image->image, LIBISO_FILE_IGNORED, "File \"%s\" ignored. "
"Special files need RockRidge extensions.", iso->name);
//TODO only supported with RR
free(iso_name);
return 0;

View File

@ -7,52 +7,94 @@
*/
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <stdarg.h>
#include "libisofs.h"
#include "messages.h"
#include "image.h"
void iso_msg_debug(IsoImage *img, char *msg_text)
#define MAX_MSG_LEN 4096
void iso_msg_debug(IsoImage *img, const char *fmt, ...)
{
libiso_msgs_submit(img->messenger, -1, 0x00000002,
LIBISO_MSGS_SEV_DEBUG, LIBISO_MSGS_PRIO_ZERO,
msg_text, 0, 0);
char msg[MAX_MSG_LEN];
va_list ap;
va_start(ap, fmt);
vsnprintf(msg, MAX_MSG_LEN, fmt, ap);
va_end(ap);
libiso_msgs_submit(img->messenger, -1, 0x00000002, LIBISO_MSGS_SEV_DEBUG,
LIBISO_MSGS_PRIO_ZERO, msg, 0, 0);
}
void iso_msg_note(IsoImage *img, int error_code, char *msg_text)
void iso_msg_note(IsoImage *img, int error_code, const char *fmt, ...)
{
libiso_msgs_submit(img->messenger, -1, error_code,
LIBISO_MSGS_SEV_NOTE, LIBISO_MSGS_PRIO_MEDIUM,
msg_text, 0, 0);
char msg[MAX_MSG_LEN];
va_list ap;
va_start(ap, fmt);
vsnprintf(msg, MAX_MSG_LEN, fmt, ap);
va_end(ap);
libiso_msgs_submit(img->messenger, -1, error_code, LIBISO_MSGS_SEV_NOTE,
LIBISO_MSGS_PRIO_MEDIUM, msg, 0, 0);
}
void iso_msg_hint(IsoImage *img, int error_code, char *msg_text)
void iso_msg_hint(IsoImage *img, int error_code, const char *fmt, ...)
{
libiso_msgs_submit(img->messenger, -1, error_code,
LIBISO_MSGS_SEV_HINT, LIBISO_MSGS_PRIO_MEDIUM,
msg_text, 0, 0);
char msg[MAX_MSG_LEN];
va_list ap;
va_start(ap, fmt);
vsnprintf(msg, MAX_MSG_LEN, fmt, ap);
va_end(ap);
libiso_msgs_submit(img->messenger, -1, error_code, LIBISO_MSGS_SEV_HINT,
LIBISO_MSGS_PRIO_MEDIUM, msg, 0, 0);
}
void iso_msg_warn(IsoImage *img, int error_code, char *msg_text)
void iso_msg_warn(IsoImage *img, int error_code, const char *fmt, ...)
{
libiso_msgs_submit(img->messenger, -1, error_code,
char msg[MAX_MSG_LEN];
va_list ap;
va_start(ap, fmt);
vsnprintf(msg, MAX_MSG_LEN, fmt, ap);
va_end(ap);
libiso_msgs_submit(img->messenger, -1, error_code,
LIBISO_MSGS_SEV_WARNING, LIBISO_MSGS_PRIO_MEDIUM,
msg_text, 0, 0);
msg, 0, 0);
}
void iso_msg_sorry(IsoImage *img, int error_code, char *msg_text)
void iso_msg_sorry(IsoImage *img, int error_code, const char *fmt, ...)
{
libiso_msgs_submit(img->messenger, -1, error_code,
char msg[MAX_MSG_LEN];
va_list ap;
va_start(ap, fmt);
vsnprintf(msg, MAX_MSG_LEN, fmt, ap);
va_end(ap);
libiso_msgs_submit(img->messenger, -1, error_code,
LIBISO_MSGS_SEV_SORRY, LIBISO_MSGS_PRIO_HIGH,
msg_text, 0, 0);
msg, 0, 0);
}
void iso_msg_fatal(IsoImage *img, int error_code, char *msg_text)
void iso_msg_fatal(IsoImage *img, int error_code, const char *fmt, ...)
{
libiso_msgs_submit(img->messenger, -1, error_code,
char msg[MAX_MSG_LEN];
va_list ap;
va_start(ap, fmt);
vsnprintf(msg, MAX_MSG_LEN, fmt, ap);
va_end(ap);
libiso_msgs_submit(img->messenger, -1, error_code,
LIBISO_MSGS_SEV_FATAL, LIBISO_MSGS_PRIO_HIGH,
msg_text, 0, 0);
msg, 0, 0);
}
/**

View File

@ -63,16 +63,16 @@
/** Unsupported file type for Joliet tree */
#define LIBISO_JOLIET_WRONG_FILE_TYPE 0x00030301
void iso_msg_debug(IsoImage *img, char *msg_text);
void iso_msg_debug(IsoImage *img, const char *fmt, ...);
void iso_msg_note(IsoImage *img, int error_code, char *msg_text);
void iso_msg_note(IsoImage *img, int error_code, const char *fmt, ...);
void iso_msg_hint(IsoImage *img, int error_code, char *msg_text);
void iso_msg_hint(IsoImage *img, int error_code, const char *fmt, ...);
void iso_msg_warn(IsoImage *img, int error_code, char *msg_text);
void iso_msg_warn(IsoImage *img, int error_code, const char *fmt, ...);
void iso_msg_sorry(IsoImage *img, int error_code, char *msg_text);
void iso_msg_sorry(IsoImage *img, int error_code, const char *fmt, ...);
void iso_msg_fatal(IsoImage *img, int error_code, char *msg_text);
void iso_msg_fatal(IsoImage *img, int error_code, const char *fmt, ...);
#endif /*MESSAGES_H_*/

View File

@ -402,9 +402,7 @@ int iso_add_dir_aux(IsoImage *image, IsoDir *parent, IsoFileSource *dir)
result = dir->open(dir);
if (result < 0) {
char msg[PATH_MAX];
sprintf(msg, "Can't open dir %s (%d)\n", dir->get_path(dir), result);
iso_msg_debug(image, msg);
iso_msg_debug(image, "Can't open dir %s", dir->get_path(dir));
return result;
}
@ -415,11 +413,7 @@ int iso_add_dir_aux(IsoImage *image, IsoDir *parent, IsoFileSource *dir)
char *name;
IsoNode *new;
{
char msg[PATH_MAX];
sprintf(msg, "Adding file %s\n", file->get_path(file));
iso_msg_debug(image, msg);
}
iso_msg_debug(image, "Adding file %s", file->get_path(file));
name = file->get_name(file);
@ -463,12 +457,8 @@ int iso_add_dir_aux(IsoImage *image, IsoDir *parent, IsoFileSource *dir)
result = builder->create_node(builder, image, file, &new);
if (result < 0) {
{
char msg[PATH_MAX];
sprintf(msg, "Error %d when adding file %s\n", result,
file->get_path(file));
iso_msg_debug(image, msg);
}
iso_msg_debug(image, "Error %d when adding file %s",
result, file->get_path(file));
if (image->recOpts->report) {
action = image->recOpts->report(file, result, flag);