"Fossies" - the Fresh Open Source Software Archive

Member "rman-3.2/contrib/sutter.txt" (26 Jul 2003, 3806 Bytes) of package /linux/www/old/rman-3.2.tar.gz:


As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 "Edward L. Sutter" <els@sage.sage.att.com>
    2 
    3 Perhaps there is already a better way to do this, but since I couldn'd find
    4 one, I'd like to make a suggestion that has helped me quite a bit for getting
    5 the proper hypertext links.  Keep in mind that this is under the context of
    6 me converting "man" directories with their typical sub-directories of
    7 man1, man2, etc... to an equivalently structured "html" directory with
    8 the same sub-directory heirarchy.
    9 
   10 I added an option to rman that allows it to search for the files over
   11 a specified set of directories.  This allows (for example) manpages under
   12 man1 that reference something under man3 to be properly linked.
   13 
   14 rman.c v2.4 ...
   15 
   16 ...
   17 
   18 /* ELS: added to support a smarter external reference generator. */
   19 char	*SearchDirs=0;
   20 int 	HrefSearch();
   21 
   22 ...
   23 
   24 /* ELS: added the -S option: */
   25 	while ((c=getopt(argc,argv,"Kh?f:l:r:bckmTpvn:t:s:yS:"))!=-1)
   26 		switch (c) {
   27 		   case 'k': fHeadfoot=1; break;
   28 		   case 'b': fSubsections=1; break;
   29 		   case 'c': fChangeleft=1; break;
   30 		   case 'S': SearchDirs=optarg; break;
   31 
   32 
   33 ...
   34 
   35 
   36 void
   37 HTML(enum command cmd) {
   38 
   39 ...
   40 
   41 	
   42 	   case BEGINMANREF:
   43 		for (p=hitxt; *p && *p!='('; p++) /* empty */;
   44 		*p++='\0'; p0=p;
   45 		for (; *p && *p!=')'; p++) /* empty */;
   46 		*p='\0';
   47 /* ELS: added a call to HrefSearch() if the -S option is set.. */
   48 		if (SearchDirs)
   49 			HrefSearch(hitxt,p0);
   50 		else {
   51 			printf("<A HREF=\"");
   52 			printf(manRef, hitxt, p0);
   53 			printf("\">");
   54 		}
   55 		break;
   56 
   57 
   58 ...
   59 
   60 
   61 /* ELS... 
   62    HrefSearch():
   63 	Active only with command line option -S...
   64 	Called when rman -fHTML has determined that it is going to add a
   65 	hypertext link.  The user tells rman where to search for the hypertext
   66 	links (local machine search only) and if HrefSearch() finds the file
   67 
   68 			SRCHDIR/manname.section
   69 
   70 	where
   71 		SRCHDIR is one of the colon-delimited paths specified with
   72 			the -S option;
   73 		manname is the text that rman found preceding a "manname(##)"
   74 			detection;
   75 		section is the string within the parens of the manname spec;
   76 
   77 
   78 	then it will use that path to build the HREF line.  If not found,
   79 	then <A> is all that is inserted.
   80 	This is generally only helpful when you are simply attempting to
   81 	turn a man directory into an html directory.
   82 
   83 	Note that if the first char of SearchDirs is a colon, then if
   84 	HrefSearch does not find the reference, it defaults to what rman
   85 	used to do (use manRef, -r option); otherwise, it will not add
   86 	a hypertext link at all.
   87 */
   88 HrefSearch(manname,section)
   89 char	*manname, *section;
   90 {
   91 	char	*dir, *colon, tmp;
   92 	int	DefaultToManRef;
   93 	FILE	*fp;
   94 	static char	path[256];
   95 
   96 	tmp = 0;
   97 
   98 again:
   99 	if (SearchDirs[0] == ':') {
  100 		dir = &SearchDirs[1];
  101 		DefaultToManRef = 1;
  102 	}
  103 	else {
  104 		dir = SearchDirs;
  105 		DefaultToManRef = 0;
  106 	}
  107 
  108 	/* Make 2 passes on all search directories... */
  109 	/* First pass is with the path dir/manname.section */
  110 	/* Second pass is with the path dir/manname.section[0] */
  111 	/* This allows the spec manname(3x) to be found as manname.3 */
  112 	/* just in cast manname.3x doesn't exist. */
  113 	/* Note that the second pass is only necessary if the section */
  114 	/* string is more than one character in length. */
  115 	while(1) {
  116 		colon =  strchr(dir,':');
  117 		if (colon) *colon = 0;
  118 		sprintf(path,"%s/%s.%s.html",dir,manname,section); 
  119 		if ((fp = fopen(path,"rw")) != NULL) {
  120 			printf("<A HREF=\"");
  121 			printf("%s",path);
  122 			printf("\">");
  123 			fclose(fp);
  124 			if (colon) *colon = ':';
  125 			fprintf(stderr,"HREF @ %s\n",path);
  126 			return(1);
  127 		}
  128 		if (colon) {
  129 			*colon = ':';
  130 			dir = colon+1;
  131 		}
  132 		else
  133 			break;
  134 	}
  135 	if (section[1]) {
  136 		tmp = section[1];
  137 		section[1] = 0;
  138 		dir = SearchDirs;
  139 		goto again;
  140 	}
  141 	if (tmp)
  142 		section[1] = tmp;
  143 
  144 	if (DefaultToManRef) {
  145 		printf("<A HREF=\"");
  146 		printf(manRef, manname, section);
  147 		printf("\">");
  148 	}
  149 	else
  150 		printf("<A>");
  151 	return(1);
  152 }
  153 
  154 /* End ELS additions. */
  155