Author: akhaldi
Date: Sun Dec 21 18:48:33 2014
New Revision: 65786
URL:
http://svn.reactos.org/svn/reactos?rev=65786&view=rev
Log:
[TREE] Attempt to fix some style & formatting crimes. Improve header inclusions.
CORE-8529
Modified:
trunk/reactos/base/applications/cmdutils/tree/CMakeLists.txt
trunk/reactos/base/applications/cmdutils/tree/tree.c
trunk/reactos/base/applications/cmdutils/tree/tree.rc
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 21
18:48:33 2014
@@ -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)
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 21 18:48:33
2014
@@ -1,23 +1,27 @@
/*
- * PROJECT: ReactOS
- * LICENSE: GNU GPLv2 only as published by the Free Software Foundation
- * PURPOSE: Implements
tree.com functionality similar to Windows
- * PROGRAMMERS: Asif Bahrainwala (asif_bahrainwala(a)hotmail.com)
+ * PROJECT: ReactOS
+ * LICENSE: GNU GPLv2 only as published by the Free Software Foundation
+ * PURPOSE: Implements
tree.com functionality similar to Windows
+ * PROGRAMMERS: Asif Bahrainwala (asif_bahrainwala(a)hotmail.com)
*/
#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
@@ -50,28 +54,28 @@
BOOL ret = FALSE;
WIN32_FIND_DATA FindFileData;
HANDLE hFind = NULL;
- static wchar_t strPath[STR_MAX]= L"";
+ static wchar_t strPath[STR_MAX] = L"";
ZeroMemory(strPath, sizeof(strPath));
- wcscat(strPath,strPath1);
- wcscat(strPath,L"\\*.");
-
- hFind=FindFirstFile(strPath, &FindFileData);
+ wcscat(strPath, strPath1);
+ wcscat(strPath, L"\\*.");
+
+ hFind = FindFirstFile(strPath, &FindFileData);
do
{
if (FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
- if(wcscmp(FindFileData.cFileName, L".")==0 ||
- wcscmp(FindFileData.cFileName, L"..")==0 )
+ if (wcscmp(FindFileData.cFileName, L".") == 0 ||
+ wcscmp(FindFileData.cFileName, L"..") == 0 )
{
continue;
}
- ret=TRUE; //found subfolder
+ ret = TRUE; //found subfolder
break;
}
}
- while(FindNextFile(hFind, &FindFileData));
+ while (FindNextFile(hFind, &FindFileData));
FindClose(hFind);
return ret;
@@ -96,50 +100,57 @@
* @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
- for(i = 0; i < szArr; ++i)
+ /* 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;
+ 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"");
wcscpy(str, L"");
- 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'|')
+ 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 (bUseAscii)
{
- wchar_t a[]={179,0};
- wcscat(consoleOut,a);
- }
- else
- {
- wcscat(consoleOut,L"|");
+ wchar_t a[] = {179, 0};
+ wcscat(consoleOut, a);
+ }
+ else
+ {
+ wcscat(consoleOut, L"|");
}
}
else
{
- wcscat(consoleOut,L" ");
- }
- }
-
- if(szArr - 1 != i)
- {
- if(drawfolder)
- {
- // will add 'ââââFolder name
+ wcscat(consoleOut, L" ");
+ }
+ }
+
+ if (szArr - 1 != i)
+ {
+ if (drawfolder)
+ {
+ /* will add 'ââââFolder name */
if (bUseAscii)
wsprintf(str, L"+---%s",
(wchar_t*)arrFolder[i].cFileName);
else
@@ -147,9 +158,10 @@
}
else
{
- if(bHasSubFolder)
- {
- // will add 'â FileNamw' //thie line is added to connect
the belowfolder sub structure
+ if (bHasSubFolder)
+ {
+ /* 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,16 +169,16 @@
}
else
{
- // will add ' FileNamw'
+ /* will add ' FileNamw' */
wsprintf(str,L" %s",
(wchar_t*)arrFolder[i].cFileName);
}
}
}
else
{
- if(drawfolder)
- {
- // 'ââââFolder name'
+ if (drawfolder)
+ {
+ /* 'ââââFolder name' */
if (bUseAscii)
wsprintf(str, L"\\---%s",
(wchar_t*)arrFolder[i].cFileName);
else
@@ -174,18 +186,18 @@
}
else
{
- if(bHasSubFolder)
- {
- // 'â FileName'
+ if (bHasSubFolder)
+ {
+ /* 'â FileName' */
if (bUseAscii)
- wsprintf(str,L"| %s",
(wchar_t*)arrFolder[i].cFileName);
+ wsprintf(str, L"| %s",
(wchar_t*)arrFolder[i].cFileName);
else
- wsprintf(str,L"%c %s", 179,
(wchar_t*)arrFolder[i].cFileName);
- }
- else
- {
- // ' FileName'
- wsprintf(str,L" %s",
(wchar_t*)arrFolder[i].cFileName);
+ wsprintf(str, L"%c %s", 179,
(wchar_t*)arrFolder[i].cFileName);
+ }
+ else
+ {
+ /* ' FileName' */
+ wsprintf(str, L" %s",
(wchar_t*)arrFolder[i].cFileName);
}
}
}
@@ -193,15 +205,15 @@
wcscat(consoleOut, str);
wprintf(L"%s\n", consoleOut);
- if(drawfolder)
+ if (drawfolder)
{
wchar_t *str = (wchar_t*)malloc(STR_MAX * sizeof(wchar_t));
- ZeroMemory(str, STR_MAX*sizeof(wchar_t));
+ ZeroMemory(str, STR_MAX * sizeof(wchar_t));
wcscat(str, strPath);
wcscat(str, L"\\");
wcscat(str, arrFolder[i].cFileName);
- GetDirectoryStructure(str, width+4, consoleOut);
+ GetDirectoryStructure(str, width + 4, consoleOut);
free(str);
}
@@ -223,75 +235,76 @@
* @return
* void
*/
-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
- WIN32_FIND_DATA *arrFolder = NULL;
- UINT arrFoldersz = 0;
- //will fill up with names of all sub folders
- WIN32_FIND_DATA *arrFile = NULL;
- UINT arrFilesz = 0;
-
- ZeroMemory(&FindFileData,sizeof(FindFileData));
-
- {
- static wchar_t tmp[STR_MAX]=L"";
- ZeroMemory(tmp,sizeof(tmp));
- wcscat(tmp,strPath);
- wcscat(tmp,L"\\*.*");
-
- hFind=FindFirstFile(tmp, &FindFileData);
-
- //err = GetLastError();
- }
-
- if(hFind == INVALID_HANDLE_VALUE)
- return;
-
- do
- {
- if (FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
- {
- if(wcscmp(FindFileData.cFileName, L".")==0 ||
- wcscmp(FindFileData.cFileName, L"..")==0 )
- continue;
-
- ++arrFoldersz;
- arrFolder=(WIN32_FIND_DATA*)realloc(arrFolder, arrFoldersz *
sizeof(FindFileData));
-
- if(arrFolder == NULL)
- exit(-1);
-
- arrFolder[arrFoldersz - 1] = FindFileData;
-
- }
- else
- {
- ++arrFilesz;
- arrFile=(WIN32_FIND_DATA*)realloc(arrFile, arrFilesz * sizeof(FindFileData));
-
- if(arrFile == NULL)
- exit(-1);
-
- arrFile[arrFilesz - 1] = FindFileData;
- }
- }
- while(FindNextFile(hFind, &FindFileData));
-
- FindClose(hFind);
-
- if(bShowFiles)
- {
- DrawTree(strPath, arrFile, arrFilesz, width, prevLine, FALSE); //will free(arrFile)
- }
-
- DrawTree(strPath, arrFolder, arrFoldersz, width, prevLine, TRUE); //will
free(arrFile)
-
- free(arrFolder);
- free(arrFile);
+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 */
+ WIN32_FIND_DATA *arrFolder = NULL;
+ UINT arrFoldersz = 0;
+ /* will fill up with names of all sub folders */
+ WIN32_FIND_DATA *arrFile = NULL;
+ UINT arrFilesz = 0;
+
+ ZeroMemory(&FindFileData, sizeof(FindFileData));
+
+ {
+ static wchar_t tmp[STR_MAX] = L"";
+ ZeroMemory(tmp, sizeof(tmp));
+ wcscat(tmp, strPath);
+ wcscat(tmp, L"\\*.*");
+ hFind = FindFirstFile(tmp, &FindFileData);
+ //err = GetLastError();
+ }
+
+ if (hFind == INVALID_HANDLE_VALUE)
+ return;
+
+ do
+ {
+ if (FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
+ {
+ if (wcscmp(FindFileData.cFileName, L".") == 0 ||
+ wcscmp(FindFileData.cFileName, L"..") == 0)
+ continue;
+
+ ++arrFoldersz;
+ arrFolder = (WIN32_FIND_DATA*)realloc(arrFolder, arrFoldersz *
sizeof(FindFileData));
+
+ if (arrFolder == NULL)
+ exit(-1);
+
+ arrFolder[arrFoldersz - 1] = FindFileData;
+
+ }
+ else
+ {
+ ++arrFilesz;
+ arrFile = (WIN32_FIND_DATA*)realloc(arrFile, arrFilesz *
sizeof(FindFileData));
+
+ if(arrFile == NULL)
+ exit(-1);
+
+ arrFile[arrFilesz - 1] = FindFileData;
+ }
+ }
+ while (FindNextFile(hFind, &FindFileData));
+
+ FindClose(hFind);
+
+ if (bShowFiles)
+ {
+ /* will free(arrFile) */
+ DrawTree(strPath, arrFile, arrFilesz, width, prevLine, FALSE);
+ }
+
+ /* will free(arrFile) */
+ DrawTree(strPath, arrFolder, arrFoldersz, width, prevLine, TRUE);
+
+ free(arrFolder);
+ free(arrFile);
}
/**
@@ -304,37 +317,43 @@
int wmain( int argc, wchar_t *argv[])
{
DWORD dwSerial = 0;
- wchar_t t=0;
+ wchar_t t = 0;
wchar_t *strPath = NULL;
DWORD sz = 0;
- //wchar_t *context = NULL ;
+ //wchar_t *context = NULL;
wchar_t *driveLetter = NULL;
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
- 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;
+ case L'?':
+ /* will print help and exit after */
+ PrintResourceString(IDS_USAGE);
+ return 0;
+ case L'f':
+ /* if set to true, will populate all the files within the folder
structure */
+ bShowFiles = TRUE;
+ break;
+ case L'a':
+ bUseAscii = TRUE;
+ break;
+ default:
+ break;
}
}
else
{
- //this must be path to some folder
- BOOL b=SetCurrentDirectoryW(argv[i]); //will set the current directory for
this executable
- if(b==FALSE)
+ /* 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);
return 1;
@@ -345,27 +364,31 @@
PrintResourceString(IDS_FOLDER_PATH);
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[]
-
- GetCurrentDirectory(sz, strPath); //get the current directory
-
-
- 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
+ PrintResourceString(IDS_VOL_SERIAL, dwSerial >> 16, dwSerial & 0xffff);
+
+ /* get the buffer size */
+ sz = GetCurrentDirectory(1, &t);
+ /* must not return before calling delete[] */
+ strPath = (wchar_t*)malloc(sizeof(wchar_t) * sz);
+
+ /* 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);
+
+ /* 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);
+ wcscpy(driveLetter, strPath);
wcstok(driveLetter, L":");
- wprintf(L"%s:.\n",driveLetter);
+ wprintf(L"%s:.\n", driveLetter);
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");
Modified: 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 [iso-8859-1] (original)
+++ trunk/reactos/base/applications/cmdutils/tree/tree.rc [iso-8859-1] Sun Dec 21 18:48:33
2014
@@ -1,13 +1,12 @@
#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.com"
+#define REACTOS_STR_FILE_DESCRIPTION "ReactOS Tree Walk Utility"
+#define REACTOS_STR_INTERNAL_NAME "tree"
+#define REACTOS_STR_ORIGINAL_FILENAME "tree.com"
#include <reactos/version.rc>
/* UTF-8 */