Example #1
0
        public void AssemblyGenerationTest()
        {
            Options options = new Options();
            options.Mode = Mode.SateliteAssembly;
            options.InputFiles.Add("../../../Examples.Hello/po/fr.po");
            options.BaseName = "Examples.Hello.Messages";
            options.OutDir = "../../../Examples.Hello/bin/Debug";
            if (Path.DirectorySeparatorChar == '\\')
                options.CompilerName = "csc";
            else
                options.CompilerName = "mcs";
            options.LibDir = "./";
            options.Locale = new CultureInfo("fr-FR");
            options.Verbose = true;
            options.DebugMode = true;

            AssemblyGen gen = new AssemblyGen(options);
            try
            {
                gen.Run();
            }
            catch(Exception e)
            {
                Assert.Fail("Assebly generation faild. Check that CSharp compiler is in PATH.\n{0}", e.Message);
            }
        }
Example #2
0
        public void ResourcesGenerationTest()
        {
            Options options = new Options();
            options.Mode = Mode.Resources;
            options.InputFiles.Add("./Data/Test01.po");
            options.OutFile = "./Messages.fr-FR.resources";
            options.Verbose = true;

            ResourcesGen gen = new ResourcesGen(options);
            gen.Run();
        }
Example #3
0
 public AssemblyGen(Options options)
 {
     sw = new StringWriter();
     cw = new IndentedTextWriter(sw);
     this.Options = options;
     ClassName = GettextResourceManager.MakeResourceSetClassName(Options.Locale);
     //            CsharpSourceFileName = Path.Combine(
     //				Options.OutDir,
     //                String.Format("{0}.{1}.resources.cs", Options.BaseName, Options.Locale.Name));
     CsharpSourceFileName = Path.GetTempFileName();
 }
Example #4
0
 public void GetoptParamsTest()
 {
     string[] args = new string[]
     {
         "-l", "fr-FR",
         "-d", "./bin/Debug",
         "-r", "Examples.Hello.Messages",
         "-L", "./../../Bin",
         "-v",
         "./po/fr.po",
         "./po/ru.po"
     };
     Options options = new Options();
     StringBuilder message;
     Assert.IsTrue(Msgfmt.Program.GetOptions(args, Program.SOpts, Program.LOpts, options, out message), message.ToString());
     CheckOptions(options);
     Assert.AreEqual(Mode.SateliteAssembly, options.Mode);
 }
Example #5
0
 public void MsgfmtResourceModeParamsTest()
 {
     string[] args = new string[]
     {
         "--csharp-resources",
         "-l", "fr-FR",
         "-d", "./bin/Debug",
         "-r", "Examples.Hello.Messages",
         "--compiler-name=gmcs",
         "-L", "./../../Bin",
         "-v",
         "./po/fr.po",
         "./po/ru.po"
     };
     Options options = new Options();
     StringBuilder message;
     Assert.IsTrue(Msgfmt.Program.GetOptions(args, Program.SOpts, Program.LOpts, options, out message), message.ToString());
     CheckOptions(options);
     Assert.AreEqual(Mode.Resources, options.Mode);
 }
Example #6
0
 public void GetoptLongParamsTest()
 {
     string[] args = new string[]
     {
         "--locale=fr-FR",
         "-d./bin/Debug",
         "--resource=Examples.Hello.Messages",
         "--compiler-name=gmcs",
         "--lib-dir=./../../Bin",
         "--verbose",
         "--check-format",
         "./po/fr.po",
         "./po/ru.po"
     };
     Options options = new Options();
     StringBuilder message;
     Assert.IsTrue(Msgfmt.Program.GetOptions(args, Program.SOpts, Program.LOpts, options, out message), message.ToString());
     Assert.AreEqual(0, message.Length, message.ToString());
     CheckOptions(options);
     Assert.AreEqual("gmcs", options.CompilerName);
     Assert.AreEqual(Mode.SateliteAssembly, options.Mode);
 }
Example #7
0
 public ResourcesGen(Options options)
 {
     this.Options = options;
 }
Example #8
0
        static int Main(string[] args)
        {
            Trace.Listeners.Add(new TextWriterTraceListener(Console.Out));

            StringBuilder message;
            Options options = new Options();
            if (args.Length == 0)
            {
                PrintUsage();
                return 1;
            }
            else if (!GetOptions(args, SOpts, LOpts, options, out message))
            {
                Console.WriteLine(message.ToString());
                return 1;
            }
            else if (options.ShowUsage)
            {
                PrintUsage();
                return 0;
            }
            if (!AnalyseOptions(options, out message))
            {
                Console.WriteLine(message.ToString());
                return 1;
            }

            try
            {
                switch (options.Mode)
                {
                    case Mode.Resources:
                        (new ResourcesGen(options)).Run();
                        Console.WriteLine("Resource created OK");
                        break;
                    case Mode.SateliteAssembly:
                        (new AssemblyGen(options)).Run();
                        Console.WriteLine("Generated OK");
                        break;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error during execution: {0}", ex.Message);
                return 1;
            }
            return 0;
        }
Example #9
0
        public static bool GetOptions(string[] args, String sopts, LongOpt[] lopts, Options options, out StringBuilder message)
        {
            message = new StringBuilder();
            Getopt.Getopt getopt = new Getopt.Getopt(
                Assembly.GetExecutingAssembly().GetName().Name,
                args, sopts, lopts)
                {
                    Opterr = false
                };

            options.Mode = Mode.SateliteAssembly;
            options.Verbose = false;
            options.CompilerName = Path.DirectorySeparatorChar == '/' ? "mcs" : "csc";
            options.ShowUsage = false;
            options.CheckFormat = false;
            options.DebugMode = false;

            int option;
            while ((option = getopt.getopt()) != -1)
            {
                switch (option)
                {
                case 1:
                    options.InputFiles.Add(getopt.Optarg);
                    break;
                case 2:
                    options.CheckFormat = true;
                    break;
                case 3:
                    options.Mode = Mode.Resources;
                    break;
                case 4:
                    options.DebugMode = true;
                    Trace.WriteLine("Debug mode is ON");
                    break;
                case '5':
                    options.CompilerName = getopt.Optarg;
                    break;
                case ':':
                    message.AppendFormat("Option {0} requires an argument", getopt.OptoptStr);
                    return false;
                case '?':
                    message.AppendFormat("Invalid option '{0}'", getopt.OptoptStr);
                    return false;
                case 'r':
                    options.BaseName = getopt.Optarg;
                    break;
                case 'o':
                    options.OutFile = getopt.Optarg;
                    break;
                case 'd':
                    options.OutDir = getopt.Optarg;
                    break;
                case 'l':
                    options.LocaleStr = getopt.Optarg;
                    break;
                case 'L':
                    options.LibDir = getopt.Optarg;
                    break;
                case 'v':
                    options.Verbose = true;
                    break;
                case 'h':
                    options.ShowUsage = true;
                    return true;
                default:
                    PrintUsage();
                    return false;
                }
            }

            if (getopt.Opterr)
            {
                message.AppendLine();
                message.Append("Error in command line options. Use -h to read options usage");
                return false;
            }
            return true;
        }
Example #10
0
        public static bool AnalyseOptions(Options options, out StringBuilder message)
        {
            message = new StringBuilder();
            bool accepted = true;
            try
            {
                if (options.InputFiles.Count == 0)
                {
                    message.Append("You must specify at least one input file");
                    accepted = false;
                }

                if (accepted)
                {
                    foreach(string fileName in options.InputFiles)
                    {
                        if (!File.Exists(fileName))
                        {
                            message.AppendFormat("File {0} not found", fileName);
                            accepted = false;
                        }
                    }
                }

                if (accepted && options.Mode == Mode.Resources && String.IsNullOrEmpty(options.OutFile))
                {
                    message.Append("Undefined output file name");
                    accepted = false;
                }

                if (accepted && options.Mode == Mode.SateliteAssembly)
                {
                    if (accepted && String.IsNullOrEmpty(options.BaseName))
                    {
                        message.Append("Undefined base name");
                        accepted = false;
                    }
                    if (accepted && String.IsNullOrEmpty(options.OutDir))
                    {
                        message.Append("Output dirictory name required");
                        accepted = false;
                    }
                    if (accepted && String.IsNullOrEmpty(options.LibDir))
                    {
                        message.Append("Assembly reference dirictory name required");
                        accepted = false;
                    }
                    if (accepted && String.IsNullOrEmpty(options.LocaleStr))
                    {
                        message.Append("Locale is not defined");
                        accepted = false;
                    }
                    else if (accepted)
                    {
                        options.Locale = new CultureInfo(options.LocaleStr);
                    }

                    if (accepted && options.Locale == null)
                    {
                        message.AppendFormat("Cannot create culture from {0}", options.LocaleStr);
                        accepted = false;
                    }
                }
            }
            catch(Exception e)
            {
                message.Append(e.Message);
                accepted = false;
            }

            if (!accepted)
            {
                message.AppendLine();
                message.Append("Error accepting options");
                return false;
            }

            return true;
        }
Example #11
0
 private void CheckOptions(Options options)
 {
     Assert.AreEqual(2, options.InputFiles.Count, "input files");
     Assert.AreEqual("./po/fr.po", options.InputFiles[0]);
     Assert.AreEqual("fr-FR", options.LocaleStr);
     Assert.AreEqual("./bin/Debug", options.OutDir);
     Assert.AreEqual("Examples.Hello.Messages", options.BaseName);
     Assert.AreEqual("./../../Bin", options.LibDir);
     Assert.IsTrue(options.Verbose);
 }