Пример #1
0
 /* Call this to reinitialize the node stack.  It is called
  * automatically by the parser's ReInit() method. */
 internal void reset()
 {
     nodes.Clear();
     marks.Clear();
     sp = 0;
     mk = 0;
 }
        public void Initialize_Hanoi()
        {
            /*
             * The function start_hanoi starts with placing the parts on the left side. It also initializes all three stacks.
             * Placing elements on the canvas starting from the left side.
             */
            int x_setleft = 50;

            Canvas.SetLeft(r_Large0, x_setleft);
            Canvas.SetLeft(r_MidLarge1, x_setleft += 15);
            Canvas.SetLeft(r_Mid2, x_setleft      += 15);
            Canvas.SetLeft(r_Small3, x_setleft    += 15);
            Canvas.SetLeft(r_Small4, x_setleft    += 15);

            // Place the elements on the canvas starting from the top.
            Canvas.SetTop(r_Large0, y_settop0);
            Canvas.SetTop(r_MidLarge1, y_settop1);
            Canvas.SetTop(r_Mid2, y_settop2);
            Canvas.SetTop(r_Small3, y_settop3);
            Canvas.SetTop(r_Small4, y_settop4);

            // All elements are inserted via stack-operations in the right order in the left stack.
            // It is very important to clear the stack before using it!
            Stack_Start.Clear();
            Stack_Start.Push(r_Large0);
            Stack_Start.Push(r_MidLarge1);
            Stack_Start.Push(r_Mid2);
            Stack_Start.Push(r_Small3);
            Stack_Start.Push(r_Small4);

            // Makes sure that the other stack are empty at the beginning.
            Stack_Support.Clear();
            Stack_Destination.Clear();
        }
Пример #3
0
        /// <summary> The front-end has finished so we pop the
        /// stack until it empty
        /// </summary>
        private ValueExp done()
        {
            while (m_opStack.Count > 0)
            {
                popOperation();
            }

            /* should only have one entry on the expression stack */
            ValueExp tree = (ValueExp)m_expStack.Pop();

            if (m_expStack.Count != 0 || m_opStack.Count != 0)
            {
                /* clear the stacks */
                m_expStack.Clear();

                m_opStack.Clear();

                throw new IncompleteExpressionException();
            }

            return(tree);
        }
Пример #4
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void parse(Lexico scanner, Semantico semanticAnalyser) throws LexicalError, SyntaticError, SemanticError
    public virtual void parse(Lexico scanner, Semantico semanticAnalyser)
    {
        this.scanner          = scanner;
        this.semanticAnalyser = semanticAnalyser;

        stack.Clear();
        stack.Push(new int?(Constants_Fields.DOLLAR));
        stack.Push(new int?(ParserConstants_Fields.START_SYMBOL));

        currentToken = scanner.nextToken();

        while (!step())
        {
            ;
        }
    }
Пример #5
0
        void NotifyWork()
        {
            NotifyEventObject notifyObj;
             System.Collections.Stack stack = new System.Collections.Stack();
             while (true)
             {

             try
             {

                         if (notifyQueue.Count == 0)
                         {
                             lock (notifyQueue)
                             {
                                 System.Threading.Monitor.Wait(notifyQueue);
                             }
                         }
                         else
                         {
                             stack.Clear();
                             notifyObj = (NotifyEventObject)notifyQueue.Dequeue();
                             foreach (ClientConnection cn in clientStreamArray)
                             {
                                 try
                                 {

                                     if (cn.IsConnected)
                                     {
                                         cn.DoNotify((NotifyEventObject)notifyObj);
                                         // cnt++;
                                     }
                                     else
                                     {
                                         Console.WriteLine("client dead");
                                         stack.Push(cn);
                                     }

                                 }
                                 catch (Exception ex)
                                 {
                                     Console.WriteLine("client dead" + ex.Message);
                                     stack.Push(cn);

                                     //clientStreamArray.Remove(stream);
                                 }
                             }
                             while (stack.Count > 0)
                             {
                                 ClientConnection cc = (ClientConnection)stack.Pop();
                                 clientStreamArray.Remove(cc);
                                 cc.Dispose();
                             }

                     }

                 //lock (clientStreamArray)
                 //{

                 //}
             }
             catch (Exception ex)
             {
                 Console.WriteLine(ex.Message + ex.StackTrace);
             }

             }
        }
Пример #6
0
        private bool ToPostfix()
        {
            System.Object prevTok = null;
            System.Object currTok;
            bool          end = false;

            postfixStack.Clear();
            operatorStack.Clear();

            for (int i = 0; i < tokenList.Count; i++)
            {
                currTok = tokenList[i];

                if (currTok.GetType() == typeof(Operator))
                {
                    switch (((Operator)currTok).type)
                    {
                    case OperatorType.LPAREN:
                        if (prevTok != null)
                        {
                            if ((prevTok.GetType() == typeof(Operator) && (
                                     (Operator)prevTok).type == OperatorType.RPAREN) ||
                                prevTok.GetType() == typeof(Operand))
                            {
                                lastError = "Parse error, unexpected left parenthesis";
                                return(false);
                            }
                            else if (prevTok.GetType() != typeof(FunctionCall))
                            {
                                operatorStack.Push(currTok);
                            }
                        }
                        else
                        {
                            operatorStack.Push(currTok);
                        }
                        end = false;
                        break;

                    case OperatorType.ARGSEP:
                    case OperatorType.RPAREN:
                        if (prevTok != null && (
                                prevTok.GetType() == typeof(Operand) || (
                                    prevTok.GetType() == typeof(Operator) &&
                                    ((Operator)prevTok).type == OperatorType.RPAREN)))
                        {
                            while (operatorStack.Count != 0 &&
                                   operatorStack.Peek().GetType() != typeof(FunctionCall) &&
                                   operatorStack.Peek().GetType() == typeof(Operator) &&
                                   ((Operator)operatorStack.Peek()).type != OperatorType.LPAREN)
                            {
                                postfixStack.Push(operatorStack.Pop());
                            }

                            if (((Operator)currTok).type == OperatorType.RPAREN)
                            {
                                if (operatorStack.Count != 0 &&
                                    operatorStack.Peek().GetType() == typeof(Operator) &&
                                    ((Operator)operatorStack.Peek()).type == OperatorType.LPAREN)
                                {
                                    operatorStack.Pop();
                                }
                                else if (operatorStack.Count != 0 && operatorStack.Peek().GetType() == typeof(FunctionCall))
                                {
                                    postfixStack.Push(operatorStack.Pop());
                                }
                                else
                                {
                                    lastError = "Parse error, unbalanced parenthesis";
                                    return(false);
                                }

                                while (operatorStack.Count != 0 &&
                                       operatorStack.Peek().GetType() == typeof(Operator) &&
                                       ((Operator)operatorStack.Peek()).type == OperatorType.UNARY)
                                {
                                    postfixStack.Push(operatorStack.Pop());
                                }
                            }
                            else if (operatorStack.Count == 0 || operatorStack.Peek().GetType() != typeof(FunctionCall))
                            {
                                lastError = "Parse error, no matching function to argument separator";
                                return(false);
                            }
                        }
                        else
                        {
                            lastError = ((Operator)currTok).type == OperatorType.RPAREN ?
                                        "Parse error, unexpected right parenthesis" :
                                        "Parse error, unexpected argument separator";

                            return(false);
                        }
                        end = true;
                        break;

                    case OperatorType.BINARY:
                        if (((Operator)currTok).semantic == OperatorSemantics.Subtract && (prevTok == null || (
                                                                                               prevTok.GetType() == typeof(Operator) &&
                                                                                               ((Operator)prevTok).type != OperatorType.RPAREN)))
                        {
                            currTok = new Operator(OperatorType.UNARY, FunctionDefinitions.Neg, 0);
                            goto UnaryContext;
                        }

                        if (prevTok == null || (prevTok.GetType() == typeof(FunctionCall) || (
                                                    prevTok.GetType() == typeof(Operator) &&
                                                    ((Operator)prevTok).type != OperatorType.RPAREN)))
                        {
                            lastError = "Parse error, unexpected binary operator";
                            return(false);
                        }

                        while (operatorStack.Count != 0 &&
                               operatorStack.Peek().GetType() == typeof(Operator) &&
                               ((Operator)operatorStack.Peek()).type != OperatorType.LPAREN &&
                               ((Operator)operatorStack.Peek()).precedence <= ((Operator)currTok).precedence)
                        {
                            postfixStack.Push(operatorStack.Pop());
                        }

                        operatorStack.Push(currTok);
                        end = false;
                        break;

                    case OperatorType.UNARY:
UnaryContext:

                        if (prevTok != null && (prevTok.GetType() == typeof(Operand) || (
                                                    prevTok.GetType() == typeof(Operator) &&
                                                    ((Operator)prevTok).type == OperatorType.RPAREN)))
                        {
                            lastError = "Parse error, unexpected unary operator";
                            return(false);
                        }

                        operatorStack.Push(currTok);
                        end = false;
                        break;
                    }
                }
                else if (currTok.GetType() == typeof(Operand))
                {
                    if (prevTok != null && (
                            prevTok.GetType() == typeof(Operand) || (
                                prevTok.GetType() == typeof(Operator) && ((Operator)prevTok).type == OperatorType.RPAREN)))
                    {
                        lastError = "Parse error, unexpected operand";
                        return(false);
                    }

                    postfixStack.Push(currTok);

                    while (operatorStack.Count != 0 &&
                           operatorStack.Peek().GetType() == typeof(Operator) &&
                           ((Operator)operatorStack.Peek()).type == OperatorType.UNARY)
                    {
                        postfixStack.Push(operatorStack.Pop());
                    }

                    end = true;
                }
                else if (currTok.GetType() == typeof(FunctionCall))
                {
                    if (prevTok != null && (
                            prevTok.GetType() == typeof(Operand) || (
                                prevTok.GetType() == typeof(Operator) && ((Operator)prevTok).type == OperatorType.RPAREN)))
                    {
                        lastError = "Parse error, unexpected function";
                        return(false);
                    }

                    operatorStack.Push(currTok);
                    end = false;
                }

                prevTok = currTok;
            }

            if (!end)
            {
                lastError = "Parse error, Unexpected end of expression";
                return(false);
            }

            while (operatorStack.Count != 0)
            {
                if ((operatorStack.Peek().GetType() == typeof(Operator) && (
                         (Operator)operatorStack.Peek()).type == OperatorType.LPAREN) ||
                    operatorStack.Peek().GetType() == typeof(FunctionCall))
                {
                    lastError = "Parse error, unbalanced parenthesis at end of expression";
                    return(false);
                }
                else
                {
                    postfixStack.Push(operatorStack.Pop());
                }
            }

            return(true);
        }
Пример #7
0
        private bool EvaluatePostfix()
        {
            operandStack.Clear();
            Operand num;

            System.Array postfix = postfixStack.ToArray();
            System.Array.Reverse(postfix);

            foreach (var token in postfix)
            {
                if (token.GetType() == typeof(Operator))
                {
                    num = new Operand();

                    switch (((Operator)token).type)
                    {
                    case OperatorType.BINARY:
                        if (operandStack.Count < 2)
                        {
                            lastError = "Evaluation error, a binary operator needs 2 operands";
                            return(false);
                        }

                        operandStack.Push(((Operator)token).semantic(ref num,
                                                                     ((Operand)operandStack.Pop()), ((Operand)operandStack.Pop())));
                        break;

                    case OperatorType.UNARY:
                        if (operandStack.Count < 1)
                        {
                            lastError = "Evaluation error, an unary operator needs 1 operand";
                            return(false);
                        }

                        operandStack.Push(((Operator)token).semantic(ref num,
                                                                     ((Operand)operandStack.Pop())));
                        break;
                    }
                }
                else if (token.GetType() == typeof(Operand))
                {
                    operandStack.Push(token);
                }
                else if (token.GetType() == typeof(FunctionCall))
                {
                    num = new Operand();
                    argumentList.Clear();

                    for (int i = 0; i < ((FunctionCall)token).args; i++)
                    {
                        if (operandStack.Count != 0)
                        {
                            argumentList.Add(operandStack.Pop());
                        }
                        else
                        {
                            lastError = "Evaluation error, wrong argument count";
                            return(false);
                        }
                    }

                    operandStack.Push(((FunctionCall)token).definition(ref num,
                                                                       (Operand[])argumentList.ToArray(typeof(Operand))));
                }
            }

            if (operandStack.Count != 1)
            {
                lastError = "Evaluation error, unstacked operands";
                return(false);
            }

            lastResult = ((Operand)operandStack.Peek());
            varTable.Remove("ans");
            varTable.Add("ans", lastResult);
            return(true);
        }
 /* Utility methods */
 private void clearDisplay() // clear display also clears the state of the data
 {
     display.Text = "";
     displayValue = 0;
     operationsStack.Clear();
 }
Пример #9
0
        private void createOPFAuto(string strPath)
        {
            //fbdSplit.ShowDialog();
            string strSavePath = strPath;
            System.Collections.Stack stkImgs;
            stkImgs = new System.Collections.Stack();
            stkImgs.Clear();
            MatchCollection mc;

            if (strSavePath.Length > 2)
            {

                try
                {

                    Application.UseWaitCursor = true;
                    toolStripStatusLabel1.Text = "Creating .OPF File... Please Wait";
                    this.Refresh();
                    string strContent = "";

                    string[] strLines;

                    strContent = rtbContent.Text;
                    strLines = strContent.Split('\n');
                    long i = strLines.Length;

                    toolStripProgressBar1.Maximum = Convert.ToInt32(i) + 1;
                    toolStripProgressBar1.Minimum = 1;
                    toolStripProgressBar1.Value = 1;
                    this.Refresh();

                    StreamWriter swFiles;
                    string strFileNames = "";
                    string strChapterTitle = "";
                    bool blSplitStart = false;
                    bool blIdFound = false;
                    bool blSrcFound = false;
                    bool blTitleFound = false;
                    bool blATitleFound = false;
                    string strWrite = "";

                    string strIdFound = "";
                    string strSrcFound = "";
                    string strTitleFound = "";
                    string strATitleFound = "";
                    long lnImgIDCount = 1;

                    swFiles = new StreamWriter(strSavePath + "\\content.opf");

                    swFiles.WriteLine("<?xml version=\"1.0\"?>\n" +
                        "<package version=\"2.0\" xmlns=\"http://www.idpf.org/2007/opf\"\n" +
                        "         unique-identifier=\"isbn\">\n" +
                        " <metadata xmlns:dc=\"http://purl.org/dc/elements/1.1/\"\n" +
                        "           xmlns:opf=\"http://www.idpf.org/2007/opf\">\n" +
                        "   <dc:title>***Book Name***</dc:title> \n" +
                        "   <dc:creator>***Author Name***</dc:creator>\n" +
                        "   <dc:language>en-US</dc:language> \n" +
                        "   <dc:rights>***Copyright***</dc:rights>\n" +
                        "   <dc:publisher>***Publisher***</dc:publisher>\n" +
                        "   <dc:identifier id=\"isbn\">****</dc:identifier>\n" +
                        "   <meta name=\"cover\" content=\"cover-image\"/>  \n" +
                        " </metadata>\n" +
                        " <manifest>\n" +
                        "\n" +
                        "<!-- Images -->\n");

                    for (int j = 0; j < i; j++)
                    {

                        mc = Regex.Matches(strLines[j], "<img src=\"([^\"]+)\"");

                        foreach (Match singleMc in mc)
                        {

                            if (stkImgs.Contains(singleMc.Result("$1")) == false)
                            {
                                stkImgs.Push(singleMc.Result("$1"));
                                swFiles.WriteLine("  <item href=\"" + singleMc.Result("$1") + "\" id=\"img_" + lnImgIDCount.ToString() + "\" media-type=\"image/jpeg\"/>");
                                lnImgIDCount++;
                            }

                        }

                        toolStripProgressBar1.Value = j + 1;

                    }

                    swFiles.WriteLine("<!-- NCX -->\n" +
                        "\n" +
                        "<item id=\"ncx\" href=\"toc.ncx\" media-type=\"application/x-dtbncx+xml\"/>\n" +
                        "\n" +
                        " <!-- CSS Style Sheets -->\n" +
                        "\n" +
                        "<item id=\"style_bv\" href=\"bv_ebook_style.css\" media-type=\"text/css\"/>\n" +
                        "<item id=\"style_basic\" href=\"stylesheet.css\" media-type=\"text/css\"/>\n" +
                        "<item id=\"pagetemplate\" href=\"page-template.xpgt\" media-type=\"application/vnd.adobe-page-template+xml\"/>\n" +
                        "<!-- Content Documents -->\n" +
                        "\n");

                    string strIDRef = " <spine toc=\"ncx\">";

                    for (int j = 0; j < i; j++)
                    {

                        if (strLines[j].StartsWith("<split"))
                        {
                            strFileNames = Regex.Replace(strLines[j], "^<split filename=\"([^<>]+)\">$", "$1");
                            blSplitStart = true;
                            //swFiles.WriteLine("      <content src=\"" + strFileNames + "\"/>");
                            blSrcFound = true;
                            strSrcFound = strFileNames;

                        }

                        if (strLines[j].StartsWith("<div>") == true)
                        {
                            j++;
                            if (strLines[j].StartsWith("<a id=") == true)
                            {
                                strChapterTitle = Regex.Replace(strLines[j], "^<a id=\"([^<]*)\"></a>(.*)$", "$1");
                                //swFiles.WriteLine("    <navPoint class=\"chapter\" id=\"" + strChapterTitle + "\" playOrder=\"1\">");
                                blIdFound = true;
                                strIdFound = strChapterTitle;

                            }

                        }

                        if (strLines[j].StartsWith("</split"))
                        {
                            strWrite = "";
                            if (blIdFound == true)
                            {

                                if (blSrcFound == true)
                                {
                                    strWrite = "  <item id=\"" + strIdFound + "\" href=\"" + strSrcFound + "\" media-type=\"application/xhtml+xml\"/>";
                                    swFiles.WriteLine(strWrite);

                                    strIDRef = strIDRef + "\n" + "  <itemref idref=\"" + strIdFound + "\" linear=\"yes\" />";

                                }

                            }

                            blIdFound = false;
                            blSrcFound = false;
                            blTitleFound = false;
                            blATitleFound = false;

                            strIdFound = "";
                            strSrcFound = "";
                            strTitleFound = "";
                            strATitleFound = "";

                            blSplitStart = false;
                        }

                        toolStripProgressBar1.Value = j + 1;

                    }

                    swFiles.WriteLine("  </manifest>\n");

                    swFiles.WriteLine(strIDRef);

                    swFiles.WriteLine("<guide>");

                    for (int j = 0; j < i; j++)
                    {

                        if (strLines[j].StartsWith("<split"))
                        {
                            strFileNames = Regex.Replace(strLines[j], "^<split filename=\"([^<>]+)\">$", "$1");
                            blSplitStart = true;
                            //swFiles.WriteLine("      <content src=\"" + strFileNames + "\"/>");
                            blSrcFound = true;
                            strSrcFound = strFileNames;

                        }

                        if (strLines[j].StartsWith("<head>") == true)
                        {
                            j++;
                            if (strLines[j].StartsWith("<title>") == true)
                            {
                                strChapterTitle = Regex.Replace(strLines[j], "^<title>(.*)</title>$", "$1");
                                //swFiles.WriteLine("        <text>" + strChapterTitle + "</text>");
                                blTitleFound = true;
                                strTitleFound = strChapterTitle;
                            }

                        }

                        if (strLines[j].StartsWith("<h2 class=\"chaptertitle\">") == true)
                        {

                            strChapterTitle = Regex.Replace(strLines[j], "^<h2 class=\"chaptertitle\">(.*)</h2>$", "$1");
                            strChapterTitle = RemoveTag(strChapterTitle);
                            blATitleFound = true;
                            strATitleFound = strChapterTitle;

                        }

                        if (strLines[j].StartsWith("<div>") == true)
                        {
                            j++;
                            if (strLines[j].StartsWith("<a id=") == true)
                            {
                                strChapterTitle = Regex.Replace(strLines[j], "^<a id=\"([^<]*)\"></a>(.*)$", "$1");
                                //swFiles.WriteLine("    <navPoint class=\"chapter\" id=\"" + strChapterTitle + "\" playOrder=\"1\">");
                                blIdFound = true;
                                strIdFound = strChapterTitle;

                            }

                        }

                        if (strLines[j].StartsWith("</split"))
                        {
                            strWrite = "";
                            if (blIdFound == true)
                            {
                                strWrite = strIdFound;
                                if (blATitleFound == true)
                                {
                                    //strATitleFound
                                }
                                else
                                {
                                    if (blTitleFound == true)
                                    {
                                        strATitleFound = strTitleFound;
                                    }

                                }

                                strWrite = "<reference type=\"text\"\n" +
                                "		   title=\"" + strATitleFound + "\"\n" +
                                "          href=\"" + strSrcFound + "\"/>";

                                swFiles.WriteLine(strWrite);
                            }

                            blIdFound = false;
                            blSrcFound = false;
                            blTitleFound = false;
                            blATitleFound = false;

                            strIdFound = "";
                            strSrcFound = "";
                            strTitleFound = "";
                            strATitleFound = "";

                            blSplitStart = false;
                        }

                        toolStripProgressBar1.Value = j + 1;

                    }

                    swFiles.WriteLine("</guide>\n</package>");

                    swFiles.Flush();
                    swFiles.Close();

                    this.Refresh();

                    rtbContent.Text = string.Join("\n", strLines);
                    toolStripProgressBar1.Value = toolStripProgressBar1.Maximum;

                    toolStripStatusLabel1.Text = "Ready";
                    Application.UseWaitCursor = false;
                }
                catch
                {
                    MessageBox.Show("Unexpected Error", "ERR", MessageBoxButtons.OK);

                }
            }
        }
Пример #10
0
        private void ConvertFile2HTML()
        {
            Application.UseWaitCursor = true;
            toolStripStatusLabel1.Text = "Converting to HTML ... Please Wait";
            this.Refresh();
            string strContent = "";

            string[] strLines;

            stkIDs = new System.Collections.Stack();
            stkIDs.Clear();

            strContent = rtbContent.Text;
            strLines = strContent.Split('\n');
            long i = strLines.Length;

            toolStripProgressBar1.Maximum = Convert.ToInt32(i)+1;
            toolStripProgressBar1.Minimum = 1;
            toolStripProgressBar1.Value = 1;
            toolStripStatusLabel1.Text = "Creating TOC ... Please Wait";
            this.Refresh();

            //strIDPrefix

            //string strIDPrefix = "images/978-1-933988-54-2-text_img_";

            #region Variable Decl

            long lnPart = 0;
            long lnChapter = 0;
            long lnAppendix = 0;
            long lnPreface = 0;
            long lnSect1 = 0;
            long lnSect2 = 0;
            long lnSect3 = 0;
            long lnSidebar = 0;
            long lnFigure = 0;
            long lnTable = 0;
            long lnOrderedList = 0;
            long lnExample = 0;

            bool blAppendix = false;
            bool blSidebar = false;
            bool blitemizedlist = false;
            bool blorderedlist = false;
            bool blSectionStart = false;
            bool blblockquote = false;
            bool blCopyrightPage = false;
            bool blTable = false;
            bool blNote = false;
            bool blNoteStart = false;
            bool blProgramListingStart = false;
            bool blExampleStart = false;
            bool blTipStart = false;

            string strChapterNumber = "";
            string strCurrentFileName = "";
            string strTempID = "";
            string strTempID2 = "";
            string strTempID3 = "";
            string strTempID4 = "";
            string strTempID5 = "";
            string strTempID6 = "";
            string strTempID7 = "";
            #endregion

            #region Looping Through Lines

            #region Content

            strContent = rtbContent.Text;
            strLines = strContent.Split('\n');
            i = strLines.Length;
            string[] strContentsFile = new string[i];
            string[] strBrfContentsFile = new string[i];
            string strCtTitle = "";
            string strCtID = "";
            int intCtIndex = 0;
            int intBfCtIndex = 0;

            for (int j = 0; j < i; j++)
            {
                if (strLines[j].StartsWith("<chapter ") || strLines[j].StartsWith("<part ") || strLines[j].StartsWith("<preface ") || strLines[j].StartsWith("<sect1 ") || strLines[j].StartsWith("<sect2 ") || strLines[j].StartsWith("<appendix "))
                {
                    if (strLines[j].IndexOf("label=") >= 0)
                    {
                        strChapterNumber = Regex.Replace(strLines[j], "^(.*) label=\"([^\"]+)\"(.*)$", "$2") +" " ;
                    }
                    else
                    {
                        strChapterNumber = "";
                    }

                    if (strLines[j].IndexOf(" id=") > 0)
                    {
                        strTempID7 = Regex.Replace(strLines[j], "^(.*) id=\"([^\"]*)\"(.*)$", "$2");
                    }
                    else
                    {
                        strTempID7 = "";
                    }

                    j++;
                    if (strLines[j].StartsWith("<title>"))
                    {
                        strTempID6 = Regex.Replace(strLines[j], "^<title>(.*)</title>$", "$1");
                    }

                    j++;

                    if (strLines[j].StartsWith("<title>"))
                    {
                        strTempID6 = Regex.Replace(strLines[j], "^<title>(.*)</title>$", "$1");
                    }

                    strContentsFile[intCtIndex] = "<link linkend=\"" + strTempID7 + "\">" + strChapterNumber + strTempID6 + "</link><br/>";
                    intCtIndex++;
                }

                toolStripProgressBar1.Value = j + 1;

            }

            string strXML1 = "<split filename=\"toc.xhtml\">\n"+
                        "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n" +
                        "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">\n" +
                        "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" +
                        "<head>\n" +
                        "<title>Contents</title>\n" +
                        "<link href=\"bv_ebook_style.css\" rel=\"stylesheet\" type=\"text/css\"/>\n" +
                        "<link rel=\"stylesheet\" type=\"application/vnd.adobe-page-template+xml\" href=\"page-template.xpgt\"/>\n" +
                        "</head>\n" +
                        "<body>\n" +
                        "<div>\n<a id=\"toc\"></a>\n";

            //rtbContent.Text = strXML1 + string.Join("\n", strContentsFile, 0, intCtIndex) + "\n</div>\n</body>\n</html>\n</split>\n" + rtbContent.Text;

            #endregion

            #region Breif_contents
            toolStripStatusLabel1.Text = "Creating Breif Contents ... Please Wait";
            toolStripProgressBar1.Value = 1;

            for (int j = 0; j < i; j++)
            {
                if (strLines[j].StartsWith("<chapter ")) //strLines[j].StartsWith("<part ") || strLines[j].StartsWith("<preface ") || strLines[j].StartsWith("<appendix ")
                {
                    if (strLines[j].IndexOf("label=") >= 0)
                    {
                        strChapterNumber = Regex.Replace(strLines[j], "^(.*) label=\"([^\"]+)\"(.*)$", "$2") + " " + "<img src=\"" + strIDPrefix + "015.jpg\" width=\"5\" height=\"5\" alt=\"icon014\"/> ";
                    }
                    else
                    {
                        strChapterNumber = "<img src=\"" + strIDPrefix + "015.jpg\" width=\"5\" height=\"5\" alt=\"icon014\"/> ";
                    }

                    if (strLines[j].IndexOf(" id=") > 0)
                    {
                        strTempID7 = Regex.Replace(strLines[j], "^(.*) id=\"([^\"]*)\"(.*)$", "$2");
                    }
                    else
                    {
                        strTempID7 = "";
                    }

                    j++;
                    if (strLines[j].StartsWith("<title>"))
                    {
                        strTempID6 = Regex.Replace(strLines[j], "^<title>(.*)</title>$", "$1");
                    }

                    j++;

                    if (strLines[j].StartsWith("<title>"))
                    {
                        strTempID6 = Regex.Replace(strLines[j], "^<title>(.*)</title>$", "$1");
                    }

                    strBrfContentsFile[intBfCtIndex] = "<link linkend=\"" + strTempID7 + "\">" + strChapterNumber + strTempID6 + "</link><br/>";
                    intBfCtIndex++;
                }

                if (strLines[j].StartsWith("<part "))
                {
                    if (strLines[j].IndexOf("label=") >= 0)
                    {
                        strChapterNumber = "<b>P<small>ART</small> " + Regex.Replace(strLines[j], "^(.*) label=\"([^\"]+)\"(.*)$", "$2") + " " + "<img src=\"" + strIDPrefix + "015.jpg\" width=\"5\" height=\"5\" alt=\"icon014\"/> ";
                    }
                    else
                    {
                        strChapterNumber = "<img src=\"" + strIDPrefix + "015.jpg\" width=\"5\" height=\"5\" alt=\"icon014\"/> ";
                    }

                    if (strLines[j].IndexOf(" id=") > 0)
                    {
                        strTempID7 = Regex.Replace(strLines[j], "^(.*) id=\"([^\"]*)\"(.*)$", "$2");
                    }
                    else
                    {
                        strTempID7 = "";
                    }

                    j++;
                    if (strLines[j].StartsWith("<title>"))
                    {
                        strTempID6 = Regex.Replace(strLines[j], "^<title>(.*)</title>$", "$1");
                    }

                    j++;

                    if (strLines[j].StartsWith("<title>"))
                    {
                        strTempID6 = Regex.Replace(strLines[j], "^<title>(.*)</title>$", "$1").ToUpper().Insert(1, "<small>") + "</small></b>";
                    }

                    strBrfContentsFile[intBfCtIndex] = "<br/>\n<link linkend=\"" + strTempID7 + "\">" + strChapterNumber + strTempID6 + "</link><br/><br/>";
                    intBfCtIndex++;
                }

                toolStripProgressBar1.Value = j + 1;

            }

            string strXML2 = "<split filename=\"brief_contents.xhtml\">\n" +
                        "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n" +
                        "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">\n" +
                        "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" +
                        "<head>\n" +
                        "<title>Brief Contents</title>\n" +
                        "<link href=\"bv_ebook_style.css\" rel=\"stylesheet\" type=\"text/css\"/>\n" +
                        "<link rel=\"stylesheet\" type=\"application/vnd.adobe-page-template+xml\" href=\"page-template.xpgt\"/>\n" +
                        "</head>\n" +
                        "<body>\n" +
                        "<div>\n<a id=\"brief_contents\"></a>\n<h2 class=\"chaptertitle\">brief contents</h2>\n";

            rtbContent.Text = strXML1 + string.Join("\n", strContentsFile, 0, intCtIndex) + "\n</div>\n</body>\n</html>\n</split>\n" + strXML2 + string.Join("\n", strBrfContentsFile, 0, intBfCtIndex) + "\n</div>\n</body>\n</html>\n</split>\n" + rtbContent.Text;

            #endregion

            this.Refresh();

            strContent = rtbContent.Text;
            strLines = strContent.Split('\n');
            i = strLines.Length;
            toolStripStatusLabel1.Text = "Converting to HTML ... Please Wait";
            toolStripProgressBar1.Maximum = Convert.ToInt32(i) + 1;
            toolStripProgressBar1.Minimum = 1;
            toolStripProgressBar1.Value = 1;
            //Creating IDs
            for (int j = 0; j < i; j++)
            {

                #region Chapters

                if (strLines[j].StartsWith("<chapter ")) // || strLines[j].StartsWith("<appendix") || strLines[j].StartsWith("<part") || strLines[j].StartsWith("<glossary")) // || strLines[j].StartsWith("<preface")
                {
                    lnChapter++;
                    blSectionStart = true;
                    strChapterNumber = Regex.Replace(strLines[j], "^(.*) label=\"([^\"]*)\"(.*)$", "$2");

                    if (strLines[j].IndexOf(" id=") > 0)
                    {
                        strTempID7 = Regex.Replace(strLines[j], "^(.*) id=\"([^\"]*)\"(.*)$", "$2");
                    }
                    else
                    {
                        strTempID7 = "";
                    }

                    strCurrentFileName = "chap" + lnChapter.ToString("00") + ".xhtml";

                    strLines[j] = "<split filename=\"chap" + lnChapter.ToString("00") + ".xhtml\">\n" +
                            "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n" +
                            "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">\n" +
                            "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" +
                            "<head>\n" +
                            "<title>Chapter " + strChapterNumber + "</title>\n" +
                            "<link href=\"bv_ebook_style.css\" rel=\"stylesheet\" type=\"text/css\"/>\n" +
                            "<link rel=\"stylesheet\" type=\"application/vnd.adobe-page-template+xml\" href=\"page-template.xpgt\"/>\n" +
                            "</head>\n" +
                            "<body>\n" +
                            "<div>\n" +
                            "<a id=\"" + strTempID7 + "\"></a>";

                    j++;

                    //MessageBox.Show(strLines[j]);

                    strLines[j] = GeneralReplace(strLines[j]);

                            //<a id=\"page_3\"></a><h2 class=\"chaptertitle\">1<br/>SOA essentials</h2>";

                    j++;
                    //MessageBox.Show(strLines[j]);
                    if (strLines[j].StartsWith("<title>")) // || strLines[j].StartsWith("<appendix") || strLines[j].StartsWith("<part") || strLines[j].StartsWith("<glossary")) // || strLines[j].StartsWith("<preface")
                    {
                        strLines[j] = Regex.Replace(strLines[j], "^<title>(.*)</title>$", "<h2 class=\"chaptertitle\">" + strChapterNumber + "<br/>$1</h2>");
                        //MessageBox.Show(strLines[j]);
                    }
                    //<title>SOA essentials</title>
                    //<h2 class="chaptertitle">1<br/>SOA essentials</h2>
                    //MessageBox.Show(strLines[j]);

                }

                #endregion

                #region Prefaces

                if (strLines[j].StartsWith("<preface ")) // || strLines[j].StartsWith("<appendix") || strLines[j].StartsWith("<part") || strLines[j].StartsWith("<glossary")) // || strLines[j].StartsWith("<preface")
                {
                    lnPreface++;
                    blSectionStart = true;
                    strChapterNumber = Regex.Replace(strLines[j], "^(.*) id=\"([^\"]*)\"(.*)$", "$2");

                    if (strLines[j].IndexOf(" id=") > 0)
                    {
                        strTempID7 = Regex.Replace(strLines[j], "^(.*) id=\"([^\"]*)\"(.*)$", "$2");
                    }
                    else
                    {
                        strTempID7 = "";
                    }

                    strCurrentFileName = "pref" + lnPreface.ToString("00") + ".xhtml";
                    strLines[j] = "<split filename=\"pref" + lnPreface.ToString("00") + ".xhtml\">\n" +
                            "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n" +
                            "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">\n" +
                            "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" +
                            "<head>";

                    j=j+2;

                    if (strLines[j].StartsWith("<title>")) // || strLines[j].StartsWith("<appendix") || strLines[j].StartsWith("<part") || strLines[j].StartsWith("<glossary")) // || strLines[j].StartsWith("<preface")
                    {
                        strLines[j - 2] = strLines[j - 2] + strLines[j] + "\n<link href=\"bv_ebook_style.css\" rel=\"stylesheet\" type=\"text/css\"/>\n" +
                            "<link rel=\"stylesheet\" type=\"application/vnd.adobe-page-template+xml\" href=\"page-template.xpgt\"/>\n" +
                            "</head>\n" +
                            "<body>\n" +
                            "<div>\n" +
                            "<a id=\"" + strTempID7 + "\"></a>";
                        //MessageBox.Show(strLines[j]);
                        if (strLines[j].IndexOf("copyright", StringComparison.InvariantCultureIgnoreCase) > 0)
                        {
                            blCopyrightPage = true;
                        }

                    }
                    strLines[j] = "";
                    j = j - 1;

                    //MessageBox.Show(strLines[j]);

                    strLines[j-1] = strLines[j-1] + GeneralReplace(strLines[j]);
                    strLines[j] = "";

                    //<a id=\"page_3\"></a><h2 class=\"chaptertitle\">1<br/>SOA essentials</h2>";

                    j = j + 2;
                    //MessageBox.Show(strLines[j]);

                    //<title>SOA essentials</title>
                    //<h2 class="chaptertitle">1<br/>SOA essentials</h2>
                    //MessageBox.Show(strLines[j]);

                }

                #endregion

                #region Closing Chapter, Part and Preface etc..

                if (strLines[j].StartsWith("</chapter>") || strLines[j].StartsWith("</partintro>") || strLines[j].StartsWith("</preface>") || strLines[j].StartsWith("</appendix>"))
                {
                    blCopyrightPage = false;
                    strLines[j] = "</div>\n</body>\n</html>\n</split>";

                    if (strLines[j].StartsWith("</appendix>"))
                    {
                        blAppendix = false;
                    }

                }

                if (strLines[j].StartsWith("<partintro>"))
                {
                    strLines[j] = "";
                }

                #endregion

                #region Part

                if (strLines[j].StartsWith("<part ")) // || strLines[j].StartsWith("<appendix") || strLines[j].StartsWith("<part") || strLines[j].StartsWith("<glossary")) // || strLines[j].StartsWith("<preface")
                {
                    lnPart++;
                    blSectionStart = true;
                    //MessageBox.Show(strLines[j]);
                    strChapterNumber = Regex.Replace(strLines[j], "^(.*) label=\"([^\"]*)\"(.*)$", "$2");

                    if (strLines[j].IndexOf(" id=") > 0)
                    {
                        strTempID7 = Regex.Replace(strLines[j], "^(.*) id=\"([^\"]*)\"(.*)$", "$2");
                    }
                    else
                    {
                        strTempID7 = "";
                    }

                    //MessageBox.Show(strChapterNumber);
                    strCurrentFileName = "part" + lnPart.ToString("00") + ".xhtml";
                    strLines[j] = "<split filename=\"part" + lnPart.ToString("00") + ".xhtml\">\n" +
                            "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n" +
                            "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">\n" +
                            "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" +
                            "<head>\n" +
                            "<title>Part " + strChapterNumber + "</title>\n" +
                            "<link href=\"bv_ebook_style.css\" rel=\"stylesheet\" type=\"text/css\"/>\n" +
                            "<link rel=\"stylesheet\" type=\"application/vnd.adobe-page-template+xml\" href=\"page-template.xpgt\"/>\n" +
                            "</head>\n" +
                            "<body>\n" +
                            "<div>\n" +
                            "<a id=\"" + strTempID7 + "\"></a>";

                    //MessageBox.Show(strLines[j]);
                    j++;

                    //MessageBox.Show(strLines[j]);

                    strLines[j] = GeneralReplace(strLines[j]);

                    //<a id=\"page_3\"></a><h2 class=\"chaptertitle\">1<br/>SOA essentials</h2>";
                    //MessageBox.Show(strLines[j]);
                    j++;
                    //MessageBox.Show(strLines[j]);
                    if (strLines[j].StartsWith("<title>")) // || strLines[j].StartsWith("<appendix") || strLines[j].StartsWith("<part") || strLines[j].StartsWith("<glossary")) // || strLines[j].StartsWith("<preface")
                    {
                        strLines[j] = Regex.Replace(strLines[j], "^<title>(.*)</title>$", "<h2 class=\"chaptertitle\">Part " + strChapterNumber + "<br/>$1</h2>");
                        //MessageBox.Show(strLines[j]);
                    }
                    //<title>SOA essentials</title>
                    //<h2 class="chaptertitle">1<br/>SOA essentials</h2>
                    //MessageBox.Show(strLines[j]);

                }
                #endregion

                #region Appendix

                if (strLines[j].StartsWith("<appendix "))
                {
                    lnAppendix++;
                    blAppendix = true;
                    blSectionStart = true;
                    if (strLines[j].IndexOf(" label=") > 0)
                    {
                        strChapterNumber = Regex.Replace(strLines[j], "^(.*) label=\"([^\"]*)\"(.*)$", "$2");
                    }
                    else
                    {
                        strChapterNumber = "";
                    }

                    if (strLines[j].IndexOf(" id=") > 0)
                    {
                        strTempID7 = Regex.Replace(strLines[j], "^(.*) id=\"([^\"]*)\"(.*)$", "$2");
                    }
                    else
                    {
                        strTempID7 = "";
                    }

                    strCurrentFileName = "appe" + lnAppendix.ToString("00") + ".xhtml";
                    strLines[j] = "<split filename=\"appe" + lnAppendix.ToString("00") + ".xhtml\">\n" +
                            "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n" +
                            "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">\n" +
                            "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" +
                            "<head>";

                    j = j + 2;

                    if (strLines[j].StartsWith("<title>")) // || strLines[j].StartsWith("<appendix") || strLines[j].StartsWith("<part") || strLines[j].StartsWith("<glossary")) // || strLines[j].StartsWith("<preface")
                    {
                        strLines[j - 2] = strLines[j - 2] + strLines[j] + "\n<link href=\"bv_ebook_style.css\" rel=\"stylesheet\" type=\"text/css\"/>\n" +
                            "<link rel=\"stylesheet\" type=\"application/vnd.adobe-page-template+xml\" href=\"page-template.xpgt\"/>\n" +
                            "</head>\n" +
                            "<body>\n" +
                            "<div>\n" +
                            "<a id=\"" + strTempID7 + "\"></a>";

                    }
                    //strLines[j] = "";
                    j = j - 1;

                    strLines[j] = strLines[j] + GeneralReplace(strLines[j]);
                    //strLines[j] = "";
                    j++;
                    if (strLines[j].StartsWith("<title>")) // || strLines[j].StartsWith("<appendix") || strLines[j].StartsWith("<part") || strLines[j].StartsWith("<glossary")) // || strLines[j].StartsWith("<preface")
                    {
                        strLines[j] = Regex.Replace(strLines[j], "^<title>(.*)</title>$", "<h2 class=\"chaptertitle\">" + strChapterNumber + "<br/>$1</h2>");
                        //MessageBox.Show(strLines[j]);
                    }
                    else
                    {
                        strLines[j] = "";
                    }

                    j++;
                    //j = j + 2;

                }

                #endregion

                #region Sect1

                if (strLines[j].StartsWith("<sect1 "))
                {
                    lnSect1++;
                    blSectionStart = true;
                    //MessageBox.Show(strLines[j]);
                    if (strLines[j].IndexOf(" label=") > 0)
                    {
                        strChapterNumber = Regex.Replace(strLines[j], "^(.*) label=\"([^\"]*)\"(.*)$", "$2") + "&#x00A0;&#x00A0;&#x00A0; ";
                    }
                    else
                    {
                        strChapterNumber = "";
                    }

                    if (strLines[j].IndexOf(" id=") > 0)
                    {
                        strTempID = " id=\"" + Regex.Replace(strLines[j], "^(.*) id=\"([^\"]*)\"(.*)$", "$2") + "\"";
                    }
                    else
                    {
                        strTempID = "";
                    }

                    //MessageBox.Show(strChapterNumber);

                    strLines[j] = ""; //"<a id=\"chapter_" + lnChapter.ToString() + "\"></a>";

                    j++;

                    strLines[j] = GeneralReplace(strLines[j]);
                    //MessageBox.Show(strLines[j]);

                    j++;
                    //MessageBox.Show(strLines[j]);
                    if (strLines[j].StartsWith("<title>")) // || strLines[j].StartsWith("<appendix") || strLines[j].StartsWith("<part") || strLines[j].StartsWith("<glossary")) // || strLines[j].StartsWith("<preface")
                    {
                        strLines[j] = Regex.Replace(strLines[j], "^<title>(.*)</title>$", "<p class=\"subhead\"" + strTempID + ">" + strChapterNumber + "$1</p>");
                        //MessageBox.Show(strLines[j]);
                    }

                }
                #endregion

                #region Sect2

                if (strLines[j].StartsWith("<sect2 ")) // || strLines[j].StartsWith("<appendix") || strLines[j].StartsWith("<part") || strLines[j].StartsWith("<glossary")) // || strLines[j].StartsWith("<preface")
                {
                    lnSect2++;
                    blSectionStart = true;
                    //MessageBox.Show(strLines[j]);
                    if (strLines[j].IndexOf(" label=") > 0)
                    {
                        strChapterNumber = Regex.Replace(strLines[j], "^(.*) label=\"([^\"]*)\"(.*)$", "$2") + "&#x00A0;&#x00A0;&#x00A0; ";
                    }
                    else
                    {
                        strChapterNumber = "";
                    }
                    //MessageBox.Show(strChapterNumber);
                    if (strLines[j].IndexOf(" id=") > 0)
                    {
                        strTempID = " id=\"" + Regex.Replace(strLines[j], "^(.*) id=\"([^\"]*)\"(.*)$", "$2") + "\"";
                    }
                    else
                    {
                        strTempID = "";
                    }

                    strLines[j] = ""; //"<a id=\"chapter_" + lnChapter.ToString() + "\"></a>";

                    j++;

                    strLines[j] = GeneralReplace(strLines[j]);
                    //MessageBox.Show(strLines[j]);

                    j++;
                    //MessageBox.Show(strLines[j]);
                    if (strLines[j].StartsWith("<title>")) // || strLines[j].StartsWith("<appendix") || strLines[j].StartsWith("<part") || strLines[j].StartsWith("<glossary")) // || strLines[j].StartsWith("<preface")
                    {
                        strLines[j] = Regex.Replace(strLines[j], "^<title>(.*)</title>$", "<p class=\"subhead1\"" + strTempID + ">" + strChapterNumber + "$1</p>");
                        //MessageBox.Show(strLines[j]);
                    }

                }

                #endregion

                #region Sect3

                if (strLines[j].StartsWith("<sect3 ")) // || strLines[j].StartsWith("<appendix") || strLines[j].StartsWith("<part") || strLines[j].StartsWith("<glossary")) // || strLines[j].StartsWith("<preface")
                {
                    lnSect3++;
                    blSectionStart = true;
                    //MessageBox.Show(strLines[j]);
                    if (strLines[j].IndexOf(" label=") > 0)
                    {
                        strChapterNumber = Regex.Replace(strLines[j], "^(.*) label=\"([^\"]*)\"(.*)$", "$2") + "&#x00A0;&#x00A0;&#x00A0; ";
                    }
                    else
                    {
                        strChapterNumber = "";
                    }
                    //MessageBox.Show(strChapterNumber);
                    if (strLines[j].IndexOf(" id=") > 0)
                    {
                        strTempID = " id=\"" + Regex.Replace(strLines[j], "^(.*) id=\"([^\"]*)\"(.*)$", "$2") + "\"";
                    }
                    else
                    {
                        strTempID = "";
                    }

                    strLines[j] = ""; //"<a id=\"chapter_" + lnChapter.ToString() + "\"></a>";

                    j++;

                    strLines[j] = GeneralReplace(strLines[j]);
                    //MessageBox.Show(strLines[j]);

                    j++;
                    //MessageBox.Show(strLines[j]);
                    if (strLines[j].StartsWith("<title>")) // || strLines[j].StartsWith("<appendix") || strLines[j].StartsWith("<part") || strLines[j].StartsWith("<glossary")) // || strLines[j].StartsWith("<preface")
                    {
                        strLines[j] = Regex.Replace(strLines[j], "^<title>(.*)</title>$", "<p class=\"subhead1\"" + strTempID + ">" + strChapterNumber + "$1</p>");
                        //MessageBox.Show(strLines[j]);
                    }

                }

                #endregion

                #region Sidebar

                if (strLines[j].StartsWith("<sidebar "))
                {
                    lnSidebar++;
                    blSidebar = true;
                    strLines[j] = "";
                    if (strLines[j].IndexOf(" id=") > 0)
                    {
                        strTempID = " id=\"" + Regex.Replace(strLines[j], "^(.*) id=\"([^\"]*)\"(.*)$", "$2") + "\"";
                    }
                    else
                    {
                        strTempID = "";
                    }
                    j++;

                    if (strLines[j].StartsWith("<title>"))
                    {
                        strLines[j] = Regex.Replace(strLines[j], "^<title>(.*)</title>$", "<p class=\"box-title\"" + strTempID + ">$1</p>");

                    }

                }

                if (strLines[j].StartsWith("</sidebar>"))
                {
                    strLines[j] = "";
                    blSidebar = false;
                    blSectionStart = true;
                }

                #endregion

                #region Note

                if (strLines[j].StartsWith("<note>"))
                {
                    strLines[j] = "";
                    blNote = true;
                    blNoteStart = true;
                }

                if (strLines[j].StartsWith("</note>"))
                {
                    strLines[j] = "";
                    blNote = false;
                    blSectionStart = true;
                }

                #endregion

                #region Programlisting

                if (strLines[j].StartsWith("<programlisting>"))
                {
                    blProgramListingStart = true;
                    strLines[j] = strLines[j].Replace("<programlisting>", "<p class=\"script\"><code>");
                    if (strLines[j].EndsWith(">") == false)
                    {
                        strLines[j] = strLines[j] + "<br/>";
                    }

                }

                //<programlisting>
                if (strLines[j].EndsWith("</programlisting>"))
                {
                    blProgramListingStart = false;
                    strLines[j] = strLines[j].Replace("</programlisting>", "</code></p>");
                    blSectionStart = true;
                }

                if (strLines[j].StartsWith("<")==false)
                {
                    if (blProgramListingStart == true)
                    {
                        strLines[j] = strLines[j] + "<br/>";

                        if (strLines[j].StartsWith(" ") == true)
                        {
                           // MessageBox.Show("[" + strLines[j].ToString() + "]");
                            strLines[j] = Regex.Replace(strLines[j], "([ ][ ])", "&#x00A0;&#x00A0;");
                            strLines[j] = Regex.Replace(strLines[j], "(&#x00A0;[ ])", "&#x00A0;&#x00A0;");
                            strLines[j] = Regex.Replace(strLines[j], "^([ ])(.*)$", "&#x00A0;$2");
                           // MessageBox.Show("[" + strLines[j].ToString() + "]");
                        }
                    }
                }

                #endregion

                #region Para

                if (strLines[j].StartsWith("<para>"))
                {
                    //Table
                    strLines[j] = Regex.Replace(strLines[j], "^<para>(.*)</para></entry>$", "<p class=\"body-text\">$1</p></td>");

                    if (strLines[j].IndexOf("<emphasis role=\"strong\">") > 0)
                    {

                        strLines[j] = Regex.Replace(strLines[j], "^<para>(.*)<emphasis role=\"strong\">(.*)</emphasis></para>$", "<p class=\"subhead2\">$1$2</p>");
                    }

                    if (blSidebar == true)
                    {
                        strLines[j] = Regex.Replace(strLines[j], "^<para>(.*)$", "<p class=\"box-para\">$1");
                    }
                    else
                    {
                        if (blblockquote == true)
                        {
                            strLines[j] = Regex.Replace(strLines[j], "^<para>(.*)$", "<p class=\"blockquote\">$1");
                        }
                        else
                        {

                            if (blNote == true)
                            {
                                if (blNoteStart == true)
                                {
                                    strLines[j] = Regex.Replace(strLines[j], "^<para>(.*)$", "<p class=\"hanging-note\"><small><b>NOTE</b></small> $1");
                                    blNoteStart = false;
                                }
                                else
                                {
                                    strLines[j] = Regex.Replace(strLines[j], "^<para>(.*)$", "<p class=\"hanging-note\">$1");
                                }

                            }
                            else
                            {

                                if (blCopyrightPage == true)
                                {

                                    strLines[j] = Regex.Replace(strLines[j], "^<para>(.*)$", "<p class=\"copyright\">$1");

                                }
                                else
                                {
                                    if (blTipStart == true)
                                    {

                                        strLines[j] = Regex.Replace(strLines[j], "^<para>(.*)$", "<p class=\"hanging-tip\"><small><b>TIP</b></small>&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;$1");

                                    }
                                    else
                                    {

                                        if (blAppendix == true)
                                        {
                                            strLines[j] = Regex.Replace(strLines[j], "^<para>(.*)$", "<p class=\"hanging-indent\">$1");
                                        }
                                        else
                                        {
                                            if (blSectionStart == true)
                                            {

                                                strLines[j] = Regex.Replace(strLines[j], "^<para>(.*)$", "<p class=\"body-text\">$1");
                                            }
                                            else
                                            {

                                                strLines[j] = Regex.Replace(strLines[j], "^<para>(.*)$", "<p class=\"indent\">$1");

                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }

                    blSectionStart = false;
                }

                #endregion

                #region Itemizedlist

                if (strLines[j].StartsWith("<itemizedlist mark=\"squf\">"))
                {
                    //strLines[j] = "";
                    strLines[j] = "<ul>";
                    blitemizedlist = true;
                }

                if (strLines[j].StartsWith("</itemizedlist>"))
                {
                    //strLines[j] = "";
                    strLines[j] = "</ul>";
                    blitemizedlist = false;
                    blSectionStart = true;
                }
                #endregion

                #region Orderedlist

                if (strLines[j].StartsWith("<orderedlist numeration=\"arabic\">"))
                {
                    //strLines[j] = "";
                    strLines[j] = "<ol>";
                    lnOrderedList = 0;
                    blorderedlist = true;
                }

                if (strLines[j].StartsWith("</orderedlist>"))
                {
                    //strLines[j] = "";
                    strLines[j] = "</ol>";
                    lnOrderedList = 0;
                    blorderedlist = false;
                    blSectionStart = true;
                }
                #endregion

                #region Blockquote

                if (strLines[j].StartsWith("<blockquote>"))
                {
                    strLines[j] = "";
                    blblockquote = true;
                }

                if (strLines[j].IndexOf("</blockquote>") > 0)
                {
                    strLines[j] = strLines[j].Replace("</blockquote>","");
                    blblockquote = false;
                    blSectionStart = true;

                }

                if (strLines[j].StartsWith("</blockquote>"))
                {
                    strLines[j] = "";
                    blblockquote = false;
                    blSectionStart = true;
                }

                #endregion

                #region Closing Sect, Figure
                //</example>

                if (strLines[j].StartsWith("</sect") || strLines[j].StartsWith("</figure>"))
                {
                    strLines[j] = "";
                    blSectionStart = true;
                }

                #endregion

                #region Closing example
                //</example>

                if (strLines[j].StartsWith("</example>"))
                {
                    strLines[j] = "";
                    blExampleStart  = false;
                    blSectionStart = true;
                }

                #endregion

                #region ListItem

                if (strLines[j].StartsWith("<listitem><para>"))
                {

                    if (blitemizedlist == true)
                    {
                        //Old
                        //strLines[j] = Regex.Replace(strLines[j], "^<listitem><para>(.*)</para></listitem>$", "<p class=\"hanging-list\"><img src=\"" + strIDPrefix + "015.jpg\" width=\"5\" height=\"5\" alt=\"icon014\"/> $1</p>");
                        strLines[j] = Regex.Replace(strLines[j], "^<listitem><para>(.*)</para></listitem>$", "<li><p>$1</p></li>");

                    }
                    else
                    {
                        if (blorderedlist == true)
                        {
                            lnOrderedList++;
                            //Old
                            //strLines[j] = Regex.Replace(strLines[j], "^<listitem><para>(.*)</para></listitem>$", "<p class=\"hanging-numberlist\">" + lnOrderedList.ToString() + " $1</p>");
                            strLines[j] = Regex.Replace(strLines[j], "^<listitem><para>(.*)</para></listitem>$", "<li><p>$1</p></li>");

                        }
                    }

                }

                #endregion

                #region Figure

                if (strLines[j].StartsWith("<figure "))
                {
                    lnFigure++;
                    if (strLines[j].IndexOf(" label=") > 0)
                    {
                        strChapterNumber = "Figure " + Regex.Replace(strLines[j], "^(.*) label=\"([^\"]*)\"(.*)$", "$2") + "&#x00A0;&#x00A0;&#x00A0; ";
                    }
                    else
                    {
                        strChapterNumber = "";
                    }

                    if (strLines[j].IndexOf(" id=") > 0)
                    {
                        strTempID = Regex.Replace(strLines[j], "^(.*) id=\"([^\"]*)\"(.*)$", "$2");
                    }
                    else
                    {
                        strTempID = "";
                    }

                    strLines[j] = "";

                    j++;
                    strTempID2 = "";
                    if (strLines[j].StartsWith("<title>"))
                    {
                        strTempID2 = Regex.Replace(strLines[j], "^<title>(.*)</title>$", "<p class=\"figure-caption\"><b>" + strChapterNumber + "$1</b></p>");
                        strLines[j] = "";
                    }

                    j++;

                    if (strLines[j].StartsWith("<graphic"))
                    {
                        //File Name
                        strTempID3 = Regex.Replace(strLines[j], "^(.*) fileref=\"([^\"]*)\"(.*)$", "$2");
                        //Width
                        strTempID4 = Regex.Replace(strLines[j], "^(.*) width=\"([^\"]*)\"(.*)$", "$2");
                        //height
                        strTempID5 = Regex.Replace(strLines[j], "^(.*) depth=\"([^\"]*)\"(.*)$", "$2");

                        //strLines[j] = "<p class=\"figure-image\" id=\"" + strTempID + "\"><img src=\"" + strIDPrefix + strTempID3 + ".jpg\" width=\"" + strTempID4 + "\" height=\"" + strTempID5 + "\" alt=\"fig" + lnFigure.ToString("000") + "\"/></p>\n" + strTempID2;
                        strLines[j] = "<p class=\"figure-image\" id=\"" + strTempID + "\"><img src=\"" + strTempID3 + "\" width=\"" + strTempID4 + "\" height=\"" + strTempID5 + "\" alt=\"" + strTempID3 + "\"/></p>\n" + strTempID2;

                    }

                }
                #endregion

                #region Example

                if (strLines[j].StartsWith("<example "))
                {
                    lnExample++;
                    blExampleStart = true;
                    if (strLines[j].IndexOf(" label=") > 0 && strLines[j].IndexOf(" role=") > 0)
                    {
                        strTempID6 = Regex.Replace(strLines[j], "^(.*) role=\"([^\"]*)\"(.*)$", "$2");
                        strChapterNumber = strTempID6 + " " + Regex.Replace(strLines[j], "^(.*) label=\"([^\"]*)\"(.*)$", "$2") + "&#x00A0;&#x00A0;&#x00A0; ";
                    }
                    else
                    {
                        strChapterNumber = "";
                    }

                    if (strLines[j].IndexOf(" id=") > 0)
                    {
                        strTempID = " id=\"" + Regex.Replace(strLines[j], "^(.*) id=\"([^\"]*)\"(.*)$", "$2") + "\"";
                    }
                    else
                    {
                        strTempID = "";
                    }

                    strLines[j] = "";

                    j++;
                    strTempID2 = "";
                    if (strLines[j].StartsWith("<title>"))
                    {
                        strLines[j] = Regex.Replace(strLines[j], "^<title>(.*)</title>$", "<p class=\"listing-script\"" + strTempID + "><b>" + strChapterNumber + "$1</b></p>");
                        //strLines[j] = "";
                    }

                    j++;

                }

                if (blExampleStart == true)
                {
                    if (strLines[j].StartsWith("<programlisting") == false && strLines[j].StartsWith("<") == true)
                    {
                        //strLines[j] = "<p class=\"script\">" + strLines[j] + "</p>";

                    }
                    else
                    {
                        strLines[j] = strLines[j].Replace("<programlisting>", "<p class=\"script\"><code>");
                        blProgramListingStart = true;
                    }
                }

                #endregion

                #region Tip

                if (strLines[j].StartsWith("<tip>"))
                {
                    blTipStart = true;
                    strLines[j] = "";

                }

                if (strLines[j].StartsWith("</tip>"))
                {
                    blTipStart = false ;
                    strLines[j] = "";

                }

                #endregion

                #region Table

                if (strLines[j].StartsWith("<table "))
                {
                    lnTable++;
                    strChapterNumber = "";
                    if (strLines[j].IndexOf(" label=") > 0)
                    {
                        strChapterNumber = "Table " + Regex.Replace(strLines[j], "^(.*) label=\"([^\"]*)\"(.*)$", "$2") + "&#x00A0;&#x00A0;&#x00A0; ";
                    }
                    else
                    {
                        strChapterNumber = "";
                    }

                    if (strLines[j].IndexOf(" id=") > 0)
                    {
                        strTempID = Regex.Replace(strLines[j], "^(.*) id=\"([^\"]*)\"(.*)$", "$2");
                    }
                    else
                    {
                        strTempID = "";
                    }

                    strLines[j] = "";

                    j++;
                    strTempID2 = "";
                    if (strLines[j].StartsWith("<title>"))
                    {
                        strTempID2 = Regex.Replace(strLines[j], "^<title>(.*)</title>$", "$1");
                        strLines[j] = "<table id=\"" + strTempID + "\" cellpadding=\"2\" cellspacing=\"0\">\n<p class=\"table-caption\"><b>" + strChapterNumber + strTempID2 + "</b></p>";
                    }
                    else
                    {
                        j--;
                        strLines[j] = "<table id=\"" + strTempID + "\" cellpadding=\"2\" cellspacing=\"0\">";

                    }

                }

                if (strLines[j].StartsWith("<row>"))
                {
                    strLines[j] = "<tr>";
                }
                if (strLines[j].StartsWith("</row>"))
                {
                    strLines[j] = "</tr>";
                }

                if (strLines[j].StartsWith("<entry"))
                {
                    strLines[j] = Regex.Replace(strLines[j], "^<entry(.*)><para>(.*)</para></entry>$", "<td$1>$2</td>");
                    strLines[j] = Regex.Replace(strLines[j], "^<entry(.*)><para>(.*)</para>$", "<td$1><p>$2</p>");
                    strLines[j] = Regex.Replace(strLines[j], "^<entry(.*)><para>(.*)$", "<td$1>$2");

                    //MessageBox.Show(strLines[j]);
                }

                if (strLines[j].StartsWith("<tgroup") || strLines[j].StartsWith("<colspec") || strLines[j].StartsWith("<thead>") || strLines[j].StartsWith("</thead>") || strLines[j].StartsWith("<tbody>") || strLines[j].StartsWith("</tbody>") || strLines[j].StartsWith("</tgroup>"))
                {
                    strLines[j] = "";
                    blSectionStart = true;
                }

                #endregion

                #region Remove Index

                if (strLines[j].IndexOf("<indexterm ") > 0 && strLines[j].LastIndexOf("</indexterm>") > 0)
                {
                    //MessageBox.Show(strLines[j] + strLines[j].IndexOf("<indexterm ").ToString());
                        strLines[j] = strLines[j].Remove(strLines[j].IndexOf("<indexterm "), (strLines[j].LastIndexOf("</indexterm>") - strLines[j].IndexOf("<indexterm ") + 12));
                    //MessageBox.Show(strLines[j]);
                }

                #endregion

                #region Some General Replacings
                //</para></entry>

                strLines[j] = strLines[j].Replace("</para></entry>", "</td>");
                strLines[j] = strLines[j].Replace("</programlisting>", "</code></p>");
                strLines[j] = strLines[j].Replace("<programlisting>", "<p class=\"script\"><code>");
                strLines[j] = strLines[j].Replace("</entry>", "</td>");
                strLines[j] = strLines[j].Replace("<p class=\"script\"><br/></p>", "<br/>");
                //Replace all general things
                strLines[j] = strLines[j].Replace("</para>", "</p>");
                //strLines[j] = strLines[j].Replace("<p class=\"script\"><p class=\"script\"><code>",
                strLines[j] = strLines[j].Replace("<listitem><para>", "<li><p>");
                strLines[j] = strLines[j].Replace("</para></listitem>", "</p></li>");
                strLines[j] = strLines[j].Replace("<listitem>", "<li>");
                strLines[j] = strLines[j].Replace("</listitem>", "</li>");
                strLines[j] = strLines[j].Replace("<entry", "<td");
                strLines[j] = strLines[j].Replace("<td align=\"center\" valign=\"bottom\">", "<td>");
                //
                if (strLines[j].IndexOf("<literal>") > 0)
                {
                    //MessageBox.Show(strLines[j]);
                    strLines[j] = Regex.Replace(strLines[j], "<literal>([^<]+)</literal>", "<code>$1</code>", RegexOptions.RightToLeft );
                    //MessageBox.Show(strLines[j]);
                }

                if (strLines[j].IndexOf("<emphasis>") > 0)
                {
                    //MessageBox.Show(strLines[j]);
                    strLines[j] = Regex.Replace(strLines[j], "<emphasis>([^<]+)</emphasis>", "<i>$1</i>", RegexOptions.RightToLeft);
                    //MessageBox.Show(strLines[j]);
                }

                if (strLines[j].IndexOf("<informalfigure>") >= 0)
                {
                    //MessageBox.Show(strLines[j]);
                    //strLines[j] = Regex.Replace(strLines[j], "<informalfigure><graphic fileref=\"figs/([^<> ]+).png\"/></informalfigure>", "<img src=\"images/$1.png\" alt=\"$1\"/>", RegexOptions.RightToLeft);
                    strLines[j] = Regex.Replace(strLines[j], "<informalfigure><graphic fileref=\"([^<> ]+)\"/></informalfigure>", "<img src=\"$1\" alt=\"$1\"/>", RegexOptions.RightToLeft);
                    //MessageBox.Show(strLines[j]);
                }

                if (strLines[j].IndexOf("<informalfigure>") < 0 && strLines[j].IndexOf("<graphic") >=0)
                {
                    //MessageBox.Show(strLines[j]);
                    //strLines[j] = Regex.Replace(strLines[j], "<graphic fileref=\"figs/([^<> ]+).png\"/>", "<img src=\"" + strIDPrefix + "/$1.png\" alt=\"$1\"/>", RegexOptions.RightToLeft);
                    strLines[j] = Regex.Replace(strLines[j], "<graphic fileref=\"([^<> ]+)\"/>", "<img src=\"$1\" alt=\"$1\"/>", RegexOptions.RightToLeft);
                    //MessageBox.Show(strLines[j]);
                }

                if (strLines[j].IndexOf("<systemitem role=\"url\">") >= 0)
                {
                    //MessageBox.Show(strLines[j]);
                    strLines[j] = Regex.Replace(strLines[j], "<systemitem role=\"url\">([^<>]+)</systemitem>", "<a href=\"$1\">$1</a>", RegexOptions.RightToLeft);
                    //MessageBox.Show(strLines[j]);
                }

                if (strLines[j].IndexOf("<systemitem role=\"httpurl\">") >= 0)
                {
                    //MessageBox.Show(strLines[j]);
                    strLines[j] = Regex.Replace(strLines[j], "<systemitem role=\"httpurl\">([^<>]+)</systemitem>", "<a href=\"http://$1\">$1</a>", RegexOptions.RightToLeft);
                    //MessageBox.Show(strLines[j]);
                }

                #endregion

                toolStripProgressBar1.Value = j+1;

            }

            #endregion

            this.Refresh();

            rtbContent.Text = string.Join("\n", strLines);
            toolStripProgressBar1.Value = toolStripProgressBar1.Maximum;
            //toolStripStatusLabel1.Text = "Ready";
            Application.UseWaitCursor = false;

            //IDLinking();
            IDLinkingVer2();
        }
Пример #11
0
        private void ConvertFootNote()
        {
            Application.UseWaitCursor = true;
            toolStripStatusLabel1.Text = "Converting Footnotes ... Please Wait";
            this.Refresh();
            string strContent = "";

            string[] strLines;

            stkIDs = new System.Collections.Stack();
            stkIDs.Clear();

            strContent = rtbContent.Text;
            strLines = strContent.Split('\n');
            long i = strLines.Length;

            toolStripProgressBar1.Maximum = Convert.ToInt32(i)+1;
            toolStripProgressBar1.Minimum = 1;
            toolStripProgressBar1.Value = 1;
            this.Refresh();

            bool blNoteStart = false;
            string strFn = "";
            long lnBibNo = 0;

            MatchCollection mc;

            #region First Loop

            //Creating IDs
            for (int j = 0; j < i; j++)
            {

                if (strLines[j].StartsWith("<note"))
                {

                    blNoteStart = true;
                    strLines[j] = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"+
                        "<!DOCTYPE noteGroup PUBLIC \"-//OXFORD//DTD OXCHAPML//EN\" \"OxChapML.dtd\">\n"+
                        "<!-- [DTD] OxChapML, v2.5 -->\n"+
                        "<!-- [TCI] Oxford Scholarship Online Text Capture Instructions, v1.2 -->\n" +
                        "<!-- [TCI] OUP Bibliographic reference capture, v1.15 -->\n"+
                        "<noteGroup>";

                }

                if (strLines[j].StartsWith("</note>"))
                {
                    blNoteStart = false;

                    strLines[j] = "</noteGroup>";
                }

                if (strLines[j].StartsWith("<fn"))
                {

                    strFn = Regex.Replace(strLines[j], "^<fn([0-9]+)>(.*)", "$1");

                    mc = Regex.Matches(strLines[j], "</bibn>", RegexOptions.RightToLeft);
                    int intFirstBibStart = 0;
                    int intFirstBibEnd = 0;
                    string strBIB = "";

                    foreach (Match singleMc in mc)
                    {
                        lnBibNo++;
                        intFirstBibStart = strLines[j].IndexOf("<bibn>");
                        intFirstBibEnd = strLines[j].IndexOf("</bibn>");
                        //MessageBox.Show(strLines[j]);
                        strBIB = strLines[j].Substring(intFirstBibStart, (intFirstBibEnd - intFirstBibStart) + 7);
                        //MessageBox.Show(strBIB);
                        strLines[j] = strLines[j].Remove(intFirstBibStart, (intFirstBibEnd - intFirstBibStart) + 7);
                        //MessageBox.Show(strLines[j]);
                        strLines[j] = strLines[j].Insert(intFirstBibStart, ConvertSingleBibn(strBIB, lnBibNo.ToString()));
                        //MessageBox.Show(strLines[j]);

                    }

                    strLines[j] = Regex.Replace(strLines[j], "^<fn([0-9]+)>(.*)</fn>$", "<note id=\"" + strIDPrefix + "-note-$1\" type=\"footnote\"><p><enumerator><sup>$1</sup></enumerator> $2</p></note>");

                }

                toolStripProgressBar1.Value = toolStripProgressBar1.Value + 1;

            }

            #endregion

            this.Refresh();

            rtbContent.Text = string.Join("\n", strLines);
            toolStripStatusLabel1.Text = "Ready";
            Application.UseWaitCursor = false;
        }
Пример #12
0
        private void ConvertFileNewID()
        {
            Application.UseWaitCursor = true;
            toolStripStatusLabel1.Text = "Creating IDs... Please Wait";
            this.Refresh();
            string strContent = "";

            string[] strLines;

            stkIDs = new System.Collections.Stack();
            stkIDs.Clear();

            strContent = rtbContent.Text;
            strLines = strContent.Split('\n');
            long i = strLines.Length;

            toolStripProgressBar1.Maximum = Convert.ToInt32(i);
            toolStripProgressBar1.Minimum = 1;
            toolStripProgressBar1.Value = 1;
            this.Refresh();

            string strID = "";

            #region First Loop

            //Creating IDs
            for (int j = 0; j < i; j++)
            {

                if (strLines[j].StartsWith("<preface") || strLines[j].StartsWith("<chapter") || strLines[j].StartsWith("<sect") || strLines[j].StartsWith("<figure") || strLines[j].StartsWith("<table") || strLines[j].StartsWith("<sidebar") || strLines[j].StartsWith("<example") || strLines[j].StartsWith("<appendix") || strLines[j].StartsWith("<part") || strLines[j].StartsWith("<glossary")) // || strLines[j].StartsWith("<preface")
                {
                    //MessageBox.Show(strLines[j]);
                    strLines[j] = Regex.Replace(strLines[j], "^(.*) id=\"([^\"]*)\"(.*)$", "$1$3");
                    //MessageBox.Show(strLines[j]);
                    strLines[j] = strLines[j].Insert(strLines[j].LastIndexOf(">"), " id=\"****\"");
                    //MessageBox.Show(strLines[j]);

                }

                toolStripProgressBar1.Increment(1);
                if (strLines[j].StartsWith("<title>"))
                {
                    strID = CreateID(Regex.Replace(strLines[j], "<title>(.*)</title>", "$1"));

                    if (strLines[j - 1].IndexOf("id=\"*") >= 0)
                    {

                        /*if (strLines[j - 1].StartsWith("<preface"))
                        {
                            strLines[j - 1] = strLines[j - 1].Insert(strLines[j - 1].IndexOf("id=") + 4, "preface").Replace("*", "");
                        }
                        else
                        {
                        */
                            strLines[j - 1] = strLines[j - 1].Insert(strLines[j - 1].IndexOf("id=") + 4, strID).Replace("*", "");
                        //}
                    }
                    else
                    {
                        if (strLines[j - 2].IndexOf("id=\"*") >= 0)
                        {
                            /*
                            if (strLines[j - 2].StartsWith("<preface"))
                            {
                                strLines[j - 2] = strLines[j - 2].Insert(strLines[j - 2].IndexOf("id=") + 4, "preface").Replace("*", "");
                            }
                            else
                            {
                             */
                                strLines[j - 2] = strLines[j - 2].Insert(strLines[j - 2].IndexOf("id=") + 4, strID).Replace("*", "");
                            //}
                        }
                    }

                }

            }

            #endregion

            this.Refresh();

            rtbContent.Text = string.Join("\n", strLines);
            toolStripStatusLabel1.Text = "Ready";
            Application.UseWaitCursor = false;
        }