6 * Make all texinfo references into the one argument form.
10 * Written: December, 1991
11 * Released: November, 1998
13 * Copyright, 1991, 1998 Arnold David Robbins
15 * DEREF is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
20 * DEREF is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
32 * One texinfo cross reference per line.
33 * Cross references may not cross newlines.
34 * Use of fgets for input (to be fixed).
41 /* for gcc on the 3B1, delete if this gives you grief */
42 extern int fclose(FILE *fp
);
43 extern int fprintf(FILE *fp
, const char *str
, ...);
44 /* extern int sprintf(char *str, const char *fmt, ...); */
45 extern int fputs(char *buf
, FILE *fp
);
47 extern char *strerror(int errno
);
48 extern char *strchr(char *cp
, int ch
);
49 extern int strncmp(const char *s1
, const char *s2
, int count
);
53 void process(FILE *fp
);
54 void repair(char *line
, char *ref
, int toffset
);
61 /* main --- handle arguments, global vars for errors */
64 main(int argc
, char **argv
)
73 for (argc
--, argv
++; *argv
!= NULL
; argc
--, argv
++) {
74 if (argv
[0][0] == '-' && argv
[0][1] == '\0') {
78 } else if ((fp
= fopen(*argv
, "r")) != NULL
) {
84 fprintf(stderr
, "%s: can not open: %s\n",
85 *argv
, strerror(errno
));
92 /* isref --- decide if we've seen a texinfo cross reference */
97 if (strncmp(cp
, "@ref{", 5) == 0)
99 if (strncmp(cp
, "@xref{", 6) == 0)
101 if (strncmp(cp
, "@pxref{", 7) == 0)
106 /* process --- read files, look for references, fix them up */
115 while (fgets(buf
, sizeof buf
, fp
) != NULL
) {
117 cp
= strchr(buf
, '@');
126 cp
= strchr(cp
, '@');
134 repair(buf
, cp
, count
);
136 } while (cp
!= NULL
);
141 /* repair --- turn all texinfo cross references into the one argument form */
144 repair(char *line
, char *ref
, int toffset
)
146 int braces
= 1; /* have seen first left brace */
151 /* output line up to and including left brace in reference */
152 for (cp
= line
; cp
<= ref
; cp
++)
155 /* output node name */
156 for (; *cp
&& *cp
!= '}' && *cp
!= ',' && *cp
!= '\n'; cp
++)
159 if (*cp
!= '}') { /* could have been one arg xref */
160 /* skip to matching right brace */
161 for (; braces
> 0; cp
++) {
164 cp
++; /* blindly skip next character */
176 "%s: %s: %d: mismatched braces\n",
191 /* now the rest of the line */
197 /* strerror --- return error string, delete if in your library */
202 static char buf
[100];
204 extern char *sys_errlist
[];
206 if (errno
< sys_nerr
&& errno
>= 0)
207 return sys_errlist
[errno
];
209 sprintf(buf
, "unknown error %d", errno
);