/* Converts DOS text file to UNIX/AMIGA format by removing CR's */ #include #include #include #include char *fnames[1024]; static void convert(char *dosfname) { static unsigned char buffer[32768]; FILE *unixf, *dosf; unsigned i, numread; dosf = fopen(dosfname, "rb"); unixf = fopen("DOSTEMP.$$$", "wb"); printf("Converting %s...\n", dosfname); do { numread = fread(buffer, 1, sizeof(buffer), dosf); for (i = 0; i < numread; i++) { if (buffer[i] != 0x0d) fwrite(&buffer[i], 1, 1, unixf); } } while (numread == sizeof(buffer)); fclose(unixf); fclose(dosf); remove(dosfname); rename("DOSTEMP.$$$", dosfname); } int main(int argc, char **argv) { static struct ffblk ffblk; int i, done, num_found = 0; if (argc < 2) { printf("DOS2UNIX converts DOS textfiles to UNIX/Amiga format\n"); printf("usage: dos2unix \n"); printf("Wildcards allowed\n"); exit(0); } done = findfirst(argv[1], &ffblk, 0); while (! done) { fnames[num_found] = malloc(strlen(ffblk.ff_name) + 1); strcpy(fnames[num_found++], ffblk.ff_name); done = findnext(&ffblk); } for (i = 0; i < num_found; i++) convert(fnames[i]); printf("OK.\n"); for (i = 0; i < num_found; i++) free(fnames[i]); return 0; } .