Date: Tue, 31 Oct 1995 13:01:50 +0000 (GMT) From: Adam David <adam@veda.is> To: freebsd-bugs@freebsd.org Subject: make(1) variable modifier :S Message-ID: <199510311301.NAA07410@veda.is>
next in thread | raw e-mail | index | archive | help
There is a discrepancy in the description in 'man make' and the behaviour that is actually implemented, concerning the :S variable substitution modifier. The manpage says that the substitution is applied to each word in the variable, but the implemetation bypasses the substitution after the first matching word unless the /g 'global' flag is specified. This is an inconsistency in the intended meaning of the global flag. According to the manpage it means to substitute all occurences in each word, but the implementation assumes that the global flag means substitute all occurences in all words (and that its absence means substitute only the first occurence in all words, instead of in each word). If the manpage is correct, the whole use of VAR_NO_SUB in var.c is bogus and should be eradicated in order to provide the expected behaviour. Otherwise, if the implementation is correct, the manpage should mention this as a bug ;-) Patch follows below. I will reindent and commit this shortly unless any objections are raised. Adam David <adam@veda.is> ==== *** var.c Fri Aug 18 12:34:13 1995 --- var.c.new Tue Oct 31 12:48:14 1995 *************** *** 147,153 **** #define VAR_SUB_GLOBAL 1 /* Apply substitution globally */ #define VAR_MATCH_START 2 /* Match at start of word */ #define VAR_MATCH_END 4 /* Match at end of word */ - #define VAR_NO_SUB 8 /* Substitution is non-global and already done */ } VarPattern; static int VarCmp __P((ClientData, ClientData)); --- 147,152 ---- *************** *** 883,891 **** VarPattern *pattern = (VarPattern *) patternp; wordLen = strlen(word); - if ((pattern->flags & VAR_NO_SUB) == 0) { /* ! * Still substituting -- break it down into simple anchored cases * and if none of them fits, perform the general substitution case. */ if ((pattern->flags & VAR_MATCH_START) && --- 882,889 ---- VarPattern *pattern = (VarPattern *) patternp; wordLen = strlen(word); /* ! * Break substitution down into simple anchored cases * and if none of them fits, perform the general substitution case. */ if ((pattern->flags & VAR_MATCH_START) && *************** *** 990,1002 **** Buf_AddBytes(buf, pattern->rightLen, (Byte *)pattern->rhs); wordLen -= (cp - word) + pattern->leftLen; word = cp + pattern->leftLen; ! if (wordLen == 0) { done = TRUE; } - if ((pattern->flags & VAR_SUB_GLOBAL) == 0) { - done = TRUE; - pattern->flags |= VAR_NO_SUB; - } } else { done = TRUE; } --- 988,996 ---- Buf_AddBytes(buf, pattern->rightLen, (Byte *)pattern->rhs); wordLen -= (cp - word) + pattern->leftLen; word = cp + pattern->leftLen; ! if (wordLen == 0 || (pattern->flags & VAR_SUB_GLOBAL) == 0) { done = TRUE; } } else { done = TRUE; } *************** *** 1015,1030 **** return ((Buf_Size(buf) != origSize) || addSpace); } /* ! * Common code for anchored substitutions: if performed a substitution ! * and it's not supposed to be global, mark the pattern as requiring ! * no more substitutions. addSpace was set TRUE if characters were ! * added to the buffer. */ - if ((pattern->flags & VAR_SUB_GLOBAL) == 0) { - pattern->flags |= VAR_NO_SUB; - } return (addSpace); - } nosub: if (addSpace) { Buf_AddByte(buf, (Byte)' '); --- 1009,1018 ---- return ((Buf_Size(buf) != origSize) || addSpace); } /* ! * Common code for anchored substitutions: ! * addSpace was set TRUE if characters were added to the buffer. */ return (addSpace); nosub: if (addSpace) { Buf_AddByte(buf, (Byte)' ');
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199510311301.NAA07410>