示例#1
0
rc_t CC KMain(int argc, char *argv[]) {
    Args *args;
    rc_t rc; /*, orc; */

    rc = ArgsMakeAndHandle(&args, argc, argv, 0);
    if (rc == 0)
    {
        uint32_t pcount;
        rc_t orc;

        /* non standard use of --quiet */
        rc = ArgsOptionCount(args, OPTION_QUIET, &pcount);
        if (rc)
            LOGERR(klogErr, rc, "error check " OPTION_QUIET " option");

        else
            rc = run (pcount != 0);

        orc = ArgsWhack(args);
        if (rc == 0)
            rc = orc;
    }

    return rc;
}
示例#2
0
rc_t CC KMain(int argc, char* argv[])
{
    rc_t rc = 0;
    Args* args = NULL;

    CmdLine cmdArgs;

    LogLevelSet("info");

    rc = ArgsMakeAndHandle
        (&args, argc, argv, 1, Options, sizeof Options / sizeof(Options[0]));

    if (rc == 0) {
        rc = CmdLineInit(args, &cmdArgs);
    }

    if (rc == 0) {
        rc = Run(&cmdArgs);
    }

    ArgsWhack(args);

    if (rc == RC(rcVDB, rcTable, rcOpening, rcSchema, rcNotFound))
    {   exit(10); }

    return rc;
}
示例#3
0
rc_t CC KMain ( int argc, char *argv [] )
{
    Args * my_args;
    rc_t rc;

    rc = ArgsMakeAndHandle (&my_args, argc, argv, 1, 
                            Options, sizeof (Options) / sizeof (OptDef));
    if (rc == 0)
    {
        context *ctx;

        context_init( &ctx );

        rc = capture_arguments_and_options( my_args, ctx );
        if ( rc == 0 )
        {
            if ( namelistcount( ctx->src_files ) > 0 )
            {
                rc = DumpSchema( ctx );
            }
            else
            {
                MiniUsage (my_args);
            }
        }
        context_destroy( ctx );

        ArgsWhack( my_args );
    }
    return rc;
}
示例#4
0
/* KMain - EXTERN
 *  executable entrypoint "main" is implemented by
 *  an OS-specific wrapper that takes care of establishing
 *  signal handlers, logging, etc.
 *
 *  in turn, OS-specific "main" will invoke "KMain" as
 *  platform independent main entrypoint.
 *
 *  "argc" [ IN ] - the number of textual parameters in "argv"
 *  should never be < 0, but has been left as a signed int
 *  for reasons of tradition.
 *
 *  "argv" [ IN ] - array of NUL terminated strings expected
 *  to be in the shell-native character set: ASCII or UTF-8
 *  element 0 is expected to be executable identity or path.
 */
rc_t CC KMain ( int argc, char *argv [] )
{
    Args * args;
    rc_t rc;

    KStsLevelSet (1);

    rc = ArgsMakeAndHandle (&args, argc, argv, 1, Options,
                            sizeof (Options) / sizeof (Options[0]));
    if (rc)
        LOGERR (klogInt, rc, "failed to parse command line parameters");

    else
    {
        uint32_t ocount;

        rc = ArgsOptionCount (args, OPTION_DEC_SRA, &ocount);
        if (rc)
            LOGERR (klogInt, rc, "failed to examine decrypt "
                    "sra option");
        else
        {
            DecryptSraFlag = (ocount > 0);

            rc = CommonMain (args);
        }
        ArgsWhack (args);
    }

    if (rc)
        STSMSG (1, ("exiting: %R (%u)", rc, rc));
    else
        STSMSG (1, ("exiting: success"));
    return rc;
}
示例#5
0
rc_t CC KMain ( int argc, char *argv [] )
{
    Args * args;

    rc_t rc = ArgsMakeAndHandle ( &args, argc, argv, 2,
                                  MyOptions, sizeof MyOptions / sizeof ( OptDef ),
                                  XMLLogger_Args, XMLLogger_ArgsQty  );

    KLogHandlerSetStdErr();
    if ( rc != 0 )
    {
        LOGERR( klogErr, rc, "error creating internal structure" );
    }
    else
    {
        ld_context lctx;

        lctx_init( &lctx );
        rc = KDirectoryNativeDir ( &lctx.wd );
        if ( rc != 0 )
        {
            LOGERR( klogErr, rc, "error creating internal structure" );
        }
        else
        {
            rc = XMLLogger_Make( &lctx.xml_logger, lctx.wd, args );
            if ( rc != 0 )
            {
                LOGERR( klogErr, rc, "error creating internal structure" );
            }
            else
            {
                context ctx;
                rc = ctx_init( args, &ctx );
                if ( rc == 0 )
                {
                    rc = pacbio_check_sourcefile( &ctx, &lctx );
                    if ( rc == 0 )
                    {
                        lctx.with_progress = ctx.with_progress;
                        ctx_show( &ctx );
                        lctx.dst_path = ctx.dst_path;

                        rc = pacbio_load( &ctx, &lctx, false, false );
                        if ( rc == 0 )
                        {
                            rc = pacbio_meta_entry( &lctx, argv[ 0 ] );
                        }
                    }
                    ctx_free( &ctx );
                }
            }
        }
        lctx_free( &lctx );
        ArgsWhack ( args );
    }

    return rc;
}
示例#6
0
static rc_t main_help_vers(int argc, char * argv[])
{
    Args *args = NULL;
    rc_t const rc = ArgsMakeAndHandle (&args, argc, argv, 2, Options,
        sizeof Options / sizeof (OptDef), XMLLogger_Args, XMLLogger_ArgsQty);
    ArgsWhack(args);
    return rc;
}
示例#7
0
static XMLLogger const *make_logger(int *argc, char *argv[])
{
    XMLLogger const *rslt = NULL;
    char *argf[4];
    int i;

    argf[0] = argv[0];
    argf[1] = NULL;
    argf[2] = NULL;
    argf[3] = NULL;

    for (i = 1; i < *argc; ++i) {
        int remove = 0;

        if (strcmp(argv[i], logger_options[2]) == 0) {
            argf[1] = argv[i];
            argf[2] = argv[i + 1];
            remove = 2;
        }
        else {
            int j;

            for (j = 0; j < 2; ++j) {
                if (strstr(argv[i], logger_options[j]) == argv[i]) {
                    int const n = strlen(logger_options[j]);

                    if (argv[i][n] == '\0') {
                        argf[1] = argv[i];
                        argf[2] = argv[i + 1];
                        remove = 2;
                    }
                    else if (argv[i][n] == '=') {
                        argv[i][n] = '\0';
                        argf[1] = argv[i];
                        argf[2] = argv[i] + n + 1;
                        remove = 1;
                    }
                    break;
                }
            }
        }
        if (argf[1] != NULL) {
            Args *args = NULL;

            ArgsMakeAndHandle(&args, 3, argf, 1, XMLLogger_Args, XMLLogger_ArgsQty);
            if (args) {
                XMLLogger_Make(&rslt, NULL, args);
                ArgsWhack(args);
            }
        }
        if (remove) {
            *argc -= remove;
            memmove(argv + i, argv + i + remove, (*argc + 1) * sizeof(argv[0]));
            break;
        }
    }
    return rslt;
}
示例#8
0
/* KMain - EXTERN
 *  executable entrypoint "main" is implemented by
 *  an OS-specific wrapper that takes care of establishing
 *  signal handlers, logging, etc.
 *
 *  in turn, OS-specific "main" will invoke "KMain" as
 *  platform independent main entrypoint.
 *
 *  "argc" [ IN ] - the number of textual parameters in "argv"
 *  should never be < 0, but has been left as a signed int
 *  for reasons of tradition.
 *
 *  "argv" [ IN ] - array of NUL terminated strings expected
 *  to be in the shell-native character set: ASCII or UTF-8
 *  element 0 is expected to be executable identity or path.
 */
rc_t CC KMain ( int argc, char *argv [] )
{
    Args* args = NULL;
    rc_t rc;

    rc = ArgsMakeAndHandle(&args, argc, argv, 1, Options, sizeof Options / sizeof (OptDef));
    if (rc)
        LOGERR (klogInt, rc, "failed to parse command line parameters");
    if (rc == 0)
    {
        uint32_t pcount;
        bool force;

        rc = ArgsOptionCount (args, OPTION_FORCE, &pcount);
        if (rc)
            LOGERR (klogInt, rc, "failed to examine force option");
        else
        {
            force = (pcount > 0);

            rc = ArgsParamCount (args, &pcount);
            if (rc)
                LOGERR (klogInt, rc, "failed to count parameters");
            else
            {
                if (pcount != 2) {
                    MiniUsage (args);
                    rc = RC(rcApp, rcArgv, rcParsing, rcParam, rcInsufficient);
                }
                else
                {
                    const char * src;

                    rc = ArgsParamValue (args, 0, (const void **)&src);
                    if (rc)
                        LOGERR (klogInt, rc, "failed to get source parameter");
                    else
                    {
                        const char * dst;
                        rc = ArgsParamValue (args, 1, (const void **)&dst);
                        if (rc)
                            LOGERR (klogInt, rc, "failed to get destination parameter");
                        else
                        {
                            rc = nenctool (src, dst, force);
                        }
                    }
                }
            }
        }
        ArgsWhack (args);
    }
    STSMSG (1, ("exiting: %R (%u)", rc, rc));
    return rc;
}
示例#9
0
rc_t CC KMain( int argc, char * argv[] )
{
    Args * args;
    rc_t rc = ArgsMakeAndHandle ( &args, argc, argv, 1,
                             MyOptions, sizeof MyOptions / sizeof ( OptDef ) );
    if ( rc != 0 )
        LogErr( klogInt, rc, "ArgsMakeAndHandle() failed\n" );
    else
    {
        context *ctx;
        KLogHandlerSetStdErr();
        rc = context_init( &ctx );
        if ( rc != 0 )
            LogErr( klogInt, rc, "context_init() failed\n" );
        else
        {
            rc = context_capture_arguments_and_options( args, ctx );
            if ( rc != 0 )
                LogErr( klogInt, rc, "context_capture_arguments_and_options() failed\n" );
            else
            {
                if ( ctx->usage_requested )
                    MiniUsage( args );
                else
                {
                    switch( ctx->output_mode[ 0 ] )
                    {
                        case 'd' :
                        case 't' : if ( context_schema_count( ctx ) == 0 )
                                    {
                                        OUTMSG(( "cannot write, schema-file is missing:\n" ));
                                        Usage( args  );
                                        rc = RC( rcApp, rcNoTarg, rcConstructing, rcSelf, rcNull );
                                    }
                    }
                    if ( rc == 0 )
                    {
                        /* ************************* */
                        rc = gater_and_write( ctx );
                        /* ************************* */
                    }
                }
            }
            context_destroy ( ctx );
        }
        ArgsWhack ( args );
    }
    return rc;
}
示例#10
0
rc_t CC KMain (int argc, char * argv[])
{
    Args * args;
    rc_t rc;

    rc = ArgsMakeAndHandle (&args, argc, argv, 1, NULL, 0);
    if (rc)
        LOGERR (klogFatal, rc, "Could not parse command line");
    else
    {
        rc = run();
        ArgsWhack (args);
    }
    return rc;
}
示例#11
0
rc_t CC KMain ( int argc, char *argv [] )
{
    Args * args;
    rc_t rc = ArgsMakeAndHandle ( &args, argc, argv, 1,
            DumpOptions, sizeof DumpOptions / sizeof DumpOptions [ 0 ] );
    if ( rc == 0 )
    {
        uint32_t count;
        rc = ArgsParamCount( args, &count );
        if ( rc != 0 )
        {
            (void)LOGERR( klogErr, rc, "cannot detect count of program arguments" );
        }
        else
        {
            if ( count != 2 )
            {
                Usage ( args );
            }
            else
            {
                cg_dump_ctx cg_ctx;
                const char * src;

                memset( &cg_ctx, 0, sizeof cg_ctx );
                rc = ArgsParamValue( args, 0, &src );
                if ( rc != 0 )
                {
                    (void)LOGERR( klogErr, rc, "cannot detect source - argument" );
                }
                else
                {
                    rc = ArgsParamValue( args, 1, &cg_ctx.dst );
                    if ( rc != 0 )
                    {
                        (void)LOGERR( klogErr, rc, "cannot detect destination - argument" );
                    }
                    else
                    {
                        rc = cg_dump_src_dst( args, src, &cg_ctx ); /* <================== */
                    }
                }
            }
        }
        ArgsWhack ( args );
    }
    return rc;
}
示例#12
0
rc_t CC KMain ( int argc, char *argv [] )
{
    rc_t rc = 0;
    Args * args;

    rc = ArgsMakeAndHandle (&args, argc, argv, 0);
    if (rc == 0)
    {
        do
        {
            uint32_t pcount;

            rc = ArgsParamCount (args, &pcount);
            if (rc)
                break;
            
            if (pcount == 0) {
                MiniUsage(args);
                rc = RC(rcExe, rcNoTarg, rcAllocating, rcParam, rcInvalid);
            }
            else
            {
                const char * pc;
                rc_t exp;
                uint32_t ix;

                /* over rule any set log level */
                rc = KLogLevelSet (klogInfo);

                for (ix = 0; ix < pcount; ++ix)
                {
                    rc = ArgsParamValue (args, ix, (const void **)&pc);
                    if (rc)
                        break;

                    exp = AsciiToU32 (pc, NULL, NULL);
                    rc = LOGERR (klogInfo, exp, pc);
                }
            }

        } while (0);

        ArgsWhack (args);
    }
    return rc;
}
示例#13
0
文件: md5cp.c 项目: Bhumi28/sra-tools
rc_t CC KMain ( int argc, char *argv [] )
{
    Args * args;
    rc_t rc;

    rc = ArgsMakeAndHandle (&args, argc, argv, 1, 
                            Options, sizeof (Options) / sizeof (OptDef));
    if (rc == 0)
    {
        do
        {
            uint32_t pcount;

            rc = ArgsOptionCount (args, OPTION_FORCE, &pcount);
            if (rc)
                break;

            force = (pcount > 0);

            rc = ArgsOptionCount (args, OPTION_RECURSE, &pcount);
            if (rc)
                break;

            recurse = (pcount > 0);


            rc = ArgsOptionCount (args, OPTION_TEST, &pcount);
            if (rc)
                break;

            test = (pcount > 0);

            rc = ArgsOptionCount (args, OPTION_PRESERVE, &pcount);
            if (rc)
                break;

            clobber_protections = (pcount > 0);

            rc  = run (args);

        }while (0);

        ArgsWhack (args);
    }
    return rc;
}
示例#14
0
rc_t CC KMain ( int argc, char *argv [] )
{
    Args * args;

    rc_t rc = ArgsMakeAndHandle ( &args, argc, argv, 1,
                CompressOptions, sizeof ( CompressOptions ) / sizeof ( OptDef ) );
    if ( rc == 0 )
    {
/*        rc = compress_main( args ); */
        rc = copy2_main( args );

        ArgsWhack ( args );
    }
    else
        OUTMSG( ( "ArgsMakeAndHandle() failed %R\n", rc ) );

    return rc;
}
示例#15
0
rc_t CC KMain ( int argc, char *argv [] )
{
    Args * args;

    rc_t rc = ArgsMakeAndHandle ( &args, argc, argv, 0 );

    KLogHandlerSetStdErr();
    if ( rc != 0 )
    {
        LOGERR( klogErr, rc, "error creating internal structure" );
    }
    else
    {
        uint32_t count;
        rc = ArgsParamCount( args, &count );
        if ( rc != 0 )
            LOGERR( klogErr, rc, "ArgsParamCount failed" );
        else
        {
            if ( count < 1 )
            {
                rc = RC( rcExe, rcNoTarg, rcAllocating, rcParam, rcInvalid );
                LOGERR( klogErr, rc, "object(s) missing" );
                Usage ( args );
            }
            else
            {
                uint32_t idx;
                for ( idx = 0; idx < count && rc == 0; ++idx )
                {
                    const char *obj;
                    rc = ArgsParamValue( args, idx, (const void **)&obj );
                    if ( rc != 0 )
                        LOGERR( klogErr, rc, "error reading commandline-parameter" );
                    else
                        rc = correct( obj ); /* ** <<<<<<<<<<<<<<<<<< ** */
                }
            }
        }
        ArgsWhack ( args );
    }

    return rc;
}
示例#16
0
/***************************************************************************
    Main:
    * create the copy-context
    * parse the commandline for arguments and options
    * react to help/usage - requests ( no dump in this case )
      these functions are in vdb-copy-context.c
    * call copy_main() to execute the copy-operation
    * destroy the copy-context
***************************************************************************/
rc_t CC KMain ( int argc, char *argv [] )
{
    Args * args;
    rc_t rc = ArgsMakeAndHandle ( &args, argc, argv, 1,
                                  MyOptions, sizeof MyOptions / sizeof ( OptDef ) );
    if ( rc != 0 )
    {
        LOGERR( klogErr, rc, "ArgsMakeAndHandle() failed" );
    }
    else
    {
        context *ctx;

        KLogHandlerSetStdErr();
        rc = context_init( &ctx );
        if ( rc != 0 )
        {
            LOGERR( klogInt, rc, "KMain:context_init() failed" );

        }
        else
        {
            rc = context_capture_arguments_and_options( args, ctx );
            if ( rc != 0 )
            {
                MiniUsage( args );
                if ( argc < 2 ) rc = 0;
            }
            else
            {
                if ( ctx->usage_requested )
                    MiniUsage( args );
                else
                    rc = ref_seq_load_main( ctx ); /* <====================== */
            }
            context_destroy( ctx );
        }
        ArgsWhack ( args );
    }
    return rc;
}
示例#17
0
rc_t CC KMain ( int argc, char *argv [] )
{
    Args * args;
    rc_t rc;

    rc = ArgsMakeAndHandle ( &args, argc, argv, 1, NULL, 0 );
    if ( rc == 0 )
    {
        rc = call_zlib();
        OUTMSG (( "calling zlib : %R\n", rc ));

        rc = call_bz2();
        OUTMSG (( "calling bz2 : %R\n", rc ));

        ArgsWhack ( args );
    }
    else
        OUTMSG( ( "ArgsMakeAndHandle() failed %R\n", rc ) );

    return rc;
}
示例#18
0
rc_t CC KMain ( int argc, char *argv [] )
{
    Args * args;
    rc_t rc = ArgsMakeAndHandle ( &args, argc, argv, 1,
								  sra_seq_count_options, 
								  ( sizeof sra_seq_count_options / sizeof sra_seq_count_options [ 0 ] ) );
    if ( rc == 0 )
    {
        struct sra_seq_count_options options;
		rc = gather_options( args, &options );
		if ( rc == 0 && options.valid )
		{
			rc = report_options( &options );
			if ( rc == 0 )
			{
				rc = matching( &options );	/* here we are calling into C++ */
			}
		}
        ArgsWhack ( args );
    }
    return rc;
}
示例#19
0
rc_t CC KMain (int argc, char * argv[])
{
    Args * args;
    rc_t rc;
    unsigned n_aligned = 0;
    unsigned n_unalgnd = 0;
    char *aligned[256];
    char *unalgnd[256];
    char *name_buffer = NULL;
    unsigned next_name = 0;
    unsigned nbsz = 0;
    char const *value;
    char *dummy;
    const XMLLogger* xml_logger = NULL;
    
    memset(&G, 0, sizeof(G));
    
    G.mode = mode_Archive;
    G.maxSeqLen = TableWriterRefSeq_MAX_SEQ_LEN;
    G.schemaPath = SCHEMAFILE;
    G.omit_aligned_reads = true;
    G.omit_reference_reads = true;
    G.minMapQual = 0; /* accept all */
    G.tmpfs = "/tmp";
#if _ARCH_BITS == 32
    G.cache_size = ( size_t ) 1 << 30;
#else
    G.cache_size = ( size_t ) 10 << 30;
#endif
    G.maxErrCount = 1000;
    G.minMatchCount = 10;
    
    set_pid();

    rc = ArgsMakeAndHandle (&args, argc, argv, 2, Options,
                            sizeof Options / sizeof (OptDef), XMLLogger_Args, XMLLogger_ArgsQty);

    while (rc == 0) {
        uint32_t pcount;

        if( (rc = XMLLogger_Make(&xml_logger, NULL, args)) != 0 ) {
            break;
        }
        rc = ArgsOptionCount(args, option_only_verify, &pcount);
        if (rc)
            break;
        G.onlyVerifyReferences = (pcount > 0);
        
        rc = ArgsOptionCount(args, option_no_verify, &pcount);
        if (rc)
            break;
        G.noVerifyReferences = (pcount > 0);
        
        rc = ArgsOptionCount(args, option_use_qual, &pcount);
        if (rc)
            break;
        G.useQUAL = (pcount > 0);
        
        rc = ArgsOptionCount(args, option_ref_config, &pcount);
        if (rc)
            break;
        G.limit2config = (pcount > 0);
        
        rc = ArgsOptionCount(args, OPTION_REF_FILE, &pcount);
        if (rc)
            break;
        G.refFiles = calloc(pcount + 1, sizeof(*(G.refFiles)));
        if( !G.refFiles ) {
            rc = RC(rcApp, rcArgv, rcAccessing, rcMemory, rcExhausted);
            break;
        }
        while(pcount-- > 0) {
            rc = ArgsOptionValue(args, OPTION_REF_FILE, pcount, &G.refFiles[pcount]);
            if (rc)
                break;
        }

        rc = ArgsOptionCount (args, OPTION_TMPFS, &pcount);
        if (rc)
            break;
        if (pcount == 1)
        {
            rc = ArgsOptionValue (args, OPTION_TMPFS, 0, &G.tmpfs);
            if (rc)
                break;
        }
        else if (pcount > 1)
        {
            rc = RC(rcApp, rcArgv, rcAccessing, rcParam, rcExcessive);
            OUTMSG (("Single parameter required\n"));
            MiniUsage (args);
            break;
        }
        
        rc = ArgsOptionCount (args, OPTION_INPUT, &pcount);
        if (rc)
            break;
        if (pcount == 1)
        {
            rc = ArgsOptionValue (args, OPTION_INPUT, 0, &G.inpath);
            if (rc)
                break;
        }
        else if (pcount > 1)
        {
            rc = RC(rcApp, rcArgv, rcAccessing, rcParam, rcExcessive);
            OUTMSG (("Single input parameter required\n"));
            MiniUsage (args);
            break;
        }
        
        rc = ArgsOptionCount (args, option_ref_filter, &pcount);
        if (rc)
            break;
        if (pcount == 1)
        {
            rc = ArgsOptionValue (args, option_ref_filter, 0, &G.refFilter);
            if (rc)
                break;
        }
        else if (pcount > 1)
        {
            rc = RC(rcApp, rcArgv, rcAccessing, rcParam, rcExcessive);
            OUTMSG (("Single parameter required\n"));
            MiniUsage (args);
            break;
        }
        
        rc = ArgsOptionCount (args, OPTION_CONFIG, &pcount);
        if (rc)
            break;
        if (pcount == 1)
        {
            rc = ArgsOptionValue (args, OPTION_CONFIG, 0, &G.refXRefPath);
            if (rc)
                break;
        }
        else if (pcount > 1)
        {
            rc = RC(rcApp, rcArgv, rcAccessing, rcParam, rcExcessive);
            OUTMSG (("Single input parameter required\n"));
            MiniUsage (args);
            break;
        }
        
        rc = ArgsOptionCount (args, OPTION_OUTPUT, &pcount);
        if (rc)
            break;
        if (pcount == 1)
        {
            rc = ArgsOptionValue (args, OPTION_OUTPUT, 0, &G.outpath);
            if (rc)
                break;
        }
        else if (pcount > 1)
        {
            rc = RC(rcApp, rcArgv, rcAccessing, rcParam, rcExcessive);
            OUTMSG (("Single output parameter required\n"));
            MiniUsage (args);
            break;
        }
        else if (!G.onlyVerifyReferences) {
            rc = RC(rcApp, rcArgv, rcAccessing, rcParam, rcInsufficient);
            OUTMSG (("Output parameter required\n"));
            MiniUsage (args);
            break;
        }
        
        rc = ArgsOptionCount (args, OPTION_MINMAPQ, &pcount);
        if (rc)
            break;
        if (pcount == 1)
        {
            rc = ArgsOptionValue (args, OPTION_MINMAPQ, 0, &value);
            if (rc)
                break;
            G.minMapQual = strtoul(value, &dummy, 0);
        }
        
        rc = ArgsOptionCount (args, OPTION_QCOMP, &pcount);
        if (rc)
            break;
        if (pcount == 1)
        {
            rc = ArgsOptionValue (args, OPTION_QCOMP, 0, &G.QualQuantizer);
            if (rc)
                break;
        }
        
        rc = ArgsOptionCount (args, option_edit_aligned_qual, &pcount);
        if (rc)
            break;
        if (pcount == 1)
        {
            rc = ArgsOptionValue (args, option_edit_aligned_qual, 0, &value);
            if (rc)
                break;
            G.alignedQualValue = strtoul(value, &dummy, 0);
            if (G.alignedQualValue == 0) {
                rc = RC(rcApp, rcArgv, rcAccessing, rcParam, rcIncorrect);
                OUTMSG (("edit-aligned-qual: bad value\n"));
                MiniUsage (args);
                break;
            }
            G.editAlignedQual = true;
        }
        
        rc = ArgsOptionCount (args, OPTION_CACHE_SIZE, &pcount);
        if (rc)
            break;
        if (pcount == 1)
        {
            rc = ArgsOptionValue (args, OPTION_CACHE_SIZE, 0, &value);
            if (rc)
                break;
            G.cache_size = strtoul(value, &dummy, 0) * 1024UL * 1024UL;
            if (G.cache_size == 0) {
                rc = RC(rcApp, rcArgv, rcAccessing, rcParam, rcIncorrect);
                OUTMSG (("cache-size: bad value\n"));
                MiniUsage (args);
                break;
            }
        }
        
        rc = ArgsOptionCount (args, OPTION_MAX_WARN_DUP_FLAG, &pcount);
        if (rc)
            break;
        if (pcount == 1)
        {
            rc = ArgsOptionValue (args, OPTION_MAX_WARN_DUP_FLAG, 0, &value);
            if (rc)
                break;
            G.maxWarnCount_DupConflict = strtoul(value, &dummy, 0);
        }
        
        rc = ArgsOptionCount (args, option_unsorted, &pcount);
        if (rc)
            break;
        G.expectUnsorted = pcount > 0;
        
        rc = ArgsOptionCount (args, OPTION_MAX_REC_COUNT, &pcount);
        if (rc)
            break;
        if (pcount == 1)
        {
            rc = ArgsOptionValue (args, OPTION_MAX_REC_COUNT, 0, &value);
            if (rc)
                break;
            G.maxAlignCount = strtoul(value, &dummy, 0);
        }
        
        rc = ArgsOptionCount (args, OPTION_MAX_ERR_COUNT, &pcount);
        if (rc)
            break;
        if (pcount == 1)
        {
            rc = ArgsOptionValue (args, OPTION_MAX_ERR_COUNT, 0, &value);
            if (rc)
                break;
            G.maxErrCount = strtoul(value, &dummy, 0);
        }
        
        rc = ArgsOptionCount (args, OPTION_MIN_MATCH, &pcount);
        if (rc)
            break;
        if (pcount == 1)
        {
            rc = ArgsOptionValue (args, OPTION_MIN_MATCH, 0, &value);
            if (rc)
                break;
            G.minMatchCount = strtoul(value, &dummy, 0);
        }
        
        rc = ArgsOptionCount (args, OPTION_ACCEPT_DUP, &pcount);
        if (rc)
            break;
        G.acceptBadDups = pcount > 0;
        
        rc = ArgsOptionCount (args, OPTION_ACCEPT_NOMATCH, &pcount);
        if (rc)
            break;
        G.acceptNoMatch = pcount > 0;
        
        rc = ArgsOptionCount (args, option_keep_mismatch_qual, &pcount);
        if (rc)
            break;
        G.keepMismatchQual = pcount > 0;
        
        rc = ArgsOptionCount (args, OPTION_NO_CS, &pcount);
        if (rc)
            break;
        G.noColorSpace = pcount > 0;
        
        rc = ArgsOptionCount (args, OPTION_NO_SECONDARY, &pcount);
        if (rc)
            break;
        G.noSecondary = pcount > 0;
        
        rc = ArgsOptionCount (args, OPTION_TI, &pcount);
        if (rc)
            break;
        G.hasTI = pcount > 0;
        
        rc = ArgsOptionCount (args, OPTION_ACCEPT_HARD_CLIP, &pcount);
        if (rc)
            break;
        G.acceptHardClip = pcount > 0;
        
        rc = ArgsOptionCount (args, OPTION_NOMATCH_LOG, &pcount);
        if (rc)
            break;
        if (pcount == 1)
        {
            KDirectory *dir;
            
            rc = ArgsOptionValue (args, OPTION_NOMATCH_LOG, 0, &value);
            if (rc) break;
            rc = KDirectoryNativeDir(&dir);
            if (rc) break;
            rc = KDirectoryCreateFile(dir, &G.noMatchLog, 0, 0664, kcmInit, value);
            KDirectoryRelease(dir);
            if (rc) break;
        }
        
        rc = ArgsOptionCount (args, OPTION_HEADER, &pcount);
        if (rc)
            break;
        if (pcount == 1) {
            rc = ArgsOptionValue (args, OPTION_HEADER, 0, &value);
            if (rc) break;
            rc = LoadHeader(&G.headerText, value, G.inpath);
            if (rc) break;
        }
        
        rc = ArgsParamCount (args, &pcount);
        if (rc) break;
        if (pcount == 0)
        {
            rc = RC(rcApp, rcArgv, rcAccessing, rcParam, rcInsufficient);
            MiniUsage (args);
            break;
        }
        else if (pcount > sizeof(aligned)/sizeof(aligned[0])) {
            rc = RC(rcApp, rcArgv, rcAccessing, rcParam, rcExcessive);
            (void)PLOGERR(klogErr, (klogErr, rc, "$(count) input files is too many, $(max) is the limit",
                        "count=%u,max=%u", (unsigned)pcount, (unsigned)(sizeof(aligned)/sizeof(aligned[0]))));
            break;
        }
        else {
            unsigned need = G.inpath ? (strlen(G.inpath) + 1) * pcount : 0;
            unsigned i;
            
            for (i = 0; i < pcount; ++i) {
                rc = ArgsParamValue(args, i, &value);
                if (rc) break;
                need += strlen(value) + 1;
            }
            nbsz = need;
        }
        
        rc = ArgsOptionCount (args, OPTION_UNALIGNED, &pcount);
        if (rc)
            break;
        if (pcount > 0)
        {
            unsigned need = G.inpath ? (strlen(G.inpath) + 1) * pcount : 0;
            unsigned i;
            
            for (i = 0; i < pcount; ++i) {
                rc = ArgsOptionValue(args, OPTION_UNALIGNED, i, &value);
                if (rc) break;
                need += strlen(value) + 1;
            }
            if (rc) break;
            nbsz += need;
        }
        
        name_buffer = malloc(nbsz);
        if (name_buffer == NULL) {
            rc = RC(rcApp, rcArgv, rcAccessing, rcMemory, rcExhausted);
            break;
        }
        
        rc = ArgsOptionCount (args, OPTION_UNALIGNED, &pcount);
        if (rc == 0) {
            unsigned i;
            
            for (i = 0; i < pcount; ++i) {
                rc = ArgsOptionValue(args, OPTION_UNALIGNED, i, &value);
                if (rc) break;
                
                unalgnd[n_unalgnd++] = name_buffer + next_name;
                rc = PathWithBasePath(name_buffer + next_name, nbsz - next_name, value, G.inpath);
                if (rc) break;
                next_name += strlen(name_buffer + next_name) + 1;
            }
            if (rc) break;
        }
        else
            break;
        
        rc = ArgsParamCount (args, &pcount);
        if (rc == 0) {
            unsigned i;
            
            for (i = 0; i < pcount; ++i) {
                rc = ArgsParamValue(args, i, &value);
                if (rc) break;
                
                aligned[n_aligned++] = name_buffer + next_name;
                rc = PathWithBasePath(name_buffer + next_name, nbsz - next_name, value, G.inpath);
                if (rc) break;
                next_name += strlen(name_buffer + next_name) + 1;
            }
        }
        else
            break;
        
        rc = run(argv[0], n_aligned, (char const **)aligned, n_unalgnd, (char const **)unalgnd);
        break;
    }
    free(name_buffer);
    free((void *)G.headerText);
    free(G.refFiles);

    value = G.outpath ? strrchr(G.outpath, '/') : "/???";
    if( value == NULL ) {
        value = G.outpath;
    } else {
        value++;
    }
    if (rc) {
        (void)PLOGERR(klogErr, (klogErr, rc, "load failed",
                "severity=total,status=failure,accession=%s,errors=%u", value, G.errCount));
    } else {
        (void)PLOGMSG(klogInfo, (klogInfo, "loaded",
                "severity=total,status=success,accession=%s,errors=%u", value, G.errCount));
    }
    ArgsWhack(args);
    XMLLogger_Release(xml_logger);
    return rc;
}
示例#20
0
static rc_t argsHandler(int argc, char* argv[]) {
    Args* args = NULL;
    rc_t rc = ArgsMakeAndHandle(&args, argc, argv, 0, NULL, 0);
    ArgsWhack(args);
    return rc;
}
示例#21
0
rc_t CC KMain( int argc, char *argv [] )
{
    Args * args;

    rc_t rc = ArgsMakeAndHandle( &args, argc, argv, 1, options, sizeof options / sizeof options [ 0 ] );
    if ( rc == 0 )
    {
        try
        {
            NGS_Pileup::Settings settings;
            
            uint32_t pcount;
            
            rc = ArgsOptionCount ( args, OPTION_REF, &pcount );
            if ( pcount > 1 )
            {
                throw ngs :: ErrorMsg ( "multiple positions are not supported at this point" );
            }
            if ( pcount == 1 )
            {
                const void * value;
                rc = ArgsOptionValue ( args, OPTION_REF, 0, & value );
                if ( rc != 0 )
                {
                    throw ngs :: ErrorMsg ( "ArgsOptionValue (" OPTION_REF ") failed" );
                }
                settings . AddReference ( static_cast <char const*> (value) );
            }
            
            rc = ArgsParamCount ( args, &pcount );
            if ( rc == 0 )
            {
                if ( pcount > 1 )
                {
                    throw ngs :: ErrorMsg ( "multiple accessions are not supported at this point" );
                }
                
                settings . output = & std::cout;
                
                void const *value;
                rc = ArgsParamValue ( args, 0, &value );
                if ( rc == 0 ) 
                {
                    settings . AddInput ( static_cast <char const*> (value) );
                    
                    NGS_Pileup ( settings ) . Run ();
                }
                else
                {
                    throw ngs :: ErrorMsg ( "ArgsParamValue failed" );
                }
            }
        }
        catch (ngs :: ErrorMsg& ex)
        {
            std :: cerr << "Program aborted: " << ex.what() << std::endl;
            exit ( -1 );
        }
        
        ArgsWhack( args );
    }
    
    return 0;
}
示例#22
0
/* KMain
 */
rc_t CC KMain ( int argc, char *argv [] )
{
    Args * args;
    rc_t rc;

    rc = ArgsMakeAndHandle (&args, argc, argv, 0);
    if (rc)
        LOGERR (klogInt, rc, "failed to parse arguments");
    else do
    {
        uint32_t acount;
        rc = ArgsParamCount (args, &acount);
        if (rc)
        {
            LOGERR (klogInt, rc, "failed to count parameters");
            break;
        }

        if (acount == 0)
        {
            rc = MiniUsage (args);
            break;
        }
        else
        {
            VFSManager* mgr;
            rc = VFSManagerMake(&mgr);
            if (rc)
                LOGERR ( klogErr, rc, "failed to create VFSManager object" );
            else
            {
                VResolver * resolver;

                rc = VFSManagerGetResolver (mgr, &resolver);
                if (rc == 0)
                {
                    uint32_t ix;
                    for ( ix = 0; ix < acount; ++ ix )
                    {
                        const char * pc;
                        rc = ArgsParamValue (args, ix, &pc );
                        if (rc)
                            LOGERR (klogInt, rc,
                                    "failed to retrieve parameter value");
                        else
                        {
                            const VPath * upath = NULL;
                            rc = VFSManagerMakePath ( mgr, (VPath**)&upath, "%s", pc);
                            if (rc == 0)
                            {
                                const VPath * local;
                                const VPath * remote;

                                rc = VResolverQuery (resolver, eProtocolHttp, upath, &local, &remote, NULL);

                                if (rc == 0)
                                {
                                    const String * s;

                                    if (local != NULL)
                                        rc = VPathMakeString (local, &s);
                                    else 
                                        rc = VPathMakeString (remote, &s);
                                    if (rc == 0)
                                    {
                                        OUTMSG (("%S\n", s));
                                        free ((void*)s);
                                    }
                                    VPathRelease (local);
                                    VPathRelease (remote);
                                }
                                else
                                {
                                    KDirectory * cwd;
                                    rc_t orc = VFSManagerGetCWD (mgr, &cwd);
                                    if (orc == 0)
                                    {
                                        KPathType kpt
                                            = KDirectoryPathType(cwd, "%s", pc);
                                        switch (kpt &= ~kptAlias)
                                        {
                                        case kptNotFound:
                                            STSMSG(1, ("'%s': not found while "
                                                "searching the file system",
                                                pc));
                                            break;
                                        case kptBadPath:
                                            STSMSG(1, ("'%s': bad path while "
                                                "searching the file system",
                                                pc));
                                            break;
                                        default:
                                            STSMSG(1, ("'%s': "
                                                "found in the file system",
                                                pc));
                                            rc = 0;
                                            break;
                                        }
                                    }
                                    if (orc == 0 && rc == 0) {
                                        if (rc != 0) {
                                            PLOGMSG(klogErr, (klogErr,
                                                              "'$(name)': not found",
                                                              "name=%s", pc));
                                        }
                                        else {
                                            char resolved[PATH_MAX] = "";
                                            rc = KDirectoryResolvePath(cwd, true,
                                                                       resolved, sizeof resolved, "%s", pc);
                                            if (rc == 0) {
                                                STSMSG(1, ("'%s': found in "
                                                           "the current directory at '%s'",
                                                           pc, resolved));
                                                OUTMSG (("%s\n", resolved));
                                            }
                                            else {
                                                STSMSG(1, ("'%s': cannot resolve "
                                                           "in the current directory",
                                                           pc));
                                                OUTMSG (("./%s\n", pc));
                                            }
                                        }
                                    }
                                    KDirectoryRelease(cwd);
                                }
                            }

                            RELEASE(VPath, upath);
                        }
                    }
                    VResolverRelease (resolver);
                }
                VFSManagerRelease(mgr);
            }
        }
        ArgsWhack (args);

    } while (0);

    return rc;
}
示例#23
0
rc_t CC KMain (int argc, char * argv[])
{
    Args * args;
    uint32_t pcount;
    rc_t rc = ArgsMakeAndHandle (&args, argc, argv, 1, Options, sizeof Options / sizeof (OptDef));

    if ( rc == 0 )
    {
        rc = ArgsParamCount (args, &pcount);
        if ( rc == 0 )
        {
            if ( pcount != 0 )
            {
                rc = RC(rcApp, rcArgv, rcAccessing, rcParam, rcExcessive);
                MiniUsage (args);
            }
            else
            { 
                const KStream *std_in;
                rc = KStreamMakeStdIn ( & std_in );
                if ( rc == 0 )
                {
                    KStream* buffered;
                    rc = KStreamMakeBuffered ( &buffered, std_in, 0 /*input-only*/, 0 /*use default size*/ );
                    if ( rc == 0 )
                    {
                        GeneralLoader loader ( *buffered );
                        
                        rc = ArgsOptionCount (args, OPTION_INCLUDE_PATHS, &pcount);
                        if ( rc == 0 )
                        {
                            for ( uint32_t i = 0 ; i < pcount; ++i )
                            {
                                const char* value;
                                rc = ArgsOptionValue (args, OPTION_INCLUDE_PATHS, i, &value);
                                if ( rc != 0 )
                                {
                                    break;
                                }
                                loader . AddSchemaIncludePath ( value );
                            }
                        }
                        
                        rc = ArgsOptionCount (args, OPTION_SCHEMAS, &pcount);
                        if ( rc == 0 )
                        {
                            for ( uint32_t i = 0 ; i < pcount; ++i )
                            {
                                const char* value;
                                rc = ArgsOptionValue (args, OPTION_SCHEMAS, i, &value);
                                if ( rc != 0 )
                                {
                                    break;
                                }
                                loader . AddSchemaFile( value );
                            }
                        }
                        
                        rc = ArgsOptionCount (args, OPTION_TARGET, &pcount);
                        if ( rc == 0 && pcount == 1 )
                        {
                            const char* value;
                            rc = ArgsOptionValue (args, OPTION_TARGET, 0, &value);
                            if ( rc == 0 )
                            {
                                loader . SetTargetOverride ( value );
                            }
                        }
                        
                        if ( rc == 0 )
                        {
                            rc = loader . Run();
                        }
                        KStreamRelease ( buffered );
                    }
                    KStreamRelease ( std_in );
                }
            }
        }
    }
    
    if ( rc != 0) 
    {
        LOGERR ( klogErr, rc, "load failed" );
    }
    
    ArgsWhack(args);
    return rc;
}
示例#24
0
rc_t CC KMain( int argc, char* argv[] )
{
    rc_t rc = 0;
    Args* args = NULL;
    const char* errmsg = NULL, *refseq_chunk = NULL, *min_mapq = NULL, *cluster_size = NULL;
    const XMLLogger* xml_logger = NULL;
    SParam params;
    memset(&params, 0, sizeof(params));
    params.schema = "align/align.vschema";

    params.argv0 = argv[0];
    
    if( (rc = ArgsMakeAndHandle(&args, argc, argv, 2, MainArgs, MainArgsQty, XMLLogger_Args, XMLLogger_ArgsQty)) == 0 ) {
        uint32_t count;
        if( (rc = ArgsParamCount (args, &count)) != 0 || count != 0 ) {
            rc = rc ? rc : RC(rcExe, rcArgv, rcParsing, rcParam, rcExcessive);
            ArgsParamValue(args, 0, &errmsg);
        
        } else if( (rc = ArgsOptionCount(args, MainArgs[eopt_Output].name, &count)) != 0 || count != 1 ) {
            rc = rc ? rc : RC(rcExe, rcArgv, rcParsing, rcParam, count ? rcExcessive : rcInsufficient);
            errmsg = MainArgs[eopt_Output].name;
        } else if( (rc = ArgsOptionValue(args, MainArgs[eopt_Output].name, 0, &params.out)) != 0 ) {
            errmsg = MainArgs[eopt_Output].name;

        } else if( (rc = ArgsOptionCount(args, MainArgs[eopt_MapInput].name, &count)) != 0 || count != 1 ) {
            rc = rc ? rc : RC(rcExe, rcArgv, rcParsing, rcParam, count ? rcExcessive : rcInsufficient);
            errmsg = MainArgs[eopt_MapInput].name;
        } else if( (rc = ArgsOptionValue(args, MainArgs[eopt_MapInput].name, 0, &params.map_path)) != 0 ) {
            errmsg = MainArgs[eopt_MapInput].name;

        } else if( (rc = ArgsOptionCount(args, MainArgs[eopt_Schema].name, &count)) != 0 || count > 1 ) {
            rc = rc ? rc : RC(rcExe, rcArgv, rcParsing, rcParam, count ? rcExcessive : rcInsufficient);
            errmsg = MainArgs[eopt_Schema].name;
        } else if( count > 0 && (rc = ArgsOptionValue(args, MainArgs[eopt_Schema].name, 0, &params.schema)) != 0 ) {
            errmsg = MainArgs[eopt_Schema].name;

        } else if( (rc = ArgsOptionCount(args, MainArgs[eopt_AsmInput].name, &count)) != 0 || count > 1 ) {
            rc = rc ? rc : RC(rcExe, rcArgv, rcParsing, rcParam, rcExcessive);
            errmsg = MainArgs[eopt_AsmInput].name;
        } else if( count > 0 && (rc = ArgsOptionValue(args, MainArgs[eopt_AsmInput].name, 0, &params.asm_path)) != 0 ) {
            errmsg = MainArgs[eopt_AsmInput].name;

        } else if( (rc = ArgsOptionCount(args, MainArgs[eopt_RefSeqConfig].name, &count)) != 0 || count > 1 ) {
            rc = rc ? rc : RC(rcExe, rcArgv, rcParsing, rcParam, rcExcessive);
            errmsg = MainArgs[eopt_RefSeqConfig].name;
        } else if( count > 0 && (rc = ArgsOptionValue(args, MainArgs[eopt_RefSeqConfig].name, 0, &params.refseqcfg)) != 0 ) {
            errmsg = MainArgs[eopt_RefSeqConfig].name;

        } else if( (rc = ArgsOptionCount(args, MainArgs[eopt_RefSeqPath].name, &count)) != 0 || count > 1 ) {
            rc = rc ? rc : RC(rcExe, rcArgv, rcParsing, rcParam, rcExcessive);
            errmsg = MainArgs[eopt_RefSeqPath].name;
        } else if( count > 0 && (rc = ArgsOptionValue(args, MainArgs[eopt_RefSeqPath].name, 0, &params.refseqpath)) != 0 ) {
            errmsg = MainArgs[eopt_RefSeqPath].name;

        } else if( (rc = ArgsOptionCount(args, MainArgs[eopt_Library].name, &count)) != 0 || count > 1 ) {
            rc = rc ? rc : RC(rcExe, rcArgv, rcParsing, rcParam, rcExcessive);
            errmsg = MainArgs[eopt_Library].name;
        } else if( count > 0 && (rc = ArgsOptionValue(args, MainArgs[eopt_Library].name, 0, &params.library)) != 0 ) {
            errmsg = MainArgs[eopt_Library].name;

        } else if( (rc = ArgsOptionCount(args, MainArgs[eopt_RefSeqChunk].name, &count)) != 0 || count > 1 ) {
            rc = rc ? rc : RC(rcExe, rcArgv, rcParsing, rcParam, rcExcessive);
            errmsg = MainArgs[eopt_RefSeqChunk].name;
        } else if( count > 0 && (rc = ArgsOptionValue(args, MainArgs[eopt_RefSeqChunk].name, 0, &refseq_chunk)) != 0 ) {
            errmsg = MainArgs[eopt_RefSeqChunk].name;

        } else if( (rc = ArgsOptionCount(args, MainArgs[eopt_Force].name, &params.force)) != 0 ) {
            errmsg = MainArgs[eopt_Force].name;

        } else if( (rc = ArgsOptionCount(args, MainArgs[eopt_ForceRef].name, &params.force_refw)) != 0 ) {
            errmsg = MainArgs[eopt_ForceRef].name;

        } else if( (rc = ArgsOptionCount(args, MainArgs[eopt_ForceRead].name, &params.force_readw)) != 0 ) {
            errmsg = MainArgs[eopt_ForceRead].name;

        } else if( (rc = ArgsOptionCount(args, MainArgs[eopt_noReadAhead].name, &params.no_read_ahead)) != 0 ) {
            errmsg = MainArgs[eopt_noReadAhead].name;

        } else if( (rc = ArgsOptionCount(args, MainArgs[eopt_NoSpotGroup].name, &params.no_spot_group)) != 0 ) {
            errmsg = MainArgs[eopt_NoSpotGroup].name;

        } else if( (rc = ArgsOptionCount(args, MainArgs[eopt_No2nd_ary].name, &params.min_mapq)) != 0 ) {
            errmsg = MainArgs[eopt_No2nd_ary].name;

        } else if( (rc = ArgsOptionCount(args, MainArgs[eopt_QualQuantization].name, &count)) != 0 || count > 1 ) {
            rc = rc ? rc : RC(rcExe, rcArgv, rcParsing, rcParam, rcExcessive);
            errmsg = MainArgs[eopt_QualQuantization].name;
        } else if( count > 0 && (rc = ArgsOptionValue(args, MainArgs[eopt_QualQuantization].name, 0, &params.qual_quant)) != 0 ) {
            errmsg = MainArgs[eopt_QualQuantization].name;

        } else if( (rc = ArgsOptionCount(args, MainArgs[eopt_MinMapQ].name, &count)) != 0 || count > 1 ) {
            rc = rc ? rc : RC(rcExe, rcArgv, rcParsing, rcParam, rcExcessive);
            errmsg = MainArgs[eopt_MinMapQ].name;
        } else if( count > 0 && (rc = ArgsOptionValue(args, MainArgs[eopt_MinMapQ].name, 0, &min_mapq)) != 0 ) {
            errmsg = MainArgs[eopt_MinMapQ].name;
        } else if( (rc = ArgsOptionCount(args, MainArgs[eopt_ClusterSize].name, &count)) != 0 || count > 1 ) {
            rc = rc ? rc : RC(rcExe, rcArgv, rcParsing, rcParam, rcExcessive);
            errmsg = MainArgs[eopt_ClusterSize].name;
        } else if( count > 0 && (rc = ArgsOptionValue(args, MainArgs[eopt_ClusterSize].name, 0, &cluster_size)) != 0 ) {
            errmsg = MainArgs[eopt_ClusterSize].name;
        } else if( (rc = ArgsOptionCount(args, MainArgs[eopt_SingleMate].name, &params.single_mate)) != 0 ) {
            errmsg = MainArgs[eopt_SingleMate].name;

        } else {
            do {
                long val = 0;
                char* end = NULL;
                uint32_t count;

                if( (rc = ArgsOptionCount(args, MainArgs[eopt_RefFile].name, &count)) != 0 ) {
                    break;
                } else {
                    params.refFiles = calloc(count + 1, sizeof(*(params.refFiles)));
                    if( params.refFiles == NULL ) {
                        rc = RC(rcApp, rcArgv, rcReading, rcMemory, rcExhausted);
                        break;
                    }
                    while(rc == 0 && count-- > 0) {
                        rc = ArgsOptionValue(args, MainArgs[eopt_RefFile].name, count, &params.refFiles[count]);
                    }
                }

                if( refseq_chunk != NULL ) {
                    errno = 0;
                    val = strtol(refseq_chunk, &end, 10);
                    if( errno != 0 || refseq_chunk == end || *end != '\0' || val < 0 || val > UINT32_MAX ) {
                        rc = RC(rcExe, rcArgv, rcReading, rcParam, rcInvalid);
                        break;
                    }
                    params.refseq_chunk = val;
                }
                if( params.min_mapq > 0 ) {
                    params.min_mapq = ~0;
                } else if( min_mapq != NULL ) {
                    errno = 0;
                    val = strtol(min_mapq, &end, 10);
                    if( errno != 0 || min_mapq == end || *end != '\0' || val < 0 || val > 255 ) {
                        rc = RC(rcExe, rcArgv, rcReading, rcParam, rcInvalid);
                        break;
                    }
                    params.min_mapq = val;
                }

                if ( cluster_size )
                    params.cluster_size = atoi( cluster_size );
                else
                    params.cluster_size = 0;

                rc = KDirectoryNativeDir( &params.input_dir );
                if ( rc != 0 )
                    errmsg = "current directory";
                else
                {
                    rc = XMLLogger_Make( &xml_logger, params.input_dir, args );
                    if ( rc != 0 )
                        errmsg = "XML logging";
                    else
                        rc = Load( &params );
                }
            } while( false );
            KDirectoryRelease( params.input_dir );
        }
    }
    /* find accession as last part of path for internal XML logging */
    refseq_chunk = params.out ? strrchr(params.out, '/') : "/???";
    if( refseq_chunk ++ == NULL )
        refseq_chunk = params.out;

    if( argc < 2 )
        MiniUsage(args);
    else if( rc != 0 )
    {
        if( errmsg )
        {
            MiniUsage(args);
            LOGERR(klogErr, rc, errmsg);
        }
        else
        {
            PLOGERR(klogErr, (klogErr, rc, "load failed: $(reason_short)",
                    "severity=total,status=failure,accession=%s", refseq_chunk));
        }
    }
    else
    {
        PLOGMSG(klogInfo, (klogInfo, "loaded",
                "severity=total,status=success,accession=%s", refseq_chunk));
    }
    ArgsWhack(args);
    XMLLogger_Release(xml_logger);
    return rc;
}
示例#25
0
rc_t CC KMain ( int argc, char *argv [] )
{
    Args * args;

    rc_t rc = ArgsMakeAndHandle ( &args, argc, argv, 1,
                QfileTestOptions, sizeof ( QfileTestOptions ) / sizeof ( OptDef ) );
    if ( rc != 0 )
    {
        OUTMSG(( "ArgsMakeAndHandle( ... ) failed: %R\n", rc ));
    }
    else
    {
        uint32_t arg_count = 0;
        rc = ArgsParamCount ( args, &arg_count );
        if ( rc != 0 )
        {
            OUTMSG(( "ArgsParamCount( ... ) failed: %R\n", rc ));
        }
        else
        {
            KDirectory *dir = NULL;
            uint64_t position = get_uint64_option( args, OPTION_POS, 0 );
            uint64_t count = get_uint64_option( args, OPTION_COUNT, 0 );
            uint32_t qsize = get_uint32_option( args, OPTION_QSIZE, 1024 );
            uint32_t bsize = get_uint32_option( args, OPTION_BSIZE, 0 );
            uint32_t csize = get_uint32_option( args, OPTION_CSIZE, 1024 );
            uint64_t pos2 = get_uint64_option( args, OPTION_POS2, 0 );

            OUTMSG(( "start-position : %lu\n", position ));
            if ( pos2 > 0 )
            {
                OUTMSG(( "2nd position   : %lu\n", pos2 ));
            }
            if ( count > 0 )
            {
                OUTMSG(( "count          : %lu\n", count ));
            }
            OUTMSG(( "queue-size     : %u\n",  qsize ));
            OUTMSG(( "block-size     : %u\n",  bsize ));
            OUTMSG(( "chunk-size     : %u\n",  csize ));

            rc = KDirectoryNativeDir( &dir );
            if ( rc != 0 )
            {
                OUTMSG(( "KDirectoryNativeDir( ... ) failed: %R\n", rc ));
            }
            else
            {
                uint32_t i;
                for ( i = 0; i < arg_count && rc == 0; ++i )
                {
                    const char * filename;
                    rc = ArgsParamValue ( args, i, &filename );
                    if ( rc != 0 )
                    {
                        OUTMSG(( "ArgsParamValue( %d ) failed: %R\n", i, rc ));
                    }
                    else
                    {
                        OUTMSG(( "file to read   : '%s'\n", filename ));
                        rc = perform_test( dir, filename, position, pos2,
                                           count, qsize, bsize, csize );
                    }
                }
                KDirectoryRelease( dir );
            }
        }
        ArgsWhack ( args );
    }

    return rc;
}
示例#26
0
rc_t CC KMain ( int argc, char *argv [] )
{
    Args *args;
    rc_t rc;
    do {
        uint32_t paramc;
        bool requireAmd64 = false;
        uint64_t requireRam = 0;

        rc = ArgsMakeAndHandle ( & args, argc, argv, 1, 
               Options, sizeof Options / sizeof (OptDef) );
        if ( rc != 0 )
        {
            LogErr ( klogErr, rc, "failed to parse arguments" );
            break;
        }
        
        // TODO: cehck if we need it
        rc = ArgsParamCount ( args, & paramc );
        if ( rc != 0 ) {
            LogErr ( klogInt, rc, "failed to obtain param count" );
            break;
        }

        {   // OPTION_AMD64
            rc = ArgsOptionCount( args, OPTION_AMD64, & paramc );
            if ( rc ) {
                LOGERR( klogErr, rc, "Failure to get '" OPTION_AMD64 "' argument" );
                break;
            }
            if ( paramc ) {
                requireAmd64 = true;
            }
        }

        {
            // OPTION_RAM
            rc = ArgsOptionCount ( args, OPTION_RAM, & paramc );
            if ( rc ) {
                LOGERR ( klogErr, rc, "Failure to get '" OPTION_RAM "' argument" );
                break;
            }
            if ( paramc ) {
                const char* dummy = NULL;
                rc = ArgsOptionValue(args, OPTION_RAM, 0, (const void **)&dummy);
                if ( rc ) {
                    LOGERR(klogErr, rc, "Failure to get '" OPTION_RAM "' argument");
                    break;
                }

                rc = sscanf(dummy, "%llu", &requireRam);
                if ( rc != 1) 
                {
                    LOGMSG(klogErr, "Failure to parse '" OPTION_RAM "' argument value");
                    break;
                }
            }

        }
       
        {
            rc = KAppCheckEnvironment(requireAmd64, requireRam);
            if (rc != 0 )
                printf("Invalid environment\n");
            else
                printf("Enviroment is fine!\n"); 
        }
    } while (false);

    ArgsWhack ( args );

    return rc;
}
示例#27
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;
}
示例#28
0
rc_t CC KMain ( int argc, char *argv [] )
{
    Args * args;
    rc_t rc;

    rc = ArgsMakeAndHandle (&args, argc, argv, 1, MyOptions, sizeof MyOptions / sizeof (OptDef));
    if (rc)
        LOGERR (klogInt, rc, "failed to parse arguments");

    else
    {
        do
        {
            KDyld *dl;
            uint32_t num_libs;

            rc = ArgsParamCount (args, &num_libs);
            if (rc)
            {
                LOGERR ( klogInt, rc, "Failure to count parameters" );
                break;
            }

            if (num_libs == 0)
            {
                rc = MiniUsage(args);
                break;
            }

            /* create loader */
            rc = KDyldMake (&dl);
            if (rc)
            {
                LOGERR ( klogInt, rc, "failed to create dynamic loader" );
                break;
            }
            else
            {
                do
                {
                    KDlset *libs;
                    const char * path;
                    uint32_t ix;
                    uint32_t num_paths;

                    rc = ArgsOptionCount (args, OPTION_LOAD, &num_paths);
                    if (rc)
                    {
                        LOGERR (klogInt, rc, "failed to count paths");
                        break;
                    }

                    for (ix = 0; ix < num_paths; ix++)
                    {

                        rc = ArgsOptionValue (args, OPTION_LOAD, ix, (const void **)&path);
                        if (rc)
                        {
                            LOGERR (klogInt, rc, "failed to access a path option");
                            break;
                        }
                        testld_update_libpath (dl, path);
                    }
                    if (rc)
                        break;

                    /* append contents of LD_LIBRARY_PATH */
                    path = getenv ( "LD_LIBRARY_PATH" );

                    if (path)
                        testld_update_libpath (dl, path);

                    /* create libset */
                    rc = KDyldMakeSet (dl, & libs);
                    if (rc)
                    {
                        LOGERR (klogInt, rc, "failed to create dl library set");
                        break;
                    }
                    else
                    {
                        /* test it */
                        for (ix = 0; ix < num_libs; ++ ix )
                        {
                            rc = ArgsParamValue (args, ix, (const void **)&path);
                            if (rc)
                                break;

                            testld_load_library (dl, libs, path);
                        }

                        KDlsetRelease ( libs );
                    }
                } while (0);

                KDyldRelease ( dl );
            }

        } while (0);

        ArgsWhack (args);
    }
    return rc;
}
示例#29
0
rc_t CC KMain ( int argc, char *argv [] )
{
    Args * args;
    rc_t rc;

    rc = ArgsMakeAndHandle (&args, argc, argv, 1, Options, sizeof Options / sizeof (OptDef));
    if (rc == 0)
    {
        uint32_t pcount;
        const char * pc;
        const char * directory;
        const char * archive;

        do
        {
            op_mode mode;
            uint32_t ix;

            BSTreeInit (&pnames);

            rc = ArgsParamCount (args, &pcount);
            if (rc)
                break;
            for (ix = 0; ix < pcount; ++ix)
            {
                rc = ArgsParamValue (args, ix, (const void **)&pc);
                if (rc)
                    break;
                rc = pnamesInsert (pc);
                if (rc)
                {
                    PLOGERR (klogInt, (klogInt, rc, "failure to process filter parameter [%s]", pc));
                    break;
                }
            }
            if (rc)
                break;

            rc = ArgsOptionCount (args, OPTION_ALIGN, &pcount);
            if (rc)
                break;
            if (pcount == 0)
                pc = NULL;
            else
            {
                rc = ArgsOptionValue (args, OPTION_ALIGN, 0, (const void **)&pc);
                if (rc)
                    break;
            }
            alignment = get_alignment (pc);
            if (alignment == sraAlignInvalid)
            {
                rc = RC (rcExe, rcArgv, rcParsing, rcParam, rcInvalid);
                PLOGERR (klogFatal, (klogFatal, rc,
                         "Parameter for alignment [$(A)] is invalid: must be a power of two bytes",
                                     PLOG_S(A), pc));
                break;
            }

            rc = ArgsOptionCount (args, OPTION_LONGLIST, &pcount);
            if (rc)
                break;
            long_list = (pcount != 0);

            rc = ArgsOptionCount (args, OPTION_FORCE, &pcount);
            if (rc)
                break;
            force = (pcount != 0);

            mode = OM_NONE;

            rc = ArgsOptionCount (args, OPTION_DIRECTORY, &pcount);
            if (rc)
                break;
            if (pcount)
            {
                rc = ArgsOptionValue (args, OPTION_DIRECTORY, 0, (const void **)&directory);
                if (rc)
                    break;

            }
            else
                directory = NULL;

            rc = ArgsOptionCount (args, OPTION_CREATE, &pcount);
            if (rc)
                break;
            if (pcount)
            {
                rc = ArgsOptionValue (args, OPTION_CREATE, 0, (const void **)&archive);

                if (rc)
                    break;
                mode = OM_CREATE;
            }

            rc = ArgsOptionCount (args, OPTION_TEST, &pcount);
            if (rc)
                break;
            if (pcount)
            {
                if (mode == OM_NONE)
                {
                    mode = OM_TEST;
                    rc = ArgsOptionValue (args, OPTION_TEST, 0, (const void **)&archive);
                    if (rc)
                        break;
                }
                else
                    mode = OM_ERROR;
            }

            rc = ArgsOptionCount (args, OPTION_LIST, &pcount);
            if (rc)
                break;
            if (pcount)
            {
                if (mode == OM_NONE)
                {
                    mode = OM_TEST;
                    rc = ArgsOptionValue (args, OPTION_LIST, 0, (const void **)&archive);
                    if (rc)
                        break;
                }
                else
                    mode = OM_ERROR;
            }

            rc = ArgsOptionCount (args, OPTION_EXTRACT, &pcount);
            if (rc)
                break;
            if (pcount)
            {
                if (mode == OM_NONE)
                {
                    mode = OM_EXTRACT;
                    rc = ArgsOptionValue (args, OPTION_EXTRACT, 0, (const void **)&archive);
                    if (rc)
                        break;
                }
                else
                    mode = OM_ERROR;
            }


            if (mode == OM_NONE)
            {
                MiniUsage(args);
                rc = RC(rcApp, rcArgv, rcParsing, rcParam, rcInsufficient);
                break;
            }


            /* -----
             * Mount the native filesystem as root
             */
            rc = KDirectoryNativeDir (&kdir);
            if (rc != 0)
            {
                LOGMSG (klogFatal, "Failed to open native KDirectory");
            }
            else
            {
                switch (mode)

                { 
                default: /* OM_NONE presumably */
/*                     assert (mode == OM_NONE); */
/*                     rc = RC (rcExe, rcNoTarg, rcParsing, rcParam, rcEmpty); */
/*                     LOGERR (klogFatal, rc, "Must provide a single operating mode and archive: Create, Test (list) or eXtract"); */
                    pc = NULL;
                    break;

                case OM_ERROR:
                    rc = RC (rcExe, rcNoTarg, rcParsing, rcParam, rcAmbiguous);
                    LOGERR (klogFatal, rc, "Must provide a single operating mode and archive: Create, Test (list) or eXtract");
                    break;
                case OM_CREATE:
                    STSMSG (2, ("Create Mode %s %s", archive, directory));
                    if (directory == NULL)
                    {
                        rc = RC (rcExe, rcNoTarg, rcParsing, rcParam, rcNull);
                        LOGERR (klogFatal, rc, "Must provide a directory for create mode");
                    }
                    else
                        rc = run_kar_create (archive, directory);
                    break;
                case OM_TEST:
                    STSMSG (2, ("Test Mode %s", archive));
                    rc = run_kar_test (archive);
                    break;
                case OM_EXTRACT:
                    STSMSG (2, ("Extract Mode %s %s", archive, directory));
                    if (directory == NULL)
                    {
                        rc = RC (rcExe, rcNoTarg, rcParsing, rcParam, rcNull);
                        LOGERR (klogFatal, rc, "Must provide a directory for extract mode");
                    }
                    else
                        rc = run_kar_extract (archive, directory);
                    break;
                }

                KDirectoryRelease (kdir);
            }

        } while (0);

        ArgsWhack (args);
    }
    if (rc)
        LOGERR (klogWarn, rc, "Failure exiting kar");
    else
        STSMSG (1, ("Success: Exiting kar\n"));
    return rc;
}
示例#30
0
rc_t CC KMain ( int argc, char *argv [] )
{
    Args *args;
    rc_t rc = ArgsMakeAndHandle ( & args, argc, argv, 0 );
    if ( rc != 0 )
        LogErr ( klogErr, rc, "failed to parse arguments" );
    else
    {
        uint32_t paramc;
        rc = ArgsParamCount ( args, & paramc );
        if ( rc != 0 )
            LogErr ( klogInt, rc, "failed to obtain param count" );
        else
        {
            if ( paramc == 0 )
            {
                rc = RC ( rcExe, rcArgv, rcParsing, rcParam, rcInsufficient );
                LogErr ( klogErr, rc, "missing target object" );
                MiniUsage ( args );
            }
            else if ( paramc > 1 )
            {
                rc = RC ( rcExe, rcArgv, rcParsing, rcParam, rcExcessive );
                LogErr ( klogErr, rc, "expected single target object" );
                MiniUsage ( args );
            }
            else
            {
                const char *target;
                rc = ArgsParamValue ( args, 0, & target );
                if ( rc != 0 )
                    LogErr ( klogInt, rc, "failed to obtain param value" );
                else
                {
                    VDBManager *mgr;

#if TOOLS_USE_SRAPATH != 0
                    char full [ 4096 ];
                    SRAPath *sra_path;
                    rc = SRAPathMake ( & sra_path, NULL );
                    if ( rc == 0 )
                    {
                        if ( ! SRAPathTest ( sra_path, target ) )
                        {
                            rc = SRAPathFind ( sra_path, target, full, sizeof full );
                            if ( rc == 0 )
                                target = full;
                        }
                        SRAPathRelease ( sra_path );
                    }
#endif

                    rc = VDBManagerMakeUpdate ( & mgr, NULL );
                    if ( rc != 0 )
                        LogErr ( klogInt, rc, "failed to open VDB manager" );
                    else
                    {
                        rc = VDBManagerLock ( mgr, target );
                        if ( rc == 0 )
                            pLogMsg ( klogInfo, "locked '$(target)'", "target=%s", target );
                        else switch ( GetRCState ( rc ) )
                        {
                        case rcLocked:
                            pLogMsg ( klogInfo, "'$(target)' was already locked", "target=%s", target );
                            break;
                        default:
                            pLogErr ( klogErr, rc, "failed to lock '$(target)'", "target=%s", target );
                        }

                        VDBManagerRelease ( mgr );
                    }
                }
            }
        }

        ArgsWhack ( args );
    }

    return rc;
}