1
0
mirror of https://github.com/gryf/wmaker.git synced 2025-12-18 20:10:29 +01:00

util: removed usage of external '__progname' because it is not portable

As reported by Milan Čermák, using this variable breaks compilation on
Solaris, because it is a hack which is not standard. To ensure portability,
we now rely on main's argv[0] which is always available.

Signed-off-by: Christophe CURIS <christophe.curis@free.fr>
This commit is contained in:
Christophe CURIS
2014-10-26 00:31:42 +02:00
committed by Carlos R. Mafra
parent ff8fc10a65
commit 3de5b8fb42
12 changed files with 90 additions and 78 deletions

View File

@@ -56,12 +56,12 @@ char *FontOptions[] = {
NULL NULL
}; };
extern char *__progname; static const char *prog_name;
static noreturn void print_help(int print_usage, int exitval) static noreturn void print_help(int print_usage, int exitval)
{ {
printf("Usage: %s [-h] [-v] [--keep-xlfd] <style_file>\n", __progname); printf("Usage: %s [-h] [-v] [--keep-xlfd] <style_file>\n", prog_name);
if (print_usage) { if (print_usage) {
puts("Converts fonts in a style file into fontconfig format"); puts("Converts fonts in a style file into fontconfig format");
puts(""); puts("");
@@ -92,10 +92,11 @@ int main(int argc, char **argv)
{ NULL, 0, NULL, 0 } { NULL, 0, NULL, 0 }
}; };
prog_name = argv[0];
while ((ch = getopt_long(argc, argv, "hv", longopts, NULL)) != -1) while ((ch = getopt_long(argc, argv, "hv", longopts, NULL)) != -1)
switch(ch) { switch(ch) {
case 'v': case 'v':
printf("%s (Window Maker %s)\n", __progname, VERSION); printf("%s (Window Maker %s)\n", prog_name, VERSION);
return 0; return 0;
/* NOTREACHED */ /* NOTREACHED */
case 'h': case 'h':
@@ -122,7 +123,7 @@ int main(int argc, char **argv)
} }
if (!S_ISREG(st.st_mode)) { /* maybe symlink too? */ if (!S_ISREG(st.st_mode)) { /* maybe symlink too? */
fprintf(stderr, "%s: `%s' is not a regular file\n", __progname, file); fprintf(stderr, "%s: `%s' is not a regular file\n", prog_name, file);
return 1; return 1;
} }
@@ -135,12 +136,12 @@ int main(int argc, char **argv)
style = WMReadPropListFromFile(file); style = WMReadPropListFromFile(file);
if (!style) { if (!style) {
perror(file); perror(file);
printf("%s: could not load style file\n", __progname); printf("%s: could not load style file\n", prog_name);
return 1; return 1;
} }
if (!WMIsPLDictionary(style)) { if (!WMIsPLDictionary(style)) {
printf("%s: '%s' is not a well formatted style file\n", __progname, file); printf("%s: '%s' is not a well formatted style file\n", prog_name, file);
return 1; return 1;
} }

View File

@@ -38,11 +38,11 @@
#include "../src/wconfig.h" #include "../src/wconfig.h"
extern char *__progname; static const char *prog_name;
static noreturn void print_help(int print_usage, int exitval) static noreturn void print_help(int print_usage, int exitval)
{ {
printf("Usage: %s [-h] [-v] [file]\n", __progname); printf("Usage: %s [-h] [-v] [file]\n", prog_name);
if (print_usage) { if (print_usage) {
puts("Retrieves program icon configuration and output to FILE or to stdout"); puts("Retrieves program icon configuration and output to FILE or to stdout");
puts(""); puts("");
@@ -65,10 +65,11 @@ int main(int argc, char **argv)
{ NULL, 0, NULL, 0 } { NULL, 0, NULL, 0 }
}; };
prog_name = argv[0];
while ((ch = getopt_long(argc, argv, "hv", longopts, NULL)) != -1) while ((ch = getopt_long(argc, argv, "hv", longopts, NULL)) != -1)
switch(ch) { switch(ch) {
case 'v': case 'v':
printf("%s (Window Maker %s)\n", __progname, VERSION); printf("%s (Window Maker %s)\n", prog_name, VERSION);
return 0; return 0;
/* NOTREACHED */ /* NOTREACHED */
case 'h': case 'h':
@@ -88,7 +89,7 @@ int main(int argc, char **argv)
all_windows = WMReadPropListFromFile(path); all_windows = WMReadPropListFromFile(path);
if (!all_windows) { if (!all_windows) {
printf("%s: could not load WindowMaker configuration file \"%s\".\n", __progname, path); printf("%s: could not load WindowMaker configuration file \"%s\".\n", prog_name, path);
return 1; return 1;
} }

View File

@@ -129,7 +129,7 @@ static char *font_options[] = {
NULL NULL
}; };
extern char *__progname; static const char *prog_name;
WMPropList *PixmapPath = NULL; WMPropList *PixmapPath = NULL;
@@ -138,7 +138,7 @@ char *ThemePath = NULL;
static noreturn void print_help(int print_usage, int exitval) static noreturn void print_help(int print_usage, int exitval)
{ {
printf("Usage: %s [-t] [-p] [-h] [-v] [file]\n", __progname); printf("Usage: %s [-t] [-p] [-h] [-v] [file]\n", prog_name);
if (print_usage) { if (print_usage) {
puts("Retrieves style/theme configuration and outputs to ~/GNUstep/Library/WindowMaker/Themes/file.themed/style or to stdout"); puts("Retrieves style/theme configuration and outputs to ~/GNUstep/Library/WindowMaker/Themes/file.themed/style or to stdout");
puts(""); puts("");
@@ -299,10 +299,11 @@ int main(int argc, char **argv)
{ NULL, 0, NULL, 0 } { NULL, 0, NULL, 0 }
}; };
prog_name = argv[0];
while ((ch = getopt_long(argc, argv, "ptvh", longopts, NULL)) != -1) while ((ch = getopt_long(argc, argv, "ptvh", longopts, NULL)) != -1)
switch(ch) { switch(ch) {
case 'v': case 'v':
printf("%s (Window Maker %s)\n", __progname, VERSION); printf("%s (Window Maker %s)\n", prog_name, VERSION);
return 0; return 0;
/* NOTREACHED */ /* NOTREACHED */
case 'h': case 'h':
@@ -329,7 +330,7 @@ int main(int argc, char **argv)
style_file = argv[argc - 1]; style_file = argv[argc - 1];
if (make_pack && !style_file) { if (make_pack && !style_file) {
printf("%s: you must supply a name for the theme pack\n", __progname); printf("%s: you must supply a name for the theme pack\n", prog_name);
return 1; return 1;
} }
@@ -339,7 +340,7 @@ int main(int argc, char **argv)
prop = WMReadPropListFromFile(path); prop = WMReadPropListFromFile(path);
if (!prop) { if (!prop) {
printf("%s: could not load WindowMaker configuration file \"%s\".\n", __progname, path); printf("%s: could not load WindowMaker configuration file \"%s\".\n", prog_name, path);
return 1; return 1;
} }

View File

@@ -38,11 +38,11 @@
#include "../src/wconfig.h" #include "../src/wconfig.h"
extern char *__progname; static const char *prog_name;
static noreturn void print_help(int print_usage, int exitval) static noreturn void print_help(int print_usage, int exitval)
{ {
printf("Usage: %s [-h] [-v] [file]\n", __progname); printf("Usage: %s [-h] [-v] [file]\n", prog_name);
if (print_usage) { if (print_usage) {
puts("Reads icon configuration from FILE and updates Window Maker."); puts("Reads icon configuration from FILE and updates Window Maker.");
puts(""); puts("");
@@ -65,10 +65,11 @@ int main(int argc, char **argv)
{ NULL, 0, NULL, 0 } { NULL, 0, NULL, 0 }
}; };
prog_name = argv[0];
while ((ch = getopt_long(argc, argv, "hv", longopts, NULL)) != -1) while ((ch = getopt_long(argc, argv, "hv", longopts, NULL)) != -1)
switch(ch) { switch(ch) {
case 'v': case 'v':
printf("%s (Window Maker %s)\n", __progname, VERSION); printf("%s (Window Maker %s)\n", prog_name, VERSION);
return 0; return 0;
/* NOTREACHED */ /* NOTREACHED */
case 'h': case 'h':
@@ -91,13 +92,13 @@ int main(int argc, char **argv)
all_windows = WMReadPropListFromFile(path); all_windows = WMReadPropListFromFile(path);
if (!all_windows) { if (!all_windows) {
printf("%s: could not load WindowMaker configuration file \"%s\".\n", __progname, path); printf("%s: could not load WindowMaker configuration file \"%s\".\n", prog_name, path);
return 1; return 1;
} }
iconset = WMReadPropListFromFile(argv[0]); iconset = WMReadPropListFromFile(argv[0]);
if (!iconset) { if (!iconset) {
printf("%s: could not load icon set file \"%s\".\n", __progname, argv[0]); printf("%s: could not load icon set file \"%s\".\n", prog_name, argv[0]);
return 1; return 1;
} }

View File

@@ -76,7 +76,7 @@ char *CursorOptions[] = {
NULL NULL
}; };
extern char *__progname; static const char *prog_name;
int ignoreFonts = 0; int ignoreFonts = 0;
int ignoreCursors = 0; int ignoreCursors = 0;
@@ -359,7 +359,7 @@ static void hackStyle(WMPropList * style)
static noreturn void print_help(int print_usage, int exitval) static noreturn void print_help(int print_usage, int exitval)
{ {
printf("Usage: %s [OPTIONS] FILE\n", __progname); printf("Usage: %s [OPTIONS] FILE\n", prog_name);
if (print_usage) { if (print_usage) {
puts("Reads style/theme configuration from FILE and updates Window Maker."); puts("Reads style/theme configuration from FILE and updates Window Maker.");
puts(""); puts("");
@@ -392,10 +392,11 @@ int main(int argc, char **argv)
{ NULL, 0, NULL, 0 } { NULL, 0, NULL, 0 }
}; };
prog_name = argv[0];
while ((ch = getopt_long(argc, argv, "hv", longopts, NULL)) != -1) while ((ch = getopt_long(argc, argv, "hv", longopts, NULL)) != -1)
switch(ch) { switch(ch) {
case 'v': case 'v':
printf("%s (Window Maker %s)\n", __progname, VERSION); printf("%s (Window Maker %s)\n", prog_name, VERSION);
return 0; return 0;
/* NOTREACHED */ /* NOTREACHED */
case 'h': case 'h':
@@ -431,7 +432,7 @@ int main(int argc, char **argv)
prop = WMReadPropListFromFile(path); prop = WMReadPropListFromFile(path);
if (!prop) { if (!prop) {
perror(path); perror(path);
printf("%s: could not load WindowMaker configuration file.\n", __progname); printf("%s: could not load WindowMaker configuration file.\n", prog_name);
return 1; return 1;
} }
@@ -450,14 +451,14 @@ int main(int argc, char **argv)
strncat(buf, "/style", sizeof(buf) - strlen(buf) - 1); strncat(buf, "/style", sizeof(buf) - strlen(buf) - 1);
if (stat(buf, &st) != 0 || !S_ISREG(st.st_mode)) { /* maybe symlink too? */ if (stat(buf, &st) != 0 || !S_ISREG(st.st_mode)) { /* maybe symlink too? */
printf("%s: %s: style file not found or not a file\n", __progname, buf); printf("%s: %s: style file not found or not a file\n", prog_name, buf);
return 1; return 1;
} }
style = WMReadPropListFromFile(buf); style = WMReadPropListFromFile(buf);
if (!style) { if (!style) {
perror(buf); perror(buf);
printf("%s: could not load style file.\n", __progname); printf("%s: could not load style file.\n", prog_name);
return 1; return 1;
} }
@@ -480,13 +481,13 @@ int main(int argc, char **argv)
style = WMReadPropListFromFile(file); style = WMReadPropListFromFile(file);
if (!style) { if (!style) {
perror(file); perror(file);
printf("%s:could not load style file.\n", __progname); printf("%s:could not load style file.\n", prog_name);
return 1; return 1;
} }
} }
if (!WMIsPLDictionary(style)) { if (!WMIsPLDictionary(style)) {
printf("%s: '%s' is not a style file/theme\n", __progname, file); printf("%s: '%s' is not a style file/theme\n", prog_name, file);
return 1; return 1;
} }

View File

@@ -44,11 +44,11 @@
#include "../src/wconfig.h" #include "../src/wconfig.h"
extern char *__progname; static const char *prog_name;
static noreturn void print_help(int print_usage, int exitval) static noreturn void print_help(int print_usage, int exitval)
{ {
printf("Usage: %s [OPTIONS] <domain> <key>\n", __progname); printf("Usage: %s [OPTIONS] <domain> <key>\n", prog_name);
if (print_usage) { if (print_usage) {
puts("Read <key> from <domain>'s database"); puts("Read <key> from <domain>'s database");
puts(""); puts("");
@@ -70,10 +70,11 @@ int main(int argc, char **argv)
{ NULL, 0, NULL, 0 } { NULL, 0, NULL, 0 }
}; };
prog_name = argv[0];
while ((ch = getopt_long(argc, argv, "hv", longopts, NULL)) != -1) while ((ch = getopt_long(argc, argv, "hv", longopts, NULL)) != -1)
switch(ch) { switch(ch) {
case 'v': case 'v':
printf("%s (Window Maker %s)\n", __progname, VERSION); printf("%s (Window Maker %s)\n", prog_name, VERSION);
return 0; return 0;
/* NOTREACHED */ /* NOTREACHED */
case 'h': case 'h':

View File

@@ -43,11 +43,11 @@
#include "../src/wconfig.h" #include "../src/wconfig.h"
extern char *__progname; static const char *prog_name;
static noreturn void print_help(int print_usage, int exitval) static noreturn void print_help(int print_usage, int exitval)
{ {
printf("Usage: %s [OPTIONS] <domain> <key> <value>\n", __progname); printf("Usage: %s [OPTIONS] <domain> <key> <value>\n", prog_name);
if (print_usage) { if (print_usage) {
puts("Write <value> for <key> in <domain>'s database"); puts("Write <value> for <key> in <domain>'s database");
puts(""); puts("");
@@ -69,10 +69,11 @@ int main(int argc, char **argv)
{ NULL, 0, NULL, 0 } { NULL, 0, NULL, 0 }
}; };
prog_name = argv[0];
while ((ch = getopt_long(argc, argv, "hv", longopts, NULL)) != -1) while ((ch = getopt_long(argc, argv, "hv", longopts, NULL)) != -1)
switch(ch) { switch(ch) {
case 'v': case 'v':
printf("%s (Window Maker %s)\n", __progname, VERSION); printf("%s (Window Maker %s)\n", prog_name, VERSION);
return 0; return 0;
/* NOTREACHED */ /* NOTREACHED */
case 'h': case 'h':
@@ -94,7 +95,7 @@ int main(int argc, char **argv)
key = WMCreatePLString(argv[1]); key = WMCreatePLString(argv[1]);
value = WMCreatePropListFromDescription(argv[2]); value = WMCreatePropListFromDescription(argv[2]);
if (!value) { if (!value) {
printf("%s: syntax error in value \"%s\"", __progname, argv[2]); printf("%s: syntax error in value \"%s\"", prog_name, argv[2]);
return 1; return 1;
} }

View File

@@ -31,7 +31,7 @@ static void find_and_write(const char *group, char *list[][2], int this_is_termi
static void other_window_managers(void); static void other_window_managers(void);
static void print_help(int print_usage, int exitval); static void print_help(int print_usage, int exitval);
extern char *__progname; static const char *prog_name;
char *path, *terminal = NULL; char *path, *terminal = NULL;
@@ -54,10 +54,11 @@ int main(int argc, char *argv[])
{ NULL, 0, NULL, 0 } { NULL, 0, NULL, 0 }
}; };
prog_name = argv[0];
while ((ch = getopt_long(argc, argv, "hv", longopts, NULL)) != -1) while ((ch = getopt_long(argc, argv, "hv", longopts, NULL)) != -1)
switch (ch) { switch (ch) {
case 'v': case 'v':
printf("%s (Window Maker %s)\n", __progname, VERSION); printf("%s (Window Maker %s)\n", prog_name, VERSION);
return 0; return 0;
/* NOTREACHED */ /* NOTREACHED */
case 'h': case 'h':
@@ -500,7 +501,7 @@ static void other_window_managers(void)
noreturn void print_help(int print_usage, int exitval) noreturn void print_help(int print_usage, int exitval)
{ {
printf("Usage: %s [-h] [-v]\n", __progname); printf("Usage: %s [-h] [-v]\n", prog_name);
if (print_usage) { if (print_usage) {
puts("Writes a menu structure usable as ~/GNUstep/Defaults/WMRootMenu to stdout"); puts("Writes a menu structure usable as ~/GNUstep/Defaults/WMRootMenu to stdout");
puts(""); puts("");

View File

@@ -48,7 +48,7 @@ static const char *terminal;
static fct_parse_menufile *parse; static fct_parse_menufile *parse;
static fct_validate_filename *validateFilename; static fct_validate_filename *validateFilename;
extern char *__progname; static const char *prog_name;
/* Global Variables from wmmenugen.h */ /* Global Variables from wmmenugen.h */
WMTreeNode *menu; WMTreeNode *menu;
@@ -60,6 +60,7 @@ int main(int argc, char **argv)
int i; int i;
int *previousDepth; int *previousDepth;
prog_name = argv[0];
plMenuNodes = WMCreateArray(8); /* grows on demand */ plMenuNodes = WMCreateArray(8); /* grows on demand */
menu = (WMTreeNode *)NULL; menu = (WMTreeNode *)NULL;
parse = NULL; parse = NULL;
@@ -77,7 +78,7 @@ int main(int argc, char **argv)
if (argc < 3) { if (argc < 3) {
fprintf(stderr, "Usage: %s -parser:<parser> fspec [fpsec...] " fprintf(stderr, "Usage: %s -parser:<parser> fspec [fpsec...] "
"[-parser:<parser> fspec [fpsec...]...]\n", __progname); "[-parser:<parser> fspec [fpsec...]...]\n", prog_name);
fputs( "Known parsers: xdg wmconfig\n", stderr); fputs( "Known parsers: xdg wmconfig\n", stderr);
return 1; return 1;
} }
@@ -97,28 +98,28 @@ int main(int argc, char **argv)
parse = &parse_wmconfig; parse = &parse_wmconfig;
validateFilename = &wmconfig_validate_file; validateFilename = &wmconfig_validate_file;
} else { } else {
fprintf(stderr, "%s: Unknown parser \"%s\"\n", __progname, argv[i] + 8); fprintf(stderr, "%s: Unknown parser \"%s\"\n", prog_name, argv[i] + 8);
} }
continue; continue;
} }
if (parse) { if (parse) {
if (stat(argv[i], &st) == -1) { if (stat(argv[i], &st) == -1) {
fprintf(stderr, "%s: unable to stat \"%s\"\n", __progname, argv[i]); fprintf(stderr, "%s: unable to stat \"%s\"\n", prog_name, argv[i]);
} else if (S_ISREG(st.st_mode)) { } else if (S_ISREG(st.st_mode)) {
parse(argv[i], addWMMenuEntryCallback); parse(argv[i], addWMMenuEntryCallback);
} else if (S_ISDIR(st.st_mode)) { } else if (S_ISDIR(st.st_mode)) {
nftw(argv[i], dirParseFunc, 16, FTW_PHYS); nftw(argv[i], dirParseFunc, 16, FTW_PHYS);
} else { } else {
fprintf(stderr, "%s: \"%s\" is not a file or directory\n", __progname, argv[i]); fprintf(stderr, "%s: \"%s\" is not a file or directory\n", prog_name, argv[i]);
} }
} else { } else {
fprintf(stderr, "%s: argument \"%s\" with no valid parser\n", __progname, argv[i]); fprintf(stderr, "%s: argument \"%s\" with no valid parser\n", prog_name, argv[i]);
} }
} }
if (!menu) { if (!menu) {
fprintf(stderr, "%s: parsers failed to create a valid menu\n", __progname); fprintf(stderr, "%s: parsers failed to create a valid menu\n", prog_name);
return 1; return 1;
} }
@@ -127,7 +128,7 @@ int main(int argc, char **argv)
i = WMGetArrayItemCount(plMenuNodes); i = WMGetArrayItemCount(plMenuNodes);
if (i > 2) { /* more than one submenu unprocessed is almost certainly an error */ if (i > 2) { /* more than one submenu unprocessed is almost certainly an error */
fprintf(stderr, "%s: unprocessed levels on the stack. fishy.\n", __progname); fprintf(stderr, "%s: unprocessed levels on the stack. fishy.\n", prog_name);
return 1; return 1;
} else if (i > 1 ) { /* possibly the top-level attachment is not yet done */ } else if (i > 1 ) { /* possibly the top-level attachment is not yet done */
WMPropList *first, *next; WMPropList *first, *next;

View File

@@ -85,7 +85,7 @@ Bool xineStretch = False;
Pixmap CurrentPixmap = None; Pixmap CurrentPixmap = None;
char *PixmapPath = NULL; char *PixmapPath = NULL;
extern char *__progname; static const char *prog_name;
typedef struct BackgroundTexture { typedef struct BackgroundTexture {
int refcount; int refcount;
@@ -1152,7 +1152,7 @@ static char *getFullPixmapPath(const char *file)
static void print_help(void) static void print_help(void)
{ {
printf("Usage: %s [options] [image]\n", __progname); printf("Usage: %s [options] [image]\n", prog_name);
puts("Sets the workspace background to the specified image or a texture and"); puts("Sets the workspace background to the specified image or a texture and");
puts("optionally update Window Maker configuration"); puts("optionally update Window Maker configuration");
puts(""); puts("");
@@ -1247,6 +1247,7 @@ int main(int argc, char **argv)
WMInitializeApplication("wmsetbg", &argc, argv); WMInitializeApplication("wmsetbg", &argc, argv);
prog_name = argv[0];
for (i = 1; i < argc; i++) { for (i = 1; i < argc; i++) {
if (strcmp(argv[i], "-helper") == 0) { if (strcmp(argv[i], "-helper") == 0) {
helperMode = 1; helperMode = 1;
@@ -1324,7 +1325,7 @@ int main(int argc, char **argv)
quit(1); quit(1);
} }
} else if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--version") == 0) { } else if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--version") == 0) {
printf("%s (Window Maker %s)\n", __progname, VERSION); printf("%s (Window Maker %s)\n", prog_name, VERSION);
quit(0); quit(0);
} else if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) { } else if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) {
print_help(); print_help();
@@ -1332,14 +1333,14 @@ int main(int argc, char **argv)
} else if (argv[i][0] != '-') { } else if (argv[i][0] != '-') {
image_name = argv[i]; image_name = argv[i];
} else { } else {
printf("%s: invalid argument '%s'\n", __progname, argv[i]); printf("%s: invalid argument '%s'\n", prog_name, argv[i]);
printf("Try '%s --help' for more information\n", __progname); printf("Try '%s --help' for more information\n", prog_name);
quit(1); quit(1);
} }
} }
if (!image_name && !texture && !helperMode) { if (!image_name && !texture && !helperMode) {
printf("%s: you must specify a image file name or a texture\n", __progname); printf("%s: you must specify a image file name or a texture\n", prog_name);
printf("Try '%s --help' for more information\n", __progname); printf("Try '%s --help' for more information\n", prog_name);
quit(1); quit(1);
} }

View File

@@ -31,11 +31,11 @@
#define LINESIZE (4*1024) #define LINESIZE (4*1024)
#define MAXDATA (64*1024) #define MAXDATA (64*1024)
extern char *__progname; static const char *prog_name;
static void print_help(void) static void print_help(void)
{ {
printf("Usage: %s [OPTIONS] [FILE]\n", __progname); printf("Usage: %s [OPTIONS] [FILE]\n", prog_name);
puts("Copies data from FILE or stdin into X cut buffer."); puts("Copies data from FILE or stdin into X cut buffer.");
puts(""); puts("");
puts(" -display <display> display to use"); puts(" -display <display> display to use");
@@ -70,37 +70,38 @@ int main(int argc, char **argv)
int limit_check = 1; int limit_check = 1;
int clear_selection = 0; int clear_selection = 0;
prog_name = argv[0];
for (i = 1; i < argc; i++) { for (i = 1; i < argc; i++) {
if (argv[i][0] == '-') { if (argv[i][0] == '-') {
if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) { if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) {
print_help(); print_help();
exit(0); exit(0);
} else if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--version") == 0) { } else if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--version") == 0) {
printf("%s (Window Maker %s)\n", __progname, VERSION); printf("%s (Window Maker %s)\n", prog_name, VERSION);
exit(0); exit(0);
} else if (strcmp(argv[i], "-cutbuffer") == 0 || strcmp(argv[i], "--cutbuffer") == 0) { } else if (strcmp(argv[i], "-cutbuffer") == 0 || strcmp(argv[i], "--cutbuffer") == 0) {
if (i < argc - 1) { if (i < argc - 1) {
i++; i++;
if (sscanf(argv[i], "%i", &buffer) != 1) { if (sscanf(argv[i], "%i", &buffer) != 1) {
fprintf(stderr, "%s: could not convert '%s' to int\n", fprintf(stderr, "%s: could not convert '%s' to int\n",
__progname, argv[i]); prog_name, argv[i]);
exit(1); exit(1);
} }
if (buffer < 0 || buffer > 7) { if (buffer < 0 || buffer > 7) {
fprintf(stderr, "%s: invalid buffer number %i\n", __progname, buffer); fprintf(stderr, "%s: invalid buffer number %i\n", prog_name, buffer);
exit(1); exit(1);
} }
} else { } else {
printf("%s: missing argument for '%s'\n", __progname, argv[i]); printf("%s: missing argument for '%s'\n", prog_name, argv[i]);
printf("Try '%s --help' for more information\n", __progname); printf("Try '%s --help' for more information\n", prog_name);
exit(1); exit(1);
} }
} else if (strcmp(argv[i], "-display") == 0) { } else if (strcmp(argv[i], "-display") == 0) {
if (i < argc - 1) { if (i < argc - 1) {
display_name = argv[++i]; display_name = argv[++i];
} else { } else {
printf("%s: missing argument for '%s'\n", __progname, argv[i]); printf("%s: missing argument for '%s'\n", prog_name, argv[i]);
printf("Try '%s --help' for more information\n", __progname); printf("Try '%s --help' for more information\n", prog_name);
exit(1); exit(1);
} }
} else if (strcmp(argv[i], "-clearselection") == 0 } else if (strcmp(argv[i], "-clearselection") == 0
@@ -109,8 +110,8 @@ int main(int argc, char **argv)
} else if (strcmp(argv[i], "-nolimit") == 0 || strcmp(argv[i], "--no-limit") == 0) { } else if (strcmp(argv[i], "-nolimit") == 0 || strcmp(argv[i], "--no-limit") == 0) {
limit_check = 0; limit_check = 0;
} else { } else {
printf("%s: invalid argument '%s'\n", __progname, argv[i]); printf("%s: invalid argument '%s'\n", prog_name, argv[i]);
printf("Try '%s --help' for more information\n", __progname); printf("Try '%s --help' for more information\n", prog_name);
exit(1); exit(1);
} }
} else { } else {
@@ -124,7 +125,7 @@ int main(int argc, char **argv)
snprintf(line, sizeof(line), snprintf(line, sizeof(line),
"%s: could not open \"%s\"", "%s: could not open \"%s\"",
__progname, filename); prog_name, filename);
perror(line); perror(line);
exit(1); exit(1);
} }
@@ -133,7 +134,7 @@ int main(int argc, char **argv)
dpy = XOpenDisplay(display_name); dpy = XOpenDisplay(display_name);
XSetErrorHandler(errorHandler); XSetErrorHandler(errorHandler);
if (!dpy) { if (!dpy) {
fprintf(stderr, "%s: could not open display \"%s\"\n", __progname, XDisplayName(display_name)); fprintf(stderr, "%s: could not open display \"%s\"\n", prog_name, XDisplayName(display_name));
exit(1); exit(1);
} }
@@ -218,7 +219,7 @@ int main(int argc, char **argv)
nbuf = buf; nbuf = buf;
} }
if (!nbuf) { if (!nbuf) {
fprintf(stderr, "%s: out of memory\n", __progname); fprintf(stderr, "%s: out of memory\n", prog_name);
exit(1); exit(1);
} }
buf = nbuf; buf = nbuf;
@@ -232,7 +233,7 @@ int main(int argc, char **argv)
fprintf fprintf
(stderr, (stderr,
"%s: too much data in input - more than %d bytes\n" "%s: too much data in input - more than %d bytes\n"
" use the -nolimit argument to remove the limit check.\n", __progname, MAXDATA); " use the -nolimit argument to remove the limit check.\n", prog_name, MAXDATA);
exit(1); exit(1);
} }
} }

View File

@@ -35,11 +35,11 @@
#define MAXDATA (4*1024*1024) #define MAXDATA (4*1024*1024)
extern char *__progname; static const char *prog_name;
static void print_help(void) static void print_help(void)
{ {
printf("Usage: %s [OPTIONS] [FILE]\n", __progname); printf("Usage: %s [OPTIONS] [FILE]\n", prog_name);
puts("Copies data from X selection or cutbuffer to FILE or stdout."); puts("Copies data from X selection or cutbuffer to FILE or stdout.");
puts(""); puts("");
puts(" -display display display to use"); puts(" -display display display to use");
@@ -157,13 +157,14 @@ int main(int argc, char **argv)
char *display_name = ""; char *display_name = "";
char *selection_name = NULL; char *selection_name = NULL;
prog_name = argv[0];
for (i = 1; i < argc; i++) { for (i = 1; i < argc; i++) {
if (argv[i][0] == '-') { if (argv[i][0] == '-') {
if (argv[i][1] == 'h' || strcmp(argv[i], "--help") == 0) { if (argv[i][1] == 'h' || strcmp(argv[i], "--help") == 0) {
print_help(); print_help();
exit(0); exit(0);
} else if (argv[i][1] == 'v' || strcmp(argv[i], "--version") == 0) { } else if (argv[i][1] == 'v' || strcmp(argv[i], "--version") == 0) {
printf("%s (Window Maker %s)\n", __progname, VERSION); printf("%s (Window Maker %s)\n", prog_name, VERSION);
exit(0); exit(0);
} else if (strcmp(argv[i], "-selection") == 0 || strcmp(argv[i], "--selection") == 0) { } else if (strcmp(argv[i], "-selection") == 0 || strcmp(argv[i], "--selection") == 0) {
if (i < argc - 1) { if (i < argc - 1) {
@@ -183,28 +184,28 @@ int main(int argc, char **argv)
i++; i++;
if (sscanf(argv[i], "%i", &buffer) != 1) { if (sscanf(argv[i], "%i", &buffer) != 1) {
fprintf(stderr, "%s: could not convert \"%s\" to int\n", fprintf(stderr, "%s: could not convert \"%s\" to int\n",
__progname, argv[i]); prog_name, argv[i]);
exit(1); exit(1);
} }
if (buffer < 0 || buffer > 7) { if (buffer < 0 || buffer > 7) {
fprintf(stderr, "%s: invalid buffer number %i\n", __progname, buffer); fprintf(stderr, "%s: invalid buffer number %i\n", prog_name, buffer);
exit(1); exit(1);
} }
} else { } else {
fprintf(stderr, "%s: invalid argument '%s'\n", __progname, argv[i]); fprintf(stderr, "%s: invalid argument '%s'\n", prog_name, argv[i]);
fprintf(stderr, "Try '%s --help' for more information.\n", __progname); fprintf(stderr, "Try '%s --help' for more information.\n", prog_name);
exit(1); exit(1);
} }
} }
} else { } else {
fprintf(stderr, "%s: invalid argument '%s'\n", __progname, argv[i]); fprintf(stderr, "%s: invalid argument '%s'\n", prog_name, argv[i]);
fprintf(stderr, "Try '%s --help' for more information.\n", __progname); fprintf(stderr, "Try '%s --help' for more information.\n", prog_name);
exit(1); exit(1);
} }
} }
dpy = XOpenDisplay(display_name); dpy = XOpenDisplay(display_name);
if (!dpy) { if (!dpy) {
fprintf(stderr, "%s: could not open display \"%s\"\n", __progname, XDisplayName(display_name)); fprintf(stderr, "%s: could not open display \"%s\"\n", prog_name, XDisplayName(display_name));
exit(1); exit(1);
} }