Exemple #1
0
        private int GetFileStats()
        {
            TextReader instream = null;

            try
            {
                instream = (ReadStdin ? Console.In : new StreamReader(FilenameIn));

                bool firstZero = true;
                for (int row = 0; ; row++)
                {
                    bool   saveLine    = true;
                    bool   processLine = true;
                    string line        = instream.ReadLine();
                    if (line == null)
                    {
                        break;
                    }

                    if (firstZero && row == 0 && Header == PrintHeaderType.PrintRow1)
                    {
                        row        = -1;
                        HeaderLine = line;
                        saveLine   = false;
                        // still process it
                        firstZero = false;
                    }

                    // if we still want to save it, it's not a header
                    if (saveLine && SkipRows > 0)
                    {
                        SkipRows--;
                        saveLine    = false;
                        processLine = false;
                    }

                    if (processLine)
                    {
                        SaveFieldCount(line);
                    }

                    if (saveLine)
                    {
                        MaxReadLine++;
                        if (!UseTwoPassMethod)
                        {
                            RawFile.Add(line);
                        }
                        if (LineCountToPrint > 0)
                        {
                            LineCountToPrint--;
                            if (LineCountToPrint <= 0)
                            {
                                break;
                            }
                        }
                    }
                }

                int ret = ReadExternHeader();
                if (ret > 0)
                {
                    return(ret);
                }

                VerifyFieldLengths();

                return(0);
            }
            finally
            {
                if (instream != null && instream != Console.In)
                {
                    try { instream.Close(); }
                    catch { }
                    try { instream.Dispose(); }
                    catch { }
                }
            }
        }