BB2 C port
API reference: Blitz libraries in C and the shared code
Loading...
Searching...
No Matches
xtra.h
Go to the documentation of this file.
1/*
2 * xtra.h - the companion settings of a Blitz source (".xtra") as one small
3 * structure of views and numbers, with a loader for the sources that carry
4 * them and writers (docs/formats.md 1.4 and 7):
5 *
6 * Blitz 2 .xtra binary, vers 0 and 1 (blitz2.s:15290 optspnts,
7 * loadxtra/savextra), the companion file NAME.xtra
8 * of a TED, BB22 or text source: read, written
9 * byte-exact
10 * BB22 source header the editor part (cursor, top line) of the "BB22"
11 * sources (docs/rwelibs/README.md 4.1): read
12 * AmiBlitz3 .ab3 the "Embedded .xtra Header" (comment lines at the
13 * start of a text source, xtra_ab3.c): read; written
14 * by updating the kept header (unchanged lines stay
15 * as they are) or as a new header
16 *
17 * The caller does the I/O: it loads the source into memory, asks
18 * xtra_detect for the type and xtra_companion_name for the name of the
19 * companion .xtra (TED, BB22, plain text), reads that too (if it exists)
20 * and passes both buffers to xtra_load. The structure copies nothing: the
21 * texts and the maxima are views - offset and length - into the .xtra
22 * buffer or into the source header, the numbers are parsed. xtra_load
23 * gives the size of the source header (x->hdr); the caller keeps these
24 * bytes (in front of the tokenised text or elsewhere: views are offsets,
25 * so the bytes may move) and the .xtra buffer, and passes both as
26 * struct xtra_base when reading a text, iterating the maxima or writing.
27 *
28 * Shared code like shared/filereq: every user compiles xtra.c and
29 * xtra_ab3.c itself with its own options - the host tools (tools/lib/xtra),
30 * later blitz2 and TED (-fbaserel). Pure C99 on the freestanding
31 * headers: no libc, no libgcc (no 32-bit multiply or divide on the 68000),
32 * no writable static data, no allocation. The file formats are
33 * big-endian; the code assembles the bytes itself.
34 *
35 * AmiBlitz3's binary .xtra (15 switch words, the CLI block's last 12
36 * bytes as stack/version/builds, PED's XtraExtend after the pairs) is
37 * only recognised (xtra_is_ab3_xtra: the mode of a tokenised source in
38 * blitz2-ab3), not loaded: AmiBlitz3 drops loading tokenised sources
39 * (docs/formats.md 7).
40 */
41#ifndef XTRA_H
42#define XTRA_H
43
44#include <stddef.h>
45#include <stdint.h>
46
47#ifdef __cplusplus
48extern "C" {
49#endif
50
51/* ------------------------------------------------------------ sizes */
52
53#define XTRA_NSWITCH 14 /* switch words of the Blitz 2 file */
54#define XTRA_NBUFFER 6 /* buffer sizes */
55#define XTRA_NRES 8 /* residents (blitz2: mostres) */
56#define XTRA_RESNAME 64 /* bytes of a resident's path field */
57#define XTRA_PATHLEN 192 /* bytes of the executable's path and name */
58#define XTRA_CLILEN 128 /* bytes of the CLI argument (vers 1) */
59#define XTRA_LABELLEN 32 /* bytes of AmiBlitz3's LabelSearch */
60#define XTRA_FIXED_V0 982 /* fixed part of a vers 0 file */
61#define XTRA_FIXED_V1 1110 /* fixed part of a vers 1 file */
62#define XTRA_AB3_NSWITCH 15 /* switch words of AmiBlitz3's binary .xtra */
63#define XTRA_AB3_FIXED 1112 /* its fixed part (always with CLI block) */
64
65/* ------------------------------------------------------------ fields */
66
67/** @brief The switch words in file order (offset 2 + 2 * index); each is
68 the Flags word of the option gadget: XTRA_ON (GFLG_SELECTED) = on. */
70 XTRA_SW_RUNTIME_ERRORS, /* +2 optreqga10, AB3 RuntimeDebug */
71 XTRA_SW_DEBUGGER, /* +4 optreqga11 */
72 XTRA_SW_LONG_ARRAYS, /* +6 optreqga12 */
73 XTRA_SW_EXPAND_MACROS, /* +8 optreqga13 */
74 XTRA_SW_QUOTED_MACROS, /* +10 optreqga14 */
75 XTRA_SW_MAKE_SMALLEST, /* +12 optreqga15, AB3 MakeSmallest */
76 XTRA_SW_DEBUG_INFO, /* +14 optreqga16, AB3 DebugInfo */
77 XTRA_SW_AUTO_RUN, /* +16 optreq2ga1, AB3 AutoRun */
78 XTRA_SW_INTERRUPT_CHECK, /* +18 optreq2ga2, AB3 InterruptCheck */
79 XTRA_SW_ASSEMBLER_CHECK, /* +20 optreq2ga3, AB3 AssemblerCheck */
80 XTRA_SW_OVERFLOW_CHECK, /* +22 optreq2ga4, AB3 OverflowCheck */
81 XTRA_SW_WARNINGS, /* +24 the warnings (blitz2 warnopt, in
82 place of optreq2ga5): XTRA_ON on,
83 0 off, XTRA_WARN_ERRORS errors */
84 XTRA_SW_DEFAULT_INTERRUPT, /* +26 optreq2ga6 */
85 XTRA_SW_DEFAULT_OVERFLOW /* +28 optreq2ga7 */
86};
87#define XTRA_ON 0x0080 /* GFLG_SELECTED; also the icon byte */
88#define XTRA_WARN_ERRORS 0x0180 /* XTRA_SW_WARNINGS: warnings are errors */
89
90/** @brief The buffer sizes in file order (offset 30 + 4 * index). */
95
96/** @brief The type of a source file (xtra_detect, xtra_load). */
98 XTRA_T_TED, /* TED's tokenised source (has a $00);
99 settings in NAME.xtra */
100 XTRA_T_BB22, /* RWE's BB22 source: 14/16-byte header
101 (cursor); settings in NAME.xtra */
102 XTRA_T_AB3, /* AmiBlitz3 text source: the settings in
103 its embedded header (or AmiBlitz3's
104 defaults without one); no NAME.xtra */
105 XTRA_T_TEXT, /* text without header; settings in
106 NAME.xtra (Blitz 2 text sources) */
108};
109
110/** @brief Where the settings came from. */
112 XTRA_SRC_NONE, /* defaults only (xtra_init) */
113 XTRA_SRC_BLITZ2, /* a Blitz 2 .xtra */
114 XTRA_SRC_AB3_TEXT /* an AmiBlitz3 source (header or not) */
115};
116
117/** @brief Where the bytes of a view are; also the file of an error. */
119 XTRA_IN_NONE, /* nothing: an empty text, no maxima */
120 XTRA_IN_XTRA, /* the .xtra buffer (xtra_base.xtra) */
121 XTRA_IN_HEADER, /* the source header (xtra_base.header);
122 for an error: the source file */
123 XTRA_IN_SET /* the caller's memory (xtra_set_text,
124 xtra_set_maxima) or a constant */
125};
126
127/** @brief The bases of the views: the .xtra as loaded and the kept source
128 header (src[0..x->hdr) of xtra_load, wherever it is now).
129
130 Either may be NULL if no view points there. */
131struct xtra_base {
132 const uint8_t *xtra;
133 const uint8_t *header;
134};
135
136/** @brief The text fields (xtra_get_text, xtra_set_text). */
138 XTRA_F_EXE_PATH, /* .xtra 598, AB3 ExePath (< 192 bytes) */
139 XTRA_F_EXE_NAME, /* .xtra 790, AB3 ExeFile (< 192) */
140 XTRA_F_CLI, /* .xtra 982 (vers 1), AB3 CliArgs (< 128) */
141 XTRA_F_LABEL_SEARCH, /* AB3 LabelSearch (< 32) */
142 XTRA_F_RES0, /* the residents: .xtra 54 + 68 * i, AB3
143 Residents part i (< 64 each) */
145};
146
147/** @brief A text: a view (in, off, len) or the caller's bytes
148 (XTRA_IN_SET: set, len).
149
150 A view into the .xtra starts at its field: the Blitz 2 writer copies
151 the whole field from there (bytes after the 0 included). */
152struct xtra_text {
153 const uint8_t *set; /* XTRA_IN_SET: the bytes */
154 uint32_t off; /* XTRA_IN_XTRA/HEADER: offset in the base */
155 uint16_t len; /* bytes, without a 0 */
156 uint8_t in; /* enum xtra_in */
157};
158
159/** @brief One object maximum.
160
161 The Blitz 2 file names the library by number (XTRA_MAX_LIB), the
162 AmiBlitz3 header the object by name (XTRA_MAX_NAME, as written there:
163 a blank in the name is '-'); mapping one to the other needs the
164 libraries and is the caller's business. */
165struct xtra_max {
166 const uint8_t *name; /* XTRA_MAX_NAME: namelen bytes, no 0 */
167 uint16_t namelen;
168 uint16_t lib; /* XTRA_MAX_LIB: library number */
169 uint16_t max; /* the maximum */
170 uint8_t flags; /* XTRA_MAX_LIB | XTRA_MAX_NAME */
171};
172#define XTRA_MAX_LIB 0x01
173#define XTRA_MAX_NAME 0x02
174
175/** @brief The maxima: the {lib, max} pairs of the .xtra (off: the first
176 pair), the "Max NAME" lines of the header (off: the first one's line,
177 n lines; a NAME given twice is there twice, the last one counts) or the
178 caller's array (xtra_set_maxima).
179
180 Read with xtra_max_begin/xtra_next_max. */
182 const struct xtra_max *set; /* XTRA_IN_SET */
183 uint32_t off;
184 uint32_t n;
185 uint8_t in; /* enum xtra_in */
186};
187
188/** @brief The editor part: not in a Blitz 2 .xtra; from a BB22 header or
189 the AmiBlitz3 header.
190
191 All values 0-based. */
193 uint8_t flags; /* XTRA_ED_CURSOR, XTRA_ED_TOP */
194 uint32_t line; /* cursor line (XTRA_ED_CURSOR) */
195 uint32_t column; /* cursor column as shown (XTRA_ED_CURSOR) */
196 uint32_t top; /* first line shown (XTRA_ED_TOP) */
197};
198#define XTRA_ED_CURSOR 0x01
199#define XTRA_ED_TOP 0x02
200
201/** @brief Keys of the AmiBlitz3 header: bit (1 << key) in xtra_ab3.seen
202 when the header has the key (docs/formats.md 7.2). */
214
215/** @brief Numbers only AmiBlitz3 has (LabelSearch: XTRA_F_LABEL_SEARCH).
216
217 Without the key in the header the value is AmiBlitz3's default. */
218struct xtra_ab3 {
219 uint32_t seen; /* 1 << enum xtra_ab3_key: keys in the header */
220 uint32_t stack; /* StackSize (default 32768) */
221 uint32_t builds; /* NumberOfBuilds */
222 uint32_t label_position; /* LabelPosition */
223 uint16_t label_remark, label_all, label_case; /* words, as written */
224 uint8_t header; /* 1: the source has a header */
225 uint8_t func_optimize; /* FuncOptimize 0/1 */
226 uint8_t create_dbgfile; /* CreateDbgFile 0/1 */
227 uint8_t version[3]; /* Version major.minor.patch */
228 /* lines "; KEY = VALUE" with a KEY the reader does not know: kept,
229 counted; the first one's line number (1-based) */
230 uint32_t unknown;
231 uint32_t unknown_line;
232};
233
234/** @brief The settings.
235
236 The numbers are members to read and set directly; the texts through
237 xtra_get_text/xtra_set_text, the maxima through the iterator and
238 xtra_set_maxima. */
239struct xtra {
240 uint8_t type; /* enum xtra_type (xtra_load) */
241 uint8_t source; /* enum xtra_source */
242 uint8_t vers; /* 0 (no CLI block) or 1 */
243 uint8_t icon; /* executable with icon: XTRA_ON or 0 */
244 uint32_t hdr; /* bytes of the source header to keep:
245 AB3 "; XTRA" to "; /XTRA" (with its line
246 end), BB22 14 or 16; 0 for the others */
247 uint16_t sw[XTRA_NSWITCH]; /* enum xtra_switch */
248 uint32_t buf[XTRA_NBUFFER]; /* enum xtra_buffer, bytes */
249 uint32_t res_ptr[XTRA_NRES]; /* the residents' pointer fields: runtime
250 values as in the file (0 from scratch) */
254 struct xtra_ab3 ab3;
255};
256
257/* ------------------------------------------------------------ errors */
258
259/** @brief The error codes of the functions (XTRA_OK = 0: no error). */
262 XTRA_E_SHORT, /* shorter than the fixed part */
263 XTRA_E_SIZE, /* not fixed part + 4n */
264 XTRA_E_VERS, /* vers neither 0 nor 1 */
265 XTRA_E_UNTERMINATED, /* text field without its 0 byte */
266 XTRA_E_SPACE, /* output buffer too small */
267 XTRA_E_BB22, /* not a BB22 header we know */
268 XTRA_E_AB3_LINE, /* header line without ';' */
269 XTRA_E_AB3_END, /* header without "; /XTRA" */
270 XTRA_E_AB3_NUMBER, /* not a number / out of range */
271 XTRA_E_AB3_QUOTE, /* '"' without its closing '"' */
272 XTRA_E_LONG, /* text longer than its field */
273 XTRA_E_AB3_RESIDENTS, /* more than XTRA_NRES residents */
274 XTRA_E_AB3_VERSION, /* Version not N.N.N (0..255 each) */
275 XTRA_E_AB3_NAME, /* "Max" without object name */
276 XTRA_E_TYPE, /* not an enum xtra_type */
277 XTRA_E_FIELD, /* not an enum xtra_field */
278 XTRA_E_TEXT, /* a text with a 0, CR or LF byte */
279 XTRA_E_BASE, /* the bytes of a view not given (base NULL) */
281};
282
283/** @brief Where an error is: file (XTRA_IN_XTRA or XTRA_IN_HEADER = the
284 source), byte offset (binary formats) or line (1-based, AB3). */
286 int code; /* enum xtra_err */
287 int in; /* enum xtra_in */
288 size_t offset;
289 uint32_t line;
290};
291
292/**
293 * @brief The message of an error code (English, without position).
294 * @param code an enum xtra_err
295 * @return the message; "unknown error" for another code
296 */
297const char *xtra_strerror(int code);
298
299/* ------------------------------------------------------------ loading */
300
301/**
302 * @brief The type of a source.
303 *
304 * "BB22" at the start: XTRA_T_BB22; a $00 byte: XTRA_T_TED; first line
305 * "; XTRA": XTRA_T_AB3; other text: XTRA_T_AB3 if path ends in ".ab3"
306 * (any case, AmiBlitz3 reads every .ab3 so), else XTRA_T_TEXT. The
307 * caller may pass another type to xtra_load.
308 *
309 * @param buf the source
310 * @param len its length
311 * @param path its file name (may be NULL)
312 * @return an enum xtra_type
313 */
314int xtra_detect(const uint8_t *buf, size_t len, const char *path);
315
316/**
317 * @brief Whether the settings of a source of this type are in NAME.xtra.
318 * @param type an enum xtra_type
319 * @return 1 for XTRA_T_TED, XTRA_T_BB22 and XTRA_T_TEXT, else 0
320 */
321int xtra_has_companion(int type);
322
323/**
324 * @brief The name of the companion of the source path: path + ".xtra" (as
325 * TED and blitz2 make it).
326 * @param path the source's file name
327 * @param out the name, 0-terminated
328 * @param cap the size of out in bytes
329 * @return 0 or XTRA_E_SPACE
330 */
331int xtra_companion_name(const char *path, char *out, size_t cap);
332
333/**
334 * @brief Whether a companion .xtra has AmiBlitz3's binary format with 15
335 * switch words (since AmiBlitz/AmiBlitz3\@bdae3f9e, docs/formats.md
336 * 1.3) - not Blitz 2's 14.
337 *
338 * The layout as AmiBlitz3's write_xtrafile writes it: vers 1, icon, 15
339 * switch words, 6 buffer sizes at 32, 8 residents at 56, path and name of
340 * the executable at 600 and 792, CLI argument (116 bytes) and stack,
341 * version, builds at 984 (fixed part XTRA_AB3_FIXED), the {lib, max}
342 * pairs, 4 more bytes, maybe PED's XtraExtend. Recognised by: at least
343 * the fixed part + 4 bytes, a multiple of 4 (a Blitz 2 .xtra is 982/1110
344 * + 4n), vers 1, icon and switch words 0 or XTRA_ON, every buffer size
345 * below 16 MB (in the 14-word layout's place a buffer's low word would be
346 * the next one's high word), the text fields 0-terminated. An older
347 * AmiBlitz3 .xtra with 14 switch words is not recognised.
348 *
349 * @param xtra the file, xtra[0..len) (NULL: none)
350 * @param len its length
351 * @return 1 or 0
352 */
353int xtra_is_ab3_xtra(const uint8_t *xtra, size_t len);
354
355/** @brief The mode a program is compiled in by blitz2-ab3 (xtra_mode). */
357 XTRA_MODE_DETECT, /* force: no mode given, detect it */
358 XTRA_MODE_BB2, /* Blitz Basic 2: its tokens and libraries */
359 XTRA_MODE_AB3 /* AmiBlitz3 v3.14.0's tokens and libraries */
360};
361
362/**
363 * @brief The mode of a source (xtra_mode.c; docs/ab3/variant.md).
364 *
365 * force XTRA_MODE_BB2 or XTRA_MODE_AB3 (the command line's -mode): that
366 * mode. Otherwise by xtra_detect: XTRA_T_AB3 (a text with the embedded
367 * header, or a text named *.ab3) is AB3; XTRA_T_TED (tokenised) is AB3 if
368 * its companion .xtra has AmiBlitz3's format (xtra_is_ab3_xtra), else
369 * BB2; everything else (BB22, text without header) is BB2. The same rule
370 * gives the mode of a tokenised include.
371 *
372 * @param force an enum xtra_mode; XTRA_MODE_DETECT (or another value):
373 * detect
374 * @param src the source, src[0..len)
375 * @param len its length
376 * @param path its file name (may be NULL)
377 * @param xtra its companion .xtra, xtra[0..xlen) (NULL: none)
378 * @param xlen its length
379 * @return XTRA_MODE_BB2 or XTRA_MODE_AB3
380 */
381int xtra_mode(int force, const uint8_t *src, size_t len, const char *path, const uint8_t *xtra,
382 size_t xlen);
383
384/**
385 * @brief Load the settings of a source.
386 *
387 * x is initialised (xtra_init) and gets:
388 * - XTRA_T_TED, XTRA_T_TEXT: the .xtra (source XTRA_SRC_BLITZ2) or the
389 * defaults (XTRA_SRC_NONE); hdr 0
390 * - XTRA_T_BB22: the header's editor part, hdr 14/16; the .xtra
391 * - XTRA_T_AB3: the embedded header (XTRA_SRC_AB3_TEXT, its size in
392 * hdr) or AmiBlitz3's defaults (hdr 0)
393 *
394 * The views point into the .xtra and into src[0..x->hdr) - the caller
395 * keeps both (struct xtra_base). Strict: a .xtra must be 982 + 4n
396 * (vers 0) or 1110 + 4n bytes (vers 1) with 0-terminated text fields; the
397 * AB3 header must be well-formed (docs/formats.md 7.4).
398 *
399 * @param x the settings
400 * @param type an enum xtra_type
401 * @param src the source, src[0..len) (may be NULL for XTRA_T_TED/
402 * XTRA_T_TEXT)
403 * @param len its length
404 * @param xtra its companion .xtra, xtra[0..xlen) (NULL: none; ignored for
405 * XTRA_T_AB3)
406 * @param xlen its length
407 * @param err the place of an error (may be NULL)
408 * @return 0 or an enum xtra_err; on an error x holds the defaults
409 */
410int xtra_load(struct xtra *x, int type, const uint8_t *src, size_t len, const uint8_t *xtra,
411 size_t xlen, struct xtra_error *err);
412
413/* ------------------------------------------------------------ fields */
414
415/**
416 * @brief Initialise settings with the defaults.
417 *
418 * Blitz 2's defaults (options.src, the initial gadget flags), no
419 * residents, empty texts, no maxima, no editor part, AmiBlitz3's defaults
420 * for its own numbers; vers 1, type XTRA_T_TED, XTRA_SRC_NONE.
421 *
422 * @param x the settings
423 */
424void xtra_init(struct xtra *x);
425
426/**
427 * @brief What blitz2's loadxtra does after reading a vers 0 file.
428 *
429 * Auto Run on, Interrupt/Overflow Checking from their defaults, Assembler
430 * Checking off (blitz2.s:15371). The loader leaves the file values alone.
431 *
432 * @param x the settings
433 */
434void xtra_apply_vers0(struct xtra *x);
435
436/**
437 * @brief A text field.
438 * @param x the settings
439 * @param b the bases of the views (may be NULL)
440 * @param field an enum xtra_field
441 * @param len out: the length
442 * @return its bytes (not 0-terminated); "" for an empty one; NULL (and
443 * *len 0) for a field number out of range or a view whose base b
444 * does not give
445 */
446const uint8_t *xtra_get_text(const struct xtra *x, const struct xtra_base *b, int field, size_t *len);
447
448/**
449 * @brief The bytes of a text field in a Blitz 2 .xtra (with the 0): a text
450 * is shorter than this.
451 * @param field an enum xtra_field
452 * @return the size; 0 for a field number out of range
453 */
454size_t xtra_text_cap(int field);
455
456/**
457 * @brief Set a text field to the caller's bytes.
458 * @param x the settings
459 * @param field an enum xtra_field
460 * @param p the text, p[0..len) - kept by the caller as long as x is
461 * used (a writer reads it from there)
462 * @param len its length
463 * @return 0, XTRA_E_FIELD, XTRA_E_LONG (len >= xtra_text_cap) or
464 * XTRA_E_TEXT (a 0, CR or LF)
465 */
466int xtra_set_text(struct xtra *x, int field, const void *p, size_t len);
467
468/**
469 * @brief The maxima from the caller's array instead of those of the
470 * .xtra/header.
471 *
472 * The AmiBlitz3 writer then replaces all "Max" lines (written in front of
473 * "; /XTRA").
474 *
475 * @param x the settings
476 * @param m the maxima, m[0..n) (kept by the caller)
477 * @param n their number; 0: none
478 */
479void xtra_set_maxima(struct xtra *x, const struct xtra_max *m, uint32_t n);
480
481/**
482 * @brief An iterator over the maxima, one by one, in file order.
483 *
484 * struct xtra_iter it;
485 * struct xtra_max m;
486 * xtra_max_begin(&it, x, b);
487 * while (xtra_next_max(&it, &m)) ...
488 *
489 * No maxima from a view whose base b does not give.
490 */
491struct xtra_iter {
492 const struct xtra *x;
493 const uint8_t *base; /* the .xtra or the header */
494 const struct xtra_max *set; /* the next one of the caller's array */
495 uint32_t pos, left;
496};
497
498/**
499 * @brief Start iterating the maxima of x.
500 * @param it the iterator
501 * @param x the settings
502 * @param b the bases of the views
503 */
504void xtra_max_begin(struct xtra_iter *it, const struct xtra *x, const struct xtra_base *b);
505
506/**
507 * @brief The next maximum.
508 * @param it the iterator (xtra_max_begin)
509 * @param m out: the maximum
510 * @return 1 with *m set, 0 at the end
511 */
512int xtra_next_max(struct xtra_iter *it, struct xtra_max *m);
513
514/**
515 * @brief Take what a Blitz 2 .xtra holds from from into to.
516 *
517 * vers, icon, switches, buffers, residents (texts, pointers), executable
518 * path and name, CLI argument - not the maxima, the editor part,
519 * AmiBlitz3's own fields. from's views keep pointing into its .xtra: the
520 * base used with to needs from's .xtra (e.g. an .ab3 header updated from
521 * a .xtra).
522 *
523 * @param to the settings to change
524 * @param from the settings to take from
525 */
526void xtra_take_blitz2(struct xtra *to, const struct xtra *from);
527
528/* ------------------------------------------------------------ Blitz 2 */
529
530/**
531 * @brief The bytes xtra_write_blitz2 writes: the fixed part of x->vers and
532 * 4 per maximum with a library number.
533 * @param x the settings
534 * @return the size
535 */
536size_t xtra_blitz2_size(const struct xtra *x);
537
538/**
539 * @brief Write x as Blitz 2 .xtra.
540 *
541 * vers as in x (0 without CLI block); a text from the .xtra as its whole
542 * field (the bytes after the 0 included: a loaded file gives the same
543 * bytes), others 0-terminated and padded with 0; the pairs of the maxima
544 * with XTRA_MAX_LIB in their order (the others skipped).
545 *
546 * @param x the settings
547 * @param b the bases of the views
548 * @param out the output
549 * @param cap its size in bytes
550 * @param len out: the size written
551 * @param skipped out: the maxima skipped (may be NULL)
552 * @param err the place of an error (may be NULL)
553 * @return 0 or XTRA_E_VERS, XTRA_E_SPACE, XTRA_E_LONG, XTRA_E_BASE
554 */
555int xtra_write_blitz2(const struct xtra *x, const struct xtra_base *b, uint8_t *out, size_t cap,
556 size_t *len, unsigned *skipped, struct xtra_error *err);
557
558/* ------------------------------------------------------------ AmiBlitz3 */
559
560/**
561 * @brief Write x as AmiBlitz3 header (not 0-terminated).
562 *
563 * - x from a source with header (x->ab3.header): that header
564 * (b->header, x->hdr bytes), line by line: unchanged lines as they
565 * are (unknown keys, comments, older layouts, the line ends); the line
566 * of a known key whose value in x differs from what the line says gets
567 * the new value (the rest of the line kept); keys the header lacks
568 * whose value differs from AmiBlitz3's default are added in front of
569 * "; /XTRA"; maxima set by xtra_set_maxima replace the "Max" lines.
570 * Unchanged x: the same bytes.
571 * - otherwise a new header, the lines of AmiBlitz3's write_AB3Header
572 * (docs/formats.md 7.1), LF line ends.
573 *
574 * @param x the settings
575 * @param b the bases of the views
576 * @param out the output
577 * @param cap its size in bytes
578 * @param len out: the size (also when it does not fit)
579 * @param skipped out: the maxima without a name, skipped (may be NULL)
580 * @return 0 or XTRA_E_SPACE, XTRA_E_BASE
581 */
582int xtra_write_ab3(const struct xtra *x, const struct xtra_base *b, char *out, size_t cap,
583 size_t *len, unsigned *skipped);
584
585/**
586 * @brief The bytes xtra_write_ab3 writes.
587 * @param x the settings
588 * @param b the bases of the views
589 * @return the size; 0 on XTRA_E_BASE
590 */
591size_t xtra_ab3_size(const struct xtra *x, const struct xtra_base *b);
592
593/**
594 * @brief The name of an AmiBlitz3 key ("ExePath", ..., "Max").
595 * @param key an enum xtra_ab3_key
596 * @return the name; "" for another number
597 */
598const char *xtra_ab3_keyname(int key);
599
600#ifdef __cplusplus
601}
602#endif
603
604#endif
ULONG x
Definition 2dlib.c:2491
ULONG WORD UWORD UWORD border ULONG ULONG to
Definition 2dlib.c:2493
ULONG WORD UWORD UWORD border ULONG ULONG struct bb_bitmap *dst void UWORD n
Definition 2dlib.c:2498
ULONG WORD UWORD UWORD border ULONG from
Definition 2dlib.c:2493
ULONG len
Definition asllib.c:158
struct TagItem path
Definition asllib.c:188
static UBYTE * key
Definition blitzkeyslib.c:101
UWORD type
Definition editlib.c:263
static UWORD buf
Definition rawkeylib.c:83
UBYTE code[4]
Definition ridisasmlib.c:375
struct IntuiText it
Definition riintuilib.c:123
Definition rilvcallhooklib.c:108
Definition ab3args.c:62
Numbers only AmiBlitz3 has (LabelSearch: XTRA_F_LABEL_SEARCH).
Definition xtra.h:218
uint32_t label_position
Definition xtra.h:222
uint8_t header
Definition xtra.h:224
uint16_t label_case
Definition xtra.h:223
uint32_t builds
Definition xtra.h:221
uint8_t version[3]
Definition xtra.h:227
uint32_t unknown
Definition xtra.h:230
uint32_t seen
Definition xtra.h:219
uint8_t create_dbgfile
Definition xtra.h:226
uint16_t label_remark
Definition xtra.h:223
uint32_t stack
Definition xtra.h:220
uint8_t func_optimize
Definition xtra.h:225
uint16_t label_all
Definition xtra.h:223
uint32_t unknown_line
Definition xtra.h:231
The bases of the views: the .xtra as loaded and the kept source header (src[0..x->hdr) of xtra_load,...
Definition xtra.h:131
const uint8_t * xtra
Definition xtra.h:132
const uint8_t * header
Definition xtra.h:133
The editor part: not in a Blitz 2 .xtra; from a BB22 header or the AmiBlitz3 header.
Definition xtra.h:192
uint8_t flags
Definition xtra.h:193
uint32_t top
Definition xtra.h:196
uint32_t column
Definition xtra.h:195
uint32_t line
Definition xtra.h:194
Where an error is: file (XTRA_IN_XTRA or XTRA_IN_HEADER = the source), byte offset (binary formats) o...
Definition xtra.h:285
uint32_t line
Definition xtra.h:289
int in
Definition xtra.h:287
size_t offset
Definition xtra.h:288
int code
Definition xtra.h:286
An iterator over the maxima, one by one, in file order.
Definition xtra.h:491
uint32_t left
Definition xtra.h:495
const struct xtra_max * set
Definition xtra.h:494
const uint8_t * base
Definition xtra.h:493
const struct xtra * x
Definition xtra.h:492
uint32_t pos
Definition xtra.h:495
One object maximum.
Definition xtra.h:165
uint16_t lib
Definition xtra.h:168
uint16_t max
Definition xtra.h:169
const uint8_t * name
Definition xtra.h:166
uint8_t flags
Definition xtra.h:170
uint16_t namelen
Definition xtra.h:167
The maxima: the {lib, max} pairs of the .xtra (off: the first pair), the "Max NAME" lines of the head...
Definition xtra.h:181
uint32_t n
Definition xtra.h:184
const struct xtra_max * set
Definition xtra.h:182
uint8_t in
Definition xtra.h:185
uint32_t off
Definition xtra.h:183
A text: a view (in, off, len) or the caller's bytes (XTRA_IN_SET: set, len).
Definition xtra.h:152
uint16_t len
Definition xtra.h:155
uint32_t off
Definition xtra.h:154
const uint8_t * set
Definition xtra.h:153
uint8_t in
Definition xtra.h:156
The settings.
Definition xtra.h:239
uint32_t res_ptr[XTRA_NRES]
Definition xtra.h:249
uint8_t source
Definition xtra.h:241
uint8_t type
Definition xtra.h:240
struct xtra_editor editor
Definition xtra.h:253
uint8_t vers
Definition xtra.h:242
struct xtra_ab3 ab3
Definition xtra.h:254
uint16_t sw[XTRA_NSWITCH]
Definition xtra.h:247
uint32_t hdr
Definition xtra.h:244
struct xtra_text text[XTRA_F_COUNT]
Definition xtra.h:251
uint8_t icon
Definition xtra.h:243
uint32_t buf[XTRA_NBUFFER]
Definition xtra.h:248
struct xtra_maxima max
Definition xtra.h:252
xtra_mode
The mode a program is compiled in by blitz2-ab3 (xtra_mode).
Definition xtra.h:356
@ XTRA_MODE_BB2
Definition xtra.h:358
@ XTRA_MODE_AB3
Definition xtra.h:359
@ XTRA_MODE_DETECT
Definition xtra.h:357
#define XTRA_NRES
Definition xtra.h:55
int xtra_write_blitz2(const struct xtra *x, const struct xtra_base *b, uint8_t *out, size_t cap, size_t *len, unsigned *skipped, struct xtra_error *err)
Write x as Blitz 2 .xtra.
Definition xtra.c:543
size_t xtra_blitz2_size(const struct xtra *x)
The bytes xtra_write_blitz2 writes: the fixed part of x->vers and 4 per maximum with a library number...
Definition xtra.c:507
void xtra_take_blitz2(struct xtra *to, const struct xtra *from)
Take what a Blitz 2 .xtra holds from from into to.
Definition xtra.c:281
size_t xtra_ab3_size(const struct xtra *x, const struct xtra_base *b)
The bytes xtra_write_ab3 writes.
Definition xtra_ab3.c:892
#define XTRA_NSWITCH
Definition xtra.h:53
void xtra_set_maxima(struct xtra *x, const struct xtra_max *m, uint32_t n)
The maxima from the caller's array instead of those of the .xtra/header.
Definition xtra.c:228
xtra_type
The type of a source file (xtra_detect, xtra_load).
Definition xtra.h:97
@ XTRA_T_TED
Definition xtra.h:98
@ XTRA_T_TEXT
Definition xtra.h:105
@ XTRA_T_BB22
Definition xtra.h:100
@ XTRA_T_AB3
Definition xtra.h:102
@ XTRA_T_COUNT
Definition xtra.h:107
int xtra_next_max(struct xtra_iter *it, struct xtra_max *m)
The next maximum.
Definition xtra.c:253
const char * xtra_ab3_keyname(int key)
The name of an AmiBlitz3 key ("ExePath", ..., "Max").
Definition xtra_ab3.c:147
xtra_in
Where the bytes of a view are; also the file of an error.
Definition xtra.h:118
@ XTRA_IN_NONE
Definition xtra.h:119
@ XTRA_IN_SET
Definition xtra.h:123
@ XTRA_IN_XTRA
Definition xtra.h:120
@ XTRA_IN_HEADER
Definition xtra.h:121
xtra_ab3_key
Keys of the AmiBlitz3 header: bit (1 << key) in xtra_ab3.seen when the header has the key (docs/forma...
Definition xtra.h:203
@ XTRA_K_CURSORLINE
Definition xtra.h:209
@ XTRA_K_INTERRUPTCHECK
Definition xtra.h:208
@ XTRA_K_CURSORCOLUMN
Definition xtra.h:209
@ XTRA_K_LABELALL
Definition xtra.h:210
@ XTRA_K_OVERFLOWCHECK
Definition xtra.h:208
@ XTRA_K_VERSION
Definition xtra.h:206
@ XTRA_K_MAKESMALLEST
Definition xtra.h:205
@ XTRA_K_EXEPATH
Definition xtra.h:204
@ XTRA_K_RUNTIMEDEBUG
Definition xtra.h:207
@ XTRA_K_DEBUGINFO
Definition xtra.h:207
@ XTRA_K_LABELPOSITION
Definition xtra.h:211
@ XTRA_K_MAX
Definition xtra.h:211
@ XTRA_K_EXEFILE
Definition xtra.h:204
@ XTRA_K_STRINGBUFFER
Definition xtra.h:205
@ XTRA_K_LABELREMARK
Definition xtra.h:210
@ XTRA_K_LABELCASE
Definition xtra.h:211
@ XTRA_K_ASSEMBLERCHECK
Definition xtra.h:208
@ XTRA_K_STACKSIZE
Definition xtra.h:206
@ XTRA_K_CREATEDBGFILE
Definition xtra.h:207
@ XTRA_K_LABELSEARCH
Definition xtra.h:210
@ XTRA_K_FUNCOPTIMIZE
Definition xtra.h:205
@ XTRA_K_AUTORUN
Definition xtra.h:209
@ XTRA_K_NUMBEROFBUILDS
Definition xtra.h:206
@ XTRA_K_RESIDENTS
Definition xtra.h:204
@ XTRA_K_CLIARGS
Definition xtra.h:206
@ XTRA_K_CREATEICON
Definition xtra.h:204
@ XTRA_K_COUNT
Definition xtra.h:212
size_t xtra_text_cap(int field)
The bytes of a text field in a Blitz 2 .xtra (with the 0): a text is shorter than this.
Definition xtra.c:169
xtra_err
The error codes of the functions (XTRA_OK = 0: no error).
Definition xtra.h:260
@ XTRA_E_VERS
Definition xtra.h:264
@ XTRA_E_AB3_NAME
Definition xtra.h:275
@ XTRA_E_LONG
Definition xtra.h:272
@ XTRA_E_AB3_VERSION
Definition xtra.h:274
@ XTRA_E_SPACE
Definition xtra.h:266
@ XTRA_E_TEXT
Definition xtra.h:278
@ XTRA_E_UNTERMINATED
Definition xtra.h:265
@ XTRA_OK
Definition xtra.h:261
@ XTRA_E_SHORT
Definition xtra.h:262
@ XTRA_E_AB3_END
Definition xtra.h:269
@ XTRA_E_FIELD
Definition xtra.h:277
@ XTRA_E_TYPE
Definition xtra.h:276
@ XTRA_E_BB22
Definition xtra.h:267
@ XTRA_E_AB3_QUOTE
Definition xtra.h:271
@ XTRA_E_SIZE
Definition xtra.h:263
@ XTRA_E_AB3_LINE
Definition xtra.h:268
@ XTRA_E_BASE
Definition xtra.h:279
@ XTRA_E_AB3_NUMBER
Definition xtra.h:270
@ XTRA_E_COUNT
Definition xtra.h:280
@ XTRA_E_AB3_RESIDENTS
Definition xtra.h:273
int xtra_is_ab3_xtra(const uint8_t *xtra, size_t len)
Whether a companion .xtra has AmiBlitz3's binary format with 15 switch words (since AmiBlitz/AmiBlitz...
Definition xtra.c:362
xtra_source
Where the settings came from.
Definition xtra.h:111
@ XTRA_SRC_BLITZ2
Definition xtra.h:113
@ XTRA_SRC_AB3_TEXT
Definition xtra.h:114
@ XTRA_SRC_NONE
Definition xtra.h:112
int xtra_set_text(struct xtra *x, int field, const void *p, size_t len)
Set a text field to the caller's bytes.
Definition xtra.c:209
const char * xtra_strerror(int code)
The message of an error code (English, without position).
Definition xtra.c:104
#define XTRA_NBUFFER
Definition xtra.h:54
xtra_switch
The switch words in file order (offset 2 + 2 * index); each is the Flags word of the option gadget: X...
Definition xtra.h:69
@ XTRA_SW_ASSEMBLER_CHECK
Definition xtra.h:79
@ XTRA_SW_LONG_ARRAYS
Definition xtra.h:72
@ XTRA_SW_DEBUG_INFO
Definition xtra.h:76
@ XTRA_SW_WARNINGS
Definition xtra.h:81
@ XTRA_SW_DEFAULT_OVERFLOW
Definition xtra.h:85
@ XTRA_SW_QUOTED_MACROS
Definition xtra.h:74
@ XTRA_SW_MAKE_SMALLEST
Definition xtra.h:75
@ XTRA_SW_OVERFLOW_CHECK
Definition xtra.h:80
@ XTRA_SW_RUNTIME_ERRORS
Definition xtra.h:70
@ XTRA_SW_EXPAND_MACROS
Definition xtra.h:73
@ XTRA_SW_INTERRUPT_CHECK
Definition xtra.h:78
@ XTRA_SW_AUTO_RUN
Definition xtra.h:77
@ XTRA_SW_DEBUGGER
Definition xtra.h:71
@ XTRA_SW_DEFAULT_INTERRUPT
Definition xtra.h:84
void xtra_apply_vers0(struct xtra *x)
What blitz2's loadxtra does after reading a vers 0 file.
Definition xtra.c:159
int xtra_write_ab3(const struct xtra *x, const struct xtra_base *b, char *out, size_t cap, size_t *len, unsigned *skipped)
Write x as AmiBlitz3 header (not 0-terminated).
Definition xtra_ab3.c:868
int xtra_load(struct xtra *x, int type, const uint8_t *src, size_t len, const uint8_t *xtra, size_t xlen, struct xtra_error *err)
Load the settings of a source.
Definition xtra.c:475
int xtra_detect(const uint8_t *buf, size_t len, const char *path)
The type of a source.
Definition xtra.c:302
const uint8_t * xtra_get_text(const struct xtra *x, const struct xtra_base *b, int field, size_t *len)
A text field.
Definition xtra.c:181
xtra_field
The text fields (xtra_get_text, xtra_set_text).
Definition xtra.h:137
@ XTRA_F_LABEL_SEARCH
Definition xtra.h:141
@ XTRA_F_EXE_NAME
Definition xtra.h:139
@ XTRA_F_EXE_PATH
Definition xtra.h:138
@ XTRA_F_COUNT
Definition xtra.h:144
@ XTRA_F_CLI
Definition xtra.h:140
@ XTRA_F_RES0
Definition xtra.h:142
void xtra_init(struct xtra *x)
Initialise settings with the defaults.
Definition xtra.c:130
int xtra_companion_name(const char *path, char *out, size_t cap)
The name of the companion of the source path: path + ".xtra" (as TED and blitz2 make it).
Definition xtra.c:337
int xtra_has_companion(int type)
Whether the settings of a source of this type are in NAME.xtra.
Definition xtra.c:332
xtra_buffer
The buffer sizes in file order (offset 30 + 4 * index).
Definition xtra.h:91
@ XTRA_BUF_MACRO
Definition xtra.h:93
@ XTRA_BUF_OBJECT
Definition xtra.h:92
@ XTRA_BUF_SYSTEM
Definition xtra.h:92
@ XTRA_BUF_STRING
Definition xtra.h:93
@ XTRA_BUF_DATA
Definition xtra.h:92
@ XTRA_BUF_LIBS
Definition xtra.h:92
void xtra_max_begin(struct xtra_iter *it, const struct xtra *x, const struct xtra_base *b)
Start iterating the maxima of x.
Definition xtra.c:236