Esempio n. 1
0
 public static void PrintCInitialize(IA5StringType pThis, PEREffectiveConstraint cns, Asn1Value defaultVal, StreamWriterLevel h, string typeName, string varName, int lev, int arrayDepth)
 {
     h.P(lev);
     if (defaultVal != null)
         h.WriteLine("strcpy({0}, {1});", varName, defaultVal.ToString());
     else
         h.WriteLine("memset({0}, 0x0, {1});", varName, pThis.maxItems(cns) + 1);
 }
Esempio n. 2
0
 public static void PrintHTypeDeclaration(IA5StringType pThis, PEREffectiveConstraint cns, StreamWriterLevel h, string typeName, string varName, int lev)
 {
     if (varName == "")
         h.WriteLine("char {0}[{1}];", typeName, pThis.maxItems(cns) + 1);
     else
         h.WriteLine("char {0}[{1}];", varName, pThis.maxItems(cns) + 1);
 }
Esempio n. 3
0
 public static void PrintCEncodeItem(IA5StringType pThis, PEREffectiveConstraint cns, StreamWriterLevel c, string errorCode, string varName, int lev)
 {
     PERAlphabetAndSizeEffectiveConstraint cn = (PERAlphabetAndSizeEffectiveConstraint)cns;
     CharSet perAlphaCon = cn.m_from;
     int min = 0;
     int max;
     List<char> tmp = null;
     if (perAlphaCon != null)
         tmp = perAlphaCon.m_set;
     else
         tmp = new List<char>(pThis.AllowedCharSet);
     max = tmp.Count - 1;
     if (min == max)
         return;
     c.P(lev);
     c.Write("static byte allowedCharSet[] = {");
     for (int i = 0; i < tmp.Count; i++)
     {
         c.Write("0x{0:X2}", Convert.ToByte(tmp[i]));
         if (i == tmp.Count - 1)
             c.WriteLine("};");
         else
             c.Write(",");
         if ((i + 1) % 15 == 0)
         {
             c.WriteLine();
             c.P(lev + 7);
         }
     }
     c.P(lev);
     c.WriteLine("int charIndex = GetCharIndex({0}, allowedCharSet,{1});", varName, tmp.Count);
     c.P(lev);
     c.WriteLine("BitStream_EncodeConstraintWholeNumber(pBitStrm, charIndex, {0}, {1});", 0, tmp.Count - 1);
 }
Esempio n. 4
0
        public static void PrintCEncode(IA5StringType pThis, PEREffectiveConstraint cns, StreamWriterLevel c, string errorCode, string varName, int lev)
        {
            long min = pThis.minItems(cns);
            long max = pThis.maxItems(cns);
            string i = "i" + (CLocalVariable.GetArrayIndex(varName) + 1);
            string prefix = varName;
            string nCount = "nCount" + (CLocalVariable.GetArrayIndex(varName) + 1);
            string curBlockSize = "curBlockSize" + (CLocalVariable.GetArrayIndex(varName) + 1);
            string curItem = "curItem" + (CLocalVariable.GetArrayIndex(varName) + 1);

            if (max < 0x10000)
            {
                if (min != max)
                {
                    c.P(lev);
                    c.WriteLine("BitStream_EncodeConstraintWholeNumber(pBitStrm, strlen({0}), {1}, {2});", prefix, min, max);
                }
                else
                {
                    c.P(lev); c.WriteLine("/* No need to encode length (it is fixed size ({0})*/", min);
                }
                c.P(lev); c.WriteLine("for({0}=0;{0}<strlen({1});{0}++)", i, prefix);
                c.P(lev); c.WriteLine("{");
                ((ISCCSizeable)pThis).PrintCEncodeItem(cns, c, errorCode + "_elem", prefix + "[" + i + "]", lev + 1);
                c.P(lev); c.WriteLine("}");
            }
            else
            {
                SCCSizeable.PrintCEncodeFragmentation(pThis, cns, c, errorCode, varName, lev,
                    string.Format(nCount + " = strlen({0});", prefix), "", max, i, prefix, nCount, curBlockSize, curItem);
            }
        }
Esempio n. 5
0
        public static void PrintCDecodeItem(IA5StringType pThis, PEREffectiveConstraint cns, StreamWriterLevel c, string varName, int lev)
        {
            PERAlphabetAndSizeEffectiveConstraint cn = (PERAlphabetAndSizeEffectiveConstraint)cns;
            CharSet perAlphaCon = cn.m_from;
            int min = 0;
            int max;
            List<char> tmp = null;
            if (perAlphaCon != null)
                tmp = perAlphaCon.m_set;
            else
                tmp = new List<char>(pThis.AllowedCharSet);
            max = tmp.Count - 1;
            if (min == max)
                return;
            c.P(lev);
            c.Write("static byte allowedCharSet[] = {");
            for (int i = 0; i < tmp.Count; i++)
            {
                c.Write("0x{0:X2}", Convert.ToByte(tmp[i]));
                if (i == tmp.Count - 1)
                    c.WriteLine("};");
                else
                    c.Write(",");
                if ((i + 1) % 15 == 0)
                {
                    c.WriteLine();
                    c.P(lev + 7);
                }
            }
            c.P(lev);
            c.WriteLine("asn1SccSint charIndex = 0;");
            c.P(lev);
            c.WriteLine("if (!BitStream_DecodeConstraintWholeNumber(pBitStrm, &charIndex, {0}, {1})) {{", 0, tmp.Count - 1);
            c.P(lev + 1);
            c.WriteLine("*pErrCode = ERR_INSUFFICIENT_DATA;");
            c.P(lev + 1);
            c.WriteLine("return FALSE;");
            c.P(lev);
            c.WriteLine("}");

            c.P(lev);
            c.WriteLine("{0} = allowedCharSet[charIndex];", varName);
        }
Esempio n. 6
0
        public static void PrintCDecode(IA5StringType pThis, PEREffectiveConstraint cns, StreamWriterLevel c, string varName, int lev)
        {
            long min = pThis.minItems(cns);
            long max = pThis.maxItems(cns);
            string i = "i" + (CLocalVariable.GetArrayIndex(varName) + 1);
            string length = "length" + (CLocalVariable.GetArrayIndex(varName) + 1);
            string curBlockSize = "curBlockSize" + (CLocalVariable.GetArrayIndex(varName) + 1);
            //            string curItem = "curItem" + (CLocalVariable.GetArrayIndex(varName) + 1);
            string nCount = "nCount" + (CLocalVariable.GetArrayIndex(varName) + 1);
            string prefix = varName;

            c.P(lev);
            c.WriteLine("memset({0}, 0x0, {1});", varName, pThis.maxItems(cns) + 1);
            if (max < 0x10000)
            {
                if (min != max)
                {
                    c.P(lev);
                    c.WriteLine("if (!BitStream_DecodeConstraintWholeNumber(pBitStrm, &nCount, {0}, {1})) {{", min, max);
                    c.P(lev + 1);
                    c.WriteLine("*pErrCode = ERR_INSUFFICIENT_DATA;");
                    c.P(lev + 1);
                    c.WriteLine("return FALSE;");
                    c.P(lev);
                    c.WriteLine("}");

                    c.P(lev); c.WriteLine("for({0}=0;{0}<nCount;{0}++)", i);
                }
                else
                {
                    //c.P(lev);
                    //c.WriteLine("nCount = {0};", max);
                    c.P(lev); c.WriteLine("for({0}=0;{0}<{1};{0}++)", i,max);
                }
                c.P(lev); c.WriteLine("{");
                ((ISCCSizeable)pThis).PrintCDecodeItem(cns, c, prefix + "[" + i + "]", lev + 1);
                c.P(lev); c.WriteLine("}");
            }
            else
            {
                SCCSizeable.PrintCDecodeFragmentation(pThis, cns, c, varName, lev,
                        "", max, i, prefix, length, curBlockSize, nCount);
            }
        }
Esempio n. 7
0
 public static string CompareTo(IA5StringType pThis, string varName, Asn1Value constValue)
 {
     return string.Format("strcmp({0},{1})", varName, constValue.ToStringC());
 }