Sorry, refactoring!

This commit is contained in:
Ianos Gnatiuc
2006-04-24 16:38:44 +00:00
parent bcf5ac98c1
commit 6cac338f3e
24 changed files with 755 additions and 741 deletions

View File

@@ -144,21 +144,20 @@ Area* AreaList::NewArea(const char *basetype) {
// ------------------------------------------------------------------
// Write lastreads for the next session
void AreaList::WriteGoldLast() {
void AreaList::WriteGoldLast()
{
word GOLDLAST_VER = CUR_GOLDLAST_VER;
gfile fp;
ggoldlast entry;
Path lst;
strcpy(lst, AddPath(CFG->goldpath, CFG->goldlast));
fp.fopen(lst, "wb", CFG->sharemode);
if(fp.isopen()) {
fp.setvbuf(NULL, _IOFBF, 8192);
fp.fwrite(&GOLDLAST_VER, sizeof(word));
fp.fwrite(AL.alistselections, sizeof(AL.alistselections));
gfile fp(lst, "wb", CFG->sharemode);
if (fp.isopen())
{
fp.SetvBuf(NULL, _IOFBF, 8192);
fp.Fwrite(&GOLDLAST_VER, sizeof(word));
fp.Fwrite(AL.alistselections, sizeof(AL.alistselections));
for(area_iterator ap = idx.begin(); ap != idx.end(); ap++) {
@@ -178,7 +177,7 @@ void AreaList::WriteGoldLast() {
if((*ap)->isunreadchg)
entry.flags |= 4;
fp.fwrite(&entry, sizeof(entry));
fp.Fwrite(&entry, sizeof(entry));
// Write variable length extensions
(*ap)->Mark.Save(fp);
@@ -186,7 +185,7 @@ void AreaList::WriteGoldLast() {
}
}
fp.fclose();
fp.Fclose();
}
}
@@ -194,27 +193,27 @@ void AreaList::WriteGoldLast() {
// ------------------------------------------------------------------
// Read the lastreads from the last session
void AreaList::ReadGoldLast() {
void AreaList::ReadGoldLast()
{
word GOLDLAST_VER;
gfile fp;
ggoldlast entry;
fp.fopen(AddPath(CFG->goldpath, CFG->goldlast), "rb", CFG->sharemode);
if(fp.isopen()) {
gfile fp(AddPath(CFG->goldpath, CFG->goldlast), "rb", CFG->sharemode);
if (fp.isopen())
{
fp.SetvBuf(NULL, _IOFBF, 8192);
fp.Fread(&GOLDLAST_VER, sizeof(word));
fp.setvbuf(NULL, _IOFBF, 8192);
fp.fread(&GOLDLAST_VER, sizeof(word));
if(GOLDLAST_VER != CUR_GOLDLAST_VER) {
fp.close();
if (GOLDLAST_VER != CUR_GOLDLAST_VER)
{
fp.Fclose();
return;
}
fp.fread(AL.alistselections, sizeof(AL.alistselections));
while(fp.fread(&entry, sizeof(entry))) {
fp.Fread(AL.alistselections, sizeof(AL.alistselections));
while (fp.Fread(&entry, sizeof(entry)))
{
bool found = false;
for(area_iterator ap = idx.begin(); ap != idx.end(); ap++) {
@@ -237,17 +236,18 @@ void AreaList::ReadGoldLast() {
}
}
if(not found) {
if (not found)
{
// skip stored message marks
dword dw;
fp.fread(&dw, sizeof(dword));
fp.fseek(dw*sizeof(dword), SEEK_CUR);
fp.fread(&dw, sizeof(dword));
fp.fseek(dw*sizeof(dword), SEEK_CUR);
fp.Fread(&dw, sizeof(dword));
fp.Fseek(dw*sizeof(dword), SEEK_CUR);
fp.Fread(&dw, sizeof(dword));
fp.Fseek(dw*sizeof(dword), SEEK_CUR);
}
}
fp.fclose();
fp.Fclose();
}
}

View File

@@ -886,14 +886,15 @@ int ReadCfg(const char* cfgfile, int ignoreunknown) {
inuse--;
// When the final cfg is compiled
if(inuse == 0) {
if (inuse == 0)
{
// Mark all areas listed in the NEWSRC file as newsgroups
gfile gfp;
gfp.fopen(CFG->soupnewsrcfile, "rt");
if(gfp.isopen()) {
gfile gfp(CFG->soupnewsrcfile, "rt");
if (gfp.isopen())
{
char buf2[512];
while(gfp.fgets(buf2, sizeof(buf2))) {
while (gfp.Fgets(buf2, sizeof(buf2)))
{
char* ptr = strpbrk(buf2, ":! ");
if(ptr) {
*ptr = NUL;
@@ -902,7 +903,7 @@ int ReadCfg(const char* cfgfile, int ignoreunknown) {
ap->set_type(ap->isnet() ? GMB_SOUP|GMB_EMAIL|GMB_NET : GMB_SOUP|GMB_NEWSGROUP|GMB_ECHO);
}
}
gfp.fclose();
gfp.Fclose();
}
if(*CFG->soupemail) {

View File

@@ -244,20 +244,20 @@ static void WriteMsgs(GMsg* msg) {
AA->SetOutputfile(ofname);
gclipbrd clipbrd;
gfile fp;
gfile fp(fname, "rb");
if(fp.fopen(fname, "rb")) {
long len = fp.filelength();
if (fp.isopen())
{
long len = fp.FileLength();
char* buf = (char*) throw_malloc(len+1);
buf[len] = NUL;
fp.fread(buf, 1, len);
fp.Fread(buf, len);
clipbrd.writeclipbrd(buf);
throw_free(buf);
fp.close();
fp.Fclose();
}
remove(fname);
@@ -316,20 +316,20 @@ static void WriteMsgs(GMsg* msg) {
SaveLines(MODE_WRITE, fname, msg, prnmargin, true);
gclipbrd clipbrd;
gfile fp;
gfile fp(fname, "rb");
if(fp.fopen(fname, "rb")) {
long len = fp.filelength();
if (fp.isopen())
{
long len = fp.FileLength();
char* buf = (char*) throw_malloc(len+1);
buf[len] = NUL;
fp.fread(buf, 1, len);
fp.Fread(buf, len);
clipbrd.writeclipbrd(buf);
throw_free(buf);
fp.close();
fp.Fclose();
}
remove(fname);

View File

@@ -3272,7 +3272,7 @@ char* ParseInternetAddr(char* __string, char* __name, char* __addr, bool detect_
char* begaddr = endchar;
if(*endchar == '<') {
begaddr++;
endchar--;
if (endchar > __string) endchar--;
}
__string = strskip_wht(__string);
strbtrim(strxcpy(__name, __string, MinV((size_t)(endchar-__string)+1, (size_t)sizeof(INam))));

View File

@@ -34,25 +34,27 @@ static void ReadGldFile() {
if(QWK->FoundBBS()) {
gfile fp;
Path gldfile;
QWK->ResetConfNo();
sprintf(gldfile, "%s%s.GLD", CFG->goldpath, QWK->BbsID());
fp.fopen(gldfile, "rt");
if(fp.isopen()) {
gfile fp(gldfile, "rt");
if (fp.isopen())
{
char* key;
char* val;
char buf[256];
while(fp.fgets(buf, sizeof(buf))) {
while (fp.Fgets(buf, sizeof(buf)))
{
val = strtrim(buf);
getkeyval(&key, &val);
strtrim(StripQuotes(val));
if(QWK->FindEcho(val))
QWK->ConfNo(atoi(key));
}
fp.fclose();
fp.Fclose();
}
}
}
@@ -65,7 +67,6 @@ int ImportQWK() {
if(not *QWK->ImportPath())
return 0;
gfile fp;
gfile fpb; // For BBSID.GLD
Path file;
Path gldfile;
@@ -73,22 +74,24 @@ int ImportQWK() {
// Parse the control file
strcpy(file, AddPath(QWK->ImportPath(), "CONTROL.DAT"));
fp.fopen(file, "rt");
if(fp.isopen()) {
gfile fp(file, "rt");
if (fp.isopen())
{
char buf[256];
int line = 0;
int confno = 0;
int confcnt = 0;
int confnos = 0;
while(fp.fgets(buf, sizeof(buf))) {
while (fp.Fgets(buf, sizeof(buf)))
{
line++;
strtrim(buf);
if((line >= 12) and (confcnt < confnos)) {
if(line % 2) {
if(fpb.isopen())
fpb.printf("%u \"%s\"\n", confno, buf);
if(line % 2)
{
if (fpb.isopen())
fpb.Printf("%u \"%s\"\n", confno, buf);
confcnt++;
}
else
@@ -99,15 +102,15 @@ int ImportQWK() {
if(ptr) {
strxcpy(bbsid, strskip_wht(ptr+1), 9);
sprintf(gldfile, "%s%s.GLD", CFG->goldpath, bbsid);
fpb.fopen(gldfile, "wt");
fpb.Fopen(gldfile, "wt");
}
}
else if(line == 11)
confnos = atoi(buf) + 1;
}
if(fpb.isopen())
fpb.fclose();
fp.fclose();
fpb.Fclose();
fp.Fclose();
remove(file);
}
@@ -122,11 +125,11 @@ int ImportQWK() {
OrigArea = CurrArea = -1;
strcpy(file, AddPath(QWK->ImportPath(), "MESSAGES.DAT"));
fp.fopen(file, "rb");
if(fp.isopen()) {
fp.Fopen(file, "rb");
if (fp.isopen())
{
// Skip past product info header
fp.fseekset(sizeof(QWKHdr));
fp.FseekSet(sizeof(QWKHdr));
QWKHdr hdr;
@@ -141,7 +144,7 @@ int ImportQWK() {
ResetMsg(msg);
memset(&hdr, 0, sizeof(QWKHdr));
more = 1 == fp.fread(&hdr, sizeof(QWKHdr));
more = 1 == fp.Fread(&hdr, sizeof(QWKHdr));
if(more) {
char blocks[7];
@@ -167,9 +170,10 @@ int ImportQWK() {
CurrArea = AL.AreaNoToId(areano);
tosstobadmsgs = true;
}
else {
else
{
tosstobadmsgs = -1;
fp.fseek(msglen, SEEK_CUR);
fp.Fseek(msglen, SEEK_CUR);
}
}
}
@@ -225,7 +229,7 @@ int ImportQWK() {
sprintf(msg->txt, "AREA:%s_%u\r", bbsid, hdr.confno);
txtptr += strlen(msg->txt);
}
fp.fread(txtptr, msglen);
fp.Fread(txtptr, msglen);
strtrim(txtptr);
strchg(txtptr, 0xE3, 0x0D);
@@ -315,22 +319,24 @@ int ImportQWK() {
ResetMsg(msg);
throw_free(msg);
fp.fclose();
fp.Fclose();
remove(file);
if(*QWK->TossLog()) {
fp.fopen(QWK->TossLog(), "at");
if(fp.isopen()) {
if (*QWK->TossLog())
{
fp.Fopen(QWK->TossLog(), "at");
if (fp.isopen())
{
uint na = 0;
while(na < AL.size()) {
if(AL[na]->istossed) {
AL[na]->istossed = false;
AL[na]->isunreadchg = true;
fp.printf("%s\n", AL[na]->echoid());
fp.Printf("%s\n", AL[na]->echoid());
}
na++;
}
fp.fclose();
fp.Fclose();
}
}
@@ -389,7 +395,7 @@ int ExportQwkMsg(GMsg* msg, gfile& fp, int confno, int& pktmsgno) {
hdr.pktmsgno = (word)++pktmsgno;
// Write preliminary header
fp.fwrite(&hdr, sizeof(QWKHdr));
fp.Fwrite(&hdr, sizeof(QWKHdr));
// Write body
int level = 0;
@@ -418,9 +424,10 @@ int ExportQwkMsg(GMsg* msg, gfile& fp, int confno, int& pktmsgno) {
while(line) {
if(line->type & GLINE_KLUDGE) {
if(AA->isinternet()) {
if((line->kludge == GKLUD_RFC) or (line->kludge == 0)) {
if ((line->kludge == GKLUD_RFC) or (line->kludge == 0))
{
XlatStr(mbuf, line->txt.c_str(), level, CharTable);
msglen += fp.printf("%s%c", mbuf, qwkterm);
msglen += fp.Printf("%s%c", mbuf, qwkterm);
}
else if(line->type & GLINE_WRAP) {
while(line->next and (line->type & GLINE_WRAP))
@@ -428,9 +435,10 @@ int ExportQwkMsg(GMsg* msg, gfile& fp, int confno, int& pktmsgno) {
}
}
else {
if((line->type & GLINE_KLUDGE) and QWK->KludgesAllowed()) {
if ((line->type & GLINE_KLUDGE) and QWK->KludgesAllowed())
{
XlatStr(mbuf, line->txt.c_str(), level, CharTable);
msglen += fp.printf("%s%c", mbuf, qwkterm);
msglen += fp.Printf("%s%c", mbuf, qwkterm);
}
}
}
@@ -438,16 +446,16 @@ int ExportQwkMsg(GMsg* msg, gfile& fp, int confno, int& pktmsgno) {
}
// Write blank line after header lines
if(AA->Internetrfcbody()) {
msglen += fp.printf("%c", qwkterm);
}
if (AA->Internetrfcbody())
msglen += fp.Printf("%c", qwkterm);
// Write all message lines
line = msg->lin;
while(line) {
if(not (line->type & GLINE_KLUDGE)) {
if (not (line->type & GLINE_KLUDGE))
{
XlatStr(mbuf, line->txt.c_str(), level, CharTable);
msglen += fp.printf("%s%c", mbuf, qwkterm);
msglen += fp.Printf("%s%c", mbuf, qwkterm);
}
line = line->next;
}
@@ -459,16 +467,17 @@ int ExportQwkMsg(GMsg* msg, gfile& fp, int confno, int& pktmsgno) {
memcpy(hdr.blocks, buf, strlen(buf));
// Write padding spaces at the end if necessary
if(endlen) {
if (endlen)
{
char padding[128];
memset(padding, ' ', 128);
fp.fwrite(padding, 128-endlen);
fp.Fwrite(padding, 128-endlen);
}
// Re-write the header
fp.fseek(-(blocks*128), SEEK_CUR);
fp.fwrite(&hdr, sizeof(QWKHdr));
fp.fseek((blocks-1)*128, SEEK_CUR);
fp.Fseek(-(blocks*128), SEEK_CUR);
fp.Fwrite(&hdr, sizeof(QWKHdr));
fp.Fseek((blocks-1)*128, SEEK_CUR);
// Mark msg as sent
msg->attr.snt1();
@@ -529,10 +538,12 @@ int ExportQWK() {
// Get the scan list
strcpy(scanfile, AddPath(CFG->goldpath, "GOLDQWK.LST"));
fp.fopen(scanfile, "rt");
if(fp.isopen()) {
fp.Fopen(scanfile, "rt");
if (fp.isopen())
{
char buf[256];
while(fp.fgets(buf, sizeof(buf))) {
while (fp.Fgets(buf, sizeof(buf)))
{
char* ptr = strchr(buf, ' ');
if(ptr) {
*ptr++ = NUL;
@@ -541,7 +552,7 @@ int ExportQWK() {
AL[a]->Expo.Add(atol(ptr));
}
}
fp.fclose();
fp.Fclose();
}
// Export from the QWK areas
@@ -550,14 +561,16 @@ int ExportQWK() {
ReadGldFile();
Path replyfile;
int pktmsgno = 0;
if(QWK->FirstConf()) {
if (QWK->FirstConf())
{
sprintf(replyfile, "%s%s.MSG", QWK->ExportPath(), QWK->BbsID());
fp.fopen(replyfile, "wb");
if(fp.isopen()) {
fp.Fopen(replyfile, "wb");
if (fp.isopen())
{
char firstrec[128];
memset(firstrec, ' ', 128);
memcpy(firstrec, QWK->BbsID(), strlen(QWK->BbsID()));
fp.fwrite(firstrec, 128);
fp.Fwrite(firstrec, 128);
pktmsgno = 0;
}
do {
@@ -568,8 +581,9 @@ int ExportQWK() {
}
} while(QWK->NextConf());
}
if(fp.isopen()) {
fp.fclose();
if (fp.isopen())
{
fp.Fclose();
if(pktmsgno == 0)
remove(replyfile);
}

View File

@@ -575,15 +575,16 @@ int ExternUtil(GMsg *msg, ExtUtil *extutil) {
if(extutil->options & EXTUTIL_RELOAD) {
if(not (extutil->options & EXTUTIL_KEEPCTRL)) {
if(*msg->tearline or *msg->origin) {
gfile fp;
fp.fopen(editorfile, "at");
if(fp.isopen()) {
if(*msg->tearline)
fp.printf("--- %s\n", msg->tearline);
if(*msg->origin)
fp.printf(" * Origin: %s\n", msg->origin);
fp.fclose();
if (*msg->tearline or *msg->origin)
{
gfile fp(editorfile, "at");
if (fp.isopen())
{
if (*msg->tearline)
fp.Printf("--- %s\n", msg->tearline);
if (*msg->origin)
fp.Printf(" * Origin: %s\n", msg->origin);
fp.Fclose();
}
}
}
@@ -938,11 +939,11 @@ void TouchSemaphore() {
// ------------------------------------------------------------------
void make_pathreport(const char* reportfile) {
gfile fp;
fp.fopen(reportfile, "wt");
if(fp) {
void make_pathreport(const char* reportfile)
{
gfile fp(reportfile, "wt");
if (fp.isopen())
{
std::string path;
ftn_addr address;
std::vector<ftn_addr> alist;
@@ -964,7 +965,7 @@ void make_pathreport(const char* reportfile) {
strcpy(buf, msg->By());
strchg(buf, ' ', '_');
std::string temp;
fp.printf("%s %s ", buf, address.make_string(temp).c_str());
fp.Printf("%s %s ", buf, address.make_string(temp).c_str());
path = "";
Line* line = msg->lin;
while(line) {
@@ -978,11 +979,11 @@ void make_pathreport(const char* reportfile) {
for(int i=0; i<links.size(); i++)
address = links[i];
}
fp.printf("%s\n", path.c_str());
fp.Printf("%s\n", path.c_str());
}
}
w_progress(MODE_QUIT, BLACK_|_BLACK, 0, 0, NULL);
fp.fclose();
fp.Fclose();
ResetMsg(msg);
throw_free(msg);
}

View File

@@ -115,17 +115,20 @@ int AreaList::AreaScan(int mode, uint currno, int pmscan, int& pmails, int& pmar
int groupid = -1;
// Load scan list into a string bag
if(mode == SCAN_LIST) {
gfile fp;
if (mode == SCAN_LIST)
{
Path tmp;
strcpy(tmp, file ? file : ListScan.File());
char* listfile;
char* option=tmp;
getkeyval(&listfile, &option);
fp.fopen(AddPath(CFG->goldpath, listfile), "rt");
if(fp.isopen()) {
gfile fp(AddPath(CFG->goldpath, listfile), "rt");
if (fp.isopen())
{
char buf[512];
while(fp.fgets(buf, sizeof(buf))) {
while (fp.Fgets(buf, sizeof(buf)))
{
strbtrim(buf);
char* val = strtok(buf, ", \t");
while(val) {
@@ -133,8 +136,8 @@ int AreaList::AreaScan(int mode, uint currno, int pmscan, int& pmails, int& pmar
val = strtok(NULL, ", \t");
}
}
fp.fclose();
if(((*option == '-') or (*option == '/')) and strieql(option+1, "delete"))
fp.Fclose();
if (((*option == '-') or (*option == '/')) and strieql(option+1, "delete"))
remove(listfile);
}
}

View File

@@ -384,16 +384,16 @@ int ImportSOUP() {
const int MBUF_SIZE = 65535;
const int LBUF_SIZE = 65535;
gfile fpa; // For AREAS file
gfile fpm; // For *.MSG files
int importedmsgs = 0;
Path areasfile;
strcpy(areasfile, AddPath(CFG->soupimportpath, "AREAS"));
fpa.fopen(areasfile, "rt");
if(fpa.isopen()) {
gfile fpa(areasfile, "rt");
if (fpa.isopen())
{
char buf[2048];
LoadCharset("N/A", "N/A");
@@ -403,8 +403,8 @@ int ImportSOUP() {
GMsg* msg = (GMsg*)throw_calloc(1, sizeof(GMsg));
while(fpa.fgets(buf, sizeof(buf))) {
while (fpa.Fgets(buf, sizeof(buf)))
{
char* delim = "\t\n";
char* prefix = strtok(buf, delim);
char* areaname = strtok(NULL, delim);
@@ -457,9 +457,9 @@ int ImportSOUP() {
AL.SetActiveAreaNo(areano);
OrigArea = CurrArea;
fpm.fopen(msgfile, "rb");
if(fpm.isopen()) {
fpm.Fopen(msgfile, "rb");
if (fpm.isopen())
{
imported++;
int msgs = 0;
@@ -477,16 +477,16 @@ int ImportSOUP() {
// Get binary formats
dword msglen = 0;
while(fpm.fread(&msglen, 4) == 1) {
while (fpm.Fread(&msglen, 4) == 1)
{
msglen = swapendian(msglen);
uint msglensz = (uint)msglen;
if(msglen != msglensz)
msglensz--;
msg->txt = (char*)throw_calloc(1, msglensz+1);
fpm.fread(msg->txt, msglensz);
if(msglen != msglensz)
fpm.fseek(msglen-msglensz, SEEK_CUR);
fpm.Fread(msg->txt, msglensz);
if (msglen != msglensz)
fpm.Fseek(msglen-msglensz, SEEK_CUR);
ProcessSoupMsg(lbuf, msg, msgs, areaname, tosstobadmsgs);
}
}
@@ -494,8 +494,8 @@ int ImportSOUP() {
// Get non-binary formats
while(fpm.fgets(mbuf, MBUF_SIZE)) {
while (fpm.Fgets(mbuf, MBUF_SIZE))
{
if(msgfmt == 'u') {
if(strneql(mbuf, "#! rnews ", 9)) {
dword msglen = atol(mbuf+9);
@@ -503,9 +503,9 @@ int ImportSOUP() {
if(msglen != msglensz)
msglensz--;
msg->txt = (char*)throw_calloc(1, msglensz+1);
fpm.fread(msg->txt, msglensz);
if(msglen != msglensz)
fpm.fseek(msglen-msglensz, SEEK_CUR);
fpm.Fread(msg->txt, msglensz);
if (msglen != msglensz)
fpm.Fseek(msglen-msglensz, SEEK_CUR);
ProcessSoupMsg(lbuf, msg, msgs, areaname, tosstobadmsgs);
}
else {
@@ -553,10 +553,9 @@ int ImportSOUP() {
AA->Unlock();
AA->Close();
if(msgs)
importedmsgs += msgs;
if (msgs) importedmsgs += msgs;
fpm.fclose();
fpm.Fclose();
}
}
@@ -571,23 +570,22 @@ int ImportSOUP() {
throw_free(lbuf);
throw_free(mbuf);
fpa.fclose();
fpa.Fclose();
remove(areasfile);
if(*CFG->souptosslog)
fpa.fopen(CFG->souptosslog, "at");
if (*CFG->souptosslog)
fpa.Fopen(CFG->souptosslog, "at");
for(uint na = 0; na < AL.size(); na++) {
if(AL[na]->istossed) {
AL[na]->istossed = false;
AL[na]->isunreadchg = true;
if(fpa.isopen())
fpa.printf("%s\n", AL[na]->echoid());
if (fpa.isopen())
fpa.Printf("%s\n", AL[na]->echoid());
}
}
if(fpa.isopen())
fpa.fclose();
fpa.Fclose();
if(importedmsgs and *CFG->soupreplylinker) {
sprintf(buf, LNG->Replylinker, CFG->soupreplylinker);
@@ -609,14 +607,15 @@ int ExportSoupMsg(GMsg* msg, char* msgfile, gfile& fp, int ismail) {
NW(ismail);
if(not fp.isopen()) {
fp.open(AddPath(CFG->soupexportpath, msgfile), O_RDWR|O_CREAT|O_BINARY, "rb+");
if(fp.isopen())
fp.fseek(0, SEEK_END);
if (not fp.isopen())
{
fp.Open(AddPath(CFG->soupexportpath, msgfile), O_RDWR|O_CREAT|O_BINARY, "rb+");
if (fp.isopen())
fp.Fseek(0, SEEK_END);
}
if(fp.isopen()) {
if (fp.isopen())
{
int level = 0;
if(CharTable)
level = CharTable->level ? CharTable->level : 2;
@@ -625,7 +624,7 @@ int ExportSoupMsg(GMsg* msg, char* msgfile, gfile& fp, int ismail) {
// Write placeholder for message length
dword msglen = 0xFFFFFFFFL;
fp.fwrite(&msglen, 4);
fp.Fwrite(&msglen, 4);
msglen = 0;
bool qp = false;
@@ -648,7 +647,7 @@ int ExportSoupMsg(GMsg* msg, char* msgfile, gfile& fp, int ismail) {
if((line->kludge == GKLUD_RFC) or (line->kludge == 0)) {
const char *ltxt = line->txt.c_str();
XlatStr(mbuf, (*ltxt == CTRL_A) ? (ltxt + 1) : ltxt, level, CharTable);
msglen += fp.printf("%s%s", mbuf, (line->type & GLINE_WRAP) ? "" : "\n");
msglen += fp.Printf("%s%s", mbuf, (line->type & GLINE_WRAP) ? "" : "\n");
}
else if(line->type & GLINE_WRAP) {
while(line->next and (line->type & GLINE_WRAP))
@@ -659,7 +658,7 @@ int ExportSoupMsg(GMsg* msg, char* msgfile, gfile& fp, int ismail) {
}
// Write blank line after header lines
msglen += fp.printf("\n");
msglen += fp.Printf("\n");
// Write all message lines
line = msg->lin;
@@ -680,19 +679,19 @@ int ExportSoupMsg(GMsg* msg, char* msgfile, gfile& fp, int ismail) {
else if(*(mptr-1) == '=')
mptr--;
int mlen = (int)(mptr - mbeg);
msglen += fp.printf("%*.*s=\n", mlen, mlen, mbeg);
msglen += fp.Printf("%*.*s=\n", mlen, mlen, mbeg);
} while(strlen(mptr) > 76);
}
msglen += fp.printf("%s\n", mptr);
msglen += fp.Printf("%s\n", mptr);
}
line = line->next;
}
// Re-write the correct message length
fp.fseek(-(msglen+4), SEEK_CUR);
fp.Fseek(-(msglen+4), SEEK_CUR);
dword be_msglen = swapendian(msglen);
fp.fwrite(&be_msglen, 4);
fp.fseek(msglen, SEEK_CUR);
fp.Fwrite(&be_msglen, 4);
fp.Fseek(msglen, SEEK_CUR);
msg->attr.snt1();
msg->attr.scn1();
@@ -762,10 +761,12 @@ int ExportSOUP() {
// Get the scan list
strcpy(scanfile, AddPath(CFG->goldpath, "goldsoup.lst"));
fp.fopen(scanfile, "rt");
if(fp.isopen()) {
fp.Fopen(scanfile, "rt");
if (fp.isopen())
{
char buf[256];
while(fp.fgets(buf, sizeof(buf))) {
while (fp.Fgets(buf, sizeof(buf)))
{
char* ptr = strchr(buf, ' ');
if(ptr) {
*ptr++ = NUL;
@@ -774,7 +775,7 @@ int ExportSOUP() {
AL[a]->Expo.Add(atol(ptr));
}
}
fp.fclose();
fp.Fclose();
}
// Export from the e-mail and newsgroup areas
@@ -787,29 +788,29 @@ int ExportSOUP() {
}
// Close any open SOUP files
if(mfp.isopen())
mfp.fclose();
if(nfp.isopen())
nfp.fclose();
mfp.Fclose();
nfp.Fclose();
// Update the REPLIES file
fp.open(AddPath(CFG->soupexportpath, "REPLIES"), O_RDWR|O_CREAT|O_BINARY, "rb+");
if(fp.isopen()) {
fp.Open(AddPath(CFG->soupexportpath, "REPLIES"), O_RDWR|O_CREAT|O_BINARY, "rb+");
if (fp.isopen())
{
char buf[512];
int hasmail = false;
int hasnews = false;
while(fp.fgets(buf, sizeof(buf))) {
while (fp.Fgets(buf, sizeof(buf)))
{
strtok(buf, "\t\n");
if(strieql(buf, "GOLDMAIL"))
hasmail = true;
else if(strieql(buf, "GOLDNEWS"))
hasnews = true;
}
if(mailexported and not hasmail)
fp.printf("GOLDMAIL\tmail\tbn\n");
if(newsexported and not hasnews)
fp.printf("GOLDNEWS\tnews\tBn\n");
fp.fclose();
if (mailexported and not hasmail)
fp.Printf("GOLDMAIL\tmail\tbn\n");
if (newsexported and not hasnews)
fp.Printf("GOLDNEWS\tnews\tBn\n");
fp.Fclose();
}
// Delete the scanfile

View File

@@ -39,9 +39,11 @@ guserbase::guserbase() {
strcpy(fname, AddPath(CFG->goldpath, CFG->golduser));
do {
usrbase.open(fname, O_RDWR|O_CREAT|O_BINARY, SH_DENYNO, S_STDRW);
if(not usrbase) {
do
{
usrbase.Open(fname, O_RDWR|O_CREAT|O_BINARY, SH_DENYNO, S_STDRW);
if (!usrbase.isopen())
{
if((errno != EACCES) or (not PopupLocked(++tries, false, fname))) {
WideLog->ErrOpen();
WideLog->printf("! Addressbook cannot be opened.");
@@ -50,13 +52,14 @@ guserbase::guserbase() {
OpenErrorExit();
}
}
} while(not usrbase);
}
while(!usrbase.isopen());
if(tries)
PopupLocked(0, 0, NULL);
if((uint) usrbase.filelength() < sizeof(gusrbaseheader) + sizeof(gusrbaseentry)) {
if (uint(usrbase.FileLength()) < sizeof(gusrbaseheader) + sizeof(gusrbaseentry))
{
header.version = 0;
strcpy(entry.macro, "_asa_");
@@ -84,8 +87,8 @@ guserbase::guserbase() {
entry.comment2[0] = NUL;
entry.comment3[0] = NUL;
usrbase.lseek(0, SEEK_SET);
usrbase.write(&header.version, sizeof(header.version));
usrbase.LseekSet(0);
usrbase.Write(&header.version, sizeof(header.version));
write_entry(0);
}
@@ -100,7 +103,7 @@ guserbase::guserbase() {
guserbase::~guserbase() {
usrbase.close();
usrbase.Close();
}
@@ -109,21 +112,25 @@ guserbase::~guserbase() {
void guserbase::refresh_maximum_index() {
// Are we doing it for the first time?
if(not read_time) {
usrbase.getftime(&read_time);
if (not read_time)
{
usrbase.GetFTime(&read_time);
need_update = true;
}
else {
else
{
dword tmp;
usrbase.getftime(&tmp);
if(read_time != tmp) {
usrbase.GetFTime(&tmp);
if (read_time != tmp)
{
read_time = tmp;
need_update = true;
}
}
if(need_update)
maximum_index = (usrbase.filelength()-sizeof(gusrbaseheader)) / sizeof(gusrbaseentry) - 1;
if(index > maximum_index)
if (need_update)
maximum_index = (uint(usrbase.FileLength()) - sizeof(gusrbaseheader)) / sizeof(gusrbaseentry) - 1;
if (index > maximum_index)
index = maximum_index;
}
@@ -136,9 +143,11 @@ void guserbase::lock() {
long tries = 0;
do {
usrbase.lock(0, 1);
if(not usrbase.okay()) {
do
{
usrbase.Lock(0, 1);
if (!usrbase.okay())
{
if(not PopupLocked(++tries, false, fname)) {
WideLog->ErrLock();
WideLog->printf("! GoldED's Addressbook could not be locked.");
@@ -147,7 +156,9 @@ void guserbase::lock() {
LockErrorExit();
}
}
} while(not usrbase.okay());
}
while(!usrbase.okay());
if(tries)
PopupLocked(0, 0, NULL);
}
@@ -156,10 +167,10 @@ void guserbase::lock() {
// ------------------------------------------------------------------
void guserbase::unlock() {
if(WideCanLock)
usrbase.unlock(0, 1);
void guserbase::unlock()
{
if (WideCanLock)
usrbase.Unlock(0, 1);
}
@@ -405,8 +416,9 @@ bool guserbase::find_entry(char* name, bool lookup) {
uint old_index = index;
refresh_maximum_index();
usrbase.lseek(sizeof(gusrbaseheader), SEEK_SET);
for(index=0; index<=maximum_index; index++) {
usrbase.LseekSet(sizeof(gusrbaseheader));
for (index=0; index<=maximum_index; index++)
{
read_entry(index, &entry);
if(strieql(name, entry.name))
@@ -446,35 +458,33 @@ void guserbase::write_entry(uint idx, bool updateit) {
entry.times++;
}
usrbase.lseek(sizeof(gusrbaseheader) + sizeof(gusrbaseentry)*(idx+1)-1, SEEK_SET);
usrbase.LseekSet(sizeof(gusrbaseheader) + sizeof(gusrbaseentry)*(idx+1)-1);
char z = 0;
usrbase.write(&z, 1); // adjust entry size first...
usrbase.lseek(sizeof(gusrbaseheader) + sizeof(gusrbaseentry)*idx, SEEK_SET);
usrbase.write(entry.macro, sizeof(entry.macro));
usrbase.write(entry.name, sizeof(entry.name));
usrbase.write(&entry.fidoaddr.zone, sizeof(entry.fidoaddr.zone));
usrbase.write(&entry.fidoaddr.net, sizeof(entry.fidoaddr.net));
usrbase.write(&entry.fidoaddr.node, sizeof(entry.fidoaddr.node));
usrbase.write(&entry.fidoaddr.point, sizeof(entry.fidoaddr.point));
usrbase.write(entry.iaddr, sizeof(entry.iaddr));
usrbase.write(&entry.prefer_internet, sizeof(entry.prefer_internet));
usrbase.write(&entry.is_deleted, sizeof(entry.is_deleted));
usrbase.write(entry.pseudo, sizeof(entry.pseudo));
usrbase.write(entry.organisation, sizeof(entry.organisation));
usrbase.write(entry.snail1, sizeof(entry.snail1));
usrbase.write(entry.snail2, sizeof(entry.snail2));
usrbase.write(entry.snail3, sizeof(entry.snail3));
usrbase.write(entry.dataphone, sizeof(entry.dataphone));
usrbase.write(entry.voicephone, sizeof(entry.voicephone));
usrbase.write(entry.faxphone, sizeof(entry.faxphone));
usrbase.write(&entry.firstdate, sizeof(entry.firstdate));
usrbase.write(&entry.lastdate, sizeof(entry.lastdate));
usrbase.write(&entry.times, sizeof(entry.times));
usrbase.write(entry.homepage, sizeof(entry.homepage));
usrbase.write(&entry.group, sizeof(entry.group));
usrbase.write(entry.comment1, sizeof(entry.comment1));
usrbase.write(entry.comment2, sizeof(entry.comment1));
usrbase.write(entry.comment3, sizeof(entry.comment1));
usrbase.Write(&z, 1); // adjust entry size first...
usrbase.LseekSet(sizeof(gusrbaseheader) + sizeof(gusrbaseentry)*idx);
usrbase.Write(entry.macro, sizeof(entry.macro));
usrbase.Write(entry.name, sizeof(entry.name));
usrbase.Write(&entry.fidoaddr.zone, sizeof(entry.fidoaddr.zone));
usrbase.Write(&entry.fidoaddr.net, sizeof(entry.fidoaddr.net));
usrbase.Write(&entry.fidoaddr.node, sizeof(entry.fidoaddr.node));
usrbase.Write(&entry.fidoaddr.point, sizeof(entry.fidoaddr.point));
usrbase.Write(entry.iaddr, sizeof(entry.iaddr));
usrbase.Write(&entry.prefer_internet, sizeof(entry.prefer_internet));
usrbase.Write(&entry.is_deleted, sizeof(entry.is_deleted));
usrbase.Write(entry.organisation, sizeof(entry.organisation));
usrbase.Write(entry.snail1, sizeof(entry.snail1));
usrbase.Write(entry.snail2, sizeof(entry.snail2));
usrbase.Write(entry.snail3, sizeof(entry.snail3));
usrbase.Write(entry.voicephone, sizeof(entry.voicephone));
usrbase.Write(entry.faxphone, sizeof(entry.faxphone));
usrbase.Write(&entry.firstdate, sizeof(entry.firstdate));
usrbase.Write(&entry.lastdate, sizeof(entry.lastdate));
usrbase.Write(&entry.times, sizeof(entry.times));
usrbase.Write(entry.homepage, sizeof(entry.homepage));
usrbase.Write(&entry.group, sizeof(entry.group));
usrbase.Write(entry.comment1, sizeof(entry.comment1));
usrbase.Write(entry.comment2, sizeof(entry.comment1));
usrbase.Write(entry.comment3, sizeof(entry.comment1));
}
// ------------------------------------------------------------------
@@ -514,33 +524,34 @@ bool guserbase::read_entry(uint idx, gusrbaseentry *ent) {
clear_entry(ent);
return false;
}
else {
usrbase.lseek(idx*sizeof(gusrbaseentry)+sizeof(gusrbaseheader), SEEK_SET);
usrbase.read(ent->macro, sizeof(ent->macro));
usrbase.read(ent->name, sizeof(ent->name));
usrbase.read(&ent->fidoaddr.zone, sizeof(ent->fidoaddr.zone));
usrbase.read(&ent->fidoaddr.net, sizeof(ent->fidoaddr.net));
usrbase.read(&ent->fidoaddr.node, sizeof(ent->fidoaddr.node));
usrbase.read(&ent->fidoaddr.point, sizeof(ent->fidoaddr.point));
usrbase.read(ent->iaddr, sizeof(ent->iaddr));
usrbase.read(&ent->prefer_internet, sizeof(ent->prefer_internet));
usrbase.read(&ent->is_deleted, sizeof(ent->is_deleted));
usrbase.read(ent->pseudo, sizeof(ent->pseudo));
usrbase.read(ent->organisation, sizeof(ent->organisation));
usrbase.read(ent->snail1, sizeof(ent->snail1));
usrbase.read(ent->snail2, sizeof(ent->snail2));
usrbase.read(ent->snail3, sizeof(ent->snail3));
usrbase.read(ent->dataphone, sizeof(ent->dataphone));
usrbase.read(ent->voicephone, sizeof(ent->voicephone));
usrbase.read(ent->faxphone, sizeof(ent->faxphone));
usrbase.read(&ent->firstdate, sizeof(ent->firstdate));
usrbase.read(&ent->lastdate, sizeof(ent->lastdate));
usrbase.read(&ent->times, sizeof(ent->times));
usrbase.read(ent->homepage, sizeof(ent->homepage));
usrbase.read(&ent->group, sizeof(ent->group));
usrbase.read(ent->comment1, sizeof(ent->comment1));
usrbase.read(ent->comment2, sizeof(ent->comment1));
usrbase.read(ent->comment3, sizeof(ent->comment1));
else
{
usrbase.LseekSet(idx*sizeof(gusrbaseentry)+sizeof(gusrbaseheader));
usrbase.Read(ent->macro, sizeof(ent->macro));
usrbase.Read(ent->name, sizeof(ent->name));
usrbase.Read(&ent->fidoaddr.zone, sizeof(ent->fidoaddr.zone));
usrbase.Read(&ent->fidoaddr.net, sizeof(ent->fidoaddr.net));
usrbase.Read(&ent->fidoaddr.node, sizeof(ent->fidoaddr.node));
usrbase.Read(&ent->fidoaddr.point, sizeof(ent->fidoaddr.point));
usrbase.Read(ent->iaddr, sizeof(ent->iaddr));
usrbase.Read(&ent->prefer_internet, sizeof(ent->prefer_internet));
usrbase.Read(&ent->is_deleted, sizeof(ent->is_deleted));
usrbase.Read(ent->pseudo, sizeof(ent->pseudo));
usrbase.Read(ent->organisation, sizeof(ent->organisation));
usrbase.Read(ent->snail1, sizeof(ent->snail1));
usrbase.Read(ent->snail2, sizeof(ent->snail2));
usrbase.Read(ent->snail3, sizeof(ent->snail3));
usrbase.Read(ent->dataphone, sizeof(ent->dataphone));
usrbase.Read(ent->voicephone, sizeof(ent->voicephone));
usrbase.Read(ent->faxphone, sizeof(ent->faxphone));
usrbase.Read(&ent->firstdate, sizeof(ent->firstdate));
usrbase.Read(&ent->lastdate, sizeof(ent->lastdate));
usrbase.Read(&ent->times, sizeof(ent->times));
usrbase.Read(ent->homepage, sizeof(ent->homepage));
usrbase.Read(&ent->group, sizeof(ent->group));
usrbase.Read(ent->comment1, sizeof(ent->comment1));
usrbase.Read(ent->comment2, sizeof(ent->comment1));
usrbase.Read(ent->comment3, sizeof(ent->comment1));
return true;
}
}
@@ -570,14 +581,15 @@ void guserbase::pack_addressbook() {
// zap
maximum_index = nidx;
// At least one record should present
if(maximum_index)
--maximum_index;
usrbase.chsize((maximum_index + 1) * sizeof(gusrbaseentry) + sizeof(gusrbaseheader));
usrbase.close();
if (maximum_index) --maximum_index;
usrbase.ChSize((maximum_index + 1) * sizeof(gusrbaseentry) + sizeof(gusrbaseheader));
usrbase.Close();
do {
usrbase.open(fname, O_RDWR|O_CREAT|O_BINARY, SH_DENYNO, S_STDRW);
if(not usrbase) {
do
{
usrbase.Open(fname, O_RDWR|O_CREAT|O_BINARY, SH_DENYNO, S_STDRW);
if (!usrbase.isopen())
{
if((errno != EACCES) or (not PopupLocked(++tries, false, fname))) {
WideLog->ErrOpen();
WideLog->printf("! GoldED's Addressbook cannot be opened.");
@@ -586,7 +598,8 @@ void guserbase::pack_addressbook() {
OpenErrorExit();
}
}
} while(not usrbase);
}
while(!usrbase.isopen());
if(tries)
PopupLocked(0, 0, NULL);

View File

@@ -54,9 +54,10 @@ void WriteNoDupes(const char* file, const char* line) {
long tries = 0;
do {
fp.fopen(file, "at+", SH_DENYRW);
fp.Fopen(file, "at+", SH_DENYRW);
if(not fp.isopen()) {
if (!fp.isopen())
{
if((errno != EACCES) or (PopupLocked(++tries, false, file) == false)) {
LOG.ErrOpen();
LOG.printf("! A semaphore file could not be opened.");
@@ -65,24 +66,27 @@ void WriteNoDupes(const char* file, const char* line) {
OpenErrorExit();
}
}
} while(not fp.isopen());
}
while(!fp.isopen());
if(tries)
if (tries)
PopupLocked(0, 0, NULL);
fp.fseek(0, SEEK_SET);
while(fp.fgets(buf, sizeof(buf))) {
fp.FseekSet(0);
while (fp.Fgets(buf, sizeof(buf)))
{
if(strieql(strtrim(buf), line)) {
found = true;
break;
}
}
if(not found) {
fp.fseek(0, SEEK_END);
fp.printf("%s\n", line);
if (not found)
{
fp.Fseek(0, SEEK_END);
fp.Printf("%s\n", line);
}
fp.fclose();
fp.Fclose();
}