[Date Prev] [Date Next] [Thread Prev] [Thread Next] Date Index Thread Index Search archive:
Date:Mon Aug 8 15:14:05 1995 
Subject:dump program 
From:Steve Knight 
Volume-ID:950809.03 

Hi Jerry,

Could you be more specific about the dump that you require?
Is the dump supposed to just be a long list printed to
standard output?  How are non-printing characters to be
handled in the ASCII listing?  How wide is the listing?
What happens if the file does not exist or is unreadable?

Assuming that it is simply to be scrolled to standard output,
that the width of the listing is arbitrary, that non-printing
ASCII characters are printed using the arbitrary character
"~", and that the Hex and ASCII are to be displayed side
by side, that the behaviour is undefined for problematic
files  .... here's a POP11 program that does the job and
some sample output.

Steve

--- Program -------------------------------

define dump( filename ); lvars filename;

    ;;; Arbitrary constants.
    lconstant
        gap = 4,                            ;;; spacing between columns.
        non_printing_char_char = `~`,
        bytes_per_line = 16,                ;;; must be greater than 0.
        buffer = inits( bytes_per_line );   ;;; create string of right length.

    define lconstant is_printing_char( ch ); lvars ch;
        32 <= ch and ch <= 126
    enddefine;

    define lconstant hex( n ); lvars n;
        lconstant hex_chars = '0123456789ABCDEF';
        cucharout( hex_chars( n + 1 ) )
    enddefine;

    define lconstant flush_buffer( n ); lvars n;
        returnunless( n > 0 );
        ;;; Hex printing loop.
        lvars i;
        for i from 1 to n do
            lvars ch = buffer( i );
            hex( ch >> 4 );                 ;;; print high nibble
            hex( ch && 16:F );              ;;; print low nibble
            cucharout( `\s` );              ;;; and a space
        endfor;
        ;;; pad to a fixed column.  Note that each byte takes 3 chars.
        repeat 3 * ( bytes_per_line - n ) + gap times
            cucharout( `\s` )
        endrepeat;
        ;;; ASCII printing loop.
        for i from 1 to n do
            lvars ch = buffer( i );
            cucharout(
                ch.is_printing_char and ch or
                non_printing_char_char
            )
        endfor;
        cucharout( `\n` );
    enddefine;

    ;;; n counts how full the buffer is.
    lvars n = 0;

    ;;; Add a character to the buffer.  If buffer is full
    ;;; then flush it and try again.
    define lconstant add_char( ch ); lvars ch;
        if n < bytes_per_line then
            n + 1 -> n;
            ch -> buffer( n );
        else
            flush_buffer( n );
            0 -> n;
            add_char( ch )
        endif;
    enddefine;

    apprepeater( filename.discin, add_char );
    flush_buffer( n );
enddefine;


--- Sample output ----

;;; Invoke the program on my ~/.login file.
dump( '~/.login' );
23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23     ################
23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23     ################
23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23     ################
23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23     ################
23 23 23 23 23 23 0A 23 23 20 53 74 65 76 65 20     ######~## Steve
4B 6E 69 67 68 74 27 73 20 52 65 63 6F 6E 73 74     Knight's Reconst
72 75 63 74 65 64 20 4C 6F 67 69 6E 20 46 69 6C     ructed Login Fil
65 20 23 23 23 23 23 23 23 23 23 23 23 23 23 23     e ##############
23 23 23 23 23 23 23 23 23 23 23 23 23 23 0A 23     ##############~#
23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23     ################
23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23     ################
23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23     ################
23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23     ################
23 23 23 23 23 23 0A 0A 23 20 73 65 74 20 69 6E     ######~~# set in
69 74 69 61 6C 20 70 61 74 68 3A 0A 23 20 73 65     itial path:~# se
74 20 70 61 74 68 3D 28 2F 75 73 72 2F 6C 6F 63     t path=(/usr/loc
61 6C 2F 62 69 6E 20 2F 75 73 72 2F 6C 6F 63 61     al/bin /usr/loca
6C 2F 62 69 6E 2F 58 31 31 20 2F 75 73 72 2F 63     l/bin/X11 /usr/c
6F 6E 74 72 69 62 2F 62 69 6E 20 2F 62 69 6E 20     ontrib/bin /bin
2F 75 73 72 2F 62 69 6E 20 24 70 61 74 68 29 0A     /usr/bin $path)~
0A 23 20 73 65 74 20 65 6E 76 69 72 6F 6E 6D 65     ~# set environme
6E 74 3A 0A 73 65 74 20 6D 61 6E 70 61 74 68 3D     nt:~set manpath=
28 2F 74 6F 6F 6C 73 2F 6F 73 2F 6D 61 6E 20 2F     (/tools/os/man /
74 6F 6F 6C 73 2F 61 72 63 68 2F 6D 61 6E 20 2F     tools/arch/man /
75 73 72 2F 6D 61 6E 20 2F 75 73 72 2F 6C 6F 63     usr/man /usr/loc
61 6C 2F 6D 61 6E 20 2F 75 73 72 2F 63 6F 6E 74     al/man /usr/cont
72 69 62 2F 6D 61 6E 29 0A 73 65 74 65 6E 76 20     rib/man)~setenv
54 5A 20 47 4D 54 30 42 53 54 20 20 20 20 20 20     TZ GMT0BST
20 20 20 20 20 20 20 20 20 20 20 20 20 23 20 63                  # c
68 61 6E 67 65 20 74 68 69 73 20 66 6F 72 20 6C     hange this for l
6F 63 61 6C 20 74 69 6D 65 2E 0A 73 65 74 65 6E     ocal time.~seten
76 20 50 52 49 4E 54 45 52 20 65 6C 6D 0A 73 65     v PRINTER elm~se
74 65 6E 76 20 4C 50 44 45 53 54 20 24 50 52 49     tenv LPDEST $PRI
4E 54 45 52 0A 73 65 74 65 6E 76 20 50 41 47 45     NTER~setenv PAGE
52 20 6C 65 73 73 0A 0A 23 20 4D 69 73 63 65 6C     R less~~# Miscel
6C 61 6E 65 6F 75 73 20 73 68 65 6C 6C 2D 6F 6E     laneous shell-on
6C 79 20 61 63 74 69 6F 6E 73 3A 0A 73 65 74 20     ly actions:~set
6D 61 69 6C 20 3D 20 28 33 30 20 2F 75 73 72 2F     mail = (30 /usr/
6D 61 69 6C 2F 24 4C 4F 47 4E 41 4D 45 29 0A 73     mail/$LOGNAME)~s
65 74 65 6E 76 20 4D 41 49 4C 52 45 43 20 7E 2F     etenv MAILREC ~/
61 74 74 69 63 2F 6D 61 69 6C 72 65 63 0A 23 20     attic/mailrec~#
6E 65 77 73 20 2D 6E 20 20 20 20 20 20 20 20 20     news -n
20 20 20 20 23 20 6E 6F 74 69 66 79 20 69 66 20         # notify if
6E 65 77 20 6E 65 77 73 2E 0A 0A 23 20 41 75 74     new news.~~# Aut
6F 6C 6F 67 6F 75 74 0A 75 6E 73 65 74 20 61 75     ologout~unset au
74 6F 6C 6F 67 6F 75 74 0A 0A 23 20 50 6F 70 6C     tologout~~# Popl
6F 67 0A 23 65 63 68 6F 20 73 6F 75 72 63 65 20     og~#echo source
2E 70 6F 70 6C 6F 67 0A 23 73 6F 75 72 63 65 20     .poplog~#source
7E 2F 2E 70 6F 70 6C 6F 67 0A 0A 23 20 41 64 64     ~/.poplog~~# Add
20 50 65 72 73 6F 6E 61 6C 20 73 74 75 66 66 20      Personal stuff
26 20 54 6F 6F 6C 73 20 74 6F 20 50 41 54 48 0A     & Tools to PATH~
73 65 74 20 70 61 74 68 3D 28 7E 2F 61 64 6D 69     set path=(~/admi
6E 2F 62 69 6E 20 24 70 61 74 68 20 2F 74 6F 6F     n/bin $path /too
6C 73 62 69 6E 2F 6F 73 2F 62 69 6E 20 2F 74 6F     lsbin/os/bin /to
6F 6C 73 2F 61 72 63 68 2F 62 69 6E 20 2F 74 6F     ols/arch/bin /to
6F 6C 73 2F 61 72 63 68 2F 62 69 6E 2F 58 31 31     ols/arch/bin/X11
20 2F 74 6F 6F 6C 73 2F 6F 73 2F 62 69 6E 2F 58      /tools/os/bin/X
31 31 29 0A 0A 23 20 53 65 74 20 75 70 20 74 65     11)~~# Set up te
72 6D 69 6E 61 6C 0A 73 74 74 79 20 65 72 61 73     rminal~stty eras
65 20 5C 5E 68 20 6B 69 6C 6C 20 5C 5E 75 20 69     e \^h kill \^u i
6E 74 72 20 5C 5E 63 20 20 20 20 23 20 63 68 61     ntr \^c    # cha
6E 67 65 20 74 6F 20 48 50 20 64 65 66 61 75 6C     nge to HP defaul
74 73 2E 0A 0A 23 20 65 6E 64 20 6F 66 20 66 69     ts.~~# end of fi
6C 65 0A 0A 23 45 6E 76 69 72 6F 6E 6D 65 6E 74     le~~#Environment
20 76 61 72 69 61 62 6C 65 73 20 66 6F 72 20 4C      variables for L
6F 74 75 73 20 31 32 33 0A 73 65 74 65 6E 76 20     otus 123~setenv
4C 4F 54 55 53 20 2F 74 6F 6F 6C 73 2F 73 37 30     LOTUS /tools/s70
30 2F 38 2E 30 2F 74 6F 6F 6C 73 2F 6C 6F 74 75     0/8.0/tools/lotu
73 0A 73 65 74 20 70 61 74 68 3D 28 20 24 70 61     s~set path=( $pa
74 68 20 24 4C 4F 54 55 53 2F 31 32 33 2E 76 31     th $LOTUS/123.v1
32 2F 68 70 37 30 30 2F 62 69 6E 20 29 0A           2/hp700/bin )~