/* test.c Change ^^ab in foo.ind into an unsigned char without test Usage: test foo.ind */ #include #include #include #define TMPNAM "ind-tmp-x.xxx" unsigned char tohex(unsigned char c) { unsigned char ret; if(c >= 'a' && c <= 'f') ret = c - 'a' + 10; else if(c >= '0' && c <= '9') ret = c - '0'; return ret; } int main(int argc, char **argv) { FILE *fin, *fout; unsigned char ibuff[4096], obuff[4096]; unsigned char *p, *q; fin = fopen(argv[1], "r"); fout = fopen(TMPNAM, "w"); while(fgets(ibuff, 4094, fin)) { p = ibuff; q = obuff; while(*p) { if(strncmp(p, "^^", 2) == 0) { p += 2; *q = tohex(*p) * 16; p++; *q += tohex(*p); q++; p++; } else { *q++ = *p++; } } *q = '\0'; fputs(obuff, fout); } fclose(fin); fclose(fout); unlink(argv[1]); rename(TMPNAM, argv[1]); return 0; }