Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: gettext(1) implementation

2 views
Skip to first unread message

Joerg Sonnenberger

unread,
Jul 5, 2015, 8:46:49 AM7/5/15
to
On Sun, May 31, 2015 at 11:21:39PM -0700, William Orr wrote:
> Currently, I've implemented the same features that exist in the GNU gettext(1)
> command. I'm thinking of adding more (easier message context support, for one)
> if this gets merged.

There is one issue with this shown by graphics/shotwell in pkgsrc. That
depends on using --domain=textdomain, which currently gives an error.
Can you implement that?

Joerg

--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-...@muc.de

William Orr

unread,
Jul 6, 2015, 1:37:49 AM7/6/15
to


On 7/5/15 5:46 AM, Joerg Sonnenberger wrote:
> On Sun, May 31, 2015 at 11:21:39PM -0700, William Orr wrote:
>> Currently, I've implemented the same features that exist in the GNU gettext(1)
>> command. I'm thinking of adding more (easier message context support, for one)
>> if this gets merged.
>
> There is one issue with this shown by graphics/shotwell in pkgsrc. That
> depends on using --domain=textdomain, which currently gives an error.
> Can you implement that?
>
> Joerg
>

Hey,

I just moved, so I'm still setting up my computers. I'll get this
implemented asap.

Sorry for the delay,
William Orr

William Orr

unread,
Jul 11, 2015, 9:50:26 PM7/11/15
to
On 07/05/2015 05:46 AM, Joerg Sonnenberger wrote:
> On Sun, May 31, 2015 at 11:21:39PM -0700, William Orr wrote:
>> Currently, I've implemented the same features that exist in the GNU gettext(1)
>> command. I'm thinking of adding more (easier message context support, for one)
>> if this gets merged.
>
> There is one issue with this shown by graphics/shotwell in pkgsrc. That
> depends on using --domain=textdomain, which currently gives an error.
> Can you implement that?
>
> Joerg
>

Hey,

This adds support for long options, as well as some changes that I had
submitted in a previous diff (fixing a memory leak, suggestions from
previous patches).

Thanks,
William Orr

--- ../netbsd/src/usr.bin/gettext/gettext.c 2015-06-03
16:15:22.000000000 -0700
+++ src/usr.bin/gettext/gettext.c 2015-07-11 18:48:20.221429987 -0700
@@ -1,5 +1,3 @@
-/* $NetBSD: gettext.c,v 1.2 2015/06/03 23:15:22 enami Exp $ */
-
/*-
* Copyright (c) 2015 William Orr <wi...@worrbase.com>
* All rights reserved.
@@ -25,8 +23,6 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__RCSID("$NetBSD: gettext.c,v 1.2 2015/06/03 23:15:22 enami Exp $");

#include <err.h>
#include <errno.h>
@@ -39,21 +35,28 @@
#include <string.h>
#include <util.h>

-static __dead void
+static bool nflag;
+
+static struct option longopts[] = {
+ { "help", no_argument, NULL, 'h' },
+ { "domain", required_argument, NULL, 'd' },
+ { NULL, 0, NULL, 0 },
+};
+
+static void
usage(int exit_status)
{

- fprintf(stderr, "Usage: %s [-ehn] [[<textdomain>] <msgid>]\n",
- getprogname());
- fprintf(stderr, "Usage: %s -s [<msgid>]...\n", getprogname());
+ fprintf(stderr, "Usage: %s [-ehn] [[TEXTDOMAIN] MSGID]\n", getprogname());
+ fprintf(stderr, "Usage: %s [-ehn] -d TEXTDOMAIN MSGID\n", getprogname());
+ fprintf(stderr, "Usage: %s -s [MSGID]...\n", getprogname());
exit(exit_status);
}

-static bool
+static void
expand(char *str)
{
char *fp, *sp, ch, pl;
- bool nflag = false;

for (fp = str, sp = str; *fp != 0;) {
if (*fp == '\\') {
@@ -122,7 +125,6 @@
}

*sp = '\0';
- return nflag;
}

int
@@ -130,28 +132,26 @@
{
char *msgdomain = NULL;
char *msgdomaindir = NULL;
+ char *msgid = NULL;
char *translation = NULL;
- char *s;
bool eflag = false;
bool sflag = false;
- bool nflag = false;
int ch;

setlocale(LC_ALL, "");
setprogname(argv[0]);

- while ((ch = getopt(argc, argv, "d:EehnsV")) != -1) {
+ while ((ch = getopt_long(argc, argv, "d:eEhnsV", longopts, NULL)) != -1) {
switch (ch) {
case 'd':
msgdomain = estrdup(optarg);
break;
- case 'E':
- /* GNU gettext compat */
- break;
case 'e':
eflag = true;
break;
- case 'V':
+ case 'E':
+ /* GNU gettext compat */
+ break;
case 'h':
free(msgdomain);
usage(EXIT_SUCCESS);
@@ -173,37 +173,37 @@

if (argc == 0) {
free(msgdomain);
- errx(EXIT_FAILURE, "missing msgid");
+ warnx("missing msgid");
+ usage(EXIT_FAILURE);
}
-
/* msgdomain can be passed as optional arg iff -s is not passed */
- if (!sflag) {
- if (argc == 2) {
- free(msgdomain);
- msgdomain = estrdup(argv[0]);
+ if (argc == 2 && !sflag) {
+ free(msgdomain);
+ msgdomain = estrdup(argv[0]);

- argc -= 1;
- argv += 1;
- } else if (argc > 2)
- errx(EXIT_FAILURE, "too many arguments");
+ argc -= 1;
+ argv += 1;
+ } else if (argc > 2 && !sflag) {
+ warnx("%s: too many arguments", getprogname());
+ usage(EXIT_FAILURE);
}
-
/* msgdomain can be passed as env var */
if (msgdomain == NULL) {
- if ((s = getenv("TEXTDOMAIN")) != NULL)
- msgdomain = estrdup(s);
+ if (getenv("TEXTDOMAIN")) {
+ free(msgdomain);
+ msgdomain = estrdup(getenv("TEXTDOMAIN"));
+ }
}

if (msgdomain != NULL) {
- if ((s = getenv("TEXTDOMAINDIR")) != NULL)
- msgdomaindir = estrdup(s);
+ if (getenv("TEXTDOMAINDIR"))
+ msgdomaindir = estrdup(getenv("TEXTDOMAINDIR"));
if (msgdomaindir)
bindtextdomain(msgdomain, msgdomaindir);
}
-
do {
if (eflag)
- nflag |= expand(*argv);
+ expand(*argv);

translation = dgettext(msgdomain, argv[0]);
printf("%s", translation);
@@ -219,6 +219,5 @@

free(msgdomain);
free(msgdomaindir);
-
return EXIT_SUCCESS;
0 new messages