/* ** _gageKindAnswerOffset ** ** return the location of the item in the master answer array ** ** I don't think this will work if there are sub-sub-items */ int _gageKindAnswerOffset(const gageKind *kind, int item) { int parent, ii; if (1 >= item) { /* the first item always has zero offset */ return 0; } /* else we're not the first */ parent = kind->table[item].parentItem; if (0 != parent) { /* we're a sub-item */ return (kind->table[item].parentIndex + _gageKindAnswerOffset(kind, parent)); } /* else we're not a sub-item: find the first previous non-sub-item */ ii = item-1; while (0 != kind->table[ii].parentItem) { /* gageKindCheck ensures that item 1 is not a sub-item */ ii--; } return (kind->table[ii].answerLength + _gageKindAnswerOffset(kind, ii)); }
int gageKindAnswerOffset(const gageKind *kind, int item) { char me[]="gageKindAnswerOffset", *err; if (gageKindCheck(kind)) { err = biffGetDone(GAGE); fprintf(stderr, "%s: PANIC:\n %s", me, err); free(err); exit(1); } return _gageKindAnswerOffset(kind, item); }