Re: The joy of octal

Liste des GroupesRevenir à col misc 
Sujet : Re: The joy of octal
De : fritz (at) *nospam* spamexpire-202411.rodent.frell.theremailer.net (Fritz Wuehler)
Groupes : comp.os.linux.misc
Date : 12. Nov 2024, 23:45:25
Autres entêtes
Organisation : dizum.com - The Internet Problem Provider
Message-ID : <70ac3933f2b6e0f3539c739acc5a792d@msgid.frell.theremailer.net>
References : 1 2 3
Chris Ahlstrom <OFeem1...@teleworm.us> [CA]:
CA> I still haven't found a program that would easily reverse
CA> octal to a string.

You have to take into account the writer machine's endianness
and character set encoding (EBCDIC anyone?).

If it's a big-endian system and the encoding is ASCII, use the
following script. It preserves regular text and converts only what
it sees as octal numbers.

Modifying it to also accept EBCDIC encoded text on a non-EBCDIC
system is left as an exercise for the reader.

I would assume that if you could find a bourne shell, 'sed' and 'awk'
on some EBCDIC system, the script might work without changes.
Can anyone comment on this?


#!/bin/sh

DELIMITER="__octal_number_delimiter__" ;

# Step1:  locate octal numbers in input
sed 's@\b\([0-7 ]\+\)\b@'"$DELIMITER"'\1'"$DELIMITER"'@g' |

# Step2:  convert octal numbers to text, leaving everything else as it is
awk -v FS="$DELIMITER" -v Q='"' '{
  for (i=1;i<=NF;i++) {   # for all line fields
    t = $i;    # get the i-th line field
    if (i%2) { # regular text; do not touch it

      printf "%s", t;

    } else {   # octal number; process it

      gsub(" ","", t);     # remove any space characters first

      # make sure the number of octal digits is a mulitiple of 6
      for (j=1;j<=(length(t)%6);j++) t = "0" t;

      # break up the octal string to sextuplets
      for (j=1;j<=length(t)/6;j++) {

        # convert a 6-digit octal number to a 4-digit hex number
        six_octal_digits=substr(t,6*j-5,6);
        four_hex_digits = sprintf ("%x", strtonum(0 six_octal_digits));

        # process each pair of hex digits (a byte)
        for (k=1;k<=length(four_hex_digits)/2;k++) {
          two_hex_digits=substr(four_hex_digits,2*k-1, 2);
          # output this byte as an ASCII character (escape non-printable ones)
          char = strtonum("0x" two_hex_digits);
          printf (((char < 32) ? "<%02x>" : "%c"), char);
        }
      }
    }
  }
  print "";   # add a newline
}
'


Date Sujet#  Auteur
9 Nov 24 * The joy of octal66Chris Ahlstrom
11 Nov 24 `* Re: The joy of octal65John Ames
11 Nov 24  +* Re: The joy of octal49Chris Ahlstrom
12 Nov 24  i+* Re: The joy of octal47Chris Ahlstrom
12 Nov 24  ii`* Re: The joy of EBCDIC46John Ames
12 Nov 24  ii +* Re: The joy of EBCDIC3Chris Ahlstrom
12 Nov 24  ii i`* Re: The joy of EBCDIC2candycanearter07
13 Nov 24  ii i `- Re: The joy of EBCDIC1Chris Ahlstrom
14 Nov 24  ii `* Re: The joy of EBCDIC42Fritz Wuehler
14 Nov 24  ii  `* Re: The joy of EBCDIC41Clemens Schüller
15 Nov 24  ii   `* Re: The joy of EBCDIC40Eli the Bearded
15 Nov 24  ii    `* Re: The joy of pipes39John Ames
15 Nov 24  ii     +* Re: The joy of pipes37Lawrence D'Oliveiro
15 Nov 24  ii     i`* Re: The joy of pipes36186282@ud0s4.net
15 Nov 24  ii     i +- Re: The joy of pipes1John Ames
16 Nov 24  ii     i +- Re: The joy of pipes1Lawrence D'Oliveiro
16 Nov 24  ii     i +* Re: The joy of pipes2Robert Riches
16 Nov 24  ii     i i`- Re: The joy of pipes1Lawrence D'Oliveiro
16 Nov 24  ii     i +* Re: The joy of pipes4186282@ud0s4.net
16 Nov 24  ii     i i`* Re: The joy of pipes3rbowman
16 Nov 24  ii     i i `* Re: The joy of pipes2186282@ud0s4.net
17 Nov 24  ii     i i  `- Re: The joy of pipes1186282@ud0s4.net
16 Nov 24  ii     i `* Re: The joy of pipes27Richard Kettlewell
17 Nov 24  ii     i  `* Re: The joy of pipes26186282@ud0s4.net
17 Nov 24  ii     i   +* Re: The joy of pipes4Lawrence D'Oliveiro
17 Nov 24  ii     i   i`* Re: The joy of pipes3186282@ud0s4.net
17 Nov 24  ii     i   i `* Re: The joy of pipes2Lawrence D'Oliveiro
17 Nov 24  ii     i   i  `- Re: The joy of pipes1186282@ud0s4.net
17 Nov 24  ii     i   `* Re: The joy of pipes21Richard Kettlewell
18 Nov 24  ii     i    `* Re: The joy of pipes20186282@ud0s4.net
18 Nov 24  ii     i     +* Re: The joy of pipes17Lawrence D'Oliveiro
18 Nov 24  ii     i     i`* Re: The joy of pipes16186282@ud0s4.net
18 Nov 24  ii     i     i `* Re: The joy of pipes15Pancho
18 Nov 24  ii     i     i  +* Re: The joy of pipes13Lawrence D'Oliveiro
18 Nov 24  ii     i     i  i`* Re: The joy of pipes12Pancho
18 Nov 24  ii     i     i  i +* Re: The joy of pipes8The Natural Philosopher
18 Nov 24  ii     i     i  i i+* Re: The joy of pipes3Pancho
18 Nov 24  ii     i     i  i ii+- Re: The joy of pipes1The Natural Philosopher
18 Nov 24  ii     i     i  i ii`- Re: The joy of pipes1rbowman
19 Nov 24  ii     i     i  i i`* Re: The joy of pipes4186282@ud0s4.net
19 Nov 24  ii     i     i  i i +- Re: The joy of pipes1Lawrence D'Oliveiro
19 Nov 24  ii     i     i  i i +- Re: The joy of pipes1The Natural Philosopher
19 Nov 24  ii     i     i  i i `- Re: The joy of pipes1Richard Kettlewell
18 Nov 24  ii     i     i  i `* Re: The joy of pipes3rbowman
19 Nov 24  ii     i     i  i  `* Re: The joy of pipes2Pancho
19 Nov 24  ii     i     i  i   `- Re: The joy of pipes1Lawrence D'Oliveiro
19 Nov 24  ii     i     i  `- Re: The joy of pipes1186282@ud0s4.net
19 Nov 24  ii     i     `* Re: The joy of pipes2Robert Riches
19 Nov 24  ii     i      `- Re: The joy of pipes1Lawrence D'Oliveiro
15 Nov 24  ii     `- Re: The joy of pipes1Eli the Bearded
12 Nov 24  i`- Re: The joy of octal1Eli the Bearded
12 Nov 24  `* Re: The joy of octal15Fritz Wuehler
15 Nov 24   `* Re: The joy of octal14186282@ud0s4.net
15 Nov 24    `* Re: The joy of octal13rbowman
16 Nov 24     +* Re: The joy of octal7186282@ud0s4.net
16 Nov 24     i`* Re: The joy of octal6rbowman
16 Nov 24     i `* Re: The joy of octal5186282@ud0s4.net
16 Nov 24     i  +* Re: The joy of octal2Don_from_AZ
17 Nov 24     i  i`- Re: The joy of octal1186282@ud0s4.net
16 Nov 24     i  `* Re: The joy of octal2rbowman
17 Nov 24     i   `- Re: The joy of octal1186282@ud0s4.net
16 Nov 24     `* Re: The joy of octal5186282@ud0s4.net
16 Nov 24      +- Re: The joy of octal1rbowman
16 Nov 24      `* Re: The joy of octal3Andreas Eder
16 Nov 24       `* Re: The joy of octal2The Natural Philosopher
17 Nov 24        `- Re: The joy of octal1186282@ud0s4.net

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal