From 997358a6c475c8886cce388ab325184a1ff733c9 Mon Sep 17 00:00:00 2001 From: Martin Willi Date: Fri, 28 Apr 2006 07:14:48 +0000 Subject: - import of strongswan-2.7.0 - applied patch for charon --- doc/utils/man_xref.c | 125 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100644 doc/utils/man_xref.c (limited to 'doc/utils/man_xref.c') diff --git a/doc/utils/man_xref.c b/doc/utils/man_xref.c new file mode 100644 index 000000000..fc3afb696 --- /dev/null +++ b/doc/utils/man_xref.c @@ -0,0 +1,125 @@ +#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 ; +} -- cgit v1.2.3