Esempio n. 1
0
        public static new BalancedTree LoadFromFile(string filename)
        {
            BalancedTree tree = null;
            StreamReader r    = new StreamReader(filename, true);
            string       str;

            while ((str = r.ReadLine()) != null)
            {
                Guid guid = Guid.Empty;

                // Pick apart bits
                int cKeep = str.IndexOf('#');
                if (cKeep >= 0)
                {
                    if (cKeep < str.Length)
                    {
                        try
                        {
                            guid = new Guid(str.Substring(cKeep + 1, str.Length - 1 - cKeep));
                        }
                        catch (Exception)                               // Swallow exceptions since they were due to trying to turn a comment into a guid
                        {
                        }
                        str = str.Substring(0, cKeep);
                    }
                }

                // Trim whitespace and don't consider blank lines
                str = str.Trim();
                if (str.Length == 0)
                {
                    continue;
                }

                if (tree == null)
                {
                    tree = new Names(new Name(str, false, guid));
                }
                else
                {
                    tree.Insert(new Name(str, false, guid));
                }
            }
            r.Close();
            return(tree);
        }
Esempio n. 2
0
        public static BalancedTree LoadFromFile(string filename)
        {
            BalancedTree tree = null;
            StreamReader r    = new StreamReader(filename, true);
            string       str;

            if ((str = r.ReadLine()) != null)
            {
                // Pick apart bits
                tree = new Names(str);
                while ((str = r.ReadLine()) != null)
                {
                    // Pick apart bits
                    tree.Insert(str);
                }
            }
            r.Close();
            return(tree);
        }
Esempio n. 3
0
        static int      Main(string[] args)
        {
            int    exitcode   = 0;
            String typelib    = null;
            String outfile    = null;
            String verifyfile = null;
            String dump       = null;
            bool   silent     = false;
            bool   verifyiid  = false;
            bool   inbuild    = false;

            try
            {
                Setting[] switches = GetSwitches(args);

                foreach (Setting sw in switches)
                {
                    if (sw.option == null)
                    {
                        if (typelib != null)
                        {
                            // We already have a typelib
                            PrintLogo();
                            WriteErrorMsg("Only one typelibrary can be operated on at a time.");
                            exitcode = 1;
                            goto done;
                        }
                        else
                        {
                            // We are cool with this
                            typelib = sw.value;
                        }
                    }
                    else
                    {
                        if (CompareString(sw.option.value, "/out") == 0)
                        {
                            outfile = sw.value;
                        }
                        else if (CompareString(sw.option.value, "/verify") == 0)
                        {
                            verifyfile = sw.value;
                        }
                        else if (CompareString(sw.option.value, "/iid") == 0)
                        {
                            verifyiid = true;
                        }
                        else if (CompareString(sw.option.value, "/dump") == 0)
                        {
                            dump = sw.value;
                        }
                        else if (CompareString(sw.option.value, "/silent") == 0)
                        {
                            silent = true;
                        }
                        else if (CompareString(sw.option.value, "/build") == 0)
                        {
                            inbuild = true;
                        }
                        else if (CompareString(sw.option.value, "/?") == 0)
                        {
                            PrintLogo();
                            PrintUsage();
                            exitcode = 0;
                            goto done;
                        }
                    }
                }

                if (!silent)
                {
                    PrintLogo();
                }
                if (typelib == null)
                {
                    WriteErrorMsg("No Type library file specified");
                    exitcode = 1;
                    goto done;
                }

                ExtractNames(typelib);
                if (dump != null)
                {
                    symbols.DumpAsTreeToFile(dump);
                    if (!silent)
                    {
                        Console.WriteLine("Successfully generated " + dump + " from " + typelib);
                    }
                }

                // Is an output file desired?
                if (outfile != null)
                {
                    symbols.DumpToFile(outfile);
                    if (!silent)
                    {
                        Console.WriteLine("Successfully generated " + outfile + " from " + typelib);
                    }
                }

                // Is verification desired?
                if (verifyfile != null)
                {
                    if (!silent)
                    {
                        if (inbuild)
                        {
                            Console.Write("Build_Status ");
                        }
                        Console.WriteLine("Verify the names from " + typelib);
                    }
                    int errors = 0;
                    verify = Names.LoadFromFile(verifyfile);
                    foreach (BalancedNode s in symbols)
                    {
                        if (s.Value != null)
                        {
                            Name         n = (Name)s.Value;
                            BalancedNode o = verify.Search(n);
                            if (o == null)
                            {
                                Console.WriteLine(typelib + " : error N2000 : Symbol named '" + n.Value + "' added to typelib.");
                                ++errors;
                            }
                            else
                            {
                                Name f = (Name)o.Value;
                                f.Found = true;
                                if (n.UUID != f.UUID)
                                {
                                    f.NEWUUID = n.UUID;
                                }
                            }
                        }
                    }

                    foreach (BalancedNode s in verify)
                    {
                        if (s.Value != null)
                        {
                            Name n = (Name)s.Value;
                            if (n.Found != true)
                            {
                                Console.WriteLine(typelib + " : error N2001 : Symbol named '" + n.Value + "' removed from typelib.");
                                ++errors;
                            }
                        }
                    }

                    if (verifyiid)
                    {
                        foreach (BalancedNode s in verify)
                        {
                            if (s.Value != null)
                            {
                                Name n = (Name)s.Value;
                                if (n.NEWUUID != Guid.Empty)
                                {
                                    Console.WriteLine(typelib + " : error N2002 : Guid changed for symbol named '" + n.Value + "'; was " + n.UUID + " now is " + n.NEWUUID);
                                    ++errors;
                                }
                            }
                        }
                    }

                    if (!silent)
                    {
                        if (errors != 0)
                        {
                            Console.WriteLine(typelib + " : error N1000 : errors comparing typelib to names file " + verifyfile);
                        }
                        else
                        if (!inbuild)
                        {
                            Console.WriteLine(typelib + " : no errors comparing typelib to names file " + verifyfile);
                        }
                    }
                    exitcode = errors;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(typelib + " : error N1001 : Exception " + e.Message);
                return(1);
            }
done:
            return(exitcode);
        }