()
| 65 | }; |
| 66 | |
| 67 | const writeFixture = () => { |
| 68 | // The git shape + designated init + assignment registration. |
| 69 | write('cmd.c', ` |
| 70 | struct cmd { const char *name; int (*fn)(int argc); }; |
| 71 | static int cmd_add(int argc) { return argc + 1; } |
| 72 | static int cmd_rm(int argc) { return argc - 1; } |
| 73 | static struct cmd commands[] = { |
| 74 | { "add", cmd_add }, |
| 75 | { "rm", cmd_rm }, |
| 76 | }; |
| 77 | int run(int i, int argc) { return commands[i].fn(argc); } |
| 78 | `); |
| 79 | // Macro-built table with an object-macro struct alias and a non-indexed |
| 80 | // include, redis-style; plus a typedef'd fn-TYPE field. |
| 81 | write('table.c', ` |
| 82 | #include "table.h" |
| 83 | #include "cmds.def" |
| 84 | int dispatch(struct client *c, int a) { return c->cur->proc(a); } |
| 85 | `); |
| 86 | write('table.h', ` |
| 87 | typedef int cmdProc(int a); |
| 88 | #define TBL_STRUCT redisCmd |
| 89 | struct redisCmd { const char *name; cmdProc *proc; }; |
| 90 | struct client { struct redisCmd *cur; }; |
| 91 | #define MK(nm, fn) { nm, fn } |
| 92 | static int getCmd(int a); |
| 93 | static int setCmd(int a); |
| 94 | `); |
| 95 | write('cmds.def', ` |
| 96 | struct TBL_STRUCT tbl[] = { |
| 97 | MK("get", getCmd), |
| 98 | MK("set", setCmd), |
| 99 | }; |
| 100 | `); |
| 101 | write('impl.c', ` |
| 102 | #include "table.h" |
| 103 | static int getCmd(int a) { return a; } |
| 104 | static int setCmd(int a) { return a + 1; } |
| 105 | `); |
| 106 | // #ifdef-guarded inline struct table + parenthesized subscript dispatch |
| 107 | // (the vim shape), switched on by the includer. |
| 108 | write('ex.c', ` |
| 109 | #define WANT_TABLE |
| 110 | #include "ex_cmds.h" |
| 111 | int exec(int i, int a) { return (cmdtab[i].cmd_fn)(a); } |
| 112 | `); |
| 113 | write('ex_cmds.h', ` |
| 114 | #ifdef WANT_TABLE |
| 115 | static int ex_quit(int a); |
| 116 | struct excmd { char *nm; int (*cmd_fn)(int); } cmdtab[] = { { "q", ex_quit } }; |
| 117 | #endif |
| 118 | `); |
| 119 | write('ex_impl.c', `static int ex_quit(int a) { return -a; }\n`); |
| 120 | // Bare arrays: fn-TYPE typedef with star, casts, index designators, and a |
| 121 | // same-named file-local collision (the SameBoy/Zend shapes). |
| 122 | write('ops.c', ` |
| 123 | typedef int op_t(int); |
| 124 | static int nop(int x) { return x; } |
no test coverage detected