"unzip -l": Use the date separator given by the system

"Cosmin T" <[email protected]> Wed, 18 Feb 2004 23:47:18 -0500
Newsgroups gmane.comp.archivers.info-zip
Message-ID <[email protected]>
Hi, again,

I noticed that unzip uses a permutation of the YY-MM-DD format,
if it is given by the system. However, it always uses '-' as date
separator, even if the system says it's a different one.

I would like to use the separator given by the system, when possible.
I hate to see dates like 04-03-02, and have to dig in order to find
out which is the year, the month, and the day. I am a little more
comfortable, however, if I see 04.03.02, because I have a clue:
the program is recognizing my system's locale (4th of March, 2002,
date separator is '.', under Romanian locale).

I made a patch only for Win32, but I believe it won't be difficult
to add support for other platforms that provide the necessary info.
The patch relates to unzip-5.51c.

Best regards,
Cosmin


diff -u list.c~ list.c
--- list.c~	Sat Jan 13 16:39:48 2001
+++ list.c	Wed Feb 18 00:12:40 2004
@@ -59,13 +59,13 @@
    static ZCONST char Far CaseConversion[] =
      "%s (\"^\" ==> case\n%s   conversion)\n";
    static ZCONST char Far LongHdrStats[] =
-     "%8lu  %-7s%8lu %4s  %02u-%02u-%02u %02u:%02u  %08lx %c";
+     "%8lu  %-7s%8lu %4s  %02u%c%02u%c%02u %02u:%02u  %08lx %c";
    static ZCONST char Far LongFileTrailer[] =
      "--------          -------  ---                       \
      -------\n%8lu         %8lu %4s                            %lu 
file%s\n";
#ifdef OS2_EAS
    static ZCONST char Far ShortHdrStats[] =
-     "%9lu %6lu %6lu  %02u-%02u-%02u %02u:%02u  %c";
+     "%9lu %6lu %6lu  %02u%c%02u%c%02u %02u:%02u  %c";
    static ZCONST char Far ShortFileTrailer[] = " --------  -----  -----     
   \
             -------\n%9lu %6lu %6lu                   %lu file%s\n";
    static ZCONST char Far OS2ExtAttrTrailer[] =
@@ -74,7 +74,7 @@
      "%lu file%s %lu bytes of access control lists attached.\n";
#else
    static ZCONST char Far ShortHdrStats[] =
-     "%9lu  %02u-%02u-%02u %02u:%02u  %c";
+     "%9lu  %02u%c%02u%c%02u %02u:%02u  %c";
    static ZCONST char Far ShortFileTrailer[] = " --------       \
             -------\n%9lu                   %lu file%s\n";
#endif /* ?OS2_EAS */
@@ -97,6 +97,7 @@
     int longhdr=(uO.vflag>1);
#endif
     int date_format;
+    char date_separator;
     ulg j, members=0L;
     unsigned methnum;
#ifdef USE_EF_UT_TIME
@@ -137,6 +138,12 @@

     G.pInfo = &info;
     date_format = DATE_FORMAT;
+#ifdef DATE_SEPARATOR
+    /* use nat'l date separator, if available */
+    date_separator = DATE_SEPARATOR;
+#else
+    date_separator = '-';  /* default */
+#endif

#ifndef WINDLL
     if (uO.qflag < 2) {
@@ -345,17 +352,20 @@
                 sprintf(cfactorstr, LoadFarString(CompFactorStr), sgn, 
cfactor);
             if (longhdr)
                 Info(slide, 0, ((char *)slide, LoadFarString(LongHdrStats),
-                  G.crec.ucsize, methbuf, csiz, cfactorstr, mo, dy,
-                  yr, hh, mm, G.crec.crc32, (G.pInfo->lcflag? '^':' ')));
+                  G.crec.ucsize, methbuf, csiz, cfactorstr,
+                  mo, date_separator, dy, date_separator, yr, hh, mm,
+                  G.crec.crc32, (G.pInfo->lcflag? '^':' ')));
             else
#ifdef OS2_EAS
                 Info(slide, 0, ((char *)slide, 
LoadFarString(ShortHdrStats),
                   G.crec.ucsize, ea_size, acl_size,
-                  mo, dy, yr, hh, mm, (G.pInfo->lcflag? '^':' ')));
+                  mo, date_separator, dy, date_separator, yr, hh, mm,
+                  (G.pInfo->lcflag? '^':' ')));
#else
                 Info(slide, 0, ((char *)slide, 
LoadFarString(ShortHdrStats),
                   G.crec.ucsize,
-                  mo, dy, yr, hh, mm, (G.pInfo->lcflag? '^':' ')));
+                  mo, date_separator, dy, date_separator, yr, hh, mm,
+                  (G.pInfo->lcflag? '^':' ')));
#endif
             fnprint(__G);
#endif /* ?WINDLL */

diff -u unzpriv.h~ unzpriv.h
--- unzpriv.h~	Sun Mar 23 16:21:26 2003
+++ unzpriv.h	Tue Feb 17 21:04:00 2004
@@ -2074,7 +2074,8 @@
    ulg      crc32           OF((ulg crc, ZCONST uch *buf, extent len));
#endif /* !USE_ZLIB */                        /* assembler source or crc32.c 
*/

-int      dateformat      OF((void));              /* currently, only 
msdos.c */
+int      dateformat      OF((void));                                /* 
local */
+char     dateseparator   OF((void));                                /* 
local */
#ifndef WINDLL
    void  version         OF((__GPRO));                              /* 
local */
#endif

diff -u win32/w32cfg.h~ win32/w32cfg.h
--- win32/w32cfg.h~	Sat Jan 04 10:09:16 2003
+++ win32/w32cfg.h	Tue Feb 17 19:25:54 2004
@@ -175,6 +175,10 @@
#  undef DATE_FORMAT
#endif
#define DATE_FORMAT   dateformat()
+#ifdef DATE_SEPARATOR
+#  undef DATE_SEPARATOR
+#endif
+#define DATE_SEPARATOR  dateseparator()
#define lenEOL        2
#define PutNativeEOL  {*q++ = native(CR); *q++ = native(LF);}


diff -u win32/win32.c~ win32/win32.c
--- win32/win32.c~	Sat May 10 14:10:46 2003
+++ win32/win32.c	Tue Feb 17 21:08:40 2004
@@ -2460,6 +2460,22 @@
}


+/****************************/
+/* Function dateseparator() */
+/****************************/
+
+char dateseparator()
+{
+  TCHAR df[2];  /* use only if the actual separator is one character long 
*/
+
+  if ((GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SDATE, df, 2) != 0) &&
+      (df[0] != '\0'))
+    return df[0];
+  else
+    return '-';
+}
+
+
#ifndef WINDLL

/************************/

_________________________________________________________________
MSN 8 with e-mail virus protection service: 2 months FREE*  
http://join.msn.com/?page=features/virus&pgmarket=en-ca&RU=http%3a%2f%2fjoin.msn.com%2f%3fpage%3dmisc%2fspecialoffers%26pgmarket%3den-ca