[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: [PATCH] #1 Update on port to OS400/EBCDIC

From: Paul Burba <paulb_at_softlanding.com>
Date: 2006-02-10 21:35:24 CET

Julian Foad <julianfoad@btopenworld.com> wrote on 02/10/2006 02:20:47 PM:

> Indeed casting away "const" is generally wrong. You've just got a
> bit confused
> over the use of "const", which is hardly surprising with so many levels
of
> indirection going on in this pointer. See below.
 
Following you direction I fixed it, new log and patch below. Thanks!
 
> > In hindsight I should have presented that next patch first, since this

> > (argv) patch is dependent on it. Briefly, this is because IBM uses
ints
> > not strings as arguments to the apr_xlate_* functions. So a call like

> > "svn_utf_cstring_to_utf8_ex (&argv_utf8[i], (*argv)[i], "0",
> > SVN_UTF_ETOU_XLATE_HANDLE, pool)" in this patch won't work without the

> > upcoming patch which converts "0" to 0.
>
> OK... maybe. I'm afraid I don't understand the encoding parameters
> so I can't
> comment on that aspect. This present patch does compile, though?

Yes, it does compile. Hopefully my next patch will clear this up some.
 
> > Index: subversion/include/svn_cmdline.h
> > ===================================================================
> [...]
> > +#ifdef AS400_UTF8
> > +/** Convert each of the @argc strings in @argv from ebcdic to utf-8.
> > + * @a pool is used for all allocations.
> > + */
>
> That would be, "@a argc" and "@a argv" for Doxygen notation.
>
> Let's rename the argument to "argv_p", as it's a pointer to what's
normally
> called "argv", and this is just too confusing otherwise!
>
> Be a bit more explicit about what this function actually does with its
> parameters. So, something like:
>
> /** Convert each of the @a argc strings in @a *argv_p from ebcdicto
utf-8.
> * Replace @a *argv_p with a pointer to a new array of the new
strings, all
> * allocated in @a pool.
> */
>
> (or being even more explicit wouldn't hurt; this is still a bit opaque).

Spelled it out a bit clearer, with valid Doxygen notation.
 
> > +svn_error_t *
> > +svn_cmdline_args_from_ebcdic (int argc,
> > + char * const * const *argv,
> > + apr_pool_t *pool);
>
> I think you've got the "const"s in the wrong place; this presently says
that
> the individual characters are writable (which isn't what's wanted)
> and that the
> argument itself points to something constant, whereas you want to
> write to what
> the argument points to. So:
>
> const char *const **argv_p,
>
>
> > Index: subversion/libsvn_subr/cmdline.c
> > ===================================================================
> > --- subversion/libsvn_subr/cmdline.c (revision 18362)
> > +++ subversion/libsvn_subr/cmdline.c (working copy)
> > @@ -46,6 +46,10 @@
> > #define SVN_UTF_CONTOU_XLATE_HANDLE "svn-utf-contou-xlate-handle"
> > #define SVN_UTF_UTOCON_XLATE_HANDLE "svn-utf-utocon-xlate-handle"
> >
> > +#ifdef AS400_UTF8
> > +#define SVN_UTF_ETOU_XLATE_HANDLE "svn_utf-etou_xlate_handle"
>
> In this value (between the quotes), can we have all dashes rather than
mixing
> with some underscores, to match the style of the existing handles just
above.

Sorry that was a typo, fixed.

> > @@ -446,3 +450,22 @@
> > +
> > +#ifdef AS400_UTF8
> > +svn_error_t *
> > +svn_cmdline_args_from_ebcdic (int argc,
> > + char * const * const *argv,
> > + apr_pool_t *pool)
> > +{
> > + int i;
> > + char **argv_utf8 = apr_palloc (pool, sizeof(char *) * argc);
>
> Then if you declare this as "const char **"...
>
> > + for (i = 0; i < argc; i++)
> > + {
> > + SVN_ERR (svn_utf_cstring_to_utf8_ex (&argv_utf8[i], (*argv)[i],
"0",
>
> ... it will firstly pass the right kind of pointer as the first arg
> here (I was
> getting a warning) ...
>
> > + SVN_UTF_ETOU_XLATE_HANDLE,
> > + pool));
> > + }
> > + *((char***)argv) = argv_utf8;
>
> ... and then you won't need any cast at all here, and all is well.

That works, thanks for the pointers <cue collective groan from the crowd>,
I knew I was doing *something* screwy.
 
> > + return SVN_NO_ERROR;
> > +}
> > +#endif
> > \ No newline at end of file
>
> Oops - please let the last line of the file end with a newline
character. It
> would be a trivial matter except that it's an error to some
> compilers (at least
> it was an error if it occurred on a preprocessor line on one compiler
that I
> used to use).

Done.

[[[
OS400/EBCDIC Port: Convert command-line arguments from EBCDIC to UTF-8.

This is the first of several patches to allow Subversion to run on under
IBM's OS400 V5R4. Despite IBM's building of APR/Apache with UTF support
in V5R4, command line arguments to main() are still encoded in EBCDIC.

* subversion/include/svn_cmdline.h
   (svn_cmdline_args_from_ebcdic): New function declaration.

* subversion/libsvn_subr/cmdline.c
   (SVN_UTF_ETOU_XLATE_HANDLE): New xlate key for EBCDIC (CCSID 0) to
    UTF-8 (CCSID 1208) conversions.
   (svn_cmdline_args_from_ebcdic): New function definition.

* subversion/svn/main.c
* subversion/svnadmin/main.c
* subversion/svndumpfilter/main.c
* subversion/svnlook/main.c
* subversion/svnserve/main.c
* subversion/svnsync/main.c
   (main): Convert command line arguments from EBCDIC to UTF-8
    with svn_cmdline_args_from_ebcdic().
]]]

Index: subversion/include/svn_cmdline.h
===================================================================
--- subversion/include/svn_cmdline.h (revision 18362)
+++ subversion/include/svn_cmdline.h (working copy)
@@ -247,6 +247,17 @@
                               void *cancel_baton,
                               apr_pool_t *pool);
 
+#ifdef AS400_UTF8
+/** Convert each of the @a argc strings in @a *argv_p from EBCDIC to
UTF-8,
+ * storing each UTF-8 string in a new array of strings allocated in
+ * @a pool. Replace @a *argv_p with the new array of UTF-8 strings.
+ */
+svn_error_t *
+svn_cmdline_args_from_ebcdic (int argc,
+ const char *const **argv_p,
+ apr_pool_t *pool);
+#endif
+
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */
Index: subversion/libsvn_subr/cmdline.c
===================================================================
--- subversion/libsvn_subr/cmdline.c (revision 18362)
+++ subversion/libsvn_subr/cmdline.c (working copy)
@@ -46,6 +46,10 @@
 #define SVN_UTF_CONTOU_XLATE_HANDLE "svn-utf-contou-xlate-handle"
 #define SVN_UTF_UTOCON_XLATE_HANDLE "svn-utf-utocon-xlate-handle"
 
+#ifdef AS400_UTF8
+#define SVN_UTF_ETOU_XLATE_HANDLE "svn-utf-etou-xlate-handle"
+#endif
+
 /* The stdin encoding. If null, it's the same as the native encoding. */
 static const char *input_encoding = NULL;
 
@@ -446,3 +450,23 @@
 
   return SVN_NO_ERROR;
 }
+
+#ifdef AS400_UTF8
+svn_error_t *
+svn_cmdline_args_from_ebcdic (int argc,
+ const char *const **argv_p,
+ apr_pool_t *pool)
+{
+ int i;
+ const char **argv_utf8 = apr_palloc (pool, sizeof(char *) * argc);
+ for (i = 0; i < argc; i++)
+ {
+ SVN_ERR (svn_utf_cstring_to_utf8_ex (&argv_utf8[i], (*argv_p)[i],
"0",
+ SVN_UTF_ETOU_XLATE_HANDLE,
+ pool));
+ }
+ *argv_p = argv_utf8;
+ return SVN_NO_ERROR;
+}
+#endif
+
Index: subversion/svn/main.c
===================================================================
--- subversion/svn/main.c (revision 18362)
+++ subversion/svn/main.c (working copy)
@@ -830,6 +830,10 @@
       return EXIT_FAILURE;
     }
 
+#ifdef AS400_UTF8
+ SVN_INT_ERR (svn_cmdline_args_from_ebcdic (argc, &argv, pool));
+#endif
+
   /* Else, parse options. */
   apr_getopt_init (&os, pool, argc, argv);
   os->interleave = 1;
Index: subversion/svnadmin/main.c
===================================================================
--- subversion/svnadmin/main.c (revision 18362)
+++ subversion/svnadmin/main.c (working copy)
@@ -1178,6 +1178,10 @@
   opt_state.start_revision.kind = svn_opt_revision_unspecified;
   opt_state.end_revision.kind = svn_opt_revision_unspecified;
 
+#ifdef AS400_UTF8
+ SVN_INT_ERR (svn_cmdline_args_from_ebcdic (argc, &argv, pool));
+#endif
+
   /* Parse options. */
   apr_getopt_init (&os, pool, argc, argv);
   os->interleave = 1;
Index: subversion/svndumpfilter/main.c
===================================================================
--- subversion/svndumpfilter/main.c (revision 18362)
+++ subversion/svndumpfilter/main.c (working copy)
@@ -1121,6 +1121,10 @@
   opt_state.start_revision.kind = svn_opt_revision_unspecified;
   opt_state.end_revision.kind = svn_opt_revision_unspecified;
 
+#ifdef AS400_UTF8
+ SVN_INT_ERR (svn_cmdline_args_from_ebcdic (argc, &argv, pool));
+#endif
+
   /* Parse options. */
   apr_getopt_init (&os, pool, argc, argv);
   os->interleave = 1;
Index: subversion/svnlook/main.c
===================================================================
--- subversion/svnlook/main.c (revision 18362)
+++ subversion/svnlook/main.c (working copy)
@@ -2026,6 +2026,10 @@
   memset (&opt_state, 0, sizeof (opt_state));
   opt_state.rev = SVN_INVALID_REVNUM;
 
+#ifdef AS400_UTF8
+ SVN_INT_ERR (svn_cmdline_args_from_ebcdic (argc, &argv, pool));
+#endif
+
   /* Parse options. */
   apr_getopt_init (&os, pool, argc, argv);
   os->interleave = 1;
Index: subversion/svnserve/main.c
===================================================================
--- subversion/svnserve/main.c (revision 18362)
+++ subversion/svnserve/main.c (working copy)
@@ -313,6 +313,10 @@
       return EXIT_FAILURE;
     }
 
+#ifdef AS400_UTF8
+ SVN_INT_ERR (svn_cmdline_args_from_ebcdic (argc, &argv, pool));
+#endif
+
   apr_getopt_init(&os, pool, argc, argv);
 
   params.root = "/";
Index: subversion/svnsync/main.c
===================================================================
--- subversion/svnsync/main.c (revision 18362)
+++ subversion/svnsync/main.c (working copy)
@@ -1200,6 +1200,10 @@
       return EXIT_FAILURE;
     }
 
+#ifdef AS400_UTF8
+ SVN_INT_ERR (svn_cmdline_args_from_ebcdic (argc, &argv, pool));
+#endif
+
   apr_getopt_init (&os, pool, argc, argv);
 
   os->interleave = 1;

_____________________________________________________________________________
Scanned for SoftLanding Systems, Inc. and SoftLanding Europe Plc by IBM Email Security Management Services powered by MessageLabs.
_____________________________________________________________________________

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Fri Feb 10 21:36:35 2006

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.