1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
|
/*
*
* This file is part of the OpenLink Software Virtuoso Open-Source (VOS)
* project.
*
* Copyright (C) 1998-2012 OpenLink Software
*
* This project is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; only version 2 of the License, dated June 1991.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#include "Dk.h"
#include "xmlparser_impl.h"
/* stubs */
int f_read_from_rebuilt_database;
int f_config_file;
/* end of stubs */
typedef ptrlong (*array_reader)(void* array, ptrlong idx);
void printarray(void* array, array_reader reader)
{
ptrlong i;
char buf[80*100+1];
char namebuf[11];
char *ptr=buf;
memset(buf,' ',80*100);
for (i=0;i<10;i++)
{
sprintf (namebuf,"%ld",i);
memcpy(ptr,namebuf,strlen(namebuf));
ptr+=8;
}
*(ptr++)='\n';
memset(ptr,'-',80);
ptr+=80;
*(ptr++)='\n';
for (i=0;i<100;i++)
{
ptrlong res = reader(array,i);
sprintf (namebuf,"%ld",res);
memcpy(ptr,namebuf,strlen(namebuf));
ptr+=8;
if ((i%10) == 9)
*(ptr++)='\n';
}
ptr[0]=0;
printf("%s",buf);
}
static
ptrlong get_idx (struct xecm_big_array_s* array, ptrlong idx)
{
xecm_st_info_t* info = (xecm_st_info_t*)xecm_ba_get_val((void*)array,idx);
if (info)
return info->xsi_idx;
*((int*)0)=0;
return 0; /* keep compiler happy */
}
int main()
{
struct xecm_big_array_s* array = xecm_create_big_array(sizeof(ptrlong));
struct xecm_nexts_array_s* nexts = xecm_nexts_allocate(XECM_STORAGE_RARE, 100, 1);
struct xecm_nexts_array_s* nexts_copy;
const char* array1[]={"aaaa","cccc", "eeee", "ggggg", "hhhh", "xxxxx"};
const char* array2[]={"bbb","ddddd", "ffff", "iiiii", "jjjj", "zzzzz", "tttt"};
char **a1 = 0, **a2 = 0;
ptrlong sz1 = 0, sz2 = 0;
ptrlong i=0;
for (i=0;i<sizeof(array1)/sizeof(char*);i++)
ecm_add_name(array1[i],(void**)&a1,&sz1,sizeof(char*));
for (i=0;i<sizeof(array2)/sizeof(char*);i++)
ecm_add_name(array2[i],(void**)&a2,&sz2,sizeof(char*));
if (-1 == ecm_fuse_arrays((caddr_t*)&a1, &sz1,
(caddr_t)a2,sz2, sizeof(char*)))
{ printf("fuse failed\n"); }
else
{
for (i=0;i<sz1;i++)
printf ("a1[%ld]=%s\n", i, a1[i]);
}
/* xecm_ba_set_val(array, 1, 2);
xecm_ba_set_val(array, 2, 4);
xecm_ba_set_val(array, 3, 8);
xecm_ba_set_val(array, 8, 255);
xecm_ba_set_val(array, 16, 256*256-1);
xecm_ba_set_val(array, 10, 100);
xecm_ba_set_val(array, 99, 100000); */
xecm_set_nextidx(nexts, 1, 2);
xecm_set_nextidx(nexts, 2, 4);
xecm_set_nextidx(nexts, 3, 8);
xecm_set_nextidx(nexts, 8, 255);
xecm_set_nextidx(nexts, 3, 9);
xecm_set_nextidx(nexts, 16, 256*256-1);
xecm_set_nextidx(nexts, 3, 13);
xecm_set_nextidx(nexts, 10, 100);
xecm_set_nextidx(nexts, 99, 100000);
xecm_set_nextidx(nexts, 1, 11);
xecm_set_nextidx(nexts, 2, 12);
nexts_copy = xecm_copy_nexts(nexts);
printf("0\\\n");
printarray(array,(array_reader)xecm_ba_get_val);
printf("1\\\n");
printarray(nexts,(array_reader)xecm_get_nextidx);
printf("2\\\n");
printarray(nexts->na_nexts.rare,(array_reader)get_idx);
printf("3\\\n");
printarray(nexts_copy->na_nexts.rare,(array_reader)get_idx);
xecm_nexts_free(nexts);
xecm_nexts_free(nexts_copy);
return 0;
}
|