чување 6e345a4663b01382738bf27c07a336b8751f8cca
родитељ 07116f937288128054b60cd48ad3e88dbd586eaa
Аутор: Страхиња Радић <contact@strahinja.org>
Датум: Mon, 29 Apr 2024 18:01:14 +0200
Add -V
Signed-off-by: Страхиња Радић <contact@strahinja.org>
Diffstat:
измењених датотека: 2, додавања: 26(+), брисања: 15(-)
diff --git a/dtree.1.in b/dtree.1.in
@@ -9,10 +9,10 @@
.Nd Command line program to draw trees
.Sh SYNOPSIS
.Nm
-.Op Fl hv
+.Op Fl hVv
.Pp
.Nm
-.Oo Fl s Ar set Oc Op Ar file
+.Oo Fl s Ar set Oc Ar file
.Sh DESCRIPTION
.Nm
is a simple command line program which reads a number of lines and formats them
@@ -31,13 +31,10 @@ Any additional arguments after
.Ar file
will be ignored.
.
-.Ss Command line options
-.Bl -tag -width ".Nm Fl h" -offset indent
-.
-.It Nm Fl h
+.Bl -tag -width Ds
+.It Fl h
Prints usage information.
-.
-.It Nm Fl s Ar set
+.It Fl s Ar set
Selects the symbol set
.Ar set .
Allowed values for
@@ -50,8 +47,11 @@ are:
and
.Cm s
(single\-stroke set, default).
-.
-.It Nm Fl v
+.It Fl V
+Prints full version information: like
+.Fl v ,
+followed by copyright notice.
+.It Fl v
Prints version and commit date.
.El
.Sh EXAMPLES
diff --git a/dtree.c b/dtree.c
@@ -12,6 +12,12 @@
#include "version.h"
#define BUFSIZE 4096
+#define COPYRIGHT \
+ (" This program is licensed under the terms of GNU GPL v3" \
+ " or (at your option)\n" \
+ " any later version. Copyright (C) 2023-2024 Strahinya Radich.\n" \
+ " See the file LICENSE for exact copyright and license " \
+ "details.")
struct Node {
int level;
@@ -40,7 +46,7 @@ size_t strlcat(char* dst, const char* src, size_t dsize);
size_t strlcpy(char* dst, const char* src, size_t dsize);
int string_to_symbol_set(const char* s);
void usage(void);
-void version(void);
+void version(const int full);
void warning(char* fmt, ...);
/* clang-format off */
@@ -287,13 +293,15 @@ string_to_symbol_set(const char* s)
void
usage(void)
{
- printf("Usage: %s [-hv] [-s a|d|s] [file]\n", PROGRAMNAME);
+ printf("Usage: %s [-hVv] | [-s a|d|s] file\n", PROGRAMNAME);
}
void
-version(void)
+version(const int full)
{
printf("%s %s, committed on %s\n", PROGRAMNAME, VERSION, DATE);
+ if (full)
+ puts(COPYRIGHT);
}
void
@@ -321,7 +329,7 @@ main(int argc, char** argv)
}
#endif
- if ((ch = getopt(argc, argv, ":hs:v")) != -1)
+ if ((ch = getopt(argc, argv, ":hs:Vv")) != -1)
{
switch (ch)
{
@@ -333,8 +341,11 @@ main(int argc, char** argv)
exit(error(1, "Invalid symbol set: '%s'",
optarg));
break;
+ case 'V':
+ version(1);
+ exit(0);
case 'v':
- version();
+ version(0);
exit(0);
case ':':
exit(error(1, "Argument expected for '-%c'", optopt));