]> granicus.if.org Git - yasm/commitdiff
Replace extension on output format rather than just always appending.
authorPeter Johnson <peter@tortall.net>
Sun, 2 Dec 2001 22:33:20 +0000 (22:33 -0000)
committerPeter Johnson <peter@tortall.net>
Sun, 2 Dec 2001 22:33:20 +0000 (22:33 -0000)
svn path=/trunk/yasm/; revision=379

frontends/yasm/yasm.c
src/main.c

index 8dccd9d04fa07cdd7e2dd85cd190d15605816d35..a1e105ef43e0d789c8b7c4bfc7180aac83dd931b 100644 (file)
@@ -139,13 +139,18 @@ main(int argc, char *argv[])
     /* open the object file if not specified */
     if (!obj) {
        /* build the object filename */
-       /* TODO: replace the existing extension; this just appends. */
+       char *exttail;
        if (obj_filename)
            xfree(obj_filename);
        assert(in_filename != NULL);
+       /* allocate enough space for full existing name + extension */
        obj_filename = xmalloc(strlen(in_filename)+
                               strlen(cur_objfmt->extension)+2);
-       sprintf(obj_filename, "%s.%s", in_filename, cur_objfmt->extension);
+       strcpy(obj_filename, in_filename);
+       exttail = strrchr(obj_filename, '.');
+       if (!exttail)
+           exttail = strrchr(obj_filename, '\0');
+       sprintf(exttail, ".%s", cur_objfmt->extension);
 
        /* open the built filename */
        obj = fopen(obj_filename, "wb");
index 8dccd9d04fa07cdd7e2dd85cd190d15605816d35..a1e105ef43e0d789c8b7c4bfc7180aac83dd931b 100644 (file)
@@ -139,13 +139,18 @@ main(int argc, char *argv[])
     /* open the object file if not specified */
     if (!obj) {
        /* build the object filename */
-       /* TODO: replace the existing extension; this just appends. */
+       char *exttail;
        if (obj_filename)
            xfree(obj_filename);
        assert(in_filename != NULL);
+       /* allocate enough space for full existing name + extension */
        obj_filename = xmalloc(strlen(in_filename)+
                               strlen(cur_objfmt->extension)+2);
-       sprintf(obj_filename, "%s.%s", in_filename, cur_objfmt->extension);
+       strcpy(obj_filename, in_filename);
+       exttail = strrchr(obj_filename, '.');
+       if (!exttail)
+           exttail = strrchr(obj_filename, '\0');
+       sprintf(exttail, ".%s", cur_objfmt->extension);
 
        /* open the built filename */
        obj = fopen(obj_filename, "wb");