public override void Execute()
        {
            int  numericWidth     = CmdLine.GetIntSwitch("/W", 6);
            bool paddingWithZeros = CmdLine.GetBooleanSwitch("/Z");
            char padChar;

            CheckIntRange(numericWidth, 0, int.MaxValue, "Numeric width", CmdLine.GetSwitchPos("/W"));

            if (paddingWithZeros)
            {
                padChar = '0';
            }
            else
            {
                padChar = ' ';
            }

            Open();

            try
            {
                int lineCount = Host.TextLineCount;
                WriteText(lineCount.ToString().PadLeft(numericWidth, padChar));
            }

            finally
            {
                Close();
            }
        }
Beispiel #2
0
        public override void Execute()
        {
            bool   cullingAll;
            string begCharStr;
            string endCharStr;
            bool   ignoringCase;
            bool   isRegEx;

            begCharStr   = (string)CmdLine.GetArg(0).Value;
            endCharStr   = (string)CmdLine.GetArg(1).Value;
            cullingAll   = CmdLine.GetBooleanSwitch("/A");
            ignoringCase = CmdLine.GetBooleanSwitch("/I");
            isRegEx      = CmdLine.GetBooleanSwitch("/R");

            Open();

            try
            {
                while (!EndOfText)
                {
                    string line = ReadLine();

                    if (StringMatched(begCharStr, line, ignoringCase, isRegEx))
                    {
                        // Found the first string.  Omit lines until after the second string is found:

                        while (!EndOfText && !StringMatched(endCharStr, line, ignoringCase, isRegEx))
                        {
                            // Omit the line && get the next one:

                            line = ReadLine();
                        }

                        if (!cullingAll)
                        {
                            // Output the remaining lines:

                            while (!EndOfText)
                            {
                                line = ReadLine();
                                WriteText(line);
                            }
                        }
                    }
                    else
                    {
                        // This line is outside of an omitted segment.  Output it:

                        WriteText(line);
                    }
                }
            }

            finally
            {
                Close();
            }
        }
Beispiel #3
0
        public override void Execute()
        {
            int  charPos     = CmdLine.GetIntSwitch("/P", 1);
            bool reverseSort = CmdLine.GetBooleanSwitch("/R");

            CheckIntRange(charPos, 1, int.MaxValue, "Char. position", CmdLine.GetSwitchPos("/P"));

            // Copy the input text to the output text object:

            File.Copy(((Filter)Host).InText, ((Filter)Host).OutText, true);

            // Sort it:

            SortFile(((Filter)Host).OutText, charPos, reverseSort);
        }
Beispiel #4
0
        public override void Execute()
        {
            bool   extractingAll;
            string begCharStr;
            string endCharStr;
            bool   done = false;
            bool   ignoringCase;
            bool   isRegEx;

            begCharStr    = (string)CmdLine.GetArg(0).Value;
            endCharStr    = (string)CmdLine.GetArg(1).Value;
            extractingAll = CmdLine.GetBooleanSwitch("/A");
            ignoringCase  = CmdLine.GetBooleanSwitch("/I");
            isRegEx       = CmdLine.GetBooleanSwitch("/R");

            Open();

            try
            {
                while (!done && !EndOfText)
                {
                    string line = ReadLine();

                    if (StringMatched(begCharStr, line, ignoringCase, isRegEx))
                    {
                        // Found the first string.  Output the line:

                        WriteText(line);

                        // Output lines until the second string is found:

                        while (!EndOfText && !StringMatched(endCharStr, line, ignoringCase, isRegEx))
                        {
                            line = ReadLine();
                            WriteText(line);
                        }

                        done = !extractingAll;
                    }
                }
            }

            finally
            {
                Close();
            }
        }
Beispiel #5
0
        public override void Execute()
        {
            LoggingEnabled = true;
            bool   prepending = CmdLine.GetBooleanSwitch("/P");
            string appStr     = (string)CmdLine.GetArg(0).Value;

            if (appStr == string.Empty)
            {
                ThrowException("String cannot be empty.", CmdLine.GetArg(0).CharPos);
            }

            Open();

            try
            {
                while (!EndOfText)
                {
                    string line = ReadLine();
                    string tempStr;

                    if (prepending)
                    {
                        tempStr = appStr + line;
                    }
                    else
                    {
                        tempStr = line + appStr;
                    }

                    WriteText(tempStr);
                }
            }

            finally
            {
                Close();
            }
        }
Beispiel #6
0
        public override void Execute()
        {
            int noOfLinesToJoin = 0;

            if (CmdLine.ArgCount > 0)
            {
                noOfLinesToJoin = (int)CmdLine.GetArg(0).Value;
                CheckIntRange(noOfLinesToJoin, 1, int.MaxValue, "No. of lines", CmdLine.GetArg(0).CharPos);
            }

            bool   paragraphJoin = CmdLine.GetBooleanSwitch("/P");
            string line;
            string newLine = string.Empty;

            Open();

            try
            {
                if (noOfLinesToJoin > 0)
                {
                    // Joining a specified number of lines.

                    int count = 1;

                    while (!EndOfText)
                    {
                        line = ReadLine();

                        if (count <= noOfLinesToJoin)
                        {
                            // Append the current line to the end of newLine:

                            newLine += line;

                            if ((count == noOfLinesToJoin) || EndOfText)
                            {
                                // Add newLine to the output queue:

                                WriteText(newLine);
                                count   = 1;
                                newLine = string.Empty;
                            }
                            else
                            {
                                count++;
                            }
                        }
                    }
                }
                else
                {
                    if (!paragraphJoin)
                    {
                        // Joining all lines, (stripping newlines).

                        while (!EndOfText)
                        {
                            newLine += ReadLine();
                        }

                        Write(newLine); // This fixes special case where joining 0 input lines was resulting in 1 line.
                    }
                    else
                    {
                        // Joining all lines, (Paragraph Join).

                        while (!EndOfText)
                        {
                            do
                            {
                                line = ReadLine();

                                if (line.Trim() != string.Empty)
                                {
                                    newLine += line;
                                }
                            }while ((line.Trim() != string.Empty) && !EndOfText);

                            if (line.Trim() == string.Empty)
                            {
                                newLine += System.Environment.NewLine;
                            }

                            WriteText(newLine);
                            newLine = string.Empty;
                        }
                    }
                }
            }

            finally
            {
                Close();
            }
        }
        public override void Execute()
        {
            string quoteStr     = CmdLine.GetStrSwitch("/Q", "\"");
            string delimiterStr = CmdLine.GetStrSwitch("/D", ",");

            unquoting           = CmdLine.GetBooleanSwitch("/U");
            usingBackslashQuote = CmdLine.GetBooleanSwitch("/B");
            int noOfSets = CmdLine.GetIntSwitch("/S", 0);
            int option   = CmdLine.GetIntSwitch("/O", 0);

            if (quoteStr == string.Empty)
            {
                ThrowException("String cannot be empty.", CmdLine.GetSwitchPos("/Q"));
            }
            if (delimiterStr == string.Empty)
            {
                ThrowException("String cannot be empty.", CmdLine.GetSwitchPos("/D"));
            }
            if (noOfSets != 0)
            {
                CheckIntRange(noOfSets, 1, int.MaxValue, "Set size", CmdLine.GetSwitchPos("/S"));
            }
            CheckIntRange(option, 0, 2, "Quote option", CmdLine.GetSwitchPos("/O"));

            quoteChar     = quoteStr[0];
            delimiterChar = delimiterStr[0];

            int    setNo      = 0;
            bool   inRange    = false;
            int    rangeIndex = 0;
            int    prevLine   = 0;
            string line       = string.Empty;

            Open();

            try
            {
                while (!EndOfText)
                {
                    int j       = rangeIndex * 2;
                    int begLine = (int)CmdLine.GetArg(j).Value;
                    int endLine = (int)CmdLine.GetArg(j + 1).Value;

                    CheckIntRange(begLine, 1, int.MaxValue, "Line no.", CmdLine.GetArg(j).CharPos);
                    CheckIntRange(endLine, 1, int.MaxValue, "Line no.", CmdLine.GetArg(j + 1).CharPos);

                    if (begLine > prevLine)
                    {
                        prevLine = begLine;

                        if (endLine >= begLine)
                        {
                            // Scan thru lines prior to range:

                            while ((!EndOfText) && (!inRange))
                            {
                                line    = ReadLine();
                                inRange = (setNo + 1 >= begLine) && (setNo + 1 <= endLine);

                                if (!inRange)
                                {
                                    WriteText(line);
                                    setNo++;

                                    if (noOfSets > 0)
                                    {
                                        setNo = setNo % noOfSets;
                                    }
                                }
                            }

                            // Scan thru lines in range:

                            do
                            {
                                QuoteLine(line, option);
                                setNo++;

                                if (noOfSets > 0)
                                {
                                    setNo = setNo % noOfSets;
                                }

                                inRange = (setNo + 1 >= begLine) && (setNo + 1 <= endLine);

                                if ((!EndOfText) && inRange)
                                {
                                    line = ReadLine();

                                    if (EndOfText)
                                    {
                                        QuoteLine(line, option);
                                    }
                                }
                            }while ((!EndOfText) && inRange);

                            if (rangeIndex == (CmdLine.ArgCount / 2) - 1)
                            {
                                // Last range - Scan to first set of next group:

                                while ((!EndOfText) && (setNo != 0))
                                {
                                    line = ReadLine();
                                    WriteText(line);
                                    setNo += 1;

                                    if (noOfSets > 0)
                                    {
                                        setNo = setNo % noOfSets;
                                    }
                                }

                                prevLine = 0;
                            }

                            rangeIndex = (rangeIndex + 1) % (CmdLine.ArgCount / 2);
                        }
                        else
                        {
                            // Begin/End pairs are reversed.

                            ThrowException("End line no. must be >= begin line no.",
                                           CmdLine.GetArg(j + 1).CharPos);
                        }
                    }
                    else
                    {
                        // Begin/End pairs are not ascending.

                        ThrowException("Begin/End pairs must be in ascending order.",
                                       CmdLine.GetArg(j).CharPos);
                    }
                }
            }

            finally
            {
                Close();
            }
        }
        public override void Execute()
        {
            bool   deletingAll    = CmdLine.GetBooleanSwitch("/A");
            bool   deletingFirst  = CmdLine.GetBooleanSwitch("/F");
            string delimiterStr   = CmdLine.GetStrSwitch("/D", string.Empty);
            bool   ignoringCase   = CmdLine.GetBooleanSwitch("/I");
            bool   rangeIsGiven   = CmdLine.ArgCount > 0;
            bool   delimSpecified = delimiterStr != string.Empty;

            char delimiter = '\0';

            if (delimSpecified)
            {
                delimiter = delimiterStr[0];
            }

            int begPos = 0;
            int endPos = 0;

            if (rangeIsGiven)
            {
                begPos = (int)CmdLine.GetArg(0).Value;
                endPos = (int)CmdLine.GetArg(1).Value;

                CheckIntRange(begPos, 1, int.MaxValue, "Char. position", CmdLine.GetArg(0).CharPos);
                CheckIntRange(endPos, 1, int.MaxValue, "Char. position", CmdLine.GetArg(1).CharPos);

                if (begPos > endPos)
                {
                    // Oops.

                    ThrowException("End position must be >= begin position.", CmdLine.GetArg(1).CharPos);
                }
            }

            string savedLine = null; // Must default to null.
            int    count     = 0;

            Open();

            try
            {
                if (!deletingFirst)
                {
                    // Deleting all but one line or all lines of each group.

                    while (!EndOfText)
                    {
                        string line = ReadLine();

                        if (!((delimSpecified && StringsCompare(line, savedLine, ignoringCase, delimiter)) ||
                              (!delimSpecified && StringsCompare(line, savedLine, ignoringCase, begPos, endPos))))
                        {
                            if ((deletingAll && (count == 1)) || (!deletingAll && (count > 0)))
                            {
                                WriteText(savedLine);
                            }

                            savedLine = line;
                            count     = 1;
                        }
                        else
                        {
                            count++;
                        }
                    }

                    if ((deletingAll && (count == 1)) || (!deletingAll && (count > 0)))
                    {
                        WriteText(savedLine);
                    }
                }
                else
                {
                    // Deleting only the FIRST line of each group. To test, use the following:
                    //
                    //    pipe: "WrapText 2 | OutDuplLines 2 2 | DelDuplLines 2 2 /f | AppendStr ',' | JoinLines | StripChars 1"
                    //    data: 112232435464748495A6B6C6D6E6F6G7
                    //
                    // After running the WrapText filter, the first char on each line is the line's
                    // sequence #. The second char is the line's data of which only even numbered
                    // data digits are duplicated (per the data digit's value). The expected test
                    // pipe results are as follows:
                    //
                    //    32,64,74,84,B6,C6,D6,E6,F6
                    //
                    // Note that all odd numbered groups (1, 3, 5 and 7), each of which contains
                    // but a single line, has been removed and that all remaining even numbered
                    // groups (2, 4 and 6) no longer include their first line of data.

                    while (!EndOfText)
                    {
                        string line = ReadLine();

                        if (!((delimSpecified && StringsCompare(line, savedLine, ignoringCase, delimiter)) ||
                              (!delimSpecified && StringsCompare(line, savedLine, ignoringCase, begPos, endPos))))
                        {
                            if (count == 1)
                            {
                                WriteText(savedLine);
                            }

                            savedLine = line;
                            count     = 1;
                        }
                        else
                        {
                            count++;
                            if (count > 1)
                            {
                                WriteText(line);
                            }
                        }
                    }

                    if (count == 1)
                    {
                        WriteText(savedLine);
                    }
                }
            }

            finally
            {
                Close();
            }
        }
        public override void Execute()
        {
            string delimiterStr   = CmdLine.GetStrSwitch("/D", string.Empty);
            bool   ignoringCase   = CmdLine.GetBooleanSwitch("/I");
            bool   rangeIsGiven   = (CmdLine.ArgCount > 0);
            bool   delimSpecified = delimiterStr != string.Empty;

            char delimiter = '\0';

            if (delimSpecified)
            {
                delimiter = delimiterStr[0];
            }

            int begPos = 0;
            int endPos = 0;

            if (rangeIsGiven)
            {
                begPos = (int)CmdLine.GetArg(0).Value;
                endPos = (int)CmdLine.GetArg(1).Value;

                CheckIntRange(begPos, 1, int.MaxValue, "Char. position", CmdLine.GetArg(0).CharPos);
                CheckIntRange(endPos, 1, int.MaxValue, "Char. position", CmdLine.GetArg(1).CharPos);

                if (begPos > endPos)
                {
                    // Oops.

                    ThrowException("End position must be >= begin position.", CmdLine.GetArg(1).CharPos);
                }
            }

            string oldLine  = null; // Must default to null.
            bool   begOfSeq = false;

            Open();

            try
            {
                while (!EndOfText)
                {
                    string line = ReadLine();

                    if ((delimSpecified && StringsCompare(line, oldLine, ignoringCase, delimiter)) ||
                        (!delimSpecified && StringsCompare(line, oldLine, ignoringCase, begPos, endPos)))
                    {
                        // Found a duplicate line.

                        if (begOfSeq)
                        {
                            // Output the previous, (first duplicate) line:

                            WriteText(oldLine);
                            begOfSeq = false;
                        }

                        // Output the current duplicate line:

                        WriteText(line);
                    }
                    else
                    {
                        // The line differs from the previous one.

                        oldLine  = line;
                        begOfSeq = true;
                    }
                }
            }

            finally
            {
                Close();
            }
        }
Beispiel #10
0
        //private Match match;

        public override void Execute()
        {
            string theMatch;
            bool   ignoringCase = CmdLine.GetBooleanSwitch("/I");
            bool   isRegEx      = CmdLine.GetBooleanSwitch("/R");

            Open();

            try
            {
                while (!EndOfText)
                {
                    string line   = ReadLine();
                    int    begPos = 1;

                    for (int i = 0; i < CmdLine.ArgCount / 2; i++)
                    {
                        int    j         = (i * 2);
                        int    charPos   = (int)CmdLine.GetArg(j).Value;
                        string matchStr  = (string)CmdLine.GetArg(j + 1).Value;
                        string subSource = line.Substring(begPos - 1, line.Length - begPos + 1);

                        CheckIntRange(charPos, 1, int.MaxValue, "Character position",
                                      CmdLine.GetArg(j).CharPos);
                        if (matchStr == string.Empty)
                        {
                            ThrowException("String cannot be empty.",
                                           CmdLine.GetArg(j + 1).CharPos);
                        }
                        int p = StringPos(matchStr, subSource, ignoringCase, isRegEx, out theMatch) + 1;

                        if (p > 0)
                        {
                            // Match string was found in the line.

                            int len;

                            if (isRegEx)
                            {
                                len = theMatch.Length;
                            }
                            else
                            {
                                len = matchStr.Length;
                            }

                            int noOfChars;

                            if ((p + begPos - 1) < charPos)
                            {
                                // The match string is located prior to the column position.

                                noOfChars = charPos - (p + begPos - 1);
                                string stringOfBlanks = new string(' ', noOfChars);
                                line   = line.Insert(p + begPos - 2, stringOfBlanks);
                                begPos = p + begPos - 1 + len + noOfChars;
                            }
                            else
                            {
                                // The match string is located after the column position.

                                noOfChars = (p + begPos - 1) - charPos;
                                line      = line.Remove(charPos - 1, noOfChars);
                                begPos    = p + begPos - 1 + len - noOfChars;
                            }
                        }
                    }

                    WriteText(line);
                }
            }

            finally
            {
                Close();
            }
        }
        public override void Execute()
        {
            bool countGiven    = CmdLine.GetBooleanSwitch("/C");
            int  insertCharPos = CmdLine.GetIntSwitch("/P", 0);

            if (insertCharPos != 0)
            {
                CheckIntRange(insertCharPos, 1, int.MaxValue,
                              "Char. position", CmdLine.GetSwitchPos("/P"));
            }

            Open();

            try
            {
                while (!EndOfText)
                {
                    string line    = ReadLine();
                    string newLine = string.Empty;

                    if (!countGiven)
                    {
                        // pos/pos pairs are supplied.

                        for (int i = 0; i < (CmdLine.ArgCount / 2); i++)
                        {
                            int j          = (i * 2);
                            int begCharPos = (int)CmdLine.GetArg(j).Value;
                            int endCharPos = (int)CmdLine.GetArg(j + 1).Value;
                            CheckIntRange(begCharPos, 1, int.MaxValue, "Begin char. position", CmdLine.GetArg(j).CharPos);
                            CheckIntRange(endCharPos, 1, int.MaxValue, "End char. position", CmdLine.GetArg(j + 1).CharPos);

                            if (endCharPos >= begCharPos)
                            {
                                while (line.Length < endCharPos)
                                {
                                    line += ' ';
                                }

                                int    len     = endCharPos - begCharPos + 1;
                                string tempStr = line.Substring(begCharPos - 1, len);
                                newLine += tempStr;
                            }
                            else
                            {
                                // Begin/End pair is reversed.

                                ThrowException("End position must be >= begin position.", CmdLine.GetArg(j + 1).CharPos);
                            }
                        }
                    }
                    else
                    {
                        // pos/count pairs are supplied.

                        for (int i = 0; i < (CmdLine.ArgCount / 2); i++)
                        {
                            int j          = (i * 2);
                            int begCharPos = (int)CmdLine.GetArg(j).Value;
                            int numOfChars = (int)CmdLine.GetArg(j + 1).Value;
                            int endCharPos = begCharPos + numOfChars - 1;
                            CheckIntRange(begCharPos, 1, int.MaxValue, "Begin char. position", CmdLine.GetArg(j).CharPos);
                            CheckIntRange(numOfChars, 1, int.MaxValue, "No. of characters", CmdLine.GetArg(j + 1).CharPos);

                            while (line.Length < endCharPos)
                            {
                                line += ' ';
                            }

                            string tempStr = line.Substring(begCharPos - 1, numOfChars);
                            newLine += tempStr;
                        }
                    }

                    if (insertCharPos > 0)
                    {
                        // Insert the resulting text back into the line:

                        while (line.Length < insertCharPos)
                        {
                            line += ' ';
                        }

                        newLine = line.Insert(insertCharPos - 1, newLine);
                    }

                    WriteText(newLine);
                }
            }

            finally
            {
                Close();
            }
        }
Beispiel #12
0
        public override void Execute()
        {
            int  numericWidth     = CmdLine.GetIntSwitch("/W", 6);
            bool paddingWithZeros = CmdLine.GetBooleanSwitch("/Z");
            bool perLineCount     = CmdLine.GetBooleanSwitch("/L");
            int  insertPos        = CmdLine.GetIntSwitch("/I", 0);
            char padChar;
            long count = 0;

            CheckIntRange(numericWidth, 0, int.MaxValue, "Numeric width", CmdLine.GetSwitchPos("/W"));
            if (insertPos != 0)
            {
                CheckIntRange(insertPos, 1, int.MaxValue, "Char. position",
                              CmdLine.GetSwitchPos("/I"));
            }

            if (paddingWithZeros)
            {
                padChar = '0';
            }
            else
            {
                padChar = ' ';
            }

            Open();

            try
            {
                while (!EndOfText)
                {
                    string line    = ReadLine();
                    int    lineLen = line.Length;

                    if (perLineCount)
                    {
                        if (insertPos > 0)
                        {
                            // Inserting the count back into the line.
                            // Pad the source line to the insertion point:

                            while (line.Length < insertPos - 1)
                            {
                                line += ' ';
                            }

                            // Insert the count:

                            WriteText(line.Insert(insertPos - 1, lineLen.ToString().PadLeft(numericWidth, padChar)));
                        }
                        else
                        {
                            // Outputting only the count.

                            WriteText(lineLen.ToString().PadLeft(numericWidth, padChar));
                        }
                    }
                    else
                    {
                        count += lineLen;
                    }
                }

                if (!perLineCount)
                {
                    WriteText(count.ToString().PadLeft(numericWidth, padChar));
                }
            }

            finally
            {
                Close();
            }
        }
Beispiel #13
0
        public override void Execute()
        {
            char   padChar;
            string tempStr;

            int  initLineNo       = CmdLine.GetIntSwitch("/L", 1);
            int  lineNoIncr       = CmdLine.GetIntSwitch("/I", 1);
            int  lineNoPos        = CmdLine.GetIntSwitch("/P", 1);
            int  lineNoSetSize    = CmdLine.GetIntSwitch("/S", 0);
            bool paddingWithZeros = CmdLine.GetBooleanSwitch("/Z");
            int  numericWidth     = CmdLine.GetIntSwitch("/W", 6);

            CheckIntRange(lineNoPos, 1, int.MaxValue, "Char. position", CmdLine.GetSwitchPos("/P"));
            if (lineNoSetSize != 0)
            {
                CheckIntRange(lineNoSetSize, 1, int.MaxValue, "Set size",
                              CmdLine.GetSwitchPos("/S"));
            }
            CheckIntRange(numericWidth, 0, int.MaxValue, "Numeric width", CmdLine.GetSwitchPos("/W"));

            int currLineNo = initLineNo;
            int count      = 1;

            Open();

            try
            {
                while (!EndOfText)
                {
                    string source = ReadLine();

                    if (paddingWithZeros)
                    {
                        padChar = '0';
                    }
                    else
                    {
                        padChar = ' ';
                    }

                    if (currLineNo < 0)
                    {
                        // The line # is negative.

                        if (paddingWithZeros)
                        {
                            tempStr = (-currLineNo).ToString().PadLeft(numericWidth, padChar);
                            if (tempStr[0] == '0')
                            {
                                tempStr = '-' + tempStr.Substring(1, tempStr.Length - 1);
                            }
                        }
                        else
                        {
                            tempStr = currLineNo.ToString().PadLeft(numericWidth, padChar);
                        }
                    }
                    else
                    {
                        // The line # is positive.

                        tempStr = currLineNo.ToString().PadLeft(numericWidth, padChar);
                    }

                    while (source.Length < lineNoPos - 1)
                    {
                        source += ' ';
                    }

                    source = source.Insert(lineNoPos - 1, tempStr);
                    WriteText(source);

                    if (lineNoSetSize > 0)
                    {
                        // Repeating line number sequence over and over.

                        if (count == lineNoSetSize)
                        {
                            // Restart the sequence:

                            currLineNo = initLineNo;
                            count      = 1;
                        }
                        else
                        {
                            // Increment the current line number and the set count:

                            currLineNo += lineNoIncr;
                            count++;
                        }
                    }
                    else
                    {
                        // Not repeating.  Just increment the current line number:

                        currLineNo += lineNoIncr;
                    }
                }
            }

            finally
            {
                Close();
            }
        }
        public override void Execute()
        {
            string        tempStr;
            double        theValue;
            string        line;
            List <double> totals       = new List <double>();
            int           numericWidth = CmdLine.GetIntSwitch("/W", 6);
            int           noOfDecimals = CmdLine.GetIntSwitch("/D", 2);
            bool          appendToEnd  = CmdLine.GetBooleanSwitch("/A");
            bool          sciNotation  = CmdLine.GetBooleanSwitch("/S");

            CheckIntRange(numericWidth, 0, int.MaxValue, "Numeric width", CmdLine.GetSwitchPos("/W"));
            CheckIntRange(noOfDecimals, 0, int.MaxValue, "No. of decimals", CmdLine.GetSwitchPos("/D"));

            for (int i = 1; i <= CmdLine.ArgCount; i++)
            {
                // Initialize the totals:

                totals.Add(0.0);
            }

            Open();

            try
            {
                while (!EndOfText)
                {
                    line = ReadLine();
                    if (appendToEnd)
                    {
                        WriteText(line);
                    }

                    // Total this line:

                    for (int i = 0; i < CmdLine.ArgCount; i++)
                    {
                        int charPos = (int)CmdLine.GetArg(i).Value;
                        CheckIntRange(charPos, 1, int.MaxValue, "Char. position", CmdLine.GetArg(i).CharPos);
                        int n = charPos - 1;
                        tempStr = ScanDecimal(line, ref n);

                        try
                        {
                            theValue   = double.Parse(tempStr);
                            totals[i] += theValue;
                        }
                        catch
                        {
                            // Numeric value is invalid.

                            ThrowException("Numeric value on text line " + TextLineNo.ToString() + " is invalid.");
                        }
                    }
                }

                // Output the totals:

                line = string.Empty;

                for (int i = 0; i < totals.Count; i++)
                {
                    theValue = totals[i];
                    int charPos = (int)CmdLine.GetArg(i).Value;

                    // Build the result string:

                    if (!sciNotation)
                    {
                        tempStr = theValue.ToString("0." +
                                                    new string('0', noOfDecimals)).PadLeft(numericWidth) + ' ';
                    }
                    else
                    {
                        tempStr = theValue.ToString("#." + new string('#', noOfDecimals) +
                                                    "e+00").PadLeft(numericWidth) + ' ';
                    }

                    // Pad the source line to the result column:

                    while (line.Length < charPos - 1)
                    {
                        line += ' ';
                    }

                    // Insert the result string:

                    line = line.Insert(charPos - 1, tempStr);
                }

                WriteText(line);
            }

            finally
            {
                Close();
            }
        }
        public override void Execute()
        {
            //LoggingEnabled = true;

            int    state = 1;
            string line;
            string newLine;

            string begStr       = (string)CmdLine.GetArg(0).Value;
            string endStr       = CmdLine.GetStrSwitch("/E", string.Empty);
            bool   ignoringCase = CmdLine.GetBooleanSwitch("/I");
            bool   isRegEx      = CmdLine.GetBooleanSwitch("/R");

            bool rangeGiven = (CmdLine.ArgCount > 1);

            int begPos = 0;
            int endPos = 0;

            if (rangeGiven)
            {
                begPos = (int)CmdLine.GetArg(1).Value;
                endPos = (int)CmdLine.GetArg(2).Value;

                CheckIntRange(begPos, 1, int.MaxValue, "Char. position", CmdLine.GetArg(1).CharPos);
                CheckIntRange(endPos, 1, int.MaxValue, "Char. position", CmdLine.GetArg(2).CharPos);
            }

            if (begPos > endPos)
            {
                // Oops.

                ThrowException("End position must be >= begin position.", CmdLine.GetArg(2).CharPos);
            }

            // Create/open a text file to contain the diverted text:

            string       divText       = Path.GetTempFileName();
            StreamWriter divTextWriter = new StreamWriter(divText);

            try
            {
                // Open the input/output files:

                Open();

                try
                {
                    // Process the text:

                    while (!EndOfText)
                    {
                        line = ReadLine();

                        if (rangeGiven)
                        {
                            newLine = line.Substring(begPos - 1, endPos - begPos + 1);
                        }
                        else
                        {
                            newLine = line;
                        }

                        if (endStr != string.Empty)
                        {
                            // The block of text is defined as the *first* encountered
                            // group of lines bounded by the two given boundary strings.

                            switch (state)
                            {
                            case 1:
                                if (!StringMatched(begStr, newLine, ignoringCase, isRegEx))
                                {
                                    // Save line to "top" of diverted text file:

                                    divTextWriter.WriteLine(line);
                                }
                                else
                                {
                                    // Output the line:

                                    WriteText(line);

                                    // Write a boundary marker between the "top"
                                    // and "bottom" of the diverted text:

                                    divTextWriter.WriteLine("<rekram yradnuob>");
                                    // TODO: Need to remove the need for this boundary marker (likely by using an additional list).

                                    if (StringMatched(endStr, newLine, ignoringCase, isRegEx))
                                    {
                                        state = 3;
                                    }
                                    else
                                    {
                                        state = 2;
                                    }
                                }
                                break;

                            case 2:

                                // Looking for ending string.  Output the line:

                                WriteText(line);

                                if (StringMatched(endStr, newLine, ignoringCase, isRegEx))
                                {
                                    state = 3;
                                }
                                break;

                            case 3:

                                // Save line to "bottom" of the diverted text file:

                                divTextWriter.WriteLine(line);
                                break;
                            }
                        }
                        else
                        {
                            // The isolated block of text is defined as the *first* encountered
                            // group of lines that contain the given string (optionally within the
                            // given range of character positions).

                            switch (state)
                            {
                            case 1:

                                // Collecting "top" lines.

                                if (StringMatched(begStr, newLine, ignoringCase, isRegEx))
                                {
                                    // Output the line:

                                    WriteText(line);

                                    // Write a boundary marker between the "top"
                                    // and "bottom" of the diverted text:

                                    divTextWriter.WriteLine("<rekram yradnuob>");
                                    state = 2;
                                }
                                else
                                {
                                    // Save line to "top" of diverted text file:

                                    divTextWriter.WriteLine(line);
                                }
                                break;

                            case 2:

                                // Collecting the "isolated" lines.

                                if (StringMatched(begStr, newLine, ignoringCase, isRegEx))
                                {
                                    // Output the line:

                                    WriteText(line);
                                }
                                else
                                {
                                    // Save line to "bottom" of the diverted text file:

                                    divTextWriter.WriteLine(line);
                                    state = 3;
                                }
                                break;

                            case 3:

                                // Save line to "bottom" of the diverted text file:

                                divTextWriter.WriteLine(line);
                                break;
                            }
                        }
                    }

                    // Push the diverted text filename onto the stack:

                    ((Filter)Host).DivTextStack.Push(divText);
                }

                finally
                {
                    Close();
                }
            }

            finally
            {
                divTextWriter.Close();
            }
        }
Beispiel #16
0
        public override void Execute()
        {
            bool ignoringCase = CmdLine.GetBooleanSwitch("/I");

            numericWidth = CmdLine.GetIntSwitch("/W", 6);
            bool   paddingWithZeros = CmdLine.GetBooleanSwitch("/Z");
            string delimiterStr     = CmdLine.GetStrSwitch("/D", string.Empty);

            explicitCounts = CmdLine.GetBooleanSwitch("/E");
            joinLinesOpt   = CmdLine.GetIntSwitch("/J", 0);
            joiningLines   = (joinLinesOpt == 1) || (joinLinesOpt == 2);
            rangeIsGiven   = CmdLine.ArgCount > 0;
            bool delimSpecified = delimiterStr != string.Empty;

            CheckIntRange(numericWidth, 0, int.MaxValue, "Numeric width", CmdLine.GetSwitchPos("/W"));
            CheckIntRange(joinLinesOpt, 0, 2, "Join option", CmdLine.GetSwitchPos("/J"));

            char delimiter = '\0';

            if (delimSpecified)
            {
                delimiter = delimiterStr[0];
            }

            begPos = 0;
            endPos = 0;

            if (rangeIsGiven)
            {
                begPos = (int)CmdLine.GetArg(0).Value;
                endPos = (int)CmdLine.GetArg(1).Value;

                CheckIntRange(begPos, 1, int.MaxValue, "Char. position", CmdLine.GetArg(0).CharPos);
                CheckIntRange(endPos, 1, int.MaxValue, "Char. position", CmdLine.GetArg(1).CharPos);
            }

            if (begPos > endPos)
            {
                // Oops.

                ThrowException("Ending position must be >= begin position.", CmdLine.GetArg(1).CharPos);
            }

            if (paddingWithZeros)
            {
                padChar = '0';
            }
            else
            {
                padChar = ' ';
            }

            savedLine = null;
            accumLine = string.Empty;
            count     = 0;

            Open();

            try
            {
                while (!EndOfText)
                {
                    string line     = ReadLine();
                    int    countVal = GetCount(line);
                    StripCount(ref line);

                    if ((delimSpecified && StringsCompare(line, savedLine, ignoringCase, delimiter)) ||
                        (!delimSpecified && StringsCompare(line, savedLine, ignoringCase, begPos, endPos)))
                    {
                        // The line compares with the last one.

                        switch (countVal)
                        {
                        case -1:

                            // Numeric value is invalid.

                            ThrowException("Numeric value on text line " + TextLineNo.ToString() + " is invalid.");
                            break;

                        case -2:

                            // Numeric value not found.

                            ThrowException("Numeric value on text line " + TextLineNo.ToString() + " not found.");
                            break;

                        default:

                            // Accumulate the count value:

                            count += countVal;

                            if (joiningLines)
                            {
                                // Accumulate the line:

                                accumLine += line;
                            }

                            break;
                        }
                    }
                    else
                    {
                        // The line does not compare to the last one.

                        OutputLine();
                        savedLine = line;
                        if (joiningLines)
                        {
                            accumLine = savedLine;
                        }
                        count = countVal;
                    }
                }

                OutputLine();
            }

            finally
            {
                Close();
            }
        }
Beispiel #17
0
        public override void Execute()
        {
            string       delimiterStr   = CmdLine.GetStrSwitch("/D", " ");
            string       placeHolderStr = CmdLine.GetStrSwitch("/P", "%");
            bool         ignoringCase   = CmdLine.GetBooleanSwitch("/I");
            int          begPos         = CmdLine.GetIntSwitch("/B", 0);
            int          endPos         = CmdLine.GetIntSwitch("/E", 0);
            bool         isRegEx        = CmdLine.GetBooleanSwitch("/R");
            RegexOptions defaultOptions = RegexOptions.Compiled | RegexOptions.Multiline;

            if (delimiterStr == string.Empty)
            {
                ThrowException("String cannot be empty.", CmdLine.GetSwitchPos("/D"));
            }
            if (placeHolderStr == string.Empty)
            {
                ThrowException("String cannot be empty.", CmdLine.GetSwitchPos("/P"));
            }
            if (begPos != 0)
            {
                CheckIntRange(begPos, 1, int.MaxValue, "Char. position", CmdLine.GetSwitchPos("/B"));
            }
            if (endPos != 0)
            {
                CheckIntRange(endPos, 1, int.MaxValue, "Char. position", CmdLine.GetSwitchPos("/E"));
            }

            char delimiter = delimiterStr[0];

            Open();

            try
            {
                while (!EndOfText)
                {
                    // Read a line of the source text:

                    string text = ReadLine();

                    // Perform text replacements to line:

                    for (int i = 0; i < CmdLine.ArgCount / 2; i++)
                    {
                        string oldStr = (string)CmdLine.GetArg(i * 2).Value;
                        if (oldStr == string.Empty)
                        {
                            ThrowException("String cannot be empty.",
                                           CmdLine.GetArg(i * 2).CharPos);
                        }
                        string newStr;

                        if (begPos == 0)
                        {
                            // Use the specified replace string literally.

                            newStr = (string)CmdLine.GetArg((i * 2) + 1).Value;
                        }
                        else
                        {
                            // Use the specified replace string as a template only.
                            // The real replace string originates from the input text.

                            string replaceStr  = GetReplString(text, begPos, endPos, delimiter);
                            string templateStr = (string)CmdLine.GetArg((i * 2) + 1).Value;
                            newStr = templateStr.Replace(placeHolderStr, replaceStr);
                        }

                        if (isRegEx)
                        {
                            if (ignoringCase)
                            {
                                text = Regex.Replace(text, oldStr, newStr, defaultOptions |
                                                     RegexOptions.IgnoreCase);
                            }
                            else
                            {
                                text = Regex.Replace(text, oldStr, newStr, defaultOptions);
                            }
                        }
                        else
                        {
                            text = ReplaceString(text, oldStr, newStr, ignoringCase);
                        }
                    }

                    // Write the edited line to the output file:

                    WriteText(text);
                }
            }

            finally
            {
                Close();
            }
        }
Beispiel #18
0
        public override void Execute()
        {
            string theStr       = (string)CmdLine.GetArg(0).Value;
            bool   ignoringCase = CmdLine.GetBooleanSwitch("/I");
            bool   isRegEx      = CmdLine.GetBooleanSwitch("/R");

            if (theStr == string.Empty)
            {
                ThrowException("String cannot be empty.", CmdLine.GetArg(0).CharPos);
            }

            bool rangeGiven = (CmdLine.ArgCount > 1);

            int begPos = 0;
            int endPos = 0;

            if (rangeGiven)
            {
                begPos = (int)CmdLine.GetArg(1).Value;
                endPos = (int)CmdLine.GetArg(2).Value;

                CheckIntRange(begPos, 1, int.MaxValue, "Char. position", CmdLine.GetArg(1).CharPos);
                CheckIntRange(endPos, 1, int.MaxValue, "Char. position", CmdLine.GetArg(2).CharPos);
            }

            if (begPos > endPos)
            {
                // Oops.

                ThrowException("Ending position must be >= begin position.", CmdLine.GetArg(2).CharPos);
            }

            // Create a temporary text list for storing "grouped" lines:

            List <string> groupedLines = new List <string>();

            Open();

            try
            {
                // Process the text:

                while (!EndOfText)
                {
                    string line = ReadLine();
                    string newLine;

                    if (rangeGiven)
                    {
                        newLine = line.Substring(begPos - 1, endPos - begPos + 1);
                    }
                    else
                    {
                        newLine = line;
                    }

                    if (StringMatched(theStr, newLine, ignoringCase, isRegEx))
                    {
                        // string found.  Add it to the list of "grouped" lines:

                        groupedLines.Add(line);
                    }
                    else
                    {
                        // string not found in line.  Output the line now:

                        WriteText(line);
                    }
                }

                // Now, output all of the grouped lines:

                foreach (string tempStr in groupedLines)
                {
                    WriteText(tempStr);
                }
            }

            finally
            {
                Close();
            }
        }
Beispiel #19
0
        public override void Execute()
        {
            string theStr       = (string)CmdLine.GetArg(0).Value;
            bool   ignoringCase = CmdLine.GetBooleanSwitch("/I");
            int    noOfRotates  = CmdLine.GetIntSwitch("/N", 1);
            bool   isRegEx      = CmdLine.GetBooleanSwitch("/R");

            CheckIntRange(noOfRotates, 1, int.MaxValue, "No. of rotates", CmdLine.GetSwitchPos("/N"));
            if (theStr == string.Empty)
            {
                ThrowException("String cannot be empty.", CmdLine.GetArg(0).CharPos);
            }

            Open();

            try
            {
                while (!EndOfText)
                {
                    string line = ReadLine();

                    if (line.Length > 0)
                    {
                        string matchStr = string.Empty;

                        for (int j = 1; j <= noOfRotates; j++)
                        {
                            if (j > 1)
                            {
                                // Move previous match found to end of line:

                                line = line.Substring(matchStr.Length) + matchStr;
                            }

                            // Find the next match:

                            int charPos = StringPos(theStr, line, ignoringCase, isRegEx, out matchStr);

                            if (charPos >= 0)
                            {
                                // Found it.

                                if (charPos > 0)
                                {
                                    // Rotate to it:

                                    string front = line.Substring(0, charPos);
                                    string back  = line.Substring(charPos, line.Length - charPos);
                                    line = back + front;
                                }
                            }
                            else
                            {
                                // No match found.  Quit:

                                break;
                            }
                        }
                    }

                    WriteText(line);
                }
            }

            finally
            {
                Close();
            }
        }
        protected void Execute(bool isAddFilter)
        {
            double resultValue;
            string tempStr;

            int  resultPos    = CmdLine.GetIntSwitch("/I", 0);
            int  numericWidth = CmdLine.GetIntSwitch("/W", 6);
            int  noOfDecimals = CmdLine.GetIntSwitch("/D", 2);
            bool sciNotation  = CmdLine.GetBooleanSwitch("/S");

            if (resultPos != 0)
            {
                CheckIntRange(resultPos, 1, int.MaxValue, "Char. position", CmdLine.GetSwitchPos("/I"));
            }

            CheckIntRange(numericWidth, 0, int.MaxValue, "Numeric width", CmdLine.GetSwitchPos("/W"));
            CheckIntRange(noOfDecimals, 0, int.MaxValue, "No. of decimals", CmdLine.GetSwitchPos("/D"));

            Open();

            try
            {
                while (!EndOfText)
                {
                    string line = ReadLine();

                    // Initialize the result:

                    if (isAddFilter)
                    {
                        resultValue = 0.0;
                    }
                    else
                    {
                        resultValue = 1.0;
                    }

                    if (CmdLine.ArgCount > 0)
                    {
                        // Adding (or multiplying) the numbers located as specific character positions.

                        for (int i = 0; i < CmdLine.ArgCount; i++)
                        {
                            int charPos = (int)CmdLine.GetArg(i).Value;
                            CheckIntRange(charPos, 1, int.MaxValue, "Char. position", CmdLine.GetArg(i).CharPos);

                            int num = charPos - 1;
                            tempStr = ScanDecimal(line, ref num);

                            try
                            {
                                double theValue = double.Parse(tempStr);

                                if (isAddFilter)
                                {
                                    resultValue += theValue;
                                }
                                else
                                {
                                    resultValue *= theValue;
                                }
                            }

                            catch (FormatException)
                            {
                                // Numeric value is invalid.

                                ThrowException("Numeric value found on text line " + TextLineNo.ToString() +
                                               ", character position " + CmdLine.GetArg(i).Value.ToString() + " is invalid.",
                                               CmdLine.GetArg(i).CharPos);
                            }
                        }

                        // Build the result string:

                        if (!sciNotation)
                        {
                            tempStr = resultValue.ToString("0." +
                                                           new string('0', noOfDecimals)).PadLeft(numericWidth);
                        }
                        else
                        {
                            tempStr = resultValue.ToString("#." + new string('#', noOfDecimals) +
                                                           "e+00").PadLeft(numericWidth) + ' ';
                        }
                    }
                    else
                    {
                        // Adding (or multiplying) all numbers found on each line separated by whitespace.

                        int countOfScannedValues = 0;
                        int charIndex            = 0;

                        while (charIndex < line.Length)
                        {
                            countOfScannedValues++;
                            tempStr = ScanDecimal(line, ref charIndex);

                            try
                            {
                                double theValue = double.Parse(tempStr);

                                if (isAddFilter)
                                {
                                    resultValue += theValue;
                                }
                                else
                                {
                                    resultValue *= theValue;
                                }
                            }

                            catch (FormatException)
                            {
                                // Numeric value is invalid.

                                ThrowException("Numeric value " + countOfScannedValues.ToString() +
                                               "found on text line " + TextLineNo.ToString() + " is invalid.");
                            }
                        }

                        if (countOfScannedValues > 0)
                        {
                            // Build the result string:

                            if (!sciNotation)
                            {
                                tempStr = resultValue.ToString("0." +
                                                               new string('0', noOfDecimals)).PadLeft(numericWidth);
                            }
                            else
                            {
                                tempStr = resultValue.ToString("#.########e+00");
                            }
                        }
                        else
                        {
                            // Build the result string:

                            tempStr = "n/a";
                        }
                    }

                    if (resultPos > 0)
                    {
                        // Inserting the result back into source.

                        tempStr += ' ';

                        // Pad the source line to the result column:

                        while (line.Length < resultPos - 1)
                        {
                            line += ' ';
                        }

                        // Insert the result string:

                        line = line.Insert(resultPos - 1, tempStr);
                        WriteText(line);
                    }
                    else
                    {
                        // Returning only the result string.

                        WriteText(tempStr);
                    }
                }
            }

            finally
            {
                Close();
            }
        }
Beispiel #21
0
        protected void Execute(bool excludingLines)
        {
            string newSource;
            bool   found;

            string matchStr     = (string)CmdLine.GetArg(0).Value;
            bool   ignoringCase = CmdLine.GetBooleanSwitch("/I");
            bool   isRegEx      = CmdLine.GetBooleanSwitch("/R");

            if (matchStr == string.Empty)
            {
                ThrowException("String cannot be empty.", CmdLine.GetArg(0).CharPos);
            }

            int begPos = 0;
            int endPos = 0;

            bool rangeGiven = (CmdLine.ArgCount > 1);

            if (rangeGiven)
            {
                begPos = (int)CmdLine.GetArg(1).Value;
                endPos = (int)CmdLine.GetArg(2).Value;

                CheckIntRange(begPos, 1, int.MaxValue, "Begin char. position", CmdLine.GetArg(1).CharPos);
                CheckIntRange(endPos, 1, int.MaxValue, "End char. position", CmdLine.GetArg(2).CharPos);
            }

            if (begPos > endPos)
            {
                // Oops.

                ThrowException("End char. position must be >= begin char. position.", CmdLine.GetArg(2).CharPos);
            }

            Open();

            try
            {
                while (!EndOfText)
                {
                    string line = ReadLine();

                    if (rangeGiven)
                    {
                        if (line.Length >= endPos)
                        {
                            newSource = line.Substring(begPos - 1, endPos - begPos + 1);
                            found     = StringMatched(matchStr, newSource, ignoringCase, isRegEx);
                        }
                        else
                        {
                            // Range extends past end of line.

                            found = false;
                        }
                    }
                    else
                    {
                        found = StringMatched(matchStr, line, ignoringCase, isRegEx);
                    }

                    if ((!found && excludingLines) || (found && !excludingLines))
                    {
                        WriteText(line);
                    }
                }
            }

            finally
            {
                Close();
            }
        }
Beispiel #22
0
        protected void Execute(bool isSubFilter)
        {
            string tempStr;

            int  arg1CharPos  = (int)CmdLine.GetArg(0).Value;
            int  arg2CharPos  = (int)CmdLine.GetArg(1).Value;
            int  resultPos    = CmdLine.GetIntSwitch("/I", 0);
            int  numericWidth = CmdLine.GetIntSwitch("/W", 6);
            int  noOfDecimals = CmdLine.GetIntSwitch("/D", 2);
            bool sciNotation  = CmdLine.GetBooleanSwitch("/S");

            CheckIntRange(arg1CharPos, 1, int.MaxValue, "Char. position", CmdLine.GetArg(0).CharPos);
            CheckIntRange(arg2CharPos, 1, int.MaxValue, "Char. position", CmdLine.GetArg(1).CharPos);

            if (resultPos != 0)
            {
                CheckIntRange(resultPos, 1, int.MaxValue, "Char. position", CmdLine.GetSwitchPos("/I"));
            }

            CheckIntRange(numericWidth, 0, int.MaxValue, "Numeric width", CmdLine.GetSwitchPos("/W"));
            CheckIntRange(noOfDecimals, 0, int.MaxValue, "No. of decimals", CmdLine.GetSwitchPos("/D"));

            Open();

            try
            {
                while (!EndOfText)
                {
                    string line = ReadLine();
                    int    num  = arg1CharPos - 1;
                    tempStr = ScanDecimal(line, ref num);

                    try
                    {
                        double value1 = double.Parse(tempStr);
                        num     = arg2CharPos - 1;
                        tempStr = ScanDecimal(line, ref num);

                        try
                        {
                            double value2 = double.Parse(tempStr);
                            double resultValue;

                            if (isSubFilter)
                            {
                                resultValue = value1 - value2;
                            }
                            else
                            {
                                resultValue = value1 / value2;
                            }

                            // Build the result string:

                            if (!sciNotation)
                            {
                                tempStr = resultValue.ToString("0." +
                                                               new string('0', noOfDecimals)).PadLeft(numericWidth);
                            }
                            else
                            {
                                tempStr = resultValue.ToString("#." + new string('#', noOfDecimals) +
                                                               "e+00").PadLeft(numericWidth) + ' ';
                            }

                            if (resultPos > 0)
                            {
                                // Inserting the result back into source.

                                tempStr += ' ';

                                // Pad the source line to the result column:

                                while (line.Length < resultPos - 1)
                                {
                                    line += ' ';
                                }

                                // Insert the result string:

                                line = line.Insert(resultPos - 1, tempStr);
                                WriteText(line);
                            }
                            else
                            {
                                // Returning only the result string.

                                WriteText(tempStr);
                            }
                        }

                        catch (FormatException)
                        {
                            // Numeric value is invalid.

                            ThrowException("Numeric value found on text line " + TextLineNo.ToString() +
                                           ", character position " + CmdLine.GetArg(1).Value.ToString() + " is invalid.",
                                           CmdLine.GetArg(1).CharPos);
                        }
                    }

                    catch (FormatException)
                    {
                        // Numeric value is invalid.

                        ThrowException("Numeric value found on text line " + TextLineNo.ToString() +
                                       ", character position " + CmdLine.GetArg(0).Value.ToString() + " is invalid.",
                                       CmdLine.GetArg(0).CharPos);
                    }
                }
            }

            finally
            {
                Close();
            }
        }
Beispiel #23
0
        public override void Execute()
        {
            //LoggingEnabled = true;
            int  radix            = (int)CmdLine.GetArg(0).Value;
            int  entryPos         = CmdLine.GetIntSwitch("/I", 0);
            int  scanPos          = CmdLine.GetIntSwitch("/S", 1);
            int  numericWidth     = CmdLine.GetIntSwitch("/W", 6);
            bool paddingWithZeros = CmdLine.GetBooleanSwitch("/Z");

            CheckIntRange(radix, 2, 62, "Radix", CmdLine.GetArg(0).CharPos);

            if (entryPos != 0)
            {
                CheckIntRange(entryPos, 1, int.MaxValue, "Char. position", CmdLine.GetSwitchPos("/I"));
            }

            CheckIntRange(scanPos, 1, int.MaxValue, "Char. position", CmdLine.GetSwitchPos("/S"));
            CheckIntRange(numericWidth, 0, int.MaxValue, "Numeric width", CmdLine.GetSwitchPos("/W"));

            Open();

            try
            {
                while (!EndOfText)
                {
                    string line       = ReadLine();
                    int    charPos    = scanPos - 1;
                    string validChars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
                    string tempStr    = ScanToken(line, ref charPos, validChars);

                    if (tempStr != string.Empty)
                    {
                        ulong num = Base2Decimal(tempStr, radix);
                        tempStr = num.ToString();
                        char padChar;

                        if (paddingWithZeros)
                        {
                            padChar = '0';
                        }
                        else
                        {
                            padChar = ' ';
                        }

                        tempStr = tempStr.PadLeft(numericWidth, padChar);

                        if (entryPos > 0)
                        {
                            // Insert the result back into source:

                            tempStr += ' ';

                            while (line.Length < entryPos - 1)
                            {
                                line += ' ';
                            }

                            line = line.Insert(entryPos - 1, tempStr);
                            WriteText(line);
                        }
                        else
                        {
                            // Only return the result:

                            WriteText(tempStr);
                        }
                    }
                    else
                    {
                        // No value found to convert.

                        ThrowException("No value was found on text line " + TextLineNo.ToString() + " to convert.");
                    }
                }
            }

            finally
            {
                Close();
            }
        }
Beispiel #24
0
        public override void Execute()
        {
            string spliceFileName = (string)CmdLine.GetArg(0).Value;
            string delimiterStr   = CmdLine.GetStrSwitch("/D", string.Empty);
            bool   mergingText    = CmdLine.GetBooleanSwitch("/M");

            try
            {
                using (TextReader tr = new StreamReader(spliceFileName))
                {
                    Open();

                    try
                    {
                        string tempStr;
                        string source;

                        if (!mergingText)
                        {
                            // Appending each line from splice file to end of input line.

                            while (!EndOfText)
                            {
                                source = ReadLine();

                                if ((tempStr = tr.ReadLine()) != null)
                                {
                                    WriteText(source + delimiterStr + tempStr);
                                }
                                else
                                {
                                    WriteText(source);
                                }
                            }

                            while ((tempStr = tr.ReadLine()) != null)
                            {
                                WriteText(tempStr);
                            }
                        }
                        else
                        {
                            // Adding all lines from splice file to end of input text (merging mode).

                            while (!EndOfText)
                            {
                                source = ReadLine();
                                WriteText(source);
                            }

                            while ((tempStr = tr.ReadLine()) != null)
                            {
                                WriteText(tempStr);
                            }
                        }
                    }

                    finally
                    {
                        Close();
                    }
                }
            }

            catch (IOException)
            {
                // Error reading the splice file.

                ThrowException("Error reading the splice file.");
            }
        }
Beispiel #25
0
        public override void Execute()
        {
            int  radix            = (int)CmdLine.GetArg(0).Value;
            int  entryPos         = CmdLine.GetIntSwitch("/I", 0);
            int  scanPos          = CmdLine.GetIntSwitch("/S", 1);
            int  numericWidth     = CmdLine.GetIntSwitch("/W", 6);
            bool paddingWithZeros = CmdLine.GetBooleanSwitch("/Z");

            CheckIntRange(radix, 2, 62, "Radix", CmdLine.GetArg(0).CharPos);

            if (entryPos != 0)
            {
                CheckIntRange(entryPos, 1, int.MaxValue, "Char. position", CmdLine.GetSwitchPos("/I"));
            }

            CheckIntRange(scanPos, 1, int.MaxValue, "Char. position", CmdLine.GetSwitchPos("/S"));
            CheckIntRange(numericWidth, 0, int.MaxValue, "Numeric width", CmdLine.GetSwitchPos("/W"));

            Open();

            try
            {
                while (!EndOfText)
                {
                    string line    = ReadLine();
                    int    charPos = scanPos - 1;
                    string tempStr = ScanInteger(line, ref charPos);

                    if (tempStr != string.Empty)
                    {
                        try
                        {
                            ulong num = ulong.Parse(tempStr);

                            // The decimal value converted ok.

                            tempStr = DecimalToBase(num, radix);
                            char padChar;

                            if (paddingWithZeros)
                            {
                                padChar = '0';
                            }
                            else
                            {
                                padChar = ' ';
                            }

                            tempStr = tempStr.PadLeft(numericWidth, padChar);

                            if (entryPos > 0)
                            {
                                // Insert the result back into source:

                                tempStr += ' ';

                                while (line.Length < entryPos - 1)
                                {
                                    line += ' ';
                                }

                                line = line.Insert(entryPos - 1, tempStr);
                                WriteText(line);
                            }
                            else
                            {
                                // Only return the result:

                                WriteText(tempStr);
                            }
                        }

                        catch (FormatException)
                        {
                            // Numeric value is invalid.

                            ThrowException("Numeric value on text line " +
                                           TextLineNo.ToString() + " is invalid.");
                        }
                    }
                    else
                    {
                        // Numeric value not found.

                        ThrowException("No numeric value was found on text line " +
                                       TextLineNo.ToString() + " to convert.");
                    }
                }
            }

            finally
            {
                Close();
            }
        }