1 /* $FreeBSD$ */ 2 #include <stdio.h> 3 #include <string.h> 4 5 int fifo(int argc, char *argv[]); 6 int memlock(int argc, char *argv[]); 7 int p26(int argc, char *argv[]); 8 int sched(int argc, char *argv[]); 9 int yield(int argc, char *argv[]); 10 11 static struct { 12 const char *t; 13 int (*f)(int, char *[]); 14 int works; 15 } tab[] = { 16 { "fifo", fifo, 1 }, 17 { "memlock", memlock, 0 }, 18 { "p26", p26, 1 }, 19 { "sched", sched, 1 }, 20 { "yield", yield, 1 }, 21 }; 22 23 #define N(T) (sizeof (T)/ sizeof(T[0])) 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 < N(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 < N(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 < N(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