|
From: <kin...@us...> - 2004-02-29 15:58:57
|
Update of /cvsroot/teem/teem/src/gage In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25242 Modified Files: kind.c Log Message: fixed big bug in _gageKindAnswerOffset Index: kind.c =================================================================== RCS file: /cvsroot/teem/teem/src/gage/kind.c,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** kind.c 13 Feb 2004 23:07:15 -0000 1.1 --- kind.c 29 Feb 2004 15:48:38 -0000 1.2 *************** *** 62,65 **** --- 62,77 ---- pindex = kind->table[ii].parentIndex; if (-1 != pitem) { + if (0 == ii) { + sprintf(err, "%s: first item (index 0) of kind \"%s\" can't " + "be a sub-item (wanted parent index %d)", + me, kind->name, pitem); + biffAdd(GAGE, err); return 1; + } + if (!(AIR_IN_CL(0, pitem, kind->itemMax))) { + sprintf(err, "%s: item %d of kind \"%s\" wants parent item %d " + "outside valid range [0..%d]", + me, ii, kind->name, pitem, kind->itemMax); + biffAdd(GAGE, err); return 1; + } if (-1 != kind->table[pitem].parentItem) { sprintf(err, "%s: item %d of kind \"%s\" has parent %d which " *************** *** 101,111 **** } int _gageKindAnswerOffset(gageKind *kind, int item) { ! return (item ! ? (kind->table[item-1].answerLength ! + _gageKindAnswerOffset(kind, item-1)) ! : 0); } --- 113,148 ---- } + /* + ** _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(gageKind *kind, int item) { + int parent, ii; ! if (!item) { ! /* the first item always has zero offset */ ! return 0; ! } ! ! /* else we're not the first */ ! parent = kind->table[item].parentItem; ! if (-1 != 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 (-1 != kind->table[ii].parentItem) { ! /* gageKindCheck ensures that item 0 is not a sub-item */ ! ii--; ! } ! return (kind->table[ii].answerLength ! + _gageKindAnswerOffset(kind, ii)); } *************** *** 120,128 **** } ! /* here's why its important that there are no sub-sub-items */ ! return (-1 == kind->table[item].parentItem ! ? _gageKindAnswerOffset(kind, item) ! : (kind->table[item].parentIndex ! + _gageKindAnswerOffset(kind, kind->table[item].parentItem))); } --- 157,161 ---- } ! return _gageKindAnswerOffset(kind, item); } |