6 look through HTMLized man pages
7 convert references like man(1) into HTML links
9 somewhat quick & dirty code
10 various dubious assumptions made:
12 [a-zA-Z0-9\-_\.]* defines legal characters in name
13 pagename(x) corresponds to pagename.x.html
14 (Fine *if* it's been converted by my scripts)
15 x in the above must be a single digit
16 (or we ignore it, which does no damage)
17 Lazy parsing: malloc() enough RAM to read in whole file
18 Limited syntax: exactly one input file, results to stdout
23 int do_file( char *, char *) ;
25 main(int argc, char **argv)
31 char *buffer, *bufend ;
34 fprintf(stderr,"usage: %s input-file\n", progname);
37 if( (in = fopen(argv[1],"r")) == NULL ) {
38 fprintf(stderr,"%s Can't open input file\n", progname);
41 if( (lsize = fseek(in, 0L, SEEK_END)) < 0L ) {
42 fprintf(stderr,"%s fseek() fails\n", progname);
47 size = (size_t) lsize ;
48 if( lsize != (long) size ) {
49 fprintf(stderr,"%s file too large\n", progname);
52 if( (buffer = (char *) malloc(size)) == NULL) {
53 fprintf(stderr,"%s malloc() failed\n", progname);
56 bufend = buffer + size ;
57 if( (nread = fread(buffer, size, 1, in)) != 1) {
58 fprintf(stderr,"%s fread() failed\n", progname);
61 do_file(buffer,bufend);
64 do_file(char *start, char *end)
66 /* p is where to start parsing, one past last output */
67 /* q is how far we've parsed */
70 for( p = q = start ; p < end ; q = (q<end) ? (q+1) : q ) {
71 /* if p is beyond q, catch up */
74 /* move q ahead until we know if we've got manpage name */
78 /* can appear in manpage name */
85 /* whatever's between p and q
90 /* leave p one past output */
94 /* we may have a manpage name */
101 /* unreached with current do_name() */
103 for( ; p <= q ; p++ )
108 do_name(char *p, char *q)
111 /* if end of string matches RE ([0-9])
112 with at least one legal character before it
115 if( (q-p > 3) && isdigit(q[-1]) && (q[-2]=='(')) {
118 printf("<a href=\"%s.%s.html\">", p, q);
119 printf("%s(%s)", p, q);
122 // otherwise just print string
123 else printf("%s)", p);