4 * This source code is part of
8 * GROningen MAchine for Chemical Simulations
12 * Copyright (c) 1991-2001
13 * BIOSON Research Institute, Dept. of Biophysical Chemistry
14 * University of Groningen, The Netherlands
16 * This program is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU General Public License
18 * as published by the Free Software Foundation; either version 2
19 * of the License, or (at your option) any later version.
21 * If you want to redistribute modifications, please consider that
22 * scientific software is very special. Version control is crucial -
23 * bugs must be traceable. We will be happy to consider code for
24 * inclusion in the official distribution, but derived work must not
25 * be called official GROMACS. Details are found in the README & COPYING
26 * files - if they are missing, get the official version at www.gromacs.org.
28 * To help us fund GROMACS development, we humbly ask that you cite
29 * the papers on the package - you can find them in the top README file.
31 * Do check out http://www.gromacs.org , or mail us at gromacs@gromacs.org .
34 * Gromacs Runs On Most of All Computer Systems
36 static char *SRCID_hrefify_c = "$Id$";
51 return (isalnum(c) || (c=='-') || (c=='_'));
54 char *strncasestr(char *line,char *str)
60 while (strlen(dum) && strncasecmp(dum,str,strlen(str)))
69 char *strstr_href(char *line,bool *bInHREF,int *i_dat,int n_dat,char **dat)
71 char *start,*found,*href;
81 while (strlen(start) && (strncasecmp(start,"</a",3) != 0))
83 if (strlen(start)>0) {
89 href=strncasestr(start,"<a href");
93 while((i<n_dat) && !found) {
94 found=strncasestr(start,dat[i]);
96 if (href && (found>href))
99 if (((found!=start) && isword(found[-1])) ||
100 isword(found[strlen(dat[i])]))
107 } while (strlen(start) && !found && href);
113 int main(int argc, char *argv[])
115 static char *desc[] = {
116 "hrefify adds href's for all the words in the input file which are not",
117 "already hyperlinked and which appear in the file specified with the",
118 "option [TT]-l[tt].[PAR]",
119 "If the href's should call a script, text can be added",
120 "with the [TT]-t[tt] option."
125 char **text,**str,line[1024],*ptr,*ref,
126 start[STRLEN],word[STRLEN],end[STRLEN];
127 int n_text,n_str,i_str;
134 { efDAT, "-l", "links", ffLIBRD },
136 #define NFILE asize(fnm)
137 static char *in=NULL,*out=NULL,*excl=NULL,*link_text=NULL;
138 static bool peratom=FALSE;
140 { "-f", FALSE, etSTR, &in, "HTML input" },
141 { "-o", FALSE, etSTR, &out, "HTML output" },
142 { "-e", FALSE, etSTR, &excl, "Exclude a string from HREF's, "
143 "when this option is not set, the filename without path and extension "
144 "will be excluded from HREF's"},
145 { "-t", FALSE, etSTR, &link_text, "Insert a string in front of the "
146 "href file name, useful for scripts" }
149 CopyRight(stderr,argv[0]);
150 parse_common_args(&argc,argv,0,FALSE,NFILE,fnm,asize(pa),pa,
151 asize(desc),desc,0,NULL);
154 fatal_error(0,"Input or output filename is not set");
156 n_text = get_file(in, &text);
157 fprintf(stderr,"Read %d lines from %s\n",n_text,in);
159 n_str=get_file(ftp2fn(efDAT,NFILE,fnm),&str);
160 fprintf(stderr,"Read %d strings %s\n",n_str,ftp2fn(efDAT,NFILE,fnm));
162 for (i=strlen(in)-1; i>0 && in[i-1]!='/'; i--);
164 for(i=strlen(excl)-1; i>0 && (excl[i]!='.'); i--);
168 fprintf(stderr,"Excluding '%s' from references\n",excl);
169 for(l=0; l<n_str && strcasecmp(str[l],excl); l++);
171 for(i=l+1; i<n_str; i++)
177 link_text=strdup("\0");
179 fprintf(stderr,"Adding '%s' to href's\n",link_text);
186 for(l=0; l<n_text; l++) {
187 strcpy(line,text[l]);
190 ptr=strstr_href(line,&bIn,&i_str,n_str,str);
193 if ((ref!=line) && (ref[-1]=='.')) {
195 while((ref>line) && isword(ref[-1]))
199 start[ref-line]='\0';
201 word[ptr-ref+strlen(str[i_str])]='\0';
202 strcpy(end,ptr+strlen(str[i_str]));
203 sprintf(line,"%s<a href=\"%s%s.html\">%s</a>%s\0",
204 start,link_text,str[i_str],word,end);
205 fprintf(stderr,"line %d: %s\n",l+1,str[i_str]);
210 fprintf(fp,"%s\n",line);
215 fprintf(stderr,"Added %d HTML references\n",n_repl);