[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-13 18:28:28 CET

Julian Foad <julianfoad@btopenworld.com> wrote on 02/13/2006 09:24:07 AM:

> Philip Martin wrote:
> >
> > Lets try and keep that conditional code in one place, rather than in
> > every main faunction. How about a function svn_getopt_int that does
> > all that on EBCDIC platforms and just calls apr_getopt_init on the
> > others? Put it in libsvn_subr/cmdline.c perhaps?
>
> Sorry, I missed the significance of this before. Yes, good idea.
> That will be
> very neat.
>
> - Julian

Julian (& company),

You said to commit this last Friday, but given all the changes since then
I thought it best to post the log and patch again, to make sure this is
what everyone had in mind.

Let me know,

Thanks,

Paul B.

[[[
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 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.

To avoid const restrictions and allow EBCDIC to UTF-8 conversion of
command
line arguments in place, this patch also normalizes the signature of
main()
to the C99 standard, i.e. int main (int argc, char *argv[]), for all
command
line programs.

Approved by: Julian Foad <julianfoad@btopenworld.com>

Suggestions by: Julian, Philip Martin <philip@codematters.co.uk>, and
                Brane <brane@xbc.nu>
 
* subversion/include/svn_cmdline.h
   Include apr_getopt.h
   (svn_cmdline_getopt_init): 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_getopt_init): 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
* subversion/svnversion/main.c
   (main): Change signature to C99 standard. Replace call to
    apr_getopt_init() with new wrapper function svn_cmdline_getopt_init().
]]]

Index: subversion/include/svn_cmdline.h
===================================================================
--- subversion/include/svn_cmdline.h (revision 18446)
+++ subversion/include/svn_cmdline.h (working copy)
@@ -29,6 +29,7 @@
 #define APR_WANT_STDIO
 #endif
 #include <apr_want.h>
+#include <apr_getopt.h>
 
 #include "svn_utf.h"
 #include "svn_auth.h"
@@ -247,6 +248,18 @@
                               void *cancel_baton,
                               apr_pool_t *pool);
 
+/** Wrapper for apr_getopt_init(), which see.
+ *
+ * On OS400 V5R4, prior to calling apr_getopt_init(), converts each of
the
+ * @a argc strings in @a argv[] in place from EBCDIC to UTF-8, allocating
+ * each new UTF-8 string in @a pool.
+ */
+svn_error_t *
+svn_cmdline_getopt_init (apr_getopt_t **os,
+ apr_pool_t *pool,
+ int argc,
+ const char *argv[]);
+
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */
Index: subversion/libsvn_subr/cmdline.c
===================================================================
--- subversion/libsvn_subr/cmdline.c (revision 18446)
+++ 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,30 @@
 
   return SVN_NO_ERROR;
 }
+
+svn_error_t *
+svn_cmdline_getopt_init(apr_getopt_t **os,
+ apr_pool_t *pool,
+ int argc,
+ const char *argv[])
+{
+ apr_status_t apr_err;
+#ifdef AS400_UTF8
+ /* Convert command line args from EBCDIC to UTF-8. */
+ int i;
+ for (i = 0; i < argc; ++i)
+ {
+ char *arg_utf8;
+ SVN_ERR(svn_utf_cstring_to_utf8_ex(&arg_utf8, argv[i], "0",
+ SVN_UTF_ETOU_XLATE_HANDLE,
+ pool));
+ argv[i] = arg_utf8;
+ }
+#endif
+ apr_err = apr_getopt_init (os, pool, argc, argv);
+ if (apr_err)
+ return svn_error_wrap_apr (apr_err,
+ _("Error initializing command line
arguments"));
+ return SVN_NO_ERROR;
+}
+
Index: subversion/svn/main.c
===================================================================
--- subversion/svn/main.c (revision 18446)
+++ subversion/svn/main.c (working copy)
@@ -762,7 +762,7 @@
 /*** Main. ***/
 
 int
-main (int argc, const char * const *argv)
+main(int argc, char *argv[])
 {
   svn_error_t *err;
   apr_allocator_t *allocator;
@@ -831,7 +831,7 @@
     }
 
   /* Else, parse options. */
- apr_getopt_init (&os, pool, argc, argv);
+ svn_cmdline_getopt_init (&os, pool, argc, argv);
   os->interleave = 1;
   while (1)
     {
Index: subversion/svnadmin/main.c
===================================================================
--- subversion/svnadmin/main.c (revision 18446)
+++ subversion/svnadmin/main.c (working copy)
@@ -1136,7 +1136,7 @@
 /** Main. **/
 
 int
-main (int argc, const char * const *argv)
+main(int argc, char *argv[])
 {
   svn_error_t *err;
   apr_status_t apr_err;
@@ -1190,7 +1190,7 @@
   opt_state.end_revision.kind = svn_opt_revision_unspecified;
 
   /* Parse options. */
- apr_getopt_init (&os, pool, argc, argv);
+ svn_cmdline_getopt_init (&os, pool, argc, argv);
   os->interleave = 1;
 
   while (1)
Index: subversion/svndumpfilter/main.c
===================================================================
--- subversion/svndumpfilter/main.c (revision 18446)
+++ subversion/svndumpfilter/main.c (working copy)
@@ -1067,7 +1067,7 @@
 /** Main. **/
 
 int
-main (int argc, const char * const *argv)
+main(int argc, char *argv[])
 {
   svn_error_t *err;
   apr_status_t apr_err;
@@ -1122,7 +1122,7 @@
   opt_state.end_revision.kind = svn_opt_revision_unspecified;
 
   /* Parse options. */
- apr_getopt_init (&os, pool, argc, argv);
+ svn_cmdline_getopt_init (&os, pool, argc, argv);
   os->interleave = 1;
   while (1)
     {
Index: subversion/svnlook/main.c
===================================================================
--- subversion/svnlook/main.c (revision 18446)
+++ subversion/svnlook/main.c (working copy)
@@ -1974,7 +1974,7 @@
 /*** Main. ***/
 
 int
-main (int argc, const char * const *argv)
+main(int argc, char *argv[])
 {
   svn_error_t *err;
   apr_status_t apr_err;
@@ -2027,7 +2027,7 @@
   opt_state.rev = SVN_INVALID_REVNUM;
 
   /* Parse options. */
- apr_getopt_init (&os, pool, argc, argv);
+ svn_cmdline_getopt_init (&os, pool, argc, argv);
   os->interleave = 1;
   while (1)
     {
Index: subversion/svnserve/main.c
===================================================================
--- subversion/svnserve/main.c (revision 18446)
+++ subversion/svnserve/main.c (working copy)
@@ -256,7 +256,7 @@
 }
 
 
-int main(int argc, const char *const *argv)
+int main(int argc, char *argv[])
 {
   enum run_mode run_mode = run_mode_unspecified;
   svn_boolean_t foreground = FALSE;
@@ -313,7 +313,7 @@
       return EXIT_FAILURE;
     }
 
- apr_getopt_init(&os, pool, argc, argv);
+ svn_cmdline_getopt_init(&os, pool, argc, argv);
 
   params.root = "/";
   params.tunnel = FALSE;
Index: subversion/svnsync/main.c
===================================================================
--- subversion/svnsync/main.c (revision 18446)
+++ subversion/svnsync/main.c (working copy)
@@ -1154,7 +1154,7 @@
 }
 
 int
-main (int argc, const char * const argv[])
+main(int argc, char *argv[])
 {
   const svn_opt_subcommand_desc_t *subcommand = NULL;
   apr_array_header_t *received_opts;
@@ -1200,7 +1200,7 @@
       return EXIT_FAILURE;
     }
 
- apr_getopt_init (&os, pool, argc, argv);
+ svn_cmdline_getopt_init (&os, pool, argc, argv);
 
   os->interleave = 1;
 
Index: subversion/svnversion/main.c
===================================================================
--- subversion/svnversion/main.c (revision 18446)
+++ subversion/svnversion/main.c (working copy)
@@ -106,7 +106,7 @@
  * program. Obviously we don't want to have to run svn when building
svn.
  */
 int
-main(int argc, const char *argv[])
+main(int argc, char *argv[])
 {
   const char *wc_path, *trail_url;
   apr_allocator_t *allocator;
@@ -163,7 +163,7 @@
     }
 #endif
 
- apr_getopt_init(&os, pool, argc, argv);
+ svn_cmdline_getopt_init(&os, pool, argc, argv);
   os->interleave = 1;
   while (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 Mon Feb 13 18:32:10 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.