196 lines
5.6 KiB
C#
196 lines
5.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
|
|
namespace VEPROMS.CSLA.Library
|
|
{
|
|
public partial class ROFST
|
|
{
|
|
private string _ROValue = "";
|
|
private List<string> lstRoValues;
|
|
private Dictionary<string,string> DictROVar = new Dictionary<string,string>();
|
|
|
|
public List<string> GetROReturnValue(string roval /*, DocVersionInfo docverinfo */)
|
|
{
|
|
lstRoValues = new List<string>();
|
|
DictROVar = new Dictionary<string,string>(); // set up a diction of RO defined Variables
|
|
string tmp = ProcessRO(docVerInfo.ProcessDocVersionSpecificInfo(roval), false /*, docverinfo */);
|
|
if (lstRoValues.Count == 0) // was not a multiple return value
|
|
lstRoValues.Add(tmp);
|
|
return lstRoValues;
|
|
}
|
|
|
|
private string ProcessRO(string roval, bool multiRtnVal /*, DocVersionInfo docverinfo*/)
|
|
{
|
|
string str = roval;
|
|
string rtnstr = "";
|
|
int l = roval.Length;
|
|
while (l > 0)
|
|
{
|
|
int ptr = NextDelimiter("{", str);
|
|
if (ptr == -1)
|
|
{ // add remaining text
|
|
//add(new seText(str, l));
|
|
rtnstr += str;
|
|
l = 0; // break out of while loop
|
|
}
|
|
else
|
|
{
|
|
int cnt = ptr; //(int)(ptr - str);
|
|
if (cnt > 0)
|
|
{ // add text
|
|
//add(new seText(str, cnt));
|
|
rtnstr += str.Substring(0, cnt);
|
|
l -= cnt;
|
|
//str = ptr;
|
|
str = str.Substring(ptr);
|
|
}
|
|
ptr = MatchingBrace(str) + 1;
|
|
cnt = ptr; //(int)(ptr - str);
|
|
bool nfnd = false;
|
|
string pbstr = ProcessBrace(str.Substring(1, cnt - 2), cnt - 2, ref nfnd, multiRtnVal /*, docverinfo */);
|
|
if (nfnd)
|
|
rtnstr += str.Substring(0, cnt);
|
|
// add(new seText(str, cnt));
|
|
else
|
|
rtnstr += pbstr;
|
|
l -= cnt;
|
|
//str = ptr;
|
|
str = str.Substring(ptr);
|
|
}
|
|
}
|
|
//rtnstr = rtnstr.Replace("`", @"\'b0"); // convert backquote to degree - left over from DOS days.
|
|
return rtnstr;
|
|
}
|
|
|
|
private string ProcessConditional(string cnd, string opt, int lencnd, int lenopt, bool multiRtnVal /*, DocVersionInfo docverinfo */)
|
|
{
|
|
// equaluate condition
|
|
string stat = (docVerInfo != null) ? docVerInfo.Evaluate(cnd,lencnd) : "";
|
|
int ls = stat.Length;//strlen(stat);
|
|
if (ls == 0)
|
|
return ""; // if evaluation not defined then return an empty string - no matches can be made
|
|
// look for match - remember default
|
|
string match = null;
|
|
int matchlen = 0;
|
|
string def = null;
|
|
int deflen = 0;
|
|
while (lenopt > 0 && match == null)
|
|
{
|
|
int end = MatchingBrace(opt);
|
|
int eq = opt.IndexOf('=');// strchr(opt, '=');
|
|
int len = end + 1; //(int)((end + 1) - opt); // +1 to include the '}'
|
|
int li = eq - 1;//(int)(eq - opt) - 1;
|
|
int ld = len - li - 3;// One for '{', '=' and '}'
|
|
if (def == null || eq == 1) // (!def || eq == opt+1)
|
|
{
|
|
def = opt.Substring(eq + 1); //def=eq+1;
|
|
deflen = ld;
|
|
}
|
|
if (ls == li && (stat.IndexOf(opt.Substring(1),li) > -1)) //(ls == li && !strncmp(stat, opt + 1, li))
|
|
{
|
|
match = opt.Substring(eq + 1,ld);// match = eq + 1;
|
|
matchlen = ld;
|
|
}
|
|
opt = opt.Substring(len); //opt += len;// point to the next piece
|
|
lenopt -= len;
|
|
}
|
|
// if match process option - or process default
|
|
if (match == null) //(!match)
|
|
{
|
|
match = def.Substring(0,deflen);
|
|
matchlen = deflen;
|
|
}
|
|
return ProcessRO(match, multiRtnVal /*, docverinfo */); //process(match, matchlen);
|
|
}
|
|
|
|
private string ProcessBrace(string str, int l, ref bool nfnd, bool multiRtnVal /*, DocVersionInfo docverinfo */)
|
|
{
|
|
string rtnstr = "";
|
|
int nxt = NextDelimiter("{=", str); //nextDelimiter("{=", str, l);
|
|
if (nxt == -1) // no delimiter found
|
|
{ // VarUse
|
|
//strList *found=vl->lookFor(str,l);
|
|
bool found = DictROVar.ContainsKey(str);
|
|
if (found)
|
|
rtnstr = DictROVar[str];
|
|
//add(new seVarUse(found));
|
|
else
|
|
nfnd = true;
|
|
}
|
|
else
|
|
{
|
|
if (str[nxt] == '{')
|
|
{ // conditonal or menu
|
|
if (nxt == 0) // if (nxt == str)
|
|
{ // menu
|
|
// TODO: implement Menu logic
|
|
//ml->process(str, l, vl);
|
|
//add(new seMenuUse(ml));
|
|
//lstRoValues.Add(ProcessRO(str.Substring(0,l), true));
|
|
ProcessMultiReturnValues(str, l);
|
|
}
|
|
else
|
|
{ // conditional
|
|
rtnstr = ProcessConditional(str, str.Substring(nxt), nxt, str.Length - nxt - 1, multiRtnVal /*, docverinfo */);//processCondition(str, nxt, (int)(nxt - str), l - (int)(nxt - str));
|
|
}
|
|
}
|
|
else
|
|
{ // must be variable definiton
|
|
//vl->add(str, nxt+1, (int)(nxt-str), (l - (int)(nxt-str))-1, ml);
|
|
|
|
// 'l' is the lenght up to the matching brace of the variable definition
|
|
string tmpval = ProcessRO(str.Substring(nxt + 1, l - nxt - 1), multiRtnVal /*,docverinfo */);
|
|
if (tmpval.Equals(string.Empty)) tmpval = " "; // nothing assinged to variable
|
|
DictROVar.Add(str.Substring(0, nxt), tmpval);
|
|
if (multiRtnVal)
|
|
rtnstr = tmpval;
|
|
}
|
|
}
|
|
return rtnstr;
|
|
}
|
|
|
|
private void ProcessMultiReturnValues(string str, int len)
|
|
{
|
|
string tstr = str.Substring(0, len);
|
|
while (tstr.Length > 0)
|
|
{
|
|
int idx = MatchingBrace(tstr);
|
|
lstRoValues.Add(ProcessRO(tstr.Substring(0,idx+1),true));
|
|
tstr = tstr.Substring(idx+1);
|
|
}
|
|
}
|
|
|
|
|
|
private int MatchingBrace(string str)
|
|
{
|
|
int level = 1;
|
|
int idx = 0; // the while will skip the first position (the first brace)
|
|
while (level > 0 && idx++ < str.Length)
|
|
{
|
|
switch (str[idx])
|
|
{
|
|
case '{':
|
|
level++;
|
|
break;
|
|
case '}':
|
|
level--;
|
|
break;
|
|
}
|
|
}
|
|
if (level != 0)
|
|
idx = -1; // didn't find matching brace
|
|
|
|
return idx; //length including end brace
|
|
}
|
|
|
|
private int NextDelimiter(string delim, string str)
|
|
{
|
|
int idx;
|
|
idx = str.IndexOfAny(delim.ToCharArray());
|
|
return idx;
|
|
}
|
|
|
|
}
|
|
}
|