#include #include "fragile.h" int main() { char buf[BUFSIZ]; char *b; struct { QUEUE *qptr; int inuse; } store[100]; int i, j; for(i = 0; i < 100; i++) store[i].inuse = 0; while(printf("> "), fgets(buf, BUFSIZ-1, stdin) != NULL){ for(b = buf; isspace(*b); b++) ; switch(*b++){ case 'c': for(i = 0; i < 100 && store[i].inuse; i++) ; if (i == 100) printf("All queues in use.\n"); else{ qmanage(&(store[i].qptr), 1, 3); printf("Queue %d created\n", i); store[i].inuse = 1; } break; case 'd': if (sscanf(b, "%d", &i) != 1) printf("delete: d \n"); else if (i < 0 || 99 < i) printf("Bad queue number %d\n", i); else{ qmanage(&(store[i].qptr), 0, 3); printf("Queue %d deleted\n", i); store[i].inuse = 0; } break; case '+': if (sscanf(b, "%d %d", &i, &j) != 2) printf("enqueue: + \n"); else if (i < 0 || 99 < i) printf("Bad queue number %d\n", i); else{ put_on_queue(store[i].qptr, j); printf("Put %d on queue %d\n", j, i); } break; case '-': if (sscanf(b, "%d", &i) != 1) printf("dequeue: - \n"); else if (i < 0 || 99 < i) printf("Bad queue number %d\n", i); else{ take_off_queue(store[i].qptr, &j); printf("Took %d off queue %d\n", j, i); } break; case 'l': for(i = 0; i < 100; i++) if (store[i].inuse) printf("queue %2d in use\n", i); break; default: printf("help:\n"); printf("c create queue\n"); printf("d n delete queue n\n"); printf("+ n v add integer v to queue n\n"); printf("- n remove head of queue n\n"); printf("EOF quit\n"); break; } } putchar('\n'); }