]> granicus.if.org Git - graphviz/commitdiff
suitable filenames for intermediate .ps.png images
authorellson <devnull@localhost>
Tue, 18 Oct 2005 18:53:40 +0000 (18:53 +0000)
committerellson <devnull@localhost>
Tue, 18 Oct 2005 18:53:40 +0000 (18:53 +0000)
contrib/diffimg/diffimg.c

index bda190e75eb386db6f35150fcd134b82e8cfab11..721be8369a6f0791fe7681545022ec96431850da 100644 (file)
@@ -41,7 +41,7 @@ static char *pstopng="gs -dNOPAUSE -sDEVICE=pngalpha -sOutputFile=- -q -";
 static gdImagePtr imageLoad (char *filename)
 {
     FILE *f;
-    char *ext, *cmd, *tmp, *base;
+    char *ext, *cmd, *tmp;
     gdImagePtr im;
     int rc;
     struct stat statbuf;
@@ -58,31 +58,32 @@ static gdImagePtr imageLoad (char *filename)
     }
     if (strcasecmp(ext, ".ps") == 0) {
        ext = ".png";
-       base = strrchr(filename, '/');
-       if (base != filename)
-           base++;
-       tmp = malloc(strlen(base) + 20 + strlen(ext));
-       strcpy(tmp,"/tmp/diffimg-");
-       strcat(tmp,base);
+       tmp = malloc(strlen(filename) + strlen(ext) + 1);
+       strcpy(tmp,filename);
        strcat(tmp,ext);
        
-       cmd = malloc(strlen(pstopng) + strlen(filename) + strlen(tmp) + 10);
+       cmd = malloc(strlen(pstopng) + 2 + strlen(filename) + 2 + strlen(tmp) + 1);
        strcpy(cmd,pstopng);
        strcat(cmd," <");
        strcat(cmd,filename);
        strcat(cmd," >");
        strcat(cmd,tmp);
        rc = system(cmd);
+       free(cmd);
        
         f = fopen(tmp, "rb");
-       free(cmd);
        free(tmp);
+        if (!f) {
+            fprintf(stderr, "Failed to open converted \"%s%s\"\n", filename, ext);
+            exit(1);
+        }
     }
     else
-        f = fopen(filename, "rb");
-    if (!f) {
-        fprintf(stderr, "Failed to open \"%s\"\n", filename);
-        exit(1);
+        f = fopen(filename, "rb");{
+        if (!f) {
+            fprintf(stderr, "Failed to open \"%s\"\n", filename);
+            exit(1);
+        }
     }
     im = 0;
     if (strcasecmp(ext, ".png") == 0)