-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New utility added to extract a list of keywords from all the source f…
…iles.
- Loading branch information
1 parent
f91e36a
commit 6ee5002
Showing
2 changed files
with
116 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
REM Because the shell is brain dead, or appears so, I need | ||
REM to pass each file individually. It cannot cope with a | ||
REM wildcard list of files such as Keywords*.clean.rst. Sigh. | ||
REM | ||
for %%f in (Keywords*.clean.rst) do @extractKeywords %%f |
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 |
---|---|---|
@@ -0,0 +1,111 @@ | ||
#include <iostream> | ||
#include <fstream> | ||
#include <iomanip> | ||
#include <string> | ||
#include <list> | ||
|
||
// | ||
// extractKeywords <list_of_files> | ||
// | ||
// This program will read the list of files and for each one found, | ||
// will extract all the keywords. | ||
// | ||
// Keywords are found as follows, in the source files: | ||
// | ||
// Keyword_name | ||
// ============ | ||
// | ||
// It's the double underline that indicates a keyword. There are some that we | ||
// might not want, like TODO for example, so that/those will be filtered out. | ||
// | ||
|
||
using std::string; | ||
using std::getline; | ||
using std::cin; | ||
using std::cout; | ||
using std::endl; | ||
using std::setw; | ||
using std::fill; | ||
using std::list; | ||
using std::ifstream; | ||
|
||
|
||
// Things I need to ignore if found as headings. | ||
string lookFor[] = {"TODO", | ||
"Keywords A", "Keywords B", "Keywords C", "Keywords D", | ||
"Keywords E", "Keywords F", "Keywords G", "Keywords H", | ||
"Keywords I", "Keywords J", "Keywords J", "Keywords L", | ||
"Keywords M", "Keywords N", "Keywords O", "Keywords P", | ||
"Keywords Q", "Keywords R", "Keywords S", "Keywords T", | ||
"Keywords U", "Keywords V", "Keywords W", "Keywords X", | ||
"Keywords Y", "Keywords Z", "Keywords Other" | ||
}; | ||
|
||
// Map the above into a string list. | ||
list<string> lookForThese(lookFor, lookFor + sizeof(lookFor) / sizeof(string)); | ||
|
||
// Globals. Yes, I know... | ||
string this_line; | ||
string last_line; | ||
|
||
void doFile(const char *fname); | ||
void doKeywords(); | ||
|
||
|
||
int main (int argc, char *argv[]) | ||
{ | ||
for (int x = 1; x < argc; x++) { | ||
doFile(argv[x]); | ||
} | ||
return 0; | ||
} | ||
|
||
|
||
void doFile(const char *fname) | ||
{ | ||
// Open a file, read it, extract the keywords. | ||
|
||
bool firstLine = true; | ||
|
||
ifstream ifs (fname, std::ifstream::in); | ||
while (ifs.good()) { | ||
getline(ifs, this_line); | ||
if (!firstLine) { | ||
if (!this_line.empty()) { | ||
if (this_line.at(0) == '=') { | ||
// We have a Keyword in last_line | ||
doKeywords(); | ||
} | ||
} | ||
} else { | ||
firstLine = false; | ||
} | ||
|
||
last_line = this_line; | ||
} | ||
|
||
ifs.close(); | ||
} | ||
|
||
|
||
|
||
void doKeywords() | ||
{ | ||
// Print contents of lookForThese list. | ||
for (list<string>::iterator thisOne = lookForThese.begin(); thisOne != lookForThese.end(); thisOne++) | ||
{ | ||
string temp = *thisOne; | ||
if (temp == last_line) { | ||
// Ignore, it's in our exceptions table. | ||
return; | ||
} | ||
} | ||
|
||
// Avoid outputting escape character (\). | ||
for (int x=0; x < last_line.size(); x++) { | ||
char c = last_line[x]; | ||
if (c != '\\') | ||
cout << c; | ||
} | ||
cout << endl; | ||
} |