openbcm

Git mirror of https://github.com/Broadcom-Network-Switching-Software/OpenBCM
git clone git://git.finwo.net/mirror/broadcom/openbcm
Log | Files | Refs | README

phymod_symbols_iter.c (3079B)


      1 /*
      2  * 
      3  * This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file.
      4  * 
      5  * Copyright 2007-2019 Broadcom Inc. All rights reserved.
      6  *
      7  * PHYMOD Shell Utility: SYMOPS
      8  *
      9  * These utility functions provide all of the symbolic
     10  * register/memory encoding and decoding. 
     11  */
     12 
     13 #include <phymod/phymod_system.h>
     14 #include <phymod/phymod_symbols.h>
     15 
     16 static char *
     17 _strtolower(char *dst, const char *src, int dmax)
     18 {
     19     const char *s = src; 
     20     char *d = dst; 
     21     
     22     while (*s && --dmax) {
     23         *d = *s;
     24         if (*s >= 'A' && *s <= 'Z') {
     25             *d += ('a' - 'A'); 
     26         }
     27         s++;
     28         d++;
     29     }
     30     *d = 0;
     31 
     32     return dst; 
     33 }
     34 
     35 static int
     36 _sym_match(phymod_symbols_iter_t *iter, const char *sym_name)
     37 {
     38     char search_name[64]; 
     39     char symbol_name[64]; 
     40 
     41     _strtolower(search_name, iter->name, sizeof(search_name)); 
     42     _strtolower(symbol_name, sym_name, sizeof(symbol_name));
     43 
     44     switch(iter->matching_mode) {
     45     case PHYMOD_SYMBOLS_ITER_MODE_EXACT:
     46         if (PHYMOD_STRCMP(search_name, symbol_name) == 0) {
     47             /* Name matches */
     48             return 1;
     49         }
     50         break; 
     51     case PHYMOD_SYMBOLS_ITER_MODE_START:
     52         if (PHYMOD_STRNCMP(symbol_name, search_name,
     53                         PHYMOD_STRLEN(search_name)) == 0) {
     54             /* Name matches */
     55             return 1;
     56         }
     57         break;
     58     case PHYMOD_SYMBOLS_ITER_MODE_STRSTR:
     59         if (PHYMOD_STRSTR(symbol_name, search_name) != NULL) {
     60             /* Name matches */
     61             return 1;
     62         }
     63         break; 
     64     default:
     65         break;
     66     }
     67     return 0;
     68 }
     69 
     70 int
     71 phymod_symbols_iter(phymod_symbols_iter_t *iter)
     72 {       
     73     int count = 0; 
     74     int rc; 
     75     int match;
     76     uint32_t idx; 
     77     phymod_symbol_t s; 
     78 
     79     for (idx = 0; phymod_symbols_get(iter->symbols, idx, &s) >= 0; idx++) {
     80 
     81         if (s.name == 0) {
     82             /* Last */
     83             continue;
     84         }
     85 
     86         /* Check flags which must be present */
     87         if (iter->pflags && ((s.flags & iter->pflags) != iter->pflags)) {
     88             /* Symbol does not match */
     89             continue; 
     90         }
     91 
     92         /* Check flags which must be absent */
     93         if (iter->aflags && ((s.flags & iter->aflags) != 0)) {
     94             /* Symbol does not match */
     95             continue;
     96         }
     97 
     98         /* Check the name */
     99         if (PHYMOD_STRCMP("*", iter->name) != 0) {
    100             /* Not wildcarded */
    101             match = 0;
    102             if (_sym_match(iter, s.name)) {
    103                 match = 1;
    104             }
    105 #if PHYMOD_CONFIG_INCLUDE_ALIAS_NAMES == 1
    106             else if (s.ufname && _sym_match(iter, s.ufname)) {
    107                 match = 1;
    108             }
    109             else if (s.alias && _sym_match(iter, s.alias)) {
    110                 match = 1;
    111             }
    112 #endif
    113             if (!match) {
    114                 continue;
    115             }
    116         }
    117 
    118         /* Whew, name is okay */
    119         count++; 
    120 
    121         if ((rc = iter->function(&s, iter->vptr)) < 0) {
    122             return rc;
    123         }
    124     }
    125     
    126     return count; 
    127 }