attrib.exe: extendend from stub

K. Wartke kwartke at gmail.com
Sat Sep 4 13:38:50 CDT 2010


---
 programs/attrib/Makefile.in |    1 +
 programs/attrib/attrib.c    |  130 ++++++++++++++++++++++++++++++++++++++++---
 2 files changed, 122 insertions(+), 9 deletions(-)

diff --git a/programs/attrib/Makefile.in b/programs/attrib/Makefile.in
index 9cf9bcfc..782e5c8 100644
--- a/programs/attrib/Makefile.in
+++ b/programs/attrib/Makefile.in
@@ -5,6 +5,7 @@ SRCDIR    = @srcdir@
 VPATH     = @srcdir@
 MODULE    = attrib.exe
 APPMODE   = -mconsole -municode
+IMPORTS   = kernel32 
 
 C_SRCS = attrib.c
 
diff --git a/programs/attrib/attrib.c b/programs/attrib/attrib.c
index 9cb9d9f..9d7b333 100644
--- a/programs/attrib/attrib.c
+++ b/programs/attrib/attrib.c
@@ -16,19 +16,131 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  */
 
+/*
+ * ATTRIB [+R | -R] [+A | -A ] [+S | -S] [+H | -H] [[drive:][path]filename] [/S [/D]]
+ * +	Sets an attribute.
+ * -	Clears an attribute.
+ * R	Read-only file attribute.
+ * A	Archive file attribute.
+ * S	System file attribute.
+ * H	Hidden file attribute.
+ * C	Compressed file attribute.
+ * /D	Process folders as well.
+ * FIXME:
+ * only file name: displays attribute of that file
+ * /S	Processes files in all directories in the specified path.
+ */
+
 #include "wine/debug.h"
+#include <windows.h>
 
 WINE_DEFAULT_DEBUG_CHANNEL(attrib);
 
 int wmain(int argc, WCHAR *argv[])
 {
-    int i;
-
-    WINE_FIXME("attrib.exe is currently only a stub command\n");
-    WINE_FIXME("cmdline:");
-    for (i = 0; i < argc; i++)
-        WINE_FIXME(" %s", wine_dbgstr_w(argv[i]));
-    WINE_FIXME("\n");
-
-    return 0;
+	int i;
+	BOOL includeDirs = FALSE;
+	DWORD addedAttributes = 0;
+	DWORD removedAttributes = 0;
+	DWORD newAttributes = 0;
+	WCHAR filemaskW[MAX_PATH];
+	WIN32_FIND_DATAW ffd;
+	HANDLE hFind = INVALID_HANDLE_VALUE;
+	
+	/* parse arguments */
+	for(i = 0; i < argc; i++)
+	{
+		if(argv[i][0] == '+')
+		{
+			switch(argv[i][1])
+			{
+				case 'R':
+				case 'r':
+					addedAttributes |= FILE_ATTRIBUTE_READONLY;
+					break;
+				case 'A':
+				case 'a':
+					addedAttributes |= FILE_ATTRIBUTE_ARCHIVE;
+					break;
+				case 'S':
+				case 's':
+					addedAttributes |= FILE_ATTRIBUTE_SYSTEM;
+					break;
+				case 'H':
+				case 'h':
+					addedAttributes |= FILE_ATTRIBUTE_HIDDEN;
+					break;
+				case 'C':
+				case 'c':
+					addedAttributes |= FILE_ATTRIBUTE_COMPRESSED;
+					break;
+				default:
+					WINE_FIXME("Unknown attribute +%c!\n", argv[i][1]);
+					break;
+			}
+		}
+		else if(argv[i][0] == '-')
+		{
+			switch(argv[i][1])
+			{
+				case 'R':
+				case 'r':
+					removedAttributes |= FILE_ATTRIBUTE_READONLY;
+					break;
+				case 'A':
+				case 'a':
+					removedAttributes |= FILE_ATTRIBUTE_ARCHIVE;
+					break;
+				case 'S':
+				case 's':
+					removedAttributes |= FILE_ATTRIBUTE_SYSTEM;
+					break;
+				case 'H':
+				case 'h':
+					removedAttributes |= FILE_ATTRIBUTE_HIDDEN;
+					break;
+				case 'C':
+				case 'c':
+					removedAttributes |= FILE_ATTRIBUTE_COMPRESSED;
+					break;
+				default:
+					WINE_FIXME("Unknown attribute -%c!\n", argv[i][1]);
+					break;
+			}
+		}
+		else if(argv[i][0] == '/')
+		{
+			if(argv[i][1] == 'D' || argv[i][1] == 'd')
+			{
+				includeDirs = TRUE;
+			}
+		}	
+		else
+		{
+			/* reached filename */
+			if(lstrcpyW(filemask, argv[i]) == NULL)
+			{
+				return 0;
+			}
+		}
+	}
+	hFind = FindFirstFileW(filemask, &ffd);
+	if (INVALID_HANDLE_VALUE == hFind) 
+	{
+		return 0;
+	}
+	do
+	{
+		if((ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && ~includeDirs)
+		{
+			continue;
+		}
+		if(addedAttributes == 0 && removedAttributes == 0)
+		{
+			// FIXME: only display attributes
+		}
+		newAttributes = ffd.dwFileAttributes | (addedAttributes & ~removedAttributes);
+		SetFileAttributesW(ffd.cFileName, newAttributes);
+	} while (FindNextFileW(hFind, &ffd) != 0);
+	return 0;
 }
-- 
1.7.2.3.392.g02377


------------0KNgia0FDs0JJuaaJDq0vw--




More information about the wine-patches mailing list