Repository navigation
Expand file tree
/
Copy pathcmd_line.cpp
More file actions
306 lines (276 loc) · 9.63 KB
/
Copy pathcmd_line.cpp
File metadata and controls
306 lines (276 loc) · 9.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
//*****************************************************************
// CMD_LINE.CPP - NDIR command_line parsing
//*****************************************************************
#include <windows.h>
#ifdef _lint
#include <stdlib.h>
#endif
#include <ctype.h>
#include <tchar.h>
#include "common.h"
#include "ndir32.h"
#include "conio32.h" // is_redirected()
// static TCHAR const topchar = _T(0xD1) ; /* � */
// static TCHAR const bottomchar = _T(0xCF) ; /* � */
// static TCHAR const vlinechar = _T(0xB3) ; /* � */
// static TCHAR const xlinechar = _T(0xD8) ; /* � */
// static TCHAR const dvlinechar = _T(0xCD) ; /* � */
static TCHAR const crosschar = _T('+') ; /* + */
static TCHAR const altvlinechar = _T('|') ; /* | */
static TCHAR const altdvlchar = _T('=') ; /* = */
//*************************************************************
// Convert command-line switches into flags
//*************************************************************
static int update_switches (TCHAR *argstr)
{
int slen = 1;
TCHAR inchar = *argstr++;
switch (inchar) {
case 'a':
if (*argstr == '1') {
n.long_attr = 1 ;
n.show_all = 1;
argstr++;
slen++ ;
} else {
n.show_all ^= 1;
}
break;
case 'b': n.batch ^= 1; break;
case 'c': n.clear ^= 1; break;
case 'd':
if (*argstr == '2') {
n.tree = eTreeForm::DIR_FILE_COUNTS;
argstr++;
}
else if (*argstr == '3') {
n.tree = eTreeForm::MIXED_COUNT_SIZE;
argstr++;
}
else if (*argstr == '4') {
n.tree = eTreeForm::MAX_FNAME_LEN;
argstr++;
}
else {
n.tree = eTreeForm::DIR_FILE_SIZES;
}
break;
case 'e': n.sort = 0; break;
case 'f': n.files_only ^= 1; break;
case 'g': n.dir_first ^= 1; break;
case 'h': n.horz = (n.horz == eFileLayout::FL_VERT)
? eFileLayout::FL_HORZ
: eFileLayout::FL_VERT ;
break;
case 'i':
if (*argstr == 'i') {
n.drive_summary = DSUMMARY_USED;
argstr++;
slen++ ;
} else {
n.drive_summary = DSUMMARY_FREE;
}
break;
// case 'j': n.low_ascii ^= 1; break;
// case 'k': n.color ^= 1; break;
// V2.62, 01/08/24 - short-filename support removed
// case 'l': n.lfn_off ^= 1; break; // toggle long_filename flag
case 'm':
n.minimize ^= 1;
break;
case 'n':
n.sort = 1;
break;
case 'o':
if (*argstr == '1')
n.fdate_option = FDATE_LAST_ACCESS;
else if (*argstr == '2')
n.fdate_option = FDATE_CREATE_TIME;
else
n.fdate_option = FDATE_LAST_WRITE;
slen = 2;
break;
case 'p': n.pause ^= 1; break;
case 'q': n.horz = eFileLayout::FL_QWISE; break;
case 'r': n.reverse ^= 1; break;
case 's': n.sort = 2; break;
case 'S': // our first case-sensitive switch!!
// check to see if special display options have been selected:
// uchar size_display ; // 0=bytes/normal, 1=KB, 2=MB
switch (*argstr) {
case '1': n.size_display = 1 ; break ;
case '2': n.size_display = 2 ; break ;
default: n.size_display = 0 ; break ;
}
argstr++;
slen++ ;
break;
case 't': n.sort = 3; break;
// case 'u': n.ucase ^= 1; break;
case 'v': n.info = 1; break;
case 'w': n.showSHRfiles ^= 1; break;
case 'x': n.exec_only ^= 1; break;
case 'y': n.tree_no_git ^= 1; break;
case 'z': n.sort = 4; break;
case '1': n.format = 0; break;
case '2': n.format = 1; break;
case '4': n.format = 2; break;
case '6': n.format = 3; break;
case '3': n.format = 5; break;
// case '5': n.ega_keep ^= 1; break;
case ',':
n.tree_short = 1;
tree_level_limit++ ;
break;
case '?':
n.help = 1;
break;
case '[': // accept this with or without preceding '-'
batch_set_left_str(argstr);
slen = 0 ; // tell argument-parsing function to skip rest of this argument
break;
case ']': // accept this with or without preceding '-'
batch_set_right_str(argstr);
slen = 0 ; // tell argument-parsing function to skip rest of this argument
break;
default:
break; // make lint happy
} /* end SWITCH */
return slen; //lint !e438 argstr
}
//**********************************************************
void parse_command_string (TCHAR *cmdstr)
{
TCHAR *extptr;
int slen;
switch (*cmdstr) {
case '-':
case '/':
cmdstr++; // skip the switch char
while (LOOP_FOREVER) {
if (*cmdstr == CR || *cmdstr == LF || *cmdstr == 0)
break;
slen = update_switches (cmdstr);
if (slen == 0) {
break ;
}
cmdstr += slen;
}
break;
case '[': // accept this with or without preceding '-'
cmdstr++; // skip the switch char
batch_set_left_str(cmdstr);
break;
case ']': // accept this with or without preceding '-'
cmdstr++; // skip the switch char
batch_set_right_str(cmdstr);
break;
case '!':
cmdstr++; // skip the switch char
_tcscpy (tempstr, cmdstr);
// process exclusion extentions...
extptr = _tcschr (tempstr, '.');
// why worry about length of extension??
// if (extptr != 0 && _tcslen (extptr) <= 4)
if (extptr != 0) {
update_exclusion_list(extptr) ;
}
break;
default:
insert_target_filespec (cmdstr);
break;
} // switch (*cmdstr)
}
//**********************************************************
void parse_command_args (int startIdx, int argc, TCHAR **argv)
{
TCHAR *argvptr, *spcptr;
// see if we have an environment variable to deal with
if (startIdx == 0) {
argvptr = argv[0];
while (LOOP_FOREVER) {
spcptr = _tcschr (argvptr, ' ');
if (spcptr == 0) {
parse_command_string (argvptr);
break;
}
// fall thru here if space is found
*spcptr++ = 0; // NULL-term first string, point to next string
parse_command_string (argvptr);
argvptr = spcptr;
}
startIdx = 1;
}
// deal with normal command-line arguments
for (int j = startIdx; j < argc; j++) {
// fix an obscure bug under win32 and 4DOS7;
// for some reason, "/?" is getting changed to "/~" ...
// argvptr = argv[j];
// if (_tcscmp(argvptr, _T("/~")) == 0) {
// *(argvptr+1) = _T('/') ;
// }
parse_command_string (argv[j]);
}
}
//************************************************************
// Test for, and correct, inconsistent flags
//************************************************************
void verify_flags (void)
{
if (is_redirected ()) {
n.color = 0 ;
}
//******************************************************
// at this point, if exec_only is set, stuff the
// executable filespec into target[]
//******************************************************
// The drawback to this technique is that the user
// cannot apply -x to multiple drives simultaneously.
//******************************************************
if (n.exec_only) {
insert_target_filespec (_T("*.exe"));
insert_target_filespec (_T("*.com"));
insert_target_filespec (_T("*.bat"));
insert_target_filespec (_T("*.btm"));
insert_target_filespec (_T("*.cmd"));
}
/* Set 'dir tree' conditions */
if (n.tree != eTreeForm::TREE_UNUSED ||
n.drive_summary > DSUMMARY_NONE) {
n.minimize = 0;
}
//****************************************************
// fix up the format specifiers
//****************************************************
// tree view doesn't even *use* columns, so this is not relevant
if (n.tree != eTreeForm::TREE_UNUSED) {
n.exec_only = 0;
columns = 0;
}
else if (n.horz == eFileLayout::FL_QWISE) {
columns = 1;
n.sort = 0; // force sort-by-extension
n.reverse = 0;
}
else {
switch (n.format) {
case 0: columns = 1; break;
case 1: columns = 2; break;
case 2: columns = 4; break;
case 3: columns = 6; break;
case 5: columns = 3; break;
default:
n.format = 2;
columns = 4;
break;
}
}
//******************************************************
// Initialize line-drawing variables
// 03/17/25 - as part of Unicode conversion,
// just use low ASCII in all cases
//******************************************************
tline = crosschar;
vline = altvlinechar;
dline = altdvlchar;
}