#include #include #include /* look through HTMLized man pages convert references like man(1) into HTML links somewhat quick & dirty code various dubious assumptions made: [a-zA-Z0-9\-_\.]* defines legal characters in name pagename(x) corresponds to pagename.x.html (Fine *if* it's been converted by my scripts) x in the above must be a single digit (or we ignore it, which does no damage) Lazy parsing: malloc() enough RAM to read in whole file Limited syntax: exactly one input file, results to stdout Sandy Harris */ int do_file( char *, char *) ; main(int argc, char **argv) { FILE *in ; char *progname; long lsize ; size_t size, nread; char *buffer, *bufend ; progname = *argv ; if( argc != 2 ) { fprintf(stderr,"usage: %s input-file\n", progname); exit(1) ; } if( (in = fopen(argv[1],"r")) == NULL ) { fprintf(stderr,"%s Can't open input file\n", progname); exit(2) ; } if( (lsize = fseek(in, 0L, SEEK_END)) < 0L ) { fprintf(stderr,"%s fseek() fails\n", progname); exit(3) ; } lsize = ftell(in) ; rewind(in) ; size = (size_t) lsize ; if( lsize != (long) size ) { fprintf(stderr,"%s file too large\n", progname); exit(4) ; } if( (buffer = (char *) malloc(size)) == NULL) { fprintf(stderr,"%s malloc() failed\n", progname); exit(5) ; } bufend = buffer + size ; if( (nread = fread(buffer, size, 1, in)) != 1) { fprintf(stderr,"%s fread() failed\n", progname); exit(6) ; } do_file(buffer,bufend); } do_file(char *start, char *end) { /* p is where to start parsing, one past last output */ /* q is how far we've parsed */ char *p, *q ; int value ; for( p = q = start ; p < end ; q = (q 3) && isdigit(q[-1]) && (q[-2]=='(')) { q[-2] = '\0' ; q-- ; printf("", p, q); printf("%s(%s)", p, q); printf(""); } // otherwise just print string else printf("%s)", p); return 1 ; }