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