140 |
|
|
141 |
|
if ((mleft == NULL) | (mright == NULL)) |
142 |
|
return(NULL); |
143 |
– |
|
143 |
|
switch (op) { |
144 |
|
case '.': /* concatenate */ |
145 |
< |
mres = rmx_multiply(mleft, mright); |
145 |
> |
if (mleft->ncomp != mright->ncomp) { |
146 |
> |
fputs(inspec, stderr); |
147 |
> |
fputs(": # components do not match\n", stderr); |
148 |
> |
} else if (mleft->ncols != mright->nrows) { |
149 |
> |
fputs(inspec, stderr); |
150 |
> |
fputs(": mismatched dimensions\n", |
151 |
> |
stderr); |
152 |
> |
} else |
153 |
> |
mres = rmx_multiply(mleft, mright); |
154 |
|
rmx_free(mleft); |
155 |
|
rmx_free(mright); |
156 |
|
if (mres == NULL) { |
157 |
|
fputs(inspec, stderr); |
158 |
< |
if (mleft->ncols != mright->nrows) |
152 |
< |
fputs(": mismatched dimensions for multiply\n", |
153 |
< |
stderr); |
154 |
< |
else |
155 |
< |
fputs(": concatenation failed\n", stderr); |
158 |
> |
fputs(": concatenation failed\n", stderr); |
159 |
|
return(NULL); |
160 |
|
} |
161 |
|
if (verbose) { |
232 |
|
int rpos = 0; |
233 |
|
/* find end of list */ |
234 |
|
while (mop[rpos].binop) |
235 |
< |
rpos++; |
235 |
> |
if (mop[rpos++].binop != '.') { |
236 |
> |
fputs( |
237 |
> |
"Right-to-left evaluation only for matrix multiplication!\n", |
238 |
> |
stderr); |
239 |
> |
return(NULL); |
240 |
> |
} |
241 |
|
mright = loadop(mop+rpos); |
242 |
|
while (rpos-- > 0) { |
243 |
|
if (mright == NULL) |
321 |
|
int i; |
322 |
|
/* get options and arguments */ |
323 |
|
for (i = 1; i < argc; i++) { |
316 |
– |
if (nmats >= nall) |
317 |
– |
mop = grow_moparray(mop, nall += 2); |
324 |
|
if (argv[i][0] && !argv[i][1] && |
325 |
|
strchr(".+*/", argv[i][0]) != NULL) { |
326 |
< |
if (mop[nmats].inspec == NULL || mop[nmats].binop) { |
327 |
< |
fprintf(stderr, "%s: missing matrix argument\n", |
328 |
< |
argv[0]); |
326 |
> |
if (!nmats || mop[nmats-1].binop) { |
327 |
> |
fprintf(stderr, |
328 |
> |
"%s: missing matrix argument before '%c' operation\n", |
329 |
> |
argv[0], argv[i][0]); |
330 |
|
return(1); |
331 |
|
} |
332 |
< |
mop[nmats++].binop = argv[i][0]; |
332 |
> |
mop[nmats-1].binop = argv[i][0]; |
333 |
|
} else if (argv[i][0] != '-' || !argv[i][1]) { |
334 |
|
if (argv[i][0] == '-') { |
335 |
|
if (stdin_used++) { |
348 |
|
int n = argc-1 - i; |
349 |
|
switch (argv[i][1]) { /* get option */ |
350 |
|
case 'v': |
351 |
< |
verbose = !verbose; |
351 |
> |
verbose++; |
352 |
|
break; |
353 |
|
case 'f': |
354 |
|
switch (argv[i][2]) { |
389 |
|
goto userr; |
390 |
|
} |
391 |
|
} |
392 |
+ |
if (nmats >= nall) |
393 |
+ |
mop = grow_moparray(mop, nall += 2); |
394 |
|
} |
395 |
|
if (mop[0].inspec == NULL) /* nothing to do? */ |
396 |
|
goto userr; |
397 |
+ |
if (mop[nmats-1].binop) { |
398 |
+ |
fprintf(stderr, |
399 |
+ |
"%s: missing matrix argument after '%c' operation\n", |
400 |
+ |
argv[0], mop[nmats-1].binop); |
401 |
+ |
return(1); |
402 |
+ |
} |
403 |
|
/* favor quicker concatenation */ |
404 |
< |
mres = prefer_right2left(mop) ? op_right2left(mop) : op_left2right(mop); |
405 |
< |
if (!mres) |
404 |
> |
mop[nmats].mtx = prefer_right2left(mop) ? op_right2left(mop) |
405 |
> |
: op_left2right(mop); |
406 |
> |
if (mop[nmats].mtx == NULL) |
407 |
> |
return(1); |
408 |
> |
/* apply trailing unary operations */ |
409 |
> |
mop[nmats].inspec = "trailing_ops"; |
410 |
> |
mres = loadop(mop+nmats); |
411 |
> |
if (mres == NULL) |
412 |
|
return(1); |
413 |
|
/* write result to stdout */ |
414 |
|
if (outfmt == DTfromHeader) |