Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wine-cw
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wine
wine-cw
Commits
a8828950
Commit
a8828950
authored
Apr 29, 2002
by
Jason Edmeades
Committed by
Alexandre Julliard
Apr 29, 2002
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- Support for dir /w and /b flags
- Fixed a couple of unclosed FindFirst/FindNext pairs
parent
8ad2676d
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
126 additions
and
6 deletions
+126
-6
builtins.c
programs/wcmd/builtins.c
+2
-0
directory.c
programs/wcmd/directory.c
+124
-6
No files found.
programs/wcmd/builtins.c
View file @
a8828950
...
@@ -172,6 +172,7 @@ char *p;
...
@@ -172,6 +172,7 @@ char *p;
if
((
strchr
(
param1
,
'*'
)
==
NULL
)
&&
(
strchr
(
param1
,
'?'
)
==
NULL
)
if
((
strchr
(
param1
,
'*'
)
==
NULL
)
&&
(
strchr
(
param1
,
'?'
)
==
NULL
)
&&
(
!
recurse
)
&&
(
fd
.
dwFileAttributes
&
FILE_ATTRIBUTE_DIRECTORY
))
{
&&
(
!
recurse
)
&&
(
fd
.
dwFileAttributes
&
FILE_ATTRIBUTE_DIRECTORY
))
{
strcat
(
param1
,
"
\\
*"
);
strcat
(
param1
,
"
\\
*"
);
FindClose
(
hff
);
WCMD_delete
(
1
);
WCMD_delete
(
1
);
return
;
return
;
}
}
...
@@ -192,6 +193,7 @@ char *p;
...
@@ -192,6 +193,7 @@ char *p;
}
}
else
{
else
{
if
(
!
DeleteFile
(
param1
))
WCMD_print_error
();
if
(
!
DeleteFile
(
param1
))
WCMD_print_error
();
FindClose
(
hff
);
}
}
}
}
...
...
programs/wcmd/directory.c
View file @
a8828950
...
@@ -41,7 +41,8 @@ extern int echo_mode;
...
@@ -41,7 +41,8 @@ extern int echo_mode;
extern
char
quals
[
MAX_PATH
],
param1
[
MAX_PATH
],
param2
[
MAX_PATH
];
extern
char
quals
[
MAX_PATH
],
param1
[
MAX_PATH
],
param2
[
MAX_PATH
];
extern
DWORD
errorlevel
;
extern
DWORD
errorlevel
;
int
file_total
,
dir_total
,
line_count
,
page_mode
,
recurse
;
int
file_total
,
dir_total
,
line_count
,
page_mode
,
recurse
,
wide
,
bare
,
max_width
;
__int64
byte_total
;
__int64
byte_total
;
/*****************************************************************************
/*****************************************************************************
...
@@ -56,12 +57,26 @@ void WCMD_directory () {
...
@@ -56,12 +57,26 @@ void WCMD_directory () {
char
path
[
MAX_PATH
],
drive
[
8
];
char
path
[
MAX_PATH
],
drive
[
8
];
int
status
;
int
status
;
ULARGE_INTEGER
avail
,
total
,
free
;
ULARGE_INTEGER
avail
,
total
,
free
;
CONSOLE_SCREEN_BUFFER_INFO
consoleInfo
;
line_count
=
5
;
line_count
=
5
;
byte_total
=
0
;
byte_total
=
0
;
file_total
=
dir_total
=
0
;
file_total
=
dir_total
=
0
;
/* Handle args */
page_mode
=
(
strstr
(
quals
,
"/P"
)
!=
NULL
);
page_mode
=
(
strstr
(
quals
,
"/P"
)
!=
NULL
);
recurse
=
(
strstr
(
quals
,
"/S"
)
!=
NULL
);
recurse
=
(
strstr
(
quals
,
"/S"
)
!=
NULL
);
wide
=
(
strstr
(
quals
,
"/W"
)
!=
NULL
);
bare
=
(
strstr
(
quals
,
"/B"
)
!=
NULL
);
/* Handle conflicting args and initialization */
if
(
bare
)
wide
=
FALSE
;
if
(
wide
)
{
GetConsoleScreenBufferInfo
(
GetStdHandle
(
STD_OUTPUT_HANDLE
),
&
consoleInfo
);
max_width
=
consoleInfo
.
dwSize
.
X
;
}
if
(
param1
[
0
]
==
'\0'
)
strcpy
(
param1
,
"."
);
if
(
param1
[
0
]
==
'\0'
)
strcpy
(
param1
,
"."
);
status
=
GetFullPathName
(
param1
,
sizeof
(
path
),
path
,
NULL
);
status
=
GetFullPathName
(
param1
,
sizeof
(
path
),
path
,
NULL
);
if
(
!
status
)
{
if
(
!
status
)
{
...
@@ -69,17 +84,27 @@ ULARGE_INTEGER avail, total, free;
...
@@ -69,17 +84,27 @@ ULARGE_INTEGER avail, total, free;
return
;
return
;
}
}
lstrcpyn
(
drive
,
path
,
3
);
lstrcpyn
(
drive
,
path
,
3
);
if
(
!
bare
)
{
status
=
WCMD_volume
(
0
,
drive
);
status
=
WCMD_volume
(
0
,
drive
);
if
(
!
status
)
{
if
(
!
status
)
{
return
;
return
;
}
}
}
WCMD_list_directory
(
path
,
0
);
WCMD_list_directory
(
path
,
0
);
lstrcpyn
(
drive
,
path
,
4
);
lstrcpyn
(
drive
,
path
,
4
);
GetDiskFreeSpaceEx
(
drive
,
&
avail
,
&
total
,
&
free
);
GetDiskFreeSpaceEx
(
drive
,
&
avail
,
&
total
,
&
free
);
WCMD_output
(
" %18s bytes free
\n\n
"
,
WCMD_filesize64
(
free
.
QuadPart
));
if
(
!
bare
)
{
if
(
recurse
)
{
if
(
recurse
)
{
WCMD_output
(
"Total files listed:
\n
%8d files%25s bytes
\n
%8d directories
\n\n
"
,
WCMD_output
(
"
\n\n
Total files listed:
\n
%8d files%25s bytes
\n
"
,
file_total
,
WCMD_filesize64
(
byte_total
),
dir_total
);
file_total
,
WCMD_filesize64
(
byte_total
));
WCMD_output
(
"%8d directories %18s bytes free
\n\n
"
,
dir_total
,
WCMD_filesize64
(
free
.
QuadPart
));
}
else
{
WCMD_output
(
" %18s bytes free
\n\n
"
,
WCMD_filesize64
(
free
.
QuadPart
));
}
}
}
}
}
...
@@ -100,18 +125,22 @@ void WCMD_list_directory (char *search_path, int level) {
...
@@ -100,18 +125,22 @@ void WCMD_list_directory (char *search_path, int level) {
char
string
[
1024
],
datestring
[
32
],
timestring
[
32
];
char
string
[
1024
],
datestring
[
32
],
timestring
[
32
];
char
mem_err
[]
=
"Memory Allocation Error"
;
char
mem_err
[]
=
"Memory Allocation Error"
;
char
*
p
;
char
*
p
;
char
real_path
[
MAX_PATH
];
DWORD
count
;
DWORD
count
;
WIN32_FIND_DATA
*
fd
;
WIN32_FIND_DATA
*
fd
;
FILETIME
ft
;
FILETIME
ft
;
SYSTEMTIME
st
;
SYSTEMTIME
st
;
HANDLE
hff
;
HANDLE
hff
;
int
status
,
dir_count
,
file_count
,
entry_count
,
i
;
int
status
,
dir_count
,
file_count
,
entry_count
,
i
,
widest
,
linesout
,
cur_width
,
tmp_width
;
ULARGE_INTEGER
byte_count
,
file_size
;
ULARGE_INTEGER
byte_count
,
file_size
;
dir_count
=
0
;
dir_count
=
0
;
file_count
=
0
;
file_count
=
0
;
entry_count
=
0
;
entry_count
=
0
;
byte_count
.
QuadPart
=
0
;
byte_count
.
QuadPart
=
0
;
widest
=
0
;
linesout
=
0
;
cur_width
=
0
;
/*
/*
* If the path supplied does not include a wildcard, and the endpoint of the
* If the path supplied does not include a wildcard, and the endpoint of the
...
@@ -131,6 +160,12 @@ ULARGE_INTEGER byte_count, file_size;
...
@@ -131,6 +160,12 @@ ULARGE_INTEGER byte_count, file_size;
}
}
}
}
/* Work out the actual current directory name */
p
=
strrchr
(
search_path
,
'\\'
);
memset
(
real_path
,
0x00
,
sizeof
(
real_path
));
lstrcpyn
(
real_path
,
search_path
,
(
p
-
search_path
+
2
));
/* Load all files into an in memory structure */
fd
=
malloc
(
sizeof
(
WIN32_FIND_DATA
));
fd
=
malloc
(
sizeof
(
WIN32_FIND_DATA
));
hff
=
FindFirstFile
(
search_path
,
fd
);
hff
=
FindFirstFile
(
search_path
,
fd
);
if
(
hff
==
INVALID_HANDLE_VALUE
)
{
if
(
hff
==
INVALID_HANDLE_VALUE
)
{
...
@@ -141,6 +176,14 @@ ULARGE_INTEGER byte_count, file_size;
...
@@ -141,6 +176,14 @@ ULARGE_INTEGER byte_count, file_size;
}
}
do
{
do
{
entry_count
++
;
entry_count
++
;
/* Keep running track of longest filename for wide output */
if
(
wide
)
{
int
tmpLen
=
strlen
((
fd
+
(
entry_count
-
1
))
->
cFileName
)
+
3
;
if
((
fd
+
(
entry_count
-
1
))
->
dwFileAttributes
&
FILE_ATTRIBUTE_DIRECTORY
)
tmpLen
=
tmpLen
+
2
;
if
(
tmpLen
>
widest
)
widest
=
tmpLen
;
}
fd
=
realloc
(
fd
,
(
entry_count
+
1
)
*
sizeof
(
WIN32_FIND_DATA
));
fd
=
realloc
(
fd
,
(
entry_count
+
1
)
*
sizeof
(
WIN32_FIND_DATA
));
if
(
fd
==
NULL
)
{
if
(
fd
==
NULL
)
{
FindClose
(
hff
);
FindClose
(
hff
);
...
@@ -149,9 +192,14 @@ ULARGE_INTEGER byte_count, file_size;
...
@@ -149,9 +192,14 @@ ULARGE_INTEGER byte_count, file_size;
}
}
}
while
(
FindNextFile
(
hff
,
(
fd
+
entry_count
))
!=
0
);
}
while
(
FindNextFile
(
hff
,
(
fd
+
entry_count
))
!=
0
);
FindClose
(
hff
);
FindClose
(
hff
);
/* Sort the list of files */
qsort
(
fd
,
entry_count
,
sizeof
(
WIN32_FIND_DATA
),
WCMD_dir_sort
);
qsort
(
fd
,
entry_count
,
sizeof
(
WIN32_FIND_DATA
),
WCMD_dir_sort
);
/* Output the results */
if
(
!
bare
)
{
if
(
level
!=
0
)
WCMD_output
(
"
\n\n
"
);
if
(
level
!=
0
)
WCMD_output
(
"
\n\n
"
);
WCMD_output
(
"Directory of %s
\n\n
"
,
search
_path
);
WCMD_output
(
"Directory of %s
\n\n
"
,
real
_path
);
if
(
page_mode
)
{
if
(
page_mode
)
{
line_count
+=
2
;
line_count
+=
2
;
if
(
line_count
>
23
)
{
if
(
line_count
>
23
)
{
...
@@ -160,6 +208,8 @@ ULARGE_INTEGER byte_count, file_size;
...
@@ -160,6 +208,8 @@ ULARGE_INTEGER byte_count, file_size;
ReadFile
(
GetStdHandle
(
STD_INPUT_HANDLE
),
string
,
sizeof
(
string
),
&
count
,
NULL
);
ReadFile
(
GetStdHandle
(
STD_INPUT_HANDLE
),
string
,
sizeof
(
string
),
&
count
,
NULL
);
}
}
}
}
}
for
(
i
=
0
;
i
<
entry_count
;
i
++
)
{
for
(
i
=
0
;
i
<
entry_count
;
i
++
)
{
FileTimeToLocalFileTime
(
&
(
fd
+
i
)
->
ftLastWriteTime
,
&
ft
);
FileTimeToLocalFileTime
(
&
(
fd
+
i
)
->
ftLastWriteTime
,
&
ft
);
FileTimeToSystemTime
(
&
ft
,
&
st
);
FileTimeToSystemTime
(
&
ft
,
&
st
);
...
@@ -167,10 +217,53 @@ ULARGE_INTEGER byte_count, file_size;
...
@@ -167,10 +217,53 @@ ULARGE_INTEGER byte_count, file_size;
sizeof
(
datestring
));
sizeof
(
datestring
));
GetTimeFormat
(
0
,
TIME_NOSECONDS
,
&
st
,
GetTimeFormat
(
0
,
TIME_NOSECONDS
,
&
st
,
NULL
,
timestring
,
sizeof
(
timestring
));
NULL
,
timestring
,
sizeof
(
timestring
));
if
(
wide
)
{
tmp_width
=
cur_width
;
if
((
fd
+
i
)
->
dwFileAttributes
&
FILE_ATTRIBUTE_DIRECTORY
)
{
if
((
fd
+
i
)
->
dwFileAttributes
&
FILE_ATTRIBUTE_DIRECTORY
)
{
WCMD_output
(
"["
);
WCMD_output
(
"%s"
,
(
fd
+
i
)
->
cFileName
);
WCMD_output
(
"]"
);
dir_count
++
;
tmp_width
=
tmp_width
+
strlen
((
fd
+
i
)
->
cFileName
)
+
2
;
}
else
{
WCMD_output
(
"%s"
,
(
fd
+
i
)
->
cFileName
);
tmp_width
=
tmp_width
+
strlen
((
fd
+
i
)
->
cFileName
)
;
file_count
++
;
#ifndef NONAMELESSSTRUCT
file_size
.
LowPart
=
(
fd
+
i
)
->
nFileSizeLow
;
file_size
.
HighPart
=
(
fd
+
i
)
->
nFileSizeHigh
;
#else
file_size
.
s
.
LowPart
=
(
fd
+
i
)
->
nFileSizeLow
;
file_size
.
s
.
HighPart
=
(
fd
+
i
)
->
nFileSizeHigh
;
#endif
byte_count
.
QuadPart
+=
file_size
.
QuadPart
;
}
cur_width
=
cur_width
+
widest
;
if
((
cur_width
+
widest
)
>
max_width
)
{
WCMD_output
(
"
\n
"
);
cur_width
=
0
;
linesout
++
;
}
else
{
WCMD_output
(
"%*.s"
,
(
tmp_width
-
cur_width
)
,
""
);
}
}
else
if
((
fd
+
i
)
->
dwFileAttributes
&
FILE_ATTRIBUTE_DIRECTORY
)
{
dir_count
++
;
dir_count
++
;
if
(
!
bare
)
{
WCMD_output
(
"%8s %8s <DIR> %s
\n
"
,
WCMD_output
(
"%8s %8s <DIR> %s
\n
"
,
datestring
,
timestring
,
(
fd
+
i
)
->
cFileName
);
datestring
,
timestring
,
(
fd
+
i
)
->
cFileName
);
linesout
++
;
}
else
{
if
(
!
((
strcmp
((
fd
+
i
)
->
cFileName
,
"."
)
==
0
)
||
(
strcmp
((
fd
+
i
)
->
cFileName
,
".."
)
==
0
)))
{
WCMD_output
(
"%s%s
\n
"
,
recurse
?
real_path
:
""
,
(
fd
+
i
)
->
cFileName
);
linesout
++
;
}
}
}
}
else
{
else
{
file_count
++
;
file_count
++
;
...
@@ -182,11 +275,30 @@ ULARGE_INTEGER byte_count, file_size;
...
@@ -182,11 +275,30 @@ ULARGE_INTEGER byte_count, file_size;
file_size
.
s
.
HighPart
=
(
fd
+
i
)
->
nFileSizeHigh
;
file_size
.
s
.
HighPart
=
(
fd
+
i
)
->
nFileSizeHigh
;
#endif
#endif
byte_count
.
QuadPart
+=
file_size
.
QuadPart
;
byte_count
.
QuadPart
+=
file_size
.
QuadPart
;
if
(
!
bare
)
{
WCMD_output
(
"%8s %8s %10s %s
\n
"
,
WCMD_output
(
"%8s %8s %10s %s
\n
"
,
datestring
,
timestring
,
datestring
,
timestring
,
WCMD_filesize64
(
file_size
.
QuadPart
),
(
fd
+
i
)
->
cFileName
);
WCMD_filesize64
(
file_size
.
QuadPart
),
(
fd
+
i
)
->
cFileName
);
linesout
++
;
}
else
{
WCMD_output
(
"%s%s
\n
"
,
recurse
?
real_path
:
""
,
(
fd
+
i
)
->
cFileName
);
linesout
++
;
}
}
}
if
(
page_mode
)
{
if
(
page_mode
)
{
line_count
=
line_count
+
linesout
;
linesout
=
0
;
if
(
line_count
>
23
)
{
line_count
=
0
;
WCMD_output
(
anykey
);
ReadFile
(
GetStdHandle
(
STD_INPUT_HANDLE
),
string
,
sizeof
(
string
),
&
count
,
NULL
);
}
}
}
if
(
wide
&&
cur_width
>
0
)
{
WCMD_output
(
"
\n
"
);
if
(
page_mode
)
{
if
(
++
line_count
>
23
)
{
if
(
++
line_count
>
23
)
{
line_count
=
0
;
line_count
=
0
;
WCMD_output
(
anykey
);
WCMD_output
(
anykey
);
...
@@ -194,6 +306,8 @@ ULARGE_INTEGER byte_count, file_size;
...
@@ -194,6 +306,8 @@ ULARGE_INTEGER byte_count, file_size;
}
}
}
}
}
}
if
(
!
bare
)
{
if
(
file_count
==
1
)
{
if
(
file_count
==
1
)
{
WCMD_output
(
" 1 file %25s bytes
\n
"
,
WCMD_filesize64
(
byte_count
.
QuadPart
));
WCMD_output
(
" 1 file %25s bytes
\n
"
,
WCMD_filesize64
(
byte_count
.
QuadPart
));
}
}
...
@@ -207,9 +321,12 @@ ULARGE_INTEGER byte_count, file_size;
...
@@ -207,9 +321,12 @@ ULARGE_INTEGER byte_count, file_size;
ReadFile
(
GetStdHandle
(
STD_INPUT_HANDLE
),
string
,
sizeof
(
string
),
&
count
,
NULL
);
ReadFile
(
GetStdHandle
(
STD_INPUT_HANDLE
),
string
,
sizeof
(
string
),
&
count
,
NULL
);
}
}
}
}
}
byte_total
=
byte_total
+
byte_count
.
QuadPart
;
byte_total
=
byte_total
+
byte_count
.
QuadPart
;
file_total
=
file_total
+
file_count
;
file_total
=
file_total
+
file_count
;
dir_total
=
dir_total
+
dir_count
;
dir_total
=
dir_total
+
dir_count
;
if
(
!
bare
)
{
if
(
dir_count
==
1
)
WCMD_output
(
"1 directory "
);
if
(
dir_count
==
1
)
WCMD_output
(
"1 directory "
);
else
WCMD_output
(
"%8d directories"
,
dir_count
);
else
WCMD_output
(
"%8d directories"
,
dir_count
);
if
(
page_mode
)
{
if
(
page_mode
)
{
...
@@ -219,6 +336,7 @@ ULARGE_INTEGER byte_count, file_size;
...
@@ -219,6 +336,7 @@ ULARGE_INTEGER byte_count, file_size;
ReadFile
(
GetStdHandle
(
STD_INPUT_HANDLE
),
string
,
sizeof
(
string
),
&
count
,
NULL
);
ReadFile
(
GetStdHandle
(
STD_INPUT_HANDLE
),
string
,
sizeof
(
string
),
&
count
,
NULL
);
}
}
}
}
}
for
(
i
=
0
;
i
<
entry_count
;
i
++
)
{
for
(
i
=
0
;
i
<
entry_count
;
i
++
)
{
if
((
recurse
)
&&
if
((
recurse
)
&&
((
fd
+
i
)
->
cFileName
[
0
]
!=
'.'
)
&&
((
fd
+
i
)
->
cFileName
[
0
]
!=
'.'
)
&&
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment