summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpgen <p.gen.progs@gmail.com>2019-03-28 22:27:32 +0100
committerpgen <p.gen.progs@gmail.com>2019-03-30 11:39:02 +0100
commitf2dd3b30aa30209253c50bdd3fab44c0de750d0f (patch)
tree5a6236cc6b30a374c1beab9b0a4811cd8652b892
parent80a48ad3ca40991bb67d9e3029417398157a1435 (diff)
Rework the usage mechanism
-rw-r--r--Makefile.am2
-rw-r--r--Makefile.in5
-rw-r--r--getopt.c4
-rw-r--r--getopt.h4
-rw-r--r--smenu.c296
-rw-r--r--smenu.h9
-rw-r--r--usage.c166
-rw-r--r--usage.h15
8 files changed, 264 insertions, 237 deletions
diff --git a/Makefile.am b/Makefile.am
index 6f47d11..4688d0e 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,7 +1,7 @@
bin_PROGRAMS = smenu
smenu_SOURCES = smenu.c smenu.h list.c list.h xmalloc.c xmalloc.h \
index.c index.h utf8.c utf8.h fgetc.c fgetc.h \
- utils.c utils.h getopt.c getopt.h
+ utils.c utils.h getopt.c getopt.h usage.c usage.h
dist_man_MANS = smenu.1
EXTRA_DIST = smenu.spec.in smenu.spec ChangeLog build.sh version \
COPYRIGHT LICENSE.rst README.rst examples build-aux tests
diff --git a/Makefile.in b/Makefile.in
index c3b0403..f33fb7d 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -104,7 +104,7 @@ am__installdirs = "$(DESTDIR)$(bindir)" "$(DESTDIR)$(man1dir)"
PROGRAMS = $(bin_PROGRAMS)
am_smenu_OBJECTS = smenu.$(OBJEXT) list.$(OBJEXT) xmalloc.$(OBJEXT) \
index.$(OBJEXT) utf8.$(OBJEXT) fgetc.$(OBJEXT) utils.$(OBJEXT) \
- getopt.$(OBJEXT)
+ getopt.$(OBJEXT) usage.$(OBJEXT)
smenu_OBJECTS = $(am_smenu_OBJECTS)
smenu_LDADD = $(LDADD)
AM_V_P = $(am__v_P_@AM_V@)
@@ -309,7 +309,7 @@ top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
smenu_SOURCES = smenu.c smenu.h list.c list.h xmalloc.c xmalloc.h \
index.c index.h utf8.c utf8.h fgetc.c fgetc.h \
- utils.c utils.h getopt.c getopt.h
+ utils.c utils.h getopt.c getopt.h usage.c usage.h
dist_man_MANS = smenu.1
EXTRA_DIST = smenu.spec.in smenu.spec ChangeLog build.sh version \
@@ -429,6 +429,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/index.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/list.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/smenu.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/usage.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/utf8.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/utils.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xmalloc.Po@am__quote@
diff --git a/getopt.c b/getopt.c
index 552d851..fde7b1b 100644
--- a/getopt.c
+++ b/getopt.c
@@ -121,6 +121,8 @@ egetopt(int nargc, char ** nargv, char * ostr)
++eoptind;
TELL("Illegal option -- "); /* bye bye */
+
+ return (eoptbad);
}
/* If there is no argument indicator, then we don't even try to */
@@ -165,6 +167,8 @@ egetopt(int nargc, char ** nargv, char * ostr)
{
place = EMSG;
TELL("Option requires an argument -- ");
+
+ return (eoptbad);
}
else
eoptarg = nargv[eoptind];
diff --git a/getopt.h b/getopt.h
index 0b3f940..fef745f 100644
--- a/getopt.h
+++ b/getopt.h
@@ -25,7 +25,9 @@
dummy_rc = write(eopterrfd, &option, 1); \
dummy_rc = write(eopterrfd, "\n", 1); \
} \
- return (eoptbad); \
}
+int
+egetopt(int nargc, char ** nargv, char * ostr);
+
#endif
diff --git a/smenu.c b/smenu.c
index ce05b95..5232bc5 100644
--- a/smenu.c
+++ b/smenu.c
@@ -45,6 +45,7 @@
#include "fgetc.h"
#include "utils.h"
#include "getopt.h"
+#include "usage.h"
#include "smenu.h"
/* **************** */
@@ -139,160 +140,6 @@ int quiet_timeout = 0; /* 1 when we want no message to be displayed. */
/* Help functions */
/* ************** */
-/* =================== */
-/* Short usage display */
-/* =================== */
-void
-short_usage(void)
-{
- printf("Usage: smenu [-h|-?] [-f config_file] [-n [lines]] ");
- printf("[-t [cols]] [-k] [-v] \\\n");
- printf(" [-s pattern] [-m message] [-w] [-d] [-M] [-c] [-l] ");
- printf("[-r] [-b] \\\n");
- printf(" [-a prefix:attr [prefix:attr]...] ");
- printf("[-i regex] [-e regex] \\\n");
- printf(" [-C [i|e]<col selectors>] ");
- printf("[-R [i|e]<row selectors>] \\\n");
- printf(" [-S /regex/repl/[g][v][s][i]] ");
- printf("[-I /regex/repl/[g][v][s][i]] \\\n");
- printf(" [-E /regex/repl/[g][v][s][i]] ");
- printf("[-A regex] [-Z regex] \\\n");
- printf(" [-N [regex]] [-U [regex]] [-F] [-D arg...] ");
- printf(" \\\n");
- printf(" [-1 regex [attr]] [-2 regex [attr]]... ");
- printf("[-5 regex [attr]] [-g [string]] \\\n");
- printf(" [-q] [-W bytes] [-L bytes] [-T [separator]] ");
- printf("[-P [separator]] [-p] \\\n");
- printf(" [-V] [-x|-X current|quit|word [<word>] ");
- printf("<seconds>] \\\n");
- printf(" [-/ prefix|substring|fuzzy] [--] [input_file]\n\n");
- printf(" <col selectors> ::= col1[-col2]...|<RE>...\n");
- printf(" <row selectors> ::= row1[-row2]...|<RE>...\n");
- printf(" <prefix> ::= i|e|c|b|s|m|t|ct|sf|st|mf|mt|");
- printf("sfe|ste|mfe|mte|da\n");
- printf(" <arg> ::= [l|r:<char>]|[a:l|r]|[p:i|a]|");
- printf("[w:<size>]|\n");
- printf(" [f:y|n]|[o:<num>[+]]|[n:<num>]|");
- printf("[i:<num>]|[d:<char>]|\n");
- printf(" [s:<num>]|[h:t|c|k]\n");
- printf(" Ex: l:'(' a:l\n");
- printf(" <attr> ::= [fg][/bg][,style] \n");
- printf(" Ex: 7/4,bu\n");
- printf(" <RE> ::= <char>regex<char> \n");
- printf(" Ex: /regex/ or :regex:\n\n");
- printf(" <col/row selectors> and <RE> can be freely mixed ");
- printf("when used\n");
- printf(" with -C and -R (ex: 2,/x/,4-5).\n");
-}
-
-/* ====================== */
-/* Usage display and exit */
-/* ====================== */
-void
-usage(void)
-{
- short_usage();
-
- printf("\nThis is a filter that gets words from stdin ");
- printf("and outputs the selected\n");
- printf("words (or nothing) on stdout in a nice selection ");
- printf("window\n\n");
- printf("The selection window appears on /dev/tty ");
- printf("immediately after the current line\n");
- printf("(no clear screen!).\n\n");
- printf("The following options are available:\n\n");
- printf("-h displays this help.\n");
- printf("-f selects an alternative configuration file.\n");
- printf("-n sets the number of lines in the selection window.\n");
- printf("-t tabulates the items. The number of columns can be limited "
- "with\n");
- printf(" an optional number.\n");
- printf("-k does not trim spaces surrounding the output string if any.\n");
- printf("-v makes the bell visual (fuzzy search with error).\n");
- printf("-s sets the initial cursor position (read the manual for "
- "more details).\n");
- printf("-m displays a one-line message above the window.\n");
- printf("-w uses all the terminal width for the columns if their numbers "
- "is given.\n");
- printf("-d deletes the selection window on exit.\n");
- printf("-M centers the display if possible.\n");
- printf("-c is like -t without argument but respects end of lines.\n");
- printf("-l is like -c without column alignments.\n");
- printf("-r enables ENTER to validate the selection even in "
- "search mode.\n");
- printf("-b displays the non printable characters as space.\n");
- printf("-a sets the attributes for the various displayed ");
- printf("elements.\n");
- printf("-i sets the regex input filter to match the selectable words.\n");
- printf("-e sets the regex input filter to match the non-selectable "
- "words.\n");
- printf("-C sets columns restrictions for selections.\n");
- printf("-R sets rows restrictions for selections.\n");
- printf("-S sets the post-processing action to apply to all words.\n");
- printf("-I sets the post-processing action to apply to selectable "
- "words only.\n");
- printf("-E sets the post-processing action to apply to non-selectable "
- "words only.\n");
- printf("-A forces a class of words to be the first of the line they "
- "appear in.\n");
- printf("-Z forces a class of words to be the latest of the line they "
- "appear in.\n");
- printf("-N/-U numbers/un-numbers and provides a direct access to words "
- "matching\n");
- printf(" (or not) a specific regex.\n");
- printf("-F numbers and provides a direct access to words by extracting the "
- "number\n");
- printf(" from the words.\n");
- printf("-D sets sub-options to modify the behaviour of -N, -U and -F.\n");
- printf("-1,-2,...,-5 gives specific colors to up to 5 classes of "
- "selectable words.\n");
- printf("-g separates columns with a character in column or tabulate "
- "mode.\n");
- printf("-q prevents the display of the scroll bar.\n");
- printf("-W sets the input words separators.\n");
- printf("-L sets the input lines separators.\n");
- printf("-T/-P enables the tagging (multi-selections) mode. ");
- printf("An optional parameter\n");
- printf(" sets the separator string between the selected words ");
- printf("on the output.\n");
- printf(" A single space is the default separator.\n");
- printf("-p activates the auto-tagging when using -T or -P.\n");
- printf("-V displays the current version and quits.\n");
- printf("-x|-X sets a timeout and specifies what to do when it expires.\n");
- printf("-/ changes the affectation of the / key (default fuzzy search).\n");
- printf("\nNavigation keys are:\n");
- printf(" - Left/Down/Up/Right arrows or h/j/k/l, H/J/K/L.\n");
- printf(" - Home/End, SHIFT|CTRL+Home/End CTRK+J/CTRL+K.\n");
- printf(" - Numbers if some words are numbered (-N/-U/-F).\n");
- printf(" - SPACE to search for the next match of a previously\n");
- printf(" entered search prefix if any, see below.\n\n");
- printf("Other useful keys are:\n");
- printf(" - Help key (temporary display of a short help line): "
- "?\n");
- printf(" - Exit key without output (do nothing) : "
- "q\n");
- printf(" - Tagging keys: Select/Deselect/Toggle : "
- "INS/DEL/t\n");
- printf(" - Selection key : "
- "ENTER\n");
- printf(" - Cancel key : "
- "ESC\n");
- printf(" - Search key : "
- "/ or CTRL-F\n\n");
- printf("The search key activates a timed search mode in which\n");
- printf("you can enter the first letters of the searched word.\n");
- printf("When entering this mode you have 7s to start typing\n");
- printf("and each entered letter gives you 5 more seconds before\n");
- printf("the timeout. After that the search mode is ended.\n\n");
- printf("Notes:\n");
- printf("- the timer can be cancelled by pressing ESC.\n");
- printf("- a bad search letter can be removed with ");
- printf("CTRL-H or Backspace.\n\n");
- printf("(C) Pierre Gentile (2015).\n");
-
- exit(EXIT_FAILURE);
-}
-
/* ==================== */
/* Help message display */
/* ==================== */
@@ -5326,18 +5173,20 @@ main(int argc, char * argv[])
daccess.num_sep = NULL;
daccess.def_number = -1;
+ /* Allowed command line options */
+ /* """""""""""""""""""""""""""" */
+ static char * optstring = "Vf:h?X:x:qdMba:i:e:S:I:E:A:Z:1:2:3:4:5:C:R:"
+ "kvclwrg%n%t%m:s:W:L:T%P%pN%U%FD:/:";
+
/* Command line options analysis */
/* """"""""""""""""""""""""""""" */
- while ((opt = egetopt(argc, argv,
- "Vf:h?X:x:qdMba:i:e:S:I:E:A:Z:1:2:3:4:5:C:R:"
- "kvclwrg%n%t%m:s:W:L:T%P%pN%U%FD:/:"))
- != -1)
+ while ((opt = egetopt(argc, argv, optstring)) != -1)
{
switch (opt)
{
case 'V':
fputs("Version: " VERSION "\n", stdout);
- exit(0);
+ exit(EXIT_SUCCESS);
case 'f':
if (eoptarg && *eoptarg != '-')
@@ -5345,8 +5194,9 @@ main(int argc, char * argv[])
else
{
TELL("Option requires an argument -- ");
- short_usage();
+ short_usage(1);
}
+
break;
case 'n':
@@ -5355,7 +5205,7 @@ main(int argc, char * argv[])
if (sscanf(eoptarg, "%ld", &(win.asked_max_lines)) != 1)
{
TELL("Argument must be numeric -- ");
- short_usage();
+ short_usage(1);
}
}
else
@@ -5379,7 +5229,7 @@ main(int argc, char * argv[])
else
{
TELL("Option requires an argument -- ");
- short_usage();
+ short_usage(1);
}
break;
@@ -5389,13 +5239,13 @@ main(int argc, char * argv[])
if (sscanf(eoptarg, "%ld", &(win.max_cols)) != 1)
{
TELL("Argument must be numeric -- ");
- short_usage();
+ short_usage(1);
}
if (win.max_cols < 1)
{
TELL("Argument must be at least 1 -- ");
- short_usage();
+ short_usage(1);
}
}
@@ -5479,7 +5329,7 @@ main(int argc, char * argv[])
free(gutter);
TELL("A multi columns gutter is not allowed -- ");
- short_usage();
+ short_usage(1);
}
offset += mblen;
@@ -5506,7 +5356,7 @@ main(int argc, char * argv[])
else
{
TELL("Option requires an argument -- ");
- short_usage();
+ short_usage(1);
}
break;
@@ -5534,7 +5384,7 @@ main(int argc, char * argv[])
else
{
TELL("Option requires an argument -- ");
- short_usage();
+ short_usage(1);
}
break;
@@ -5554,7 +5404,7 @@ main(int argc, char * argv[])
else
{
TELL("Option requires an argument -- ");
- short_usage();
+ short_usage(1);
}
break;
@@ -5569,7 +5419,7 @@ main(int argc, char * argv[])
else
{
TELL("Option requires an argument -- ");
- short_usage();
+ short_usage(1);
}
break;
@@ -5585,7 +5435,7 @@ main(int argc, char * argv[])
else
{
TELL("Option requires an argument -- ");
- short_usage();
+ short_usage(1);
}
break;
@@ -5606,7 +5456,7 @@ main(int argc, char * argv[])
else
{
TELL("Option requires an argument -- ");
- short_usage();
+ short_usage(1);
}
break;
@@ -5627,7 +5477,7 @@ main(int argc, char * argv[])
else
{
TELL("Option requires an argument -- ");
- short_usage();
+ short_usage(1);
}
break;
@@ -5648,7 +5498,7 @@ main(int argc, char * argv[])
else
{
TELL("Option requires an argument -- ");
- short_usage();
+ short_usage(1);
}
break;
@@ -5672,7 +5522,7 @@ main(int argc, char * argv[])
if (count > 2)
{
TELL("Too many arguments -- ");
- short_usage();
+ short_usage(1);
}
/* Colors must respect the format: <fg color>/<bg color> */
@@ -5692,7 +5542,7 @@ main(int argc, char * argv[])
else
{
TELL("Bad optional color settings -- ");
- short_usage();
+ short_usage(1);
}
eoptind++;
@@ -5702,7 +5552,7 @@ main(int argc, char * argv[])
else
{
TELL("Option requires an argument -- ");
- short_usage();
+ short_usage(1);
}
break;
@@ -5797,7 +5647,7 @@ main(int argc, char * argv[])
if (*argv[eoptind] == '-')
{
TELL("A blank is required before the first sub-option -- ");
- short_usage();
+ short_usage(1);
}
/* Parse the arguments arguments */
@@ -5809,7 +5659,7 @@ main(int argc, char * argv[])
if (strlen(argv[eoptind]) < 3)
{
TELL("Empty attribute value -- ");
- short_usage();
+ short_usage(1);
}
i = 0;
@@ -5822,7 +5672,7 @@ main(int argc, char * argv[])
if (*attr_infos[i].flag)
{
TELL(attr_infos[i].msg);
- short_usage();
+ short_usage(1);
}
attr_to_set = attr_infos[i].attr;
@@ -5836,7 +5686,7 @@ main(int argc, char * argv[])
if (attr_infos[i].flag == NULL)
{
TELL("Bad attribute prefix -- ");
- short_usage();
+ short_usage(1);
}
/* Attributes must respect the format: */
@@ -5857,7 +5707,7 @@ main(int argc, char * argv[])
else
{
TELL("Bad attribute settings -- ");
- short_usage();
+ short_usage(1);
}
eoptind++;
@@ -5866,7 +5716,7 @@ main(int argc, char * argv[])
else
{
TELL("Option requires an argument -- ");
- short_usage();
+ short_usage(1);
}
break;
@@ -5891,13 +5741,13 @@ main(int argc, char * argv[])
else
{
TELL("Missing timeout word -- ");
- short_usage();
+ short_usage(1);
}
}
else
{
TELL("Invalid timeout type -- ");
- short_usage();
+ short_usage(1);
}
if (argv[eoptind] && *argv[eoptind] != '-')
@@ -5910,13 +5760,13 @@ main(int argc, char * argv[])
else
{
TELL("Invalid timeout delay -- ");
- short_usage();
+ short_usage(1);
}
}
else
{
TELL("Missing timeout delay -- ");
- short_usage();
+ short_usage(1);
}
eoptind++;
@@ -5936,7 +5786,7 @@ main(int argc, char * argv[])
else
{
TELL("Option requires an argument -- ");
- short_usage();
+ short_usage(1);
}
break;
@@ -5949,7 +5799,7 @@ main(int argc, char * argv[])
else
{
TELL("Option requires an argument -- ");
- short_usage();
+ short_usage(1);
}
break;
@@ -5962,7 +5812,7 @@ main(int argc, char * argv[])
else
{
TELL("Option requires an argument -- ");
- short_usage();
+ short_usage(1);
}
break;
@@ -5975,7 +5825,7 @@ main(int argc, char * argv[])
else
{
TELL("Option requires an argument -- ");
- short_usage();
+ short_usage(1);
}
break;
@@ -6008,7 +5858,7 @@ main(int argc, char * argv[])
if (*argv[eoptind] == '-')
{
TELL("A blank is required before the first sub-option -- ");
- short_usage();
+ short_usage(1);
}
while (argv[eoptind] && *argv[eoptind] != '-')
@@ -6016,7 +5866,7 @@ main(int argc, char * argv[])
if (argv[eoptind][1] != ':')
{
TELL("Bad format -- ");
- short_usage();
+ short_usage(1);
}
switch (*(argv[eoptind]))
@@ -6030,7 +5880,7 @@ main(int argc, char * argv[])
if (utf8_strlen(daccess.left) != 1)
{
TELL("Too many characters after l: -- ");
- short_usage();
+ short_usage(1);
}
n = wcswidth((w = utf8_strtowcs(daccess.left)), 1);
@@ -6040,7 +5890,7 @@ main(int argc, char * argv[])
{
TELL("A multi columns character is not allowed "
"after l: -- ");
- short_usage();
+ short_usage(1);
}
break;
@@ -6053,7 +5903,7 @@ main(int argc, char * argv[])
if (utf8_strlen(daccess.right) != 1)
{
TELL("Too many characters after r: -- ");
- short_usage();
+ short_usage(1);
}
n = wcswidth((w = utf8_strtowcs(daccess.right)), 1);
@@ -6063,7 +5913,7 @@ main(int argc, char * argv[])
{
TELL("A multi columns character is not allowed "
"after r: -- ");
- short_usage();
+ short_usage(1);
}
break;
@@ -6075,7 +5925,7 @@ main(int argc, char * argv[])
else
{
TELL("Bad format -- ");
- short_usage();
+ short_usage(1);
}
break;
@@ -6087,7 +5937,7 @@ main(int argc, char * argv[])
else
{
TELL("Bad format -- ");
- short_usage();
+ short_usage(1);
}
break;
@@ -6096,17 +5946,17 @@ main(int argc, char * argv[])
!= 1)
{
TELL("Bad format -- ");
- short_usage();
+ short_usage(1);
}
if (argv[eoptind][pos + 2] != '\0')
{
TELL("Bad format -- ");
- short_usage();
+ short_usage(1);
}
if (daccess.length <= 0 || daccess.length > 5)
{
TELL("w suboption must be between 1 and 5 -- ");
- short_usage();
+ short_usage(1);
}
break;
@@ -6121,19 +5971,19 @@ main(int argc, char * argv[])
if (argv[eoptind][pos + 3] != '\0')
{
TELL("Bad format -- ");
- short_usage();
+ short_usage(1);
}
}
else if (argv[eoptind][pos + 2] != '\0')
{
TELL("Bad format -- ");
- short_usage();
+ short_usage(1);
}
}
else
{
TELL("Bad format -- ");
- short_usage();
+ short_usage(1);
}
break;
@@ -6142,17 +5992,17 @@ main(int argc, char * argv[])
if (sscanf(argv[eoptind] + 2, "%d%n", &daccess.size, &pos) != 1)
{
TELL("Bad format -- ");
- short_usage();
+ short_usage(1);
}
if (argv[eoptind][pos + 2] != '\0')
{
TELL("Bad format -- ");
- short_usage();
+ short_usage(1);
}
if (daccess.size <= 0 || daccess.size > 5)
{
TELL("n suboption must be between 1 and 5 -- ");
- short_usage();
+ short_usage(1);
}
break;
@@ -6162,12 +6012,12 @@ main(int argc, char * argv[])
!= 1)
{
TELL("Bad format -- ");
- short_usage();
+ short_usage(1);
}
if (argv[eoptind][pos + 2] != '\0')
{
TELL("Bad format -- ");
- short_usage();
+ short_usage(1);
}
break;
@@ -6179,7 +6029,7 @@ main(int argc, char * argv[])
else
{
TELL("Bad format -- ");
- short_usage();
+ short_usage(1);
}
break;
@@ -6192,7 +6042,7 @@ main(int argc, char * argv[])
if (utf8_strlen(daccess.num_sep) != 1)
{
TELL("Too many characters after d: -- ");
- short_usage();
+ short_usage(1);
}
n = wcswidth((w = utf8_strtowcs(daccess.num_sep)), 1);
@@ -6202,7 +6052,7 @@ main(int argc, char * argv[])
{
TELL("A multi columns separator is not allowed "
"after d: -- ");
- short_usage();
+ short_usage(1);
}
break;
@@ -6219,7 +6069,7 @@ main(int argc, char * argv[])
else
{
TELL("Invalid first index after s: -- ");
- short_usage();
+ short_usage(1);
}
}
break;
@@ -6234,14 +6084,14 @@ main(int argc, char * argv[])
else
{
TELL("Bad format -- ");
- short_usage();
+ short_usage(1);
}
break;
default:
{
TELL("Bad format -- ");
- short_usage();
+ short_usage(1);
}
}
@@ -6254,7 +6104,7 @@ main(int argc, char * argv[])
else
{
TELL("Option requires an argument -- ");
- short_usage();
+ short_usage(1);
}
break;
@@ -6312,21 +6162,19 @@ main(int argc, char * argv[])
else
{
TELL("Bad format -- ");
- short_usage();
+ short_usage(1);
}
break;
case '?':
- fputc('\n', stderr);
- short_usage();
-
- exit(EXIT_FAILURE);
+ short_usage(1);
case 'h':
usage();
- exit(EXIT_FAILURE);
+ case BADCH:
+ short_usage(1);
default:
exit(EXIT_FAILURE);
@@ -6339,7 +6187,7 @@ main(int argc, char * argv[])
if (argv[argc - 1][0] == '-')
{
fprintf(stderr, "Not an option -- %s\n", argv[argc - 1]);
- short_usage();
+ short_usage(1);
exit(EXIT_FAILURE);
}
@@ -6348,7 +6196,7 @@ main(int argc, char * argv[])
if (input_file == NULL)
{
fprintf(stderr, "Cannot open \"%s\"\n", argv[argc - 1]);
- short_usage();
+ short_usage(1);
exit(EXIT_FAILURE);
}
diff --git a/smenu.h b/smenu.h
index b9ab07a..ba8a420 100644
--- a/smenu.h
+++ b/smenu.h
@@ -65,12 +65,6 @@ typedef enum bitmap_affinities bitmap_affinity_t;
void
help(win_t * win, term_t * term, long last_line, toggle_t * toggle);
-void
-short_usage(void);
-
-void
-usage(void);
-
int
tag_comp(void * a, void * b);
@@ -175,9 +169,6 @@ void
disp_word(long pos, search_mode_t search_mode, search_data_t * search_data,
term_t * term, win_t * win, char * tmp_word);
-int
-egetopt(int nargc, char ** nargv, char * ostr);
-
size_t
expand(char * src, char * dest, langinfo_t * langinfo, toggle_t * toggle);
diff --git a/usage.c b/usage.c
new file mode 100644
index 0000000..0a1b644
--- /dev/null
+++ b/usage.c
@@ -0,0 +1,166 @@
+/* *************** */
+/* Usage functions */
+/* *************** */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include "usage.h"
+
+/* =================== */
+/* Short usage display */
+/* =================== */
+void
+short_usage(int must_exit)
+{
+ printf("\nUsage: smenu [-h|-?] [-f config_file] [-n [lines]] ");
+ printf("[-t [cols]] [-k] [-v] \\\n");
+ printf(" [-s pattern] [-m message] [-w] [-d] [-M] [-c] [-l] ");
+ printf("[-r] [-b] \\\n");
+ printf(" [-a prefix:attr [prefix:attr]...] ");
+ printf("[-i regex] [-e regex] \\\n");
+ printf(" [-C [i|e]<col selectors>] ");
+ printf("[-R [i|e]<row selectors>] \\\n");
+ printf(" [-S /regex/repl/[g][v][s][i]] ");
+ printf("[-I /regex/repl/[g][v][s][i]] \\\n");
+ printf(" [-E /regex/repl/[g][v][s][i]] ");
+ printf("[-A regex] [-Z regex] \\\n");
+ printf(" [-N [regex]] [-U [regex]] [-F] [-D arg...] ");
+ printf(" \\\n");
+ printf(" [-1 regex [attr]] [-2 regex [attr]]... ");
+ printf("[-5 regex [attr]] [-g [string]] \\\n");
+ printf(" [-q] [-W bytes] [-L bytes] [-T [separator]] ");
+ printf("[-P [separator]] [-p] \\\n");
+ printf(" [-V] [-x|-X current|quit|word [<word>] ");
+ printf("<seconds>] \\\n");
+ printf(" [-/ prefix|substring|fuzzy] [--] [input_file]\n\n");
+ printf(" <col selectors> ::= col1[-col2]...|<RE>...\n");
+ printf(" <row selectors> ::= row1[-row2]...|<RE>...\n");
+ printf(" <prefix> ::= i|e|c|b|s|m|t|ct|sf|st|mf|mt|");
+ printf("sfe|ste|mfe|mte|da\n");
+ printf(" <arg> ::= [l|r:<char>]|[a:l|r]|[p:i|a]|");
+ printf("[w:<size>]|\n");
+ printf(" [f:y|n]|[o:<num>[+]]|[n:<num>]|");
+ printf("[i:<num>]|[d:<char>]|\n");
+ printf(" [s:<num>]|[h:t|c|k]\n");
+ printf(" Ex: l:'(' a:l\n");
+ printf(" <attr> ::= [fg][/bg][,style] \n");
+ printf(" Ex: 7/4,bu\n");
+ printf(" <RE> ::= <char>regex<char> \n");
+ printf(" Ex: /regex/ or :regex:\n\n");
+ printf(" <col/row selectors> and <RE> can be freely mixed ");
+ printf("when used\n");
+ printf(" with -C and -R (ex: 2,/x/,4-5).\n\n");
+
+ if (must_exit)
+ exit(EXIT_FAILURE);
+}
+
+/* ====================== */
+/* Usage display and exit */
+/* ====================== */
+void
+usage(void)
+{
+ short_usage(0);
+
+ printf("This is a filter that gets words from stdin ");
+ printf("and outputs the selected\n");
+ printf("words (or nothing) on stdout in a nice selection ");
+ printf("window\n\n");
+ printf("The selection window appears on /dev/tty ");
+ printf("immediately after the current line\n");
+ printf("(no clear screen!).\n\n");
+ printf("The following options are available:\n\n");
+ printf("-h displays this help.\n");
+ printf("-f selects an alternative configuration file.\n");
+ printf("-n sets the number of lines in the selection window.\n");
+ printf("-t tabulates the items. The number of columns can be limited "
+ "with\n");
+ printf(" an optional number.\n");
+ printf("-k does not trim spaces surrounding the output string if any.\n");
+ printf("-v makes the bell visual (fuzzy search with error).\n");
+ printf("-s sets the initial cursor position (read the manual for "
+ "more details).\n");
+ printf("-m displays a one-line message above the window.\n");
+ printf("-w uses all the terminal width for the columns if their numbers "
+ "is given.\n");
+ printf("-d deletes the selection window on exit.\n");
+ printf("-M centers the display if possible.\n");
+ printf("-c is like -t without argument but respects end of lines.\n");
+ printf("-l is like -c without column alignments.\n");
+ printf("-r enables ENTER to validate the selection even in "
+ "search mode.\n");
+ printf("-b displays the non printable characters as space.\n");
+ printf("-a sets the attributes for the various displayed ");
+ printf("elements.\n");
+ printf("-i sets the regex input filter to match the selectable words.\n");
+ printf("-e sets the regex input filter to match the non-selectable "
+ "words.\n");
+ printf("-C sets columns restrictions for selections.\n");
+ printf("-R sets rows restrictions for selections.\n");
+ printf("-S sets the post-processing action to apply to all words.\n");
+ printf("-I sets the post-processing action to apply to selectable "
+ "words only.\n");
+ printf("-E sets the post-processing action to apply to non-selectable "
+ "words only.\n");
+ printf("-A forces a class of words to be the first of the line they "
+ "appear in.\n");
+ printf("-Z forces a class of words to be the latest of the line they "
+ "appear in.\n");
+ printf("-N/-U numbers/un-numbers and provides a direct access to words "
+ "matching\n");
+ printf(" (or not) a specific regex.\n");
+ printf("-F numbers and provides a direct access to words by extracting the "
+ "number\n");
+ printf(" from the words.\n");
+ printf("-D sets sub-options to modify the behaviour of -N, -U and -F.\n");
+ printf("-1,-2,...,-5 gives specific colors to up to 5 classes of "
+ "selectable words.\n");
+ printf("-g separates columns with a character in column or tabulate "
+ "mode.\n");
+ printf("-q prevents the display of the scroll bar.\n");
+ printf("-W sets the input words separators.\n");
+ printf("-L sets the input lines separators.\n");
+ printf("-T/-P enables the tagging (multi-selections) mode. ");
+ printf("An optional parameter\n");
+ printf(" sets the separator string between the selected words ");
+ printf("on the output.\n");
+ printf(" A single space is the default separator.\n");
+ printf("-p activates the auto-tagging when using -T or -P.\n");
+ printf("-V displays the current version and quits.\n");
+ printf("-x|-X sets a timeout and specifies what to do when it expires.\n");
+ printf("-/ changes the affectation of the / key (default fuzzy search).\n");
+ printf("\nNavigation keys are:\n");
+ printf(" - Left/Down/Up/Right arrows or h/j/k/l, H/J/K/L.\n");
+ printf(" - Home/End, SHIFT|CTRL+Home/End CTRK+J/CTRL+K.\n");
+ printf(" - Numbers if some words are numbered (-N/-U/-F).\n");
+ printf(" - SPACE to search for the next match of a previously\n");
+ printf(" entered search prefix if any, see below.\n\n");
+ printf("Other useful keys are:\n");
+ printf(" - Help key (temporary display of a short help line): "
+ "?\n");
+ printf(" - Exit key without output (do nothing) : "
+ "q\n");
+ printf(" - Tagging keys: Select/Deselect/Toggle : "
+ "INS/DEL/t\n");