root/oldXMenu/FindSel.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. XMenuFindSelection

     1 /* Copyright    Massachusetts Institute of Technology    1985   */
     2 
     3 /*
     4 
     5 Copyright 1985, 1986, 1987 by the Massachusetts Institute of Technology
     6 
     7 Permission to use, copy, modify, and distribute this
     8 software and its documentation for any purpose and without
     9 fee is hereby granted, provided that the above copyright
    10 notice appear in all copies and that both that copyright
    11 notice and this permission notice appear in supporting
    12 documentation, and that the name of M.I.T. not be used in
    13 advertising or publicity pertaining to distribution of the
    14 software without specific, written prior permission.
    15 M.I.T. makes no representations about the suitability of
    16 this software for any purpose.  It is provided "as is"
    17 without express or implied warranty.
    18 
    19 */
    20 
    21 
    22 
    23 /*
    24 Copyright (C) 2001-2023 Free Software Foundation, Inc.
    25 
    26 This program is free software: you can redistribute it and/or modify
    27 it under the terms of the GNU General Public License as published by
    28 the Free Software Foundation, either version 3 of the License, or (at
    29 your option) any later version.
    30 
    31 This program is distributed in the hope that it will be useful,
    32 but WITHOUT ANY WARRANTY; without even the implied warranty of
    33 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    34 GNU General Public License for more details.
    35 
    36 You should have received a copy of the GNU General Public License
    37 along with this program.  If not, see <https://www.gnu.org/licenses/>.
    38 */
    39 
    40 /*
    41  * XMenu:       MIT Project Athena, X Window system menu package
    42  *
    43  *      XMenuFindSelection - Find the first selection in a pane who's
    44  *                           label matches a particular string.
    45  *
    46  *      Author:         Tony Della Fera, DEC
    47  *                      January 22, 1986
    48  *
    49  */
    50 
    51 #include "XMenuInt.h"
    52 #include <string.h>
    53 
    54 int
    55 XMenuFindSelection(register XMenu *menu, int p_num, register char *label)
    56 {
    57     register XMPane *p_ptr;
    58     register XMSelect *s_ptr;
    59     register int i = 0;
    60 
    61     /*
    62      * Check for NULL pointers!
    63      */
    64     if (label == NULL) {
    65         _XMErrorCode = XME_ARG_BOUNDS;
    66         return(XM_FAILURE);
    67     }
    68 
    69     /*
    70      * Find the right pane.
    71      */
    72     p_ptr = _XMGetPanePtr(menu, p_num);
    73     if (p_ptr == NULL) return(XM_FAILURE);
    74 
    75     /*
    76      * Find the right selection.
    77      */
    78     for (
    79         s_ptr = p_ptr->s_list->next;
    80         s_ptr != p_ptr->s_list;
    81         s_ptr = s_ptr->next
    82     ){
    83         if (s_ptr->label_length == 0) {
    84             if (*label == '\0') {
    85                 _XMErrorCode = XME_NO_ERROR;
    86                 return (i);
    87             }
    88         }
    89         else {
    90             if (strncmp (label, s_ptr->label, s_ptr->label_length) == 0) {
    91                 _XMErrorCode = XME_NO_ERROR;
    92                 return (i);
    93             }
    94         }
    95         i++;
    96     }
    97 
    98     /*
    99      * If we get here then we have not found
   100      * a match.
   101      */
   102     _XMErrorCode = XME_S_NOT_FOUND;
   103     return (XM_FAILURE);
   104 }

/* [<][>][^][v][top][bottom][index][help] */