mirror of
https://github.com/ascii-boxes/boxes.git
synced 2025-06-19 17:28:26 +02:00
Added support for --help and -? options, which do the same as -h
(This feature was requested by Raphael Wimmer).
This commit is contained in:
parent
d6b08f40b4
commit
92a5770124
55
src/boxes.c
55
src/boxes.c
@ -2,7 +2,7 @@
|
||||
* File: boxes.c
|
||||
* Date created: March 18, 1999 (Thursday, 15:09h)
|
||||
* Author: Copyright (C) 1999 Thomas Jensen <boxes@thomasjensen.com>
|
||||
* Version: $Id: boxes.c,v 1.37 2006/07/12 05:49:50 tsjensen Exp tsjensen $
|
||||
* Version: $Id: boxes.c,v 1.38 2006/07/22 19:40:40 tsjensen Exp tsjensen $
|
||||
* Language: ANSI C
|
||||
* Platforms: sunos5/sparc, for now
|
||||
* World Wide Web: http://boxes.thomasjensen.com/
|
||||
@ -44,6 +44,11 @@
|
||||
* Revision History:
|
||||
*
|
||||
* $Log: boxes.c,v $
|
||||
* Revision 1.38 2006/07/22 19:40:40 tsjensen
|
||||
* Applied patch by Christoph Dreyer to support unexpansion of leading tabs
|
||||
* Added ability to retain leading tabs in their original positions
|
||||
* Mending a box with -m now implies -k false
|
||||
*
|
||||
* Revision 1.37 2006/07/12 05:49:50 tsjensen
|
||||
* Updated email and web addresses in comment header etc.
|
||||
* Applied patch by Elmar Loos that adds -m option for mending a box
|
||||
@ -251,7 +256,7 @@ extern int optind, opterr, optopt; /* for getopt() */
|
||||
|
||||
|
||||
static const char rcsid_boxes_c[] =
|
||||
"$Id: boxes.c,v 1.37 2006/07/12 05:49:50 tsjensen Exp tsjensen $";
|
||||
"$Id: boxes.c,v 1.38 2006/07/22 19:40:40 tsjensen Exp tsjensen $";
|
||||
|
||||
|
||||
|
||||
@ -310,6 +315,34 @@ static void usage (FILE *st)
|
||||
|
||||
|
||||
|
||||
static void usage_short (FILE *st)
|
||||
/*
|
||||
* Print abbreviated usage information on stream st.
|
||||
*
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
*/
|
||||
{
|
||||
fprintf (st, "Usage: %s [options] [infile [outfile]]\n", PROJECT);
|
||||
fprintf (st, "Try `%s -h' for more information.\n", PROJECT);
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void usage_long (FILE *st)
|
||||
/*
|
||||
* Print usage information on stream st, including a header text.
|
||||
*
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
*/
|
||||
{
|
||||
fprintf (st, "%s - draws any kind of box around your text (and removes it)\n", PROJECT);
|
||||
fprintf (st, " (c) Thomas Jensen <boxes@thomasjensen.com>\n");
|
||||
fprintf (st, " Web page: http://boxes.thomasjensen.com/\n");
|
||||
usage (st);
|
||||
}
|
||||
|
||||
|
||||
|
||||
static int is_dir (const char *path)
|
||||
/*
|
||||
* Return true if file specified by path is a directory
|
||||
@ -529,6 +562,16 @@ static int process_commandline (int argc, char *argv[])
|
||||
opt.padding[idummy] = -1;
|
||||
yyin = stdin;
|
||||
|
||||
/*
|
||||
* Intercept '--help' and '-?' cases first, as they are not supported by getopt()
|
||||
*/
|
||||
if (argc >= 2 && argv[1] != NULL
|
||||
&& (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0))
|
||||
{
|
||||
usage_long (stdout);
|
||||
return 42;
|
||||
}
|
||||
|
||||
/*
|
||||
* Parse Command Line
|
||||
*/
|
||||
@ -672,10 +715,7 @@ static int process_commandline (int argc, char *argv[])
|
||||
/*
|
||||
* Display usage information and terminate
|
||||
*/
|
||||
printf ("%s - draws any kind of box around your text (and removes it)\n", PROJECT);
|
||||
printf (" (c) Thomas Jensen <boxes@thomasjensen.com>\n");
|
||||
printf (" Web page: http://boxes.thomasjensen.com/\n");
|
||||
usage (stdout);
|
||||
usage_long (stdout);
|
||||
return 42;
|
||||
|
||||
case 'i':
|
||||
@ -877,6 +917,7 @@ static int process_commandline (int argc, char *argv[])
|
||||
/*
|
||||
* Missing argument or illegal option - do nothing else
|
||||
*/
|
||||
usage_short (stderr);
|
||||
return 1;
|
||||
|
||||
case EOF:
|
||||
@ -906,7 +947,7 @@ static int process_commandline (int argc, char *argv[])
|
||||
else if (argv[optind+1] && argv[optind+2]) { /* illegal third file */
|
||||
fprintf (stderr, "%s: illegal parameter -- %s\n",
|
||||
PROJECT, argv[optind+2]);
|
||||
usage (stderr);
|
||||
usage_short (stderr);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user