Esempio n. 1
0
        private static void GenerateScanner(string[] args)
        {
            bool        fileArg  = false;
            TaskState   task     = new TaskState();
            OptionState opResult = OptionState.clear;

            if (args.Length == 0)
            {
                Usage("No arguments");
            }
            for (int i = 0; i < args.Length; i++)
            {
                if (args[i][0] == '/' || args[i][0] == '-')
                {
                    string arg = args[i].Substring(1);
                    opResult = task.ParseOption(arg);
                    if (opResult != OptionState.clear &&
                        opResult != OptionState.needCodepageHelp &&
                        opResult != OptionState.needUsage)
                    {
                        BadOption(arg, opResult);
                    }
                }
                else if (i != args.Length - 1)
                {
                    Usage("Too many arguments");
                }
                else
                {
                    fileArg = true;
                }
            }
            if (task.Version)
            {
                task.Msg.WriteLine("GPLEX version: " + task.VerString);
            }
            if (opResult == OptionState.needCodepageHelp)
            {
                CodepageHelp(fileArg);
            }
            if (opResult == OptionState.errors)
            {
                Usage(null); // print usage and abort
            }
            else if (!fileArg)
            {
                Usage("No filename");
            }
            else if (opResult == OptionState.needUsage)
            {
                Usage(); // print usage but do not abort
            }
            try
            {
                task.Process(args[args.Length - 1]);
            }
            catch (Exception ex)
            {
                if (ex is TooManyErrorsException)
                {
                    return;
                }
                Console.Error.WriteLine(ex.Message);
                throw;
            }
            finally
            {
                if (task.ErrNum + task.WrnNum > 0 || task.Listing)
                {
                    task.MakeListing();
                }
                if (task.ErrNum + task.WrnNum > 0)
                {
                    task.ErrorReport();
                }
                else if (task.Verbose)
                {
                    task.Msg.WriteLine("GPLEX <" + task.FileName + "> Completed successfully");
                }
                task.Dispose();
            }
        }