示例#1
0
NITFPROT(NITF_BOOL) nitf_PluginRegistry_unload(nitf_PluginRegistry * reg,
        nitf_Error * error)
{

    /*  Pop the front off, until the list is empty  */
    nitf_List* l = reg->dsos;
    NITF_BOOL success = NITF_SUCCESS;
    while ( ! nitf_List_isEmpty(l) )
    {
        nitf_DLL* dso = (nitf_DLL*)nitf_List_popFront(l);
        success &= unloadDSO(dso, error);
    }
    return success;

}
示例#2
0
int main(int argc, char **argv)
{
    /*  Get the error object       */
    nitf_Error     error;

    /*  This is the reader object  */
    nitf_Reader* reader;
    nitf_Record* record;

    /*  The IO handle  */
    nitf_IOHandle io;
    int num;

    /*  Check argv and make sure we are happy  */
    if ( argc != 2 )
    {
        printf("Usage: %s <nitf-file>\n", argv[0]);
        exit(EXIT_FAILURE);
    }

    io = nitf_IOHandle_create(argv[1], NITF_ACCESS_READONLY, NITF_OPEN_EXISTING, &error);
    if ( NITF_INVALID_HANDLE( io ) )
    {
        nitf_Error_print(&error, stdout, "Exiting...");
        exit( EXIT_FAILURE );
    }

    reader = nitf_Reader_construct(&error);
    if (!reader)
    {
        nitf_Error_print(&error, stdout, "Exiting (1) ...");
        exit( EXIT_FAILURE );
    }

    /*    record = nitf_Record_construct(&error);
    if (!record)
    {
    nitf_Error_print(&error, stdout, "Exiting (2) ...");
    nitf_Reader_destruct(&reader);
    exit( EXIT_FAILURE );
    }*/


#if NITF_VERBOSE_READER
    printf("Here are the loaded handlers\n");
    printf("* * * * * * * * * * * * * * * *\n");
    nitf_HashTable_print(reader->reg->treHandlers);
    printf("* * * * * * * * * * * * * * * *\n");
#endif

    if ( ! (record = nitf_Reader_read(reader, io, &error  )) )
    {
        nitf_Error_print(&error, stdout, "Exiting ...");
        exit(EXIT_FAILURE);
    }

    printf("User defined: in file header\n");
    showExtSection(record->header->userDefinedSection);
    printf("Extended defined: in file header\n");
    showExtSection(record->header->extendedSection);



    if (!nitf_Field_get(record->header->numImages,
                        &num,
                        NITF_CONV_INT,
                        NITF_INT32_SZ,
                        &error))
        nitf_Error_print(&error, stdout, "Skipping b/c Invalid numImages");
    /* And now show the image information */
    else if (num > 0)
    {

        /*  Walk each image and show  */
        nitf_ListIterator iter = nitf_List_begin(record->images);
        nitf_ListIterator end  = nitf_List_end(record->images);

        while ( nitf_ListIterator_notEqualTo(&iter, &end) )
        {
            nitf_ImageSegment* segment =
                (nitf_ImageSegment*)nitf_ListIterator_get(&iter);

            printf("User defined: in image segment\n");
            showExtSection(segment->subheader->userDefinedSection);
            printf("Extended defined: in image segment\n");
            showExtSection(segment->subheader->extendedSection);


            nitf_ListIterator_increment(&iter);

        }
    }
    else
    {
        printf("No image in file!\n");
    }




    nitf_IOHandle_close(io);
    nitf_Record_destruct(&record);

    if ( !nitf_List_isEmpty(reader->warningList))
    {
        /*  Iterator to a list  */
        nitf_ListIterator it;

        /*  Iterator to the end of list  */
        nitf_ListIterator endList;

        it      = nitf_List_begin(reader->warningList);

        /*  End of list pointer  */
        endList = nitf_List_end(reader->warningList);

        printf("WARNINGS: ");
        printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");

        /*  While we are not at the end  */
        while ( nitf_ListIterator_notEqualTo( &it, &endList ) )
        {
            /*  Get the last data  */
            char* p = (char*)nitf_ListIterator_get(&it);
            /*  Make sure  */
            assert(p != NULL);

            /*  Show the data  */
            printf("\tFound problem: [%s]\n\n", p);

            /*  Increment the list iterator  */
            nitf_ListIterator_increment(&it);
        }
        printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
    }

    nitf_Reader_destruct(&reader);

    return 0;
}
示例#3
0
文件: TRECursor.c 项目: mdaus/nitro
NITFPRIV(int) nitf_TRECursor_evaluatePostfix(nitf_TRE *tre,
                                             char idx[10][10],
                                             int looping,
                                             char *expression,
                                             nitf_Error *error)
{
    nitf_List *parts = NULL;
    nitf_IntStack *stack = NULL;
    int expressionValue;

    /* create the postfix stack */
    stack = nitf_IntStack_construct(error);
    if (!stack)
        goto CATCH_ERROR;

    /* split the expression by spaces */
    parts = nitf_Utils_splitString(expression, 0, error);
    if (!parts)
        goto CATCH_ERROR;

    while(!nitf_List_isEmpty(parts))
    {
        char* expr = (char*) nitf_List_popFront(parts);
        if (strlen(expr) == 1 &&
                (expr[0] == '+' || expr[0] == '-' || expr[0] == '*' ||
                        expr[0] == '/' || expr[0] == '%'))
        {
            int op1, op2, stackSize;
            stackSize = nitf_IntStack_depth(stack, error) + 1;

            if (stackSize == 0)
            {
                /* error for postfix... */
                nitf_Error_init(error,
                        "nitf_TRECursor_evaluatePostfix: invalid expression",
                        NITF_CTXT, NITF_ERR_INVALID_PARAMETER);
                goto CATCH_ERROR;
            }

            op2 = nitf_IntStack_pop(stack, error);
            if (stackSize == 1)
                op1 = 0; /* assume 0 for the first operand of a unary op */
            else
                op1 = nitf_IntStack_pop(stack, error);

            switch(expr[0])
            {
            case '+':
                nitf_IntStack_push(stack, (op1 + op2), error);
                break;
            case '-':
                nitf_IntStack_push(stack, (op1 - op2), error);
                break;
            case '*':
                nitf_IntStack_push(stack, (op1 * op2), error);
                break;
            case '/':
                /* check for divide by zero */
                if (op2 == 0)
                {
                    nitf_Error_init(error,
                            "nitf_TRECursor_evaluatePostfix: attempt to divide by zero",
                            NITF_CTXT, NITF_ERR_INVALID_PARAMETER);
                    goto CATCH_ERROR;
                }
                nitf_IntStack_push(stack, (op1 / op2), error);
                break;
            case '%':
                nitf_IntStack_push(stack, (op1 % op2), error);
                break;
            }
        }
        else
        {
            /* evaluate as an integer and push onto the stack */
            if (nitf_Utils_isNumeric(expr))
            {
                nitf_IntStack_push(stack, NITF_ATO32(expr), error);
            }
            else
            {
                /* must be a dependent field */
                int intVal;
                nitf_Field *field = NULL;
                nitf_Pair *pair = nitf_TRECursor_getTREPair(tre, expr, idx,
                        looping, error);

                if (!pair)
                {
                    nitf_Error_init(error,
                            "nitf_TRECursor_evaluatePostfix: invalid TRE field reference",
                            NITF_CTXT, NITF_ERR_INVALID_PARAMETER);
                    goto CATCH_ERROR;
                }
                field = (nitf_Field *) pair->data;

                /* get the int value */
                if (!nitf_Field_get(field, (char*) &intVal, NITF_CONV_INT,
                         sizeof(intVal), error))
                {
                    goto CATCH_ERROR;
                }
                nitf_IntStack_push(stack, intVal, error);
            }
        }

        /* must cleanup after ourselves */
        if (expr)
            NITF_FREE(expr);
    }

    /* if all is well, the postfix stack should have one value */
    if (nitf_IntStack_depth(stack, error) != 0)
    {
        nitf_Error_init(error, "Invalid postfix expression",
                NITF_CTXT, NITF_ERR_INVALID_PARAMETER);
        goto CATCH_ERROR;
    }

    expressionValue = nitf_IntStack_pop(stack, error);

    nitf_IntStack_destruct(&stack);
    nitf_List_destruct(&parts);

    return expressionValue;

  CATCH_ERROR:
    if (stack) nitf_IntStack_destruct(&stack);
    if (parts) nitf_List_destruct(&parts);
    return -1;
}