1
0
mirror of https://github.com/gryf/wmaker.git synced 2025-12-19 12:28:22 +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

@@ -31,11 +31,11 @@
#define LINESIZE (4*1024)
#define MAXDATA (64*1024)
extern char *__progname;
static const char *prog_name;
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("");
puts(" -display <display> display to use");
@@ -70,37 +70,38 @@ int main(int argc, char **argv)
int limit_check = 1;
int clear_selection = 0;
prog_name = argv[0];
for (i = 1; i < argc; i++) {
if (argv[i][0] == '-') {
if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) {
print_help();
exit(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);
} else if (strcmp(argv[i], "-cutbuffer") == 0 || strcmp(argv[i], "--cutbuffer") == 0) {
if (i < argc - 1) {
i++;
if (sscanf(argv[i], "%i", &buffer) != 1) {
fprintf(stderr, "%s: could not convert '%s' to int\n",
__progname, argv[i]);
prog_name, argv[i]);
exit(1);
}
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);
}
} else {
printf("%s: missing argument for '%s'\n", __progname, argv[i]);
printf("Try '%s --help' for more information\n", __progname);
printf("%s: missing argument for '%s'\n", prog_name, argv[i]);
printf("Try '%s --help' for more information\n", prog_name);
exit(1);
}
} else if (strcmp(argv[i], "-display") == 0) {
if (i < argc - 1) {
display_name = argv[++i];
} else {
printf("%s: missing argument for '%s'\n", __progname, argv[i]);
printf("Try '%s --help' for more information\n", __progname);
printf("%s: missing argument for '%s'\n", prog_name, argv[i]);
printf("Try '%s --help' for more information\n", prog_name);
exit(1);
}
} 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) {
limit_check = 0;
} else {
printf("%s: invalid argument '%s'\n", __progname, argv[i]);
printf("Try '%s --help' for more information\n", __progname);
printf("%s: invalid argument '%s'\n", prog_name, argv[i]);
printf("Try '%s --help' for more information\n", prog_name);
exit(1);
}
} else {
@@ -124,7 +125,7 @@ int main(int argc, char **argv)
snprintf(line, sizeof(line),
"%s: could not open \"%s\"",
__progname, filename);
prog_name, filename);
perror(line);
exit(1);
}
@@ -133,7 +134,7 @@ int main(int argc, char **argv)
dpy = XOpenDisplay(display_name);
XSetErrorHandler(errorHandler);
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);
}
@@ -218,7 +219,7 @@ int main(int argc, char **argv)
nbuf = buf;
}
if (!nbuf) {
fprintf(stderr, "%s: out of memory\n", __progname);
fprintf(stderr, "%s: out of memory\n", prog_name);
exit(1);
}
buf = nbuf;
@@ -232,7 +233,7 @@ int main(int argc, char **argv)
fprintf
(stderr,
"%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);
}
}