diff options
| author | KonAki <konaki@anokonaki.org> | 2026-10-16 07:11:26 +0800 |
|---|---|---|
| committer | KonAki <konaki@anokonaki.org> | 2026-10-16 07:11:26 +0800 |
| commit | ad93bb8e31c93cae77ba1361db4f9ea5cb8a4267 (patch) | |
| tree | 8b9182db2e5fbc8e7acc45cd2658e8e535b8c6b8 | |
| parent | 2292abb2d35fda99cc2d4cf8026c64e868d0a835 (diff) | |
mzscript: list the plugin commands a game uses
| -rw-r--r-- | tools/mzscript.c | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/tools/mzscript.c b/tools/mzscript.c index 1ad1c6a..196ddc4 100644 --- a/tools/mzscript.c +++ b/tools/mzscript.c @@ -128,6 +128,44 @@ static void countHost(int code) } } +/* plugin commands by name, to see what a game asks of its plugins */ +typedef struct pluginTally { + char name[64]; + int n; +} pluginTally_t; + +static pluginTally_t plugins[256]; +static int pluginKinds; + +static void countPlugin(const char *first, const char *second) +{ + char name[64]; + size_t len = 0; + int i; + + while (first[len] && first[len] != ' ' && len < sizeof name - 1) { + name[len] = first[len]; + len++; + } + if (second && len < sizeof name - 2) { + const char *s = second; + + name[len++] = '.'; + while (*s && len < sizeof name - 1) name[len++] = *s++; + } + name[len] = '\0'; + for (i = 0; i < pluginKinds; i++) { + if (!strcmp(plugins[i].name, name)) { + plugins[i].n++; + return; + } + } + if (pluginKinds < 256) { + strcpy(plugins[pluginKinds].name, name); + plugins[pluginKinds++].n = 1; + } +} + static void warn(const char *scope, const char *what) { if (warnings++ < 20) fprintf(stderr, "%s: %s\n", scope, what); @@ -243,6 +281,8 @@ static void host(buf_t *out, int code, const kon_json_t *parameters) t.item = calloc(MAX_TOKENS, sizeof *t.item); if (!t.item) exit(1); flatten(&t, parameters); + if (code == 356 && t.count > 0) countPlugin(t.item[0], NULL); + if (code == 357 && t.count > 1) countPlugin(t.item[0], t.item[1]); countHost(code); put(out, "\thost %d", code); @@ -971,6 +1011,19 @@ int main(int argc, char **argv) hosts[best] = t; if (k < 15) printf(" %6d host %d\n", hosts[k].n, hosts[k].code); } + if (pluginKinds) printf("%d kinds of plugin commands (356 and 357):\n", pluginKinds); + for (k = 0; k < pluginKinds; k++) { + int best = k, j; + pluginTally_t t; + + for (j = k + 1; j < pluginKinds; j++) { + if (plugins[j].n > plugins[best].n) best = j; + } + t = plugins[k]; + plugins[k] = plugins[best]; + plugins[best] = t; + if (k < 15) printf(" %6d %s\n", plugins[k].n, plugins[k].name); + } if (warnings) printf("%d warnings\n", warnings); free(speakers); return 0; |
