ren: add .ls and \n(.L
[neatroff.git] / xroff.h
blobc8fe2e180ed040cb0e42d943b5828009ff959048
1 /* converting scales */
2 #define SC_IN (dev_res) /* inch in units */
3 #define SC_PT (SC_IN / 72) /* point in units */
5 /* predefined array limits */
6 #define PATHLEN 1024 /* path length */
7 #define NFILES 16 /* number of input files */
8 #define NFONTS 32 /* number of fonts */
9 #define FNLEN 32 /* font name length */
10 #define NGLYPHS 512 /* glyphs in fonts */
11 #define GNLEN 32 /* glyph name length */
12 #define ILNLEN 256 /* line limit of input files */
13 #define LNLEN 4000 /* line buffer length (ren.c/out.c) */
14 #define NWORDS 1000 /* number of words in line buffer */
15 #define NARGS 9 /* number of macro arguments */
16 #define RLEN 4 /* register/macro name */
17 #define NPREV 16 /* environment stack depth */
18 #define NTRAPS 1024 /* number of traps per page */
19 #define NIES 128 /* number of nested .ie commands */
21 /* escape sequences */
22 #define ESC_Q "bCDhHlLNoSvwxX" /* quoted escape sequences */
23 #define ESC_P "*fgkns" /* 1 or 2-char escape sequences */
25 #define LEN(a) (sizeof(a) / sizeof((a)[0]))
27 /* number registers */
28 int num_get(int id, int inc);
29 void num_set(int id, int val);
30 void num_inc(int id, int val);
31 void num_del(int id);
32 char *num_str(int id);
33 int *nreg(int id);
34 int eval(char *s, int orig, int unit);
36 /* string registers */
37 void str_set(int id, char *s);
38 void str_dset(int id, void *d);
39 char *str_get(int id);
40 void *str_dget(int id);
41 void str_rm(int id);
42 void str_rn(int src, int dst);
44 /* saving and restoring registers before and after printing diverted lines */
45 void odiv_beg(void);
46 void odiv_end(void);
48 /* enviroments */
49 void env_init(void);
50 void env_free(void);
51 struct adj *env_adj(void);
53 /* device related variables */
54 extern int dev_res;
55 extern int dev_uwid;
56 extern int dev_hor;
57 extern int dev_ver;
59 struct glyph {
60 char name[FNLEN]; /* name of the glyph */
61 char id[FNLEN]; /* device-dependent glyph identifier */
62 struct font *font; /* glyph font */
63 int wid; /* character width */
64 int type; /* character type; ascender/descender */
67 struct font {
68 char name[FNLEN];
69 struct glyph glyphs[NGLYPHS];
70 int nglyphs;
71 int spacewid;
72 int special;
73 char c[NGLYPHS][FNLEN]; /* character names in charset */
74 struct glyph *g[NGLYPHS]; /* character glyphs in charset */
75 int n; /* number of characters in charset */
78 /* troff output function */
79 #define OUT printf
81 /* output device functions */
82 int dev_open(char *path);
83 void dev_close(void);
84 int dev_mnt(int pos, char *id, char *name);
85 int dev_font(char *id);
86 int charwid(int wid, int sz);
88 /* font-related functions */
89 struct font *font_open(char *path);
90 void font_close(struct font *fn);
91 struct glyph *font_glyph(struct font *fn, char *id);
92 struct glyph *font_find(struct font *fn, char *name);
94 /* glyph handling functions */
95 struct glyph *dev_glyph(char *c, int fn);
96 struct glyph *dev_glyph_byid(char *id, int fn);
97 int dev_spacewid(void);
99 /* different layers of neatroff */
100 int in_next(void); /* input layer */
101 int cp_next(void); /* copy-mode layer */
102 int tr_next(void); /* troff layer */
103 void in_push(char *s, char **args);
104 void in_source(char *path); /* .so request */
105 void in_queue(char *path); /* next input file */
106 char *in_arg(int i); /* look up argument */
107 void in_back(int c); /* push back input character */
108 char *in_filename(void); /* current filename */
109 void cp_back(int c); /* push back copy-mode character */
110 void cp_skip(void); /* skip current input line or block */
112 /* rendering */
113 void render(void); /* read from in.c and print the output */
114 void output(char *s); /* output the given rendered line */
115 int out_draw(char *s, char *cc);
117 /* troff commands */
118 void tr_bp(char **args);
119 void tr_br(char **args);
120 void tr_ch(char **args);
121 void tr_di(char **args);
122 void tr_divbeg(char **args);
123 void tr_divend(char **args);
124 void tr_dt(char **args);
125 void tr_ev(char **args);
126 void tr_fi(char **args);
127 void tr_fp(char **args);
128 void tr_ft(char **args);
129 void tr_in(char **args);
130 void tr_ll(char **args);
131 void tr_mk(char **args);
132 void tr_ne(char **args);
133 void tr_nf(char **args);
134 void tr_ns(char **args);
135 void tr_os(char **args);
136 void tr_pn(char **args);
137 void tr_ps(char **args);
138 void tr_rs(char **args);
139 void tr_rt(char **args);
140 void tr_sp(char **args);
141 void tr_sv(char **args);
142 void tr_ti(char **args);
143 void tr_wh(char **args);
145 void tr_init(void);
147 /* helpers */
148 void errmsg(char *msg, ...);
149 int utf8len(int c);
151 /* variable length string buffer */
152 struct sbuf {
153 char *s;
154 int sz;
155 int n;
158 void sbuf_init(struct sbuf *sbuf);
159 void sbuf_done(struct sbuf *sbuf);
160 char *sbuf_buf(struct sbuf *sbuf);
161 void sbuf_add(struct sbuf *sbuf, int c);
162 void sbuf_append(struct sbuf *sbuf, char *s);
163 void sbuf_putnl(struct sbuf *sbuf);
164 int sbuf_empty(struct sbuf *sbuf);
166 /* diversions */
167 #define DIV_BEG ".&<"
168 #define DIV_END ".&>"
170 /* adjustment */
171 #define AD_L 0
172 #define AD_B 1
173 #define AD_C 3
174 #define AD_R 5
176 struct adj *adj_alloc(void);
177 void adj_free(struct adj *adj);
178 int adj_fill(struct adj *adj, int ad_b, int fill, char *dst,
179 int *ll, int *in, int *ti, int *els_neg, int *els_pos);
180 void adj_put(struct adj *adj, int wid, char *s, ...);
181 void adj_swid(struct adj *adj, int swid);
182 int adj_full(struct adj *adj, int fill);
183 int adj_empty(struct adj *adj, int fill);
184 int adj_wid(struct adj *adj);
185 void adj_ll(struct adj *adj, int ll);
186 void adj_in(struct adj *adj, int in);
187 void adj_ti(struct adj *adj, int ti);
188 void adj_els(struct adj *adj, int els);
189 void adj_conf(struct adj *adj, int *ll, int *in, int *ti);
191 /* builtin number registers; n_X for .X register */
192 #define REG(c1, c2) ((c1) * 256 + (c2))
193 #define n_a (*nreg(REG('.', 'a')))
194 #define n_d (*nreg(REG('.', 'd')))
195 #define n_f (*nreg(REG('.', 'f')))
196 #define n_h (*nreg(REG('.', 'h')))
197 #define n_i (*nreg(REG('.', 'i')))
198 #define n_j (*nreg(REG('.', 'j')))
199 #define n_l (*nreg(REG('.', 'l')))
200 #define n_L (*nreg(REG('.', 'L')))
201 #define n_n (*nreg(REG('.', 'n')))
202 #define n_o (*nreg(REG('.', 'o')))
203 #define n_p (*nreg(REG('.', 'p')))
204 #define n_s (*nreg(REG('.', 's')))
205 #define n_u (*nreg(REG('.', 'u')))
206 #define n_v (*nreg(REG('.', 'v')))
207 #define n_ct (*nreg(REG('c', 't')))
208 #define n_dl (*nreg(REG('d', 'l')))
209 #define n_dn (*nreg(REG('d', 'n')))
210 #define n_nl (*nreg(REG('n', 'l')))
211 #define n_pg (*nreg(REG('%', '\0'))) /* % */
212 #define n_lb (*nreg(REG(0, 'b'))) /* input line beg */
213 #define n_f0 (*nreg(REG(0, 'f'))) /* last .f */
214 #define n_i0 (*nreg(REG(0, 'i'))) /* last .i */
215 #define n_l0 (*nreg(REG(0, 'l'))) /* last .l */
216 #define n_L0 (*nreg(REG(0, 'L'))) /* last .L */
217 #define n_mk (*nreg(REG(0, 'm'))) /* .mk internal register */
218 #define n_na (*nreg(REG(0, 'n'))) /* .na mode */
219 #define n_ns (*nreg(REG(0, 'N'))) /* .ns mode */
220 #define n_o0 (*nreg(REG(0, 'o'))) /* last .o */
221 #define n_s0 (*nreg(REG(0, 's'))) /* last .s */
222 #define n_sv (*nreg(REG(0, 'S'))) /* .sv value */
223 #define n_v0 (*nreg(REG(0, 'v'))) /* last .v */
225 /* functions for implementing read-only registers */
226 int f_nexttrap(void); /* .t */
227 int f_divreg(void); /* .z */
228 int f_hpos(void); /* .k */