From da4989aaa1959514c181622831627be8cf91b20d Mon Sep 17 00:00:00 2001 From: Ianos Gnatiuc Date: Tue, 8 Nov 2005 12:35:23 +0000 Subject: [PATCH] Improved ColorName matching --- docs/notework.txt | 4 ++++ golded3/gemlst.cpp | 12 +++--------- golded3/geprot.h | 3 +-- golded3/geutil2.cpp | 31 ++++++++++--------------------- golded3/geview.cpp | 14 ++++---------- 5 files changed, 22 insertions(+), 42 deletions(-) diff --git a/docs/notework.txt b/docs/notework.txt index 10ae0a7..dbe318f 100644 --- a/docs/notework.txt +++ b/docs/notework.txt @@ -10,6 +10,10 @@ ______________________________________________________________________ Notes for GoldED+ 1.1.5, /snapshot/ ______________________________________________________________________ ++ Improved ColorName matching. Case insensitive wildcard matching will be + used for ColorName names. Also, search will be stopped on first matched + name or address. + - Relative path usage is fixed. Now a Real UID is used to parse "~/" always. + Several unicode charset convertion tables is included into distribution of diff --git a/golded3/gemlst.cpp b/golded3/gemlst.cpp index b7b8883..0040407 100644 --- a/golded3/gemlst.cpp +++ b/golded3/gemlst.cpp @@ -209,10 +209,8 @@ void GMsgList::ReadMlst(int n) { strcpy(ml->to, msg.To()); strcpy(ml->re, msg.re); - ml->colorby = GetColorName(msg.orig); - if (ml->colorby == -1) ml->colorby = GetColorName(ml->by); - ml->colorto = AA->isnet() ? GetColorName(msg.dest) : -1; - if (ml->colorto == -1) ml->colorto = GetColorName(ml->to); + ml->colorby = GetColorName(ml->by, msg.orig, -1); + ml->colorto = GetColorName(ml->to, AA->isnet() ? msg.dest : Addr(), -1); } @@ -944,11 +942,7 @@ void GThreadlist::print_line(uint idx, uint pos, bool isbar) { } if (!isbar) - { - int colorname = GetColorName(msg.orig); - if (colorname == -1) colorname = GetColorName(msg.By()); - if (colorname != -1) attr = colorname; - } + attr = GetColorName(msg.By(), msg.orig, attr); else if (CFG->replylinkfloat) { size_t bylen = strlen(msg.By()); diff --git a/golded3/geprot.h b/golded3/geprot.h index 1a4ed63..efbc4c0 100644 --- a/golded3/geprot.h +++ b/golded3/geprot.h @@ -418,8 +418,7 @@ char* strtmp(const char* str); int quotecolor(const char* line); void doinvalidate(char* text, const char* find, const char* replace, bool is_tearline = false); bool find(const std::vector &vec, const char *str); -int GetColorName(Addr &addr); -int GetColorName(char *name); +int GetColorName(const char *name, Addr &addr, int color); // ------------------------------------------------------------------ diff --git a/golded3/geutil2.cpp b/golded3/geutil2.cpp index e4d0742..069badd 100644 --- a/golded3/geutil2.cpp +++ b/golded3/geutil2.cpp @@ -330,35 +330,24 @@ void ScreenBlankIdle() { // ------------------------------------------------------------------ -int GetColorName(Addr &addr) +int GetColorName(const char *name, Addr &addr, int color) { - if (addr.invalid()) return -1; + bool addr_valid = addr.valid(); + bool name_valid = (name != NULL); + + if (!addr_valid && !name_valid) + return color; std::vector< std::pair >::iterator it; for (it = CFG->colorname.begin(); it != CFG->colorname.end(); it++) { - if (addr.match(it->first.addr)) + if (addr_valid && addr.match(it->first.addr)) + return it->second; + if (name_valid && gwildmat(name, it->first.name)) return it->second; } - return -1; -} - - -// ------------------------------------------------------------------ - -int GetColorName(char *name) -{ - if (!name) return -1; - - std::vector< std::pair >::iterator it; - for (it = CFG->colorname.begin(); it != CFG->colorname.end(); it++) - { - if (strieql(it->first.name, name)) - return it->second; - } - - return -1; + return color; } diff --git a/golded3/geview.cpp b/golded3/geview.cpp index 188d133..27141d7 100644 --- a/golded3/geview.cpp +++ b/golded3/geview.cpp @@ -100,7 +100,6 @@ void GMsgHeaderView::Paint() { int namewidth = CFG->disphdrnodeset.pos - CFG->disphdrnameset.pos; int nodewidth = CFG->disphdrdateset.pos - CFG->disphdrnodeset.pos; int datewidth = MinV(width - CFG->disphdrdateset.pos, CFG->disphdrdateset.len); - int colorname = -1; #if defined(GUTLOS_FUNCS) g_set_ostitle_name(struplow(strtmp(area->echoid())), 0); @@ -194,8 +193,6 @@ void GMsgHeaderView::Paint() { if(not area->isinternet()) { if(area->isecho() or not (*msg->ifrom and (*msg->realby or *msg->iorig))) { - colorname = GetColorName(msg->orig); - // Generate orig node data if(msg->orig.net) msg->orig.make_string(buf); @@ -214,13 +211,12 @@ void GMsgHeaderView::Paint() { else strxcpy(buf, msg->By(), (namewidth+nodewidth)); - if (colorname == -1) colorname = GetColorName(buf); strsetsz(buf, nodegenerated ? namewidth : (namewidth+nodewidth)); window.prints(2, 0, window_color, LNG->From); int color = ((msg->foundwhere&GFIND_FROM) or msg->attr.fmu() or (msg->attr.loc() and CFG->switches.get(displocalhigh))) ? highlight_color : from_color; - window.prints(2, CFG->disphdrnameset.pos, (colorname != -1) ? colorname : color, buf); - colorname = -1; + color = GetColorName(msg->By(), msg->orig, color); + window.prints(2, CFG->disphdrnameset.pos, color, buf); if(datewidth > 0) { if(msg->written) @@ -236,8 +232,6 @@ void GMsgHeaderView::Paint() { if(not area->isinternet()) { if(not (*msg->ito and (*msg->realto or *msg->idest))) { - if (area->isnet()) colorname = GetColorName(msg->dest); - if(msg->dest.net and area->isnet()) { msg->dest.make_string(buf); if(msg->odest.net) { @@ -259,12 +253,12 @@ void GMsgHeaderView::Paint() { else strxcpy(buf, msg->To(), (namewidth+nodewidth)); - if (colorname == -1) colorname = GetColorName(buf); strsetsz(buf, nodegenerated ? namewidth : (namewidth+nodewidth)); window.prints(3, 0, window_color, LNG->To); color = ((msg->foundwhere&GFIND_TO) or msg->attr.tou()) ? highlight_color : to_color; - window.prints(3, CFG->disphdrnameset.pos, (colorname != -1) ? colorname : color , buf); + color = GetColorName(msg->To(), area->isnet() ? msg->dest : Addr(), color); + window.prints(3, CFG->disphdrnameset.pos, color, buf); if(datewidth > 0) { if(msg->arrived)