Mercurial > hg > mlmmj
diff src/ctrlvalue.c @ 754:ecb991e41a4c
Add $controlN$ substitution
The interfaces to substitute() and substitute_one() have changed, as they
now need to know the listdir to be able to find control files
author | Ben Schmidt |
---|---|
date | Wed, 06 Oct 2010 23:30:26 +1100 |
parents | 7da5c55b9330 |
children | bb803487199c |
line wrap: on
line diff
--- a/src/ctrlvalue.c Wed Oct 06 23:26:26 2010 +1100 +++ b/src/ctrlvalue.c Wed Oct 06 23:30:26 2010 +1100 @@ -33,10 +33,10 @@ #include "chomp.h" #include "memory.h" -char *ctrlvalue(const char *listdir, const char *ctrlstr) +static char *ctrlval(const char *listdir, const char *ctrlstr, int oneline) { char *filename, *value = NULL; - int ctrlfd; + int ctrlfd, i; if(listdir == NULL) return NULL; @@ -48,12 +48,32 @@ if(ctrlfd < 0) return NULL; + if (oneline) { value = mygetline(ctrlfd); + chomp(value); + } else { + value = mygetcontent(ctrlfd); + i = strlen(value) - 1; + if (i >= 0 && value[i] == '\n') { + value[i] = '\0'; + i--; + } + if (i >= 0 && value[i] == '\r') { + value[i] = '\0'; + i--; + } + } close(ctrlfd); - chomp(value); return value; } +char *ctrlvalue(const char *listdir, const char *ctrlstr) +{ + return ctrlval(listdir, ctrlstr, 1); +} - +char *ctrlcontent(const char *listdir, const char *ctrlstr) +{ + return ctrlval(listdir, ctrlstr, 0); +}