Example #1
0
void DateReadCommand :: ProcessFlags( ALib::CommandLine & cmd ) {

    ALib::CommaList cl( cmd.GetValue( FLAG_COLS, "" ) );
    CommaListToIndex( cl, mFields );
    string mask = cmd.GetValue( FLAG_MASK, "" );
    string cys = cmd.GetValue( FLAG_CDATE, ALib::Str( BASE_YEAR ) );

    NotBoth( cmd, FLAG_BDLIST, FLAG_BDEXCL );

    if ( cmd.HasFlag( FLAG_BDLIST )  ) {
        mWriteAction = WriteBad;
    }
    else if ( cmd.HasFlag( FLAG_BDEXCL ) ) {
        mWriteAction = WriteGood;
    }
    else {
        mWriteAction = WriteAll;
    }

    if  ( ! ALib::IsInteger( cys )) {
        CSVTHROW( "Invalid year value " << cys );

    }
    int cy = ALib::ToInteger( cys );
    string mnames = cmd.GetValue( FLAG_MNAMES, MONTH_NAMES );
    delete mReader;
    mReader = new MaskedDateReader( mask, mnames, cy );
}
Example #2
0
int TrimCommand ::	Execute( ALib::CommandLine & cmd ) {

    GetSkipOptions( cmd );
    if ( cmd.HasFlag( FLAG_TRLEAD ) || cmd.HasFlag( FLAG_TRTRAIL ) ) {
        mTrimLead = cmd.HasFlag( FLAG_TRLEAD );
        mTrimTrail = cmd.HasFlag( FLAG_TRTRAIL );
    }
    else {
        mTrimLead = mTrimTrail = true;
    }

    if ( cmd.HasFlag( FLAG_WIDTH ) ) {
        GetWidths( cmd.GetValue( FLAG_WIDTH ) );
    }

    ALib::CommaList cl( cmd.GetValue( FLAG_COLS, "" ) );
    CommaListToIndex( cl, mFields );

    IOManager io( cmd );
    CSVRow row;

    while( io.ReadCSV( row ) ) {
        if ( Skip( row ) ) {
            continue;
        }

        if ( ! Pass( row ) ) {
            Trim( row );
        }
        io.WriteRow( row );
    }

    return 0;
}
Example #3
0
int EditCommand :: Execute( ALib::CommandLine & cmd ) {

	GetSkipOptions( cmd );
	for ( int i = 2; i < cmd.Argc(); i++ ) {
		if ( cmd.Argv( i ) == FLAG_EDIT ) {
			AddSubCmd( cmd.Argv( i + 1 ) );
			i++;
		}
	}

	ALib::CommaList cl( cmd.GetValue( FLAG_COLS, "" ) );
	CommaListToIndex( cl, mCols );

	IOManager io( cmd );
	CSVRow row;

	while( io.ReadCSV( row ) ) {
		if ( Skip( io, row ) ) {
			continue;
		}
		if ( ! Pass( io, row ) ) {
			EditRow( row );
		}
		io.WriteRow( row );
	}

	return 0;
}
Example #4
0
void FileSplitCommand :: ProcessFlags( ALib::CommandLine & cmd ) {
	mDir = cmd.GetValue( FLAG_FSDIR, DEF_DIR );
	mFilePrefix = cmd.GetValue( FLAG_FSPRE, DEF_PREF );
	mFileExt= cmd.GetValue( FLAG_FSEXT, DEF_EXT );
	ALib::CommaList cl( cmd.GetValue( FLAG_COLS ) );
	CommaListToIndex( cl, mColIndex );
	mUseFieldNames = cmd.HasFlag( FLAG_USEFLD );
}
Example #5
0
void DateFormatCommand :: ProcessFlags( ALib::CommandLine & cmd ) {
    ALib::CommaList cl( cmd.GetValue( FLAG_COLS, "" ) );
    CommaListToIndex( cl, mFields );
    string fmt = cmd.GetValue( FLAG_FMT, "" );
    if ( ALib::IsEmpty( fmt ) ) {
        CSVTHROW( "Empty date format" );
    }
    BuildFormat( fmt );
}
Example #6
0
void RemoveNewlineCommand :: ProcessFlags( const ALib::CommandLine & cmd ) {

	string scols = cmd.GetValue( FLAG_COLS, "" );
	ALib::CommaList cl( cmd.GetValue( FLAG_COLS, "" ) );
	CommaListToIndex( cl, mFields);
	if ( cmd.HasFlag( FLAG_EXCLNL ) && cmd.HasFlag( FLAG_STR ) ) {
		CSVTHROW( "Flags " << FLAG_EXCLNL << " and " << FLAG_STR
					<< " are mutually exclusive" );
 	}
	mSep = cmd.GetValue( FLAG_STR, "" );
	ExpandSep();
	mExcludeAfter = cmd.HasFlag( FLAG_EXCLNL );
}
Example #7
0
void AsciiTableCommand :: ProcessFlags( ALib::CommandLine & cmd ) {
	mUseLineSep = cmd.HasFlag( FLAG_SEP );
	mHeadings = ALib::CommaList( cmd.GetValue( FLAG_HEADER, "" ) );
	ALib::CommaList ra = ALib::CommaList( cmd.GetValue( FLAG_RALIGN, "" ) );
	CommaListToIndex( ra, mRightAlign );

	if ( mHeadings.Size() && mHeadings.At(0) != FILE_HEADER) {
		CSVRow r;
		for ( unsigned int i = 0; i < mHeadings.Size() ; i++ ) {
			r.push_back( mHeadings.At( i ) );
		}
		AddRow( r );
	}
}
Example #8
0
void CallCommand :: ProcessFlags( const ALib::CommandLine & cmd ) {

	string bs = cmd.GetValue( FLAG_BSIZE, ALib::Str( DEF_OUTBUF_SIZE ) );
	if ( ! ALib::IsInteger( bs )) {
		CSVTHROW( "Value for buffer size must be integer" );
	}
	mOutBufSize = ALib::ToInteger( bs ) * 1024;
	if ( mOutBufSize < DEF_OUTBUF_SIZE ) {
		CSVTHROW( "Output buffer size too small" );
	}
	mDLL = cmd.GetValue( FLAG_DLL );
	mFuncName = cmd.GetValue( FLAG_FUNC );
	ALib::CommaList cl( cmd.GetValue( FLAG_COLS ) );
	CommaListToIndex( cl, mFields );

}
Example #9
0
void SQLCommand :: GetCommonValues( ALib::CommandLine & cmd ) {

	GetSkipOptions( cmd );
	mTable = cmd.GetValue( FLAG_TABLE );
	if ( mTable == "" ) {
		CSVTHROW( "Need table name specified by " << FLAG_TABLE << " flag" );
	}
	if ( ! cmd.HasFlag( FLAG_SQLSEP ) ) {
		mSep ="\n;\n";
	}
	else {
		mSep = ALib::UnEscape( cmd.GetValue( FLAG_SQLSEP ) );
	}

	string noq = cmd.GetValue( FLAG_NOQUOTE, "" );
	if ( ! ALib::IsEmpty( noq ) ) {
		CommaListToIndex( ALib::CommaList( noq ), mNoQuote );
	}
	mQuoteNulls = cmd.HasFlag( FLAG_QNULLS );
	mEmptyNulls = cmd.HasFlag( FLAG_ENULLS );
}
Example #10
0
void ExcludeCommand :: ProcessFlags( const ALib::CommandLine & cmd ) {

	NotBoth( cmd, FLAG_REVCOLS, FLAG_COLS, ReqOp::Required );

	string es = cmd.GetValue( FLAG_IF, "" );
	if ( es != "" ) {
		string emsg = mExpr.Compile( es );
		if ( emsg != "" ) {
			CSVTHROW( emsg + " " + es );
		}

	}
	mReverse = cmd.HasFlag( FLAG_REVCOLS );
	string sn = cmd.GetValue( FLAG_COLS, ""  );
	if ( sn == "" ) {
		sn = cmd.GetValue( FLAG_REVCOLS, ""  );
	}
	CommaListToIndex( ALib::CommaList( sn ), mFields );
	if ( mFields.size() == 0 ) {
		CSVTHROW( "Field list  specified by " << FLAG_COLS << " or "
						<< FLAG_REVCOLS << " cannot be empty" );
	}
}
Example #11
0
void ShuffleCommand :: ProcessFlags( const ALib::CommandLine & cmd ) {

    string sn = cmd.GetValue( FLAG_NUM, ALib::Str(INT_MAX -1) );
    if ( ! ALib::IsInteger( sn )) {
        CSVTHROW( "Value for " << FLAG_NUM << " must be integeer" );
    }

    if ( ALib::ToInteger( sn ) < 0 ) {
        CSVTHROW( "Value for " << FLAG_NUM << " must be zero or greater" );
    }
    mCount = ALib::ToInteger( sn );

    string sr = cmd.GetValue( FLAG_RSEED, "-1" );
    if ( ! ALib::IsInteger( sr ) ) {
        CSVTHROW( "Value for " << FLAG_RSEED << " must be integer" );
    }
    int n = ALib::ToInteger( sr );
    mSeed = n < 0 ? std::time(0) : n;
    if ( cmd.HasFlag( FLAG_COLS ) ) {
        ALib::CommaList cl( cmd.GetValue( FLAG_COLS ) );
        CommaListToIndex( cl, mFields );
    }
}
Example #12
0
void DSVBase ::	ReadFlags( const ALib::CommandLine & cl ) {
    string delim = cl.GetValue( FLAG_SEP, ALib::Str( DEF_DELIM ) );
    if ( delim.size() == 0 ) {
        CSVTHROW( "Separator specified by " << FLAG_SEP
                  << " cannot be empty" );
    }
    else if ( delim.size() == 1 ) {
        mDelim = delim[0];
    }
    else if ( delim.size() == 2 && delim[0] == '\\' ) {
        if ( delim[1] == 't' ) {
            mDelim = '\t';
        }
        else {
            CSVTHROW( "Bad escaped separator specified by " << FLAG_SEP );
        }
    }
    else {
        CSVTHROW( "Bad separator specified by " << FLAG_SEP );
    }

    string fields = cl.GetValue( FLAG_COLS, "" );
    CommaListToIndex( ALib::CommaList( fields ), mFields );
}
Example #13
0
void SummaryCommand :: GetFields( const ALib::CommandLine & cmd,
									const std::string & flag ) {
		ALib::CommaList cl( cmd.GetValue( flag ) );
		CommaListToIndex( cl, mFields );
}