mirror of
https://github.com/reactos/reactos.git
synced 2025-08-04 18:57:04 +00:00
[TREE] Attempt to fix some style & formatting crimes. Improve header inclusions. CORE-8529
svn path=/trunk/; revision=65786
This commit is contained in:
parent
9d80e094b4
commit
b37505476c
3 changed files with 156 additions and 134 deletions
|
@ -2,5 +2,5 @@
|
|||
add_executable(tree tree.c tree.rc)
|
||||
set_module_type(tree win32cui UNICODE)
|
||||
set_target_properties(tree PROPERTIES SUFFIX ".com")
|
||||
add_importlibs(tree msvcrt kernel32 user32)
|
||||
add_importlibs(tree user32 msvcrt kernel32)
|
||||
add_cd_file(TARGET tree DESTINATION reactos/system32 FOR all)
|
||||
|
|
|
@ -6,18 +6,22 @@
|
|||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
//#include <stdarg.h>
|
||||
#include <windows.h>
|
||||
#include <stdlib.h>
|
||||
#include <windef.h>
|
||||
#include <winbase.h>
|
||||
#include <winuser.h>
|
||||
|
||||
#include "resource.h"
|
||||
|
||||
#define STR_MAX 2048
|
||||
|
||||
static void DrawTree(const wchar_t* strPath, const WIN32_FIND_DATA *arrFolder, const size_t szArr, UINT width, const wchar_t *prevLine, BOOL drawfolder);
|
||||
static void GetDirectoryStructure(wchar_t* strPath, UINT width, const wchar_t* prevLine);
|
||||
|
||||
BOOL bShowFiles = FALSE; //if this flag is set to true, files will also be listed
|
||||
BOOL bUseAscii = FALSE; //if this flag is true, ASCII characters will be used instead of UNICODE ones
|
||||
/* if this flag is set to true, files will also be listed */
|
||||
BOOL bShowFiles = FALSE;
|
||||
|
||||
/* if this flag is true, ASCII characters will be used instead of UNICODE ones */
|
||||
BOOL bUseAscii = FALSE;
|
||||
|
||||
/*
|
||||
* This takes strings from a resource string table
|
||||
|
@ -96,19 +100,24 @@ static BOOL HasSubFolder(const wchar_t *strPath1)
|
|||
* @return
|
||||
* void
|
||||
*/
|
||||
static void DrawTree(const wchar_t* strPath, const WIN32_FIND_DATA *arrFolder, const size_t szArr, UINT width, const wchar_t *prevLine, BOOL drawfolder)
|
||||
static void DrawTree(const wchar_t* strPath,
|
||||
const WIN32_FIND_DATA *arrFolder,
|
||||
const size_t szArr,
|
||||
UINT width,
|
||||
const wchar_t *prevLine,
|
||||
BOOL drawfolder)
|
||||
{
|
||||
BOOL bHasSubFolder = HasSubFolder(strPath);
|
||||
UINT i = 0;
|
||||
|
||||
//this will format the spaces required for correct formatting
|
||||
/* this will format the spaces required for correct formatting */
|
||||
for (i = 0; i < szArr; ++i)
|
||||
{
|
||||
wchar_t *consoleOut = (wchar_t*)malloc(sizeof(wchar_t) * STR_MAX);
|
||||
UINT j = 0;
|
||||
static wchar_t str[STR_MAX];
|
||||
|
||||
// As we do not seem to have the _s functions properly set up, use the non-secure version for now
|
||||
/* As we do not seem to have the _s functions properly set up, use the non-secure version for now */
|
||||
//wcscpy_s(consoleOut, STR_MAX, L"");
|
||||
//wcscpy_s(str, STR_MAX, L"");
|
||||
wcscpy(consoleOut, L"");
|
||||
|
@ -116,8 +125,10 @@ static void DrawTree(const wchar_t* strPath, const WIN32_FIND_DATA *arrFolder, c
|
|||
|
||||
for (j = 0; j < width - 1; ++j)
|
||||
{
|
||||
//if the previous line has '├' or '│' then the current line will add '│' to continue the connecting line
|
||||
if((BYTE)prevLine[j] == 195 || (BYTE)prevLine[j] == 179 || (BYTE)prevLine[j] == L'+' || (BYTE)prevLine[j] == L'|')
|
||||
/* if the previous line has '├' or '│' then the current line will
|
||||
add '│' to continue the connecting line */
|
||||
if ((BYTE)prevLine[j] == 195 || (BYTE)prevLine[j] == 179 ||
|
||||
(BYTE)prevLine[j] == L'+' || (BYTE)prevLine[j] == L'|')
|
||||
{
|
||||
if (bUseAscii)
|
||||
{
|
||||
|
@ -139,7 +150,7 @@ static void DrawTree(const wchar_t* strPath, const WIN32_FIND_DATA *arrFolder, c
|
|||
{
|
||||
if (drawfolder)
|
||||
{
|
||||
// will add '├───Folder name
|
||||
/* will add '├───Folder name */
|
||||
if (bUseAscii)
|
||||
wsprintf(str, L"+---%s", (wchar_t*)arrFolder[i].cFileName);
|
||||
else
|
||||
|
@ -149,7 +160,8 @@ static void DrawTree(const wchar_t* strPath, const WIN32_FIND_DATA *arrFolder, c
|
|||
{
|
||||
if (bHasSubFolder)
|
||||
{
|
||||
// will add '│ FileNamw' //thie line is added to connect the belowfolder sub structure
|
||||
/* will add '│ FileNamw' //thie line is added to connect
|
||||
the belowfolder sub structure */
|
||||
if (bUseAscii)
|
||||
wsprintf(str,L"| %s", (wchar_t*)arrFolder[i].cFileName);
|
||||
else
|
||||
|
@ -157,7 +169,7 @@ static void DrawTree(const wchar_t* strPath, const WIN32_FIND_DATA *arrFolder, c
|
|||
}
|
||||
else
|
||||
{
|
||||
// will add ' FileNamw'
|
||||
/* will add ' FileNamw' */
|
||||
wsprintf(str,L" %s", (wchar_t*)arrFolder[i].cFileName);
|
||||
}
|
||||
}
|
||||
|
@ -166,7 +178,7 @@ static void DrawTree(const wchar_t* strPath, const WIN32_FIND_DATA *arrFolder, c
|
|||
{
|
||||
if (drawfolder)
|
||||
{
|
||||
// '└───Folder name'
|
||||
/* '└───Folder name' */
|
||||
if (bUseAscii)
|
||||
wsprintf(str, L"\\---%s", (wchar_t*)arrFolder[i].cFileName);
|
||||
else
|
||||
|
@ -176,7 +188,7 @@ static void DrawTree(const wchar_t* strPath, const WIN32_FIND_DATA *arrFolder, c
|
|||
{
|
||||
if (bHasSubFolder)
|
||||
{
|
||||
// '│ FileName'
|
||||
/* '│ FileName' */
|
||||
if (bUseAscii)
|
||||
wsprintf(str, L"| %s", (wchar_t*)arrFolder[i].cFileName);
|
||||
else
|
||||
|
@ -184,7 +196,7 @@ static void DrawTree(const wchar_t* strPath, const WIN32_FIND_DATA *arrFolder, c
|
|||
}
|
||||
else
|
||||
{
|
||||
// ' FileName'
|
||||
/* ' FileName' */
|
||||
wsprintf(str, L" %s", (wchar_t*)arrFolder[i].cFileName);
|
||||
}
|
||||
}
|
||||
|
@ -223,15 +235,16 @@ static void DrawTree(const wchar_t* strPath, const WIN32_FIND_DATA *arrFolder, c
|
|||
* @return
|
||||
* void
|
||||
*/
|
||||
static void GetDirectoryStructure(wchar_t* strPath, UINT width, const wchar_t* prevLine)
|
||||
static void
|
||||
GetDirectoryStructure(wchar_t* strPath, UINT width, const wchar_t* prevLine)
|
||||
{
|
||||
WIN32_FIND_DATA FindFileData;
|
||||
HANDLE hFind = NULL;
|
||||
//DWORD err = 0;
|
||||
//will fill up with names of all sub folders
|
||||
/* will fill up with names of all sub folders */
|
||||
WIN32_FIND_DATA *arrFolder = NULL;
|
||||
UINT arrFoldersz = 0;
|
||||
//will fill up with names of all sub folders
|
||||
/* will fill up with names of all sub folders */
|
||||
WIN32_FIND_DATA *arrFile = NULL;
|
||||
UINT arrFilesz = 0;
|
||||
|
||||
|
@ -242,9 +255,7 @@ static void GetDirectoryStructure(wchar_t* strPath, UINT width, const wchar_t* p
|
|||
ZeroMemory(tmp, sizeof(tmp));
|
||||
wcscat(tmp, strPath);
|
||||
wcscat(tmp, L"\\*.*");
|
||||
|
||||
hFind = FindFirstFile(tmp, &FindFileData);
|
||||
|
||||
//err = GetLastError();
|
||||
}
|
||||
|
||||
|
@ -285,10 +296,12 @@ static void GetDirectoryStructure(wchar_t* strPath, UINT width, const wchar_t* p
|
|||
|
||||
if (bShowFiles)
|
||||
{
|
||||
DrawTree(strPath, arrFile, arrFilesz, width, prevLine, FALSE); //will free(arrFile)
|
||||
/* will free(arrFile) */
|
||||
DrawTree(strPath, arrFile, arrFilesz, width, prevLine, FALSE);
|
||||
}
|
||||
|
||||
DrawTree(strPath, arrFolder, arrFoldersz, width, prevLine, TRUE); //will free(arrFile)
|
||||
/* will free(arrFile) */
|
||||
DrawTree(strPath, arrFolder, arrFoldersz, width, prevLine, TRUE);
|
||||
|
||||
free(arrFolder);
|
||||
free(arrFile);
|
||||
|
@ -312,28 +325,34 @@ int wmain( int argc, wchar_t *argv[])
|
|||
|
||||
int i;
|
||||
|
||||
for(i = 1; i < argc; ++i) //parse the command line
|
||||
/* parse the command line */
|
||||
for (i = 1; i < argc; ++i)
|
||||
{
|
||||
if (argv[i][0] == L'-' || argv[i][0] == L'/')
|
||||
{
|
||||
switch (towlower(argv[i][1]))
|
||||
{
|
||||
case L'?':
|
||||
PrintResourceString(IDS_USAGE); //will print help and exit after
|
||||
/* will print help and exit after */
|
||||
PrintResourceString(IDS_USAGE);
|
||||
return 0;
|
||||
case L'f':
|
||||
bShowFiles=TRUE; //if set to true, will populate all the files within the folder structure
|
||||
/* if set to true, will populate all the files within the folder structure */
|
||||
bShowFiles = TRUE;
|
||||
break;
|
||||
case L'a':
|
||||
bUseAscii = TRUE;
|
||||
break;
|
||||
default:break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//this must be path to some folder
|
||||
BOOL b=SetCurrentDirectoryW(argv[i]); //will set the current directory for this executable
|
||||
/* this must be path to some folder */
|
||||
|
||||
/* will set the current directory for this executable */
|
||||
BOOL b = SetCurrentDirectoryW(argv[i]);
|
||||
if (b == FALSE)
|
||||
{
|
||||
PrintResourceString(IDS_NO_SUBDIRECTORIES);
|
||||
|
@ -347,15 +366,18 @@ int wmain( int argc, wchar_t *argv[])
|
|||
GetVolumeInformation(NULL, NULL, 0, &dwSerial, NULL, NULL, NULL, 0);
|
||||
PrintResourceString(IDS_VOL_SERIAL, dwSerial >> 16, dwSerial & 0xffff);
|
||||
|
||||
sz = GetCurrentDirectory(1, &t); //get the buffer size
|
||||
strPath = (wchar_t*)malloc(sizeof(wchar_t) * sz); //must not return before calling delete[]
|
||||
/* get the buffer size */
|
||||
sz = GetCurrentDirectory(1, &t);
|
||||
/* must not return before calling delete[] */
|
||||
strPath = (wchar_t*)malloc(sizeof(wchar_t) * sz);
|
||||
|
||||
GetCurrentDirectory(sz, strPath); //get the current directory
|
||||
/* get the current directory */
|
||||
GetCurrentDirectory(sz, strPath);
|
||||
|
||||
/* get the drive letter , must not return before calling delete[] */
|
||||
driveLetter = (wchar_t*)malloc(sizeof(wchar_t) * sz);
|
||||
|
||||
driveLetter = (wchar_t*)malloc(sizeof(wchar_t) * sz); //get the drive letter , must not return before calling delete[]
|
||||
|
||||
// As we do not seem to have the _s functions properly set up, use the non-secure version for now
|
||||
/* As we do not seem to have the _s functions properly set up, use the non-secure version for now */
|
||||
//wcscpy_s(driveLetter,sz,strPath);
|
||||
//wcstok_s(driveLetter,L":", &context); //parse for the drive letter
|
||||
wcscpy(driveLetter, strPath);
|
||||
|
@ -365,7 +387,8 @@ int wmain( int argc, wchar_t *argv[])
|
|||
|
||||
free(driveLetter);
|
||||
|
||||
GetDirectoryStructure(strPath, 1, L" "); //get the sub directories within this current folder
|
||||
/* get the sub directories within this current folder */
|
||||
GetDirectoryStructure(strPath, 1, L" ");
|
||||
|
||||
free(strPath);
|
||||
wprintf(L"\n");
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#include <windef.h>
|
||||
#include <winuser.h>
|
||||
|
||||
#include "resource.h"
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue