1 /* rendering lines and managing traps */
8 #define NOPAGE 0x40000000 /* undefined bp_next */
9 #define cfmt env_fmt() /* current formatter */
10 #define cwb env_wb() /* current word buffer */
14 struct sbuf sbuf
; /* diversion output */
15 int reg
; /* diversion register */
16 int tpos
; /* diversion trap position */
17 int treg
; /* diversion trap register */
18 int dl
; /* diversion width */
19 int prev_d
; /* previous \n(.d value */
20 int prev_h
; /* previous \n(.h value */
21 int prev_mk
; /* previous .mk internal register */
22 int prev_ns
; /* previous .ns value */
24 static struct div divs
[NPREV
]; /* diversion stack */
25 static struct div
*cdiv
; /* current diversion */
26 static int ren_div
; /* rendering a diversion */
27 static int ren_divvs
; /* the amount of .v in diversions */
28 static int trap_em
= -1; /* end macro */
30 static int ren_nl
; /* just after a newline */
31 static int ren_partial
; /* reading an input line in render_rec() */
32 static int ren_unbuf
[8]; /* ren_back() buffer */
34 static int ren_aborted
; /* .ab executed */
36 static int bp_first
= 1; /* prior to the first page */
37 static int bp_next
= NOPAGE
; /* next page number */
38 static int bp_count
; /* number of pages so far */
39 static int bp_ejected
; /* current ejected page */
40 static int bp_final
; /* 1: executing em, 2: the final page, 3: the 2nd final page */
41 static int ren_level
; /* the depth of render_rec() calls */
43 static char c_fa
[GNLEN
]; /* field delimiter */
44 static char c_fb
[GNLEN
]; /* field padding */
46 static int ren_next(void)
48 return ren_un
> 0 ? ren_unbuf
[--ren_un
] : tr_next();
51 static void ren_back(int c
)
53 ren_unbuf
[ren_un
++] = c
;
56 void tr_di(char **args
)
59 cdiv
= cdiv
? cdiv
+ 1 : divs
;
60 memset(cdiv
, 0, sizeof(*cdiv
));
61 sbuf_init(&cdiv
->sbuf
);
62 cdiv
->reg
= map(args
[1]);
64 if (args
[0][2] == 'a' && str_get(cdiv
->reg
)) /* .da */
65 sbuf_append(&cdiv
->sbuf
, str_get(cdiv
->reg
));
66 sbuf_printf(&cdiv
->sbuf
, "%c%s\n", c_cc
, TR_DIVBEG
);
76 sbuf_printf(&cdiv
->sbuf
, "%c%s\n", c_cc
, TR_DIVEND
);
77 str_set(cdiv
->reg
, sbuf_buf(&cdiv
->sbuf
));
78 sbuf_done(&cdiv
->sbuf
);
85 cdiv
= cdiv
> divs
? cdiv
- 1 : NULL
;
91 return cdiv
? cdiv
->reg
: -1;
96 return fmt_wid(cfmt
) + wb_wid(cwb
);
99 void tr_divbeg(char **args
)
105 void tr_divend(char **args
)
108 errdie("neatroff: diversion stack empty\n");
113 void tr_divvs(char **args
)
115 ren_divvs
= eval(args
[1], 'u');
118 void tr_transparent(char **args
)
121 sbuf_printf(&cdiv
->sbuf
, "%s\n", args
[1]);
123 out("%s\n", args
[1]);
126 static int trap_reg(int pos
);
127 static int trap_pos(int pos
);
128 static void trap_exec(int reg
);
130 static void ren_page(int force
)
132 if (!force
&& bp_final
>= 2)
137 n_pg
= bp_next
!= NOPAGE
? bp_next
: n_pg
+ 1;
142 if (trap_pos(-1) == 0)
143 trap_exec(trap_reg(-1));
146 static int ren_first(void)
148 if (bp_first
&& !cdiv
) {
156 /* when nodiv, do not append .sp to diversions */
157 static void ren_sp(int n
, int nodiv
)
159 int linevs
= !n
; /* the vertical spacing before a line */
161 if (!n
&& ren_div
&& ren_divvs
&& !n_u
)
162 n
= ren_divvs
; /* .v at the time of diversion */
168 if (cdiv
&& !nodiv
) {
170 sbuf_printf(&cdiv
->sbuf
, "%c%s %du\n", c_cc
, TR_DIVVS
, n_v
);
172 sbuf_printf(&cdiv
->sbuf
, "%csp %du\n", c_cc
, n
? n
: n_v
);
178 static int render_rec(int level
);
180 static void trap_exec(int reg
)
183 int partial
= ren_partial
&& (!ren_un
|| ren_unbuf
[0] != '\n');
185 sprintf(cmd
, "%c%s %d\n", c_cc
, TR_POPREN
, ren_level
);
187 in_push(str_get(reg
), NULL
);
190 render_rec(++ren_level
);
191 /* executed the trap while in the middle of an input line */
193 fmt_suppressnl(cfmt
);
197 static int detect_traps(int beg
, int end
)
199 int pos
= trap_pos(beg
);
200 return pos
>= 0 && (cdiv
|| pos
< n_p
) && pos
<= end
;
203 /* return 1 if executed a trap */
204 static int ren_traps(int beg
, int end
, int dosp
)
206 int pos
= trap_pos(beg
);
207 if (detect_traps(beg
, end
)) {
208 if (dosp
&& pos
> beg
)
209 ren_sp(pos
- beg
, 0);
210 trap_exec(trap_reg(beg
));
216 static int detect_pagelimit(int ne
)
218 return !cdiv
&& n_nl
+ ne
>= n_p
;
221 /* start a new page if needed */
222 static int ren_pagelimit(int ne
)
224 if (detect_pagelimit(ne
)) {
231 /* return 1 if triggered a trap */
232 static int down(int n
)
234 if (ren_traps(n_d
, n_d
+ (n
? n
: n_v
), 1))
236 ren_sp(MAX(n
, -n_d
), 0);
237 return ren_pagelimit(0);
240 /* line adjustment */
241 static int ren_ljust(struct sbuf
*spre
, int w
, int ad
, int li
, int lI
, int ll
)
244 int llen
= ll
- lI
- li
;
246 if ((ad
& AD_B
) == AD_C
)
247 ljust
+= llen
> w
? (llen
- w
) / 2 : 0;
248 if ((ad
& AD_B
) == AD_R
)
251 sbuf_printf(spre
, "%ch'%du'", c_ec
, ljust
);
252 if (cdiv
&& cdiv
->dl
< w
+ ljust
)
253 cdiv
->dl
= w
+ ljust
;
257 /* append the line to the current diversion or send it to out.c */
258 static void ren_out(char *beg
, char *mid
, char *end
)
261 sbuf_append(&cdiv
->sbuf
, beg
);
262 sbuf_append(&cdiv
->sbuf
, mid
);
263 sbuf_append(&cdiv
->sbuf
, end
);
264 sbuf_append(&cdiv
->sbuf
, "\n");
274 static void ren_dir(struct sbuf
*sbuf
)
278 dir_fix(&fixed
, sbuf_buf(sbuf
));
281 sbuf_append(sbuf
, sbuf_buf(&fixed
));
285 static int zwid(void)
287 struct glyph
*g
= dev_glyph("0", n_f
);
288 return g
? font_gwid(g
->font
, dev_font(n_f
), n_s
, g
->wid
) : 0;
291 /* append the line number to the output line */
292 static void ren_lnum(struct sbuf
*spre
)
299 if (n_nn
<= 0 && (n_ln
% n_nM
) == 0)
300 sprintf(num
, "%d", n_ln
);
301 wb_hmov(&wb
, n_nI
* zwid());
303 wb_hmov(&wb
, (3 - strlen(num
)) * zwid());
308 wb_hmov(&wb
, n_nS
* zwid());
309 sbuf_append(spre
, wb_buf(&wb
));
317 /* append margin character */
318 static void ren_mc(struct sbuf
*sbuf
, int w
, int ljust
)
322 if (w
+ ljust
< n_l
+ n_mcn
)
323 wb_hmov(&wb
, n_l
+ n_mcn
- w
- ljust
);
324 wb_putexpand(&wb
, c_mc
);
325 sbuf_append(sbuf
, wb_buf(&wb
));
329 /* process a line and print it with ren_out() */
330 static int ren_line(char *line
, int w
, int ad
, int body
,
331 int li
, int lI
, int ll
, int els_neg
, int els_pos
)
333 struct sbuf sbeg
, send
, sbuf
;
334 int prev_d
, lspc
, ljust
;
339 sbuf_append(&sbuf
, line
);
340 lspc
= MAX(1, n_L
) * n_v
; /* line space, ignoreing \x */
342 if (!n_ns
|| line
[0] || els_neg
|| els_pos
) {
346 if (line
[0] && n_nm
&& body
)
348 if (!ren_div
&& dir_do
)
350 ljust
= ren_ljust(&sbeg
, w
, ad
, li
, lI
, ll
);
351 if (line
[0] && body
&& n_mc
)
352 ren_mc(&send
, w
, ljust
);
353 ren_out(sbuf_buf(&sbeg
), sbuf_buf(&sbuf
), sbuf_buf(&send
));
362 if (detect_traps(prev_d
, n_d
) || detect_pagelimit(lspc
- n_v
)) {
363 if (!ren_pagelimit(lspc
- n_v
))
364 ren_traps(prev_d
, n_d
, 0);
367 if (lspc
- n_v
&& down(lspc
- n_v
))
372 /* read a line from fmt and send it to ren_line() */
373 static int ren_passline(struct fmt
*fmt
)
376 int ll
, li
, lI
, els_neg
, els_pos
, w
, ret
;
379 if (!fmt_morewords(fmt
))
381 buf
= fmt_nextline(fmt
, &w
, &li
, &lI
, &ll
, &els_neg
, &els_pos
);
382 if ((n_cp
&& !n_u
) || n_na
)
384 else if ((ad
& AD_B
) == AD_B
)
385 ad
= n_td
> 0 ? AD_R
: AD_L
;
388 ret
= ren_line(buf
, w
, ad
, 1, li
, lI
, ll
, els_neg
, els_pos
);
393 /* output formatted lines in fmt */
394 static int ren_fmtpop(struct fmt
*fmt
)
397 while (fmt_morelines(fmt
))
398 ret
= ren_passline(fmt
);
402 /* format and output all lines in fmt */
403 static void ren_fmtpopall(struct fmt
*fmt
)
405 while (fmt_fill(fmt
, 0))
410 /* pass the given word buffer to the current line buffer (cfmt) */
411 static void ren_fmtword(struct wb
*wb
)
413 while (fmt_word(cfmt
, wb
))
418 /* output current line; returns 1 if triggered a trap */
419 static int ren_br(void)
423 while (fmt_fill(cfmt
, 1))
425 return ren_fmtpop(cfmt
);
428 void tr_br(char **args
)
430 if (args
[0][0] == c_cc
)
433 ren_fmtpopall(cfmt
); /* output the completed lines */
436 void tr_sp(char **args
)
440 if (args
[0][0] == c_cc
)
442 n
= args
[1] ? eval(args
[1], 'v') : n_v
;
443 if (n
&& (!n_ns
|| ren_div
) && !traps
)
447 void tr_sv(char **args
)
449 int n
= eval(args
[1], 'v');
451 if (n_d
+ n
< f_nexttrap())
457 void tr_ns(char **args
)
462 void tr_rs(char **args
)
467 void tr_os(char **args
)
474 void tr_mk(char **args
)
477 num_set(map(args
[1]), n_d
);
482 void tr_rt(char **args
)
484 int n
= args
[1] ? eval_re(args
[1], n_d
, 'v') : n_mk
;
485 if (n
>= 0 && n
< n_d
)
489 void tr_ne(char **args
)
491 int n
= args
[1] ? eval(args
[1], 'v') : n_v
;
494 if (!ren_traps(n_d
, n_d
+ n
- 1, 1))
498 static void ren_ejectpage(int br
)
501 bp_ejected
= bp_count
;
504 while (bp_count
== bp_ejected
&& !cdiv
) {
505 if (detect_traps(n_d
, n_p
)) {
506 ren_traps(n_d
, n_p
, 1);
514 void tr_bp(char **args
)
516 if (!cdiv
&& (args
[1] || !n_ns
)) {
518 bp_next
= eval_re(args
[1], n_pg
, 0);
519 ren_ejectpage(args
[0][0] == c_cc
);
523 void tr_pn(char **args
)
526 bp_next
= eval_re(args
[1], n_pg
, 0);
529 static void ren_ps(char *s
)
531 int ps
= !s
|| !*s
|| !strcmp("0", s
) ?
532 n_s0
* SC_PT
: eval_re(s
, n_s
* SC_PT
, 'p');
534 n_s
= MAX(1, (ps
+ SC_PT
/ 2) / SC_PT
);
537 void tr_ps(char **args
)
542 void tr_ll(char **args
)
544 int ll
= args
[1] ? eval_re(args
[1], n_l
, 'm') : n_l0
;
549 void tr_in(char **args
)
551 int in
= args
[1] ? eval_re(args
[1], n_i
, 'm') : n_i0
;
552 if (args
[0][0] == c_cc
)
559 void tr_ti(char **args
)
561 if (args
[0][0] == c_cc
)
564 n_ti
= eval_re(args
[1], n_i
, 'm');
567 void tr_l2r(char **args
)
570 if (args
[0][0] == c_cc
)
576 void tr_r2l(char **args
)
579 if (args
[0][0] == c_cc
)
585 void tr_in2(char **args
)
587 int I
= args
[1] ? eval_re(args
[1], n_I
, 'm') : n_I0
;
588 if (args
[0][0] == c_cc
)
595 void tr_ti2(char **args
)
597 if (args
[0][0] == c_cc
)
600 n_tI
= eval_re(args
[1], n_I
, 'm');
603 static void ren_ft(char *s
)
605 int fn
= !s
|| !*s
|| !strcmp("P", s
) ? n_f0
: dev_pos(s
);
607 errmsg("neatroff: failed to mount <%s>\n", s
);
614 void tr_ft(char **args
)
619 void tr_fp(char **args
)
624 pos
= isdigit((unsigned char) args
[1][0]) ? atoi(args
[1]) : -1;
625 if (dev_mnt(pos
, args
[2], args
[3] ? args
[3] : args
[2]) < 0)
626 errmsg("neatroff: failed to mount <%s>\n", args
[2]);
629 void tr_nf(char **args
)
631 if (args
[0][0] == c_cc
)
636 void tr_fi(char **args
)
638 if (args
[0][0] == c_cc
)
643 void tr_ce(char **args
)
645 if (args
[0][0] == c_cc
)
647 n_ce
= args
[1] ? atoi(args
[1]) : 1;
650 void tr_fc(char **args
)
654 if (fa
&& charread(&fa
, c_fa
) >= 0) {
655 if (!fb
|| charread(&fb
, c_fb
) < 0)
663 static void ren_cl(char *s
)
665 int m
= !s
|| !*s
? n_m0
: clr_get(s
);
670 void tr_cl(char **args
)
675 void tr_ab(char **args
)
677 fprintf(stderr
, "%s\n", args
[1]);
681 static void ren_cmd(struct wb
*wb
, int c
, char *arg
)
685 wb_hmov(wb
, font_swid(dev_font(n_f
), n_s
, n_ss
));
697 wb_vmov(wb
, SC_EM
/ 2);
703 wb_hmov(wb
, eval(arg
, 'm'));
706 wb_setcost(wb
, eval(arg
, 0));
709 num_set(map(arg
), wb
== cwb
? f_hpos() - n_lb
: wb_wid(wb
));
725 while (fmt_fillreq(cfmt
))
735 wb_vmov(wb
, -SC_EM
/ 2);
738 wb_vmov(wb
, eval(arg
, 'v'));
744 wb_els(wb
, eval(arg
, 'v'));
753 wb_hmov(wb
, SC_EM
/ 6);
759 wb_hmov(wb
, SC_EM
/ 12);
762 wb_italiccorrection(wb
);
765 wb_italiccorrectionleft(wb
);
775 static void ren_field(struct wb
*wb
, int (*next
)(void), void (*back
)(int));
776 static void ren_tab(struct wb
*wb
, char *tc
, int (*next
)(void), void (*back
)(int));
778 /* insert a character, escape sequence, field or etc into wb */
779 static void ren_put(struct wb
*wb
, char *c
, int (*next
)(void), void (*back
)(int))
782 if (c
[0] == ' ' || c
[0] == '\n') {
786 if (c
[0] == '\t' || c
[0] == '\x01') {
787 ren_tab(wb
, c
[0] == '\t' ? c_tc
: c_lc
, next
, back
);
790 if (c_fa
[0] && !strcmp(c_fa
, c
)) {
791 ren_field(wb
, next
, back
);
797 ren_char(wb
, next
, back
);
798 wb_hmov(wb
, w
- wb_wid(wb
));
801 if (strchr(" bCcDdefHhjkLlmNoprSsuvXxZz0^|!{}&/,<>", c
[1])) {
803 if (strchr(ESC_P
, c
[1]))
804 arg
= unquotednext(c
[1], next
, back
);
805 if (strchr(ESC_Q
, c
[1]))
806 arg
= quotednext(next
, back
);
808 snprintf(c
, GNLEN
, "%c%c", c_ec
, c_ec
);
809 } else if (c
[1] == 'N') {
810 snprintf(c
, GNLEN
, "GID=%s", arg
);
812 ren_cmd(wb
, c
[1], arg
);
823 if (cdef_map(c
, n_f
)) /* .char characters */
829 /* read one character and place it inside wb buffer */
830 int ren_char(struct wb
*wb
, int (*next
)(void), void (*back
)(int))
833 if (charnext(c
, next
, back
) < 0)
835 ren_put(wb
, c
, next
, back
);
839 /* like ren_char(); return 1 if d1 was read and 2 if d2 was read */
840 static int ren_chardel(struct wb
*wb
, int (*next
)(void), void (*back
)(int),
844 if (charnext(c
, next
, back
) < 0)
846 if (d1
&& !strcmp(d1
, c
))
848 if (d2
&& !strcmp(d2
, c
))
850 ren_put(wb
, c
, next
, back
);
854 /* read the argument of \w and push its width */
855 int ren_wid(int (*next
)(void), void (*back
)(int))
861 charnext(delim
, next
, back
);
864 while (c
>= 0 && c
!= '\n') {
866 if (ren_chardel(&wb
, next
, back
, delim
, NULL
))
872 wb_wconf(&wb
, &n_ct
, &n_st
, &n_sb
, &n_llx
, &n_lly
, &n_urx
, &n_ury
);
877 /* return 1 if d1 was read and 2 if d2 was read */
878 static int ren_until(struct wb
*wb
, int (*next
)(void), void (*back
)(int),
883 while (c
>= 0 && c
!= '\n') {
885 ret
= ren_chardel(wb
, next
, back
, d1
, d2
);
895 /* like ren_until(); map src to dst */
896 static int ren_untilmap(struct wb
*wb
, int (*next
)(void), void (*back
)(int),
897 char *end
, char *src
, char *dst
)
900 while ((ret
= ren_until(wb
, next
, back
, src
, end
)) == 1) {
902 ren_until(wb
, sstr_next
, sstr_back
, end
, NULL
);
908 static void wb_cpy(struct wb
*dst
, struct wb
*src
, int left
)
910 wb_hmov(dst
, left
- wb_wid(dst
));
914 void ren_tl(int (*next
)(void), void (*back
)(int))
920 pgnum
= num_str(map("%"));
923 charnext(delim
, next
, back
);
924 if (!strcmp("\n", delim
))
926 /* the left-adjusted string */
927 ren_untilmap(&wb2
, next
, back
, delim
, c_pc
, pgnum
);
928 wb_cpy(&wb
, &wb2
, 0);
929 /* the centered string */
930 ren_untilmap(&wb2
, next
, back
, delim
, c_pc
, pgnum
);
931 wb_cpy(&wb
, &wb2
, (n_lt
- wb_wid(&wb2
)) / 2);
932 /* the right-adjusted string */
933 ren_untilmap(&wb2
, next
, back
, delim
, c_pc
, pgnum
);
934 wb_cpy(&wb
, &wb2
, n_lt
- wb_wid(&wb2
));
935 /* flushing the line */
936 ren_line(wb_buf(&wb
), wb_wid(&wb
), AD_L
, 0,
937 0, 0, n_lt
, wb
.els_neg
, wb
.els_pos
);
942 static void ren_field(struct wb
*wb
, int (*next
)(void), void (*back
)(int))
944 struct wb wbs
[NFIELDS
];
947 int left
, right
, cur_left
;
949 while (n
< LEN(wbs
)) {
951 if (ren_until(&wbs
[n
++], next
, back
, c_fb
, c_fa
) != 1)
954 left
= wb
== cwb
? f_hpos() : wb_wid(wb
);
955 right
= tab_next(left
);
956 for (i
= 0; i
< n
; i
++)
957 wid
+= wb_wid(&wbs
[i
]);
958 pad
= (right
- left
- wid
) / (n
> 1 ? n
- 1 : 1);
959 rem
= (right
- left
- wid
) % (n
> 1 ? n
- 1 : 1);
960 for (i
= 0; i
< n
; i
++) {
964 cur_left
= right
- wb_wid(&wbs
[i
]);
966 cur_left
= wb_wid(wb
) + pad
+ (i
+ rem
>= n
);
967 wb_cpy(wb
, &wbs
[i
], cur_left
);
972 static void ren_tab(struct wb
*wb
, char *tc
, int (*next
)(void), void (*back
)(int))
975 int pos
= wb
== cwb
? f_hpos() : wb_wid(wb
);
976 int ins
= tab_next(pos
); /* insertion position */
977 int typ
= tab_type(pos
); /* tab type */
980 if (typ
== 'R' || typ
== 'C') {
982 while (c
>= 0 && c
!= '\n' && c
!= '\t' && c
!= '\x01') {
984 ren_char(&t
, next
, back
);
990 ins
-= wb_wid(&t
) / 2;
993 if (!tc
[0] || ins
<= pos
)
994 wb_hmov(wb
, ins
- pos
);
996 ren_hline(wb
, ins
- pos
, tc
);
1001 /* parse characters and troff requests of s and append them to wb */
1002 int ren_parse(struct wb
*wb
, char *s
)
1010 if (ren_char(wb
, sstr_next
, sstr_back
))
1019 /* cause nested render_rec() to exit */
1020 void tr_popren(char **args
)
1022 ren_level
= args
[1] ? atoi(args
[1]) : 0;
1025 #define FMT_PAR() (n_u && !n_na && !n_ce && (n_j & AD_P) == AD_P)
1027 /* read characters from tr.c and pass the rendered lines to out.c */
1028 static int render_rec(int level
)
1031 while (ren_level
>= level
) {
1032 while (!ren_un
&& !tr_nextreq())
1033 if (ren_level
< level
)
1035 if (ren_level
< level
)
1043 if (bp_final
== 0) {
1053 ren_partial
= c
!= '\n';
1054 /* add cwb (the current word) to cfmt */
1055 if (c
== ' ' || c
== '\n') {
1056 if (!wb_part(cwb
)) { /* not after a \c */
1059 while (fmt_newline(cfmt
))
1062 ren_fmtpopall(cfmt
);
1067 /* flush the line if necessary */
1068 if (c
== ' ' || c
== '\n' || c
< 0)
1070 if (c
== '\n' || ren_nl
) /* end or start of input line */
1072 if (c
== '\n' && n_it
&& --n_itn
== 0)
1074 if (c
== '\n' && !wb_part(cwb
))
1075 n_ce
= MAX(0, n_ce
- 1);
1076 if (c
!= ' ' && c
>= 0) {
1078 ren_char(cwb
, ren_next
, ren_back
);
1086 /* render input words */
1090 while (!tr_nextreq())
1092 ren_first(); /* transition to the first page */
1095 if (fmt_morewords(cfmt
))
1103 #define tposval(i) (tpos[i] < 0 ? n_p + tpos[i] : tpos[i])
1105 static int tpos
[NTRAPS
]; /* trap positions */
1106 static int treg
[NTRAPS
]; /* trap registers */
1109 static int trap_first(int pos
)
1113 for (i
= 0; i
< ntraps
; i
++)
1114 if (treg
[i
] >= 0 && tposval(i
) > pos
)
1115 if (best
< 0 || tposval(i
) < tposval(best
))
1120 static int trap_byreg(int reg
)
1123 for (i
= 0; i
< ntraps
; i
++)
1129 static int trap_bypos(int reg
, int pos
)
1132 for (i
= 0; i
< ntraps
; i
++)
1133 if (treg
[i
] >= 0 && tposval(i
) == pos
)
1134 if (reg
== -1 || treg
[i
] == reg
)
1139 void tr_wh(char **args
)
1144 pos
= eval(args
[1], 'v');
1145 id
= trap_bypos(-1, pos
);
1152 if (id
< 0) /* find an unused position in treg[] */
1153 id
= trap_byreg(-1);
1160 void tr_ch(char **args
)
1167 id
= trap_byreg(reg
);
1170 tpos
[id
] = eval(args
[2], 'v');
1176 void tr_dt(char **args
)
1181 cdiv
->tpos
= eval(args
[1], 'v');
1182 cdiv
->treg
= map(args
[2]);
1188 void tr_em(char **args
)
1190 trap_em
= args
[1] ? map(args
[1]) : -1;
1193 static int trap_pos(int pos
)
1195 int ret
= trap_first(pos
);
1199 return cdiv
->treg
&& cdiv
->tpos
> pos
? cdiv
->tpos
: -1;
1200 return ret
>= 0 ? tposval(ret
) : -1;
1203 static int trap_reg(int pos
)
1205 int ret
= trap_first(pos
);
1207 return cdiv
->treg
&& cdiv
->tpos
> pos
? cdiv
->treg
: -1;
1208 return ret
>= 0 ? treg
[ret
] : -1;
1211 int f_nexttrap(void)
1213 int pos
= trap_pos(n_d
);
1215 return pos
>= 0 ? pos
: 0x7fffffff;
1216 return (pos
>= 0 && pos
< n_p
? pos
: n_p
) - n_d
;