dag

Djmoch's Auto Generator
git clone git://git.danielmoch.com/dag.git
Log | Files | Refs | README | LICENSE

commit dec2669b0e600d896f350ebd6d30629037c76f1d
parent 18f32a9be40d81ff0a3de609aba0629fae70af48
Author: Daniel Moch <daniel@danielmoch.com>
Date:   Wed,  2 Sep 2020 12:19:52 -0400

create separate module for m4

Diffstat:
Mconfig.mk | 2+-
Mdag.c | 21---------------------
Am4.c | 25+++++++++++++++++++++++++
3 files changed, 26 insertions(+), 22 deletions(-)

diff --git a/config.mk b/config.mk @@ -12,7 +12,7 @@ PREFIX := /usr/local MANPATH := ${PREFIX}/share/man X11BASE := /usr/X11R6 -SRC = dag.c string.c +SRC = dag.c string.c m4.c DIST_SRC = ${SRC} Makefile README config.mk OBJ = ${SRC:.c=.o} INCS = diff --git a/dag.c b/dag.c @@ -4,7 +4,6 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <sys/types.h> #include <sys/stat.h> #include <fts.h> #include <unistd.h> @@ -36,26 +35,6 @@ usage(int e_val) { } char * -make_m4_cmd(const char **defines, const int num_defines, const char *infile, const char *outfile) { - char *retval = malloc(strlen(M4) + 1); - sprintf(retval, M4); - - for (int i=0; i<num_defines; i++) { - /* "-D" + defines[i] + " " + '\0' */ - int len = strlen(defines[i]) + 4; - - retval = realloc(retval, strlen(retval) + len); - sprintf(retval, "%s -D%s", retval, defines[i]); - } - - retval = realloc(retval, strlen(retval) + strlen(infile) + strlen(" > ") + - strlen(outfile)); - sprintf(retval, "%s %s > %s", retval, infile, outfile); - - return retval; -} - -char * make_outpath(const char *out, const char *srcpath, char *src_argv[]) { for (int i=0; src_argv[i]!=NULL; i++) { if (strbegin(srcpath, src_argv[i])) { diff --git a/m4.c b/m4.c @@ -0,0 +1,25 @@ +/* See LICENSE file for copyright and license details */ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +char * +make_m4_cmd(const char **defines, const int num_defines, + const char *infile, const char *outfile) { + char *retval = malloc(strlen(M4) + 1); + sprintf(retval, M4); + + for (int i=0; i<num_defines; i++) { + /* "-D" + defines[i] + " " + '\0' */ + int len = strlen(defines[i]) + 4; + + retval = realloc(retval, strlen(retval) + len); + sprintf(retval, "%s -D%s", retval, defines[i]); + } + + retval = realloc(retval, strlen(retval) + strlen(infile) + + strlen(" > ") + strlen(outfile)); + sprintf(retval, "%s %s > %s", retval, infile, outfile); + + return retval; +}