2001-10-18 Lutz M�ller <urc8@rz.uni-karlsruhe.de>

* frontends/command-line/main.c: Port to gp_log
        * libgphoto2/gphoto2-debug.[c,h]: Clean up even more.
        * po/POTFILES.in: Add frontends/command-line/main.c


git-svn-id: https://svn.code.sf.net/p/gphoto/code/trunk/libgphoto2@2611 67ed7778-7388-44ab-90cf-0a291f65f57c
This commit is contained in:
Lutz Mueller
2001-10-18 17:06:52 +00:00
parent 24e45f418e
commit b83bcadd99
4 changed files with 35 additions and 64 deletions

View File

@@ -1,5 +1,7 @@
/* $Id$ */
#include <config.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
@@ -10,10 +12,6 @@
#include <signal.h>
#endif
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "main.h"
#include "actions.h"
@@ -28,6 +26,21 @@
#ifdef ENABLE_NLS
# include <libintl.h>
# undef _
# define _(String) dgettext (PACKAGE, String)
# ifdef gettext_noop
# define N_(String) gettext_noop (String)
# else
# define N_(String) (String)
# endif
#else
# define textdomain(String) (String)
# define gettext(String) (String)
# define dgettext(Domain,Message) (Message)
# define dcgettext(Domain,Message,Type) (Message)
# define bindtextdomain(Domain,Directory) (Domain)
# define _(String) (String)
# define N_(String) (String)
#endif
#define CHECK_RESULT(result) {int r = (result); if (r < 0) return (r);}
@@ -441,12 +454,22 @@ OPTION_CALLBACK(model)
return (GP_OK);
}
static void
debug_func (GPLogLevels levels, const char *domain, const char *msg,
void *data)
{
if (levels & GP_LOG_ERROR)
printf ("*** ERROR *** ");
printf ("%s: %s\n", domain, msg);
}
OPTION_CALLBACK (debug)
{
glob_debug = GP_DEBUG_HIGH;
cli_debug_print(PACKAGE " " VERSION ": " "Turning on debug mode");
gp_debug_set_level (GP_DEBUG_HIGH);
gp_log_add_func (GP_LOG_DATA | GP_LOG_DEBUG | GP_LOG_ERROR,
debug_func, NULL);
return (GP_OK);
}
@@ -890,7 +913,7 @@ set_globals (void)
* check every single error message returned by gphoto2, we need
* to make sure that we have a serial port.
*/
if (!strncmp (glob_port, "serial", 6))
if (!strncmp (glob_port, "serial:", 7))
CHECK_RESULT (gp_camera_set_port_speed (glob_camera, glob_speed));
gp_camera_set_status_func (glob_camera, status_func, NULL);
@@ -1031,15 +1054,13 @@ e.g. SET IOLIBS=C:\\GPHOTO2\\IOLIB\n");
exit(EXIT_FAILURE);
}
if ((result = execute_options(argc, argv)) != GP_OK) {
result = execute_options(argc, argv);
if (result < 0) {
printf ("gPhoto2 reported the error '%s'\n",
gp_camera_get_result_as_string (glob_camera, result));
if (gp_debug_get_level () == GP_DEBUG_NONE) {
printf ("Last debugging messages (use --debug for "
"more):\n");
printf ("%s\n", gp_log_history_get ());
}
printf ("Last debugging messages (use --debug for more):\n");
printf ("%s\n", gp_log_history_get ());
exit (EXIT_FAILURE);
}

View File

@@ -26,23 +26,7 @@
#include <stdlib.h>
#include <string.h>
#include <gphoto2-result.h>
#include <gphoto2-port-log.h>
#include <gphoto2-port.h>
static int port_func_set = 0;
static int debug_level = GP_DEBUG_NONE;
static void
gp_port_func (GPLogLevels levels, const char *domain,
const char *msg, void *data)
{
if (debug_level) {
fprintf (stderr, msg);
fprintf (stderr, "\n");
}
}
/**
* gp_debug_printf:
@@ -63,11 +47,6 @@ gp_debug_printf (int level, const char *id, const char *format, ...)
char buffer[2048];
va_list arg;
if (!port_func_set)
port_func_set = gp_log_add_func (
GP_LOG_DATA | GP_LOG_DEBUG | GP_LOG_ERROR,
gp_port_func, NULL);
va_start (arg, format);
#if HAVE_VSNPRINTF
vsnprintf (buffer, sizeof (buffer), format, arg);
@@ -76,32 +55,5 @@ gp_debug_printf (int level, const char *id, const char *format, ...)
#endif
va_end (arg);
if (level <= debug_level)
gp_log (GP_LOG_DEBUG, id, buffer);
}
/**
* gp_debug_set_level:
* @level: a gphoto2 debug level
*
* Sets the debugging level. Only debugging messages with a debugging level
* higher than the given @level will be printed.
**/
void
gp_debug_set_level (int level)
{
debug_level = level;
}
/**
* gp_debug_get_level:
*
* Gets the current debugging level.
*
* Return value: the current gphoto2 debug level or a gphoto2 error code
**/
int
gp_debug_get_level (void)
{
return (debug_level);
gp_log (GP_LOG_DEBUG, id, buffer);
}

View File

@@ -29,7 +29,4 @@
/* DEPRECATED. Use gphoto2-port-log */
void gp_debug_printf (int level, const char *id, const char *format, ...);
void gp_debug_set_level (int level);
int gp_debug_get_level (void);
#endif /* __GPHOTO2_DEBUG_H__ */

View File

@@ -16,3 +16,4 @@ libgphoto2/gphoto2-camera.c
libgphoto2/gphoto2-filesys.c
libgphoto2/gphoto2-abilities-list.c
libgphoto2/gphoto2-result.c
frontends/command-line/main.c