[PATCH] urxvtd and getopt
Russell Harmon
russ at eatnumber1.com
Wed Jan 21 19:45:58 CET 2009
I wrote a patch to urxvtd to use getopt. Note that this patch depends on my
previous patch "urxvtd and mlock". Patch follows:
Any interest in including this in the mainline?
-Russell Harmon
--- src/rxvtd.C.lock 2009-01-21 13:33:37.056813013 -0500
+++ src/rxvtd.C 2009-01-21 13:31:39.236823942 -0500
@@ -33,6 +33,9 @@
#include <sys/socket.h>
#include <sys/un.h>
#include <sys/mman.h>
+#ifdef _GNU_SOURCE
+#include <getopt.h>
+#endif
#include <cerrno>
@@ -224,6 +227,50 @@
{
rxvt_init ();
+#ifdef _GNU_SOURCE
+ static struct option long_options[] = {
+ {"fork", no_argument, NULL, 'f'},
+ {"opendisplay", no_argument, NULL, 'o'},
+ {"open-display", no_argument, NULL, 'o'},
+ {"quiet", no_argument, NULL, 'q'},
+ {"lock", no_argument, NULL, 'l'},
+ {"help", no_argument, NULL, 'h'},
+ {0, 0, 0, 0}
+ };
+
+ char c;
+ while ((c = getopt_long (argc, (char* const*) argv, "foqlh",
long_options, NULL)) != -1)
+ {
+ switch(c)
+ {
+ case 'f':
+ opt_fork = 1;
+ break;
+ case 'o':
+ opt_opendisplay = 1;
+ break;
+ case 'q':
+ opt_quiet = 1;
+ break;
+ case 'l':
+ opt_lock = 1;
+ break;
+ case 'h':
+ printf("Usage: %s [options]\n", argv[0]);
+ printf(" %-3s %-15s %s\n", "-f,", "--fork", "Fork to
background.");
+ printf(" %-3s %-15s %s\n", "-o,", "--open-display",
+ "Open the display and keep it open (daemon will
terminate with X).");
+ printf(" %-3s %-15s %s\n", "-l,", "--lock",
+ "Lock the daemon in RAM and prevent it from being
swapped out.");
+ printf(" %-3s %-15s\n", "-q,", "--quiet");
+ return EXIT_SUCCESS;
+ case '?':
+ return EXIT_FAILURE;
+ default:
+ return EXIT_FAILURE;
+ }
+ }
+#else
for (int i = 1; i < argc; i++)
{
if (!strcmp (argv [i], "-f") || !strcmp (argv [i], "--fork"))
@@ -240,6 +287,7 @@
return EXIT_FAILURE;
}
}
+#endif
// optionally open display and never release it.
if (opt_opendisplay)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.schmorp.de/pipermail/rxvt-unicode/attachments/20090121/f5330c0d/attachment.html>
More information about the rxvt-unicode
mailing list