Skip to content

Commit d1d7ab1

Browse files
Possible to escape -.
1 parent b97c1ef commit d1d7ab1

File tree

1 file changed

+53
-54
lines changed

1 file changed

+53
-54
lines changed

main.c

Lines changed: 53 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,17 @@
1616
#include<sys/stat.h>
1717
#endif
1818
#include"csloc.h"
19-
#define VERSION_MAJOR "8"
20-
#define VERSION_MINOR "0"
19+
#define VERSION_MINOR "8"
20+
#define VERSION_PATCH "1"
2121
int main(int argl,char*argv[])
2222
{
2323
if(argl==1)
2424
{
2525
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);
2727
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.");
2930
puts("-e to alternate colours in -s mode, making output easier to read.");
3031
puts("-n to list the number before the path in -qs mode.");
3132
puts("-r to sort least to greatest.");
@@ -68,62 +69,14 @@ int main(int argl,char*argv[])
6869
if(strchr(argv[i], 'x') != NULL)
6970
{
7071
ext = 1, fel = argl - i - 1;
71-
extbegin = i + 1;
72+
extbegin = i;
7273
fexts = malloc(sizeof(const char*) * fel);
7374
}
7475
}
7576
}
7677
for(int i = 1; i < extbegin; ++i)
7778
{
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)
12780
{
12881
ofile = 0;
12982
ofn = argv[i];
@@ -134,9 +87,55 @@ int main(int argl,char*argv[])
13487
fprintf(stderr, "File %s could not be opened for writing, check permissions.\n", ofn);
13588
}
13689
}
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+
}
137134
else
138135
{
139136
dir = argv[i];
137+
if(*dir == '\\')
138+
++dir;
140139
++dircnt;
141140
#ifdef _WIN32
142141
int isdir = GetFileAttributesA(dir) & FILE_ATTRIBUTE_DIRECTORY;

0 commit comments

Comments
 (0)