0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034 #include <string.h>
0035 #include <stdio.h>
0036 #include <stdlib.h>
0037 #include <memory.h>
0038 #include <sys/param.h>
0039
0040 #include <ndrstandard.h>
0041 #include <ndebug.h>
0042 #include <nstdutil.h>
0043
0044 #include <ndrxdcmn.h>
0045 #include <atmi_int.h>
0046 #include <gencall.h>
0047 #include <utlist.h>
0048 #include <Exfields.h>
0049
0050 #include "xa_cmn.h"
0051 #include "tpadmsv.h"
0052 #include <ndrx.h>
0053 #include <qcommon.h>
0054 #include <nclopt.h>
0055 #include <tpadm.h>
0056 #include <ubfutil.h>
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070 expublic void ndrx_tab_init(ndrx_growlist_t *table)
0071 {
0072 ndrx_growlist_init(table, 100, sizeof(ndrx_growlist_t*));
0073 }
0074
0075
0076
0077
0078
0079
0080
0081
0082 expublic int ndrx_tab_add_col(ndrx_growlist_t *table, int col_nr, char *str)
0083 {
0084 ndrx_growlist_t *col_new;
0085 ndrx_growlist_t **col_cur;
0086 int ret = EXSUCCEED;
0087 char *dups;
0088 long *width;
0089 int len;
0090
0091 if (col_nr > table->maxindexused)
0092 {
0093 col_new = NDRX_MALLOC(sizeof(ndrx_growlist_t));
0094
0095 if (NULL==col_new)
0096 {
0097 NDRX_MALLOC_FAIL_NDRX(sizeof(ndrx_growlist_t));
0098 EXFAIL_OUT(ret);
0099 }
0100
0101 ndrx_growlist_init(col_new, 100, sizeof(char *));
0102
0103 if (EXSUCCEED!=ndrx_growlist_add(table, (char *)&col_new, col_nr))
0104 {
0105 NDRX_LOG(log_error, "Failed to add to growlist");
0106 EXFAIL_OUT(ret);
0107 }
0108 }
0109
0110 col_cur = (ndrx_growlist_t **)(table->mem + sizeof(ndrx_growlist_t *)*col_nr);
0111
0112
0113
0114 if (EXFAIL==(*col_cur)->maxindexused)
0115 {
0116
0117 width = (long *)0;
0118 if (EXSUCCEED!=ndrx_growlist_add(*col_cur, (char *)&width, (*col_cur)->maxindexused+1))
0119 {
0120 NDRX_LOG(log_error, "Failed to add column width entry at 0");
0121 EXFAIL_OUT(ret);
0122 }
0123 }
0124
0125 width = (long *)((*col_cur)->mem);
0126
0127 dups = NDRX_STRDUP(str);
0128
0129 if (NULL==dups)
0130 {
0131 NDRX_MALLOC_FAIL_NDRX(sizeof(char *));
0132 EXFAIL_OUT(ret);
0133 }
0134
0135
0136 len = strlen(dups);
0137 if ( (long)*width < len)
0138 {
0139 *width = len;
0140 }
0141
0142 if (EXSUCCEED!=ndrx_growlist_add(*col_cur, (char *)&dups, (*col_cur)->maxindexused+1))
0143 {
0144 NDRX_LOG(log_error, "Failed to add column at row %d to table", col_nr);
0145 EXFAIL_OUT(ret);
0146 }
0147
0148 out:
0149 return ret;
0150 }
0151
0152
0153
0154
0155
0156
0157
0158
0159
0160 expublic void ndrx_tab_print(ndrx_growlist_t *table, ndrx_growlist_t *coltypes)
0161 {
0162 int col, row = 0;
0163 ndrx_growlist_t **col_cur;
0164 char **val_cur;
0165 long *width;
0166 long *typ;
0167 int first = 0;
0168
0169 while (1)
0170 {
0171 for (col=0; col<=table->maxindexused; col++)
0172 {
0173
0174 col_cur = (ndrx_growlist_t **)(table->mem + sizeof(ndrx_growlist_t *)*col);
0175 typ=(long *)(coltypes->mem + sizeof(long)*col);
0176 if (row > (*col_cur)->maxindexused)
0177 {
0178 goto out;
0179 }
0180
0181 val_cur = (*col_cur)->mem + row*sizeof(char *);
0182 width = (*col_cur)->mem;
0183
0184 if (1==row)
0185 {
0186 if (0==first)
0187 {
0188 if (BFLD_STRING==*typ || BFLD_CARRAY==*typ)
0189 {
0190 fprintf(stderr, "%-*s ", (int)*width, *val_cur);
0191 }
0192 else
0193 {
0194 fprintf(stderr, "%*s ", (int)*width, *val_cur);
0195 }
0196 }
0197 else
0198 {
0199 int i;
0200 for (i=0; i<(int)*width; i++)
0201 {
0202 fprintf(stderr, "-");
0203 }
0204 fprintf(stderr, " ");
0205
0206 }
0207
0208 }
0209 else if (row > 1)
0210 {
0211 if (BFLD_STRING==*typ || BFLD_CARRAY==*typ)
0212 {
0213 fprintf(stdout, "%-*s ", (int)*width, *val_cur);
0214 }
0215 else
0216 {
0217 fprintf(stdout, "%*s ", (int)*width, *val_cur);
0218 }
0219 }
0220 }
0221
0222 if (1==row)
0223 {
0224 fprintf(stderr, "\n");
0225 }
0226 else if (row > 1)
0227 {
0228 fprintf(stdout, "\n");
0229 }
0230
0231 if (row==1)
0232 {
0233 first++;
0234 if (first>1)
0235 {
0236 row++;
0237 }
0238 }
0239 else
0240 {
0241 row++;
0242 }
0243 }
0244
0245
0246 out:
0247
0248 return;
0249 }
0250
0251
0252
0253
0254
0255 expublic void ndrx_tab_free(ndrx_growlist_t *table)
0256 {
0257 int col, row = 0;
0258 ndrx_growlist_t **col_cur;
0259 char **val_cur;
0260
0261 for (col=0; col<=table->maxindexused; col++)
0262 {
0263 col_cur = (ndrx_growlist_t **)(table->mem + sizeof(ndrx_growlist_t *)*col);
0264
0265 for (row=1; row<=(*col_cur)->maxindexused; row++)
0266 {
0267 val_cur = (*col_cur)->mem + row*sizeof(char *);
0268 NDRX_FREE(*val_cur);
0269 }
0270
0271 ndrx_growlist_free(*col_cur);
0272 NDRX_FREE(*col_cur);
0273 }
0274
0275 ndrx_growlist_free(table);
0276 }
0277
0278