Beispiel #1
0
        internal static unsafe string GetUnicodeName(char ch)
        {
            UInt32 usv            = ch;
            byte * pszUnicodeName = TECkit_GetTECkitName(usv);

            byte[] baUnicodeName  = ECNormalizeData.ByteStarToByteArr(pszUnicodeName);
            string strUnicodeName = Encoding.ASCII.GetString(baUnicodeName);

            return(strUnicodeName);
        }
Beispiel #2
0
        static unsafe void DisplayCompilerError(byte *pszName, byte *msg, byte *param, UInt32 line)
        {
            byte[]   baMsg = ECNormalizeData.ByteStarToByteArr(msg);
            Encoding enc   = Encoding.ASCII;
            string   str   = new string(enc.GetChars(baMsg));

            if (param != (byte *)0)
            {
                baMsg = ECNormalizeData.ByteStarToByteArr(param);
                str  += String.Format(": \"{0}\"", new string(enc.GetChars(baMsg)));
            }

            if (line != 0)
            {
                str += cstrLineNumClue;
                str += line.ToString();
            }

            m_lstErrorMsgs.Add(str);
        }
Beispiel #3
0
        public unsafe static void CompileMap(string strFilename, ref string strCompiledFilename)
        {
            m_lstErrorMsgs.Clear();             // start with an empty list of errors so we can detect them.

            int        status  = 0;
            FileStream fileMap = new FileStream(strFilename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);

            byte[] pTxt          = new byte[fileMap.Length];
            uint   nMapSize      = (uint)fileMap.Read(pTxt, 0, (int)fileMap.Length);
            byte * compiledTable = (byte *)0;
            UInt32 compiledSize  = 0;

            errFunc dsplyErr = new errFunc(TECkitDllWrapper.DisplayCompilerError);

            byte[] baName = Encoding.ASCII.GetBytes(strFilename);

            fixed(byte *lpTxt = pTxt)
            fixed(byte *lpName = baName)
            status             = TECkit_Compile(
                lpTxt,
                nMapSize,
                (byte)1,                           // docompression
                dsplyErr,
                lpName,
                &compiledTable,
                &compiledSize);

            // any errors occur?
            if (m_lstErrorMsgs.Count > 0)
            {
                // show the compiler errors, but limit it to some value.
                const int cnTeCkitCompilerMaxErrors = 20;
                string    strErrs     = null;
                int       i           = 0;
                int       nUpperLimit = Math.Min(m_lstErrorMsgs.Count, cnTeCkitCompilerMaxErrors);
                while (i < nUpperLimit)
                {
                    string strErr = m_lstErrorMsgs[i++];
                    strErrs += strErr + Environment.NewLine;
                }

                if (i == cnTeCkitCompilerMaxErrors)
                {
                    strErrs = String.Format("First {1} errors:{0}{2}",
                                            Environment.NewLine, cnTeCkitCompilerMaxErrors,
                                            strErrs);
                }

                ApplicationException e = new ApplicationException(strErrs);
                throw e;
            }
            else if (status == (int)ErrStatus.NoError)
            {
                // put the data from TEC into a managed byte array for the following Write
                byte[] baOut = new byte[compiledSize];
                ECNormalizeData.ByteStarToByteArr(compiledTable, (int)compiledSize, baOut);

                // save the compiled mapping (but if it fails because it's locked, then
                //  try to save it with a temporary name.
                FileStream fileTec = null;
                try
                {
                    fileTec = File.OpenWrite(strCompiledFilename);
                }
                catch (System.IO.IOException)
                {
                    // temporary filename for temporary CC tables (to check portions of the file at a time)
                    strCompiledFilename = Path.GetTempFileName();
                    strCompiledFilename = strCompiledFilename.Remove(strCompiledFilename.Length - 3) + "tec";
                    fileTec             = File.OpenWrite(strCompiledFilename);
                }

                fileTec.Write(baOut, 0, (int)compiledSize);
                fileTec.Close();
            }
        }