This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
deb-goldedplus/goldlib/gcfg/gxhpt.cpp

434 lines
11 KiB
C++
Raw Normal View History

2000-02-25 10:15:17 +00:00
// This may look like C code, but it is really -*- C++ -*-
// ------------------------------------------------------------------
// The Goldware Library
2002-05-12 13:07:37 +00:00
// Copyright (C) 1999-2002 Alexander S. Aganichev
2000-02-25 10:15:17 +00:00
// ------------------------------------------------------------------
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Library General Public License for more details.
//
// You should have received a copy of the GNU Library General Public
// License along with this program; if not, write to the Free
// Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
// MA 02111-1307, USA
// ------------------------------------------------------------------
// $Id$
// ------------------------------------------------------------------
// Read areas from Fidoconfig
// ------------------------------------------------------------------
#include <cstdlib>
#include <gcrcall.h>
#include <gstrall.h>
#include <gmemdbg.h>
#if defined(__GOLD_GUI__)
#include <gvidall.h>
#include <gvidgui.h>
#endif
#undef GCFG_NOFIDOCONF
2000-02-25 10:15:17 +00:00
#include <gedacfg.h>
// ------------------------------------------------------------------
2005-08-26 23:12:29 +00:00
static char comment_char = '#';
2000-02-25 10:15:17 +00:00
// ------------------------------------------------------------------
bool gareafile::ReadHPTLine(FILE* f, std::string* s, bool add, int state) {
2000-02-25 10:15:17 +00:00
std::string str;
2000-02-25 10:15:17 +00:00
char buf[81];
if(fgets(buf, 81, f) == NULL)
return false; // eof
str = buf;
if(buf[strlen(buf)-1] != '\n') {
while(fgets(buf, 81, f) != NULL) {
str += buf;
if(buf[strlen(buf)-1] == '\n')
break;
}
}
std::string::iterator ptr = str.begin();
2000-02-25 10:15:17 +00:00
// state 0: normal state
// 1: between ""
// 2: end
// 3: whitespace
while((ptr != str.end()) and (state != 2)) {
2001-04-08 08:02:01 +00:00
if(*ptr == comment_char) {
if(state != 1) {
str.erase(ptr, str.end());
state = 2;
}
}
else {
switch(*ptr) {
case '\"':
2001-11-15 11:08:21 +00:00
state = (state == 1) ? 0 : 1;
2001-04-08 08:02:01 +00:00
break;
default:
break;
}
2000-02-25 10:15:17 +00:00
}
++ptr;
}
while(not str.empty() and ((*(str.end()-1) == '\n') or (*(str.end()-1) == '\r')))
2000-02-25 10:15:17 +00:00
str.erase(str.end()-1);
const char *p = strskip_wht(str.c_str());
if(add)
*s += p;
else
*s = p;
2005-08-26 23:12:29 +00:00
return true;
2000-02-25 10:15:17 +00:00
}
// ------------------------------------------------------------------
void gareafile::gettok(char** key, char** val) {
char* p = strskip_wht(*val);
// Get the keyword
switch(*p) {
// Strip "double" quotes
case '\"':
*key = ++p;
do {
p = strskip_to(p, '\"');
if(not *p or (*(p-1) != '\\'))
break;
else
p++;
} while(*p);
break;
// Strip 'single' quotes
case '\'':
*key = ++p;
do {
p = strskip_to(p, '\'');
if(not *p or (*(p-1) != '\\'))
break;
else
p++;
} while(*p);
break;
// Strip round brackets
case '(': /*)*/
*key = ++p;
p = strskip_to(p, /*(*/ ')');
break;
// Get straight keyword
default:
*key = p;
while(*p and not isspace(*p))
p++;
}
// Nul-terminate keyword
if(*p)
*p++ = NUL;
// Skip whitespace if any
p = strskip_wht(p);
// Get the value
*val = p;
}
// ------------------------------------------------------------------
2002-10-05 21:13:23 +00:00
void gareafile::ReadHPTFile(char* path, char* file, char* origin, int group) {
2000-02-25 10:15:17 +00:00
const word CRC_ADDRESS = 0xFDD6;
const word CRC_INCLUDE = 0x379B;
2001-11-15 11:08:21 +00:00
const word CRC_NETAREA = 0x8F1C;
const word CRC_NETMAILAREA = 0xD2D7;
2000-02-25 10:15:17 +00:00
const word CRC_LOCALAREA = 0xAEC1;
const word CRC_ECHOAREA = 0x0D63;
const word CRC_DUPEAREA = 0xD8B9;
const word CRC_BADAREA = 0x8DA5;
const word CRC_SYSOP = 0x967F;
const word CRC_VERSION = 0xF78F;
2001-04-08 08:02:01 +00:00
const word CRC_COMMENTCHAR = 0xE2CC;
2002-09-29 16:06:10 +00:00
const word CRC_ECHOAREADEFAULTS = 0x2CBB;
2000-02-25 10:15:17 +00:00
2002-10-05 21:13:23 +00:00
AreaCfg aa;
2000-02-25 10:15:17 +00:00
Path buf2;
FILE* fp = fsopen(file, "rb", sharemode);
if (fp)
{
2000-02-25 10:15:17 +00:00
setvbuf(fp, NULL, _IOFBF, 8192);
if (not quiet)
STD_PRINT("* Reading " << file << std::endl);
2000-02-25 10:15:17 +00:00
aa.reset();
2002-10-11 05:54:11 +00:00
aa.type = GMB_NONE;
2003-12-10 08:35:16 +00:00
aa.basetype = fidomsgtype;
2002-10-11 05:54:11 +00:00
aa.groupid = group;
2000-02-25 10:15:17 +00:00
std::string s;
2000-02-25 10:15:17 +00:00
while(ReadHPTLine(fp, &s)) {
if(not s.empty()) {
char *alptr = throw_xstrdup(s.c_str());
char *ptr = alptr;
char* key;
char* val = ptr;
gettok(&key, &val);
switch(strCrc16(key)) {
case CRC_VERSION:
{
int ver_maj, ver_min;
sscanf(val, "%d.%d", &ver_maj, &ver_min);
if ((ver_maj != 0) and (ver_min != 15))
{
STD_PRINT("* Error: Unknown fidoconfig version " << ver_maj << '.' << ver_min << " - Skipping." << std::endl);
2000-02-25 10:15:17 +00:00
throw_xfree(alptr);
goto skip_config;
}
}
break;
case CRC_ADDRESS:
CfgAddress(val);
break;
case CRC_SYSOP:
CfgUsername(val);
break;
case CRC_INCLUDE:
strxcpy(buf2, val, sizeof(buf2));
if(strchg(buf2, '[', '%') != 0)
strchg(buf2, ']', '%');
2000-02-25 10:15:17 +00:00
MakePathname(buf2, path, buf2);
2002-10-05 21:13:23 +00:00
ReadHPTFile(path, buf2, origin, group);
2000-02-25 10:15:17 +00:00
break;
2001-04-08 08:02:01 +00:00
case CRC_COMMENTCHAR:
if((strlen(val) == 3) and (val[0] == val[2]) and strpbrk(val, "\'\""))
comment_char = val[1];
else if(*val)
comment_char = val[0];
break;
2000-02-25 10:15:17 +00:00
case CRC_NETAREA:
2001-11-15 11:08:21 +00:00
case CRC_NETMAILAREA:
2000-02-25 10:15:17 +00:00
aa.type = GMB_NET;
break;
case CRC_LOCALAREA:
case CRC_DUPEAREA:
case CRC_BADAREA:
2002-10-11 05:54:11 +00:00
aa = echoareadefaults;
2000-02-25 10:15:17 +00:00
aa.type = GMB_LOCAL;
break;
case CRC_ECHOAREA:
2002-10-05 21:13:23 +00:00
aa = echoareadefaults;
2000-02-25 10:15:17 +00:00
aa.type = GMB_ECHO;
break;
2002-09-29 16:06:10 +00:00
case CRC_ECHOAREADEFAULTS:
2002-10-05 21:13:23 +00:00
echoareadefaults.reset();
2002-09-29 16:06:10 +00:00
aa.type = GMB_DEFAULT;
2003-12-10 08:35:16 +00:00
aa.basetype = fidomsgtype;
2002-10-11 05:54:11 +00:00
aa.groupid = group;
2002-09-29 16:06:10 +00:00
break;
2000-02-25 10:15:17 +00:00
}
2002-09-29 16:06:10 +00:00
if(aa.type != GMB_NONE) {
if(aa.type == GMB_DEFAULT) {
*key = NUL;
}
else {
2000-02-25 10:15:17 +00:00
2002-09-29 16:06:10 +00:00
// Get echoid
gettok(&key, &val);
aa.setechoid(key);
2000-02-25 10:15:17 +00:00
2002-09-29 16:06:10 +00:00
// Get path
gettok(&key, &val);
}
2000-02-25 10:15:17 +00:00
// If not pass-through
if(not strieql("Passthrough", key)) {
2000-02-25 10:15:17 +00:00
if(strchg(key, '[', '%') != 0)
strchg(key, ']', '%');
aa.setpath(key);
2000-02-25 10:15:17 +00:00
gettok(&key, &val);
2001-11-15 11:08:21 +00:00
while((*key == '-') or strieql(key, "Squish") or strieql(key, "Jam") or strieql(key, "MSG")) {
2000-02-25 10:15:17 +00:00
if(strieql(key, "Squish"))
2003-12-10 08:35:16 +00:00
aa.basetype = "SQUISH";
2000-02-25 10:15:17 +00:00
else if(strieql(key, "Jam"))
2003-12-10 08:35:16 +00:00
aa.basetype = "JAM";
2001-11-15 11:08:21 +00:00
else if(strieql(key, "MSG"))
2003-12-10 08:35:16 +00:00
aa.basetype = fidomsgtype;
2000-02-25 10:15:17 +00:00
else {
char *opt = key + 1;
2005-08-26 23:12:29 +00:00
2001-11-15 11:08:21 +00:00
if(strieql(opt, "p") or strieql(opt, "$m")
or strieql(opt, "lr") or strieql(opt, "lw")
or strieql(opt, "dupeCheck") or strieql(opt, "dupehistory")
or strieql(opt, "r") or strieql(opt, "w")
or strieql(opt, "l") or strieql(opt, "fperm")
or strieql(opt, "fowner") or strnieql(opt, "sbadd(", 6)
or strnieql(opt, "sbign(", 6)) {
2005-08-26 23:12:29 +00:00
2000-02-25 10:15:17 +00:00
gettok(&key, &val);
}
else if(strieql(opt, "a")) {
2005-08-26 23:12:29 +00:00
2000-02-25 10:15:17 +00:00
gettok(&key, &val);
CfgAddress(key);
aa.aka.set(key);
}
else if(strieql(opt, "h") or strieql(opt, "manual")
or strieql(opt, "nopause") or strieql(opt, "mandatory")
2001-11-15 11:08:21 +00:00
or strieql(opt, "dosfile") or strieql(opt, "ccoff")
or strieql(opt, "b") or strieql(opt, "tinysb")
or strieql(opt, "killsb") or strieql(opt, "keepunread")
or strieql(opt, "killread") or strieql(opt, "h")
or strieql(opt, "nolink") or strieql(opt, "debug")
or strieql(opt, "nopack") or strieql(opt, "keepsb")
or strieql(opt, "$") or strieql(opt, "0")) {
2000-02-25 10:15:17 +00:00
}
2001-11-15 11:08:21 +00:00
else if(strieql(opt, "g")) {
2005-08-26 23:12:29 +00:00
2000-02-25 10:15:17 +00:00
gettok(&key, &val);
2005-08-26 23:12:29 +00:00
2002-05-12 13:07:37 +00:00
if(isdigit(*key))
aa.groupid = 0x8000+atoi(key);
else if(g_isalpha(*key))
aa.groupid = g_toupper(*key);
2000-02-25 10:15:17 +00:00
}
else if (strieql(opt, "d")) {
2005-08-26 23:12:29 +00:00
2000-02-25 10:15:17 +00:00
gettok(&key, &val);
aa.setdesc(key);
}
2003-10-23 10:44:32 +00:00
else if (strieql(opt, "pass")) {
aa.type = GMB_NONE;
break;
}
2000-02-25 10:15:17 +00:00
}
gettok(&key, &val);
}
2005-08-26 23:12:29 +00:00
2002-09-29 16:06:10 +00:00
aa.setorigin(origin);
2000-02-25 10:15:17 +00:00
switch(aa.type) {
case GMB_NET:
aa.attr = attribsnet;
2003-12-10 08:35:16 +00:00
if(*aa.basetype == '\0')
aa.basetype = fidomsgtype;
2002-09-29 16:06:10 +00:00
AddNewArea(aa);
2000-02-25 10:15:17 +00:00
break;
case GMB_ECHO:
aa.attr = attribsecho;
2003-12-10 08:35:16 +00:00
if(*aa.basetype == '\0')
aa.basetype = fidomsgtype;
2002-09-29 16:06:10 +00:00
AddNewArea(aa);
2000-02-25 10:15:17 +00:00
break;
case GMB_LOCAL:
aa.attr = attribslocal;
2003-12-10 08:35:16 +00:00
if(*aa.basetype == '\0')
aa.basetype = fidomsgtype;
2002-09-29 16:06:10 +00:00
AddNewArea(aa);
break;
case GMB_DEFAULT:
2002-10-05 21:13:23 +00:00
echoareadefaults = aa;
2002-09-29 16:06:10 +00:00
break;
default:
2000-02-25 10:15:17 +00:00
break;
}
}
aa.reset();
}
throw_xfree(alptr);
}
}
skip_config:
fclose(fp);
}
}
// ------------------------------------------------------------------
// Read areas from HPT (echomail processor)
void gareafile::ReadHPT(char* tag) {
char origin[80];
char options[80];
word defaultgroup = 0;
Path file, path;
*origin = NUL;
*file = NUL;
strcpy(options, tag);
char* ptr = strtok(tag, " \t");
while(ptr) {
if(*ptr != '-')
strcpy(file, ptr);
else {
if(g_toupper(*(++ptr)) == 'G') {
2000-02-25 10:15:17 +00:00
if(*(++ptr) == '=')
ptr++;
if(*ptr == '#')
defaultgroup = (word)(atoi(ptr+1)+0x8000u);
else
defaultgroup = (word)(g_isupper(*ptr) ? *ptr : 0);
2000-02-25 10:15:17 +00:00
}
}
ptr = strtok(NULL, " \t");
}
if(not *file and ((ptr = getenv("FIDOCONFIG"))!=NULL))
strcpy(file, ptr);
extractdirname(path, file);
CfgSquishuserpath(path);
2000-02-25 10:15:17 +00:00
CfgJAMSMAPIHighwater(true);
2002-10-05 21:13:23 +00:00
echoareadefaults.type = GMB_NONE;
2003-12-10 08:35:16 +00:00
echoareadefaults.basetype = fidomsgtype;
2002-10-05 21:13:23 +00:00
echoareadefaults.groupid = defaultgroup;
ReadHPTFile(path, file, origin, defaultgroup);
2000-02-25 10:15:17 +00:00
}
// ------------------------------------------------------------------