Refactoring!
This commit is contained in:
@@ -997,11 +997,10 @@ bool operator<(CmdKey &a, CmdKey &b) {
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
|
||||
int ReadKeysCfg(int force) {
|
||||
|
||||
int ReadKeysCfg(int force)
|
||||
{
|
||||
byte ch;
|
||||
gkey* mac;
|
||||
FILE *ifp;
|
||||
char* ptr;
|
||||
char* ptr2;
|
||||
int keytype;
|
||||
@@ -1011,8 +1010,8 @@ int ReadKeysCfg(int force) {
|
||||
uint line=0;
|
||||
|
||||
const char* cfg = AddPath(CFG->goldpath, CFG->keyscfg);
|
||||
ifp = fsopen(cfg, "rt", CFG->sharemode);
|
||||
if (ifp)
|
||||
gfile ifp(cfg, "rt", CFG->sharemode);
|
||||
if (ifp.isopen())
|
||||
{
|
||||
const char* cfgname = strrchr(cfg, '\\');
|
||||
cfgname = cfgname ? cfgname+1 : cfg;
|
||||
@@ -1025,7 +1024,8 @@ int ReadKeysCfg(int force) {
|
||||
if(CFG->switches.get(keybdefaults))
|
||||
SetKeybDefaults();
|
||||
|
||||
while(fgets(buf, sizeof(buf), ifp)) {
|
||||
while (ifp.Fgets(buf, sizeof(buf)))
|
||||
{
|
||||
line++;
|
||||
ptr = strskip_wht(buf);
|
||||
if(*ptr == ';' or strblank(ptr))
|
||||
@@ -1146,7 +1146,7 @@ int ReadKeysCfg(int force) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
fclose(ifp);
|
||||
ifp.Fclose();
|
||||
}
|
||||
|
||||
// Setup default keyset when no keys are defined
|
||||
|
@@ -613,41 +613,42 @@ static int CmpEsc(const char* a, const char* b) {
|
||||
// ------------------------------------------------------------------
|
||||
// Read the translation tables
|
||||
|
||||
void ReadXlatTables() {
|
||||
|
||||
if(not CFG->xlatcharset.empty() or not CFG->xlatescset.empty()) {
|
||||
|
||||
void ReadXlatTables()
|
||||
{
|
||||
if (not CFG->xlatcharset.empty() or not CFG->xlatescset.empty())
|
||||
{
|
||||
Esc EscTable;
|
||||
Chs ChsTable;
|
||||
char buf[256];
|
||||
char* ptr;
|
||||
char* ptr2;
|
||||
FILE *ifp, *ofp;
|
||||
int line, n, x, y, ch=0;
|
||||
|
||||
ofp = fsopen(AddPath(CFG->goldpath, CFG->xlatged), "wb", CFG->sharemode);
|
||||
if(ofp) {
|
||||
|
||||
gfile ofp(AddPath(CFG->goldpath, CFG->xlatged), "wb", CFG->sharemode);
|
||||
if (ofp.isopen())
|
||||
{
|
||||
// Compile CHARSET tables
|
||||
std::vector<Map>::iterator xlt;
|
||||
for(xlt = CFG->xlatcharset.begin(); xlt != CFG->xlatcharset.end(); xlt++) {
|
||||
|
||||
for (xlt = CFG->xlatcharset.begin(); xlt != CFG->xlatcharset.end(); xlt++)
|
||||
{
|
||||
// Assign table defaults
|
||||
memset(&ChsTable, 0, sizeof(Chs));
|
||||
for(n=0; n<256; n++) {
|
||||
ChsTable.t[n][0] = 1;
|
||||
ChsTable.t[n][1] = (uint8_t)n; // The character
|
||||
}
|
||||
|
||||
strcpy(buf, AddPath(CFG->xlatpath, xlt->mapfile));
|
||||
ifp = fsopen(buf, "rb", CFG->sharemode);
|
||||
if (ifp)
|
||||
gfile ifp(buf, "rb", CFG->sharemode);
|
||||
if (ifp.isopen())
|
||||
{
|
||||
if (not quiet)
|
||||
STD_PRINTNL("* Reading " << buf);
|
||||
|
||||
// Read the definition file
|
||||
line = 1;
|
||||
while(fgets(buf, sizeof(buf), ifp)) {
|
||||
while (ifp.Fgets(buf, sizeof(buf)))
|
||||
{
|
||||
ptr = buf;
|
||||
if(*ptr != ';' and not strblank(ptr)) {
|
||||
if((ptr2 = strchr(ptr+2, ';')) != NULL)
|
||||
@@ -722,29 +723,29 @@ void ReadXlatTables() {
|
||||
line++;
|
||||
}
|
||||
}
|
||||
fclose(ifp);
|
||||
}
|
||||
else
|
||||
STD_PRINTNL("* XLAT table " << buf << " could not be opened.");
|
||||
|
||||
fwrite(&ChsTable, sizeof(Chs), 1, ofp);
|
||||
ofp.Fwrite(&ChsTable, sizeof(Chs));
|
||||
}
|
||||
|
||||
// Compile ESCSET tables
|
||||
for(xlt = CFG->xlatescset.begin(); xlt != CFG->xlatescset.end(); xlt++) {
|
||||
|
||||
for (xlt = CFG->xlatescset.begin(); xlt != CFG->xlatescset.end(); xlt++)
|
||||
{
|
||||
// Assign defaults
|
||||
memset(&EscTable, 0, sizeof(Esc));
|
||||
strcpy(buf, AddPath(CFG->xlatpath, xlt->mapfile));
|
||||
ifp = fsopen(buf, "rb", CFG->sharemode);
|
||||
if (ifp)
|
||||
gfile ifp(buf, "rb", CFG->sharemode);
|
||||
if (ifp.isopen())
|
||||
{
|
||||
if (not quiet)
|
||||
STD_PRINTNL("* Reading " << buf);
|
||||
|
||||
// Read the definition file
|
||||
line = 1;
|
||||
while(fgets(buf, sizeof(buf), ifp)) {
|
||||
while (ifp.Fgets(buf, sizeof(buf)))
|
||||
{
|
||||
ptr = buf;
|
||||
if(*ptr != ';' and not strblank(ptr)) {
|
||||
if((ptr2 = strchr(ptr+2, ';')) != NULL)
|
||||
@@ -800,16 +801,12 @@ void ReadXlatTables() {
|
||||
}
|
||||
|
||||
qsort(EscTable.t, EscTable.size, 5, (StdCmpCP)CmpEsc);
|
||||
|
||||
fclose(ifp);
|
||||
}
|
||||
else
|
||||
STD_PRINTNL("* XLAT table " << buf << " could not be opened.");
|
||||
|
||||
fwrite(&EscTable, sizeof(Esc), 1, ofp);
|
||||
ofp.Fwrite(&EscTable, sizeof(Esc));
|
||||
}
|
||||
|
||||
fclose(ofp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user