[PATCH 2/3] time/tst-strftime2.c: Make the file easier to maintain.

TAMUKI Shoichi tamuki@linet.gr.jp
Wed Mar 27 03:29:00 GMT 2019


Hello Rafal-san,

I am sorry I can not tell you at once.

From: Rafal Luzynski <digitalfreak@lingonborough.com>
Subject: [PATCH 2/3] time/tst-strftime2.c: Make the file easier to maintain.
Date: Fri, 15 Mar 2019 12:48:34 +0100 (CET)

> [...]
> +static bool
> +is_before (const date_t *date, const int d, const int m, const int y)
> +{
> +  if (date->y < y)
> +    return true;
> +  else if (date->y > y)
> +    return false;
> +  else if (date->m < m)
> +    return true;
> +  else if (date->m > m)
> +    return false;
> +  else
> +    return date->d < d;
> +}
> +

Since dates[] is a global variable, I think that it will be
simplified by using the index of dates[] instead of the address of
dates[] as an argument for the is_before function.

So maybe something like this:

@@ -62,18 +62,18 @@
 	       [array_length (dates)][100];
 
 static bool
-is_before (const date_t *date, const int d, const int m, const int y)
+is_before (const int i, const int d, const int m, const int y)
 {
-  if (date->y < y)
+  if (dates[i].y < y)
     return true;
-  else if (date->y > y)
+  else if (dates[i].y > y)
     return false;
-  else if (date->m < m)
+  else if (dates[i].m < m)
     return true;
-  else if (date->m > m)
+  else if (dates[i].m > m)
     return false;
   else
-    return date->d < d;
+    return dates[i].d < d;
 }
 
 static void
@@ -103,11 +103,11 @@
 	{
 	  if (i == 0)  /* ja_JP  */
 	    {
-	      if (is_before (&dates[k], 30, 7, 1912))
+	      if (is_before (k, 30, 7, 1912))
 		era = "\xe6\x98\x8e\xe6\xb2\xbb";
-	      else if (is_before (&dates[k], 25, 12, 1926))
+	      else if (is_before (k, 25, 12, 1926))
 		era = "\xe5\xa4\xa7\xe6\xad\xa3";
-	      else if (is_before (&dates[k], 8, 1, 1989))
+	      else if (is_before (k, 8, 1, 1989))
 		era = "\xe6\x98\xad\xe5\x92\x8c";
 	      else
 		era = "\xe5\xb9\xb3\xe6\x88\x90";
@@ -125,7 +125,7 @@
 	    }
 	  else if (i >= 3 && i <= 7)  /* {zh,cmn,hak,nan,lzh}_TW  */
 	    {
-	      if (is_before (&dates[k], 1, 1, 1912))
+	      if (is_before (k, 1, 1, 1912))
 		era = "\xe6\xb0\x91\xe5\x89\x8d";
 	      else
 		era = "\xe6\xb0\x91\xe5\x9c\x8b";

From: TAMUKI Shoichi <tamuki@linet.gr.jp>
Subject: Re: [PATCH 3/3] time: Add tests for Minguo calendar [BZ #24293]
Date: Sun, 24 Mar 2019 20:40:07 +0900

> Question:
> 
> In the typedef struct, which indentation style is appropriate?
> 
> | typedef struct
> | {
> |   const int d, m, y;
> | } date_t;
> | 
> 
> or
> 
> | typedef struct
> |   {
> |     const int d, m, y;
> |   } date_t;
> | 
> 
> ?

According to GNU Coding Standards documentation:

| For struct and enum types, likewise put the braces in column one,
| unless the whole contents fits on one line:
| 
| struct foo
| {
|   int a, b;
| }
| 
| or
| 
| struct foo { int a, b; }

So perhaps maybe something like these:

| static const char *locales[] =
| {
|   "ja_JP.UTF-8", "lo_LA.UTF-8", "th_TH.UTF-8",
|   "zh_TW.UTF-8", "cmn_TW.UTF-8", "hak_TW.UTF-8",
|   "nan_TW.UTF-8", "lzh_TW.UTF-8"
| };

| static const date_t dates[] =
| {
|   {  1,  4, 1910 },
|   { 31, 12, 1911 },
|   { 29,  7, 1912 },
|   { 30,  7, 1912 },
|   {  1,  4, 1913 },
|   {  1,  4, 1988 },
|   {  7,  1, 1989 },
|   {  8,  1, 1989 },
|   {  1,  4, 1990 },
|   {  1,  4, 1997 },
|   {  1,  4, 1998 },
|   {  1,  4, 2010 },
|   {  1,  4, 2011 }
| };

| static void
| mkreftable (void)
| {
|   [...]
|   static const int yrj[] =
|   {
|     43, 44, 45, 1, 2,
|     63, 64, 1, 2, 9, 10, 22, 23
|   };
|   static const int yrb[] =
|   {
|     2453, 2454, 2455, 2455, 2456,
|     2531, 2532, 2532, 2533, 2540, 2541, 2553, 2554
|   };
|   static const int yrc[] =
|   {
|     -2, -1, 1, 1, 2,
|     77, 78, 78, 79, 86, 87, 99, 100
|   };
| 
|   [...]

Regards,
TAMUKI Shoichi



More information about the Libc-alpha mailing list