/* * iso2utf.c - Converts iso-8859-1 into utf-8 * * Usage: ./iso2utf * Author: Sean B. Palmer, http://purl.org/net/sbp/ * License: GPL 2; share and enjoy! */ #include #include #include #define BUFSIZE 4096 int main(int argc, char *argv[]) { int i; FILE *input; unsigned long length; unsigned char bytes[BUFSIZE]; if ((argc == 2) && (strcmp(argv[1], "-") != 1)) fopen(argv[1], "rb"); else input = stdin; if (input == NULL) { perror("iso2utf"); exit(EXIT_FAILURE); } while((length = fread(bytes, sizeof(char), BUFSIZE, input))) { for (i=0; i < length; i++) { if (bytes[i] < 0x80) putchar(bytes[i]); else if (bytes[i] < 0xC0) { putchar('\xC2'); putchar(bytes[i]); } else { putchar('\xC3'); putchar(bytes[i] - 64); } } } if (input != stdin) fclose(input); exit(EXIT_SUCCESS); }