dag

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

commit 2e8463cd040448770bc299f722d07c8027976576
parent 790790236554089f69023d7e28ba96bca9f71303
Author: Daniel Moch <daniel@danielmoch.com>
Date:   Fri,  9 Oct 2020 14:39:35 -0400

K&R style

Diffstat:
Mdag.c | 19++++++++-----------
Alowdown.c | 37+++++++++++++++++++++++++++++++++++++
Mm4.c | 3++-
Mstring.c | 9++++++---
Mstring_test.c | 21++++++++++++++-------
5 files changed, 67 insertions(+), 22 deletions(-)

diff --git a/dag.c b/dag.c @@ -20,7 +20,8 @@ enum { }; void -usage(int e_val) { +usage(int e_val) +{ FILE *fp; if (e_val) { @@ -30,12 +31,13 @@ usage(int e_val) { fp = stdout; } - fprintf(fp, "usage: %s [-hv] [-Dname=value ...] [-H header] [-f footer] in ... out\n", argv0); + fprintf(fp, "usage: %s [-hv] [-Dname=value ...] in ... out\n", argv0); exit(e_val); } char * -make_outpath(const char *out, const char *srcpath, char *src_argv[]) { +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])) { char *outpath = NULL; @@ -55,10 +57,11 @@ make_outpath(const char *out, const char *srcpath, char *src_argv[]) { } int -main(int argc, char **argv) { +main(int argc, char **argv) +{ char ch, *header = NULL, *footer = NULL, *defines[MAX_DEFINES]; char *out; - int num_defines = 0; + size_t num_defines = 0; argv0 = basename(argv[0]); FTSENT *entry = NULL; @@ -68,12 +71,6 @@ main(int argc, char **argv) { defines[num_defines] = optarg; num_defines += 1; break; - case 'f': - footer = optarg; - break; - case 'H': - header = optarg; - break; case 'h': usage(ERR_NONE); break; diff --git a/lowdown.c b/lowdown.c @@ -0,0 +1,37 @@ +/* See LICENSE file for copyright and license details */ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include "util.h" + +static const char redir[] = " > "; + +char * +lowdown_html_cmd(const char *infile, const char *outfile) +{ + char *retval = malloc(strlen(LOWDOWN) + 1); + sprintf(retval, LOWDOWN); + + const char html[] = " -Thtml "; + + retval = realloc(retval, strlen(retval) + strlen(html) + + strlen(infile) + strlen(redir) + strlen(outfile)); + sprintf(retval, "%s %s > %s", retval, infile, outfile); + + return retval; +} + +char * +lowdown_pdf_cmd(const char *infile, const char *outfile) +{ + char *retval = malloc(strlen(LOWDOWN) + 1); + sprintf(retval, LOWDOWN); + + const char pdf[] = " -Tms | TROFF | + retval = realloc(retval, strlen(retval) + strlen(infile) + + strlen(redir) + strlen(outfile)); + sprintf(retval, "%s %s > %s", retval, infile, outfile); + + return retval; +} diff --git a/m4.c b/m4.c @@ -5,7 +5,8 @@ char * make_m4_cmd(const char **defines, const int num_defines, - const char *infile, const char *outfile) { + const char *infile, const char *outfile) +{ char *retval = malloc(strlen(M4) + 1); sprintf(retval, M4); diff --git a/string.c b/string.c @@ -3,12 +3,14 @@ #include <string.h> int -strbegin(const char *big, const char *little) { +strbegin(const char *big, const char *little) +{ return (strstr(big, little) == big); } void -strnswp(char *big, const char *old, const char *new, size_t max) { +strnswp(char *big, const char *old, const char *new, size_t max) +{ size_t biglen = strlen(big); size_t oldlen = strlen(old); size_t newlen = strlen(new); @@ -34,7 +36,8 @@ strnswp(char *big, const char *old, const char *new, size_t max) { } void -dedup(char **strarray) { +dedup(char **strarray) +{ int i = 0; while(strarray[i] != NULL) { for(int j=0; j!=i; j++) { diff --git a/string_test.c b/string_test.c @@ -4,7 +4,8 @@ #include "string.h" int -test_strnswp1() { +test_strnswp1() +{ char big[] = "thisandthat"; char old[] = "and"; char new[] = "foo"; @@ -19,7 +20,8 @@ test_strnswp1() { } int -test_strnswp2() { +test_strnswp2() +{ char big[12] = "thisandthat"; char old[] = "and"; char new[] = "foot"; @@ -34,7 +36,8 @@ test_strnswp2() { } int -test_strnswp3() { +test_strnswp3() +{ char big[] = "thisandthat"; char old[] = "and"; char new[] = "fo"; @@ -49,7 +52,8 @@ test_strnswp3() { } int -test_strnswp4() { +test_strnswp4() +{ char big[] = "thisandthat"; char old[] = "and"; char new[] = ""; @@ -64,7 +68,8 @@ test_strnswp4() { } int -test_strnswp5() { +test_strnswp5() +{ char big[] = "thisandthat"; char old[] = "and"; char new[] = "foot"; @@ -79,7 +84,8 @@ test_strnswp5() { } int -test_strnswp6() { +test_strnswp6() +{ char big[] = "thisandthat"; char old[] = "foot"; char new[] = "bat"; @@ -93,7 +99,8 @@ test_strnswp6() { return 0; } -int main() { +int main() +{ int retval = test_strnswp1(); retval |= test_strnswp2(); retval |= test_strnswp3();