Browse Source

Implements help & usage

Yann Weber 7 years ago
parent
commit
3ca964c51e
3 changed files with 53 additions and 1 deletions
  1. 20
    1
      src/include/ttail_init.h
  2. 2
    0
      src/main.c
  3. 31
    0
      src/ttail_init.c

+ 20
- 1
src/include/ttail_init.h View File

@@ -18,7 +18,7 @@
18 18
 	{"verbose", no_argument, 0, 'v'},\
19 19
 	{"re-prefix", required_argument, 0, 'r'},\
20 20
 	{"re-extended", no_argument, 0, 'E'},\
21
-	{"re-case-insensitive", no_argument, 0, 'I'},\
21
+	{"re-ignore-case", no_argument, 0, 'i'},\
22 22
 	{"prefix-len", required_argument, 0, 'p'},\
23 23
 	{"date-format", required_argument, 0, 'f'},\
24 24
 	{"date-min", required_argument, 0, 'd'},\
@@ -26,8 +26,27 @@
26 26
 	{"logfile", required_argument, 0, 'l'},\
27 27
 	{0,	0,	0,	0 }\
28 28
 }
29
+
30
+#define TTAIL_OPT_HELP {\
31
+	{"Augment the verbosity level",NULL},\
32
+	{"Matched part of logline will be stripped","REGEX"},\
33
+	{"Interpret REGEX as an extended regular expression (specified by \
34
+POSIX) ",NULL},\
35
+	{"Ignore  case  distinctions (specified by POSIX)",NULL},\
36
+	{"Indicate to strip a fixed len prefix","CHAR_COUNT"},\
37
+	{"Set the date format (see man strptime for supported date formats"\
38
+,"FORMAT"},\
39
+	{"Start to output loglines starting from this date","DATE"},\
40
+	{"Not implemented","DATE"},\
41
+	{"Indicate logfiles","FILE"},\
42
+	{"",NULL},\
43
+	{"",NULL}\
44
+}
29 45
 #define TTAIL_SHORT_OPT "r:EIp:f:d:l:m:"
30 46
 
47
+/**<! Print help & usage */
48
+void usage();
49
+
31 50
 /**@brief Parse cli arguments and return a ttail_t
32 51
  *@param int argc
33 52
  *@param char** argv

+ 2
- 0
src/main.c View File

@@ -12,10 +12,12 @@ int main(int argc, char **argv)
12 12
 	ttail_t *ttail;
13 13
 	if(!(ttail = ttail_init(argc, argv)))
14 14
 	{
15
+		usage();
15 16
 		return 1;
16 17
 	}
17 18
 	if(ttail_init_check(ttail) < 0)
18 19
 	{
20
+		usage();
19 21
 		ttail_free(ttail);
20 22
 		return 1;
21 23
 	}

+ 31
- 0
src/ttail_init.c View File

@@ -1,5 +1,36 @@
1 1
 #include "ttail_init.h"
2 2
 
3
+void usage()
4
+{
5
+	static struct option opts[] = TTAIL_LONG_OPT;
6
+	static char *help[][2] = TTAIL_OPT_HELP;
7
+	size_t i;
8
+	printf("Usage : ttail -d DATE [OPTIONS]\n");
9
+	printf("\t\n");
10
+	printf("Options list\n");
11
+	i=0;
12
+	while(opts[i].name)
13
+	{
14
+		printf("\t-%c, --%s", opts[i].val, opts[i].name);
15
+		if(opts[i].has_arg == required_argument)
16
+		{
17
+			printf("=%s\n",
18
+				help[i][1]?help[i][1]:"ARG");
19
+		}
20
+		else if(opts[i].has_arg == optional_argument)
21
+		{
22
+			printf("[=%s]\n",
23
+				help[i][1]?help[i][1]:"ARG");
24
+		}
25
+		else
26
+		{
27
+			printf("\n");
28
+		}
29
+		printf("\t\t%s\n\n", help[i][0]);
30
+		i++;
31
+	}
32
+}
33
+
3 34
 ttail_t *ttail_init(int argc, char **argv)
4 35
 {
5 36
 	ttail_t *res;

Loading…
Cancel
Save