Example #1
0
File: wc.cs Project: amure/WC
    public static void Main( string [] args)
    {
        bool traceOn = false; //There is a code block about foreach in P14
        bool spyOn = false;
        string file_name = null; //code from p17
        string defaultfile = @"wordCount.txt";//N.0204

        Console.WriteLine("Beginning WordCount program ... ");

        //��������жϿ�
        if (args.Length == 0 )
        {
            display_usage();
            return;
        }else{
            foreach ( string option in args )
            {
                if ( option.Equals ( "-t" ))
                    traceOn = true;
                else if (option.Equals ( "-s" ))
                    spyOn = true;
                else if (option.Equals ( "-h" ))
                {display_usage(); return;}
                else
                {
                    Console.WriteLine( @"check_valid_file_type( option );" );
                    file_name = option;
                }

            }
        }
        /*�������ģ���ж����������е�-t��-s���أ�������
        if ( traceOn )
            Console.WriteLine( "traceOn = true" );
        else
            Console.WriteLine( "traceOn = false" );
        if ( spyOn )
            Console.WriteLine( "spyOn = true" );
        else
            Console.WriteLine( "spyOn = false" );
        */

        //transmit filename into processFile
        //theObj.processFile();����ѡ�񴫵ݸ�������������ݸ����캯���ĵȵ��˺����ڿ���
        //���������ʽ�Ƚϼ򵥣���һ���汾��ʹ�ù��캯��
        /* 	WordCount theObj = new WordCount();
            theObj.processFile( file_name );	*/
        WordCount theObj = new WordCount( file_name, spyOn, traceOn );
        //N.0204
        if ( theObj.OutFile == null )
            theObj.OutFile = defaultfile;
        theObj.processFile( );

        //N.20501
        //ʹ��getConsoleInput����ʵ��WC֮index�ĵ���
        if ( getConsoleInput() == "q" ) return;
        Console.WriteLine ( " {0} line(s) match: ", theObj[ getConsoleInput() ] );

        Console.WriteLine( "Ending WordCount program ... ");
    }