示例#1
0
文件: XString.cs 项目: d3x0r/xperdex
        public void Expand(StringBuilder sb)
        {
            for (int i = 0; i < tabs; i++)
            {
                sb.Append('\t');
            }
            for (int i = 0; i < spaces; i++)
            {
                sb.Append(' ');
            }

            if (PreText != null)
            {
                sb.Append(PreText);
            }
            if (actual != null)
            {
                XStringSeg tmp = actual.firstseg;
                for ( ; tmp != null; tmp = tmp.next)
                {
                    tmp.Expand(sb);
                }
            }
            if (Text != null)
            {
                sb.Append(Text);
            }
        }
示例#2
0
        //----------------------------------------------------------------------

        static bool GrabExtra(ref Types.XStringSeg word, out String result)
        {
            if (word != null)
            {
                XString type = new XString();
                {
                    while (word && ((word[0] != ',') && (word[0] != ')')))
                    {
                        if (word[0] == ')')
                        {
                            break;
                        }
                        type.Append(word.Clone());
                        word = word.Next;
                    }
                }
                if (type)
                {
                    type.Originate();
                    result = type.ToString();
                }
                else
                {
                    result = null;
                }
            }
            else
            {
                result = null;
            }
            return(true);
        }
示例#3
0
文件: XString.cs 项目: d3x0r/xperdex
 public XStringSeg(XStringSeg clone)
 {
     this.tabs    = clone.tabs;
     this.spaces  = clone.spaces;
     this.Text    = clone.Text;
     this.PreText = clone.PreText;
 }
示例#4
0
        //----------------------------------------------------------------------

        static bool GrabType(ref Types.XStringSeg word, out String result)
        {
            if (word != null)
            {
                //int quote = 0;
                //int escape = 0;
                XString    type = new XString();
                XStringSeg first_word;
                type.Append(first_word = word.Clone());
                first_word.Originate();
                word = word.Next;
                if (word && word[0] == '(')
                {
                    while (word && word[0] != ')')
                    {
                        type.Append(word.Clone());
                        word = word.Next;
                    }
                    type.Append(word.Clone());
                    word = word.Next;
                }
                result = type.ToString();
                return(true);
            }
            else
            {
                result = null;
            }
            return(false);
        }
示例#5
0
        //----------------------------------------------------------------------

        static bool GetTableExtra(XDataTable <DataRow> table, ref Types.XStringSeg word)
        {
            // prior code ended us on the ')'

            word = word.Next;
            if (word != null)
            {
                table.extra = word.ToString();
                return(true);
            }
            return(false);
        }
示例#6
0
文件: XString.cs 项目: d3x0r/xperdex
        public void Append(XStringSeg xStringSeg)
        {
            XStringSeg phrase = this;

            while (phrase != null && phrase.next != null)
            {
                phrase = phrase.next;
            }
            if (phrase != null)
            {
                phrase.next      = xStringSeg;
                xStringSeg.prior = phrase;
            }
        }
示例#7
0
        //----------------------------------------------------------------------

        static bool GrabName(ref Types.XStringSeg word, out String result, out bool bQuoted)
        {
            String name = null;

            //PTEXT start = word;
            //printf( "word is %s", GetText( *word ) );
            if (TextLike(word, "`"))
            {
                XString phrase = new XString();
                //Types.XStringSeg phrase = null;
                bQuoted = true;
                word    = word.Next;
                while (word != null && word.ToString()[0] != '`')
                {
                    phrase.Append(word.Clone());
                    word = word.Next;
                }
                // skip one more - end after the last `
                word = word.Next;
                name = phrase.ToString();
            }
            else
            {
                // don't know...
                String next;
                bQuoted = false;
                next    = word.Next;
                if (next != null && next[0] == '.')
                {
                    // database and table name...
                    word = word.Next;
                    word = word.Next;
                    name = (String)word;
                    word = word.Next;
                }
                else
                {
                    if (word.Text == "(")
                    {
                        result  = null;
                        bQuoted = false;
                        return(true);
                    }
                    name = (String)word;
                    word = word.Next;
                }
            }
            result = name;
            return((result != null) ? true : false);
        }
示例#8
0
 static void GrabKeyColumns(ref Types.XStringSeg word, ref List <String> columns)
 {
     if ((word != null) && word[0] == '(')
     {
         do
         {
             String result;
             bool   quoted;
             word = word.Next;
             GrabName(ref word, out result, out quoted);
             columns.Add(result);
         }while(word && word[0] != ')');
         word = word.Next;
     }
 }
示例#9
0
        static bool ValidateCreateTable(ref Types.XStringSeg word)
        {
            if (!TextLike(word, "create"))
            {
                return(false);
            }

            word = word.Next;

            if (TextLike(word, "temporary"))
            {
                word = word.Next;
            }
            else if (TextLike(word, "temp"))
            {
                word = word.Next;
            }

            if (!TextLike(word, "table"))
            {
                return(false);
            }

            word = word.Next;
            if (TextLike(word, "if"))
            {
                word = word.Next;
                if (TextLike(word, "not"))
                {
                    word = word.Next;
                    if (TextLike(word, "exists"))
                    {
                        word = word.Next;
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }
            }
            return(true);
        }
示例#10
0
文件: XString.cs 项目: d3x0r/xperdex
        public static XStringSeg Append(XStringSeg phrase, XStringSeg xStringSeg)
        {
            XStringSeg save = phrase;

            while (phrase != null && phrase.next != null)
            {
                phrase = phrase.next;
            }
            if (phrase != null)
            {
                phrase.next      = xStringSeg;
                xStringSeg.prior = phrase;
            }
            else
            {
                save = xStringSeg;
            }
            return(save);
        }
示例#11
0
        //----------------------------------------------------------------------

        static void AddIndexKey(XDataTable <DataRow> table, ref Types.XStringSeg word, bool has_name, bool primary, bool unique)
        {
            //table.Columns.
            XDataTableKey key = new XDataTableKey();

            //key.null = null;
            key.primary = primary;
            key.unique  = unique;
            bool quoted = false;

            if (has_name)
            {
                GrabName(ref word, out key.name, out quoted);
            }
            //else
            //	table.keys.key[table.keys.count-1].name = null;
            //table.keys.key[table.keys.count-1].colnames = New( CTEXTSTR );
            //table.keys.key[table.keys.count-1].colnames[0] = null;

            // 5.0 database this occurs before the columns
            if (word == "USING")
            {
                word = word.Next;
                if (word == "BTREE")
                {
                    word = word.Next;
                }
            }
            GrabKeyColumns(ref word, ref key.columns);
            // 5.5 database this occurs after the columns of index
            if (word == "USING")
            {
                word = word.Next;
                if (word == "BTREE")
                {
                    word = word.Next;
                }
            }
            table.keys.Add(key);
        }
示例#12
0
文件: XString.cs 项目: d3x0r/xperdex
        public static void TextParse(List <XStringSeg> outdata, String input, String punctuation, String filter_space, bool bTabs, bool bSpaces)
        {
            /* takes a line of input and creates a line equivalent to it, but
             * burst into its block peices.*/
            StringBuilder sb;
            XStringSeg    seg;

            int charnum;
            int size;

            char character;
            bool elipses = false;
            int  spaces = 0, tabs = 0;

            if (input == null)                     // if nothing new to process- return nothing processed.
            {
                return;
            }

            sb = new StringBuilder();

            //while (input)  // while there is data to process...
            {
                //tempText = GetText(input);  // point to the data to process...
                size   = input.Length;
                spaces = 0;
                tabs   = 0;
                //Log1( WIDE("Assuming %d spaces... "), spaces );
                for (charnum = 0; (charnum < size); charnum++)                    // while not at the
                // end of the line.
                {
                    character = input[charnum];
                    if (elipses && character != '.')
                    {
                        if (sb.Length > 0)
                        {
                            outdata.Add(seg = new XStringSeg(tabs, spaces, sb.ToString()));
                            if (outdata.Count > 1)
                            {
                                seg.prior = outdata[outdata.Count - 2];
                                outdata[outdata.Count - 2].next = seg;
                            }
                            sb.Length = 0;
                            tabs      = 0;
                            spaces    = 0;
                        }
                        elipses = false;
                    }
                    else if (elipses)                      // elipses and character is . - continue
                    {
                        sb.Append(character);
                        continue;
                    }
                    if (filter_space != null && filter_space.IndexOf(character) > -1)
                    {
                        if (sb.Length > 0)
                        {
                            outdata.Add(seg = new XStringSeg(tabs, spaces, sb.ToString()));
                            if (outdata.Count > 1)
                            {
                                seg.prior = outdata[outdata.Count - 2];
                                outdata[outdata.Count - 2].next = seg;
                            }
                            sb.Length = 0;
                            tabs      = 0;
                            spaces    = 0;
                        }
                        spaces++;
                    }
                    else if (punctuation != null && punctuation.IndexOf(character) > -1)
                    {
                        switch (character)
                        {
                        case '.':                                 // handle multiple periods grouped (elipses)
                            //goto NormalPunctuation;
                        {
                            char c;
                            if ((!elipses &&
                                 ((c = ((charnum + 1 < input.Length) ? input[charnum + 1] : (char)0)) != 0) &&
                                 (c == '.')))
                            {
                                if (sb.Length > 0)
                                {
                                    outdata.Add(seg = new XStringSeg(tabs, spaces, sb.ToString()));
                                    if (outdata.Count > 1)
                                    {
                                        seg.prior = outdata[outdata.Count - 2];
                                        outdata[outdata.Count - 2].next = seg;
                                    }
                                    sb.Length = 0;
                                    tabs      = 0;
                                    spaces    = 0;
                                }
                                sb.Append('.');
                                elipses = true;
                                break;
                            }
                            if (((c = ((charnum + 1 < input.Length) ? input[charnum + 1] : (char)0)) != 0) &&
                                (c >= '0' && c <= '9'))
                            {
                                // gather together as a floating point number...
                                sb.Append(character);
                                break;
                            }
                        }
                            goto skip1;

                        case '-':                                  // work seperations flaming-long-sword
                        case '+':
                        {
                            int c;
                            if (((c = ((charnum + 1 < input.Length) ? input[charnum + 1] : (char)0)) != 0) &&
                                (c >= '0' && c <= '9'))
                            {
                                if (sb.Length > 0)
                                {
                                    outdata.Add(seg = new XStringSeg(tabs, spaces, sb.ToString()));
                                    if (outdata.Count > 1)
                                    {
                                        seg.prior = outdata[outdata.Count - 2];
                                        outdata[outdata.Count - 2].next = seg;
                                    }
                                    sb.Length = 0;
                                    tabs      = 0;
                                    spaces    = 0;
                                    // gather together as a sign indication on a number.
                                }
                                sb.Append(character);
                                break;
                            }
                        }
                            //         NormalPunctuation:
                            if (sb.Length > 0)
                            {
                                outdata.Add(seg = new XStringSeg(tabs, spaces, sb.ToString()));
                                if (outdata.Count > 1)
                                {
                                    seg.prior = outdata[outdata.Count - 2];
                                    outdata[outdata.Count - 2].next = seg;
                                }
                                sb.Length = 0;
                                tabs      = 0;
                                spaces    = 0;
                                sb.Append(character);
                                outdata.Add(seg = new XStringSeg(tabs, spaces, sb.ToString()));
                                if (outdata.Count > 1)
                                {
                                    seg.prior = outdata[outdata.Count - 2];
                                    outdata[outdata.Count - 2].next = seg;
                                }
                                sb.Length = 0;
                            }
                            else
                            {
                                sb.Append(character);
                                outdata.Add(seg = new XStringSeg(tabs, spaces, sb.ToString()));
                                if (outdata.Count > 1)
                                {
                                    seg.prior = outdata[outdata.Count - 2];
                                    outdata[outdata.Count - 2].next = seg;
                                }
                                sb.Length = 0;
                                tabs      = 0;
                                spaces    = 0;
                            }
                            break;

                        default:
skip1:
                            if (elipses)
                            {
                                if (sb.Length > 0)
                                {
                                    outdata.Add(seg = new XStringSeg(tabs, spaces, sb.ToString()));
                                    if (outdata.Count > 1)
                                    {
                                        seg.prior = outdata[outdata.Count - 2];
                                        outdata[outdata.Count - 2].next = seg;
                                    }
                                    sb.Length = 0;
                                    tabs      = 0;
                                    spaces    = 0;
                                }
                                elipses = false;
                            }
                            if (sb.Length > 0)
                            {
                                outdata.Add(seg = new XStringSeg(tabs, spaces, sb.ToString()));
                                if (outdata.Count > 1)
                                {
                                    seg.prior = outdata[outdata.Count - 2];
                                    outdata[outdata.Count - 2].next = seg;
                                }
                                sb.Length = 0;
                                tabs      = 0;
                                spaces    = 0;

                                sb.Append(character);

                                outdata.Add(seg = new XStringSeg(tabs, spaces, sb.ToString()));
                                if (outdata.Count > 1)
                                {
                                    seg.prior = outdata[outdata.Count - 2];
                                    outdata[outdata.Count - 2].next = seg;
                                }
                                sb.Length = 0;
                            }
                            else
                            {
                                sb.Append(character);
                                outdata.Add(seg = new XStringSeg(tabs, spaces, sb.ToString()));
                                if (outdata.Count > 1)
                                {
                                    seg.prior = outdata[outdata.Count - 2];
                                    outdata[outdata.Count - 2].next = seg;
                                }
                                sb.Length = 0;
                                tabs      = 0;
                                spaces    = 0;
                            }
                            break;
                        }
                    }
                    else
                    {
                        switch (character)
                        {
                        case '\n':
                            if (sb.Length > 0)
                            {
                                outdata.Add(seg = new XStringSeg(tabs, spaces, sb.ToString()));
                                if (outdata.Count > 1)
                                {
                                    seg.prior = outdata[outdata.Count - 2];
                                    outdata[outdata.Count - 2].next = seg;
                                }
                                sb.Length = 0;
                                tabs      = 0;
                                spaces    = 0;
                            }

                            outdata.Add(seg = new XStringSeg(tabs, spaces, sb.ToString()));
                            if (outdata.Count > 1)
                            {
                                seg.prior = outdata[outdata.Count - 2];
                                outdata[outdata.Count - 2].next = seg;
                            }
                            sb.Length = 0;
                            tabs      = 0;
                            spaces    = 0;
                            break;

                        case ' ':
                            if (bSpaces)
                            {
                                if (sb.Length > 0)
                                {
                                    outdata.Add(seg = new XStringSeg(tabs, spaces, sb.ToString()));
                                    if (outdata.Count > 1)
                                    {
                                        seg.prior = outdata[outdata.Count - 2];
                                        outdata[outdata.Count - 2].next = seg;
                                    }
                                    sb.Length = 0;
                                    tabs      = 0;
                                    spaces    = 0;
                                }
                                spaces++;
                                break;
                            }
                            goto skip1;

                        case '\t':
                            if (bTabs)
                            {
                                if (sb.Length > 0)
                                {
                                    outdata.Add(seg = new XStringSeg(tabs, spaces, sb.ToString()));
                                    if (outdata.Count > 1)
                                    {
                                        seg.prior = outdata[outdata.Count - 2];
                                        outdata[outdata.Count - 2].next = seg;
                                    }
                                    sb.Length = 0;
                                    tabs      = 0;
                                    spaces    = 0;
                                }
                                if (spaces > 0)
                                {
                                    //lprintf( WIDE("Input stream has mangled spaces and tabs.") );
                                    spaces = 0;                                             // assume that the tab takes care of appropriate spacing
                                }
                                tabs++;
                                break;
                            }
                            goto skip1;

                        case '\r':                                 // a space space character...
                            if (sb.Length > 0)
                            {
                                outdata.Add(seg = new XStringSeg(tabs, spaces, sb.ToString()));
                                if (outdata.Count > 1)
                                {
                                    seg.prior = outdata[outdata.Count - 2];
                                    outdata[outdata.Count - 2].next = seg;
                                }
                                sb.Length = 0;
                                tabs      = 0;
                                spaces    = 0;
                            }
                            break;

                        case '.':                                 // handle multiple periods grouped (elipses)
                            //goto NormalPunctuation;
                        {
                            char c;
                            if ((!elipses &&
                                 ((c = ((charnum + 1 < input.Length) ? input[charnum + 1] : (char)0)) != 0) &&
                                 (c == '.')))
                            {
                                if (sb.Length > 0)
                                {
                                    outdata.Add(seg = new XStringSeg(tabs, spaces, sb.ToString()));
                                    if (outdata.Count > 1)
                                    {
                                        seg.prior = outdata[outdata.Count - 2];
                                        outdata[outdata.Count - 2].next = seg;
                                    }
                                    sb.Length = 0;
                                    tabs      = 0;
                                    spaces    = 0;
                                }
                                sb.Append('.');
                                elipses = true;
                                break;
                            }
                            if (((c = ((charnum + 1 < input.Length) ? input[charnum + 1] : (char)0)) != 0) &&
                                (c >= '0' && c <= '9'))
                            {
                                // gather together as a floating point number...
                                sb.Append(character);
                                break;
                            }
                        }
                            goto skip1;

#if asefsdf
                        case '-':                          // work seperations flaming-long-sword
                        case '+':
                        {
                            int c;
                            if (((c = ((charnum + 1 < input.Length) ? input[charnum + 1] : (char)0)) != 0) &&
                                (c >= '0' && c <= '9'))
                            {
                                if (sb.Length > 0)
                                {
                                    outdata.Add(seg = new XStringSeg(tabs, spaces, sb.ToString()));
                                    if (outdata.Count > 1)
                                    {
                                        seg.prior = outdata[outdata.Count - 2];
                                        outdata[outdata.Count - 2].next = seg;
                                    }
                                    sb.Length = 0;
                                    tabs      = 0;
                                    spaces    = 0;
                                    // gather together as a sign indication on a number.
                                }
                                sb.Append(character);
                                break;
                            }
                        }
                            //         NormalPunctuation:
                            if (sb.Length > 0)
                            {
                                outdata.Add(seg = new XStringSeg(tabs, spaces, sb.ToString()));
                                if (outdata.Count > 1)
                                {
                                    seg.prior = outdata[outdata.Count - 2];
                                    outdata[outdata.Count - 2].next = seg;
                                }
                                sb.Length = 0;
                                tabs      = 0;
                                spaces    = 0;
                                sb.Append(character);
                                outdata.Add(seg = new XStringSeg(tabs, spaces, sb.ToString()));
                                if (outdata.Count > 1)
                                {
                                    seg.prior = outdata[outdata.Count - 2];
                                    outdata[outdata.Count - 2].next = seg;
                                }
                                sb.Length = 0;
                            }
                            else
                            {
                                sb.Append(character);
                                outdata.Add(seg = new XStringSeg(tabs, spaces, sb.ToString()));
                                if (outdata.Count > 1)
                                {
                                    seg.prior = outdata[outdata.Count - 2];
                                    outdata[outdata.Count - 2].next = seg;
                                }
                                sb.Length = 0;
                                tabs      = 0;
                                spaces    = 0;
                            }
                            break;
#endif
                        default:
skip1:
                            if (elipses)
                            {
                                if (sb.Length > 0)
                                {
                                    outdata.Add(seg = new XStringSeg(tabs, spaces, sb.ToString()));
                                    if (outdata.Count > 1)
                                    {
                                        seg.prior = outdata[outdata.Count - 2];
                                        outdata[outdata.Count - 2].next = seg;
                                    }
                                    sb.Length = 0;
                                    tabs      = 0;
                                    spaces    = 0;
                                }
                                elipses = false;
                            }
                            sb.Append(character);
                            break;
                        }
                    }
                }
                //input = NEXTLINE( input );
            }

            if (sb.Length > 0)              // any generic outstanding data?
            {
                outdata.Add(seg = new XStringSeg(tabs, spaces, sb.ToString()));
                if (outdata.Count > 1)
                {
                    seg.prior = outdata[outdata.Count - 2];
                    outdata[outdata.Count - 2].next = seg;
                }
                sb.Length = 0;
                tabs      = 0;
                spaces    = 0;
            }
        }
示例#13
0
文件: XString.cs 项目: d3x0r/xperdex
        public static void Burst(XString outdata, string s, bool quote, bool parenthize, bool allow_escapes)
        {
            //lock( Preload )
            {
                XStringSeg    seg;
                ParenStack    paren_stack = parenthize ? new ParenStack() : null;
                StringBuilder sb          = new StringBuilder(s.Length);
                int           spaces      = 0;
                int           tabs        = 0;
                char          quote_char  = '\0';
                bool          escape      = false;
                int           charnum;
                bool          elipses = false;

                for (charnum = 0; charnum < s.Length; charnum++)
                {
                    Char character = s[charnum];

                    if (parenthize && paren_stack.Count > 0)
                    {
                        BurstParenState paren_state = paren_stack.Peek();
                        if (character == paren_state.CloseChar)
                        {
                            if (escape)
                            {
                                escape = false;
                            }
                            else
                            {
                                CollapseStringBuilder(sb, outdata, ref tabs, ref spaces);

                                paren_state.outdata_previous.Append(new XStringSeg(
                                                                        paren_state.tabs
                                                                        , paren_state.spaces
                                                                        , paren_state.OpenChar.ToString()
                                                                        , outdata
                                                                        , paren_state.CloseChar.ToString()));
                                paren_stack.Pop();

                                outdata = paren_state.outdata_previous;
                                sb      = paren_state.sb_previous;
                                continue;
                            }
                        }
                        else
                        {
                            if (allow_escapes && character == '\\')
                            {
                                escape = true;
                                continue;
                            }
                        }
                    }

                    if (quote_char != 0)
                    {
                        if (character == quote_char)
                        {
                            if (escape)
                            {
                                escape = false;
                            }
                            else
                            {
                                quote_char = '\0';
                            }
                        }
                        else
                        {
                            if (character == '\\')
                            {
                                escape = true;
                            }
                            sb.Append(character);
                        }
                        continue;
                    }

                    if (elipses && character != '.')
                    {
                        CollapseStringBuilder(sb, outdata, ref tabs, ref spaces);
                        elipses = false;
                    }
                    else if (elipses)                      // elipses and character is . - continue
                    {
                        sb.Append(character);
                        continue;
                    }

                    switch (character)
                    {
                    case '\n':
                        CollapseStringBuilder(sb, outdata, ref tabs, ref spaces);
                        outdata.Add(seg = new XStringSeg(0, 0, ""));
                        break;

                    case ' ':
                        CollapseStringBuilder(sb, outdata, ref tabs, ref spaces);
                        spaces++;
                        break;

                    case '\t':
                        CollapseStringBuilder(sb, outdata, ref tabs, ref spaces);
                        if (spaces != 0)
                        {
                            //lprintf( WIDE("Input stream has mangled spaces and tabs.") );
                            spaces = 0;
                        }
                        tabs++;
                        break;

                    case '\r':                             // a space space character...
                        CollapseStringBuilder(sb, outdata, ref tabs, ref spaces);
                        break;

                    case '.':                             // handle multiple periods grouped (elipses)
                        //goto NormalPunctuation;
                    {
                        char c;
                        if ((!elipses &&
                             ((c = ((charnum + 1 < s.Length) ? s[charnum + 1] : (char)0)) != 0) &&
                             (c == '.')))
                        {
                            CollapseStringBuilder(sb, outdata, ref tabs, ref spaces);
                            sb.Append(".");
                            elipses = true;
                            break;
                        }
                        if (((c = ((charnum + 1 < s.Length) ? s[charnum + 1] : (char)0)) != 0) &&
                            (c >= '0' && c <= '9'))
                        {
                            // gather together as a floating point number...
                            sb.Append(character);
                            break;
                        }
                    }
                        goto continue_case;

                    case '-':                              // work seperations flaming-long-sword
                        goto continue_case;

                    case '+':
continue_case:
                        {
                            int c;
                            if (((c = ((charnum + 1 < s.Length) ? s[charnum + 1] : 0)) != 0) &&
                                (c >= '0' && c <= '9'))
                            {
                                CollapseStringBuilder(sb, outdata, ref tabs, ref spaces);
                                // gather together as a sign indication on a number.
                                sb.Append(character);
                                break;
                            }
                        }
                        goto continue_case2;

                    case '\'':                             // single quote bound
                    case '\"':                             // double quote bound
                        if (quote)
                        {
                            CollapseStringBuilder(sb, outdata, ref tabs, ref spaces);
                            paren_stack.PushParen(character, character, ref outdata, ref sb, ref tabs, ref spaces);
                            break;
                        }
                        goto continue_case2;

                    case '(':                             // expression bounders
                        if (parenthize)
                        {
                            CollapseStringBuilder(sb, outdata, ref tabs, ref spaces);
                            paren_stack.PushParen(character, ')', ref outdata, ref sb, ref tabs, ref spaces);
                            break;
                        }
                        goto continue_case2;

                    case '{':
                        if (parenthize)
                        {
                            CollapseStringBuilder(sb, outdata, ref tabs, ref spaces);
                            paren_stack.PushParen(character, '}', ref outdata, ref sb, ref tabs, ref spaces);
                            break;
                        }
                        goto continue_case2;

                    case '[':
                        if (parenthize)
                        {
                            CollapseStringBuilder(sb, outdata, ref tabs, ref spaces);
                            paren_stack.PushParen(character, ']', ref outdata, ref sb, ref tabs, ref spaces);
                            break;
                        }
                        goto continue_case2;

                    case '<':
                        if (parenthize)
                        {
                            CollapseStringBuilder(sb, outdata, ref tabs, ref spaces);
                            paren_stack.PushParen(character, '>', ref outdata, ref sb, ref tabs, ref spaces);
                            break;
                        }
                        goto continue_case2;

                    case ')':                             // expression closers
                    case '}':
                    case ']':
                    case '>':

                    case '\\':                             // escape next thingy... unusable in c processor
                    case ':':                              // internet addresses
                    case '@':                              // email addresses
                    case '%':
                    case '/':
                    case ',':
                    case ';':
                    case '!':
                    case '?':
                    case '=':
                    case '*':
                    case '&':
                    case '$':
                    case '^':
                    case '~':
                    case '#':
                    case '`':
continue_case2:
                        //         NormalPunctuation:
                        CollapseStringBuilder(sb, outdata, ref tabs, ref spaces);

                        sb.Append(character);

                        /*
                         * if( parenthize && paren_stack.Count > 0 )
                         * {
                         *      BurstParenState state = paren_stack.Peek();
                         *
                         *      // if it is in a paren condition, then
                         *      // don't put this out yet... otherwise emit directly.
                         *      state.outdata.Add( seg = new XStringSeg( tabs, spaces, sb.ToString() ) );
                         *      if( state.outdata.Count > 1 )
                         *      {
                         *              seg.prior = state.outdata[state.outdata.Count - 2];
                         *              state.outdata[state.outdata.Count - 2].next = seg;
                         *      }
                         *      sb.Length = 0;
                         *      tabs = 0;
                         *      spaces = 0;
                         * }
                         * else
                         */
                        CollapseStringBuilder(sb, outdata, ref tabs, ref spaces);
                        break;

                    default:
                        if (elipses)
                        {
                            if (sb.Length > 0)
                            {
                                outdata.Append(seg = new XStringSeg(tabs, spaces, sb.ToString()));
                                sb.Length          = 0;
                                tabs   = 0;
                                spaces = 0;
                            }
                            elipses = false;
                        }
                        sb.Append(character);
                        break;
                    }
                }
                // here at the end I have collection without a push.
                if (sb.Length > 0)
                {
                    outdata.Append(seg = new XStringSeg(tabs, spaces, sb.ToString()));
                    sb.Length          = 0;
                    tabs   = 0;
                    spaces = 0;
                }
            }
        }
示例#14
0
        static bool GetTableColumns(XDataTable <DataRow> table, ref Types.XStringSeg word)
        {
            if (word == null)
            {
                return(false);
            }
            //DebugBreak();
            if (word[0] != '(')
            {
                //PTEXT line;
                Log.log("Failed to find columns... extra data between table name and columns....");
                Log.log("Failed at " + word);
                return(false);
            }
            while (word != null && word[0] != ')')
            {
                String name  = null;
                String type  = null;
                String extra = null;
                bool   bQuoted;
                word = word.Next;
                while (word.Text.Length == 0)
                {
                    word = word.Next;
                }

                //if( word && GetText( *word )[0] == ',' )
                //	word = NEXTLINE( *word );
                if (!GrabName(ref word, out name, out bQuoted))
                {
                    Log.log("Failed column parsing...");
                }
                else
                {
                    if (!bQuoted)
                    {
                        if (TextLike(name, ")"))
                        {
                            // close of the SQL columns.
                            break;
                        }
                        else if (TextLike(name, "CONSTRAINT"))
                        {
                            XDataTable <DataRow> .XDataTableForeignKey fk = new XDataTable <DataRow> .XDataTableForeignKey();

                            bool con_quote;
                            if (!TextLike(word, "FOREIGN"))
                            {
                                GrabName(ref word, out fk.keyname, out con_quote);
                            }
                            if (TextLike(word, "FOREIGN"))
                            {
                                word = word.Next;
                                if (TextLike(word, "KEY"))
                                {
                                    word = word.Next;
                                    if (word != "(")
                                    {
                                        bool key_quoted;
                                        GrabName(ref word, out fk.child_indexname, out key_quoted);
                                        // no name
                                    }
                                    if (word == "(")
                                    {
                                        GrabKeyColumns(ref word, ref fk.child_columns);
                                    }
                                    else
                                    {
                                        Log.log("parse failure.");
                                    }
                                }
                            }
                            if (TextLike(word, "REFERENCES"))
                            {
                                word = word.Next;
                                {
                                    bool key_quoted;
                                    GrabName(ref word, out fk.parent_table, out key_quoted);
                                }
                                if (word == "(")
                                {
                                    GrabKeyColumns(ref word, ref fk.parent_columns);
                                }
                                else
                                {
                                    Log.log("parse failure.");
                                }
                            }
                            while (TextLike(word, "ON"))
                            {
                                word = word.Next;
                                if (TextLike(word, "DELETE"))
                                {
                                    word = word.Next;
                                    if (String.Compare(word, "CASCADE", true) == 0)
                                    {
                                        word             = word.Next;
                                        fk.fk_DeleteRule = Rule.Cascade;
                                    }
                                    else if (String.Compare(word, "SET", true) == 0)
                                    {
                                        word = word.Next;
                                        if (String.Compare(word, "NULL", true) == 0)
                                        {
                                            word = word.Next;

                                            fk.fk_DeleteRule = Rule.SetNull;
                                        }
                                        if (String.Compare(word, "DEFAULT", true) == 0)
                                        {
                                            word             = word.Next;
                                            fk.fk_DeleteRule = Rule.SetDefault;
                                        }
                                    }
                                    if (String.Compare(word, "RESTRICT", true) == 0)
                                    {
                                        word = word.Next;
                                        //fk.fk.DeleteRule = Rule.Restrict;
                                    }
                                    else if (String.Compare(word, "NO", true) == 0)
                                    {
                                        word = word.Next;
                                        if (String.Compare(word, "ACTION", true) == 0)
                                        {
                                            word             = word.Next;
                                            fk.fk_DeleteRule = Rule.None;
                                        }
                                    }
                                }

                                if (TextLike(word, "UPDATE"))
                                {
                                    word = word.Next;
                                    if (String.Compare(word, "CASCADE", true) == 0)
                                    {
                                        word             = word.Next;
                                        fk.fk_UpdateRule = Rule.Cascade;
                                    }
                                    else if (String.Compare(word, "SET", true) == 0)
                                    {
                                        word = word.Next;
                                        if (String.Compare(word, "NULL", true) == 0)
                                        {
                                            word             = word.Next;
                                            fk.fk_UpdateRule = Rule.SetNull;
                                        }
                                        if (String.Compare(word, "DEFAULT", true) == 0)
                                        {
                                            word             = word.Next;
                                            fk.fk_UpdateRule = Rule.SetDefault;
                                        }
                                    }
                                    if (String.Compare(word, "RESTRICT", true) == 0)
                                    {
                                        word = word.Next;
                                        //fk.fk.UpdateRule = Rule.Restrict;
                                    }
                                    else if (String.Compare(word, "NO", true) == 0)
                                    {
                                        word = word.Next;
                                        if (String.Compare(word, "ACTION", true) == 0)
                                        {
                                            word             = word.Next;
                                            fk.fk_UpdateRule = Rule.None;
                                        }
                                    }
                                }
                            }
                            table.foreign.Add(fk);
                        }
                        else if (TextLike(name, "PRIMARY"))
                        {
                            if (TextLike((String)word, "KEY"))
                            {
                                word = word.Next;
                                if (TextLike((String)word, "USING"))
                                {
                                    word = word.Next;
                                    if (TextLike((String)word, "BTREE"))
                                    {
                                        word = word.Next;
                                    }
                                }
                                AddIndexKey(table, ref word, false, true, false);
                            }
                            else
                            {
                                Log.log("PRIMARY keyword without KEY keyword is invalid.");
                            }
                        }
                        else if (TextLike(name, "UNIQUE"))
                        {
                            // these are optional words... so skip them...
                            if ((TextLike((String)word, "KEY")) ||
                                (TextLike((String)word, "INDEX")))
                            {
                                // skip this word.
                                word = word.Next;
                            }
                            AddIndexKey(table, ref word, true, false, true);
                        }
                        else if ((TextLike(name, "INDEX")) ||
                                 TextLike(name, "BTREE") ||
                                 (TextLike(name, "KEY")))
                        {
                            AddIndexKey(table, ref word, true, false, false);
                        }
                        else
                        {
                            GrabType(ref word, out type);
                            GrabExtra(ref word, out extra);
                            DataColumn dc = table.Columns.Add(name, GetType(type));
                            SetMaxLength(type, dc);
                            if (extra != null && extra.Contains("auto_increment"))
                            {
                                dc.AutoIncrement     = true;
                                dc.AutoIncrementSeed = 1;
                                dc.AllowDBNull       = false;
                            }

                            //table.fields.count++;
                            //table.fields.field = Renew( FIELD, table.fields.field, table.fields.count + 1 );
                            //table.fields.field[table.fields.count - 1].name = name;
                            //table.fields.field[table.fields.count - 1].type = type;
                            //table.fields.field[table.fields.count - 1].extra = extra;
                            //table.fields.field[table.fields.count - 1].previous_names[0] = null;
                        }
                    }
                    else
                    {
                        GrabType(ref word, out type);
                        GrabExtra(ref word, out extra);
                        DataColumn dc = table.Columns.Add(name, GetType(type));
                        SetMaxLength(name, dc);
                        if (extra != null && extra.Contains("auto_increment"))
                        {
                            dc.AutoIncrement     = true;
                            dc.AutoIncrementSeed = 1;
                            dc.AllowDBNull       = false;
                        }
                        //table.fields.count++;
                        //table.fields.field = Renew( FIELD, table.fields.field, table.fields.count + 1 );
                        //table.fields.field[table.fields.count - 1].name = name;
                        //table.fields.field[table.fields.count - 1].type = type;
                        //table.fields.field[table.fields.count - 1].extra = extra;
                        //table.fields.field[table.fields.count - 1].previous_names[0] = null;
                    }
                }
            }

            return(true);
        }