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();
}

View File

@ -29,11 +29,56 @@
#include <cstdarg>
#include <gfile.h>
#if defined(_MSC_VER) /*&& (_MSC_VER >= 1400)*/
#define g_sopen(fn, of, sh, pm) _tsopen(fn, of, sh, pm)
#define g_close(fh) _close(fh)
#define g_read(fh, buf, cnt) _read(fh, buf, cnt)
#define g_write(fh, buf, cnt) _write(fh, buf, cnt)
#define g_tell(fh) _tell(fh)
#define g_lseek(fh, off, org) _lseek(fh, off, org)
#define g_filelength(fh) _filelength(fh)
#define g_chsize(fh, size) _chsize(fh, size)
#define g_fsopen(fn, of, sh) _tfsopen(fn, of, sh)
#define g_fdopen(fp, of) _tfdopen(fp, of)
#define g_fileno(fp) _fileno(fp)
#else
#define g_sopen(fn, of, sh, pm) sopen(fn, of, sh, pm)
#define g_close(fh) close(fh)
#define g_read(fh, buf, cnt) read(fh, buf, cnt)
#define g_write(fh, buf, cnt) write(fh, buf, cnt)
#define g_tell(fh) tell(fh)
#define g_lseek(fh, off, org) lseek(fh, off, org)
#define g_filelength(fh) filelength(fh)
#define g_chsize(fh, size) chsize(fh, size)
#define g_fsopen(fn, of, sh) fsopen(fn, of, sh)
#define g_fdopen(fp, of) fdopen(fp, of)
#define g_fileno(fp) fileno(fp)
#endif
#define g_lock(fh, off, len) lock(fh, off, len)
#define g_unlock(fh, off, len) unlock(fh, off, len)
#define g_fclose(fp) fclose(fp)
#define g_fread(buf, rsz, cnt, fp) fread(buf, rsz, cnt, fp)
#define g_fwrite(buf, rsz, cnt, fp) fwrite(buf, rsz, cnt, fp)
#define g_fgetc(fp) fgetc(fp)
#define g_fputc(c, fp) fputc(c, fp)
#define g_fgets(str, cnt, fp) fgets(str, cnt, fp)
#define g_fputs(str, fp) fputs(str, fp)
#define g_fflush(fp) fflush(fp)
#define g_ftell(fp) ftell(fp)
// ------------------------------------------------------------------
gfile::gfile() {
gfile::gfile()
{
fh = -1;
fp = NULL;
status = EBADF;
@ -42,8 +87,8 @@ gfile::gfile() {
// ------------------------------------------------------------------
gfile::gfile(int __fh) {
gfile::gfile(int __fh)
{
fh = __fh;
fp = NULL;
status = 0;
@ -52,8 +97,8 @@ gfile::gfile(int __fh) {
// ------------------------------------------------------------------
gfile::gfile(FILE* __fp) {
gfile::gfile(FILE* __fp)
{
fh = -1;
fp = __fp;
status = 0;
@ -62,51 +107,42 @@ gfile::gfile(FILE* __fp) {
// ------------------------------------------------------------------
gfile::gfile(const char* __path, int __access, int __shflag, int __mode) {
open(__path, __access, __shflag, __mode);
}
// ------------------------------------------------------------------
gfile::gfile(const char* __path, const char* __mode, int __shflag) {
fopen(__path, __mode, __shflag);
}
// ------------------------------------------------------------------
gfile::~gfile() {
if(fp != NULL)
fclose();
if(fh != -1)
close();
}
// ------------------------------------------------------------------
int gfile::okay() {
return !status;
gfile::gfile(const char* __path, int __access, int __shflag, int __mode)
{
fh = -1;
fp = NULL;
Open(__path, __access, __shflag, __mode);
}
// ------------------------------------------------------------------
bool gfile::isopen() {
gfile::gfile(const char* __path, const char* __mode, int __shflag)
{
fh = -1;
fp = NULL;
Fopen(__path, __mode, __shflag);
}
if((fh != -1) or (fp != NULL))
return true;
// ------------------------------------------------------------------
gfile::~gfile()
{
if (fp != NULL) Fclose();
if (fh != -1) Close();
}
// ------------------------------------------------------------------
bool gfile::isopen()
{
if ((fh != -1) or (fp != NULL)) return true;
return false;
}
// ------------------------------------------------------------------
int gfile::setfh(int __fh) {
int gfile::setfh(int __fh)
{
fh = __fh;
status = 0;
return fh;
@ -114,8 +150,8 @@ int gfile::setfh(int __fh) {
// ------------------------------------------------------------------
FILE* gfile::setfp(FILE* __fp) {
FILE* gfile::setfp(FILE* __fp)
{
fp = __fp;
status = 0;
return fp;
@ -123,31 +159,35 @@ FILE* gfile::setfp(FILE* __fp) {
// ------------------------------------------------------------------
int gfile::open(const char* __path, int __access, int __shflag, int __mode) {
fh = ::sopen(__path, __access, __shflag, __mode);
int gfile::Open(const char* __path, int __access, int __shflag, int __mode)
{
#if defined(_tsopen_s)
status = _tsopen_s(&fh, __path, __access, __shflag, __mode);
return fh;
#else
fh = g_sopen(__path, __access, __shflag, __mode);
status = (fh == -1) ? errno : 0;
return fh;
#endif
}
// ------------------------------------------------------------------
int gfile::open(const char* __path, int __access, char* __fmode, int __shflag, int __mode) {
open(__path, __access, __shflag, __mode);
fdopen(__fmode);
int gfile::Open(const char* __path, int __access, const char* __fmode, int __shflag, int __mode)
{
Open(__path, __access, __shflag, __mode);
Fdopen(__fmode);
return fh;
}
// ------------------------------------------------------------------
int gfile::close() {
int gfile::Close()
{
if (fp) return Fclose();
if(fp)
return fclose();
int _ret = ::close(fh);
int _ret = g_close(fh);
status = _ret ? errno : 0;
fh = -1;
return _ret;
@ -155,223 +195,214 @@ int gfile::close() {
// ------------------------------------------------------------------
int gfile::read(void* __ptr, size_t __len) {
int _ret = ::read(fh, __ptr, (unsigned)__len);
int gfile::Read(void* __ptr, size_t __len)
{
int _ret = g_read(fh, __ptr, unsigned(__len));
status = (_ret == -1) ? errno : 0;
return _ret;
}
// ------------------------------------------------------------------
int gfile::write(void* __ptr, size_t __len) {
int _ret = ::write(fh, __ptr, (unsigned)__len);
int gfile::Write(void* __ptr, size_t __len)
{
int _ret = g_write(fh, __ptr, unsigned(__len));
status = (_ret == -1) ? errno : 0;
return _ret;
}
// ------------------------------------------------------------------
long gfile::tell() {
long _ret = ::tell(fh);
long gfile::Tell()
{
long _ret = g_tell(fh);
status = (_ret == -1) ? errno : 0;
return _ret;
}
// ------------------------------------------------------------------
long gfile::lseek(long __offset, int __direction) {
long _ret = ::lseek(fh, __offset, __direction);
long gfile::Lseek(long __offset, int __direction)
{
long _ret = g_lseek(fh, __offset, __direction);
status = (_ret == -1) ? errno : 0;
return _ret;
}
// ------------------------------------------------------------------
long gfile::filelength() {
long _ret = ::filelength(fh);
long gfile::FileLength()
{
long _ret = g_filelength(fh);
status = (_ret == -1) ? errno : 0;
return _ret;
}
// ------------------------------------------------------------------
int gfile::chsize(long __size) {
int _ret = ::chsize(fh, __size);
int gfile::ChSize(long __size)
{
int _ret = g_chsize(fh, __size);
status = _ret ? errno : 0;
return _ret;
}
// ------------------------------------------------------------------
int gfile::lock(long __offset, long __len) {
int _ret = ::lock(fh, __offset, __len);
int gfile::Lock(long __offset, long __len)
{
int _ret = g_lock(fh, __offset, __len);
status = _ret ? errno : 0;
return _ret;
}
// ------------------------------------------------------------------
int gfile::unlock(long __offset, long __len) {
int _ret = ::unlock(fh, __offset, __len);
int gfile::Unlock(long __offset, long __len)
{
int _ret = g_unlock(fh, __offset, __len);
status = _ret ? errno : 0;
return _ret;
}
// ------------------------------------------------------------------
int gfile::getftime(dword* __ftime) {
int gfile::GetFTime(time32_t *__ftime)
{
struct stat s;
if(fp)
fflush();
int rv = fstat (fh, &s);
if (fp) Fflush();
int rv = fstat(fh, &s);
status = (rv) ? errno : 0;
if(rv == 0)
*__ftime = gfixstattime(s.st_mtime);
else
__ftime = 0;
if (rv == 0) *__ftime = gfixstattime(time32_t(s.st_mtime));
else __ftime = 0;
return rv;
}
// ------------------------------------------------------------------
FILE* gfile::fopen(const std::string& __path, const char* __mode, int __shflag) {
return fopen(__path.c_str(), __mode, __shflag);
}
// ------------------------------------------------------------------
FILE* gfile::fopen(const char* __path, const char* __mode, int __shflag) {
fp = ::fsopen(__path, __mode, __shflag);
FILE* gfile::Fopen(const char* __path, const char* __mode, int __shflag)
{
fp = g_fsopen(__path, __mode, __shflag);
status = (fp == NULL) ? errno : 0;
if(fp)
fh = fileno(fp);
if (fp) fh = g_fileno(fp);
return fp;
}
// ------------------------------------------------------------------
FILE* gfile::fdopen(char* __mode) {
fp = ::fdopen(fh, __mode);
FILE* gfile::Fdopen(const char* __mode)
{
fp = g_fdopen(fh, __mode);
status = fp ? 0 : errno;
if(fp)
fh = fileno(fp);
if (fp) fh = g_fileno(fp);
return fp;
}
// ------------------------------------------------------------------
int gfile::fclose() {
int gfile::Fclose()
{
int _ret = 0;
if(fp)
_ret = ::fclose(fp);
if (fp) _ret = g_fclose(fp);
status = _ret ? errno : 0;
fp = NULL;
fh = -1;
fp = NULL; fh = -1;
return _ret;
}
// ------------------------------------------------------------------
size_t gfile::fread(void* __ptr, size_t __size, size_t __items) {
size_t _ret = ::fread(__ptr, __size, __items, fp);
size_t gfile::Fread(void* __ptr, size_t __size, size_t __items)
{
size_t _ret = g_fread(__ptr, __size, __items, fp);
status = ferror_() ? errno : 0;
return _ret;
}
// ------------------------------------------------------------------
size_t gfile::fwrite(const void* __ptr, size_t __size, size_t __items) {
size_t _ret = ::fwrite(__ptr, __size, __items, fp);
size_t gfile::Fwrite(const void* __ptr, size_t __size, size_t __items)
{
size_t _ret = g_fwrite(__ptr, __size, __items, fp);
status = (_ret < __items) ? errno : 0;
return _ret;
}
// ------------------------------------------------------------------
int gfile::fgetc() {
int gfile::Fgetc()
{
int _ret = g_fgetc(fp);
status = ferror_() ? errno : 0;
return _ret;
}
int _ret = ::fgetc(fp);
// ------------------------------------------------------------------
int gfile::Fputc(int __ch)
{
int _ret = g_fputc(__ch, fp);
status = ferror_() ? errno : 0;
return _ret;
}
// ------------------------------------------------------------------
int gfile::fputc(int __ch) {
int _ret = ::fputc(__ch, fp);
status = ferror_() ? errno : 0;
return _ret;
}
// ------------------------------------------------------------------
char* gfile::fgets(char* __str, size_t __len) {
char* _ret = ::fgets(__str, __len, fp);
char* gfile::Fgets(char* __str, size_t __len)
{
char* _ret = g_fgets(__str, int(__len), fp);
status = (_ret == NULL) ? errno : 0;
return _ret;
}
// ------------------------------------------------------------------
int gfile::fputs(const char* __str) {
int _ret = ::fputs(__str, fp);
int gfile::Fputs(const char* __str)
{
int _ret = g_fputs(__str, fp);
status = (_ret == EOF) ? errno : 0;
return _ret;
}
// ------------------------------------------------------------------
int gfile::printf(const char* __format, ...) {
int gfile::Printf(const char* __format, ...)
{
va_list _argptr;
va_start(_argptr, __format);
int _outcount = ::vfprintf(fp, __format, _argptr);
int _outcount = vfprintf(fp, __format, _argptr);
va_end(_argptr);
return _outcount;
}
// ------------------------------------------------------------------
int gfile::fflush() {
int _ret = ::fflush(fp);
int gfile::Fflush()
{
int _ret = g_fflush(fp);
status = _ret ? errno : 0;
return _ret;
}
// ------------------------------------------------------------------
long gfile::ftell() {
long _ret = ::ftell(fp);
long gfile::Ftell()
{
long _ret = g_ftell(fp);
status = (_ret == -1) ? errno : 0;
return _ret;
}
// ------------------------------------------------------------------
int gfile::fseek(long __offset, int __direction) {
int gfile::Fseek(long __offset, int __direction)
{
int _ret = ::fseek(fp, __offset, __direction);
status = _ret ? errno : 0;
return _ret;
@ -379,31 +410,12 @@ int gfile::fseek(long __offset, int __direction) {
// ------------------------------------------------------------------
int gfile::setvbuf(char* __buf, int __type, size_t __size) {
int gfile::SetvBuf(char* __buf, int __type, size_t __size)
{
int _ret = ::setvbuf(fp, __buf, __type, __size);
status = _ret ? errno : 0;
return _ret;
}
// ------------------------------------------------------------------
#ifdef __GOLDWARE_HAS_BOOL
gfile& gfile::operator>> (bool& i) { fread(&i, sizeof(bool)); return *this; }
#endif
gfile& gfile::operator>> (uint8_t& i) { fread(&i, sizeof(uint8_t)); return *this; }
gfile& gfile::operator>> (uint16_t& i) { fread(&i, sizeof(uint16_t)); return *this; }
gfile& gfile::operator>> (uint32_t& i) { fread(&i, sizeof(uint32_t)); return *this; }
gfile& gfile::operator>> (unsigned long& i) { fread(&i, sizeof(unsigned long)); return *this; }
#ifdef __GOLDWARE_HAS_BOOL
gfile& gfile::operator<< (bool o) { fwrite(&o, sizeof(o)); return *this; }
#endif
gfile& gfile::operator<< (uint8_t o) { fwrite(&o, sizeof(o)); return *this; }
gfile& gfile::operator<< (uint16_t o) { fwrite(&o, sizeof(o)); return *this; }
gfile& gfile::operator<< (uint32_t o) { fwrite(&o, sizeof(o)); return *this; }
gfile& gfile::operator<< (unsigned long o) { fwrite(&o, sizeof(o)); return *this; }
// ------------------------------------------------------------------

View File

@ -43,8 +43,8 @@
// ------------------------------------------------------------------
// Stream/Unix-style file I/O class
class gfile {
class gfile
{
public:
// ----------------------------------------------------------------
@ -63,8 +63,9 @@ public:
// --------------------------------------------------------------
// Handy utility functions
int okay(); // Returns non-zero if no errors were detected
int okay() { return (0 == status); }
bool isopen(); // true if the file is open
operator bool() { return isopen(); }
// --------------------------------------------------------------
@ -78,8 +79,6 @@ public:
~gfile(); // Destructor (closes file)
operator bool() { return isopen(); }
// --------------------------------------------------------------
// Set file handle or stream pointer
@ -91,73 +90,73 @@ public:
// --------------------------------------------------------------
// UNIX-style raw I/O
int open (const char* __path, int __access, int __shflag=SH_DENYNO, int __mode=S_IREAD|S_IWRITE);
int open (const char* __path, int __access, char* __fmode, int __shflag=SH_DENYNO, int __mode=S_IREAD|S_IWRITE);
int close ();
int Open (const char* __path, int __access, int __shflag=SH_DENYNO, int __mode=S_IREAD|S_IWRITE);
int Open (const char* __path, int __access, const char* __fmode, int __shflag=SH_DENYNO, int __mode=S_IREAD|S_IWRITE);
int Close ();
int read (void* __ptr, size_t __len);
int write (void* __ptr, size_t __len);
int Read (void* __ptr, size_t __len);
int Write (void* __ptr, size_t __len);
long tell ();
long lseek (long __offset, int __direction);
long lseek (long __record, long __recordsize, int __direction);
long lseekset (long __record, long __recordsize=1);
long Tell ();
long Lseek (long __offset, int __direction);
long Lseek (long __record, long __recordsize, int __direction) { return Lseek(__record*__recordsize, __direction); }
long LseekSet (long __record, long __recordsize = 1) { return Lseek(__record*__recordsize, SEEK_SET); }
long filelength ();
long FileLength ();
int chsize (long __size);
int ChSize (long __size);
int lock (long __offset, long __len);
int unlock (long __offset, long __len);
int Lock (long __offset, long __len);
int Unlock (long __offset, long __len);
int getftime (dword* __ftime);
int GetFTime (dword* __ftime);
// --------------------------------------------------------------
// ANSI-style streaming buffered I/O
FILE* fopen (const char* __path, const char* __mode, int __shflag=SH_DENYNO);
FILE* fopen (const std::string& __path, const char* __mode, int __shflag=SH_DENYNO);
FILE* fdopen (char* __mode);
int fclose ();
FILE* Fopen (const char* __path, const char* __mode, int __shflag=SH_DENYNO);
FILE* Fopen (const std::string& __path, const char* __mode, int __shflag=SH_DENYNO) { return Fopen(__path.c_str(), __mode, __shflag); }
FILE* Fdopen (const char* __mode);
int Fclose ();
size_t fread (void* __ptr, size_t __size, size_t __items=1);
size_t fwrite (const void* __ptr, size_t __size, size_t __items=1);
size_t Fread (void* __ptr, size_t __size, size_t __items=1);
size_t Fwrite (const void* __ptr, size_t __size, size_t __items=1);
int fgetc ();
int fputc (int __ch);
int Fgetc ();
int Fputc (int __ch);
char* fgets (char* __str, size_t __len);
int fputs (const char* __str);
char* Fgets (char* __str, size_t __len);
int Fputs (const char* __str);
int printf (const char* __format, ...) __attribute__ ((format (printf, 2, 3)));
int Printf (const char* __format, ...) __attribute__ ((format (printf, 2, 3)));
int fflush ();
int Fflush ();
long ftell ();
int fseek (long __offset, int __direction);
int fseek (long __record, long __recordsize, int __direction);
int fseekset(long __record, long __recordsize=1);
long Ftell ();
int Fseek (long __offset, int __direction);
int Fseek (long __record, long __recordsize, int __direction) { return Fseek(__record*__recordsize, __direction); }
int FseekSet(long __record, long __recordsize = 1) { return Fseek(__record*__recordsize, SEEK_SET); }
void rewind ();
void Rewind () { rewind(fp); }
int setvbuf (char* __buf=NULL, int __type=_IOFBF, size_t __size=8192);
int setvbuf (size_t __size) { return setvbuf(NULL, _IOFBF, __size); }
int SetvBuf (char* __buf=NULL, int __type=_IOFBF, size_t __size=8192);
int SetvBuf (size_t __size) { return SetvBuf(NULL, _IOFBF, __size); }
int feof_ ();
int ferror_ ();
int feof_ () { return feof(fp); }
int ferror_ () { return ferror(fp); }
// ----------------------------------------------------------------
#ifdef __GOLDWARE_HAS_BOOL
gfile& operator>> (bool& i);
gfile& operator>> (bool& i) { Fread(&i, sizeof(bool)); return *this; }
#endif
gfile& operator>> (uint8_t& i);
gfile& operator>> (uint16_t& i);
gfile& operator>> (uint32_t& i);
gfile& operator>> (uint8_t& i) { Fread(&i, sizeof(uint8_t)); return *this; }
gfile& operator>> (uint16_t& i) { Fread(&i, sizeof(uint16_t)); return *this; }
gfile& operator>> (uint32_t& i) { Fread(&i, sizeof(uint32_t)); return *this; }
#if !defined(__CYGWIN__)
gfile& operator>> (unsigned long& i);
gfile& operator>> (unsigned long& i) { Fread(&i, sizeof(unsigned long)); return *this; }
#endif
gfile& operator>> (char& i) { return operator>>((uint8_t&)i); }
@ -171,13 +170,13 @@ public:
#endif
#ifdef __GOLDWARE_HAS_BOOL
gfile& operator<< (bool o);
gfile& operator<< (bool o) { Fwrite(&o, sizeof(o)); return *this; }
#endif
gfile& operator<< (uint8_t o);
gfile& operator<< (uint16_t o);
gfile& operator<< (uint32_t o);
gfile& operator<< (uint8_t o) { Fwrite(&o, sizeof(o)); return *this; }
gfile& operator<< (uint16_t o) { Fwrite(&o, sizeof(o)); return *this; }
gfile& operator<< (uint32_t o) { Fwrite(&o, sizeof(o)); return *this; }
#if !defined(__CYGWIN__)
gfile& operator<< (unsigned long o);
gfile& operator<< (unsigned long o) { Fwrite(&o, sizeof(o)); return *this; }
#endif
gfile& operator<< (char o) { return operator<<((uint8_t )o); }
@ -189,70 +188,9 @@ public:
#if !defined(__CYGWIN__)
gfile& operator<< (long o) { return operator<<((unsigned long)o); }
#endif
};
// ------------------------------------------------------------------
// Inline implementations
// ------------------------------------------------------------------
inline long gfile::lseek(long __record, long __recordsize, int __direction) {
return lseek(__record*__recordsize, __direction);
}
// ------------------------------------------------------------------
inline long gfile::lseekset(long __record, long __recordsize) {
return lseek(__record*__recordsize, SEEK_SET);
}
// ------------------------------------------------------------------
inline int gfile::ferror_() {
return ferror(fp);
}
// ------------------------------------------------------------------
inline int gfile::fseek(long __record, long __recordsize, int __direction) {
return fseek(__record*__recordsize, __direction);
}
// ------------------------------------------------------------------
inline int gfile::fseekset(long __record, long __recordsize) {
return fseek(__record*__recordsize, SEEK_SET);
}
// ------------------------------------------------------------------
inline void gfile::rewind() {
::rewind(fp);
}
// ------------------------------------------------------------------
inline int gfile::feof_() {
return feof(fp);
}
// ------------------------------------------------------------------
#endif

View File

@ -159,10 +159,10 @@ inline bool fexist(const TCHAR *filename) { return *filename ? (0 == (_taccess(f
#endif
inline bool fexist(const std::string& filename) { return fexist(filename.c_str()); }
dword gfixstattime(time32_t st_time);
time32_t gfixstattime(time32_t st_time);
dword GetFiletime(const char* file);
inline dword GetFiletime(const std::string& file) { return GetFiletime(file.c_str()); }
time32_t GetFiletime(const char* file);
inline time32_t GetFiletime(const std::string& file) { return GetFiletime(file.c_str()); }
inline long FiletimeCmp(const char* file1, const char* file2) { return long(GetFiletime(file1) - GetFiletime(file2)); }
inline long FiletimeCmp(const std::string& file1, const std::string& file2) { return FiletimeCmp(file1.c_str(), file2.c_str()); }
@ -184,7 +184,7 @@ char* StripBackslash(char* p);
char* PathCopy(char* dst, const char* src);
void PathCopy(std::string& dst, const char* src);
void TouchFile(const char* __filename);
void TouchFile(const TCHAR *filename);
int TestLockPath(const char* __path);
void WipeFile(const char* file, int options);

View File

@ -28,6 +28,8 @@
#include <gtimall.h>
#include <gstrall.h>
#include <gfilutil.h>
#include <gfile.h>
#if defined(__MINGW32__) || defined(_MSC_VER)
#include <sys/utime.h>
#else
@ -96,7 +98,7 @@ long GetFilesize(const char* file) {
// ------------------------------------------------------------------
// Convert time returned with stat to FFTime
dword gfixstattime(time32_t st_time)
time32_t gfixstattime(time32_t st_time)
{
#if (defined(__MINGW32__) && !defined(__MSVCRT__)) || defined(__CYGWIN__)
struct tm f; ggmtime(&f, &st_time);
@ -138,7 +140,7 @@ dword gfixstattime(time32_t st_time)
// ------------------------------------------------------------------
// Get timestamp of file
dword GetFiletime(const char* file) {
time32_t GetFiletime(const char* file) {
struct stat st;
if(stat(file, &st) == 0) {
@ -301,11 +303,14 @@ FILE *fsopen(const char *path, const char *type, int shflag) {
// ------------------------------------------------------------------
void TouchFile(const char* filename) {
if(not fexist(filename))
close(open(filename, O_WRONLY|O_CREAT|O_TRUNC, S_STDRW));
else {
void TouchFile(const TCHAR *filename)
{
if (not fexist(filename))
{
gfile fh(filename, O_WRONLY|O_CREAT|O_TRUNC);
}
else
{
struct utimbuf ut;
ut.actime = ut.modtime = time(NULL);
utime(filename, &ut);

View File

@ -62,17 +62,18 @@ glog::~glog() {
// ------------------------------------------------------------------
int glog::open(const char* filename, const char* name, const char* shortname, int type, uint bufsz, int shflag) {
fp.fopen(filename, "at", shflag);
if(fp.status) {
int glog::open(const char* filename, const char* name, const char* shortname, int type, uint bufsz, int shflag)
{
fp.Fopen(filename, "at", shflag);
if (fp.status)
{
status = fp.status;
return status;
}
count++;
bufsize = bufsz;
fp.setvbuf(NULL, bufsize ? _IOFBF : _IONBF, bufsize);
fp.SetvBuf(NULL, bufsize ? _IOFBF : _IONBF, bufsize);
init(name, shortname, type);
@ -82,9 +83,9 @@ int glog::open(const char* filename, const char* name, const char* shortname, in
// ------------------------------------------------------------------
void glog::close() {
fp.fclose();
void glog::close()
{
fp.Fclose();
count--;
}
@ -138,8 +139,8 @@ void glog::printf(const char* format, ...) {
break;
}
if(fp.isopen())
fp.printf("%s", logbuf);
if (fp.isopen())
fp.Printf("%s", logbuf);
}
*buf = NUL;
@ -172,9 +173,10 @@ void glog::printf(const char* format, ...) {
sprintf(logbuf, "%s %s", strftimei(timebuf, 20, "%m/%d/%y %H:%M", &time_now), buf+2);
break;
}
if(fp.isopen()) {
fp.printf("%s\n", logbuf);
fp.fflush();
if (fp.isopen())
{
fp.Printf("%s\n", logbuf);
fp.Fflush();
}
if(storelines != -1) {
if(storelines < GLOG_STORELINES)

View File

@ -293,30 +293,29 @@ uint GTag::ToReln(uint32_t __tagn) {
// ------------------------------------------------------------------
void GTag::Load(gfile& fp) {
void GTag::Load(gfile& fp)
{
dword val;
fp.fread(&val, sizeof(dword));
fp.Fread(&val, sizeof(dword));
count = (uint) val;
if(count) {
if (count)
{
Resize(count);
fp.fread(tag, sizeof(uint32_t), count);
fp.Fread(tag, sizeof(uint32_t), count);
}
}
// ------------------------------------------------------------------
void GTag::Save(gfile& fp) {
void GTag::Save(gfile& fp)
{
dword val = (dword) count;
fp.Fwrite(&val, sizeof(dword));
dword val;
val = (dword) count;
fp.fwrite(&val, sizeof(dword));
if(tag and count)
fp.fwrite(tag, sizeof(uint32_t), count);
if (tag and count)
fp.Fwrite(tag, sizeof(uint32_t), count);
}

View File

@ -131,20 +131,22 @@ static int find_cat_name(const char* cat) {
int found=NO;
// Reset file pointer.
whelp.fp->fseekset(whelp.offset);
whelp.fp->FseekSet(whelp.offset);
// Check for "*I" marker.
whelp.fp->fgets(buf, BUFSIZE);
if(strnieql(buf,"*I",2)) {
whelp.fp->Fgets(buf, BUFSIZE);
if (strnieql(buf,"*I",2))
{
// Search index for help category entry. If found,
// then advance file pointer to specified position.
for(;;) {
whelp.fp->fread(&recd,sizeof(Hlpr));
for(;;)
{
whelp.fp->Fread(&recd,sizeof(Hlpr));
if(recd.offset==-1L)
break;
if(strieql(recd.category,cat)) {
whelp.fp->fseekset(whelp.offset + recd.offset);
if (strieql(recd.category,cat))
{
whelp.fp->FseekSet(whelp.offset + recd.offset);
found=YES;
break;
}
@ -166,20 +168,22 @@ static int find_cat_number(int cat) {
int found=NO;
// Reset file pointer.
whelp.fp->fseekset(whelp.offset);
whelp.fp->FseekSet(whelp.offset);
// Check for "*I" marker.
whelp.fp->fgets(buf, BUFSIZE);
if(strnieql(buf,"*I",2)) {
whelp.fp->Fgets(buf, BUFSIZE);
if (strnieql(buf,"*I",2))
{
// Search index for help category entry. If found,
// then advance file pointer to specified position.
for(;;) {
whelp.fp->fread(&recd,sizeof(Hlpr));
if(recd.offset==-1L)
for (;;)
{
whelp.fp->Fread(&recd,sizeof(Hlpr));
if (recd.offset==-1L)
break;
if(recd.help==cat) {
whelp.fp->fseekset(whelp.offset + recd.offset);
if (recd.help==cat)
{
whelp.fp->FseekSet(whelp.offset + recd.offset);
found=YES;
break;
}
@ -205,18 +209,21 @@ static int find_page(long startpos, int pageofs) {
int lines = whelp.srow;
lastpagepos = currpos = startpos;
whelp.fp->fseekset(startpos);
whelp.fp->FseekSet(startpos);
while(currpage < pageofs) {
whelp.fp->fgets(buf, BUFSIZE);
if(not whelp.fp->okay()) {
whelp.fp->fseekset(lastpagepos);
while (currpage < pageofs)
{
whelp.fp->Fgets(buf, BUFSIZE);
if (not whelp.fp->okay())
{
whelp.fp->FseekSet(lastpagepos);
break;
}
lines++;
currpos=whelp.fp->ftell();
if(strnieql(buf, "*E", 2)) {
whelp.fp->fseekset(lastpagepos);
currpos=whelp.fp->Ftell();
if (strnieql(buf, "*E", 2))
{
whelp.fp->FseekSet(lastpagepos);
break;
}
if(strnieql(buf, "*P", 2)) {
@ -252,7 +259,7 @@ static void disp_cat() {
page = wrow = wcol = end = menuopen = itemopen = 0;
// save current info
startpos = whelp.fp->ftell();
startpos = whelp.fp->Ftell();
curr = gwin.cmenu;
// set text attribute
@ -261,7 +268,7 @@ static void disp_cat() {
for(;;) {
// read next line from help file into buffer
whelp.fp->fgets(buf,BUFSIZE);
whelp.fp->Fgets(buf,BUFSIZE);
strtrim(buf);
// if end-of-file or "*E" was found, assume end-of-category
@ -326,10 +333,10 @@ static void disp_cat() {
// try to find selected category, if found set
// file pointer to it, otherwise reset file
// pointer back to previous help category
if(find_cat_name(catarray[i]))
startpos=whelp.fp->ftell();
if (find_cat_name(catarray[i]))
startpos = whelp.fp->Ftell();
else
whelp.fp->fseekset(startpos);
whelp.fp->FseekSet(startpos);
// clear help window and set
// position to upper left corner
@ -501,11 +508,13 @@ static void help_handler() {
}
else {
if(not whelp.fp) {
if (not whelp.fp)
{
whelpclosefile = true;
whelp.fp = new gfile; throw_new(whelp.fp);
whelp.fp->fopen(whelp.file,"rb");
if(not whelp.fp->isopen()) {
whelp.fp->Fopen(whelp.file,"rb");
if (!whelp.fp->isopen())
{
wtextattr(whelp.textattr);
wputs("\nHelp file not found: ");
wputs(whelp.file);
@ -514,9 +523,9 @@ static void help_handler() {
}
}
if(whelp.fp->isopen()) {
whelp.fp->fseekset(whelp.offset);
if (whelp.fp->isopen())
{
whelp.fp->FseekSet(whelp.offset);
// find help category in help file
found=find_cat_number(cat);
@ -526,8 +535,9 @@ static void help_handler() {
disp_cat();
}
if(whelpclosefile) {
whelp.fp->fclose();
if (whelpclosefile)
{
whelp.fp->Fclose();
delete whelp.fp;
whelp.fp = NULL;
}

View File

@ -42,30 +42,32 @@ extern _help_t whelp;
void whelpcompile(const char* helpfile, long& offset) {
gfile ifp(helpfile, "rb");
if(ifp) {
ifp.setvbuf();
if (ifp.isopen())
{
ifp.SetvBuf();
int count = 0;
char buf[1024];
while(ifp.fgets(buf, sizeof(buf))) {
while (ifp.Fgets(buf, sizeof(buf)))
{
if(strnieql(buf, "*B ", 3))
count++;
}
ifp.rewind();
ifp.Rewind();
Hlpr* helpindex = (Hlpr*)throw_xcalloc(count+2, sizeof(Hlpr));
long relative_offset = 0;
whelp.fp->fputs("*I\r\n");
whelp.fp->fwrite(helpindex, count+1, sizeof(Hlpr));
whelp.fp->fputs("\r\n\r\n");
whelp.fp->Fputs("*I\r\n");
whelp.fp->Fwrite(helpindex, count+1, sizeof(Hlpr));
whelp.fp->Fputs("\r\n\r\n");
relative_offset += 4 + ((count+1)*sizeof(Hlpr)) + 4;
int counter = 0;
bool comment = true;
while(ifp.fgets(buf, sizeof(buf))) {
while (ifp.Fgets(buf, sizeof(buf)))
{
if(strnieql(buf, "*B ", 3)) {
comment = false;
helpindex[counter].help = atow(buf+3);
@ -74,8 +76,9 @@ void whelpcompile(const char* helpfile, long& offset) {
helpindex[counter].offset = relative_offset + strlen(buf);
counter++;
}
if(not comment) {
whelp.fp->fputs(buf);
if (not comment)
{
whelp.fp->Fputs(buf);
relative_offset += strlen(buf);
}
if(strnieql(buf, "*E", 2))
@ -83,15 +86,15 @@ void whelpcompile(const char* helpfile, long& offset) {
}
helpindex[counter].offset = -1L;
whelp.fp->fseekset(offset);
whelp.fp->fputs("*I\r\n");
whelp.fp->fwrite(helpindex, count+1, sizeof(Hlpr));
whelp.fp->FseekSet(offset);
whelp.fp->Fputs("*I\r\n");
whelp.fp->Fwrite(helpindex, count+1, sizeof(Hlpr));
offset += relative_offset;
whelp.fp->fseekset(offset);
whelp.fp->FseekSet(offset);
throw_xfree(helpindex);
ifp.fclose();
ifp.Fclose();
}
}

View File

@ -1231,8 +1231,9 @@ int wmenuget() {
// separate ASCII code from keypress code, if ASCII
// code is zero, then it must be an extended key
ch=(char)xch;
if(!ch and gmnudropthrough) {
ch = char(xch & 0xFF);
if (!ch and gmnudropthrough)
{
if((xch != Key_PgDn) and (xch != Key_PgUp))
kbput(xch);
goto ESCAPE_KEY;

View File

@ -678,7 +678,7 @@ int wpickstr(int srow, int scol, int erow, int ecol, int btype, vattr bordattr,
// position for the item that begins with the same ASCII
// character as the keypress. If not found after current
// position, search from the beginning for a match
ch = (char)g_toupper((char)xch);
ch = (char)g_toupper(char(xch & 0xFF));
if(!ch)
break;
for(i=r.curr+1; i<r.numelems; i++)

View File

@ -66,8 +66,7 @@ void gareafile::ReadInterMail(char* tag) {
const char* _file = AddPath(_path, "fd.sys");
gfile fp;
fp.fopen(_file, "rb");
gfile fp(_file, "rb");
if (fp.isopen())
{
_ctl* ctl = (_ctl*)throw_calloc(1, sizeof(_ctl));
@ -75,11 +74,11 @@ void gareafile::ReadInterMail(char* tag) {
if (not quiet)
STD_PRINTNL("* Reading " << _file);
fp.fread(ctl, sizeof(_ctl));
fp.Fread(ctl, sizeof(_ctl));
if(not memcmp(ctl->fingerprint, "JoHo", 5) and (ctl->sysrev == IM_THISREV)) {
fp.fclose();
if (not memcmp(ctl->fingerprint, "JoHo", 5) and (ctl->sysrev == IM_THISREV))
{
fp.Fclose();
CfgHudsonpath(ctl->e.qbase);
@ -136,7 +135,7 @@ void gareafile::ReadInterMail(char* tag) {
if(fexist(_file)) {
_file = AddPath(ctl->s.systempath, "imfolder.cfg");
fp.fopen(_file, "rb");
fp.Fopen(_file, "rb");
if (fp.isopen())
{
if (not quiet)
@ -144,8 +143,8 @@ void gareafile::ReadInterMail(char* tag) {
FOLDER* _folder = (FOLDER*)throw_calloc(1, sizeof(FOLDER));
while(fp.fread(_folder, sizeof(FOLDER)) == 1) {
while (fp.Fread(_folder, sizeof(FOLDER)) == 1)
{
aa.reset();
switch(_folder->ftype) {
case F_MSG: aa.basetype = "OPUS"; break;
@ -174,13 +173,13 @@ void gareafile::ReadInterMail(char* tag) {
}
}
throw_free(_folder);
fp.fclose();
fp.Fclose();
}
}
else {
else
{
_file = AddPath(ctl->s.systempath, "folder.cfg");
fp.fopen(_file, "rb");
fp.Fopen(_file, "rb");
if (fp.isopen())
{
if (not quiet)
@ -188,7 +187,8 @@ void gareafile::ReadInterMail(char* tag) {
OLDFOLDER* _folder = (OLDFOLDER*)throw_calloc(1, sizeof(OLDFOLDER));
while(fp.fread(_folder, sizeof(OLDFOLDER)) == 1) {
while (fp.Fread(_folder, sizeof(OLDFOLDER)) == 1)
{
long _behave = _folder->behave;
if(not (DELETED & _behave)) {
@ -216,7 +216,7 @@ void gareafile::ReadInterMail(char* tag) {
}
}
throw_free(_folder);
fp.fclose();
fp.Fclose();
}
}
}

View File

@ -66,17 +66,16 @@ void gareafile::ReadLoraBBS(char* tag) {
if(*_path == NUL)
strcpy(_path, areapath);
gfile fp;
const char* _file = AddPath(_path, "config.dat");
fp.fopen(_file, "rb");
gfile fp(_file, "rb");
if (fp.isopen())
{
if (not quiet)
STD_PRINTNL("* Reading " << _file);
_configuration* cfg = (_configuration*)throw_calloc(1, sizeof(_configuration));
fp.fread(cfg, sizeof(_configuration));
fp.fclose();
fp.Fread(cfg, sizeof(_configuration));
fp.Fclose();
//CfgUsername(cfg->sysop);
@ -134,18 +133,18 @@ void gareafile::ReadLoraBBS(char* tag) {
}
_file = AddPath(_path, "sysmsg.dat");
fp.fopen(_file, "rb");
fp.Fopen(_file, "rb");
if (fp.isopen())
{
fp.setvbuf(NULL, _IOFBF, 8192);
fp.SetvBuf(NULL, _IOFBF, 8192);
if (not quiet)
STD_PRINTNL("* Reading " << _file);
_sysmsg* sysmsg = (_sysmsg*)throw_calloc(1, sizeof(_sysmsg));
while(fp.fread(sysmsg, sizeof(_sysmsg)) == 1) {
while (fp.Fread(sysmsg, sizeof(_sysmsg)) == 1)
{
if(sysmsg->passthrough)
continue;
@ -196,7 +195,7 @@ void gareafile::ReadLoraBBS(char* tag) {
AddNewArea(aa);
}
throw_free(sysmsg);
fp.fclose();
fp.Fclose();
}
throw_free(cfg);
}

View File

@ -84,9 +84,8 @@ void gareafile::ReadPCBoard(char* tag) {
CfgPcboardpath(_path);
gfile fp;
const char* _file = AddPath(_path, "pcboard.dat");
fp.fopen(_file, "rt");
gfile fp(_file, "rt");
if (fp.isopen())
{
if (not quiet)
@ -95,7 +94,8 @@ void gareafile::ReadPCBoard(char* tag) {
int _line = 0;
char _buf[256];
while(fp.fgets(_buf, sizeof(_buf))) {
while (fp.Fgets(_buf, sizeof(_buf)))
{
_line++;
switch(_line) {
case 28: // Location of User INDEX Files
@ -113,44 +113,45 @@ void gareafile::ReadPCBoard(char* tag) {
}
}
fp.fclose();
fp.Fclose();
if(*_fidopath) {
if (*_fidopath)
{
const char* _file = AddPath(_fidopath, "pcbfido.cfg");
fp.fopen(_file, "rb");
fp.Fopen(_file, "rb");
if (fp.isopen())
{
if (not quiet)
STD_PRINTNL("* Reading " << _file);
// Get configuration file version
fp.fread(&fido_version, 2);
fp.Fread(&fido_version, 2);
if(fido_version == 2) {
word numrecs = 0;
// Get areas
fp.fread(&numrecs, 2);
fp.Fread(&numrecs, 2);
numareas = numrecs;
areap = (PcbFidoArea*)throw_calloc(1+numrecs, sizeof(PcbFidoArea));
fp.fread(areap, sizeof(PcbFidoArea), numrecs);
fp.Fread(areap, sizeof(PcbFidoArea), numrecs);
// Skip archivers
fp.fseek(sizeof(PcbFidoArchivers), SEEK_CUR);
fp.Fseek(sizeof(PcbFidoArchivers), SEEK_CUR);
// Get directories
dirp = (PcbFidoDirectories*)throw_calloc(1, sizeof(PcbFidoDirectories));
fp.fread(dirp, sizeof(PcbFidoDirectories));
fp.Fread(dirp, sizeof(PcbFidoDirectories));
// Skip EMSI profile
fp.fseek(sizeof(PcbFidoEmsiData), SEEK_CUR);
fp.Fseek(sizeof(PcbFidoEmsiData), SEEK_CUR);
// Get akas
fp.fread(&numrecs, 2);
fp.Fread(&numrecs, 2);
akanumrecs = numrecs;
akap = (PcbFidoAddress*)throw_calloc(1+numrecs, sizeof(PcbFidoAddress));
fp.fread(akap, sizeof(PcbFidoAddress), numrecs);
fp.Fread(akap, sizeof(PcbFidoAddress), numrecs);
int akano = 0;
while(akano < numrecs) {
CfgAddress(akap[akano].nodestr);
@ -160,41 +161,43 @@ void gareafile::ReadPCBoard(char* tag) {
else if(fido_version == 3) {
dir3 = (PcbDirectories*)throw_calloc(1, sizeof(PcbDirectories));
fp.fread(dir3, sizeof(PcbDirectories));
fp.fclose();
fp.Fread(dir3, sizeof(PcbDirectories));
fp.Fclose();
_file = AddPath(_fidopath, "areas.dat");
fp.fopen(_file, "rb");
fp.Fopen(_file, "rb");
if (fp.isopen())
{
if (not quiet)
STD_PRINTNL("* Reading " << _file);
word cfgver = 0;
fp.fread(&cfgver, 2);
if(cfgver == 3) {
word numrecs = (word)(fp.filelength() / sizeof(PcbAreasDat));
fp.Fread(&cfgver, 2);
if (cfgver == 3)
{
word numrecs = (word)(fp.FileLength() / sizeof(PcbAreasDat));
area3 = (PcbAreasDat*)throw_calloc(1+numrecs, sizeof(PcbAreasDat));
fp.fread(area3, sizeof(PcbAreasDat), numrecs);
fp.Fread(area3, sizeof(PcbAreasDat), numrecs);
numareas = numrecs;
}
fp.fclose();
fp.Fclose();
}
_file = AddPath(_fidopath, "akas.dat");
fp.fopen(_file, "rb");
fp.Fopen(_file, "rb");
if (fp.isopen())
{
if (not quiet)
STD_PRINTNL("* Reading " << _file);
word cfgver = 0;
fp.fread(&cfgver, 2);
if(cfgver == 3) {
word numrecs = (word)(fp.filelength() / sizeof(PcbAkasDat));
fp.Fread(&cfgver, 2);
if (cfgver == 3)
{
word numrecs = (word)(fp.FileLength() / sizeof(PcbAkasDat));
akanumrecs = numrecs;
aka3 = (PcbAkasDat*)throw_calloc(1+numrecs, sizeof(PcbAkasDat));
fp.fread(aka3, sizeof(PcbAkasDat), numrecs);
fp.Fread(aka3, sizeof(PcbAkasDat), numrecs);
int akano = 0;
while(akano < numrecs) {
char abuf[40];
@ -202,28 +205,29 @@ void gareafile::ReadPCBoard(char* tag) {
akano++;
}
}
fp.fclose();
fp.Fclose();
}
_file = AddPath(_fidopath, "origins.dat");
fp.fopen(_file, "rb");
fp.Fopen(_file, "rb");
if (fp.isopen())
{
if (not quiet)
STD_PRINTNL("* Reading " << _file);
word cfgver = 0;
fp.fread(&cfgver, 2);
if(cfgver == 3) {
word numrecs = (word)(fp.filelength() / sizeof(PcbOriginsDat));
fp.Fread(&cfgver, 2);
if (cfgver == 3)
{
word numrecs = (word)(fp.FileLength() / sizeof(PcbOriginsDat));
origin3 = (PcbOriginsDat*)throw_calloc(1+numrecs, sizeof(PcbOriginsDat));
fp.fread(origin3, sizeof(PcbOriginsDat), numrecs);
fp.Fread(origin3, sizeof(PcbOriginsDat), numrecs);
}
fp.fclose();
fp.Fclose();
}
}
fp.fclose();
fp.Fclose();
}
Path netmailpath;
@ -255,7 +259,7 @@ void gareafile::ReadPCBoard(char* tag) {
}
_file = AddPath(_cnamespath, ".@@@");
fp.fopen(_file, "rb");
fp.Fopen(_file, "rb");
if (fp.isopen())
{
if (not quiet)
@ -263,21 +267,23 @@ void gareafile::ReadPCBoard(char* tag) {
gfile fp2;
_file = AddPath(_cnamespath, ".add");
fp2.fopen(_file, "rb");
fp2.Fopen(_file, "rb");
if (fp2.isopen())
{
if (not quiet)
STD_PRINTNL("* Reading " << _file);
word _recsize = 0;
fp.fread(&_recsize, 2);
fp.Fread(&_recsize, 2);
int confno = 0;
PcbConf* _cnames = (PcbConf*)throw_calloc(1, _recsize);
PcbAddConf* _cnamesadd = (PcbAddConf*)throw_calloc(1, sizeof(PcbAddConf));
while(fp.fread(_cnames, _recsize) == 1) {
fp2.fread(_cnamesadd, sizeof(PcbAddConf));
if(*_cnames->name and *_cnames->msgfile) {
while (fp.Fread(_cnames, _recsize) == 1)
{
fp2.Fread(_cnamesadd, sizeof(PcbAddConf));
if (*_cnames->name and *_cnames->msgfile)
{
aa.reset();
aa.basetype = "PCBOARD";
switch(_cnamesadd->conftype) {
@ -351,10 +357,10 @@ void gareafile::ReadPCBoard(char* tag) {
throw_free(_cnamesadd);
throw_free(_cnames);
fp2.fclose();
fp2.Fclose();
}
fp.fclose();
fp.Fclose();
}
}

View File

@ -80,16 +80,16 @@ void PcbInit(const char* path, int userno) {
*_cnamespath = NUL;
// Open PCBOARD.DAT
gfile fp;
const char* _file = AddPath(_path, "PCBOARD.DAT");
fp.fopen(_file, "rt", WideSharemode);
if(fp.isopen()) {
gfile fp(_file, "rt", WideSharemode);
if (fp.isopen())
{
// Get some paths/filenames
int _line = 0;
char _buf[256];
fp.setvbuf(NULL, _IOFBF, 8192);
while(fp.fgets(_buf, sizeof(_buf))) {
fp.SetvBuf(NULL, _IOFBF, 8192);
while (fp.Fgets(_buf, sizeof(_buf)))
{
_line++;
if(_line == 28)
strxcpy(pcbwide->usersidxpath, strbtrim(_buf), sizeof(Path));
@ -102,32 +102,34 @@ void PcbInit(const char* path, int userno) {
else if(_line == 208)
pcbwide->foreign = atoi(_buf);
}
fp.fclose();
fp.Fclose();
// Open CNAMES.@@@
_file = AddPath(_cnamespath, ".@@@");
fp.fopen(_file, "rb", WideSharemode);
fp.Fopen(_file, "rb", WideSharemode);
// Get board numbers for lastread indexing in the userfiles
word _recsize = 0;
fp.setvbuf(NULL, _IOFBF, 8192);
fp.fread(&_recsize, 2);
if(_recsize) {
fp.SetvBuf(NULL, _IOFBF, 8192);
fp.Fread(&_recsize, 2);
if (_recsize)
{
PcbConf* _cnames = (PcbConf*)throw_calloc(1, _recsize);
int _rec = 0;
pcbwide->numareas = (int)((fp.filelength()-2)/_recsize);
pcbwide->numareas = (int)((fp.FileLength()-2)/_recsize);
pcbwide->confbytelen = (pcbwide->numareas/8) + ((pcbwide->numareas%8) != 0 ? 1 : 0);
if(pcbwide->confbytelen < 5)
pcbwide->confbytelen = 5;
pcbwide->extconflen = pcbwide->confbytelen - 5;
pcbwide->lastread = (int32_t*)throw_calloc(pcbwide->numareas, sizeof(int32_t));
while(fp.fread(_cnames, _recsize) == 1) {
while (fp.Fread(_cnames, _recsize) == 1)
{
PcbAdjustArea((uint)_rec, _cnames->msgfile);
_rec++;
}
throw_free(_cnames);
}
fp.fclose();
fp.Fclose();
const char* _username = WideUsername[0];
pcbwide->user->fh = ::sopen(AddPath(_path, pcbwide->users), O_RDONLY|O_BINARY, WideSharemode, S_STDRD);