16
16
#include <sys/stat.h>
17
17
#endif
18
18
#include "csloc.h"
19
- #define VERSION_MAJOR "8"
20
- #define VERSION_MINOR "0 "
19
+ #define VERSION_MINOR "8"
20
+ #define VERSION_PATCH "1 "
21
21
int main (int argl ,char * argv [])
22
22
{
23
23
if (argl == 1 )
24
24
{
25
25
help :
26
- printf ("csloc version 1.%s.%s\n" ,VERSION_MAJOR , VERSION_MINOR );
26
+ printf ("csloc version 1.%s.%s\n" ,VERSION_MINOR , VERSION_PATCH );
27
27
printf ("Usage: %s [OPTIONS...] FILES... [-x] [EXTENSIONS...]\nCommand line options...\n\n" , argv [0 ]);
28
- puts ("-o to write output to a file instead of stdout" );
28
+ puts ("If a file starts with '-', escape it with a \\, otherwise the first \\ of an argument is ignored." );
29
+ puts ("-o to write output to a file instead of stdout, the next argument MUST be that file." );
29
30
puts ("-e to alternate colours in -s mode, making output easier to read." );
30
31
puts ("-n to list the number before the path in -qs mode." );
31
32
puts ("-r to sort least to greatest." );
@@ -68,62 +69,14 @@ int main(int argl,char*argv[])
68
69
if (strchr (argv [i ], 'x' ) != NULL )
69
70
{
70
71
ext = 1 , fel = argl - i - 1 ;
71
- extbegin = i + 1 ;
72
+ extbegin = i ;
72
73
fexts = malloc (sizeof (const char * ) * fel );
73
74
}
74
75
}
75
76
}
76
77
for (int i = 1 ; i < extbegin ; ++ i )
77
78
{
78
- if (argv [i ][0 ] == '-' )
79
- {
80
- {
81
- for (const char * it = argv [i ] + 1 ; * it != '\0' ; ++ it )
82
- {
83
- currop = * it ;
84
- switch (currop )
85
- {
86
- case 'o' :
87
- ofile = 1 ;
88
- break ;
89
- case 'e' :
90
- colours = 1 ;
91
- break ;
92
- case 'n' :
93
- numfirst = 1 ;
94
- break ;
95
- case 'r' :
96
- options |= CSLOC_RSORT ;
97
- break ;
98
- case 'f' :
99
- options |= CSLOC_FSIZE ;
100
- break ;
101
- case 't' :
102
- options |= CSLOC_SORT ;
103
- break ;
104
- case 's' :
105
- options |= CSLOC_SIF ;
106
- break ;
107
- case 'h' :
108
- options |= CSLOC_IGNDOT ;
109
- break ;
110
- case 'q' :
111
- options |= CSLOC_QUIET ;
112
- break ;
113
- case 'c' :
114
- cp = it + 1 ;
115
- cr = strtoul (cp + 1 , & numend , 10 );
116
- it = numend - 1 ;
117
- break ;
118
- case 'x' :
119
- break ;
120
- default :
121
- fprintf (stderr , "Unrecognized option -%c, it will be ignored.\n" , currop );
122
- }
123
- }
124
- }
125
- }
126
- else if (ofile )
79
+ if (ofile )
127
80
{
128
81
ofile = 0 ;
129
82
ofn = argv [i ];
@@ -134,9 +87,55 @@ int main(int argl,char*argv[])
134
87
fprintf (stderr , "File %s could not be opened for writing, check permissions.\n" , ofn );
135
88
}
136
89
}
90
+ else if (argv [i ][0 ] == '-' )
91
+ {
92
+ for (const char * it = argv [i ] + 1 ; * it != '\0' ; ++ it )
93
+ {
94
+ currop = * it ;
95
+ switch (currop )
96
+ {
97
+ case 'o' :
98
+ ofile = 1 ;
99
+ break ;
100
+ case 'e' :
101
+ colours = 1 ;
102
+ break ;
103
+ case 'n' :
104
+ numfirst = 1 ;
105
+ break ;
106
+ case 'r' :
107
+ options |= CSLOC_RSORT ;
108
+ break ;
109
+ case 'f' :
110
+ options |= CSLOC_FSIZE ;
111
+ break ;
112
+ case 't' :
113
+ options |= CSLOC_SORT ;
114
+ break ;
115
+ case 's' :
116
+ options |= CSLOC_SIF ;
117
+ break ;
118
+ case 'h' :
119
+ options |= CSLOC_IGNDOT ;
120
+ break ;
121
+ case 'q' :
122
+ options |= CSLOC_QUIET ;
123
+ break ;
124
+ case 'c' :
125
+ cp = it + 1 ;
126
+ cr = strtoul (cp + 1 , & numend , 10 );
127
+ it = numend - 1 ;
128
+ break ;
129
+ default :
130
+ fprintf (stderr , "Unrecognized option -%c, it will be ignored.\n" , currop );
131
+ }
132
+ }
133
+ }
137
134
else
138
135
{
139
136
dir = argv [i ];
137
+ if (* dir == '\\' )
138
+ ++ dir ;
140
139
++ dircnt ;
141
140
#ifdef _WIN32
142
141
int isdir = GetFileAttributesA (dir ) & FILE_ATTRIBUTE_DIRECTORY ;
0 commit comments