Author: fireball
Date: Thu Dec 20 16:11:30 2007
New Revision: 31352
URL: 
http://svn.reactos.org/svn/reactos?rev=31352&view=rev
Log:
- Implement bin-files creation (as opposed to inlining resource data, which is
incompatible with MSVC). Result matches 1:1 with mc.exe output on the same input file.
- This patch was submitted to Wine, but it needs to be reworked.
Modified:
    trunk/reactos/tools/wmc/utils.c
    trunk/reactos/tools/wmc/utils.h
    trunk/reactos/tools/wmc/wmc.c
    trunk/reactos/tools/wmc/write.c
    trunk/reactos/tools/wmc/write.h
Modified: trunk/reactos/tools/wmc/utils.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/wmc/utils.c?rev=3135…
==============================================================================
--- trunk/reactos/tools/wmc/utils.c (original)
+++ trunk/reactos/tools/wmc/utils.c Thu Dec 20 16:11:30 2007
@@ -131,6 +131,20 @@
                base[namelen - extlen] = '\0';
        }
        return base;
+}
+
+void get_rcbasedir(char *basedir, const char *name)
+{
+       char *slash;
+       slash = strrchr(name, '/');
+
+       if (!slash)
+               slash = strrchr(name, '\\');
+
+       basedir[0] = 0;
+
+       strncpy(basedir, name, slash - name + 1);
+       basedir[slash-name + 1] = '\0';
 }
 void *xmalloc(size_t size)
Modified: trunk/reactos/tools/wmc/utils.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/wmc/utils.h?rev=3135…
==============================================================================
--- trunk/reactos/tools/wmc/utils.h (original)
+++ trunk/reactos/tools/wmc/utils.h Thu Dec 20 16:11:30 2007
@@ -41,6 +41,7 @@
 void warning(const char *s, ...) __attribute__((format (printf, 1, 2)));
 char *dup_basename(const char *name, const char *ext);
+void get_rcbasedir(char *basedir, const char *name);
 WCHAR *xunistrdup(const WCHAR * str);
 WCHAR *unistrcpy(WCHAR *dst, const WCHAR *src);
Modified: trunk/reactos/tools/wmc/wmc.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/wmc/wmc.c?rev=31352&…
==============================================================================
--- trunk/reactos/tools/wmc/wmc.c (original)
+++ trunk/reactos/tools/wmc/wmc.c Thu Dec 20 16:11:30 2007
@@ -138,6 +138,7 @@
        int ret;
        int i;
        int cmdlen;
+       char rcbasedir[MAX_PATH];
        atexit( cleanup_files );
        signal(SIGSEGV, segvhandler);
@@ -265,6 +266,8 @@
                strcat(header_name, ".h");
        }
+       get_rcbasedir(rcbasedir, output_name);
+
        if(input_name)
        {
                if(!(yyin = fopen(input_name, "rb")))
@@ -287,7 +290,7 @@
        write_h_file(header_name);
        write_rc_file(output_name);
        if(!rcinline)
-               write_bin_files();
+               write_bin_files(rcbasedir);
        output_name = NULL;
        header_name = NULL;
        return 0;
Modified: trunk/reactos/tools/wmc/write.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/wmc/write.c?rev=3135…
==============================================================================
--- trunk/reactos/tools/wmc/write.c (original)
+++ trunk/reactos/tools/wmc/write.c Thu Dec 20 16:11:30 2007
@@ -509,7 +509,110 @@
        fclose(fp);
 }
-void write_bin_files(void)
-{
-       assert(rcinline == 0);
-}
+static void write_bin_file(const char *fname, lan_blk_t *lbp)
+{
+       FILE *fp;
+       unsigned int offs;
+       unsigned short buf;
+       int i, j, k;
+
+       fp = fopen(fname, "wb");
+
+       fwrite(&lbp->nblk, sizeof(int), 1, fp);
+
+       offs = 4 * (lbp->nblk * 3 + 1);
+       for(i = 0; i < lbp->nblk; i++)
+       {
+               fwrite(&lbp->blks[i].idlo, sizeof(unsigned), 2, fp);
+               fwrite(&offs, sizeof(int), 1, fp);
+
+               offs += lbp->blks[i].size;
+       }
+
+       for(i = 0; i < lbp->nblk; i++)
+       {
+               block_t *blk = &lbp->blks[i];
+               for(j = 0; j < blk->nmsg; j++)
+               {
+                       char *cptr;
+                       int len = blk->msgs[j]->len;
+                       short aligned_size = (unicodeout ? (len*2+3)&~3 :
(len+3)&~3) + 4;
+
+                       fwrite(&aligned_size, sizeof(short), 1, fp);
+
+                       buf = unicodeout ? 1 : 0;
+                       fwrite(&buf, sizeof(buf), 1, fp);
+
+                       // no need to count these 4 bytes when calculating alignment
+                       aligned_size -= 4;
+
+                       if (unicodeout)
+                       {
+                               fwrite(blk->msgs[j]->msg, sizeof(WCHAR), len, fp);
+
+                               // fill with nulls so it matches aligned_len
+                               for (k=0; k<(aligned_size-(len*sizeof(WCHAR))); k++)
+                                       fputc(0, fp);
+                       }
+                       else
+                       {
+                               WCHAR *uc;
+                               char *tmp;
+                               int mlen, len;
+                               const union cptable *cpdef =
find_codepage(blk->msgs[j]->cp);
+                               uc = blk->msgs[j]->msg;
+
+                               assert(cpdef != NULL);
+                               mlen = wine_cp_wcstombs(cpdef, 0, uc, unistrlen(uc)+1,
NULL, 0, NULL, NULL);
+                               tmp = xmalloc(mlen);
+                               if((i = wine_cp_wcstombs(cpdef, 0, uc, unistrlen(uc)+1,
tmp, mlen, NULL, NULL)) < 0)
+                                       internal_error(__FILE__, __LINE__, "Buffer
overflow? code %d\n", i);
+
+                               len = strlen(tmp);
+                               fwrite(tmp, sizeof(char), len, fp);
+
+                               // fill with nulls so it matches aligned_len
+                               for (k=0; k<(aligned_size-len); k++)
+                                       fputc(0, fp);
+
+                               free(tmp);
+                       }
+
+                       free(cptr);
+               }
+       }
+
+       fclose(fp);
+}
+
+void write_bin_files(const char *basedir)
+{
+       lan_blk_t *lbp;
+       token_t *ttab;
+       char fname[MAX_PATH];
+       int ntab;
+       int i;
+
+       get_tokentable(&ttab, &ntab);
+
+       for(lbp = lanblockhead; lbp; lbp = lbp->next)
+       {
+               char *cptr = NULL;
+               for(i = 0; i < ntab; i++)
+               {
+                       if(ttab[i].type == tok_language && ttab[i].token ==
lbp->lan)
+                       {
+                               if(ttab[i].alias)
+                                       cptr = dup_u2c(WMC_DEFAULT_CODEPAGE,
ttab[i].alias);
+                               break;
+                       }
+               }
+               if(!cptr)
+                       internal_error(__FILE__, __LINE__, "Filename vanished for
language 0x%0x\n", lbp->lan);
+
+               sprintf(fname, "%s%s.bin", basedir, cptr);
+               write_bin_file(fname, lbp);
+
+               free(cptr);
+       }
+}
Modified: trunk/reactos/tools/wmc/write.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/wmc/write.h?rev=3135…
==============================================================================
--- trunk/reactos/tools/wmc/write.h (original)
+++ trunk/reactos/tools/wmc/write.h Thu Dec 20 16:11:30 2007
@@ -22,6 +22,6 @@
 void write_h_file(const char *fname);
 void write_rc_file(const char *fname);
-void write_bin_files(void);
+void write_bin_files(const char *basedir);
 #endif