slang-users mailing list

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

[slang-users] USIng the LIST inside of C ...


I would like to USE the LIST functions:
such as :

 list = { "hello", 7, 3.14, {&sin, &cos}}

  then

 list_insert (list, 0, "hi");
 list_append (list, 0, "there");
 list_insert (list, -1, "before");
 list_append (list, -1, "after");

inside of my C SLAG programs, then return the created LIST
back to the S-Lang program.

Any Pointers on how to go about doing this ?

Here is a snippet of code of my doing this with python :

static PyObject *apgn_extrall ( apgnobject * dp, PyObject * args )
{
  PyObject *list;
  PyObject *attr_string;
  char message[256];
  char *Buffer;
  char END_TEXT [] = { 0xff, '\0' } ;
  int Attribute = 0;
  int idx = 0;
  int status = 0;
  int MV_CNT = 0;
  int SubVal = 0;

  if ( !PyArg_ParseTuple ( args, "i:extrall", &Attribute ) )
    return NULL;
  check_apgnobject_open ( dp );

  if ( dp->rec_key == NULL )
    {
      sprintf ( message, "No Record has been read! " );
      PyErr_SetString ( ApgnError, message );
      return NULL;
    }

  if ( Attribute < 1 )
    {
      sprintf ( message, "Invalid Attribute Requested! " );
      PyErr_SetString ( ApgnError, message );
      return NULL;
    }

  /* Create and Allocate a Managed Python List */
  list = PyList_New ( 0 );
  if ( list == NULL )
    {
      Py_DECREF ( list );
      sprintf ( message, "CANNOT Allocate appgen LIST in extrall! " );
      PyErr_SetString ( ApgnError, message );
      return NULL;
    }

  /* Check OUR attribute status for number of Multi values */
  MV_CNT = db_stat( dp->di_apgn, Attribute, -1 ) ;
  if ( MV_CNT == -1 )
    {
     return list ;
    }

  if ( MV_CNT == 0 )
    {
     return list ;
    }

  /*
     Go thru Extracting EACH attribute from a  Multi value
     Append each of the STRINGS return to the end of the list
  */
  for (idx = 1 ; idx <= MV_CNT ; idx++ )
    {
       Buffer = str_extract ( dp->di_apgn, Attribute, idx );
       attr_string = PyString_FromString ( Buffer );
       free ( Buffer );

       status = PyList_Append ( list, attr_string );
       Py_DECREF ( attr_string );

       if ( status != 0 )
        {
          sprintf ( message, "Invalid MV BUFFER APPEND ! " );
          PyErr_SetString ( ApgnError, message );
          Py_DECREF ( list );
          return NULL;

        }
    }

  /* Return the list back to the Python program */
  return list;

}


.. 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



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