bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

address@hidden: ls --translators (coreutils)]


From: Alfred M. Szmidt
Subject: address@hidden: ls --translators (coreutils)]
Date: Tue, 16 Sep 2003 15:06:18 +0200 (MEST)

[I'm keeping bug-hurd in the CC since maybe someone on that list has
something to comment.]

Ping.

Cheers.
------- Start of forwarded message -------
Date: Sun, 17 Aug 2003 12:46:26 +0200 (MEST)
From: "Alfred M. Szmidt" <address@hidden>
To: address@hidden, address@hidden
Cc: 
Subject: ls --translators (coreutils)

Howdy,

here is a new version of a patch that nobody can live without, the
whooping --translator patch for ls! It will list your translators and
cook your socks in a fashion that has never been seen before.  And did
I say that it also works and compiles without warnings? There are also
screenshots attached in a amazing 80x25 char. resolution, using 2
colors and encoded in ASCII. Enjoy!


There is two small problems, the first one is argz.h.  Adding a special check
for it in configure.ac and then doing an ifdef seems abit over kill
for one function call.  Right now it just checks for hurd.h, and
assumes that argz.h exists (which will work since all GNU/Hurd systems
run glibc).  If the current solution is not liked then I'll change it
and send another patch (or the person commiting the change can do it).

The second problem is that I haven't tested if this compiles on
GNU/Linux, could someone do that for me and report back? --translator
on GNU/Linux should be a no-op.

~/test $ settrans -ac look_a_GNU_says_hello_over_there /hurd/hello
~/test $ settrans -c look_a_passive_GNU_says_hello_over_there /hurd/hello
~/test $ /obj/devel/ams/coreutils/src/ls --translator -l 
total 4
- -r--r--r--    1 ams      ams            14 Aug 16 21:31 
look_a_GNU_says_hello_over_there => unknown (2709)
- -r--r--r--    1 ams      ams            14 Aug 16 21:31 
look_a_passive_GNU_says_hello_over_there => /hurd/hello (2718)
~/test $ 

2003-08-16  Alfred M. Szmidt  <address@hidden>

        Add support for new ls option, --translator, for GNU/Hurd.

        * doc/coreutils.texi (ls invocation), NEWS: Document this.
        * configure.ac: Check for <hurd.h>.
        * src/ls.c [HAVE_HURD_H]: Include <hurd.h> and <argz.h>.
        (struct fileinfo) [HAVE_HURD_H]: New members trans_name,
        trans_fsid and trans_mode.
        (print_translator): New variable.
        (TRANSLATOR_OPTION): New enum value.
        (long_options, decode_switches, gobble_file)
        (print_long_format, usage): Support --translator.

diff -upr /src-cvs/coreutils/NEWS /home/ams/src/coreutils/NEWS
- --- /src-cvs/coreutils/NEWS   1980-01-04 16:52:01.000000000 +0100
+++ /home/ams/src/coreutils/NEWS        2003-08-16 21:52:07.000000000 +0200
@@ -13,6 +13,8 @@ GNU coreutils NEWS                      
   timestamps to their full nanosecond resolution; microsecond
   resolution is the best we can do right now.
 
+  ls can now list translators (--translator) on GNU/Hurd.
+
 ** Bug fixes
 
   fold -s -wN would infloop for N < 8 with TABs in the input.
diff -upr /src-cvs/coreutils/configure.ac /home/ams/src/coreutils/configure.ac
- --- /src-cvs/coreutils/configure.ac   2003-08-10 16:00:14.000000000 +0200
+++ /home/ams/src/coreutils/configure.ac        2003-08-16 20:27:31.000000000 
+0200
@@ -250,6 +250,8 @@ fi
 # For src/kill.c.
 AC_CHECK_DECLS([strsignal, strtoimax, sys_siglist, _sys_siglist, 
__sys_siglist])
 
+AC_CHECK_HEADERS(hurd.h)
+
 jm_LIB_CHECK
 
 AM_GNU_GETTEXT([external], [need-ngettext])
diff -upr /src-cvs/coreutils/doc/coreutils.texi 
/home/ams/src/coreutils/doc/coreutils.texi
- --- /src-cvs/coreutils/doc/coreutils.texi     2003-08-10 16:00:14.000000000 
+0200
+++ /home/ams/src/coreutils/doc/coreutils.texi  2003-08-16 20:29:13.000000000 
+0200
@@ -5267,6 +5267,12 @@ megabytes.  Powers of 1000 are used, not
 @option{--human-readable} option if
 you prefer powers of 1024.
 
address@hidden --translator
address@hidden --translator
address@hidden --translator
+Print the arguments and the fsid (also called the file system id) that a
+passive or active translator was started with to the right of the file name.
+
 @end table
 
 
diff -upr /src-cvs/coreutils/src/ls.c /home/ams/src/coreutils/src/ls.c
- --- /src-cvs/coreutils/src/ls.c       2003-07-27 13:41:33.000000000 +0200
+++ /home/ams/src/coreutils/src/ls.c    2003-08-16 21:47:20.000000000 +0200
@@ -52,6 +52,11 @@
 # include <sys/ptem.h>
 #endif
 
+#if HAVE_HURD_H
+# include <hurd.h>
+# include <argz.h>
+#endif
+
 #include <stdio.h>
 #include <assert.h>
 #include <setjmp.h>
@@ -204,6 +209,18 @@ struct fileinfo
     /* For symbolic link, name of the file linked to, otherwise zero. */
     char *linkname;
 
+#if HAVE_HURD_H    
+    /* The translator that is attached to the node.  */
+    char *trans_name;
+    
+    /* The fsid for the active translator.  */
+    int trans_fsid;
+    
+    /* If 1 then we have a translator attached and/or running on the node,
+       otherwise 0.  */
+    int trans_mode;
+#endif
+
     /* For symbolic link and long listing, st_mode of file linked to, otherwise
        zero. */
     mode_t linkmode;
@@ -442,6 +459,10 @@ static bool print_author;
 
 static int print_group = 1;
 
+/* Nonzero means to display translator information.  */
+
+static int print_translator = 0;
+
 /* Nonzero means print the user and group id's as numbers rather
    than as names.  -n  */
 
@@ -692,6 +713,7 @@ enum
   SI_OPTION,
   SORT_OPTION,
   TIME_OPTION,
+  TRANSLATOR_OPTION,
   TIME_STYLE_OPTION
 };
 
@@ -735,6 +757,7 @@ static struct option const long_options[
   {"color", optional_argument, 0, COLOR_OPTION},
   {"block-size", required_argument, 0, BLOCK_SIZE_OPTION},
   {"author", no_argument, 0, AUTHOR_OPTION},
+  {"translator", no_argument, 0, TRANSLATOR_OPTION},
   {GETOPT_HELP_OPTION_DECL},
   {GETOPT_VERSION_OPTION_DECL},
   {NULL, 0, NULL, 0}
@@ -1571,6 +1594,10 @@ decode_switches (int argc, char **argv)
           print_author = true;
           break;
 
+       case TRANSLATOR_OPTION:
+         print_translator = true;
+         break;
+
        case SORT_OPTION:
          sort_type = XARGMATCH ("--sort", optarg, sort_args, sort_types);
          sort_type_specified = 1;
@@ -2435,6 +2462,51 @@ gobble_file (const char *name, enum file
            free (linkpath);
        }
 
+#if HAVE_HURD_H
+      if ((files[files_index].stat.st_mode & S_ITRANS) && print_translator)
+       {
+          int trans_fd;
+         file_t trans_port;
+          struct stat trans_stat;
+         
+          files[files_index].trans_fsid = files[files_index].stat.st_fsid;
+         
+          /* Get the underlying node */
+         trans_fd = open (path, O_NOTRANS);
+         if ((trans_fd && fstat (trans_fd, &trans_stat)) < 0)
+           {
+             error (0, errno, "%s", quotearg_colon (path));
+             close (trans_fd);
+             exit_status = 1;
+             return 0;
+           }
+         
+         trans_port = getdport (trans_fd);
+         close (trans_fd);
+         
+          if (trans_stat.st_mode & S_IPTRANS)
+            {
+              char buf[1024], *trans = buf;
+              int trans_len = sizeof (buf);
+             
+             if (file_get_translator (trans_port, &trans, &trans_len))
+                {
+                 mach_port_deallocate (mach_task_self(), trans_port);
+                  error (0, errno, "%s", quotearg_colon (path));
+                  exit_status = 1;
+                  return 0;
+                }
+              
+              argz_stringify (trans, trans_len, ' ');
+              
+              files[files_index].trans_name = strdup(trans);
+              files[files_index].trans_mode = 1;
+             
+             mach_port_deallocate (mach_task_self(), trans_port);
+           }
+       }
+#endif
+
       if (S_ISLNK (files[files_index].stat.st_mode))
        files[files_index].filetype = symbolic_link;
       else if (S_ISDIR (files[files_index].stat.st_mode))
@@ -3092,6 +3164,22 @@ print_long_format (const struct fileinfo
            print_type_indicator (f->linkmode);
        }
     }
+#if HAVE_HURD_H
+  else if ((f->stat.st_mode & S_ITRANS)
+          && print_translator)
+    {
+      DIRED_FPUTS_LITERAL (" => ", stdout);
+      if (f->trans_name)
+       printf ("%s", f->trans_name);
+      else
+       printf ("unknown");
+      
+      printf (" (%d)", f->trans_fsid);
+      if (indicator_style != none)
+       print_type_indicator (f->stat.st_mode);
+
+    }
+#endif
   else if (indicator_style != none)
     print_type_indicator (f->stat.st_mode);
 }
@@ -3852,6 +3940,7 @@ Mandatory arguments to long options are 
                              non-recent files and FORMAT2 to recent files;\n\
                              if STYLE is prefixed with `posix-', STYLE\n\
                              takes effect only outside the POSIX locale\n\
+      --translator           show active/passive translator information\n\
   -t                         sort by modification time\n\
   -T, --tabsize=COLS         assume tab stops at each COLS instead of 8\n\
 "), stdout);


_______________________________________________
Bug-hurd mailing list
address@hidden
http://mail.gnu.org/mailman/listinfo/bug-hurd
------- End of forwarded message -------




reply via email to

[Prev in Thread] Current Thread [Next in Thread]