Commit fc2c1ad6 authored by Patrick Ohly's avatar Patrick Ohly
Browse files

MAKE/PARSETEXTWITHPROFILE: added remote rule name parameter

If not empty, the remote rule name is used to activate a specific
remote rule while using the profile. Otherwise the profile
is applied without any active rule, as before.

The new parameter is optional, thus macro calls without it still
work. This is thus an API extension which is backwards compatible
=> bumping revision and age. Code linked against old lib still
works, code linked against new one requires new one.
parent e14f54d1
......@@ -91,9 +91,9 @@ endif
# incompatible way, increment CURRENT and reset AGE and REVISION to
# zero. When fixing something without interface change, increment
# REVISION.
ENGINE_CURRENT = 0
ENGINE_CURRENT = 1
ENGINE_REVISION = 0
ENGINE_AGE = 0
ENGINE_AGE = 1
libsynthesis_la_LDFLAGS = -version-info $(ENGINE_CURRENT):$(ENGINE_REVISION):$(ENGINE_AGE) \
-Wl,--version-script=$(srcdir)/synthesis-linker.map
libsynthesis_la_DEPENDENCIES = $(srcdir)/synthesis-linker.map libsmltk.la
......
......@@ -5000,7 +5000,17 @@ void TMimeDirProfileHandler::setProfileMode(sInt32 aMode)
}
} // TMimeDirProfileHandler::setProfileMode
void TMimeDirProfileHandler::setRemoteRule(const string &aRemoteRuleName)
{
TSessionConfig *scP = getSession()->getSessionConfig();
TRemoteRulesList::iterator pos;
for(pos=scP->fRemoteRulesList.begin();pos!=scP->fRemoteRulesList.end();pos++) {
if((*pos)->fElementName == aRemoteRuleName) {
fAppliedRemoteRuleP = *pos;
break;
}
}
} // TMimeDirProfileHandler::setRemoteRule
// - check mode
bool TMimeDirProfileHandler::mimeModeMatch(TMimeDirMode aMimeMode)
......
......@@ -458,6 +458,9 @@ public:
// set profile options
// - mode (for those profiles that have more than one, like MIME-DIR's old/standard)
virtual void setProfileMode(sInt32 aMode);
#ifndef NO_REMOTE_RULES
virtual void setRemoteRule(const string &aRemoteRuleName);
#endif
// generate Text Data (includes header and footer)
virtual void generateText(TMultiFieldItem &aItem, string &aString);
// parse Data item (includes header and footer)
......
......@@ -166,6 +166,10 @@ public:
// set profile options
// - mode (for those profiles that have more than one, like MIME-DIR's old/standard)
virtual void setProfileMode(sInt32 aMode) { /* nop here */ };
#ifndef NO_REMOTE_RULES
// - choose remote rule by name, true if found
virtual void setRemoteRule(const string &aRemoteRuleName) { /* nop here */ }
#endif
// set related datastore (NULL for independent use e.g. from script functions)
void setRelatedDatastore(TLocalEngineDS *aRelatedDatastoreP) { fRelatedDatastoreP = aRelatedDatastoreP; };
// generate Text Data
......
......@@ -1985,7 +1985,7 @@ public:
}
// integer PARSETEXTWITHPROFILE(string textformat, string profileName [, int mode])
// integer PARSETEXTWITHPROFILE(string textformat, string profileName [, int mode = 0 = default [, string remoteRuleName = "" = other]])
static void func_ParseTextWithProfile(TItemField *&aTermP, TScriptContext *aFuncContextP)
{
bool ok = false;
......@@ -1999,8 +1999,19 @@ public:
if (profileHandlerP) {
// now we can convert
// - set the mode code (none = 0 = default)
// TODO? Shouldn't this check whether arg #2 was passed at all? If not,
// the code will segfault when trying to call getAsInteger()
profileHandlerP->setProfileMode(aFuncContextP->getLocalVar(2)->getAsInteger());
profileHandlerP->setRelatedDatastore(NULL); // no datastore in particular is related
profileHandlerP->setRelatedDatastore(NULL); // no datastore in particular is related
#ifndef NO_REMOTE_RULES
// - try to find remote rule
TItemField *field = aFuncContextP->getLocalVar(3);
if (field) {
field->getAsString(s);
if (!s.empty())
profileHandlerP->setRemoteRule(s);
}
#endif
// - convert
aFuncContextP->getLocalVar(0)->getAsString(s);
ok = profileHandlerP->parseText(s.c_str(), s.size(), *itemP);
......@@ -2012,7 +2023,7 @@ public:
} // func_ParseTextWithProfile
// string MAKETEXTWITHPROFILE(string profileName [, int mode])
// string MAKETEXTWITHPROFILE(string profileName [, int mode [, string remoteRuleName = "" = other] ])
static void func_MakeTextWithProfile(TItemField *&aTermP, TScriptContext *aFuncContextP)
{
if (aFuncContextP->fParentContextP) {
......@@ -2027,6 +2038,15 @@ public:
// - set the mode code (none = 0 = default)
profileHandlerP->setProfileMode(aFuncContextP->getLocalVar(1)->getAsInteger());
profileHandlerP->setRelatedDatastore(NULL); // no datastore in particular is related
#ifndef NO_REMOTE_RULES
// - try to find remote rule
TItemField *field = aFuncContextP->getLocalVar(2);
if (field) {
field->getAsString(s);
if (!s.empty())
profileHandlerP->setRemoteRule(s);
}
#endif
// - convert, after clearing the string (some generateText() implementations
// append instead of overwriting)
s = "";
......@@ -2075,8 +2095,8 @@ const uInt8 param_NumFormat[] = { VAL(fty_integer), VAL(fty_integer), OPTVAL(fty
const uInt8 param_Explode[] = { VAL(fty_string), REFARR(fty_none) };
const uInt8 param_parseEmailSpec[] = { VAL(fty_string), REF(fty_string), REF(fty_string) };
const uInt8 param_makeEmailSpec[] = { VAL(fty_string), VAL(fty_string) };
const uInt8 param_parseTextWithProfile[] = { VAL(fty_string), VAL(fty_string), OPTVAL(fty_integer) };
const uInt8 param_makeTextWithProfile[] = { VAL(fty_string), OPTVAL(fty_integer) };
const uInt8 param_parseTextWithProfile[] = { VAL(fty_string), VAL(fty_string), OPTVAL(fty_integer), OPTVAL(fty_string) };
const uInt8 param_makeTextWithProfile[] = { VAL(fty_string), OPTVAL(fty_integer), OPTVAL(fty_string) };
#ifdef REGEX_SUPPORT
......@@ -2174,8 +2194,8 @@ const TBuiltInFuncDef BuiltInFuncDefs[] = {
{ "PARSE_RRULE", TBuiltinStdFuncs::func_Parse_RRULE, fty_integer, 8, param_Parse_RRULE },
{ "PARSEEMAILSPEC", TBuiltinStdFuncs::func_ParseEmailSpec, fty_integer, 3, param_parseEmailSpec },
{ "MAKEEMAILSPEC", TBuiltinStdFuncs::func_MakeEmailSpec, fty_string, 2, param_makeEmailSpec },
{ "PARSETEXTWITHPROFILE", TBuiltinStdFuncs::func_ParseTextWithProfile, fty_integer, 3, param_parseTextWithProfile },
{ "MAKETEXTWITHPROFILE", TBuiltinStdFuncs::func_MakeTextWithProfile, fty_string, 2, param_makeTextWithProfile },
{ "PARSETEXTWITHPROFILE", TBuiltinStdFuncs::func_ParseTextWithProfile, fty_integer, 4, param_parseTextWithProfile },
{ "MAKETEXTWITHPROFILE", TBuiltinStdFuncs::func_MakeTextWithProfile, fty_string, 3, param_makeTextWithProfile },
{ "SYNCMLVERS", TBuiltinStdFuncs::func_SyncMLVers, fty_string, 0, NULL },
{ "ALLDAYCOUNT", TBuiltinStdFuncs::func_AlldayCount, fty_integer, 4, param_AlldayCount },
{ "MAKEALLDAY", TBuiltinStdFuncs::func_MakeAllday, fty_integer, 3, param_MakeAllday },
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment