public override void ParseText()
        {
            StreamReader sr    = new StreamReader(filename);
            string       input = sr.ReadLine();

            while (null != input)
            {
                while (input.Trim().StartsWith("'"))
                {
                    input = sr.ReadLine();
                }

                APIUtility.GetRidExtraSpaces(ref input);
                if (input.StartsWith("Declare "))
                {
                    string[] pieces = input.Split(' ');

                    string returnType = GetFunctionReturnType(pieces);
                    string funcName   = pieces[2];
                    string dllName    = GetDllName(pieces[4]);
                    string paramStr   = ParseParameters(input);
                    string cSharpCode = CompleteDllImportCoding(dllName, returnType, funcName, paramStr);
                    AddCSharpCode(funcName, cSharpCode);
                }

                input = sr.ReadLine();
            }
            sr.Close();
        }
Exemplo n.º 2
0
        private string DefineCShpStructBody(string input)
        {
            if (input == "")
            {
                return("");
            }
            input = input.Replace(" as ", APIUtility.VB_AS);
            input = input.Replace(APIUtility.VB_AS, " ^ ");
            string[] pieces = input.Split('^');

            string cSharpStruct = "";

            if (input.IndexOf("*") > 0)
            {
                cSharpStruct = APIUtility.CSHP_MARSHAL_EXP_1.Replace(APIUtility.REPLACEABlE, input.Split('*')[1].Trim());
                pieces[1]    = pieces[1].Replace("* " + input.Split('*')[1].Trim(), "");
            }
            if (pieces[0].IndexOf("(") > 0)
            {
                string[] arrSeps = pieces[0].Split('(');
                pieces[0]    = arrSeps[0];
                cSharpStruct = APIUtility.CSHP_MARSHAL_EXP_2.Replace(APIUtility.REPLACEABlE, arrSeps[1]);
            }

            cSharpStruct += APIUtility.CSHP_SCOPE + " ";
            APIUtility.GetCSharpStyle(ref pieces[1]);
            cSharpStruct += pieces[1] + " ";
            cSharpStruct += pieces[0].Trim() + ";\n";
            cSharpStruct  = cSharpStruct.Replace(" '", "; //");
            cSharpStruct  = cSharpStruct.Replace("'", "; //");
            return("   " + cSharpStruct);
        }
 private string GetFunctionReturnType(string[] pieces)
 {
     if (pieces[1].Trim() == "Sub")
     {
         return("void");
     }
     else
     {
         APIUtility.GetCSharpStyle(ref pieces[pieces.Length - 1]);
         return(pieces[pieces.Length - 1]);
     }
 }
Exemplo n.º 4
0
        public override void ParseText()
        {
            bool structStart = false;
            bool structEnd   = false;

            string       cSharpCode = "";
            string       structKey  = "";
            StreamReader sr         = new StreamReader(filename);
            string       input      = sr.ReadLine();


            while (null != input)
            {
                while (input.Trim().StartsWith("'"))
                {
                    input = sr.ReadLine();
                }

                APIUtility.GetRidExtraSpaces(ref input);

                if (IsStruct(input))
                {
                    structStart = true;
                    structEnd   = false;
                    cSharpCode += DefineCShpStruct(input, ref structKey);
                    input       = sr.ReadLine();
                    continue;
                }
                if (structStart)
                {
                    if (input.Trim().StartsWith(APIUtility.VB_END_TYPE))
                    {
                        structStart = false;
                        structEnd   = true;

                        cSharpCode += "}\n";
                        AddCSharpCode(structKey, cSharpCode);
                        structKey  = "";
                        cSharpCode = "";
                        input      = sr.ReadLine();
                        continue;
                    }
                    else if (!structEnd)
                    {
                        cSharpCode += DefineCShpStructBody(input);
                        input       = sr.ReadLine();
                        continue;
                    }
                }
                input = sr.ReadLine();
            }
            sr.Close();
        }
        public override void ParseText()
        {
            StreamReader sr    = new StreamReader(filename);
            string       input = sr.ReadLine();

            while (null != input)
            {
                // Ignore comments
                while (input.Trim().StartsWith("'"))
                {
                    input = sr.ReadLine();
                }

                APIUtility.GetRidExtraSpaces(ref input);

                if (input.StartsWith("Const "))
                {
                    string cKey = input.Split(' ')[1];

                    string cshpType = "int";
                    if (input.IndexOf(" As ") > 0)
                    {
                        input    = input.Replace(" As ", " : ");
                        cshpType = input.Split(':')[1].Trim();
                        cshpType = cshpType.Substring(0, cshpType.IndexOf(" "));
                        input    = input.Replace(": " + cshpType, "");
                        APIUtility.GetCSharpStyle(ref cshpType);
                    }


                    string cSharpCode = APIUtility.CSHP_SCOPE + " " + input + ";\n";
                    cSharpCode = cSharpCode.Replace(APIUtility.VB_CONST_LEADING, APIUtility.CSHP_CONST_LEADING + cshpType);
                    cSharpCode = cSharpCode.Replace(APIUtility.VB_HEX_EXP, APIUtility.CSHP_HEX_EXP);
                    cSharpCode = cSharpCode.Replace(APIUtility.VB_OR, APIUtility.CSHP_OR);
                    cSharpCode = cSharpCode.Replace("&'", "; //");
                    cSharpCode = cSharpCode.Replace("'", "; //");
                    cSharpCode = cSharpCode.Replace("&;", ";");

                    AddCSharpCode(cKey, cSharpCode);
                    cSharpCode = "";
                }
                input = sr.ReadLine();
            }
            sr.Close();
        }
        private string MakeAParameter(string paramA)
        {
            paramA = paramA.Trim().Replace(" As ", " ");
            string[] pPieces = paramA.Split(' ');
            int      pLen    = pPieces.Length;

            if (pPieces[0].Trim() == "ByRef")
            {
                APIUtility.GetCSharpStyle(ref pPieces[pLen - 1], true);
                return("ref " + pPieces[pLen - 1] + " " + pPieces[pLen - 2]);
            }

            if (!APIUtility.GetCSharpStyle(ref pPieces[pLen - 1]))
            {
                pPieces[pLen - 1] = APIUtility.CSHP_MARSHAL_EXP_5 + pPieces[pLen - 1];
            }

            APIUtility.GetCSharpStyle(ref pPieces[pLen - 1], true);
            return(pPieces[pLen - 1] + " " + pPieces[pLen - 2]);
        }