home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d1xx / d162 / cli_utilities.lha / CLI_Utilities / StripBin / Stripbin.c < prev    next >
C/C++ Source or Header  |  1988-10-02  |  2KB  |  77 lines

  1. /* stripbin.c
  2.    22 July 1988
  3.  
  4.    Copyright (c) 1988 by Fabbian G. Dufoe, III
  5.    All rights reserved.
  6.  
  7.    Permission is granted to redistribute this program provided the source
  8.    code is included in the distribution and this copyright notice is
  9.    unchanged.
  10.  
  11.    This program reads its standard input, deletes any binary characters,
  12.    and writes to standard output.  The user may optionally have binary codes
  13.    translated to spaces (0x20) or represented in hexadecimal notation.
  14.  
  15.    Binary characters are all the control characters (less than 0x20) except
  16.    NULL (0x00), HORIZONTAL TAB (0x09), LINE FEED (0x0a), FORM FEED (0x0c),
  17.    CARRIAGE RETURN (0x0d), and ESCAPE (0x1b).  Also, high ASCII characters
  18.    from 0x7f to 0x9f are binary.  In other words, binary characters are
  19.    those which the AmigaDOS screen editor Ed will refuse to process.
  20.  
  21.    The following command line options determine how binary characters in the
  22.    input stream will be treated:
  23.  
  24.       -s    translate binary characters to spaces.
  25.       -h    represent binary characters in hexadecimal notation.
  26.  
  27. */
  28.  
  29. #include <stdio.h>
  30. #include <fcntl.h>
  31.  
  32. int
  33. main(argc, argv)
  34. int argc;
  35. char **argv;
  36. {
  37.    int c;
  38.    void puthex(int);
  39.  
  40.    c = getchar();
  41.    while (c != EOF)
  42.    {
  43.       if (((c > 0x00) && (c < 0x09)) ||
  44.           (c == 0x0b) ||
  45.           ((c > 0x0d) && (c < 0x1b)) ||
  46.           ((c > 0x1b) && (c < 0x20)) ||
  47.           ((c > 0x7e) && (c < 0xa0)))
  48.       {
  49.          if (argv[1][1] == 's')
  50.             putchar(0x20);
  51.          else if (argv[1][1] == 'h')
  52.             puthex(c);
  53.       }
  54.       else
  55.          putchar(c);
  56.       c = getchar();
  57.    }
  58.    return(0);
  59. }
  60.  
  61. void
  62. puthex(c)
  63. int c;
  64. {
  65.    int h;
  66.    int l;
  67.    static char list[] = "0123456789abcdef";
  68.  
  69.    h = c / 16;
  70.    l = c % 16;
  71.    putchar('0');
  72.    putchar('x');
  73.    putchar(list[h]);
  74.    putchar(list[l]);
  75.    return;
  76. }
  77.