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 <errno.h>
0039 #include <dirent.h>
0040 #include <limits.h>
0041
0042 #include <ndrstandard.h>
0043 #include <ubfview.h>
0044 #include <ndebug.h>
0045
0046 #include <userlog.h>
0047 #include <view_cmn.h>
0048 #include <atmi_tls.h>
0049 #include "Exfields.h"
0050
0051
0052 #define API_ENTRY {ndrx_Bunset_error(); \
0053 }\
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065 expublic int ndrx_view_plot_object(FILE *f)
0066 {
0067 int ret = EXSUCCEED;
0068 ndrx_typedview_t * views = ndrx_view_get_handle();
0069 ndrx_typedview_t * vel, *velt;
0070 ndrx_typedview_field_t * fld;
0071 char tmp_count[32];
0072 char tmp_size[32];
0073 char tmp_null[NDRX_VIEW_NULL_LEN+3];
0074 int err;
0075 API_ENTRY;
0076
0077 #define WRITE_ERR \
0078 err = errno;\
0079 UBF_LOG(log_error, "Failed to write to file: %s", strerror(err));\
0080 ndrx_Bset_error_fmt(TPEOS, "Failed to write to file: %s", strerror(err));\
0081 EXFAIL_OUT(ret);
0082
0083 if (0>fprintf(f, "#Compiled VIEW file %s %s %d bit, compiler: %s\n",
0084 NDRX_VERSION, NDRX_BUILD_OS_NAME, (int)sizeof(void *)*8, NDRX_COMPILER))
0085 {
0086 WRITE_ERR;
0087 }
0088
0089 if (0>fprintf(f, "#Time stamp: %s %s\n", __DATE__, __TIME__))
0090 {
0091 WRITE_ERR;
0092 }
0093
0094 if (0>fprintf(f, "#It is possible to use this file as source of the "
0095 "view and recompile it\n"))
0096 {
0097 WRITE_ERR;
0098 }
0099
0100 if (0>fprintf(f, "#that will basically update the offsets and sizes of "
0101 "target platform\n"))
0102 {
0103 WRITE_ERR;
0104 }
0105
0106 if (0>fprintf(f, "#@__platform=%s;@__arch=%s;@__wsize=%d\n\n",
0107 NDRX_BUILD_OS_NAME, NDRX_CPUARCH, (int)sizeof(void *)*8))
0108 {
0109 WRITE_ERR;
0110 }
0111
0112
0113 EXHASH_ITER(hh, views, vel, velt)
0114 {
0115
0116 if (0>fprintf(f, "\nVIEW %s\n", vel->vname))
0117 {
0118 WRITE_ERR;
0119 }
0120
0121 if (0>fprintf(f, "#type cname fbname count flag size null compiled_data\n"))
0122 {
0123 WRITE_ERR;
0124 }
0125
0126 DL_FOREACH(vel->fields, fld)
0127 {
0128 char L_offs[256]="";
0129 char C_offs[256]="";
0130 snprintf(tmp_count, sizeof(tmp_count), "%d", fld->count);
0131
0132 if (BFLD_CARRAY==fld->typecode || BFLD_STRING==fld->typecode)
0133 {
0134 snprintf(tmp_size, sizeof(tmp_size), "%d", fld->size);
0135 }
0136 else
0137 {
0138 NDRX_STRCPY_SAFE(tmp_size, "-");
0139 }
0140
0141 if (fld->flags & NDRX_VIEW_FLAG_ELEMCNT_IND_C)
0142 {
0143 snprintf(C_offs, sizeof(C_offs), "coffs=%ld;", fld->count_fld_offset);
0144 }
0145
0146 if (fld->flags & NDRX_VIEW_FLAG_LEN_INDICATOR_L)
0147 {
0148 snprintf(L_offs, sizeof(L_offs), "loffs=%ld;", fld->length_fld_offset);
0149 }
0150
0151 if (NDRX_VIEW_QUOTES_SINGLE==fld->nullval_quotes)
0152 {
0153 snprintf(tmp_null, sizeof(tmp_null), "'%s'", fld->nullval);
0154 }
0155 else if (NDRX_VIEW_QUOTES_DOUBLE==fld->nullval_quotes)
0156 {
0157 snprintf(tmp_null, sizeof(tmp_null), "\"%s\"", fld->nullval);
0158 }
0159 else
0160 {
0161 snprintf(tmp_null, sizeof(tmp_null), "%s", fld->nullval);
0162 }
0163
0164 if (0>fprintf(f, "%-6s %-20s %-15s %-5s %-7s %-5s %-20s offset=%ld;fldsize=%ld;%s%s\n",
0165 fld->type_name,
0166 fld->cname,
0167 fld->fbname,
0168 tmp_count,
0169 fld->flagsstr,
0170 tmp_size,
0171 tmp_null,
0172 fld->offset,
0173 fld->fldsize,
0174 C_offs,
0175 L_offs
0176 ))
0177 {
0178 WRITE_ERR;
0179 }
0180 }
0181
0182
0183 if (0>fprintf(f, "#@__ssize=%ld;@__cksum=%lu\n", vel->ssize,
0184 (unsigned long)vel->cksum))
0185 {
0186 WRITE_ERR;
0187 }
0188
0189
0190 if (0>fprintf(f, "END\n\n"))
0191 {
0192 WRITE_ERR;
0193 }
0194 }
0195
0196 out:
0197 UBF_LOG(log_debug, "%s terminates %d", __func__, ret);
0198 return ret;
0199 }
0200