Changeset 38002
- Timestamp:
- Mar 24, 2015, 8:18:59 PM (11 years ago)
- File:
-
- 1 edited
-
trunk/Ohana/src/opihi/lib.shell/expand_vectors.c (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/opihi/lib.shell/expand_vectors.c
r27491 r38002 1 1 # include "opihi.h" 2 3 // converts a[], a[4], a[2][3] to their numeric values 4 // add a?[] and a?[][] as equivalent to $?a 5 // a[][?] 2 6 3 7 char *expand_vectors (char *line) { … … 5 9 char *newline, *tmpline, strValue[128], *val; 6 10 char *L, *N, *p, *q, *p2, *w; 7 int n, I, J, size, showLength, NLINE, Noff, isBuffer, inRange;11 int n, I, J, size, showLength, showXsize, showYsize, checkType, NLINE, Noff, isBuffer, inRange; 8 12 float *ptr; 9 13 double f1; … … 41 45 val = NULL; 42 46 showLength = FALSE; 47 showXsize = FALSE; 48 showYsize = FALSE; 49 43 50 if (n == 0) { 44 51 showLength = TRUE; 52 showXsize = TRUE; 45 53 } else { 46 54 tmpline = strncreate (p+1, n); … … 60 68 p2 = strchr (q + 1, ']'); 61 69 if (p2 != NULL) { 62 if (showLength) {63 gprint (GP_ERR, "unsupported : name[][..]\n");64 goto asVector;65 }70 // if (showLength) { 71 // gprint (GP_ERR, "unsupported : name[][..]\n"); 72 // goto asVector; 73 // } 66 74 67 75 isBuffer = TRUE; … … 71 79 val = NULL; 72 80 if (n == 0) { 73 gprint (GP_ERR, "unsupported : name[..][]\n"); 74 isBuffer = FALSE; 75 goto asVector; 76 } 77 tmpline = strncreate (q+2, n); 78 val = dvomath (1, &tmpline, &size, 0); 79 free (tmpline); 80 if (val == NULL) { 81 isBuffer = FALSE; 82 goto asVector; /* not a valid vector subscript */ 81 showYsize = TRUE; 82 // gprint (GP_ERR, "unsupported : name[..][]\n"); 83 // isBuffer = FALSE; 84 // goto asVector; 85 } else { 86 tmpline = strncreate (q+2, n); 87 val = dvomath (1, &tmpline, &size, 0); 88 free (tmpline); 89 if (val == NULL) { 90 isBuffer = FALSE; 91 goto asVector; /* not a valid vector subscript */ 92 } 83 93 } 84 94 J = 0; … … 93 103 asVector: 94 104 /* find vector/buffer name */ 105 checkType = FALSE; 106 if (*(p-1) == '?') { 107 checkType = TRUE; 108 p--; 109 } 95 110 for (w = p - 1; (w >= line) && !OHANA_WHITESPACE(*w) && (isalnum(*w) || (*w == ':') || (*w == '_')); w--); 96 111 w ++; … … 99 114 100 115 if (isBuffer) { 101 if ((buf = SelectBuffer (tmpline, OLDBUFFER, TRUE)) == NULL) goto dumpline; 102 116 buf = SelectBuffer (tmpline, OLDBUFFER, !checkType); 117 if (checkType) { 118 f1 = (buf != NULL); 119 goto skipBuffer; 120 } 121 if (showXsize && showYsize) { 122 gprint (GP_ERR, "ambiguous size option buf[][]\n"); 123 goto dumpline; 124 } 125 if (buf == NULL) goto dumpline; 126 if (showXsize) { 127 f1 = buf[0].header.Naxis[0]; 128 goto skipBuffer; 129 } 130 if (showYsize) { 131 f1 = buf[0].header.Naxis[1]; 132 goto skipBuffer; 133 } 103 134 /* find buffer element */ 104 135 inRange = TRUE; … … 116 147 f1 = ptr[I + J*buf[0].header.Naxis[0]]; 117 148 } else { 118 if ((vec = SelectVector (tmpline, OLDVECTOR, TRUE)) == NULL) goto dumpline; 119 120 /* find vector element */ 121 if (showLength) { 122 f1 = vec[0].Nelements; 149 vec = SelectVector (tmpline, OLDVECTOR, !checkType); 150 if (checkType) { 151 f1 = (vec != NULL); 123 152 } else { 124 if ((I >= vec[0].Nelements) || (I < -1*vec[0].Nelements)) { 125 gprint (GP_ERR, "vector subscript out of range\n"); 126 goto escape; 153 if (vec == NULL) goto dumpline; 154 155 /* find vector element */ 156 if (showLength) { 157 f1 = vec[0].Nelements; 158 } else { 159 if ((I >= vec[0].Nelements) || (I < -1*vec[0].Nelements)) { 160 gprint (GP_ERR, "vector subscript out of range\n"); 161 goto escape; 162 } 163 if (I < 0) I += vec[0].Nelements; 164 f1 = (vec[0].type == OPIHI_FLT) ? vec[0].elements.Flt[I] : vec[0].elements.Int[I]; 127 165 } 128 if (I < 0) I += vec[0].Nelements; 129 f1 = (vec[0].type == OPIHI_FLT) ? vec[0].elements.Flt[I] : vec[0].elements.Int[I]; 130 } 131 } 132 166 } 167 } 168 169 skipBuffer: 133 170 free (tmpline); 134 171 if ((int)f1 == f1)
Note:
See TracChangeset
for help on using the changeset viewer.
