Author: zguo
Date: Sun Dec 14 18:30:14 2014
New Revision: 65646
URL:
http://svn.reactos.org/svn/reactos?rev=65646&view=rev
Log:
[TREE]
Cleanup of Tree utility by Lee Schroeder.
CORE-8908
Added:
trunk/reactos/base/applications/cmdutils/tree/lang/
trunk/reactos/base/applications/cmdutils/tree/lang/en-US.rc (with props)
trunk/reactos/base/applications/cmdutils/tree/resource.h (with props)
trunk/reactos/base/applications/cmdutils/tree/tree.rc (with props)
Modified:
trunk/reactos/base/applications/cmdutils/tree/CMakeLists.txt
trunk/reactos/base/applications/cmdutils/tree/tree.c
Modified: trunk/reactos/base/applications/cmdutils/tree/CMakeLists.txt
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/cmdutils…
==============================================================================
--- trunk/reactos/base/applications/cmdutils/tree/CMakeLists.txt [iso-8859-1] (original)
+++ trunk/reactos/base/applications/cmdutils/tree/CMakeLists.txt [iso-8859-1] Sun Dec 14
18:30:14 2014
@@ -1,5 +1,6 @@
-add_executable(tree tree.c)
+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_cd_file(TARGET tree DESTINATION reactos/system32 FOR all)
Added: trunk/reactos/base/applications/cmdutils/tree/lang/en-US.rc
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/cmdutils…
==============================================================================
--- trunk/reactos/base/applications/cmdutils/tree/lang/en-US.rc (added)
+++ trunk/reactos/base/applications/cmdutils/tree/lang/en-US.rc [iso-8859-1] Sun Dec 14
18:30:14 2014
@@ -0,0 +1,12 @@
+LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
+
+STRINGTABLE
+BEGIN
+ IDS_USAGE "Visually displays the folder structure of a drive or path.\n\n\
+TREE [drive:][path] [/F] [/A]\n\n\
+\t/F Display the names of the files in each folder.\n\
+\t/A Use ASCII instead of extended characters.\n"
+ IDS_NO_SUBDIRECTORIES "No subdirectories exist"
+ IDS_FOLDER_PATH "Folder PATH Listing\n"
+ IDS_VOL_SERIAL "Volume serial number is %x:%x\n"
+END
Propchange: trunk/reactos/base/applications/cmdutils/tree/lang/en-US.rc
------------------------------------------------------------------------------
svn:eol-style = native
Added: trunk/reactos/base/applications/cmdutils/tree/resource.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/cmdutils…
==============================================================================
--- trunk/reactos/base/applications/cmdutils/tree/resource.h (added)
+++ trunk/reactos/base/applications/cmdutils/tree/resource.h [iso-8859-1] Sun Dec 14
18:30:14 2014
@@ -0,0 +1,9 @@
+#ifndef RESOURCE_H
+#define RESOURCE_H
+
+#define IDS_USAGE 0
+#define IDS_NO_SUBDIRECTORIES 1
+#define IDS_FOLDER_PATH 2
+#define IDS_VOL_SERIAL 3
+
+#endif /* RESOURCE_H */
Propchange: trunk/reactos/base/applications/cmdutils/tree/resource.h
------------------------------------------------------------------------------
svn:eol-style = native
Modified: trunk/reactos/base/applications/cmdutils/tree/tree.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/cmdutils…
==============================================================================
--- trunk/reactos/base/applications/cmdutils/tree/tree.c [iso-8859-1] (original)
+++ trunk/reactos/base/applications/cmdutils/tree/tree.c [iso-8859-1] Sun Dec 14 18:30:14
2014
@@ -9,16 +9,32 @@
//
#include <windows.h>
#include <stdio.h>
+//#include <stdarg.h>
+
+#include "resource.h"
#define STR_MAX 2048
-
-const wchar_t *HELP = L"\nGraphically displays the folder structure of a drive or
path. \n\nTREE [drive:][path] [/F] [/A]\n\n /F Display the names of the files in each
folder.\n\n\n";
-const wchar_t *INVALID = L"No subfolders exist";
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
+
+/*
+ * This takes strings from a resource string table
+ * and outputs it to the console.
+ */
+VOID PrintResourceString(INT resID, ...)
+{
+ WCHAR tmpBuffer[STR_MAX];
+ va_list arg_ptr;
+
+ va_start(arg_ptr, resID);
+ LoadStringW(GetModuleHandle(NULL), resID, tmpBuffer, STR_MAX);
+ vfwprintf(stdout, tmpBuffer, arg_ptr);
+ va_end(arg_ptr);
+}
/**
* @name: HasSubFolder
@@ -101,10 +117,17 @@
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)
- {
- wchar_t a[]={179,0};
- wcscat(consoleOut,a);
+ if((BYTE)prevLine[j] == 195 || (BYTE)prevLine[j] == 179 || (BYTE)prevLine[j]
== L'+' || (BYTE)prevLine[j] == L'|')
+ {
+ if (bUseAscii)
+ {
+ wchar_t a[]={179,0};
+ wcscat(consoleOut,a);
+ }
+ else
+ {
+ wcscat(consoleOut,L"|");
+ }
}
else
{
@@ -117,14 +140,20 @@
if(drawfolder)
{
// will add 'ââââFolder name
- wsprintf(str, L"%c%c%c%c%s", 195, 196, 196, 196,
(wchar_t*)arrFolder[i].cFileName);
+ if (bUseAscii)
+ wsprintf(str, L"+---%s",
(wchar_t*)arrFolder[i].cFileName);
+ else
+ wsprintf(str, L"%c%c%c%c%s", 195, 196, 196, 196,
(wchar_t*)arrFolder[i].cFileName);
}
else
{
if(bHasSubFolder)
{
// will add 'â FileNamw' //thie line is added to connect
the belowfolder sub structure
- wsprintf(str,L"%c %s", 179,
(wchar_t*)arrFolder[i].cFileName);
+ if (bUseAscii)
+ wsprintf(str,L"| %s",
(wchar_t*)arrFolder[i].cFileName);
+ else
+ wsprintf(str,L"%c %s", 179,
(wchar_t*)arrFolder[i].cFileName);
}
else
{
@@ -138,14 +167,20 @@
if(drawfolder)
{
// 'ââââFolder name'
- wsprintf(str, L"%c%c%c%c%s", 192, 196, 196, 196,
(wchar_t*)arrFolder[i].cFileName);
+ if (bUseAscii)
+ wsprintf(str, L"\\---%s",
(wchar_t*)arrFolder[i].cFileName);
+ else
+ wsprintf(str, L"%c%c%c%c%s", 192, 196, 196, 196,
(wchar_t*)arrFolder[i].cFileName);
}
else
{
if(bHasSubFolder)
{
// 'â FileName'
- wsprintf(str,L"%c %s", 179,
(wchar_t*)arrFolder[i].cFileName);
+ if (bUseAscii)
+ wsprintf(str,L"| %s",
(wchar_t*)arrFolder[i].cFileName);
+ else
+ wsprintf(str,L"%c %s", 179,
(wchar_t*)arrFolder[i].cFileName);
}
else
{
@@ -279,14 +314,21 @@
for(i = 1; i < argc; ++i) //parse the command line
{
- if(wcscmp(argv[i], L"/?") == 0)
- {
- wprintf(HELP); //will print help and exit after
- return 0;
- }
- else if(wcscmp(argv[i],L"/F")==0 ||
wcscmp(argv[i],L"/f")==0)
- {
- bShowFiles=TRUE; //if set to true, will populate all the files within the
folder structure
+ 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
+ return 0;
+ case L'f':
+ bShowFiles=TRUE; //if set to true, will populate all the files within
the folder structure
+ break;
+ case L'a':
+ bUseAscii=TRUE;
+ break;
+ default:break;
+ }
}
else
{
@@ -294,16 +336,16 @@
BOOL b=SetCurrentDirectoryW(argv[i]); //will set the current directory for
this executable
if(b==FALSE)
{
- wprintf(INVALID);
+ PrintResourceString(IDS_NO_SUBDIRECTORIES);
return 1;
}
}
}
- wprintf(L"Folder PATH listing\n");
+ PrintResourceString(IDS_FOLDER_PATH);
GetVolumeInformation(NULL, NULL, 0, &dwSerial, NULL, NULL, NULL, 0);
- wprintf(L"Volume serial number is %x:%x\n", dwSerial >> 16, dwSerial
& 0xffff);
+ 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[]
Added: trunk/reactos/base/applications/cmdutils/tree/tree.rc
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/cmdutils…
==============================================================================
--- trunk/reactos/base/applications/cmdutils/tree/tree.rc (added)
+++ trunk/reactos/base/applications/cmdutils/tree/tree.rc [iso-8859-1] Sun Dec 14 18:30:14
2014
@@ -0,0 +1,17 @@
+#include <windef.h>
+#include <winuser.h>
+
+#include "resource.h"
+
+LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
+
+#define REACTOS_STR_FILE_DESCRIPTION "ReactOS Tree Walk Utility"
+#define REACTOS_STR_INTERNAL_NAME "tree"
+#define REACTOS_STR_ORIGINAL_FILENAME "tree.exe"
+#include <reactos/version.rc>
+
+/* UTF-8 */
+#pragma code_page(65001)
+#ifdef LANGUAGE_EN_US
+ #include "lang/en-US.rc"
+#endif
Propchange: trunk/reactos/base/applications/cmdutils/tree/tree.rc
------------------------------------------------------------------------------
svn:eol-style = native