コード例 #1
0
        public static VB_FILE_TYPE FileExtensionDecode(string fileName)
        {
            VB_FILE_TYPE fileType = VB_FILE_TYPE.VB_FILE_UNKNOWN;

            string fileExt = fileName.Substring(fileName.Length - 3, 3);

            if (fileExt != String.Empty)
            {
                switch (fileExt.ToUpper())
                {
                case "FRM":
                    fileType = VB_FILE_TYPE.VB_FILE_FORM;
                    break;

                case "BAS":
                    fileType = VB_FILE_TYPE.VB_FILE_MODULE;
                    break;

                case "CLS":
                    fileType = VB_FILE_TYPE.VB_FILE_CLASS;
                    break;

                default:
                    fileType = VB_FILE_TYPE.VB_FILE_UNKNOWN;
                    break;
                }
            }

            return(fileType);
        }
コード例 #2
0
ファイル: CodeParser.cs プロジェクト: kokheng1025/VEGA
        public int ParseFile(string fileName, List <String> checkedFiles)
        {
            int status = (int)SystemLogStatusCode.Success;

            checkedFilesFromForm = checkedFiles;
            string line     = String.Empty;
            string tempLine = String.Empty;

            // open file
            StreamReader Reader = new StreamReader(fileName, Encoding.ASCII, false, 65536);

            try
            {
                // decode file extension
                mFileType = Utils.FileExtensionDecode(fileName);

                // parse header function
                status = ParseHeader(Reader);

                // parse remain - variables, functions, procedures
                if (status == (int)SystemLogStatusCode.Success)
                {
                    status = ParseBodyProcedure(Reader);
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message);
                return((int)SystemLogStatusCode.ParseFileError);
            }

            // close stream before exit
            Reader.Close();

            // generate output File
            if (status == (int)SystemLogStatusCode.Success)
            {
                status = GenerateSourceCode(fileName);
            }

            return(status);
        }
コード例 #3
0
ファイル: CodeParser.cs プロジェクト: kokheng1025/VEGA
        private int ParseHeader(StreamReader reader)
        {
            int status = (int)SystemLogStatusCode.Success;

            string line     = String.Empty;
            string tempLine = String.Empty;
            int    wordNum  = 0;

            // Start from begin
            reader.BaseStream.Seek(0, SeekOrigin.Begin);
            line = reader.ReadLine();
            lineNum++;

            // get first word from first line
            status = Utils.GetNextWord(line, ref tempLine, ref wordNum);
            if (status != (int)SystemLogStatusCode.Success)
            {
                return(status);
            }

            switch (tempLine.ToUpper())
            {
            // 'Attribute VB_Name = "ModuleName"'
            case MODULE_FIRST_LINE:
                mFileType = VB_FILE_TYPE.VB_FILE_MODULE;
                break;

            case "VERSION":
                string version = String.Empty;
                if ((status = Utils.GetNextWord(line, ref version, ref wordNum)) != (int)SystemLogStatusCode.Success)
                {
                    return(status);
                }
                mSourceModule.Version = version;
                break;
            }

            // parse header module base on file extension
            if (mFileType == VB_FILE_TYPE.VB_FILE_CLASS)
            {
                mSourceModule.Type = VB_FILE_TYPE.VB_FILE_CLASS;
                if ((status = ParseClass(reader)) != (int)SystemLogStatusCode.Success)
                {
                    return(status);
                }
            }
            else if (mFileType == VB_FILE_TYPE.VB_FILE_FORM)
            {
                mSourceModule.Type = VB_FILE_TYPE.VB_FILE_FORM;
            }
            else if (mFileType == VB_FILE_TYPE.VB_FILE_MODULE)
            {
                mSourceModule.Type = VB_FILE_TYPE.VB_FILE_MODULE;
            }
            else
            {
                status = (int)SystemLogStatusCode.ParseHeaderError;
            }

            return(status);
        }