/* ** Title: FuzzyMatch ** SCCSid: %W% %E% %U% ** CCid: %W% %E% %U% ** Author: Informix Software, Inc. ** Created: 06/11/1998 14:50 ** Description: This is the generated 'C' file for the FuzzyMatch DataBlade. ** Comments: Generated for project FuzzyMatch.3.6 */ /* ** The following is placed here to insure ** that name "mangling" does not occur. */ #ifdef __cplusplus extern "C" { #endif /* Standard library includes. */ #include #include #include #include #include /* Used by Informix GLS routines. */ #include /* Include when accessing the Informix API. */ #include /* This is the project include file. */ #include "FuzzyMatch.h" #ifndef NT_MI_SAPI #define strnicmp(a, b, len) strncasecmp(a, b, len) #endif /* {{FUNCTION(a9e91f5d-f895-11d0-8885-00a0c9255cf3) (MergeSection) */ /**************************************************************** ** ** Function name: ** ** ColorTypeInput ** ** Description: ** ** This function converts from the external representation of the ** UDT type ColorType to its internal representation. The external ** representation is a blank-separated list of values and the ** internal representation is a 'C' structure of type ColorType as ** defined in the header file. ** ** ** Data can be inserted into a table using an SQL insert statement: ** ** insert into tablename values ( 'value-list' ); ** ** value-list is a space-delimited list of values. ** ** Data for the mi_integer type is in the range [-32767, +32767]. ** Special Comments: ** ** Support routine for opaque type ColorType returns ColorType. ** ** Parameters: ** ** mi_lvarchar * Gen_param1; Pointer to the input text. ** MI_FPARAM * Gen_fparam; Standard info - see DBDK docs. ** ** Return value: ** ** ColorType * The constructed UDT value. ** ** History: ** ** 06/11/1998 - Generated by BladeSmith Version 3.60.TC1B1. ** ** Identification: ** ** Warning: Do not remove or modify this comment: ** ColorTypeInput FunctionId: a9e91f5d-f895-11d0-8885-00a0c9255cf3 ** ***************************************************************** */ ColorType * ColorTypeInput ( mi_lvarchar * Gen_param1, /* Pointer to the input text. */ MI_FPARAM * Gen_fparam /* Standard info - see DBDK docs. */ ) { MI_CONNECTION * Gen_Con; /* The current connection. */ gl_mchar_t * Gen_InData; /* Pointer to the input data. */ ColorType * Gen_OutData; /* Pointer to the output data. */ mi_integer Gen_DataLen; /* Length of the data in bytes. */ ColorType * Gen_RetVal; /* The return value. */ mi_integer ColorFd; /* Color map file descriptor. */ ColorMap_t * ColorMap; /* Color definitions from color.map. */ int ColorIndex; /* Index over colors. */ char * informixdir; /* The envr $INFORMIXDIR variable. */ char MapFile[FILENAME_MAX];/* Name of the color.map file. */ char ColorText[20]; /* The color.map color triplets. */ char iobuf[100]; /* Read color.map lines of text here. */ /* Get the current connection handle. */ Gen_Con = mi_open( NULL, NULL, NULL ); /* Verify that the connection has been established. */ if( Gen_Con == 0 ) { /* ** Opening the current connection has failed ** so issue the following message and quit. ** ** "Connection has failed in ColorTypeInput." */ DBDK_TRACE_ERROR( "ColorTypeInput", ERRORMESG1, 10 ); /* not reached */ } /* ** Write to the trace file indicating ** that ColorTypeInput has been called. */ DBDK_TRACE_ENTER( "ColorTypeInput" ); /* Allocate memory room to build the UDT in. */ Gen_RetVal = (ColorType *)mi_alloc( sizeof( ColorType ) ); if( Gen_RetVal == 0 ) { /* ** Memory allocation has failed so issue ** the following message and quit. ** ** "Memory allocation has failed in ColorTypeInput." */ DBDK_TRACE_ERROR( "ColorTypeInput", ERRORMESG2, 10 ); /* not reached */ } /* Point to the input data. */ Gen_InData = (gl_mchar_t *)mi_get_vardata( Gen_param1 ); /* Point to the output data. */ Gen_OutData = (ColorType *)Gen_RetVal; /* Get the length of the input string. */ Gen_DataLen = mi_get_varlen( Gen_param1 ); /* ** If the first character is a letter then this must be a color name. ** In this case, we'll automatically convert to a color triplet using ** the conversions stored in the color.map file. */ if( isalpha( *Gen_InData ) ) { /* Allocate storage for the color map. */ ColorMap = (ColorMap_t *)mi_dalloc( 1000 * sizeof( ColorMap_t ), PER_COMMAND ); if( ColorMap == NULL ) { /* ** Memory allocation has failed so issue ** the following message and quit. ** ** "Memory allocation has failed in ColorTypeInput." */ DBDK_TRACE_ERROR( "ColorTypeInput", ERRORMESG2, 10 ); /* not reached */ } /* Prepend to INFORMIXDIR/extend/dir to file */ informixdir = getenv("INFORMIXDIR"); /* on NT, calls NTGetEnvironment. */ if (informixdir == NULL) { #ifndef NT_MI_SAPI strcpy( MapFile, "/informix" ); #else strcpy( MapFile, "\\informix" ); #endif } else { strcpy( MapFile, informixdir ); } #ifndef NT_MI_SAPI strcat( MapFile, "/extend/FuzzyMatch.3.6/color.map" ); #else strcat( MapFile, "\\extend\\FuzzyMatch.3.6\\color.map" ); #endif /* Open the data file. */ ColorFd = mi_file_open( MapFile, MI_O_RDONLY, 0 ); /* Check for success. */ if( ColorFd != MI_ERROR ) { mi_integer BytesRead = 0; char * ptr; /* Read and store the color table. */ for( ColorIndex = 0; ; ++ColorIndex ) { /* Read a line from the color.map file into iobuf. */ for( BytesRead = 1, ptr = iobuf; BytesRead == 1; ++ptr ) { /* Read a single character and build the line. */ BytesRead = mi_file_read( ColorFd, ptr, 1 ); if( BytesRead == 0 || BytesRead == MI_ERROR ) { break; } if( *ptr == '\n' ) { *ptr = 0; break; } } if( BytesRead == 0 || BytesRead == MI_ERROR ) { break; } sscanf( iobuf, "%d %d %d %s", &ColorMap[ColorIndex].Red, &ColorMap[ColorIndex].Green, &ColorMap[ColorIndex].Blue, &ColorMap[ColorIndex].ColorName ); } /* Terminate the list. */ ColorMap[ColorIndex].Red = -1; } else { /* Error - unable to open color.map file. */ DBDK_TRACE_ERROR( "ColorTypeInput", "FZM02", 10 ); } /* Look up the color name in the color map table. */ for( ColorIndex = 0; ColorMap[ColorIndex].Red != -1; ++ColorIndex ) { /* Match the color names. */ if( !strnicmp( ColorMap[ColorIndex].ColorName, (const char*)Gen_InData, Gen_DataLen ) ) { sprintf( ColorText, "%d %d %d", ColorMap[ColorIndex].Red, ColorMap[ColorIndex].Green, ColorMap[ColorIndex].Blue ); /* Redirect the input pointer. */ Gen_InData = (gl_mchar_t *) ColorText; /* Recompute the data string's length. */ Gen_DataLen = strlen( ColorText ); break; } } /* Was the color name located in color.map? */ if( ColorMap[ColorIndex].Red == -1 ) { /* Error - color name not found. */ DBDK_TRACE_ERROR( "ColorTypeInput", "FZM01", 10 ); } /* Close the open color map file. */ mi_file_close( ColorFd ); } /* Get the data value for Gen_OutData->Red. */ Gen_InData = Gen_sscanf( Gen_Con, "ColorTypeInput", Gen_InData, Gen_DataLen, 0, "%d %n", (char *)&Gen_OutData->Red ); /* Get the data value for Gen_OutData->Green. */ Gen_InData = Gen_sscanf( Gen_Con, "ColorTypeInput", Gen_InData, Gen_DataLen, 0, "%d %n", (char *)&Gen_OutData->Green ); /* Get the data value for Gen_OutData->Blue. */ Gen_InData = Gen_sscanf( Gen_Con, "ColorTypeInput", Gen_InData, Gen_DataLen, 0, "%d %n", (char *)&Gen_OutData->Blue ); /* ** Write to the trace file indicating ** that ColorTypeInput has successfully exited. */ DBDK_TRACE_EXIT( "ColorTypeInput" ); /* Close the connection. */ mi_close( Gen_Con ); /* Return the UDT value. */ return Gen_RetVal; } /* }}FUNCTION (#9H5NUTNN) */ /* {{FUNCTION(a9e91f5e-f895-11d0-8885-00a0c9255cf3) (MergeSection) */ /**************************************************************** ** ** Function name: ** ** ColorTypeOutput ** ** Description: ** ** This function converts from the internal representation of the ** UDT type ColorType to its external representation. The external ** representation is a blank-separated list of values and the ** internal representation is a 'C' structure of type ColorType as ** defined in the header file. ** ** Data can be retrieved from a table using an SQL select statement: ** ** select * from tablename; ** ** Data for the mi_integer type is in the range [-32767, +32767]. ** Special Comments: ** ** Support routine for opaque type ColorType returns mi_lvarchar. ** ** Parameters: ** ** ColorType * Gen_param1; Pointer to the input text. ** MI_FPARAM * Gen_fparam; Standard info - see DBDK docs. ** ** Return value: ** ** mi_lvarchar * The constructed UDT value. ** ** History: ** ** 06/11/1998 - Generated by BladeSmith Version 3.60.TC1B1. ** ** Identification: ** ** Warning: Do not remove or modify this comment: ** ColorTypeOutput FunctionId: a9e91f5e-f895-11d0-8885-00a0c9255cf3 ** ***************************************************************** */ mi_lvarchar * ColorTypeOutput ( ColorType * Gen_param1, /* The UDT value. */ MI_FPARAM * Gen_fparam /* Standard info - see DBDK docs. */ ) { MI_CONNECTION * Gen_Con; /* The current connection. */ mi_integer Gen_CharLen; /* Estimate maximum length. */ ColorType * Gen_InData; /* Pointer to the input data. */ char * Gen_OutData; /* Pointer to the output data. */ mi_lvarchar * Gen_RetVal; /* The return result. */ mi_integer Gen_DataLen; /* The data length. */ /* Get the current connection handle. */ Gen_Con = mi_open( NULL, NULL, NULL ); /* Verify that the connection has been established. */ if( Gen_Con == 0 ) { /* ** Opening the current connection has failed ** so issue the following message and quit. ** ** "Connection has failed in ColorTypeOutput." */ DBDK_TRACE_ERROR( "ColorTypeOutput", ERRORMESG1, 10 ); /* not reached */ } /* Point to the input data. */ Gen_InData = Gen_param1; /* Compute the maximum length of the text representation. */ Gen_CharLen = 1 /* Leave room for the NULL terminator. */ + 12 /* Add the length for Red. */ + 12 /* Add the length for Green. */ + 12 /* Add the length for Blue. */ ; /* Allocate room for the output string. */ Gen_RetVal = mi_new_var( Gen_CharLen ); if( Gen_RetVal == 0 ) { /* ** Memory allocation has failed so issue ** the following message and quit. ** ** "Memory allocation has failed in ColorTypeOutput." */ DBDK_TRACE_ERROR( "ColorTypeOutput", ERRORMESG2, 10 ); /* not reached */ } /* Point to the output data. */ Gen_OutData = mi_get_vardata( Gen_RetVal ); /* Format the attribute value into the output string. */ /* Format the mi_integer value for Gen_InData->Red. */ sprintf( Gen_OutData, "%d ", Gen_InData->Red ); Gen_OutData += strlen( Gen_OutData ); /* Format the mi_integer value for Gen_InData->Green. */ sprintf( Gen_OutData, "%d ", Gen_InData->Green ); Gen_OutData += strlen( Gen_OutData ); /* Format the mi_integer value for Gen_InData->Blue. */ sprintf( Gen_OutData, "%d", Gen_InData->Blue ); Gen_OutData += strlen( Gen_OutData ); /* ** Compute the length of the data and ** place it in the return structure. */ Gen_DataLen = (mi_integer)(Gen_OutData - mi_get_vardata( Gen_RetVal )); mi_set_varlen ( Gen_RetVal, Gen_DataLen ); /* Close the connection. */ mi_close( Gen_Con ); /* Return the UDT value. */ return Gen_RetVal; } /* }}FUNCTION (#M7CD4406) */ #ifdef __cplusplus } #endif