Module Name: src Committed By: sjg Date: Mon Jul 1 21:02:26 UTC 2024
Modified Files: src/usr.bin/make: make.1 var.c src/usr.bin/make/unit-tests: Makefile Added Files: src/usr.bin/make/unit-tests: varmod-to-title.exp varmod-to-title.mk Log Message: make: add :tc to capitalize first letter of each word This is very hard to do without :tc Reviewed by: rillig To generate a diff of this commit: cvs rdiff -u -r1.377 -r1.378 src/usr.bin/make/make.1 cvs rdiff -u -r1.1125 -r1.1126 src/usr.bin/make/var.c cvs rdiff -u -r1.347 -r1.348 src/usr.bin/make/unit-tests/Makefile cvs rdiff -u -r0 -r1.1 src/usr.bin/make/unit-tests/varmod-to-title.exp \ src/usr.bin/make/unit-tests/varmod-to-title.mk Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/usr.bin/make/make.1 diff -u src/usr.bin/make/make.1:1.377 src/usr.bin/make/make.1:1.378 --- src/usr.bin/make/make.1:1.377 Sat Jun 1 06:26:36 2024 +++ src/usr.bin/make/make.1 Mon Jul 1 21:02:26 2024 @@ -1,4 +1,4 @@ -.\" $NetBSD: make.1,v 1.377 2024/06/01 06:26:36 sjg Exp $ +.\" $NetBSD: make.1,v 1.378 2024/07/01 21:02:26 sjg Exp $ .\" .\" Copyright (c) 1990, 1993 .\" The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\" .\" from: @(#)make.1 8.4 (Berkeley) 3/19/94 .\" -.Dd June 1, 2024 +.Dd July 1, 2024 .Dt MAKE 1 .Os .Sh NAME @@ -1574,6 +1574,9 @@ If .Ar c is omitted, no separator is used. The common escapes (including octal numeric codes) work as expected. +.It Cm \&:tt +Converts the first character of each word to upper-case, +and the rest to lower-case letters. .It Cm \&:tu Converts the value to upper-case letters. .It Cm \&:tW Index: src/usr.bin/make/var.c diff -u src/usr.bin/make/var.c:1.1125 src/usr.bin/make/var.c:1.1126 --- src/usr.bin/make/var.c:1.1125 Sun Jun 30 15:21:23 2024 +++ src/usr.bin/make/var.c Mon Jul 1 21:02:26 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: var.c,v 1.1125 2024/06/30 15:21:23 rillig Exp $ */ +/* $NetBSD: var.c,v 1.1126 2024/07/01 21:02:26 sjg Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -132,7 +132,7 @@ #include "metachar.h" /* "@(#)var.c 8.3 (Berkeley) 3/19/94" */ -MAKE_RCSID("$NetBSD: var.c,v 1.1125 2024/06/30 15:21:23 rillig Exp $"); +MAKE_RCSID("$NetBSD: var.c,v 1.1126 2024/07/01 21:02:26 sjg Exp $"); /* * Variables are defined using one of the VAR=value assignments. Their @@ -3142,6 +3142,21 @@ ok: } static char * +str_totitle(const char *str) +{ + size_t i, n = strlen(str) + 1; + char *res = bmake_malloc(n); + for (i = 0; i < n; i++) { + if (i == 0 || ch_isspace(res[i - 1])) + res[i] = ch_toupper(str[i]); + else + res[i] = ch_tolower(str[i]); + } + return res; +} + + +static char * str_toupper(const char *str) { size_t i, n = strlen(str) + 1; @@ -3188,6 +3203,13 @@ ApplyModifier_To(const char **pp, ModCha return AMR_OK; } + if (mod[1] == 't') { /* :tt */ + *pp = mod + 2; + if (Expr_ShouldEval(expr)) + Expr_SetValueOwn(expr, str_totitle(Expr_Str(expr))); + return AMR_OK; + } + if (mod[1] == 'u') { /* :tu */ *pp = mod + 2; if (Expr_ShouldEval(expr)) Index: src/usr.bin/make/unit-tests/Makefile diff -u src/usr.bin/make/unit-tests/Makefile:1.347 src/usr.bin/make/unit-tests/Makefile:1.348 --- src/usr.bin/make/unit-tests/Makefile:1.347 Sat Jun 1 15:54:40 2024 +++ src/usr.bin/make/unit-tests/Makefile Mon Jul 1 21:02:26 2024 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.347 2024/06/01 15:54:40 sjg Exp $ +# $NetBSD: Makefile,v 1.348 2024/07/01 21:02:26 sjg Exp $ # # Unit tests for make(1) # @@ -397,6 +397,7 @@ TESTS+= varmod-to-lower TESTS+= varmod-to-many-words TESTS+= varmod-to-one-word TESTS+= varmod-to-separator +TESTS+= varmod-to-title TESTS+= varmod-to-upper TESTS+= varmod-undefined TESTS+= varmod-unique Added files: Index: src/usr.bin/make/unit-tests/varmod-to-title.exp diff -u /dev/null src/usr.bin/make/unit-tests/varmod-to-title.exp:1.1 --- /dev/null Mon Jul 1 21:02:26 2024 +++ src/usr.bin/make/unit-tests/varmod-to-title.exp Mon Jul 1 21:02:26 2024 @@ -0,0 +1 @@ +exit status 0 Index: src/usr.bin/make/unit-tests/varmod-to-title.mk diff -u /dev/null src/usr.bin/make/unit-tests/varmod-to-title.mk:1.1 --- /dev/null Mon Jul 1 21:02:26 2024 +++ src/usr.bin/make/unit-tests/varmod-to-title.mk Mon Jul 1 21:02:26 2024 @@ -0,0 +1,31 @@ +# $NetBSD: varmod-to-title.mk,v 1.1 2024/07/01 21:02:26 sjg Exp $ +# +# Tests for the :tc variable modifier, which converts the expression value +# to lowercase. +# +# TODO: What about non-ASCII characters? ISO-8859-1, UTF-8? + +.if ${:UUPPER:tt} != "Upper" +. error +.endif + +.if ${:Ulower:tt} != "Lower" +. error +.endif + +.if ${:UMixeD case.:tt} != "Mixed Case." +. error +.endif + +# The ':tt' modifier works on the whole string, without splitting it into +# words. +.if ${:Umultiple spaces:tt} != "Multiple Spaces" +. error +.endif + +# Note words only count if separated by spaces +.if ${:Uthis&that or os/2:tt} != "This&that Or Os/2" +. error +.endif + +all: .PHONY