var.c (49caa483b3fafffd9cf5197eb30e8bb235aa7410) var.c (ef0b253881c9546ff88d3ed8480df7c791b3ddff)
1/* $NetBSD: var.c,v 1.223 2020/04/25 18:20:57 christos Exp $ */
1/* $NetBSD: var.c,v 1.224 2020/06/05 19:20:46 sjg Exp $ */
2
3/*
4 * Copyright (c) 1988, 1989, 1990, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * This code is derived from software contributed to Berkeley by
8 * Adam de Boor.
9 *

--- 54 unchanged lines hidden (view full) ---

64 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
65 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
66 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
67 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
68 * SUCH DAMAGE.
69 */
70
71#ifndef MAKE_NATIVE
2
3/*
4 * Copyright (c) 1988, 1989, 1990, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * This code is derived from software contributed to Berkeley by
8 * Adam de Boor.
9 *

--- 54 unchanged lines hidden (view full) ---

64 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
65 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
66 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
67 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
68 * SUCH DAMAGE.
69 */
70
71#ifndef MAKE_NATIVE
72static char rcsid[] = "$NetBSD: var.c,v 1.223 2020/04/25 18:20:57 christos Exp $";
72static char rcsid[] = "$NetBSD: var.c,v 1.224 2020/06/05 19:20:46 sjg Exp $";
73#else
74#include <sys/cdefs.h>
75#ifndef lint
76#if 0
77static char sccsid[] = "@(#)var.c 8.3 (Berkeley) 3/19/94";
78#else
73#else
74#include <sys/cdefs.h>
75#ifndef lint
76#if 0
77static char sccsid[] = "@(#)var.c 8.3 (Berkeley) 3/19/94";
78#else
79__RCSID("$NetBSD: var.c,v 1.223 2020/04/25 18:20:57 christos Exp $");
79__RCSID("$NetBSD: var.c,v 1.224 2020/06/05 19:20:46 sjg Exp $");
80#endif
81#endif /* not lint */
82#endif
83
84/*-
85 * var.c --
86 * Variable-handling functions
87 *

--- 1934 unchanged lines hidden (view full) ---

2022
2023static int
2024VarWordCompare(const void *a, const void *b)
2025{
2026 int r = strcmp(*(const char * const *)a, *(const char * const *)b);
2027 return r;
2028}
2029
80#endif
81#endif /* not lint */
82#endif
83
84/*-
85 * var.c --
86 * Variable-handling functions
87 *

--- 1934 unchanged lines hidden (view full) ---

2022
2023static int
2024VarWordCompare(const void *a, const void *b)
2025{
2026 int r = strcmp(*(const char * const *)a, *(const char * const *)b);
2027 return r;
2028}
2029
2030static int
2031VarWordCompareReverse(const void *a, const void *b)
2032{
2033 int r = strcmp(*(const char * const *)b, *(const char * const *)a);
2034 return r;
2035}
2036
2030/*-
2031 *-----------------------------------------------------------------------
2032 * VarOrder --
2033 * Order the words in the string.
2034 *
2035 * Input:
2036 * str String whose words should be sorted.
2037 * otype How to order: s - sort, x - random.

--- 15 unchanged lines hidden (view full) ---

2053 int ac, i;
2054
2055 Buf_Init(&buf, 0);
2056
2057 av = brk_string(str, &ac, FALSE, &as);
2058
2059 if (ac > 0)
2060 switch (otype) {
2037/*-
2038 *-----------------------------------------------------------------------
2039 * VarOrder --
2040 * Order the words in the string.
2041 *
2042 * Input:
2043 * str String whose words should be sorted.
2044 * otype How to order: s - sort, x - random.

--- 15 unchanged lines hidden (view full) ---

2060 int ac, i;
2061
2062 Buf_Init(&buf, 0);
2063
2064 av = brk_string(str, &ac, FALSE, &as);
2065
2066 if (ac > 0)
2067 switch (otype) {
2068 case 'r': /* reverse sort alphabetically */
2069 qsort(av, ac, sizeof(char *), VarWordCompareReverse);
2070 break;
2061 case 's': /* sort alphabetically */
2062 qsort(av, ac, sizeof(char *), VarWordCompare);
2063 break;
2064 case 'x': /* randomize */
2065 {
2066 int rndidx;
2067 char *t;
2068

--- 1488 unchanged lines hidden (view full) ---

3557 case 'O':
3558 {
3559 char otype;
3560
3561 cp = tstr + 1; /* skip to the rest in any case */
3562 if (tstr[1] == endc || tstr[1] == ':') {
3563 otype = 's';
3564 termc = *cp;
2071 case 's': /* sort alphabetically */
2072 qsort(av, ac, sizeof(char *), VarWordCompare);
2073 break;
2074 case 'x': /* randomize */
2075 {
2076 int rndidx;
2077 char *t;
2078

--- 1488 unchanged lines hidden (view full) ---

3567 case 'O':
3568 {
3569 char otype;
3570
3571 cp = tstr + 1; /* skip to the rest in any case */
3572 if (tstr[1] == endc || tstr[1] == ':') {
3573 otype = 's';
3574 termc = *cp;
3565 } else if ( (tstr[1] == 'x') &&
3575 } else if ( (tstr[1] == 'r' || tstr[1] == 'x') &&
3566 (tstr[2] == endc || tstr[2] == ':') ) {
3567 otype = tstr[1];
3568 cp = tstr + 2;
3569 termc = *cp;
3570 } else {
3571 goto bad_modifier;
3572 }
3573 newStr = VarOrder(nstr, otype);

--- 784 unchanged lines hidden ---
3576 (tstr[2] == endc || tstr[2] == ':') ) {
3577 otype = tstr[1];
3578 cp = tstr + 2;
3579 termc = *cp;
3580 } else {
3581 goto bad_modifier;
3582 }
3583 newStr = VarOrder(nstr, otype);

--- 784 unchanged lines hidden ---