[hackers] [scc] [driver] simplify out-filenames generation logic || Quentin Rameau

From: <git_AT_suckless.org>
Date: Mon, 4 Jul 2016 15:26:51 +0200 (CEST)

commit abe630986636294d50ba567fb73713cb7c219e0c
Author: Quentin Rameau <quinq_AT_fifth.space>
AuthorDate: Mon Jul 4 14:18:58 2016 +0200
Commit: Quentin Rameau <quinq_AT_fifth.space>
CommitDate: Mon Jul 4 15:20:36 2016 +0200

    [driver] simplify out-filenames generation logic

diff --git a/driver/posix/scc.c b/driver/posix/scc.c
index e3b0199..b1ffc02 100644
--- a/driver/posix/scc.c
+++ b/driver/posix/scc.c
_AT_@ -137,28 +137,29 @@ inittool(int tool)
 }
 
 static char *
-outfilename(char *path, char *ext)
+outfname(char *path, char *type)
 {
- char *new, *fmt, *p;
+ char *new, sep, *p;
         size_t newsz, pathln;
         int tmpfd, n;
 
         if (path) {
- fmt = "%.0s%.*4$s.%s";
+ sep = '.';
                 if (p = strrchr(path, '/'))
                         path = p + 1;
                 pathln = strlen(path);
                 if (p = strrchr(path, '.'))
                         pathln -= strlen(p);
- newsz = pathln + 1 + strlen(ext) + 1;
         } else {
- fmt = "%s/%s";
- path = "scc-XXXXXX";
- newsz = tmpdirln + 1 + strlen(path) + 1;
+ sep = '/';
+ type = "scc-XXXXXX";
+ path = tmpdir;
+ pathln = tmpdirln;
         }
 
+ newsz = pathln + 1 + strlen(type) + 1;
         new = xmalloc(newsz);
- n = snprintf(new, newsz, fmt, tmpdir, path, ext, pathln);
+ n = snprintf(new, newsz, "%.*s%c%s", path, pathln, sep, type);
         if (n < 0 || n >= newsz)
                 die("scc: wrong output filename");
         if ((tmpfd = mkstemp(new)) < 0 && errno != EINVAL)
_AT_@ -179,15 +180,15 @@ settool(int tool, char *infile, int nexttool)
 
         switch (tool) {
         case TEEIR:
- t->outfile = outfilename(infile, "ir");
+ t->outfile = outfname(infile, "ir");
                 addarg(tool, t->outfile);
                 break;
         case TEEQBE:
- t->outfile = outfilename(infile, "qbe");
+ t->outfile = outfname(infile, "qbe");
                 addarg(tool, t->outfile);
                 break;
         case TEEAS:
- t->outfile = outfilename(infile, "as");
+ t->outfile = outfname(infile, "as");
                 addarg(tool, t->outfile);
                 break;
         case AS:
_AT_@ -195,7 +196,7 @@ settool(int tool, char *infile, int nexttool)
                         objfile = outfile;
                 } else {
                         objfile = (cflag || kflag) ? infile : NULL;
- objfile = outfilename(objfile, "o");
+ objfile = outfname(objfile, "o");
                 }
                 t->outfile = xstrdup(objfile);
                 addarg(tool, t->outfile);
Received on Mon Jul 04 2016 - 15:26:51 CEST

This archive was generated by hypermail 2.3.0 : Mon Jul 04 2016 - 15:36:20 CEST