From ad0a329eed2f913ffa2b8c786b07ea688c9c5b61 Mon Sep 17 00:00:00 2001 From: John Denker Date: Mon, 16 Jul 2012 17:11:37 -0700 Subject: scan for +keyword:value (not just keyword) --- tools/mail-scan.c | 48 ++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 40 insertions(+), 8 deletions(-) (limited to 'tools') diff --git a/tools/mail-scan.c b/tools/mail-scan.c index 56b3806..c70a1de 100644 --- a/tools/mail-scan.c +++ b/tools/mail-scan.c @@ -150,6 +150,25 @@ string join(const string sep, list stuff){ return rslt; } +class watcher { +public: + string key; + string val; + + watcher(const string init) + : key(""), val("") + { + size_t where = init.find(":"); + if (where != string::npos) { + key = init.substr(0, where); + val = init.substr(1+where); + } else { + key = init; + } + } +}; + + //////////////////////////////////////////////////////////// int main(int _argc, const char** _argv){ //// pid_t pid = getpid(); @@ -160,10 +179,11 @@ int main(int _argc, const char** _argv){ string progname(*argv); argv++; argc--; int maxsize(1000000); - list watchword; + list watchword; list dofile; int vflag(0); int multi(0); + int fname_only(0); while (argc) { string arg(*argv); argv++; argc--; @@ -174,6 +194,9 @@ int main(int _argc, const char** _argv){ if (prefix(arg, "-verify")){ vflag++; continue; + } else if (prefix(arg, "-l")){ + fname_only++; + continue; } else if (prefix(arg, "-multi")){ multi++; continue; @@ -192,7 +215,6 @@ int main(int _argc, const char** _argv){ for (list::const_iterator file = dofile.begin(); file != dofile.end(); file++) { - struct stat filestatus; stat(file->c_str(), &filestatus ); if (S_ISDIR(filestatus.st_mode)) { @@ -236,7 +258,7 @@ int main(int _argc, const char** _argv){ inheads = 0; } else { - string headword; + string headword; // the first thing on the line, e.g. "Subject" string rest; string header; if (!multi) header = join(" ", Header); @@ -246,13 +268,23 @@ int main(int _argc, const char** _argv){ headword = header.substr(0, where); rest = ltrim(header.substr(1+where)); } +// temporary? FIXME? lowercase headword = toLower(headword); - for (list::const_iterator ptr = watchword.begin(); + rest = toLower(rest); + for (list::const_iterator ptr = watchword.begin(); ptr != watchword.end(); ptr++) { - if (headword == toLower(*ptr)) { - foundsome_infile++; - if (!vflag) cout // << foundsome_infile << " " - << *file << " :: " << header << endl; + if (headword == toLower(ptr->key)) { + // here if match as to keyword; check for match as to value + if (ptr->val.length()==0 + || rest.find(toLower(ptr->val)) != string::npos) { + foundsome_infile++; + if (!vflag) { + // << foundsome_infile << " " ; (number of occurrences) + cout << *file; + if (!fname_only) cout << " :: " << header; + cout << endl; + } + } } } } -- cgit v1.2.3