home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c070 / 4.ddi / TOOLS.4 / TCTSRC1.EXE / MNMCHITM.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-03-31  |  2.9 KB  |  112 lines

  1. /**
  2. *
  3. * Name        MNMCHITM - Match a menu item to a specification.
  4. *
  5. * Synopsis    presult = mnmchitm (pmenu, pitem, row, col, iprot, pcode);
  6. *
  7. *        BITEM *presult    Pointer to the item in the menu's
  8. *                item list which matches row and col,
  9. *                or NIL if failure.
  10. *        BMENU *pmenu    Pointer to menu in which to search
  11. *                item list.  Needed if we get to the
  12. *                end of the list and have to wrap
  13. *                around.
  14. *        BITEM *pitem    Pointer to item in list to start
  15. *                search at, or NIL to start at
  16. *                first item.
  17. *        int    row,    Row and column requested.  If either
  18. *               col    or both are specified as -1, that
  19. *                component of the specification is
  20. *                ignored.
  21. *        int    iprot    If iprot is 1, protected items are
  22. *                also considered in the search.
  23. *        int   *pcode    Pointer to varaible in which to return
  24. *                error code.  NIL if no code to be
  25. *                returned.
  26. *
  27. * Description    MNMCHITM searches from a given point in the item
  28. *        list of a menu for an item matching a particular
  29. *        specification.
  30. *
  31. *        It only matches unprotected items, unless iprot is
  32. *        equal to 1.
  33. *
  34. *        If row or col (or both) is -1, it is taken to be
  35. *        a wildcard specification.  For example:
  36. *
  37. *            presult = mnmchitm (pmenu, pitem, -1, col);
  38. *
  39. *        will match to the first item (starting from pitem)
  40. *        which is in the "col" column; row doesn't matter.
  41. *
  42. *        The following matches the next unprotected item.
  43. *
  44. *            presult = mnmchitm (pmenu, pitem->next, -1, -1, 0);
  45. *
  46. * Returns    presult     Pointer to BITEM found, or NIL
  47. *                if failure.
  48. *
  49. **/
  50.  
  51.  
  52. #include <bmenu.h>
  53.  
  54. #define TRUE 1
  55. #define FALSE 0
  56.  
  57.  
  58. BITEM *mnmchitm (pmenu, pitem, row, col, iprot, pcode)
  59. BMENU *pmenu;
  60. BITEM *pitem;
  61. int    row, col;
  62. int    iprot;
  63. int   *pcode;
  64. {
  65.     int gotnil = FALSE;
  66.  
  67.     if (pcode != NIL)
  68.     *pcode = WN_NO_ERROR;
  69.  
  70.     for (;;)
  71.     {
  72.         /* If we already found the tail of the list, and we */
  73.         /* just found it again, we know that we will not    */
  74.         /* find what we are looking for.            */
  75.     if ((pitem == NIL) && gotnil)
  76.         return (NIL);
  77.  
  78.         /* Wrap around to head of list if at tail.  Record  */
  79.         /* that we got to tail once so we know when we are  */
  80.         /* done if we don't find what we are looking for.   */
  81.     else if (pitem == NIL)
  82.     {
  83.         if ((pitem = pmenu->pitems) == NIL)
  84.         return (NIL);
  85.  
  86.         gotnil = TRUE;
  87.     }
  88.  
  89.         /* Check item signature.                */
  90.     if ((pitem != NIL) && (pitem->signature != MN_ITEM_SIGN))
  91.     {
  92.         if (pcode != NIL)
  93.         *pcode = MN_BAD_ITEM;
  94.  
  95.         wnreterr (MN_BAD_ITEM);
  96.     }
  97.  
  98.         /* If *pitem matches the given specification, we    */
  99.         /* are done, so return the item we found.        */
  100.     if ((!(pitem->option & MN_PROTECT)) || iprot)
  101.         if (((row == -1)         && (col == -1))         ||
  102.         ((row == -1)         && (pitem->col == col)) ||
  103.         ((col == -1)         && (pitem->row == row)) ||
  104.         ((pitem->row == row) && (pitem->col == col)))
  105.  
  106.         return (pitem);
  107.  
  108.         /* Didn't find it yet--go on to next.               */
  109.     pitem = pitem->next;
  110.     }
  111. }
  112.