home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / pp / pp-6.0 / Format / charset / test / progs / bit2ch.c next >
Encoding:
C/C++ Source or Header  |  1991-05-20  |  888 b   |  65 lines

  1. /* bit2ch.c - converts one 8 bit string at a time into a one byte character */
  2.  
  3. # ifndef lint
  4. static char Rcsid[] = "@(#)$Header$";
  5. # endif
  6.  
  7. /*
  8.  * $Header$
  9.  *
  10.  * $Log$
  11.  */
  12.  
  13.  
  14. #include <stdio.h>
  15. #include "charset.h"
  16.  
  17. #define BITS    8
  18.  
  19.  
  20. main (argc, argv)
  21. int    argc;
  22. CHAR8U    *argv[];
  23. {
  24.     CHAR8U    buf[BUFSIZ];    
  25.     int    i = 0;
  26.  
  27.     bzero (buf, sizeof (buf)); 
  28.  
  29.     if (argc == 1)
  30.         while (gets (buf) != NULL) {
  31.             convert (&buf[0]);    
  32.             bzero (buf, sizeof (buf)); 
  33.         }
  34.     else
  35.         while (i < argc-1)
  36.             convert (argv[++i]);
  37.  
  38.     printf ("\n");
  39. }
  40.  
  41.  
  42.  
  43. /* ---------------------  Static  Routines  ------------------------------- */
  44.  
  45.  
  46. static convert(str)
  47. CHAR8U    *str;
  48. {
  49.     int    i;
  50.     CHAR8U    c=0;
  51.  
  52.     for (i=BITS-1; i >= 0; i--) {
  53.         if (str[i] == '1')
  54.             c |= 1 << (BITS - (i+1));
  55.         else if (str[i] == '0')
  56.             continue;
  57.         else {
  58.             printf ("**** Error this is not a bitstring\n");
  59.             return;
  60.         }
  61.     }
  62.  
  63.     printf ("%d - %c", c, c);
  64. }
  65.