Exemplo n.º 1
0
/*
 * Routine: ProcessSet
 * Purpose: Read distribution settings
 * Algorithm:
 * Data Structures:
 *
 * Params:
 * Returns:
 * Called By:
 * Calls:
 * Assumptions:
 * Side Effects:
 * TODO: None
 *
 * NOTE: if QERR_SYNTAX can be a valid return value, we have a problem.
 */
int
ProcessSet (char *stmt, token_t * tokens)
{
    int nRetCode = 0,
        i;
    char *cp = NULL;

    cp = SafeStrtok (NULL, " \t=");
    switch (i = FindToken (cp))
    {
    case TKN_WEIGHTS:
        cp = SafeStrtok (NULL, " \t");	/* discard = */
        pCurrentIndexEntry->w_width = ProcessInt (stmt, tokens);
        if (pCurrentIndexEntry->w_width == QERR_SYNTAX)
            nRetCode = QERR_RANGE_ERROR;
        else
        {
            if (pCurrentIndexEntry->w_width > nMaxWeightWidth)
            {
                arWeights = (int *) REALLOC (arWeights,
                                             pCurrentIndexEntry->w_width *
                                             sizeof (int));
                if (arWeights == NULL)
                    nRetCode = QERR_NO_MEMORY;
            }
            else
                nMaxWeightWidth = pCurrentIndexEntry->w_width;
        }
        pCurrentIndexEntry->dist->weight_sets =
            (int **) MALLOC (pCurrentIndexEntry->w_width * sizeof (int *));
        if (pCurrentIndexEntry->dist->weight_sets == NULL)
            nRetCode = QERR_NO_MEMORY;
        memset(pCurrentIndexEntry->dist->weight_sets, 0, pCurrentIndexEntry->w_width * sizeof(int *));
        break;
    case TKN_TYPES:
        pCurrentIndexEntry->v_width = ProcessTypes (stmt, tokens);
        if (pCurrentIndexEntry->v_width == QERR_SYNTAX)
            nRetCode = QERR_RANGE_ERROR;
        else
        {
            if (pCurrentIndexEntry->v_width > nMaxValueWidth)
            {
                arValues =
                    (char **) REALLOC (arValues,
                                       pCurrentIndexEntry->v_width *
                                       sizeof (char *));
                arValueLengths =
                    (int *) REALLOC (arValueLengths,
                                     pCurrentIndexEntry->v_width *
                                     sizeof (int));
            }
            if (arValues == NULL || arValueLengths == NULL)
                nRetCode = QERR_NO_MEMORY;
            else
            {
                for (i=nMaxValueWidth; i < pCurrentIndexEntry->v_width; i++)
                {
                    arValueLengths[i] = 0;
                    arValues[i] = NULL;
                }
                nMaxValueWidth = pCurrentIndexEntry->v_width;
            }
        }
        pCurrentIndexEntry->dist->value_sets =
            (int **) MALLOC (pCurrentIndexEntry->v_width * sizeof (int *));
        if (pCurrentIndexEntry->dist->value_sets == NULL)
            nRetCode = QERR_NO_MEMORY;
        memset(pCurrentIndexEntry->dist->value_sets, 0, pCurrentIndexEntry->v_width * sizeof(int *));
        break;
    case TKN_NAMES:
        if ((pCurrentIndexEntry->v_width <= 0) || (pCurrentIndexEntry->w_width <= 0))
            return(QERR_NAMES_EARLY);
        pCurrentIndexEntry->name_space = ProcessNames(stmt, tokens);
        break;
    default:
        nRetCode = QERR_SYNTAX;
    }

    return (nRetCode);
}
Exemplo n.º 2
0
int ProcessHeader(FILE* out, EphCtx* ctx, const char* headerFileName)
{
    int i, tmp, retVal;

    FILE* f = fopen(headerFileName, "r");
    if (!f)
    {
        fprintf(stderr, "Error:unable to open header file: %s\n",
                headerFileName);
        return ERR_FILE_OPEN;

    }

    if ((retVal = ScanNextLine(f, 2, "KSIZE= %d NCOEFF= %d",
                               &ctx->ksize, &ctx->nCoeff)))
    {
        goto exit;
    }

    /*************** GROUP 1010 *****************/
    if ((retVal = GetSpecificGroup(f, 1010)))
    {
        goto exit;
    }

    /* goofy fortran i/o: fill 3 lines of 84 chars from the file */
    for (i = 0; i < 3; ++i)
    {
        long numChars;

        if ( !fgets(gLine, sizeof(gLine), f))
        {
            retVal = ERR_EOF;
            goto exit;
        }

        numChars = strlen( gLine);

        while (iscntrl(gLine[numChars-1]))
        {
            --numChars;
        }

        memset( gLine + numChars, 0x20, 84 - numChars);
        if (84 != fwrite( gLine, 1, 84, out))
        {
            retVal = ERR_FILE_WRITE;
            goto exit;
        }
    }

    /*************** GROUP 1030 *****************/
    if ((retVal = GetSpecificGroup(f, 1030)))
    {
        goto exit;
    }

    if ((retVal = ScanNextLine(f, 3, "%lf %lf %lf",
                               ctx->ss, ctx->ss+1, ctx->ss+2)))
    {
        goto exit;
    }

    /*************** GROUP 1040 *****************/
    if ((retVal = GetSpecificGroup(f, 1040)))
    {
        goto exit;
    }

    if ((retVal = ScanNextLine(f, 1, "%d", &ctx->nCon)))
    {
        goto exit;
    }

    /* read ctx->ncon names, names 6 characters long (padded with space)
     and preceded by 2 spaces  10 names per line of 80 chars*/
    if ((retVal = ProcessNames(out, f, ctx)))
    {
        goto exit;
    }

    /*************** GROUP 1041 *****************/
    if ((retVal = GetSpecificGroup(f, 1041)))
    {
        goto exit;
    }

    if ((retVal = ScanNextLine(f, 1, "%d", &tmp)))
    {
        goto exit;
    }

    if (tmp != ctx->nCon)
    {
        retVal = ERR_FORMAT;
        goto exit;
    }
    /* go to data record 1 and write the values */
    if (0 != fseek(out, RecordSize(ctx), SEEK_SET))
    {
        retVal = ERR_FILE_SEEK;
        goto exit;
    }

    if ((retVal = WriteRecord(out, f, ctx->nCon, NULL)))
    {
        goto exit;
    }

    /*************** GROUP 1050 *****************/
    if ((retVal = GetSpecificGroup(f, 1050)))
    {
        goto exit;
    }

    if ((retVal = ProcessGroup1050(out, f)))
    {
        goto exit;
    }


    retVal = 0;

exit:

    fclose(f);
    return retVal;

}