diff options
author | marcel <marcel@FreeBSD.org> | 2003-09-18 03:15:57 +0000 |
---|---|---|
committer | marcel <marcel@FreeBSD.org> | 2003-09-18 03:15:57 +0000 |
commit | 8c313e90831739d9340e924337499e3688d73202 (patch) | |
tree | 1bf554bbd1d69119e59c29da595809f6332956ad /usr.bin/make | |
parent | 1644dd5fce2192d54736b9824e5a6cd6ec9ef0fa (diff) | |
download | FreeBSD-src-8c313e90831739d9340e924337499e3688d73202.zip FreeBSD-src-8c313e90831739d9340e924337499e3688d73202.tar.gz |
Implement the O modifier. The O modifier sorts the words in a
variable. The implementation is based upon the patch sent to
arch@, but modified to be compatible with NetBSD. The modifier
that does a reverse sort has been dropped for now, but the
ability to add one later has been preserved.
Diffstat (limited to 'usr.bin/make')
-rw-r--r-- | usr.bin/make/var.c | 52 |
1 files changed, 51 insertions, 1 deletions
diff --git a/usr.bin/make/var.c b/usr.bin/make/var.c index 3221bdd..dd39ce6 100644 --- a/usr.bin/make/var.c +++ b/usr.bin/make/var.c @@ -608,6 +608,48 @@ VarModify (char *str, Boolean (*modProc)(const char *, Boolean, Buffer, void *), /*- *----------------------------------------------------------------------- + * VarSortWords -- + * Sort the words in the string. + * + * Input: + * str String whose words should be sorted + * cmp A comparison function to control the ordering + * + * Results: + * A string containing the words sorted + * + * Side Effects: + * None. + * + *----------------------------------------------------------------------- + */ +static char * +VarSortWords(char *str, int (*cmp)(const void *, const void *)) +{ + Buffer buf; + char **av; + int ac, i; + + buf = Buf_Init(0); + av = brk_string(str, &ac, FALSE); + qsort((void*)(av + 1), ac - 1, sizeof(char*), cmp); + for (i = 1; i < ac; i++) { + Buf_AddBytes(buf, strlen(av[i]), (Byte *)av[i]); + Buf_AddByte(buf, (Byte)((i < ac - 1) ? ' ' : '\0')); + } + str = (char *)Buf_GetAll(buf, (int *)NULL); + Buf_Destroy(buf, FALSE); + return (str); +} + +static int +SortIncreasing(const void *l, const void *r) +{ + return (strcmp(*(const char* const*)l, *(const char* const*)r)); +} + +/*- + *----------------------------------------------------------------------- * VarGetPattern -- * Pass through the tstr looking for 1) escaped delimiters, * '$'s and backslashes (place the escaped character in @@ -1114,7 +1156,7 @@ Var_Parse(char *str, GNode *ctxt, Boolean err, int *lengthPtr, Boolean *freePtr) DEBUGF(VAR, ("Applying :%c to \"%s\"\n", *tstr, str)); switch (*tstr) { - case 'U': + case 'U': if (tstr[1] == endc || tstr[1] == ':') { Buffer buf; buf = Buf_Init(MAKE_BSIZE); @@ -1448,6 +1490,14 @@ Var_Parse(char *str, GNode *ctxt, Boolean err, int *lengthPtr, Boolean *freePtr) free(pattern.matches); break; } + case 'O': + if (tstr[1] == endc || tstr[1] == ':') { + newStr = VarSortWords(str, SortIncreasing); + cp = tstr + 1; + termc = *cp; + break; + } + /* FALLTHROUGH */ case 'Q': if (tstr[1] == endc || tstr[1] == ':') { newStr = VarQuote (str); |