BB2 C port
API reference: Blitz libraries in C and the shared code
Loading...
Searching...
No Matches
edstub.h
Go to the documentation of this file.
1/*
2 * edstub.h - frame of a headless editor that blitz2 loads as blitz2:ted
3 * (from bb2 compilerlauf/tedstub). A program on this frame gets the
4 * compiler's edstruct (token list, xtra hooks, menu callback) and runs its
5 * own main instead of an editor; when that returns, blitz2 quits.
6 *
7 * Interface (ted.s 1.1, blitz2.s 1.95): blitz2 LoadSeg()s blitz2:ted and
8 * calls hunk+4 (`outside`, start.c) with a1 = edstruct; it gets a0 = main
9 * entry, a1 = comdata (the table of editor services the compiler calls,
10 * edstub.c). Then it calls main (a0 = its argument, the file name).
11 *
12 * The frame answers the compiler's services without a screen: requesters
13 * are remembered but never shown, getinput answers the known ones (the
14 * version requester, "Not Enough Object Memory"), DOS requesters are off.
15 *
16 * Built without any C runtime (-nostdlib, -ffreestanding): no startup
17 * code, no libc, no libgcc - no 32 bit multiplication or division. A
18 * program on TED's core (ab3cli) compiles the frame itself with TED's
19 * -fbaserel (the entries load its a4, start.c) and EDSTUB_INIT.
20 *
21 * Runs on Kickstart 1.2 (V33) and later: only functions of V33 (no
22 * CreateMsgPort, CreateIORequest, AllocDosObject ...; the helpers below
23 * do what those do).
24 */
25#ifndef EDSTUB_H
26#define EDSTUB_H
27
28#include <stddef.h>
29#include <exec/types.h>
30
31/**
32 * @brief The register frame of the stubs in start.c (movem d0-d7/a0-a6).
33 */
34struct regs {
35 ULONG d[8];
36 ULONG a[7];
37};
38
39/**
40 * @brief The compiler's edstruct (blitz2.s 274; ted.s `outside` copies its
41 * 14 words).
42 */
43struct edstruct {
44 APTR tokens; /* first node: next.l, word.w, name */
45 APTR menus;
46 APTR loadxtra; /* d7 = file handle, a6 = DOSBase */
48 APTR menu; /* menu callback: d6 = item */
49 APTR cleanup;
51};
52
53/** @brief The edstruct blitz2 passed to `outside` (a1). */
54extern struct edstruct *edstub_ed;
55
56/**
57 * @brief The program part, provided by the program on this frame.
58 *
59 * Called by the main entry; when it returns, the frame closes everything
60 * and blitz2 quits.
61 *
62 * @param arg the argument blitz2 got (a0 of the main entry: the file name)
63 */
64void edstub_main(const char *arg);
65
66#ifdef EDSTUB_INIT
67/**
68 * @brief The program's set-up, provided by a program whose frame is
69 * compiled with EDSTUB_INIT defined (ab3cli).
70 *
71 * Called by the init entry once the frame is ready, before the compiler
72 * goes on (loads its libraries, opens the version requester): the place to
73 * set the hooks and edstub_quiet for what comes before edstub_main.
74 */
75void edstub_init(void);
76#endif
77
78/**
79 * @brief Call code that may change every register (compiler callbacks, TED
80 * routines).
81 *
82 * Loads d0-d7/a0-a6 from *r, calls fn and stores all registers back into
83 * *r.
84 *
85 * @param fn the routine to call
86 * @param r the registers: in before the call, out after it
87 * @return d0 after the call
88 */
89ULONG edstub_callregs(APTR fn, struct regs *r);
90
91/**
92 * @brief Back to the compiler as if the editor had quit.
93 *
94 * Drops everything below the main entry's frame (the stack pointer kept
95 * by the main entry). Only inside main.
96 */
97void edstub_abort(void) __attribute__((noreturn));
98
99/**
100 * @name Hooks of the program
101 * NULL: the frame's default.
102 * @{
103 */
104/** @brief ezfreq: the file name for the requester with this title, or NULL
105 * (default: cancelled). */
106extern const char *(*edstub_ezfreq_hook)(const char *title);
107/** @brief The compiler's error message (default: logged). */
108extern void (*edstub_error_hook)(const char *msg);
109/** @brief tokone: tokenise the line (default: logged, line left as is). */
110extern void (*edstub_tokone_hook)(UBYTE *line);
111/** @brief Before the frame aborts inside main (compiler waits for input
112 * forever, extalloc of the original compiler failed): the program
113 * can log its result and free its data. */
114extern void (*edstub_abort_hook)(const char *why);
115/** @brief openio/closeio (ted.s: the console window of a program run from
116 * the editor): called in the program's process, runtheprog, before
117 * and after the program. */
118extern void (*edstub_openio_hook)(void);
119/** @copydoc edstub_openio_hook */
120extern void (*edstub_closeio_hook)(void);
121/** @brief getinput2 (the compiler polls the stop requester, chkrealstop):
122 * the id of the gadget hit, 0 = nothing (default: nothing). */
123extern UWORD (*edstub_getinput2_hook)(void);
124/** @} */
125
126/**
127 * @brief The number of requesters open now (openreq not yet closed).
128 * @return the depth of the requester stack
129 */
130int edstub_open_requests(void);
131
132struct MsgPort;
133/**
134 * @brief The UserPort of the requester window.
135 *
136 * Its signal is the stop requester's exception (blitz2 openstopreq), a
137 * message there is "a gadget was hit".
138 *
139 * @return the port
140 */
141struct MsgPort *edstub_req_port(void);
142
143/** @brief Length of edstub_logname. */
144#define EDSTUB_PATHLEN 256
145/** @brief The log file's name; empty while there is none. */
146extern char edstub_logname[EDSTUB_PATHLEN];
147
148/**
149 * @brief Log a line: to Output() and appended to the log file.
150 *
151 * Before there is a log file, the lines are kept and edstub_set_log()
152 * writes them first. The file is opened and closed for every line, so the
153 * log survives a crash of the compiler.
154 *
155 * @param s the line, without its line feed
156 */
157void edstub_log(const char *s);
158
159/** @brief Non-zero: edstub_log does not write to Output() (a program with a
160 * console output of its own; the log file still gets the lines). */
161extern int edstub_quiet;
162
163/**
164 * @brief Set the log file: create it (a new file) and write the lines kept
165 * so far.
166 * @param path the file name (cut to EDSTUB_PATHLEN - 1 characters)
167 * @return 1, or 0 if the file cannot be created (no log file then)
168 */
169int edstub_set_log(const char *path);
170
171/**
172 * @brief The busy pointer: sleepon sets it (1), pointeron clears it (ted.s:
173 * the window pointer); the frame shows nothing, it only keeps the
174 * state.
175 */
176extern int edstub_busy;
177
178/** @brief A new job: the counters of the requester answers start again. */
179void edstub_reset_requests(void);
180
181/**
182 * @name The racing stripe (#980)
183 * The compiler's progress bar. The original compiler XORs it into the
184 * editor's bitmap (comdata+36, rows 0 to 9, comdata+92 bytes per row);
185 * blitz2-c reports its cells through TED-C's progress call (comdata+98
186 * marker 'TEDp', +102 entry: d0 bar, d1 byte column). By default the frame
187 * has a bitmap of 80 bytes per row and does not announce the call.
188 * @{
189 */
190/**
191 * @brief Give the compiler a bitmap of bmapmul bytes per row (comdata+92)
192 * with guard bytes before and after it, and record the stripe from
193 * now on (edstub_stripe_log).
194 * @param bmapmul bytes per row (at least 80)
195 * @param guard guard bytes before and after the bitmap
196 * @return 1, or 0 if out of memory (the bitmap stays as it was)
197 */
198int edstub_set_bitmap(UWORD bmapmul, ULONG guard);
199
200/**
201 * @brief Announce the progress call (comdata+98 = 'TEDp') or not (0).
202 *
203 * A call toggles the cell as the original compiler XORs it (the byte
204 * column of rows bar and 9 - bar of the bitmap) and is counted.
205 */
206void edstub_set_progress(int on);
207
208/**
209 * @brief After a compile: log the stripe, then clear the bitmap, refill
210 * the guards and the counters.
211 *
212 * Lines (tab separated, with the job's id): `PROGRESS ID none` (no call)
213 * or per bar with calls `PROGRESS ID bar N COUNTS` (the calls per column
214 * from column 0, a digit each, '+' above 9, up to the last column called),
215 * plus `PROGRESS ID bad N` for calls with a bar above 3 or a column
216 * outside the row; `STRIPE ID none` (bitmap empty) or per row with set
217 * bytes `STRIPE ID row R PICTURE` ('#' $FF, '.' 0, 'x' else, up to the
218 * last byte not 0, columns 0 to 255); `GUARD ID ok` or `GUARD ID before N
219 * after M` (bytes of the guards changed). The picture and the guards are
220 * those of the checkpoints openreq, closereq and the end of the job: the
221 * fullest picture, the most changed guard bytes (with two passes the XORs
222 * of the second undo those of the first; the requester of the second pass
223 * opens between them). Nothing without edstub_set_bitmap.
224 *
225 * @param id the job's id
226 */
227void edstub_stripe_log(const char *id);
228/** @} */
229
230struct IORequest;
231/**
232 * @brief A message port with a signal of its own, with Kickstart 1.x calls
233 * (CreateMsgPort of V36).
234 * @return the port, or NULL if out of memory or signals
235 */
236struct MsgPort *edstub_create_port(void);
237
238/**
239 * @brief Free a port of edstub_create_port() and its signal.
240 * @param port the port (NULL: nothing)
241 */
242void edstub_delete_port(struct MsgPort *port);
243
244/**
245 * @brief An IO request for a port, with Kickstart 1.x calls
246 * (CreateIORequest of V36).
247 * @param port the reply port (NULL: fails)
248 * @param size the size of the request in bytes (cleared)
249 * @return the request, or NULL if port is NULL or out of memory
250 */
251struct IORequest *edstub_create_ioreq(struct MsgPort *port, ULONG size);
252
253/**
254 * @brief Free a request of edstub_create_ioreq() (as DeleteIORequest: the
255 * node's successor and io_Device set to -1 first).
256 * @param io the request (NULL: nothing)
257 */
258void edstub_delete_ioreq(struct IORequest *io);
259
260/**
261 * @name Small libc replacements
262 * memset/memcpy for the compiler as well.
263 * @{
264 */
265void *memset(void *d, int c, size_t n);
266void *memcpy(void *d, const void *s, size_t n);
267/** @brief The length of the string s. */
268ULONG edstub_strlen(const char *s);
269/** @brief 1 if the strings are equal, else 0. */
270int edstub_streq(const char *a, const char *b);
271/** @brief 1 if s starts with pre, else 0. */
272int edstub_prefix(const char *s, const char *pre);
273/** @brief Copy s to d, at most max - 1 characters and the 0 (nothing if
274 * max is 0). */
275void edstub_strcpy(char *d, const char *s, ULONG max);
276/** @brief Append s to d; max is the size of all of d (as edstub_strcpy). */
277void edstub_strcat(char *d, const char *s, ULONG max);
278/** @brief u / 10 without libgcc (no __udivsi3 in a -nostdlib build); the
279 * remainder to *rem. */
280ULONG edstub_udiv10(ULONG u, ULONG *rem);
281/** @} */
282
283/**
284 * @brief A bounded string builder: buf of max bytes, len used, always
285 * 0-terminated (what does not fit is dropped).
286 */
287struct sb {
288 char *buf;
289 ULONG len, max;
290};
291
292/** @brief Append the character c. */
293void sbc(struct sb *b, char c);
294/** @brief Append the string s ("(null)" for NULL). */
295void sbs(struct sb *b, const char *s);
296/** @brief Append v in decimal. */
297void sbn(struct sb *b, LONG v);
298/** @brief Append the low digits hex digits of v, upper case. */
299void sbx(struct sb *b, ULONG v, int digits);
300/** @brief Append s quoted, controls (< 32 and 127) as \\xNN. */
301void sbq(struct sb *b, const char *s);
302
303#endif
ULONG WORD UWORD c
Definition 2dlib.c:2491
ULONG WORD UWORD UWORD border ULONG ULONG struct bb_bitmap *dst void UWORD n
Definition 2dlib.c:2498
UWORD size
Definition 2dlib.c:1170
struct TagItem path
Definition asllib.c:188
static void line(WORD x1, WORD y1, WORD x2, WORD y2, ULONG c)
Definition blitzoslib.c:392
struct MsgPort port
Definition brexxlib.c:299
struct IOStdReq io
Definition brexxlib.c:298
static struct @065163037313156332013005143365272036211065172003 d
struct edstruct * edstub_ed
The edstruct blitz2 passed to outside (a1).
Definition edstub.c:21
char edstub_logname[EDSTUB_PATHLEN]
The log file's name; empty while there is none.
Definition edstub.c:29
void(* edstub_closeio_hook)(void)
openio/closeio (ted.s: the console window of a program run from the editor): called in the program's ...
Definition edstub.c:27
void(* edstub_openio_hook)(void)
openio/closeio (ted.s: the console window of a program run from the editor): called in the program's ...
Definition edstub.c:26
int edstub_busy
The busy pointer: sleepon sets it (1), pointeron clears it (ted.s: the window pointer); the frame sho...
Definition edstub.c:419
void(* edstub_error_hook)(const char *msg)
The compiler's error message (default: logged).
Definition edstub.c:23
void(* edstub_tokone_hook)(UBYTE *line)
tokone: tokenise the line (default: logged, line left as is).
Definition edstub.c:24
UWORD(* edstub_getinput2_hook)(void)
getinput2 (the compiler polls the stop requester, chkrealstop): the id of the gadget hit,...
Definition edstub.c:28
void(* edstub_abort_hook)(const char *why)
Before the frame aborts inside main (compiler waits for input forever, extalloc of the original compi...
Definition edstub.c:25
int edstub_quiet
Non-zero: edstub_log does not write to Output() (a program with a console output of its own; the log ...
Definition edstub.c:30
struct MsgPort * edstub_req_port(void)
The UserPort of the requester window.
Definition edstub.c:474
void edstub_strcpy(char *d, const char *s, ULONG max)
Copy s to d, at most max - 1 characters and the 0 (nothing if max is 0).
Definition edstub.c:175
ULONG edstub_callregs(APTR fn, struct regs *r)
Call code that may change every register (compiler callbacks, TED routines).
void edstub_main(const char *arg)
The program part, provided by the program on this frame.
void edstub_stripe_log(const char *id)
After a compile: log the stripe, then clear the bitmap, refill the guards and the counters.
Definition edstub.c:718
int edstub_open_requests(void)
The number of requesters open now (openreq not yet closed).
Definition edstub.c:469
void sbn(struct sb *b, LONG v)
Append v in decimal.
Definition edstub.c:226
void * memcpy(void *d, const void *s, size_t n)
Definition edstub.c:141
ULONG edstub_udiv10(ULONG u, ULONG *rem)
u / 10 without libgcc (no __udivsi3 in a -nostdlib build); the remainder to *rem.
Definition edstub.c:195
#define EDSTUB_PATHLEN
Length of edstub_logname.
Definition edstub.h:144
void edstub_reset_requests(void)
A new job: the counters of the requester answers start again.
Definition edstub.c:376
void edstub_log(const char *s)
Log a line: to Output() and appended to the log file.
Definition edstub.c:277
void * memset(void *d, int c, size_t n)
Definition edstub.c:132
ULONG edstub_strlen(const char *s)
The length of the string s.
Definition edstub.c:151
int edstub_streq(const char *a, const char *b)
1 if the strings are equal, else 0.
Definition edstub.c:168
void sbx(struct sb *b, ULONG v, int digits)
Append the low digits hex digits of v, upper case.
Definition edstub.c:245
void sbc(struct sb *b, char c)
Append the character c.
Definition edstub.c:211
struct IORequest * edstub_create_ioreq(struct MsgPort *port, ULONG size)
An IO request for a port, with Kickstart 1.x calls (CreateIORequest of V36).
Definition edstub.c:829
int edstub_prefix(const char *s, const char *pre)
1 if s starts with pre, else 0.
Definition edstub.c:160
void edstub_set_progress(int on)
Announce the progress call (comdata+98 = 'TEDp') or not (0).
Definition edstub.c:697
void sbs(struct sb *b, const char *s)
Append the string s ("(null)" for NULL).
Definition edstub.c:218
void edstub_strcat(char *d, const char *s, ULONG max)
Append s to d; max is the size of all of d (as edstub_strcpy).
Definition edstub.c:187
int edstub_set_log(const char *path)
Set the log file: create it (a new file) and write the lines kept so far.
Definition edstub.c:299
int edstub_set_bitmap(UWORD bmapmul, ULONG guard)
Give the compiler a bitmap of bmapmul bytes per row (comdata+92) with guard bytes before and after it...
Definition edstub.c:673
void edstub_abort(void)
Back to the compiler as if the editor had quit.
void sbq(struct sb *b, const char *s)
Append s quoted, controls (< 32 and 127) as \xNN.
Definition edstub.c:251
void edstub_delete_port(struct MsgPort *port)
Free a port of edstub_create_port() and its signal.
Definition edstub.c:821
struct MsgPort * edstub_create_port(void)
A message port with a signal of its own, with Kickstart 1.x calls (CreateMsgPort of V36).
Definition edstub.c:801
void edstub_delete_ioreq(struct IORequest *io)
Free a request of edstub_create_ioreq() (as DeleteIORequest: the node's successor and io_Device set t...
Definition edstub.c:841
static struct AppMessage * msg
Definition riapplib.c:274
static struct @342026374002303043102303243063125232020331002053 v
char digits[16]
Definition ridisasmlib.c:396
Definition cliargslib.c:38
The compiler's edstruct (blitz2.s 274; ted.s outside copies its 14 words).
Definition edstub.h:43
APTR menus
Definition edstub.h:45
APTR menu
Definition edstub.h:48
APTR tokens
Definition edstub.h:44
APTR cleanup
Definition edstub.h:49
UBYTE quote
Definition edstub.h:50
APTR loadxtra
Definition edstub.h:46
UBYTE colon
Definition edstub.h:50
APTR savextra
Definition edstub.h:47
UBYTE label
Definition edstub.h:50
UBYTE remark
Definition edstub.h:50
The register frame of the stubs in start.c (movem d0-d7/a0-a6).
Definition edstub.h:34
ULONG d[8]
Definition edstub.h:35
ULONG a[7]
Definition edstub.h:36
A bounded string builder: buf of max bytes, len used, always 0-terminated (what does not fit is dropp...
Definition edstub.h:287
ULONG len
Definition edstub.h:289
ULONG max
Definition edstub.h:289
char * buf
Definition edstub.h:288
static int on(uint16_t v)
Definition xtra_ab3.c:557