You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@stdcxx.apache.org by Andrew Black <ab...@roguewave.com> on 2007/04/10 19:47:56 UTC

Re: svn commit: r526304 - in /incubator/stdcxx/trunk: etc/config/GNUmakefile.bin util/locale.cpp util/locale_stub.cpp util/localedef.cpp

Greetings Farid

At some point it'll be necessary to replicate this change to the 
makefile in the windows infrastructure.  Until this happens, we'll be 
observing failures on windows, caused by an inability to build the 
locale utilities.  While I might be able to fix this myself, it would 
likely be more efficient, time-wise, for you to make the change as you 
are more familiar with the solution generator code.

--Andrew Black

sebor@apache.org wrote:
> Author: sebor
> Date: Fri Apr  6 15:34:41 2007
> New Revision: 526304
> 
> URL: http://svn.apache.org/viewvc?view=rev&rev=526304
> Log:
> 2007-04-06  Martin Sebor  <se...@roguewave.com>
> 
> 	STDCXX-386
> 	* locale.cpp (main): Renamed...
> 	(locale_main): ...to this and removed exception handling.
> 	(print_mon): Added missing comma.
> 	* localedef.cpp (main): Renamed...
> 	(localedef_main): ...to this and removed exception handling.
> 	(main): Invoked locale_main() or localedef_main() depending on whether
> 	the first command line option is the special keyword "--locale-mode"
> 	or something else. Handled exceptions from either function.
> 	* locale_stub.cpp: New. Invokes localedef --locale-mode ...
> 	* GNUmakefile.bin (localedef): Added a dependency on locale.o and
> 	memchk.o.
> 	(locale): Replaced all dependencies with one on locale_stub.o so
> 	as to avoid linking the same object files into more than one program.
> 
> Added:
>     incubator/stdcxx/trunk/util/locale_stub.cpp   (with props)
> Modified:
>     incubator/stdcxx/trunk/etc/config/GNUmakefile.bin
>     incubator/stdcxx/trunk/util/locale.cpp
>     incubator/stdcxx/trunk/util/localedef.cpp
> 
> Modified: incubator/stdcxx/trunk/etc/config/GNUmakefile.bin
> URL: http://svn.apache.org/viewvc/incubator/stdcxx/trunk/etc/config/GNUmakefile.bin?view=diff&rev=526304&r1=526303&r2=526304
> ==============================================================================
> --- incubator/stdcxx/trunk/etc/config/GNUmakefile.bin (original)
> +++ incubator/stdcxx/trunk/etc/config/GNUmakefile.bin Fri Apr  6 15:34:41 2007
> @@ -69,17 +69,15 @@
>  	$(LD) $^ -o $@ $(LDFLAGS.exec) $(LDLIBS) $(call CXX.repo,$<) $(TEEOPTS)
>  
>  # link the localedef utility
> -localedef: localedef.o aliases.o charmap.o codecvt.o collate.o ctype.o \
> -           def.o diagnostic.o messages.o monetary.o numeric.o path.o   \
> -           time.o scanner.o
> +localedef: localedef.o locale.o aliases.o charmap.o codecvt.o collate.o \
> +           ctype.o def.o diagnostic.o memchk.o messages.o monetary.o    \
> +           numeric.o path.o time.o scanner.o
>  	@echo "$(LD) $^ -o $@ $(LDFLAGS) $(LDLIBS)" $(call CXX.repo,$<) \
>  	>> $(LOGFILE)
>  	$(LD) $^ -o $@ $(LDFLAGS) $(LDLIBS) $(call CXX.repo,$<) $(TEEOPTS)
>  
>  # link the locale utility
> -locale: locale.o aliases.o charmap.o codecvt.o collate.o def.o ctype.o \
> -        diagnostic.o memchk.o messages.o monetary.o numeric.o path.o   \
> -        scanner.o time.o
> +locale: locale_stub.o
>  	@echo "$(LD) $^ -o $@ $(LDFLAGS) $(LDLIBS)" $(call CXX.repo,$<) \
>  	>> $(LOGFILE)
>  	$(LD) $^ -o $@ $(LDFLAGS) $(LDLIBS) $(call CXX.repo,$<) $(TEEOPTS)
> 
> Modified: incubator/stdcxx/trunk/util/locale.cpp
> URL: http://svn.apache.org/viewvc/incubator/stdcxx/trunk/util/locale.cpp?view=diff&rev=526304&r1=526303&r2=526304
> ==============================================================================
> --- incubator/stdcxx/trunk/util/locale.cpp (original)
> +++ incubator/stdcxx/trunk/util/locale.cpp Fri Apr  6 15:34:41 2007
> @@ -1924,7 +1924,7 @@
>  print_mon (const char *keyword, int print_cat)
>  {
>      static const char str[][10] = {
> -        "January", "February", "March", "April", "May", "June"
> +        "January", "February", "March", "April", "May", "June",
>          "July", "August", "September", "October", "November", "December"
>      };
>  
> @@ -2816,130 +2816,113 @@
>  };
>  
>  
> -int main (int argc, char *argv[])
> +int locale_main (int argc, char *argv[])
>  {
> -    try {
> -        const char* const program_name = argv [0];
> +    const char* const program_name = argv [0];
>  
> -        if (1 == argc) {
> -            // print all localization environment variables
> -            print_lc_vars ();
> -        }
> -        else {
> -            init_sections ();
> +    if (1 == argc) {
> +        // print all localization environment variables
> +        print_lc_vars ();
> +    }
> +    else {
> +        init_sections ();
>  
> -            --argc;
> +        --argc;
>  
> -            while (0 != *++argv && 0 < argc-- && '-' == **argv) {
> +        while (0 != *++argv && 0 < argc-- && '-' == **argv) {
>  
> -                switch (*++*argv) {
> +            switch (*++*argv) {
>  
> -                case 'a':
> -                    // -a: print the names of all installed locales
> -                    print_locale_names ();
> -                    return EXIT_SUCCESS;
> +            case 'a':
> +                // -a: print the names of all installed locales
> +                print_locale_names ();
> +                return EXIT_SUCCESS;
>  
> -                case 'k':
> -                    // -k: print the names of keywords when printing
> -                    //     their values
> +            case 'k':
> +                // -k: print the names of keywords when printing
> +                //     their values
> +                print_keywords = true;
> +                break;
> +
> +            case 'c':
> +                // -c[k]: print the name of each section
> +                print_sect_names = true;
> +                if (*(*argv + 1) == 'k')
>                      print_keywords = true;
> -                    break;
> +                break;
>  
> -                case 'c':
> -                    // -c[k]: print the name of each section
> -                    print_sect_names = true;
> -                    if (*(*argv + 1) == 'k')
> -                        print_keywords = true;
> -                    break;
> +            case 'm':
> +                print_charmap_names ();
> +                return EXIT_SUCCESS;
> +
> +            case 'h':
> +                // -h: use character names from the original charmap
> +                //     used by localedef to build the locale (if possible)
> +                decode = true;
> +                break;
>  
> -                case 'm':
> -                    print_charmap_names ();
> -                    return EXIT_SUCCESS;
> +            case 'l':
> +                // -l: produce output suitable as input for processing
> +                //     by the localedef utility
> +                posix_output = false;
> +                break;
> +
> +            case 'p':
> +                // -p: produce output using symbols from the Portable
> +                //     Character Set whenever possible
> +                use_pcs      = true;
> +                posix_output = false;
> +                break;
> +
> +            case 'w':
> +                if (std::strlen (*argv) == 1)
> +                    issue_diag (W_DISABLE, 0, 0, 0);
> +                else
> +                    issue_diag (std::atoi (++*argv), 0, 0, 0);
> +                break;
>  
> -                case 'h':
> -                    // -h: use character names from the original charmap
> -                    //     used by localedef to build the locale (if possible)
> -                    decode = true;
> -                    break;
> -
> -                case 'l':
> -                    // -l: produce output suitable as input for processing
> -                    //     by the localedef utility
> -                    posix_output = false;
> -                    break;
> -
> -                case 'p':
> -                    // -p: produce output using symbols from the Portable
> -                    //     Character Set whenever possible
> -                    use_pcs      = true;
> -                    posix_output = false;
> -                    break;
> -
> -                case 'w':
> -                    if (std::strlen (*argv) == 1)
> -                        issue_diag (W_DISABLE, 0, 0, 0);
> -                    else
> -                        issue_diag (std::atoi (++*argv), 0, 0, 0);
> -                    break;
> +            case '?':
> +                print_help ();
> +                return EXIT_SUCCESS;
>  
> -                case '?':
> +            case '-':
> +                if (0 == std::strcmp (*argv, "-help")) {
>                      print_help ();
>                      return EXIT_SUCCESS;
> +                }
>  
> -                case '-':
> -                    if (0 == std::strcmp (*argv, "-help")) {
> -                        print_help ();
> -                        return EXIT_SUCCESS;
> -                    }
> -
> -                    if (0 == std::strcmp (*argv, "-charmap")) {
> -                        print_charmap ();
> -                        return EXIT_SUCCESS;
> -                    }
> -
> -                    // fall through...
> -
> -                default:
> -                    issue_diag (504, true, 0, "%s: invalid option "
> -                                "-%s\n", program_name, *argv);
> +                if (0 == std::strcmp (*argv, "-charmap")) {
> +                    print_charmap ();
> +                    return EXIT_SUCCESS;
>                  }
> -            }
>  
> -            if (0 == *argv) {
> -                issue_diag (505, true, 0, "%s: missing argument\n Try '"
> -                            "%s --help'\n", program_name, program_name);
> +                // fall through...
> +
> +            default:
> +                issue_diag (504, true, 0, "%s: invalid option "
> +                            "-%s\n", program_name, *argv);
>              }
> +        }
>  
> -            for (; 0 != *argv; ++argv) {
> +        if (0 == *argv) {
> +            issue_diag (505, true, 0, "%s: missing argument\n Try '"
> +                        "%s --help'\n", program_name, program_name);
> +        }
> +
> +        for (; 0 != *argv; ++argv) {
>  
> -                for (std::size_t i = 0; handlers [i].name; ++i) {
> -                    if (0 == std::strcmp (*argv, handlers [i].name)) {
> +            for (std::size_t i = 0; handlers [i].name; ++i) {
> +                if (0 == std::strcmp (*argv, handlers [i].name)) {
>  
> -                        const int arg =
> -                            -1 == handlers [i].arg ? print_sect_names
> -                                                   : handlers [i].arg;
> +                    const int arg =
> +                        -1 == handlers [i].arg ? print_sect_names
> +                        : handlers [i].arg;
>  
> -                        handlers [i].print (handlers [i].name, arg);
> -                    }
> +                    handlers [i].print (handlers [i].name, arg);
>                  }
>              }
>          }
>      }
> -    catch (loc_exception&) {
> -        return 1;
> -    }
> -    catch (const std::exception& error) {
> -        std::cerr <<"Error: " << error.what () << '\n';
> -        return 1;
> -    }
> -    catch (...) {
> -        std::cerr << "unknown exception\n";
> -        return 1;
> -    }
> -
> -#ifdef _RWSTD_NO_ISO_10646_WCHAR_T
> -        //      std::setlocale (LC_CTYPE, saved_loc_name);
> -#endif   // _RWSTD_NO_ISO_10646_WCHAR_T
>  
>      return EXIT_SUCCESS;
>  }
> 
> Added: incubator/stdcxx/trunk/util/locale_stub.cpp
> URL: http://svn.apache.org/viewvc/incubator/stdcxx/trunk/util/locale_stub.cpp?view=auto&rev=526304
> ==============================================================================
> --- incubator/stdcxx/trunk/util/locale_stub.cpp (added)
> +++ incubator/stdcxx/trunk/util/locale_stub.cpp Fri Apr  6 15:34:41 2007
> @@ -0,0 +1,78 @@
> +/***************************************************************************
> + *
> + * locale_stub.cpp
> + *
> + * $Id$
> + *
> + ***************************************************************************
> + *
> + * Licensed to the Apache Software  Foundation (ASF) under one or more
> + * contributor  license agreements.  See  the NOTICE  file distributed
> + * with  this  work  for  additional information  regarding  copyright
> + * ownership.   The ASF  licenses this  file to  you under  the Apache
> + * License, Version  2.0 (the  "License"); you may  not use  this file
> + * except in  compliance with the License.   You may obtain  a copy of
> + * the License at
> + *
> + * http://www.apache.org/licenses/LICENSE-2.0
> + *
> + * Unless required by applicable law or agreed to in writing, software
> + * distributed under the  License is distributed on an  "AS IS" BASIS,
> + * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY  KIND, either  express or
> + * implied.   See  the License  for  the  specific language  governing
> + * permissions and limitations under the License.
> + *
> + **************************************************************************/
> +
> +#include <cstdlib>   // for size_t, system()
> +#include <cstring>   // for strcat(), strlen()
> +
> +
> +int main (int argc, char *argv[])
> +{
> +    // compute the total length of the command line arguments
> +    std::size_t arglen = 0;
> +    for (int i = 1; i != argc; ++i)
> +        arglen += std::strlen (argv [i]);
> +
> +    // add the length of space separating adjacent pairs
> +    arglen += argc;
> +
> +    // add the length of the option to invoke localeded in locale mode
> +    const char argv_1[] = "--locale-mode";
> +    arglen += sizeof argv_1;
> +
> +    // allocate space for the new command line
> +    char* const cmdline = new char [arglen + 3];
> +
> +    // replace the basename of argv[0] with "localedef" keeping the
> +    // directory portion, if it's there, followed by the new option
> +    // separated by a space
> +    std::strcpy (cmdline, argv [0]);
> +    char* slash = std::strrchr (cmdline, '/');
> +
> +    if (0 == slash) {
> +        // look for backslash for Windoze
> +        slash = std::strrchr (cmdline, '\\');
> +    }
> +
> +    std::strcpy (slash ? slash + 1 : cmdline, "localedef");
> +
> +    std::strcat (cmdline, " ");
> +    std::strcat (cmdline, argv_1);
> +
> +    // copy arguments to the newly allocated buffer
> +    for (int i = 1; i != argc; ++i) {
> +        std::strcat (cmdline, " ");
> +        std::strcat (cmdline, argv [i]);
> +    }
> +
> +    // invoke the localedef utility instructing it to switch
> +    // to locale mode
> +    const int status = std::system (cmdline);
> +
> +    // clean up
> +    delete[] cmdline;
> +
> +    return status;
> +}
> 
> Propchange: incubator/stdcxx/trunk/util/locale_stub.cpp
> ------------------------------------------------------------------------------
>     svn:keywords = Id
> 
> Modified: incubator/stdcxx/trunk/util/localedef.cpp
> URL: http://svn.apache.org/viewvc/incubator/stdcxx/trunk/util/localedef.cpp?view=diff&rev=526304&r1=526303&r2=526304
> ==============================================================================
> --- incubator/stdcxx/trunk/util/localedef.cpp (original)
> +++ incubator/stdcxx/trunk/util/localedef.cpp Fri Apr  6 15:34:41 2007
> @@ -6,16 +6,23 @@
>   *
>   ***************************************************************************
>   *
> - * Copyright (c) 1994-2005 Quovadx,  Inc., acting through its  Rogue Wave
> - * Software division. Licensed under the Apache License, Version 2.0 (the
> - * "License");  you may  not use this file except  in compliance with the
> - * License.    You    may   obtain   a   copy   of    the   License    at
> - * http://www.apache.org/licenses/LICENSE-2.0.    Unless   required    by
> - * applicable law  or agreed to  in writing,  software  distributed under
> - * the License is distributed on an "AS IS" BASIS,  WITHOUT WARRANTIES OR
> - * CONDITIONS OF  ANY KIND, either  express or implied.  See  the License
> - * for the specific language governing permissions  and limitations under
> - * the License.
> + * Licensed to the Apache Software  Foundation (ASF) under one or more
> + * contributor  license agreements.  See  the NOTICE  file distributed
> + * with  this  work  for  additional information  regarding  copyright
> + * ownership.   The ASF  licenses this  file to  you under  the Apache
> + * License, Version  2.0 (the  "License"); you may  not use  this file
> + * except in  compliance with the License.   You may obtain  a copy of
> + * the License at
> + *
> + * http://www.apache.org/licenses/LICENSE-2.0
> + *
> + * Unless required by applicable law or agreed to in writing, software
> + * distributed under the  License is distributed on an  "AS IS" BASIS,
> + * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY  KIND, either  express or
> + * implied.   See  the License  for  the  specific language  governing
> + * permissions and limitations under the License.
> + *
> + * Copyright 2001-2006 Rogue Wave Software.
>   * 
>   **************************************************************************/
>  
> @@ -514,51 +521,79 @@
>  }
>  
>  
> +int localedef_main (int argc, char *argv[])
> +{
> +    ProgramOptions opts;
> +
> +    if (!process_command_line (&opts, argc, argv))
> +        return EXIT_OK;
> +
> +    if (opts.gen) {
> +        // create the locale databases as specified in generation list
> +        generate_locales (opts.map_file, opts.alias_file,
> +                          opts.charmap_dir.c_str (),
> +                          opts.src_dir.c_str (),
> +                          opts.output_dir.c_str (),
> +                          opts.use_ucs,
> +                          opts.no_position,
> +                          opts.link_aliases);
> +    }
> +    else {
> +        assert (0 != opts.locale_name);
> +
> +        // C++ locale name requested
> +        std::string std_locale (opts.locale_name);
> +
> +        // retrieve the output directory if any
> +        std::string std_outdir ("");
> +
> +        if (std_locale.rfind (_RWSTD_PATH_SEP) != std::string::npos) {
> +            std_outdir = 
> +                std_locale.substr (
> +                    0, std_locale.rfind (_RWSTD_PATH_SEP) + 1);
> +
> +            std_locale = 
> +                std_locale.substr (std_locale.rfind (_RWSTD_PATH_SEP) + 1,
> +                                   std_locale.size ());
> +        }
> +
> +        // create the locale database
> +        create_locale (opts.source_name, opts.charmap_name,
> +                       std_outdir, std_locale,
> +                       opts.force_output, opts.use_ucs,
> +                       opts.no_position, opts.link_aliases);
> +    }
> +
> +    return EXIT_OK;
> +}
> +
> +
> +// defined in locale.cpp
> +int locale_main (int, char*[]);
> +
> +
>  int main (int argc, char *argv[])
>  {
>      int exit_status = EXIT_OK;
>  
>      try {
>  
> -        ProgramOptions opts;
> -
> -        if (!process_command_line (&opts, argc, argv))
> -            return exit_status;
> -
> -        if (opts.gen) {
> -            // create the locale databases as specified in generation list
> -            generate_locales (opts.map_file, opts.alias_file,
> -                              opts.charmap_dir.c_str (),
> -                              opts.src_dir.c_str (),
> -                              opts.output_dir.c_str (),
> -                              opts.use_ucs,
> -                              opts.no_position,
> -                              opts.link_aliases);
> -        }
> -        else {
> -            assert (0 != opts.locale_name);
> +        if (1 < argc && 0 == std::strcmp (argv [1], "--locale-mode")) {
>  
> -            // C++ locale name requested
> -            std::string std_locale (opts.locale_name);
> +            // invoked with the special option ""--locale-mode"
> +            // to act like the locale utility
>  
> -            // retrieve the output directory if any
> -            std::string std_outdir ("");
> +            // remove argv [1] from command line
> +            for (int i = 2; argv [i]; ++i)
> +                argv [i - 1] = argv [i];
>  
> -            if (std_locale.rfind (_RWSTD_PATH_SEP) != std::string::npos) {
> -                std_outdir = 
> -                    std_locale.substr (
> -                        0, std_locale.rfind (_RWSTD_PATH_SEP) + 1);
> -
> -                std_locale = 
> -                    std_locale.substr (std_locale.rfind (_RWSTD_PATH_SEP) + 1,
> -                                       std_locale.size ());
> -            }
> +            // NULL-terminate argv
> +            argv [argc - 1] = 0;
>  
> -            // create the locale database
> -            create_locale (opts.source_name, opts.charmap_name,
> -                           std_outdir, std_locale,
> -                           opts.force_output, opts.use_ucs,
> -                           opts.no_position, opts.link_aliases);
> +            exit_status = locale_main (argc - 1, argv);
> +        }
> +        else {
> +            exit_status = localedef_main (argc, argv);
>          }
>      }
>      catch (const std::ios::failure& error) {
> 
> 
> 

Re: svn commit: r526304 - in /incubator/stdcxx/trunk: etc/config/GNUmakefile.bin util/locale.cpp util/locale_stub.cpp util/localedef.cpp

Posted by Martin Sebor <ms...@gmail.com>.
Farid Zaripov wrote:
>> -----Original Message-----
>> From: Andrew Black [mailto:ablack@roguewave.com] 
>> Sent: Tuesday, April 10, 2007 8:48 PM
>> To: stdcxx-dev@incubator.apache.org
>> Subject: Re: svn commit: r526304 - in 
>> /incubator/stdcxx/trunk: etc/config/GNUmakefile.bin 
>> util/locale.cpp util/locale_stub.cpp util/localedef.cpp
>>
>> Greetings Farid
>>
>> At some point it'll be necessary to replicate this change to 
>> the makefile in the windows infrastructure.  Until this 
>> happens, we'll be observing failures on windows, caused by an 
>> inability to build the locale utilities.  While I might be 
>> able to fix this myself, it would likely be more efficient, 
>> time-wise, for you to make the change as you are more 
>> familiar with the solution generator code.
> 
>   Done:  http://svn.apache.org/viewvc?view=rev&rev=527468
> 
> Farid.

Thanks for handling this! I should have thought of it when I made
the GNUmakefile changes.

Martin

RE: svn commit: r526304 - in /incubator/stdcxx/trunk: etc/config/GNUmakefile.bin util/locale.cpp util/locale_stub.cpp util/localedef.cpp

Posted by Farid Zaripov <Fa...@epam.com>.
> -----Original Message-----
> From: Andrew Black [mailto:ablack@roguewave.com] 
> Sent: Tuesday, April 10, 2007 8:48 PM
> To: stdcxx-dev@incubator.apache.org
> Subject: Re: svn commit: r526304 - in 
> /incubator/stdcxx/trunk: etc/config/GNUmakefile.bin 
> util/locale.cpp util/locale_stub.cpp util/localedef.cpp
> 
> Greetings Farid
> 
> At some point it'll be necessary to replicate this change to 
> the makefile in the windows infrastructure.  Until this 
> happens, we'll be observing failures on windows, caused by an 
> inability to build the locale utilities.  While I might be 
> able to fix this myself, it would likely be more efficient, 
> time-wise, for you to make the change as you are more 
> familiar with the solution generator code.

  Done:  http://svn.apache.org/viewvc?view=rev&rev=527468

Farid.