1 /* helper for drawing commands in ren.c */
7 static int cwid(char *c
)
18 static int hchar(char *c
)
21 return c
[1] == '_' || c
[1] == '-';
24 return (c
[0] == 'r' && c
[1] == 'u') || (c
[0] == 'u' && c
[1] == 'l') ||
25 (c
[0] == 'r' && c
[1] == 'n');
28 static int vchar(char *c
)
32 return (c
[0] == 'b' && c
[1] == 'v') || (c
[0] == 'b' && c
[1] == 'r');
35 void ren_hline(struct wb
*wb
, int l
, char *c
)
39 /* negative length; moving backwards */
46 /* length less than character width */
50 wb_hmov(wb
, -(w
- l
) / 2);
61 for (i
= 0; i
< n
; i
++)
65 wb_hmov(wb
, -(w
- l
+ 1) / 2);
68 static void ren_vline(struct wb
*wb
, int l
, char *c
)
70 int w
, n
, i
, rem
, hw
, neg
;
72 w
= SC_EM
; /* character height */
73 hw
= cwid(c
); /* character width */
74 /* negative length; moving backwards */
81 /* length less than character width */
85 wb_vmov(wb
, -w
+ l
/ 2);
98 for (i
= 0; i
< n
; i
++) {
111 void ren_hlcmd(struct wb
*wb
, char *arg
)
114 int l
= eval_up(&arg
, 'm');
115 if (arg
[0] == c_ec
&& arg
[1] == '&') /* \& can be used as a separator */
117 if (!*arg
|| charread(&arg
, lc
) < 0)
120 ren_hline(wb
, l
, lc
);
123 void ren_vlcmd(struct wb
*wb
, char *arg
)
126 int l
= eval_up(&arg
, 'v');
127 if (arg
[0] == c_ec
&& arg
[1] == '&') /* \& can be used as a separator */
129 if (!*arg
|| charread(&arg
, lc
) < 0)
132 ren_vline(wb
, l
, lc
);
135 static int tok_num(char **s
, int scale
)
141 while (**s
&& !isspace(**s
))
144 return eval(tok
, scale
);
147 void ren_dcmd(struct wb
*wb
, char *s
)
151 switch (tolower(c
)) {
153 h1
= tok_num(&s
, 'm');
154 v1
= tok_num(&s
, 'v');
155 wb_drawl(wb
, c
, h1
, v1
);
158 h1
= tok_num(&s
, 'm');
162 h1
= tok_num(&s
, 'm');
163 v1
= tok_num(&s
, 'v');
164 wb_drawe(wb
, c
, h1
, v1
);
167 h1
= tok_num(&s
, 'm');
168 v1
= tok_num(&s
, 'v');
169 h2
= tok_num(&s
, 'm');
170 v2
= tok_num(&s
, 'v');
171 wb_drawa(wb
, c
, h1
, v1
, h2
, v2
);
177 h1
= tok_num(&s
, 'm');
178 v1
= tok_num(&s
, 'v');
179 wb_drawxdot(wb
, h1
, v1
);
186 void ren_bcmd(struct wb
*wb
, char *arg
)
191 sstr_push(arg
); /* using ren_char()'s interface */
196 ren_char(&wb2
, sstr_next
, sstr_back
);
197 if (wb_wid(&wb2
) > w
)
199 wb_hmov(&wb2
, -wb_wid(&wb2
));
200 wb_vmov(&wb2
, SC_EM
);
205 center
= -(n
* SC_EM
+ SC_EM
) / 2;
206 wb_vmov(wb
, center
+ SC_EM
);
213 void ren_ocmd(struct wb
*wb
, char *arg
)
218 sstr_push(arg
); /* using ren_char()'s interface */
224 ren_char(&wb3
, sstr_next
, sstr_back
);
228 wb_hmov(&wb2
, -wc
/ 2);
230 wb_hmov(&wb2
, -wc
/ 2);
241 void ren_zcmd(struct wb
*wb
, char *arg
)
248 while ((c
= sstr_next()) >= 0) {
250 ren_char(wb
, sstr_next
, sstr_back
);
253 wb_hmov(wb
, h
- wb_hpos(wb
));
254 wb_vmov(wb
, v
- wb_vpos(wb
));