File: convert.c

package info (click to toggle)
abuse 2.00-12
  • links: PTS
  • area: main
  • in suites: slink
  • size: 12,708 kB
  • ctags: 15,389
  • sloc: ansic: 115,852; cpp: 6,792; lisp: 2,066; sh: 1,734; makefile: 1,601; asm: 264
file content (39 lines) | stat: -rw-r--r-- 894 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/* Jonathan Clark April 5, 93   Converts Unix file for to DOS & vice versa. */
#include <stdio.h>

#define STReq(x,y) (!strcmp(x,y))
main(int argc, char **argv)
{
  FILE *fp,*o;
  int i,strip,add,c;
  char st[100];
  if (argc<3 || !(STReq(argv[1],"2unix") || STReq(argv[1],"2dos")))
  { printf("Usage : convert [2unix]|[2dos] files\n");
    exit(0);
  }
  if (STReq(argv[1],"2unix"))
  { strip=1; add=0; }
  else {strip=0; add=1; }
  printf("Converting...\n");
  for (i=2;i<argc;i++)
  {
    printf("  %s\n",argv[i]);
    fp=fopen(argv[i],"r"); 
    o=fopen("testXDF.out","w");
    while (!feof(fp))
    {
      c=fgetc(fp);
      if (c>=0)
      {
        if (c=='\n' && add) { fputc('\r',o); }
        if (!(c=='\r') || !strip)
          fputc(c,o); 
      }
    }
    fclose(o);
    fclose(fp);
    sprintf(st,"cp testXDF.out %s",argv[i]);
    system(st);
    unlink("testXDF.out"); 
  } 
}