All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ddate: St. Tib's Day in other languages
@ 2011-08-17 18:35 Nick Erdmann
  2011-08-18  9:31 ` Karel Zak
  0 siblings, 1 reply; 2+ messages in thread
From: Nick Erdmann @ 2011-08-17 18:35 UTC (permalink / raw)
  To: util-linux

In other languages than english, the translation of "St. Tib's Day" may not
be 13 bytes long. Example of what happens in german:
$ ddate 29 2 2008
St. Tib’s D, 3174 YOLD

Signed-off-by: Nick Erdmann <erdmann@date.upb.de>
--- a/misc-utils/ddate.c	2011-07-20 21:55:23.000000000 +0200
+++ b/misc-utils/ddate.c	2011-08-17 18:11:12.437504258 +0200
@@ -223,6 +223,7 @@
     int tib_start=-1, tib_end=0;
     int i, fmtlen=strlen(fmt);
     char *bufptr=buf;
+    char *foo;
 
 /*    fprintf(stderr, "format(%p, \"%s\", dt)\n", buf, fmt);*/
 
@@ -249,7 +250,9 @@
     for(i=0; i<fmtlen; i++) {
 	if((i==tib_start) && (dt.day==-1)) {
 	    /* handle St. Tib's Day */
-	    strcpy(bufptr, _("St. Tib's Day")); bufptr += 13;
+	    foo = _("St. Tib's Day");
+	    while((*bufptr++=*foo++));
+	    --bufptr;
 	    i=tib_end;
 	} else {
 	    if(fmt[i]=='%') {

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] ddate: St. Tib's Day in other languages
  2011-08-17 18:35 [PATCH] ddate: St. Tib's Day in other languages Nick Erdmann
@ 2011-08-18  9:31 ` Karel Zak
  0 siblings, 0 replies; 2+ messages in thread
From: Karel Zak @ 2011-08-18  9:31 UTC (permalink / raw)
  To: Nick Erdmann; +Cc: util-linux

On Wed, Aug 17, 2011 at 08:35:02PM +0200, Nick Erdmann wrote:
> In other languages than english, the translation of "St. Tib's Day" may not
> be 13 bytes long. Example of what happens in german:
> $ ddate 29 2 2008
> St. Tib’s D, 3174 YOLD
> 
> Signed-off-by: Nick Erdmann <erdmann@date.upb.de>
> --- a/misc-utils/ddate.c	2011-07-20 21:55:23.000000000 +0200
> +++ b/misc-utils/ddate.c	2011-08-17 18:11:12.437504258 +0200
> @@ -223,6 +223,7 @@
>      int tib_start=-1, tib_end=0;
>      int i, fmtlen=strlen(fmt);
>      char *bufptr=buf;
> +    char *foo;
>  
>  /*    fprintf(stderr, "format(%p, \"%s\", dt)\n", buf, fmt);*/
>  
> @@ -249,7 +250,9 @@
>      for(i=0; i<fmtlen; i++) {
>  	if((i==tib_start) && (dt.day==-1)) {
>  	    /* handle St. Tib's Day */
> -	    strcpy(bufptr, _("St. Tib's Day")); bufptr += 13;
> +	    foo = _("St. Tib's Day");
> +	    while((*bufptr++=*foo++));
> +	    --bufptr;
>  	    i=tib_end;

        strcpy(bufptr, _("St. Tib's Day"));
        bufptr += strlen(bufptr);

seems more readable.

Anyway, the horrible code does not check the size of the bufptr, etc.

I'm still surprised that we have this crazy thing in util-linux
package and it's enabled by default. I'll probably add --enable-ddate.

    Karel

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-08-18  9:32 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-08-17 18:35 [PATCH] ddate: St. Tib's Day in other languages Nick Erdmann
2011-08-18  9:31 ` Karel Zak

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.