v4: mkf18a, the host tool that builds a train's F18 artifact (ADR step 3, task 3)
The artifact's layout and its check (artifact.h, artifact.c), the tool (tools/f18a.c, mkf18a.c) and make -C v4 artifacts. test_mkf18a, 83 checks at both widths, failed against a stub first. Gates: test, test-32 and sanitize pass, POST 990/990. Plan section 11. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017RzZgrf7V7Zk2iczBXDRbm
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
/* SPDX-License-Identifier: LicenseRef-Starship-1.0
|
||||
* Copyright (c) 2023-2026 Robert A. James
|
||||
*/
|
||||
/* mkf18a.c -- build a train's engine, its F18 artifact, off the node (f18a.h).
|
||||
*
|
||||
* mkf18a OUT.f18a MAP.f18 ROM DIR [TRAIN=PATH.f18a ...]
|
||||
*
|
||||
* docs/v4.0.0/plans/2026-11-19-f18-artifact-build.md section 2. Built as mkrom is, one per cell width,
|
||||
* with the node's size. DIR holds the train's .f18; each TRAIN=PATH is a train it may import from.
|
||||
*/
|
||||
#include "f18a.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifndef V4_ROOT
|
||||
#error "V4_ROOT must name the v4 directory"
|
||||
#endif
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
f18a_args a;
|
||||
f18a_train trains[64];
|
||||
unsigned char *out = NULL;
|
||||
size_t len = 0;
|
||||
char err[512];
|
||||
int i;
|
||||
FILE *f;
|
||||
|
||||
if (argc < 5) { fprintf(stderr, "usage: mkf18a OUT.f18a MAP.f18 ROM DIR [TRAIN=PATH.f18a ...]\n"); return 2; }
|
||||
a.map = argv[2];
|
||||
a.rom = argv[3];
|
||||
a.dir = argv[4];
|
||||
a.ntrains = 0;
|
||||
for (i = 5; i < argc; i++) {
|
||||
char *eq = strchr(argv[i], '=');
|
||||
if (!eq || a.ntrains == 64) { fprintf(stderr, "mkf18a: not TRAIN=PATH: %s\n", argv[i]); return 2; }
|
||||
*eq = 0;
|
||||
trains[a.ntrains].name = argv[i];
|
||||
trains[a.ntrains].path = eq + 1;
|
||||
a.ntrains++;
|
||||
}
|
||||
a.trains = trains;
|
||||
a.tool_root = V4_ROOT;
|
||||
if (!f18a_build(&a, &out, &len, err, sizeof err)) { fprintf(stderr, "mkf18a: %s: %s\n", a.dir, err); return 1; }
|
||||
f = fopen(argv[1], "wb");
|
||||
if (!f || fwrite(out, 1, len, f) != len || fclose(f) != 0) { fprintf(stderr, "mkf18a: cannot write %s\n", argv[1]); return 1; }
|
||||
free(out);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user