BB2 C port
API reference: Blitz libraries in C and the shared code
Loading...
Searching...
No Matches
ab3job.h
Go to the documentation of this file.
1/*
2 * ab3job.h - a compile from the shell with blitz2-ab3 (spec
3 * ab3-compat/command-line, docs/ab3/variant.md): the command line, modelled
4 * on AmiBlitz3's CLI mode, and the job blitz2-ab3 hands to its headless
5 * editor ab3cli.
6 *
7 * blitz2-ab3 -s SOURCE -e EXE [-r] [-mode ab3|bb2] [-w LIST] [-werr LIST]
8 *
9 * blitz2-ab3 parses its arguments with ab3args_parse, decides the mode of
10 * the source, loads PROGDIR:ab3cli instead of blitz2:ted and calls its main
11 * entry with a0 = the job (instead of the file name an editor gets);
12 * ab3cli loads and compiles the source and leaves its return code in the
13 * job. The job is plain data, so both sides - compiled in their own
14 * worlds - share this layout.
15 *
16 * Shared code like shared/xtra: every user compiles ab3args.c itself (the
17 * host tests in tools/lib/ab3job, blitz2-ab3). C99 on the freestanding
18 * headers: no libc, no writable static data.
19 */
20#ifndef AB3JOB_H
21#define AB3JOB_H
22
23#include <stddef.h>
24#include <stdint.h>
25
26#ifdef __cplusplus
27extern "C" {
28#endif
29
30/** @brief The job's first bytes: what ab3cli checks before it trusts a0. */
31#define AB3JOB_MAGIC "AB3JOB1"
32/** @brief Bytes of a file name in the job (with its 0). */
33#define AB3JOB_PATHLEN 256
34
35/** @brief The return codes of a command line run (design D6): those of
36 * the NDK's dos/dos.h (ab3cli checks that they agree; the host
37 * has no dos/dos.h). */
39 AB3JOB_RC_OK = 0, /* RETURN_OK: compiled without warnings
40 (or -h) */
41 AB3JOB_RC_WARN = 5, /* RETURN_WARN: compiled with warnings */
42 AB3JOB_RC_ERROR = 10, /* RETURN_ERROR: compile error, or a
43 warning that is an error */
44 AB3JOB_RC_FAIL = 20 /* RETURN_FAIL: argument or setup error */
45};
46
47/**
48 * @brief The compiler's warnings (change compiler-warnings, design D1):
49 * their numbers, bit n of a warning set. The compiler core has the
50 * same numbers in parse.h (W_*); ab3main.c checks that they agree.
51 */
53 AB3JOB_W_RESCLASH, /* a constant of the residents with two
54 values (stmts.c checkconstclash) */
56};
57/** @brief The set of all warnings. */
58#define AB3JOB_W_ALL ((uint32_t)((1UL << AB3JOB_W_COUNT) - 1))
59
60/** @brief The names of the warnings by number (-w, -werr and the console
61 * line), AB3JOB_W_COUNT entries and a NULL. */
62extern const char *const ab3args_warnings[];
63
64/**
65 * @brief The job of a command line run.
66 *
67 * Filled by ab3args_parse (force, release_exe, source, exe, the warning
68 * lists), by blitz2-ab3 (mode, the error's place, warnerrs, warnings) and
69 * by ab3cli (started, result, tokfile).
70 */
71struct ab3job {
72 char magic[8]; /* AB3JOB_MAGIC with its 0 */
73 uint8_t force; /* -mode: enum xtra_mode, XTRA_MODE_DETECT
74 (0) without the option */
75 uint8_t mode; /* the program's mode (XTRA_MODE_BB2 or
76 XTRA_MODE_AB3), decided by blitz2-ab3 */
77 uint8_t release_exe; /* -r: no runtime error checking, no
78 debugger, no debug information */
79 uint8_t started; /* ab3cli ran the job */
80 uint8_t result; /* enum ab3job_rc, set by ab3cli */
81 uint8_t pad;
82 /* ab3cli's service for a text include, set by ab3cli: an entry with
83 the registers of an editor service (blitz2 callregs) - a0 = the
84 include's name; out d0 = its lines as the editor loads them (TED's
85 readline: tokenised with the program's token list), each ending in
86 its 0, in AllocMem(d1 + 1, MEMF_PUBLIC) memory the caller frees;
87 d1 = their length; d2 = the empty lines its embedded header became
88 (AB3 mode; 0 without a header and in BB2 mode); d0 = 0: the file
89 cannot be read (reported) */
90 void *tokfile;
91 char source[AB3JOB_PATHLEN]; /* -s */
92 char exe[AB3JOB_PATHLEN]; /* -e */
93 /* the place of a compile error inside an include (task 3.6): ab3cli
94 clears errset before the compile; blitz2-ab3 places the first error
95 (errset = 1): errline > 0 - line errline of the include errfile
96 (the innermost one that has a line read), 0 - the compiler's line
97 of the source */
98 uint8_t errset;
99 uint8_t pad2[3];
100 uint32_t errline;
102 /* -w and -werr (design D4): the lists, left to right, as changes of
103 the source's setting: set = (set & keep) | add, for the enabled
104 warnings (warn_*) and the ones that are errors (werr_*); without
105 the option keep = AB3JOB_W_ALL, add = 0 */
108 /* the warnings that became errors (blitz2-ab3, ext_warning): ab3cli
109 ends with AB3JOB_RC_ERROR when they were all its set-up errors */
110 uint8_t warnerrs;
111 /* the warnings printed (blitz2-ab3, ext_warning; at most 255): a
112 compile without errors ends with AB3JOB_RC_WARN */
113 uint8_t warnings;
114 uint8_t pad3[2];
115};
116
117/**
118 * @brief The return code at the end of a compile (design D6 of the change
119 * compiler-warnings), what ab3cli leaves in the job.
120 *
121 * A set-up error (outside the compile: loading libraries or residents)
122 * gives AB3JOB_RC_FAIL, unless all of them were warnings that are errors
123 * (AB3JOB_RC_ERROR); a compile error AB3JOB_RC_ERROR; no executable
124 * written AB3JOB_RC_FAIL; otherwise AB3JOB_RC_WARN after a warning, else
125 * AB3JOB_RC_OK.
126 *
127 * @param job the job (warnerrs, warnings)
128 * @param setuperrs the set-up errors (0: the compile ran)
129 * @param compileerr nonzero: the compile ended with an error
130 * @param written nonzero: the executable was written
131 * @return an enum ab3job_rc
132 */
133static inline int ab3job_rc(const struct ab3job *job, int setuperrs, int compileerr, int written)
134{
135 if (setuperrs)
136 return setuperrs == job->warnerrs ? AB3JOB_RC_ERROR : AB3JOB_RC_FAIL;
137 if (compileerr)
138 return AB3JOB_RC_ERROR;
139 if (!written)
140 return AB3JOB_RC_FAIL;
141 return job->warnings ? AB3JOB_RC_WARN : AB3JOB_RC_OK;
142}
143
144/** @brief What ab3args_parse found. */
146 AB3ARGS_EDITOR, /* no option: start the editor as blitz2 */
147 AB3ARGS_COMPILE, /* the job is filled: compile it */
148 AB3ARGS_HELP, /* -h: print the usage, return code 0 */
149 AB3ARGS_UNSUPPORTED, /* an option of AmiBlitz3 this change does
150 not support: print the message, 20 */
151 AB3ARGS_FAIL /* an argument error: print the message and
152 the usage, 20 */
153};
154
155/** @brief The usage (several lines, each ending in LF). */
156extern const char ab3args_usage[];
157
158/**
159 * @brief Parse the command line of blitz2-ab3.
160 *
161 * argv[1..argc) as libnix (or a shell) splits them. Without an argument
162 * that starts with '-' the result is AB3ARGS_EDITOR (blitz2's start with
163 * at most a project name). Options, in any case, AmiBlitz3's spelling:
164 * -s/-source FILE, -e/-exe FILE, -r/-release, -mode ab3|bb2 and
165 * -w/-werr LIST (this repository's), -h/-help. A LIST is comma-separated
166 * items all, none, NAME, -NAME (ab3args_warnings), applied left to right;
167 * several -w (-werr) are applied in order. The other options of AmiBlitz3's CLI mode
168 * (-d/-debug, -run, -dump, -setcom, -setdbg, -strbufsize, -stacksize,
169 * -maxerrors, -1/-1pass, -dform, -PED, -save, -v/-verbose) are refused.
170 * The first problem decides; -h before it gives AB3ARGS_HELP. Given
171 * twice, the last value counts (the lists: both are applied). An unknown
172 * warning name or an empty item is AB3ARGS_FAIL.
173 *
174 * @param argc the number of arguments with the program's name
175 * @param argv the arguments; argv[0] is the program's name
176 * @param job the job: initialised (magic, defaults) and filled
177 * @param msg the message for AB3ARGS_UNSUPPORTED and AB3ARGS_FAIL (one
178 * line without LF; "" otherwise)
179 * @param cap the size of msg in bytes (> 0)
180 * @return an enum ab3args_result
181 */
182int ab3args_parse(int argc, char *const argv[], struct ab3job *job, char *msg, size_t cap);
183
184/**
185 * @brief The return code that goes with a result of ab3args_parse.
186 * @param result an enum ab3args_result
187 * @return AB3JOB_RC_OK for AB3ARGS_HELP, AB3JOB_RC_FAIL for the errors, -1
188 * for AB3ARGS_EDITOR and AB3ARGS_COMPILE (not the end of the run)
189 */
190int ab3args_rc(int result);
191
192#ifdef __cplusplus
193}
194#endif
195
196#endif
const char ab3args_usage[]
The usage (several lines, each ending in LF).
Definition ab3args.c:14
const char *const ab3args_warnings[]
The names of the warnings by number (-w, -werr and the console line), AB3JOB_W_COUNT entries and a NU...
Definition ab3args.c:30
int ab3args_rc(int result)
The return code that goes with a result of ab3args_parse.
Definition ab3args.c:245
ab3args_result
What ab3args_parse found.
Definition ab3job.h:145
@ AB3ARGS_COMPILE
Definition ab3job.h:147
@ AB3ARGS_FAIL
Definition ab3job.h:151
@ AB3ARGS_UNSUPPORTED
Definition ab3job.h:149
@ AB3ARGS_HELP
Definition ab3job.h:148
@ AB3ARGS_EDITOR
Definition ab3job.h:146
ab3job_rc
The return codes of a command line run (design D6): those of the NDK's dos/dos.h (ab3cli checks that ...
Definition ab3job.h:38
@ AB3JOB_RC_OK
Definition ab3job.h:39
@ AB3JOB_RC_WARN
Definition ab3job.h:41
@ AB3JOB_RC_ERROR
Definition ab3job.h:42
@ AB3JOB_RC_FAIL
Definition ab3job.h:44
#define AB3JOB_PATHLEN
Bytes of a file name in the job (with its 0).
Definition ab3job.h:33
ab3job_warning
The compiler's warnings (change compiler-warnings, design D1): their numbers, bit n of a warning set....
Definition ab3job.h:52
@ AB3JOB_W_RESCLASH
Definition ab3job.h:53
@ AB3JOB_W_COUNT
Definition ab3job.h:55
int ab3args_parse(int argc, char *const argv[], struct ab3job *job, char *msg, size_t cap)
Parse the command line of blitz2-ab3.
Definition ab3args.c:174
static struct AppMessage * msg
Definition riapplib.c:274
static ULONG argc
Definition rievallib.c:186
The job of a command line run.
Definition ab3job.h:71
uint8_t pad2[3]
Definition ab3job.h:99
char exe[AB3JOB_PATHLEN]
Definition ab3job.h:92
void * tokfile
Definition ab3job.h:90
char errfile[AB3JOB_PATHLEN]
Definition ab3job.h:101
uint32_t werr_keep
Definition ab3job.h:107
uint8_t release_exe
Definition ab3job.h:77
uint8_t mode
Definition ab3job.h:75
uint32_t warn_add
Definition ab3job.h:106
char source[AB3JOB_PATHLEN]
Definition ab3job.h:91
uint8_t started
Definition ab3job.h:79
char magic[8]
Definition ab3job.h:72
uint32_t werr_add
Definition ab3job.h:107
uint32_t errline
Definition ab3job.h:100
uint32_t warn_keep
Definition ab3job.h:106
uint8_t pad
Definition ab3job.h:81
uint8_t result
Definition ab3job.h:80
uint8_t warnings
Definition ab3job.h:113
uint8_t warnerrs
Definition ab3job.h:110
uint8_t force
Definition ab3job.h:73
uint8_t pad3[2]
Definition ab3job.h:114
uint8_t errset
Definition ab3job.h:98