Changeset 35802 for branches/eam_branches/ipp-20130711/Ohana/src/opihi
- Timestamp:
- Jul 11, 2013, 3:08:39 PM (13 years ago)
- Location:
- branches/eam_branches/ipp-20130711/Ohana/src/opihi
- Files:
-
- 2 edited
-
cmd.basic/list.c (modified) (10 diffs)
-
lib.shell/ListOps.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20130711/Ohana/src/opihi/cmd.basic/list.c
r33662 r35802 2 2 # define D_NLINES 100 3 3 static char prompt[] = ">> "; 4 5 static int set_list_varname (char *line, char *base, int N, int excelStyle); 4 6 5 7 int list (int argc, char **argv) { … … 21 23 } 22 24 25 int EXCEL_STYLE = FALSE; 26 if ((N = get_argument (argc, argv, "-excel-style"))) { 27 remove_argument (N, &argc, argv); 28 EXCEL_STYLE = TRUE; 29 } 30 if ((N = get_argument (argc, argv, "-excel"))) { 31 remove_argument (N, &argc, argv); 32 EXCEL_STYLE = TRUE; 33 } 34 23 35 if ((N = get_argument (argc, argv, "-vectors"))) { 24 36 remove_argument (N, &argc, argv); … … 49 61 50 62 for (i = 0; i < argc - 3; i++) { 51 s printf (line, "%s:%d", argv[1], i);63 set_list_varname (line, argv[1], i, EXCEL_STYLE); 52 64 set_str_variable (line, argv[i+3]); 53 65 } … … 83 95 if (!word) break; 84 96 85 sprintf (line, "%s:%d", argv[1], nWords); 97 // sprintf (line, "%s:%d", argv[1], nWords); 98 set_list_varname (line, argv[1], nWords, EXCEL_STYLE); 99 86 100 set_str_variable (line, word); 87 101 FREE (word); … … 120 134 sprintf (line, "%s:%d", argv[3], i); 121 135 value = get_variable (line); 122 sprintf (line, "%s:%d", argv[1], i); 136 // sprintf (line, "%s:%d", argv[1], i); 137 set_list_varname (line, argv[1], i, EXCEL_STYLE); 123 138 set_str_variable (line, value); 124 139 } … … 136 151 N = get_int_variable (line, &found); 137 152 for (i = 0; i < argc - 3; i++) { 138 sprintf (line, "%s:%d", argv[1], N + i); 153 // sprintf (line, "%s:%d", argv[1], N + i); 154 set_list_varname (line, argv[1], N + i, EXCEL_STYLE); 139 155 set_str_variable (line, argv[i+3]); 140 156 } … … 159 175 N = get_int_variable (line, &found); 160 176 for (i = 0; i < N; i++) { 161 sprintf (line, "%s:%d", argv[1], i); 177 // sprintf (line, "%s:%d", argv[1], i); 178 set_list_varname (line, argv[1], i, EXCEL_STYLE); 162 179 value = get_variable (line); 163 180 if (value == NULL) continue; … … 165 182 free (value); 166 183 for (j = i + 1; j < N; j++) { 167 sprintf (line2, "%s:%d", argv[1], j); 184 // sprintf (line2, "%s:%d", argv[1], j); 185 set_list_varname (line2, argv[1], j, EXCEL_STYLE); 168 186 next_value = get_variable (line2); 169 187 set_str_variable (line, next_value); … … 235 253 if (B != (char *) NULL) { *B = 0; } 236 254 if (*A != 0) { 237 sprintf (line, "%s:%d", argv[1], i); 255 // sprintf (line, "%s:%d", argv[1], i); 256 set_list_varname (line, argv[1], i, EXCEL_STYLE); 238 257 set_str_variable (line, A); 239 258 A = B + 1; … … 283 302 284 303 if (*input) { 285 sprintf (line, "%s:%d", argv[1], i); 304 // sprintf (line, "%s:%d", argv[1], i); 305 set_list_varname (line, argv[1], i, EXCEL_STYLE); 286 306 set_str_variable (line, input); 287 307 free (input); 288 308 i++; 289 }309 } 290 310 } 291 311 return (TRUE); 292 312 } 313 314 static int set_list_varname (char *line, char *base, int N, int excelStyle) { 315 316 int i; 317 318 // A-Z correspond to 0 - 25 319 320 if (excelStyle) { 321 float f = log(26.0); 322 float g = (N == 0) ? 0.0 : log(1.0*N); 323 int Ndigit = (int) (g / f) + 1; 324 if (Ndigit > 10) { 325 sprintf (line, "%s:ZZZZZZZZZZ", base); 326 return FALSE; 327 } 328 char name[12]; 329 memset (name, 0, 12); 330 for (i = 0; i < Ndigit; i++) { 331 float Npow = Ndigit - i - 1; 332 float g = pow(26.0, Npow); 333 int V = (int) (N / g); 334 name[i] = (Npow == 0.0) ? 'A' + V : 'A' + V - 1; 335 N -= V * g; 336 } 337 sprintf (line, "%s:%s", base, name); 338 } else { 339 sprintf (line, "%s:%d", base, N); 340 } 341 return TRUE; 342 } -
branches/eam_branches/ipp-20130711/Ohana/src/opihi/lib.shell/ListOps.c
r33963 r35802 189 189 int is_list_data (char *line) { 190 190 191 char *comm , *temp;192 193 temp = thisword (nextword (nextword (line)));194 comm = thisword (line); 195 191 char *comm = NULL; 192 char *temp = NULL; 193 char *ptr = NULL; 194 195 comm = thisword (line); 196 196 if (comm == NULL) goto escape; 197 198 197 if (strcmp (comm, "list")) goto escape; 198 199 ptr = nextword (line); 200 if (!strncmp("-excel", ptr, strlen("-excel"))) ptr = nextword (ptr); 201 if (!strncmp("-excel-style", ptr, strlen("-excel-style"))) ptr = nextword (ptr); 202 ptr = nextword (ptr); 203 if (!strncmp("-excel", ptr, strlen("-excel"))) ptr = nextword (ptr); 204 if (!strncmp("-excel-style", ptr, strlen("-excel-style"))) ptr = nextword (ptr); 205 temp = thisword (ptr); 199 206 200 207 /* if (cond) (command) does not define a complete block */
Note:
See TracChangeset
for help on using the changeset viewer.
