Source File modules/er/er_arrays.c

    1    | /***************************************
    2    |   $Revision: 1.2 $
    3    |
    4    |   Error reporting (er) er_arrays.c - auxiliary routines for parameter arrays
    5    |
    6    |   Status: NOT REVUED, PARTLY TESTED
    7    |
    8    |   Design and implementation by: Marek Bukowy
    9    |
    10   |   ******************/ /******************
    11   |   Copyright (c) 1999,2000                              RIPE NCC
    12   |
    13   |   All Rights Reserved
    14   |
    15   |   Permission to use, copy, modify, and distribute this software and its
    16   |   documentation for any purpose and without fee is hereby granted,
    17   |   provided that the above copyright notice appear in all copies and that
    18   |   both that copyright notice and this permission notice appear in
    19   |   supporting documentation, and that the name of the author not be
    20   |   used in advertising or publicity pertaining to distribution of the
    21   |   software without specific, written prior permission.
    22   |
    23   |   THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
    24   |   ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS; IN NO EVENT SHALL
    25   |   AUTHOR BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
    26   |   DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
    27   |   AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
    28   |   OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
    29   |   ***************************************/
    30   |
    31   | #include "erroutines.h"
    32   |
    33   | er_ret_t er_getsevval(char *sev)
    34   | {
    35   |   int i;
    36   |
    37   |   for(i=0; er_level_a[i].sev != 0; i++) {
    38   |     if( strcasecmp(er_level_a[i].chr, sev) == 0 ) {
    39   |       return er_level_a[i].sev;
    40   |     }
    41   |   }
    42   |
    43   |   return 0;
    44   | }
    45   |
    46   | char *er_getsevsym( int sev, int mode )
    47   | {
    48   | int i;
    49   |
    50   |   for(i=0; er_level_a[i].sev != 0; i++) {
    51   | 	if (er_level_a[i].sev == sev)  {
    52   | 	    break;
    53   | 	}
    54   |   }
    55   |
    56   |   switch( mode & 0x03 ) {
    57   |   case ER_M_SEVCHAR:	/* one-letter severity indication */
    58   |     return er_level_a[i].chr;
    59   |   case ER_M_SEVLONG: 	/* long severity indication */
    60   |     return er_level_a[i].txt;
    61   |   }
    62   |
    63   |   /* no severity indication */
    64   |   return "";	/* "" goes to program text, so returning a
    65   | 		   pointer to it is OK */
    66   | }
    67   |
    68   | char *er_getfacsym(er_fac_code_t faccode)
    69   | {
    70   | int facidx;
    71   |
    72   |   if( faccode != FAC_NONE  )  {
    73   |     for (facidx=0; facidx<FAC_LAST; facidx++) {
    74   |       if( er_fac_err[facidx].code == faccode ) {
    75   |         break;
    76   |       }
    77   |     }
    78   |     return  er_fac_err[facidx].name;
    79   |   }
    80   |   else	return "";
    81   | }
    82   |
    83   | er_mask_t er_getfacval(char *key)
    84   | {
    85   |   int i;
    86   |
    87   |   for(i=0; er_fac_err[i].code != -1; i++) {
    88   |     if(strcasecmp(key,er_fac_err[i].name) == 0) {
    89   |       return er_fac_err[i].code;
    90   |     }
    91   |   }
    92   |
    93   |   return 0;
    94   | }
    95   |
    96   | mask_t er_getfacallmask(void)
    97   | {
    98   |   int i = FAC_NONE;
    99   |   mask_t all = MA_new(MA_END);
    100  |
    101  |   while( ++i != FAC_LAST ) {
    102  |     MA_set(&all, i, 1);
    103  |   }
    104  |   return all;
    105  | }
    106  |
    107  | unsigned int er_getaspval(char *key)
    108  | {
    109  |   int i;
    110  |
    111  |   for(i=0; er_asparr[i].n != NULL; i++) {
    112  |     if(strcasecmp(key,er_asparr[i].n) == 0) {
    113  |       return er_asparr[i].v;
    114  |     }
    115  |   }
    116  |
    117  |   return 0;
    118  | }
    119  |
    120  |
    121  |
    122  |
    123  | void er_getaspsym(mask_t facmask, int asp, GString *g_reply)
    124  | {
    125  |   int i, found=0;
    126  |
    127  |   for(i=0; er_asparr[i].n != NULL; i++) {
    128  |     if(  MA_isset(facmask, er_asparr[i].f) && asp == er_asparr[i].v) {
    129  |       g_string_sprintfa(g_reply, "%s|", er_asparr[i].n);
    130  |       found = 1;
    131  |     }
    132  |   }
    133  |
    134  |   if( !found ) {
    135  |     g_string_sprintfa(g_reply, "0x%x|", asp);
    136  |   }
    137  |
    138  |   g_string_truncate(g_reply, strlen(g_reply->str)-1);
    139  |
    140  | }
    141  |
    142  | er_path_mt er_getpathval(char *key)
    143  | {
    144  |   int i;
    145  |
    146  |   for(i=0;  er_pathtypes[i] != NULL; i++) {
    147  |     if(strcasecmp(key,er_pathtypes[i]) == 0) {
    148  |       return i;
    149  |     }
    150  |   }
    151  |
    152  |   return -1;
    153  | }
    154  |
    155  | int er_getformatval(char *key)
    156  | {
    157  |  int i;
    158  |
    159  |   for(i=0;  er_formarr[i].n != NULL; i++) {
    160  |     if(strcasecmp(key,er_formarr[i].n) == 0) {
    161  |       return er_formarr[i].v;
    162  |     }
    163  |   }
    164  |
    165  |   return -1;
    166  | }