dag

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

commit 1c291f956e3c0a953913172b6e8b187b193a239d
parent 9475ac0f6b795ba8a0d118c80467b20b3535395c
Author: Daniel Moch <daniel@danielmoch.com>
Date:   Tue,  1 Sep 2020 19:32:31 -0400

string.c: Add dedup function. Use in dag.c.

Diffstat:
ATODO.txt | 2++
Mdag.c | 3++-
Mstring.c | 23++++++++++++++++++-----
Mstring.h | 9++++++++-
4 files changed, 30 insertions(+), 7 deletions(-)

diff --git a/TODO.txt b/TODO.txt @@ -0,0 +1,2 @@ +- If one "in" directory is an exact substring of another, that will + cause problems with make_outpath. diff --git a/dag.c b/dag.c @@ -119,6 +119,7 @@ main(int argc, char **argv) { path_argv[i] = argv[i]; } path_argv[argc - 1] = NULL; + dedup(path_argv); out = argv[argc - 1]; FTS *src_tree = fts_open(path_argv, FTS_LOGICAL, NULL); @@ -132,7 +133,7 @@ main(int argc, char **argv) { char *outpath = make_outpath(out, entry->fts_accpath, path_argv); printf("%s: found file -- %s\n", argv0, entry->fts_accpath); - printf("%s: creating file -- %s/%s\n", argv0, out, entry->fts_accpath); + printf("%s: creating file -- %s\n", argv0, outpath); free(outpath); } } diff --git a/string.c b/string.c @@ -1,8 +1,5 @@ -/* See LICENSE file for copyright and license details - * - * NOTE: All functions in this file assume strings are NUL-terminated - * unless otherwise specified - */ +/* See LICENSE file for copyright and license details */ +#include <stdio.h> #include <string.h> int @@ -35,3 +32,19 @@ strnswp(char *big, const char *old, const char *new, size_t max) { memcpy(begin, new, newlen); } + +void +dedup(char **strarray) { + int i = 0; + while(strarray[i] != NULL) { + for(int j=0; j!=i; j++) { + if(strcmp(strarray[i], strarray[j]) == 0) { + for(int k=i; strarray[k]!=NULL; k++) { + strarray[k] = strarray[k+1]; + } + break; + } + } + i++; + } +} diff --git a/string.h b/string.h @@ -1,4 +1,11 @@ -/* See LICENSE file for copyright and license details */ +/* See LICENSE file for copyright and license details + * + * NOTE: All functions in this file assume strings are NUL-terminated + * unless otherwise specified + */ int strbegin(const char *big, const char *little); char *strnswp(char *big, const char *old, const char *new, size_t max); + +/* assumes the last element of strarray is NULL */ +void dedup(char **strarray);