Beispiel #1
0
        private int DecodeString(List <string> textString, string endString, int hexSize)
        {
            int        hexoff          = 0;
            string     hexstr          = string.Empty;
            string     textstr         = string.Empty;
            int        i               = 0;
            Func <int> currentPosition = () => hexoff + BufferPosition;

            if (hexSize == 0)
            {
                return(0);
            }

            while (hexoff < hexSize)
            {
                for (i = Math.Min(Table.LongestHex, hexSize - hexoff); i > 0; --i)
                {
                    int sizeLeft = BytesLeft - hexoff;
                    hexstr = string.Concat(tempbuf.GetRange(currentPosition(), Math.Min(sizeLeft, i)));

                    if (Table.LookupValue.ContainsKey(hexstr))
                    {
                        textstr = Table.LookupValue[hexstr];
                        textString.Add(textstr);
                        hexoff += hexstr.Length / 2;

                        if (textstr == endString)
                        {
                            BufferPosition += hexoff;
                            return(hexoff);
                        }
                        break;
                    }
                    else if (Table.LinkedEntries.ContainsKey(hexstr))
                    {
                        LinkedEntry l         = Table.LinkedEntries[hexstr];
                        int         hexLength = hexstr.Length / 2;
                        int         hexBytes  = hexLength + l.Number;
                        if (hexBytes <= sizeLeft)
                        {
                            textString.Add(l.Text);
                            hexoff += hexLength;
                            for (int j = 0; j < l.Number; ++j)
                            {
                                textString.Add("<$" + tempbuf[currentPosition() + j] + ">");
                            }
                            hexoff += l.Number;
                        }
                        else
                        {
                            return(-1);
                        }
                        break;
                    }
                }

                if (i == 0)
                {
                    if (StopOnUndefinedCharacter)
                    {
                        ++BufferPosition;
                        break;
                    }
                    textString.Add("<$" + tempbuf[currentPosition()] + ">");
                    ++hexoff;
                }
            }

            BufferPosition += hexoff;
            return(hexoff);
        }
Beispiel #2
0
		private bool parseLink (string line)
		{
			LinkedEntry l =  new LinkedEntry();
			int pos;
			line = line.Substring(1);
			string hexstr, textstr;
			HexValuePair tokens =  getTokens(line, true);

            if (tokens == null)
            {
                return false;
            }

			hexstr = tokens.HexNumber;
            pos = tokens.Value.LastIndexOf(',');

			if (pos == -1) {
				RecordError ("No comma, linked entry format is $XX=<text>,num");
				return false;
			}

			textstr = tokens.Value.Substring(0, pos);
			tokens.Value = tokens.Value.Substring (pos + 1);
            pos = findFirstNotOf (tokens.Value, "0123456789");

			if (pos >= 0) {
				RecordError ("Nonnumeric characters in num field, linked entry format is $XX=<text>,num");
				return false;
			}

			l.Text = textstr;
			l.Number = int.Parse (tokens.Value);

			if (ReaderType == TableReaderType.ReadTypeDump) {
                l.Text = changeControlCodes(l.Text, true);
                if (LinkedEntries.ContainsKey(hexstr))
                {
                    RecordError("Linked entry with this hex token already exists.");
                    return false;
                }
                else
                {
                    LinkedEntries.Add(hexstr, l);
                }
			} else if (ReaderType == TableReaderType.ReadTypeInsert) {
                string modString = textstr;
				modString = changeControlCodes(modString, false);
				if (LookupValue.ContainsKey(modString)) {
					RecordError("Unable to add duplicate text token, causes dumper conflicts");
					return false;
				} else {
					LookupValue.Add(modString, hexstr);
					updateLongest (hexstr, modString);
				}
			}
			return true;
		}
Beispiel #3
0
        private bool parseLink(string line)
        {
            LinkedEntry l = new LinkedEntry();
            int         pos;

            line = line.Substring(1);
            string       hexstr, textstr;
            HexValuePair tokens = getTokens(line, true);

            if (tokens == null)
            {
                return(false);
            }

            hexstr = tokens.HexNumber;
            pos    = tokens.Value.LastIndexOf(',');

            if (pos == -1)
            {
                RecordError("No comma, linked entry format is $XX=<text>,num");
                return(false);
            }

            textstr      = tokens.Value.Substring(0, pos);
            tokens.Value = tokens.Value.Substring(pos + 1);
            pos          = findFirstNotOf(tokens.Value, "0123456789");

            if (pos >= 0)
            {
                RecordError("Nonnumeric characters in num field, linked entry format is $XX=<text>,num");
                return(false);
            }

            l.Text   = textstr;
            l.Number = int.Parse(tokens.Value);

            if (ReaderType == TableReaderType.ReadTypeDump)
            {
                l.Text = changeControlCodes(l.Text, true);
                if (LinkedEntries.ContainsKey(hexstr))
                {
                    RecordError("Linked entry with this hex token already exists.");
                    return(false);
                }
                else
                {
                    LinkedEntries.Add(hexstr, l);
                }
            }
            else if (ReaderType == TableReaderType.ReadTypeInsert)
            {
                string modString = textstr;
                modString = changeControlCodes(modString, false);
                if (LookupValue.ContainsKey(modString))
                {
                    RecordError("Unable to add duplicate text token, causes dumper conflicts");
                    return(false);
                }
                else
                {
                    LookupValue.Add(modString, hexstr);
                    updateLongest(hexstr, modString);
                }
            }
            return(true);
        }