]> git.saurik.com Git - wxWidgets.git/blobdiff - distrib/msw/unix2dos.c
don't show warning to the user if session manager detection failed, this is annoying...
[wxWidgets.git] / distrib / msw / unix2dos.c
index 991b8517c56e2fa4a8ccc60b45d87fd77ff1d255..f725b9ee51dfaffb4f2ee2993cb7585c9a061a2c 100644 (file)
@@ -37,7 +37,7 @@ main(int argc, char *argv[])
     unix2Dos = 1;
     
     i = 1;
-    if (i > argc)
+    if (argc > 1)
     {
         if (strcmp(argv[1], "--help") == 0)
         {
@@ -69,24 +69,26 @@ main(int argc, char *argv[])
             char tmpFile[512];
             sprintf(tmpFile, "%s.tmp", argv[i]);
             
-            fp = fopen(argv[i], "r");
-            outFile = fopen(tmpFile, "w");
-            if (!outFile)
-            {
-                fprintf(stderr, "Cannot open %s.\n", tmpFile);
-                exit(1);
-            }
+            fp = fopen(argv[i], "rb");
             if (!fp)
             {
                 fprintf(stderr, "Cannot open %s.\n", argv[i]);
+                i ++;
+                continue;
+            }
+            outFile = fopen(tmpFile, "wb");
+            if (!outFile)
+            {
+                fprintf(stderr, "Cannot open %s.\n", tmpFile);
                 exit(1);
             }
             translate(fp, outFile, unix2Dos);
             
             if (warning) /* unix2dos acting on a possible DOS file */
             {
-                fprintf(stderr,"%s: %s may have already been in DOS format.\n",
-                    prog, argv[i]);
+                fprintf(stderr,"%s: %s may have already been in DOS format. Not converted.\n",
+                        prog, argv[i]);
+                warning = 0;
             }
             fclose(fp);
             fclose(outFile);
@@ -110,28 +112,37 @@ void translate(FILE *ifp, FILE *ofp, int unix2Dos)
     int c,d;
     
     if (!unix2Dos)
+    {
         /* DOS2Unix */
-        while ((c = getc(ifp)) != EOF){
+        while ((c = getc(ifp)) != EOF)
+        {
             if (c == CR)
-                switch(d = getc(ifp)){ /* check to see if LF follows */
-    case LF:
-        putc(d,ofp);         /* if so, ignore CR */
-        break;
-    default:
-        putc(c,ofp);         /* if not, output CR and following char */
-        putc(d,ofp);
-            }   else putc(c, ofp); /* c is not a CR */
+            {
+                switch(d = getc(ifp))
+                { /* check to see if LF follows */
+                    case LF:
+                        putc(d,ofp);         /* if so, ignore CR */
+                        break;
+                    default:
+                        putc(c,ofp);         /* if not, output CR and following char */
+                        putc(d,ofp);
+                }
+            }
+            else
+                putc(c, ofp); /* c is not a CR */
         }
-        
-        else
+     }
+     else
+        {
             /* Unix2DOS */
             while ((c = getc(ifp)) != EOF){
                 if (c == CR)
                     warning = 1;   /* set warning flag: input file may be a DOS file */
-                if (c == LF
+                if (c == LF && (warning == 0))
                     putc(CR, ofp); /* add CR before each LF */
                 putc(c, ofp);
             }
+        }
 }
 
 void usage()