STATUS MOlongout( STATUS errstat, i8 val, i4 destlen, char *dest ) { char bufa[ MO_MAX_NUM_BUF ]; char bufb[ MO_MAX_NUM_BUF ]; char *p; char *q; i4 padlen; bufa[0] = EOS; /* Ignore errors in CVla8 -- force to 0 */ (void)CVla8( val, bufa ); padlen = MAX_I8_DIGITS_AND_SIGN - (i4)STlength( bufa ); p = bufb; q = bufa; /* put sign first, before pad */ if( bufa[0] == '-' ) *p++ = *q++; while( padlen-- > 0 ) *p++ = '0'; STcopy( q, p ); return( MOstrout( errstat, bufb, destlen, dest ) ); }
VOID adu_2prvalue( i4 (*fcn)(char *, ...), DB_DATA_VALUE *db_dv) { char num_buf[64]; i2 flt_wid; f8 f8_tmp; AD_DTUNION *dp; DB_TAB_LOGKEY_INTERNAL *tab_logkey; DB_OBJ_LOGKEY_INTERNAL *obj_logkey; DB_DT_ID bdt; i4 blen; i4 prec; char *data; char fmt[16]; i4 tmp; i4 tcnt; i4 i; i4 res_wid; i8 i8_tmp; f4 f4_tmp; i4 i4_tmp; i2 i2_tmp, i2_tmp2; i1 i1_tmp; char stbuf[2048]; if (db_dv == NULL) { (*fcn)(STprintf(stbuf,"< Pointer to DB_DATA_VALUE is NULL >\n")); return; } bdt = abs(db_dv->db_datatype); blen = db_dv->db_length - (db_dv->db_datatype < 0); prec = db_dv->db_prec; data = db_dv->db_data; dp = (AD_DTUNION*)data; if (data == NULL) { (*fcn)(STprintf(stbuf,"< pointer to data is NULL >\n")); } else if (ADI_ISNULL_MACRO(db_dv)) { (*fcn)(STprintf(stbuf,"< NULL >\n")); } else { switch (bdt) { case DB_LOGKEY_TYPE: obj_logkey = (DB_OBJ_LOGKEY_INTERNAL *) data; (*fcn)(STprintf(stbuf, "olk_db_id = %x\tolk_rel_id = %x\n", obj_logkey->olk_db_id, obj_logkey->olk_rel_id)); (*fcn)(STprintf(stbuf, "olk_high_id = %x\tolk_low_id = %x\n", obj_logkey->olk_high_id, obj_logkey->olk_low_id)); break; case DB_TABKEY_TYPE: tab_logkey = (DB_TAB_LOGKEY_INTERNAL *) data; (*fcn)(STprintf(stbuf, "tlk_high_id = %x\ttlk_low_id = %x\n", tab_logkey->tlk_high_id, tab_logkey->tlk_low_id)); break; case DB_CHA_TYPE: case DB_CHR_TYPE: case DB_BYTE_TYPE: if (blen == 0) { (*fcn)(STprintf(stbuf,"''")); break; } (*fcn)(STprintf(stbuf, "'%*s'", blen, (u_char *) data)); break; case DB_DTE_TYPE: (*fcn)(STprintf(stbuf, "dn_status = %x\tdn_highday = %d\tdn_time = %d\n", dp->ing_date.dn_status, dp->ing_date.dn_highday, dp->ing_date.dn_time)); (*fcn)(STprintf(stbuf, "dn_year = %d\tdn_month = %d\tdn_lowday = %d", dp->ing_date.dn_year, dp->ing_date.dn_month, dp->ing_date.dn_lowday)); break; case DB_ADTE_TYPE: (*fcn)(STprintf(stbuf,"dn_year = %d\tdn_month = %d\tdn_day = %d\n", dp->adate.dn_year, dp->adate.dn_month, dp->adate.dn_day)); break; case DB_TMWO_TYPE: case DB_TMW_TYPE: case DB_TME_TYPE: (*fcn)(STprintf(stbuf,"dn_seconds = %d\tdn_nsecond = %d\n", dp->atime.dn_seconds, dp->atime.dn_nsecond)); (*fcn)(STprintf(stbuf,"dn_tzoffset = %d\n", AD_TZ_OFFSET(&dp->atime))); break; case DB_INYM_TYPE: (*fcn)(STprintf(stbuf,"dn_years = %d\tdn_months = %d\n", dp->aintym.dn_years, dp->aintym.dn_months)); break; case DB_INDS_TYPE: (*fcn)(STprintf(stbuf,"dn_days = %d\tdn_seconds = %d\tdn_nseconds = %d\n", dp->aintds.dn_days, dp->aintds.dn_seconds, dp->aintds.dn_nseconds)); break; case DB_TSWO_TYPE: case DB_TSW_TYPE: case DB_TSTMP_TYPE: (*fcn)(STprintf(stbuf,"dn_year = %d\tdn_month = %d\tdn_day = %d\n", dp->atimestamp.dn_year, dp->atimestamp.dn_month, dp->atimestamp.dn_day)); (*fcn)(STprintf(stbuf,"dn_seconds = %d\tdn_nsecond = %d\n", dp->atimestamp.dn_seconds, dp->atimestamp.dn_nsecond)); (*fcn)(STprintf(stbuf,"dn_tzoffset = %d\n", AD_TZ_OFFSET(&dp->atimestamp))); break; case DB_DEC_TYPE: CVpka(data, (i4)DB_P_DECODE_MACRO(prec), (i4)DB_S_DECODE_MACRO(prec), '.', (i4)DB_P_DECODE_MACRO(prec) + 5, (i4)DB_S_DECODE_MACRO(prec), CV_PKLEFTJUST, num_buf, &res_wid); tmp = res_wid; i = 0; fmt[i++] = '%'; if (tmp >= 10) { fmt[i++] = (tmp / 10) + '0'; tmp = tmp % 10; } fmt[i++] = tmp + '0'; fmt[i++] = 's'; fmt[i] = EOS; (*fcn)(STprintf(stbuf, fmt, num_buf)); break; case DB_FLT_TYPE: if (blen == 4) { F4ASSIGN_MACRO(*data, f4_tmp); f8_tmp = f4_tmp; } else F8ASSIGN_MACRO(*data, f8_tmp); CVfa(f8_tmp, (i4) sizeof(num_buf), (i4) 4, 'f', '.', num_buf, &flt_wid); (*fcn)(STprintf(stbuf, "%*s", flt_wid, (u_char *)num_buf)); break; case DB_INT_TYPE: if (blen == 4) { I4ASSIGN_MACRO(*data, i4_tmp); } else if (blen == 2) { I2ASSIGN_MACRO(*data, i2_tmp); i4_tmp = i2_tmp; } else if (blen == 1) { i4_tmp = I1_CHECK_MACRO(*(i1 *)data); } else /* blen == 8 */ { /* Depending on host, printing i8's might be %ld (lp64) ** or %lld (lpi32). Avoid issues by converting to string. */ I8ASSIGN_MACRO(*data,i8_tmp); CVla8(i8_tmp,&num_buf[0]); (*fcn)(num_buf); break; } (*fcn)(STprintf(stbuf, "%d", i4_tmp)); break; case DB_MNY_TYPE: f8_tmp = ((AD_MONEYNTRNL *) data)->mny_cents / 100.0; CVfa(f8_tmp, 32, 2, 'f', '.', num_buf, &flt_wid); tmp = flt_wid; i = 0; fmt[i++] = '%'; if (flt_wid >= 100) { fmt[i++] = (tmp / 100) + '0'; tmp = tmp % 100; } if (flt_wid >= 10) { fmt[i++] = (tmp / 10) + '0'; tmp = tmp % 10; } fmt[i++] = tmp + '0'; fmt[i++] = 's'; fmt[i] = EOS; (*fcn)(STprintf(stbuf, fmt, num_buf)); break; case DB_VCH_TYPE: case DB_TXT_TYPE: case DB_LTXT_TYPE: case DB_VBYTE_TYPE: I2ASSIGN_MACRO(((DB_TEXT_STRING *)data)->db_t_count, i2_tmp); if (i2_tmp == 0) { (*fcn)(STprintf(stbuf,"''")); break; } (*fcn)(STprintf(stbuf, "'%*s'", i2_tmp, ((DB_TEXT_STRING *) data)->db_t_text)); break; case DB_BOO_TYPE: if (*((bool *) data)) (*fcn)(STprintf(stbuf,"TRUE")); else (*fcn)(STprintf(stbuf,"FALSE")); break; case DB_NCHR_TYPE: for(i=0; i< blen/2; i++) { I2ASSIGN_MACRO(data[2*i], i2_tmp); i4_tmp = i2_tmp; (*fcn)(STprintf(stbuf,"%x ", i4_tmp)); } break; case DB_NVCHR_TYPE: case DB_PAT_TYPE: I2ASSIGN_MACRO(((DB_NVCHR_STRING *)data)->count, i2_tmp); if (bdt == DB_PAT_TYPE) i2_tmp = 4; for(i=0; i< i2_tmp; i++) { I2ASSIGN_MACRO(((DB_NVCHR_STRING *)data)->element_array[i], i2_tmp2); i4_tmp = i2_tmp2; (*fcn)(STprintf(stbuf,"%x ", i4_tmp)); } break; case DB_LVCH_TYPE: case DB_LBYTE_TYPE: case DB_GEOM_TYPE: case DB_POINT_TYPE: case DB_MPOINT_TYPE: case DB_LINE_TYPE: case DB_MLINE_TYPE: case DB_POLY_TYPE: case DB_MPOLY_TYPE: case DB_GEOMC_TYPE: case DB_LNVCHR_TYPE: { ADP_PERIPHERAL *p = (ADP_PERIPHERAL *) data; ADP_COUPON *cpn; (*fcn)(STprintf(stbuf, "%s/length = (%d., %0d.): ", (p->per_tag == ADP_P_COUPON ? "ADP_P_COUPON" : "ADP_P_DATA"), p->per_length0, p->per_length1)); if (p->per_tag == ADP_P_COUPON) { cpn = &p->per_value.val_coupon; #if defined(axp_osf) || defined(ris_u64) || defined(LP64) || \ defined(axp_lnx) (*fcn)(STprintf(stbuf, "(%d.,%d.,%d.,%d.,%d.,%d.)", cpn->cpn_id[0],cpn->cpn_id[1], cpn->cpn_id[2],cpn->cpn_id[3], cpn->cpn_id[4],cpn->cpn_id[5])); #else (*fcn)(STprintf(stbuf, "(%d.,%d.,%d.,%d.,%d.)", cpn->cpn_id[0],cpn->cpn_id[1], cpn->cpn_id[2],cpn->cpn_id[3], cpn->cpn_id[4])); #endif } else { (*fcn)(STprintf(stbuf, "(first %d. of value) '%t'", min(100, p->per_length1), min(100, p->per_length1), p->per_value.val_value)); } } break; default: (*fcn)(STprintf(stbuf, "< unknown type: don't know how to interpret data >")); break; } } return; }
STATUS adu_sc930prtdataval( i4 msg_type, char *parameter_name, i4 parameter_no, DB_DATA_VALUE *db_dv, ADF_CB *tzcb, PTR file) { char num_buf[64]; i2 flt_wid; f8 f8_tmp; AD_NEWDTNTRNL dateval; AD_NEWDTNTRNL *datep=&dateval; DB_TAB_LOGKEY_INTERNAL *tab_logkey; DB_OBJ_LOGKEY_INTERNAL *obj_logkey; DB_DT_ID bdt; DB_STATUS db_stat; i4 blen; i4 prec; char *data; char fmt[16]; i4 tmp; i4 tcnt; i4 i; i4 res_wid; f4 f4_tmp; i4 i4_tmp; i2 i2_tmp, i2_tmp2; i1 i1_tmp; u_char u_tmp_i1; char stbuf[SC930_DATAVAL_BUFSIZE]; AD_DTUNION *dp; i8 i8_tmp; char *c_tmp,*c_buf_end; if (db_dv == NULL) { SIfprintf(file, "< Pointer to DB_DATA_VALUE is NULL >\n"); return E_DB_ERROR; } if (parameter_name) { STprintf(stbuf,"%d:%d(%s)=", db_dv->db_datatype, parameter_no, parameter_name); } else { STprintf(stbuf,"%d:%d=", db_dv->db_datatype, parameter_no); } /* output the PARM/PARMEXEC 'header' to the trace file */ switch (msg_type) { case SC930_LTYPE_PARM: SIfprintf(file,"PARM:%s",stbuf); break; case SC930_LTYPE_PARMEXEC: SIfprintf(file,"PARMEXEC:%s",stbuf); break; default: SIfprintf(file,"UNKNOWN:%s",stbuf); } bdt = abs(db_dv->db_datatype); blen = db_dv->db_length - (db_dv->db_datatype < 0); prec = db_dv->db_prec; data = db_dv->db_data; if (data == NULL) { SIfprintf(file, "< pointer to data is NULL >\n"); return E_DB_ERROR; } else if (ADI_ISNULL_MACRO(db_dv)) { SIfprintf(file, "< NULL >\n"); return OK; } else { switch (bdt) { case DB_LOGKEY_TYPE: obj_logkey = (DB_OBJ_LOGKEY_INTERNAL *) data; SIfprintf(file, "olk_high_id = %x\tolk_low_id = %x\t" "olk_rel_id = %d\tolk_db_id = %d\n" , obj_logkey->olk_high_id, obj_logkey->olk_low_id, obj_logkey->olk_rel_id, obj_logkey->olk_db_id); break; case DB_TABKEY_TYPE: tab_logkey = (DB_TAB_LOGKEY_INTERNAL *) data; SIfprintf(file, "tlk_high_id = %x\ttlk_low_id = %x\n", tab_logkey->tlk_high_id, tab_logkey->tlk_low_id); break; case DB_CHA_TYPE: case DB_CHR_TYPE: if (blen == 0) SIfprintf(file, "''\n"); else SIfprintf(file, "'%*s'\n", blen, (u_char *) data); break; case DB_DTE_TYPE: db_stat = adu_6to_dtntrnl (tzcb, db_dv, datep); if (datep->dn_status == 0) { SIfprintf(file, "''\n"); break; } SIfprintf(file, "(%s) %d/%d/%d %d:%d:%d.%.3d (%d)\n", (datep->dn_status & AD_DN_ABSOLUTE)? ((datep->dn_status & AD_DN_TIMESPEC)?"DATETIME":"DATE") :"INTERVAL", (i2)datep->dn_year,(i2)datep->dn_month,datep->dn_day, datep->dn_seconds / AD_39DTE_ISECPERHOUR, (datep->dn_seconds / AD_10DTE_ISECPERMIN) % 60, datep->dn_seconds % 60, (datep->dn_nsecond % AD_29DTE_NSPERMS), AD_TZ_OFFSETNEW(datep)); break; case DB_ADTE_TYPE: dp = (AD_DTUNION*)data; SIfprintf(file,"%d/%d/%d\n", dp->adate.dn_year, dp->adate.dn_month, dp->adate.dn_day); break; case DB_TMWO_TYPE: case DB_TMW_TYPE: case DB_TME_TYPE: dp = (AD_DTUNION*)data; SIfprintf(file,"%d,%d +/- %d\n", dp->atime.dn_seconds, dp->atime.dn_nsecond, AD_TZ_OFFSET(&dp->atime)); break; case DB_INYM_TYPE: dp = (AD_DTUNION*)data; SIfprintf(file,"%d %d\n",dp->aintym.dn_years, dp->aintym.dn_months); break; case DB_INDS_TYPE: dp = (AD_DTUNION*)data; SIfprintf(file,"%d %d %d\n", dp->aintds.dn_days, dp->aintds.dn_seconds, dp->aintds.dn_nseconds); break; case DB_TSWO_TYPE: case DB_TSW_TYPE: case DB_TSTMP_TYPE: dp = (AD_DTUNION*)data; SIfprintf(file,"%d/%d/%d %d %d (%d)\n", dp->atimestamp.dn_year, dp->atimestamp.dn_month, dp->atimestamp.dn_day, dp->atimestamp.dn_seconds, dp->atimestamp.dn_nsecond, AD_TZ_OFFSET(&dp->atimestamp)); break; case DB_DEC_TYPE: CVpka(data, (i4)DB_P_DECODE_MACRO(prec), (i4)DB_S_DECODE_MACRO(prec), '.', (i4)DB_P_DECODE_MACRO(prec) + 5, (i4)DB_S_DECODE_MACRO(prec), CV_PKLEFTJUST, num_buf, &res_wid); tmp = res_wid; i = 0; fmt[i++] = '%'; if (tmp >= 10) { fmt[i++] = (tmp / 10) + '0'; tmp = tmp % 10; } fmt[i++] = tmp + '0'; fmt[i++] = 's'; fmt[i++] = '\n'; fmt[i] = EOS; SIfprintf(file, fmt, num_buf); break; case DB_FLT_TYPE: if (blen == 4) { F4ASSIGN_MACRO(*data, f4_tmp); f8_tmp = f4_tmp; } else F8ASSIGN_MACRO(*data, f8_tmp); CVfa(f8_tmp, (i4) sizeof(num_buf), (i4) 4, 'f', '.', num_buf, &flt_wid); SIfprintf(file, "%*s\n", flt_wid, (u_char *) num_buf); break; case DB_INT_TYPE: if (blen == 4) { I4ASSIGN_MACRO(*data, i4_tmp); } else if (blen == 2) { I2ASSIGN_MACRO(*data, i2_tmp); i4_tmp = i2_tmp; } else if (blen == 1) { i4_tmp = I1_CHECK_MACRO(*(i1 *)data); } else /* blen == 8 */ { I8ASSIGN_MACRO(*data,i8_tmp); CVla8(i8_tmp,num_buf); SIfprintf(file, "%s\n", num_buf); break; } SIfprintf(file, "%d\n", i4_tmp); break; case DB_MNY_TYPE: f8_tmp = ((AD_MONEYNTRNL *) data)->mny_cents / 100.0; CVfa(f8_tmp, 32, 2, 'f', '.', num_buf, &flt_wid); tmp = flt_wid; i = 0; fmt[i++] = '%'; if (flt_wid >= 100) { fmt[i++] = (tmp / 100) + '0'; tmp = tmp % 100; } if (flt_wid >= 10) { fmt[i++] = (tmp / 10) + '0'; tmp = tmp % 10; } fmt[i++] = tmp + '0'; fmt[i++] = 's'; fmt[i++] = '\n'; fmt[i] = EOS; SIfprintf(file, fmt, num_buf); break; case DB_VCH_TYPE: case DB_TXT_TYPE: case DB_LTXT_TYPE: I2ASSIGN_MACRO(((DB_TEXT_STRING *)data)->db_t_count, i2_tmp); if (i2_tmp == 0) { SIfprintf(file, "''\n"); } else { SIfprintf(file, "'%*s'\n", i2_tmp, ((DB_TEXT_STRING *) data)->db_t_text); } break; case DB_BOO_TYPE: if (*((bool *) data)) SIfprintf(file,"TRUE\n"); else SIfprintf(file,"FALSE\n"); break; case DB_VBYTE_TYPE: I2ASSIGN_MACRO(((DB_TEXT_STRING *)data)->db_t_count, i2_tmp); blen=i2_tmp; data = ((DB_TEXT_STRING *)data)->db_t_text; case DB_BYTE_TYPE: c_tmp=stbuf; c_buf_end=c_tmp + SC930_DATAVAL_BUFSIZE - 10; STprintf(c_tmp,"%d:",blen); c_tmp += STlength(c_tmp); for(i=0; i< blen; i++) { u_tmp_i1=(u_char) data[i]; STprintf(c_tmp,"%02x ", u_tmp_i1); c_tmp += 3; if (c_tmp > c_buf_end ) { SIfprintf(file,stbuf); c_tmp=stbuf; stbuf[0]=EOS; } } SIfprintf(file,"%s\n",stbuf); break; case DB_NCHR_TYPE: stbuf[0] = EOS; c_tmp = stbuf; c_buf_end=c_tmp + SC930_DATAVAL_BUFSIZE - 10; for(i=0; i< blen/2; i++) { I2ASSIGN_MACRO(data[2*i], i2_tmp); i4_tmp = i2_tmp; STprintf(c_tmp,"%x ", i4_tmp); c_tmp += STlength(c_tmp); if (c_tmp > c_buf_end ) { SIfprintf(file,stbuf); c_tmp=stbuf; stbuf[0]=EOS; } } SIfprintf(file,"%s\n",stbuf); break; case DB_NVCHR_TYPE: I2ASSIGN_MACRO(((DB_NVCHR_STRING *)data)->count, i2_tmp); stbuf[0] = EOS; c_tmp = stbuf; c_buf_end=c_tmp + SC930_DATAVAL_BUFSIZE - 10; for(i=0; i< i2_tmp; i++) { I2ASSIGN_MACRO(((DB_NVCHR_STRING *)data)->element_array[i], i2_tmp2); i4_tmp = i2_tmp2; STprintf(c_tmp,"%x ", i4_tmp); c_tmp += STlength(c_tmp); if (c_tmp > c_buf_end ) { SIfprintf(file,stbuf); c_tmp=stbuf; stbuf[0]=EOS; } } SIfprintf(file,"%s\n",stbuf); break; case DB_LVCH_TYPE: case DB_LBYTE_TYPE: case DB_GEOM_TYPE: case DB_POINT_TYPE: case DB_MPOINT_TYPE: case DB_LINE_TYPE: case DB_MLINE_TYPE: case DB_POLY_TYPE: case DB_MPOLY_TYPE: case DB_GEOMC_TYPE: case DB_LNVCHR_TYPE: { ADP_PERIPHERAL *p = (ADP_PERIPHERAL *) data; ADP_COUPON *cpn; DB_DATA_VALUE dv_work; char tmp_val[DB_MAXSTRING + 1] = {0}; i4 i; dv_work.db_datatype = DB_CHA_TYPE; dv_work.db_length = DB_MAXSTRING; dv_work.db_data = tmp_val; adu_lvch_move(tzcb, db_dv, &dv_work); i = DB_MAXSTRING; while (dv_work.db_data[i] == ' ') dv_work.db_data[i--] = EOS; SIfprintf(file, "(%d/%d):'%s'\n",p->per_length0,p->per_length1, dv_work.db_data); } break; default: SIfprintf(file, "< unknown type: don't know how to interpret data >\n"); return E_DB_ERROR; } } return OK; }
DB_STATUS adu_copascii( ADF_CB *adf_scb, DB_DATA_VALUE *dv1, DB_DATA_VALUE *rdv) { register char *p; char temp[ADI_OUTMXFIELD]; i4 leftfill; i4 plen; i4 str_len; i2 out_width; p = temp; switch(dv1->db_datatype) { case DB_INT_TYPE: if (dv1->db_length == 8) { CVla8(*(i8 *) dv1->db_data, p); } else if (dv1->db_length == 4) { CVla(*(i4 *) dv1->db_data, p); } else if (dv1->db_length == 2) { CVla((i4) *(i2 *) dv1->db_data, p); } else { CVla(I1_CHECK_MACRO(*(i1 *) dv1->db_data), p); } break; case DB_DEC_TYPE: { i4 pr = DB_P_DECODE_MACRO(dv1->db_prec); i4 sc = DB_S_DECODE_MACRO(dv1->db_prec); i4 available_width = rdv->db_length; char decimal = (adf_scb->adf_decimal.db_decspec ? (char) adf_scb->adf_decimal.db_decimal : '.' ); if ( rdv->db_datatype == DB_VCH_TYPE || rdv->db_datatype == DB_TXT_TYPE || rdv->db_datatype == DB_LTXT_TYPE ) available_width -= DB_CNTSIZE; /* now convert to ascii: use formula from lenspec for length, get ** scale # of digits after decimal point, use left-justify */ if (CVpka((PTR)dv1->db_data, pr, sc, decimal, AD_PS_TO_PRN_MACRO(pr, sc), sc, CV_PKLEFTJUST, p, &str_len) == CV_OVERFLOW) { /* this should never happen */ return(adu_error(adf_scb, E_AD9999_INTERNAL_ERROR, 0)); } if (str_len > available_width) return(adu_error(adf_scb, E_AD1030_F_COPY_STR_TOOSHORT, 0)); } break; case DB_FLT_TYPE: { char decimal = (adf_scb->adf_decimal.db_decspec ? (char) adf_scb->adf_decimal.db_decimal : '.'); i4 available_width = rdv->db_length; if ( rdv->db_datatype == DB_VCH_TYPE || rdv->db_datatype == DB_TXT_TYPE || rdv->db_datatype == DB_LTXT_TYPE ) available_width -= DB_CNTSIZE; if (dv1->db_length == 4) { f8 f8tmp = (f8) *(f4 *) dv1->db_data; /* BUG : b119968 ** ** CVfa is a utility routine for both f8 and f4 floats. ** In the f4 case, the value is converted to f8 prior ** to call (as here). ** ** This works well except for the boundary case, where ** the f4 is FLT_MAX. In this case, an effective ** rounding up of the f8 that occurs as we convert to ** a string (eventually through fcvt) "overflows" the ** original f4 value. ** ** We bump down the last sig bit of the f4, and then ** we have no problems. */ if ( f8tmp == FLT_MAX ) { f8tmp = FLT_MAX_ROUND; } else if ( f8tmp == -FLT_MAX ) { f8tmp = -FLT_MAX_ROUND; } CVfa(f8tmp, adf_scb->adf_outarg.ad_f4width, adf_scb->adf_outarg.ad_f4prec, adf_scb->adf_outarg.ad_f4style, decimal, p, &out_width); if (out_width > available_width) return(adu_error(adf_scb, E_AD1030_F_COPY_STR_TOOSHORT, 0)); } else { CVfa(*(f8 *)dv1->db_data, adf_scb->adf_outarg.ad_f8width, adf_scb->adf_outarg.ad_f8prec, adf_scb->adf_outarg.ad_f8style, decimal, p, &out_width); if (out_width > available_width) return(adu_error(adf_scb, E_AD1030_F_COPY_STR_TOOSHORT, 0)); } } break; default: return(adu_error(adf_scb, E_AD5002_BAD_NUMBER_TYPE, 0)); } while (*p == ' ') p++; /* ** TEXT, VARCHAR, and LONGTEXT are variable length copies, ** so no need to pad on the left. */ if ( rdv->db_datatype == DB_TXT_TYPE || rdv->db_datatype == DB_VCH_TYPE || rdv->db_datatype == DB_LTXT_TYPE ) { return(adu_movestring(adf_scb, (u_char *) p, (i4) STlength(p), dv1->db_datatype, rdv)); } /* ** At this point the result type can be C or CHAR */ plen = min(STlength(p), rdv->db_length); leftfill = rdv->db_length - plen; MEfill(leftfill, ' ', rdv->db_data); MEcopy((PTR)p, plen, (PTR)((char *)rdv->db_data + leftfill)); return(E_DB_OK); }
DB_STATUS adu_ascii( ADF_CB *adf_scb, register DB_DATA_VALUE *dv1, DB_DATA_VALUE *rdv) { DB_STATUS db_stat = E_DB_OK; register char *p; char temp[ADI_OUTMXFIELD]; /* could probably be smaller */ u_char *str_addr; i4 str_len; i2 reswidth; bool char_text = FALSE; i8 i8_tmp = 0; p = temp; switch(dv1->db_datatype) { case DB_INT_TYPE: if (dv1->db_length == 8) { CVla8(*(i8 *) dv1->db_data, p); } else if (dv1->db_length == 4) { CVla(*(i4 *) dv1->db_data, p); } else if (dv1->db_length == 2) { CVla((i4) (*(i2 *) dv1->db_data), p); } else { CVla(I1_CHECK_MACRO(*(i1 *) dv1->db_data), p); } break; case DB_BOO_TYPE: if (((DB_ANYTYPE *)dv1->db_data)->db_booltype == DB_FALSE) STcopy("FALSE", p); else STcopy("TRUE", p); break; case DB_VCH_TYPE: case DB_CHA_TYPE: case DB_CHR_TYPE: case DB_TXT_TYPE: case DB_LTXT_TYPE: case DB_BYTE_TYPE: case DB_VBYTE_TYPE: if ((db_stat = adu_3straddr(adf_scb, dv1, (char **) &str_addr))) return(db_stat); if ((db_stat = adu_size(adf_scb, dv1, &str_len))) return(db_stat); if ((db_stat = adu_movestring(adf_scb, str_addr, str_len, dv1->db_datatype, rdv))) return(db_stat); char_text = TRUE; break; case DB_DEC_TYPE: { i4 pr = DB_P_DECODE_MACRO(dv1->db_prec); i4 sc = DB_S_DECODE_MACRO(dv1->db_prec); char decimal = (adf_scb->adf_decimal.db_decspec ? (char) adf_scb->adf_decimal.db_decimal : '.' ); /* now convert to ascii: use formula from lenspec for length, get ** scale # of digits after decimal point, use left-justify option */ if (CVpka((PTR)dv1->db_data, pr, sc, decimal, AD_PS_TO_PRN_MACRO(pr, sc), sc, CV_PKLEFTJUST, p, &str_len) == CV_OVERFLOW) { /* this should never happen */ return(adu_error(adf_scb, E_AD9999_INTERNAL_ERROR, 0)); } } break; case DB_FLT_TYPE: { char decimal = (adf_scb->adf_decimal.db_decspec ? (char) adf_scb->adf_decimal.db_decimal : '.'); if (dv1->db_length == 4) { CVfa((f8) *(f4 *) dv1->db_data, adf_scb->adf_outarg.ad_f4width, adf_scb->adf_outarg.ad_f4prec, adf_scb->adf_outarg.ad_f4style, decimal, p, &reswidth); } else { CVfa(*(f8 *)dv1->db_data, adf_scb->adf_outarg.ad_f8width, adf_scb->adf_outarg.ad_f8prec, adf_scb->adf_outarg.ad_f8style, decimal, p, &reswidth); } } break; case DB_DTE_TYPE: case DB_ADTE_TYPE: case DB_TMWO_TYPE: case DB_TMW_TYPE: case DB_TME_TYPE: case DB_TSWO_TYPE: case DB_TSW_TYPE: case DB_TSTMP_TYPE: case DB_INYM_TYPE: case DB_INDS_TYPE: return( adu_6datetostr( adf_scb, dv1, rdv)); case DB_MNY_TYPE: return( adu_9mnytostr( adf_scb, dv1, rdv)); case DB_LVCH_TYPE: case DB_LBYTE_TYPE: case DB_GEOM_TYPE: case DB_POINT_TYPE: case DB_MPOINT_TYPE: case DB_LINE_TYPE: case DB_MLINE_TYPE: case DB_POLY_TYPE: case DB_MPOLY_TYPE: case DB_GEOMC_TYPE: case DB_LNVCHR_TYPE: case DB_LCLOC_TYPE: case DB_LBLOC_TYPE: case DB_LNLOC_TYPE: return( adu_lvch_move( adf_scb, dv1, rdv)); case DB_BIT_TYPE: case DB_VBIT_TYPE: return( adu_bit2str( adf_scb, dv1, rdv)); case DB_LOGKEY_TYPE: case DB_TABKEY_TYPE: return( adu_3logkeytostr( adf_scb, dv1, rdv)); default: return(adu_error(adf_scb, E_AD2090_BAD_DT_FOR_STRFUNC, 0)); } if (!char_text) { if ((db_stat = adu_movestring(adf_scb, (u_char *) p, (i4) STlength(p), dv1->db_datatype, rdv)) != E_DB_OK ) return(db_stat); } return(E_DB_OK); }
STATUS ERslookup( i4 msg_number, CL_ERR_DESC *clerror, i4 flags, char *sqlstate, char *msg_buf, i4 msg_buf_size, i4 language, i4 *msg_length, CL_ERR_DESC *err_code, i4 num_param, ER_ARGUMENT *param ) { i4 erindex; /* index of ERmulti table */ i4 status; i4 length = 0; ER_ARGUMENT *p; ER_ARGUMENT hidden[CLE_INFO_ITEMS]; /* to access info in clerror */ char tempbuf[ER_MAX_LEN+ER_MAX_NAME+2]; i4 templen; char *p_msg_buf; char *p_tempbuf; SYSTIME stime; char langbuf[ER_MAX_LANGSTR]; EX_CONTEXT context; ER_SEMFUNCS *sems; #define D_WIDTH 23 #define F_WIDTH 20 #define X_WIDTH 18 /* Validate the parameters. */ if (msg_buf == 0 || msg_buf_size == 0 || msg_length == 0) { return (ER_BADPARAM); } if (language != -1 && ERlangstr(language,langbuf) != OK) { return (ER_BADLANGUAGE); } if (!(flags & ER_NAMEONLY)) { EXdump(msg_number,0); } /* Insert timestamp if requested. */ if (flags & ER_TIMESTAMP) { if (msg_buf_size < 21) { return (ER_TOOSMALL); } TMnow(&stime); TMstr(&stime,msg_buf); length = (i4)STlength(msg_buf); msg_buf[length++] = ' '; } /* ** if (clerror && msg_number) ** look up msg_number, optional parameters in clerror->moreinfo ** else if (clerror) ** { ** if (clerror->intern) ** look up clerror.intern, optional params in clerror->moreinfo ** if (clerror->callid) ** look up system error message ** } */ if (clerror) { if (msg_number) /* Look up message after system error */ { /* ** Set up an ER_ARGUMENT that references system-dependent ** information in `clerror', and point `param' at it. */ i4 i; for (i = 0; i < CLE_INFO_ITEMS; ++i) { /* "...all of whose members begin at offset 0..." (K&R) */ hidden[i].er_value = (PTR)&clerror->moreinfo[i].data._i4; hidden[i].er_size = clerror->moreinfo[i].size; } param = &hidden[0]; num_param = CLE_INFO_ITEMS; } else /* retrieve system-dependent error messages */ { i4 len; ER_ARGUMENT argv[3]; if (clerror->intern) /* look up internal CL error */ { i4 i; for (i = 0; i < CLE_INFO_ITEMS; ++i) { argv[i].er_value = (PTR)&clerror->moreinfo[i].data._i4; argv[i].er_size = clerror->moreinfo[i].size; } /* ** Don't timestamp on recursive call, since it's been done ** already (if requested). */ if ((status = ERslookup((i4) clerror->intern, (CL_ERR_DESC*) NULL, flags & ~ER_TIMESTAMP | ER_TEXTONLY, NULL, &msg_buf[length], msg_buf_size-length, language, &len, err_code, CLE_INFO_ITEMS, argv)) != OK) { return (status); } length += len; if (clerror->callid) msg_buf[length++] = '\n'; } if (clerror->callid) /* look up system error message text */ { DESCRIPTOR msg_desc; msg_desc.desc_length = sizeof(tempbuf) - 1; msg_desc.desc_value = tempbuf; if ((status = cer_sysgetmsg(clerror, &len, &msg_desc, err_code)) != OK) { return(status); } argv[0].er_size = argv[1].er_size = argv[2].er_size = ER_PTR_ARGUMENT; argv[0].er_value = (PTR)&clerror->errnum; argv[1].er_value = (PTR)ERNAME((i4) clerror->callid); argv[2].er_value = (PTR)tempbuf; if ((status = ERslookup(ER_UNIXERROR, (CL_ERR_DESC*) NULL, flags & ~ER_TIMESTAMP | ER_TEXTONLY, NULL, &msg_buf[length], msg_buf_size - length, language, &len,err_code, 3, argv)) != OK) { return (status); } length += len; } msg_buf[*msg_length = length] = EOS; return (OK); } } /* ** Check if error message file is already opened or not yet. ** First see if the language is initialized. If not, initialize ** it and the message files. ** If it is already opened, cer_fndindex function returns the index of ** ERmulti table that internal language code is parameter 'language'. ** If not yet, it returns '-1'. */ if (cer_issem(&sems)) { if (((sems->sem_type & MU_SEM) ? (*sems->er_p_semaphore)(&sems->er_mu_sem) : (*sems->er_p_semaphore)(1, &sems->er_sem)) != OK) { sems = NULL; } } if ((erindex = cer_fndindex(language)) == -1) { if ((status = cer_nxtindex(language,&erindex)) != OK) { /* Error in initializing the language */ if (sems) { if (sems->sem_type & MU_SEM) _VOID_ (*sems->er_v_semaphore)(&sems->er_mu_sem); else _VOID_ (*sems->er_v_semaphore)(&sems->er_sem); } return (status); } } /* If the error message file is not opened, open the message file. */ if (!cer_isopen(erindex,ER_SLOWSIDE)) { if ((status = cer_sinit(language,msg_number,erindex,err_code)) != OK) { if (sems) { if (sems->sem_type & MU_SEM) _VOID_ (*sems->er_v_semaphore)(&sems->er_mu_sem); else _VOID_ (*sems->er_v_semaphore)(&sems->er_sem); } return (status); } } /* If not open then just return. */ if (!cer_isopen(erindex,ER_SLOWSIDE)) { if (sems) { if (sems->sem_type & MU_SEM) _VOID_ (*sems->er_v_semaphore)(&sems->er_mu_sem); else _VOID_ (*sems->er_v_semaphore)(&sems->er_sem); } /* ** As internal file id is '0', openning file will fail. ** In her,return status 'ER_BADOPEN' to show open fail. */ return (ER_BADOPEN); } /* ** Search message string from file and set to buffer. ** Error status on system call set to 'err_code'. */ status = cer_sstr(msg_number, sqlstate, tempbuf, msg_buf_size - length, erindex, err_code, flags & ER_TEXTONLY? ER_GET : ER_LOOKUP); if (sems) { if (sems->sem_type & MU_SEM) _VOID_ (*sems->er_v_semaphore)(&sems->er_mu_sem); else _VOID_ (*sems->er_v_semaphore)(&sems->er_sem); } if (status != OK) { return (status); } /* ** Format the text with parameters into the callers buffer. ** The message is truncated if it will not fit. */ /* Insert part of name from temporary buffer to buffer */ status = OK; templen = (i4)STlength(tempbuf); p_msg_buf = &msg_buf[length]; p_tempbuf = tempbuf; if (!(flags & ER_TEXTONLY)) { while(*p_tempbuf != '\t') { CMcpyinc(p_tempbuf,p_msg_buf); } CMcpyinc(p_tempbuf,p_msg_buf); } /* ============================================ */ /* Copy text to message substituting arguments. */ /* -------------------------------------------- */ /* (But first, declare an exception handler to */ /* catch bad params that may access violate.) */ /* ============================================ */ if (EXdeclare(er_exhandler, &context)) { u_i4 res_len; u_i4 bytes_left_in_buf; bytes_left_in_buf = (u_i4)(msg_buf_size - (p_msg_buf - msg_buf)); res_len = STlen( STncpy(p_msg_buf, ERx("*** ERslookup() ERROR: Missing or bad parameter for this message. ***"), bytes_left_in_buf )); p_msg_buf[ bytes_left_in_buf - 1 ] = EOS; p_msg_buf += res_len; *msg_length = (i4)(p_msg_buf - msg_buf); EXdelete(); return (OK); } for( ;p_tempbuf - tempbuf < templen; CMnext(p_tempbuf)) { long number; u_long unumber; double fnumber; i4 i; i4 pnum; if ( (*p_tempbuf != '%') || (flags & ER_NOPARAM) ) { if ((p_msg_buf - msg_buf) >= msg_buf_size) break; CMcpychar(p_tempbuf,p_msg_buf); CMnext(p_msg_buf); continue; } if (p_tempbuf - tempbuf + 2 >= templen) continue; CMnext(p_tempbuf); if (*p_tempbuf == '!') { if ((p_msg_buf - msg_buf) + 3 >= msg_buf_size) continue; CMcpychar(ERx("\r"),p_msg_buf); CMnext(p_msg_buf); CMcpychar(ERx("\n"),p_msg_buf); CMnext(p_msg_buf); CMcpychar(ERx("\t"),p_msg_buf); CMnext(p_msg_buf); continue; } /* ** Only works for up to 10 parameters, and makes character set ** assumptions - should be fixed. */ if ( *p_tempbuf < '0' || *p_tempbuf > '9' ) { /* treat any other character as a literal */ if ((p_msg_buf - msg_buf) >= msg_buf_size) break; if ( *p_tempbuf != '%' ) { CMcpychar("%",p_msg_buf); CMnext(p_msg_buf); } CMcpychar(p_tempbuf,p_msg_buf); CMnext(p_msg_buf); continue; } pnum = *p_tempbuf - '0'; if (pnum >= num_param) { EXdelete(); return(ER_BADPARAM); } p = ¶m[pnum]; CMnext(p_tempbuf); switch (*p_tempbuf) { case 'd': /* Convert an integer into the buffer with width D_WIDTH */ if (p->er_size == ER_PTR_ARGUMENT) /* this is ptr to i4 */ number = *(i4 *)p->er_value; else if (p->er_size == 0) /* this is a i4 */ number = (i4)(SCALARP)p->er_value; else if (p->er_size == 1) number = *(i1 *)p->er_value; else if (p->er_size == 2) number = *(i2 *)p->er_value; else if (p->er_size == 4) number = *(i4 *)p->er_value; else if (p->er_size == 8) number = *(i8 *)p->er_value; else continue; if (p_msg_buf - msg_buf + D_WIDTH >= msg_buf_size) continue; if (p->er_size == 8) { CVla8(number, p_msg_buf); } else { CVla((i4)number, p_msg_buf); } while (*p_msg_buf) CMnext(p_msg_buf); continue; case 'u': /* Convert an integer into the buffer with width D_WIDTH */ if (p->er_size == ER_PTR_ARGUMENT) /* this is ptr to u_i4 */ number = *(u_i4 *)p->er_value; else if (p->er_size == 0) /* this is a u_i4 */ number = (u_i4)(SCALARP)p->er_value; else if (p->er_size == 1) number = *(u_i1 *)p->er_value; else if (p->er_size == 2) number = *(u_i2 *)p->er_value; else if (p->er_size == 4) number = *(u_i4 *)p->er_value; else if (p->er_size == 8) number = *(u_i8 *)p->er_value; else continue; if (p_msg_buf - msg_buf + D_WIDTH >= msg_buf_size) continue; if (p->er_size == 8) { CVula8(number, p_msg_buf); } else { CVula((u_i4)number, p_msg_buf); } while (*p_msg_buf) CMnext(p_msg_buf); continue; case 'f': { i2 res_width; /* Convert a float into the buffer with width F_WIDTH */ if (p->er_size == ER_PTR_ARGUMENT) /* Pointer to a double */ fnumber = *(double *)p->er_value; else if (p->er_size == 4) fnumber = *(f4 *)p->er_value; else if (p->er_size == 8) fnumber = *(f8 *)p->er_value; else continue; if (p_msg_buf - msg_buf + F_WIDTH >= msg_buf_size) continue; /* Always convert to 'e' format. */ CVfa(fnumber, (i4) 20, (i4) 5, 'e', '.', p_msg_buf, &res_width); p_msg_buf += F_WIDTH; continue; } case 'c': /* Convert a character array into buffer. */ if (p->er_value == 0) p->er_value = (PTR)ERx("<missing>"); if ((p->er_size == 0) || (p->er_size == ER_PTR_ARGUMENT)) { for (i = 0; ((char *)p->er_value)[i]; i++) ; p->er_size = i; } if (p_msg_buf - msg_buf + p->er_size >= msg_buf_size) continue; if (p->er_size > msg_buf_size - (p_msg_buf - msg_buf)) p->er_size = (i4)(msg_buf_size - (p_msg_buf - msg_buf)); /* p->er_size=STtrmwhite(p_msg_buf);*/ MEcopy(p->er_value, p->er_size, p_msg_buf); p->er_size = (i4)STtrmnwhite(p_msg_buf, p->er_size); p_msg_buf += p->er_size; continue; case 'x': /* Convert an integer into the buffer with width D_WIDTH */ if (p->er_size == ER_PTR_ARGUMENT) unumber = *(u_i4 *)p->er_value; else if (p->er_size == 0) unumber = (u_i4)(SCALARP)p->er_value; else if (p->er_size == 1) unumber = *(u_i1 *)p->er_value; else if (p->er_size == 2) unumber = *(u_i2 *)p->er_value; else if (p->er_size == 4) unumber = *(u_i4 *)p->er_value; else if (p->er_size == 8) unumber = *(u_i8 *)p->er_value; if (p_msg_buf - msg_buf + X_WIDTH >= msg_buf_size) continue; for (i = 8; --i >= 0; ) { /* {@fix_me@} ** This is *NOT* machine independent. This relys on an ** ASCII-like character set, where the digits '0'-'9' are ** contiguous and sequential, and the characters 'A'-'F' ** are contiguous and sequential. Both ASCII and EBCDIC ** happen to be this way. */ if ((*(p_msg_buf + i) = (unumber & 0x0f) + '0') > '9') *(p_msg_buf + i) += 'A' - '9' - 1; unumber >>= 4; } p_msg_buf += 8; continue; default: continue; } } *msg_length = (i4)(p_msg_buf - msg_buf); *p_msg_buf = EOS; EXdelete(); return (OK); }