-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from TravelMapping/master
sync, 2018-11-06
- Loading branch information
Showing
5 changed files
with
99 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,33 @@ | ||
// Travel Mapping Project, Eric Bryant, 2017, 2018 | ||
#include <fstream> | ||
#include <iostream> | ||
#include <list> | ||
using namespace std; | ||
|
||
class entry | ||
{ public: | ||
string text; | ||
bool cull; | ||
entry *prev, *next; | ||
|
||
// init alpha | ||
entry() {prev = 0; next = 0; cull = 0;} | ||
// insertions | ||
entry(entry *cursor) // cursor, in this case, is a pointer to the prev entry | ||
{ prev = cursor; | ||
next = 0; | ||
cull = 0; | ||
} | ||
}; | ||
|
||
bool find(string needle, entry *haystack) | ||
{ while (haystack) | ||
{ if (needle == haystack->text) return 1; | ||
haystack = haystack->next; | ||
} | ||
return 0; | ||
} | ||
|
||
int main(int argc, char *argv[]) | ||
{ entry *cList = new entry; | ||
entry *fList = new entry; | ||
entry *cursor; | ||
{ string FPline; | ||
if (argc != 4) { cout << "usage: ./fpcull CullFile FullFile OutputFile\n"; return 0; } | ||
// init ifstreams | ||
ifstream cFile(argv[1], ios::in); | ||
if (!cFile.is_open()) { cout << argv[1] << " file not found!\n"; return 0; } | ||
ifstream fFile(argv[2], ios::in); | ||
if (!fFile.is_open()) { cout << argv[2] << " file not found!\n"; return 0; } | ||
|
||
// create cull list | ||
cFile >> cList->text; //TODO: enclose in an IF in case hell breaks loose (IE, no text in cFile) //FIXME: see below | ||
cursor = new entry(cList); | ||
while (cFile >> cursor->text) //FIXME: This expects every line to be one text string and every text string to be one line. This will not always be the case. | ||
// For example, see line 6613 of https://github.com/TravelMapping/HighwayData/blob/d33d0f6e93eec8ce7f71f31af94336a473161e5f/datacheckfps.csv | ||
{ cursor->prev->next = cursor; | ||
cursor = new entry(cursor); | ||
} | ||
delete cursor; | ||
|
||
// create full list | ||
fFile >> fList->text; //TODO: enclose in an IF in case hell breaks loose (IE, no text in fFile) //FIXME: see below | ||
cursor = new entry(fList); | ||
while (fFile >> cursor->text) //FIXME: This expects every line to be one text string and every text string to be one line. This will not always be the case. | ||
// For example, see line 6613 of https://github.com/TravelMapping/HighwayData/blob/d33d0f6e93eec8ce7f71f31af94336a473161e5f/datacheckfps.csv | ||
{ cursor->prev->next = cursor; | ||
cursor = new entry(cursor); | ||
list<string> fList; | ||
while (getline(fFile, FPline)) fList.push_back(FPline); | ||
|
||
// read cull list... | ||
while (getline(cFile, FPline)) | ||
{ list<string>::iterator cursor = fList.begin(); | ||
// advance thru full FP list until current unmatched entry found... | ||
while (*cursor != FPline && cursor != fList.end()) cursor++; | ||
// ...and delete it. | ||
if (cursor != fList.end()) cursor = fList.erase(cursor); | ||
} | ||
delete cursor; | ||
|
||
// flag unmatchedfps as to-be-culled | ||
for (cursor = fList; cursor; cursor = cursor->next) | ||
if (find(cursor->text, cList)) cursor->cull = 1; | ||
|
||
// output | ||
ofstream oFile(argv[3]); | ||
cursor = fList; | ||
while (cursor) | ||
{ if (!cursor->cull) oFile << cursor->text << endl; | ||
cursor = cursor->next; | ||
} | ||
for (list<string>::iterator cursor = fList.begin(); cursor != fList.end(); cursor++) | ||
oFile << *cursor << '\n'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters