Commits

Anonymous committed 04f23e4

more cleanup

  • Participants
  • Parent commits 72501ca

Comments (0)

Files changed (9)

File csvfix/inc/csved_cli.h

 	private:
 
 		Command * FindCommand();
-		Command * FindAbb( const std::string & ab );
+		Command * FindAbbrev( const std::string & ab );
 
 		int Help();
 		int HelpCmd();

File csvfix/src/csved_block.cpp

 // Are we inside or outside a block?
 //----------------------------------------------------------------------------
 
-enum State { Outside, Inside };
+enum class InOut { Outside, Inside };
 
 //----------------------------------------------------------------------------
 // Read rows and flip state depending on the return value of the begin/end
 	ProcessFlags( cmd );
 	IOManager io( cmd );
 	CSVRow row;
-	State state = Outside;
+	InOut state = InOut::Outside;
 	bool block = true;
 
 	while( io.ReadCSV( row ) ) {
-		if ( state == Outside ) {
+		if ( state == InOut::Outside ) {
 			AddVars( mBeginEx, io, row );
 			if ( AtBeginBlock() ) {
 				block = ! mExclusive;
-				state = Inside;
+				state = InOut::Inside;
 			}
 			else {
 				block = false;
 			}
 		}
-		else if ( state == Inside ) {
+		else if ( state == InOut::Inside ) {
 			AddVars( mEndEx, io, row );
 			if ( AtEndBlock() ) {
 				block = ! mExclusive;
-				state = Outside;
+				state = InOut::Outside;
 			}
 			else {
 				block = true;
 			CSVTHROW( "Invalid mark string for " << FLAG_ACTMARK );
 		}
 	}
-	if ( actions > 1  ) {
-		CSVTHROW( "Can specify only one of "
+	if ( actions != 1 ) {
+		CSVTHROW( "Need only one of "
 					<< FLAG_ACTKEEP << ", "
 					<< FLAG_ACTREM <<" or "
 					<< FLAG_ACTMARK );
 	}
-	if ( actions == 0 ) {
-		CSVTHROW( "Need one of "
-					<< FLAG_ACTKEEP << ", "
-					<< FLAG_ACTREM <<" or "
-					<< FLAG_ACTMARK );
-	}
+
 	mExclusive = cmd.HasFlag( FLAG_BLKEXC );
 }
 

File csvfix/src/csved_case.cpp

 //---------------------------------------------------------------------------
 // csved_case.cpp
 //
-// Case conversion for csvfix
+// Character case conversion for csvfix
 //
 // Copyright (C) 2009 Neil Butterworth
 //---------------------------------------------------------------------------

File csvfix/src/csved_cli.cpp

 		return mDict->Get( mCmdLine.Argv( 1 ) );
 	}
 	else {
-		Command * c = FindAbb( mCmdLine.Argv( 1 ) );
+		Command * c = FindAbbrev( mCmdLine.Argv( 1 ) );
 		if (  c == 0 ) {
 			CSVTHROW( "Unknown command - try 'csvfix help'" );
 		}
 // Find possibly abbreviated command
 //----------------------------------------------------------------------------
 
-Command * CLIHandler :: FindAbb( const  string & ab ) {
+Command * CLIHandler :: FindAbbrev( const  string & ab ) {
 	vector <string> mPossibles;
 	mDict->GetAbbreviations( ab, mPossibles );
 	if ( mPossibles.size() == 0 ) {
 //---------------------------------------------------------------------------
 
 int CLIHandler :: HelpCmd() {
-	Command * cp = FindAbb( mCmdLine.Argv(2) );
+	Command * cp = FindAbbrev( mCmdLine.Argv(2) );
 	if ( cp == nullptr ) {
 		cerr << "no such command: " << mCmdLine.Argv(2) << "\n";
 		cerr << "use 'csvfix help' to see a list of commands\n";

File csvfix/src/csved_command.cpp

 // Process help text. May contain a terminal section preceded by a # char
 // containing names of the generic flags applicable to this command. The
 // name "ALL" means the command can support all generic flags.
+//
+// ToDo: This is a mess and needs rethinking. But it does "work".
 //----------------------------------------------------------------------------
 
 const char GFL_DELIM = '#';

File csvfix/src/csved_dsv.cpp

 
 
 //----------------------------------------------------------------------------
-// Get field selimitter = default is pipe character.
+// Get field delimiter = default is pipe character.
 //----------------------------------------------------------------------------
 
 char DSVBase ::	Delim() const {
 }
 
 //---------------------------------------------------------------------------
-// Chop line up into fields seoarated by mDelim. The delimitter can be
+// Chop line up into fields seoarated by mDelim. The delimiter can be
 // escaped with a backslash. If the mCollapseSep flag is set, multiple
-// occurences of a separator are treated as a asingle one.
+// occurences of a separator are treated as a single one.
 //---------------------------------------------------------------------------
 
 void DSVReadCommand :: ParseDSV( const string & line, CSVRow & rv ) {
 }
 
 //---------------------------------------------------------------------------
-// Create field contaents, quoting any delimitter
+// Create field contaents, quoting any delimiter
 //---------------------------------------------------------------------------
 
 string DSVWriteCommand :: MakeField( const string & val ) {

File csvfix/src/csved_edit.cpp

 }
 
 //---------------------------------------------------------------------------
-// Edit single field using suncommands. Currently only the 's' command
+// Edit single field using subcommands. Currently only the 's' subcommand
 // is supported, which works like that in vi. e.g.
 //
 //		s/abc/XXX/g

File csvfix/src/csved_put.cpp

 
 
 void PutCommand :: ProcessFlags( ALib::CommandLine & cmd ) {
-	if ( cmd.HasFlag( FLAG_VAL ) == cmd.HasFlag( FLAG_VALENV ) ) {
-		CSVTHROW( "Need one of " << FLAG_VAL << " or " << FLAG_VALENV );
-	}
+
+	NotBoth( cmd, FLAG_VAL, FLAG_VALENV, ReqOp::Required );
 
 	if ( cmd.HasFlag( FLAG_VAL ) ) {
 		mValue = cmd.GetValue( FLAG_VAL, "" );

File csvfix/src/csved_readmulti.cpp

 void ReadMultiCommand :: ProcessFlags( ALib::CommandLine & cmd ) {
 
 	const unsigned int MAX_LINES = 200;	    // max allowed multi lines
-	int nf = cmd.HasFlag( FLAG_NUM ) ? 1 : 0;
-	nf += cmd.HasFlag( FLAG_SEP ) ? 1 : 0;
 
-	if ( nf == 0 ) {
-		CSVTHROW( "Need " << FLAG_NUM << " or " << FLAG_SEP << " flag" );
-	}
-	else if ( nf == 2 ) {
-		CSVTHROW( "Can have " << FLAG_NUM << " or " << FLAG_SEP
-					<< " but not both" );
-	}
+	NotBoth( cmd, FLAG_SEP, FLAG_NUM, ReqOp::Required );
 
 	if ( cmd.HasFlag( FLAG_NUM ) ) {
 		string ns = cmd.GetValue( FLAG_NUM );