| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: var.c,v 1.878 2021/03/14 20:00:48 rillig Exp $ */ | | 1 | /* $NetBSD: var.c,v 1.879 2021/03/14 20:03:56 rillig Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 1988, 1989, 1990, 1993 | | 4 | * Copyright (c) 1988, 1989, 1990, 1993 |
5 | * The Regents of the University of California. All rights reserved. | | 5 | * The Regents of the University of California. All rights reserved. |
6 | * | | 6 | * |
7 | * This code is derived from software contributed to Berkeley by | | 7 | * This code is derived from software contributed to Berkeley by |
8 | * Adam de Boor. | | 8 | * Adam de Boor. |
9 | * | | 9 | * |
10 | * Redistribution and use in source and binary forms, with or without | | 10 | * Redistribution and use in source and binary forms, with or without |
11 | * modification, are permitted provided that the following conditions | | 11 | * modification, are permitted provided that the following conditions |
12 | * are met: | | 12 | * are met: |
13 | * 1. Redistributions of source code must retain the above copyright | | 13 | * 1. Redistributions of source code must retain the above copyright |
14 | * notice, this list of conditions and the following disclaimer. | | 14 | * notice, this list of conditions and the following disclaimer. |
| @@ -130,27 +130,27 @@ | | | @@ -130,27 +130,27 @@ |
130 | #include <regex.h> | | 130 | #include <regex.h> |
131 | #endif | | 131 | #endif |
132 | #include <errno.h> | | 132 | #include <errno.h> |
133 | #include <inttypes.h> | | 133 | #include <inttypes.h> |
134 | #include <limits.h> | | 134 | #include <limits.h> |
135 | #include <time.h> | | 135 | #include <time.h> |
136 | | | 136 | |
137 | #include "make.h" | | 137 | #include "make.h" |
138 | #include "dir.h" | | 138 | #include "dir.h" |
139 | #include "job.h" | | 139 | #include "job.h" |
140 | #include "metachar.h" | | 140 | #include "metachar.h" |
141 | | | 141 | |
142 | /* "@(#)var.c 8.3 (Berkeley) 3/19/94" */ | | 142 | /* "@(#)var.c 8.3 (Berkeley) 3/19/94" */ |
143 | MAKE_RCSID("$NetBSD: var.c,v 1.878 2021/03/14 20:00:48 rillig Exp $"); | | 143 | MAKE_RCSID("$NetBSD: var.c,v 1.879 2021/03/14 20:03:56 rillig Exp $"); |
144 | | | 144 | |
145 | typedef enum VarFlags { | | 145 | typedef enum VarFlags { |
146 | VFL_NONE = 0, | | 146 | VFL_NONE = 0, |
147 | | | 147 | |
148 | /* | | 148 | /* |
149 | * The variable's value is currently being used by Var_Parse or | | 149 | * The variable's value is currently being used by Var_Parse or |
150 | * Var_Subst. This marker is used to avoid endless recursion. | | 150 | * Var_Subst. This marker is used to avoid endless recursion. |
151 | */ | | 151 | */ |
152 | VFL_IN_USE = 1 << 0, | | 152 | VFL_IN_USE = 1 << 0, |
153 | | | 153 | |
154 | /* | | 154 | /* |
155 | * The variable comes from the environment. | | 155 | * The variable comes from the environment. |
156 | * These variables are not registered in any GNode, therefore they | | 156 | * These variables are not registered in any GNode, therefore they |
| @@ -3265,26 +3265,29 @@ ApplyModifier_Order(const char **pp, App | | | @@ -3265,26 +3265,29 @@ ApplyModifier_Order(const char **pp, App |
3265 | enum SortMode { | | 3265 | enum SortMode { |
3266 | ASC, DESC, SHUFFLE | | 3266 | ASC, DESC, SHUFFLE |
3267 | } mode; | | 3267 | } mode; |
3268 | | | 3268 | |
3269 | if (IsDelimiter(mod[1], st)) { | | 3269 | if (IsDelimiter(mod[1], st)) { |
3270 | mode = ASC; | | 3270 | mode = ASC; |
3271 | } else if ((mod[1] == 'r' || mod[1] == 'x') && | | 3271 | } else if ((mod[1] == 'r' || mod[1] == 'x') && |
3272 | IsDelimiter(mod[2], st)) { | | 3272 | IsDelimiter(mod[2], st)) { |
3273 | (*pp)++; | | 3273 | (*pp)++; |
3274 | mode = mod[1] == 'r' ? DESC : SHUFFLE; | | 3274 | mode = mod[1] == 'r' ? DESC : SHUFFLE; |
3275 | } else | | 3275 | } else |
3276 | return AMR_BAD; | | 3276 | return AMR_BAD; |
3277 | | | 3277 | |
| | | 3278 | if (!(st->expr->eflags & VARE_WANTRES)) |
| | | 3279 | return AMR_OK; |
| | | 3280 | |
3278 | words = Str_Words(st->expr->value.str, FALSE); | | 3281 | words = Str_Words(st->expr->value.str, FALSE); |
3279 | if (mode == SHUFFLE) | | 3282 | if (mode == SHUFFLE) |
3280 | ShuffleStrings(words.words, words.len); | | 3283 | ShuffleStrings(words.words, words.len); |
3281 | else | | 3284 | else |
3282 | qsort(words.words, words.len, sizeof words.words[0], | | 3285 | qsort(words.words, words.len, sizeof words.words[0], |
3283 | mode == ASC ? str_cmp_asc : str_cmp_desc); | | 3286 | mode == ASC ? str_cmp_asc : str_cmp_desc); |
3284 | Expr_SetValueOwn(st->expr, Words_JoinFree(words)); | | 3287 | Expr_SetValueOwn(st->expr, Words_JoinFree(words)); |
3285 | | | 3288 | |
3286 | return AMR_OK; | | 3289 | return AMR_OK; |
3287 | } | | 3290 | } |
3288 | | | 3291 | |
3289 | /* :? then : else */ | | 3292 | /* :? then : else */ |
3290 | static ApplyModifierResult | | 3293 | static ApplyModifierResult |