Hello,

Am Sunday, den 21. April 2002 13:13:16 schrieb berberic:
> I appended a patch for cat.c. 

I'm very sorry, but as I just noticed the patch was not against the
original sources, but against a patched version of the sources from my
linux-distribution. This time I attached the (hopefully) correct patch.
(I repeat the explanation:)

cat -v prints every character out of 32..127 as ^ or M- notation. This
might be sufficient for the english speaking world, but is an anoyance
for europeans, because it destroys text strings containing accented
charakters, umlauts, etc. I added a new option (-p or
--show-locale-chars) that does not change characters that are
printable in the actual locale (using isprint).

This is quite usefull for non-english-speaking peoples because it
allows to "strip" control-chars from a "text"-stream without
destroying accented characters, umlauts, ...

        MfG
        bmg

-- 
"Des is völlig wurscht, was heut beschlos- | M G Berberich
 sen wird: I bin sowieso dagegn!"          | [EMAIL PROTECTED]
(SPD-Stadtrat Kurt Schindler; Regensburg)  |
diff -Naur textutils-2.0/po/de.po textutils-2.0-isprint/po/de.po
--- textutils-2.0/po/de.po      Fri Aug  6 22:56:36 1999
+++ textutils-2.0-isprint/po/de.po      Sun Apr 21 14:53:45 2002
@@ -42,6 +43,8 @@
 "  -T, --show-tabs          display TAB characters as ^I\n"
 "  -u                       (ignored)\n"
 "  -v, --show-nonprinting   use ^ and M- notation, except for LFD and TAB\n"
+"  -p, --show-locale-chars  don't use ^ and M- notation for characters\n"
+"                           that are printable in the current locale\n"
 "      --help               display this help and exit\n"
 "      --version            output version information and exit\n"
 "\n"
@@ -59,6 +59,8 @@
 "  -T, --show-tabs          gib TAB-Zeichen als ^I aus\n"
 "  -u                       (ignoriert)\n"
 "  -v, --show-nonprinting   benutze ^ und M- Notation, außer für LFD und TAB\n"
+"  -p, --show-locale-chars  benutze keine ^ und M- Notation für Zeichen\n"
+"                           die in der eingestellten Sprache druckbar sind.\n"
 "      --help               gib diese Hilfe aus und beende das Programm\n"
 "      --version            gib Versionsinformation aus und beende das "
 "Programm\n"
diff -Naur textutils-2.0/src/cat.c textutils-2.0-isprint/src/cat.c
--- textutils-2.0/src/cat.c     Tue May 18 16:12:03 1999
+++ textutils-2.0-isprint/src/cat.c     Sun Apr 21 14:54:44 2002
@@ -102,6 +102,8 @@
   -T, --show-tabs          display TAB characters as ^I\n\
   -u                       (ignored)\n\
   -v, --show-nonprinting   use ^ and M- notation, except for LFD and TAB\n\
+  -p, --show-locale-chars  don't use ^ and M- notation for characters\n\
+                           that are printable in the current locale\n\
       --help               display this help and exit\n\
       --version            output version information and exit\n\
 \n\
@@ -199,6 +201,7 @@
 
      /* Variables that have values according to the specified options.  */
      int quote,
+     int printable,
      int output_tabs,
      int numbers,
      int numbers_at_empty_lines,
@@ -395,35 +398,33 @@
        {
          for (;;)
            {
-             if (ch >= 32)
+             if ((!printable && ch >= 32 && ch < 127) ||
+                 (printable && isprint(ch)))
+               *bpout++ = ch;
+             else if (ch == 127)
                {
-                 if (ch < 127)
-                   *bpout++ = ch;
-                 else if (ch == 127)
-                   {
-                     *bpout++ = '^';
-                     *bpout++ = '?';
-                   }
-                 else
+                 *bpout++ = '^';
+                 *bpout++ = '?';
+               }
+             else if (ch > 127)
+               {
+                 *bpout++ = 'M';
+                 *bpout++ = '-';
+                 if (ch >= 128 + 32)
                    {
-                     *bpout++ = 'M';
-                     *bpout++ = '-';
-                     if (ch >= 128 + 32)
-                       {
-                         if (ch < 128 + 127)
-                           *bpout++ = ch - 128;
-                         else
-                           {
-                             *bpout++ = '^';
-                             *bpout++ = '?';
-                           }
-                       }
+                     if (ch < 128 + 127)
+                       *bpout++ = ch - 128;
                      else
                        {
                          *bpout++ = '^';
-                         *bpout++ = ch - 128 + 64;
+                         *bpout++ = '?';
                        }
                    }
+                 else
+                   {
+                     *bpout++ = '^';
+                     *bpout++ = ch - 128 + 64;
+                   }
                }
              else if (ch == '\t' && output_tabs)
                *bpout++ = '\t';
@@ -437,7 +438,7 @@
                  *bpout++ = '^';
                  *bpout++ = ch + 64;
                }
-
+             
              ch = *bpin++;
            }
        }
@@ -505,6 +506,7 @@
   int squeeze_empty_lines = 0;
   int mark_line_ends = 0;
   int quote = 0;
+  int printable = 0;
   int output_tabs = 1;
 #if O_BINARY
   int binary_files  = 0;
@@ -521,6 +523,7 @@
     {"number", no_argument, NULL, 'n'},
     {"squeeze-blank", no_argument, NULL, 's'},
     {"show-nonprinting", no_argument, NULL, 'v'},
+    {"show-locale-chars", no_argument, NULL, 'p'},
     {"show-ends", no_argument, NULL, 'E'},
     {"show-tabs", no_argument, NULL, 'T'},
     {"show-all", no_argument, NULL, 'A'},
@@ -541,9 +544,9 @@
 
   while ((c = getopt_long (argc, argv,
 #if O_BINARY
-                          "benstuvABET"
+                          "benpstuvABET"
 #else
-                          "benstuvAET"
+                          "benpstuvAET"
 #endif
                           , long_options, NULL)) != -1)
     {
@@ -569,6 +572,11 @@
          numbers = 1;
          break;
 
+       case 'p':
+         ++options;
+         printable = 1;
+         break;
+
        case 's':
          ++options;
          squeeze_empty_lines = 1;
@@ -796,7 +804,7 @@
 
          outbuf = (unsigned char *) xmalloc (outsize - 1 + insize * 4 + 13);
 
-         cat (inbuf, insize, outbuf, outsize, quote,
+         cat (inbuf, insize, outbuf, outsize, quote, printable,
               output_tabs, numbers, numbers_at_empty_lines, mark_line_ends,
               squeeze_empty_lines);
 

Attachment: msg00784/pgp00000.pgp
Description: PGP signature

Reply via email to