slang-users mailing list

[2007 Date Index] [2007 Thread Index] [Other years]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]

[slang-users] John, Please verify ....


If I am doing this correctly. The routine is designed to get Multi values
from a attribute in the AppGen Data File and create an array item of them.

As Always .. thanks ........

----------------------------------------------------------------------------

-
Ben Duncan - Business Network Solutions, Inc. 336 Elton Road Jackson MS, 39212
"Never attribute to malice, that which can be adequately explained by stupidity"
       - Hanlon's Razor
/*
 **********************************************************************
 * This routine is designed to extract all of a multi value attribute *
 * and put them in a S-lang Array type. Appgen will give us the count *
 * of the Multi values in a particular attribute, so we know that     *
 * before hand.                                                       *
 **********************************************************************
*/
static void apgn_extrall ( )
{

  APGN_Type *dp ;
  SLang_MMT_Type *mmt ;
  SLang_Array_Type *array_type  ;

  int MV_CNT = 0 ;
  int idx = 0 ;
  int atrib_num = 0 ;
  char *attribute ;
  char **atrib_list ;
  /*
   ********************************************************************
   * Ourt attribute list starts OUT with a value of 512 for number of *
   * pointers. We will increase it by 1024 each time as the needs     *
   * arise.                                                           *
   ********************************************************************
  */
  unsigned int num_atribs = 0 ;

  unsigned int ArgCnt  = SLang_Num_Function_Args ;
  if (ArgCnt != 1 )
     {
    SLang_verror (SL_Usage_Error, "Usage: agextrall ( file,  attribute number ) " ) ;
    return ;
     }

  if ( SLang_pop_integer ( &atrib_num  ) != 0 )
    {
     SLang_verror (SL_INVALID_PARM, "\n Invalid atribute NUMBER on agextrall!\n ");
     return  ;
    }

  if (NULL == (mmt = SLang_pop_mmt (APGN_Type_Id)))
     return;
  dp = SLang_object_from_mmt (mmt);

  AppGen_Status = check_appgen_open ( dp );
  if ( AppGen_Status == -1 )
     {
       SLang_free_mmt (mmt);
       return ;
     }

  /*
   ********************************************************************
   * This GIVES us the number of attributes in our MV list BEFORE     *
   * WE have to do anything with it. If our value is less than 1 (one)*
   * we have zero ( 0 ) attributes, or if it is a -1 is a invalid     *
   * exsisting attribute, so ignore them                              *
   ********************************************************************
  */
  MV_CNT = db_stat( dp->di_apgn, Attribute, -1 ) ;
  if ( MV_CNT < 1  )
    {
       SLang_free_mmt (mmt);
       (void) SLang_push_null();
       return ;
    }

  atrib_list = (char **) SLmalloc (sizeof (char *) * MV_CNT );
  if (atrib_list == NULL)
      {
    SLang_verror (SL_MALLOC_ERROR, "Cannot get Memory for MV atrib list !! " ) ;
        SLang_free_mmt (mmt);
        SLang_push_null ();
        return;
      }

  /* Always reset the atr looping information */
  dp->Attribute = atrib_num ;
  dp->MV_CNT = 0 ;
  dp->Sub_Val = 0 ;

  /*
   ********************************************************************
   * Appgen's str_extract returns the correct atribute and returns    *
   * a pointer to a MALLOC'd buffer that that string item is in.      *
   * In Appgen, MV number 0 is the whole attribute, since we are      *
   * TRYING to parse out the individual items, we will have to be 1   *
   * ahead of our idx count here ...                                  *
   ********************************************************************
  */
  for (idx = 0 ; idx < MV_CNT ; idx++ )
    {
       Buffer = str_extract ( dp->di_apgn, Attribute, ( idx + 1 ) );
       atrib_list [idx] = SLmake_string ( (char *)Buffer ) ;
       free ( Buffer );
       /* SAVE our count in case we BLOW up !! */
       num_atribs = idx ;               
       if ( atrib_list [idx] == NULL  )
         {
           /*
            *******************************************************
            * Gosh I HATE goto's,  I really do !!! But there is   *
            * NO real easy way round this at this point !!!       *
            *******************************************************
           */
       SLang_verror (SL_MALLOC_ERROR, "Cannot make string from Attribute!! " ) ;
           goto attribute_error ;
         }

    }

    if (NULL == (at = SLang_create_array (SLANG_STRING_TYPE, 0, (VOID_STAR) atrib_list, &MV_CNT, 1)))
         {
       SLang_verror (SL_MALLOC_ERROR, "Cannot Create ARRAY for Attributes!! " ) ;
           goto attribute_error ;
         }

     if (-1 == SLang_push_array (at, 1))
         {
       SLang_verror (SL_INTRIN_ERROR, "Cannot Push  Attribute Array on Stack !! " ) ;
           goto attribute_error ;
         }


   return;

attribute_error:
  /*
   ********************************************************************
   * we will first free each of the strings we have created, then we  *
   * will FREE the keeper of the string list itself.                  *
   ********************************************************************
  */
  while (num_atribs > 0)
   {
     num_atribs--;
     SLfree (atrib_list[num_atribs]);
     }

  SLang_push_null ();
  return;

}






[2007 date index] [2007 thread index]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]