/* str_decomp.c */ /* decompose a detector list like : 1-5,7,9-12 */ /* into a simple array */ /* tl/94/7/26 */ /* main(argc, argv) int argc; char *argv[]; { char str[50]; int array[100]; int i; str_decomp(argv[1], 100, array); for (i = 0; i < 20; i++) printf("%2i: %i\n", i, array[i]); return (0); }; */ /*----------------------------------------------- */ int str_decomp(str, dim, yy) char str[]; int dim; int yy[]; { /* declarations */ int i, j, pos, nn, ok, lo, hi; char lstr[100]; /* zero array */ for (i = 0; i < dim; i++) yy[i] = 0; pos = 0; ok = 1; while (ok == 1) { /* search for the next sub range */ nn = 0; while ((str[pos + nn] != ',') && (ok == 1)) { nn++; if (str[pos + nn] == 0) ok = 0; }; /* create the local string */ j = 0; for (i = pos; i < (pos + nn); i++) { lstr[j] = str[i]; j++; }; lstr[j] = 0; /* remove non numeric characters in this string */ for (i = 0; i < nn; i++) if ((lstr[i] < 48) || (lstr[i] > 57)) lstr[i] = ' '; /* extract limits */ i = sscanf(lstr, "%i%i", &lo, &hi); /* fill array */ if (i == 1) hi = lo; for (j = lo; j <= hi; j++) yy[j] = 1; /* move pos pointer forward */ pos += nn; pos++; }; /* done */ return (0); };