12
12
#include <stdio.h>
13
13
#include <string.h>
14
14
#include <time.h>
15
+ #include <unistd.h> //for isatty
15
16
16
17
#define VERSION_TAG "v1.6.0"
17
18
#ifndef VERSION
18
- #define VERSION_PRETTY ""
19
+ #define VERSION_PRETTY ""
19
20
#else
20
- #define VERSION_PRETTY VERSION
21
+ #define VERSION_PRETTY VERSION
21
22
#endif
22
23
23
24
/* Help and usage */
24
- void print_version (char const * arg );
25
- void print_usage (char const * arg );
25
+ void print_version (char const * arg );
26
+ void print_usage (char const * arg );
26
27
27
28
/* getopt */
28
29
static int help_flag ;
@@ -47,11 +48,10 @@ static struct option long_options[] = {
47
48
{"sunos" , no_argument , 0 , 'p' },
48
49
{"list" , no_argument , & list_flag , 'l' },
49
50
{"render" , required_argument , 0 , 'r' },
50
- {"color" , no_argument , & color_flag , 'C' }, {0 , 0 , 0 , 0 }};
51
+ {"color" , no_argument , & color_flag , 'C' },
52
+ {0 , 0 , 0 , 0 }};
51
53
52
- int
53
- main (int argc , char * * argv )
54
- {
54
+ int main (int argc , char * * argv ) {
55
55
int c ;
56
56
int missing_arg ;
57
57
int option_index ;
@@ -79,12 +79,12 @@ main(int argc, char **argv)
79
79
break ;
80
80
81
81
case '?' :
82
- /* do not set help flag, only show getopt error */
82
+ /* do not set the help flag, only show getopt error */
83
83
/* help_flag = 1; */
84
84
break ;
85
85
86
86
case 'p' : {
87
- const char * platform_name = long_options [option_index ].name ;
87
+ const char * platform_name = long_options [option_index ].name ;
88
88
if (strcmp (platform_name , "platform" ) == 0 ) {
89
89
size_t len = strlen (optarg );
90
90
if (len > STRBUFSIZ )
@@ -121,7 +121,7 @@ main(int argc, char **argv)
121
121
check_localdate ();
122
122
}
123
123
124
- /* show help, if platform was supplied, but no further argument */
124
+ /* show help, if the platform was supplied, but no further argument */
125
125
missing_arg = (platform_flag && !list_flag && (optind == argc ));
126
126
if (help_flag || missing_arg ) {
127
127
print_usage (argv [0 ]);
@@ -166,7 +166,7 @@ main(int argc, char **argv)
166
166
sum = 0 ;
167
167
while (optind < argc ) {
168
168
len = strlen (argv [optind ]);
169
- if (sum + len >= 4096 )
169
+ if (sum + len >= 4096 )
170
170
exit (EXIT_FAILURE );
171
171
memcpy (buf + sum , argv [optind ], len );
172
172
memcpy (buf + sum + len , "-" , 1 );
@@ -192,22 +192,18 @@ main(int argc, char **argv)
192
192
return EXIT_SUCCESS ;
193
193
}
194
194
195
- void
196
- print_version (char const * arg )
197
- {
195
+ void print_version (char const * arg ) {
198
196
/* *INDENT-OFF* */
199
197
if (strcmp ("" , VERSION_PRETTY ) == 0 )
200
- fprintf (stdout , "%s %s\n" , arg , VERSION_TAG );
198
+ fprintf (stdout , "%s %s\n" , arg , VERSION_TAG );
201
199
else
202
- fprintf (stdout , "%s %s (%s)\n" , arg , VERSION_TAG , VERSION_PRETTY );;
200
+ fprintf (stdout , "%s %s (%s)\n" , arg , VERSION_TAG , VERSION_PRETTY );;
203
201
fprintf (stdout , "Copyright (C) 2016 Arvid Gerstmann\n" );
204
202
fprintf (stdout , "Source available at https://github.com/tldr-pages/tldr-c-client\n" );
205
203
/* *INDENT-ON* */
206
204
}
207
205
208
- void
209
- print_usage (char const * arg )
210
- {
206
+ void print_usage (char const * arg ) {
211
207
char const * out = "usage: %s [-v] [OPTION]... SEARCH\n\n" ;
212
208
213
209
/* *INDENT-OFF* */
@@ -229,4 +225,3 @@ print_usage(char const *arg)
229
225
fprintf (stdout , " %-20s %-30s\n" , "-C, --color" , "force color display" );
230
226
/* *INDENT-ON* */
231
227
}
232
-
0 commit comments