Example #1
0
        public int makelit(DDlDevDescription.STRING_TBL string_tbl, bool isLatin1)
        {
            //List<ddpSTRING> dstring = null;      /* temp pointer for the list */
            //List<ddpSTRING> end_string = null;   /* end pointer for the list */

            uint index = 0;

            foreach (ddpSTRING dstring in string_tbl.list)
            {// a list of ddpSTRING
                /*
                 * string hld;
                 * hld = dstring.str;
                 * string lit;
                 * dstring.str = null;// stevev 28sep11 - take ownership of the memory
                 * if (isLatin1)
                 * {
                 *  //int iAllocLength = latin2utf8size(string->str) + 1;
                 *  int iAllocLength = hld.Length + 1;
                 *      //latin2utf8size(hld) + 1;
                 *  lit = new char[iAllocLength];
                 *  //if (lit == (char*)0)
                 *  {
                 *      //LOGIT(CERR_LOG, L"Memory exhausted.\n");
                 *      //exit(-1);
                 *  }
                 *
                 *  //latin2utf8(string->str, lit, iAllocLength);
                 *  latin2utf8(hld, lit, iAllocLength);
                 *  //delete[] hld;
                 * }
                 * else
                 * {
                 *  lit = hld;  // before this change, valid utf8 strings caused a
                 *              // NULL to install in the table [2/27/2014 timj]
                 * }
                 */
                install(index++, dstring.str);
            }

            return(0);   // dicterrs            ;
        }
Example #2
0
        public unsafe static int eval_dir_string_tbl(ref DDlDevDescription.STRING_TBL string_tbl, ref DDlDevDescription.BININFO bin)
        {

            //ddpSTRING * string = NULL;      /* temp pointer for the list */
            //ddpSTRING* end_string = NULL;   /* end pointer for the list */
            UInt64 temp_int;      /* integer value */
            uint size = 0;         /* temp size */
            //byte* root_ptr = null;     /* temp pointer */
            //int rc = 0;             /* return code */

            //ASSERT_DBG(bin && bin->chunk && bin->size);

            /* parse count */
            fixed (byte* chunk = &bin.chunk[bin.uoffset])
            {
                fixed (uint* pz = &bin.size)
                {
                    Common.DDL_PARSE_INTEGER(&chunk, pz, &temp_int);
                    /* parse count */

                    /*
                     * if count is zero
                     */

                    if (temp_int == 0)
                    {

                        string_tbl.count = 0;
                        string_tbl.list = null;
                        return Common.DDL_SUCCESS;
                    }

                    //assert(temp_int < MAXIMUM_INT);

                    string_tbl.count = (int)temp_int;

                    /* malloc the list */
                    string_tbl.list = new ddpSTRING[temp_int];
                    //if (string_tbl->list == NULL)
                    //{

                    //    string_tbl->count = 0;
                    //    return DDL_MEMORY_ERROR;
                    //}

                    /* malloc the root */
                    /*	string_tbl->root =
                            (unsigned char *)new char[((size_t) (bin->size ))];
                        if (string_tbl->root == NULL) {

                            return DDL_MEMORY_ERROR;
                        }

                        /* load list with zeros */
                    /*	(void)memset((char *) string_tbl->list, 0,
                                (size_t) (temp_int * sizeof(ddpSTRING))); */

                    /* copy the chunk to the root */
                    /*	(void)memcpy((char *) string_tbl->root, (char *) bin->chunk,
                                (size_t) (bin->size * sizeof(unsigned char))); */

                    /*
                     * load the list
                     */


                    size = bin.size;
                    byte* ch = chunk;
                    for (uint i = 0; i < string_tbl.count; i++)
                    {
                        Common.DDL_PARSE_INTEGER(&ch, &size, &temp_int);
                        byte[] rootchar = new byte[temp_int];
                        string_tbl.list[i] = new ddpSTRING();
                        for (uint j = 0; j < temp_int; j++)
                        {
                            rootchar[j] = ch[j];//bin.chunk[bin.uoffset + j + i * temp_int];//Encoding.ASCII.GetChars(bin.chunk)
                        }
                        string_tbl.list[(int)i].len = (ushort)temp_int;//??????
                        string_tbl.list[(int)i].str = Encoding.Default.GetString(rootchar);//Convert.ToString(rootchar);// new string(rootchar);// Convert.ToBase64String(bin.chunk);//??????
                        string_tbl.list[(int)i].str = string_tbl.list[(int)i].str.TrimEnd('\0');
                        string_tbl.list[(int)i].flags = Common.DONT_FREE_STRING;
                        size -= (ushort)temp_int;
                        ch += temp_int;
                    }

                }
            }
            return Common.DDL_SUCCESS;
        }