Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
tree: 77e17fae9e
Fetching contributors…

Cannot retrieve contributors at this time

87 lines (72 sloc) 2.435 kb
#include <sstream>
#include <iostream>
#include <fstream>
#include <cctype>
#include <cmath>
#include "Driver.h"
#include "skipList.h"
#define LINES_PER_PAGE 40.0
using namespace std;
int main(int argc, char *argv[])
{
if (argc != 3) {
std::cout << "usage: ./index source target" << std::endl;
exit(-1);
}
skipList *index = skipCreate();
int lines = 0;
string word, line;
ifstream inFile;
inFile.open(argv[1]);
if (inFile.is_open()) {
while (!inFile.eof()) {
getline(inFile, line);
lines++;
istringstream iss(line, istringstream::in);
while(iss >> word) {
trim(&word);
string::iterator it;
for (it = word.begin();
it != word.end(); it++) {
if(isalpha(*it) && isupper(*it))
(*it) = tolower((*it));
}
if (word.begin() != word.end())
skipInsert(index, word.c_str(), getpage(lines));
}
}
inFile.close();
}
std::ofstream out(argv[2]);
skipPrint(out, index);
}
void trim(string *word)
{
string::iterator it;
// trim non-alphas off the beginning
for (it = (*word).begin(); it != (*word).end(); it++) {
if (isalpha(*it)) {
(*word).erase((*word).begin(), it);
break;
}
if (it == (*word).end()) {
(*word).clear();
break;
}
}
// trim non-alphas off the end
for (it = (*word).end() - 1;; it--) {
if (isalpha(*it)) {
(*word).erase(it+1, (*word).end());
break;
}
if (it == (*word).begin()) {
(*word).clear();
break;
}
}
}
int getpage(int lines)
{
return (ceil(lines/LINES_PER_PAGE));
}
Jump to Line
Something went wrong with that request. Please try again.