stein@rocksanne.UUCP (Adam Stein) (12/17/87)
Here is a program to show the status of task slots or remove a task. Hopefully the comments should describe everything you need to know to run it or translate it for another C compiler (it was written using Aztec C). Adam Stein rutgers!rochester!rocksanne!stein ------cut here-----------cut here-----------cut here-----------cut here----- /*This program will tell if a task slot is filled or empty, or remove a task if the slot is filled. Usage is: task [task# ...] [-r task#] [-s task#] where task# is the slot number to see or remove. Just putting the task number (as opposed to '-s task#') will tell the status of the slot before any '-r' options take effect while '-s' will tell the status after. The status of multiple tasks is always shown in numerical order, tasks are always removed in the order on the command line. i.e. task 2 |Show the status of task #2 task -s 3 |Show the status of task #3 task -r 11 |Remove task #11 task -r 2 2 -s 2 |Show the status of task #2, remove task #2, and then show the status again (-s option) task 2 3 -r 5 -r 6 |Show the status of tasks #2 and #3 and then remove tasks #5 and #6 Written because no other program exists to do this. Written using Aztec C v1.06A. Specific Aztec functions: svc [svc(code,bc,de,hl)] - used to call a TRSDOS SVC. The first argument is the SVC number, the last 3 arguments fill the BC, DE, and HL registers, respectively. If the SVC returns with the Z flag set, svc() returns 0, otherwise it returns the value in the A register. Specific Aztec constants: S_CKTSK - the SVC number for cktsk SVC (28). S_RMTSK - the SVC number for the rmtsk SVC (30). Written by Adam Stein (12/04/87). */ #include <stdio/h> #include <ctype/h> #include <trs4/h> #define E_BADTASK "%s: task #%d out of range <0-11>\n" #define E_NOTASK "\n%s: warning, task slot #%d is already empty\n\n" #define USAGE "usage: %s [task# ...] [-r task#] [-s task#]\n" int remove[12],see_after[12],see_before[12]; char *program; main(argc,argv) register int argc; register char *argv[]; { program = argv[0]; getargs(argc,argv); if(see_before[0] != -1) see_tasks(see_before); if(remove[0] != -1) { puts(""); remove_tasks(); } if(see_after[0] != -1) { puts(""); see_tasks(see_after); } } getargs(argc,argv) register int argc; register char *argv[]; { register int loop,index1,index2,index3; register char *pointer; if(argc == 1) { remove[0] = -1; see_after[0] = -1; for(loop = 0;loop < 12;++loop) see_before[loop] = loop; return; } for(loop = 0;loop < 12;++loop) remove[loop] = see_after[loop] = see_before[loop] = -1; for(index1 = index2 = index3 = 0,loop = 1;loop < argc;++loop) { pointer = argv[loop]; if(*pointer == '-') ++pointer; switch(*pointer) { case 'r': sscanf(argv[++loop],"%d",&remove[index1++]); check_number(remove[index1-1]); break; case 's': sscanf(argv[++loop],"%d",&see_after[index2++]); check_number(see_after[index2-1]); break; default: if(!sscanf(argv[loop],"%d",&see_before[index3++])) { fprintf(stderr,USAGE,program); exit(-1); } check_number(see_before[index3-1]); break; } } } see_tasks(arry) int *arry; { register int loop; int cmp(); qsort(arry,12,sizeof(int),cmp); for(loop = 0;(arry[loop] != -1) && (loop < 12);++loop) { printf("Task slot #%d is ",arry[loop]); if(!svc(S_CKTSK,arry[loop],0,0)) puts("empty"); else puts("filled"); } } remove_tasks() { register int loop; for(loop = 0;(remove[loop] != -1) && (loop < 12);++loop) { if(svc(S_CKTSK,remove[loop],0,0)) { printf("Removing task #%d\n",remove[loop]); svc(S_RMTSK,remove[loop],0,0); } else fprintf(stderr,E_NOTASK,program,remove[loop]); } } check_number(number) register int number; { if((number < 0) || (number > 11)) { fprintf(stderr,E_BADTASK,program,number); exit(-1); } } cmp(a,b) register int *a,*b; { /*Make -1 the highest number so it goes at the end of the list*/ if(*a == -1) return 1; if(*b == -1) return -1; if(*a > *b) return 1; if(*b > *a) return -1; return 0; } ------cut here-----------cut here-----------cut here-----------cut here-----