modules/er/er_arrays.c
/* [<][>][^][v][top][bottom][index][help] */
FUNCTIONS
This source file includes following functions.
- er_getsevval
- er_getsevsym
- er_getfacsym
- er_getfacval
- er_getfacallmask
- er_getaspval
- er_getaspsym
- er_getpathval
- er_getformatval
1 /***************************************
2 $Revision: 1.3 $
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 #include "er_arrays.h"
34
35 er_ret_t er_getsevval(char *sev)
/* [<][>][^][v][top][bottom][index][help] */
36 {
37 int i;
38
39 for(i=0; er_level_a[i].sev != 0; i++) {
40 if( strcasecmp(er_level_a[i].chr, sev) == 0 ) {
41 return er_level_a[i].sev;
42 }
43 }
44
45 return 0;
46 }
47
48 char *er_getsevsym( int sev, int mode )
/* [<][>][^][v][top][bottom][index][help] */
49 {
50 int i;
51
52 for(i=0; er_level_a[i].sev != 0; i++) {
53 if (er_level_a[i].sev == sev) {
54 break;
55 }
56 }
57
58 switch( mode & 0x03 ) {
59 case ER_M_SEVCHAR: /* one-letter severity indication */
60 return er_level_a[i].chr;
61 case ER_M_SEVLONG: /* long severity indication */
62 return er_level_a[i].txt;
63 }
64
65 /* no severity indication */
66 return ""; /* "" goes to program text, so returning a
67 pointer to it is OK */
68 }
69
70 char *er_getfacsym(er_fac_code_t faccode)
/* [<][>][^][v][top][bottom][index][help] */
71 {
72 int facidx;
73
74 if( faccode != FAC_NONE ) {
75 for (facidx=0; facidx<FAC_LAST; facidx++) {
76 if( er_fac_err[facidx].code == faccode ) {
77 break;
78 }
79 }
80 return er_fac_err[facidx].name;
81 }
82 else return "";
83 }
84
85 er_mask_t er_getfacval(char *key)
/* [<][>][^][v][top][bottom][index][help] */
86 {
87 int i;
88
89 for(i=0; er_fac_err[i].code != -1; i++) {
90 if(strcasecmp(key,er_fac_err[i].name) == 0) {
91 return er_fac_err[i].code;
92 }
93 }
94
95 return 0;
96 }
97
98 mask_t er_getfacallmask(void)
/* [<][>][^][v][top][bottom][index][help] */
99 {
100 int i = FAC_NONE;
101 mask_t all = MA_new(MA_END);
102
103 while( ++i != FAC_LAST ) {
104 MA_set(&all, (unsigned) i, 1);
105 }
106 return all;
107 }
108
109 unsigned int er_getaspval(char *key)
/* [<][>][^][v][top][bottom][index][help] */
110 {
111 int i;
112
113 for(i=0; er_asparr[i].n != NULL; i++) {
114 if(strcasecmp(key,er_asparr[i].n) == 0) {
115 return er_asparr[i].v;
116 }
117 }
118
119 return 0;
120 }
121
122
123
124
125 void er_getaspsym(mask_t facmask, int asp, GString *g_reply)
/* [<][>][^][v][top][bottom][index][help] */
126 {
127 int i, found=0;
128
129 for(i=0; er_asparr[i].n != NULL; i++) {
130 if( MA_isset(facmask, er_asparr[i].f) && asp == er_asparr[i].v) {
131 g_string_sprintfa(g_reply, "%s|", er_asparr[i].n);
132 found = 1;
133 }
134 }
135
136 if( !found ) {
137 g_string_sprintfa(g_reply, "0x%x|", asp);
138 }
139
140 g_string_truncate(g_reply, (int)strlen(g_reply->str)-1);
141
142 }
143
144 er_path_mt er_getpathval(char *key)
/* [<][>][^][v][top][bottom][index][help] */
145 {
146 int i;
147
148 for(i=0; er_pathtypes[i] != NULL; i++) {
149 if(strcasecmp(key,er_pathtypes[i]) == 0) {
150 return i;
151 }
152 }
153
154 return -1;
155 }
156
157 int er_getformatval(char *key)
/* [<][>][^][v][top][bottom][index][help] */
158 {
159 int i;
160
161 for(i=0; er_formarr[i].n != NULL; i++) {
162 if(strcasecmp(key,er_formarr[i].n) == 0) {
163 return er_formarr[i].v;
164 }
165 }
166
167 return -1;
168 }