1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate *
4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate * with the License.
8*7c478bd9Sstevel@tonic-gate *
9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate *
14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate *
20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate */
26*7c478bd9Sstevel@tonic-gate
27*7c478bd9Sstevel@tonic-gate /*
28*7c478bd9Sstevel@tonic-gate * In this mode, we generate forthdebug macros as requested by the input
29*7c478bd9Sstevel@tonic-gate * template, the format of which is given below.
30*7c478bd9Sstevel@tonic-gate *
31*7c478bd9Sstevel@tonic-gate * These templates have the following elements:
32*7c478bd9Sstevel@tonic-gate *
33*7c478bd9Sstevel@tonic-gate * 1. Macro creation
34*7c478bd9Sstevel@tonic-gate *
35*7c478bd9Sstevel@tonic-gate * Given the name of a structure, union, or enum type, a forthdebug macro
36*7c478bd9Sstevel@tonic-gate * is created that will dump the members of the type. The type can be
37*7c478bd9Sstevel@tonic-gate * specified as a standalone structure, union, or enum, or it can be
38*7c478bd9Sstevel@tonic-gate * described relative to another structure or union as "type.member".
39*7c478bd9Sstevel@tonic-gate *
40*7c478bd9Sstevel@tonic-gate * By default, all struct members, union members, or enum values, as
41*7c478bd9Sstevel@tonic-gate * appropriate, will be printed. An alternate form allows specific members
42*7c478bd9Sstevel@tonic-gate * of struct or union types to be printed. Both forms must be followed by a
43*7c478bd9Sstevel@tonic-gate * blank line. In the specific-member case, an optional format specifier can
44*7c478bd9Sstevel@tonic-gate * be provided that will be used to dump the contents of the member.
45*7c478bd9Sstevel@tonic-gate * Builtins `d' and `x' can be used to dump the member in decimal or
46*7c478bd9Sstevel@tonic-gate * hexadecimal, respectively. Alternatively, a custom formatter can be
47*7c478bd9Sstevel@tonic-gate * specified.
48*7c478bd9Sstevel@tonic-gate *
49*7c478bd9Sstevel@tonic-gate * 2. Model-specific sections
50*7c478bd9Sstevel@tonic-gate *
51*7c478bd9Sstevel@tonic-gate * `model_start' / `model_end' pairs function as an #ifdef for the ctfstabs
52*7c478bd9Sstevel@tonic-gate * tool. They take, as an argument, either `ilp32' or `lp64'. If a 64-bit
53*7c478bd9Sstevel@tonic-gate * macro is being generated (if a 64-bit object file is being used), lines
54*7c478bd9Sstevel@tonic-gate * between `lp64' model pairs will be processed, but lines between `ilp32'
55*7c478bd9Sstevel@tonic-gate * pairs will be omitted. The reverse is true for 32-bit macros.
56*7c478bd9Sstevel@tonic-gate *
57*7c478bd9Sstevel@tonic-gate * 3. Literal sections
58*7c478bd9Sstevel@tonic-gate *
59*7c478bd9Sstevel@tonic-gate * Portions of the input template file enclosed within `forth_start' /
60*7c478bd9Sstevel@tonic-gate * `forth_end' pairs and between `verbatim_begin' / `verbatim_end' pairs
61*7c478bd9Sstevel@tonic-gate * will be copied as-is to the output file.
62*7c478bd9Sstevel@tonic-gate *
63*7c478bd9Sstevel@tonic-gate * 4. Comments
64*7c478bd9Sstevel@tonic-gate *
65*7c478bd9Sstevel@tonic-gate * Lines beginning with backslashes are ignored.
66*7c478bd9Sstevel@tonic-gate *
67*7c478bd9Sstevel@tonic-gate * Example:
68*7c478bd9Sstevel@tonic-gate *
69*7c478bd9Sstevel@tonic-gate * \ dump the `foo' structure
70*7c478bd9Sstevel@tonic-gate * foo
71*7c478bd9Sstevel@tonic-gate *
72*7c478bd9Sstevel@tonic-gate * \ dump the `a' and `b' members of the `bar' structure. dump member `b'
73*7c478bd9Sstevel@tonic-gate * \ in hexadecimal
74*7c478bd9Sstevel@tonic-gate * bar
75*7c478bd9Sstevel@tonic-gate * a
76*7c478bd9Sstevel@tonic-gate * b x
77*7c478bd9Sstevel@tonic-gate *
78*7c478bd9Sstevel@tonic-gate * \ dump the `big' member of the `baz' structure in 64-bit macros, and
79*7c478bd9Sstevel@tonic-gate * \ the `small' member in 32-bit macros.
80*7c478bd9Sstevel@tonic-gate * baz
81*7c478bd9Sstevel@tonic-gate * model_start lp64
82*7c478bd9Sstevel@tonic-gate * big
83*7c478bd9Sstevel@tonic-gate * model_end
84*7c478bd9Sstevel@tonic-gate * model_start ilp32
85*7c478bd9Sstevel@tonic-gate * small
86*7c478bd9Sstevel@tonic-gate * model_end
87*7c478bd9Sstevel@tonic-gate *
88*7c478bd9Sstevel@tonic-gate * \ copy `literal 1' and `literal 2' to the output file
89*7c478bd9Sstevel@tonic-gate * verbatim_begin
90*7c478bd9Sstevel@tonic-gate * literal 1
91*7c478bd9Sstevel@tonic-gate * verbatim_end
92*7c478bd9Sstevel@tonic-gate * forth_start
93*7c478bd9Sstevel@tonic-gate * literal 2
94*7c478bd9Sstevel@tonic-gate * forth_end
95*7c478bd9Sstevel@tonic-gate *
96*7c478bd9Sstevel@tonic-gate * For a more complex example, see common.fdbg.
97*7c478bd9Sstevel@tonic-gate */
98*7c478bd9Sstevel@tonic-gate
99*7c478bd9Sstevel@tonic-gate #include <stdio.h>
100*7c478bd9Sstevel@tonic-gate #include <stdlib.h>
101*7c478bd9Sstevel@tonic-gate #include <string.h>
102*7c478bd9Sstevel@tonic-gate #include <ctype.h>
103*7c478bd9Sstevel@tonic-gate
104*7c478bd9Sstevel@tonic-gate #include "ctf_headers.h"
105*7c478bd9Sstevel@tonic-gate #include "ctfstabs.h"
106*7c478bd9Sstevel@tonic-gate #include "forth.h"
107*7c478bd9Sstevel@tonic-gate #include "utils.h"
108*7c478bd9Sstevel@tonic-gate #include "memory.h"
109*7c478bd9Sstevel@tonic-gate
110*7c478bd9Sstevel@tonic-gate char *fth_curtype; /* name of the type being processed */
111*7c478bd9Sstevel@tonic-gate static fth_type_ops_t *fth_type_ops; /* see forth.h */
112*7c478bd9Sstevel@tonic-gate
113*7c478bd9Sstevel@tonic-gate static char *fth_model; /* the current macro type - for model_start */
114*7c478bd9Sstevel@tonic-gate static int fth_ignoring; /* in a non-matching model_start/end pair */
115*7c478bd9Sstevel@tonic-gate static int fth_copying; /* in a verbatim_* or forth_* pair */
116*7c478bd9Sstevel@tonic-gate
117*7c478bd9Sstevel@tonic-gate static int
fth_init(char * model)118*7c478bd9Sstevel@tonic-gate fth_init(char *model)
119*7c478bd9Sstevel@tonic-gate {
120*7c478bd9Sstevel@tonic-gate fth_model = model;
121*7c478bd9Sstevel@tonic-gate
122*7c478bd9Sstevel@tonic-gate return (0);
123*7c478bd9Sstevel@tonic-gate }
124*7c478bd9Sstevel@tonic-gate
125*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/
126*7c478bd9Sstevel@tonic-gate static int
fth_null_header(ctf_id_t tid)127*7c478bd9Sstevel@tonic-gate fth_null_header(ctf_id_t tid)
128*7c478bd9Sstevel@tonic-gate {
129*7c478bd9Sstevel@tonic-gate return (0);
130*7c478bd9Sstevel@tonic-gate }
131*7c478bd9Sstevel@tonic-gate
132*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/
133*7c478bd9Sstevel@tonic-gate static int
fth_null_members(char * memfilter,char * format)134*7c478bd9Sstevel@tonic-gate fth_null_members(char *memfilter, char *format)
135*7c478bd9Sstevel@tonic-gate {
136*7c478bd9Sstevel@tonic-gate return (0);
137*7c478bd9Sstevel@tonic-gate }
138*7c478bd9Sstevel@tonic-gate
139*7c478bd9Sstevel@tonic-gate static int
fth_null_trailer(void)140*7c478bd9Sstevel@tonic-gate fth_null_trailer(void)
141*7c478bd9Sstevel@tonic-gate {
142*7c478bd9Sstevel@tonic-gate return (0);
143*7c478bd9Sstevel@tonic-gate }
144*7c478bd9Sstevel@tonic-gate
145*7c478bd9Sstevel@tonic-gate static fth_type_ops_t fth_null_ops = {
146*7c478bd9Sstevel@tonic-gate fth_null_header,
147*7c478bd9Sstevel@tonic-gate fth_null_members,
148*7c478bd9Sstevel@tonic-gate fth_null_trailer
149*7c478bd9Sstevel@tonic-gate };
150*7c478bd9Sstevel@tonic-gate
151*7c478bd9Sstevel@tonic-gate /*ARGSUSED2*/
152*7c478bd9Sstevel@tonic-gate static int
find_member_cb(const char * memname,ctf_id_t tid,ulong_t off,void * arg)153*7c478bd9Sstevel@tonic-gate find_member_cb(const char *memname, ctf_id_t tid, ulong_t off, void *arg)
154*7c478bd9Sstevel@tonic-gate {
155*7c478bd9Sstevel@tonic-gate char *memtofind = arg;
156*7c478bd9Sstevel@tonic-gate
157*7c478bd9Sstevel@tonic-gate if (strcmp(memname, memtofind) == 0)
158*7c478bd9Sstevel@tonic-gate return (tid);
159*7c478bd9Sstevel@tonic-gate
160*7c478bd9Sstevel@tonic-gate return (0);
161*7c478bd9Sstevel@tonic-gate }
162*7c478bd9Sstevel@tonic-gate
163*7c478bd9Sstevel@tonic-gate /* find the tid of a specified member */
164*7c478bd9Sstevel@tonic-gate static ctf_id_t
find_member(ctf_id_t tid,char * memname)165*7c478bd9Sstevel@tonic-gate find_member(ctf_id_t tid, char *memname)
166*7c478bd9Sstevel@tonic-gate {
167*7c478bd9Sstevel@tonic-gate return (ctf_member_iter(ctf, tid, find_member_cb, memname));
168*7c478bd9Sstevel@tonic-gate }
169*7c478bd9Sstevel@tonic-gate
170*7c478bd9Sstevel@tonic-gate /*
171*7c478bd9Sstevel@tonic-gate * Begin a macro.
172*7c478bd9Sstevel@tonic-gate *
173*7c478bd9Sstevel@tonic-gate * Once we figure out the type of the thing that we're supposed to dump (struct,
174*7c478bd9Sstevel@tonic-gate * union, or enum), we select the proper type-specific ops-vector for dumping.
175*7c478bd9Sstevel@tonic-gate */
176*7c478bd9Sstevel@tonic-gate static int
fth_section_init(char * fullname)177*7c478bd9Sstevel@tonic-gate fth_section_init(char *fullname)
178*7c478bd9Sstevel@tonic-gate {
179*7c478bd9Sstevel@tonic-gate ctf_id_t ltid = 0, tid;
180*7c478bd9Sstevel@tonic-gate char *curtype, *lpart, *part, *npart;
181*7c478bd9Sstevel@tonic-gate int lkind = 0, kind;
182*7c478bd9Sstevel@tonic-gate
183*7c478bd9Sstevel@tonic-gate curtype = xstrdup(fullname);
184*7c478bd9Sstevel@tonic-gate lpart = NULL;
185*7c478bd9Sstevel@tonic-gate part = strtok(fullname, ".");
186*7c478bd9Sstevel@tonic-gate
187*7c478bd9Sstevel@tonic-gate /*
188*7c478bd9Sstevel@tonic-gate * First figure out what sort of type we're looking at. Life would be
189*7c478bd9Sstevel@tonic-gate * simple if we were only going to get type names, but it's not - we
190*7c478bd9Sstevel@tonic-gate * could also get `type.member'. In that case, we need to figure out
191*7c478bd9Sstevel@tonic-gate * (and dump) the type of `member' instead.
192*7c478bd9Sstevel@tonic-gate */
193*7c478bd9Sstevel@tonic-gate for (;;) {
194*7c478bd9Sstevel@tonic-gate if (lpart == NULL) {
195*7c478bd9Sstevel@tonic-gate /* First part - the struct name */
196*7c478bd9Sstevel@tonic-gate if ((tid = find_type(part)) == CTF_ERR ||
197*7c478bd9Sstevel@tonic-gate (tid = ctf_type_resolve(ctf, tid)) == CTF_ERR ||
198*7c478bd9Sstevel@tonic-gate (kind = ctf_type_kind(ctf, tid)) == CTF_ERR) {
199*7c478bd9Sstevel@tonic-gate free(curtype);
200*7c478bd9Sstevel@tonic-gate return (parse_warn("Couldn't find %s: %s",
201*7c478bd9Sstevel@tonic-gate part, ctf_errmsg(ctf_errno(ctf))));
202*7c478bd9Sstevel@tonic-gate }
203*7c478bd9Sstevel@tonic-gate } else {
204*7c478bd9Sstevel@tonic-gate /* Second (or more) part - the member name */
205*7c478bd9Sstevel@tonic-gate if (lkind != CTF_K_STRUCT && lkind != CTF_K_UNION) {
206*7c478bd9Sstevel@tonic-gate free(curtype);
207*7c478bd9Sstevel@tonic-gate return (parse_warn("%s isn't a struct/union",
208*7c478bd9Sstevel@tonic-gate lpart));
209*7c478bd9Sstevel@tonic-gate }
210*7c478bd9Sstevel@tonic-gate
211*7c478bd9Sstevel@tonic-gate if ((tid = find_member(ltid, part)) <= 0) {
212*7c478bd9Sstevel@tonic-gate free(curtype);
213*7c478bd9Sstevel@tonic-gate return (parse_warn("%s isn't a member of %s",
214*7c478bd9Sstevel@tonic-gate part, lpart));
215*7c478bd9Sstevel@tonic-gate }
216*7c478bd9Sstevel@tonic-gate
217*7c478bd9Sstevel@tonic-gate if ((kind = ctf_type_kind(ctf, tid)) == CTF_ERR) {
218*7c478bd9Sstevel@tonic-gate free(curtype);
219*7c478bd9Sstevel@tonic-gate return (parse_warn("Can't get kind for %s",
220*7c478bd9Sstevel@tonic-gate part));
221*7c478bd9Sstevel@tonic-gate }
222*7c478bd9Sstevel@tonic-gate }
223*7c478bd9Sstevel@tonic-gate
224*7c478bd9Sstevel@tonic-gate /*
225*7c478bd9Sstevel@tonic-gate * Stop if there aren't any more parts. We use `npart' here
226*7c478bd9Sstevel@tonic-gate * because we don't want to clobber part - we need it later.
227*7c478bd9Sstevel@tonic-gate */
228*7c478bd9Sstevel@tonic-gate if ((npart = strtok(NULL, ".")) == NULL)
229*7c478bd9Sstevel@tonic-gate break;
230*7c478bd9Sstevel@tonic-gate
231*7c478bd9Sstevel@tonic-gate lpart = part;
232*7c478bd9Sstevel@tonic-gate ltid = tid;
233*7c478bd9Sstevel@tonic-gate lkind = kind;
234*7c478bd9Sstevel@tonic-gate
235*7c478bd9Sstevel@tonic-gate part = npart;
236*7c478bd9Sstevel@tonic-gate }
237*7c478bd9Sstevel@tonic-gate
238*7c478bd9Sstevel@tonic-gate /*
239*7c478bd9Sstevel@tonic-gate * Pick the right ops vector for dumping.
240*7c478bd9Sstevel@tonic-gate */
241*7c478bd9Sstevel@tonic-gate switch (kind) {
242*7c478bd9Sstevel@tonic-gate case CTF_K_STRUCT:
243*7c478bd9Sstevel@tonic-gate case CTF_K_UNION:
244*7c478bd9Sstevel@tonic-gate fth_type_ops = &fth_struct_ops;
245*7c478bd9Sstevel@tonic-gate break;
246*7c478bd9Sstevel@tonic-gate
247*7c478bd9Sstevel@tonic-gate case CTF_K_ENUM:
248*7c478bd9Sstevel@tonic-gate fth_type_ops = &fth_enum_ops;
249*7c478bd9Sstevel@tonic-gate break;
250*7c478bd9Sstevel@tonic-gate
251*7c478bd9Sstevel@tonic-gate default:
252*7c478bd9Sstevel@tonic-gate fth_type_ops = &fth_null_ops;
253*7c478bd9Sstevel@tonic-gate free(curtype);
254*7c478bd9Sstevel@tonic-gate return (parse_warn("%s isn't a struct, union, or enum", part));
255*7c478bd9Sstevel@tonic-gate }
256*7c478bd9Sstevel@tonic-gate
257*7c478bd9Sstevel@tonic-gate fth_curtype = curtype;
258*7c478bd9Sstevel@tonic-gate
259*7c478bd9Sstevel@tonic-gate return (fth_type_ops->fto_header(tid));
260*7c478bd9Sstevel@tonic-gate }
261*7c478bd9Sstevel@tonic-gate
262*7c478bd9Sstevel@tonic-gate static int
fth_section_add_member(char * name,char * format)263*7c478bd9Sstevel@tonic-gate fth_section_add_member(char *name, char *format)
264*7c478bd9Sstevel@tonic-gate {
265*7c478bd9Sstevel@tonic-gate if (fth_curtype == NULL)
266*7c478bd9Sstevel@tonic-gate return (fth_section_init(name));
267*7c478bd9Sstevel@tonic-gate
268*7c478bd9Sstevel@tonic-gate if (fth_type_ops->fto_members(name, format) < 0)
269*7c478bd9Sstevel@tonic-gate return (-1);
270*7c478bd9Sstevel@tonic-gate
271*7c478bd9Sstevel@tonic-gate return (0);
272*7c478bd9Sstevel@tonic-gate }
273*7c478bd9Sstevel@tonic-gate
274*7c478bd9Sstevel@tonic-gate static int
fth_section_end(void)275*7c478bd9Sstevel@tonic-gate fth_section_end(void)
276*7c478bd9Sstevel@tonic-gate {
277*7c478bd9Sstevel@tonic-gate if (fth_curtype == NULL)
278*7c478bd9Sstevel@tonic-gate return (0);
279*7c478bd9Sstevel@tonic-gate
280*7c478bd9Sstevel@tonic-gate if (fth_type_ops->fto_trailer() < 0)
281*7c478bd9Sstevel@tonic-gate return (-1);
282*7c478bd9Sstevel@tonic-gate
283*7c478bd9Sstevel@tonic-gate free(fth_curtype);
284*7c478bd9Sstevel@tonic-gate fth_curtype = NULL;
285*7c478bd9Sstevel@tonic-gate
286*7c478bd9Sstevel@tonic-gate return (0);
287*7c478bd9Sstevel@tonic-gate }
288*7c478bd9Sstevel@tonic-gate
289*7c478bd9Sstevel@tonic-gate static int
fth_process_line(char * line)290*7c478bd9Sstevel@tonic-gate fth_process_line(char *line)
291*7c478bd9Sstevel@tonic-gate {
292*7c478bd9Sstevel@tonic-gate char *format = NULL;
293*7c478bd9Sstevel@tonic-gate char *word, *name, *c;
294*7c478bd9Sstevel@tonic-gate int nblank = 0;
295*7c478bd9Sstevel@tonic-gate int n;
296*7c478bd9Sstevel@tonic-gate
297*7c478bd9Sstevel@tonic-gate if (strlen(line) == 0) {
298*7c478bd9Sstevel@tonic-gate if (fth_section_end() < 0)
299*7c478bd9Sstevel@tonic-gate return (-1);
300*7c478bd9Sstevel@tonic-gate
301*7c478bd9Sstevel@tonic-gate if (fth_copying == 1 || nblank++ == 1)
302*7c478bd9Sstevel@tonic-gate (void) fprintf(out, "\n");
303*7c478bd9Sstevel@tonic-gate return (0);
304*7c478bd9Sstevel@tonic-gate } else
305*7c478bd9Sstevel@tonic-gate nblank = 0;
306*7c478bd9Sstevel@tonic-gate
307*7c478bd9Sstevel@tonic-gate /* skip comments */
308*7c478bd9Sstevel@tonic-gate if (line[0] == '\\')
309*7c478bd9Sstevel@tonic-gate return (0);
310*7c478bd9Sstevel@tonic-gate
311*7c478bd9Sstevel@tonic-gate if (strcmp(line, "model_end") == 0) {
312*7c478bd9Sstevel@tonic-gate fth_ignoring = 0;
313*7c478bd9Sstevel@tonic-gate return (0);
314*7c478bd9Sstevel@tonic-gate }
315*7c478bd9Sstevel@tonic-gate
316*7c478bd9Sstevel@tonic-gate if (fth_ignoring == 1)
317*7c478bd9Sstevel@tonic-gate return (0);
318*7c478bd9Sstevel@tonic-gate
319*7c478bd9Sstevel@tonic-gate word = "model_start ";
320*7c478bd9Sstevel@tonic-gate if (strncmp(line, word, strlen(word)) == 0) {
321*7c478bd9Sstevel@tonic-gate for (c = line + strlen(word); isspace(*c); c++);
322*7c478bd9Sstevel@tonic-gate if (strlen(c) == strlen(fth_model) &&
323*7c478bd9Sstevel@tonic-gate strncmp(c, fth_model, strlen(fth_model)) == 0)
324*7c478bd9Sstevel@tonic-gate /* EMPTY - match */;
325*7c478bd9Sstevel@tonic-gate else
326*7c478bd9Sstevel@tonic-gate fth_ignoring = 1;
327*7c478bd9Sstevel@tonic-gate return (0);
328*7c478bd9Sstevel@tonic-gate }
329*7c478bd9Sstevel@tonic-gate
330*7c478bd9Sstevel@tonic-gate if (strcmp(line, "verbatim_end") == 0 ||
331*7c478bd9Sstevel@tonic-gate strcmp(line, "forth_end") == 0) {
332*7c478bd9Sstevel@tonic-gate char *start = (strcmp(line, "verbatim_end") == 0 ?
333*7c478bd9Sstevel@tonic-gate "verbatim_begin" : "forth_start");
334*7c478bd9Sstevel@tonic-gate
335*7c478bd9Sstevel@tonic-gate if (fth_copying == 0) {
336*7c478bd9Sstevel@tonic-gate (void) parse_warn("Found %s without matching %s",
337*7c478bd9Sstevel@tonic-gate line, start);
338*7c478bd9Sstevel@tonic-gate if (fth_curtype != NULL)
339*7c478bd9Sstevel@tonic-gate (void) fth_section_end();
340*7c478bd9Sstevel@tonic-gate return (-1);
341*7c478bd9Sstevel@tonic-gate }
342*7c478bd9Sstevel@tonic-gate fth_copying = 0;
343*7c478bd9Sstevel@tonic-gate return (0);
344*7c478bd9Sstevel@tonic-gate }
345*7c478bd9Sstevel@tonic-gate
346*7c478bd9Sstevel@tonic-gate if (fth_copying == 1) {
347*7c478bd9Sstevel@tonic-gate (void) fprintf(out, "%s\n", line);
348*7c478bd9Sstevel@tonic-gate return (0);
349*7c478bd9Sstevel@tonic-gate }
350*7c478bd9Sstevel@tonic-gate
351*7c478bd9Sstevel@tonic-gate if (strcmp(line, "verbatim_begin") == 0 ||
352*7c478bd9Sstevel@tonic-gate strcmp(line, "forth_start") == 0) {
353*7c478bd9Sstevel@tonic-gate if (fth_curtype != NULL) {
354*7c478bd9Sstevel@tonic-gate (void) parse_warn("Expected blank line between %s "
355*7c478bd9Sstevel@tonic-gate "macro and %s", fth_curtype, line);
356*7c478bd9Sstevel@tonic-gate return (fth_section_end());
357*7c478bd9Sstevel@tonic-gate }
358*7c478bd9Sstevel@tonic-gate
359*7c478bd9Sstevel@tonic-gate fth_copying = 1;
360*7c478bd9Sstevel@tonic-gate return (0);
361*7c478bd9Sstevel@tonic-gate }
362*7c478bd9Sstevel@tonic-gate
363*7c478bd9Sstevel@tonic-gate for (n = 1, word = strtok(line, " \t"); word != NULL;
364*7c478bd9Sstevel@tonic-gate word = strtok(NULL, " \t"), n++) {
365*7c478bd9Sstevel@tonic-gate if (n == 1)
366*7c478bd9Sstevel@tonic-gate name = word;
367*7c478bd9Sstevel@tonic-gate else if (n == 2)
368*7c478bd9Sstevel@tonic-gate format = word;
369*7c478bd9Sstevel@tonic-gate else
370*7c478bd9Sstevel@tonic-gate (void) parse_warn("Too many words");
371*7c478bd9Sstevel@tonic-gate }
372*7c478bd9Sstevel@tonic-gate
373*7c478bd9Sstevel@tonic-gate return (fth_section_add_member(name, format));
374*7c478bd9Sstevel@tonic-gate }
375*7c478bd9Sstevel@tonic-gate
376*7c478bd9Sstevel@tonic-gate static int
fth_fini(void)377*7c478bd9Sstevel@tonic-gate fth_fini(void)
378*7c478bd9Sstevel@tonic-gate {
379*7c478bd9Sstevel@tonic-gate return (fth_section_end());
380*7c478bd9Sstevel@tonic-gate }
381*7c478bd9Sstevel@tonic-gate
382*7c478bd9Sstevel@tonic-gate proc_ops_t fth_ops = {
383*7c478bd9Sstevel@tonic-gate fth_init,
384*7c478bd9Sstevel@tonic-gate fth_process_line,
385*7c478bd9Sstevel@tonic-gate fth_fini
386*7c478bd9Sstevel@tonic-gate };
387