Пример #1
0
        /// <exception cref="System.IO.IOException"/>
        protected internal override void ProcessOptions(List <string> args)
        {
            CommandFormat cf = new CommandFormat(1, int.MaxValue, OptionFollowLink, OptionFollowArgLink
                                                 , null);

            cf.Parse(args);
            if (cf.GetOpt(OptionFollowLink))
            {
                GetOptions().SetFollowLink(true);
            }
            else
            {
                if (cf.GetOpt(OptionFollowArgLink))
                {
                    GetOptions().SetFollowArgLink(true);
                }
            }
            // search for first non-path argument (ie starts with a "-") and capture and
            // remove the remaining arguments as expressions
            List <string>        expressionArgs = new List <string>();
            IEnumerator <string> it             = args.GetEnumerator();
            bool isPath = true;

            while (it.HasNext())
            {
                string arg = it.Next();
                if (isPath)
                {
                    if (arg.StartsWith("-"))
                    {
                        isPath = false;
                    }
                }
                if (!isPath)
                {
                    expressionArgs.AddItem(arg);
                    it.Remove();
                }
            }
            if (args.IsEmpty())
            {
                args.AddItem(Path.CurDir);
            }
            Expression expression = ParseExpression(expressionArgs);

            if (!expression.IsAction())
            {
                Expression         and      = GetExpression(typeof(And));
                Deque <Expression> children = new List <Expression>();
                children.AddItem(GetExpression(typeof(Print)));
                children.AddItem(expression);
                and.AddChildren(children);
                expression = and;
            }
            SetRootExpression(expression);
        }
Пример #2
0
            /// <exception cref="System.IO.IOException"/>
            protected internal override void ProcessOptions(List <string> args)
            {
                CommandFormat cf = new CommandFormat(1, int.MaxValue, "ignoreCrc");

                cf.Parse(args);
                verifyChecksum = !cf.GetOpt("ignoreCrc");
            }
Пример #3
0
            // used by chown/chgrp
            ///allows only "allowedChars" above in names for owner and group
            /// <exception cref="System.IO.IOException"/>
            protected internal override void ProcessOptions(List <string> args)
            {
                CommandFormat cf = new CommandFormat(2, int.MaxValue, "R");

                cf.Parse(args);
                SetRecursive(cf.GetOpt("R"));
                ParseOwnerGroup(args.RemoveFirst());
            }
Пример #4
0
            /// <exception cref="System.IO.IOException"/>
            protected internal override void ProcessOptions(List <string> args)
            {
                CommandFormat cf = new CommandFormat(2, int.MaxValue, "R", null);

                cf.Parse(args);
                SetRecursive(cf.GetOpt("R"));
                string modeStr = args.RemoveFirst();

                try
                {
                    pp = new ChmodParser(modeStr);
                }
                catch (ArgumentException)
                {
                    // TODO: remove "chmod : " so it's not doubled up in output, but it's
                    // here for backwards compatibility...
                    throw new ArgumentException("chmod : mode '" + modeStr + "' does not match the expected pattern."
                                                );
                }
            }
Пример #5
0
        /// <exception cref="System.IO.IOException"/>
        protected internal override void ProcessOptions(LinkedList <string> args)
        {
            CommandFormat cf = new CommandFormat(2, int.MaxValue, "w");

            cf.Parse(new List <string>(args));
            waitOpt = cf.GetOpt("w");
            try
            {
                newLength = long.Parse(args.First.Value);
                args.RemoveFirst();
            }
            catch (FormatException nfe)
            {
                DisplayWarning("Illegal length, a non-negative integer expected");
                throw;
            }
            if (newLength < 0)
            {
                throw new ArgumentException("length must be >= 0");
            }
        }
Пример #6
0
        /// <summary>Main entry point.</summary>
        /// <param name="args">command-line arguments</param>
        public static void Main(string[] args)
        {
            if (args.Length < 1 || args[0].Equals("-h") || args[0].Equals("--help"))
            {
                System.Console.Out.WriteLine(usage);
                return;
            }
            // Copy args, because CommandFormat mutates the list.
            IList <string> argsList = new AList <string>(Arrays.AsList(args));
            CommandFormat  cf       = new CommandFormat(0, int.MaxValue, "-glob", "-jar");

            try
            {
                cf.Parse(argsList);
            }
            catch (CommandFormat.UnknownOptionException)
            {
                Terminate(1, "unrecognized option");
                return;
            }
            string classPath = Runtime.GetProperty("java.class.path");

            if (cf.GetOpt("-glob"))
            {
                // The classpath returned from the property has been globbed already.
                System.Console.Out.WriteLine(classPath);
            }
            else
            {
                if (cf.GetOpt("-jar"))
                {
                    if (argsList.IsEmpty() || argsList[0] == null || argsList[0].IsEmpty())
                    {
                        Terminate(1, "-jar option requires path of jar file to write");
                        return;
                    }
                    // Write the classpath into the manifest of a temporary jar file.
                    Path   workingDir = new Path(Runtime.GetProperty("user.dir"));
                    string tmpJarPath;
                    try
                    {
                        tmpJarPath = FileUtil.CreateJarWithClassPath(classPath, workingDir, Runtime.GetEnv
                                                                         ())[0];
                    }
                    catch (IOException e)
                    {
                        Terminate(1, "I/O error creating jar: " + e.Message);
                        return;
                    }
                    // Rename the temporary file to its final location.
                    string jarPath = argsList[0];
                    try
                    {
                        FileUtil.ReplaceFile(new FilePath(tmpJarPath), new FilePath(jarPath));
                    }
                    catch (IOException e)
                    {
                        Terminate(1, "I/O error renaming jar temporary file to path: " + e.Message);
                        return;
                    }
                }
            }
        }