apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wr...@apache.org
Subject cvs commit: apr/misc/win32 apr_app.c
Date Wed, 30 Jan 2002 03:15:32 GMT
wrowe       02/01/29 19:15:32

  Modified:    misc/win32 apr_app.c
  Log:
    The 'second way' - not yet published in a .h file.  This would allow
    a win32 app to fix up the environment and args to our apr-adopted utf-8,
    allowing absolutely any input, in any local codepage, to be handled by
    Apache [even though we did _not_ use a wmainCRTStartup entry point.]
  
    Not tested - next fix is to prevent people from coding to both methods
    [or provide a quick fix so it becomes a noop.]  Find a place a write a
    dummy for unix (simply return APR_SUCCESS is sufficient.)  Then this
    module can be extended first for services, then for signals.
  
  Revision  Changes    Path
  1.6       +91 -7     apr/misc/win32/apr_app.c
  
  Index: apr_app.c
  ===================================================================
  RCS file: /home/cvs/apr/misc/win32/apr_app.c,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- apr_app.c	29 Jan 2002 15:18:48 -0000	1.5
  +++ apr_app.c	30 Jan 2002 03:15:32 -0000	1.6
  @@ -71,14 +71,13 @@
    *   since we are single threaded [so far].
    */
   
  -#include "apr_private.h"
   #include "apr_general.h"
  +#include "ShellAPI.h"
  +#include "crtdbg.h"
   #include "wchar.h"
   #include "fileio.h"
   #include "assert.h"
  -#include <crtdbg.h>
  -
  -extern int main(int argc, char **argv, char **env);
  +#include "apr_private.h"
   
   static int wastrtoastr(char ***retarr, wchar_t **arr, int args)
   {
  @@ -93,7 +92,7 @@
               ;
       }
   
  -    newarr = _malloc_dbg(args * sizeof(char *),
  +    newarr = _malloc_dbg((args + 1) * sizeof(char *),
                            _CRT_BLOCK, __FILE__, __LINE__);
   
       for (arg = 0; arg < args; ++arg) {
  @@ -120,11 +119,11 @@
   
           newlen -= elesize;
           ele += newlen;
  -        assert(elesize);
  +        assert(elesize && (len == 0));
       }
   
       newarr[arg] = NULL;
  -    *ele = '\0';
  +    *(ele++) = '\0';
   
       /* Return to the free store if the heap realloc is the least bit optimized
        */
  @@ -142,6 +141,10 @@
       return args;
   }
   
  +#ifdef APR_APP
  +
  +extern int main(int argc, char **argv, char **env);
  +
   int wmain(int argc, wchar_t **wargv, wchar_t **wenv)
   {
       char **argv;
  @@ -171,3 +174,84 @@
   
       return main(argc, argv, env);
   }
  +
  +#else
  +
  +static int warrsztoastr(char ***retarr, wchar_t *arrsz, int args)
  +{
  +    apr_wchar_t *wch;
  +    size_t totlen;
  +    size_t newlen;
  +    size_t wsize;
  +    char **newarr;
  +    int arg;
  +
  +    if (args < 0) {
  +        for (args = 1, wch = arrsz; wch[0] || wch[1]; ++wch)
  +            if (!*wch) 
  +                ++args;
  +    }
  +    wsize = 1 + wch - arrsz;
  +
  +    newarr = _malloc_dbg((args + 1) * sizeof(char *),
  +                         _CRT_BLOCK, __FILE__, __LINE__);
  +
  +    /* This is a safe max allocation, we will realloc after
  +     * processing and return the excess to the free store.
  +     * 3 ucs bytes hold any single wchar_t value (16 bits)
  +     * 4 ucs bytes will hold a wchar_t pair value (20 bits)
  +     */
  +    newlen = totlen = wsize * 3 + 1;
  +    newarr[0] = _malloc_dbg(newlen * sizeof(char), 
  +                            _CRT_BLOCK, __FILE__, __LINE__);
  +
  +    (void)apr_conv_ucs2_to_utf8(arrsz, &wsize,
  +                                newarr[0], &newlen);
  +
  +    assert(newlen && !wsize);
  +    /* Return to the free store if the heap realloc is the least bit optimized
  +     */
  +    newarr[0] = _realloc_dbg(newarr[0], totlen - newlen, 
  +                             _CRT_BLOCK, __FILE__, __LINE__);
  +
  +    for (arg = 1; arg < args; ++arg) {
  +        newarr[arg] = newarr[arg - 1] + 2;
  +        while (*(newarr[arg]++)) {
  +            ;
  +        }
  +    }
  +
  +    newarr[arg] = NULL;
  +
  +    *retarr = newarr;
  +    return args;
  +}
  +
  +/* Reprocess the arguments to main() for a completely apr-ized application
  + */
  +
  +APR_DECLARE(apr_status_t) apr_main(int *argc, char ***argv, char ***env)
  +{
  +#if APR_HAS_UNICODE_FS
  +    IF_WIN_OS_IS_UNICODE
  +    {
  +        apr_wchar_t **wstrs;
  +        apr_wchar_t *sysstr;
  +        int wstrc;
  +
  +        sysstr = GetCommandLineW();
  +        if (sysstr) {
  +            wstrs = CommandLineToArgvW(sysstr, &wstrc);
  +            if (wstrs) {
  +                *argc = wastrtoastr(argv, wstrs, wstrc);
  +                GlobalFree(wstrs);
  +            }
  +        }
  +
  +        sysstr = GetEnvironmentStringsW();
  +    }
  +#endif
  +    return APR_SUCCESS;
  +}
  +
  +#endif
  \ No newline at end of file
  
  
  

Mime
View raw message