home *** CD-ROM | disk | FTP | other *** search
- /**
- *
- * Name MNMCHITM - Match a menu item to a specification.
- *
- * Synopsis presult = mnmchitm (pmenu, pitem, row, col, iprot, pcode);
- *
- * BITEM *presult Pointer to the item in the menu's
- * item list which matches row and col,
- * or NIL if failure.
- * BMENU *pmenu Pointer to menu in which to search
- * item list. Needed if we get to the
- * end of the list and have to wrap
- * around.
- * BITEM *pitem Pointer to item in list to start
- * search at, or NIL to start at
- * first item.
- * int row, Row and column requested. If either
- * col or both are specified as -1, that
- * component of the specification is
- * ignored.
- * int iprot If iprot is 1, protected items are
- * also considered in the search.
- * int *pcode Pointer to varaible in which to return
- * error code. NIL if no code to be
- * returned.
- *
- * Description MNMCHITM searches from a given point in the item
- * list of a menu for an item matching a particular
- * specification.
- *
- * It only matches unprotected items, unless iprot is
- * equal to 1.
- *
- * If row or col (or both) is -1, it is taken to be
- * a wildcard specification. For example:
- *
- * presult = mnmchitm (pmenu, pitem, -1, col);
- *
- * will match to the first item (starting from pitem)
- * which is in the "col" column; row doesn't matter.
- *
- * The following matches the next unprotected item.
- *
- * presult = mnmchitm (pmenu, pitem->next, -1, -1, 0);
- *
- * Returns presult Pointer to BITEM found, or NIL
- * if failure.
- *
- **/
-
-
- #include <bmenu.h>
-
- #define TRUE 1
- #define FALSE 0
-
-
- BITEM *mnmchitm (pmenu, pitem, row, col, iprot, pcode)
- BMENU *pmenu;
- BITEM *pitem;
- int row, col;
- int iprot;
- int *pcode;
- {
- int gotnil = FALSE;
-
- if (pcode != NIL)
- *pcode = WN_NO_ERROR;
-
- for (;;)
- {
- /* If we already found the tail of the list, and we */
- /* just found it again, we know that we will not */
- /* find what we are looking for. */
- if ((pitem == NIL) && gotnil)
- return (NIL);
-
- /* Wrap around to head of list if at tail. Record */
- /* that we got to tail once so we know when we are */
- /* done if we don't find what we are looking for. */
- else if (pitem == NIL)
- {
- if ((pitem = pmenu->pitems) == NIL)
- return (NIL);
-
- gotnil = TRUE;
- }
-
- /* Check item signature. */
- if ((pitem != NIL) && (pitem->signature != MN_ITEM_SIGN))
- {
- if (pcode != NIL)
- *pcode = MN_BAD_ITEM;
-
- wnreterr (MN_BAD_ITEM);
- }
-
- /* If *pitem matches the given specification, we */
- /* are done, so return the item we found. */
- if ((!(pitem->option & MN_PROTECT)) || iprot)
- if (((row == -1) && (col == -1)) ||
- ((row == -1) && (pitem->col == col)) ||
- ((col == -1) && (pitem->row == row)) ||
- ((pitem->row == row) && (pitem->col == col)))
-
- return (pitem);
-
- /* Didn't find it yet--go on to next. */
- pitem = pitem->next;
- }
- }