Esempio n. 1
0
        //public static void LoadPATLib(IToken libName)
        //{
        //    string dll = Ultility.LibFolderPath + "/" + libName.Text + ".dll";
        //    if(File.Exists(dll))
        //    {
        //        Ultility.LoadDLLLibrary(dll);
        //    }
        //    else
        //    {
        //        throw new ParsingException("The C# library " + dll + " can not be found!", libName);
        //    }
        //}

        public static void LoadStandardLib(IToken libPath, string filePathOld)
        {
            string filePath = ParsingException.GetFileNameByLineNumber(libPath.Line);

            string dll = libPath.Text.Trim('"');

            if (dll == "PAT.Math")
            {
                Utilities.LoadMathLib();
                return;
            }
            if (File.Exists(dll))
            {
                Utilities.LoadDLLLibrary(dll);
            }
            else
            {
                string dlllocal = "";
                if (!string.IsNullOrEmpty(filePath))
                {
                    dlllocal = Path.Combine(Path.GetDirectoryName(filePath), dll) + ".dll";
                    if (File.Exists(dlllocal))
                    {
                        Utilities.LoadDLLLibrary(dlllocal);
                        return;
                    }
                    dlllocal = " or " + dlllocal;
                }

                dll = Path.Combine(Utilities.StandardLibFolderPath, libPath.Text.Trim('"') + ".dll");
                if (File.Exists(dll))
                {
                    Utilities.LoadDLLLibrary(dll);
                }
                else
                {
                    throw new ParsingException(string.Format(Resources.The_C__library__0__can_not_be_found_, dll + dlllocal),
                                               libPath);
                }
            }
        }
Esempio n. 2
0
        public static void LoadIncludeModel(IToken libPath, SpecificationBase Spec)
        {
            //string s = libPath.Text;
            try
            {
                string filePath = ParsingException.GetFileNameByLineNumber(libPath.Line);
                //s += "\r\n1" + filePath;

                if (filePath == null)
                {
                    throw new ParsingException(string.Format("Cannot get the current file path"), libPath);
                }

                string dll = libPath.Text.Trim('"');

                /**
                 * Notes: if the dll path is start with "..\",
                 * which means that get the file name from the super directory,
                 * we parse this syntax here and assign the dll directory the value
                 * of the current file's super directory
                 */
                string dllFileDirectory = Path.GetDirectoryName(filePath);

                //s += "\r\n2" + dllFileDirectory;

                if (Common.Utility.Utilities.IsWindowsOS)
                {
                    if (dll.StartsWith("../"))
                    {
                        throw new ParsingException(
                                  string.Format("Please use char '\\' instead of '/' in the include file path"),
                                  libPath);
                    }

                    while (dll.StartsWith("..\\"))
                    {
                        dllFileDirectory = dllFileDirectory.Substring(0, dllFileDirectory.LastIndexOf('\\'));
                        dll = dll.Substring(dll.IndexOf('\\') + 1);
                    }
                }
                else
                {
                    while (dll.StartsWith("../") || dll.StartsWith("..\\"))
                    {
                        dllFileDirectory = dllFileDirectory.Substring(0, dllFileDirectory.LastIndexOf('/'));
                        if (dll.Contains("\\"))
                        {
                            dll = dll.Substring(dll.IndexOf('\\') + 1);
                        }
                        else if (dll.Contains("/"))
                        {
                            dll = dll.Substring(dll.IndexOf('/') + 1);
                        }
                    }
                }


                //s += "\r\n3" ;
                if (File.Exists(dll))
                {
                    Spec.IncludeFiles.Add(Path.Combine(dllFileDirectory, dll));
                }
                else
                {
                    string dlllocal = "";
                    if (!string.IsNullOrEmpty(filePath))
                    {
                        dlllocal = Path.Combine(dllFileDirectory, dll);
                        //s += "\r\n4" + dlllocal;
                        if (File.Exists(dlllocal))
                        {
                            Spec.IncludeFiles.Add(dlllocal);
                            return;
                        }
                    }

                    throw new ParsingException(string.Format("Cannot find the including file: {0}", dll), libPath);
                }
            }
            catch (Exception ex)
            {
                //MessageBox.Show(s + "\r\n" + ex.Message + ex.StackTrace);
                //throw new ParsingException(s + "\r\n" + ex.Message + ex.StackTrace, libPath);
                throw new ParsingException(string.Format("Cannot find the including file: {0}", libPath.Text), libPath);
            }
        }