Subject: umpteenth patch for /bin/ls compatibility
From: Camiel Dobbelaar <[email-masked]>
To: [email-masked]
Date: Tue, 19 Sep 2000 13:31:19 +0200

This is a multi-part message in MIME format.
--------------D9C68AB37BA772D49F3599AB
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Let me post the umpteenth patch for /bin/ls compatibility for
publicfile. I feel that this one has the following advantages:
- it does not use stdio (sprintf, snprintf) that publicfile so carefully
avoids; it only uses the DJB substdio functions.
- avoids the use of bounded arrays (char [xx];)
- it tries to mimic the EPLF implementation in the amount of information
that is put out (for example: non-regular files or unreadable files will
have rights '----------' and size 0)

Tested succesfully with Netscape, IE, and the OpenBSD ftp client.

It does not work with ncftp. (ncftp does not really issue 'cd' commands
to the ftp-server. It caches this information to issue commands with the
cached path as an argument). I have seen patches on this mailinglist
that address this issue as well, but I feel it's not publicfile's
problem.

--
Cam
--------------D9C68AB37BA772D49F3599AB
Content-Type: text/plain; charset=us-ascii;
 name="patch-compat"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="patch-compat"

--- fetch.c.orig	Tue Nov  9 08:23:46 1999
+++ fetch.c	Tue Sep 19 11:48:13 2000
@@ -40,24 +40,36 @@
 
 static void printstat()
 {
-  substdio_puts(&ss,"+i");
-  substdio_put(&ss,strnum,fmt_ulong(strnum,(unsigned long) st.st_dev));
-  substdio_puts(&ss,".");
-  substdio_put(&ss,strnum,fmt_ulong(strnum,(unsigned long) st.st_ino));
+  char *longstring;
+  int len;
 
-  if (st.st_mtime > 0)
-    if (st.st_mtime < now - 60) {
-      substdio_puts(&ss,",m");
-      substdio_put(&ss,strnum,fmt_ulong(strnum,(unsigned long) st.st_mtime));
-    }
-
-  if ((st.st_mode & S_IFMT) == S_IFDIR)
-    substdio_puts(&ss,",/");
-  if (((st.st_mode & S_IFMT) == S_IFREG) && ((st.st_mode & 0444) == 0444)) {
-    substdio_puts(&ss,",r,s");
-    substdio_put(&ss,strnum,fmt_ulong(strnum,(unsigned long) st.st_size));
+  /* rights, links, user, group */
+  if (((st.st_mode & S_IFMT) == S_IFREG) && ((st.st_mode & 0444) == 0444)) 
+    substdio_puts(&ss,"-r--r--r--  1 pub  pub ");
+  else if ((st.st_mode & S_IFMT) == S_IFDIR)
+    substdio_puts(&ss,"dr-xr-xr-x  2 pub  pub ");
+  else {
+    substdio_puts(&ss,"----------  1 pub  pub ");
+    /* do not reveal size, the EPLF implementation does not either */
+    st.st_size = 0;
   }
-  substdio_puts(&ss,",\t");
+
+  /* size */
+  len = fmt_ulong(strnum,(unsigned long) st.st_size);
+  /* Internet Explorer gets deeply confused when using tabs, so */
+  /* align size using this ugly hack, to suit textmode clients. */
+  substdio_put(&ss,"          ",((10-len) > 0) ? (10-len):0);
+  substdio_put(&ss,strnum,len);
+  substdio_puts(&ss," ");
+
+  /* date, time/year */
+  longstring = ctime(&st.st_mtime);
+  substdio_put(&ss,longstring+4,7);
+  if (st.st_mtime + ((365/2)*86400) > now)
+    substdio_put(&ss,longstring+11,5);
+  else
+    substdio_put(&ss,longstring+19,5);
+  substdio_puts(&ss," ");
 }
 
 static void list(char *fn,int flaglong)

--------------D9C68AB37BA772D49F3599AB--