Beispiel #1
0
/*--------------------------------------------------------------------------*/
int checkPList(void* _pvCtx, int * _piAddress)
{
    int nb_param = 0, i = 0, var_type = 0;
    int m_label = 0, n_label = 0;
    int * len_label = NULL;
    char ** label_list = NULL;
    int result = 0;
    SciErr _SciErr;

    _SciErr.iErr = 0;
    _SciErr.iMsgCount = 0;

    _SciErr = getVarType(_pvCtx, _piAddress, &var_type);
    if (var_type != sci_mlist)
    {
        return 0;
    }

    _SciErr = getListItemNumber(_pvCtx, _piAddress, &nb_param);

    if (nb_param != 0)
    {
        _SciErr = getMatrixOfStringInList(_pvCtx, _piAddress, 1, &m_label, &n_label, NULL, NULL);

        len_label = (int *)MALLOC(m_label * n_label * sizeof(int));
        _SciErr = getMatrixOfStringInList(_pvCtx, _piAddress, 1, &m_label, &n_label, len_label, NULL);

        label_list = (char **)MALLOC(m_label * n_label * sizeof(char *));
        for (i = 0; i < n_label * m_label; i++)
        {
            label_list[i] = (char *)MALLOC((len_label[i] + 1) * sizeof(char));
        }
        _SciErr = getMatrixOfStringInList(_pvCtx, _piAddress, 1, &m_label, &n_label, len_label, label_list);
        if (strcmp(label_list[0], "plist") != 0)
        {
            if (len_label)
            {
                FREE(len_label);
                len_label = NULL;
            }
            freeArrayOfString(label_list, m_label * n_label);

            return 0;
        }

        if (len_label)
        {
            FREE(len_label);
            len_label = NULL;
        }
        freeArrayOfString(label_list, m_label * n_label);
    }

    result = 1;

    return result;
}
/**
 * Compare a strings to the mlist type
 * @param str an array of string
 * @param nb the strings number
 * @param mlist the mlist address
 * @return 0 if one of the strings is not the mlist type
 */
static int compareStrToMlistType(const char **str, int nb, int *mlist, void *pvApiCtx)
{
    char **mlist_type = NULL;
    int i = 0, type;
    int rows, cols;
    int *lengths = NULL;
    int cmp = 0;

    SciErr err = getVarType(pvApiCtx, mlist, &type);

    if (err.iErr || type != sci_mlist)
    {
        return 0;
    }

    err = getMatrixOfStringInList(pvApiCtx, mlist, 1, &rows, &cols, NULL, NULL);
    if (err.iErr || rows != 1 || cols <= 0)
    {
        return 0;
    }

    lengths = (int *)MALLOC(sizeof(int) * rows * cols);
    err = getMatrixOfStringInList(pvApiCtx, mlist, 1, &rows, &cols, lengths, NULL);
    if (err.iErr)
    {
        return 0;
    }

    mlist_type = (char **)MALLOC(sizeof(char *) * rows * cols);
    for (; i < rows * cols; i++)
    {
        mlist_type[i] = (char *)MALLOC(sizeof(char) * (lengths[i] + 1));
    }

    err = getMatrixOfStringInList(pvApiCtx, mlist, 1, &rows, &cols, lengths, mlist_type);
    if (err.iErr)
    {
        return 0;
    }

    for (i = 0; i < nb && !cmp; i++)
    {
        cmp = !strcmp(mlist_type[0], str[i]);
    }

    freeAllocatedMatrixOfString(rows, cols, mlist_type);
    FREE(lengths);

    if (cmp)
    {
        // useful when called by isXMLObject
        cmp = i;
    }

    return cmp;
}
Beispiel #3
0
matvar_t *GetCharVariable(int iVar, const char *name, int * parent, int item_position)
{
    char * dataAdr = NULL;
    int rank = 0, i = 0, j = 0;
    int *dims = NULL;
    matvar_t *createdVar = NULL;
    int* piLen = NULL;
    char** pstData = NULL;
    char* pstMatData = NULL;
    int * piAddr = NULL;
    int * item_addr = NULL;
    int var_type;
    int saveDim = 0; /* Used to save old dimension before restoring it */
    SciErr sciErr;

    if (parent==NULL)
    {
        sciErr = getVarAddressFromPosition(pvApiCtx, iVar, &piAddr);
        if(sciErr.iErr)
        {
            printError(&sciErr, 0);
            return NULL;
        }
        sciErr = getVarType(pvApiCtx, piAddr, &var_type);
        if(sciErr.iErr)
        {
            printError(&sciErr, 0);
            return NULL;
        }
    }
    else
    {
        sciErr = getListItemAddress(pvApiCtx, parent, item_position, &item_addr);
        if(sciErr.iErr)
        {
            printError(&sciErr, 0);
            return NULL;
        }
        sciErr = getVarType(pvApiCtx, item_addr, &var_type);
        if(sciErr.iErr)
        {
            printError(&sciErr, 0);
            return NULL;
        }
    }

    if(var_type == sci_strings) /* 2-D array */
    {
        rank = 2;
        if ((dims = (int*)MALLOC(sizeof(int) * rank)) == NULL)
        {
            Scierror(999, _("%s: No more memory.\n"), "GetCharVariable");
            return NULL;
        }

        if (parent==NULL)
        {
            // First call to retrieve dimensions
            sciErr = getMatrixOfString(pvApiCtx, piAddr, &dims[0], &dims[1], NULL, NULL);
            if(sciErr.iErr)
            {
                printError(&sciErr, 0);
                return 0;
            }
            piLen = (int *)MALLOC(dims[0] * dims[1] * sizeof(int));
            // Second call to retrieve length of each string
            sciErr = getMatrixOfString(pvApiCtx, piAddr, &dims[0], &dims[1], piLen, NULL);
            if(sciErr.iErr)
            {
                printError(&sciErr, 0);
                return 0;
            }
            pstData = (char**)MALLOC(sizeof(char*) * dims[0] * dims[1]);
            for(i = 0 ; i < dims[0] * dims[1] ; i++)
            {
                pstData[i] = (char*)MALLOC(sizeof(char) * (piLen[i] + 1)); //+ 1 for null termination
            }
            // Third call to retrieve data
            sciErr = getMatrixOfString(pvApiCtx, piAddr, &dims[0], &dims[1], piLen, pstData);
            if(sciErr.iErr)
            {
                printError(&sciErr, 0);
                return 0;
            }
            dataAdr = strdup(pstData[0]);
        }
        else
        {
            // First call to retrieve dimensions
            sciErr  = getMatrixOfStringInList(pvApiCtx, parent, item_position, &dims[0], &dims[1], NULL, NULL);
            if(sciErr.iErr)
            {
                printError(&sciErr, 0);
                return NULL;
            }
            piLen = (int *)MALLOC(dims[0] * dims[1] * sizeof(int));
            // Second call to retrieve length of each string
            sciErr = getMatrixOfStringInList(pvApiCtx, parent, item_position, &dims[0], &dims[1], piLen, NULL);
            if(sciErr.iErr)
            {
                printError(&sciErr, 0);
                return NULL;
            }
            pstData = (char**)MALLOC(sizeof(char*) * dims[0] * dims[1]);
            for(i = 0 ; i < dims[0] * dims[1] ; i++)
            {
                pstData[i] = (char*)MALLOC(sizeof(char) * (piLen[i] + 1)); //+ 1 for null termination
            }
            // Third call to retrieve data
            sciErr = getMatrixOfStringInList(pvApiCtx, parent, item_position, &dims[0], &dims[1], piLen, pstData);
            if(sciErr.iErr)
            {
                printError(&sciErr, 0);
                return NULL;
            }
            dataAdr = strdup(pstData[0]);
        }

        if (dims[0] == 0) /* Empty character string */
        {
            createdVar = Mat_VarCreate(name, MAT_C_CHAR, MAT_T_UINT8, rank, dims, pstData[0], 0);
        }
        else if (dims[0]*dims[1] == 1) /* Scalar character string */
        {
            saveDim = dims[1];
            dims[1] = piLen[0];
            createdVar = Mat_VarCreate(name, MAT_C_CHAR, MAT_T_UINT8, rank, dims, pstData[0], 0);
            dims[1] = saveDim;
        }
        else /* More than one character string -> save as a Cell */
        {
            if (dims[0] == 1)
            {
                /* TODO: Should be saved as a cell */
                Scierror(999, _("%s: Row array of strings saving is not implemented.\n"), "GetCharVariable");
                freeArrayOfString(pstData, dims[0]*dims[1]);
                FREE(dims);
                FREE(dataAdr);
                FREE(piLen);
                return NULL;
            }
            else if (dims[1] == 1)
            {
                /* Check that all strings have the same length */
                for (i = 0 ; i < dims[0] ; i++)
                {
                    if (piLen[0] != piLen[i])
                    {
                        /* TODO: Should be saved as a cell */
                        Scierror(999, _("%s: Column array of strings with different lengths saving is not implemented.\n"), "GetCharVariable");
                        freeArrayOfString(pstData, dims[0]*dims[1]);
                        FREE(dims);
                        FREE(dataAdr);
                        FREE(piLen);
                        return NULL;
                    }
                }

                /* Reorder characters */
                pstMatData = (char*)MALLOC(sizeof(char) * dims[0] * piLen[0]);
                for (i = 0 ; i < dims[0] ; i++)
                {
                    for (j = 0 ; j < piLen[0] ; j++)
                    {
                        pstMatData[i+j*dims[0]] = pstData[i][j];
                    }
                }

                /* Save the variable */
                saveDim = dims[1];
                dims[1] = piLen[0];
                createdVar = Mat_VarCreate(name, MAT_C_CHAR, MAT_T_UINT8, rank, dims, pstMatData, 0);
                dims[1] = saveDim;

                freeArrayOfString(pstData, dims[0]*dims[1]); /* FREE now because dimensions are changed just below */
                FREE(pstMatData);
                FREE(dims);
                FREE(dataAdr);
                FREE(piLen);
            }
            else
            {
                /* TODO: Should be saved as a cell */
                Scierror(999, _("%s: 2D array of strings saving is not implemented.\n"), "GetCharVariable");
                freeArrayOfString(pstData, dims[0]*dims[1]);
                FREE(dims);
                FREE(dataAdr);
                FREE(piLen);
                return NULL;
            }
        }
    }
    else
    {
        Scierror(999, _("%s: Wrong type for first input argument: String matrix expected.\n"), "GetCharVariable");
        freeArrayOfString(pstData, dims[0]*dims[1]);
        FREE(dims);
        FREE(dataAdr);
        FREE(piLen);
        return NULL;
    }

    return createdVar;
}
Beispiel #4
0
//--------------------------------------------------------------------------------------------------------
FILE * createFILEFromScilabFannErrorStruct(unsigned int StackPos, int * res)
{
  int m_param, n_param, * pi_param_addr;
  int type, * pi_len = NULL, i;
  char ** LabelList = NULL;
  FILE * log_file = NULL;
  SciErr _sciErr;

  *res = -1;

  _sciErr = getVarAddressFromPosition(pvApiCtx, StackPos, &pi_param_addr);
  if (_sciErr.iErr)
    {
      printError(&_sciErr, 0);
      return NULL;
    }
  _sciErr = getVarType(pvApiCtx, pi_param_addr, &type);
  if (_sciErr.iErr)
    {
      printError(&_sciErr, 0);
      return NULL;
    }

  if (type!=sci_mlist)
    {
      Scierror(999,"Argument %d is not a mlist\n",StackPos);
      return NULL;
    }

  _sciErr = getMatrixOfStringInList(pvApiCtx, pi_param_addr, 1, &m_param, &n_param, NULL, NULL);
  if (_sciErr.iErr)
    {
      printError(&_sciErr, 0);
      return NULL;
    }

  pi_len = (int*)MALLOC(sizeof(int) * m_param * n_param);
  _sciErr = getMatrixOfStringInList(pvApiCtx, pi_param_addr, 1, &m_param, &n_param, pi_len, NULL);
  if (_sciErr.iErr)
    {
      printError(&_sciErr, 0);
      return NULL;
    }
  
  LabelList = (char**)MALLOC(sizeof(char*) * m_param * n_param);
  for(i=0; i<m_param*n_param; i++)
    {
      LabelList[i] = (char*)MALLOC(sizeof(char) * (pi_len[i] + 1)); // + 1 for null termination
    }
  
  _sciErr = getMatrixOfStringInList(pvApiCtx, pi_param_addr, 1, &m_param, &n_param, pi_len, LabelList);
  if (_sciErr.iErr)
    {
      printError(&_sciErr, 0);
      return NULL;
    }

  if (strcmp(LabelList[0],"fannerrorlist") != 0) 
    {
      Scierror(999,"Argument 1 is not a fannerrorlist\r\n");
      return NULL;
    }

  _sciErr = getPointerInList(pvApiCtx, pi_param_addr, 2, (void **)&log_file);
  if (_sciErr.iErr)
    {
      printError(&_sciErr, 0);
      return NULL;
    }

  *res = 0;

  return log_file;
}
Beispiel #5
0
//--------------------------------------------------------------------------------------------------------
int detect_fannerrorlist(int StackPos)
{
  int m_param, n_param, * pi_param_addr;
  int type, * pi_len = NULL, i;
  char ** LabelList = NULL;
  SciErr _sciErr;

  _sciErr = getVarAddressFromPosition(pvApiCtx, StackPos, &pi_param_addr);
  if (_sciErr.iErr)
    {
      printError(&_sciErr, 0);
      return -1;
    }
  _sciErr = getVarType(pvApiCtx, pi_param_addr, &type);
  if (_sciErr.iErr)
    {
      printError(&_sciErr, 0);
      return -1;
    }

  if (type!=sci_mlist)
    {
      Scierror(999,"Argument %d is not a mlist\n",StackPos);
      return 0;
    }

  _sciErr = getMatrixOfStringInList(pvApiCtx, pi_param_addr, 1, &m_param, &n_param, NULL, NULL);
  if (_sciErr.iErr)
    {
      printError(&_sciErr, 0);
      return -1;
    }

  pi_len = (int*)MALLOC(sizeof(int) * m_param * n_param);
  _sciErr = getMatrixOfStringInList(pvApiCtx, pi_param_addr, 1, &m_param, &n_param, pi_len, NULL);
  if (_sciErr.iErr)
    {
      printError(&_sciErr, 0);
      return -1;
    }
  
  LabelList = (char**)MALLOC(sizeof(char*) * m_param * n_param);
  for(i=0; i<m_param*n_param; i++)
    {
      LabelList[i] = (char*)MALLOC(sizeof(char) * (pi_len[i] + 1)); // + 1 for null termination
    }
  
  _sciErr = getMatrixOfStringInList(pvApiCtx, pi_param_addr, 1, &m_param, &n_param, pi_len, LabelList);
  if (_sciErr.iErr)
    {
      printError(&_sciErr, 0);
      return -1;
    }

  if (strcmp(LabelList[0],"fannerrorlist") != 0) 
    {
      Scierror(999,"Argument %d is not a fannerrorlist\n",StackPos);
      return 0;
    }
  
  return 0;
}
Beispiel #6
0
int ScilabObjects::getMListType(int * mlist, void * pvApiCtx)
{
    char * mlist_type[3];
    char * mtype = 0;
    int lengths[3];
    int rows, cols;
    int type;

    SciErr err = getVarType(pvApiCtx, mlist, &type);
    if (err.iErr || type != sci_mlist)
    {
        return EXTERNAL_INVALID;
    }

    err = getMatrixOfStringInList(pvApiCtx, mlist, 1, &rows, &cols, NULL, NULL);
    if (err.iErr || rows != 1 || cols != 3)
    {
        return EXTERNAL_INVALID;
    }

    err = getMatrixOfStringInList(pvApiCtx, mlist, 1, &rows, &cols, lengths, NULL);
    if (err.iErr)
    {
        return EXTERNAL_INVALID;
    }

    for (int i = 0; i < 3; i++)
    {
        mlist_type[i] = new char[lengths[i] + 1];
    }

    err = getMatrixOfStringInList(pvApiCtx, mlist, 1, &rows, &cols, lengths, mlist_type);
    mtype = mlist_type[0];
    for (int i = 1; i < 3; i++)
    {
        delete[] mlist_type[i];
    }

    type = EXTERNAL_INVALID;

    if (err.iErr)
    {
        return EXTERNAL_INVALID;
    }

    if (!std::strcmp("_EObj", mtype))
    {
        type = EXTERNAL_OBJECT;
    }
    else if (!std::strcmp("_EClass", mtype))
    {
        type = EXTERNAL_CLASS;
    }
    else if (!std::strcmp("_EVoid", mtype))
    {
        type = EXTERNAL_VOID;
    }

    delete[] mtype;

    return type;
}
int get_string_info(void* _pvCtx, int _iRhs, int* _piParent, int *_piAddr, int _iItemPos)
{
    SciErr sciErr;
    int i;
    int iRows       = 0;
    int iCols       = 0;
    int* piLen      = NULL;
    char **pstData  = NULL;

    if (_iItemPos == 0)
    {
        //Not in list
        sciErr = getMatrixOfString(_pvCtx, _piAddr, &iRows, &iCols, NULL, NULL);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            return 0;
        }

        piLen = (int*)MALLOC(sizeof(int) * iRows * iCols);
        sciErr = getMatrixOfString(_pvCtx, _piAddr, &iRows, &iCols, piLen, NULL);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            return 0;
        }

        pstData = (char**)MALLOC(sizeof(char*) * iRows * iCols);

        for (i = 0 ; i < iRows * iCols ; i++)
        {
            pstData[i] = (char*)MALLOC(sizeof(char) * (piLen[i] + 1));//+ 1 for null termination
        }

        sciErr = getMatrixOfString(_pvCtx, _piAddr, &iRows, &iCols, piLen, pstData);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            return 0;
        }
    }
    else
    {
        sciErr = getMatrixOfStringInList(_pvCtx, _piParent, _iItemPos, &iRows, &iCols, NULL, NULL);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            return 0;
        }

        piLen = (int*)MALLOC(sizeof(int) * iRows * iCols);

        sciErr = getMatrixOfStringInList(_pvCtx, _piParent, _iItemPos, &iRows, &iCols, piLen, NULL);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            return 0;
        }

        pstData = (char**)MALLOC(sizeof(char*) * iRows * iCols);

        for (i = 0 ; i < iRows * iCols ; i++)
        {
            pstData[i] = (char*)MALLOC(sizeof(char) * (piLen[i] + 1));//+ 1 for null termination
        }

        sciErr = getMatrixOfStringInList(_pvCtx, _piParent, _iItemPos, &iRows, &iCols, piLen, pstData);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            return 0;
        }
    }
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        return 0;
    }

    for (i = 0 ; i < iRows * iCols ; i++)
    {
        FREE(pstData[i]);
    }

    FREE(pstData);
    FREE(piLen);

    insert_indent();
    sciprint("Strings (%d x %d)\n", iRows, iCols);
    return 0;;
}