icl_list_test.c

Go to the documentation of this file.
00001 
00007 /* $Id: icl_list_test.c,v 1.3 2004/09/12 05:21:15 seymour Exp $ */
00008 /* $UTK_Copyright: $ */
00009 
00010 #include <stdlib.h>
00011 #include <stdio.h>
00012 #include <string.h>
00013 
00014 #include "icl_list.h"
00015 
00016 /* This function can be used as a standin for strcmp, to avoid the
00017    warnings about incompatible pointer types */
00018 int cmp(void* p1, void* p2) { return strcmp((char*)p1, (char*) p2); }
00019 #undef strcmp
00020 #define strcmp cmp
00021 
00031 int main(int argc, char** argv)
00032 {
00033   icl_list_t* head = icl_list_new();
00034   icl_list_t* l = NULL;
00035   
00036   icl_list_prepend(head, strdup("A word"));
00037   icl_list_prepend(head, strdup("B word"));
00038   icl_list_prepend(head, strdup("This word"));
00039   icl_list_prepend(head, strdup("C word"));
00040   icl_list_prepend(head, strdup("D word"));
00041   icl_list_prepend(head, strdup("That word"));
00042   
00043   printf("size %d\n", icl_list_size(head));
00044   
00045   printf("Printing the list\n");
00046   for (l=icl_list_first(head); l!=NULL; l=icl_list_next(head, l)) {
00047     printf("%s\n", (char *)l->data);
00048   }
00049   
00050   printf("Search: This word\n");
00051   l=icl_list_search(head, "This word", strcmp);
00052   printf("Found %s\n", (char *)l->data);
00053   
00054   printf("Insert: After this word\n");
00055   l=icl_list_insert(head, l, strdup("After this word"));
00056   
00057   printf("Search: This man\n");
00058   l=icl_list_search(head, "This man", strcmp);
00059   if (l!=NULL)  printf("Found %s\n", (char *)l->data);
00060   else printf("Not found\n");
00061 
00062   printf("Search: After this word\n");
00063   l=icl_list_search(head, "After this word", strcmp);
00064   if (l!=NULL)  printf("Found %s\n", (char *)l->data);
00065   else printf("Not found\n");
00066 
00067   icl_list_destroy(head, free);
00068 
00069   exit(EXIT_SUCCESS);
00070 }