static VOID eqck_idstrip(char *idname, char *stripid ) { register char *cp = idname; if (*cp == '"') /* Get rid of starting double quote */ CMnext(cp); /* Get rid of embedded double quotes */ while (*cp) { if (*cp == '"') { if (*(cp+1) == '"') /* Skip escaped embedded quotes */ CMnext(cp); if (*(cp+1) == '\0') /* Skip last quote */ { *stripid = '\0'; break; } } CMcpyinc(cp, stripid); } if (*stripid != '\0') *stripid = '\0'; }
/* ** Name: FWrite_Fenc ** ** Decription: ** An encoding description for the following file. Stored for use in ** the furture. ** ** Inputs: ** sess ice session structure ** line pointer to the current line ** linelen length of the line ** ** Outputs: ** pos number of characters handled. ** ** Return: ** GSTAT_OK success ** other failure ** ** History: ** 23-Oct-98 (fanra01) ** Created. */ static GSTATUS FParm_Fenc (WTS_SESSION* sess, char* line, i4 linelen, i4 * pos) { GSTATUS err = GSTAT_OK; PWTS_UPLOAD load= sess->load; i4 remain = linelen - *pos; char* p = line + *pos; char* enc = NULL; i4 i=0; if ((err = GAlloc (&enc, remain + 1, FALSE)) == GSTAT_OK) { load->encode = enc; while (CMwhite(p)) { CMbyteinc(i,p); CMnext(p); } while (i < remain) { CMbyteinc(i,p); CMcpyinc (p, enc); } load->state = US_FPARM; } *pos += i; return (err); }
/* ** Name: File_Mime ** ** Decription: ** The mime type of the following file. Extracted an saved for use in ** in the future. ** ** Inputs: ** sess ice session structure ** line pointer to the current line ** linelen length of the line ** ** Outputs: ** pos number of characters handled. ** ** Return: ** GSTAT_OK success ** other failure ** ** History: ** 23-Oct-98 (fanra01) ** Created. */ static GSTATUS File_Mime (WTS_SESSION* sess, char* line, i4 linelen, i4 * pos) { GSTATUS err = GSTAT_OK; PWTS_UPLOAD load= sess->load; i4 remain = linelen - *pos; char* p = line + *pos; char* mime = NULL; i4 i=0; if ((err = GAlloc (&mime, remain + 1, FALSE)) == GSTAT_OK) { load->type = mime; while ((remain > 0) && CMwhite(p)) { CMbyteinc(i,p); CMnext(p); } while (i < remain) { CMbyteinc(i,p); CMcpyinc (p, mime); } load->state = US_FPARM; } *pos += i; return (err); }
/* Name: adu_csnormalize - Normalizes a platform characterset ** string in the alias table or as obtained ** by CM_getcharset. ** Description: ** ** As per the Unicode technical report UTR22. Ref: ** http://www.unicode.org/reports/tr22/ section 1.4, recommended ** method to compare the alias values in an alias table to a character ** set is to normalize the string in following manner. ** ** 1. Delete all characters except a-z, A-Z, and 0-9. ** 2. Map uppercase A-Z to the corresponding lowercase a-z. ** 3. From left to right, delete each 0 that is not preceded by a digit. ** ** For example, the following names should match: "UTF-8", "utf8", ** "u.t.f-008", but not "utf-80" or "ut8". ** ** Input: ** instring - Unnormalized converter name string. ** ** Output: ** instring - Normalized converter name string. ** ** History: ** 23-Jan-2004 (gupsh01) ** Added. */ void adu_csnormalize( char *instring, i4 inlength, char *outstring) { char *iptr = instring; char *endinput = instring + inlength; char *optr = outstring; char nopreceding = '0'; while (iptr < endinput) { if (CMdigit(iptr) || CMalpha(iptr)) { if (CMalpha(iptr)) nopreceding = *iptr; else nopreceding = '0'; CMtolower(iptr,iptr); if (nopreceding != '0'&& *iptr == '0') { *iptr++; continue; } CMcpyinc(iptr, optr); } else iptr++; } *optr = '\0'; }
STATUS s_srem_set() { char *s; char *send; i4 pos; i4 n; char short_remark[OOSHORTREMSIZE+1]; if (St_sr_given) { s_error(0x3A8, NONFATAL, NULL); s_cmd_skip(); return FAIL; } if (Cact_ren == NULL) { s_error(0x38A, FATAL, NULL); } St_sr_given = TRUE; Tokchar++; while (CMspace(Tokchar) || *Tokchar == '\t') { CMnext(Tokchar); } s = short_remark; send = s + OOSHORTREMSIZE; while (*Tokchar != '\n' && *Tokchar != EOS) { if (s <= send-CMbytecnt(Tokchar)) { if (*Tokchar == '\t') { /* if tab, replace it with the one blank */ *s = ' '; s++; Tokchar++; } else { CMcpyinc(Tokchar, s); } } else { CMnext(Tokchar); } } *s = EOS; Cact_ren->ren_shortrem = STalloc(short_remark); return OK; }
/*{ ** Name: opt_chkprint - Check that text string contains printable ascii. ** ** Description: ** Check that all characters in the text string provided are ascii ** for the length provided, or up to the first '\0' encountered, ** whichever comes first. Return TRUE if all ** characters are ascii, FALSE otherwise. ** ** Inputs: ** buf_to_check Ptr to char string to check ** buflen Maximum length to be checked ** ** Outputs: ** Returns: ** VOID ** Exceptions: ** none ** ** Side Effects: ** none ** ** History: ** 03jul-89 (robin) ** Created. [@history_template@]... */ bool opt_chkprint( char *buf_to_check, i4 buflen) { char wbuf[5]; i4 bytecount; char *bufptr; for ( bytecount = 0; bytecount <= buflen && *buf_to_check != '\0'; CMbyteinc( bytecount, buf_to_check)) { bufptr = &wbuf[0]; CMcpyinc(buf_to_check,bufptr); *bufptr = '\0'; if ( !CMprint(&wbuf[0] )) { return( FALSE ); } } return( TRUE ); }
i4 Is_it_If_statement(FILE *testFile,i4 *counter,bool Ignore_it) { char *cp1 = NULL ; char *cp2 = NULL ; i4 cmd ; bool yes_its_if = FALSE ; bool yes_its_tc = FALSE ; cmd = 0; if ((!shellMode)&&(SEP_CMstlen(lineTokens[0],0) > 1)&& (CMcmpcase(lineTokens[0],ERx(".")) == 0)) { cp1 = buffer_1 ; /* Fix the ".if" statement. */ cp2 = buffer_2 ; STcopy(buffer_1, holdBuf); CMcpyinc(cp1,cp2); CMcpychar(ERx(" "),cp2); CMnext(cp2); STcopy(cp1, cp2); STcopy(buffer_2, buffer_1); break_line(buffer_2, counter, lineTokens); } cmd = classify_cmmd(sepcmmds, lineTokens[1]); if (cmd == IF_CMMD || cmd == ELSE_CMMD || cmd == ENDIF_CMMD) { yes_its_if = TRUE; } else if (cmd == TEST_CASE_CMMD || cmd == TEST_CASE_END_CMMD) { yes_its_tc = TRUE; } if (yes_its_if || yes_its_tc) { append_line(holdBuf, 0); if (Ignore_it) ignore_silent == TRUE; if (yes_its_if) { process_if(testFile, lineTokens, cmd); } else if (yes_its_tc) { if (cmd == TEST_CASE_CMMD) { testcase_start(&lineTokens[1]); } else if (cmd == TEST_CASE_END_CMMD) { testcase_end(FALSE); } } if (Ignore_it) ignore_silent == FALSE; } else { cmd = 0; } return (cmd); }
/*{ ** Name: rms_movestring - moves a string into a DB_DATA_VALUE. ** ** Description: ** Moves a "C" string into a DB_DATA_VALUE padding the DB_DATA_VALUE ** string appropriately. If the DB_DATA_VALUE string has INGRES type c, ** any non-printing characters will be mapped to blanks. If the string ** has INGRES type text, then null characters are converted to blanks. ** ** Inputs: ** source The source "C" string. ** sourcelen The length of the source string. ** dest Ptr to the destination DB_DATA_VALUE. ** .db_datatype Datatype of the DB_DATA_VALUE. ** .db_length Length of the result DB_DATA_VALUE. ** ** Outputs: ** dest Ptr to the destination DB_DATA_VALUE. ** .db_data Ptr to memory where string is moved to. ** Returns: ** E_DB_OK ** ** Exceptions: ** none ** ** Side Effects: ** none ** ** History: ** 12-apr-90 (jrb) ** Created. */ DB_STATUS rms_movestring ( register u_char *source, register i4 sourcelen, register DB_DATA_VALUE *dest ) { DB_STATUS db_stat; char *cptr; u_char *endsource; register u_char *outstring; register i4 outlength; u_char *endout; if (db_stat = rms_straddr(dest, &cptr) != E_DB_OK) return (db_stat); outstring = (u_char *)cptr; switch (dest->db_datatype) { case DB_CHA_TYPE: case DB_CHR_TYPE: case DB_BYTE_TYPE: case DB_LBYTE_TYPE: outlength = dest->db_length; break; case DB_TXT_TYPE: case DB_VCH_TYPE: case DB_VBYTE_TYPE: outlength = dest->db_length - DB_CNTSIZE; break; } endsource = source + sourcelen; endout = outstring + outlength; if (dest->db_datatype == DB_CHR_TYPE) { while (source < endsource && outstring + CMbytecnt(source) <= endout) { /* ** The characters that are allowed as part of a string of type ** c are the printable characters(alpha, numeric, ** punctuation), blanks, IIMAX_CHAR_VALUE, or the pattern matching ** characters. NOTE: other whitespace (tab, etc.) is not ** allowed. */ if (!CMprint(source) && (*source) != ' ' && (*source) != IIMAX_CHAR_VALUE && (*source) != DB_PAT_ANY && (*source) != DB_PAT_ONE && (*source) != DB_PAT_LBRAC && (*source) != DB_PAT_RBRAC) { *outstring++ = ' '; CMnext(source); } else { CMcpyinc(source, outstring); } } } else if (dest->db_datatype == DB_TXT_TYPE) { while (source < endsource && outstring + CMbytecnt(source) <= endout) { /* NULLCHARs get cvt'ed to blank for text */ if (*source == NULLCHAR) { *outstring++ = ' '; CMnext(source); } else { CMcpyinc(source, outstring); } } } else { while (source < endsource && outstring + CMbytecnt(source) <= endout) CMcpyinc(source, outstring); } switch (dest->db_datatype) { case DB_CHA_TYPE: case DB_CHR_TYPE: while (outstring < endout) *outstring++ = ' '; break; case DB_VCH_TYPE: case DB_TXT_TYPE: ((DB_TEXT_STRING *)dest->db_data)->db_t_count = outstring - (u_char *)cptr; break; } return (E_DB_OK); }
STATUS s_lrem_set() { char *b; char *bend; i4 pos; i4 n; i4 length; # ifdef UNIX char word[OOLONGREMSIZE+1]; # else char word[MAXCMD+1]; # endif i4 code; i4 count; char *save_Tokchar; char long_remark[OOLONGREMSIZE+1]; i4 rtn_char; /* dummy variable for sgskip */ if (St_lr_given) { s_error(0x3A9, NONFATAL, NULL); s_cmd_skip(); return FAIL; } if (Cact_ren == NULL) { s_error(0x38A, FATAL, NULL); } St_lr_given = TRUE; /* skip leading white space */ s_g_skip(TRUE, &rtn_char); /* handle rest of remark up to the .ENDREMARK */ code = S_ERROR; b = long_remark; bend = b + OOLONGREMSIZE; for (;;) { while (*Tokchar != '\n' && *Tokchar != EOS) { if (*Tokchar == '.' && CMalpha(Tokchar+1)) { /* check for .ENDREMARK */ save_Tokchar = Tokchar; Tokchar++; r_gt_word(word); CVlower(word); code = s_get_scode(word); if (code == S_ENDREMARK) { break; } else { Tokchar = save_Tokchar; } } if (b <= bend-CMbytecnt(Tokchar)) { if (*Tokchar == '\t') { /* if tab, replace it with the one blank */ *b = ' '; b++; Tokchar++; } else { CMcpyinc(Tokchar, b); } } else { CMnext(Tokchar); } } if (code == S_ENDREMARK) { *b = EOS; Cact_ren->ren_longrem = STalloc(long_remark); break; } else { if (b < bend) { *b++ = ' '; } count = s_next_line(); if (count == 0) { /* ERROR: EOF in middle of remark */ s_error(0x3A3, FATAL, NULL); break; } } } return OK; }
/* ** Name: qeu_gen_alarm_name ** ** Description: ** Generates a default alarm name when none has been specified ** ** Name will consist of a $ followed by first 5 chars of the object name ** (blank padded if necessary), followed by _X_ where X is D or T ** followed by the hex representation of the alarm id. Before ** returning to the caller, we will call cui_idxlate() to convert name to ** the case appropriate for the database to which we are connected. ** ** Inputs: ** obj_name - Object name ** ** obj_type - Object type ** ** qef_rcb - RCB ** ** alarm_name - Where to put result. ** ** alarm_id - Unique id for number. ** ** Outputs: ** ** alarm_name - Name ** ** History: ** 26-nov-93 (robf) ** Created ** 2-Dec-2010 (kschendel) SIR 124685 ** Warning fixes, CMcpychar not to be used with single letter ** ascii constants. (array out of bounds warnings.) */ static DB_STATUS qeu_gen_alarm_name( i4 obj_type, char *obj_name, QEF_RCB *qef_rcb, DB_TAB_ID *alarm_id, char *alarm_name, i4 *err_code ) { DB_STATUS status = E_DB_OK; QEF_CB *qef_cb = qef_rcb->qef_cb; u_i4 cui_flags = ( * ( qef_cb->qef_dbxlate ) ) | CUI_ID_DLM | CUI_ID_NORM; u_i4 ret_mode; u_i4 len_untrans, len_trans = DB_ALARM_MAXNAME; u_char untrans_str[DB_ALARM_MAXNAME]; i4 j; char *p = (char *) untrans_str; char *limit; char id_str[20], *id_p = id_str; DB_ERROR err_blk; *p++ = '$'; for (j = 0; j < 5; j++) CMcpyinc(obj_name, p); *p++ = '_'; if(obj_type==DBOB_TABLE) *p++ = 'T'; else if(obj_type==DBOB_DATABASE) *p++ = 'D'; else { /* Unknown object type */ *err_code=E_QE0018_BAD_PARAM_IN_CB; return E_DB_ERROR; } *p++ = '_'; /* convert alarm id into a hex string */ seedToDigits(alarm_id, id_str, qef_rcb ); /* append id string to the name built so far */ for (; *id_p != EOS; CMcpyinc(id_p, p)) ; /* remember length of the name */ len_untrans = p - (char *) untrans_str; status = cui_idxlate(untrans_str, &len_untrans, (u_char *) alarm_name, &len_trans, cui_flags, &ret_mode, &qef_rcb->error); if (DB_FAILURE_MACRO(status)) { /* ** cui_idxlate errors have two params currently. ** We report here to avoid errors in generic code which ** doens't have params. */ (VOID) qef_error(qef_rcb->error.err_code, 0L, status, err_code, &err_blk, 2, sizeof(ERx("System generated alarm name"))-1, ERx("System generated alarm name"), len_untrans, untrans_str); /* Assume passed bad input */ *err_code=E_QE0018_BAD_PARAM_IN_CB; return status; } /* blank pad */ p = alarm_name + len_trans; limit = alarm_name + DB_ALARM_MAXNAME; while (p < limit) *p++ = ' '; return(E_DB_OK); }
STATUS Trans_SEPfile(char **Token,LOCTYPE *typeOfLoc,bool Dont_free,i2 ME_tag) { STATUS syserr ; char *newstr = NULL ; char *temp_ptr = NULL ; char *tmp_buffer1 = NULL ; char *tmp_buffer2 = NULL ; char *tmp_ptr1 = NULL ; char *tmp_ptr2 = NULL ; char *tmp_ptr3 = NULL ; char *token_ptr = NULL ; char *tmp_token = NULL ; if (ME_tag == SEP_ME_TAG_NODEL && Dont_free != TRUE) Dont_free = TRUE; if (tracing&TRACE_PARM) { SIfprintf(traceptr,ERx("Trans_SEPfile> *Token = %s\n"),*Token); if (Dont_free) SIfprintf(traceptr,ERx(" Dont_free = TRUE\n")); else SIfprintf(traceptr,ERx(" Dont_free = FALSE\n")); } tmp_token = *Token; if ((token_ptr = FIND_SEPstring(tmp_token,ERx("@FILE("))) == NULL) { if (tracing&TRACE_PARM) SIfprintf(traceptr,ERx("Trans_SEPfile> FIND_SEPstring is FALSE\n")); return (FALSE); } if (tracing&TRACE_PARM) SIfprintf(traceptr,ERx("Trans_SEPfile> FIND_SEPstring is TRUE\n")); tmp_buffer1 = SEP_MEalloc(SEP_ME_TAG_MISC, 128, TRUE, (STATUS *) NULL); tmp_buffer2 = SEP_MEalloc(SEP_ME_TAG_MISC, 128, TRUE, (STATUS *) NULL); if (token_ptr != tmp_token) { for (tmp_ptr1 = tmp_buffer1, tmp_ptr2 = tmp_token; tmp_ptr2 != token_ptr; ) CMcpyinc(tmp_ptr2,tmp_ptr1); } else { tmp_ptr2 = token_ptr; } for (tmp_ptr3 = tmp_buffer2; CMcmpcase(tmp_ptr2,ERx(")")); ) CMcpyinc(tmp_ptr2,tmp_ptr3); CMcpychar(tmp_ptr2,tmp_ptr3); CMnext(tmp_ptr2); newstr = SEP_MEalloc(SEP_ME_TAG_MISC, 128, TRUE, (STATUS *) NULL); if ((syserr = getLocation(tmp_buffer2,newstr,typeOfLoc)) == OK) { if (tracing&TRACE_PARM) { SIfprintf(traceptr,ERx("Trans_SEPfile> newstr = %s\n"),newstr); SIfprintf(traceptr,ERx("Trans_SEPfile> tmp_buffer1 = %s\n"), tmp_buffer1); SIfprintf(traceptr,ERx("Trans_SEPfile> tmp_buffer2 = %s\n"), tmp_buffer2); } STcat(tmp_buffer1, newstr); STcat(tmp_buffer1, tmp_ptr2); if (tracing&TRACE_PARM) SIfprintf(traceptr,ERx("Trans_SEPfile> tmp_buffer1 = %s\n"), tmp_buffer1); temp_ptr = *Token; *Token = STtalloc(ME_tag,tmp_buffer1); if (Dont_free != TRUE) MEfree(temp_ptr); } MEfree(tmp_buffer1); MEfree(tmp_buffer2); MEfree(newstr); if (tracing&TRACE_PARM) SIfprintf(traceptr,ERx("Trans_SEPfile> *Token = %s\n"),*Token); return (syserr); }
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); }