Imported Upstream version 2.17
[debian/cpmtools] / cpmls.c
diff --git a/cpmls.c b/cpmls.c
index e2d1786ec4970062401dae95750859eed5f23e56..fa100e9d5e80fdfdf81cc29a11ad99c944680141 100644 (file)
--- a/cpmls.c
+++ b/cpmls.c
@@ -1,12 +1,18 @@
 /* #includes */ /*{{{C}}}*//*{{{*/
+#include "config.h"
+
 #include <ctype.h>
 #include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include "config.h"
-#include "getopt.h"
+
+#include "getopt_.h"
 #include "cpmfs.h"
+
+#ifdef USE_DMALLOC
+#include <dmalloc.h>
+#endif
 /*}}}*/
 
 /* variables */ /*{{{*/
@@ -30,7 +36,7 @@ static void olddir(char **dirent, int entries)
   {
     for (i=l=0; i<entries; ++i)
     {
-      if (dirent[i][0]=='0'+user/10 && dirent[i][1]=='0'+user%33)
+      if (dirent[i][0]=='0'+user/10 && dirent[i][1]=='0'+user%10)
       {
         if (announce==1)
         {
@@ -45,9 +51,15 @@ static void olddir(char **dirent, int entries)
         for (; k<3; ++k) putchar(' ');
         ++l;
       }
-      if (l && (l%4)==0) putchar('\n');
+      if (l && (l%4)==0) {
+       l = 0;
+       putchar('\n');
+      }        
     }
-    if (l%4) putchar('\n');
+    if (l%4) {
+       putchar('\n');
+    }
+
     if (announce==2) announce=1;
   }
   if (entries==0) printf("No files\n");
@@ -75,7 +87,7 @@ static void oldddir(char **dirent, int entries, struct cpmInode *ino)
       {
         struct tm *tmp;
 
-        if (dirent[i][0]=='0'+user/10 && dirent[i][1]=='0'+user%33)
+        if (dirent[i][0]=='0'+user/10 && dirent[i][1]=='0'+user%10)
         {
           if (announce==1)
           {
@@ -93,16 +105,22 @@ static void oldddir(char **dirent, int entries, struct cpmInode *ino)
 
           cpmNamei(ino,dirent[i],&file);
           cpmStat(&file,&statbuf);
-          printf(" %5.1ldK",(statbuf.size+buf.f_bsize-1)/buf.f_bsize*(buf.f_bsize/1024));
+          printf(" %5.1ldK",(long) (statbuf.size+buf.f_bsize-1) /
+                       buf.f_bsize*(buf.f_bsize/1024));
+
           printf(" %6.1ld ",(long)(statbuf.size/128));
           putchar(statbuf.mode&0200 ? ' ' : 'R');
           putchar(statbuf.mode&01000 ? 'S' : ' ');
           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');
@@ -138,7 +156,7 @@ static void old3dir(char **dirent, int entries, struct cpmInode *ino)
       {
         struct tm *tmp;
 
-        if (dirent[i][0]=='0'+user/10 && dirent[i][1]=='0'+user%33)
+        if (dirent[i][0]=='0'+user/10 && dirent[i][1]=='0'+user%10)
         {
           cpmNamei(ino,dirent[i],&file);
           cpmStat(&file,&statbuf);
@@ -160,7 +178,8 @@ static void old3dir(char **dirent, int entries, struct cpmInode *ino)
 
           totalBytes+=statbuf.size;
           totalRecs+=(statbuf.size+127)/128;
-          printf(" %5.1ldk",(statbuf.size+buf.f_bsize-1)/buf.f_bsize*(buf.f_bsize/1024));
+          printf(" %5.1ldk",(long) (statbuf.size+buf.f_bsize-1) /
+                       buf.f_bsize*(buf.f_bsize/1024));
           printf(" %6.1ld ",(long)(statbuf.size/128));
           putchar((attrib & CPM_ATTR_F1)   ? '1' : ' ');
           putchar((attrib & CPM_ATTR_F2)   ? '2' : ' ');
@@ -174,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;
         }
@@ -210,7 +236,7 @@ static void ls(char **dirent, int entries, struct cpmInode *ino, int l, int c, i
     announce=0;
     for (i=0; i<entries; ++i) if (dirent[i][0]!='.')
     {
-      if (dirent[i][0]=='0'+user/10 && dirent[i][1]=='0'+user%33)
+      if (dirent[i][0]=='0'+user/10 && dirent[i][1]=='0'+user%10)
       {
         if (announce==0)
         {
@@ -224,7 +250,7 @@ static void ls(char **dirent, int entries, struct cpmInode *ino, int l, int c, i
           cpmNamei(ino,dirent[i],&file);
           cpmStat(&file,&statbuf);
         }
-        if (iflag) printf("%4ld ",statbuf.ino);
+        if (iflag) printf("%4ld ",(long) statbuf.ino);
         if (l)
         {
           struct tm *tmp;
@@ -245,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);
@@ -272,7 +298,7 @@ static void lsattr(char **dirent, int entries, struct cpmInode *ino)
     announce=0;
     for (i=0; i<entries; ++i) if (dirent[i][0]!='.')
     {
-      if (dirent[i][0]=='0'+user/10 && dirent[i][1]=='0'+user%33)
+      if (dirent[i][0]=='0'+user/10 && dirent[i][1]=='0'+user%10)
       {
         if (announce==0)
         {
@@ -310,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;
@@ -325,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;