Skip to content

Commit 4085649

Browse files
committed
Allow $n in env exp for file names
1 parent 8123a09 commit 4085649

File tree

9 files changed

+48
-2
lines changed

9 files changed

+48
-2
lines changed

man/man1rwl/filestatement.1rwl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ of $NAME or ${NAME} is done similar to how it is done in the shell, unless the
8787
option or the
8888
.B $namexpand:off
8989
directive is in effect.
90+
You can also use $n where n is a single digit beteen 1 and 9 to expand the value of a positional
91+
argument to rwloadsim.
9092
This is not done for pipelines, although the popen call is likely to do it.
9193
.P
9294
If the concatenation is

man/man1rwl/include.1rwl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ directive.
2727
Unless -no-nameexpand option or the $nameexpand:off directive is used,
2828
environment names in either $NAME or ${NAME} syntax will be expanded
2929
before opening the include file.
30+
You can also use $n where n is a single digit beteen 1 and 9 to expand the value of a positional
31+
argument to rwloadsim.
3032
.P
3133
If the filename is embedded within the characters < and > instead of ",
3234
the name cannot start with . or / and

oltp/csvdata.rwl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ execute at rwloadsim
531531
# which events E1 .. E8 are, and to assemble
532532
# the plotline for gnuplot
533533
sql ashevents
534-
select '# '||to_char(enum+2,'FM9')||': '||ename
534+
select '# '||to_char(enum+2,'FM99')||': '||ename
535535
, ename
536536
from rwlash
537537
where runnumber = :1

src/rwlmisc.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
*
1515
* History
1616
*
17+
* bengsig 8-may-2023 - Use $n in e.g. $include
1718
* bengsig 1-may-2023 - $hostname directive
1819
* bengsig 24-apr-2023 - Prevent gcc 4.4.7 warning
1920
* bengsig 17-apr-2023 - Engineering notation output
@@ -2261,6 +2262,31 @@ text *rwlenvexp2(rwl_xeqenv *xev, rwl_location *loc, text *filn, ub4 eeflags, ub
22612262
*n++ = *p++;
22622263
i++;
22632264
}
2265+
else if (p[1] >= '1' && p[1] <= '9')
2266+
{
2267+
// $n where n is a single digit 1..9
2268+
text dollar[4];
2269+
sb4 j;
2270+
dollar[0] = (text) '$';
2271+
dollar[1] = p[1];
2272+
dollar[2] = 0;
2273+
p += 2;
2274+
if ((j=rwlfindvar(xev, dollar, RWL_VAR_NOGUESS))>0)
2275+
{
2276+
// $n exists
2277+
r = xev->evar[j].num.sval;
2278+
while (*r && i<RWL_PATH_MAX-1) // copy as long as it fits
2279+
{
2280+
*n++ = *r++;
2281+
i++;
2282+
}
2283+
}
2284+
else
2285+
{
2286+
failcode = RWL_ERROR_BAD_ENV_EXPANSION;
2287+
goto exitfromenvexp;
2288+
}
2289+
}
22642290
else
22652291
{
22662292
// found an environment variable

test/344-i.rwl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
integer abc;
2+
3+
abc := 42;

test/344.rwl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
$include:"$1.rwl"
2+
3+
printline abc;
4+
5+
$include:<$2.rwl>

test/test.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ then
4747
testlist="$*"
4848
else
4949
# note that 323..326 test CQN which we don't currently compile in
50-
testlist='1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343'
50+
testlist='1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344'
5151
fi
5252

5353
diffokcount=0;
@@ -168,6 +168,10 @@ do
168168
180)
169169
pre='--len4 12345 --abc 42'
170170
;;
171+
344)
172+
pre='-A 1'
173+
post='344-i'
174+
;;
171175
esac
172176

173177
diffok=no

test/testres/344.err.good

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
RWL-017: error at [344.rwl;5]: '$2' has not been declared
2+
RWL-207: error at [344.rwl;5]: illegal environment expansion in file name '$2.rwl'
3+
RWL-001: error: cannot open '$2.rwl' for reading

test/testres/344.out.good

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
42

0 commit comments

Comments
 (0)