示例#1
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;
}
示例#2
0
static rc_t copy2_main( Args * args )
{
    const char * source_path;
    rc_t rc = ArgsParamValue( args, 0, &source_path );
    if ( rc != 0 )
        LOGERR( klogInt, rc, "ArgsParamValue( 0 ) failed" );
    else
    {
        const char * dest_path;
        rc = ArgsParamValue( args, 1, &dest_path );
        if ( rc != 0 )
            LOGERR( klogInt, rc, "ArgsParamValue( 1 ) failed" );
        else
        {
            KDirectory *dir, *dest_dir;
            const KDirectory *source_dir;
            rc = KDirectoryNativeDir ( &dir );
            if ( rc != 0 )
                LOGERR( klogInt, rc, "KDirectoryNativeDir() failed" );
            else
            {
                rc = KDirectoryOpenDirRead( dir, &source_dir, false,
                                            source_path );
                if ( rc != 0 )
                    LOGERR( klogInt, rc, "KDirectoryOpenDirRead() failed" );
                else
                {
                    rc = KDirectoryOpenDirUpdate( dir, &dest_dir, false,
                                            dest_path );
                    if ( rc != 0 )
                        LOGERR( klogInt, rc,
                                "KDirectoryOpenDirUpdate() failed" );
                    else
                    {
                        rc = KDirectoryCopy( source_dir, dest_dir, true,
                                             source_path, dest_path );
                        if ( rc != 0 )
                            LOGERR( klogInt, rc, "copy_dirs() failed" );
                        else
                            OUTMSG(( "copy successful!\n" ));
                        KDirectoryRelease ( dest_dir );
                    }
                    KDirectoryRelease ( source_dir );
                }
                KDirectoryRelease ( dir );
            }
        }
    }
    return rc;
}
示例#3
0
static void setup_compress_context( const Args * args, p_compress_context ctx )
{
    uint32_t count;
    const char *value = NULL;
    rc_t rc = ArgsParamCount( args, &count );
    DISP_RC( rc, "ArgsParamCount() failed" );
    if ( rc == 0 )
    {
        rc = ArgsParamValue( args, 0, &value );
        DISP_RC( rc, "ArgsParamValue() failed" );
        if ( rc == 0 )
            ctx->src_file = string_dup_measure( value, NULL );

        rc = ArgsParamValue( args, 1, &value );
        DISP_RC( rc, "ArgsParamValue() failed" );
        if ( rc == 0 )
            ctx->dst_file = string_dup_measure( value, NULL );
    }

    value = get_str_option( args, OPTION_DIRECTION );
    if ( value )
    {
        switch ( value[0] )
        {
        case 'c' :
        case 'C' : ctx->direction = KC_COMPRESS; break;
        case 'd' :
        case 'D' : ctx->direction = KC_DECOMPRESS; break;
        }
    }
    if ( ctx->direction == 0 )
        ctx->direction = KC_DECOMPRESS;

    value = get_str_option( args, OPTION_METHOD );
    if ( value )
    {
        switch ( value[0] )
        {
        case 'g' :
        case 'G' : ctx->method = KC_GZIP; break;
        case 'b' :
        case 'B' : ctx->method = KC_BZIP; break;
        case 's' :
        case 'S' : ctx->method = KC_SZIP; break;
        }
    }
    if ( ctx->method == 0 )
        ctx->method = KC_GZIP;
}
示例#4
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;
}
示例#5
0
static rc_t get_tool_options( Args * args, tool_options * options )
{
    uint32_t idx, count;

    rc_t rc = ArgsParamCount( args, &count );
    if ( rc != 0 )
    {
        PLOGERR( klogErr, ( klogErr, rc,
                 "ArgsParamCount() failed in $(func)", "func=%s", __func__ ) );
    }
    else if ( count > 0 )
    {
        for ( idx = 0; idx < count && rc == 0; ++idx )
        {
            const char *value = NULL;
            rc = ArgsParamValue( args, idx, &value );
            if ( rc != 0 )
            {
                PLOGERR( klogErr, ( klogErr, rc,
                         "ArgsParamValue( $(idx) ) failed in $(func)", "idx=%d,func=%s", idx, __func__ ) );
            }
            else if ( value != NULL )
                rc = add_tool_options_path( options, value );
        }
    }

    options->main_function = tf_unknown;
    options->detailed = get_bool_option( args, OPTION_DETAIL );
	options->tstzero = get_bool_option( args, OPTION_TSTZERO );
    options->remove_dirs = get_bool_option( args, OPTION_REMDIR );

    if ( get_bool_option( args, OPTION_CREPORT ) )
        options->main_function = tf_report;
    else if ( get_bool_option( args, OPTION_RREPORT ) )
        options->main_function = tf_rreport;
    else if ( get_bool_option( args, OPTION_UNLOCK ) )
        options->main_function = tf_unlock;
    else if ( get_bool_option( args, OPTION_CLEAR ) )
        options->main_function = tf_clear;
    else
    {
        options->category = get_repo_select( args, OPTION_ENABLE );
        if ( options->category != krepBadCategory )
            options->main_function = tf_enable;

        if ( options->category == krepBadCategory )
        {
            options->category = get_repo_select( args, OPTION_DISABLE );
            if ( options->category != krepBadCategory )
                options->main_function = tf_disable;
        }
    }

    if ( rc == 0 )
        rc = get_user_repo_name( args, &options->user_repo_name );
    if ( rc == 0 )
        rc = get_max_remove( args, &options->max_remove );
    return rc;
}
示例#6
0
文件: reref.c 项目: mariux/sratoolkit
rc_t report_on_reference( Args * args, bool extended )
{
    uint32_t count;
    rc_t rc = ArgsParamCount( args, &count );
    if ( rc != 0 )
    {
        LOGERR( klogInt, rc, "ArgsParamCount() failed" );
    }
    else
    {
        KDirectory *dir; 
        rc = KDirectoryNativeDir( &dir );
        if ( rc != 0 )
        {
            LOGERR( klogInt, rc, "KDirectoryNativeDir() failed" );
        }
        else
        {
            const VDBManager *vdb_mgr;
            rc = VDBManagerMakeRead ( &vdb_mgr, dir );
            if ( rc != 0 )
            {
                LOGERR( klogInt, rc, "VDBManagerMakeRead() failed" );
            }
            else
            {
                VFSManager * vfs_mgr;
                rc =  VFSManagerMake ( &vfs_mgr );
                if ( rc != 0 )
                {
                    (void)LOGERR( klogErr, rc, "cannot make vfs-manager" );
                }
                else
                {
                    uint32_t idx;
                    for ( idx = 0; idx < count && rc == 0; ++idx )
                    {
                        const char *param = NULL;
                        rc = ArgsParamValue( args, idx, &param );
                        if ( rc != 0 )
                        {
                            LOGERR( klogInt, rc, "ArgsParamvalue() failed" );
                        }
                        else
                        {
                            /* rc value not used, because it can be something that has no references */
                            report_references( vdb_mgr, vfs_mgr, param, extended );
                        }
                    }
                    VFSManagerRelease ( vfs_mgr );
                }
                VDBManagerRelease( vdb_mgr );
            }
            KDirectoryRelease( dir );
        }
    }
    return rc;
}
示例#7
0
rc_t report_deletes( Args * args, uint32_t min_len )
{
    uint32_t count;
    rc_t rc = ArgsParamCount( args, &count );
    if ( rc != 0 )
    {
        LOGERR( klogInt, rc, "ArgsParamCount() failed" );
    }
    else
    {
        KDirectory *dir; 
        rc = KDirectoryNativeDir( &dir );
        if ( rc != 0 )
        {
            LOGERR( klogInt, rc, "KDirectoryNativeDir() failed" );
        }
        else
        {
            const VDBManager *vdb_mgr;
            rc = VDBManagerMakeRead ( &vdb_mgr, dir );
            if ( rc != 0 )
            {
                LOGERR( klogInt, rc, "VDBManagerMakeRead() failed" );
            }
            else
            {
                VFSManager * vfs_mgr;
                rc =  VFSManagerMake ( &vfs_mgr );
                if ( rc != 0 )
                {
                    (void)LOGERR( klogErr, rc, "cannot make vfs-manager" );
                }
                else
                {
                    uint32_t idx;
                    for ( idx = 0; idx < count && rc == 0; ++idx )
                    {
                        const char *param = NULL;
                        rc = ArgsParamValue( args, idx, (const void **)&param );
                        if ( rc != 0 )
                        {
                            LOGERR( klogInt, rc, "ArgsParamvalue() failed" );
                        }
                        else
                        {
                            rc = report_deletes_spec( vdb_mgr, vfs_mgr, param, min_len );
                        }
                    }
                    VFSManagerRelease ( vfs_mgr );
                }
                VDBManagerRelease( vdb_mgr );
            }
            KDirectoryRelease( dir );
        }
    }
    return rc;
}
示例#8
0
static rc_t populate_tool_ctx( tool_ctx_t * tool_ctx, const Args * args )
{
    rc_t rc = ArgsParamValue( args, 0, ( const void ** )&( tool_ctx -> accession_path ) );
    if ( rc != 0 )
        ErrMsg( "ArgsParamValue() -> %R", rc );
    else
    {
        tool_ctx -> lookup_filename[ 0 ] = 0;
        tool_ctx -> index_filename[ 0 ] = 0;
        tool_ctx -> dflt_output[ 0 ] = 0;
    
        get_user_input( tool_ctx, args );
        encforce_constrains( tool_ctx );
        get_environment( tool_ctx );
        
        rc = make_temp_dir( &tool_ctx -> temp_dir,
                          tool_ctx -> requested_temp_path,
                          tool_ctx -> dir );
    }
    
    if ( rc == 0 )
        rc = handle_accession( tool_ctx );
    
    if ( rc == 0 )
        rc = handle_lookup_path( tool_ctx );
    
    if ( rc == 0 && tool_ctx -> output_dirname != NULL )
    {
        if ( !dir_exists( tool_ctx -> dir, "%s", tool_ctx -> output_dirname ) )
            rc = create_this_dir_2( tool_ctx -> dir, tool_ctx -> output_dirname, true );
    }
    
    if ( rc == 0 )
    {
        if ( tool_ctx -> output_filename == NULL )
        {
            if ( tool_ctx -> output_dirname == NULL )
                rc = make_output_filename_from_accession( tool_ctx );
            else
                rc = make_output_filename_from_dir_and_accession( tool_ctx );
        }
        else
        {
            if ( tool_ctx -> output_dirname == NULL )
                rc = adjust_output_filename( tool_ctx );
            else
                rc = adjust_output_filename_by_dir( tool_ctx );
        }
    }
    
    if ( rc == 0 )
        rc = Make_FastDump_Cleanup_Task ( &( tool_ctx -> cleanup_task ) ); /* cleanup_task.c */
    if ( rc == 0 )
        rc = Add_Directory_to_Cleanup_Task ( tool_ctx -> cleanup_task, 
                get_temp_dir( tool_ctx -> temp_dir ) );
    return rc;
}
示例#9
0
static rc_t gather_options( const Args * args, struct sra_seq_count_options * options )
{
	rc_t rc;

	memset ( options, 0, sizeof *options );
	rc = get_str_option( args, OPTION_ID_ATTR, &options->id_attrib, DEFAULT_ID_ATTR );
	if ( rc == 0 )
		rc = get_str_option( args, OPTION_FEATURE_TYPE, &options->feature_type, DEFAULT_FEATURE_TYPE );
	if ( rc == 0 )
	{
		const char * mode;
		rc = get_str_option( args, OPTION_MODE, &mode, "norm" );
		if ( rc == 0 )
		{
			if ( mode[ 0 ] == 'd' && mode[ 1 ] == 'e' && mode[ 2 ] == 'b' && mode[ 3 ] == 'u' &&
				 mode[ 4 ] == 'g' && mode[ 5 ] == 0 )
			{
				options -> output_mode = SSC_MODE_DEBUG;
			}
		}
	}
	
	if ( rc == 0 )
	{
		uint32_t count;
		rc = ArgsParamCount( args, &count );
		if ( rc == 0 )
		{
			if ( count == 2 )
			{
				rc = ArgsParamValue( args, 0, (const void **)&options->sra_accession );
				if ( rc == 0 )
					rc = ArgsParamValue( args, 1, (const void **)&options->gtf_file );
				if ( rc == 0 )
					options -> valid = true;
			}
			else
			{
				UsageSummary ( UsageDefaultName );
			}
		}
	}
	return rc;
}
示例#10
0
static rc_t ParamsGetNextParam(Params* prm, const char** param) {
    rc_t rc = 0;
    assert(prm && param);
    *param = NULL;
    if (prm->argsParamIdx < prm->argsParamCnt) {
        rc = ArgsParamValue(prm->args, prm->argsParamIdx++, param);
        if (rc)
        {   LOGERR(klogErr, rc, "Failure retrieving query"); }
    }
    return rc;
}
示例#11
0
static void append_str_arguments( const Args *my_args, VNamelist *dst )
{
    uint32_t count;
    rc_t rc = ArgsParamCount( my_args, &count );
    if ( ( rc == 0 )&&( count > 0 ) )
    {
        uint32_t idx;
        for ( idx=0; idx<count; ++idx )
        {
            const char* s;
            if ( ArgsParamValue( my_args, idx, (const void **)&s ) == 0 )
                VNamelistAppend( dst, s );
        }
    }
}
示例#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
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;
}
示例#14
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;
}
示例#15
0
rc_t CC KMain ( int argc, char *argv [] )
{
    XMLLogger const *xlogger = NULL;
    Args * args;
    rc_t rc;
    bool any_failed = false;
    CheckCorruptConfig config = { -1.0, SA_TABLE_LOOKUP_LIMIT, -1.0, SEQ_TABLE_LOOKUP_LIMIT, PA_LONGER_SA_LIMIT, 0 };

    KLogLevelSet(klogInfo);

    rc = ArgsMakeAndHandle (&args, argc, argv, 2, Options,
                            sizeof (Options) / sizeof (Options[0]),
                            XMLLogger_Args, XMLLogger_ArgsQty);
    if (rc)
        LOGERR (klogInt, rc, "failed to parse command line parameters");
    else
    {
        rc = XMLLogger_Make(&xlogger, NULL, args);
        if (rc)
            LOGERR (klogInt, rc, "failed to make xml logger");
        else
        {
            rc = parseArgs ( args, &config );
            if (rc == 0)
            {
                uint32_t pcount;
                rc = ArgsParamCount ( args, &pcount );
                if (rc)
                    LOGERR (klogInt, rc, "ArgsParamCount() failed");
                else
                {
                    if ( pcount == 0 )
                        LOGMSG (klogErr, "no accessions were passed in");
                    else
                    {
                        for ( uint32_t i = 0; i < pcount; ++i )
                        {
                            const char * accession;
                            rc = ArgsParamValue ( args, i, (const void **)&accession );
                            if (rc)
                            {
                                PLOGERR (klogInt, (klogInt, rc, "failed to get $(PARAM_I) accession from command line", "PARAM_I=%d", i));
                                any_failed = true;
                            }
                            else
                            {
                                if (!checkAccession ( accession, &config ))
                                    any_failed = true;
                            }
                        }

                        if (!any_failed)
                            LOGMSG (klogInfo, "All accessions are good!");
                    }
                }
            }
            XMLLogger_Release(xlogger);
        }
        ArgsWhack ( args );
    }
    return rc != 0 || any_failed ? 1 : 0;
}
示例#16
0
rc_t CC KMain(int argc, char* argv[]) {
    rc_t rc = 0;
    Args* args = NULL;

    Params prm;
    memset(&prm, 0, sizeof prm);

    do {
        uint32_t pcount = 0;

        rc = ArgsMakeAndHandle(&args, argc, argv, 1,
            Options, sizeof Options / sizeof (OptDef));
        if (rc) {
            LOGERR(klogErr, rc, "While calling ArgsMakeAndHandle");
            break;
        }
        rc = ArgsParamCount(args, &pcount);
        if (rc) {
            LOGERR(klogErr, rc, "While calling ArgsParamCount");
            break;
        }
        if (pcount < 1) {
            MiniUsage(args);
            DESTRUCT(Args, args);
            exit(1);
            break;
        }
        if (pcount > 1) {
            rc = RC(rcExe, rcArgv, rcParsing, rcParam, rcAmbiguous);
            LOGERR(klogErr, rc, "Too many database parameters");
            break;
        }
        rc = ArgsParamValue(args, 0, &prm.dbPath);
        if (rc) {
            LOGERR(klogErr, rc, "Failure retrieving database name");
            break;
        }

        rc = ArgsOptionCount (args, OPTION_ALL, &pcount);
        if (rc) {
            LOGERR(klogErr, rc, "Failure to get '" OPTION_ALL "' argument");
            break;
        }
        if (pcount)
        {   prm.paramBamHeader = prm.paramQuality = prm.paramRef = true; }

        rc = ArgsOptionCount (args, OPTION_BAM, &pcount);
        if (rc) {
            LOGERR(klogErr, rc, "Failure to get '" OPTION_BAM "' argument");
            break;
        }
        if (pcount)
        {   prm.paramBamHeader = true; }

        rc = ArgsOptionCount (args, OPTION_QUA, &pcount);
        if (rc) {
            LOGERR(klogErr, rc, "Failure to get '" OPTION_QUA "' argument");
            break;
        }
        if (pcount)
        {   prm.paramQuality = true; }

        rc = ArgsOptionCount (args, OPTION_REF, &pcount);
        if (rc) {
            LOGERR(klogErr, rc, "Failure to get '" OPTION_REF "' argument");
            break;
        }
        if (pcount)
        {   prm.paramRef = true; }

        if (!prm.paramBamHeader && !prm.paramQuality && !prm.paramRef)
        {   prm.paramRef = true; }
    } while (false);

    if (rc == 0)
    {   rc = align_info(&prm); }

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

    rc = ArgsMakeAndHandle (&args, argc, argv, 0 /*1, Options, sizeof Options / sizeof (&Options[1])*/);
    if (rc)
    {
        LOGERR (klogInt, rc, "Failed to parse parameters");
        return rc;
    }
    else
    {
        do
        {
            param_block pb;
            uint32_t pcount;

            rc = ArgsParamCount (args, &pcount);
            if (rc)
            {
                LOGERR (klogInt, rc, "Failed to get paramater count");
                break;
            }
            switch (pcount)
            {
            default:
                rc = MiniUsage (args);
                goto bailout;
                
            case 2:
                pb.schema_path = SCHEMASPEC;
                break;

            case 3:
                pb.schema_path = NULL;
                break;
            }
        
            rc = ArgsParamValue (args, 0, (const void **)&pb.file_path);
            if (rc)
            {
                LOGERR (klogInt,rc, "Failed to get file path");
                break;
            }

            rc = ArgsParamValue (args, 1, (const void **)&pb.table_path);
            if (rc)
            {
                LOGERR (klogInt,rc, "Failed to get table path");
                break;
            }
            if (pb.schema_path == NULL)
            {
                rc = ArgsParamValue (args, 2, (const void **)&pb.schema_path);
                if (rc)
                {
                    LOGERR (klogInt,rc, "Failed to get schema path");
                    break;
                }
            }
            rc = open (&pb);

        } while (0);
    bailout:
        ArgsWhack (args);
    }
    if (rc)
        LOGERR (klogFatal, rc, "Failed!");
    else
        KStsMsg("Exit success %R");


    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
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;
}
示例#21
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;
}
示例#22
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;
}
示例#23
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)
    {
        do 
        {
            uint32_t pcount;

            rc = ArgsParamCount (args, &pcount);
            if (rc)
                break;

            switch (pcount)
            {
            case 0:
                MiniUsage (args);
                rc = 1;
                break;

            case 1:
                rc = RC (rcExe, rcNoTarg, rcParsing, rcParam, rcNotFound);
                LOGERR (klogFatal, rc, "Missing KColumn path");
                MiniUsage (args);
                break;

            default:
                rc = RC (rcExe, rcNoTarg, rcParsing, rcParam, rcExcessive);
                LOGERR (klogFatal, rc, "Too many parameters");
                MiniUsage (args);
                break;

            case 2:
                break;
            }
            if (rc)
            {
                if (rc == 1)
                    rc = 0;
                break;
            }

            rc = ArgsParamValue (args, 0, &G.txtpath);
            if (rc)
                break;

            rc = ArgsParamValue (args, 1, &G.colpath);
            if (rc)
                break;

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

            if (pcount != 1)
                G.begin_seen = false;
            else
            {
                const char * pc;

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

                G.begin = AsciiToU64 ( pc, ascii_to_u64_error_handler, &rc );

                if (rc)
                    break;
                G.begin_seen = true;
            }

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

            if (pcount != 1)
                G.end_seen = false;
            else
            {
                const char * pc;

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

                G.end = AsciiToU64 (pc, ascii_to_u64_error_handler, &rc);
                if (rc)
                    break;

                G.end_seen = true;
            }


            if (G.begin_seen && G.end_seen && (G.end < G.begin))
            {
                rc = RC (rcExe, rcNoTarg, rcAccessing, rcParam, rcInvalid);
                LOGERR (klogFatal, rc, "Conflicting options end before begin");
                break;
            }

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

            G.force = (pcount != 0);

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

            G.append = (pcount != 0);

            if (G.force && G.append)
            {
                rc = RC (rcExe, rcNoTarg, rcAccessing, rcParam, rcInvalid);
                LOGERR (klogFatal, rc, "Conflicting options force and append");
                break;
            }

            /* handle the KFS interface */
            rc = txt2kdb_kfs();

            if (rc == 0)
                rc = txt2kdb_io();

            txt2kdb_release();


        } while (0);
        ArgsWhack (args);
    }

    STSMSG (1, ("exit txt2kdb %R\n", rc));
    return rc;
}
示例#24
0
static rc_t CmdLineInit(const Args* args, CmdLine* cmdArgs)
{
    rc_t rc = 0;

    assert(args && cmdArgs);

    memset(cmdArgs, 0, sizeof *cmdArgs);

    while (rc == 0) {
        uint32_t pcount = 0;

        /* file path parameter */
        rc = ArgsOptionCount(args, OPTION_FILE, &pcount);
        if (rc) {
            LOGERR(klogErr, rc, "Failure parsing file name");
            break;
        }
        if (pcount < 1) {
            rc = RC(rcExe, rcArgv, rcParsing, rcParam, rcInsufficient);
            LOGERR(klogErr, rc, "Missing file parameter");
            break;
        }
        if (pcount > 1) {
            rc = RC(rcExe, rcArgv, rcParsing, rcParam, rcAmbiguous);
            LOGERR(klogErr, rc, "Too many file parameters");
            break;
        }
        rc = ArgsOptionValue (args, OPTION_FILE, 0, &cmdArgs->file);
        if (rc) {
            LOGERR(klogErr, rc, "Failure retrieving file name");
            break;
        }

        /* table path parameter */
        rc = ArgsParamCount(args, &pcount);
        if (rc) {
            LOGERR(klogErr, rc, "Failure parsing table name");
            break;
        }
        if (pcount < 1) {
            rc = RC(rcExe, rcArgv, rcParsing, rcParam, rcInsufficient);
            LOGERR(klogErr, rc, "Missing table parameter");
            break;
        }
        if (pcount > 1) {
            rc = RC(rcExe, rcArgv, rcParsing, rcParam, rcAmbiguous);
            LOGERR(klogErr, rc, "Too many table parameters");
            break;
        }
        rc = ArgsParamValue(args, 0, &cmdArgs->table);
        if (rc) {
            LOGERR(klogErr, rc, "Failure retrieving table name");
            break;
        }

        break;
    }

    if (rc != 0) {
        MiniUsage (args);
    }

    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
/*  ----------------------------------------------------------------------
 * KMain
 *
 * Figure out what is on the command line
 */
rc_t KMain ( int argc, char *argv [] )
{
    Args * args;
    rc_t rc;

    rc = ArgsMakeAndHandle (&args, argc, argv, 1, Options, sizeof Options / sizeof (OptDef));
    if (rc == 0)
    {
        /* use do {} while; for easy outs */
        do
        {
            const char * pc;
            uint32_t pcount;

            rc = ArgsProgram (args, &full_path, &program_name);
            if (rc)
            {
                PLOGERR (klogFatal,
                         (klogFatal, rc,  "failed to set name to $'(N)'",
                          "N=%s", program_name));
                break;
            }

            rc = ArgsOptionCount (args, OPTION_FORCE, &pcount);
            if (rc)
            {
                LOGERR (klogFatal, rc, "failed to check force option");
                break;
            }
            if (pcount)
            {
                options.force = true;
                options.cm = kcmParents | kcmInit;
            }
            else
            {
                options.force = true;
                options.cm = kcmParents | kcmCreate;
            }

            rc = ArgsOptionCount (args, OPTION_XML, &pcount);
            if (rc)
            {
                LOGERR (klogFatal, rc, "failed to check XML option");
                break;
            }
            if (pcount)
            {
                rc = ArgsOptionValue (args, OPTION_XML, 0, (const void **)&options.xmlstr);
                if (rc)
                {
                    LOGERR (klogFatal, rc, "failed to get XML value");
                    break;
                }
            }
            else
            {
                rc = RC (rcExe, rcArgv, rcParsing, rcParam, rcNull);
                LOGERR (klogFatal, rc, "missing required copycat-xml option");
                MiniUsage(args);
                break;
            }

            rc = ArgsOptionCount (args, OPTION_DIR, &pcount);
            if (rc)
            {
                LOGERR (klogFatal, rc, "failed to check directory option");
                break;
            }
            if (pcount)
            {
                rc = ArgsOptionValue (args, OPTION_DIR, 0, (const void **)&options.dirstr);
                if (rc)
                {
                    LOGERR (klogFatal, rc, "failed to get directory value");
                    break;
                }
            }
            else
            {
                options.dirstr = ".";
            }


            rc = ArgsParamCount (args, &pcount);
            if (rc)
            {
                LOGERR (klogFatal, rc, "failed to count parameters");
                break;
            }
            if (pcount == 0)
            {
                rc = RC ( rcExe, rcArgv, rcReading, rcParam, rcInsufficient );
                LOGERR (klogFatal, rc, "Missing archive parameter");
                MiniUsage (args);
                break;
            }

            {
                uint32_t block;

                block = 1;
                if (pcount > 2)
                    block = pcount - 1;

                VectorInit (&options.pathstr, 0, block);
            }

            rc = ArgsParamValue (args, 0, (const void **)&options.arcstr);
            if (rc)
                LOGERR (klogFatal, rc, "failed to retrieve archive parameter");
            else
            {
                if (pcount == 1)
                {
                    rc = VectorAppend (&options.pathstr, NULL, ".");
                    if (rc)
                        LOGERR (klogFatal, rc, "failed to set default path parameter");
                }
                else
                {
                    uint32_t ix;

                    for (ix = 1; ix < pcount; ++ix)
                    {
                        rc = ArgsParamValue (args, ix, (const void **)&pc);
                        if (rc)
                        {
                            PLOGERR (klogFatal, 
                                     (klogFatal, rc, "unable to extract path parameter '$(K)",
                                      "K=%u", ix));
                            break;
                        }
                        rc = VectorAppend (&options.pathstr, NULL, pc);
                        if (rc)
                        {
                            PLOGERR (klogFatal, 
                                     (klogFatal, rc, "failed to add path '$(P)' to list",
                                      "P=%s", pc));
                            break;
                        }
                    }
                }
            }
            if (rc == 0)
                open_mgr_then_run();

            VectorWhack (&options.pathstr, NULL, NULL);

        } while (0);
        ArgsWhack (args);
    }                
    return rc;
}
示例#27
0
rc_t CommonMain (Args * args)
{
    rc_t rc;
    uint32_t ocount; /* we take the address of ocount but not pcount. */
    uint32_t pcount; /* does that help the compiler optimize? */

    rc = ArgsParamCount (args, &ocount);
    if (rc)
        LOGERR (klogInt, rc, "failed to count parameters");

    else if ((pcount = ocount) == 0)
        MiniUsage (args);

    else if (pcount > 2)
    {
        LOGERR (klogErr, rc, "too many parameters");
        MiniUsage(args);
    }

    else
    {
        const char * dst; /* we only take the address of one of these */
        const char * src;

        rc = ArgsOptionCount (args, OPTION_FORCE, &ocount);
        if (rc)
            LOGERR (klogInt, rc, "failed to examine force option");

        else
        {
            ForceFlag = (ocount > 0);

            /* -----
             * letting comp put src in register
             * only if it wants
             */
            rc = ArgsParamValue (args, 0, &dst);
            if (rc)
                LOGERR (klogInt, rc, "Failure to fetch "
                        "source parameter");

            else
            {
                src = dst;

                if (pcount == 1)
                    dst = NULL;

                else
                {
                    rc = ArgsParamValue (args, 1, &dst);
                    if (rc)
                        LOGERR (klogInt, rc, "Failure to fetch "
                                "destination parameter");
                }

                if (rc == 0)
                    rc = StartFileSystem (src, dst);
            }
        }
    }
    return rc;
}
示例#28
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;
}
示例#29
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;

    default_log_level = KLogLevelGet();

    rc = ArgsMakeAndHandle (&args, argc, argv, 1, Options, sizeof Options / sizeof (OptDef));
    if (rc == 0)
    {
        do
        {
            srakar_parms pb;
            KDirectory * pwd;
            const char * name;
            uint32_t pcount;
            char archive_name [256];

            rc = KDirectoryNativeDir (&pwd);
            if (rc)
                break;

            pb.lite = false;
            pb.force = false;
            pb.dir = pwd;

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

            if (pcount == 1)
            {
                STSMSG (1, ("Using lite option"));
                pb.lite = true;
            }

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

            if (pcount == 1)
            {
                STSMSG (1, ("Using force option"));
                pb.force = true;
            }
#endif
            rc = ArgsParamCount (args, &pcount);
            if (rc)
                break;

            if (pcount == 0)
            {
                KOutMsg ("missing source table\n");
                rc = MiniUsage (args);
                break;
            }
            else if (pcount > 2)
            {
                KOutMsg ("Too many parameters\n");
                rc = MiniUsage (args);
                break;
            }

            rc = ArgsParamValue (args, 0, &pb.src_path);
            if (rc)
            {
                KOutMsg ("failure to get source path/name\n");
                break;
            }

            pb.dst_path = archive_name;

            name = string_rchr (pb.src_path, string_size (pb.src_path), '/');
            if (name == NULL)
                name = pb.src_path;

            if (pcount == 1)
            {
                size_t size;

                rc = string_printf (archive_name, sizeof (archive_name), & size,
                                 "%s%s", name, pb.lite ? ".lite.sra" : ".sra");
                if ( rc != 0 )
                {
                    rc = RC (rcExe, rcArgv, rcParsing, rcPath, rcInsufficient);
                    PLOGERR (klogFatal, (klogFatal, rc, "Failure building archive name $(P)", "P=%s", archive_name));
                    break;
                }
            }
            else
            {
                rc = ArgsParamValue (args, 1, &pb.dst_path);
                if (rc)
                {
                    LOGERR (klogInt, rc, "failure to get destination path");
                    break;
                }
            }

            if (rc == 0)
            {
                KPathType kpt;

                kpt = KDirectoryPathType (pwd, "%s", pb.dst_path);

                switch (kpt & ~kptAlias)
                {
                case kptNotFound:
                    /* found nothing so assume its a valid new file name
                     * not gonna tweak extensions at this point but that can be upgraded */
                    break;
                case kptFile:
                    /* got a file name, use it  - would need force... */
                    if (pb.force == false)
                    {
                        rc = RC (rcExe, rcArgv, rcParsing, rcPath, rcBusy);
                        PLOGERR (klogFatal, (klogFatal, rc, 
                                             "Output file already exists $(P)",
                                             "P=%s", archive_name));
                    }
                    break;

                case kptDir:
                {
                    size_t size;

                    rc = string_printf (archive_name, sizeof (archive_name), & size,
                                     "%s/%s%s", pb.dst_path, name, pb.lite ? ".lite.sra" : ".sra");
                    if ( rc != 0 )
                    {
                        rc = RC (rcExe, rcArgv, rcParsing, rcPath, rcInsufficient);
                        PLOGERR (klogFatal, (klogFatal, rc, "Failure building archive name $(P)", "P=%s", archive_name));
                        break;
                    }
                    pb.dst_path = archive_name;
                    break;
                }
                default:
                    rc = RC (rcExe, rcArgv, rcParsing, rcPath, rcInvalid);
                    break;
                }
                if (rc == 0)
                {
                    STSMSG (1,("Creating archive (%s) from table (%s)\n", pb.dst_path, pb.src_path));

                    rc = run (&pb);
                    STSMSG (5, ("Run exits with %d %R\n", rc, rc));
                }
            }

        } while (0);
    }
    STSMSG (1, ("Exit status %u %R", rc, rc));
    return rc;
}
示例#30
0
rc_t KMain(int argc, char *argv[])
{
    rc_t rc = 0;
    Args* args = NULL;
    const char* errmsg = NULL, *table_dir = NULL;
    char accn[1024];
    
    if( (rc = ArgsMakeAndHandle(&args, argc, argv, 1, MainArgs, MainArgsQty)) == 0 ) {
        const char* blksz = NULL;
        uint32_t count, dump = 0, gzip = 0;

        if( (rc = ArgsParamCount(args, &count)) != 0 || count != 1 ) {
            rc = rc ? rc : RC(rcExe, rcArgv, rcParsing, rcParam, count > 1 ? rcExcessive : rcInsufficient);
            errmsg = "table";

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

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

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

        } else if( (rc = ArgsOptionCount(args, MainArgs[eopt_noGzip].name, &gzip)) != 0 ) {
            errmsg = MainArgs[eopt_noGzip].name;
        }
        while( rc == 0 ) {
            long val = 0;
            char* end = NULL;

            if( blksz != NULL ) {
                errno = 0;
                val = strtol(blksz, &end, 10);
                if( errno != 0 || blksz == end || *end != '\0' || val <= 0 ) {
                    rc = RC(rcExe, rcArgv, rcReading, rcParam, rcInvalid);
                    errmsg = MainArgs[eopt_BlockSize].name;
                    break;
                } else if( val <= 128 || val > (1024 * 1024 * 1024) ) {
                    rc = RC(rcExe, rcArgv, rcValidating, rcParam, rcEmpty);
                    errmsg = "block size invalid";
                    break;
                }
                g_file_block_sz = val;
            }
            if( (rc = ArgsParamValue(args, 0, (const void **)&table_dir)) != 0 ) {
                errmsg = "table";
                break;
            }
            if( g_accession == NULL ) {
                const char* p = strchr(table_dir, '/');
                size_t l = 0;

                g_accession = accn;
                if( p == NULL ) {
                    p = strchr(table_dir, '\\');
                }
                strncpy(accn, p == NULL ? table_dir : p + 1, sizeof(accn) - 1);
                if( accn[0] == '\0' ) {
                    rc = RC(rcExe, rcArgv, rcValidating, rcParam, rcEmpty);
                    errmsg = "accession";
                }
                l = strlen(accn);
                if( accn[l - 1] == '/' || accn[l - 1] == '\\') {
                    accn[--l] = '\0';
                }
                if( strncmp(&accn[l - 9], ".lite.sra", 9) == 0 ) {
                    accn[l - 9] = '\0';
                } else if( strncmp(&accn[l - 4], ".sra", 4) == 0 ) {
                    accn[l - 4] = '\0';
                }
            }
            g_dump = dump > 0;
            g_ungzip = gzip > 0;
            break;
        }
    }
    if( rc == 0 ) {
        SRAMgr* smgr = NULL;
        KDBManager* kmgr = NULL;

        DEBUG_MSG(5, ("table %s, accession %s\n", table_dir, g_accession));
        if( (rc = SRAMgrMakeUpdate(&smgr, NULL)) == 0 ) {
            if( (rc = KDBManagerMakeUpdate(&kmgr, NULL)) == 0 ) {
                bool relock = true;
                if( (rc = KDBManagerUnlock(kmgr, table_dir)) != 0 ) {
                    relock = false;
                    rc = GetRCState(rc) == rcUnlocked ? 0 : rc;
                } else {
                    PLOGMSG(klogInfo, (klogInfo, "Table $(p) locked, unlocking", PLOG_S(p), table_dir));
                }
                if( rc == 0 ) {
                    KTable* ktbl = NULL;
                    if( (rc = KDBManagerOpenTableUpdate(kmgr, &ktbl, table_dir)) == 0 ) {
                        KMetadata* meta = NULL;
                        if( (rc = KTableOpenMetadataUpdate(ktbl, &meta)) == 0 ) {
                            const SRATable* stbl = NULL;
                            if( (rc = SRAMgrOpenTableRead(smgr, &stbl, table_dir)) == 0 ) {
                                rc = MakeIndexes(stbl, ktbl, meta);
                                SRATableRelease(stbl);
                            }
                        }
                        KMetadataRelease(meta);
                    }
                    KTableRelease(ktbl);
                }
                if( rc == 0 && relock ) {
                    rc = KDBManagerLock(kmgr, table_dir);
                }
                KDBManagerRelease(kmgr);
            }
            SRAMgrRelease(smgr);
        }
    }
    if( rc != 0 && rc != KLogLastErrorCode() ) {
        if( errmsg ) {
            Usage(args);
        }
        LOGERR(klogErr, rc, errmsg ? errmsg : "stop");
    }
    ArgsWhack(args);
    return rc;
}