コード例 #1
0
ファイル: test.c プロジェクト: Refandler/gentee
int __cdecl main( int argc, char *argv[] )
{
   lex ilex;
   plexitem pil;
   buf in;
   str fn;
   arr out;
   uint i;
   uint fout;

   gentee_init();
   printf("Start\n");
   str_init( &fn );

   str_copyzero( &fn, "gttbl.dat");
   fout = os_fileopen( &fn, FOP_CREATE );
   printf("Fout=%i %s\n", fout, str_ptr( &fn ));
   os_filewrite( fout, ( pubyte )&tbl_gt, 97 * sizeof( uint ));
   os_fileclose( ( pvoid )fout );

   str_copyzero( &fn, "gtdotbl.dat");
   fout = os_fileopen( &fn, FOP_CREATE );
   printf("Fout=%i %s\n", fout, str_ptr( &fn ));
   str_delete( &fn );
   os_filewrite( fout, ( pubyte )&tbl_gtdo, 81 * sizeof( uint ));
   os_fileclose( ( pvoid )fout );

   arr_init( &out, sizeof( lexitem ));
   buf_init( &in );
   buf_copyzero( &in, 
      "</r/&xfa;&#10;&#3;&#1&xfa; #ap/dfield( 'qwer ()ty' , \"my , name\" , qqq)#asdf.fgwsw/# se# &xaa;"
      "<2 qqq> </2><1 a2345=&xf0;> 223&</1><-qwe-rty->"
      "<mygt /asd = \"qwerty sese'\" qq21 = 'dedxd' 'esese;' aqaq=325623/>"
      "<a asdff /a>   <mygtdd><a /><-ooops-><ad />< qq</>"
      "xxx  </r/nm <_aa aqaqa /_aaaa /_a/_aa><a22222/ >"
      "<*abc ></abc><|*aaa = qqqq></aaa>ooops aaa</eee>\"\r\n</>");
//   buf_copyzero( &in, "<mygt > <aaa asdff>qqqq</>      </mygtdd>qq </> xxx  </r/nm <_aa aqaqa /_aaaa /_aa> <a22222/ /> </ >  ");
   printf("lex_init\n");
   lex_init( &ilex, (puint)&tbl_gtdo );
   printf("gentee_lex\n");
   gentee_lex( &in, &ilex, &out );
   if (arr_count(&ilex.state))
      printf("================= State=%x/%i \n", arr_getuint( &ilex.state,
          arr_count(&ilex.state) - 1 ), arr_count(&ilex.state));
   for ( i = 0; i < arr_count( &out ); i++ )
   {
      pil = ( plexitem )arr_ptr( &out, i );
      printf("ID=%x pos=%i len=%i \n", pil->type, pil->pos, pil->len,
             buf_ptr( &in ) + pil->pos );
   }
//   gentee_compile();
   lex_delete( &ilex );
   buf_delete( &in );
   arr_delete( &out );
   gentee_deinit();
   printf("OK\n");
   getch();
   return 0;
}
コード例 #2
0
ファイル: test.c プロジェクト: Thar0l/mipt-lunev
int main(int argc, char *argv[])
{
	struct array *arr = NULL;
	unsigned int i = 0;
	unsigned int x = 0;
	unsigned int errors = 0;
	srand(time(NULL));
	printf("*********************************************\n");
	printf(" TEST 1\n");
	printf(" Normal array work. Size = %d\n",SIZE1);
	printf("*********************************************\n");
	errors = 0;
	printf("\tCreating ...\n");
	arr = arr_create(SIZE1);
	if (arr == NULL) errors++;
	printf("\tDone with %d errors.\n\n",errors);
	errors = 0;
	printf("\tSetting %d elements ...\n",SIZE1+4);
    for (i = 0; i < SIZE1; i++)
    {
    	x = rand()%MAXELEM;
    	if (arr_setitem(arr, 0, x) < 0) errors++;
    }
    if (arr_setitem(arr, SIZE1-1, 0) < 0) errors++;
    if (arr_setitem(arr, 1, 1) < 0) errors++;
    if (arr_setitem(arr, 1, 1) < 0) errors++;
    if (arr_setitem(arr, 1, MAXELEM+1) < 0) errors++;
	printf("\tDone with %d errors.\n\n",errors);
	errors = 0;
	printf("\tGetting %d elements ...\n",SIZE1);
    for (i = 0; i < SIZE1; i++)
    {
    	if (arr_getitem(arr,i,&x) < 0) errors++;
    }
	printf("\tDone with %d errors.\n\n",errors);
	errors=0;
	printf("\tIterator ...\n");
	if (arr_for_each(arr,(*sqr), NULL) < 0) errors++;
	printf("\tDone with %d errors.\n\n",errors);
	arr_delete(arr);


	printf("*********************************************\n");
	printf(" TEST 2\n");
	printf(" Zero array size. Working with empty array. \n");
	printf("*********************************************\n");
	errors = 0;
	printf("\tCreating ...\n");
	arr = arr_create(0);
	if (arr == NULL) errors++;
	printf("\tDone with %d errors.\n\n",errors);
	errors = 0;
	printf("\tSetting 1 element ...\n");
	if (arr_setitem(arr,0,x) < 0) errors++;
	printf("\tDone with %d errors.\n\n",errors);
	errors = 0;
	printf("\tGetting 1 element ...\n");
	if (arr_getitem(arr,0,&x) < 0) errors++;
	printf("\tDone with %d errors.\n\n",errors);
	errors=0;
	printf("\tIterator ...\n");
	if (arr_for_each(arr,(*sqr), NULL) < 0) errors++;
	printf("\tDone with %d errors.\n\n",errors);
	arr_delete(arr);


	printf("*********************************************\n");
	printf(" TEST 3\n");
	printf(" Invalid indexes. Size = %d\n",SIZE3);
	printf("*********************************************\n");
	errors = 0;
	printf("\tCreating ...\n");
	arr = arr_create(SIZE3);
	if (arr == NULL) errors++;
	printf("\tDone with %d errors.\n\n",errors);
	errors = 0;
	printf("\tSetting 3 elements ...\n");
	if (arr_setitem(arr,-1,x) < 0) errors++;
	if (arr_setitem(arr,SIZE3,x) < 0) errors++;
	if (arr_setitem(arr,SIZE3+1,x) < 0) errors++;
	printf("\tDone with %d errors.\n\n",errors);
	errors = 0;
	printf("\tGetting 3 elements ...\n");
	if (arr_getitem(arr,-1,&x) < 0) errors++;
	if (arr_getitem(arr,SIZE3,&x) < 0) errors++;
	if (arr_getitem(arr,SIZE3+1,&x) < 0) errors++;
	printf("\tDone with %d errors.\n\n",errors);
	arr_delete(arr);


	printf("*********************************************\n");
	printf(" TEST 4\n");
	printf(" Normal resizing. Size1 = %d, Size2 = %d, Size3 = %d\n", SIZE41, SIZE42, SIZE43);
	printf("*********************************************\n");
	errors = 0;
	printf("\tCreating ...\n");
	arr = arr_create(SIZE41);
	if (arr == NULL) errors++;
	printf("\tDone with %d errors.\n\n",errors);
	errors = 0;
	printf("\tSetting %d elements ...\n",SIZE41);
    for (i = 0; i < SIZE41; i++)
    {
    	x = rand()%MAXELEM;
    	if (arr_setitem(arr, 0, x) < 0) errors++;
    }
	printf("\tDone with %d errors.\n\n",errors);
	errors = 0;
	printf("\tPrinting Array ...\n");
	if (arr_for_each(arr,(*print), NULL) < 0) errors++;
	printf("\tDone with %d errors.\n\n",errors);
	errors = 0;
	printf("\tResizing Array from %d to %d ...\n", SIZE41, SIZE42);
	if (arr_resize(arr, SIZE42) < 0) errors++;
	printf("\tDone with %d errors.\n\n",errors);
	errors = 0;
	printf("\tPrinting Array ...\n");
	if (arr_for_each(arr,(*print), NULL) < 0) errors++;
	printf("\tDone with %d errors.\n\n",errors);
	errors = 0;
	printf("\tResizing Array from %d to %d ...\n", SIZE42, SIZE43);
	if (arr_resize(arr, SIZE43) < 0) errors++;
	printf("\tDone with %d errors.\n\n",errors);
	errors = 0;
	printf("\tPrinting Array ...\n");
	if (arr_for_each(arr,(*print), NULL) < 0) errors++;
	printf("\tDone with %d errors.\n\n",errors);
	arr_delete(arr);


	printf("*********************************************\n");
	printf(" TEST 5\n");
	printf(" Memory limit. \n");
	printf("*********************************************\n");
	struct rlimit r;
	r.rlim_cur=SIZE5;
	r.rlim_max=2*SIZE5;
	setrlimit(RLIMIT_AS, &r);
	errors = 0;
	printf("\tCreating with size = %d ...\n",SIZE5*5);
	arr = arr_create(SIZE5*5);
	if (arr == NULL) errors++;
	printf("\tDone with %d errors.\n\n",errors);
	errors = 0;
	arr_delete(arr);
	printf("\tCreating with size = %d ...\n",SIZE1);
	arr = arr_create(SIZE1);
	if (arr == NULL) errors++;
	printf("\tDone with %d errors.\n\n",errors);
	errors = 0;
	printf("\tSetting %d elements ...\n",SIZE1);
	for (i = 0; i < SIZE1; i++)
	{
	   	x = rand()%MAXELEM;
	   	if (arr_setitem(arr, 0, x) < 0) errors++;
	}
	printf("\tDone with %d errors.\n\n",errors);
	errors = 0;
	printf("\tPrinting Array ...\n");
	if (arr_for_each(arr,(*print), NULL) < 0) errors++;
	printf("\tDone with %d errors.\n\n",errors);
	errors = 0;
	printf("\tResizing Array from %d to %d ...\n", SIZE1, SIZE5*5);
	if (arr_resize(arr, SIZE5*5) < 0) errors++;
	printf("\tDone with %d errors.\n\n",errors);
	errors = 0;
	printf("\tResizing Array from %d to %d ...\n", SIZE1, SIZE5/2);
	if (arr_resize(arr, SIZE5) < 0) errors++;
	printf("\tDone with %d errors.\n\n",errors);
	errors = 0;
	printf("\tPrinting Array ...\n");
	if (arr_for_each(arr,(*print), NULL) < 0) errors++;
	printf("\tDone with %d errors.\n\n",errors);
	arr_delete(arr);


	printf("*********************************************\n");
	printf(" TEST 6\n");
	printf(" Resizing to zero size.\n");
	printf("*********************************************\n");
	errors = 0;
	printf("\tCreating with size = %d ...\n",SIZE1);
	arr = arr_create(SIZE1);
	if (arr == NULL) errors++;
	printf("\tDone with %d errors.\n\n",errors);
	errors = 0;
	printf("\tSetting %d elements ...\n",SIZE1);
    for (i = 0; i < SIZE1; i++)
    {
    	x = rand()%MAXELEM;
    	if (arr_setitem(arr, 0, x) < 0) errors++;
    }
    printf("\tDone with %d errors.\n\n",errors);
    errors = 0;
	printf("\tPrinting Array ...\n");
	if (arr_for_each(arr,(*print), NULL) < 0) errors++;
	printf("\tDone with %d errors.\n\n",errors);
	errors = 0;
	printf("\tResizing Array from %d to %d ...\n", SIZE1, 0);
	if (arr_resize(arr, 0) < 0) errors++;
	printf("\tDone with %d errors.\n\n",errors);
	errors = 0;
	printf("\tPrinting Array ...\n");
	if (arr_for_each(arr,(*print), NULL) < 0) errors++;
	printf("\tDone with %d errors.\n\n",errors);
	arr_delete(arr);
    return 0;
}
コード例 #3
0
ファイル: hash.c プロジェクト: Refandler/gentee
void  STDCALL hash_delete( phash ph )
{

   arr_delete( &ph->values );
   arr_delete( &ph->names );
}