From ef527d721a56fcaa6516b9e21300ad70f18f20a8 Mon Sep 17 00:00:00 2001
From: Ilya Shpigor <shpigor@etersoft.ru>
Date: Thu, 22 Oct 2009 14:48:20 +0400
Subject: [PATCH 1/2] extrac32: Add command-line parsing

---
 programs/extrac32/Makefile.in |    2 +-
 programs/extrac32/extrac32.c  |   75 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 76 insertions(+), 1 deletions(-)

diff --git a/programs/extrac32/Makefile.in b/programs/extrac32/Makefile.in
index 3f57dee..c40ce2b 100644
--- a/programs/extrac32/Makefile.in
+++ b/programs/extrac32/Makefile.in
@@ -5,7 +5,7 @@ VPATH     = @srcdir@
 MODULE    = extrac32.exe
 APPMODE   = -mwindows -municode
 EXTRADEFS = -DUNICODE
-IMPORTS   = kernel32
+IMPORTS   = kernel32 shell32
 
 C_SRCS = \
 	extrac32.c
diff --git a/programs/extrac32/extrac32.c b/programs/extrac32/extrac32.c
index 7e8fbed..f83fb16 100644
--- a/programs/extrac32/extrac32.c
+++ b/programs/extrac32/extrac32.c
@@ -2,6 +2,7 @@
  * Extract - Wine-compatible program for extract *.cab files.
  *
  * Copyright 2007 Etersoft (Lyutin Anatoly)
+ * Copyright 2009 Ilya Shpigor
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -19,13 +20,87 @@
  */
 
 #include <windows.h>
+#include <shellapi.h>
 
 #include "wine/unicode.h"
 #include "wine/debug.h"
 
 WINE_DEFAULT_DEBUG_CHANNEL(extrac32);
 
+#define EFLAGY  0x01
+#define EFLAGA  0x02
+#define EFLAGD  0x04
+#define EFLAGE  0x08
+#define EFLAGL  0x10
+#define EFLAGC  0x20
+#define CMD_FLAGS (EFLAGC | EFLAGD | EFLAGE)
+
+typedef struct sOptions
+{
+    WCHAR wFlag[3];
+    int   nFlag;
+} sOptions;
+
+static sOptions sFlags[] =
+{
+    { { '/', 'Y', 0 }, EFLAGY },
+    { { '/', 'A', 0 }, EFLAGA },
+    { { '/', 'D', 0 }, EFLAGD },
+    { { '/', 'E', 0 }, EFLAGE },
+    { { '/', 'L', 0 }, EFLAGL },
+    { { '/', 'C', 0 }, EFLAGC },
+};
+
 int PASCAL wWinMain(HINSTANCE hInstance, HINSTANCE prev, LPWSTR cmdline, int show)
 {
+    LPWSTR *argv;
+    int argc;
+    int i, j;
+    UINT comp = 0;
+
+    argv = CommandLineToArgvW(cmdline, &argc);
+
+    if(!argv)
+    {
+        WINE_ERR("Bad command line arguments\n");
+        return 0;
+    }
+
+    /* Parse options */
+    for(i = 0; i < argc; i++)
+    {
+        if (argv[i][0] == '/')
+        {
+            for(j = 0; j < sizeof(sFlags) / sizeof(sFlags[0]); j++)
+                if (!strcmpiW(argv[i], sFlags[j].wFlag))
+                {
+                    comp |= sFlags[j].nFlag;
+                    goto next;
+                }
+        }
+        next:
+            continue;
+    }
+
+    switch(comp & CMD_FLAGS)
+    {
+        case EFLAGC:
+            /* copy file */
+            WINE_FIXME("/C not implemented\n");
+            break;
+        case EFLAGD:
+            /* display CAB archive */
+            WINE_FIXME("/D not implemented\n");
+            break;
+        case EFLAGE:
+            /* extract CAB archive */
+            WINE_FIXME("/E not implemented\n");
+            break;
+        case 0:
+            /* expand mode */
+            WINE_FIXME("Expand mode not implemented\n");
+            break;
+    }
+
     return 0;
 }
-- 
1.6.4.4


