NODE *memberp_help(NODE *args, BOOLEAN notp, BOOLEAN substr) {
    NODE *obj1, *obj2, *val;
    int leng;
    int caseig = varTrue(Caseignoredp);

    val = FalseName();
    obj1 = car(args);
    obj2 = cadr(args);
    if (is_list(obj2)) {
	if (substr) return FalseName();
	while (obj2 != NIL && NOT_THROWING) {
	    if (equalp_help(obj1, car(obj2), caseig))
		return (notp ? obj2 : TrueName());
	    obj2 = cdr(obj2);
	    if (check_throwing) break;
	}
	return (notp ? NIL : FalseName());
    }
    else if (nodetype(obj2) == ARRAY) {
	int len = getarrdim(obj2);
	NODE **data = getarrptr(obj2);

	if (notp)
	    err_logo(BAD_DATA_UNREC,obj2);
	if (substr) return FalseName();
	while (--len >= 0 && NOT_THROWING) {
	    if (equalp_help(obj1, *data++, caseig)) return TrueName();
	}
	return FalseName();
    } else {
	NODE *tmp;
	int i;

	if (aggregate(obj1)) return (notp ? Null_Word : FalseName());
	setcar (cdr(args), cnv_node_to_strnode(obj2));
	obj2 = cadr(args);
	setcar (args, cnv_node_to_strnode(obj1));
	obj1 = car(args);
	tmp = NIL;
	if (obj1 != UNBOUND && obj2 != UNBOUND &&
	    getstrlen(obj1) <= getstrlen(obj2) &&
	    (substr || (getstrlen(obj1) == 1))) {
	    leng = getstrlen(obj2) - getstrlen(obj1);
	    setcar(cdr(args),make_strnode(getstrptr(obj2), getstrhead(obj2),
					  getstrlen(obj1), nodetype(obj2),
					  strnzcpy));
	    tmp = cadr(args);
	    for (i = 0; i <= leng; i++) {
		if (equalp_help(obj1, tmp, caseig)) {
		    if (notp) {
			setstrlen(tmp,leng+getstrlen(obj1)-i);
			return tmp;
		    } else return TrueName();
		}
		setstrptr(tmp, getstrptr(tmp) + 1);
	    }
	}
	return (notp ? Null_Word : FalseName());
    }
}
예제 #2
0
파일: currency.c 프로젝트: DeegC/10d
/////////////////////////////////////////////////////////////////////////////
//
//  OPERATION: AlphaNumericUpperStrip
//
// Strip all non-alphanumerics and upper case all characters
//
/////////////////////////////////////////////////////////////////////////////
zOPER_EXPORT zLONG OPERATION
AlphaNumericUpperStrip( zLONG lEntryType,
            LPDOMAINDATA lpDomainData )
{
   zSHORT         nRC;
   zSHORT         nWChar;
   zCHAR          szWorkString[ 512 ];
   zPCHAR         pszStringToStore;
   zPLONG         lplInteger;
   zLONG          lWork;
   LPDOMAIN       lpDomain;
   zCHAR          szNullS[ 2 ];
   zLONG          lNullInteger = -2147483647 - 1;

   nRC = zDME_NOT_HANDLED;         // Default to not-handled.
   szNullS[ 0 ] = 0;

   lpDomain = (LPDOMAIN) SysGetPointerFromHandle( lpDomainData->lpViewAttribute->hDomain );

   switch ( lEntryType )
   {
      case zDME_VALIDATE_LPDATA:
      case zDME_SET_ATTRIBUTE:
         if ( lpDomainData->lpViewAttribute->cType == zTYPE_STRING )
         {
            szWorkString[ 0 ] = 0;

            // determine input data type
            switch ( lpDomainData->cType )
            {
               case zTYPE_STRING:
                  // string to string
                  pszStringToStore = (zPCHAR) lpDomainData->lpData;
                  if ( lpDomainData->lpData == 0 )
                     pszStringToStore = szWorkString;

                  break;

               case zTYPE_INTEGER:
                  // convert long to a string
                  lplInteger = (zPLONG) lpDomainData->lpData;
                  if ( *lplInteger != lNullInteger )
                     zltoa( *lplInteger, szWorkString );

                  pszStringToStore = szWorkString;
                  break;

               case zTYPE_DATETIME:
                  // convert DateTime to String
                  nRC = UfDateTimeToString( (LPDATETIME) lpDomainData->lpData,
                                            szWorkString, 18 );
                  if ( nRC == zCALL_ERROR )
                     return( nRC );

                  pszStringToStore = szWorkString;
                  break;

               default:
                  szWorkString[ 0 ] = lpDomainData->cType;
                  szWorkString[ 1 ] = 0;
                  strcat_s( szWorkString, zsizeof( szWorkString ), ", " );
                  strcat_s( szWorkString, zsizeof( szWorkString ), lpDomainData->lpViewEntity->szName );
                  // "TZDME001 - Invalid Input Data Type"
                  SendDomainError( lpDomainData->zView, lpDomain, 8, 1, 0,
                                   szWorkString,
                                   lpDomainData->lpViewAttribute->szName );
                  return( zCALL_ERROR );
            }

            // transfer all alphanumeric characters
            zPCHAR  psz;
            nWChar = 0;

            for ( psz = (zPCHAR) lpDomainData->lpData; *psz; psz++ )
            {
               if ( zisalnum( *psz ) )
               {
                  szWorkString[ nWChar++ ] = ztoupper( *psz );
               }
            }

            szWorkString[ nWChar ] = 0;

            // finally store it
            if ( lEntryType == zDME_SET_ATTRIBUTE )
            {
               nRC = StoreValueInRecord( lpDomainData->zView,
                                         lpDomainData->lpViewEntity,
                                         lpDomainData->lpViewAttribute,
                                         szWorkString, 0 );
            }
            else
               nRC = 0;
         }
         else
         {
            szWorkString[ 0 ] = lpDomainData->lpViewAttribute->cType;
            szWorkString[ 1 ] = 0;
            strcat_s( szWorkString, zsizeof( szWorkString ), ", " );
            strcat_s( szWorkString, zsizeof( szWorkString ), lpDomainData->lpViewEntity->szName );

            // "TZDME003 - Attribute Type invalid for this Domain"
            SendDomainError( lpDomainData->zView, lpDomain, 8, 3, 0,
                             szWorkString,
                             lpDomainData->lpViewAttribute->szName );
            return( zCALL_ERROR );
         }

         break;

      case zDME_GET_VARIABLE:

         if ( lpDomainData->lpViewAttribute->cType == zTYPE_STRING )
         {
            zPCHAR   lpAttrAddr;
            zCHAR    cAttrType;
            zULONG   uAttrLength;

            if ( lpDomainData->cType != zTYPE_PIC )
            {
               nRC = GetValueFromRecord( lpDomainData->zView,
                                         lpDomainData->lpViewEntity,
                                         lpDomainData->lpViewAttribute,
                                         &lpAttrAddr, &cAttrType,
                                         &uAttrLength );
               if ( nRC )
                  return( zCALL_ERROR );
            }

            // determine input data type
            switch ( lpDomainData->cType )
            {
               case zTYPE_STRING:
                  if ( (zPCHAR) lpAttrAddr == 0 ) //null string
                  {
                     *((zPCHAR) lpDomainData->lpData) = 0;
                     nRC = -1;   // indicate attribute is null
                  }
                  else
                  {
                     *((zPCHAR) lpDomainData->lpData ) = 0;
                     zstrncat( (zPCHAR) lpDomainData->lpData,
                               (zPCHAR) lpAttrAddr,
                               lpDomainData->uMaxStringLength );
                     nRC = 0;
                  }

                  break;

               case zTYPE_INTEGER:
                  // convert string to long
                  if ( (zPCHAR) lpAttrAddr == 0 ) //null string
                  {
                     *((zPLONG) lpDomainData->lpData) = 0;
                     nRC = -1;   // indicate attribute is null
                  }
                  else
                  {
                     strcpy_s( szWorkString, zsizeof( szWorkString ), (zPCHAR) lpAttrAddr );
                     *((zPLONG) lpDomainData->lpData) = atol( szWorkString );
                     nRC = 0;
                  }

                  break;

               case zTYPE_PIC:
                  // return the picture string for the given context
                  {
                     zLPCONTEXT   lpContext;

                     if ( GetContext( &lpContext, lpDomain,
                                      lpDomainData->pszContextName ) )
                     {
                        zPCHAR lpEditString = (zPCHAR) SysGetPointerFromHandle( lpContext->hEditString );

                        if ( lpEditString && *lpEditString )
                           strcpy_s( (zPCHAR) lpDomainData->lpData, lpDomainData->uMaxStringLength,
                                    lpEditString );
                        else
                           *((zPCHAR) lpDomainData->lpData) = 0;

                        nRC = 0;
                     }
                     else
                     {
                        // "TZDME008 - Could not find context for Domain "
                        SendDomainError( lpDomainData->zView, lpDomain, 8, 8, 0,
                                         TrueName( lpDomainData->pszContextName, zSHOW_ZKEY ),
                                         lpDomainData->lpViewAttribute->szName );
                        nRC = zCALL_ERROR;
                     }
                  }

                  break;

               default:
                  szWorkString[ 0 ] = lpDomainData->cType;
                  szWorkString[ 1 ] = 0;
                  strcat_s( szWorkString, zsizeof( szWorkString ), ", " );
                  strcat_s( szWorkString, zsizeof( szWorkString ), lpDomainData->lpViewEntity->szName );
                  // "TZDME001 - Invalid Input Data Type"
                  SendDomainError( lpDomainData->zView, lpDomain, 8, 1,
                                   0, szWorkString, lpDomainData->lpViewAttribute->szName );
                  return( zCALL_ERROR );
            }

            nRC = 0;
         }
         else
         {
            szWorkString[ 0 ] = lpDomainData->lpViewAttribute->cType;
            szWorkString[ 1 ] = 0;
            strcat_s( szWorkString, zsizeof( szWorkString ), ", " );
            strcat_s( szWorkString, zsizeof( szWorkString ), lpDomainData->lpViewEntity->szName );
            // "TZDME003 - Attribute Type invalid for this Domain"
            SendDomainError( lpDomainData->zView, lpDomain, 8, 3, 0,
                             szWorkString, lpDomainData->lpViewAttribute->szName );
            return( zCALL_ERROR );
         }

      case zDME_COMPARE_ATTRIBUTE:
         if ( lpDomainData->lpViewAttribute->cType == zTYPE_STRING )
         {
            zPCHAR   lpAttrAddr;
            zCHAR    cAttrType;
            zULONG   uAttrLength;

            nRC = GetValueFromRecord( lpDomainData->zView, lpDomainData->lpViewEntity, lpDomainData->lpViewAttribute,
                                      &lpAttrAddr, &cAttrType, &uAttrLength );
            if ( nRC )
               return( zCALL_ERROR );

            if ( lpAttrAddr == 0 )
               lpAttrAddr = szNullS;

            // determine input data type
            switch ( lpDomainData->cType )
            {
               case zTYPE_STRING:
                  if ( lpDomainData->lpViewAttribute->bCaseSens )
                     nRC = zstrcmp( lpAttrAddr, (zPCHAR) lpDomainData->lpData );
                  else
                     nRC = zstrcmpi( lpAttrAddr, (zPCHAR) lpDomainData->lpData );

                  break;

               case zTYPE_INTEGER:
                  lWork = zatol( lpAttrAddr );
                  lWork -= *((zPLONG) lpDomainData->lpData);
                  nRC = (lWork == 0) ? 0 : (lWork < 0) ? -1 : 1;
                  break;

               default:
                  szWorkString[ 0 ] = lpDomainData->cType;
                  szWorkString[ 1 ] = 0;
                  strcat_s( szWorkString, zsizeof( szWorkString ), ", " );
                  strcat_s( szWorkString, zsizeof( szWorkString ), lpDomainData->lpViewEntity->szName );
                  // "TZDME001 - Invalid Input Data Type"
                  SendDomainError( lpDomainData->zView, lpDomain, 8, 1, 0, szWorkString,
                                   lpDomainData->lpViewAttribute->szName );
                  return( zCALL_ERROR );
            }
         }
         else
         {
            szWorkString[ 0 ] = lpDomainData->lpViewAttribute->cType;
            szWorkString[ 1 ] = 0;
            strcat_s( szWorkString, zsizeof( szWorkString ), ", " );
            strcat_s( szWorkString, zsizeof( szWorkString ), lpDomainData->lpViewEntity->szName );
            // "TZDME003 - Attribute Type invalid for this Domain"
            SendDomainError( lpDomainData->zView, lpDomain, 8, 3, 0,
                             szWorkString, lpDomainData->lpViewAttribute->szName );
            return( zCALL_ERROR );
         }

         break;

      case zDME_GET_COMPARE_VALUE:
         switch ( lpDomainData->cType )
         {
            case zTYPE_STRING:
               nRC = 0;
               break;

            case zTYPE_INTEGER:
               zltoa( *((zPLONG) lpDomainData->lpData), szWorkString );
               strcpy_s( (zPCHAR) lpDomainData->lpData, lpDomainData->uMaxStringLength, szWorkString );
               nRC = 1; // indicate returning a string value
               break;

            default:
               szWorkString[ 0 ] = lpDomainData->cType;
               szWorkString[ 1 ] = 0;
               strcat_s( szWorkString, zsizeof( szWorkString ), ", " );
               strcat_s( szWorkString, zsizeof( szWorkString ), lpDomainData->lpViewEntity->szName );

               // "TZDME001 - Invalid Input Data Type"
               SendDomainError( lpDomainData->zView, lpDomain, 8, 1, 0,
                                szWorkString, lpDomainData->lpViewAttribute->szName );
               nRC = -2;
         }

         break;

      case zDME_ADD_TO_ATTRIBUTE:
      case zDME_GET_FIRST_TBL_ENT_FOR_ATTR:
      case zDME_GET_NEXT_TBL_ENT_FOR_ATTR:
      case zDME_SET_ATTRIBUTE_VALUE_NEXT:
      case zDME_SET_ATTRIBUTE_VALUE_PREV:
      default:
         // Entry not handled
         return( zDME_NOT_HANDLED );
   }

   return( nRC );

} // AlphaNumericUpperStrip