]> granicus.if.org Git - libexpat/commitdiff
No more search for (back)slashes in the string "STDIN".
authorKarl Waclawek <kwaclaw@users.sourceforge.net>
Mon, 30 Apr 2007 00:50:22 +0000 (00:50 +0000)
committerKarl Waclawek <kwaclaw@users.sourceforge.net>
Mon, 30 Apr 2007 00:50:22 +0000 (00:50 +0000)
Optimized code with regards to use of path delimters on different platforms.

expat/xmlwf/xmlwf.c

index 4b455d1ee16c15f137c04d9de0a84cb49ca9b3cb..82082a730144adb52d988a9c667d1a882b2e1427 100755 (executable)
@@ -777,17 +777,28 @@ tmain(int argc, XML_Char **argv)
       XML_SetProcessingInstructionHandler(parser, nopProcessingInstruction);
     }
     else if (outputDir) {
+      const XML_Char * delim = T("/");
       const XML_Char *file = useStdin ? T("STDIN") : argv[i];
-      if (tcsrchr(file, T('/')))
-        file = tcsrchr(file, T('/')) + 1;
+      if (!useStdin) {
+        /* Jump after last (back)slash */
+        const XML_Char * lastDelim = tcsrchr(file, delim[0]);
+        if (lastDelim)
+          file = lastDelim + 1;
 #if (defined(WIN32) || defined(__WATCOMC__))
-      if (tcsrchr(file, T('\\')))
-        file = tcsrchr(file, T('\\')) + 1;
+        else {
+          const XML_Char * winDelim = T("\\");
+          lastDelim = tcsrchr(file, winDelim[0]);
+          if (lastDelim) {
+            file = lastDelim + 1;
+            delim = winDelim;
+          }
+        }
 #endif
+      }
       outName = (XML_Char *)malloc((tcslen(outputDir) + tcslen(file) + 2)
                        * sizeof(XML_Char));
       tcscpy(outName, outputDir);
-      tcscat(outName, T("/"));
+      tcscat(outName, delim);
       tcscat(outName, file);
       fp = tfopen(outName, T("wb"));
       if (!fp) {