- Resource script restructuring.
- Build info et al. is given by files instead of env. vars.
- Store that information in resources.
- Make the main windows not resizeable.
- Insist on creating a fresh log file.
- Introduce the make dist target.

diff --git a/programs/winetest/.cvsignore b/programs/winetest/.cvsignore
index 4ba4aa3..52487fa 100644
--- a/programs/winetest/.cvsignore
+++ b/programs/winetest/.cvsignore
@@ -1,6 +1,6 @@
 Makefile
-gui.res
+dist.res
+tests.rc
 wine.ico
 winetest.exe.dbg.c
-winetest.rc
 winetest.res
diff --git a/programs/winetest/Makefile.in b/programs/winetest/Makefile.in
index 9939097..1da9b58 100644
--- a/programs/winetest/Makefile.in
+++ b/programs/winetest/Makefile.in
@@ -13,9 +13,9 @@
 	util.c
 
 RC_SRCS = \
-	gui.rc
+	winetest.rc
 
-RC_BINSRC = gui.rc
+RC_BINSRC = winetest.rc
 RC_BINARIES = wine.ico 
 
 TESTS = \
@@ -44,17 +44,34 @@
 
 TESTBINS = $(TESTS:%=%_test.exe$(DLLEXT))
 
-winetest.rc: maketest Makefile.in
+tests.rc: maketest Makefile.in
 	$(SRCDIR)/maketest $(TOPSRCDIR) $(TESTBINS) > $@ || ( $(RM) $@ && exit 1 )
 
-gui.res: winetest.rc $(TESTBINS)
+winetest.res: $(TESTBINS)
 
 clean::
-	$(RM) winetest.rc $(TESTBINS)
+	$(RM) tests.rc dist.res winetest-dist winetest-dist.exe $(TESTBINS)
 
-depend: winetest.rc
+depend: tests.rc
 
-# rules for stripping the test executables
+# Rules for building distributable executable
+
+.PHONY: dist
+
+dist: winetest-dist.exe$(DLLEXT) winetest-dist$(EXEEXT)
+
+winetest-dist.exe.so: $(ALL_OBJS) dist.res Makefile.in
+	$(WINEGCC) -B$(TOOLSDIR)/tools/winebuild $(APPMODE) $(ALL_OBJS) dist.res -o $@ -L$(DLLDIR) $(DELAYIMPORTS:%=-Wb,-d%) $(ALL_LIBS)
+
+winetest-dist: $(WINEWRAPPER)
+	$(RM) $@ && $(LN_S) $(WINEWRAPPER) $@
+
+winetest-dist.exe: $(ALL_OBJS) dist.res.o Makefile.in
+	$(CC) $(APPMODE) $(ALL_OBJS) dist.res.o -o $@ $(DELAYIMPORTS:%=-l%) $(ALL_LIBS)
+
+dist.res: winetest.rc tests.rc build.id build.nfo tests.url $(TESTBINS) $(RC_BINARIES)
+
+# Rules for stripping the test executables
 
 advapi32_test.exe$(DLLEXT): $(DLLDIR)/advapi32/tests/advapi32_test.exe$(DLLEXT)
 	cp $(DLLDIR)/advapi32/tests/advapi32_test.exe$(DLLEXT) $@ && $(STRIP) $@
diff --git a/programs/winetest/README b/programs/winetest/README
new file mode 100644
index 0000000..90e8acc
--- /dev/null
+++ b/programs/winetest/README
@@ -0,0 +1,22 @@
+                           Wine Test Shell
+                           ~~~~~~~~~~~~~~~
+
+Winetest is a single-executable version of all the DLL conformance
+test programs suitable for unattended testing and report submission.
+People assigned to build winetest must take care of the following
+files, which are only used by 'make dist':
+
+* build.id
+
+Contains a single (either CR or CR-LF) terminated line providing the
+build identification.  The accepted characters are [-.0-9a-zA-Z].
+
+* tests.url
+
+Also contains a single terminated line providing the archive URL of
+the testing suite being built.
+
+* build.nfo
+
+Contains a block of terminated lines providing miscellaneous
+information about the build, like eg. the tools being used.
diff --git a/programs/winetest/guires.h b/programs/winetest/dist.rc
similarity index 67%
copy from programs/winetest/guires.h
copy to programs/winetest/dist.rc
index 24f0379..50a2288 100644
--- a/programs/winetest/guires.h
+++ b/programs/winetest/dist.rc
@@ -1,5 +1,5 @@
 /*
- * GUI resource definitions
+ * Resources for the binary we distribute to testers
  *
  * Copyright 2004 Ferenc Wagner
  *
@@ -15,25 +15,11 @@
  *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
- *
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#define IDI_WINE 1
+#include "winetest.rc"
 
-#define IDD_STATUS 100
-#define IDD_ABOUT  101
-
-#define IDC_ST0 1000
-#define IDC_PB0 1001
-#define IDC_ST1 1002
-#define IDC_PB1 1003
-#define IDC_ST2 1004
-#define IDC_PB2 1005
-
-#define IDC_DIR 2000
-#define IDC_OUT 2001
-
-#define IDC_SB  3000
-
-#define IDC_EDIT  4000
-#define IDC_ABOUT 4001
+WINE_BUILD STRINGRES "build.id"
+BUILD_INFO STRINGRES "build.nfo"
+TESTS_URL  STRINGRES "tests.url"
diff --git a/programs/winetest/gui.c b/programs/winetest/gui.c
index 0704dea..89a3108 100644
--- a/programs/winetest/gui.c
+++ b/programs/winetest/gui.c
@@ -15,13 +15,13 @@
  *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
- *
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
 #include <windows.h>
 #include <commctrl.h>
 
-#include "guires.h"
+#include "resource.h"
 #include "winetest.h"
 
 /* Event object to signal successful window creation to main thread.
diff --git a/programs/winetest/main.c b/programs/winetest/main.c
index 8b9db14..d749f00 100644
--- a/programs/winetest/main.c
+++ b/programs/winetest/main.c
@@ -17,6 +17,7 @@
  *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  *
  * This program is dedicated to Anna Lindh,
  * Swedish Minister of Foreign Affairs.
@@ -36,8 +37,7 @@
 #include <windows.h>
 
 #include "winetest.h"
-
-#define TESTRESOURCE "USERDATA"
+#include "resource.h"
 
 struct wine_test
 {
@@ -174,7 +174,7 @@
 	}
 	memset(rev_infos + i, 0, sizeof(rev_infos[i]));
 
-        len = LoadStringA (module, i + 30000, revinfo, sizeof(revinfo));
+        len = LoadStringA (module, REV_INFO+i, revinfo, sizeof(revinfo));
         if (len == 0) break; /* end of revision info */
 	if (len >= sizeof(revinfo) - 1) 
 	    report (R_FATAL, "Revision info too long.");
@@ -186,18 +186,17 @@
     }
 }
 
-void* extract_rcdata (int id, DWORD* size)
+void* extract_rcdata (int id, int type, DWORD* size)
 {
     HRSRC rsrc;
     HGLOBAL hdl;
-    LPVOID addr = NULL;
+    LPVOID addr;
     
-    if (!(rsrc = FindResource (0, (LPTSTR)id, TESTRESOURCE)) ||
+    if (!(rsrc = FindResource (NULL, (LPTSTR)id, MAKEINTRESOURCE(type))) ||
         !(*size = SizeofResource (0, rsrc)) ||
         !(hdl = LoadResource (0, rsrc)) ||
         !(addr = LockResource (hdl)))
-        report (R_FATAL, "Can't extract test file of id %d: %d",
-                id, GetLastError ());
+        return NULL;
     return addr;
 }
 
@@ -211,7 +210,9 @@
     int strlen, bufflen = 128;
     char *exepos;
 
-    code = extract_rcdata (id, &size);
+    code = extract_rcdata (id, TESTRES, &size);
+    if (!code) report (R_FATAL, "Can't find test resource %d: %d",
+                       id, GetLastError ());
     test->name = xmalloc (bufflen);
     while ((strlen = LoadStringA (NULL, id, test->name, bufflen))
            == bufflen - 1) {
@@ -406,11 +407,29 @@
 {
     int nr_of_files = 0, nr_of_tests = 0, i;
     char *tempdir;
-    FILE *logfile;
-    char build_tag[128];
+    int logfile;
+    char *strres, *eol, *nextline;
+    DWORD strsize;
 
     SetErrorMode (SEM_NOGPFAULTERRORBOX);
 
+    if (!logname) {
+        logname = tempnam (0, "res");
+        if (!logname) report (R_FATAL, "Can't name logfile.");
+    }
+    report (R_OUT, logname);
+
+    logfile = open (logname, O_WRONLY | O_CREAT | O_EXCL | O_APPEND,
+                    0666);
+    if (-1 == logfile) {
+        if (EEXIST == errno)
+            report (R_FATAL, "File %s already exists.");
+        else report (R_FATAL, "Could not open logfile: %d", errno);
+    }
+    if (-1 == dup2 (logfile, 1))
+        report (R_FATAL, "Can't redirect stdout: %d", errno);
+    close (logfile);
+
     tempdir = tempnam (0, "wct");
     if (!tempdir)
         report (R_FATAL, "Can't name temporary dir (check %%TEMP%%).");
@@ -418,35 +437,37 @@
     if (!CreateDirectory (tempdir, NULL))
         report (R_FATAL, "Could not create directory: %s", tempdir);
 
-    if (!logname) {
-        logname = tempnam (0, "res");
-        if (!logname) report (R_FATAL, "Can't name logfile.");
-    }
-    report (R_OUT, logname);
-
-    logfile = fopen (logname, "a");
-    if (!logfile) report (R_FATAL, "Could not open logfile.");
-    if (-1 == dup2 (fileno (logfile), 1))
-        report (R_FATAL, "Can't redirect stdout.");
-    fclose (logfile);
-
     xprintf ("Version 3\n");
-    i = LoadStringA (GetModuleHandle (NULL), 0,
-                     build_tag, sizeof build_tag);
-    if (i == 0) report (R_FATAL, "Build descriptor not found: %d",
-                        GetLastError ());
-    if (i >= sizeof build_tag)
-        report (R_FATAL, "Build descriptor too long.");
-    xprintf ("Tests from build %s\n", build_tag);
-    xprintf ("Archive: %s\n", url?url:"");
+    strres = extract_rcdata (WINE_BUILD, STRINGRES, &strsize);
+    xprintf ("Tests from build ");
+    if (strres) xprintf ("%.*s", strsize, strres);
+    else xprintf ("-\n");
+    strres = extract_rcdata (TESTS_URL, STRINGRES, &strsize);
+    xprintf ("Archive: ");
+    if (strres) xprintf ("%.*s", strsize, strres);
+    else xprintf ("-\n");
     xprintf ("Tag: %s\n", tag?tag:"");
     xprintf ("Build info:\n");
+    strres = extract_rcdata (BUILD_INFO, STRINGRES, &strsize);
+    while (strres) {
+        eol = memchr (strres, '\n', strsize);
+        if (!eol) {
+            nextline = NULL;
+            eol = strres + strsize;
+        } else {
+            strsize -= eol - strres + 1;
+            nextline = strsize?eol+1:NULL;
+            if (eol > strres && *(eol-1) == '\r') eol--;
+        }
+        xprintf ("    %.*s\n", eol-strres, strres);
+        strres = nextline;
+    }
     xprintf ("Operating system version:\n");
     print_version ();
     xprintf ("Test output:\n" );
 
     report (R_STATUS, "Counting tests");
-    if (!EnumResourceNames (NULL, TESTRESOURCE,
+    if (!EnumResourceNames (NULL, MAKEINTRESOURCE(TESTRES),
                             EnumTestFileProc, (LPARAM)&nr_of_files))
         report (R_FATAL, "Can't enumerate test files: %d",
                 GetLastError ());
@@ -455,7 +476,7 @@
     report (R_STATUS, "Extracting tests");
     report (R_PROGRESS, 0, nr_of_files);
     for (i = 0; i < nr_of_files; i++) {
-        get_subtests (tempdir, wine_tests+i, i+1);
+        get_subtests (tempdir, wine_tests+i, i);
         nr_of_tests += wine_tests[i].subtest_count;
     }
     report (R_DELTA, 0, "Extracting: Done");
diff --git a/programs/winetest/maketest b/programs/winetest/maketest
index b2bc9ff..4d18b39 100755
--- a/programs/winetest/maketest
+++ b/programs/winetest/maketest
@@ -1,31 +1,26 @@
 #!/bin/sh
 
-if [ -z "$WINE_BUILD" ]; then
-    WINE_BUILD="`date +%Y%m%d.%H%M-auto`"
-    echo "warning: using automatically generated BUILD tag: $WINE_BUILD" 1>&2
-fi
-
 TOPSRCDIR="$1"
 shift
 
 echo "/* Automatically generated -- do not edit! */"
+echo "#include \"resource.h\""
 echo "STRINGTABLE {"
-echo "0 \"$WINE_BUILD\""
 
 i=0
 for test
 do
-    i=`expr $i + 1`
     echo "$i \"$test\""
+    i=`expr $i + 1`
 done
 
-i=30000
+i=0
 cd $TOPSRCDIR
 for dir in dlls/*/tests; do
     sed -ne "s|^/\([^.]*.c\)/\([^/]*\).*|$dir/\1:\2|p" $dir/CVS/Entries 2>/dev/null
 done |\
 while read; do
-    echo "$i \"$REPLY\""
+    echo "REV_INFO+$i \"$REPLY\""
     i=`expr $i + 1`
 done
 
@@ -34,6 +29,6 @@
 i=0
 for test
 do
+    echo "$i TESTRES \"$test\""
     i=`expr $i + 1`
-    echo "$i USERDATA \"$test\""
 done
diff --git a/programs/winetest/guires.h b/programs/winetest/resource.h
similarity index 74%
rename from programs/winetest/guires.h
rename to programs/winetest/resource.h
index 24f0379..1c81e6b 100644
--- a/programs/winetest/guires.h
+++ b/programs/winetest/resource.h
@@ -1,5 +1,5 @@
 /*
- * GUI resource definitions
+ * Resource definitions
  *
  * Copyright 2004 Ferenc Wagner
  *
@@ -15,7 +15,7 @@
  *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
- *
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
 #define IDI_WINE 1
@@ -37,3 +37,17 @@
 
 #define IDC_EDIT  4000
 #define IDC_ABOUT 4001
+
+/* Resource types */
+
+#define TESTRES   1000
+#define STRINGRES 1001
+
+/* String resources */
+
+#define WINE_BUILD 10000
+#define BUILD_INFO 10001
+#define TESTS_URL  10002
+
+/* Revision info strings start from this index: */
+#define REV_INFO 30000
diff --git a/programs/winetest/send.c b/programs/winetest/send.c
index 4385b92..e95fc24 100644
--- a/programs/winetest/send.c
+++ b/programs/winetest/send.c
@@ -15,8 +15,9 @@
  *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
- *
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
+
 #include <winsock.h>
 #include <stdio.h>
 #include <errno.h>
diff --git a/programs/winetest/util.c b/programs/winetest/util.c
index 94da1e8..d09b90b 100644
--- a/programs/winetest/util.c
+++ b/programs/winetest/util.c
@@ -16,8 +16,9 @@
  *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
- *
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
+
 #include <unistd.h>
 #include <errno.h>
 
diff --git a/programs/winetest/winetest.h b/programs/winetest/winetest.h
index 22dbad0..97ea097 100644
--- a/programs/winetest/winetest.h
+++ b/programs/winetest/winetest.h
@@ -16,7 +16,7 @@
  *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
- *
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
 #ifndef __WINETESTS_H
diff --git a/programs/winetest/gui.rc b/programs/winetest/winetest.rc
similarity index 96%
rename from programs/winetest/gui.rc
rename to programs/winetest/winetest.rc
index 5422a87..c9b7b0c 100644
--- a/programs/winetest/gui.rc
+++ b/programs/winetest/winetest.rc
@@ -1,5 +1,5 @@
 /*
- * GUI resources
+ * Winetest resources
  *
  * Copyright 2004 Ferenc Wagner
  *
@@ -15,16 +15,16 @@
  *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
- *
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
 #include <windows.h>
 #include <winres.h>
-#include "guires.h"
-#include "winetest.rc"          /* for the MinGW cross-compiler */
+#include "resource.h"
+#include "tests.rc"
 
 IDD_STATUS DIALOG 0, 0, 160, 140
-STYLE WS_OVERLAPPEDWINDOW
+STYLE WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX
 CAPTION "Wine Test Shell"
 BEGIN
     LTEXT   "Extracting:",       IDC_ST0,        10,   5, 140, 10