Imported Upstream version 2.17
[debian/cpmtools] / cpmls.c
diff --git a/cpmls.c b/cpmls.c
index 382ad3add73e87dc75fda9a3677888b4a21cc26e..fa100e9d5e80fdfdf81cc29a11ad99c944680141 100644 (file)
--- a/cpmls.c
+++ b/cpmls.c
@@ -7,7 +7,7 @@
 #include <stdlib.h>
 #include <string.h>
 
-#include "getopt.h"
+#include "getopt_.h"
 #include "cpmfs.h"
 
 #ifdef USE_DMALLOC
@@ -114,9 +114,13 @@ static void oldddir(char **dirent, int entries, struct cpmInode *ino)
           putchar(' ');
           if (statbuf.mtime)
           {
-            tmp=gmtime(&statbuf.mtime);
+            tmp=localtime(&statbuf.mtime);
             printf("  %02d-%s-%04d %02d:%02d",tmp->tm_mday,month[tmp->tm_mon],tmp->tm_year+1900,tmp->tm_hour,tmp->tm_min);
-            tmp=gmtime(&statbuf.ctime);
+          }
+          else if (statbuf.ctime) printf("                   ");
+          if (statbuf.ctime)
+          {
+            tmp=localtime(&statbuf.ctime);
             printf("  %02d-%s-%04d %02d:%02d",tmp->tm_mday,month[tmp->tm_mon],tmp->tm_year+1900,tmp->tm_hour,tmp->tm_min);
           }
           putchar('\n');
@@ -189,10 +193,17 @@ static void old3dir(char **dirent, int entries, struct cpmInode *ino)
           else if (attrib & CPM_ATTR_PWWRITE) printf("Write  ");
           else if (attrib & CPM_ATTR_PWDEL)   printf("Delete "); 
           else printf("None   ");
-          tmp=gmtime(&statbuf.mtime);
-          printf("%02d/%02d/%02d %02d:%02d  ",tmp->tm_mon+1,tmp->tm_mday,tmp->tm_year%100,tmp->tm_hour,tmp->tm_min);
-          tmp=gmtime(&statbuf.ctime);
-          printf("%02d/%02d/%02d %02d:%02d",tmp->tm_mon+1,tmp->tm_mday,tmp->tm_year%100,tmp->tm_hour,tmp->tm_min);
+          if (statbuf.mtime)
+          {
+            tmp=localtime(&statbuf.mtime);
+            printf("%02d/%02d/%02d %02d:%02d  ",tmp->tm_mon+1,tmp->tm_mday,tmp->tm_year%100,tmp->tm_hour,tmp->tm_min);
+          }
+          else if (statbuf.ctime) printf("                ");
+          if (statbuf.ctime)
+          {
+            tmp=localtime(&statbuf.ctime);
+            printf("%02d/%02d/%02d %02d:%02d",tmp->tm_mon+1,tmp->tm_mday,tmp->tm_year%100,tmp->tm_hour,tmp->tm_min);
+          }
           putchar('\n');
           ++l;
         }
@@ -260,7 +271,7 @@ static void ls(char **dirent, int entries, struct cpmInode *ino, int l, int c, i
           printf(" %-2d ",dir[i].user);
 #endif
           printf("%8.1ld ",(long)statbuf.size);
-          tmp=gmtime(c ? &statbuf.ctime : &statbuf.mtime);
+          tmp=localtime(c ? &statbuf.ctime : &statbuf.mtime);
           printf("%s %02d ",month[tmp->tm_mon],tmp->tm_mday);
           if ((c ? statbuf.ctime : statbuf.mtime)<(now-182*24*3600)) printf("%04d  ",tmp->tm_year+1900);
           else printf("%02d:%02d ",tmp->tm_hour,tmp->tm_min);
@@ -325,7 +336,7 @@ int main(int argc, char *argv[])
   /* variables */ /*{{{*/
   const char *err;
   const char *image;
-  const char *format=FORMAT;
+  const char *format;
   const char *devopts=NULL;
   int c,usage=0;
   struct cpmSuperBlock drive;
@@ -340,6 +351,7 @@ int main(int argc, char *argv[])
   /*}}}*/
 
   /* parse options */ /*{{{*/
+  if (!(format=getenv("CPMTOOLSFMT"))) format=FORMAT;
   while ((c=getopt(argc,argv,"cT:f:ih?dDFlA"))!=EOF) switch(c)
   {
     case 'f': format=optarg; break;