diff options
author | John Denker <jsd@av8n.com> | 2012-07-17 07:04:19 -0700 |
---|---|---|
committer | John Denker <jsd@av8n.com> | 2012-07-29 15:32:33 -0700 |
commit | d074f40718110a3b289dff5fb594425431805df8 (patch) | |
tree | 41c771b661889b3e3a80910edb95bbcad4c5a62b /tools | |
parent | 1427af73b6837df40333f3b317e9ce1f5fde83cc (diff) |
show filename only once in "-l" mode
Diffstat (limited to 'tools')
-rw-r--r-- | tools/mail-scan.c | 60 |
1 files changed, 31 insertions, 29 deletions
diff --git a/tools/mail-scan.c b/tools/mail-scan.c index bb8605f..0d7f722 100644 --- a/tools/mail-scan.c +++ b/tools/mail-scan.c @@ -168,6 +168,7 @@ public: } else { key = init; } + //xx cerr << "watcher key: " << key << " val: " << val << endl; } }; @@ -240,7 +241,7 @@ int main(int _argc, const char** _argv){ string boundary("x-xx-x"); int msgsize(0); int foundsome_infile(0); - for (;;){ // loop over all records in file + for (;;){ // loop over all records in this file if (inheads) { list<string> Header; string line; @@ -264,44 +265,45 @@ int main(int _argc, const char** _argv){ } if (Header.front().length() == 0) { inheads = 0; + continue; // blank line needs no further processing + } + string headword; // the first thing on the line, e.g. "Subject" + string rest; + string header; + if (!multi) header = join(" ", Header); + else header = join("\n", Header); + size_t where = header.find(":"); + if (where != string::npos) { + headword = header.substr(0, where); + rest = ltrim(header.substr(1+where)); } - else { - string headword; // the first thing on the line, e.g. "Subject" - string rest; - string header; - if (!multi) header = join(" ", Header); - else header = join("\n", Header); - size_t where = header.find(":"); - if (where != string::npos) { - headword = header.substr(0, where); - rest = ltrim(header.substr(1+where)); - } // temporary? FIXME? lowercase - headword = toLower(headword); - rest = toLower(rest); - for (list<watcher>::const_iterator ptr = watchword.begin(); - ptr != watchword.end(); ptr++) { - 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; - didprint++; - } + headword = toLower(headword); + rest = toLower(rest); + for (list<watcher>::const_iterator ptr = watchword.begin(); + ptr != watchword.end(); ptr++) { + 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; + didprint++; } } } } +// only show file once, even if there might have been multiple matches: + if (fname_only && didprint) break; } else { // not in header break; } - } + } // end loop over matching records in this file if (vflag && !foundsome_infile) { cout << *file << endl; didprint++; |