看板 DFBSD_submit 關於我們 聯絡資訊
This is a multi-part message in MIME format. --------------010605040506050005080900 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Add O modifier to make. This patch was missed in last round of commits. I guess my mega patch caused more problems. Back to small patches. :-) --------------010605040506050005080900 Content-Type: text/plain; name="patch-4.25" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="patch-4.25" --------------------- PatchSet 320, 321 Date: 2003/09/18 04:15:57 Author: marcel, ru Log: 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. Document the `O' modifier. Members: var.c:1.42->1.43 make.1:1.63->1.64 Members: Index: var.c =================================================================== RCS file: /usr/home/okumoto/Work/make/fbsd-cvs/src/usr.bin/make/var.c,v retrieving revision 1.42 retrieving revision 1.43 diff -u -r1.42 -r1.43 --- var.c 15 Jan 2003 22:36:15 -0000 1.42 +++ var.c 18 Sep 2003 03:15:57 -0000 1.43 @@ -608,6 +608,48 @@ /*- *----------------------------------------------------------------------- + * 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 @@ 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 @@ 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); Index: make.1 =================================================================== RCS file: /usr/home/okumoto/Work/make/fbsd-cvs/src/usr.bin/make/make.1,v retrieving revision 1.63 retrieving revision 1.64 diff -u -r1.63 -r1.64 --- make.1 14 Sep 2003 12:31:33 -0000 1.63 +++ make.1 2 Oct 2003 18:38:23 -0000 1.64 @@ -652,6 +652,8 @@ .Cm M , but selects all words which do not match the rest of the modifier. +.It Cm O +Order every word in the variable alphabetically. .It Cm Q Quotes every shell meta-character in the variable, so that it can be passed safely through recursive invocations of --------------010605040506050005080900--