Example #1
0
rc_t CC Args_parse_inf_file( Args * args, const char * file_option )
{
    uint32_t count;
    rc_t rc = ArgsOptionCount( args, file_option, &count );
    if ( rc != 0 )
        LOGERR( klogInt, rc, "ArgsOptionCount() failed" );
    else if ( count > 0 )
    {
        uint32_t count2 = 0;
        do
        {
            uint32_t idx;
            for ( idx = count2; idx < count && rc == 0; ++idx )
            {
                const char *filename;
                rc = ArgsOptionValue( args, file_option, idx, (const void **)&filename );
                if ( rc != 0 )
                    LOGERR( klogInt, rc, "ArgsOptionValue() failed" );
                else if ( filename != NULL )
                {
                    int argc;
                    char ** argv;
                    rc = Args_tokenize_file_into_argv( filename, &argc, &argv );
                    if ( rc == 0 && argv != NULL && argc > 0 )
                    {
                        rc = ArgsParse ( args, argc, argv );
                        Args_free_token_argv( argc, argv );
                    }
                }
            }
            count2 = count;
            rc = ArgsOptionCount( args, file_option, &count );
            if ( rc != 0 )
                LOGERR( klogInt, rc, "ArgsOptionCount() failed" );
        } while ( rc == 0 && count > count2 );
    }
    return rc;
}
Example #2
0
rc_t CC KMain ( int argc, char *argv[] )
{
    rc_t rc = 0;
    Args * args;

    rc = ArgsMakeStandardOptions (&args);
    if (rc == 0)
    {
        do
        {
            uint32_t pcount;

            rc = ArgsAddOptionArray (args, MyOptions, sizeof MyOptions / sizeof (OptDef));
            if (rc)
                break;

            rc = ArgsParse (args, argc, argv);
            if (rc)
                break;

            /* quirky way default path is generated means this comes
             * before standard argument handling */
            rc = ArgsOptionCount (args, OPTION_TABLE, &pcount);
            if (rc)
                break;

            if (pcount == 0)
            {
                static char * default_name = "RowWriteTestOutTable";
                char * user;

                user = getenv ("USER");

                if (user)
                    snprintf (tablePath, sizeof (tablePath),
                              "/home/%s/%s", user, default_name);
                else
                    strncpy (tablePath, default_name, sizeof (tablePath));
            }
            else
            {
                const char * pc;

                ArgsOptionValue (args, OPTION_TABLE, 0, &pc);
                strncpy (tablePath, pc, sizeof (tablePath));
            }

            rc = ArgsHandleStandardOptions (args);
            if (rc)
                break;

            rc = ArgsParamCount (args, &pcount);
            if (rc)
                break;
            
            if (pcount)
            {
                const char * pc;

                rc = ArgsArgvValue (args, 0, &pc);
                if (rc)
                    break;

                rc = RC (rcExe, rcNoTarg, rcParsing, rcParam, rcExcessive);
              
                PLOGERR (klogFatal, (klogFatal, rc, "$(P) takes no parameters", PLOG_S(P), pc));
                break;
            }

            rc = ArgsOptionCount (args, OPTION_ROW, &pcount);
            if (rc == 0)
            {
                uint64_t row_count;

                if (pcount)
                {
                    const char * pc;

                    rc = ArgsOptionValue (args, OPTION_ROW, 0, &pc);
                    if (rc)
                        break;

                    row_count = AsciiToU32 (pc, NULL, NULL);
                }
                else
                    row_count = ROWS;

                rc = run (tablePath, row_count);
            }
        } while (0);

        ArgsWhack (args);
    }
    return rc;
}