:u modifier a'la uniq(1) [from der Mouse]
This commit is contained in:
parent
9c5afcb2f0
commit
73e15c3ea3
|
@ -1,4 +1,4 @@
|
|||
.\" $NetBSD: make.1,v 1.42 2000/06/01 02:29:21 sjg Exp $
|
||||
.\" $NetBSD: make.1,v 1.43 2000/09/05 17:57:52 christos Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 1990, 1993
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
|
@ -602,6 +602,9 @@ potentially affected, the latter whether multiple substitutions can
|
|||
potentially occur within each affected word.
|
||||
.It Cm T
|
||||
Replaces each word in the variable with its last component.
|
||||
.It Cm u
|
||||
Remove adjacent duplicate words (like
|
||||
.Xr uniq 1 ).
|
||||
.It Cm ? Ar true_string Cm : Ar false_string
|
||||
If the variable evaluates to true, return as its value the
|
||||
.Ar true_string,
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: var.c,v 1.54 2000/08/13 22:47:01 christos Exp $ */
|
||||
/* $NetBSD: var.c,v 1.55 2000/09/05 17:57:52 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1988, 1989, 1990, 1993
|
||||
|
@ -39,14 +39,14 @@
|
|||
*/
|
||||
|
||||
#ifdef MAKE_BOOTSTRAP
|
||||
static char rcsid[] = "$NetBSD: var.c,v 1.54 2000/08/13 22:47:01 christos Exp $";
|
||||
static char rcsid[] = "$NetBSD: var.c,v 1.55 2000/09/05 17:57:52 christos Exp $";
|
||||
#else
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)var.c 8.3 (Berkeley) 3/19/94";
|
||||
#else
|
||||
__RCSID("$NetBSD: var.c,v 1.54 2000/08/13 22:47:01 christos Exp $");
|
||||
__RCSID("$NetBSD: var.c,v 1.55 2000/09/05 17:57:52 christos Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
#endif
|
||||
|
@ -215,6 +215,7 @@ static char *VarModify __P((char *, Boolean (*)(char *, Boolean, Buffer,
|
|||
ClientData),
|
||||
ClientData));
|
||||
static char *VarSort __P((char *));
|
||||
static char *VarUniq __P((char *));
|
||||
static int VarWordCompare __P((const void *, const void *));
|
||||
static void VarPrintVar __P((ClientData));
|
||||
|
||||
|
@ -1357,6 +1358,55 @@ VarSort (str)
|
|||
}
|
||||
|
||||
|
||||
/*-
|
||||
*-----------------------------------------------------------------------
|
||||
* VarUniq --
|
||||
* Remove adjacent duplicate words.
|
||||
*
|
||||
* Results:
|
||||
* A string containing the resulting words.
|
||||
*
|
||||
* Side Effects:
|
||||
* None.
|
||||
*
|
||||
*-----------------------------------------------------------------------
|
||||
*/
|
||||
static char *
|
||||
VarUniq(str)
|
||||
char *str; /* String whose words should be sorted */
|
||||
/* Function to use to modify them */
|
||||
{
|
||||
Buffer buf; /* Buffer for new string */
|
||||
char **av; /* List of words to affect */
|
||||
char *as; /* Word list memory */
|
||||
int ac, i, j;
|
||||
|
||||
buf = Buf_Init(0);
|
||||
av = brk_string(str, &ac, FALSE, &as);
|
||||
|
||||
if (ac > 1) {
|
||||
for (j = 0, i = 1; i < ac; i++)
|
||||
if (strcmp(av[i], av[j]) != 0 && (++j != i))
|
||||
av[j] = av[i];
|
||||
ac = j + 1;
|
||||
}
|
||||
|
||||
for (i = 0; i < ac; i++) {
|
||||
Buf_AddBytes(buf, strlen(av[i]), (Byte *)av[i]);
|
||||
if (i != ac - 1)
|
||||
Buf_AddByte(buf, ' ');
|
||||
}
|
||||
|
||||
free(as);
|
||||
free(av);
|
||||
|
||||
Buf_AddByte(buf, '\0');
|
||||
str = (char *)Buf_GetAll(buf, (int *)NULL);
|
||||
Buf_Destroy(buf, FALSE);
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
/*-
|
||||
*-----------------------------------------------------------------------
|
||||
* VarGetPattern --
|
||||
|
@ -1832,7 +1882,8 @@ Var_Parse (str, ctxt, err, lengthPtr, freePtr)
|
|||
* each word
|
||||
* :R Substitute the root of each word
|
||||
* (pathname minus the suffix).
|
||||
* :O Sort words in variable.
|
||||
* :O ("Order") Sort words in variable.
|
||||
* :U ("Uniq") Remove adjacent duplicate words.
|
||||
* :?<true-value>:<false-value>
|
||||
* If the variable evaluates to true, return
|
||||
* true value, else return the second value.
|
||||
|
@ -2377,6 +2428,15 @@ Var_Parse (str, ctxt, err, lengthPtr, freePtr)
|
|||
termc = *cp;
|
||||
break;
|
||||
}
|
||||
/*FALLTHRU*/
|
||||
case 'u':
|
||||
if (tstr[1] == endc || tstr[1] == ':') {
|
||||
newStr = VarUniq (str);
|
||||
cp = tstr + 1;
|
||||
termc = *cp;
|
||||
break;
|
||||
}
|
||||
/*FALLTHRU*/
|
||||
#ifdef SUNSHCMD
|
||||
case 's':
|
||||
if (tstr[1] == 'h' && (tstr[2] == endc || tstr[2] == ':')) {
|
||||
|
|
Loading…
Reference in New Issue