Exemple #1
0
static i4
yylex( FILE *input )
{
	char *pscan;

	if( yygetline( input ) != OK )
		return( tEOF );

	/* Unless the -C flag was specified, blank out all of the comments */
	pscan = infile->yytext;
	while (pass_comments == FALSE && *pscan != EOS)
	{
		if (infile->yycomment == TRUE)
		{
			/* Look for the 'end comment' identifier */
			if (STbcompare(pscan,2,ERx("*/"),2,FALSE) == 0)
			{
				/* Blank out the 'end comment' characters */
				CMcpychar(ERx(" "), pscan);
				CMnext(pscan);
				CMcpychar(ERx(" "), pscan);

				/* Remember that the comment has ended */
				infile->yycomment = FALSE;
			}
			/* Blank out non-whitespace characters of the comment */
			else if (!CMwhite(pscan))
			{
				CMcpychar(ERx(" "), pscan);
			}
			/* Whitespace chars are skipped, this lets \n thru */
		}
		/* Look for the 'begin comment' identifier */
		else if (STbcompare(pscan,2,ERx("/*"),2,FALSE) == 0)
		{
			/* Blank out the 'begin comment' characters */
			CMcpychar(ERx(" "), pscan);
			CMnext(pscan);
			CMcpychar(ERx(" "), pscan);
			infile->yycomment = TRUE;
		}
		CMnext(pscan);	/* Continue the scan with the next character */
	}

	if( is_history(infile->yytext ) == OK)
	{
		return( tHISTORY ); 
	}

	if( *infile->yytext == '#' ) 
		return( tDIRECTIVE );

	return( tSOURCE );
}
Exemple #2
0
/*
 * regc - emit (if appropriate) a byte of code
 */
static void
regc( char *b )
{
    if (regcode != &regdummy) {
        CMcpychar( b, regcode );
        CMnext( regcode );
    } else
# ifndef DOUBLEBYTE
        regsize++;
# else
        CMbyteinc(regsize, b);
# endif /* #ifndef DOUBLEBYTE */
}
Exemple #3
0
static bool
pp_eval_boolexp( char **strptr, char *goal )
{
	bool boolval[2];
	i4  notval[2];
	i4  oper = OPER_NONE;
	i4  curval = 0;
	i4  maxval;
	i4  goalfound = FALSE;
	char *parser = *strptr;
	bool rtn;

	notval[0] = notval[1] = 0;
	maxval = (sizeof(boolval) / sizeof(boolval[0])) - 1;
	while (goalfound == FALSE)
	{

		/* Are we through yet? */
		if( CMcmpcase( parser, goal ) == 0 )
		{
			goalfound = TRUE;
			CMnext(parser);
		}

		/* If the string is empty then bail out */
		else if( STlength( parser ) == 0)
			break;

		/* Have we exhausted our parsing capabilities? */
		else if (curval > maxval)
			break;

		/* If this is white space then just skip over it */
		else if( CMwhite( parser ))
			CMnext( parser );

		/* Is this an end to a parenthetical expression? */
		/* its not our goal, but it could be someones */
		else if( CMcmpcase( parser, ERx(")") ) == 0 &&
			*goal != EOS)
		{
			goalfound = TRUE;
			break;
		}

		/* Is this a NOT (!) to reverse the value of next boolean? */
		else if( CMcmpcase( parser, ERx("!") ) == 0 )
		{
			/* Use the xor operator to toggle, allows for !(!val) */
			notval[curval] ^= 1;
			CMnext(parser);
		}

		/* Is this a parenthetical expression? */
		else if( CMcmpcase( parser,ERx("(") ) == 0)
		{
			CMnext(parser);
			boolval[curval++] = pp_eval_boolexp(&parser, ERx(")"));
		}

		/* Is this an AND (&&) operator? */
 		else if( STbcompare( parser, 2, ERx("&&"), 2, 0 ) == 0) 
		{
			if (oper != OPER_NONE)
			{
				SIfprintf( stderr, E_YAPP001 );
				SIfprintf( stderr, E_YAPP00F );
				yydump();
			}
			oper = OPER_AND;

			CMnext(parser);
			CMnext(parser);

			boolval[curval++] = pp_eval_boolexp(&parser, ERx("\n"));
		}

		/* Is this an OR (||) operator? */
 		else if( STbcompare( parser, 2, ERx("||"), 2, 0 ) == 0) 
		{
			if (oper != OPER_NONE)
			{
				SIfprintf( stderr, E_YAPP001 );
				SIfprintf( stderr, E_YAPP011 );
				yydump();
			}
			oper = OPER_OR;

			CMnext(parser);
			CMnext(parser);

			boolval[curval++] = pp_eval_boolexp(&parser, ERx("\n"));
		}

		/* Is this the defined() preprocessor macro? */
 		else if( STbcompare( parser, 7, ERx("defined"), 7, 0 ) == 0 ) 
		{
			char defsym[MAX_SYMLEN + 1];
			char *defptr;

			/* Initialize the symbol name */
			STcopy(ERx(""), defsym);

			/* Try and find the beginning '(' */
			while (STlength(parser) > 0 &&
				CMcmpcase(parser, ERx("(") ) != 0)
				CMnext(parser);

			/* Skip over the open parenthesis, ( */
			if (STlength(parser) != 0)
				CMnext(parser);

			/* Skip over any whitespace following '(' */
			while (STlength(parser) > 0 && CMwhite(parser))
				CMnext(parser);

			/* Save the name of the symbol to look up */
			defptr = defsym;
			while (STlength(parser) > 0 &&
				CMcmpcase(parser, ERx(")") ) != 0 &&
				!CMwhite(parser))
			{
				CMcpychar(parser, defptr);
				CMnext(parser);
				CMnext(defptr);
			}
			*defptr = EOS;

			/* Try and find the ending ')' */
			while (STlength(parser) > 0 &&
				CMcmpcase(parser, ERx(")") ) != 0)
				CMnext(parser);

			/* Skip over the closed parenthesis, ) */
			if (STlength(parser) != 0)
				CMnext(parser);

			/* Make sure there was something in the parenthesis */
			if (STlength(defsym) == 0)
			{
				SIfprintf( stderr, E_YAPP001 );
				SIfprintf( stderr, E_YAPP013 );
				yydump();
			}
			boolval[curval++] = (is_defined(defsym, NULL) == OK);
		}

		/* Thats all we know how to parse, gotta bail out */
		else
		{
			SIfprintf( stderr, E_YAPP001 );
			SIfprintf( stderr, E_YAPP014 );
			yydump();
		}
	}

	/* Did we ultimately fail to evaluate the expression? */
	if (*goal == EOS && goalfound == FALSE)
	{
		SIfprintf( stderr, E_YAPP001 );
		SIfprintf( stderr, E_YAPP015 );
		yydump();
	}

	/* Now make sure something was specified in the current expression */
	if (curval == 0)
	{
		SIfprintf( stderr, E_YAPP001 );
		SIfprintf( stderr, E_YAPP016 );
		yydump();

	}

	/* If an operator is found make sure it had an object to operate on */
	if (oper != OPER_NONE && curval <= maxval)	
	{
		SIfprintf( stderr, E_YAPP001 );
		SIfprintf( stderr, E_YAPP017 );
		yydump();
	}

	/* Save the current location in parse string */
	*strptr = parser;

	/* Resolve the highest precedence NOT operators */
	if (curval > 0 && notval[0] == 1)
		boolval[0] = !boolval[0];
	if (curval > 1 && notval[1] == 1)
		boolval[1] = !boolval[1];

	/* Resolve the final expression */
	switch (oper)
	{
		case OPER_OR:
			rtn = boolval[0] || boolval[1];
			break;

		case OPER_AND:
			rtn = boolval[0] && boolval[1];
			break;

		default: 
			rtn = boolval[0]; 
			break;
	}
	return rtn;
}
Exemple #4
0
static u_i4 
pp_directive( FILE *input, STACK_FRAME *stack , bool ifdef )
{
	i4 n, len;
	char *words[ MAX_LINE / 2 ], *temp, *p;
	char *parse_val, *parse_end;
	STACK_FRAME stack_frame;
	bool def_dir;
	u_i4 rtn = NONE;

	stack_frame.prev = stack;
	stack_frame.display_mode = TRUE;

	p = temp = STalloc( infile->yytext );
	CMnext( p );
	n = sizeof( words );
	STgetwords( p, &n, words ); 

	/* process the directive, watch out for the empty directive */
	if (n == 0)
	{
		;       /* empty directive */
	}
	else if( STequal( words[ 0 ], ERx( "define" ) ) != 0 )
	{
		/* If a symbol was specified look for the value to give it */
		if (n > 1) 
		{
			/* Scan for the 'define' keyword */
			parse_val = infile->yytext;
			CMnext(parse_val);         /* Skip over the '#' */
			while (CMwhite(parse_val))
				CMnext(parse_val);

			/* Scan past the 'define' keyword */
			while (!CMwhite(parse_val))
				CMnext(parse_val);

			/* Scan over white space separating 'define' */
			/* keyword and the specified symbol name */
			while (CMwhite(parse_val))
				CMnext(parse_val);

			/* Skip over the symbol name */
			while (!CMwhite(parse_val))
				CMnext(parse_val);

			/* Skip over white space after the symbol name */
			while (CMwhite(parse_val))
				CMnext(parse_val);

			/* At this point we have scanned to the beginning */
			/* of the defined value for the symbol, Trim off */
			/* any trailing white space */
			STtrmwhite(parse_val);

			/* Define value found, could be the empty string, "" */
			if( active( &stack_frame ) )
			{
				define( words[ 1 ], parse_val, FALSE );
			}
		}
		rtn = DEFINE;
	}

	else if( active( &stack_frame ) &&
		STequal( words[ 0 ], ERx( "undef" ) ) != 0 )
	{
		if (n > 1)
		{
			undefine( words[ 1 ] );
		}
		rtn = UNDEF;
	}

	else if( STequal( words[ 0 ], ERx( "if" ) ) != 0 )
	{
		/* If an expression was specified look for its evaluation */
		if (n > 1) 
		{
			/* Scan for the 'if' keyword */
			parse_val = infile->yytext;
			CMnext(parse_val);         /* Skip over the '#' */
			while (CMwhite(parse_val))
				CMnext(parse_val);

			/* Scan past the 'if' keyword */
			while (!CMwhite(parse_val))
				CMnext(parse_val);

			/* Scan over white space separating 'if' */
			/* keyword and the expression */
			while (CMwhite(parse_val))
				CMnext(parse_val);

			/* At this point we have scanned to the beginning */
			/* of the expression.*/
			if( active( &stack_frame ) )
			{
				/* Evaluate boolean expression found */
				stack_frame.display_mode = 
					pp_eval_boolexp( &parse_val, ERx("") );
			}
			(void) pp_input( input, &stack_frame, TRUE );
		}
		rtn = IF;
	}

	else if( STequal( words[ 0 ], ERx( "ifdef" ) ) != 0 )
	{
		if( active(&stack_frame) && is_defined(words[1], NULL) == OK)
		{
			stack_frame.display_mode = TRUE;
		}
		else
			stack_frame.display_mode = FALSE;
		(void) pp_input( input, &stack_frame, TRUE );
		rtn = IFDEF;
	}

	else if( STequal( words[ 0 ], ERx( "ifndef" ) ) != 0 )
	{
		if( active(&stack_frame) && is_defined(words[1], NULL) != OK)
		{
			stack_frame.display_mode = TRUE;
		}
		else
			stack_frame.display_mode = FALSE;
		(void) pp_input( input, &stack_frame, TRUE );
		rtn = IFNDEF;
	}

	else if( STequal( words[ 0 ], ERx( "else" ) ) != 0 )
	{
		if( !ifdef )
		{
			SIfprintf( stderr, E_YAPP007 );
			yydump();
		}
		stack_frame.prev->display_mode =
			( stack_frame.prev->display_mode == TRUE ) ?
			FALSE : TRUE;
		rtn = ELSE;
	}

	else if( STequal( words[ 0 ], ERx( "endif" ) ) != 0 )
	{
		rtn = ENDIF;
	}

	else if( STequal( words[ 0 ], ERx( "include" ) ) != 0 )
	{
		/* Look for the include filename */
		if (n > 1) 
		{
			/* Scan for the 'include' keyword */
			parse_val = infile->yytext;
			CMnext(parse_val);         /* Skip over the '#' */
			while (CMwhite(parse_val))
				CMnext(parse_val);

			/* Scan past the include keyword */
			while (!CMwhite(parse_val))
				CMnext(parse_val);

			/* Scan over white space separating 'include' */
			/* keyword and the specified filename */
			while (CMwhite(parse_val))
				CMnext(parse_val);

			/* At this point were expecting "file" or <file> */
			/* remember the character which ends the filename */
			def_dir = TRUE;
			if (CMcmpcase(parse_val, ERx("\"")) == 0)
			{
				parse_end = ERx("\"");
			}
			else if (CMcmpcase(parse_val, ERx("<")) == 0)
			{
				parse_end = ERx(">");
				def_dir = FALSE;
			}
			else
			{
				parse_end = ERx("");
			}

			/* Save the include file name in the temp string. */
			/* Note, this overwrites the parsed words of the  */
			/* record since but these are no longer needed.   */
			p = temp;
			CMnext(parse_val);
			while (*parse_val != EOS)
			{
				if (CMcmpcase(parse_val, parse_end) == 0) 
				{
					/* Terminate the file name and call */
					/* pp_file to process the file. */
					STcopy(ERx(""), p);
					pp_file(stack, temp, def_dir);
					break;
				}
				CMcpychar(parse_val, p);
				CMnext(parse_val);
				CMnext(p);
			}
		}
		rtn = DEFINE;
	}

	/* display everthing but legal directives */ 
	if (rtn == NONE && active( &stack_frame ) )
		yyputline( infile->yytext );

	MEfree( temp );
	return( rtn );
}
Exemple #5
0
/*{
** Name: PSQ_TCNVT	- convert db_data_value to text form
**
** Description:
**      This routine takes any user supplied db_data_value and converts
**  it to the value's textual representation.  This is required for the
**  iiqrytext catalog.  It is assumed that all datavalues can be written
**  into a character representation. 
**
** Inputs:
**	sess_cb				session control block
**	    .pss_adfcb			adf session control block for output
**					arguments.
**      header                          Pointer to chain header
**	dbval				db_data_value
**	result				Place to put pointer to new piece
**	err_blk				Filled in if an error happens
**
** Outputs:
**      result                          Filled in with pointer to chain element
**	err_blk				Filled in if an error happens
**	Returns:
**	    E_DB_OK			Success
**	    E_DB_ERROR			Non-catastrophic failure
**	    E_DB_FATAL			Catastrophic failure
**	Exceptions:
**	    none
**
** Side Effects:
**	    Allocates memory
**
** History:
**      29-jun-87 (daved)
**          written
**	28-jan-91 (andre)
**	    fix bug 35446: size of a new piece should include quotes, if they
**	    were added.
**	18-nov-91 (rog)
**	    Fixed bug 40869, et alia: the above fix missed adding the quotes
**	    to the total size and not just the piece size.
**	23-Sep-2009 (kiria01) b122578
**	    Initialise the ADF_FN_BLK .adf_fi_desc and adf_dv_n members.
**	19-Aug-2010 (kschendel) b124282
**	    Make sure fi-desc is always set to something.
*/
DB_STATUS
psq_tcnvt(
	PSS_SESBLK	   *sess_cb,
	PTR                header,
	DB_DATA_VALUE	   *dbval,
	PTR		   *result,
	DB_ERROR	   *err_blk)
{
    PSQ_THEAD           *hp;
    PSQ_TEXT		*tp;
    i4		err_code;
    DB_STATUS		status;
    ADF_CB		*adf_cb;
    ADF_FN_BLK		adffn;
    i4			dv_size;
    i4			count;
    char		*cptr;
    char		*quote_char;
    DB_TEXT_STRING      *string;
    ADI_DT_NAME		dt_fname;
    ADI_DT_NAME		dt_tname;
    char		f4_style;
    char		f8_style;
    i4			f4_width;
    i4			f8_width;
    i4			f4_prec;
    i4			f8_prec;
    i4			totype;
    i4			is_string;

    hp	    = (PSQ_THEAD *) header;
    adf_cb  = (ADF_CB *) sess_cb->pss_adfcb;
    status  = E_DB_OK;
    totype  = (DB_DT_ID) DB_LTXT_TYPE;

    adffn.adf_r_dv.db_datatype = totype;
    if (dbval->db_datatype == totype)
	dv_size = dbval->db_length;
    else
	dv_size = 0;

    /* JRBCMT -- PSF is not allowed to know this!!  First of all, date is   */
    /* missing from the list below and decimal will soon need to be on it.  */
    /* But also, we need to fix this code so that it doesn't make	    */
    /* assumptions about what types exist.  I think the proper approach is  */
    /* to quote all non-intrinsic types, but this should be investigated.   */

    /* are we dealing with a string type (incoming). */
    if (abs(dbval->db_datatype) == DB_INT_TYPE ||
        abs(dbval->db_datatype) == DB_FLT_TYPE ||
	abs(dbval->db_datatype) == DB_MNY_TYPE ||
	abs(dbval->db_datatype) == DB_BOO_TYPE)
    {
	is_string = FALSE;
	quote_char = (char *) NULL;
    }
    else
    {
	is_string = TRUE;
	quote_char = (sess_cb->pss_lang == DB_SQL) ? "\'" : "\"";
    }
    

    /* set the floating point conversion display */
    f4_style = adf_cb->adf_outarg.ad_f4style;
    f8_style = adf_cb->adf_outarg.ad_f8style;
    f4_width = adf_cb->adf_outarg.ad_f4width;
    f8_width = adf_cb->adf_outarg.ad_f8width;
    f4_prec  = adf_cb->adf_outarg.ad_f4prec;
    f8_prec  = adf_cb->adf_outarg.ad_f8prec;

    adf_cb->adf_outarg.ad_f4style = 'n';
    adf_cb->adf_outarg.ad_f8style = 'n';
    adf_cb->adf_outarg.ad_f4width = 20;
    adf_cb->adf_outarg.ad_f8width = 20;
    adf_cb->adf_outarg.ad_f4prec  = 10;
    adf_cb->adf_outarg.ad_f8prec  = 10;

    /* get the function instance id for this conversion */
    status = adi_ficoerce(adf_cb, dbval->db_datatype, totype, &adffn.adf_fi_id);
    if (status != E_DB_OK)
    {
	goto exit;
    }         

    /* determine the result size. */
    status = adi_fidesc(adf_cb, adffn.adf_fi_id, &adffn.adf_fi_desc);
    if (status != E_DB_OK)
    {
	goto exit;
    }
    if (!dv_size)
    {
	/* Now lets fill in the datatype length info and allocate space for the 
	** data.
	*/
	status = adi_0calclen(adf_cb, &adffn.adf_fi_desc->adi_lenspec, 1, &dbval, 
		&adffn.adf_r_dv);
	dv_size = adffn.adf_r_dv.db_length;

	if (status != E_DB_OK)
	{
	     goto exit;
	}
    }
    /* if string, add room for quotes */
    if (is_string)
	dv_size += 2 * CMbytecnt(quote_char);

    /* Allocate enough space for PSQ_TEXT structure containing piece */
    hp->psq_tmem.ulm_psize = dv_size + sizeof(PSQ_TEXT) - 1;
    status = ulm_palloc(&hp->psq_tmem);
    if (status != E_DB_OK)
    {
	if (hp->psq_tmem.ulm_error.err_code == E_UL0005_NOMEM)
	{
	    psf_error(E_PS0F02_MEMORY_FULL, 0L, PSF_CALLERR, 
		&err_code, err_blk, 0);
	}
	else
	    (VOID) psf_error(E_PS0371_ALLOC_TEXT_CHAIN,
		hp->psq_tmem.ulm_error.err_code, PSF_INTERR,
		&err_code, err_blk, 0);
	return (status);
    }
    *result = hp->psq_tmem.ulm_pptr;
    tp	    = (PSQ_TEXT*) *result;

    string	  = (DB_TEXT_STRING*) tp->psq_tval;
    /* Fill in text piece */
    adffn.adf_r_dv.db_length	= dv_size;
    adffn.adf_r_dv.db_data	= (PTR) string;
    adffn.adf_dv_n		= 1;
    STRUCT_ASSIGN_MACRO(*dbval, adffn.adf_1_dv);
    adffn.adf_pat_flags		= AD_PAT_DOESNT_APPLY;
    if ((status = adf_func(adf_cb, &adffn)) != E_DB_OK)
    {
	goto exit;
    }
    /* CAUTION: entering tricky code.
    ** string is a variable containing a text datatype. We want to convert
    ** to a C datatype.  We also want to add quote characters if the datatype
    ** was a string type.  We grab the count from the string variable first.
    ** we can then use the 2 byte count for character data.
    */
    count = string->db_t_count;
    cptr = (char *)  string;
    if (is_string)
    {
	/*
	** for strings, copy the opening quote (" or ', depending on language)
	*/ 
	CMcpychar(quote_char, cptr);
	cptr += CMbytecnt(quote_char);
    }
    MEcopy((PTR) string->db_t_text, count, (PTR) cptr);
    cptr += count;
    if (is_string)
    {
	/*
	** for strings, copy the closing quote (" or ', depending on language)
	*/ 
	CMcpychar(quote_char, cptr);
    }

    /* if storing a string, do not forget to account for quotes (bug 35446) */
    tp->psq_psize = (is_string) ? count + 2 * CMbytecnt(quote_char) : count;

    /* Hook it up to the chain */
    tp->psq_next = (PSQ_TEXT *) NULL;
    if (hp->psq_last != (PSQ_TEXT *) NULL)
    {
	hp->psq_last->psq_next = tp;
	tp->psq_prev = hp->psq_last;
    }
    else
    {
	tp->psq_prev = NULL;
    }
    hp->psq_last = tp;
    if (hp->psq_first == (PSQ_TEXT *) NULL)
	hp->psq_first = tp;

    /* Add in the length to the total for the chain */
    hp->psq_tsize += tp->psq_psize;

exit:
    /* set the floating point conversion display */
    adf_cb->adf_outarg.ad_f4style = f4_style;
    adf_cb->adf_outarg.ad_f8style = f8_style;
    adf_cb->adf_outarg.ad_f4width = f4_width;
    adf_cb->adf_outarg.ad_f8width = f8_width;
    adf_cb->adf_outarg.ad_f4prec  = f4_prec;
    adf_cb->adf_outarg.ad_f8prec  = f8_prec;

    if (status != E_DB_OK)
    {
	(VOID) adi_tyname(adf_cb, dbval->db_datatype, &dt_fname);
	(VOID) adi_tyname(adf_cb, totype, &dt_tname);
	(VOID) psf_error(2911L, 0L, PSF_USERERR,
	    &err_code, err_blk, 3, sizeof (sess_cb->pss_lineno),
	    &sess_cb->pss_lineno, 
	    psf_trmwhite(sizeof(dt_fname), (char *) &dt_fname), &dt_fname, 
	    psf_trmwhite(sizeof (dt_tname), (char *) &dt_tname), &dt_tname);
        return (E_DB_ERROR);    
    }
    return (status);
}
Exemple #6
0
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);
}
Exemple #7
0
/*{
** Name: psq_rptqry_text - add a piece of text to the text chain for a repeat
**			   query
**
** Description: Add a piece of text to the text chain for a repeat query.  It is
**		imperative that text of all repeat queries be stored in a
**		uniform fashion so that comparing two stored query texts would
**		serve as a reliable indicator of their sameness.  Each piece
**		will be preceeded with a blank except for a PERIOD.  Neither the
**		piece consisting of PERIOD nor the following piece will be
**		preceeded with a blank.
**
** Inputs:
**      header                          Pointer to chain header
**	piece				Pointer to piece of text
**	size				Size of piece
**	result				Place to put pointer to new piece
**	err_blk				Filled in if an error happens
**
** Outputs:
**      result                          Filled in with pointer to chain element
**	err_blk				Filled in if an error happens
**	Returns:
**	    E_DB_OK			Success
**	    E_DB_ERROR			Non-catastrophic failure
**	    E_DB_FATAL			Catastrophic failure
**	Exceptions:
**	    none
**
** Side Effects:
**	    Allocates memory
**
** History:
**      24-jan-90 (andre)
**          Plagiarized from psq_tadd().
**	28-jan-91 (andre)
**	    Do not insert a space if a piece is immediately following a piece
**	    consisting of a $.
*/
DB_STATUS
psq_rptqry_text(
	PTR                header,
	u_char		   *piece,
	i4		   size,
	PTR		   *result,
	DB_ERROR	   *err_blk)
{
    PSQ_THEAD           *hp = (PSQ_THEAD *) header;
    PSQ_TEXT		*tp;
    i4		err_code;
    bool		leading_blank;
    char		*txt;
    DB_STATUS		status;

    /*
    ** Allocate enough space for PSQ_TEXT structure containing piece:
    ** all pieces will be preceeded with a blank with the following exceptions:
    **	- piece consisting of PERIOD will not be preceeeded with a blank;
    **	- piece which immediately follows a piece consisting of PERIOD;
    **	- piece starting with a "white" character will not be preceeded with a
    **	  blank;
    **	- piece which immediately follows a piece consisting of $ (preceeded by
    **	  a blank which was inserted by this function)
    */

    if (   size == CMbytecnt(".") && !CMcmpcase(piece, ".")
	|| CMwhite(piece))
    {
	/*
	** piece consists of a period or starts with a "white" character - no
	** leading blanks will be added
	*/
	leading_blank = FALSE;
    }
    else if (   hp->psq_last != (PSQ_TEXT *) NULL
	     && ((   hp->psq_last->psq_psize == CMbytecnt(".")
		  && !CMcmpcase(hp->psq_last->psq_tval, ".")
		 )
		 ||
		 (   hp->psq_last->psq_psize == CMbytecnt(" ") + CMbytecnt("$")
		  && !CMcmpcase(hp->psq_last->psq_tval, " ")
		  && !CMcmpcase((hp->psq_last->psq_tval + CMbytecnt(" ")), "$")
		 )
	        )
	    )
    {
	/*
	** previous piece consists of a period or of a $ preceeded by a blank
	** inserted by this function - no leading blanks will be added
	*/
	leading_blank = FALSE;
    }
    else
    {
	/* insert a blank before the piece */
	leading_blank = TRUE;
    }

    hp->psq_tmem.ulm_psize = (leading_blank)
	? size + sizeof(PSQ_TEXT) - 1 + CMbytecnt(" ")
	: size + sizeof(PSQ_TEXT) - 1;

    if ((status = ulm_palloc(&hp->psq_tmem)) != E_DB_OK)
    {
	if (hp->psq_tmem.ulm_error.err_code == E_UL0005_NOMEM)
	{
	    (VOID) psf_error(E_PS0F02_MEMORY_FULL, 0L, PSF_CALLERR, 
		&err_code, err_blk, 0);
	}
	else
	{
	    (VOID) psf_error(E_PS0371_ALLOC_TEXT_CHAIN,
		hp->psq_tmem.ulm_error.err_code, PSF_INTERR, &err_code, err_blk,
		0);
	}

	return (status);
    }

    *result = hp->psq_tmem.ulm_pptr;
    tp	    = (PSQ_TEXT*) *result;

    /* Fill in text piece */
    txt = (char *) tp->psq_tval;

    /* insert a leading blank if necessary */
    if (leading_blank)
    {
	CMcpychar(" ", txt);
	txt += CMbytecnt(" ");
    }
	
    MEcopy((char *) piece, size, txt);
    tp->psq_psize = (leading_blank) ? size + CMbytecnt(" ") : size;

    /* Hook it up to the chain */
    tp->psq_next = (PSQ_TEXT *) NULL;
    if (hp->psq_last != (PSQ_TEXT *) NULL)
    {
	hp->psq_last->psq_next = tp;
	tp->psq_prev = hp->psq_last;
    }
    else
    {
	tp->psq_prev = NULL;
    }
    hp->psq_last = tp;
    if (hp->psq_first == (PSQ_TEXT *) NULL)
	hp->psq_first = tp;

    /* Add in the length to the total for the chain */
    hp->psq_tsize += tp->psq_psize;

    return (E_DB_OK);
}
Exemple #8
0
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);
}
Exemple #9
0
i4
yylex()
{
	bool pattern;
	bool component;
	bool keyword;
	char *keyhead;
	char yytext[ SI_MAX_TXT_REC + 1 ];
	i4 yyleng;

	/* skip whitespace and comments */
	while( CMwhite( yyp ) || *yyp == EOS || *yyp == '-' )
	{
		/* check for comment */
		if( *yyp == '-' )
		{
			if( STbcompare( yyp, 2, ERx( "--" ), 2, FALSE ) == 0 )
			{
				while( *yyp != EOS )
					CMnext( yyp );
			}
			else
				break;
		}

		if( *yyp == EOS )
		{
			if( SIgetrec( yybuf, sizeof( yybuf ), yyin ) != OK &&
				yywrap() )
			{
				return( 0 );
			}
			else
			{
				yyp = yybuf;
				++yylineno;
			}
		}
		else
			CMnext( yyp );
	}

	/* check for a SYMBOL, PATTERN or keyword */
	yyleng = 0;
	pattern = FALSE;
	keyword = TRUE;
	keyhead = yyp;
	while( CMalpha( yyp ) || *yyp == '%' || *yyp == '$' || *yyp == '*' )
	{
		/* check for component of legal SYMBOL or PATTERN */ 
		component = FALSE;

		/* check for single-character component */
		switch( *yyp )
		{
			case '%':
				pattern = TRUE;
			case '*':
			case '$':
				component = TRUE;
				++yyleng;
				CMnext( yyp );
				if( *yyp == '.' )
				{
					++yyleng;
					CMnext( yyp );
					keyword = FALSE;
					continue;
				}
				else if( CMalpha( yyp ) )
					yyerror(); 
				continue;
		}

		while( CMalpha( yyp ) || CMdigit( yyp ) ||
			*yyp == '_' || *yyp == '-' )
		{
			++yyleng;
			CMnext( yyp );
			component = TRUE;
		}
		if( component )
		{
			if( *yyp == '.' )
			{
				++yyleng;
				CMnext( yyp );
				keyword = FALSE;
				continue;
			}
			continue;
		}
	}

	/* check for uneaten '.' */
	if( *yyp == '.' )
		yyerror();

	if( yyleng > 0 )
	{
		/* A keyword, SYMBOL or PATTERN was scanned */
		char *p;
		i4 i;

		/* put NULL-terminated copy in yytext */
		STlcopy( keyhead, yytext, yyleng );	
		for( p = yytext, i = 0; i <= yyleng; CMnext( p ), i++ );
		*p = EOS;	

		/* check for keywords */
		if( CMalpha( keyhead) && keyword )
		{
			if( STequal( ERx( "IF" ), yytext ) != 0 )
				return( IF );

			if( STequal( ERx( "ELSE" ), yytext ) != 0 )
				return( ELSE );

			if( STequal( ERx( "ELSEIF" ), yytext ) != 0 )
				return( ELSEIF );

			if( STequal( ERx( "ENDIF" ), yytext ) != 0 )
				return( ENDIF );

			if( STequal( ERx( "MIN" ), yytext ) != 0 )
				return( MIN );

			if( STequal( ERx( "MAX" ), yytext ) != 0 )
				return( MAX );

			if( STequal( ERx( "VALID" ), yytext ) != 0 )
				return( VALID );

			if( STequal( ERx( "PRIME" ), yytext ) != 0 )
				return( PRIME );

			if( STequal( ERx( "SIGNED_INT" ), yytext ) != 0 )
				return( SIGNED_INT );

			if( STequal( ERx( "DECIMAL" ), yytext ) != 0 )
				return( DECIMAL );

			if( STequal( ERx( "SIZETYPE" ), yytext ) != 0 )
				return( SIZETYPE );

			if( STequal( ERx( "POWER2" ), yytext ) != 0 )
				return( POWER2 );

			if( STequal( ERx( "REQUIRES" ), yytext ) != 0 )
				return( REQUIRES );

			if( STequal( ERx( "UNDEFINED" ), yytext ) != 0 )
				return( UNDEFINED );

			if( STequal( ERx( "SUM" ), yytext ) != 0 )
			{
				yylval.integer = SUM;
				return( SUM );
			}

			if( STequal( ERx( "ON" ), yytext ) != 0 )
			{
				yylval.real = 1;
				return( BOOL_CON );
			}

			if( STequal( ERx( "OFF" ), yytext ) != 0 )
			{
				yylval.real = 0;
				return( BOOL_CON );
			}

			if( STequal( ERx( "IS" ), yytext ) != 0 )
			{
				yylval.string = STalloc( yytext );
				return( COMPARE_OP );
			}

			if( STequal( ERx( "DIRECTORY" ), yytext ) != 0 )
				return( DIRECTORY );

			if( STequal( ERx( "FILE" ), yytext ) != 0 )
				return( FILESPEC );

		}
		/* valid SYMBOL or PATTERN */
		yylval.string = STalloc( yytext );
		if( pattern )
			return( PATTERN );
		/* don't accept a single '*' as SYMBOL */
		if( yyleng != 1 || *yytext != '*' )
			return( SYMBOL );

		/* push '*' back onto the input stream */
		CMprev( yyp, yybuf );
	}

	/* check for EXEC_TEXT, STR_CON, or EXEC_TEXT_STR */
	if( *yyp == '`' || *yyp == '"' )
	{
		int exec_str = 0;
		char *initstr = yyp;
		char *p = yyp, *text, *yyprev;

		if ( *yyp == '"' )
		{
			CMnext( yyp );
			if ( *yyp == '`' )
			{
				CMnext( p );
				exec_str = 1;
			}
			else
				yyp = p;
		}
		for( yyleng = 0, CMnext( yyp ), yyprev = ERx( "" );
			*yyp != *p || *yyprev == '\\';
			yyprev = ( *yyprev == EOS ) ? yyp : CMnext( yyprev ),
			CMnext( yyp ), ++yyleng )
		{
			if( *yyp == *p && *yyprev == '\\' )
			{
				/* remove escape character */
				char *p1, *p2;

				for( p1 = p2 = yyprev, CMprev( p1, p );
					p1 >= p; CMprev( p1, p ),
					CMprev( p2, p ) )
				{
					CMcpychar( p1, p2 );
				}
				--yyleng;
				CMnext( p );
			}

			if( *yyp == EOS )
				yyerror();
		}
		CMnext( yyp );
		if ( exec_str )
		{
			if ( *yyp == '"' )
				CMnext( yyp );
			else
			{
				/* keep scanning to final '"' */
				p = initstr;
				exec_str = 0;
				yyleng++;
				for( ; *yyp != *p || *yyprev == '\\';
					yyprev = ( *yyprev == EOS ) ? yyp : 
					CMnext( yyprev ),
					CMnext( yyp ), ++yyleng )
				{
					if( *yyp == EOS )
						yyerror();
				}
			}
		}
		text = p;
		CMnext( text );
		STlcopy( text, yytext, yyleng );
		yytext[ yyleng ] = EOS;
		yylval.string = STalloc( yytext );
		if( *p == '`' )
		{
			if ( exec_str )
				return( EXEC_TEXT_STR );
			return( EXEC_TEXT );
		}
		return( STR_CON );
	}

	/* check for NUM_CON */
	yyleng = 0;
	if( *yyp == '-' || CMdigit( yyp ) )
	{
		f8 factor;
		char *p = yyp;

		if( *yyp == '-' )
		{
			++yyleng;
			factor = -1;
			CMnext( yyp );
		}
		else
			factor = 1;
		
		if( !CMdigit( yyp ) )
			CMprev( yyp, yybuf );
		else
		{
			if( *yyp == '-' )
			{
				CMnext( yyp );	
				
			}
			else
				factor = 1;

			while( CMdigit( yyp ) )
			{
				++yyleng;
				CMnext( yyp );
			}

			if( *yyp == '.' )
			{
				++yyleng;
				CMnext( yyp );
				if( !CMdigit( yyp ) )
					yyerror();
				while( CMdigit( yyp ) )
				{
					++yyleng;
					CMnext( yyp );
				}
			}
			else if( *yyp == 'K' || *yyp == 'M' )
			{
				++yyleng;
				CMnext( yyp );
			}

			STlcopy( p, yytext, yyleng ); 
			yytext[ yyleng ] = EOS;

			if( yytext[ yyleng - 1 ] == 'K' )
			{
				factor = 1024;
				yytext[ yyleng - 1 ] = EOS;
			}
			else if( yytext[ yyleng - 1 ] == 'M' )
			{
				factor = 1048576;
				yytext[ yyleng - 1 ] = EOS;
			}
			CVaf( yytext, ERx( '.' ), &yylval.real );
			yylval.real *= factor;
			return( NUM_CON );
		}
	}

	if( STbcompare( yyp, 2, ERx( ">=" ), 2, FALSE ) == 0 )
	{
		yylval.string = STalloc( ERx( ">=" ) );
		CMnext( yyp );
		CMnext( yyp );
		return( COMPARE_OP );
	}
	if( STbcompare( yyp, 2, ERx( "<=" ), 2, FALSE ) == 0 )
	{
		yylval.string = STalloc( ERx( "<=" ) );
		CMnext( yyp );
		CMnext( yyp );
		return( COMPARE_OP );
	}
	/* check for COMPARE_OP */
	if( STbcompare( yyp, 1, ERx( "<" ), 1, FALSE ) == 0 )
	{
		yylval.string = STalloc( ERx( "<" ) );
		CMnext( yyp );
		return( COMPARE_OP );
	}
	if( STbcompare( yyp, 1, ERx( ">" ), 1, FALSE ) == 0 ) 
	{
		yylval.string = STalloc( ERx( ">" ) );
		CMnext( yyp );
		return( COMPARE_OP );
	}
	if( STbcompare( yyp, 2, ERx( "==" ), 2, FALSE ) == 0 )
	{
		yylval.string = STalloc( ERx( "==" ) );
		CMnext( yyp );
		CMnext( yyp );
		return( COMPARE_OP );
	}

	/* check for characters which get passed directly */
	switch( *yyp )
	{
		char *p;

		case '(':
		case ')':
		case '[':
		case ']':
		case '{':
		case '}':
		case ':':
		case ';':
		case ',':
		case '=':
			p = yyp;
			CMnext( yyp );
			return( *p );	

		case '+':
			yylval.string = STalloc( ERx( "+" ) );
			CMnext( yyp );
			return( *yylval.string );

		case '-':
			yylval.string = STalloc( ERx( "-" ) );
			CMnext( yyp );
			return( *yylval.string );

		case '*':
			yylval.string = STalloc( ERx( "*" ) );
			CMnext( yyp );
			return( *yylval.string );

		case '/':
			yylval.string = STalloc( ERx( "/" ) );
			CMnext( yyp );
			return( *yylval.string );
	}

	/* check for LOGIC_OP */
	if( STbcompare( yyp, 3, ERx( "&&" ), 3, FALSE ) == 0 )
	{
		yylval.string = STalloc( ERx( "&&" ) );
		CMnext( yyp );
		CMnext( yyp );
		return( LOGIC_OP );
	}
	if( STbcompare( yyp, 3, ERx( "||" ), 3, FALSE ) == 0 )
	{
		yylval.string = STalloc( ERx( "||" ) );
		CMnext( yyp );
		CMnext( yyp );
		return( LOGIC_OP );
	}

	/* anything else is an error */
	yyerror();

}
Exemple #10
0
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 = &param[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);
}
Exemple #11
0
/*{
** Name:	RPedit_name - edit an Ingres name
**
** Description:
**	Edit an Ingres name as specified.  The edited name is placed in a
**	global buffer.
**
** Inputs:
**	edit_type	- edit type
**			  EDNM_ALPHA	- replace special chars with '_'.
**			  EDNM_DELIMIT	- Ingres delimited name.
**			  EDNM_SLITERAL	- SQL single quoted string.
**			  else		- no edit
**	name		- name to edit
**
** Outputs:
**	edited_name	- if supplied, this buffer is filled with the edited
**			  name;  if NULL, a global buffer is used and the
**			  caller should do an STcopy() upon return.
**
** Returns:
**	pointer to the edited name
**/
char *
RPedit_name(
i4	edit_type,
char	*name,
char	*edited_name)
{
	char	tmp_name[DB_MAXNAME*2+3];
	char	*t = tmp_name;
	char	*en;
	char	*n;

	if (edited_name != NULL)
		en = edited_name;
	else
		en = Edited_Name_Buf;

	switch (edit_type)
	{
	case EDNM_ALPHA:		/* alphanumeric */
		for (n = name; *n != EOS; CMnext(n))
		{
			if (CMalpha(n) || (n != name && CMdigit(n)))
				CMcpychar(n, t);
			else
				CMcpychar(ERx("_"), t);
			CMnext(t);
		}
		*t = EOS;
		break;

	case EDNM_DELIMIT:		/* delimited */
		CMcpychar(ERx("\""), t);
		CMnext(t);
		for (n = name; *n != EOS; CMnext(n))
		{
			CMcpychar(n, t);
			if (!CMcmpcase(t, ERx("\"")))
			{
				CMnext(t);
				CMcpychar(ERx("\""), t);
			}
			CMnext(t);
		}
		CMcpychar(ERx("\""), t);
		CMnext(t);
		*t = EOS;
		break;

	case EDNM_SLITERAL:		/* SQL quoted */
		CMcpychar(ERx("'"), t);
		CMnext(t);
		for (n = name; *n != EOS; CMnext(n))
		{
			if (!CMcmpcase(n, ERx("'")))
			{
				CMcpychar(ERx("'"), t);
				CMnext(t);
			}
			CMcpychar(n, t);
			CMnext(t);
		}
		CMcpychar(ERx("'"), t);
		CMnext(t);
		*t = EOS;
		break;

	default:			/* no edit */
		t = name;
		break;
	}

	STcopy(tmp_name, en);
	return (en);
}