First three parameters to \fade() are now int as they should be

Fixed \t argument disappearance bug!

Originally committed to SVN as r48.
This commit is contained in:
Niels Martin Hansen 2006-01-29 22:46:18 +00:00
parent ba9fb80bd9
commit 6862c2d4a8
1 changed files with 63 additions and 34 deletions

View File

@ -232,9 +232,9 @@ void AssOverrideTagProto::LoadProtos () {
// \fade(<a1>,<a2>,<a3>,<t1>,<t2>,<t3>,<t4>) // \fade(<a1>,<a2>,<a3>,<t1>,<t2>,<t3>,<t4>)
proto.push_back(AssOverrideTagProto()); proto.push_back(AssOverrideTagProto());
proto.back().name = _T("\\fade"); proto.back().name = _T("\\fade");
proto.back().params.push_back(AssOverrideParamProto(VARDATA_TEXT)); proto.back().params.push_back(AssOverrideParamProto(VARDATA_INT));
proto.back().params.push_back(AssOverrideParamProto(VARDATA_TEXT)); proto.back().params.push_back(AssOverrideParamProto(VARDATA_INT));
proto.back().params.push_back(AssOverrideParamProto(VARDATA_TEXT)); proto.back().params.push_back(AssOverrideParamProto(VARDATA_INT));
proto.back().params.push_back(AssOverrideParamProto(VARDATA_INT,NOT_OPTIONAL,PARCLASS_RELATIVE_TIME_START)); proto.back().params.push_back(AssOverrideParamProto(VARDATA_INT,NOT_OPTIONAL,PARCLASS_RELATIVE_TIME_START));
proto.back().params.push_back(AssOverrideParamProto(VARDATA_INT,NOT_OPTIONAL,PARCLASS_RELATIVE_TIME_START)); proto.back().params.push_back(AssOverrideParamProto(VARDATA_INT,NOT_OPTIONAL,PARCLASS_RELATIVE_TIME_START));
proto.back().params.push_back(AssOverrideParamProto(VARDATA_INT,NOT_OPTIONAL,PARCLASS_RELATIVE_TIME_START)); proto.back().params.push_back(AssOverrideParamProto(VARDATA_INT,NOT_OPTIONAL,PARCLASS_RELATIVE_TIME_START));
@ -501,6 +501,7 @@ void AssOverrideTag::SetText (wxString text) {
// Set tag name // Set tag name
if (!Name.empty()) { if (!Name.empty()) {
wxLogDebug(_T("Parsing tag: %s"), Name);
ParseParameters(text.Mid(Name.length())); ParseParameters(text.Mid(Name.length()));
valid = true; valid = true;
} }
@ -523,42 +524,64 @@ bool AssOverrideTag::IsValid() {
///////////////////// /////////////////////
// Parses parameters // Parses parameters
void AssOverrideTag::ParseParameters(wxString text) { void AssOverrideTag::ParseParameters(wxString text) {
// Split parameters // text is all text following the name until the next \ or the end of the override block
// Tokenize text, attempting to find all parameters
wxArrayString paramList; wxArrayString paramList;
size_t start = 0;
wxString work; wxString work;
int parDepth = 0;
for (size_t i=0;i<text.Length();i++) { {
// Started an overrides block if (text.IsEmpty() || text[0] != _T('(')) {
if (text[i] == _T('\\')) { // There's just one (or none at all) parameter (because there's no parantheses)
work = text.Mid(start); // This means text is all our parameters
while (parDepth > 0 && work.Right(1) == _T(")")) { paramList.Add(text.Trim(true).Trim(false));
work = work.Left(work.Length()-1); // Only using goto here to avoid yet another nested block (keeps the code cleaner!)
work.Trim(true); goto end_tokenizing;
work.Trim(false);
parDepth--;
} }
paramList.Add(work);
start = text.Length(); // Ok, so there are parantheses used here, so there may be more than one parameter
// Enter fullscale parsing!
size_t i = 0, textlen = text.Length();
size_t start = 0;
int parDepth = 1;
while (i < textlen && parDepth > 0) {
// Just skip until next ',' or ')', whichever comes first
// (Next ')' is achieved when parDepth == 0)
start = ++i;
while (i < textlen && parDepth > 0) {
if (text[i] == _T('(')) parDepth++;
if (text[i] == _T(')')) parDepth--;
// parDepth 1 is where we start, and the tag-level we're interested in parsing on
if (text[i] == _T(',') && parDepth == 1) break;
if (parDepth < 0) {
wxLogWarning(_T("Unmatched parenthesis near '%s'!\nTag-parsing incomplete."), text.SubString(i, 10));
goto end_tokenizing;
}
if (parDepth == 0) {
// We just ate the paranthesis ending this parameter block
// Make sure it doesn't get included in the parameter text
break; break;
} }
else if (text[i] == _T(',') || text[i] == _T('(') || text[i] == _T(')')) { i++;
if (text[i] == _T('(')) parDepth++;
work = text.SubString(start,i-1);
work.Trim(true);
work.Trim(false);
if (work != _T("")) paramList.Add(work);
start = i+1;
} }
else if (text[i] == _T(')')) parDepth--; // i now points to the first character not member of this parameter
} work = text.SubString(start, i-1);
work = text.Mid(start); work.Trim(true).Trim(false);
work.Trim(true);
work.Trim(false);
if (work != _T(""))
paramList.Add(work); paramList.Add(work);
wxLogDebug(_T("Got parameter: %s"), work);
}
if (i+1 < textlen) {
// There's some additional garbage after the parantheses
// Just add it in for completeness
paramList.Add(text.Mid(i+1));
}
}
// This label is only gone to from inside the previous block, if the tokenizing needs to end early
end_tokenizing:
int curPar = 0; int curPar = 0;
int totalPars = paramList.GetCount(); size_t totalPars = paramList.GetCount();
// Get optional parameters flag // Get optional parameters flag
ASS_ParameterOptional parsFlag = OPTIONAL_0; ASS_ParameterOptional parsFlag = OPTIONAL_0;
@ -613,6 +636,9 @@ void AssOverrideTag::ParseParameters(wxString text) {
newparam->CopyFrom(curproto->defaultValue); newparam->CopyFrom(curproto->defaultValue);
} }
newparam->ommited = true; newparam->ommited = true;
// This parameter doesn't really count against the number of parsed parameters,
// since it's left out. Don't count it.
curPar--;
} }
if (isDefault == false) { if (isDefault == false) {
@ -651,9 +677,12 @@ void AssOverrideTag::ParseParameters(wxString text) {
// Get next actual parameter // Get next actual parameter
if (curPar < totalPars) { if (curPar < totalPars) {
// Unless this parameter was omitted (in which case the token shouldn't be eaten)
if (!newparam->ommited) {
curtok = paramList[curPar]; curtok = paramList[curPar];
curPar++; curPar++;
} }
}
else curtok = _T(""); else curtok = _T("");
} }
@ -670,7 +699,7 @@ wxString AssOverrideTag::ToString() {
// Start with name // Start with name
wxString result = Name; wxString result = Name;
// Determine if it needs parenthesis // Determine if it needs parentheses
bool parenthesis = false; bool parenthesis = false;
if (Name == _T("\\t") || Name == _T("\\pos") || Name == _T("\\fad") || Name == _T("\\org") || Name == _T("\\clip") || Name == _T("\\move") || Name == _T("\\fade")) parenthesis = true; if (Name == _T("\\t") || Name == _T("\\pos") || Name == _T("\\fad") || Name == _T("\\org") || Name == _T("\\clip") || Name == _T("\\move") || Name == _T("\\fade")) parenthesis = true;
if (parenthesis) result += _T("("); if (parenthesis) result += _T("(");