[BACK]Return to crlf.c CVS log [TXT][DIR] Up to [local] / OpenXM / misc / packages / Windows / debug-tools

Annotation of OpenXM/misc/packages/Windows/debug-tools/crlf.c, Revision 1.2

1.2     ! ohara       1: /* $OpenXM: OpenXM/misc/packages/Windows/debug-tools/crlf.c,v 1.1 2002/01/16 09:11:59 takayama Exp $ */
1.1       takayama    2: #include <stdio.h>
                      3: main(int argc,char *argv[]) {
                      4:   FILE *fp;
                      5:   FILE *fp2;
                      6:   char s[1024];
                      7:   char fname[1024];
                      8:   int cr = 0;
                      9:   int c;
                     10:   if (argc < 2) {
                     11:     fprintf(stderr,"crlf filename\n");
1.2     ! ohara      12:     exit(1);
1.1       takayama   13:   }
                     14:   fp = fopen(argv[1],"r");
                     15:   if (fp == NULL) {
                     16:     fprintf(stderr,"Could not open the file %s.\n",argv[1]);
                     17:   }
                     18:   while ( (c=fgetc(fp)) != EOF) {
                     19:     if ( c == 0xd) {
                     20:       cr = 1; break;
                     21:     }
                     22:   }
                     23:   if (cr == 1) exit(0);  /* do nothing. Windows file. */
                     24:   fclose(fp);
                     25:
                     26:   sprintf(fname,"%s.BAK",argv[1]);
                     27:   sprintf(s,"cp %s %s",argv[1],fname);
                     28:   system(s);
                     29:
                     30:   fp = fopen(fname,"r");
                     31:   fp2 = fopen(argv[1],"w");
                     32:   while ((c=fgetc(fp)) != EOF) {
                     33:     if (c == 0xa) {
                     34:       fputc(0xd,fp2); fputc(0xa,fp2);
                     35:     }else{
                     36:       fputc(c,fp2);
                     37:     }
                     38:   }
                     39:   fclose(fp); fclose(fp2);
                     40: }
                     41:
                     42:

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>