Logo Search packages:      
Sourcecode: maradns version File versions

utf8tol1.c

/* Process a UTF-8 sequence so that it becomes an iso 8859-1 string;
   hi-level unicodes become hash marks */

#include <stdio.h>

main() {
      int a,v;
      unsigned char c;

      while(!feof(stdin)) {
          c = getc(stdin);
        if(c<128) {
            printf("%c",c);
            }
          else {
            if(c < 0xe0) { /* two-byte sequence */
                  v = c & 0x1f;
              v <<= 6;
              c = getc(stdin);
              if(c != 255) 
                  v = v + (c & 0x3f);
                  else
                  exit(1);
                  printf("%c",v);
                } 
              else { /* multi-byte sequence */
                while(c & 0xc0 == 0x80 && !feof(stdin)) {
                  c = getc(stdin);
                  }
                  if(!feof(stdin))
                      printf("%c",'#');
                  }
            }
           fflush(stdout);
           }
      }

Generated by  Doxygen 1.6.0   Back to index