void column::debug_print(const char *s) { char c = '\0'; // shut up -Wall switch (align) { case LEFT_ALIGN: c = 'l'; break; case RIGHT_ALIGN: c = 'r'; break; case CENTER_ALIGN: c = 'c'; break; default: assert(0); } fprintf(stderr, "%c%s %d { ", c, s, space); list_debug_print(" above "); fprintf(stderr, " }"); }
int main(void) { data_t *datap = NULL; list_t *Lptr = NULL; /***** Lptr = list_construct(trte_compare, trte_route_rec_cleanup); // create one item to test list_insert datap = (data_t *) calloc(1,sizeof(data_t)); datap->src_ip_addr = 555; datap->dest_ip_addr = 555; list_insert(Lptr, datap, LISTPOS_HEAD); datap = NULL; // add a second item to head of the list datap = (data_t *) calloc(1,sizeof(data_t)); datap->src_ip_addr = 444; datap->dest_ip_addr = 444; list_insert(Lptr, datap, LISTPOS_HEAD); datap = NULL; // add a 3rd item to tail of the list datap = (data_t *) calloc(1,sizeof(data_t)); datap->src_ip_addr = 777; datap->dest_ip_addr = 777; list_insert(Lptr, datap, LISTPOS_TAIL); datap = NULL; // add a 4th item datap = (data_t *) calloc(1,sizeof(data_t)); datap->src_ip_addr = 500; datap->dest_ip_addr = 500; list_insert(Lptr, datap, LISTPOS_TAIL); datap = NULL; // add a 4th item, sorted datap = (data_t *) calloc(1,sizeof(data_t)); datap->src_ip_addr = 333; datap->dest_ip_addr = 333; list_insert_sorted(Lptr, datap); datap = NULL; // test list_access with one item in list datap = list_access(Lptr, LISTPOS_HEAD); printf("Should find 555 and found (%d)\n\n", datap->src_ip_addr); datap = NULL; // find all three and print datap = list_access(Lptr, 0); printf("Second test\nPosition 0 should find 555 and found (%d)\n", datap->src_ip_addr); datap = list_access(Lptr, 1); printf("Position 1 should find 555 and found (%d)\n", datap->src_ip_addr); datap = list_access(Lptr, 2); printf("Position 2 should find 777 and found (%d)\n", datap->src_ip_addr); datap = list_access(Lptr, 3); printf("Position 3 should find 777 and found (%d)\n", datap->src_ip_addr); datap = list_access(Lptr, 3); printf("Position 3 should find 777 and found (%d)\n", datap->src_ip_addr); //Next try to use list_debug_print printf("\nTest of list print\n\n"); list_debug_print(Lptr); */ // Uncomment this section to test list_elem_find /********************************************************************* data_t template; int my_index = -999; template.src_ip_addr = 444; template.dest_ip_addr = 444; data_t *foundp = list_elem_find(Lptr, &template, &my_index); printf("\nTest of list elem find\n"); if (foundp != NULL) printf("looked for %d and found %d at index %d\n", template.src_ip_addr, foundp->src_ip_addr, my_index); else printf("looked for %d and did not find \n", template.src_ip_addr); foundp = NULL; */ //list_destruct(Lptr); // End of tests with unsorted list // Uncomment this section to try some tests on a sorted list /*********************************************************************/ list_t *Lsortptr = list_construct(trte_compare, trte_route_rec_cleanup); //Lsortptr->list_sorted_state = -7654321; datap = (data_t *) calloc(1,sizeof(data_t)); datap->src_ip_addr = 23; datap->dest_ip_addr = 23; list_insert_sorted(Lsortptr, datap); datap = NULL; // add a second item datap = (data_t *) calloc(1,sizeof(data_t)); datap->src_ip_addr = 7; datap->dest_ip_addr = 7; list_insert_sorted(Lsortptr, datap); datap = NULL; // add a third item datap = (data_t *) calloc(1,sizeof(data_t)); datap->src_ip_addr = 15; datap->dest_ip_addr = 15; list_insert_sorted(Lsortptr, datap); datap = NULL; // add a fourth item datap = (data_t *) calloc(1,sizeof(data_t)); datap->src_ip_addr = 8; datap->dest_ip_addr = 8; list_insert_sorted(Lsortptr, datap); datap = NULL; // add a fifth item datap = (data_t *) calloc(1,sizeof(data_t)); datap->src_ip_addr = 28; datap->dest_ip_addr = 28; list_insert_sorted(Lsortptr, datap); datap = NULL; //print list_debug_print(Lsortptr); // remove an item data_t *temp = list_remove(Lsortptr, 3); //print list_debug_print(Lsortptr); // add a sixth item datap = (data_t *) calloc(1,sizeof(data_t)); datap->src_ip_addr = 2; datap->dest_ip_addr = 2; list_insert_sorted(Lsortptr, datap); datap = NULL; list_reverse(Lsortptr); //print list_debug_print(Lsortptr); list_destruct(Lsortptr); return 0; }