FindSel.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /* Copyright Massachusetts Institute of Technology 1985 */
  2. #include "copyright.h"
  3. /*
  4. Copyright (C) 2001-2012 Free Software Foundation, Inc.
  5. This program is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. /*
  17. * XMenu: MIT Project Athena, X Window system menu package
  18. *
  19. * XMenuFindSelection - Find the first selection in a pane who's
  20. * label matches a particular string.
  21. *
  22. * Author: Tony Della Fera, DEC
  23. * January 22, 1986
  24. *
  25. */
  26. #include "XMenuInt.h"
  27. #include <string.h>
  28. int
  29. XMenuFindSelection(register XMenu *menu, int p_num, register char *label)
  30. {
  31. register XMPane *p_ptr;
  32. register XMSelect *s_ptr;
  33. register int i = 0;
  34. /*
  35. * Check for NULL pointers!
  36. */
  37. if (label == NULL) {
  38. _XMErrorCode = XME_ARG_BOUNDS;
  39. return(XM_FAILURE);
  40. }
  41. /*
  42. * Find the right pane.
  43. */
  44. p_ptr = _XMGetPanePtr(menu, p_num);
  45. if (p_ptr == NULL) return(XM_FAILURE);
  46. /*
  47. * Find the right selection.
  48. */
  49. for (
  50. s_ptr = p_ptr->s_list->next;
  51. s_ptr != p_ptr->s_list;
  52. s_ptr = s_ptr->next
  53. ){
  54. if (s_ptr->label_length == 0) {
  55. if (*label == '\0') {
  56. _XMErrorCode = XME_NO_ERROR;
  57. return (i);
  58. }
  59. }
  60. else {
  61. if (strncmp (label, s_ptr->label, s_ptr->label_length) == 0) {
  62. _XMErrorCode = XME_NO_ERROR;
  63. return (i);
  64. }
  65. }
  66. i++;
  67. }
  68. /*
  69. * If we get here then we have not found
  70. * a match.
  71. */
  72. _XMErrorCode = XME_S_NOT_FOUND;
  73. return (XM_FAILURE);
  74. }