indent(1): add --version option

There exist multi-platform programs that check indent's version in order to
know what they can expect from it. GNU indent provides that via --version,
so implement the same option here.
This commit is contained in:
Piotr Pawel Stefaniak 2018-06-04 21:05:56 +00:00
parent 88b24a62d1
commit d0f86f663f
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=334636
2 changed files with 14 additions and 1 deletions

View File

@ -58,6 +58,8 @@ __FBSDID("$FreeBSD$");
#include "indent_globs.h"
#include "indent.h"
#define INDENT_VERSION "2.0"
/* profile types */
#define PRO_SPECIAL 1 /* special case */
#define PRO_BOOL 2 /* boolean */
@ -76,6 +78,7 @@ __FBSDID("$FreeBSD$");
static void scan_profile(FILE *);
#define KEY_FILE 5 /* only used for args */
#define VERSION 6 /* only used for args */
const char *option_source = "?";
@ -97,6 +100,7 @@ struct pro {
{"T", PRO_SPECIAL, 0, KEY, 0},
{"U", PRO_SPECIAL, 0, KEY_FILE, 0},
{"-version", PRO_SPECIAL, 0, VERSION, 0},
{"P", PRO_SPECIAL, 0, IGN, 0},
{"bacc", PRO_BOOL, false, ON, &blanklines_around_conditional_compilation},
{"badp", PRO_BOOL, false, ON, &blanklines_after_declarations_at_proctop},
@ -302,6 +306,10 @@ set_option(char *arg)
add_typedefs_from_file(param_start);
break;
case VERSION:
printf("FreeBSD indent %s\n", INDENT_VERSION);
exit(0);
default:
errx(1, "set_option: internal error: p_special %d", p->p_special);
}

View File

@ -30,7 +30,7 @@
.\" @(#)indent.1 8.1 (Berkeley) 7/1/93
.\" $FreeBSD$
.\"
.Dd August 7, 2017
.Dd June 4, 2018
.Dt INDENT 1
.Os
.Sh NAME
@ -90,6 +90,7 @@
.Op Fl U Ns Ar file
.Op Fl ut | Fl nut
.Op Fl v | Fl \&nv
.Op Fl -version
.Sh DESCRIPTION
The
.Nm
@ -491,6 +492,10 @@ reports when it splits one line of input into two or more lines of output,
and gives some size statistics at completion.
The default is
.Fl \&nv .
.It Fl -version
Causes
.Nm
to print its version number and exit.
.El
.Pp
You may set up your own `profile' of defaults to