diff --git a/golded.sln b/golded.sln index 41e5981..ebea242 100644 --- a/golded.sln +++ b/golded.sln @@ -52,7 +52,6 @@ Global {C23888DA-7024-4A38-A8C5-CE4BEFA4629A}.Release|x64.ActiveCfg = Release|x64 {C23888DA-7024-4A38-A8C5-CE4BEFA4629A}.Release|x64.Build.0 = Release|x64 {B80E3728-98E5-4A9A-B883-9C064F1FFFA7}.Debug|Win32.ActiveCfg = Debug|Win32 - {B80E3728-98E5-4A9A-B883-9C064F1FFFA7}.Debug|Win32.Build.0 = Debug|Win32 {B80E3728-98E5-4A9A-B883-9C064F1FFFA7}.Debug|x64.ActiveCfg = Debug|x64 {B80E3728-98E5-4A9A-B883-9C064F1FFFA7}.Debug|x64.Build.0 = Debug|x64 {B80E3728-98E5-4A9A-B883-9C064F1FFFA7}.Release|Win32.ActiveCfg = Release|Win32 @@ -60,7 +59,6 @@ Global {B80E3728-98E5-4A9A-B883-9C064F1FFFA7}.Release|x64.ActiveCfg = Release|x64 {B80E3728-98E5-4A9A-B883-9C064F1FFFA7}.Release|x64.Build.0 = Release|x64 {951D76D2-FA57-4C95-8F65-A6C19C122AA5}.Debug|Win32.ActiveCfg = Debug|Win32 - {951D76D2-FA57-4C95-8F65-A6C19C122AA5}.Debug|Win32.Build.0 = Debug|Win32 {951D76D2-FA57-4C95-8F65-A6C19C122AA5}.Debug|x64.ActiveCfg = Debug|x64 {951D76D2-FA57-4C95-8F65-A6C19C122AA5}.Debug|x64.Build.0 = Debug|x64 {951D76D2-FA57-4C95-8F65-A6C19C122AA5}.Release|Win32.ActiveCfg = Release|Win32 diff --git a/golded3/gccfgg.h b/golded3/gccfgg.h index 19d4066..4e77192 100644 --- a/golded3/gccfgg.h +++ b/golded3/gccfgg.h @@ -386,6 +386,7 @@ const word CRC_TWITSUBJ = 0x08C0; const word CRC_TWITTO = 0x9DFE; const word CRC_UNPACKER = 0x5691; const word CRC_URLHANDLER = 0x688E; +const word CRC_URLSCHEME = 0x89FC; const word CRC_USEAREA = 0x2FD4; const word CRC_USECHARSET = 0xE1B9; const word CRC_USEFLAGS = 0xE2B6; diff --git a/golded3/gccfgg0.cpp b/golded3/gccfgg0.cpp index ed2b893..622b7bb 100644 --- a/golded3/gccfgg0.cpp +++ b/golded3/gccfgg0.cpp @@ -588,6 +588,7 @@ SwitchU: switch(crc) { case CRC_UNPACKER : CfgUnpacker (); break; case CRC_URLHANDLER : CfgUrlhandler (); break; + case CRC_URLSCHEME : CfgUrlscheme (); break; case CRC_USEAREA : CfgUsearea (); break; case CRC_USECHARSET : CfgUsecharset (); break; case CRC_USEFWD : CfgUsefwd (); break; diff --git a/golded3/gccfgg4.cpp b/golded3/gccfgg4.cpp index 5bed1de..0709ee3 100644 --- a/golded3/gccfgg4.cpp +++ b/golded3/gccfgg4.cpp @@ -41,7 +41,7 @@ void CfgExcludenodes() { } // ------------------------------------------------------------------ - + void CfgExternoptions() { const word CRC_CLS = 0x34F4; @@ -64,7 +64,7 @@ void CfgExternoptions() { if(*val == '-') val++; - + char* _key; word _crc = getkeyvalcrc(&_key, &val); @@ -119,8 +119,8 @@ void CfgExternoptions() { // ------------------------------------------------------------------ -void CfgExternutil() { - +void CfgExternutil() +{ ExtUtil extutil; // Get util number @@ -131,16 +131,18 @@ void CfgExternutil() { // Get options int _optbak = CFG->externoptions; - while(strchr("-", *_val)) { + + while(strchr("-", *_val)) + { getkeyval(&_key, &_val); val = _key; CfgExternoptions(); } + extutil.options = CFG->externoptions; CFG->externoptions = _optbak; - // Get commandline - strxcpy(extutil.cmdline, _val, sizeof(extutil.cmdline)); + extutil.cmdline = _val; // Get commandline // Count it CFG->externutil.push_back(extutil); @@ -293,14 +295,14 @@ void CfgGedhandshake() { CFG->gedhandshake = make_bool(GetYesno(val)); } - + // ------------------------------------------------------------------ void CfgGermankeyboard() { right_alt_same_as_left = not GetYesno(val); } - + // ------------------------------------------------------------------ void CfgGoldbasepath(const char *path, bool force) { @@ -369,4 +371,3 @@ void CfgGroup() { } // ------------------------------------------------------------------ - diff --git a/golded3/gccfgg8.cpp b/golded3/gccfgg8.cpp index 7cb2909..aace5f3 100644 --- a/golded3/gccfgg8.cpp +++ b/golded3/gccfgg8.cpp @@ -329,24 +329,34 @@ void CfgUnpacker() { // ------------------------------------------------------------------ -void CfgUrlhandler() { - +void CfgUrlhandler() +{ // Get util number char* _key; char* _val = val; // Get options int _optbak = CFG->externoptions; - while(strchr("-", *_val)) { + + while (strchr("-", *_val)) + { getkeyval(&_key, &_val); val = _key; CfgExternoptions(); } - CFG->urlhandler.options = CFG->externoptions; + + UrlHandler url; + url.handler.cmdline = _val; + url.handler.options = CFG->externoptions; CFG->externoptions = _optbak; - // Get commandline - strxcpy(CFG->urlhandler.cmdline, _val, sizeof(CFG->urlhandler.cmdline)); + CFG->urlhandler.push_back(url); +} + +// ------------------------------------------------------------------ + +void CfgUrlscheme() +{ } // ------------------------------------------------------------------ diff --git a/golded3/gcprot.h b/golded3/gcprot.h index 5f9c81b..5c3f210 100644 --- a/golded3/gcprot.h +++ b/golded3/gcprot.h @@ -366,6 +366,7 @@ void CfgTwitsubj (); void CfgTwitto (); void CfgUnpacker (); void CfgUrlhandler (); +void CfgUrlscheme (); void CfgUsearea (); void CfgUsecharset (); void CfgUseflags (); diff --git a/golded3/gecfgg.h b/golded3/gecfgg.h index 95b6047..3493c94 100644 --- a/golded3/gecfgg.h +++ b/golded3/gecfgg.h @@ -302,7 +302,7 @@ public: uint disptabsize; // tabsize; bool encodeemailheaders; std::vector event; - int externoptions; + uint32_t externoptions; std::vector externutil; Ezycom ezycom; int ezycomuserno; @@ -451,7 +451,7 @@ public: std::vector twitname; gstrarray twitsubj; std::vector< std::pair > unpacker; - ExtUtil urlhandler; + std::vector urlhandler; bool usearea; bool usecharset; int usefwd; diff --git a/golded3/gefile.cpp b/golded3/gefile.cpp index 342924a..4824287 100644 --- a/golded3/gefile.cpp +++ b/golded3/gefile.cpp @@ -25,6 +25,7 @@ // ------------------------------------------------------------------ #include +#include #include #include #include @@ -622,9 +623,9 @@ void CreateFileMsgs(int mode, GMsg* msg) { // ------------------------------------------------------------------ -static int FreqCmp(const char** a, const char** b) { - - return stricmp(*a, *b); +static bool FreqCmp(const std::string &a, const std::string &b) +{ + return (stricmp(a.c_str(), b.c_str()) < 0); } @@ -722,27 +723,25 @@ static int frqgetfile(char* file, char* desc, char* filesize, const char* txt) { // ------------------------------------------------------------------ -void FileRequest(GMsg* msg) { - +void FileRequest(GMsg* msg) +{ GFTRK("FileRequest"); int oldtopline = reader_topline; - if(AA->Msgn.Count() and msg->line and msg->lines) { - + if (AA->Msgn.Count() and msg->line and msg->lines) + { + gstrarray freqfile; char buf[256]; const char* ptr; const char* ptr1 = NULL; const char* ptr2; const char* txtptr; - char** freqfile = NULL; int gotticket = false; int getnextdesc = false; Line** lin = msg->line; char file[GMAXPATH], desc[200], filesize[10]; - int freqfiles = 0; bool esc = true; - int n; byte numlines = 0; *desc = *file = *filesize = NUL; @@ -753,8 +752,9 @@ void FileRequest(GMsg* msg) { int tline = reader_topline; if(CFG->frqoptions & FREQ_FROMTOP) tline = 0; - for(n=tline; nlines; n++) { + for (size_t n = tline; n < msg->lines; n++) + { // Don't look in control info for files if(lin[n]->type & (GLINE_KLUDGE|GLINE_TEAR|GLINE_ORIG)) continue; @@ -895,13 +895,11 @@ void FileRequest(GMsg* msg) { if (*file and *desc) { // Yes, so add it to the list - freqfile = (char**)throw_realloc(freqfile, (freqfiles+3)*sizeof(char*)); gsprintf(PRINTF_DECLARE_BUFFER(buf), " %-12s %8s %s", file, filesize, desc); strsetsz(buf, 76); - freqfile[freqfiles] = throw_strdup(buf); + freqfile.push_back(buf); *desc = *file = *filesize = NUL; numlines = 0; - freqfiles++; } // Maybe there was a false match, so re-initialize if @@ -919,27 +917,24 @@ void FileRequest(GMsg* msg) { { strcpy(file, "FILES"); gsprintf(PRINTF_DECLARE_BUFFER(desc), LNG->FilelistFrom, msg->By()); - freqfile = (char**)throw_realloc(freqfile, (freqfiles+3)*sizeof(char*)); gsprintf(PRINTF_DECLARE_BUFFER(buf), " %-12.12s %-52.52s ", file, desc); - freqfile[freqfiles] = throw_strdup(buf); + freqfile.push_back(buf); *desc = *file = NUL; - freqfiles++; } w_info(NULL); // Let user select the file(s) to be requested - if(freqfile) { - - // NULL terminate list - freqfile[freqfiles] = NULL; - + if (freqfile.size()) + { // Sort list if requested - if(CFG->frqoptions & FREQ_SORT) - qsort(freqfile, freqfiles, sizeof(char*), (StdCmpCP)FreqCmp); + if (CFG->frqoptions & FREQ_SORT) + { + sort(freqfile.begin(), freqfile.end(), FreqCmp); + } // Run the picker - int items = MinV(freqfiles, (MAXROW-10)); + int items = MinV(freqfile.size(), MAXROW-10); set_title(LNG->FreqMenuTitle, TCENTER, C_ASKT); update_statusline(LNG->FreqStat); whelppcat(H_FileRequest); @@ -963,10 +958,16 @@ void FileRequest(GMsg* msg) { // Handle picked files msg->re[0] = NUL; - for(n=0; nattr.frq1(); - ptr = freqfile[n]+1; // 01234567890123456 + ptr = &(*it)[1]; // 01234567890123456 ptr2 = strskip_txt(ptr); #if defined(__USE_ALLOCA__) char *tmpbuf = (char*)alloca(ptr2-ptr+1); @@ -987,10 +988,12 @@ void FileRequest(GMsg* msg) { } } } - if(freqs == 0) { + + if (freqs == 0) + { // AARRRGGGHH!! More bloody duplicate code :-(( msg->attr.frq1(); - ptr = freqfile[crsr]+1; // 01234567890123456 + ptr = &freqfile[crsr][1]; // 01234567890123456 ptr2 = strskip_txt(ptr); #if defined(__USE_ALLOCA__) char *tmpbuf = (char*)alloca(ptr2-ptr+1); @@ -1033,8 +1036,10 @@ void FileRequest(GMsg* msg) { int destarea = CurrArea; reader_topline = 0; AA->attr().hex0(); - if(*AA->Areafreqto()) { - for(n=0; (uint) nAreafreqto()) + { + for (size_t n = 0; n < AL.size(); n++) + { if(strieql(AL[n]->echoid(), AA->Areafreqto())) { destarea = AL[n]->areaid(); break; @@ -1065,12 +1070,6 @@ void FileRequest(GMsg* msg) { } } - if(freqfile) { - for(n=0; n #include +#include +#if defined(_MSC_VER) && defined(_DEBUG) +static struct LeakFinder +{ + LeakFinder() + { + InitAllocCheck(); + } + + ~LeakFinder() + { + DeInitAllocCheck(); + } +} leakFinder; +#endif // ------------------------------------------------------------------ // Main function @@ -35,6 +50,7 @@ int main(int argc, char *argv[]) { Initialize(argc, argv); Reader(); + Uninitialize(); return errorlevel; } diff --git a/golded3/gemenu.cpp b/golded3/gemenu.cpp index 56082f4..0266467 100644 --- a/golded3/gemenu.cpp +++ b/golded3/gemenu.cpp @@ -387,7 +387,7 @@ static void DispAttrWindow(int show=-1) { if(show) { wh_background = whandle(); - int wide = MaxV(strlen(LNG->AttrTitle)+2, strlen(LNG->AttrPvt)+2); + size_t wide = MaxV(strlen(LNG->AttrTitle)+2, strlen(LNG->AttrPvt)+2); wide = MinV(wide, MAXCOL-4); wh_attributes = wopen_(6, 0, 17, wide, W_BMENU, C_MENUB, C_MENUW); set_title(LNG->AttrTitle, TCENTER, C_MENUT); @@ -606,9 +606,7 @@ void AskAttributes(GMsg* __msg) { int SelectFromFile(const char* file, char* selection, const char* title, const char* nolines) { char buf[256]; - int n; bool retval=false; - char** Listi; int lines = 0; gfile fp(AddPath(CFG->goldpath, file), "rt", CFG->sharemode); @@ -620,8 +618,10 @@ int SelectFromFile(const char* file, char* selection, const char* title, const c if (lines) { - Listi = (char**)throw_calloc(lines+1, sizeof(char*)); + gstrarray Listi; fp.Rewind(); + + size_t n; for (n = 0; n < lines; n++) { fp.Fgets(buf, sizeof(buf)-2); @@ -632,20 +632,21 @@ int SelectFromFile(const char* file, char* selection, const char* title, const c buf[MAXCOL-2-2] = NUL; Listi[n] = throw_strdup(buf); } + n = MinV(n, (MAXROW-10)); set_title(title, TCENTER, C_ASKT); n = wpickstr(6, 0, 6+n+1, -1, W_BASK, C_ASKB, C_ASKW, C_ASKS, Listi, 0, title_shadow); - if(n != -1) { - strcpy(selection, Listi[n]); + + if (n != -1) + { + strcpy(selection, Listi[n].c_str()); strtrim(selection); strltrim(selection); retval = true; } - for(n=0; ntagline.empty()) + { + char buf[256]; + gstrarray Listi; - if(not CFG->tagline.empty()) { - Listi = (char**)throw_calloc(CFG->tagline.size()+1, sizeof(char*)); - gstrarray::iterator i; - for(n = 0, i = CFG->tagline.begin(); i != CFG->tagline.end(); i++, n++) { - if((*i)[0] == '@') - strxmerge(buf, MAXCOL-2-2, " [", CleanFilename(i->c_str()+1), "] ", NULL); + gstrarray::iterator it = CFG->tagline.begin(); + gstrarray::iterator end = CFG->tagline.end(); + + for (; it != end; it++) + { + if((*it)[0] == '@') + strxmerge(buf, MAXCOL-2-2, " [", CleanFilename(it->c_str() + 1), "] ", NULL); else - strxmerge(buf, MAXCOL-2-2, " ", i->c_str(), " ", NULL); - Listi[n] = throw_strdup(buf); + strxmerge(buf, MAXCOL-2-2, " ", it->c_str(), " ", NULL); + + Listi.push_back(buf); } - n = MinV(n, (MAXROW-10)); + + size_t n = MinV(Listi.size(), (MAXROW-10)); set_title(LNG->Taglines, TCENTER, C_ASKT); update_statusline(LNG->ChangeTagline); whelppcat(H_ChangeTagline); n = wpickstr(6, 0, 6+n+1, -1, W_BASK, C_ASKB, C_ASKW, C_ASKS, Listi, CFG->taglineno, title_shadow); - if(n != -1) { + + if (n != -1) + { const char *tagl = CFG->tagline[n].c_str(); if(tagl[0] == '@') { strxmerge(buf, MAXCOL-2-2, LNG->Taglines, " [", CleanFilename(tagl+1), "] ", NULL); @@ -694,45 +702,52 @@ int ChangeTagline() { retval = true; } } - for(n=CFG->tagline.size(); n; n--) - throw_free(Listi[n-1]); - throw_free(Listi); + whelpop(); } - else { + else + { w_info(LNG->NoTagline); waitkeyt(10000); w_info(NULL); } - return(retval); + + return retval; } // ------------------------------------------------------------------ -int ChangeOrigin() { +int ChangeOrigin() +{ + bool retval = false; - char buf[256]; - int n; - bool retval=false; - char** Listi; + if (not CFG->origin.empty()) + { + char buf[256]; + gstrarray Listi; - if(not CFG->origin.empty()) { - Listi = (char**)throw_calloc(CFG->origin.size()+1, sizeof(char*)); - gstrarray::iterator i; - for(n = 0, i = CFG->origin.begin(); i != CFG->origin.end(); n++, i++) { - if((*i)[0] == '@') - strxmerge(buf, MAXCOL-2-2, " [", CleanFilename(i->c_str()+1), "] ", NULL); + gstrarray::iterator it = CFG->origin.begin(); + gstrarray::iterator end = CFG->origin.end(); + + for (; it !=end; it++) + { + if ((*it)[0] == '@') + strxmerge(buf, MAXCOL-2-2, " [", CleanFilename(it->c_str() + 1), "] ", NULL); else - strxmerge(buf, MAXCOL-2-2, " ", i->c_str(), " ", NULL); - Listi[n] = throw_strdup(buf); + strxmerge(buf, MAXCOL-2-2, " ", it->c_str(), " ", NULL); + + Listi.push_back(buf); } - n = MinV(n, (MAXROW-10)); + + size_t n = MinV(Listi.size(), (MAXROW-10)); set_title(LNG->Origins, TCENTER, C_ASKT); update_statusline(LNG->ChangeOrigin); whelppcat(H_ChangeOrigin); n = wpickstr(6, 0, 6+n+1, -1, W_BASK, C_ASKB, C_ASKW, C_ASKS, Listi, CFG->originno, title_shadow); - if(n != -1) { + + if (n != -1) + { const char *orig = CFG->origin[n].c_str(); if(orig[0] == '@') { strxmerge(buf, MAXCOL-2-2, LNG->Origins, " [", CleanFilename(orig+1), "] ", NULL); @@ -747,43 +762,48 @@ int ChangeOrigin() { retval = true; } } - for(n = CFG->origin.size(); n; n--) - throw_free(Listi[n-1]); - throw_free(Listi); + whelpop(); } - else { + else + { w_info(LNG->NoOrigDefined); waitkeyt(10000); w_info(NULL); } - return(retval); + + return retval; } // ------------------------------------------------------------------ -int ChangeUsername() { +int ChangeUsername() +{ + if(not CFG->username.empty()) + { + char buf[256]; + char adrs[40]; + gstrarray Listi; - char buf[256], adrs[40]; - int n; - char** Listi; + std::vector::iterator it = CFG->username.begin(); + std::vector::iterator end = CFG->username.end(); - if(not CFG->username.empty()) { - Listi = (char**)throw_calloc(CFG->username.size()+1, sizeof(char*)); - std::vector::iterator i; - for (n = 0, i = CFG->username.begin(); i != CFG->username.end(); n++, i++) + for (; it != end; it++) { - i->addr.make_string(adrs); - gsprintf(PRINTF_DECLARE_BUFFER(buf), " %-35s %s ", i->name, adrs); - Listi[n] = throw_strdup(buf); + it->addr.make_string(adrs); + gsprintf(PRINTF_DECLARE_BUFFER(buf), " %-35s %s ", it->name, adrs); + Listi.push_back(buf); } - n = MinV(n, (MAXROW-10)); + + size_t n = MinV(Listi.size(), (MAXROW-10)); set_title(LNG->Usernames, TCENTER, C_ASKT); update_statusline(LNG->ChangeUsername); whelppcat(H_ChangeUsername); n = wpickstr(6, 0, 6+n+1, -1, W_BASK, C_ASKB, C_ASKW, C_ASKS, Listi, CFG->usernameno, title_shadow); - if(n != -1) { + + if (n != -1) + { CFG->usernameno = n; AA->SetUsername(CFG->username[n]); for(std::vector::iterator a = CFG->aka.begin(); a != CFG->aka.end(); a++) { @@ -793,94 +813,101 @@ int ChangeUsername() { } } } - for(n = CFG->username.size(); n; n--) - throw_free(Listi[n-1]); - throw_free(Listi); + whelpop(); } - else { + else + { w_info(LNG->NoUserDefined); waitkeyt(10000); w_info(NULL); } - return(YES); + + return YES; } // ------------------------------------------------------------------ -int ChangeTemplate() { +int ChangeTemplate() +{ + if (not CFG->tpl.empty()) + { + char buf[256]; + char adrs[40]; + gstrarray Listi; - char buf[256], adrs[40]; - int n; - int selected=-1; - char** Listi; + std::vector::iterator it = CFG->tpl.begin(); + std::vector::iterator end = CFG->tpl.end(); - if(not CFG->tpl.empty()) { - Listi = (char**)throw_calloc(CFG->tpl.size()+1, sizeof(char*)); - std::vector::iterator t; - for (n = 0, t = CFG->tpl.begin(); t != CFG->tpl.end(); n++, t++) + for (; it != end; it++) { - t->match.make_string(adrs); - gsprintf(PRINTF_DECLARE_BUFFER(buf), " %-45s %s ", t->name, adrs); - Listi[n] = throw_strdup(buf); + it->match.make_string(adrs); + gsprintf(PRINTF_DECLARE_BUFFER(buf), " %-45s %s ", it->name, adrs); + Listi.push_back(buf); } - n = MinV(n, (MAXROW-10)); + + size_t n = MinV(Listi.size(), (MAXROW-10)); set_title(LNG->Templates, TCENTER, C_ASKT); update_statusline(LNG->ChangeTemplate); whelppcat(H_ChangeTemplate); n = wpickstr(6, 0, 6+n+1, -1, W_BASK, C_ASKB, C_ASKW, C_ASKS, Listi, CFG->tplno, title_shadow); whelpop(); - if(n != -1) { + + if (n != -1) + { AA->SetTpl(CFG->tpl[n].file); CFG->tplno = n; } - selected = n; - for(n = CFG->tpl.size(); n; n--) - throw_free(Listi[n-1]); - throw_free(Listi); + + return n; } else { w_info(LNG->NoTplDefined); waitkeyt(10000); w_info(NULL); } - return selected; + + return -1; } // ------------------------------------------------------------------ -int ChangeAka() { - int n; - std::vector::iterator i; - int startat = 0; - char** Listi; - char addr[100], buf[100]; +int ChangeAka() +{ + if (CFG->aka.size() > 1) + { + size_t startat = 0; + char addr[100]; + char buf[100]; + gstrarray Listi; - if(CFG->aka.size() > 1) { - Listi = (char**)throw_calloc(CFG->aka.size()+1, sizeof(char*)); - for (i = CFG->aka.begin(), n=0; i != CFG->aka.end(); n++, i++) + std::vector::iterator it = CFG->aka.begin(); + std::vector::iterator end = CFG->aka.end(); + + for (; it != end; it++) { - i->addr.make_string(addr, i->domain); + it->addr.make_string(addr, it->domain); gsprintf(PRINTF_DECLARE_BUFFER(buf), " %s ", addr); - Listi[n] = throw_strdup(buf); - if(AA->Aka().addr.equals(i->addr)) - startat = n; + Listi.push_back(buf); + + if (AA->Aka().addr.equals(it->addr)) + startat = Listi.size() - 1; } - n = MinV(n, (MAXROW-10)); + + size_t n = MinV(Listi.size(), (MAXROW-10)); set_title(LNG->Akas, TCENTER, C_ASKT); update_statusline(LNG->ChangeAka); whelppcat(H_ChangeAka); n = wpickstr(6, 0, 6+n+1, -1, W_BASK, C_ASKB, C_ASKW, C_ASKS, Listi, startat, title_shadow); whelpop(); - if(n != -1) + + if (n != -1) AA->SetAka(CFG->aka[n].addr); - for(n=CFG->aka.size(); n; n--) - throw_free(Listi[n-1]); - throw_free(Listi); } - else { + else + { w_info(LNG->NoAkaDefined); waitkeyt(10000); w_info(NULL); @@ -891,61 +918,71 @@ int ChangeAka() { // ------------------------------------------------------------------ -int ChangeXlatImport() { +int ChangeXlatImport() +{ + if (not CFG->xlatcharset.empty()) + { + size_t startat = 0; + int maximport = 0; + int maxexport = 0; - int n, startat = 0; - int xlatimports = 1; - int maximport = 0; - int maxexport = 0; - char** Listi; - char buf[100]; + char buf[100]; + gstrarray Listi; + + std::vector::iterator xlt = CFG->xlatcharset.begin(); + std::vector::iterator end = CFG->xlatcharset.end(); - if(not CFG->xlatcharset.empty()) { - Listi = (char**)throw_calloc(CFG->xlatcharset.size()+2, sizeof(char*)); - std::vector::iterator xlt; - for(xlt = CFG->xlatcharset.begin(); xlt != CFG->xlatcharset.end(); xlt++) { - if(strieql(xlt->exp, CFG->xlatlocalset)) { + for (size_t xlatimports = 1; xlt != end; xlt++) + { + if (strieql(xlt->exp, CFG->xlatlocalset)) + { maximport = MaxV(maximport, (int)strlen(xlt->imp)); maxexport = MaxV(maxexport, (int)strlen(xlt->exp)); - if((CFG->ignorecharset == true) and strieql(xlt->imp, AA->Xlatimport())) + if ((CFG->ignorecharset == true) and strieql(xlt->imp, AA->Xlatimport())) startat = xlatimports; xlatimports++; } } - Listi[0] = throw_strdup(LNG->CharsetAuto); - xlatimports = 1; - for (xlt = CFG->xlatcharset.begin(); xlt != CFG->xlatcharset.end(); xlt++) + + Listi.push_back(LNG->CharsetAuto); + + for (xlt = CFG->xlatcharset.begin(); xlt != end; xlt++) { if (strieql(xlt->exp, CFG->xlatlocalset)) { gsprintf(PRINTF_DECLARE_BUFFER(buf), " %*.*s -> %-*.*s ", maximport, maximport, xlt->imp, maxexport, maxexport, xlt->exp); - Listi[xlatimports++] = throw_strdup(buf); + Listi.push_back(buf); } } - n = MinV(xlatimports, (MAXROW-10)); + + size_t n = MinV(Listi.size(), (MAXROW-10)); set_title(LNG->Charsets, TCENTER, C_ASKT); update_statusline(LNG->ChangeXlatImp); whelppcat(H_ChangeXlatImport); n = wpickstr(6, 0, 6+n+1, -1, W_BASK, C_ASKB, C_ASKW, C_ASKS, Listi, startat, title_shadow); whelpop(); - if(n == 0) { + + if (n == 0) + { CFG->ignorecharset = false; } - else if(n != -1) { + else if (n != -1) + { CFG->ignorecharset = true; - AA->SetXlatimport(strtok(Listi[n], " ")); + std::string xlatImport = Listi[n].substr(0, Listi[n].find(" ")); + AA->SetXlatimport(xlatImport.c_str()); } + LoadCharset(AA->Xlatimport(), CFG->xlatlocalset); - for(n=0; nNoXlatImport); waitkeyt(10000); w_info(NULL); } + return true; } diff --git a/golded3/gemsgs.cpp b/golded3/gemsgs.cpp index ad12f89..6a3cd05 100644 --- a/golded3/gemsgs.cpp +++ b/golded3/gemsgs.cpp @@ -681,13 +681,51 @@ void TokenXlat(int mode, std::string &input, GMsg* msg, GMsg* oldmsg, int __orig if (tokenxchg(input, dst, "@tr", "", 0, 1, (int)true)) continue; } - } +#if 0 + if (strnieql(it2str(input, dst), "@uptime", 7)) + { + size_t days = 0; + size_t hours = 0; + size_t minutes = 0; + size_t seconds = 0; + size_t useconds = 0; + +#ifdef __WIN32__ + LARGE_INTEGER counter; + LARGE_INTEGER frequency; + QueryPerformanceCounter(&counter); + QueryPerformanceFrequency(&frequency); + seconds = counter.QuadPart / frequency.QuadPart; + useconds = size_t(double(counter.QuadPart % frequency.QuadPart)*1000 / frequency.QuadPart); +#endif + + days = seconds/(60*60*24); seconds %= 60*60*24; + hours = seconds/(60*60); seconds %= 60*60; + minutes = seconds/60; seconds %= 60; + + char uptime[1024]; +/* + FormatString( + FormatString( + FormatString( + FormatString( + FormatString("%days day(s) %hours:%minutes:%seconds.%useconds", + "%days", days), + "%hours", hours), + "%minutes", minutes), + "%seconds", seconds), + "%useconds", useconds); +*/ + + tokenxchg(input, dst, "@uptime", uptime); + } +#endif + } dst++; } } - // ------------------------------------------------------------------ void TokenXlat(int mode, char *&input, size_t size, bool resize, GMsg* msg, GMsg* oldmsg, int origarea) diff --git a/golded3/geprot.h b/golded3/geprot.h index 03bd810..7784389 100644 --- a/golded3/geprot.h +++ b/golded3/geprot.h @@ -161,6 +161,7 @@ int IsMacro(gkey key, int type); // ------------------------------------------------------------------ // GEINIT prototypes +void Uninitialize(); void Initialize(int argc, char* argv[]); @@ -357,7 +358,7 @@ void NextArea(); void PrevArea(); void Reader(); void UpdateArea(GMsg* msg); -int ExternUtil(GMsg* msg, int utilno); +int ExternUtil(GMsg* msg, uint32_t utilno); void ExternUtilMenu(GMsg* msg); void ReadPeekURLs(GMsg* msg); uint next_msg(int direction); @@ -545,3 +546,4 @@ void RemoveHTML(char *&txt); #endif // ------------------------------------------------------------------ + diff --git a/golded3/geread.cpp b/golded3/geread.cpp index 8681a61..bd454cc 100644 --- a/golded3/geread.cpp +++ b/golded3/geread.cpp @@ -1390,15 +1390,15 @@ struct ReplySel { // ------------------------------------------------------------------ -void GotoReplies() { - +void GotoReplies() +{ reader_direction = DIR_NEXT; GMsg* msg = reader_msg; const int list_max = msg->link.list_max(); char buf[200]; - int replies = 0; + size_t replies = 0; int cursorbar = -1; uint maxname = 0; uint maxaddr = 0; @@ -1447,40 +1447,38 @@ void GotoReplies() { throw_free(rmsg); int selected = 0; - if(replies > 1) { + if(replies > 1) + { uint maxname2 = MAXCOL-16-maxmsgno-maxaddr-maxwritten; maxname = MinV(maxname, maxname2); - char** listr = (char**)throw_calloc(list_max+3, sizeof(char*)); + gstrarray listr; + int n; - for(n=0; n= replies) break; - } + + sprintf(buf, "%c %c %*s : %-*.*s %-*s %-*s ", + rlist[n].isread, + rlist[n].msgno[0], + maxmsgno, rlist[n].msgno+1, + (int) maxname, (int) maxname, rlist[n].name, + maxaddr, rlist[n].addr, + maxwritten, rlist[n].written + ); + + listr.push_back(buf); } set_title(LNG->Replies, TCENTER, C_ASKT); update_statusline(LNG->SelectReply); whelppcat(H_GotoReplies); - int pick_max = MinV(replies, (MAXROW-10)); + size_t pick_max = MinV(replies, (MAXROW-10)); if(cursorbar < 0) cursorbar = 0; selected = wpickstr(6, 0, 6+pick_max+1, -1, W_BASK, C_ASKB, C_ASKW, C_ASKS, listr, cursorbar, title_shadow); whelpop(); gotolink = (selected != -1) ? rlist[selected].reln : 0; - for(n=0; n +#include #include #include #include -#include #define PROTOTYPES #include @@ -534,14 +535,14 @@ void TouchNetscan(int popup) // ------------------------------------------------------------------ -int ExternUtil(GMsg *msg, ExtUtil *extutil) { - +int ExternUtil(GMsg *msg, const ExtUtil &extutil) +{ Path editorfile, tmpfile, buf; strxcpy(editorfile, AddPath(CFG->goldpath, EDIT->File()), sizeof(Path)); - std::string cmdline = extutil->cmdline; + std::string cmdline = extutil.cmdline; - int mode = (extutil->options & EXTUTIL_KEEPCTRL) ? MODE_SAVE : MODE_SAVENOCTRL; + int mode = (extutil.options & EXTUTIL_KEEPCTRL) ? MODE_SAVE : MODE_SAVENOCTRL; SaveLines(mode, editorfile, msg, 79); strcpy(buf, editorfile); strchg(buf, GOLD_WRONG_SLASH_CHR, GOLD_SLASH_CHR); @@ -562,20 +563,20 @@ int ExternUtil(GMsg *msg, ExtUtil *extutil) { TokenXlat(MODE_NEW, cmdline, msg, msg, CurrArea); int pauseval = 0; - if(extutil->options & EXTUTIL_PAUSEONERROR) + if(extutil.options & EXTUTIL_PAUSEONERROR) pauseval = -1; - if(extutil->options & EXTUTIL_PAUSE) + if(extutil.options & EXTUTIL_PAUSE) pauseval = 1; ShellToDos(cmdline.c_str(), "", - extutil->options & EXTUTIL_CLS ? LGREY_|_BLACK : BLACK_|_BLACK, - extutil->options & EXTUTIL_CURSOR, + extutil.options & EXTUTIL_CLS ? LGREY_|_BLACK : BLACK_|_BLACK, + extutil.options & EXTUTIL_CURSOR, pauseval ); - if(extutil->options & EXTUTIL_RELOAD) { + if(extutil.options & EXTUTIL_RELOAD) { - if(not (extutil->options & EXTUTIL_KEEPCTRL)) { + if(not (extutil.options & EXTUTIL_KEEPCTRL)) { if (*msg->tearline or *msg->origin) { gfile fp(editorfile, "at"); @@ -621,7 +622,7 @@ int ExternUtil(GMsg *msg, ExtUtil *extutil) { msg->charsetlevel = LoadCharset(msg->charset, CFG->xlatlocalset); } - if(extutil->options & EXTUTIL_WIPE) + if(extutil.options & EXTUTIL_WIPE) WipeFile(editorfile, 0); if(tmpfile[0] != NUL) WipeFile(tmpfile, 0); @@ -632,15 +633,15 @@ int ExternUtil(GMsg *msg, ExtUtil *extutil) { // ------------------------------------------------------------------ -int ExternUtil(GMsg *msg, int utilno) { - - std::vector::iterator extutil = CFG->externutil.begin(); - - for(int utlno=0; extutil != CFG->externutil.end(); utlno++, extutil++) { - - if(extutil->utilno == utilno) { - return ExternUtil(msg, &(*extutil)); - } +int ExternUtil(GMsg *msg, uint32_t utilno) +{ + std::vector::iterator it = CFG->externutil.begin(); + std::vector::iterator end = CFG->externutil.end(); + + for (uint32_t i = 0; it != end; i++, it++) + { + if (it->utilno != i) continue; + return ExternUtil(msg, *it); } SayBibi(); @@ -650,147 +651,181 @@ int ExternUtil(GMsg *msg, int utilno) { // ------------------------------------------------------------------ -void ExternUtilMenu(GMsg* msg) { - int n; - std::vector::iterator i; +void ExternUtilMenu(GMsg* msg) +{ static int startat = 0; - char** Listi; - char buf[100]; static char cmdline[1024] = ""; + gstrarray Listi; - Listi = (char**)throw_calloc(CFG->externutil.size()+2, sizeof(char*)); - Listi[0] = throw_strdup(LNG->EnterCmdLine); - for(i = CFG->externutil.begin(), n=1; i != CFG->externutil.end(); n++, i++) { - sprintf(buf, " %02d %.59s%s ", i->utilno, i->cmdline, strlen(i->cmdline) > 59 ? ">" : "" ); - Listi[n] = throw_strdup(buf); + Listi.push_back(LNG->EnterCmdLine); + + std::vector::iterator it = CFG->externutil.begin(); + std::vector::iterator end = CFG->externutil.end(); + for (; it != end; it++) + { + char buf[100]; + sprintf(buf, " %02d %.59s%s ", it->utilno, it->cmdline, (it->cmdline.length() > 59) ? ">" : "" ); + Listi.push_back(buf); } - n = MinV(n, (MAXROW-10)); + + size_t n = MinV(Listi.size(), (MAXROW-10)); set_title(LNG->ExternUtil, TCENTER, C_ASKT); update_statusline(LNG->SelectExternUtil); whelppcat(H_ReadExternUtil); n = wpickstr(6, 0, 6+n+1, -1, W_BASK, C_ASKB, C_ASKW, C_ASKS, Listi, startat, title_shadow); whelpop(); - if(n != -1) { - if(n == 0) { - if(edit_string(cmdline, sizeof(cmdline), LNG->ExecCmdLine, H_ReadExternUtil)) { + + if (n != -1) + { + if (n == 0) + { + if (edit_string(cmdline, sizeof(cmdline), LNG->ExecCmdLine, H_ReadExternUtil)) + { ExtUtil extutil; extutil.utilno = 0; - strxcpy(extutil.cmdline, cmdline, sizeof(extutil.cmdline)); + extutil.cmdline = cmdline; extutil.options = CFG->externoptions; - reader_keyok = ExternUtil(msg, &extutil); + reader_keyok = ExternUtil(msg, extutil); } } - else { - reader_keyok = ExternUtil(msg, &CFG->externutil[n-1]); + else + { + reader_keyok = ExternUtil(msg, CFG->externutil[n-1]); } } - for(n=CFG->externutil.size()+1; n; n--) - throw_free(Listi[n-1]); - throw_free(Listi); } // ------------------------------------------------------------------ -static int PeekURLCmp(const char** a, const char** b) { - - return stricmp(*a, *b); +static bool PeekURLCmp(const std::string &a, const std::string b) +{ + return stricmp(a.c_str(), b.c_str()) > 0; } // ------------------------------------------------------------------ -void ReadPeekURLs(GMsg* msg) { - - Line **lin = msg->line; - const char *ptr, *end, *begin; - char buf[256]; - std::vector urls; - std::vector::iterator i; - int n; - +void ReadPeekURLs(GMsg* msg) +{ w_info(LNG->Wait); // Scan the current msg for urls int tline = reader_topline; - if(CFG->peekurloptions & PEEK_FROMTOP) + if (CFG->peekurloptions & PEEK_FROMTOP) tline = 0; - for(n=tline; nlines; n++) { - ptr = lin[n]->txt.c_str(); + Line **lin = msg->line; + std::vector urls; - while(*ptr) { - if(((begin = url_begin(ptr)) != NULL) and not strneql(ptr, "mailto:", 7)) { - end = begin+strcspn(begin, " \t\"\'<>()[]"); - if(ispunct(end[-1]) and (end[-1] != '/')) - --end; - if(begin < end) { - char* bufurl=(char*)throw_malloc(end-ptr+3); + for (int n = tline; n < msg->lines; n++) + { + const char *ptr = lin[n]->txt.c_str(); + + while (*ptr) + { + const char *urlBegin = url_begin(ptr); + if (urlBegin and not strneql(ptr, "mailto:", 7)) + { + const char *urlEnd = urlBegin + strcspn(urlBegin, " \t\"\'<>()[]"); + if (ispunct(urlEnd[-1]) and (urlEnd[-1] != '/')) + --urlEnd; + + if (urlBegin < urlEnd) + { + char* bufurl=(char*)throw_malloc(urlEnd - ptr + 3); bufurl[0] = ' '; - strxcpy(bufurl+1, ptr, (end-ptr)+1); + strxcpy(bufurl + 1, ptr, (urlEnd - ptr) + 1); strcat(bufurl, " "); - for(i = urls.begin(); i != urls.end(); i++) - if(strieql(*i, bufurl)) + + std::vector::iterator it = urls.begin(); + std::vector::iterator end = urls.end(); + for (; it != end; it++) + { + if (strieql(*it, bufurl)) break; - if(i == urls.end()) + } + + if (it == end) urls.push_back(bufurl); else throw_free(bufurl); - ptr = end-1; + + ptr = urlEnd - 1; } } + ptr++; } } w_info(NULL); - if(not urls.empty()) { + if (not urls.empty()) + { + gstrarray Listi; - char** Listi = (char**)throw_calloc(urls.size()+1, sizeof(char*)); - - for(n = 0, i = urls.begin(); i != urls.end(); i++, n++) - Listi[n] = *i; + std::vector::iterator it = urls.begin(); + std::vector::iterator end = urls.end(); + for (; it != end; it++) + { + Listi.push_back(*it); + } // Sort list if requested if(CFG->peekurloptions & FREQ_SORT) - qsort(Listi, urls.size(), sizeof(char*), (StdCmpCP)PeekURLCmp); + sort(Listi.begin(), Listi.end(), PeekURLCmp); // Run the picker - n = MinV((int)urls.size(), (MAXROW-10)); + size_t n = MinV(urls.size(), (MAXROW-10)); set_title(LNG->PeekURLMenuTitle, TCENTER, C_ASKT); update_statusline(LNG->PeekURLStat); whelppcat(H_PeekURL); - n = wpickstr(6, 0, 6+n+1, -1, W_BASK, C_ASKB, C_ASKW, C_ASKS, Listi, 0, title_shadow); + n = wpickstr(6, 0, 6 + n + 1, -1, W_BASK, C_ASKB, C_ASKW, C_ASKS, Listi, 0, title_shadow); whelpop(); - if(n != -1) { - std::string cmdline = CFG->urlhandler.cmdline; - strxmerge(buf, sizeof(buf), "\"", strtrim(strltrim(Listi[n])), "\"", NULL); - strischg(cmdline, "@url", buf); - strxcpy(buf, CFG->goldpath, sizeof(buf)); + if(n != -1) + { + std::vector::iterator it = CFG->urlhandler.begin(); + std::vector::iterator end = CFG->urlhandler.end(); +#if 0 // will be implemented later + for (; it != end; it++) + { + if (it->scheme.match(Listi[n].c_str(), gregex::extended | gregex::icase)) + break; + } +#else + it = end; +#endif + + if (it == end) it = CFG->urlhandler.begin(); + + std::string cmdline = it->handler.cmdline; + std::string buf = "\"" + strtrim(strltrim(Listi[n])) + "\""; + strischg(cmdline, "@url", buf.c_str()); + + buf = CFG->goldpath; strchg(buf, GOLD_WRONG_SLASH_CHR, GOLD_SLASH_CHR); - strischg(cmdline, "@path", buf); + strischg(cmdline, "@path", buf.c_str()); + TokenXlat(MODE_NEW, cmdline, msg, msg, CurrArea); int pauseval = 0; - if(CFG->urlhandler.options & EXTUTIL_PAUSEONERROR) + if (it->handler.options & EXTUTIL_PAUSEONERROR) pauseval = -1; - if(CFG->urlhandler.options & EXTUTIL_PAUSE) + + if (it->handler.options & EXTUTIL_PAUSE) pauseval = 1; ShellToDos(cmdline.c_str(), "", - CFG->urlhandler.options & EXTUTIL_CLS ? LGREY_|_BLACK : BLACK_|_BLACK, - CFG->urlhandler.options & EXTUTIL_CURSOR, + it->handler.options & EXTUTIL_CLS ? LGREY_|_BLACK : BLACK_|_BLACK, + it->handler.options & EXTUTIL_CURSOR, pauseval ); } - - for(n = 0, i = urls.begin(); i != urls.end(); i++, n++) - throw_free(Listi[n]); - throw_free(Listi); } - else { + else + { w_info(LNG->PeekInfoNoURLs); waitkeyt(10000); w_info(NULL); diff --git a/golded3/gesrch.h b/golded3/gesrch.h index b9f7c2c..8b525f5 100644 --- a/golded3/gesrch.h +++ b/golded3/gesrch.h @@ -26,7 +26,6 @@ #ifndef __GESRCH_H #define __GESRCH_H -#include #include diff --git a/golded3/golded.h b/golded3/golded.h index 18aa062..7110707 100644 --- a/golded3/golded.h +++ b/golded3/golded.h @@ -66,7 +66,6 @@ #include #include #include -#include #include #include #include diff --git a/goldlib/gall/gdirposx.h b/goldlib/gall/gdirposx.h index 2df32cc..7bf1b55 100644 --- a/goldlib/gall/gdirposx.h +++ b/goldlib/gall/gdirposx.h @@ -31,7 +31,7 @@ // ------------------------------------------------------------------ #include -#include +#include // ------------------------------------------------------------------ diff --git a/goldlib/gall/geall.h b/goldlib/gall/geall.h index a6754b4..9157360 100644 --- a/goldlib/gall/geall.h +++ b/goldlib/gall/geall.h @@ -31,6 +31,7 @@ #include #include +#include // ------------------------------------------------------------------ @@ -239,9 +240,9 @@ const int DISPMSGSIZE_LINES = 3; // ------------------------------------------------------------------ // Replylink types -const int REPLYLINK_DIRECT = 0; -const int REPLYLINK_CHAIN = 1; -const int REPLYLINK_NONE = 2; +const int REPLYLINK_DIRECT = 0; +const int REPLYLINK_CHAIN = 1; +const int REPLYLINK_NONE = 2; const int REPLYLINKLIST_FAST = 0; const int REPLYLINKLIST_FULL = 1; @@ -562,23 +563,32 @@ struct infoLookup { // ------------------------------------------------------------------ // Structures and constants for external utilities -const int EXTUTIL_CLS = 0x0001; -const int EXTUTIL_CURSOR = 0x0004; -const int EXTUTIL_RELOAD = 0x0008; -const int EXTUTIL_PAUSE = 0x0010; -const int EXTUTIL_PAUSEONERROR = 0x0020; -const int EXTUTIL_WIPE = 0x0040; -const int EXTUTIL_KEEPCTRL = 0x0080; +const uint32_t EXTUTIL_CLS = 0x0001; +const uint32_t EXTUTIL_CURSOR = 0x0004; +const uint32_t EXTUTIL_RELOAD = 0x0008; +const uint32_t EXTUTIL_PAUSE = 0x0010; +const uint32_t EXTUTIL_PAUSEONERROR = 0x0020; +const uint32_t EXTUTIL_WIPE = 0x0040; +const uint32_t EXTUTIL_KEEPCTRL = 0x0080; -struct ExtUtil { - int utilno; - int options; - char cmdline[256]; +struct ExtUtil +{ + uint32_t utilno; + uint32_t options; + std::string cmdline; }; -struct SaveUtil { - int utilno; - char menutext[41]; +struct SaveUtil +{ + uint32_t utilno; + std::string menutext; +}; + +struct UrlHandler +{ + std::string name; + gregex scheme; + ExtUtil handler; }; diff --git a/goldlib/gall/gstrall.h b/goldlib/gall/gstrall.h index bf23649..97bdca9 100644 --- a/goldlib/gall/gstrall.h +++ b/goldlib/gall/gstrall.h @@ -33,6 +33,7 @@ // Required headers #include +#include #include #include #include @@ -54,11 +55,17 @@ char* strlwr(char* s); #endif +// ------------------------------------------------------------------ + +typedef std::vector gstrarray; + + // ------------------------------------------------------------------ // Function prototypes bool strblank(const char* str); -int strchg(char* str, char oldch, char newch); +size_t strchg(char *str, char oldch, char newch); +size_t strchg(std::string &str, char oldch, char newch); char* stridela(const char* substr, char* str); int strnicmpw(const char* str1, const char* str2, int len); const char* striinc(const char* str1, const char* str2); @@ -74,7 +81,8 @@ char* strshr(char* str, int count); char* strsrep(char* str, const char* search, const char* replace); char* strltrim(char* str); char* strtrim(char* str); -std::string& strtrim(std::string& p); +std::string &strtrim(std::string &str); +std::string &strltrim(std::string &str); char* struplow(char* str); char* longdotstr(long num); // Convert a long to a dotted string: xxx.xxx.xxx.xxx @@ -147,6 +155,8 @@ int gsprintf(TCHAR* buffer, size_t sizeOfBuffer, const TCHAR* __file, int __line // ------------------------------------------------------------------ // String tokenizer class +void tokenize(gstrarray &array, const TCHAR* str, const TCHAR *delim = NULL); + class GTok { protected: diff --git a/goldlib/gall/gstrarr.h b/goldlib/gall/gstrarr.h index 8ef7b88..e69de29 100644 --- a/goldlib/gall/gstrarr.h +++ b/goldlib/gall/gstrarr.h @@ -1,76 +0,0 @@ -// This may look like C code, but it is really -*- C++ -*- - -// ------------------------------------------------------------------ -// The Goldware Library -// Copyright (C) 1999-2000 Alexander S. Aganichev -// ------------------------------------------------------------------ -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Library General Public -// License as published by the Free Software Foundation; either -// version 2 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Library General Public License for more details. -// -// You should have received a copy of the GNU Library General Public -// License along with this program; if not, write to the Free -// Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, -// MA 02111-1307, USA -// ------------------------------------------------------------------ -// $Id$ -// ------------------------------------------------------------------ -// String manipulation routines. -// ------------------------------------------------------------------ - -#ifndef __gstrarr_h -#define __gstrarr_h - - -// ------------------------------------------------------------------ - -#include -#include -#include -#include -#include - - -// ------------------------------------------------------------------ - -typedef std::vector gstrarray; - - -// ------------------------------------------------------------------ - -inline void tokenize(gstrarray &array, const TCHAR* str, const TCHAR *delim = NULL) -{ - if (delim == NULL) delim = ", \t"; - TCHAR *tmp = throw_xstrdup(str); -#if defined(_tcstok_s) - TCHAR *next_token; - TCHAR *token = _tcstok_s(tmp, delim, &next_token); -#else - TCHAR *token = strtok(tmp, delim); -#endif - - while (NULL != token) - { - array.push_back(token); -#if defined(_tcstok_s) - token = _tcstok_s(NULL, delim, &next_token); -#else - token = strtok(NULL, delim); -#endif - } - - throw_xfree(tmp); -} - - -// ------------------------------------------------------------------ - -#endif // __gstrarr_h - -// ------------------------------------------------------------------ diff --git a/goldlib/gall/gstrutil.cpp b/goldlib/gall/gstrutil.cpp index dd2280a..4abbbd3 100644 --- a/goldlib/gall/gstrutil.cpp +++ b/goldlib/gall/gstrutil.cpp @@ -52,12 +52,14 @@ bool strblank(const char* str) { // ------------------------------------------------------------------ // Changes all occurrences of one character to another -int strchg(char* str, char oldch, char newch) { +size_t strchg(char *str, char oldch, char newch) +{ + size_t count = 0; - int count = 0; - - for(char* p=str; *p; p++) { - if(oldch == *p) { + for (char *p = str; *p; p++) + { + if (oldch == *p) + { *p = newch; count++; } @@ -67,6 +69,28 @@ int strchg(char* str, char oldch, char newch) { } +// ------------------------------------------------------------------ +// Changes all occurrences of one character to another + +size_t strchg(std::string &str, char oldch, char newch) +{ + size_t count = 0; + + std::string::iterator it = str.begin(); + std::string::iterator end = str.end(); + for (; it != end; it++) + { + if (oldch == *it) + { + *it = newch; + count++; + } + } + + return count; +} + + // ------------------------------------------------------------------ // Deletes a substring from within a string @@ -478,28 +502,34 @@ char* strtrim(char* p) { } -std::string& strtrim(std::string& p) { +std::string &strtrim(std::string &str) +{ + if (!str.empty()) + { + std::string::iterator trail = str.end(); - if(not p.empty()) { - std::string::iterator trail = p.end(); - while(trail != p.begin()) { + while(trail != str.begin()) + { --trail; - if(not isspace(*trail) and not iscntrl(*trail)) { + if (not isspace(*trail) and not iscntrl(*trail)) + { ++trail; break; } } - p.erase(trail, p.end()); + + str.erase(trail, str.end()); } - return p; + + return str; } // ------------------------------------------------------------------ // Trims leading spaces off of a string -char* strltrim(char* str) { - +char* strltrim(char* str) +{ char* p; char* q; @@ -516,6 +546,22 @@ char* strltrim(char* str) { return str; } +// ------------------------------------------------------------------ + +std::string &strltrim(std::string &str) +{ + if (!str.empty()) + { + std::string::iterator begin = str.begin(); + std::string::iterator end = str.end(); + std::string::iterator it = begin; + + for (; (it != end) && isspace(*it); it++) { /**/ } + if (it != begin) str.erase(begin, it); + } + + return str; +} // ------------------------------------------------------------------ @@ -695,4 +741,33 @@ char* strlwr(char* s) { #endif +// ------------------------------------------------------------------ + +void tokenize(gstrarray &array, const TCHAR* str, const TCHAR *delim) +{ + if (delim == NULL) delim = ", \t"; + +#if defined(_tcstok_s) + TCHAR *tmp = _strdup(str); + TCHAR *next_token; + TCHAR *token = _tcstok_s(tmp, delim, &next_token); +#else + TCHAR *tmp = strdup(str); + TCHAR *token = strtok(tmp, delim); +#endif + + while (token) + { + array.push_back(token); +#if defined(_tcstok_s) + token = _tcstok_s(NULL, delim, &next_token); +#else + token = strtok(NULL, delim); +#endif + } + + free(tmp); +} + + // ------------------------------------------------------------------ diff --git a/goldlib/gall/gvidall.h b/goldlib/gall/gvidall.h index 2d899a2..48be7e4 100644 --- a/goldlib/gall/gvidall.h +++ b/goldlib/gall/gvidall.h @@ -313,8 +313,8 @@ public: int currow; // Current cursor row int curcol; // Current cursor column - int numrows; // number of displayed rows - int numcols; // number of displayed columns + size_t numrows; // number of displayed rows + size_t numcols; // number of displayed columns word videoseg; // video buffer segment address diff --git a/goldlib/gall/gwinall.h b/goldlib/gall/gwinall.h index 8a88228..3fdf740 100644 --- a/goldlib/gall/gwinall.h +++ b/goldlib/gall/gwinall.h @@ -371,7 +371,7 @@ int wopen (int srow, int scol, int erow, int ecol, int btype, vattr inline int wopen_ (int srow, int scol, int vlen, int hlen, int btype, vattr battr, vattr wattr, vattr sbattr = DEFATTR, vattr loattr = DEFATTR) { return wopen(srow, scol, srow+vlen-1, scol+hlen-1, btype, battr, wattr, sbattr, loattr); } int wperror (const char* message); bool wpickfile (int srow, int scol, int erow, int ecol, int btype, vattr bordattr, vattr winattr, vattr barattr, bool title, std::string &filespec, IfcpCP open, bool casesens=false); -int wpickstr (int srow, int scol, int erow, int ecol, int btype, vattr bordattr, vattr winattr, vattr barattr, char* strarr[], int initelem, VfvCP open); +int wpickstr (int srow, int scol, int erow, int ecol, int btype, vattr bordattr, vattr winattr, vattr barattr, gstrarray &strarr, int initelem, VfvCP open); int wprintc (int wrow, int wcol, vattr attr, vchar ch); int wprintf (const char* format, ...) __attribute__ ((format (printf, 1, 2))); int wprintaf (int attr, const char* format, ...) __attribute__ ((format (printf, 2, 3))); @@ -379,7 +379,7 @@ int wprintfs (int wrow, int wcol, vattr attr, const char* format, ...) int wprints (int wrow, int wcol, vattr attr, const char* str); int wprints_box (int wrow, int wcol, vattr attr, const char* str); int wprintvs (int wrow, int wcol, vattr attr, const vchar* str); -int wprintns (int wrow, int wcol, vattr attr, const char* str, uint len, vchar fill=' ', vattr fill_attr = DEFATTR); +int wprintns (int wrow, int wcol, vattr attr, const std::string &str, uint len, vchar fill=' ', vattr fill_attr = DEFATTR); int wprintsf (int wrow, int wcol, vattr attr, const char* format, const char* str); int wprintws (int wrow, int wcol, vatch* buf, uint len); void wpropbar (int xx, int yy, long len, vattr attr, long pos, long size); diff --git a/goldlib/gall/gwinbase.cpp b/goldlib/gall/gwinbase.cpp index 5faf885..3eadf03 100644 --- a/goldlib/gall/gwinbase.cpp +++ b/goldlib/gall/gwinbase.cpp @@ -951,9 +951,9 @@ int wputy(int wrow, int wcol, vattr attr, vchar chr, uint len) { // ------------------------------------------------------------------ // Displays a string inside active window -int wprintns(int wrow, int wcol, vattr attr, const char* str, uint len, vchar fill, vattr fill_attr) +int wprintns(int wrow, int wcol, vattr attr, const std::string &str, uint len, vchar fill, vattr fill_attr) { - char* istr = throw_xstrdup(str); + char* istr = throw_xstrdup(str.c_str()); char* ostr = istr; char och = *ostr; uint olen = strlen(istr); diff --git a/goldlib/gall/gwinpckf.cpp b/goldlib/gall/gwinpckf.cpp index 53ad3c3..5db91fb 100644 --- a/goldlib/gall/gwinpckf.cpp +++ b/goldlib/gall/gwinpckf.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -49,30 +50,29 @@ static char* namextp; // ------------------------------------------------------------------ -// this function is the compare function for qsort() - -static int compare(const char** str1, const char** str2) { +// this function is the compare function for std::sort() +static bool compare(const std::string str1, const std::string str2) +{ // Sort with directories first - bool dir1 = !!strchr(*str1, GOLD_SLASH_CHR); - bool dir2 = !!strchr(*str2, GOLD_SLASH_CHR); - int cmp = compare_two(dir2, dir1); - if(cmp != 0) - return cmp; + bool dir1 = !!strchr(str1.c_str(), GOLD_SLASH_CHR); + bool dir2 = !!strchr(str2.c_str(), GOLD_SLASH_CHR); + if (dir1 && !dir2) return true; - Path p1, p2; - strcpy(p1, *str1); if(dir1) { p1[strlen(p1)-1] = NUL; } - strcpy(p2, *str2); if(dir2) { p2[strlen(p2)-1] = NUL; } + std::string s1 = dir1 ? str1.substr(0, str1.length()-1) : str1; + std::string s2 = dir2 ? str2.substr(0, str2.length()-1) : str2; - if(case_sensitive) - return strcmp(p1, p2); - else { - cmp = stricmp(p1, p2); - if(cmp == 0) - cmp = strcmp(p1, p2); + int cmp; + if (case_sensitive) + cmp = strcmp(s1.c_str(), s2.c_str()); + else + { + cmp = stricmp(s1.c_str(), s2.c_str()); + if (cmp == 0) + cmp = strcmp(s1.c_str(), s2.c_str()); } - return cmp; + return (cmp > 0); } @@ -101,39 +101,15 @@ static void disp_title() { // ------------------------------------------------------------------ -// this function frees all allocated strings in the array of pointers - -static void free_strings(char** p, int numelems) { - - for(int i=0;iis_directory()) { + if (de->is_directory()) + { if(de->name != ".") { strxmerge(path, sizeof(Path), de->name.c_str(), GOLD_SLASH_STR, NULL); name = path; } } - else if(de->is_file()) { + else if(de->is_file()) + { if(case_sensitive ? gwildmat(de->name.c_str(), namext) : gwildmati(de->name.c_str(), namext)) name = de->name.c_str(); } - if(name) { - p[files] = throw_xstrdup(name); - files++; - if(files == allocated-1) { - allocated *= 2; - p = (char**)throw_xrealloc(p, allocated*sizeof(char*)); - } - } + + if (name) strarr.push_back(name); } } - p[files] = NULL; // sort files in array by swapping their pointers - qsort(p, files, sizeof(char*), (StdCmpCP)compare); + sort(strarr.begin( ), strarr.end( ), compare); + //std::qsort(p, files, sizeof(char*), (StdCmpCP)compare); // let user pick file - if(files) - picked = wpickstr(srow, scol, erow, ecol, btype, bordattr, winattr, barattr, p, 0, disp_title); - if(picked == -1 or files == 0) { - pre_exit(p, files); + if (strarr.size()) + { + picked = wpickstr(srow, scol, erow, ecol, btype, bordattr, winattr, barattr, strarr, 0, disp_title); + } + + if (picked == -1 or !strarr.size()) + { + gchdir(tcwdp); return false; } // see if a directory was selected. if so save // directory name, otherwise build whole path name - q = strchr(p[picked], GOLD_SLASH_CHR); - if(q) { + const char *slash = strchr(strarr[picked].c_str(), GOLD_SLASH_CHR); + if (slash) + { finished = false; - strcpy(dir, p[picked]); + strcpy(dir, strarr[picked].c_str()); r = strrchr(dir, GOLD_SLASH_CHR); - if(r) - *r = NUL; - *q = NUL; + if (r) *r = NUL; } else { finished = true; PathCopy(filespec, cwd); - filespec += p[picked]; + filespec += strarr[picked].c_str(); } - // free allocated strings - free_strings(p, files); + strarr.clear(); + } + while(not finished); // if a directory was selected, go back and do again - // if a directory was selected, go back and do again - } while(not finished); - - // change back to current drive and directory - gchdir(tcwd); - - // free allocated char pointers - throw_xfree(p); - - // return normally - return true; + gchdir(tcwd); // change back to current drive and directory + return true; // return normally } diff --git a/goldlib/gall/gwinpcks.cpp b/goldlib/gall/gwinpcks.cpp index 6ffc8b7..d050247 100644 --- a/goldlib/gall/gwinpcks.cpp +++ b/goldlib/gall/gwinpcks.cpp @@ -98,8 +98,8 @@ static void hide_mouse_cursor_pck() { // this function updates the current item by either // displaying or erasing the selection bar on it -static void update_curr(char* strarr[], r_t* r, int bar) { - +static void update_curr( const gstrarray &strarr, r_t* r, int bar) +{ // calculate row and column string will be displayed // at, then print out the string character-by-character @@ -119,8 +119,8 @@ static void update_curr(char* strarr[], r_t* r, int bar) { // ------------------------------------------------------------------ -static void update_line(char* strarr[], r_t* r, int wrow, int upcurr) { - +static void update_line(const gstrarray &strarr, r_t* r, int wrow, int upcurr) +{ int nomore = false; int ccol = r->gapspaces + r->xtraspaces; int celem = (wrow*r->strsperline) + r->first; @@ -142,8 +142,8 @@ static void update_line(char* strarr[], r_t* r, int wrow, int upcurr) { // ------------------------------------------------------------------ // this function will update all items in the window -static void update_window(char* strarr[], r_t* r) { - +static void update_window(const gstrarray &strarr, r_t* r) +{ hide_mouse_cursor_pck(); for(int crow=0; crowwheight; crow++) update_line(strarr, r, crow, 1); @@ -205,8 +205,8 @@ static int e_endwin(r_t* r, int felem) { // ------------------------------------------------------------------ -static void goto_item(r_t* r, char* strarr[], int elem) { - +static void goto_item(r_t* r, const gstrarray &strarr, int elem) +{ if(elem<0 or elem>r->lastelem) elem = 0; int outside = (elemfirst or elem>r->last) ? YES : NO; @@ -260,8 +260,8 @@ static int mouse_on_item(r_t* r, int mcrow, int mccol) { // ------------------------------------------------------------------ -static void page_down(char* strarr[], r_t* r) { - +static void page_down(const gstrarray &strarr, r_t* r) +{ if(r->curr != r->last) { r->curr = r->last; update_window(strarr, r); @@ -279,8 +279,8 @@ static void page_down(char* strarr[], r_t* r) { // ------------------------------------------------------------------ -static void page_up(char* strarr[], r_t* r) { - +static void page_up(const gstrarray &strarr, r_t* r) +{ if(r->curr != r->first) { r->curr = r->first; update_window(strarr, r); @@ -297,8 +297,8 @@ static void page_up(char* strarr[], r_t* r) { // ------------------------------------------------------------------ -static void scroll_down(char* strarr[], r_t* r, int upcurr) { - +static void scroll_down(const gstrarray &strarr, r_t* r, int upcurr) +{ if(r->first) { hide_mouse_cursor_pck(); if(upcurr) @@ -317,8 +317,8 @@ static void scroll_down(char* strarr[], r_t* r, int upcurr) { // ------------------------------------------------------------------ -static void scroll_up(char* strarr[], r_t* r, int upcurr) { - +static void scroll_up(const gstrarray &strarr, r_t* r, int upcurr) +{ if(r->last!=(r->lastelem)) { hide_mouse_cursor_pck(); if(upcurr) @@ -339,8 +339,8 @@ static void scroll_up(char* strarr[], r_t* r, int upcurr) { // ------------------------------------------------------------------ // this function reads the mouse for input -static gkey read_mouse(char* strarr[], r_t* r) { - +static gkey read_mouse(const gstrarray & /*strarr*/, r_t* /*r*/) +{ #ifdef GOLD_MOUSE // if free-floating mouse cursor support is on if(gmou.FreeCursor()) { @@ -403,12 +403,11 @@ static gkey read_mouse(char* strarr[], r_t* r) { // ------------------------------------------------------------------ -int wpickstr(int srow, int scol, int erow, int ecol, int btype, vattr bordattr, vattr winattr, vattr barattr, char* strarr[], int initelem, VfvCP open) { - - int i, j, maxlen, outside; +int wpickstr(int srow, int scol, int erow, int ecol, int btype, vattr bordattr, vattr winattr, vattr barattr, gstrarray &strarr, int initelem, VfvCP open) +{ + int outside; gkey xch; char ch; - char* p; r_t r; int quickpos = (strarr[0][0] == ' ') ? 1 : 0; @@ -416,14 +415,22 @@ int wpickstr(int srow, int scol, int erow, int ecol, int btype, vattr bordattr, // go through input array and determine the longest // string, and count the number of elements in the array - maxlen = strlen(m_title); + size_t maxlen = strlen(m_title); - for (i = 0; strarr[i] != NULL; i++) - if ((j = strlen(strarr[i])) > maxlen) - maxlen = j; + gstrarray::const_iterator it = strarr.begin(); + gstrarray::const_iterator end = strarr.end(); + for (; it != end; it++) + { + size_t len; + if ((len = it->length()) > maxlen) + { + maxlen = len; + } + } r.maxstrlen = maxlen; - r.lastelem = ((r.numelems=i)-1); + r.numelems = strarr.size(); + r.lastelem = r.numelems - 1; r.winattr = winattr; r.barattr = barattr; @@ -507,16 +514,18 @@ int wpickstr(int srow, int scol, int erow, int ecol, int btype, vattr bordattr, switch(xch) { case Key_Space: - if(wpickstr_tag) { - p = strarr[r.curr]; - switch(*p) { + if (wpickstr_tag) + { + char p = strarr[r.curr][0]; + switch (p) + { case ' ': - *p = (char)wpickstr_tag; - update_curr(strarr,&r,1); + strarr[r.curr][0] = (char)wpickstr_tag; + update_curr(strarr, &r, 1); break; default: - *p = ' '; - update_curr(strarr,&r,1); + strarr[r.curr][0] = ' '; + update_curr(strarr, &r, 1); } kbput(Key_Dwn); } @@ -544,18 +553,26 @@ int wpickstr(int srow, int scol, int erow, int ecol, int btype, vattr bordattr, case Key_StrG: case Key_S_8: - if(wpickstr_tag) { - for(i=0; i -#include #include #include diff --git a/windows/golded.vcproj b/windows/golded.vcproj index 89db107..125b629 100644 --- a/windows/golded.vcproj +++ b/windows/golded.vcproj @@ -2716,10 +2716,6 @@ - - + + + + + + + + + + + + + + @@ -940,6 +976,38 @@ RelativePath="..\goldlib\gall\gwinput2.cpp" > + + + + + + + + + + + + + + + +