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; int result;
IsoImage *image; IsoImage *image;
Ecma119Image *ecma119; Ecma119Image *ecma119;
Ecma119Node *tree;
if (argc != 2) { if (argc != 2) {
printf ("You need to specify a valid path\n"); 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 = calloc(1, sizeof(Ecma119Image));
ecma119->iso_level = 1; ecma119->iso_level = 1;
ecma119->image = image;
/* create low level tree */ /* 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) { if (result < 0) {
printf ("Error creating ecma-119 tree: %d\n", result); printf ("Error creating ecma-119 tree: %d\n", result);
return 1; return 1;

View File

@ -17,6 +17,7 @@
#include "libburn/libburn.h" #include "libburn/libburn.h"
#include <stdlib.h> #include <stdlib.h>
#include <time.h>
static static
int ecma119_image_new(IsoImage *src, Ecma119WriteOpts *opts, int ecma119_image_new(IsoImage *src, Ecma119WriteOpts *opts,
@ -31,6 +32,11 @@ int ecma119_image_new(IsoImage *src, Ecma119WriteOpts *opts,
return ISO_MEM_ERROR; return ISO_MEM_ERROR;
} }
target->image = src;
target->iso_level = opts->level;
target->now = time(NULL);
ret = ecma119_tree_create(target, src->root); ret = ecma119_tree_create(target, src->root);
if (ret < 0) { if (ret < 0) {
// TODO free image data // 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); max_path = pathlen + 1 + (iso_name ? strlen(iso_name) : 0);
if (1) { //TODO !rockridge && !relaxed_paths if (1) { //TODO !rockridge && !relaxed_paths
if (depth > 8 || max_path > 255) { if (depth > 8 || max_path > 255) {
// char msg[512]; iso_msg_note(image->image, LIBISO_FILE_IGNORED,
// sprintf(msg, "File %s can't be added, because depth > 8 " "File \"%s\" can't be added, because depth > 8 "
// "or path length over 255\n", iso_name); "or path length over 255", iso->name);
// iso_msg_note(image, LIBISO_FILE_IGNORED, msg);
free(iso_name); free(iso_name);
return 0; return 0;
} }
@ -188,17 +187,23 @@ int create_tree(Ecma119Image *image, IsoNode *iso, Ecma119Node **tree,
case LIBISO_FILE: case LIBISO_FILE:
ret = create_file(image, (IsoFile*)iso, &node); ret = create_file(image, (IsoFile*)iso, &node);
if (ret == ISO_FILE_TOO_BIG) { 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); free(iso_name);
// TODO log
return 0; return 0;
} }
break; break;
case LIBISO_SYMLINK: case LIBISO_SYMLINK:
//TODO only supported with RR //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); free(iso_name);
return 0; return 0;
break; break;
case LIBISO_SPECIAL: 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 //TODO only supported with RR
free(iso_name); free(iso_name);
return 0; return 0;

View File

@ -7,52 +7,94 @@
*/ */
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <stdio.h>
#include <stdarg.h>
#include "libisofs.h" #include "libisofs.h"
#include "messages.h" #include "messages.h"
#include "image.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, char msg[MAX_MSG_LEN];
LIBISO_MSGS_SEV_DEBUG, LIBISO_MSGS_PRIO_ZERO, va_list ap;
msg_text, 0, 0);
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, char msg[MAX_MSG_LEN];
LIBISO_MSGS_SEV_NOTE, LIBISO_MSGS_PRIO_MEDIUM, va_list ap;
msg_text, 0, 0);
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, char msg[MAX_MSG_LEN];
LIBISO_MSGS_SEV_HINT, LIBISO_MSGS_PRIO_MEDIUM, va_list ap;
msg_text, 0, 0);
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, 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, 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, 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 */ /** Unsupported file type for Joliet tree */
#define LIBISO_JOLIET_WRONG_FILE_TYPE 0x00030301 #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_*/ #endif /*MESSAGES_H_*/

View File

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