4 * compile command: gcc -g -o deref deref.c
6 * execute command: deref filename.texi > newfile.texi
8 * To: bob@gnu.ai.mit.edu
9 * Subject: another tool
10 * Date: 18 Dec 91 16:03:13 EST (Wed)
11 * From: gatech!skeeve!arnold@eddie.mit.edu (Arnold D. Robbins)
13 * Here is deref.c. It turns texinfo cross references back into the
14 * one argument form. It has the same limitations as fixref; one xref per
15 * line and can't cross lines. You can use it to find references that do
16 * cross a line boundary this way:
18 * deref < manual > /dev/null 2>errs
20 * (This assumes bash or /bin/sh.) The file errs will have list of lines
21 * where deref could not find matching braces.
23 * A gawk manual processed by deref goes through makeinfo without complaint.
24 * Compile with gcc and you should be set.
35 * Make all texinfo references into the one argument form.
38 * arnold@skeeve.atl.ga.us
41 * Copyright, 1991, Arnold Robbins
46 * One texinfo cross reference per line.
47 * Cross references may not cross newlines.
48 * Use of fgets for input (to be fixed).
55 /* for gcc on the 3B1, delete if this gives you grief */
56 extern int fclose (FILE * fp
);
57 extern int fprintf (FILE * fp
, const char *str
,...);
59 extern char *strerror (int errno
);
60 extern char *strchr (char *cp
, int ch
);
61 extern int strncmp (const char *s1
, const char *s2
, int count
);
65 void process (FILE * fp
);
66 void repair (char *line
, char *ref
, int toffset
);
73 /* main --- handle arguments, global vars for errors */
76 main (int argc
, char **argv
)
85 for (argc
--, argv
++; *argv
!= NULL
; argc
--, argv
++)
87 if (argv
[0][0] == '-' && argv
[0][1] == '\0')
93 else if ((fp
= fopen (*argv
, "r")) != NULL
)
102 fprintf (stderr
, "%s: can not open: %s\n",
103 *argv
, strerror (errno
));
110 /* isref --- decide if we've seen a texinfo cross reference */
115 if (strncmp (cp
, "@ref{", 5) == 0)
117 if (strncmp (cp
, "@xref{", 6) == 0)
119 if (strncmp (cp
, "@pxref{", 7) == 0)
124 /* process --- read files, look for references, fix them up */
133 while (fgets (buf
, sizeof buf
, fp
) != NULL
)
136 cp
= strchr (buf
, '@');
148 cp
= strchr (cp
, '@');
157 repair (buf
, cp
, count
);
165 /* repair --- turn all texinfo cross references into the one argument form */
168 repair (char *line
, char *ref
, int toffset
)
170 int braces
= 1; /* have seen first left brace */
175 /* output line up to and including left brace in reference */
176 for (cp
= line
; cp
<= ref
; cp
++)
179 /* output node name */
180 for (; *cp
&& *cp
!= '}' && *cp
!= ',' && *cp
!= '\n'; cp
++)
184 { /* could have been one arg xref */
185 /* skip to matching right brace */
186 for (; braces
> 0; cp
++)
191 cp
++; /* blindly skip next character */
203 "%s: %s: %d: mismatched braces\n",
218 /* now the rest of the line */
224 /* strerror --- return error string, delete if in your library */
229 static char buf
[100];
231 extern char *sys_errlist
[];
233 if (errno
< sys_nerr
&& errno
>= 0)
234 return sys_errlist
[errno
];
236 sprintf (buf
, "unknown error %d", errno
);