backscratcher

 

ascii

Page history last edited by tbarron 11 mos ago

ascii

 

Notes

 

  • 2008.1214: added python version
  • 2008.1215: Reformated output to all show up in one window
  • 2008.1215: Added perldoc


 

ascii


#!/usr/bin/python
import sys
import ascii
ascii.main(sys.argv)

 

ascii.py


#!/usr/bin/python
'''
ascii - Display ASCII collating sequence.

Copyright (C) 1995 - <the end of time>  Tom Barron
  tom.barron@comcast.net
  227 Tusculum Drive
  Oak Ridge, TN  37830

This software is licensed under the CC-GNU GPL. For the full text of
the license, see http://creativecommons.org/licenses/GPL/2.0/

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
'''

import getopt
import sys

def main(argv = None):
    asc = ['NUL', 'SOH', 'STX', 'ETX', 'EOT', 'ENQ', 'ACK', 'BEL', 'BS',
           'TAB', 'LF', 'VT', 'FF', 'CR', 'SO', 'SI', 'DLE', 'DC1', 'DC2',
           'DC3', 'DC4', 'NAK', 'SYN', 'ETB', 'CAN', 'EM', 'SUB', 'ESC',
           'FS', 'GS', 'RS', 'US', 'SPC']

    for i in range(33):
        sys.stdout.write('0x%02x %-3s ' % (i, asc[i]))
        if (i+1) % 8 == 0:
            sys.stdout.write('n')

    for i in range(33,128):
        sys.stdout.write('0x%02x %-3c ' % (i, i))
        if (i+1) % 8 == 0:
            sys.stdout.write('n')

if __name__ == '__main__':
    unittest.main()


ascii.pl


#!/usr/bin/perl

@asc = ('NUL', 'SOH', 'STX', 'ETX', 'EOT', 'ENQ', 'ACK', 'BEL', 'BS',
        'TAB', 'LF', 'VT', 'FF', 'CR', 'SO', 'SI', 'DLE', 'DC1', 'DC2',
        'DC3', 'DC4', 'NAK', 'SYN', 'ETB', 'CAN', 'EM', 'SUB', 'ESC',
        'FS', 'GS', 'RS', 'US', 'SPC');

for ($i = 0 ; $i < @asc ; $i++) {
   printf("0x%02x %-3s ", $i, $asc[$i]);
   print("n") if ((($i + 1) % 8) == 0);

}

for ($i = 33 ; $i < 128 ; $i++) {
   printf("0x%02x %-3c ", $i, $i);
   print("n") if ((($i + 1) % 8) == 0);
}

__END__

=head1

ascii - Display ASCII collating sequence.

Copyright (C) 1995 - <the end of time>  Tom Barron
  tom.barron@comcast.net
  227 Tusculum Drive
  Oak Ridge, TN  37830

This software is licensed under the CC-GNU GPL. For the full text of
the license, see http://creativecommons.org/licenses/GPL/2.0/

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

=cut

Comments (0)

You don't have permission to comment on this page.