Refactoring. Added URLSCHEME config keyword (not active yet).

This commit is contained in:
Ianos Gnatiuc 2007-01-08 09:48:18 +00:00
parent 0d84e02cfa
commit 3750658bf2
30 changed files with 796 additions and 574 deletions

View File

@ -52,7 +52,6 @@ Global
{C23888DA-7024-4A38-A8C5-CE4BEFA4629A}.Release|x64.ActiveCfg = Release|x64 {C23888DA-7024-4A38-A8C5-CE4BEFA4629A}.Release|x64.ActiveCfg = Release|x64
{C23888DA-7024-4A38-A8C5-CE4BEFA4629A}.Release|x64.Build.0 = 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.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.ActiveCfg = Debug|x64
{B80E3728-98E5-4A9A-B883-9C064F1FFFA7}.Debug|x64.Build.0 = Debug|x64 {B80E3728-98E5-4A9A-B883-9C064F1FFFA7}.Debug|x64.Build.0 = Debug|x64
{B80E3728-98E5-4A9A-B883-9C064F1FFFA7}.Release|Win32.ActiveCfg = Release|Win32 {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.ActiveCfg = Release|x64
{B80E3728-98E5-4A9A-B883-9C064F1FFFA7}.Release|x64.Build.0 = 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.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.ActiveCfg = Debug|x64
{951D76D2-FA57-4C95-8F65-A6C19C122AA5}.Debug|x64.Build.0 = Debug|x64 {951D76D2-FA57-4C95-8F65-A6C19C122AA5}.Debug|x64.Build.0 = Debug|x64
{951D76D2-FA57-4C95-8F65-A6C19C122AA5}.Release|Win32.ActiveCfg = Release|Win32 {951D76D2-FA57-4C95-8F65-A6C19C122AA5}.Release|Win32.ActiveCfg = Release|Win32

View File

@ -386,6 +386,7 @@ const word CRC_TWITSUBJ = 0x08C0;
const word CRC_TWITTO = 0x9DFE; const word CRC_TWITTO = 0x9DFE;
const word CRC_UNPACKER = 0x5691; const word CRC_UNPACKER = 0x5691;
const word CRC_URLHANDLER = 0x688E; const word CRC_URLHANDLER = 0x688E;
const word CRC_URLSCHEME = 0x89FC;
const word CRC_USEAREA = 0x2FD4; const word CRC_USEAREA = 0x2FD4;
const word CRC_USECHARSET = 0xE1B9; const word CRC_USECHARSET = 0xE1B9;
const word CRC_USEFLAGS = 0xE2B6; const word CRC_USEFLAGS = 0xE2B6;

View File

@ -588,6 +588,7 @@ SwitchU:
switch(crc) { switch(crc) {
case CRC_UNPACKER : CfgUnpacker (); break; case CRC_UNPACKER : CfgUnpacker (); break;
case CRC_URLHANDLER : CfgUrlhandler (); break; case CRC_URLHANDLER : CfgUrlhandler (); break;
case CRC_URLSCHEME : CfgUrlscheme (); break;
case CRC_USEAREA : CfgUsearea (); break; case CRC_USEAREA : CfgUsearea (); break;
case CRC_USECHARSET : CfgUsecharset (); break; case CRC_USECHARSET : CfgUsecharset (); break;
case CRC_USEFWD : CfgUsefwd (); break; case CRC_USEFWD : CfgUsefwd (); break;

View File

@ -41,7 +41,7 @@ void CfgExcludenodes() {
} }
// ------------------------------------------------------------------ // ------------------------------------------------------------------
void CfgExternoptions() { void CfgExternoptions() {
const word CRC_CLS = 0x34F4; const word CRC_CLS = 0x34F4;
@ -64,7 +64,7 @@ void CfgExternoptions() {
if(*val == '-') if(*val == '-')
val++; val++;
char* _key; char* _key;
word _crc = getkeyvalcrc(&_key, &val); word _crc = getkeyvalcrc(&_key, &val);
@ -119,8 +119,8 @@ void CfgExternoptions() {
// ------------------------------------------------------------------ // ------------------------------------------------------------------
void CfgExternutil() { void CfgExternutil()
{
ExtUtil extutil; ExtUtil extutil;
// Get util number // Get util number
@ -131,16 +131,18 @@ void CfgExternutil() {
// Get options // Get options
int _optbak = CFG->externoptions; int _optbak = CFG->externoptions;
while(strchr("-", *_val)) {
while(strchr("-", *_val))
{
getkeyval(&_key, &_val); getkeyval(&_key, &_val);
val = _key; val = _key;
CfgExternoptions(); CfgExternoptions();
} }
extutil.options = CFG->externoptions; extutil.options = CFG->externoptions;
CFG->externoptions = _optbak; CFG->externoptions = _optbak;
// Get commandline extutil.cmdline = _val; // Get commandline
strxcpy(extutil.cmdline, _val, sizeof(extutil.cmdline));
// Count it // Count it
CFG->externutil.push_back(extutil); CFG->externutil.push_back(extutil);
@ -293,14 +295,14 @@ void CfgGedhandshake() {
CFG->gedhandshake = make_bool(GetYesno(val)); CFG->gedhandshake = make_bool(GetYesno(val));
} }
// ------------------------------------------------------------------ // ------------------------------------------------------------------
void CfgGermankeyboard() { void CfgGermankeyboard() {
right_alt_same_as_left = not GetYesno(val); right_alt_same_as_left = not GetYesno(val);
} }
// ------------------------------------------------------------------ // ------------------------------------------------------------------
void CfgGoldbasepath(const char *path, bool force) { void CfgGoldbasepath(const char *path, bool force) {
@ -369,4 +371,3 @@ void CfgGroup() {
} }
// ------------------------------------------------------------------ // ------------------------------------------------------------------

View File

@ -329,24 +329,34 @@ void CfgUnpacker() {
// ------------------------------------------------------------------ // ------------------------------------------------------------------
void CfgUrlhandler() { void CfgUrlhandler()
{
// Get util number // Get util number
char* _key; char* _key;
char* _val = val; char* _val = val;
// Get options // Get options
int _optbak = CFG->externoptions; int _optbak = CFG->externoptions;
while(strchr("-", *_val)) {
while (strchr("-", *_val))
{
getkeyval(&_key, &_val); getkeyval(&_key, &_val);
val = _key; val = _key;
CfgExternoptions(); CfgExternoptions();
} }
CFG->urlhandler.options = CFG->externoptions;
UrlHandler url;
url.handler.cmdline = _val;
url.handler.options = CFG->externoptions;
CFG->externoptions = _optbak; CFG->externoptions = _optbak;
// Get commandline CFG->urlhandler.push_back(url);
strxcpy(CFG->urlhandler.cmdline, _val, sizeof(CFG->urlhandler.cmdline)); }
// ------------------------------------------------------------------
void CfgUrlscheme()
{
} }
// ------------------------------------------------------------------ // ------------------------------------------------------------------

View File

@ -366,6 +366,7 @@ void CfgTwitsubj ();
void CfgTwitto (); void CfgTwitto ();
void CfgUnpacker (); void CfgUnpacker ();
void CfgUrlhandler (); void CfgUrlhandler ();
void CfgUrlscheme ();
void CfgUsearea (); void CfgUsearea ();
void CfgUsecharset (); void CfgUsecharset ();
void CfgUseflags (); void CfgUseflags ();

View File

@ -302,7 +302,7 @@ public:
uint disptabsize; // tabsize; uint disptabsize; // tabsize;
bool encodeemailheaders; bool encodeemailheaders;
std::vector<GEvent> event; std::vector<GEvent> event;
int externoptions; uint32_t externoptions;
std::vector<ExtUtil> externutil; std::vector<ExtUtil> externutil;
Ezycom ezycom; Ezycom ezycom;
int ezycomuserno; int ezycomuserno;
@ -451,7 +451,7 @@ public:
std::vector<Node> twitname; std::vector<Node> twitname;
gstrarray twitsubj; gstrarray twitsubj;
std::vector< std::pair<std::string, std::string> > unpacker; std::vector< std::pair<std::string, std::string> > unpacker;
ExtUtil urlhandler; std::vector<UrlHandler> urlhandler;
bool usearea; bool usearea;
bool usecharset; bool usecharset;
int usefwd; int usefwd;

View File

@ -25,6 +25,7 @@
// ------------------------------------------------------------------ // ------------------------------------------------------------------
#include <fcntl.h> #include <fcntl.h>
#include <algorithm>
#include <golded.h> #include <golded.h>
#include <gwildmat.h> #include <gwildmat.h>
#include <gdirposx.h> #include <gdirposx.h>
@ -622,9 +623,9 @@ void CreateFileMsgs(int mode, GMsg* msg) {
// ------------------------------------------------------------------ // ------------------------------------------------------------------
static int FreqCmp(const char** a, const char** b) { static bool FreqCmp(const std::string &a, const std::string &b)
{
return stricmp(*a, *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"); GFTRK("FileRequest");
int oldtopline = reader_topline; 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]; char buf[256];
const char* ptr; const char* ptr;
const char* ptr1 = NULL; const char* ptr1 = NULL;
const char* ptr2; const char* ptr2;
const char* txtptr; const char* txtptr;
char** freqfile = NULL;
int gotticket = false; int gotticket = false;
int getnextdesc = false; int getnextdesc = false;
Line** lin = msg->line; Line** lin = msg->line;
char file[GMAXPATH], desc[200], filesize[10]; char file[GMAXPATH], desc[200], filesize[10];
int freqfiles = 0;
bool esc = true; bool esc = true;
int n;
byte numlines = 0; byte numlines = 0;
*desc = *file = *filesize = NUL; *desc = *file = *filesize = NUL;
@ -753,8 +752,9 @@ void FileRequest(GMsg* msg) {
int tline = reader_topline; int tline = reader_topline;
if(CFG->frqoptions & FREQ_FROMTOP) if(CFG->frqoptions & FREQ_FROMTOP)
tline = 0; tline = 0;
for(n=tline; n<msg->lines; n++) {
for (size_t n = tline; n < msg->lines; n++)
{
// Don't look in control info for files // Don't look in control info for files
if(lin[n]->type & (GLINE_KLUDGE|GLINE_TEAR|GLINE_ORIG)) if(lin[n]->type & (GLINE_KLUDGE|GLINE_TEAR|GLINE_ORIG))
continue; continue;
@ -895,13 +895,11 @@ void FileRequest(GMsg* msg) {
if (*file and *desc) if (*file and *desc)
{ {
// Yes, so add it to the list // 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); gsprintf(PRINTF_DECLARE_BUFFER(buf), " %-12s %8s %s", file, filesize, desc);
strsetsz(buf, 76); strsetsz(buf, 76);
freqfile[freqfiles] = throw_strdup(buf); freqfile.push_back(buf);
*desc = *file = *filesize = NUL; *desc = *file = *filesize = NUL;
numlines = 0; numlines = 0;
freqfiles++;
} }
// Maybe there was a false match, so re-initialize if // Maybe there was a false match, so re-initialize if
@ -919,27 +917,24 @@ void FileRequest(GMsg* msg) {
{ {
strcpy(file, "FILES"); strcpy(file, "FILES");
gsprintf(PRINTF_DECLARE_BUFFER(desc), LNG->FilelistFrom, msg->By()); 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); gsprintf(PRINTF_DECLARE_BUFFER(buf), " %-12.12s %-52.52s ", file, desc);
freqfile[freqfiles] = throw_strdup(buf); freqfile.push_back(buf);
*desc = *file = NUL; *desc = *file = NUL;
freqfiles++;
} }
w_info(NULL); w_info(NULL);
// Let user select the file(s) to be requested // Let user select the file(s) to be requested
if(freqfile) { if (freqfile.size())
{
// NULL terminate list
freqfile[freqfiles] = NULL;
// Sort list if requested // Sort list if requested
if(CFG->frqoptions & FREQ_SORT) if (CFG->frqoptions & FREQ_SORT)
qsort(freqfile, freqfiles, sizeof(char*), (StdCmpCP)FreqCmp); {
sort(freqfile.begin(), freqfile.end(), FreqCmp);
}
// Run the picker // Run the picker
int items = MinV(freqfiles, (MAXROW-10)); int items = MinV(freqfile.size(), MAXROW-10);
set_title(LNG->FreqMenuTitle, TCENTER, C_ASKT); set_title(LNG->FreqMenuTitle, TCENTER, C_ASKT);
update_statusline(LNG->FreqStat); update_statusline(LNG->FreqStat);
whelppcat(H_FileRequest); whelppcat(H_FileRequest);
@ -963,10 +958,16 @@ void FileRequest(GMsg* msg) {
// Handle picked files // Handle picked files
msg->re[0] = NUL; msg->re[0] = NUL;
for(n=0; n<freqfiles; n++) {
if(*freqfile[n] != ' ') { gstrarray::iterator it = freqfile.begin();
gstrarray::iterator end = freqfile.end();
for (; it != end; it++)
{
if((*it)[0] != ' ')
{
msg->attr.frq1(); msg->attr.frq1();
ptr = freqfile[n]+1; // 01234567890123456 ptr = &(*it)[1]; // 01234567890123456
ptr2 = strskip_txt(ptr); ptr2 = strskip_txt(ptr);
#if defined(__USE_ALLOCA__) #if defined(__USE_ALLOCA__)
char *tmpbuf = (char*)alloca(ptr2-ptr+1); 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 :-(( // AARRRGGGHH!! More bloody duplicate code :-((
msg->attr.frq1(); msg->attr.frq1();
ptr = freqfile[crsr]+1; // 01234567890123456 ptr = &freqfile[crsr][1]; // 01234567890123456
ptr2 = strskip_txt(ptr); ptr2 = strskip_txt(ptr);
#if defined(__USE_ALLOCA__) #if defined(__USE_ALLOCA__)
char *tmpbuf = (char*)alloca(ptr2-ptr+1); char *tmpbuf = (char*)alloca(ptr2-ptr+1);
@ -1033,8 +1036,10 @@ void FileRequest(GMsg* msg) {
int destarea = CurrArea; int destarea = CurrArea;
reader_topline = 0; reader_topline = 0;
AA->attr().hex0(); AA->attr().hex0();
if(*AA->Areafreqto()) { if (*AA->Areafreqto())
for(n=0; (uint) n<AL.size(); n++) { {
for (size_t n = 0; n < AL.size(); n++)
{
if(strieql(AL[n]->echoid(), AA->Areafreqto())) { if(strieql(AL[n]->echoid(), AA->Areafreqto())) {
destarea = AL[n]->areaid(); destarea = AL[n]->areaid();
break; break;
@ -1065,12 +1070,6 @@ void FileRequest(GMsg* msg) {
} }
} }
if(freqfile) {
for(n=0; n<freqfiles; n++)
throw_release(freqfile[n]);
throw_free(freqfile);
}
if(gkbd.quitall) if(gkbd.quitall)
QuitNow(); QuitNow();
} }

View File

@ -502,6 +502,14 @@ BOOL WINAPI GoldedCtrlHandler(DWORD dwCtrlType) {
#endif #endif
// ------------------------------------------------------------------
void Uninitialize()
{
delete WideUsername;
}
// ------------------------------------------------------------------ // ------------------------------------------------------------------
// Initialize defaults and generally get the system up and running // Initialize defaults and generally get the system up and running

View File

@ -26,7 +26,22 @@
#include <golded.h> #include <golded.h>
#include <gutlos.h> #include <gutlos.h>
#include <memleak.h>
#if defined(_MSC_VER) && defined(_DEBUG)
static struct LeakFinder
{
LeakFinder()
{
InitAllocCheck();
}
~LeakFinder()
{
DeInitAllocCheck();
}
} leakFinder;
#endif
// ------------------------------------------------------------------ // ------------------------------------------------------------------
// Main function // Main function
@ -35,6 +50,7 @@ int main(int argc, char *argv[]) {
Initialize(argc, argv); Initialize(argc, argv);
Reader(); Reader();
Uninitialize();
return errorlevel; return errorlevel;
} }

View File

@ -387,7 +387,7 @@ static void DispAttrWindow(int show=-1) {
if(show) { if(show) {
wh_background = whandle(); 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); wide = MinV(wide, MAXCOL-4);
wh_attributes = wopen_(6, 0, 17, wide, W_BMENU, C_MENUB, C_MENUW); wh_attributes = wopen_(6, 0, 17, wide, W_BMENU, C_MENUB, C_MENUW);
set_title(LNG->AttrTitle, TCENTER, C_MENUT); 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) int SelectFromFile(const char* file, char* selection, const char* title, const char* nolines)
{ {
char buf[256]; char buf[256];
int n;
bool retval=false; bool retval=false;
char** Listi;
int lines = 0; int lines = 0;
gfile fp(AddPath(CFG->goldpath, file), "rt", CFG->sharemode); 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) if (lines)
{ {
Listi = (char**)throw_calloc(lines+1, sizeof(char*)); gstrarray Listi;
fp.Rewind(); fp.Rewind();
size_t n;
for (n = 0; n < lines; n++) for (n = 0; n < lines; n++)
{ {
fp.Fgets(buf, sizeof(buf)-2); 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; buf[MAXCOL-2-2] = NUL;
Listi[n] = throw_strdup(buf); Listi[n] = throw_strdup(buf);
} }
n = MinV(n, (MAXROW-10)); n = MinV(n, (MAXROW-10));
set_title(title, TCENTER, C_ASKT); 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); 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); strtrim(selection);
strltrim(selection); strltrim(selection);
retval = true; retval = true;
} }
for(n=0; n<lines; n++)
throw_free(Listi[n]);
throw_free(Listi);
} }
else { else
{
w_info(nolines); w_info(nolines);
waitkeyt(10000); waitkeyt(10000);
w_info(NULL); w_info(NULL);
@ -657,29 +658,36 @@ int SelectFromFile(const char* file, char* selection, const char* title, const c
// ------------------------------------------------------------------ // ------------------------------------------------------------------
int ChangeTagline() { int ChangeTagline()
{
bool retval = false;
char buf[256]; if (not CFG->tagline.empty())
int n; {
bool retval=false; char buf[256];
char** Listi; gstrarray Listi;
if(not CFG->tagline.empty()) { gstrarray::iterator it = CFG->tagline.begin();
Listi = (char**)throw_calloc(CFG->tagline.size()+1, sizeof(char*)); gstrarray::iterator end = CFG->tagline.end();
gstrarray::iterator i;
for(n = 0, i = CFG->tagline.begin(); i != CFG->tagline.end(); i++, n++) { for (; it != end; it++)
if((*i)[0] == '@') {
strxmerge(buf, MAXCOL-2-2, " [", CleanFilename(i->c_str()+1), "] ", NULL); if((*it)[0] == '@')
strxmerge(buf, MAXCOL-2-2, " [", CleanFilename(it->c_str() + 1), "] ", NULL);
else else
strxmerge(buf, MAXCOL-2-2, " ", i->c_str(), " ", NULL); strxmerge(buf, MAXCOL-2-2, " ", it->c_str(), " ", NULL);
Listi[n] = throw_strdup(buf);
Listi.push_back(buf);
} }
n = MinV(n, (MAXROW-10));
size_t n = MinV(Listi.size(), (MAXROW-10));
set_title(LNG->Taglines, TCENTER, C_ASKT); set_title(LNG->Taglines, TCENTER, C_ASKT);
update_statusline(LNG->ChangeTagline); update_statusline(LNG->ChangeTagline);
whelppcat(H_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); 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(); const char *tagl = CFG->tagline[n].c_str();
if(tagl[0] == '@') { if(tagl[0] == '@') {
strxmerge(buf, MAXCOL-2-2, LNG->Taglines, " [", CleanFilename(tagl+1), "] ", NULL); strxmerge(buf, MAXCOL-2-2, LNG->Taglines, " [", CleanFilename(tagl+1), "] ", NULL);
@ -694,45 +702,52 @@ int ChangeTagline() {
retval = true; retval = true;
} }
} }
for(n=CFG->tagline.size(); n; n--)
throw_free(Listi[n-1]);
throw_free(Listi);
whelpop(); whelpop();
} }
else { else
{
w_info(LNG->NoTagline); w_info(LNG->NoTagline);
waitkeyt(10000); waitkeyt(10000);
w_info(NULL); w_info(NULL);
} }
return(retval);
return retval;
} }
// ------------------------------------------------------------------ // ------------------------------------------------------------------
int ChangeOrigin() { int ChangeOrigin()
{
bool retval = false;
char buf[256]; if (not CFG->origin.empty())
int n; {
bool retval=false; char buf[256];
char** Listi; gstrarray Listi;
if(not CFG->origin.empty()) { gstrarray::iterator it = CFG->origin.begin();
Listi = (char**)throw_calloc(CFG->origin.size()+1, sizeof(char*)); gstrarray::iterator end = CFG->origin.end();
gstrarray::iterator i;
for(n = 0, i = CFG->origin.begin(); i != CFG->origin.end(); n++, i++) { for (; it !=end; it++)
if((*i)[0] == '@') {
strxmerge(buf, MAXCOL-2-2, " [", CleanFilename(i->c_str()+1), "] ", NULL); if ((*it)[0] == '@')
strxmerge(buf, MAXCOL-2-2, " [", CleanFilename(it->c_str() + 1), "] ", NULL);
else else
strxmerge(buf, MAXCOL-2-2, " ", i->c_str(), " ", NULL); strxmerge(buf, MAXCOL-2-2, " ", it->c_str(), " ", NULL);
Listi[n] = throw_strdup(buf);
Listi.push_back(buf);
} }
n = MinV(n, (MAXROW-10));
size_t n = MinV(Listi.size(), (MAXROW-10));
set_title(LNG->Origins, TCENTER, C_ASKT); set_title(LNG->Origins, TCENTER, C_ASKT);
update_statusline(LNG->ChangeOrigin); update_statusline(LNG->ChangeOrigin);
whelppcat(H_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); 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(); const char *orig = CFG->origin[n].c_str();
if(orig[0] == '@') { if(orig[0] == '@') {
strxmerge(buf, MAXCOL-2-2, LNG->Origins, " [", CleanFilename(orig+1), "] ", NULL); strxmerge(buf, MAXCOL-2-2, LNG->Origins, " [", CleanFilename(orig+1), "] ", NULL);
@ -747,43 +762,48 @@ int ChangeOrigin() {
retval = true; retval = true;
} }
} }
for(n = CFG->origin.size(); n; n--)
throw_free(Listi[n-1]);
throw_free(Listi);
whelpop(); whelpop();
} }
else { else
{
w_info(LNG->NoOrigDefined); w_info(LNG->NoOrigDefined);
waitkeyt(10000); waitkeyt(10000);
w_info(NULL); 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]; std::vector<Node>::iterator it = CFG->username.begin();
int n; std::vector<Node>::iterator end = CFG->username.end();
char** Listi;
if(not CFG->username.empty()) { for (; it != end; it++)
Listi = (char**)throw_calloc(CFG->username.size()+1, sizeof(char*));
std::vector<Node>::iterator i;
for (n = 0, i = CFG->username.begin(); i != CFG->username.end(); n++, i++)
{ {
i->addr.make_string(adrs); it->addr.make_string(adrs);
gsprintf(PRINTF_DECLARE_BUFFER(buf), " %-35s %s ", i->name, adrs); gsprintf(PRINTF_DECLARE_BUFFER(buf), " %-35s %s ", it->name, adrs);
Listi[n] = throw_strdup(buf); Listi.push_back(buf);
} }
n = MinV(n, (MAXROW-10));
size_t n = MinV(Listi.size(), (MAXROW-10));
set_title(LNG->Usernames, TCENTER, C_ASKT); set_title(LNG->Usernames, TCENTER, C_ASKT);
update_statusline(LNG->ChangeUsername); update_statusline(LNG->ChangeUsername);
whelppcat(H_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); 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; CFG->usernameno = n;
AA->SetUsername(CFG->username[n]); AA->SetUsername(CFG->username[n]);
for(std::vector<gaka>::iterator a = CFG->aka.begin(); a != CFG->aka.end(); a++) { for(std::vector<gaka>::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(); whelpop();
} }
else { else
{
w_info(LNG->NoUserDefined); w_info(LNG->NoUserDefined);
waitkeyt(10000); waitkeyt(10000);
w_info(NULL); 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]; std::vector<Tpl>::iterator it = CFG->tpl.begin();
int n; std::vector<Tpl>::iterator end = CFG->tpl.end();
int selected=-1;
char** Listi;
if(not CFG->tpl.empty()) { for (; it != end; it++)
Listi = (char**)throw_calloc(CFG->tpl.size()+1, sizeof(char*));
std::vector<Tpl>::iterator t;
for (n = 0, t = CFG->tpl.begin(); t != CFG->tpl.end(); n++, t++)
{ {
t->match.make_string(adrs); it->match.make_string(adrs);
gsprintf(PRINTF_DECLARE_BUFFER(buf), " %-45s %s ", t->name, adrs); gsprintf(PRINTF_DECLARE_BUFFER(buf), " %-45s %s ", it->name, adrs);
Listi[n] = throw_strdup(buf); Listi.push_back(buf);
} }
n = MinV(n, (MAXROW-10));
size_t n = MinV(Listi.size(), (MAXROW-10));
set_title(LNG->Templates, TCENTER, C_ASKT); set_title(LNG->Templates, TCENTER, C_ASKT);
update_statusline(LNG->ChangeTemplate); update_statusline(LNG->ChangeTemplate);
whelppcat(H_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); n = wpickstr(6, 0, 6+n+1, -1, W_BASK, C_ASKB, C_ASKW, C_ASKS, Listi, CFG->tplno, title_shadow);
whelpop(); whelpop();
if(n != -1) {
if (n != -1)
{
AA->SetTpl(CFG->tpl[n].file); AA->SetTpl(CFG->tpl[n].file);
CFG->tplno = n; CFG->tplno = n;
} }
selected = n;
for(n = CFG->tpl.size(); n; n--) return n;
throw_free(Listi[n-1]);
throw_free(Listi);
} }
else { else {
w_info(LNG->NoTplDefined); w_info(LNG->NoTplDefined);
waitkeyt(10000); waitkeyt(10000);
w_info(NULL); w_info(NULL);
} }
return selected;
return -1;
} }
// ------------------------------------------------------------------ // ------------------------------------------------------------------
int ChangeAka() { int ChangeAka()
int n; {
std::vector<gaka>::iterator i; if (CFG->aka.size() > 1)
int startat = 0; {
char** Listi; size_t startat = 0;
char addr[100], buf[100]; char addr[100];
char buf[100];
gstrarray Listi;
if(CFG->aka.size() > 1) { std::vector<gaka>::iterator it = CFG->aka.begin();
Listi = (char**)throw_calloc(CFG->aka.size()+1, sizeof(char*)); std::vector<gaka>::iterator end = CFG->aka.end();
for (i = CFG->aka.begin(), n=0; i != CFG->aka.end(); n++, i++)
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); gsprintf(PRINTF_DECLARE_BUFFER(buf), " %s ", addr);
Listi[n] = throw_strdup(buf); Listi.push_back(buf);
if(AA->Aka().addr.equals(i->addr))
startat = n; 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); set_title(LNG->Akas, TCENTER, C_ASKT);
update_statusline(LNG->ChangeAka); update_statusline(LNG->ChangeAka);
whelppcat(H_ChangeAka); whelppcat(H_ChangeAka);
n = wpickstr(6, 0, 6+n+1, -1, W_BASK, C_ASKB, C_ASKW, C_ASKS, Listi, startat, title_shadow); n = wpickstr(6, 0, 6+n+1, -1, W_BASK, C_ASKB, C_ASKW, C_ASKS, Listi, startat, title_shadow);
whelpop(); whelpop();
if(n != -1)
if (n != -1)
AA->SetAka(CFG->aka[n].addr); 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); w_info(LNG->NoAkaDefined);
waitkeyt(10000); waitkeyt(10000);
w_info(NULL); 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; char buf[100];
int xlatimports = 1; gstrarray Listi;
int maximport = 0;
int maxexport = 0; std::vector<Map>::iterator xlt = CFG->xlatcharset.begin();
char** Listi; std::vector<Map>::iterator end = CFG->xlatcharset.end();
char buf[100];
if(not CFG->xlatcharset.empty()) { for (size_t xlatimports = 1; xlt != end; xlt++)
Listi = (char**)throw_calloc(CFG->xlatcharset.size()+2, sizeof(char*)); {
std::vector<Map>::iterator xlt; if (strieql(xlt->exp, CFG->xlatlocalset))
for(xlt = CFG->xlatcharset.begin(); xlt != CFG->xlatcharset.end(); xlt++) { {
if(strieql(xlt->exp, CFG->xlatlocalset)) {
maximport = MaxV(maximport, (int)strlen(xlt->imp)); maximport = MaxV(maximport, (int)strlen(xlt->imp));
maxexport = MaxV(maxexport, (int)strlen(xlt->exp)); 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; startat = xlatimports;
xlatimports++; xlatimports++;
} }
} }
Listi[0] = throw_strdup(LNG->CharsetAuto);
xlatimports = 1; Listi.push_back(LNG->CharsetAuto);
for (xlt = CFG->xlatcharset.begin(); xlt != CFG->xlatcharset.end(); xlt++)
for (xlt = CFG->xlatcharset.begin(); xlt != end; xlt++)
{ {
if (strieql(xlt->exp, CFG->xlatlocalset)) if (strieql(xlt->exp, CFG->xlatlocalset))
{ {
gsprintf(PRINTF_DECLARE_BUFFER(buf), " %*.*s -> %-*.*s ", gsprintf(PRINTF_DECLARE_BUFFER(buf), " %*.*s -> %-*.*s ",
maximport, maximport, xlt->imp, maxexport, maxexport, xlt->exp); 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); set_title(LNG->Charsets, TCENTER, C_ASKT);
update_statusline(LNG->ChangeXlatImp); update_statusline(LNG->ChangeXlatImp);
whelppcat(H_ChangeXlatImport); whelppcat(H_ChangeXlatImport);
n = wpickstr(6, 0, 6+n+1, -1, W_BASK, C_ASKB, C_ASKW, C_ASKS, Listi, startat, title_shadow); n = wpickstr(6, 0, 6+n+1, -1, W_BASK, C_ASKB, C_ASKW, C_ASKS, Listi, startat, title_shadow);
whelpop(); whelpop();
if(n == 0) {
if (n == 0)
{
CFG->ignorecharset = false; CFG->ignorecharset = false;
} }
else if(n != -1) { else if (n != -1)
{
CFG->ignorecharset = true; 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); LoadCharset(AA->Xlatimport(), CFG->xlatlocalset);
for(n=0; n<xlatimports; n++)
throw_free(Listi[n]);
throw_free(Listi);
} }
else { else
{
w_info(LNG->NoXlatImport); w_info(LNG->NoXlatImport);
waitkeyt(10000); waitkeyt(10000);
w_info(NULL); w_info(NULL);
} }
return true; return true;
} }

View File

@ -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)) if (tokenxchg(input, dst, "@tr", "", 0, 1, (int)true))
continue; 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++; dst++;
} }
} }
// ------------------------------------------------------------------ // ------------------------------------------------------------------
void TokenXlat(int mode, char *&input, size_t size, bool resize, GMsg* msg, GMsg* oldmsg, int origarea) void TokenXlat(int mode, char *&input, size_t size, bool resize, GMsg* msg, GMsg* oldmsg, int origarea)

View File

@ -161,6 +161,7 @@ int IsMacro(gkey key, int type);
// ------------------------------------------------------------------ // ------------------------------------------------------------------
// GEINIT prototypes // GEINIT prototypes
void Uninitialize();
void Initialize(int argc, char* argv[]); void Initialize(int argc, char* argv[]);
@ -357,7 +358,7 @@ void NextArea();
void PrevArea(); void PrevArea();
void Reader(); void Reader();
void UpdateArea(GMsg* msg); void UpdateArea(GMsg* msg);
int ExternUtil(GMsg* msg, int utilno); int ExternUtil(GMsg* msg, uint32_t utilno);
void ExternUtilMenu(GMsg* msg); void ExternUtilMenu(GMsg* msg);
void ReadPeekURLs(GMsg* msg); void ReadPeekURLs(GMsg* msg);
uint next_msg(int direction); uint next_msg(int direction);
@ -545,3 +546,4 @@ void RemoveHTML(char *&txt);
#endif #endif
// ------------------------------------------------------------------ // ------------------------------------------------------------------

View File

@ -1390,15 +1390,15 @@ struct ReplySel {
// ------------------------------------------------------------------ // ------------------------------------------------------------------
void GotoReplies() { void GotoReplies()
{
reader_direction = DIR_NEXT; reader_direction = DIR_NEXT;
GMsg* msg = reader_msg; GMsg* msg = reader_msg;
const int list_max = msg->link.list_max(); const int list_max = msg->link.list_max();
char buf[200]; char buf[200];
int replies = 0; size_t replies = 0;
int cursorbar = -1; int cursorbar = -1;
uint maxname = 0; uint maxname = 0;
uint maxaddr = 0; uint maxaddr = 0;
@ -1447,40 +1447,38 @@ void GotoReplies() {
throw_free(rmsg); throw_free(rmsg);
int selected = 0; int selected = 0;
if(replies > 1) { if(replies > 1)
{
uint maxname2 = MAXCOL-16-maxmsgno-maxaddr-maxwritten; uint maxname2 = MAXCOL-16-maxmsgno-maxaddr-maxwritten;
maxname = MinV(maxname, maxname2); maxname = MinV(maxname, maxname2);
char** listr = (char**)throw_calloc(list_max+3, sizeof(char*)); gstrarray listr;
int n; int n;
for(n=0; n<list_max+3; n++) { for (n = 0; n < list_max + 3; n++)
if(n<replies) { {
sprintf(buf, "%c %c %*s : %-*.*s %-*s %-*s ", if (n >= replies)
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[n] = throw_strdup(buf);
}
else {
listr[n] = NULL;
break; 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); set_title(LNG->Replies, TCENTER, C_ASKT);
update_statusline(LNG->SelectReply); update_statusline(LNG->SelectReply);
whelppcat(H_GotoReplies); whelppcat(H_GotoReplies);
int pick_max = MinV(replies, (MAXROW-10)); size_t pick_max = MinV(replies, (MAXROW-10));
if(cursorbar < 0) if(cursorbar < 0)
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); selected = wpickstr(6, 0, 6+pick_max+1, -1, W_BASK, C_ASKB, C_ASKW, C_ASKS, listr, cursorbar, title_shadow);
whelpop(); whelpop();
gotolink = (selected != -1) ? rlist[selected].reln : 0; gotolink = (selected != -1) ? rlist[selected].reln : 0;
for(n=0; n<replies; n++)
throw_free(listr[n]);
throw_free(listr);
} }
throw_free(rlist); throw_free(rlist);

View File

@ -24,10 +24,11 @@
// Reader secondary functions // Reader secondary functions
// ------------------------------------------------------------------ // ------------------------------------------------------------------
#include <vector>
#include <algorithm>
#include <golded.h> #include <golded.h>
#include <gwinput.h> #include <gwinput.h>
#include <gftnall.h> #include <gftnall.h>
#include <vector>
#define PROTOTYPES #define PROTOTYPES
#include <uudeview.h> #include <uudeview.h>
@ -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; Path editorfile, tmpfile, buf;
strxcpy(editorfile, AddPath(CFG->goldpath, EDIT->File()), sizeof(Path)); 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); SaveLines(mode, editorfile, msg, 79);
strcpy(buf, editorfile); strcpy(buf, editorfile);
strchg(buf, GOLD_WRONG_SLASH_CHR, GOLD_SLASH_CHR); 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); TokenXlat(MODE_NEW, cmdline, msg, msg, CurrArea);
int pauseval = 0; int pauseval = 0;
if(extutil->options & EXTUTIL_PAUSEONERROR) if(extutil.options & EXTUTIL_PAUSEONERROR)
pauseval = -1; pauseval = -1;
if(extutil->options & EXTUTIL_PAUSE) if(extutil.options & EXTUTIL_PAUSE)
pauseval = 1; pauseval = 1;
ShellToDos(cmdline.c_str(), "", ShellToDos(cmdline.c_str(), "",
extutil->options & EXTUTIL_CLS ? LGREY_|_BLACK : BLACK_|_BLACK, extutil.options & EXTUTIL_CLS ? LGREY_|_BLACK : BLACK_|_BLACK,
extutil->options & EXTUTIL_CURSOR, extutil.options & EXTUTIL_CURSOR,
pauseval 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) if (*msg->tearline or *msg->origin)
{ {
gfile fp(editorfile, "at"); gfile fp(editorfile, "at");
@ -621,7 +622,7 @@ int ExternUtil(GMsg *msg, ExtUtil *extutil) {
msg->charsetlevel = LoadCharset(msg->charset, CFG->xlatlocalset); msg->charsetlevel = LoadCharset(msg->charset, CFG->xlatlocalset);
} }
if(extutil->options & EXTUTIL_WIPE) if(extutil.options & EXTUTIL_WIPE)
WipeFile(editorfile, 0); WipeFile(editorfile, 0);
if(tmpfile[0] != NUL) if(tmpfile[0] != NUL)
WipeFile(tmpfile, 0); WipeFile(tmpfile, 0);
@ -632,15 +633,15 @@ int ExternUtil(GMsg *msg, ExtUtil *extutil) {
// ------------------------------------------------------------------ // ------------------------------------------------------------------
int ExternUtil(GMsg *msg, int utilno) { int ExternUtil(GMsg *msg, uint32_t utilno)
{
std::vector<ExtUtil>::iterator extutil = CFG->externutil.begin(); std::vector<ExtUtil>::iterator it = CFG->externutil.begin();
std::vector<ExtUtil>::iterator end = CFG->externutil.end();
for(int utlno=0; extutil != CFG->externutil.end(); utlno++, extutil++) {
for (uint32_t i = 0; it != end; i++, it++)
if(extutil->utilno == utilno) { {
return ExternUtil(msg, &(*extutil)); if (it->utilno != i) continue;
} return ExternUtil(msg, *it);
} }
SayBibi(); SayBibi();
@ -650,147 +651,181 @@ int ExternUtil(GMsg *msg, int utilno) {
// ------------------------------------------------------------------ // ------------------------------------------------------------------
void ExternUtilMenu(GMsg* msg) { void ExternUtilMenu(GMsg* msg)
int n; {
std::vector<ExtUtil>::iterator i;
static int startat = 0; static int startat = 0;
char** Listi;
char buf[100];
static char cmdline[1024] = ""; static char cmdline[1024] = "";
gstrarray Listi;
Listi = (char**)throw_calloc(CFG->externutil.size()+2, sizeof(char*)); Listi.push_back(LNG->EnterCmdLine);
Listi[0] = throw_strdup(LNG->EnterCmdLine);
for(i = CFG->externutil.begin(), n=1; i != CFG->externutil.end(); n++, i++) { std::vector<ExtUtil>::iterator it = CFG->externutil.begin();
sprintf(buf, " %02d %.59s%s ", i->utilno, i->cmdline, strlen(i->cmdline) > 59 ? ">" : "" ); std::vector<ExtUtil>::iterator end = CFG->externutil.end();
Listi[n] = throw_strdup(buf); 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); set_title(LNG->ExternUtil, TCENTER, C_ASKT);
update_statusline(LNG->SelectExternUtil); update_statusline(LNG->SelectExternUtil);
whelppcat(H_ReadExternUtil); whelppcat(H_ReadExternUtil);
n = wpickstr(6, 0, 6+n+1, -1, W_BASK, C_ASKB, C_ASKW, C_ASKS, Listi, startat, title_shadow); n = wpickstr(6, 0, 6+n+1, -1, W_BASK, C_ASKB, C_ASKW, C_ASKS, Listi, startat, title_shadow);
whelpop(); whelpop();
if(n != -1) {
if(n == 0) { if (n != -1)
if(edit_string(cmdline, sizeof(cmdline), LNG->ExecCmdLine, H_ReadExternUtil)) { {
if (n == 0)
{
if (edit_string(cmdline, sizeof(cmdline), LNG->ExecCmdLine, H_ReadExternUtil))
{
ExtUtil extutil; ExtUtil extutil;
extutil.utilno = 0; extutil.utilno = 0;
strxcpy(extutil.cmdline, cmdline, sizeof(extutil.cmdline)); extutil.cmdline = cmdline;
extutil.options = CFG->externoptions; extutil.options = CFG->externoptions;
reader_keyok = ExternUtil(msg, &extutil); reader_keyok = ExternUtil(msg, extutil);
} }
} }
else { else
reader_keyok = ExternUtil(msg, &CFG->externutil[n-1]); {
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) { static bool PeekURLCmp(const std::string &a, const std::string b)
{
return stricmp(*a, *b); return stricmp(a.c_str(), b.c_str()) > 0;
} }
// ------------------------------------------------------------------ // ------------------------------------------------------------------
void ReadPeekURLs(GMsg* msg) { void ReadPeekURLs(GMsg* msg)
{
Line **lin = msg->line;
const char *ptr, *end, *begin;
char buf[256];
std::vector<char *> urls;
std::vector<char *>::iterator i;
int n;
w_info(LNG->Wait); w_info(LNG->Wait);
// Scan the current msg for urls // Scan the current msg for urls
int tline = reader_topline; int tline = reader_topline;
if(CFG->peekurloptions & PEEK_FROMTOP) if (CFG->peekurloptions & PEEK_FROMTOP)
tline = 0; tline = 0;
for(n=tline; n<msg->lines; n++) {
ptr = lin[n]->txt.c_str(); Line **lin = msg->line;
std::vector<char *> urls;
while(*ptr) { for (int n = tline; n < msg->lines; n++)
if(((begin = url_begin(ptr)) != NULL) and not strneql(ptr, "mailto:", 7)) { {
end = begin+strcspn(begin, " \t\"\'<>()[]"); const char *ptr = lin[n]->txt.c_str();
if(ispunct(end[-1]) and (end[-1] != '/'))
--end; while (*ptr)
if(begin < end) { {
char* bufurl=(char*)throw_malloc(end-ptr+3); 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] = ' '; bufurl[0] = ' ';
strxcpy(bufurl+1, ptr, (end-ptr)+1); strxcpy(bufurl + 1, ptr, (urlEnd - ptr) + 1);
strcat(bufurl, " "); strcat(bufurl, " ");
for(i = urls.begin(); i != urls.end(); i++)
if(strieql(*i, bufurl)) std::vector<char *>::iterator it = urls.begin();
std::vector<char *>::iterator end = urls.end();
for (; it != end; it++)
{
if (strieql(*it, bufurl))
break; break;
if(i == urls.end()) }
if (it == end)
urls.push_back(bufurl); urls.push_back(bufurl);
else else
throw_free(bufurl); throw_free(bufurl);
ptr = end-1;
ptr = urlEnd - 1;
} }
} }
ptr++; ptr++;
} }
} }
w_info(NULL); w_info(NULL);
if(not urls.empty()) { if (not urls.empty())
{
gstrarray Listi;
char** Listi = (char**)throw_calloc(urls.size()+1, sizeof(char*)); std::vector<char *>::iterator it = urls.begin();
std::vector<char *>::iterator end = urls.end();
for(n = 0, i = urls.begin(); i != urls.end(); i++, n++) for (; it != end; it++)
Listi[n] = *i; {
Listi.push_back(*it);
}
// Sort list if requested // Sort list if requested
if(CFG->peekurloptions & FREQ_SORT) if(CFG->peekurloptions & FREQ_SORT)
qsort(Listi, urls.size(), sizeof(char*), (StdCmpCP)PeekURLCmp); sort(Listi.begin(), Listi.end(), PeekURLCmp);
// Run the picker // 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); set_title(LNG->PeekURLMenuTitle, TCENTER, C_ASKT);
update_statusline(LNG->PeekURLStat); update_statusline(LNG->PeekURLStat);
whelppcat(H_PeekURL); 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(); whelpop();
if(n != -1) { if(n != -1)
std::string cmdline = CFG->urlhandler.cmdline; {
strxmerge(buf, sizeof(buf), "\"", strtrim(strltrim(Listi[n])), "\"", NULL); std::vector<UrlHandler>::iterator it = CFG->urlhandler.begin();
strischg(cmdline, "@url", buf); std::vector<UrlHandler>::iterator end = CFG->urlhandler.end();
strxcpy(buf, CFG->goldpath, sizeof(buf)); #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); 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); TokenXlat(MODE_NEW, cmdline, msg, msg, CurrArea);
int pauseval = 0; int pauseval = 0;
if(CFG->urlhandler.options & EXTUTIL_PAUSEONERROR) if (it->handler.options & EXTUTIL_PAUSEONERROR)
pauseval = -1; pauseval = -1;
if(CFG->urlhandler.options & EXTUTIL_PAUSE)
if (it->handler.options & EXTUTIL_PAUSE)
pauseval = 1; pauseval = 1;
ShellToDos(cmdline.c_str(), "", ShellToDos(cmdline.c_str(), "",
CFG->urlhandler.options & EXTUTIL_CLS ? LGREY_|_BLACK : BLACK_|_BLACK, it->handler.options & EXTUTIL_CLS ? LGREY_|_BLACK : BLACK_|_BLACK,
CFG->urlhandler.options & EXTUTIL_CURSOR, it->handler.options & EXTUTIL_CURSOR,
pauseval 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); w_info(LNG->PeekInfoNoURLs);
waitkeyt(10000); waitkeyt(10000);
w_info(NULL); w_info(NULL);

View File

@ -26,7 +26,6 @@
#ifndef __GESRCH_H #ifndef __GESRCH_H
#define __GESRCH_H #define __GESRCH_H
#include <gstrarr.h>
#include <gsrchmgr.h> #include <gsrchmgr.h>

View File

@ -66,7 +66,6 @@
#include <gprnall.h> #include <gprnall.h>
#include <gsearch.h> #include <gsearch.h>
#include <gstrbags.h> #include <gstrbags.h>
#include <gstrarr.h>
#include <gtimall.h> #include <gtimall.h>
#include <gtxtpara.h> #include <gtxtpara.h>
#include <gutlgrp.h> #include <gutlgrp.h>

View File

@ -31,7 +31,7 @@
// ------------------------------------------------------------------ // ------------------------------------------------------------------
#include <gfilutil.h> #include <gfilutil.h>
#include <gstrarr.h> #include <gstrall.h>
// ------------------------------------------------------------------ // ------------------------------------------------------------------

View File

@ -31,6 +31,7 @@
#include <string> #include <string>
#include <gdefs.h> #include <gdefs.h>
#include <gregex.h>
// ------------------------------------------------------------------ // ------------------------------------------------------------------
@ -239,9 +240,9 @@ const int DISPMSGSIZE_LINES = 3;
// ------------------------------------------------------------------ // ------------------------------------------------------------------
// Replylink types // Replylink types
const int REPLYLINK_DIRECT = 0; const int REPLYLINK_DIRECT = 0;
const int REPLYLINK_CHAIN = 1; const int REPLYLINK_CHAIN = 1;
const int REPLYLINK_NONE = 2; const int REPLYLINK_NONE = 2;
const int REPLYLINKLIST_FAST = 0; const int REPLYLINKLIST_FAST = 0;
const int REPLYLINKLIST_FULL = 1; const int REPLYLINKLIST_FULL = 1;
@ -562,23 +563,32 @@ struct infoLookup {
// ------------------------------------------------------------------ // ------------------------------------------------------------------
// Structures and constants for external utilities // Structures and constants for external utilities
const int EXTUTIL_CLS = 0x0001; const uint32_t EXTUTIL_CLS = 0x0001;
const int EXTUTIL_CURSOR = 0x0004; const uint32_t EXTUTIL_CURSOR = 0x0004;
const int EXTUTIL_RELOAD = 0x0008; const uint32_t EXTUTIL_RELOAD = 0x0008;
const int EXTUTIL_PAUSE = 0x0010; const uint32_t EXTUTIL_PAUSE = 0x0010;
const int EXTUTIL_PAUSEONERROR = 0x0020; const uint32_t EXTUTIL_PAUSEONERROR = 0x0020;
const int EXTUTIL_WIPE = 0x0040; const uint32_t EXTUTIL_WIPE = 0x0040;
const int EXTUTIL_KEEPCTRL = 0x0080; const uint32_t EXTUTIL_KEEPCTRL = 0x0080;
struct ExtUtil { struct ExtUtil
int utilno; {
int options; uint32_t utilno;
char cmdline[256]; uint32_t options;
std::string cmdline;
}; };
struct SaveUtil { struct SaveUtil
int utilno; {
char menutext[41]; uint32_t utilno;
std::string menutext;
};
struct UrlHandler
{
std::string name;
gregex scheme;
ExtUtil handler;
}; };

View File

@ -33,6 +33,7 @@
// Required headers // Required headers
#include <string> #include <string>
#include <vector>
#include <gctype.h> #include <gctype.h>
#include <cstring> #include <cstring>
#include <gdefs.h> #include <gdefs.h>
@ -54,11 +55,17 @@ char* strlwr(char* s);
#endif #endif
// ------------------------------------------------------------------
typedef std::vector<std::string> gstrarray;
// ------------------------------------------------------------------ // ------------------------------------------------------------------
// Function prototypes // Function prototypes
bool strblank(const char* str); 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); char* stridela(const char* substr, char* str);
int strnicmpw(const char* str1, const char* str2, int len); int strnicmpw(const char* str1, const char* str2, int len);
const char* striinc(const char* str1, const char* str2); 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* strsrep(char* str, const char* search, const char* replace);
char* strltrim(char* str); char* strltrim(char* str);
char* strtrim(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* struplow(char* str);
char* longdotstr(long num); // Convert a long to a dotted string: xxx.xxx.xxx.xxx 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 // String tokenizer class
void tokenize(gstrarray &array, const TCHAR* str, const TCHAR *delim = NULL);
class GTok class GTok
{ {
protected: protected:

View File

@ -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 <cstring>
#include <vector>
#include <string>
#include <gdefs.h>
#include <gmemdbg.h>
// ------------------------------------------------------------------
typedef std::vector<std::string> 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
// ------------------------------------------------------------------

View File

@ -52,12 +52,14 @@ bool strblank(const char* str) {
// ------------------------------------------------------------------ // ------------------------------------------------------------------
// Changes all occurrences of one character to another // 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++)
{
for(char* p=str; *p; p++) { if (oldch == *p)
if(oldch == *p) { {
*p = newch; *p = newch;
count++; 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 // 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()) { while(trail != str.begin())
std::string::iterator trail = p.end(); {
while(trail != p.begin()) {
--trail; --trail;
if(not isspace(*trail) and not iscntrl(*trail)) { if (not isspace(*trail) and not iscntrl(*trail))
{
++trail; ++trail;
break; break;
} }
} }
p.erase(trail, p.end());
str.erase(trail, str.end());
} }
return p;
return str;
} }
// ------------------------------------------------------------------ // ------------------------------------------------------------------
// Trims leading spaces off of a string // Trims leading spaces off of a string
char* strltrim(char* str) { char* strltrim(char* str)
{
char* p; char* p;
char* q; char* q;
@ -516,6 +546,22 @@ char* strltrim(char* str) {
return 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 #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);
}
// ------------------------------------------------------------------ // ------------------------------------------------------------------

View File

@ -313,8 +313,8 @@ public:
int currow; // Current cursor row int currow; // Current cursor row
int curcol; // Current cursor column int curcol; // Current cursor column
int numrows; // number of displayed rows size_t numrows; // number of displayed rows
int numcols; // number of displayed columns size_t numcols; // number of displayed columns
word videoseg; // video buffer segment address word videoseg; // video buffer segment address

View File

@ -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); } 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); 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); 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 wprintc (int wrow, int wcol, vattr attr, vchar ch);
int wprintf (const char* format, ...) __attribute__ ((format (printf, 1, 2))); int wprintf (const char* format, ...) __attribute__ ((format (printf, 1, 2)));
int wprintaf (int attr, const char* format, ...) __attribute__ ((format (printf, 2, 3))); 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 (int wrow, int wcol, vattr attr, const char* str);
int wprints_box (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 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 wprintsf (int wrow, int wcol, vattr attr, const char* format, const char* str);
int wprintws (int wrow, int wcol, vatch* buf, uint len); int wprintws (int wrow, int wcol, vatch* buf, uint len);
void wpropbar (int xx, int yy, long len, vattr attr, long pos, long size); void wpropbar (int xx, int yy, long len, vattr attr, long pos, long size);

View File

@ -951,9 +951,9 @@ int wputy(int wrow, int wcol, vattr attr, vchar chr, uint len) {
// ------------------------------------------------------------------ // ------------------------------------------------------------------
// Displays a string inside active window // 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* ostr = istr;
char och = *ostr; char och = *ostr;
uint olen = strlen(istr); uint olen = strlen(istr);

View File

@ -30,6 +30,7 @@
#include <cstdio> #include <cstdio>
#include <cstdlib> #include <cstdlib>
#include <cstring> #include <cstring>
#include <algorithm>
#include <gmemdbg.h> #include <gmemdbg.h>
#include <gfilutil.h> #include <gfilutil.h>
#include <gwildmat.h> #include <gwildmat.h>
@ -49,30 +50,29 @@ static char* namextp;
// ------------------------------------------------------------------ // ------------------------------------------------------------------
// this function is the compare function for qsort() // this function is the compare function for std::sort()
static int compare(const char** str1, const char** str2) {
static bool compare(const std::string str1, const std::string str2)
{
// Sort with directories first // Sort with directories first
bool dir1 = !!strchr(*str1, GOLD_SLASH_CHR); bool dir1 = !!strchr(str1.c_str(), GOLD_SLASH_CHR);
bool dir2 = !!strchr(*str2, GOLD_SLASH_CHR); bool dir2 = !!strchr(str2.c_str(), GOLD_SLASH_CHR);
int cmp = compare_two(dir2, dir1); if (dir1 && !dir2) return true;
if(cmp != 0)
return cmp;
Path p1, p2; std::string s1 = dir1 ? str1.substr(0, str1.length()-1) : str1;
strcpy(p1, *str1); if(dir1) { p1[strlen(p1)-1] = NUL; } std::string s2 = dir2 ? str2.substr(0, str2.length()-1) : str2;
strcpy(p2, *str2); if(dir2) { p2[strlen(p2)-1] = NUL; }
if(case_sensitive) int cmp;
return strcmp(p1, p2); if (case_sensitive)
else { cmp = strcmp(s1.c_str(), s2.c_str());
cmp = stricmp(p1, p2); else
if(cmp == 0) {
cmp = strcmp(p1, p2); 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;i<numelems;i++)
throw_xfree(p[i]);
}
// ------------------------------------------------------------------
static void pre_exit(char** p, int numelems) {
free_strings(p,numelems);
throw_xfree(p);
gchdir(tcwdp);
}
// ------------------------------------------------------------------
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) {
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)
{
Path cwd, dir, namext, tcwd, path, spec; Path cwd, dir, namext, tcwd, path, spec;
cwdp = cwd; cwdp = cwd;
tcwdp = tcwd; tcwdp = tcwd;
namextp = namext; namextp = namext;
// allocate space to hold array of char pointers
int allocated = 100;
char** p = (char**)throw_xmalloc(allocated*sizeof(char*));
// set static variables // set static variables
open_function = open; open_function = open;
path_in_title = title; path_in_title = title;
@ -165,16 +141,15 @@ bool wpickfile(int srow, int scol, int erow, int ecol, int btype, vattr bordattr
} }
bool finished; bool finished;
int picked, files; int picked;
do {
do
{
// if directory was specified, change to it // if directory was specified, change to it
if(*dir) { if (*dir && gchdir(dir))
if(gchdir(dir)) { {
pre_exit(p, 0); gchdir(tcwdp);
return false; return false;
}
} }
// get current working directory // get current working directory
@ -183,77 +158,71 @@ bool wpickfile(int srow, int scol, int erow, int ecol, int btype, vattr bordattr
// find all directories plus all files matching input filespec in // find all directories plus all files matching input filespec in
// current directory, allocating an array element for each // current directory, allocating an array element for each
files = 0;
picked = -1; picked = -1;
gposixdir d(dir); gposixdir d(dir);
gstrarray strarr;
const gdirentry *de; const gdirentry *de;
if(d.ok) {
while((de = d.nextentry()) != NULL) { if (d.ok)
{
while((de = d.nextentry()) != NULL)
{
const char* name = NULL; const char* name = NULL;
if(de->is_directory()) { if (de->is_directory())
{
if(de->name != ".") { if(de->name != ".") {
strxmerge(path, sizeof(Path), de->name.c_str(), GOLD_SLASH_STR, NULL); strxmerge(path, sizeof(Path), de->name.c_str(), GOLD_SLASH_STR, NULL);
name = path; 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)) if(case_sensitive ? gwildmat(de->name.c_str(), namext) : gwildmati(de->name.c_str(), namext))
name = de->name.c_str(); name = de->name.c_str();
} }
if(name) {
p[files] = throw_xstrdup(name); if (name) strarr.push_back(name);
files++;
if(files == allocated-1) {
allocated *= 2;
p = (char**)throw_xrealloc(p, allocated*sizeof(char*));
}
}
} }
} }
p[files] = NULL;
// sort files in array by swapping their pointers // 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 // let user pick file
if(files) if (strarr.size())
picked = wpickstr(srow, scol, erow, ecol, btype, bordattr, winattr, barattr, p, 0, disp_title); {
if(picked == -1 or files == 0) { picked = wpickstr(srow, scol, erow, ecol, btype, bordattr, winattr, barattr, strarr, 0, disp_title);
pre_exit(p, files); }
if (picked == -1 or !strarr.size())
{
gchdir(tcwdp);
return false; return false;
} }
// see if a directory was selected. if so save // see if a directory was selected. if so save
// directory name, otherwise build whole path name // directory name, otherwise build whole path name
q = strchr(p[picked], GOLD_SLASH_CHR); const char *slash = strchr(strarr[picked].c_str(), GOLD_SLASH_CHR);
if(q) { if (slash)
{
finished = false; finished = false;
strcpy(dir, p[picked]); strcpy(dir, strarr[picked].c_str());
r = strrchr(dir, GOLD_SLASH_CHR); r = strrchr(dir, GOLD_SLASH_CHR);
if(r) if (r) *r = NUL;
*r = NUL;
*q = NUL;
} }
else { else {
finished = true; finished = true;
PathCopy(filespec, cwd); PathCopy(filespec, cwd);
filespec += p[picked]; filespec += strarr[picked].c_str();
} }
// free allocated strings strarr.clear();
free_strings(p, files); }
while(not finished); // if a directory was selected, go back and do again
// if a directory was selected, go back and do again gchdir(tcwd); // change back to current drive and directory
} while(not finished); return true; // return normally
// change back to current drive and directory
gchdir(tcwd);
// free allocated char pointers
throw_xfree(p);
// return normally
return true;
} }

View File

@ -98,8 +98,8 @@ static void hide_mouse_cursor_pck() {
// this function updates the current item by either // this function updates the current item by either
// displaying or erasing the selection bar on it // 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 // calculate row and column string will be displayed
// at, then print out the string character-by-character // 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 nomore = false;
int ccol = r->gapspaces + r->xtraspaces; int ccol = r->gapspaces + r->xtraspaces;
int celem = (wrow*r->strsperline) + r->first; 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 // 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(); hide_mouse_cursor_pck();
for(int crow=0; crow<r->wheight; crow++) for(int crow=0; crow<r->wheight; crow++)
update_line(strarr, r, crow, 1); 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) if(elem<0 or elem>r->lastelem)
elem = 0; elem = 0;
int outside = (elem<r->first or elem>r->last) ? YES : NO; int outside = (elem<r->first 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) { if(r->curr != r->last) {
r->curr = r->last; r->curr = r->last;
update_window(strarr, r); 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) { if(r->curr != r->first) {
r->curr = r->first; r->curr = r->first;
update_window(strarr, r); 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) { if(r->first) {
hide_mouse_cursor_pck(); hide_mouse_cursor_pck();
if(upcurr) 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)) { if(r->last!=(r->lastelem)) {
hide_mouse_cursor_pck(); hide_mouse_cursor_pck();
if(upcurr) if(upcurr)
@ -339,8 +339,8 @@ static void scroll_up(char* strarr[], r_t* r, int upcurr) {
// ------------------------------------------------------------------ // ------------------------------------------------------------------
// this function reads the mouse for input // 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 #ifdef GOLD_MOUSE
// if free-floating mouse cursor support is on // if free-floating mouse cursor support is on
if(gmou.FreeCursor()) { 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 wpickstr(int srow, int scol, int erow, int ecol, int btype, vattr bordattr, vattr winattr, vattr barattr, gstrarray &strarr, int initelem, VfvCP open)
{
int i, j, maxlen, outside; int outside;
gkey xch; gkey xch;
char ch; char ch;
char* p;
r_t r; r_t r;
int quickpos = (strarr[0][0] == ' ') ? 1 : 0; 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 // go through input array and determine the longest
// string, and count the number of elements in the array // 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++) gstrarray::const_iterator it = strarr.begin();
if ((j = strlen(strarr[i])) > maxlen) gstrarray::const_iterator end = strarr.end();
maxlen = j; for (; it != end; it++)
{
size_t len;
if ((len = it->length()) > maxlen)
{
maxlen = len;
}
}
r.maxstrlen = maxlen; r.maxstrlen = maxlen;
r.lastelem = ((r.numelems=i)-1); r.numelems = strarr.size();
r.lastelem = r.numelems - 1;
r.winattr = winattr; r.winattr = winattr;
r.barattr = barattr; r.barattr = barattr;
@ -507,16 +514,18 @@ int wpickstr(int srow, int scol, int erow, int ecol, int btype, vattr bordattr,
switch(xch) { switch(xch) {
case Key_Space: case Key_Space:
if(wpickstr_tag) { if (wpickstr_tag)
p = strarr[r.curr]; {
switch(*p) { char p = strarr[r.curr][0];
switch (p)
{
case ' ': case ' ':
*p = (char)wpickstr_tag; strarr[r.curr][0] = (char)wpickstr_tag;
update_curr(strarr,&r,1); update_curr(strarr, &r, 1);
break; break;
default: default:
*p = ' '; strarr[r.curr][0] = ' ';
update_curr(strarr,&r,1); update_curr(strarr, &r, 1);
} }
kbput(Key_Dwn); 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_StrG:
case Key_S_8: case Key_S_8:
if(wpickstr_tag) { if (wpickstr_tag)
for(i=0; i<r.numelems; i++) {
for (size_t i = 0; i < r.numelems; i++)
{
strarr[i][0] = (char)wpickstr_tag; strarr[i][0] = (char)wpickstr_tag;
update_window(strarr,&r); }
update_window(strarr, &r);
} }
break; break;
case Key_Sls: case Key_Sls:
if(wpickstr_tag) { if (wpickstr_tag)
for(i=0; i<r.numelems; i++) {
for (size_t i = 0; i < r.numelems; i++)
{
strarr[i][0] = ' '; strarr[i][0] = ' ';
update_window(strarr,&r); }
update_window(strarr, &r);
} }
break; break;
@ -679,22 +696,29 @@ int wpickstr(int srow, int scol, int erow, int ecol, int btype, vattr bordattr,
// character as the keypress. If not found after current // character as the keypress. If not found after current
// position, search from the beginning for a match // position, search from the beginning for a match
ch = (char)g_toupper(char(xch & 0xFF)); ch = (char)g_toupper(char(xch & 0xFF));
if(!ch) if (!ch) break;
break;
for(i=r.curr+1; i<r.numelems; i++) size_t i;
if(ch==g_toupper(strarr[i][quickpos])) for (i = r.curr + 1; i < r.numelems; i++)
{
if (ch == g_toupper(strarr[i][quickpos]))
break; break;
if(i==r.numelems) { }
for(i=0;i<r.curr;i++)
if(ch==g_toupper(strarr[i][quickpos])) if (i == r.numelems)
{
for (i = 0; i < r.curr; i++)
{
if (ch == g_toupper(strarr[i][quickpos]))
break; break;
if(i==r.curr) }
continue;
if (i == r.curr) continue;
} }
// a matching ASCII character was found. set position // a matching ASCII character was found. set position
// to matching element, adjusting window if necessary // to matching element, adjusting window if necessary
goto_item(&r,strarr,i); goto_item(&r, strarr, i);
} }
} }
} }

View File

@ -35,7 +35,6 @@
using namespace std; using namespace std;
#include <gstrall.h> #include <gstrall.h>
#include <gstrarr.h>
#include <gftnall.h> #include <gftnall.h>
#include <golded3.h> #include <golded3.h>

View File

@ -2716,10 +2716,6 @@
</FileConfiguration> </FileConfiguration>
</File> </File>
</Filter> </Filter>
<Filter
Name="goldlib"
>
</Filter>
</Filter> </Filter>
<Filter <Filter
Name="Header Files" Name="Header Files"

View File

@ -608,6 +608,42 @@
RelativePath="..\goldlib\gall\gstrctyp.cpp" RelativePath="..\goldlib\gall\gstrctyp.cpp"
> >
</File> </File>
<File
RelativePath="..\goldlib\gall\gstring.cpp"
>
<FileConfiguration
Name="Debug|Win32"
ExcludedFromBuild="true"
>
<Tool
Name="VCCLCompilerTool"
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|x64"
ExcludedFromBuild="true"
>
<Tool
Name="VCCLCompilerTool"
/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
ExcludedFromBuild="true"
>
<Tool
Name="VCCLCompilerTool"
/>
</FileConfiguration>
<FileConfiguration
Name="Release|x64"
ExcludedFromBuild="true"
>
<Tool
Name="VCCLCompilerTool"
/>
</FileConfiguration>
</File>
<File <File
RelativePath="..\goldlib\gall\gstrmail.cpp" RelativePath="..\goldlib\gall\gstrmail.cpp"
> >
@ -940,6 +976,38 @@
RelativePath="..\goldlib\gall\gwinput2.cpp" RelativePath="..\goldlib\gall\gwinput2.cpp"
> >
</File> </File>
<File
RelativePath="..\goldlib\gall\memleak.cpp"
>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|x64"
>
<Tool
Name="VCCLCompilerTool"
/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
/>
</FileConfiguration>
<FileConfiguration
Name="Release|x64"
>
<Tool
Name="VCCLCompilerTool"
/>
</FileConfiguration>
</File>
</Filter> </Filter>
<Filter <Filter
Name="gcfg" Name="gcfg"
@ -1887,11 +1955,11 @@
> >
</File> </File>
<File <File
RelativePath="..\goldlib\gall\gstrarr.h" RelativePath="..\goldlib\gall\gstrbags.h"
> >
</File> </File>
<File <File
RelativePath="..\goldlib\gall\gstrbags.h" RelativePath="..\goldlib\gall\gstring.h"
> >
</File> </File>
<File <File
@ -2002,6 +2070,10 @@
RelativePath="..\goldlib\gall\gwinput.h" RelativePath="..\goldlib\gall\gwinput.h"
> >
</File> </File>
<File
RelativePath="..\goldlib\gall\memleak.h"
>
</File>
</Filter> </Filter>
<Filter <Filter
Name="gcfg.h" Name="gcfg.h"