diff --git a/golded3/gcalst.cpp b/golded3/gcalst.cpp index 87732db..d82bbe0 100644 --- a/golded3/gcalst.cpp +++ b/golded3/gcalst.cpp @@ -184,8 +184,6 @@ void AreaList::WriteGoldLast() (*ap)->PMrk.Save(fp); } } - - fp.Fclose(); } } @@ -205,10 +203,7 @@ void AreaList::ReadGoldLast() fp.Fread(&GOLDLAST_VER, sizeof(word)); if (GOLDLAST_VER != CUR_GOLDLAST_VER) - { - fp.Fclose(); return; - } fp.Fread(AL.alistselections, sizeof(AL.alistselections)); @@ -246,8 +241,6 @@ void AreaList::ReadGoldLast() fp.Fseek(dw*sizeof(dword), SEEK_CUR); } } - - fp.Fclose(); } } @@ -255,18 +248,17 @@ void AreaList::ReadGoldLast() // ------------------------------------------------------------------ // Write all areas to GOLDAREA.INC in AREADEF format -void AreaList::WriteAreaDef(const char* file) { - +void AreaList::WriteAreaDef(const char* file) +{ int tmp; - FILE* fp; Path path; char groupid[10], echoid[sizeof(Echo)+2]; int maxechoid=0, maxdesc=0, maxgroupid=0, maxpath=0, maxaddr=0, maxattr=0; char desc[sizeof(Desc)+2], type[6], msgbase[9], addr[40], attr[150], origin[163]; - fp = fsopen(file, "wt", CFG->sharemode); - if(fp) { - + gfile fp(file, "wt", CFG->sharemode); + if (fp.isopen()) + { area_iterator aa; for(aa = idx.begin(); aa != idx.end(); aa++) { tmp = strlen((*aa)->echoid()); @@ -325,8 +317,9 @@ void AreaList::WriteAreaDef(const char* file) { sprintf(echoid, "\"%s\"", (*aa)->echoid()); else strcpy(echoid, (*aa)->echoid()); - if((*aa)->isseparator()) { - fprintf(fp, "AREASEP %-*s %-*s %*s %s\n", + if ((*aa)->isseparator()) + { + fp.Printf("AREASEP %-*s %-*s %*s %s\n", maxechoid, echoid, maxdesc, desc, maxgroupid, groupid, @@ -349,7 +342,7 @@ void AreaList::WriteAreaDef(const char* file) { sprintf(origin, " \"%.*s\"", (int)sizeof(origin)-4, CFG->origin[(*aa)->originno()].c_str()); else *origin = NUL; - fprintf(fp, "AREADEF %-*s %-*s %*s %s %s %-*s %-*s %-*s%s\n", + fp.Printf("AREADEF %-*s %-*s %*s %s %s %-*s %-*s %-*s%s\n", maxechoid, echoid, maxdesc, desc, maxgroupid, groupid, @@ -362,8 +355,6 @@ void AreaList::WriteAreaDef(const char* file) { ); } } - - fclose(fp); } } diff --git a/golded3/gcarea.cpp b/golded3/gcarea.cpp index 8568a7a..32a6dbc 100644 --- a/golded3/gcarea.cpp +++ b/golded3/gcarea.cpp @@ -807,9 +807,8 @@ void getdztoken(char** key, char** val) { // ------------------------------------------------------------------ -void AreaList::ReadEcholist(char* val) { - - FILE* fp; +void AreaList::ReadEcholist(char* val) +{ char* key; Path file; char buf[256], options[80]; @@ -836,11 +835,11 @@ void AreaList::ReadEcholist(char* val) { strcpy(file, key); } - if(*file) { - - fp = fsopen(file, "rt", CFG->sharemode); - if(fp) { - + if (*file) + { + gfile fp(file, "rt", CFG->sharemode); + if (fp.isopen()) + { void (*tok)(char**, char**); if(is_dz) @@ -851,8 +850,8 @@ void AreaList::ReadEcholist(char* val) { if (not quiet) STD_PRINTNL("* Reading " << file); - while(fgets((val=buf), sizeof(buf), fp)) { - + while (fp.Fgets((val=buf), sizeof(buf))) + { // Get echoid if(is_sqafix) { tok(&key, &val); @@ -900,8 +899,6 @@ void AreaList::ReadEcholist(char* val) { } } } - - fclose(fp); } } } diff --git a/golded3/gccfgg.cpp b/golded3/gccfgg.cpp index b310c09..efa9464 100644 --- a/golded3/gccfgg.cpp +++ b/golded3/gccfgg.cpp @@ -323,8 +323,8 @@ struct AF_entry idetect[] = { }; -void InstallDetect(char* path) { - +void InstallDetect(char* path) +{ // Create GOLDED.BAK file if there is an existing GOLDED.CFG if(fexist(CFG->goldcfg)) { Path cmdlinecfgbak; @@ -337,12 +337,13 @@ void InstallDetect(char* path) { STD_PRINTNL("Please wait while GoldED+ is detecting your software."); - FILE* fp = fopen(CFG->goldcfg, "wt"); - if(fp) { - - if(*path) { + gfile fp(CFG->goldcfg, "wt"); + if (fp.isopen()) + { + if (*path) + { MapPath(PathCopy(CFG->areapath, path)); - fprintf(fp, "AREAPATH %s\n", path); + fp.Printf("AREAPATH %s\n", path); } Path pth; @@ -362,8 +363,9 @@ void InstallDetect(char* path) { if(ptr) *ptr = NUL; } - if(fexist(AddPath(pth, idetect[i].configname))) { - fprintf(fp, "AREAFILE %s %s\n", idetect[i].name, pth); + if (fexist(AddPath(pth, idetect[i].configname))) + { + fp.Printf("AREAFILE %s %s\n", idetect[i].name, pth); STD_PRINTNL("Found " << idetect[i].name << (ptr ? "." : " (unreliable).")); if(streql(idetect[i].name, "Squish")) gotsquish = true; @@ -376,8 +378,9 @@ void InstallDetect(char* path) { ptr = getenv("IM"); if(ptr) PathCopy(pth, ptr); - if(fexist(AddPath(pth, "im.exe")) or fexist(AddPath(pth, "intrecho.exe"))) { - fprintf(fp, "AREAFILE InterMail %s\n", pth); + if (fexist(AddPath(pth, "im.exe")) or fexist(AddPath(pth, "intrecho.exe"))) + { + fp.Printf("AREAFILE InterMail %s\n", pth); STD_PRINTNL("Found InterMail and/or InterEcho."); detected = true; } @@ -391,21 +394,24 @@ void InstallDetect(char* path) { else extractdirname(pth, pth); } - if(fexist(AddPath(pth, "max.prm"))) { - fprintf(fp, "AREAFILE Maximus %s\n", pth); + if (fexist(AddPath(pth, "max.prm"))) + { + fp.Printf("AREAFILE Maximus %s\n", pth); STD_PRINTNL("Found Maximus."); detected = true; } - if(not gotsquish and fexist(AddPath(pth, "squish.cfg"))) { - fprintf(fp, "AREAFILE Squish %s\n", pth); + if (not gotsquish and fexist(AddPath(pth, "squish.cfg"))) + { + fp.Printf("AREAFILE Squish %s\n", pth); STD_PRINTNL("Found Squish."); detected = true; } // Detect ME2 strcpy(pth, CFG->areapath); - if(fexist(AddPath(pth, "areadesc.me2"))) { - fprintf(fp, "AREAFILE ME2 %sareadesc.me2 %sareas.bbs\n", pth, pth); + if (fexist(AddPath(pth, "areadesc.me2"))) + { + fp.Printf("AREAFILE ME2 %sareadesc.me2 %sareas.bbs\n", pth, pth); STD_PRINTNL("Found ME2."); gotareasbbs = true; detected = true; @@ -414,8 +420,9 @@ void InstallDetect(char* path) { // Detect AREAS.BBS if(not gotareasbbs) { strcpy(pth, CFG->areapath); - if(fexist(AddPath(pth, "areas.bbs"))) { - fprintf(fp, "AREAFILE AreasBBS %sareas.bbs\n", pth); + if (fexist(AddPath(pth, "areas.bbs"))) + { + fp.Printf("AREAFILE AreasBBS %sareas.bbs\n", pth); STD_PRINTNL("Found AREAS.BBS."); detected = true; } @@ -423,37 +430,37 @@ void InstallDetect(char* path) { if(not detected) STD_PRINTNL("Sorry, could not find any supported software. Try another path."); - - fclose(fp); } } // ------------------------------------------------------------------ -int InstallFinish() { - - FILE* fp = fopen(CFG->goldcfg, "at"); - if(fp) { - +int InstallFinish() +{ + gfile fp(CFG->goldcfg, "at"); + if (fp.isopen()) + { char buf[77]; // Check what we have - - if(CFG->username.empty()) { - if(EnterString("Please enter your name:", buf, sizeof(buf))) - goto install_terminated; - fprintf(fp, "USERNAME %s\n", buf); + if (CFG->username.empty()) + { + if (EnterString("Please enter your name:", buf, sizeof(buf))) + return -1; + fp.Printf("USERNAME %s\n", buf); CfgUsername(buf); } - if(CFG->aka.empty()) { - if(EnterString("Please enter your FidoNet address:", buf, sizeof(buf))) - goto install_terminated; - fprintf(fp, "ADDRESS %s\n", buf); + if (CFG->aka.empty()) + { + if (EnterString("Please enter your FidoNet address:", buf, sizeof(buf))) + return -1; + fp.Printf("ADDRESS %s\n", buf); CfgAddress(buf); } - if(AL.basetypes.empty()) { - if(EnterString("Please enter the path to your *.msg netmail area:", buf, sizeof(buf))) + if (AL.basetypes.empty()) + { + if (EnterString("Please enter the path to your *.msg netmail area:", buf, sizeof(buf))) return -1; AreaCfg aa; aa.reset(); @@ -464,54 +471,53 @@ int InstallFinish() { aa.setpath(buf); aa.attr = CFG->attribsnet; AL.AddNewArea(&aa); - fprintf(fp, "AREADEF %s \"%s\" 0 Net %s %s\n", aa.desc, aa.echoid, aa.basetype, buf); - if(EnterString("Please enter the path *and* filename of your areas.bbs file:", buf, sizeof(buf))) - goto install_terminated; - fprintf(fp, "AREAFILE AreasBBS %s\n", buf); + fp.Printf("AREADEF %s \"%s\" 0 Net %s %s\n", aa.desc, aa.echoid, aa.basetype, buf); + if (EnterString("Please enter the path *and* filename of your areas.bbs file:", buf, sizeof(buf))) + return -1; + fp.Printf("AREAFILE AreasBBS %s\n", buf); char buf2[200]="AreasBBS "; strcat(buf2, buf); AL.GetAreafile(buf2); } #ifndef GMB_NOHUDS - if(find(AL.basetypes, "HUDSON") and (*CFG->hudsonpath == NUL)) { - if(EnterString("Please enter the path to your Hudson msgbase files:", buf, sizeof(buf))) - goto install_terminated; - fprintf(fp, "HUDSONPATH %s\n", buf); + if (find(AL.basetypes, "HUDSON") and (*CFG->hudsonpath == NUL)) + { + if (EnterString("Please enter the path to your Hudson msgbase files:", buf, sizeof(buf))) + return -1; + fp.Printf("HUDSONPATH %s\n", buf); PathCopy(CFG->hudsonpath, buf); } #endif #ifndef GMB_NOGOLD - if(find(AL.basetypes, "GOLDBASE") and (*CFG->goldbasepath == NUL)) { - if(EnterString("Please enter the path to your Goldbase msgbase files:", buf, sizeof(buf))) - goto install_terminated; - fprintf(fp, "GOLDBASEPATH %s\n", buf); + if (find(AL.basetypes, "GOLDBASE") and (*CFG->goldbasepath == NUL)) + { + if (EnterString("Please enter the path to your Goldbase msgbase files:", buf, sizeof(buf))) + return -1; + fp.Printf("GOLDBASEPATH %s\n", buf); PathCopy(CFG->goldbasepath, buf); } #endif #ifndef GMB_NOJAM - if(find(AL.basetypes, "JAM") and (*CFG->jampath == NUL)) { - if(EnterString("Please enter the path where net/echomail.jam can be placed:", buf, sizeof(buf))) - goto install_terminated; - fprintf(fp, "JAMPATH %s\n", buf); + if (find(AL.basetypes, "JAM") and (*CFG->jampath == NUL)) + { + if (EnterString("Please enter the path where net/echomail.jam can be placed:", buf, sizeof(buf))) + return -1; + fp.Printf("JAMPATH %s\n", buf); PathCopy(CFG->jampath, buf); } #endif #ifndef GMB_NOPCB - if(find(AL.basetypes, "PCBOARD") and (*CFG->pcboardpath == NUL)) { - if(EnterString("Please enter the path to PCBoard:", buf, sizeof(buf))) - goto install_terminated; - fprintf(fp, "PCBOARDPATH %s\n", buf); + if (find(AL.basetypes, "PCBOARD") and (*CFG->pcboardpath == NUL)) + { + if (EnterString("Please enter the path to PCBoard:", buf, sizeof(buf))) + return -1; + fp.Printf("PCBOARDPATH %s\n", buf); PathCopy(CFG->pcboardpath, buf); } #endif - fclose(fp); return 0; } - -install_terminated: - fclose(fp); - return -1; } #endif diff --git a/golded3/gccfgg0.cpp b/golded3/gccfgg0.cpp index 5b40f5a..a66dede 100644 --- a/golded3/gccfgg0.cpp +++ b/golded3/gccfgg0.cpp @@ -720,11 +720,10 @@ static int do_if(char* val) { // ------------------------------------------------------------------ // Compile a GoldED text config file -int ReadCfg(const char* cfgfile, int ignoreunknown) { - +int ReadCfg(const char* cfgfile, int ignoreunknown) +{ const word CRC_APP = 0x08B5; - FILE* fp; Path cfg; char buf[1024]; static int inuse = 0; @@ -741,8 +740,8 @@ int ReadCfg(const char* cfgfile, int ignoreunknown) { strcpy(cfg, cfgfile); MakePathname(cfg, CFG->goldpath, cfg); - fp = fsopen(cfg, "rt", CFG->sharemode); - if (fp) + gfile fp(cfg, "rt", CFG->sharemode); + if (fp.isopen()) { cfgname = strrchr(cfg, '\\'); cfgname = cfgname ? cfgname+1 : cfg; @@ -752,11 +751,11 @@ int ReadCfg(const char* cfgfile, int ignoreunknown) { STD_PRINTNL("* Reading " << cfg); // Assign file buffer - setvbuf(fp, NULL, _IOFBF, 8192); + fp.SetvBuf(NULL, _IOFBF, 8192); // Read each line - while(fgets((val=buf), sizeof(buf), fp)) { - + while (fp.Fgets((val=buf), sizeof(buf))) + { line++; // Replace TABs with SPACEs @@ -882,7 +881,7 @@ int ReadCfg(const char* cfgfile, int ignoreunknown) { } // Close and return all OK - fclose(fp); + fp.Fclose(); inuse--; // When the final cfg is compiled diff --git a/golded3/gclang.cpp b/golded3/gclang.cpp index af39e2a..fe41386 100644 --- a/golded3/gclang.cpp +++ b/golded3/gclang.cpp @@ -646,18 +646,19 @@ void AssignDateNames() { // ------------------------------------------------------------------ // Load a GoldED language file -void LoadLanguage(const char* file) { - - FILE* fp; +void LoadLanguage(const char* file) +{ char* ptr; char* str; int line = 0; char buf[256]; - fp = fsopen(AddPath(CFG->goldpath, file), "rt", CFG->sharemode); - if(fp) { - setvbuf(fp, NULL, _IOFBF, 8192); - while(fgets((ptr=buf), sizeof(buf), fp)) { + gfile fp(AddPath(CFG->goldpath, file), "rt", CFG->sharemode); + if (fp.isopen()) + { + fp.SetvBuf(NULL, _IOFBF, 8192); + while (fp.Fgets((ptr=buf), sizeof(buf))) + { line++; ptr = strskip_wht(ptr); if(g_isalpha(*ptr)) { @@ -682,7 +683,6 @@ void LoadLanguage(const char* file) { } } } - fclose(fp); // Assign weekday/month names AssignDateNames(); @@ -693,9 +693,8 @@ void LoadLanguage(const char* file) { // ------------------------------------------------------------------ // Read the main language definition file -bool ReadLangCfg(int force) { - - FILE *fpi; +bool ReadLangCfg(int force) +{ char* ptr; char* str; long size; @@ -705,17 +704,19 @@ bool ReadLangCfg(int force) { // Read the GOLDLANG.CFG if there is one const char* cfgname = AddPath(CFG->goldpath, CFG->langcfg); - fpi = fsopen(cfgname, "rt", CFG->sharemode); - if (fpi) + + gfile fpi(cfgname, "rt", CFG->sharemode); + if (fpi.isopen()) { - setvbuf(fpi, NULL, _IOFBF, 8192); + fpi.SetvBuf(NULL, _IOFBF, 8192); if (not quiet) STD_PRINTNL("* Reading " << cfgname); cfgname = CleanFilename(cfgname); - while(fgets((ptr=buf), sizeof(buf), fpi)) { + while (fpi.Fgets((ptr=buf), sizeof(buf))) + { line++; ptr = strskip_wht(ptr); if(g_isalpha(*ptr)) { @@ -741,7 +742,6 @@ bool ReadLangCfg(int force) { } } } - fclose(fpi); } // Fill in the defaults if there are "holes" diff --git a/golded3/gcmisc.cpp b/golded3/gcmisc.cpp index aded215..2192430 100644 --- a/golded3/gcmisc.cpp +++ b/golded3/gcmisc.cpp @@ -34,20 +34,19 @@ int ReadHelpCfg(int force) { char* ptr; long offset; char buf[1024]; - FILE* ifp; - FILE* ofp; Hlpr* HlpL; int count; int counter; int comment; - if((force > 1) or (FiletimeCmp(CFG->helpcfg.fn, CFG->helpged) > 0)) { - - ifp = fsopen(AddPath(CFG->goldpath, CFG->helpcfg.fn), "rb", CFG->sharemode); - if(ifp) { - setvbuf(ifp, NULL, _IOFBF, 8192); - ofp = fsopen(AddPath(CFG->goldpath, CFG->helpged), "wb", CFG->sharemode); - if (ofp) + if ((force > 1) or (FiletimeCmp(CFG->helpcfg.fn, CFG->helpged) > 0)) + { + gfile ifp(AddPath(CFG->goldpath, CFG->helpcfg.fn), "rb", CFG->sharemode); + if (ifp.isopen()) + { + ifp.SetvBuf(NULL, _IOFBF, 8192); + gfile ofp(AddPath(CFG->goldpath, CFG->helpged), "wb", CFG->sharemode); + if (ofp.isopen()) { offset = 0L; CFG->helpcfg.ft = GetFiletime(AddPath(CFG->goldpath, CFG->helpcfg.fn)); @@ -55,27 +54,29 @@ int ReadHelpCfg(int force) { if (not quiet) STD_PRINTNL("* Reading " << AddPath(CFG->goldpath, CFG->helpcfg.fn)); - setvbuf(ofp, NULL, _IOFBF, 8192); + ofp.SetvBuf(NULL, _IOFBF, 8192); count = 0; - rewind(ifp); + ifp.Rewind(); - while(fgets(buf, sizeof(buf), ifp)) { + while (ifp.Fgets(buf, sizeof(buf))) + { if(strnieql(buf, "*B ", 3)) count++; } HlpL = (Hlpr*)throw_calloc(count+2, sizeof(Hlpr)); - rewind(ifp); - fputs("*I\r\n", ofp); - fwrite(HlpL, count+1, sizeof(Hlpr), ofp); - fputs("\r\n\r\n", ofp); + ifp.Rewind(); + ofp.Fputs("*I\r\n"); + ofp.Fwrite(HlpL, count+1, sizeof(Hlpr)); + ofp.Fputs("\r\n\r\n"); offset += 4 + ((count+1)*sizeof(Hlpr)) + 4; counter = 0; comment = YES; - while(fgets(buf, sizeof(buf), ifp)) { + while (ifp.Fgets(buf, sizeof(buf))) + { if(strnieql(buf, "*B ", 3)) { comment = NO; HlpL[counter].help = atow(buf+3); @@ -84,8 +85,9 @@ int ReadHelpCfg(int force) { HlpL[counter].offset = offset + strlen(buf); counter++; } - if(not comment) { - fputs(buf, ofp); + if (not comment) + { + ofp.Fputs(buf); offset += strlen(buf); } if(strnieql(buf, "*E", 2)) @@ -93,15 +95,12 @@ int ReadHelpCfg(int force) { } HlpL[counter].offset = -1L; - fseek(ofp, 0L, SEEK_SET); - fputs("*I\r\n", ofp); - fwrite(HlpL, count+1, sizeof(Hlpr), ofp); + ofp.FseekSet(0); + ofp.Fputs("*I\r\n"); + ofp.Fwrite(HlpL, count+1, sizeof(Hlpr)); throw_free(HlpL); - fclose(ofp); } - - fclose(ifp); } } @@ -818,21 +817,25 @@ void ReadXlatTables() { // ------------------------------------------------------------------ -void CookieIndex(char* textfile, char* indexfile) { - - FILE* ifp = fsopen(textfile, "rb", CFG->sharemode); - if(ifp) { - setvbuf(ifp, NULL, _IOFBF, 32000); - FILE* ofp = fsopen(indexfile, "wb", CFG->sharemode); - if(ofp) { - setvbuf(ofp, NULL, _IOFBF, 16000); +void CookieIndex(char* textfile, char* indexfile) +{ + gfile ifp(textfile, "rb", CFG->sharemode); + if (ifp.isopen()) + { + ifp.SetvBuf(NULL, _IOFBF, 32000); + gfile ofp(indexfile, "wb", CFG->sharemode); + if (ofp) + { + ofp.SetvBuf(NULL, _IOFBF, 16000); char buf[256]; long fpos = 0; long tpos = 0; bool was_blank = false; - while(fgets(buf, sizeof(buf), ifp)) { - if(strblank(buf)) { - fwrite(&fpos, sizeof(long), 1, ofp); + while (ifp.Fgets(buf, sizeof(buf))) + { + if (strblank(buf)) + { + ofp.Fwrite(&fpos, sizeof(long)); fpos = tpos + strlen(buf); was_blank = true; } @@ -841,11 +844,9 @@ void CookieIndex(char* textfile, char* indexfile) { } tpos += strlen(buf); } - if(not was_blank) - fwrite(&fpos, sizeof(long), 1, ofp); - fclose(ofp); + if (not was_blank) + ofp.Fwrite(&fpos, sizeof(long)); } - fclose(ifp); } } diff --git a/golded3/gecarb.cpp b/golded3/gecarb.cpp index 74ee50f..474a879 100644 --- a/golded3/gecarb.cpp +++ b/golded3/gecarb.cpp @@ -167,16 +167,16 @@ int DoCarboncopy(GMsg* msg, GMsg** carbon) { else cchide = false; - if(*ptr == '@') { - FILE* fp = fsopen(AddPath(CFG->goldpath, ++ptr), "rt", CFG->sharemode); - if(fp) { + if (*ptr == '@') + { + gfile fp(AddPath(CFG->goldpath, ++ptr), "rt", CFG->sharemode); + if (fp.isopen()) + { gstrarray fc; - while(fgets(buf, sizeof(buf), fp)) + while (fp.Fgets(buf, sizeof(buf))) tokenize(fc, buf, ",\n"); - fclose(fp); - for(int j = 0; j < fc.size(); j++) if(fc[j][0] != '@') // we don't like nesting! AddCCList(fc[j].c_str(), cchide, msg, carbon, cc, A, AA, xc2to); @@ -386,16 +386,16 @@ void DoCrosspost(GMsg* msg, std::vector &postareas) { else xphide = false; - if(*ptr == '@') { - FILE* fp = fsopen(AddPath(CFG->goldpath, ++ptr), "rt", CFG->sharemode); - if(fp) { + if (*ptr == '@') + { + gfile fp(AddPath(CFG->goldpath, ++ptr), "rt", CFG->sharemode); + if (fp.isopen()) + { gstrarray fc; - while(fgets(buf, sizeof(buf), fp)) + while (fp.Fgets(buf, sizeof(buf))) tokenize(fc, buf, ", \n"); - fclose(fp); - for(int j = 0; j < fc.size(); j++) if(fc[j][0] != '@') // we don't like nesting! hideoriginal = AddXCAreas(fc[j].c_str(), xphide, postareas, postareas_attrs, local_xps) or hideoriginal; diff --git a/golded3/gedoit.cpp b/golded3/gedoit.cpp index e21273a..3bf116f 100644 --- a/golded3/gedoit.cpp +++ b/golded3/gedoit.cpp @@ -29,7 +29,7 @@ // ------------------------------------------------------------------ -static FILE* prnfp; +static gfile prnfp; static int prnheader; @@ -51,13 +51,15 @@ void SaveLines(int mode, const char* savefile, GMsg* msg, int margin, bool clip) strcpy(fnam, "PRN"); if(mode == MODE_WRITE and streql(savefile, "\001PRN")) prn = YES; - else { + else + { strcpy(fnam, savefile); strschg_environ(fnam); - prnfp = fsopen(fnam, prnacc, CFG->sharemode); + prnfp.Fopen(fnam, prnacc, CFG->sharemode); } int lines=0; - if(prnfp) { + if (prnfp.isopen()) + { char *old_msg_txt = throw_strdup(msg->txt); #ifdef OLD_STYLE_HEADER if(mode == MODE_WRITE) { @@ -99,40 +101,42 @@ void SaveLines(int mode, const char* savefile, GMsg* msg, int margin, bool clip) } } const char *ptr = line->txt.c_str(); - fwrite(ptr, strlen(ptr), 1, prnfp); - if(mode == MODE_NEW) { + prnfp.Fwrite(ptr, strlen(ptr)); + if (mode == MODE_NEW) + { if(EDIT->HardLines()) { if(line->type & GLINE_HARD) { - if(not ((line->type & (GLINE_TEAR|GLINE_ORIG|GLINE_KLUDGE|GLINE_QUOT)) or strblank(ptr))) { - fwrite(EDIT->HardLine(), strlen(EDIT->HardLine()), 1, prnfp); + if (not ((line->type & (GLINE_TEAR|GLINE_ORIG|GLINE_KLUDGE|GLINE_QUOT)) or strblank(ptr))) + { + prnfp.Fwrite(EDIT->HardLine(), strlen(EDIT->HardLine())); } } } } - fwrite(prn ? NL : "\n", prn ? sizeof(NL) : 1, 1, prnfp); - if(prn) { + prnfp.Fwrite(prn ? NL : "\n", prn ? sizeof(NL) : 1); + if (prn) + { lines++; - if(lines%CFG->printlength == 0 and CFG->switches.get(printformfeed)) { - fwrite("\f", 1, 1, prnfp); - } + if (lines%CFG->printlength == 0 and CFG->switches.get(printformfeed)) + prnfp.Fwrite("\f", 1); } } line = lin[++n]; } } // Add an empty line and formfeed at the bottom - if(mode == MODE_WRITE) { - fwrite(prn ? NL : "\n", prn ? sizeof(NL) : 1, 1, prnfp); - } + if (mode == MODE_WRITE) + prnfp.Fwrite(prn ? NL : "\n", prn ? sizeof(NL) : 1); + // Add formfeed if requested - if((prn and CFG->switches.get(printformfeed)) or - (not prn and not clip and CFG->switches.get(formfeedseparator))) { - fwrite("\f", 1, 1, prnfp); - } - if(not prn) { - fclose(prnfp); - prnfp = NULL; + if ((prn and CFG->switches.get(printformfeed)) or + (not prn and not clip and CFG->switches.get(formfeedseparator))) + { + prnfp.Fwrite("\f", 1); } + + prnfp.Fclose(); + throw_release(msg->txt); msg->txt = old_msg_txt; } @@ -162,8 +166,6 @@ static void WriteMsgs(GMsg* msg) { int overwrite = NO; - prnfp = NULL; - GMenuDomarks MenuDomarks; int source = AA->Mark.Count() ? MenuDomarks.Run(LNG->Write) : WRITE_CURRENT; @@ -203,12 +205,12 @@ static void WriteMsgs(GMsg* msg) { } else if(target & WRITE_PRINTER) { #ifdef __UNIX__ - prnfp = popen(CFG->printdevice, "w"); + prnfp.Popen(CFG->printdevice, "w"); #else - prnfp = fsopen(CFG->printdevice, "wt", CFG->sharemode); + prnfp.Fopen(CFG->printdevice, "wt", CFG->sharemode); #endif - if(prnfp) - fwrite(CFG->printinit+1, CFG->printinit[0], 1, prnfp); + if (prnfp.isopen()) + prnfp.Fwrite(CFG->printinit+1, CFG->printinit[0]); } else if(target & WRITE_CLIPBRD) { overwrite = YES; @@ -238,9 +240,10 @@ static void WriteMsgs(GMsg* msg) { SaveLines(overwrite ? MODE_WRITE : MODE_APPEND, AA->Outputfile(), msg, prnmargin, make_bool(target & WRITE_CLIPBRD)); } } - if(prnfp) - fwrite(CFG->printreset+1, CFG->printreset[0], 1, prnfp); - if(target & WRITE_CLIPBRD) { + if (prnfp.isopen()) + prnfp.Fwrite(CFG->printreset+1, CFG->printreset[0]); + if (target & WRITE_CLIPBRD) + { AA->SetOutputfile(ofname); gclipbrd clipbrd; @@ -296,14 +299,15 @@ static void WriteMsgs(GMsg* msg) { w_info(LNG->WritingPRN); AA->LoadMsg(msg, msg->msgno, prnmargin); #ifdef __UNIX__ - prnfp = popen(CFG->printdevice, "w"); + prnfp.Popen(CFG->printdevice, "w"); #else - prnfp = fsopen(CFG->printdevice, "wt", CFG->sharemode); + prnfp.Fopen(CFG->printdevice, "wt", CFG->sharemode); #endif - if(prnfp) { - fwrite(CFG->printinit+1, CFG->printinit[0], 1, prnfp); + if (prnfp.isopen()) + { + prnfp.Fwrite(CFG->printinit+1, CFG->printinit[0]); SaveLines(MODE_WRITE, "\001PRN", msg, prnmargin); - fwrite(CFG->printreset+1, CFG->printreset[0], 1, prnfp); + prnfp.Fwrite(CFG->printreset+1, CFG->printreset[0]); } w_info(NULL); } @@ -343,14 +347,11 @@ Finish: w_info(NULL); - if(prnfp) { - #ifdef __UNIX__ - pclose(prnfp); - #else - fclose(prnfp); - #endif - prnfp = NULL; - } + #ifdef __UNIX__ + prnfp.Pclose(); + #else + prnfp.Fclose(); + #endif GFTRK(NULL); } @@ -439,13 +440,13 @@ void QuoteBuf(GMsg* msg) { break; } - if(*openmode) { - - FILE* fp = fsopen(quotebuf, openmode, CFG->sharemode); - if(fp) { + if (*openmode) + { + gfile fp(quotebuf, openmode, CFG->sharemode); + if (fp.isopen()) + { strchg(msg->txt, 0x0D, 0x0A); - fputs(msg->txt, fp); - fclose(fp); + fp.Fputs(msg->txt); } HandleGEvent(EVTT_JOBDONE); diff --git a/golded3/geedit.cpp b/golded3/geedit.cpp index cd05118..b5f4253 100644 --- a/golded3/geedit.cpp +++ b/golded3/geedit.cpp @@ -2012,16 +2012,17 @@ void IEclass::savefile(int __status) { // Open the save file const char* editorfile = AddPath(CFG->goldpath, EDIT->File()); remove(editorfile); - FILE* _fp = fsopen(editorfile, "wb", CFG->sharemode); - if(_fp) { - + gfile _fp(editorfile, "wb", CFG->sharemode); + if (_fp) + { // Find the first line Line* _saveline = findfirstline(); // First save the "unfinished" identifier - if(__status == MODE_UPDATE) { - fputs(unfinished, _fp); - fputs("\r\n", _fp); + if (__status == MODE_UPDATE) + { + _fp.Fputs(unfinished); + _fp.Fputs("\r\n"); } // Save as whole paragraphs @@ -2037,14 +2038,11 @@ void IEclass::savefile(int __status) { strcpy(_lfptr, "\r\n"); // Save the line - fputs(_buf, _fp); + _fp.Fputs(_buf); // Continue with the next line _saveline = _saveline->next; } - - // Close save file and remove wait window - fclose(_fp); } update_statusline(statbak); @@ -2864,12 +2862,15 @@ int IEclass::Start(int __mode, uint* __position, GMsg* __msg) { } // Check if there is an unfinished backup message - FILE* _fp = fsopen(AddPath(CFG->goldpath, EDIT->File()), "rt", CFG->sharemode); - if(_fp) { + gfile _fp(AddPath(CFG->goldpath, EDIT->File()), "rt", CFG->sharemode); + if (_fp) + { char _buf[EDIT_BUFLEN]; - fgets(_buf, sizeof(_buf), _fp); - fclose(_fp); - if(striinc(unfinished, _buf)) { + _fp.Fgets(_buf, sizeof(_buf)); + _fp.Fclose(); + + if (striinc(unfinished, _buf)) + { w_info(LNG->UnfinishedMsg); update_statusline(LNG->LoadUnfinished); HandleGEvent(EVTT_ATTENTION); diff --git a/golded3/geedit2.cpp b/golded3/geedit2.cpp index e1f28f3..a2cdbdf 100644 --- a/golded3/geedit2.cpp +++ b/golded3/geedit2.cpp @@ -798,9 +798,9 @@ void IEclass::LoadFile() { GFTRK("EditLoadFile"); // Open the file to load - FILE* _fp = fsopen(AddPath(CFG->goldpath, EDIT->File()), "rb", CFG->sharemode); - if(_fp) { - + gfile _fp(AddPath(CFG->goldpath, EDIT->File()), "rb", CFG->sharemode); + if (_fp) + { XlatName __oldxlatimport; // Pop up a wait window @@ -824,17 +824,17 @@ void IEclass::LoadFile() { currline = msgptr->lin = NULL; // Allocate space for new message text - msgptr->txt = (char*)throw_calloc(1, (uint)(fsize(_fp)+256)); + msgptr->txt = (char*)throw_calloc(1, (uint)(_fp.FileLength()+256)); // Eat the backup marking line char _buf[EDIT_BUFLEN]; - fgets(_buf, sizeof(_buf), _fp); - if(not striinc(unfinished, _buf)) - rewind(_fp); + _fp.Fgets(_buf, sizeof(_buf)); + if (not striinc(unfinished, _buf)) + _fp.Rewind(); // Load the file and close it - fread(msgptr->txt, 1, (uint)fsize(_fp), _fp); - fclose(_fp); + _fp.Fread(msgptr->txt, (uint)_fp.FileLength()); + _fp.Fclose(); // Save current charset strcpy(__oldxlatimport, AA->Xlatimport()); @@ -981,18 +981,18 @@ void IEclass::editimport(Line* __line, char* __filename, bool imptxt) { } } - if(fileselected or getclip) { - + if (fileselected or getclip) + { // Open the file/clipboard - FILE* fp = NULL; + gfile fp; gclipbrd clipbrd; if(getclip) filenamebuf = CLIP_NAME; if(getclip ? clipbrd.openread() : - (fp = fsopen(filenamebuf.c_str(), binary ? "rb" : "rt", CFG->sharemode))!=NULL) { - + (fp.Fopen(filenamebuf.c_str(), binary ? "rb" : "rt", CFG->sharemode))!=NULL) + { if (isPipe) filenamebuf = AA->Inputfile(); @@ -1037,14 +1037,15 @@ void IEclass::editimport(Line* __line, char* __filename, bool imptxt) { __line = insertlinebelow(__line, _parabuf); setlinetype(__line); - while(1) { + while (true) + { char ibuf[80]; char* iptr = ibuf; char* optr = _parabuf; - int n = fread(ibuf, 1, 45, fp); - if(n < 45) - memset(ibuf+n, 0, 45-n); + int n = fp.Fread(ibuf, 45); + if (n < 45) memset(ibuf+n, 0, 45-n); *optr++ = uuencode_enc(n); + for(int i=0; i> 2); *optr++ = uuencode_enc(((*iptr << 4) & 060) | ((iptr[1] >> 4) & 017)); @@ -1079,10 +1080,11 @@ void IEclass::editimport(Line* __line, char* __filename, bool imptxt) { __line = insertlinebelow(__line, _parabuf); setlinetype(__line); - for(;;) { + while (true) + { char ibuf[80]; char* optr = _parabuf; - int n = fread(ibuf, 1, 54, fp); + int n = fp.Fread(ibuf, 54); optr = b64.encode(optr, ibuf, n); *optr++ = '\n'; *optr = NUL; @@ -1109,8 +1111,8 @@ void IEclass::editimport(Line* __line, char* __filename, bool imptxt) { __line->next = NULL; // Read paragraphs - while(getclip ? clipbrd.read(_parabuf, EDIT_PARABUFLEN-7) : fgets(_parabuf, EDIT_PARABUFLEN-7, fp)) { - + while (getclip ? clipbrd.read(_parabuf, EDIT_PARABUFLEN-7) : fp.Fgets(_parabuf, EDIT_PARABUFLEN-7)) + { XlatStr(buf, _parabuf, level, CharTable); // Insert a quotestring if asked @@ -1208,10 +1210,10 @@ void IEclass::editimport(Line* __line, char* __filename, bool imptxt) { throw_free(_parabuf); - if(getclip) + if (getclip) clipbrd.close(); else - fclose(fp); + fp.Fclose(); } else { w_infof(LNG->CouldNotOpen, filenamebuf.c_str()); @@ -1279,8 +1281,8 @@ void IEclass::editexport(Line* __exportline, int __endat) { update_statusline(LNG->ExportFile); - if(edit_string(Edit__exportfilename, sizeof(Path), LNG->ExportWhatFile, H_ExportFile)) { - + if (edit_string(Edit__exportfilename, sizeof(Path), LNG->ExportWhatFile, H_ExportFile)) + { // Pointer to export filename char* _filenameptr = Edit__exportfilename; @@ -1288,20 +1290,19 @@ void IEclass::editexport(Line* __exportline, int __endat) { if(*_filenameptr == '+') _filenameptr++; - FILE* _fp = fsopen(_filenameptr, (*Edit__exportfilename == '+') ? "at" : "wt", CFG->sharemode); - if(_fp) { - + gfile _fp(_filenameptr, (*Edit__exportfilename == '+') ? "at" : "wt", CFG->sharemode); + if (_fp.isopen()) + { update_statuslinef(LNG->ExportStatus, "ST_EXPORTSTATUS", Edit__exportfilename); - fputc('\n', _fp); + _fp.Fputc('\n'); - while((__endat ? __exportline != currline : 1) and __exportline) { - fwrite(__exportline->txt.c_str(), 1, __exportline->txt.length(), _fp); - if(__exportline->txt.find('\n') == __exportline->txt.npos) - fputc('\n', _fp); + while ((__endat ? __exportline != currline : 1) and __exportline) + { + _fp.Fwrite(__exportline->txt.c_str(), __exportline->txt.length()); + if (__exportline->txt.find('\n') == __exportline->txt.npos) + _fp.Fputc('\n'); __exportline = __exportline->next; } - - fclose(_fp); } } diff --git a/golded3/geinit.cpp b/golded3/geinit.cpp index 84e6cba..3e49ccf 100644 --- a/golded3/geinit.cpp +++ b/golded3/geinit.cpp @@ -173,25 +173,27 @@ static void ReadEcholists() { Echo* echoin = (Echo*)throw_calloc(1, sizeof(Echo)); // Read the import taglist - FILE* fp = fsopen(AddPath(CFG->areapath, CFG->semaphore.importlist), "rt", CFG->sharemode); - - if(fp) { + gfile fp(AddPath(CFG->areapath, CFG->semaphore.importlist), "rt", CFG->sharemode); + if (fp.isopen()) + { char buf[256]; int echonums = 0; update_statusline(LNG->ReadingEcholist); - while(fgets(buf, sizeof(buf), fp)) { + while (fp.Fgets(buf, sizeof(buf))) + { if(not strblank(buf)) { echonums++; echoin = (Echo*)throw_realloc(echoin, (echonums+2)*sizeof(Echo)); strcpy(echoin[echonums-1], strtrim(strsetsz(buf, sizeof(Echo)-1))); } } + *echoin[echonums] = 0; // Mark end - fclose(fp); } // Mark the areas from the import taglist - for(uint n=0; nechoid()); int x = SearchTaglist(echoin, buf); @@ -205,41 +207,33 @@ static void ReadEcholists() { // ------------------------------------------------------------------ -static void ReadEscsets() { +static void ReadEscsets() +{ + std::vector::iterator x = CFG->xlatescset.begin(); + for (int n = 0; x != CFG->xlatescset.end(); x++, n++) + { + gfile fp(AddPath(CFG->goldpath, CFG->xlatged), "rb", CFG->sharemode); + if (fp.isopen()) + { + fp.FseekSet(((long)CFG->xlatcharset.size()*(long)sizeof(Chs)) + ((long)n*(long)sizeof(Esc))); - FILE* fp; - - std::vector::iterator x; - int n; - for(n = 0, x = CFG->xlatescset.begin(); x != CFG->xlatescset.end(); x++, n++) { - if(strieql(x->imp, "Composed")) { - fp = fsopen(AddPath(CFG->goldpath, CFG->xlatged), "rb", CFG->sharemode); - if(fp) { + if (strieql(x->imp, "Composed")) + { CompTable = (Esc*)throw_realloc(CompTable, sizeof(Esc)); - fseek(fp, ((long)CFG->xlatcharset.size()*(long)sizeof(Chs)) + ((long)n*(long)sizeof(Esc)), SEEK_SET); - fread(CompTable, sizeof(Esc), 1, fp); + fp.Fread(CompTable, sizeof(Esc)); CompTP = CompTable->t; - fclose(fp); } - } - else if(strieql(x->imp, "I51")) { - fp = fsopen(AddPath(CFG->goldpath, CFG->xlatged), "rb", CFG->sharemode); - if(fp) { + else if (strieql(x->imp, "I51")) + { I51Table = (Esc*)throw_realloc(I51Table, sizeof(Esc)); - fseek(fp, ((long)CFG->xlatcharset.size()*(long)sizeof(Chs)) + ((long)n*(long)sizeof(Esc)), SEEK_SET); - fread(I51Table, sizeof(Esc), 1, fp); + fp.Fread(I51Table, sizeof(Esc)); I51TP = I51Table->t; - fclose(fp); } - } - else if(strieql(x->imp, "MNEMONIC")) { - fp = fsopen(AddPath(CFG->goldpath, CFG->xlatged), "rb", CFG->sharemode); - if(fp) { + else if (strieql(x->imp, "MNEMONIC")) + { MNETable = (Esc*)throw_realloc(MNETable, sizeof(Esc)); - fseek(fp, ((long)CFG->xlatcharset.size()*(long)sizeof(Chs)) + ((long)n*(long)sizeof(Esc)), SEEK_SET); - fread(MNETable, sizeof(Esc), 1, fp); + fp.Fread(MNETable, sizeof(Esc)); MNETP = MNETable->t; - fclose(fp); } } } @@ -248,9 +242,8 @@ static void ReadEscsets() { // ------------------------------------------------------------------ -static void ReadAddrMacros() { - - FILE* fp; +static void ReadAddrMacros() +{ char* ptr; char buf[256], path[GMAXPATH]; @@ -262,16 +255,15 @@ static void ReadAddrMacros() { MakePathname(CFG->namesfile, path, CFG->namesfile); - if(fexist(CFG->namesfile)) { - fp = fsopen(CFG->namesfile, "rt", CFG->sharemode); - if(fp) { - update_statusline(LNG->ReadingAddrMacros); - while(fgets(buf, sizeof(buf), fp)) { - strbtrim(buf); - if(*buf != ';' and *buf) - CfgAddressmacro(buf); - } - fclose(fp); + gfile fp(CFG->namesfile, "rt", CFG->sharemode); + if (fp.isopen()) + { + update_statusline(LNG->ReadingAddrMacros); + while (fp.Fgets(buf, sizeof(buf))) + { + strbtrim(buf); + if(*buf != ';' and *buf) + CfgAddressmacro(buf); } } } diff --git a/golded3/geline.cpp b/golded3/geline.cpp index 395892e..1554ffd 100644 --- a/golded3/geline.cpp +++ b/golded3/geline.cpp @@ -2980,15 +2980,13 @@ static bool CheckLevel(const char* imp, const char* imp2, int n, int ¤t_ta if (CharTable && (n == current_table) && (level <= CharTable->level)) return true; - FILE* fp = fsopen(AddPath(CFG->goldpath, CFG->xlatged), "rb", CFG->sharemode); - - if (fp) + gfile fp(AddPath(CFG->goldpath, CFG->xlatged), "rb", CFG->sharemode); + if (fp.isopen()) { if (!CharTable) CharTable = (Chs*)throw_calloc(1, sizeof(Chs)); - fseek(fp, ((long)n*(long)sizeof(Chs)), SEEK_SET); - fread(CharTable, sizeof(Chs), 1, fp); - fclose(fp); - + fp.FseekSet(n, sizeof(Chs)); + fp.Fread(CharTable, sizeof(Chs)); + ChsTP = CharTable->t; current_table = n; diff --git a/golded3/gemenu.cpp b/golded3/gemenu.cpp index a3c68ac..e28bc7d 100644 --- a/golded3/gemenu.cpp +++ b/golded3/gemenu.cpp @@ -604,25 +604,28 @@ void AskAttributes(GMsg* __msg) { // ------------------------------------------------------------------ -int SelectFromFile(const char* file, char* selection, const char* title, const char* nolines) { - +int SelectFromFile(const char* file, char* selection, const char* title, const char* nolines) +{ char buf[256]; int n; bool retval=false; char** Listi; int lines = 0; - FILE* fp = fsopen(AddPath(CFG->goldpath, file), "rt", CFG->sharemode); - if(fp) { - while(fgets(buf, sizeof(buf), fp)) + gfile fp(AddPath(CFG->goldpath, file), "rt", CFG->sharemode); + if (fp.isopen()) + { + while (fp.Fgets(buf, sizeof(buf))) lines++; } - if(lines) { + if (lines) + { Listi = (char**)throw_calloc(lines+1, sizeof(char*)); - rewind(fp); - for(n=0; nsharemode); - if(fp) { - + gfile fp(textfile, "rt", CFG->sharemode); + if (fp.isopen()) + { #define PBUFSIZE 4096 // Allow a 4k long paragraph size_t buf_len = PBUFSIZE; @@ -773,7 +772,7 @@ void LoadText(GMsg* msg, const char* textfile) { memset(spaces, ' ', tabsz); spaces[tabsz] = NUL; - uint tlen = (uint)(fsize(fp)+512); + uint tlen = (uint)(fp.FileLength()+512); msg->txt = txtptr = (char*)throw_realloc(msg->txt, tlen); memset(msg->txt, NUL, tlen); @@ -785,8 +784,8 @@ void LoadText(GMsg* msg, const char* textfile) { hardlen = strlen(hardline); *txtptr = NUL; - while(fgets(buf, PBUFSIZE-1, fp)) { - + while (fp.Fgets(buf, PBUFSIZE-1)) + { if(EDIT->HardLines() and strneql(buf, hardline, hardlen)) { hardcr = not hardcr; if(*txtptr == LF) @@ -891,7 +890,6 @@ void LoadText(GMsg* msg, const char* textfile) { if(*txtptr != CR) *(++txtptr) = CR; *(++txtptr) = NUL; - fclose(fp); throw_free(buf); } } diff --git a/golded3/genode.cpp b/golded3/genode.cpp index 7aa921b..5700812 100644 --- a/golded3/genode.cpp +++ b/golded3/genode.cpp @@ -1247,13 +1247,14 @@ void CheckNodelists() { update_statusline(LNG->CheckingNodelists); - FILE* fp = fsopen(file, "rt", CFG->sharemode); - if(fp) { - + gfile fp(file, "rt", CFG->sharemode); + if (fp) + { // Read the list index char buf[256]; NODE->nodelists = 0; - while(fgets(buf, sizeof(buf), fp)) { + while (fp.Fgets(buf, sizeof(buf))) + { NODE->nodelist = (Stamp*)throw_realloc(NODE->nodelist, (NODE->nodelists+1)*sizeof(Stamp)); char* key; char* val=buf; @@ -1263,7 +1264,7 @@ void CheckNodelists() { NODE->nodelist[NODE->nodelists].ft = atol(val); NODE->nodelists++; } - fclose(fp); + fp.Fclose(); // Check the files if(CFG->switches.get(nodelistwarn)) { diff --git a/golded3/gepost.cpp b/golded3/gepost.cpp index a23f730..23c4e91 100644 --- a/golded3/gepost.cpp +++ b/golded3/gepost.cpp @@ -1100,13 +1100,14 @@ void MakeMsg(int mode, GMsg* omsg, bool ignore_replyto) { if (confirm) { throw_release(msg->txt); - FILE* fp = fsopen(AddPath(CFG->goldpath, CFG->confirmfile), "rt", CFG->sharemode); - if(fp) { + gfile fp(AddPath(CFG->goldpath, CFG->confirmfile), "rt", CFG->sharemode); + + if (fp.isopen()) LoadText(msg, AddPath(CFG->goldpath, CFG->confirmfile)); - fclose(fp); - } - if(msg->txt == NULL) + + if (msg->txt == NULL) msg->txt = throw_strdup("\r\rConfirmation Receipt\r\r"); + TokenXlat(mode, msg->txt, strlen(msg->txt)+1, true, msg, omsg, CurrArea); } else diff --git a/golded3/geprot.h b/golded3/geprot.h index e2c2da9..ea5b41a 100644 --- a/golded3/geprot.h +++ b/golded3/geprot.h @@ -293,9 +293,6 @@ int MsgIsTwit(GMsg* msg, bool& istwitto, bool& istwitsubj); uint32_t MsgHasReplies(GMsg* msg); gkey ViewMessage(int istwit=NOT_TWIT); int LoadMessage(GMsg* msg, int margin); -#ifdef OLD_STYLE_HEADER -void DispHeader(GMsg* msg, bool prn, FILE* fp=NULL, int width=-1); -#endif void LoadRawMsg(GMsg* msg, int margin); void make_pathreport(char* reportfile); diff --git a/golded3/geqwks.cpp b/golded3/geqwks.cpp index 26d4f17..1b93223 100644 --- a/golded3/geqwks.cpp +++ b/golded3/geqwks.cpp @@ -32,15 +32,14 @@ static void ReadGldFile() { - if(QWK->FoundBBS()) { - + if (QWK->FoundBBS()) + { Path gldfile; - + QWK->ResetConfNo(); - sprintf(gldfile, "%s%s.GLD", CFG->goldpath, QWK->BbsID()); + gfile fp(gldfile, "rt"); - if (fp.isopen()) { char* key; @@ -54,7 +53,6 @@ static void ReadGldFile() { if(QWK->FindEcho(val)) QWK->ConfNo(atoi(key)); } - fp.Fclose(); } } } @@ -336,7 +334,6 @@ int ImportQWK() { } na++; } - fp.Fclose(); } } diff --git a/golded3/gerand.cpp b/golded3/gerand.cpp index 4eadcb5..b7793d3 100644 --- a/golded3/gerand.cpp +++ b/golded3/gerand.cpp @@ -29,8 +29,8 @@ // ------------------------------------------------------------------ -char* GetRandomLine(char* __buf, size_t __bufsize, const char* file) { - +char* GetRandomLine(char* __buf, size_t __bufsize, const char* file) +{ Path indexfile; Path __file; @@ -39,10 +39,10 @@ char* GetRandomLine(char* __buf, size_t __bufsize, const char* file) { replaceextension(indexfile, __file, ".sdx"); - FILE* fp = fsopen(AddPath(CFG->goldpath, __file), "rb", CFG->sharemode); - if(fp) { - - setvbuf(fp, NULL, _IOFBF, 32000); + gfile fp(AddPath(CFG->goldpath, __file), "rb", CFG->sharemode); + if (fp.isopen()) + { + fp.SetvBuf(NULL, _IOFBF, 32000); // Check if index exists or if it is older than the textfile const char* idxfile = AddPath(CFG->goldpath, indexfile); @@ -52,45 +52,45 @@ char* GetRandomLine(char* __buf, size_t __bufsize, const char* file) { idxexist = false; // Create index if one was missing - if(not idxexist) { - FILE* fpi = fsopen(idxfile, "wb", CFG->sharemode); - if(fpi) { - setvbuf(fpi, NULL, _IOFBF, 16000); + if (not idxexist) + { + gfile fpi(idxfile, "wb", CFG->sharemode); + if (fpi.isopen()) + { + fpi.SetvBuf(NULL, _IOFBF, 16000); long fpos = 0; char buf[512]; - while(fgets(buf, sizeof(buf), fp)) { - fwrite(&fpos, sizeof(long), 1, fpi); + while (fp.Fgets(buf, sizeof(buf))) + { + fpi.Fwrite(&fpos, sizeof(long)); fpos += strlen(buf); } - fclose(fpi); } } - FILE* fpi = fsopen(idxfile, "rb", CFG->sharemode); - if(fpi) { - - setvbuf(fpi, NULL, _IOFBF, 16000); + gfile fpi(idxfile, "rb", CFG->sharemode); + if (fpi.isopen()) + { + fpi.SetvBuf(NULL, _IOFBF, 16000); // Get random line if there is at least one - int _lines = (int)(fsize(fpi)/sizeof(long)); + int _lines = (int)(fpi.FileLength()/sizeof(long)); if(_lines > 0) { // Select a random line long _offset = 0; long _ourline = rand() % _lines; - fseek(fpi, _ourline*(long)sizeof(long), SEEK_SET); - fread(&_offset, sizeof(long), 1, fpi); + fpi.FseekSet(_ourline, (long)sizeof(long)); + fpi.Fread(&_offset, sizeof(long)); // Get it char buf[512]; - fseek(fp, _offset, SEEK_SET); - fgets(buf, sizeof(buf), fp); + fp.FseekSet(_offset); + fp.Fgets(buf, sizeof(buf)); StripQuotes(strbtrim(buf)); strxcpy(__buf, buf, __bufsize); } - fclose(fpi); } - fclose(fp); } return __buf; diff --git a/golded3/geread2.cpp b/golded3/geread2.cpp index a025e88..5c5e938 100644 --- a/golded3/geread2.cpp +++ b/golded3/geread2.cpp @@ -516,12 +516,13 @@ void DosShell() { // ------------------------------------------------------------------ -void TouchNetscan(int popup) { - - FILE* fp = fsopen(AddPath(CFG->areapath, CFG->semaphore.netscan), "wb", CFG->sharemode); - if(fp) { - fclose(fp); - if(popup) { +void TouchNetscan(int popup) +{ + gfile fp(AddPath(CFG->areapath, CFG->semaphore.netscan), "wb", CFG->sharemode); + if (fp.isopen()) + { + if (popup) + { w_infof(" %s ", CFG->semaphore.netscan); HandleGEvent(EVTT_JOBDONE); waitkeyt(10000); @@ -584,7 +585,6 @@ int ExternUtil(GMsg *msg, ExtUtil *extutil) { fp.Printf("--- %s\n", msg->tearline); if (*msg->origin) fp.Printf(" * Origin: %s\n", msg->origin); - fp.Fclose(); } } } @@ -873,9 +873,8 @@ void UUDecode(GMsg* msg) { // ------------------------------------------------------------------ -void Make_Userlist(const char* userlist) { - - FILE* fp; +void Make_Userlist(const char* userlist) +{ word* crclist; word crc, crcs=0; uint n, x; @@ -884,8 +883,9 @@ void Make_Userlist(const char* userlist) { GMsg* msg = (GMsg*)throw_calloc(1, sizeof(GMsg)); crclist = (word*)throw_calloc(AA->Msgn.Count()+1, sizeof(word)); - fp = fsopen(userlist, "ab", CFG->sharemode); - if(fp) { + gfile fp(userlist, "ab", CFG->sharemode); + if (fp.isopen()) + { w_progress(MODE_NEW, C_INFOW, 0, AA->Msgn.Count(), LNG->GenUserlist); for(n=AA->Msgn.Count(); n; n--) { update_statuslinef(LNG->ReadingMsg, "ST_READINGMSG", n, AA->Msgn.Count()); @@ -895,16 +895,16 @@ void Make_Userlist(const char* userlist) { for(x=0; x= crcs) { + if (x >= crcs) + { crclist[crcs++] = crc; strrevname(userline, msg->by); msg->orig.make_string(adrs); - fprintf(fp, "%-36.36s%24.24s\r\n", userline, adrs); + fp.Printf("%-36.36s%24.24s\r\n", userline, adrs); } } throw_free(crclist); w_progress(MODE_QUIT, BLACK_|_BLACK, 0, 0, NULL); - fclose(fp); } ResetMsg(msg); @@ -983,7 +983,6 @@ void make_pathreport(const char* reportfile) } } w_progress(MODE_QUIT, BLACK_|_BLACK, 0, 0, NULL); - fp.Fclose(); ResetMsg(msg); throw_free(msg); } diff --git a/golded3/gesoup.cpp b/golded3/gesoup.cpp index 8c7c704..d864d3a 100644 --- a/golded3/gesoup.cpp +++ b/golded3/gesoup.cpp @@ -554,8 +554,6 @@ int ImportSOUP() { AA->Close(); if (msgs) importedmsgs += msgs; - - fpm.Fclose(); } } diff --git a/golded3/getpls.cpp b/golded3/getpls.cpp index e323284..0266d02 100644 --- a/golded3/getpls.cpp +++ b/golded3/getpls.cpp @@ -69,15 +69,13 @@ inline int IsInitial(char c) { // ------------------------------------------------------------------ -int TemplateToText(int mode, GMsg* msg, GMsg* oldmsg, const char* tpl, int origarea) { - - FILE* fp; +int TemplateToText(int mode, GMsg* msg, GMsg* oldmsg, const char* tpl, int origarea) +{ long fpos; Path tplfile; int n; int x; - FILE *tfp; - FILE *ifp; + gfile fp; char* tptr; char* ptr; char* ptr2; @@ -220,56 +218,58 @@ int TemplateToText(int mode, GMsg* msg, GMsg* oldmsg, const char* tpl, int origa tmptpl = YES; // Create a temporary template mktemp(strcpy(tplfile, AddPath(CFG->temppath, "GDXXXXXX"))); - if ((fp = fsopen(tplfile, "wt", CFG->sharemode)) != NULL) + fp.Fopen(tplfile, "wt", CFG->sharemode); + if (fp.isopen()) { - fputs("@header= @oecho (@caddr) @align{79}{=}\n" - "@header Msg : @msgno of @msgs@align{44}@attr\n", fp); + fp.Fputs("@header= @oecho (@caddr) @align{79}{=}\n" + "@header Msg : @msgno of @msgs@align{44}@attr\n"); if (AA->isinternet()) { - fputs("@header From : @ofrom@align{60}@odtime\n" - "@header To : @oto\n", fp); + fp.Fputs("@header From : @ofrom@align{60}@odtime\n" + "@header To : @oto\n"); } else { - fputs("@header From : @oname@align{44}@oaddr@align{60}@odtime\n", fp); + fp.Fputs("@header From : @oname@align{44}@oaddr@align{60}@odtime\n"); if (AA->isnet()) - fputs("@header To : @dname@align{44}@daddr\n", fp); + fp.Fputs("@header To : @dname@align{44}@daddr\n"); else - fputs("@header To : @dname\n", fp); + fp.Fputs("@header To : @dname\n"); } - fputs("@header Subj : @subject\n" - "@header@align{79}{=}\n" - "@moved* Replying to a msg in @oecho (@odesc)\n@moved\n" - "@changed* Changed by @cname (@caddr), @cdate @ctime.\n@changed\n" - "@forward* Forwarded from @oecho by @fname (@faddr).\n" - "@forward* Originally by: @oname (@oaddr), @odate @otime.\n" - "@forward* Originally to: @dname{}{}{all}.\n" - "@forward\n" - "@message\n" - "@forward\n" - "Hello @pseudo{}{}{everybody}.\n" - "@new\n" - "@position\n" - "@replyReplying to a msg dated @odate @otime, from @oname{me}{you} to @dname{me}{you}{all}.\n" - "@reply@position\n" - "@quoted@odate @otime, @oname{I}{you} wrote to @dname{me}{you}{all}:\n" - "@quoted@position\n" - "@comment@odate @otime, @oname{I}{you} wrote to @dname{me}{you}{all}:\n" - "@comment@position\n" - "@quotebuf\n" - "@quotebuf@odate @otime, @oname{I}{you} wrote to @dname{me}{you}{all}:\n" - "@quotebuf\n" - "@quote\n\n" - "@cfname\n\n", fp); - fclose(fp); + fp.Fputs("@header Subj : @subject\n" + "@header@align{79}{=}\n" + "@moved* Replying to a msg in @oecho (@odesc)\n@moved\n" + "@changed* Changed by @cname (@caddr), @cdate @ctime.\n@changed\n" + "@forward* Forwarded from @oecho by @fname (@faddr).\n" + "@forward* Originally by: @oname (@oaddr), @odate @otime.\n" + "@forward* Originally to: @dname{}{}{all}.\n" + "@forward\n" + "@message\n" + "@forward\n" + "Hello @pseudo{}{}{everybody}.\n" + "@new\n" + "@position\n" + "@replyReplying to a msg dated @odate @otime, from @oname{me}{you} to @dname{me}{you}{all}.\n" + "@reply@position\n" + "@quoted@odate @otime, @oname{I}{you} wrote to @dname{me}{you}{all}:\n" + "@quoted@position\n" + "@comment@odate @otime, @oname{I}{you} wrote to @dname{me}{you}{all}:\n" + "@comment@position\n" + "@quotebuf\n" + "@quotebuf@odate @otime, @oname{I}{you} wrote to @dname{me}{you}{all}:\n" + "@quotebuf\n" + "@quote\n\n" + "@cfname\n\n"); + fp.Fclose(); } } - fp = fsopen(tplfile, "rt", CFG->sharemode); - if(fp == NULL) { + fp.Fopen(tplfile, "rt", CFG->sharemode); + if (!fp.isopen()) + { LOG.ErrOpen(); LOG.printf("! A template file could not be opened."); LOG.printf(": %s", tplfile); @@ -332,7 +332,7 @@ int TemplateToText(int mode, GMsg* msg, GMsg* oldmsg, const char* tpl, int origa size_t oldmsg_size = oldmsg->txt ? strlen(oldmsg->txt) : REALLOC_CACHE_SIZE; size_t msg_txt_realloc_cache = 0; - while(fgets(buf, sizeofbuf, fp)) + while (fp.Fgets(buf, sizeofbuf)) { ptr = strskip_wht(buf); if(*ptr != ';') { @@ -589,17 +589,21 @@ int TemplateToText(int mode, GMsg* msg, GMsg* oldmsg, const char* tpl, int origa CookieIndex(textfile, indexfile); // Get a random cookie - tfp = fsopen(textfile, "rt", CFG->sharemode); - if(tfp) { - ifp = fsopen(indexfile, "rb", CFG->sharemode); - if(ifp) { - fseek(ifp, 0L, SEEK_END); - int idxs = (int)(ftell(ifp)/sizeof(long)); - if(idxs) { - fseek(ifp, (long)(rand()%idxs)*sizeof(long), SEEK_SET); - fread(&fpos, sizeof(long), 1, ifp); - fseek(tfp, fpos, SEEK_SET); - while(fgets(buf, 255, tfp)) { + gfile tfp(textfile, "rt", CFG->sharemode); + if (tfp.isopen()) + { + gfile ifp(indexfile, "rb", CFG->sharemode); + if (ifp.isopen()) + { + ifp.Fseek(0L, SEEK_END); + int idxs = (int)(ifp.Ftell()/sizeof(long)); + if (idxs) + { + ifp.FseekSet((long)(rand()%idxs), sizeof(long)); + ifp.Fread(&fpos, sizeof(long)); + tfp.FseekSet(fpos); + while (tfp.Fgets(buf, 255)) + { strtrim(buf); if(*buf) { if(*buf == '+' and buf[1] == NUL) @@ -623,21 +627,22 @@ int TemplateToText(int mode, GMsg* msg, GMsg* oldmsg, const char* tpl, int origa break; } } - fclose(ifp); } - fclose(tfp); } } continue; case TPLTOKEN_INCLUDE: - if(mode != MODE_QUOTEBUF) { + if(mode != MODE_QUOTEBUF) + { strbtrim(ptr); strcpy(textfile, ptr); MakePathname(textfile, CFG->templatepath, textfile); - tfp = fsopen(textfile, "rt", CFG->sharemode); - if(tfp) { - while(fgets(buf, 255, tfp)) { + gfile tfp(textfile, "rt", CFG->sharemode); + if (tfp.isopen()) + { + while (tfp.Fgets(buf, 255)) + { TokenXlat(mode, buf, sizeofbuf, true, msg, oldmsg, origarea); strtrim(buf); strcat(buf, "\r"); @@ -653,7 +658,6 @@ int TemplateToText(int mode, GMsg* msg, GMsg* oldmsg, const char* tpl, int origa strcpy(&(msg->txt[pos]), buf); pos += len; } - fclose(tfp); } } continue; @@ -882,7 +886,7 @@ int TemplateToText(int mode, GMsg* msg, GMsg* oldmsg, const char* tpl, int origa loop_next: ; } - fclose(fp); + fp.Fclose(); if((mode != MODE_CHANGE) and (mode != MODE_QUOTEBUF) and (mode != MODE_HEADER) and (mode != MODE_WRITEHEADER) and diff --git a/golded3/gmarea.cpp b/golded3/gmarea.cpp index 57e2818..bdaa3fd 100644 --- a/golded3/gmarea.cpp +++ b/golded3/gmarea.cpp @@ -86,7 +86,6 @@ void WriteNoDupes(const char* file, const char* line) { fp.Fseek(0, SEEK_END); fp.Printf("%s\n", line); } - fp.Fclose(); } @@ -136,10 +135,11 @@ void FreqWaZOO(const char* files, const Addr& dest, const Attr& attr) { i++; } - FILE* fcs = fopen(tmp, "at"); - if(fcs) { - fprintf(fcs, "%s\n", buf); - fclose(fcs); + gfile fcs(tmp, "at"); + if (fcs.isopen()) + { + fcs.Printf("%s\n", buf); + fcs.Fclose(); } strcpy(tmp, filename); diff --git a/goldlib/gall/gdefs.h b/goldlib/gall/gdefs.h index 7ef47dd..cff9ef6 100644 --- a/goldlib/gall/gdefs.h +++ b/goldlib/gall/gdefs.h @@ -119,13 +119,6 @@ #endif -/* ------------------------------------------------------------------ */ -#if defined(_MSC_VER) -#define popen(f,m) _popen(f,m) -#define pclose(fh) _pclose(fh) -#endif - - /* ------------------------------------------------------------------ // Special character constants */ diff --git a/goldlib/gall/gfile.cpp b/goldlib/gall/gfile.cpp index 386fa94..d39cb9d 100644 --- a/goldlib/gall/gfile.cpp +++ b/goldlib/gall/gfile.cpp @@ -31,6 +31,9 @@ #if defined(_MSC_VER) /*&& (_MSC_VER >= 1400)*/ +#define g_popen(comm, mode) _tpopen(comm, mode) +#define g_pclose(fp) _pclose(fp) + #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) @@ -46,6 +49,9 @@ #else +#define g_popen(comm, mode) popen(comm, mode) +#define g_pclose(fp) pclose(fp) + #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) @@ -86,24 +92,24 @@ gfile::gfile() // ------------------------------------------------------------------ - +/* gfile::gfile(int __fh) { fh = __fh; fp = NULL; status = 0; } - +*/ // ------------------------------------------------------------------ - +/* gfile::gfile(FILE* __fp) { fh = -1; fp = __fp; status = 0; } - +*/ // ------------------------------------------------------------------ @@ -290,6 +296,17 @@ FILE* gfile::Fopen(const char* __path, const char* __mode, int __shflag) } +// ------------------------------------------------------------------ + +FILE* gfile::Popen(const char* __path, const char* __mode) +{ + fp = g_popen(__path, __mode); + status = (fp == NULL) ? errno : 0; + if (fp) fh = g_fileno(fp); + return fp; +} + + // ------------------------------------------------------------------ FILE* gfile::Fdopen(const char* __mode) @@ -312,6 +329,18 @@ int gfile::Fclose() return _ret; } + +// ------------------------------------------------------------------ + +int gfile::Pclose() +{ + int _ret = 0; + if (fp) _ret = g_pclose(fp); + status = _ret ? errno : 0; + fp = NULL; fh = -1; + return _ret; +} + // ------------------------------------------------------------------ size_t gfile::Fread(void* __ptr, size_t __size, size_t __items) diff --git a/goldlib/gall/gfile.h b/goldlib/gall/gfile.h index 446f3c2..9bed583 100644 --- a/goldlib/gall/gfile.h +++ b/goldlib/gall/gfile.h @@ -72,8 +72,8 @@ public: // Constructors and destructor gfile(); // Bare constructor - gfile(int __fh); // Construct from Unix file handle - gfile(FILE* __fp); // Construct from ANSI stream pointer +// gfile(int __fh); // Construct from Unix file handle +// gfile(FILE* __fp); // Construct from ANSI stream pointer gfile(const char* __path, int __access, int __shflag=SH_DENYNO, int __mode=S_IREAD|S_IWRITE); gfile(const char* __path, const char* __mode, int __shflag=SH_DENYNO); @@ -120,6 +120,10 @@ public: FILE* Fdopen (const char* __mode); int Fclose (); + FILE* Popen (const char* __path, const char* __mode); + FILE* Popen (const std::string& __path, const char* __mode) { return Popen(__path.c_str(), __mode); } + int Pclose (); + 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); diff --git a/goldlib/uulib/uunconc.c b/goldlib/uulib/uunconc.c index daf9d2e..0f30589 100644 --- a/goldlib/uulib/uunconc.c +++ b/goldlib/uulib/uunconc.c @@ -642,13 +642,13 @@ UUDecodeLine (char *s, char *d, int method) cc |= (c >> 2); if(i-- > 0) - d[count++] = cc; + d[count++] = (char)(cc & 0xFF); c <<= 6; c |= table[ACAST(*s++)]; if(i-- > 0) - d[count++] = c; + d[count++] = (char)(c & 0xFF); j -= 4; }