print_usb_usermap: made program name configurable

git-svn-id: https://svn.code.sf.net/p/gphoto/code/trunk/libgphoto2@8443 67ed7778-7388-44ab-90cf-0a291f65f57c
This commit is contained in:
Hans Ulrich Niedermann
2006-01-09 14:27:20 +00:00
parent 7a6cec1fd6
commit 9d80cdfd3d

View File

@@ -21,25 +21,26 @@
*/
#define GP_USB_HOTPLUG_SCRIPT "usbcam"
#define ARGV0 "print-usb-usermap"
#define HELP_TEXT \
"print-usb-usermap - print usb.usermap file for linux-hotplug\n" \
ARGV0 " - print usb.usermap file for linux-hotplug or FDI file for HAL\n" \
"\n" \
"Syntax:\n" \
" print-usb-usermap [ --verbose ] [ --debug ] [ --fdi | <scriptname> ]\n" \
" " ARGV0 " [ --verbose ] [ --debug ] [ --fdi | <scriptname> ]\n" \
"\n" \
" --verbose also print comments with camera model names\n" \
" --fdi print FDI file for HAL\n" \
" --debug print all debug output\n" \
"\n" \
"print-usb-usermap prints the lines for the usb.usermap file on stdout.\n" \
ARGV0 " prints the lines for the usb.usermap file on stdout.\n" \
"All other messages are printed on stderr. In case of any error, the \n" \
"program aborts regardless of data printed on stdout and returns a non-zero\n" \
"status code.\n" \
"If no <scriptname> is given, print-usb-usermap uses the script name\n" \
"If --fdi is given it generates a fdi file for HAL. Put it into\n" \
"/usr/share/hal/fdi/information/10freedesktop/10-camera-libgphoto2.fdi\n" \
"\"" GP_USB_HOTPLUG_SCRIPT "\"."
"If no <scriptname> is given, " ARGV0 " uses the script name\n" \
" \"" GP_USB_HOTPLUG_SCRIPT "\"." \
"If --fdi is given, " ARGV0 " generates a fdi file for HAL. Put it into\n" \
"/usr/share/hal/fdi/information/10freedesktop/10-camera-libgphoto2.fdi\n"
#include <stdio.h>
#include <sys/time.h>
@@ -63,12 +64,13 @@
#define GP_USB_HOTPLUG_MATCH_DEV_SUBCLASS 0x0100
#define GP_USB_HOTPLUG_MATCH_DEV_PROTOCOL 0x0200
#ifdef __GNUC__
#define CR(result) \
do { \
int r = (result); \
if (r < 0) { \
fprintf(stderr, "print-usb-usermap: " \
fprintf(stderr, ARGV0 ": " \
"Fatal error running `%s'.\n" \
"Aborting.\n", #result ); \
return (r); \
@@ -79,14 +81,15 @@
do { \
int r = (result); \
if (r < 0) { \
fprintf(stderr, "print-usb-usermap: " \
fprintf(stderr, ARGV0 ": " \
"Fatal error detected, aborting.\n"); \
return (r); \
} \
} while (0)
#endif /* __GNUC__ */
/* print-usb-usermap
/* print_usb_usermap
*
* Print out lines that can be included into usb.usermap
* - for all cams supported by our instance of libgphoto2.
@@ -99,7 +102,7 @@ static int print_usb_usermap(const char *usermap_script, const int add_comments)
{
int x, n;
CameraAbilitiesList *al;
CameraAbilities a;
CameraAbilities a;
CR (gp_abilities_list_new (&al));
CR (gp_abilities_list_load (al, NULL)); /* use NULL context */
@@ -166,7 +169,8 @@ static int print_usb_usermap(const char *usermap_script, const int add_comments)
return (0);
}
/* print-fdi-map
/* print_fdi_map
*
* Print FDI Device Information file for HAL with information on
* all cams supported by our instance of libgphoto2.
@@ -179,7 +183,7 @@ static int print_fdi_map(const int add_comments, const char *argv0)
{
int x, n;
CameraAbilitiesList *al;
CameraAbilities a;
CameraAbilities a;
CR (gp_abilities_list_new (&al));
CR (gp_abilities_list_load (al, NULL)); /* use NULL context */
@@ -187,7 +191,7 @@ static int print_fdi_map(const int add_comments, const char *argv0)
printf("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?> <!-- -*- SGML -*- -->\n");
printf("<!-- This file was generated by %s - - fdi -->\n",
(argv0!=NULL)?argv0:"libgphoto2 print-usb-usermap");
(argv0!=NULL)?argv0:"libgphoto2 " ARGV0);
printf("<deviceinfo version=\"0.2\">\n");
printf(" <device>\n");
printf(" <match key=\"info.bus\" string=\"usb\">\n");
@@ -257,6 +261,7 @@ static int print_fdi_map(const int add_comments, const char *argv0)
return (0);
}
/* time zero for debug log time stamps */
struct timeval glob_tv_zero = { 0, 0 };
@@ -274,6 +279,7 @@ debug_func (GPLogLevel level, const char *domain, const char *format,
fprintf (stderr, "\n");
}
int main(int argc, char *argv[])
{
char *usermap_script = NULL; /* script name to use */