int main(int argc, char *argv[]) { el *name, *tmp; el *head = NULL; char linebuf[BUFLEN]; FILE *file; file = fopen( "test11.dat", "r" ); if (file == NULL) { perror("can't open: "); exit(-1); } while (fgets(linebuf,BUFLEN,file) != NULL) { name = (el*)malloc(sizeof(el)); if (name == NULL) exit(-1); strncpy(name->bname,linebuf,sizeof(name->bname)); LL_PREPEND(head, name); } LL_SORT(head, namecmp); LL_FOREACH(head,tmp) printf("%s", tmp->bname); fclose(file); return 0; }
int main() { int i; el els[10], *e, *tmp, *tmp2; for(i=0;i<10;i++) els[i].id='a'+i; /* test LL macros */ printf("LL macros\n"); LL_APPEND(head,&els[0]); LL_APPEND(head,&els[1]); LL_APPEND(head,&els[2]); LL_FOREACH(head,e) printf("%c ", e->id); printf("\n"); LL_SEARCH_SCALAR(head, e, id, 'b'); if (e) printf("search scalar found b\n"); LL_SEARCH(head, e, &els[0], eltcmp); if (e) printf("search found %c\n",e->id); LL_FOREACH_SAFE(head,e,tmp) LL_DELETE(head,e); printf("\n"); /* test DL macros */ printf("DL macros\n"); DL_APPEND(head,&els[0]); DL_APPEND(head,&els[1]); DL_APPEND(head,&els[2]); DL_FOREACH(head,e) printf("%c ", e->id); printf("\n"); DL_SEARCH_SCALAR(head, e, id, 'b'); if (e) printf("search scalar found b\n"); DL_SEARCH(head, e, &els[0], eltcmp); if (e) printf("search found %c\n",e->id); DL_FOREACH_SAFE(head,e,tmp) DL_DELETE(head,e); printf("\n"); /* test CDL macros */ printf("CDL macros\n"); CDL_PREPEND(head,&els[0]); CDL_PREPEND(head,&els[1]); CDL_PREPEND(head,&els[2]); CDL_FOREACH(head,e) printf("%c ", e->id); printf("\n"); CDL_SEARCH_SCALAR(head, e, id, 'b'); if (e) printf("search scalar found b\n"); CDL_SEARCH(head, e, &els[0], eltcmp); if (e) printf("search found %c\n",e->id); CDL_FOREACH_SAFE(head,e,tmp,tmp2) CDL_DELETE(head,e); return 0; }
int main(int argc, char *argv[]) { int i; el els[10], *e; for(i=0;i<10;i++) els[i].id='a'+i; /* test LL macros */ printf("LL macros\n"); LL_APPEND(headA,&els[0]); LL_APPEND(headA,&els[1]); LL_APPEND(headA,&els[2]); LL_FOREACH(headA,e) printf("%c ", e->id); printf("\n"); LL_APPEND(headB,&els[3]); LL_APPEND(headB,&els[4]); LL_APPEND(headB,&els[5]); LL_FOREACH(headB,e) printf("%c ", e->id); printf("\n"); LL_CONCAT(headA,headB); LL_FOREACH(headA,e) printf("%c ", e->id); printf("\n"); /* other variations */ headA = NULL; LL_CONCAT(headA,headB); LL_FOREACH(headA,e) printf("%c ", e->id); printf("\n"); headB = NULL; LL_CONCAT(headA,headB); LL_FOREACH(headA,e) printf("%c ", e->id); printf("\n"); headA=NULL; headB=NULL; LL_APPEND(headA,&els[0]); LL_APPEND(headB,&els[1]); LL_CONCAT(headA,headB); LL_FOREACH(headA,e) printf("%c ", e->id); printf("\n"); return 0; }
int main(int argc, char *argv[]) { int i; el els[10], *e; for(i=0;i<10;i++) els[i].id='a'+i; /* test CDL macros */ printf("CDL macros\n"); CDL_PREPEND(head,&els[0]); CDL_PREPEND(head,&els[1]); CDL_PREPEND(head,&els[2]); CDL_PREPEND(head,&els[3]); CDL_FOREACH(head,e) printf("%c ", e->id); printf("\n"); /* point head to head->next */ printf("advancing head pointer\n"); head = head->next; CDL_FOREACH(head,e) printf("%c ", e->id); printf("\n"); /* follow circular loop a few times */ for(i=0,e=head;e && i<10;i++,e=e->next) printf("%c ", e->id); printf("\n"); /* follow circular loop backwards a few times */ for(i=0,e=head;e && i<10;i++,e=e->prev) printf("%c ", e->id); printf("\n"); printf("deleting b\n"); CDL_DELETE(head,&els[1]); CDL_FOREACH(head,e) printf("%c ", e->id); printf("\n"); printf("deleting (a)\n"); CDL_DELETE(head,&els[0]); CDL_FOREACH(head,e) printf("%c ", e->id); printf("\n"); printf("deleting (c)\n"); CDL_DELETE(head,&els[2]); CDL_FOREACH(head,e) printf("%c ", e->id); printf("\n"); printf("deleting (d)\n"); CDL_DELETE(head,&els[3]); CDL_FOREACH(head,e) printf("%c ", e->id); printf("\n"); /* test DL macros */ printf("DL macros\n"); DL_PREPEND(head,&els[0]); DL_PREPEND(head,&els[1]); DL_PREPEND(head,&els[2]); DL_APPEND(head,&els[3]); DL_FOREACH(head,e) printf("%c ", e->id); printf("\n"); printf("deleting c\n"); DL_DELETE(head,&els[2]); DL_FOREACH(head,e) printf("%c ", e->id); printf("\n"); printf("deleting a\n"); DL_DELETE(head,&els[0]); DL_FOREACH(head,e) printf("%c ", e->id); printf("\n"); printf("deleting b\n"); DL_DELETE(head,&els[1]); DL_FOREACH(head,e) printf("%c ", e->id); printf("\n"); printf("deleting d\n"); DL_DELETE(head,&els[3]); DL_FOREACH(head,e) printf("%c ", e->id); printf("\n"); /* test LL macros */ printf("LL macros\n"); LL_PREPEND(head,&els[0]); LL_PREPEND(head,&els[1]); LL_PREPEND(head,&els[2]); LL_APPEND(head,&els[3]); LL_FOREACH(head,e) printf("%c ", e->id); printf("\n"); printf("deleting c\n"); LL_DELETE(head,&els[2]); LL_FOREACH(head,e) printf("%c ", e->id); printf("\n"); printf("deleting a\n"); LL_DELETE(head,&els[0]); LL_FOREACH(head,e) printf("%c ", e->id); printf("\n"); printf("deleting b\n"); LL_DELETE(head,&els[1]); LL_FOREACH(head,e) printf("%c ", e->id); printf("\n"); printf("deleting d\n"); LL_DELETE(head,&els[3]); LL_FOREACH(head,e) printf("%c ", e->id); printf("\n"); return 0; }
void print_all_codes(){ ir_code *c = NULL; LL_FOREACH(code_list,c);{ printf("code no. %d\n",c->code.counter_id); } }