summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/mail-scan.c54
-rw-r--r--tools/skrewt.c54
-rw-r--r--tools/utils.c28
-rw-r--r--tools/utils.h29
-rw-r--r--tools/ward.c54
5 files changed, 57 insertions, 162 deletions
diff --git a/tools/mail-scan.c b/tools/mail-scan.c
index 058caed..3100ab6 100644
--- a/tools/mail-scan.c
+++ b/tools/mail-scan.c
@@ -61,49 +61,6 @@ const int sa_good(0);
const int sa_spam(1);
const int sa_usage(64);
-/////////////////////////////////////////////////////////
-// Case insensitive comparison of strings
-
-class lessthan_foldcase{
-public:
- bool operator() (const std::string& a, const std::string& b) const {
- size_t a_len = a.length();
- size_t b_len = b.length();
-
- size_t lim = a_len < b_len ? a_len : b_len;
-
- for (size_t i=0; i<lim; ++i)
- {
- char cha = toupper(a[i]);
- char chb = toupper(b[i]);
-
- if (cha < chb) return true;
- if (cha > chb) return false;
- }
- // here if one is an extension of the other
- if ( a_len < b_len ) return true;
- return false;
- }
-};
-
-
-// Returns negative if a is less than b in alphabetical order
-// returns 0 if they are the same, or positive if a is greater.
-// Like perl cmp operator, but ignores case.
-int cmp_casefold(const std::string& a, const std::string& b) {
- string::const_iterator aa, bb;
- aa = a.begin();
- bb = b.begin();
- while (aa != a.end() && bb != b.end()){
- char ca = tolower(*aa++);
- char cb = tolower(*bb++);
- if (ca != cb) return ca < cb ? -2 : 2;
- }
- if (aa != a.end()) return 1; // a is longer
- if (bb != b.end()) return -1; // b is longer
- return 0;
-}
-
void exeunt(const int sts){
if (sts == sa_good) exit(sts);
@@ -158,17 +115,6 @@ public:
}
};
-string noCR(const string bar){
- string foo(bar);
- int len = foo.length();
- if (len){
- if (foo[len-1] == '\r') {
- foo.erase(len-1);
- }
- }
- return foo;
-}
-
////////////////////////////////////////////////////////////
int main(int _argc, const char** _argv){
//// pid_t pid = getpid();
diff --git a/tools/skrewt.c b/tools/skrewt.c
index 70265da..540b1cf 100644
--- a/tools/skrewt.c
+++ b/tools/skrewt.c
@@ -41,60 +41,6 @@ void usage(const int sts){
#include "utils.h"
#include "sepofra.h"
-/////////////////////////////////////////////////////////
-// Case insensitive comparison of strings
-
-class lessthan_foldcase{
-public:
- bool operator() (const std::string& a, const std::string& b) const {
- size_t a_len = a.length();
- size_t b_len = b.length();
-
- size_t lim = a_len < b_len ? a_len : b_len;
-
- for (size_t i=0; i<lim; ++i)
- {
- char cha = toupper(a[i]);
- char chb = toupper(b[i]);
-
- if (cha < chb) return true;
- if (cha > chb) return false;
- }
- // here if one is an extension of the other
- if ( a_len < b_len ) return true;
- return false;
- }
-};
-
-
-// Returns negative if a is less than b in alphabetical order
-// returns 0 if they are the same, or positive if a is greater.
-// Like perl cmp operator, but ignores case.
-int cmp_casefold(const std::string& a, const std::string& b) {
- string::const_iterator aa, bb;
- aa = a.begin();
- bb = b.begin();
- while (aa != a.end() && bb != b.end()){
- char ca = tolower(*aa++);
- char cb = tolower(*bb++);
- if (ca != cb) return ca < cb ? -2 : 2;
- }
- if (aa != a.end()) return 1; // a is longer
- if (bb != b.end()) return -1; // b is longer
- return 0;
-}
-
-string noCR(const string bar){
- string foo(bar);
- int len = foo.length();
- if (len){
- if (foo[len-1] == '\r') {
- foo.erase(len-1);
- }
- }
- return foo;
-}
-
void maybe_exeunt(const int sts, const int really){
if (!really) return;
if (sts == ex_good) exit(sts);
diff --git a/tools/utils.c b/tools/utils.c
index a7c2878..6dbbff4 100644
--- a/tools/utils.c
+++ b/tools/utils.c
@@ -87,3 +87,31 @@ string purify(const string arg){
}
return rslt;
}
+
+// Returns negative if a is less than b in alphabetical order
+// returns 0 if they are the same, or positive if a is greater.
+// Like perl cmp operator, but ignores case.
+int cmp_casefold(const std::string& a, const std::string& b) {
+ string::const_iterator aa, bb;
+ aa = a.begin();
+ bb = b.begin();
+ while (aa != a.end() && bb != b.end()){
+ char ca = tolower(*aa++);
+ char cb = tolower(*bb++);
+ if (ca != cb) return ca < cb ? -2 : 2;
+ }
+ if (aa != a.end()) return 1; // a is longer
+ if (bb != b.end()) return -1; // b is longer
+ return 0;
+}
+
+string noCR(const string bar){
+ string foo(bar);
+ int len = foo.length();
+ if (len){
+ if (foo[len-1] == '\r') {
+ foo.erase(len-1);
+ }
+ }
+ return foo;
+}
diff --git a/tools/utils.h b/tools/utils.h
index 4f5418f..77cff5e 100644
--- a/tools/utils.h
+++ b/tools/utils.h
@@ -1,6 +1,35 @@
#include <string>
#include <list>
+std::string noCR(const std::string bar);
+int cmp_casefold(const std::string& a, const std::string& b);
+
+/////////////////////////////////////////////////////////
+// Case insensitive comparison of strings
+
+class lessthan_foldcase{
+public:
+ bool operator() (const std::string& a, const std::string& b) const {
+ size_t a_len = a.length();
+ size_t b_len = b.length();
+
+ size_t lim = a_len < b_len ? a_len : b_len;
+
+ for (size_t i=0; i<lim; ++i)
+ {
+ char cha = toupper(a[i]);
+ char chb = toupper(b[i]);
+
+ if (cha < chb) return true;
+ if (cha > chb) return false;
+ }
+ // here if one is an extension of the other
+ if ( a_len < b_len ) return true;
+ return false;
+ }
+};
+
+
std::string basename(const std::string path);
int prefix(const std::string shorter, const std::string longer);
std::string time_out(const int _ttt);
diff --git a/tools/ward.c b/tools/ward.c
index 70265da..540b1cf 100644
--- a/tools/ward.c
+++ b/tools/ward.c
@@ -41,60 +41,6 @@ void usage(const int sts){
#include "utils.h"
#include "sepofra.h"
-/////////////////////////////////////////////////////////
-// Case insensitive comparison of strings
-
-class lessthan_foldcase{
-public:
- bool operator() (const std::string& a, const std::string& b) const {
- size_t a_len = a.length();
- size_t b_len = b.length();
-
- size_t lim = a_len < b_len ? a_len : b_len;
-
- for (size_t i=0; i<lim; ++i)
- {
- char cha = toupper(a[i]);
- char chb = toupper(b[i]);
-
- if (cha < chb) return true;
- if (cha > chb) return false;
- }
- // here if one is an extension of the other
- if ( a_len < b_len ) return true;
- return false;
- }
-};
-
-
-// Returns negative if a is less than b in alphabetical order
-// returns 0 if they are the same, or positive if a is greater.
-// Like perl cmp operator, but ignores case.
-int cmp_casefold(const std::string& a, const std::string& b) {
- string::const_iterator aa, bb;
- aa = a.begin();
- bb = b.begin();
- while (aa != a.end() && bb != b.end()){
- char ca = tolower(*aa++);
- char cb = tolower(*bb++);
- if (ca != cb) return ca < cb ? -2 : 2;
- }
- if (aa != a.end()) return 1; // a is longer
- if (bb != b.end()) return -1; // b is longer
- return 0;
-}
-
-string noCR(const string bar){
- string foo(bar);
- int len = foo.length();
- if (len){
- if (foo[len-1] == '\r') {
- foo.erase(len-1);
- }
- }
- return foo;
-}
-
void maybe_exeunt(const int sts, const int really){
if (!really) return;
if (sts == ex_good) exit(sts);