Skip to content

Commit

Permalink
small last-minute updates. just to satisfu CppCheck a it more
Browse files Browse the repository at this point in the history
  • Loading branch information
kosloot committed Jul 4, 2023
1 parent 8e869d3 commit 8c94663
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 34 deletions.
13 changes: 3 additions & 10 deletions src/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <glob.h>
#include <sstream>
#include <vector>
#include <numeric>

using namespace std;

Expand Down Expand Up @@ -32,19 +33,11 @@ bool strip_extension(std::string& filename, const std::string& extension) {
}

double listproduct(const vector<double> & l) {
double p = 1;
for ( const auto& iter : l ){
p *= iter;
}
return p;
return std::accumulate( l.begin(), l.end(), 1, std::multiplies<double>() );
}

double listsum(const vector<double> & l) {
double p = 0;
for ( const auto& iter: l ){
p += iter;
}
return p;
return std::accumulate( l.begin(), l.end(), 0 );
}

void orderedinsert(list<double> & l, double value) {
Expand Down
52 changes: 28 additions & 24 deletions src/grep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,31 +39,35 @@ int main( int argc, char *argv[] ) {

char c;
while ((c = getopt(argc, argv, "c:hf:i::l:r:s:")) != -1) {
switch (c) {
case 'c':
classfile = optarg;
break;
case 'f':
corpusfile = optarg;
break;
case 'i':
modelfile = optarg;
break;
case 'l':
leftcontextsize = atoi(optarg);
break;
case 'r':
rightcontextsize = atoi(optarg);
break;
case 'h':
usage();
exit(0);
default:
cerr << "ERROR: Unknown option: -" << optopt << endl;
abort ();
}
switch (c) {
case 'c':
classfile = optarg;
break;
case 'f':
corpusfile = optarg;
break;
case 'i':
modelfile = optarg;
break;
case 'l':
leftcontextsize = atoi(optarg);
break;
case 'r':
rightcontextsize = atoi(optarg);
break;
case 'h':
usage();
exit(0);
default:
cerr << "ERROR: Unknown option: -" << optopt << endl;
abort ();
}
}
if ( leftcontextsize != 0
|| rightcontextsize != 0 ){
cerr << "Sorry, options '-l' and '-r' are nor implemented yet." << endl;
abort();
}

for (int i = optind; i < argc; i++) {
string tmp = argv[i];
querystrings.push_back(tmp);
Expand Down

0 comments on commit 8c94663

Please sign in to comment.