예제 #1
0
void
gui_completion_free_data (struct t_gui_completion *completion)
{
    if (completion->base_command)
        free (completion->base_command);
    completion->base_command = NULL;

    if (completion->base_word)
        free (completion->base_word);
    completion->base_word = NULL;

    if (completion->args)
        free (completion->args);
    completion->args = NULL;

    if (completion->list)
    {
        arraylist_free (completion->list);
        completion->list = NULL;
    }

    if (completion->word_found)
        free (completion->word_found);
    completion->word_found = NULL;

    if (completion->partial_list)
    {
        arraylist_free (completion->partial_list);
        completion->partial_list = NULL;
    }
}
예제 #2
0
int main() {
	ARRAYLIST myArrayList = arraylist_init();
	myArrayList->Array = malloc(10*sizeof(int));

    int j,k,l,m,n;
    j = 1;
    k = 2;
    l = 5;
    n = 3;
	m = 4;

    arraylist_prepend(myArrayList, &j);
	printArr(myArrayList);

    arraylist_append(myArrayList, &k);
    arraylist_append(myArrayList, &l);
    arraylist_append(myArrayList, &j);
    arraylist_append(myArrayList, &n);
	printArr(myArrayList);

	arraylist_insert(myArrayList, &m, 1);//insert 4 to index 1
	printArr(myArrayList);

    int u = 8;
	arraylist_set(myArrayList, &u, 3);// set index 3 as 8
	printArr(myArrayList);

    int *a = arraylist_get(myArrayList, 3);//get address of index 3
	printf("get %d\n", *a);

    arraylist_insert(myArrayList, &m, 10);//insert 4 to index of 10 which does not exist
	printArr(myArrayList);

    arraylist_insert(myArrayList, &k, 15);//insert 2 to index of 15 which does not exist
    printArr(myArrayList);

    arraylist_set(myArrayList, &k, 7);//set index 7 as 2
	printArr(myArrayList);

    arraylist_remove(myArrayList, 1);//remove index of 9
	printArr(myArrayList);

    arraylist_removeall(myArrayList);//remove everything
    printArr(myArrayList);

    arraylist_free(myArrayList);
    return 1;
}
예제 #3
0
파일: libpeers.c 프로젝트: drfh/p2plib
void p2p_free(p2p_ctx *ctx)
{
	if(ctx!=NULL)
	{
		int		thread_status=0;

		pthread_mutex_lock(&ctx->mutex);
		ctx->status=0;
		pthread_mutex_unlock(&ctx->mutex);
		thread_status=pthread_join(ctx->tid,NULL);
		printf("thread joined with status: %d\n",thread_status);
		if(ctx->peers!=NULL)
		{
			arraylist_free(ctx->peers);
		}
		pthread_mutex_destroy(&ctx->mutex);
		free(ctx);
	}
}
예제 #4
0
JNIEXPORT jstring JNICALL
Java_universe_constellation_orion_viewer_djvu_DjvuDocument_getText(JNIEnv *env, jobject thiz, int pageNumber,
		int startX, int startY, int width, int height)
{

    LOGI("==================Start Text Extraction==============");

    miniexp_t pagetext;
    while ((pagetext=ddjvu_document_get_pagetext(doc,pageNumber,0))==miniexp_dummy) {
      //handle_ddjvu_messages(ctx, TRUE);
    }

    if (miniexp_nil == pagetext) {
        return NULL;
    }
//
    ddjvu_status_t status;
    ddjvu_pageinfo_t info;
    while ((status = ddjvu_document_get_pageinfo(doc, pageNumber, &info)) < DDJVU_JOB_OK) {
        //nothing
    }

	LOGI("Extraction rectangle=[%d,%d,%d,%d]", startX, startY, width, height);

	Arraylist values = arraylist_create();

    int w = info.width;
    int h = info.height;
    fz_bbox target = {startX, h - startY - height, startX + width, h - startY};
    LOGI("Extraction irectangle=[%d,%d,%d,%d]", target.x0, target.y0, target.x1, target.y1);

	extractText(pagetext, values, &target);

	arraylist_add(values, 0);

    LOGI("Data: %s", arraylist_getData(values));
    jstring result = (*env)->NewStringUTF(env, arraylist_getData(values));
    arraylist_free(values);

    return result;
}
예제 #5
0
void seqstack_free(ArrayList *seqstack) {
	arraylist_free(seqstack);
}
예제 #6
0
static void test_arraylist (void) {
  ArrayList* arraylist;

  arraylist = arraylist_new (0);
  arraylist_free (arraylist);
  }
예제 #7
0
void
test_arraylist (int initial_size, int sorted, int allow_duplicates)
{
    struct t_arraylist *arraylist;
    int i, index, index_insert;
    void *pointer;
    const char *item_aaa = "aaa";
    const char *item_abc = "abc";
    const char *item_DEF = "DEF";
    const char *item_Def = "Def";
    const char *item_def = "def";
    const char *item_xxx = "xxx";
    const char *item_zzz = "zzz";

    /* create arraylist */
    arraylist = arraylist_new (initial_size,
                               sorted,
                               allow_duplicates,
                               &test_cmp_cb, NULL,
                               NULL, NULL);

    /* check values after creation */
    CHECK(arraylist);
    LONGS_EQUAL(0, arraylist->size);
    LONGS_EQUAL(initial_size, arraylist->size_alloc);
    LONGS_EQUAL(initial_size, arraylist->size_alloc_min);
    if (initial_size > 0)
    {
        CHECK(arraylist->data);
        for (i = 0; i < initial_size; i++)
        {
            POINTERS_EQUAL(NULL, arraylist->data[i]);
        }
    }
    else
    {
        POINTERS_EQUAL(NULL, arraylist->data);
    }
    LONGS_EQUAL(sorted, arraylist->sorted);
    LONGS_EQUAL(allow_duplicates, arraylist->allow_duplicates);

    /* check size */
    LONGS_EQUAL(0, arraylist_size (arraylist));

    /* get element (this should always fail, the list is empty!) */
    POINTERS_EQUAL(NULL, arraylist_get (NULL, -1));
    POINTERS_EQUAL(NULL, arraylist_get (NULL, 0));
    POINTERS_EQUAL(NULL, arraylist_get (NULL, 1));
    POINTERS_EQUAL(NULL, arraylist_get (arraylist, -1));
    POINTERS_EQUAL(NULL, arraylist_get (arraylist, 0));
    POINTERS_EQUAL(NULL, arraylist_get (arraylist, 1));

    /* search element (this should always fail, the list is empty!) */
    POINTERS_EQUAL(NULL, arraylist_search (NULL, NULL, NULL, NULL));
    POINTERS_EQUAL(NULL, arraylist_search (arraylist, NULL, NULL, NULL));
    POINTERS_EQUAL(NULL,
                   arraylist_search (NULL, (void *)item_abc, NULL, NULL));
    POINTERS_EQUAL(NULL,
                   arraylist_search (arraylist, (void *)item_abc, NULL, NULL));

    /* invalid add of element */
    LONGS_EQUAL(-1, arraylist_add (NULL, NULL));

    /* add some elements */
    if (sorted)
    {
        TEST_ARRAYLIST_ADD(0, item_zzz);
        TEST_ARRAYLIST_ADD(0, item_xxx);
        TEST_ARRAYLIST_ADD(0, NULL);
        TEST_ARRAYLIST_ADD(1, item_DEF);
        TEST_ARRAYLIST_ADD((allow_duplicates) ? 2 : 1, item_def);
        TEST_ARRAYLIST_ADD((allow_duplicates) ? 3 : 1, item_Def);
        TEST_ARRAYLIST_ADD(1, item_abc);
    }
    else
    {
        TEST_ARRAYLIST_ADD(0, item_zzz);
        TEST_ARRAYLIST_ADD(1, item_xxx);
        TEST_ARRAYLIST_ADD(2, NULL);
        TEST_ARRAYLIST_ADD(3, item_DEF);
        TEST_ARRAYLIST_ADD((allow_duplicates) ? 4 : 3, item_def);
        TEST_ARRAYLIST_ADD((allow_duplicates) ? 5 : 3, item_Def);
        TEST_ARRAYLIST_ADD((allow_duplicates) ? 6 : 4, item_abc);
    }

    /*
     * arraylist is now:
     *   sorted:
     *     dup   : [NULL, "abc", "DEF", "def", "Def", "xxx", "zzz"] + 2 NULL
     *     no dup: [NULL, "abc", "Def", "xxx", "zzz"] + 1 NULL
     *   not sorted:
     *     dup   : ["zzz", "xxx", NULL, "DEF", "def", "Def", "abc"] + 2 NULL
     *     no dup: ["zzz", "xxx", NULL, "Def", "abc"] + 1 NULL
     */

    /* check size after adds */
    LONGS_EQUAL((allow_duplicates) ? 7 : 5, arraylist->size);
    LONGS_EQUAL((allow_duplicates) ? 7 : 5, arraylist_size (arraylist));
    LONGS_EQUAL((allow_duplicates) ? 9 : 6, arraylist->size_alloc);

    /* check content after adds */
    if (sorted)
    {
        if (allow_duplicates)
        {
            POINTERS_EQUAL(NULL, arraylist->data[0]);
            STRCMP_EQUAL(item_abc, (const char *)arraylist->data[1]);
            STRCMP_EQUAL(item_DEF, (const char *)arraylist->data[2]);
            STRCMP_EQUAL(item_def, (const char *)arraylist->data[3]);
            STRCMP_EQUAL(item_Def, (const char *)arraylist->data[4]);
            STRCMP_EQUAL(item_xxx, (const char *)arraylist->data[5]);
            STRCMP_EQUAL(item_zzz, (const char *)arraylist->data[6]);
            for (i = 7; i < arraylist->size_alloc; i++)
            {
                POINTERS_EQUAL(NULL, arraylist->data[i]);
            }
        }
        else
        {
            POINTERS_EQUAL(NULL, arraylist->data[0]);
            STRCMP_EQUAL(item_abc, (const char *)arraylist->data[1]);
            STRCMP_EQUAL(item_Def, (const char *)arraylist->data[2]);
            STRCMP_EQUAL(item_xxx, (const char *)arraylist->data[3]);
            STRCMP_EQUAL(item_zzz, (const char *)arraylist->data[4]);
            for (i = 5; i < arraylist->size_alloc; i++)
            {
                POINTERS_EQUAL(NULL, arraylist->data[i]);
            }
        }
    }
    else
    {
        if (allow_duplicates)
        {
            STRCMP_EQUAL(item_zzz, (const char *)arraylist->data[0]);
            STRCMP_EQUAL(item_xxx, (const char *)arraylist->data[1]);
            POINTERS_EQUAL(NULL, arraylist->data[2]);
            STRCMP_EQUAL(item_DEF, (const char *)arraylist->data[3]);
            STRCMP_EQUAL(item_def, (const char *)arraylist->data[4]);
            STRCMP_EQUAL(item_Def, (const char *)arraylist->data[5]);
            STRCMP_EQUAL(item_abc, (const char *)arraylist->data[6]);
            for (i = 7; i < arraylist->size_alloc; i++)
            {
                POINTERS_EQUAL(NULL, arraylist->data[i]);
            }
        }
        else
        {
            STRCMP_EQUAL(item_zzz, (const char *)arraylist->data[0]);
            STRCMP_EQUAL(item_xxx, (const char *)arraylist->data[1]);
            POINTERS_EQUAL(NULL, arraylist->data[2]);
            STRCMP_EQUAL(item_Def, (const char *)arraylist->data[3]);
            STRCMP_EQUAL(item_abc, (const char *)arraylist->data[4]);
            for (i = 5; i < arraylist->size_alloc; i++)
            {
                POINTERS_EQUAL(NULL, arraylist->data[i]);
            }
        }
    }

    /* search elements */
    if (sorted)
    {
        if (allow_duplicates)
        {
            TEST_ARRAYLIST_SEARCH(NULL, 0, 1, NULL);
            TEST_ARRAYLIST_SEARCH(item_abc, 1, 2, item_abc);
            TEST_ARRAYLIST_SEARCH(item_DEF, 2, 5, item_DEF);
            TEST_ARRAYLIST_SEARCH(item_DEF, 2, 5, item_def);
            TEST_ARRAYLIST_SEARCH(item_DEF, 2, 5, item_Def);
            TEST_ARRAYLIST_SEARCH(item_xxx, 5, 6, item_xxx);
            TEST_ARRAYLIST_SEARCH(item_zzz, 6, 7, item_zzz);
        }
        else
        {
            TEST_ARRAYLIST_SEARCH(NULL, 0, 1, NULL);
            TEST_ARRAYLIST_SEARCH(item_abc, 1, 2, item_abc);
            TEST_ARRAYLIST_SEARCH(item_Def, 2, 3, item_DEF);
            TEST_ARRAYLIST_SEARCH(item_Def, 2, 3, item_def);
            TEST_ARRAYLIST_SEARCH(item_Def, 2, 3, item_Def);
            TEST_ARRAYLIST_SEARCH(item_xxx, 3, 4, item_xxx);
            TEST_ARRAYLIST_SEARCH(item_zzz, 4, 5, item_zzz);
        }

        /* search non-existing element */
        TEST_ARRAYLIST_SEARCH(NULL, -1, 1, item_aaa);
    }
    else
    {
        if (allow_duplicates)
        {
            TEST_ARRAYLIST_SEARCH(item_zzz, 0, -1, item_zzz);
            TEST_ARRAYLIST_SEARCH(item_xxx, 1, -1, item_xxx);
            TEST_ARRAYLIST_SEARCH(NULL, 2, -1, NULL);
            TEST_ARRAYLIST_SEARCH(item_DEF, 3, -1, item_DEF);
            TEST_ARRAYLIST_SEARCH(item_DEF, 3, -1, item_def);
            TEST_ARRAYLIST_SEARCH(item_DEF, 3, -1, item_Def);
            TEST_ARRAYLIST_SEARCH(item_abc, 6, -1, item_abc);
        }
        else
        {
            TEST_ARRAYLIST_SEARCH(item_zzz, 0, -1, item_zzz);
            TEST_ARRAYLIST_SEARCH(item_xxx, 1, -1, item_xxx);
            TEST_ARRAYLIST_SEARCH(NULL, 2, -1, NULL);
            TEST_ARRAYLIST_SEARCH(item_Def, 3, -1, item_DEF);
            TEST_ARRAYLIST_SEARCH(item_Def, 3, -1, item_def);
            TEST_ARRAYLIST_SEARCH(item_Def, 3, -1, item_Def);
            TEST_ARRAYLIST_SEARCH(item_abc, 4, -1, item_abc);
        }

        /* search non-existing element */
        TEST_ARRAYLIST_SEARCH(NULL, -1, -1, item_aaa);
    }

    /* invalid remove of elements */
    LONGS_EQUAL(-1, arraylist_remove (NULL, -1));
    LONGS_EQUAL(-1, arraylist_remove (arraylist, -1));
    LONGS_EQUAL(-1, arraylist_remove (NULL, 0));

    /* remove the 3 first elements and check size after each remove */
    LONGS_EQUAL(0, arraylist_remove (arraylist, 0));
    LONGS_EQUAL((allow_duplicates) ? 6 : 4, arraylist->size);
    LONGS_EQUAL((allow_duplicates) ? 6 : 4, arraylist_size (arraylist));
    LONGS_EQUAL((allow_duplicates) ? 9 : 6, arraylist->size_alloc);
    LONGS_EQUAL(0, arraylist_remove (arraylist, 0));
    LONGS_EQUAL((allow_duplicates) ? 5 : 3, arraylist->size);
    LONGS_EQUAL((allow_duplicates) ? 5 : 3, arraylist_size (arraylist));
    LONGS_EQUAL((allow_duplicates) ? 9 : 6, arraylist->size_alloc);
    LONGS_EQUAL(0, arraylist_remove (arraylist, 0));
    LONGS_EQUAL((allow_duplicates) ? 4 : 2, arraylist->size);
    LONGS_EQUAL((allow_duplicates) ? 4 : 2, arraylist_size (arraylist));
    LONGS_EQUAL((allow_duplicates) ? 5 : 3, arraylist->size_alloc);

    /*
     * arraylist is now:
     *   sorted:
     *     dup   : ["def", "Def", "xxx", "zzz"] + 1 NULL
     *     no dup: ["xxx", "zzz"] + 1 NULL
     *   not sorted:
     *     dup   : ["DEF", "def", "Def", "abc"] + 1 NULL
     *     no dup: ["Def", "abc"] + 1 NULL
     */

    /* check content after the 3 deletions */
    if (sorted)
    {
        if (allow_duplicates)
        {
            STRCMP_EQUAL(item_def, (const char *)arraylist->data[0]);
            STRCMP_EQUAL(item_Def, (const char *)arraylist->data[1]);
            STRCMP_EQUAL(item_xxx, (const char *)arraylist->data[2]);
            STRCMP_EQUAL(item_zzz, (const char *)arraylist->data[3]);
            for (i = 4; i < arraylist->size_alloc; i++)
            {
                POINTERS_EQUAL(NULL, arraylist->data[i]);
            }
        }
        else
        {
            STRCMP_EQUAL(item_xxx, (const char *)arraylist->data[0]);
            STRCMP_EQUAL(item_zzz, (const char *)arraylist->data[1]);
            for (i = 2; i < arraylist->size_alloc; i++)
            {
                POINTERS_EQUAL(NULL, arraylist->data[i]);
            }
        }
    }
    else
    {
        if (allow_duplicates)
        {
            STRCMP_EQUAL(item_DEF, (const char *)arraylist->data[0]);
            STRCMP_EQUAL(item_def, (const char *)arraylist->data[1]);
            STRCMP_EQUAL(item_Def, (const char *)arraylist->data[2]);
            STRCMP_EQUAL(item_abc, (const char *)arraylist->data[3]);
            for (i = 4; i < arraylist->size_alloc; i++)
            {
                POINTERS_EQUAL(NULL, arraylist->data[i]);
            }
        }
        else
        {
            STRCMP_EQUAL(item_Def, (const char *)arraylist->data[0]);
            STRCMP_EQUAL(item_abc, (const char *)arraylist->data[1]);
            for (i = 2; i < arraylist->size_alloc; i++)
            {
                POINTERS_EQUAL(NULL, arraylist->data[i]);
            }
        }
    }

    /* invalid insert of element */
    LONGS_EQUAL(-1, arraylist_insert (NULL, 0, NULL));

    /* insert of one element */
    LONGS_EQUAL(0, arraylist_insert (arraylist, 0, (void *)item_aaa));

    /*
     * arraylist is now:
     *   sorted:
     *     dup   : ["aaa", "def", "Def", "xxx", "zzz"]
     *     no dup: ["aaa", "xxx", "zzz"]
     *   not sorted:
     *     dup   : ["aaa", "DEF", "def", "Def", "abc"]
     *     no dup: ["aaa", "Def", "abc"]
     */

    /* check size after insert */
    LONGS_EQUAL((allow_duplicates) ? 5 : 3, arraylist->size);
    LONGS_EQUAL((allow_duplicates) ? 5 : 3, arraylist_size (arraylist));
    LONGS_EQUAL((allow_duplicates) ? 5 : 3, arraylist->size_alloc);

    /* check content after the insert */
    if (sorted)
    {
        if (allow_duplicates)
        {
            STRCMP_EQUAL(item_aaa, (const char *)arraylist->data[0]);
            STRCMP_EQUAL(item_def, (const char *)arraylist->data[1]);
            STRCMP_EQUAL(item_Def, (const char *)arraylist->data[2]);
            STRCMP_EQUAL(item_xxx, (const char *)arraylist->data[3]);
            STRCMP_EQUAL(item_zzz, (const char *)arraylist->data[4]);
            for (i = 5; i < arraylist->size_alloc; i++)
            {
                POINTERS_EQUAL(NULL, arraylist->data[i]);
            }
        }
        else
        {
            STRCMP_EQUAL(item_aaa, (const char *)arraylist->data[0]);
            STRCMP_EQUAL(item_xxx, (const char *)arraylist->data[1]);
            STRCMP_EQUAL(item_zzz, (const char *)arraylist->data[2]);
            for (i = 3; i < arraylist->size_alloc; i++)
            {
                POINTERS_EQUAL(NULL, arraylist->data[i]);
            }
        }
    }
    else
    {
        if (allow_duplicates)
        {
            STRCMP_EQUAL(item_aaa, (const char *)arraylist->data[0]);
            STRCMP_EQUAL(item_DEF, (const char *)arraylist->data[1]);
            STRCMP_EQUAL(item_def, (const char *)arraylist->data[2]);
            STRCMP_EQUAL(item_Def, (const char *)arraylist->data[3]);
            STRCMP_EQUAL(item_abc, (const char *)arraylist->data[4]);
            for (i = 5; i < arraylist->size_alloc; i++)
            {
                POINTERS_EQUAL(NULL, arraylist->data[i]);
            }
        }
        else
        {
            STRCMP_EQUAL(item_aaa, (const char *)arraylist->data[0]);
            STRCMP_EQUAL(item_Def, (const char *)arraylist->data[1]);
            STRCMP_EQUAL(item_abc, (const char *)arraylist->data[2]);
            for (i = 3; i < arraylist->size_alloc; i++)
            {
                POINTERS_EQUAL(NULL, arraylist->data[i]);
            }
        }
    }

    /* clear arraylist */
    LONGS_EQUAL(0, arraylist_clear (NULL));
    LONGS_EQUAL(1, arraylist_clear (arraylist));

    /* check size and data after clear */
    LONGS_EQUAL(0, arraylist->size);
    LONGS_EQUAL(0, arraylist_size (arraylist));
    LONGS_EQUAL(initial_size, arraylist->size_alloc);
    if (initial_size > 0)
    {
        CHECK(arraylist->data);
        for (i = 0; i < initial_size; i++)
        {
            POINTERS_EQUAL(NULL, arraylist->data[i]);
        }
    }
    else
    {
        POINTERS_EQUAL(NULL, arraylist->data);
    }

    /* free arraylist */
    arraylist_free (arraylist);
}