/* ** Title: Strings ** SCCSid: %W% %E% %U% ** CCid: %W% %E% %U% ** Author: Informix Software, Inc. ** Created: 06/11/1998 14:51 ** Description: This is the generated 'C' file for the Strings DataBlade. ** Comments: Generated for project Strings.3.6 */ /* ** The following is placed here to insure ** that name "mangling" does not occur. */ /* ** This file contains the following functions: ** ** InStr ** LCase ** Len ** LTrim ** Mid ** MidSansLen ** Right ** RTrim ** Spaces ** StrCat ** StringDup ** TrimSpaces ** UCase ** ** The following custom errors are used: ** ** ** STR01 - The string "%s" contains an invalid GLS character. ** STR02 - The character count must be greater than or equal to 0. ** STR03 - The starting search position must be greater than or equal to 1. ** STR04 - The input string contains an invalid GLS character. ** STR05 - The character length must be greater than or equal to 0. ** STR06 - Saving the Large Object to the database has failed. ** STR07 - Reading the Large Object has failed. */ #ifdef __cplusplus extern "C" { #endif /* Standard library includes. */ #include #include #include #include /* Used by Informix GLS routines. */ #include /* Include when accessing the Informix API. */ #include /* This is the project include file. */ #include "Strings.h" #ifdef max #undef max #endif #define max(a,b) (((a) > (b)) ? (a) : (b)) #ifdef min #undef min #endif #define min(a,b) (((a) < (b)) ? (a) : (b)) /* Headers used by the compression routines. */ #include "lobitio.h" #include "errhand.h" /* Function prototypes. */ UDREXPORT mi_integer Len( mi_lvarchar * String1, MI_FPARAM * Gen_fparam ); UDREXPORT mi_lvarchar * LTrim( mi_lvarchar * String1, MI_FPARAM * Gen_fparam ); UDREXPORT mi_lvarchar * Mid( mi_lvarchar * String1, mi_integer Start, mi_integer Len, MI_FPARAM * Gen_fparam ); UDREXPORT mi_lvarchar * RTrim( mi_lvarchar * String1, MI_FPARAM * Gen_fparam ); UDREXPORT void CompressStr( char * input, BIT_FILE * output, long ); UDREXPORT void ExpandStr( BIT_FILE * input, char * output ); UDREXPORT mi_lvarchar *StrCat(mi_lvarchar *String1,mi_lvarchar *String2,MI_FPARAM *Gen_fparam); /* {{FUNCTION(1cda81ce-ce19-11d0-8874-00a0c9255cf3) (MergeSection) */ /**************************************************************** ** ** Function name: ** ** Spaces ** ** Description: ** ** Special Comments: ** ** Entrypoint for the SQL routine Spaces (integer) returns lvarchar. ** ** Parameters: ** ** Return value: ** ** mi_lvarchar ** ** History: ** ** 06/30/1998 - Generated by BladeSmith Version 3.60.630 . ** ** Identification: ** ** NOTE: ** ** BladeSmith will add and remove parameters from the function ** prototype, and will generate tracing calls. ONLY EDIT code ** in blocks marked Your_
. Any other modifications ** will require manual merging. ** ***************************************************************** */ UDREXPORT mi_lvarchar *Spaces ( mi_integer Count, MI_FPARAM * Gen_fparam /* Standard info - see DBDK docs.*/ ) { mi_lvarchar* Gen_RetVal; /* The return value. */ MI_CONNECTION * Gen_Con; /* The connection handle. */ /* ------ {{Your_Declarations (PreserveSection) BEGIN ------ */ /* ------ }}Your_Declarations (#0000) END ------ */ /* Use the NULL connection. */ Gen_Con = NULL; /* ------ {{Your_Code (PreserveSection) BEGIN ------ */ /* ** Write to the trace file indicating ** that Spaces has been called. */ DBDK_TRACE_ENTER( "Spaces" ); /* Validate the input parameters. */ if( Count < 0 ) { /* ** An invalid character count was requested ** so issue the following message and quit. ** ** "The character count must be greater than or equal to 0." */ DBDK_TRACE_ERROR( "Spaces", "STR02", 10 ); /* not reached */ } /* ** Allocate the return value. It must be ** allocated if it is a UDT or type whose ** size is greater than 4 bytes. */ Gen_RetVal = (mi_lvarchar *)mi_new_var( Count ); /* Verify that memory was successfully allocated. */ if( Gen_RetVal == 0 ) { /* ** Memory allocation has failed so issue ** the following message and quit. ** ** "Memory allocation has failed in Spaces." */ DBDK_TRACE_ERROR( "Spaces", ERRORMESG2, 10 ); /* not reached */ } /* Flood fill the return string with blanks. */ if( Count > 0 ) { memset( mi_get_vardata( Gen_RetVal ), ' ', Count); } /* ** Write to the trace file indicating ** that Spaces has successfully exited. */ DBDK_TRACE_EXIT( "Spaces" ); /* ------ }}Your_Code (#63RM) END ------ */ /* Return the function's return value. */ return Gen_RetVal; } /* }}FUNCTION (#SFIOCGL0) */ /* {{FUNCTION(1cda81cb-ce19-11d0-8874-00a0c9255cf3) (MergeSection) */ /**************************************************************** ** ** Function name: ** ** Mid ** ** Description: ** ** Special Comments: ** ** Entrypoint for the SQL routine Mid (lvarchar,integer,integer) returns lvarchar. ** ** Parameters: ** ** Return value: ** ** mi_lvarchar ** ** History: ** ** 06/30/1998 - Generated by BladeSmith Version 3.60.630 . ** ** Identification: ** ** NOTE: ** ** BladeSmith will add and remove parameters from the function ** prototype, and will generate tracing calls. ONLY EDIT code ** in blocks marked Your_
. Any other modifications ** will require manual merging. ** ***************************************************************** */ UDREXPORT mi_lvarchar *Mid ( mi_lvarchar * String1, mi_integer Start, mi_integer Len, MI_FPARAM * Gen_fparam /* Standard info - see DBDK docs.*/ ) { mi_lvarchar* Gen_RetVal; /* The return value. */ MI_CONNECTION * Gen_Con; /* The connection handle. */ /* ------ {{Your_Declarations (PreserveSection) BEGIN ------ */ gl_mchar_t * Gen_In; gl_mchar_t * StartPos; gl_mchar_t * EndPos; mi_integer StrLen; mi_integer ByteLen; mi_integer index; /* ------ }}Your_Declarations (#0000) END ------ */ /* Use the NULL connection. */ Gen_Con = NULL; /* ------ {{Your_Code (PreserveSection) BEGIN ------ */ /* ** Write to the trace file indicating ** that Mid has been called. */ DBDK_TRACE_ENTER( "Mid" ); /* Validate the input parameters. */ if( Start <= 0 ) { /* ** The starting position is out of range ** so issue the following message and quit. ** ** "The Starting position is invalid in Mid." */ DBDK_TRACE_ERROR( "Mid", "STR03", 10 ); /* not reached */ } /* Compute the length of String1 in bytes. */ StrLen = ifx_gl_mbslen( (gl_mchar_t *)mi_get_vardata( String1 ), mi_get_varlen( String1 ) ); /* Check for any GLS error that might have occurred. */ if( StrLen == -1 ) { /* ** A GLS error has occurred so issue ** the following message and quit. ** ** "The input string contains an invalid GLS character." */ DBDK_TRACE_ERROR( "Mid", "STR04", 10 ); /* not reached */ } /* ** If the requested starting position is past the ** end of the string, return a zero-length string. */ if( Start > StrLen ) { Gen_RetVal = (mi_lvarchar *)mi_new_var( 0 ); } else { /* Map Start to 0-based. */ --Start; /* Unwrap the characters from the string. */ Gen_In = (gl_mchar_t *)mi_get_vardata( String1 ); /* Locate the start position in the string. */ for( index = -1; ++index < Start; ) { /* Advance to the next character. */ Gen_In = ifx_gl_mbsnext( Gen_In, 4 ); /* Check for any GLS error that might have occurred. */ if( Gen_In == NULL ) { /* ** A GLS error has occurred so issue ** the following message and quit. ** ** "The input string contains an invalid GLS character." */ DBDK_TRACE_ERROR( "Mid", "STR04", 10 ); /* not reached */ } } /* Point to the start of the characters to copy. */ StartPos = Gen_In; /* Locate the end position in the string. */ while( index++ < min(Start+Len, StrLen) ) { /* Advance to the next character. */ Gen_In = ifx_gl_mbsnext( Gen_In, 4 ); /* Check for any GLS error that might have occurred. */ if( Gen_In == NULL ) { /* ** A GLS error has occurred so issue ** the following message and quit. ** ** "The input string contains an invalid GLS character." */ DBDK_TRACE_ERROR( "Mid", "STR04", 10 ); /* not reached */ } } /* Point to the end of the characters to copy. */ EndPos = Gen_In; /* Allocate the return value. */ ByteLen = EndPos - StartPos; Gen_RetVal = (mi_lvarchar *)mi_new_var( ByteLen ); /* Verify that memory was successfully allocated. */ if( Gen_RetVal == 0 ) { /* ** Memory allocation has failed so issue ** the following message and quit. ** ** "Memory allocation has failed in Mid." */ DBDK_TRACE_ERROR( "Mid", ERRORMESG2, 10 ); /* not reached */ } /* Copy the right-most Len characters of the string. */ memcpy( mi_get_vardata( Gen_RetVal ), StartPos, ByteLen ); } /* ** Write to the trace file indicating ** that Mid has successfully exited. */ DBDK_TRACE_EXIT( "Mid" ); /* ------ }}Your_Code (#7KNF) END ------ */ /* Return the function's return value. */ return Gen_RetVal; } /* }}FUNCTION (#QK0K8R2J) */ /* {{FUNCTION(295abf70-d1fd-11d0-8874-00a0c9255cf3) (MergeSection) */ /**************************************************************** ** ** Function name: ** ** Plus ** ** Description: ** ** Special Comments: ** ** Entrypoint for the SQL routine Plus (lvarchar,lvarchar) returns lvarchar. ** ** Parameters: ** ** Return value: ** ** mi_lvarchar ** ** History: ** ** 06/30/1998 - Generated by BladeSmith Version 3.60.630 . ** ** Identification: ** ** NOTE: ** ** BladeSmith will add and remove parameters from the function ** prototype, and will generate tracing calls. ONLY EDIT code ** in blocks marked Your_
. Any other modifications ** will require manual merging. ** ***************************************************************** */ UDREXPORT mi_lvarchar *Plus ( mi_lvarchar * String1, mi_lvarchar * String2, MI_FPARAM * Gen_fparam /* Standard info - see DBDK docs.*/ ) { mi_lvarchar* Gen_RetVal; /* The return value. */ MI_CONNECTION * Gen_Con; /* The connection handle. */ /* ------ {{Your_Declarations (PreserveSection) BEGIN ------ */ /* ------ }}Your_Declarations (#0000) END ------ */ /* Use the NULL connection. */ Gen_Con = NULL; /* ------ {{Your_Code (PreserveSection) BEGIN ------ */ /* ** Write to the trace file indicating ** that Plus has been called. */ DBDK_TRACE_ENTER( "Plus" ); /* Concatenate the two strings. */ Gen_RetVal = StrCat( String1, String2, Gen_fparam ); /* ** Write to the trace file indicating ** that Plus has successfully exited. */ DBDK_TRACE_EXIT( "Plus" ); /* ------ }}Your_Code (#A9IO) END ------ */ /* Return the function's return value. */ return Gen_RetVal; } /* }}FUNCTION (#A29KJR4F) */ /* {{FUNCTION(1cda81cc-ce19-11d0-8874-00a0c9255cf3) (MergeSection) */ /**************************************************************** ** ** Function name: ** ** MidSansLen ** ** Description: ** ** Special Comments: ** ** Entrypoint for the SQL routine Mid (lvarchar,integer) returns lvarchar. ** ** Parameters: ** ** Return value: ** ** mi_lvarchar ** ** History: ** ** 06/30/1998 - Generated by BladeSmith Version 3.60.630 . ** ** Identification: ** ** NOTE: ** ** BladeSmith will add and remove parameters from the function ** prototype, and will generate tracing calls. ONLY EDIT code ** in blocks marked Your_
. Any other modifications ** will require manual merging. ** ***************************************************************** */ UDREXPORT mi_lvarchar *MidSansLen ( mi_lvarchar * String1, mi_integer Len, MI_FPARAM * Gen_fparam /* Standard info - see DBDK docs.*/ ) { mi_lvarchar* Gen_RetVal; /* The return value. */ MI_CONNECTION * Gen_Con; /* The connection handle. */ /* ------ {{Your_Declarations (PreserveSection) BEGIN ------ */ /* ------ }}Your_Declarations (#0000) END ------ */ /* Use the NULL connection. */ Gen_Con = NULL; /* ------ {{Your_Code (PreserveSection) BEGIN ------ */ Gen_RetVal = Mid( String1, 1, Len, Gen_fparam ); /* ------ }}Your_Code (#H79T) END ------ */ /* Return the function's return value. */ return Gen_RetVal; } /* }}FUNCTION (#INFJJ3PL) */ /* {{FUNCTION(1cda81c7-ce19-11d0-8874-00a0c9255cf3) (MergeSection) */ /**************************************************************** ** ** Function name: ** ** RTrim ** ** Description: ** ** Special Comments: ** ** Entrypoint for the SQL routine RTrim (lvarchar) returns lvarchar. ** ** Parameters: ** ** Return value: ** ** mi_lvarchar ** ** History: ** ** 06/30/1998 - Generated by BladeSmith Version 3.60.630 . ** ** Identification: ** ** NOTE: ** ** BladeSmith will add and remove parameters from the function ** prototype, and will generate tracing calls. ONLY EDIT code ** in blocks marked Your_
. Any other modifications ** will require manual merging. ** ***************************************************************** */ UDREXPORT mi_lvarchar *RTrim ( mi_lvarchar * String1, MI_FPARAM * Gen_fparam /* Standard info - see DBDK docs.*/ ) { mi_lvarchar* Gen_RetVal; /* The return value. */ MI_CONNECTION * Gen_Con; /* The connection handle. */ /* ------ {{Your_Declarations (PreserveSection) BEGIN ------ */ gl_mchar_t * Gen_In; /* Point to the input characters. */ mi_integer Len; /* The length of the string in bytes. */ mi_integer ByteLen; /* The length of the return string. */ mi_integer index; /* Index through the characters. */ gl_mchar_t * BlankPtr; /* The position of the last blank seen. */ mi_integer PrevCharIsBlank; /* ------ }}Your_Declarations (#0000) END ------ */ /* Use the NULL connection. */ Gen_Con = NULL; /* ------ {{Your_Code (PreserveSection) BEGIN ------ */ /* ** Write to the trace file indicating ** that RTrim has been called. */ DBDK_TRACE_ENTER( "RTrim" ); /* Compute the length of String1. */ Len = ifx_gl_mbslen( (gl_mchar_t *)mi_get_vardata( String1 ), mi_get_varlen( String1 ) ); /* Locate the start of the blank padding. */ PrevCharIsBlank = 0; Gen_In = (gl_mchar_t *)mi_get_vardata( String1 ); for( index = 0; index < Len; ++index ) { if( ifx_gl_ismblank( Gen_In, 4) ) { if( !PrevCharIsBlank ) { PrevCharIsBlank = 1; BlankPtr = Gen_In; } } else { PrevCharIsBlank = 0; BlankPtr = Gen_In; } /* Advance to the next character. */ Gen_In = ifx_gl_mbsnext( Gen_In, 4 ); } /* Point back to the last blank. */ Gen_In = BlankPtr; /* Allocate the return value. */ ByteLen = Gen_In - (gl_mchar_t *)mi_get_vardata( String1 ); Gen_RetVal = (mi_lvarchar *)mi_new_var( ByteLen ); /* Verify that memory was successfully allocated. */ if( Gen_RetVal == 0 ) { /* ** Memory allocation has failed so issue ** the following message and quit. ** ** "Memory allocation has failed in RTrim." */ DBDK_TRACE_ERROR( "RTrim", ERRORMESG2, 10 ); /* not reached */ } /* Finally, copy the string. */ memcpy( mi_get_vardata( Gen_RetVal ), mi_get_vardata( String1 ), ByteLen ); /* ** Write to the trace file indicating ** that RTrim has successfully exited. */ DBDK_TRACE_EXIT( "RTrim" ); /* ------ }}Your_Code (#QU9A) END ------ */ /* Return the function's return value. */ return Gen_RetVal; } /* }}FUNCTION (#IQM1GOPO) */ /* {{FUNCTION(1cda81c2-ce19-11d0-8874-00a0c9255cf3) (MergeSection) */ /**************************************************************** ** ** Function name: ** ** Right ** ** Description: ** ** Special Comments: ** ** Entrypoint for the SQL routine Right (lvarchar,integer) returns lvarchar. ** ** Parameters: ** ** Return value: ** ** mi_lvarchar ** ** History: ** ** 06/30/1998 - Generated by BladeSmith Version 3.60.630 . ** ** Identification: ** ** NOTE: ** ** BladeSmith will add and remove parameters from the function ** prototype, and will generate tracing calls. ONLY EDIT code ** in blocks marked Your_
. Any other modifications ** will require manual merging. ** ***************************************************************** */ UDREXPORT mi_lvarchar *Right ( mi_lvarchar * String1, mi_integer Length, MI_FPARAM * Gen_fparam /* Standard info - see DBDK docs.*/ ) { mi_lvarchar* Gen_RetVal; /* The return value. */ MI_CONNECTION * Gen_Con; /* The connection handle. */ /* ------ {{Your_Declarations (PreserveSection) BEGIN ------ */ mi_integer ByteLen; /* Number of bytes in the string. */ gl_mchar_t * Gen_In; /* Points to the input string. */ mi_integer index; /* Index through characters. */ /* ------ }}Your_Declarations (#0000) END ------ */ /* Use the NULL connection. */ Gen_Con = NULL; /* ------ {{Your_Code (PreserveSection) BEGIN ------ */ /* ** Write to the trace file indicating ** that Right has been called. */ DBDK_TRACE_ENTER( "Right" ); /* Validate the input arguments. */ if( Length < 0 ) { /* ** The length is out of range ** so issue the following message and quit. ** ** "The length is invalid." */ DBDK_TRACE_ERROR( "Right", "STR05", 10 ); /* not reached */ } /* If the string is NULL, return NULL. */ if( String1 == NULL ) { mi_fp_setreturnisnull( Gen_fparam, 0, MI_TRUE ); return ( 0 ); } /* Locate the start of the right-most characters. */ Gen_In = (gl_mchar_t *)mi_get_vardata( String1 ); for( index = Len( String1, Gen_fparam ) - Length; index > 0; --index ) { /* Advance to the next character. */ Gen_In = ifx_gl_mbsnext( Gen_In, 4 ); } /* Determine the number of bytes in the new string. */ ByteLen = mi_get_varlen( String1 ) - (Gen_In - (gl_mchar_t *)mi_get_vardata( String1 )); /* Allocate room for the new string. */ Gen_RetVal = (mi_lvarchar *)mi_new_var( ByteLen ); /* Check for an allocation error. */ if( Gen_RetVal == 0 ) { /* ** Memory allocation has failed so issue ** the following message and quit. ** ** "Memory allocation has failed in Right." */ DBDK_TRACE_ERROR( "Right", ERRORMESG2, 10 ); /* not reached */ } /* Copy the right-most bytes to the new string. */ memcpy( mi_get_vardata( Gen_RetVal ), Gen_In, ByteLen ); /* ** Write to the trace file indicating ** that Right has successfully exited. */ DBDK_TRACE_EXIT( "Right" ); /* ------ }}Your_Code (#Q49A) END ------ */ /* Return the function's return value. */ return Gen_RetVal; } /* }}FUNCTION (#OOCN2TA7) */ /* {{FUNCTION(1cda81c5-ce19-11d0-8874-00a0c9255cf3) (MergeSection) */ /**************************************************************** ** ** Function name: ** ** TrimSpaces ** ** Description: ** ** Special Comments: ** ** Entrypoint for the SQL routine TrimSpaces (lvarchar) returns lvarchar. ** ** Parameters: ** ** Return value: ** ** mi_lvarchar ** ** History: ** ** 06/30/1998 - Generated by BladeSmith Version 3.60.630 . ** ** Identification: ** ** NOTE: ** ** BladeSmith will add and remove parameters from the function ** prototype, and will generate tracing calls. ONLY EDIT code ** in blocks marked Your_
. Any other modifications ** will require manual merging. ** ***************************************************************** */ UDREXPORT mi_lvarchar *TrimSpaces ( mi_lvarchar * String1, MI_FPARAM * Gen_fparam /* Standard info - see DBDK docs.*/ ) { mi_lvarchar* Gen_RetVal; /* The return value. */ MI_CONNECTION * Gen_Con; /* The connection handle. */ /* ------ {{Your_Declarations (PreserveSection) BEGIN ------ */ /* ------ }}Your_Declarations (#0000) END ------ */ /* Use the NULL connection. */ Gen_Con = NULL; /* ------ {{Your_Code (PreserveSection) BEGIN ------ */ /* ** Write to the trace file indicating ** that TrimSpaces has been called. */ DBDK_TRACE_ENTER( "TrimSpaces" ); /* Trim the leading and trailing spaces. */ Gen_RetVal = LTrim( RTrim( String1, Gen_fparam ), Gen_fparam ); /* ** Write to the trace file indicating ** that TrimSpaces has successfully exited. */ DBDK_TRACE_EXIT( "TrimSpaces" ); /* ------ }}Your_Code (#HAD9) END ------ */ /* Return the function's return value. */ return Gen_RetVal; } /* }}FUNCTION (#LL31NHPA) */ /* {{FUNCTION(1cda81c9-ce19-11d0-8874-00a0c9255cf3) (MergeSection) */ /**************************************************************** ** ** Function name: ** ** LCase ** ** Description: ** ** Special Comments: ** ** Entrypoint for the SQL routine LCase (lvarchar) returns lvarchar. ** ** Parameters: ** ** Return value: ** ** mi_lvarchar ** ** History: ** ** 06/30/1998 - Generated by BladeSmith Version 3.60.630 . ** ** Identification: ** ** NOTE: ** ** BladeSmith will add and remove parameters from the function ** prototype, and will generate tracing calls. ONLY EDIT code ** in blocks marked Your_
. Any other modifications ** will require manual merging. ** ***************************************************************** */ UDREXPORT mi_lvarchar *LCase ( mi_lvarchar * String1, MI_FPARAM * Gen_fparam /* Standard info - see DBDK docs.*/ ) { mi_lvarchar* Gen_RetVal; /* The return value. */ MI_CONNECTION * Gen_Con; /* The connection handle. */ /* ------ {{Your_Declarations (PreserveSection) BEGIN ------ */ unsigned short CharVal; gl_mchar_t * SrcMb; gl_mchar_t * DestMb; int index; mi_integer Gen_DataLen; /* ------ }}Your_Declarations (#0000) END ------ */ /* Use the NULL connection. */ Gen_Con = NULL; /* ------ {{Your_Code (PreserveSection) BEGIN ------ */ /* ** Write to the trace file indicating ** that LCase has been called. */ DBDK_TRACE_ENTER( "LCase" ); /* ** Compute the length of the resultant string. This length ** may differ from the length of the original string. */ Gen_DataLen = ifx_gl_case_conv_outbuflen( mi_get_varlen( String1 ) ); Gen_RetVal = (mi_lvarchar *)mi_new_var( Gen_DataLen ); /* Verify that memory was successfully allocated. */ if( Gen_RetVal == 0 ) { /* ** Memory allocation has failed so issue ** the following message and quit. ** ** "Memory allocation has failed in LCase." */ DBDK_TRACE_ERROR( "LCase", ERRORMESG2, 10 ); /* not reached */ } /* Clone the string converting each character to lower case. */ SrcMb = (gl_mchar_t *)mi_get_vardata( String1 ); DestMb = (gl_mchar_t *)mi_get_vardata( Gen_RetVal ); Gen_DataLen = mi_get_varlen( String1 ); for( index = ifx_gl_mbslen( (gl_mchar_t *)mi_get_vardata( String1 ), Gen_DataLen); index > 0; --index ) { CharVal = ifx_gl_tomlower( DestMb, SrcMb, 4 ); SrcMb += IFX_GL_CASE_CONV_SRC_BYTES( CharVal ); DestMb += IFX_GL_CASE_CONV_DST_BYTES( CharVal ); } /* ** Write to the trace file indicating ** that LCase has successfully exited. */ DBDK_TRACE_EXIT( "LCase" ); /* ------ }}Your_Code (#QG9A) END ------ */ /* Return the function's return value. */ return Gen_RetVal; } /* }}FUNCTION (#IUE1GNTG) */ /* {{FUNCTION(1cda81ca-ce19-11d0-8874-00a0c9255cf3) (MergeSection) */ /**************************************************************** ** ** Function name: ** ** Len ** ** Description: ** ** Special Comments: ** ** Entrypoint for the SQL routine Len (lvarchar) returns integer. ** ** Parameters: ** ** Return value: ** ** mi_integer ** ** History: ** ** 06/30/1998 - Generated by BladeSmith Version 3.60.630 . ** ** Identification: ** ** NOTE: ** ** BladeSmith will add and remove parameters from the function ** prototype, and will generate tracing calls. ONLY EDIT code ** in blocks marked Your_
. Any other modifications ** will require manual merging. ** ***************************************************************** */ UDREXPORT mi_integer Len ( mi_lvarchar * String1, MI_FPARAM * Gen_fparam /* Standard info - see DBDK docs.*/ ) { MI_CONNECTION * Gen_Con; /* The connection handle. */ mi_integer Gen_RetVal; /* The return value. */ /* ------ {{Your_Declarations (PreserveSection) BEGIN ------ */ mi_integer ByteLen; /* Number of bytes in the string. */ mi_integer CharLen; /* Number of characters in the str. */ /* ------ }}Your_Declarations (#0000) END ------ */ /* Use the NULL connection. */ Gen_Con = NULL; /* ------ {{Your_Code (PreserveSection) BEGIN ------ */ /* ** Write to the trace file indicating ** that Len has been called. */ DBDK_TRACE_ENTER( "Len" ); /* If the string is NULL, return NULL. */ if( String1 == NULL ) { mi_fp_setreturnisnull( Gen_fparam, 0, MI_TRUE ); return ( 0 ); } /* Determine the number of bytes in the string. */ ByteLen = mi_get_varlen( String1 ); /* ** Write to the trace file indicating ** that Len has successfully exited. */ DBDK_TRACE_EXIT( "Len" ); /* Compute the length of the string in characters. */ CharLen = ifx_gl_mbslen( (gl_mchar_t *)String1, ByteLen ); /* Check for an error. */ if( CharLen == -1 ) { /* ** A GLS error has occurred so issue ** the following message and quit. ** ** "The input string contains an invalid GLS character." */ DBDK_TRACE_ERROR( "Len", "STR04", 10 ); /* not reached */ } Gen_RetVal = CharLen; /* ------ }}Your_Code (#MIR1) END ------ */ /* Return the function's return value. */ return Gen_RetVal; } /* }}FUNCTION (#6GC9PIDV) */ /* {{FUNCTION(1cda81cd-ce19-11d0-8874-00a0c9255cf3) (MergeSection) */ /**************************************************************** ** ** Function name: ** ** StringDup ** ** Description: ** ** Special Comments: ** ** Entrypoint for the SQL routine StringDup (integer,lvarchar) returns lvarchar. ** ** Parameters: ** ** Return value: ** ** mi_lvarchar ** ** History: ** ** 06/30/1998 - Generated by BladeSmith Version 3.60.630 . ** ** Identification: ** ** NOTE: ** ** BladeSmith will add and remove parameters from the function ** prototype, and will generate tracing calls. ONLY EDIT code ** in blocks marked Your_
. Any other modifications ** will require manual merging. ** ***************************************************************** */ UDREXPORT mi_lvarchar *StringDup ( mi_integer Number, mi_lvarchar * Char, MI_FPARAM * Gen_fparam /* Standard info - see DBDK docs.*/ ) { mi_lvarchar* Gen_RetVal; /* The return value. */ MI_CONNECTION * Gen_Con; /* The connection handle. */ /* ------ {{Your_Declarations (PreserveSection) BEGIN ------ */ /* ------ }}Your_Declarations (#0000) END ------ */ /* Use the NULL connection. */ Gen_Con = NULL; /* ------ {{Your_Code (PreserveSection) BEGIN ------ */ /* ** Write to the trace file indicating ** that StringDup has been called. */ DBDK_TRACE_ENTER( "StringDup" ); /* Validate the input parameters. */ if( Number < 0 ) { /* ** An invalid character count was requested ** so issue the following message and quit. ** ** "The character count must be greater than or equal to 0." */ DBDK_TRACE_ERROR( "StringDup", "STR02", 10 ); /* not reached */ } /* ** Allocate the return value. It must be ** allocated if it is a UDT or type whose ** size is greater than 4 bytes. */ Gen_RetVal = (mi_lvarchar *)mi_new_var( Number ); /* Verify that memory was successfully allocated. */ if( Gen_RetVal == 0 ) { /* ** Memory allocation has failed so issue ** the following message and quit. ** ** "Memory allocation has failed in StringDup." */ DBDK_TRACE_ERROR( "StringDup", ERRORMESG2, 10 ); /* not reached */ } /* ** Flood fill the return string with the character. ** If Count is 0 then an empty string is returned. */ if( Number > 0 ) { memset( mi_get_vardata( Gen_RetVal ), *mi_get_vardata( Char ), Number ); } /* ** Write to the trace file indicating ** that StringDup has successfully exited. */ DBDK_TRACE_EXIT( "StringDup" ); /* ------ }}Your_Code (#4GB3) END ------ */ /* Return the function's return value. */ return Gen_RetVal; } /* }}FUNCTION (#RPUBDHOF) */ /* {{FUNCTION(1cda81c6-ce19-11d0-8874-00a0c9255cf3) (MergeSection) */ /**************************************************************** ** ** Function name: ** ** LTrim ** ** Description: ** ** Special Comments: ** ** Entrypoint for the SQL routine LTrim (lvarchar) returns lvarchar. ** ** Parameters: ** ** Return value: ** ** mi_lvarchar ** ** History: ** ** 06/30/1998 - Generated by BladeSmith Version 3.60.630 . ** ** Identification: ** ** NOTE: ** ** BladeSmith will add and remove parameters from the function ** prototype, and will generate tracing calls. ONLY EDIT code ** in blocks marked Your_
. Any other modifications ** will require manual merging. ** ***************************************************************** */ UDREXPORT mi_lvarchar *LTrim ( mi_lvarchar * String1, MI_FPARAM * Gen_fparam /* Standard info - see DBDK docs.*/ ) { mi_lvarchar* Gen_RetVal; /* The return value. */ MI_CONNECTION * Gen_Con; /* The connection handle. */ /* ------ {{Your_Declarations (PreserveSection) BEGIN ------ */ int index; gl_mchar_t * SrcMb; mi_integer Len; /* ------ }}Your_Declarations (#0000) END ------ */ /* Use the NULL connection. */ Gen_Con = NULL; /* ------ {{Your_Code (PreserveSection) BEGIN ------ */ /* ** Write to the trace file indicating ** that LTrim has been called. */ DBDK_TRACE_ENTER( "LTrim" ); Len = mi_get_varlen( String1 ); /* Scan to the first non-blank. */ for( SrcMb = (gl_mchar_t *)mi_get_vardata( String1 ), index = ifx_gl_mbslen( SrcMb, Len ); index > 0;--index ) { /* Check for a non-blank. */ if( !ifx_gl_ismblank( SrcMb, 4 ) ) { break; } /* Advance to the next character. */ SrcMb = ifx_gl_mbsnext( SrcMb, 4 ); } /* Allocate the return value. */ Gen_RetVal = (mi_lvarchar *)mi_new_var( Len - ((char *)SrcMb - mi_get_vardata( String1 )) ); /* Verify that memory was successfully allocated. */ if( Gen_RetVal == 0 ) { /* ** Memory allocation has failed so issue ** the following message and quit. ** ** "Memory allocation has failed in LTrim." */ DBDK_TRACE_ERROR( "LTrim", ERRORMESG2, 10 ); /* not reached */ } /* Copy the right-most portion of the string. */ memcpy( mi_get_vardata( Gen_RetVal ), SrcMb, Len - ((char *)SrcMb - mi_get_vardata( String1 ) ) ); /* ** Write to the trace file indicating ** that LTrim has successfully exited. */ DBDK_TRACE_EXIT( "LTrim" ); /* ------ }}Your_Code (#QT9A) END ------ */ /* Return the function's return value. */ return Gen_RetVal; } /* }}FUNCTION (#IQU1GOP0) */ /* {{FUNCTION(1cda81c3-ce19-11d0-8874-00a0c9255cf3) (MergeSection) */ /**************************************************************** ** ** Function name: ** ** InStr ** ** Description: ** ** Special Comments: ** ** Entrypoint for the SQL routine InStr (integer,lvarchar,lvarchar) returns integer. ** ** Parameters: ** ** Return value: ** ** mi_integer ** ** History: ** ** 06/30/1998 - Generated by BladeSmith Version 3.60.630 . ** ** Identification: ** ** NOTE: ** ** BladeSmith will add and remove parameters from the function ** prototype, and will generate tracing calls. ONLY EDIT code ** in blocks marked Your_
. Any other modifications ** will require manual merging. ** ***************************************************************** */ UDREXPORT mi_integer InStr ( mi_integer StartPos, mi_lvarchar * String1, mi_lvarchar * String2, MI_FPARAM * Gen_fparam /* Standard info - see DBDK docs.*/ ) { MI_CONNECTION * Gen_Con; /* The connection handle. */ mi_integer Gen_RetVal; /* The return value. */ /* ------ {{Your_Declarations (PreserveSection) BEGIN ------ */ mi_integer StrLen1; mi_integer StrLen2; gl_mchar_t * CurPos; gl_mchar_t * EndPos; mi_integer CharPos; mi_integer index; gl_mchar_t * mbs1; gl_mchar_t * mbs2; int CharWidth; /* ------ }}Your_Declarations (#0000) END ------ */ /* Use the NULL connection. */ Gen_Con = NULL; /* ------ {{Your_Code (PreserveSection) BEGIN ------ */ Gen_RetVal = 0; /* ** Write to the trace file indicating ** that InStr has been called. */ DBDK_TRACE_ENTER( "InStr" ); /* Map Start from 1-based to 0-based. */ --StartPos; /* Validate the input values. */ if( StartPos < 0 ) { /* ** The starting position is out of range ** so issue the following message and quit. ** ** "The Starting position is invalid." */ DBDK_TRACE_ERROR( "InStr", "STR03", 10 ); /* not reached */ } /* Unravel the strings from the mi_lvarchar container. */ mbs1 = (gl_mchar_t *) mi_get_vardata( String1 ); mbs2 = (gl_mchar_t * ) mi_get_vardata( String2 ); /* Compute the length of both strings. */ StrLen1 = ifx_gl_mbslen( (gl_mchar_t *)mbs1, mi_get_varlen( String1 ) ); StrLen2 = ifx_gl_mbslen( (gl_mchar_t *)mbs2, mi_get_varlen( String2 ) ); /* Check for any GLS error that might have occurred. */ if( StrLen1 == -1 || StrLen2 == -1 ) { /* ** A GLS error has occurred so issue ** the following message and quit. ** ** "The input string contains an invalid GLS character." */ DBDK_TRACE_ERROR( "InStr", "STR04", 10 ); /* not reached */ } /* ** If the string to be searched is zero length or ** the length of the string to be search is insufficent, ** return 0. If the requested starting position is past ** the end of the string, return 0. */ if( StrLen1 == 0 || StrLen2 > StrLen1 || StartPos > StrLen1 ) { return ( 0 ); } /* ** An empty string matches the start of the string so ** if the search string is zero length, return Start. */ if( StrLen2 == 0 ) { return ( StartPos ); } /* Locate the start position in the string. */ mbs1 = (gl_mchar_t *)mi_get_vardata( String1 ); for( index = -1, CharPos = 1; ++index < StartPos-1; ) { /* Advance to the next character. */ mbs1 = ifx_gl_mbsnext( mbs1, 4 ); } CharPos += index; /* Match the first and second strings. */ for( CurPos = mbs1, EndPos = mbs1 + StrLen1; EndPos > CurPos ; ) { CharWidth = ifx_gl_mblen( CurPos, EndPos - CurPos ); if( CharWidth == 0 ) { CharWidth = 1; } else if( CharWidth < 0 ) { /* ** A GLS error has occurred so issue ** the following message and quit. ** ** "The input string contains an invalid GLS character." */ DBDK_TRACE_ERROR( "InStr", "STR04", 10 ); /* not reached */ } /* Compare for string2 inside string1. */ if ( !memcmp( (char *)CurPos, (char *)mbs2, (size_t)StrLen2 ) ) { return ( CharPos ); } CurPos += CharWidth; /* Count the characters to determine the match position. */ ++CharPos; } /* ** Write to the trace file indicating ** that InStr has successfully exited. */ DBDK_TRACE_EXIT( "InStr" ); /* ------ }}Your_Code (#KJLK) END ------ */ /* Return the function's return value. */ return Gen_RetVal; } /* }}FUNCTION (#A1MN1GA0) */ /* {{FUNCTION(1cda81c8-ce19-11d0-8874-00a0c9255cf3) (MergeSection) */ /**************************************************************** ** ** Function name: ** ** UCase ** ** Description: ** ** Special Comments: ** ** Entrypoint for the SQL routine UCase (lvarchar) returns lvarchar. ** ** Parameters: ** ** Return value: ** ** mi_lvarchar ** ** History: ** ** 06/30/1998 - Generated by BladeSmith Version 3.60.630 . ** ** Identification: ** ** NOTE: ** ** BladeSmith will add and remove parameters from the function ** prototype, and will generate tracing calls. ONLY EDIT code ** in blocks marked Your_
. Any other modifications ** will require manual merging. ** ***************************************************************** */ UDREXPORT mi_lvarchar *UCase ( mi_lvarchar * String1, MI_FPARAM * Gen_fparam /* Standard info - see DBDK docs.*/ ) { mi_lvarchar* Gen_RetVal; /* The return value. */ MI_CONNECTION * Gen_Con; /* The connection handle. */ /* ------ {{Your_Declarations (PreserveSection) BEGIN ------ */ unsigned short CharVal; gl_mchar_t * SrcMb; gl_mchar_t * DestMb; int index; mi_integer Gen_DataLen; /* ------ }}Your_Declarations (#0000) END ------ */ /* Use the NULL connection. */ Gen_Con = NULL; /* ------ {{Your_Code (PreserveSection) BEGIN ------ */ /* ** Write to the trace file indicating ** that UCase has been called. */ DBDK_TRACE_ENTER( "UCase" ); /* ** Compute the length of the resultant string. This length ** may differ from the length of the original string. */ Gen_DataLen = ifx_gl_case_conv_outbuflen( mi_get_varlen( String1 ) ); Gen_RetVal = (mi_lvarchar *)mi_new_var( Gen_DataLen ); /* Verify that memory was successfully allocated. */ if( Gen_RetVal == 0 ) { /* ** Memory allocation has failed so issue ** the following message and quit. ** ** "Memory allocation has failed in UCase." */ DBDK_TRACE_ERROR( "UCase", ERRORMESG2, 10 ); /* not reached */ } /* Clone the string converting each character to lower case. */ SrcMb = (gl_mchar_t *)mi_get_vardata( String1 ); DestMb = (gl_mchar_t *)mi_get_vardata( Gen_RetVal ); Gen_DataLen = mi_get_varlen( String1 ); for( index = ifx_gl_mbslen( (gl_mchar_t *)mi_get_vardata( String1 ), Gen_DataLen); index > 0; --index ) { CharVal = ifx_gl_tomupper( DestMb, SrcMb, 4 ); SrcMb += IFX_GL_CASE_CONV_SRC_BYTES( CharVal ); DestMb += IFX_GL_CASE_CONV_DST_BYTES( CharVal ); } /* ** Write to the trace file indicating ** that UCase has successfully exited. */ DBDK_TRACE_EXIT( "UCase" ); /* ------ }}Your_Code (#QHPA) END ------ */ /* Return the function's return value. */ return Gen_RetVal; } /* }}FUNCTION (#IUI1GNTK) */ /* {{FUNCTION(1cda81c1-ce19-11d0-8874-00a0c9255cf3) (MergeSection) */ /**************************************************************** ** ** Function name: ** ** Left ** ** Description: ** ** Special Comments: ** ** Entrypoint for the SQL routine Left (lvarchar,integer) returns lvarchar. ** ** Parameters: ** ** Return value: ** ** mi_lvarchar ** ** History: ** ** 06/30/1998 - Generated by BladeSmith Version 3.60.630 . ** ** Identification: ** ** NOTE: ** ** BladeSmith will add and remove parameters from the function ** prototype, and will generate tracing calls. ONLY EDIT code ** in blocks marked Your_
. Any other modifications ** will require manual merging. ** ***************************************************************** */ UDREXPORT mi_lvarchar *Left ( mi_lvarchar * String1, mi_integer Length, MI_FPARAM * Gen_fparam /* Standard info - see DBDK docs.*/ ) { mi_lvarchar* Gen_RetVal; /* The return value. */ MI_CONNECTION * Gen_Con; /* The connection handle. */ /* ------ {{Your_Declarations (PreserveSection) BEGIN ------ */ mi_integer ByteLen; /* Number of bytes in the string. */ gl_mchar_t * Gen_In; /* Points to the input string. */ mi_integer index; /* Index through characters. */ mi_integer CharLen; /* The number of characters in String. */ /* ------ }}Your_Declarations (#0000) END ------ */ /* Use the NULL connection. */ Gen_Con = NULL; /* ------ {{Your_Code (PreserveSection) BEGIN ------ */ /* ** Write to the trace file indicating ** that Left has been called. */ DBDK_TRACE_ENTER( "Left" ); /* Validate the input arguments. */ if( Length < 0 ) { /* ** The length is out of range ** so issue the following message and quit. ** ** "The length is invalid." */ DBDK_TRACE_ERROR( "Left", "STR05", 10 ); /* not reached */ } /* If the string is NULL, return NULL. */ if( String1 == NULL ) { mi_fp_setreturnisnull( Gen_fparam, 0, MI_TRUE ); return ( 0 ); } /* Point to the input string. */ Gen_In = (gl_mchar_t *)mi_get_vardata( String1 ); /* Compute the length of String1. */ CharLen = ifx_gl_mbslen( Gen_In, mi_get_varlen( String1 ) ); /* Check for any GLS error that might have occurred. */ if( CharLen == -1 ) { /* ** A GLS error has occurred so issue ** the following message and quit. ** ** "The input string contains an invalid GLS character." */ DBDK_TRACE_ERROR( "Mid", "STR04", 10 ); /* not reached */ } /* Truncate Length if too large. */ if( Length > CharLen ) { Length = CharLen; } /* Locate the end of the left-most characters. */ for( index = Length; index > 0; --index ) { /* Advance to the next character. */ Gen_In = ifx_gl_mbsnext( Gen_In, 4 ); } /* Determine the number of bytes in the new string. */ ByteLen = Gen_In - (gl_mchar_t *)mi_get_vardata( String1 ); /* Allocate room for the new string. */ Gen_RetVal = (mi_lvarchar *)mi_new_var( ByteLen ); /* Check for an allocation error. */ if( Gen_RetVal == 0 ) { /* ** Memory allocation has failed so issue ** the following message and quit. ** ** "Memory allocation has failed in Left." */ DBDK_TRACE_ERROR( "Left", ERRORMESG2, 10 ); /* not reached */ } /* Copy the left-most bytes to the new string. */ memcpy( mi_get_vardata( Gen_RetVal ), mi_get_vardata( String1 ), ByteLen ); /* ** Write to the trace file indicating ** that Left has successfully exited. */ DBDK_TRACE_EXIT( "Left" ); /* ------ }}Your_Code (#ALIO) END ------ */ /* Return the function's return value. */ return Gen_RetVal; } /* }}FUNCTION (#FDPSCKCS) */ /* {{FUNCTION(1cda81c4-ce19-11d0-8874-00a0c9255cf3) (MergeSection) */ /**************************************************************** ** ** Function name: ** ** StrCat ** ** Description: ** ** Special Comments: ** ** Entrypoint for the SQL routine StrCat (lvarchar,lvarchar) returns lvarchar. ** ** Parameters: ** ** Return value: ** ** mi_lvarchar ** ** History: ** ** 06/30/1998 - Generated by BladeSmith Version 3.60.630 . ** ** Identification: ** ** NOTE: ** ** BladeSmith will add and remove parameters from the function ** prototype, and will generate tracing calls. ONLY EDIT code ** in blocks marked Your_
. Any other modifications ** will require manual merging. ** ***************************************************************** */ UDREXPORT mi_lvarchar *StrCat ( mi_lvarchar * String1, mi_lvarchar * String2, MI_FPARAM * Gen_fparam /* Standard info - see DBDK docs.*/ ) { mi_lvarchar* Gen_RetVal; /* The return value. */ MI_CONNECTION * Gen_Con; /* The connection handle. */ /* ------ {{Your_Declarations (PreserveSection) BEGIN ------ */ mi_integer Len1; /* The length of String1. */ mi_integer Len2; /* The length of String2. */ /* ------ }}Your_Declarations (#0000) END ------ */ /* Use the NULL connection. */ Gen_Con = NULL; /* ------ {{Your_Code (PreserveSection) BEGIN ------ */ /* ** Write to the trace file indicating ** that StrCat has been called. */ DBDK_TRACE_ENTER( "StrCat" ); /* Validate the input strings. */ if( String1 == NULL || String2 == NULL ) { mi_fp_setreturnisnull( Gen_fparam, 0, MI_TRUE ); return ( 0 ); } /* Compute the length of both strings. */ Len1 = mi_get_varlen( String1 ); Len2 = mi_get_varlen( String2 ); /* Allocate the return value. */ Gen_RetVal = (mi_lvarchar *)mi_new_var( Len1 + Len2 ); /* Verify that memory was successfully allocated. */ if( Gen_RetVal == 0 ) { /* ** Memory allocation has failed so issue ** the following message and quit. ** ** "Memory allocation has failed in StrCat." */ DBDK_TRACE_ERROR( "StrCat", ERRORMESG2, 10 ); /* not reached */ } /* Build the concatenated string. */ memcpy( mi_get_vardata( Gen_RetVal ), mi_get_vardata( String1 ), Len1 ); memcpy( mi_get_vardata( Gen_RetVal ) + Len1, mi_get_vardata( String2 ), Len2 ); /* ** Write to the trace file indicating ** that StrCat has successfully exited. */ DBDK_TRACE_EXIT( "StrCat" ); /* ------ }}Your_Code (#68RM) END ------ */ /* Return the function's return value. */ return Gen_RetVal; } /* }}FUNCTION (#DD2OF9G9) */ #ifdef __cplusplus } #endif