1 2 #include <sys/param.h> 3 4 #include <stdio.h> 5 #include <string.h> 6 7 int fifo(int argc, char *argv[]); 8 int memlock(int argc, char *argv[]); 9 int p26(int argc, char *argv[]); 10 int sched(int argc, char *argv[]); 11 int yield(int argc, char *argv[]); 12 13 static struct { 14 const char *t; 15 int (*f)(int, char *[]); 16 int works; 17 } tab[] = { 18 { "fifo", fifo, 1 }, 19 { "memlock", memlock, 0 }, 20 { "p26", p26, 1 }, 21 { "sched", sched, 1 }, 22 { "yield", yield, 1 }, 23 }; 24 25 static int usage(int argc, char *argv[]) 26 { 27 int i; 28 if (argc > 1) 29 fprintf(stderr, "%s is unknown\n", argv[1]); 30 31 fprintf(stderr, "usage: %s [-a] or one of [", argv[0]); 32 for (i = 0; i < (sizeof(tab) / sizeof(tab[0])); i++) 33 fprintf(stderr, "%s%s", (i)? " | " : "", tab[i].t); 34 fprintf(stderr, "]\n"); 35 36 return -1; 37 } 38 39 int main(int argc, char *argv[]) 40 { 41 int i; 42 43 if (argc == 2 && strcmp(argv[1], "-a") == 0) { 44 #if 1 45 fprintf(stderr, 46 "-a should but doesn't really work" 47 " (my notes say \"because things detach\");\n" 48 "meanwhile do these individual tests and look" 49 " for a non-zero exit code:\n"); 50 for (i = 0; i < nitems(tab); i++) 51 if (tab[i].works) 52 fprintf(stderr, "p1003_1b %s\n", tab[i].t); 53 return -1; 54 #else 55 { 56 int r; 57 for (i = 0; i < nitems(tab); i++) { 58 if (tab[i].works) { 59 if ( (r = 60 (*tab[i].f)(argc - 1, argv + 1)) ) { 61 fprintf(stderr, 62 "%s failed\n", tab[i].t); 63 return r; 64 } 65 } 66 } 67 return 0; 68 } 69 #endif 70 } 71 72 if (argc > 1) { 73 for (i = 0; i < nitems(tab); i++) 74 if (strcmp(tab[i].t, argv[1]) == 0) 75 return (*tab[i].f)(argc - 1, argv + 1); 76 } 77 78 return usage(argc, argv); 79 } 80