RE: [PATCH] gencat.cpp (was: RE: svn commit: r555006 - /incubator/stdcxx/trunk/src/catalog.cpp)

2007-08-03 Thread Farid Zaripov
 -Original Message-
 From: Martin Sebor [mailto:[EMAIL PROTECTED] 
 Sent: Friday, August 03, 2007 2:03 AM
 To: stdcxx-dev@incubator.apache.org
 Subject: Re: [PATCH] gencat.cpp (was: RE: svn commit: r555006 
 - /incubator/stdcxx/trunk/src/catalog.cpp)
 
 This looks good, although it could use a few more comments :)
 
 Where does it live? In $TOPDIR/util/?
  Yes.

 Does the conditional #error cause any problems on UNIX?
  We can exclude this file from compilation (the same way as
excluded rwstdmessages.cpp in makefile.exm).
  
 Would it be safer to implement it on UNIX as well by having it
 invoke the system gencat utility?
  Yes we can do it, but with renaming the utility to, for example,
rwgencat
to avoid invoking the utility recursively.

Farid.


Re: [PATCH] gencat.cpp (was: RE: svn commit: r555006 - /incubator/stdcxx/trunk/src/catalog.cpp)

2007-08-02 Thread Martin Sebor

This looks good, although it could use a few more comments :)

Where does it live? In $TOPDIR/util/? Does the conditional #error
cause any problems on UNIX? Would it be safer to implement it on
UNIX as well by having it invoke the system gencat utility?

Martin

Farid Zaripov wrote:

  -Original Message-
  From: Martin Sebor [mailto:[EMAIL PROTECTED]
  Sent: Friday, July 13, 2007 5:53 PM
  To: stdcxx-dev@incubator.apache.org
  Subject: Re: svn commit: r555006 -
  /incubator/stdcxx/trunk/src/catalog.cpp
 
   If it does, is the bug easily
   reproducible so we can add a test case for it to the bug tracking
   database?

 The JIRA issue created: http://issues.apache.org/jira/browse/STDCXX-508

 For the test case the valid catalog should be created
  (.dll file on
   windows).
   It's not so easy and platform dependent. Of course we can use
   generate_catalog () function from 22.locale.messages.cpp test.
 
  That seems like a good approach. We could use it as the first
  step toward providing an easier and portable way to build
  message catalogs on Windows as well as other platforms. A
  portable utility that takes a source file such as
  rwstderr.msg or rwstderr.rc as input and produces a catalog
  from it suitable for the target platform.

 Attached is a new utility for generating the message catalogs on Windows.

 ChangeLog:
 * gencat.cpp: New utility for generating the message catalogs on Windows.

Farid.





[PATCH] gencat.cpp (was: RE: svn commit: r555006 - /incubator/stdcxx/trunk/src/catalog.cpp)

2007-08-01 Thread Farid Zaripov

 -Original Message-
 From: Martin Sebor [mailto:[EMAIL PROTECTED]
 Sent: Friday, July 13, 2007 5:53 PM
 To: stdcxx-dev@incubator.apache.org
 Subject: Re: svn commit: r555006 -
 /incubator/stdcxx/trunk/src/catalog.cpp

  If it does, is the bug easily
  reproducible so we can add a test case for it to the bug tracking
  database?

 The JIRA issue created: http://issues.apache.org/jira/browse/STDCXX-508

For the test case the valid catalog should be created
 (.dll file on
  windows).
  It's not so easy and platform dependent. Of course we can use
  generate_catalog () function from 22.locale.messages.cpp test.

 That seems like a good approach. We could use it as the first
 step toward providing an easier and portable way to build
 message catalogs on Windows as well as other platforms. A
 portable utility that takes a source file such as
 rwstderr.msg or rwstderr.rc as input and produces a catalog
 from it suitable for the target platform.

 Attached is a new utility for generating the message catalogs on Windows.

 ChangeLog:
 * gencat.cpp: New utility for generating the message catalogs on Windows.

Farid.

/***
 *
 * gencat.cpp - Utility for generating message catalogs on Windows
 *
 * $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.
 *
 **/

#ifndef _WIN32
#error This utility should be compiled only on Windows
#endif

#include cstdlib   // for system(), getenv()
#include cstdio// for printf()
#include cstring   // for strcmp(), strrchr()
#include cstddef   // for size_t

#include string

static const char
usage_text[] = {
Usage: %s OUTPUT-FILE INPUT-FILE\n
Generate message catalog.\n
\n
  -?, --help Give this help list\n
};

#ifndef _WIN64
#  define PLATFORM X86
#else   // _WIN64
#  define PLATFORM X64
#endif  // _WIN64

// replace file extension in str by new extension ext
static void change_ext (std::string str, const char* ext)
{
const std::string::size_type npos = std::string::npos;
std::string::size_type dot_pos = str.find_last_of ('.');
std::string::size_type quote_pos =
npos == dot_pos ? str.find_last_of ('\')
: str.find_first_of ('\', dot_pos);
if (npos == quote_pos)
quote_pos = str.size ();
if (npos == dot_pos)
dot_pos = quote_pos;
str.replace (dot_pos, quote_pos - dot_pos, ext);
}

int main (int argc, char *argv[])
{
const char* exe_name = std::strrchr (argv [0], '\\');
if (exe_name)
++exe_name;
else
exe_name = argv [0];

if (1 == argc) {
std::printf (usage_text, exe_name);
return 0;
}

--argc;

while (0 != *++argv  0  argc--  '-' == **argv) {

switch (*++*argv) {

case '?':
std::printf (usage_text, exe_name);
return 0;

case '-':
if (0 == std::strcmp (*argv, -help)) {
std::printf (usage_text, exe_name);
return 0;
}

// fall through...
default:
std::printf (%s: invalid option -%s\n,
 exe_name, *argv);
return 1;
}
}

if (1  argc) {
std::printf (%s: missing arguments\n Try '%s --help'\n,
 exe_name, exe_name);
return 1;
}

const char* const env_vars [] = {
VS80COMNTOOLS, VS71COMNTOOLS, VSCOMNTOOLS
};

std::string cmd;

for (size_t i = 0; i  sizeof (env_vars) / sizeof (*env_vars); ++i) {
if (const char* vcvarspath = std::getenv (env_vars [i])) {
cmd = vcvarspath;
cmd += vsvars32.bat;
break;
}
}

if (std::string::npos != cmd.find (' ')) {
cmd.insert (0, 1, '\');
cmd.push_back ('\');
}

const char* const dll_name = argv [0];
const char* const rc_name = argv [1];

std::string res_name (rc_name);
change_ext (res_name, .res);

if (!cmd.empty ())
cmd +=   ;

cmd += rc

Re: svn commit: r555006 - /incubator/stdcxx/trunk/src/catalog.cpp

2007-07-13 Thread Martin Sebor

Farid Zaripov wrote:

-Original Message-
From: Martin Sebor [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, July 11, 2007 10:14 PM

To: stdcxx-dev@incubator.apache.org
Subject: Re: svn commit: r555006 - 
/incubator/stdcxx/trunk/src/catalog.cpp



* catalog.cpp (catopen): while() loop replaced to for() loop
with checking for max iterations.

Does this fix a bug?


  Definitely :)

  As you can see the __rw_catlist container resized only if i ==
__rw_catlist.size(),
but before of that __rw_catlist.size()'th element is accessed in while
(__rw_catlist[i] != 0)
and this is undefined behavior.

If it does, is the bug easily 
reproducible so we can add a test case for it to the bug 
tracking database?


  For the test case the valid catalog should be created (.dll file on
windows).
It's not so easy and platform dependent. Of course we can use
generate_catalog ()
function from 22.locale.messages.cpp test.


That seems like a good approach. We could use it as the first
step toward providing an easier and portable way to build message
catalogs on Windows as well as other platforms. A portable utility
that takes a source file such as rwstderr.msg or rwstderr.rc as
input and produces a catalog from it suitable for the target
platform.

Martin


RE: svn commit: r555006 - /incubator/stdcxx/trunk/src/catalog.cpp

2007-07-12 Thread Farid Zaripov
 -Original Message-
 From: Martin Sebor [mailto:[EMAIL PROTECTED] 
 Sent: Wednesday, July 11, 2007 10:14 PM
 To: stdcxx-dev@incubator.apache.org
 Subject: Re: svn commit: r555006 - 
 /incubator/stdcxx/trunk/src/catalog.cpp
 
  * catalog.cpp (catopen): while() loop replaced to for() loop
  with checking for max iterations.
 
 Does this fix a bug?

  Definitely :)

  As you can see the __rw_catlist container resized only if i ==
__rw_catlist.size(),
but before of that __rw_catlist.size()'th element is accessed in while
(__rw_catlist[i] != 0)
and this is undefined behavior.

 If it does, is the bug easily 
 reproducible so we can add a test case for it to the bug 
 tracking database?

  For the test case the valid catalog should be created (.dll file on
windows).
It's not so easy and platform dependent. Of course we can use
generate_catalog ()
function from 22.locale.messages.cpp test.

Farid.


Re: svn commit: r555006 - /incubator/stdcxx/trunk/src/catalog.cpp

2007-07-11 Thread Martin Sebor

[EMAIL PROTECTED] wrote:

Author: faridz
Date: Tue Jul 10 09:55:02 2007
New Revision: 555006

URL: http://svn.apache.org/viewvc?view=revrev=555006
Log:
2007-07-10 Farid Zaripov [EMAIL PROTECTED]

* catalog.cpp (catopen): while() loop replaced to for() loop
with checking for max iterations.


Does this fix a bug? If it does, is the bug easily reproducible
so we can add a test case for it to the bug tracking database?

Martin



Modified:
incubator/stdcxx/trunk/src/catalog.cpp

Modified: incubator/stdcxx/trunk/src/catalog.cpp
URL: 
http://svn.apache.org/viewvc/incubator/stdcxx/trunk/src/catalog.cpp?view=diffrev=555006r1=555005r2=555006
==
--- incubator/stdcxx/trunk/src/catalog.cpp (original)
+++ incubator/stdcxx/trunk/src/catalog.cpp Tue Jul 10 09:55:02 2007
@@ -95,8 +95,7 @@
 
 if (cat  cat-good()) {

 CatVector::size_type i = 0;
-while (__rw_catlist[i] != 0)
-i++;
+for (; i  __rw_catlist.size()  __rw_catlist[i]; ++i) ;
 if (__rw_catlist.size() == i)
 __rw_catlist.resize(__rw_catlist.size() * 2,0);
 __rw_catlist[i] = cat;