convert.c 894 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /* Jonathan Clark April 5, 93 Converts Unix file for to DOS & vice versa. */
  2. #include <stdio.h>
  3. #define STReq(x,y) (!strcmp(x,y))
  4. main(int argc, char **argv)
  5. {
  6. FILE *fp,*o;
  7. int i,strip,add,c;
  8. char st[100];
  9. if (argc<3 || !(STReq(argv[1],"2unix") || STReq(argv[1],"2dos")))
  10. { printf("Usage : convert [2unix]|[2dos] files\n");
  11. exit(0);
  12. }
  13. if (STReq(argv[1],"2unix"))
  14. { strip=1; add=0; }
  15. else {strip=0; add=1; }
  16. printf("Converting...\n");
  17. for (i=2;i<argc;i++)
  18. {
  19. printf(" %s\n",argv[i]);
  20. fp=fopen(argv[i],"r");
  21. o=fopen("testXDF.out","w");
  22. while (!feof(fp))
  23. {
  24. c=fgetc(fp);
  25. if (c>=0)
  26. {
  27. if (c=='\n' && add) { fputc('\r',o); }
  28. if (!(c=='\r') || !strip)
  29. fputc(c,o);
  30. }
  31. }
  32. fclose(o);
  33. fclose(fp);
  34. sprintf(st,"cp testXDF.out %s",argv[i]);
  35. system(st);
  36. unlink("testXDF.out");
  37. }
  38. }