2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
5 * Copyright (c) 2001-2006, The GROMACS development team,
6 * check out http://www.gromacs.org for more information.
7 * Copyright (c) 2012, by the GROMACS development team, led by
8 * David van der Spoel, Berk Hess, Erik Lindahl, and including many
9 * others, as listed in the AUTHORS file in the top-level source
10 * directory and at http://www.gromacs.org.
12 * GROMACS is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public License
14 * as published by the Free Software Foundation; either version 2.1
15 * of the License, or (at your option) any later version.
17 * GROMACS is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Lesser General Public License for more details.
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with GROMACS; if not, see
24 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
25 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 * If you want to redistribute modifications to GROMACS, please
28 * consider that scientific software is very special. Version
29 * control is crucial - bugs must be traceable. We will be happy to
30 * consider code for inclusion in the official distribution, but
31 * derived work must not be called official GROMACS. Details are found
32 * in the README & COPYING files - if they are missing, get the
33 * official version at http://www.gromacs.org.
35 * To help us fund GROMACS development, we humbly ask that you cite
36 * the research papers on the package. Check out http://www.gromacs.org.
56 gmx_bool isword(char c)
58 return (isalnum(c) || (c=='-') || (c=='_'));
61 char *strncasestr(char *line,char *str)
67 while (strlen(dum) && strncasecmp(dum,str,strlen(str)))
76 char *strstr_href(char *line,gmx_bool *bInHREF,int *i_dat,int n_dat,char **dat)
78 char *start,*found,*href=NULL;
88 while (strlen(start) && (strncasecmp(start,"</a",3) != 0))
90 if (strlen(start)>0) {
96 href=strncasestr(start,"<a href");
100 while((i<n_dat) && !found) {
101 found=strncasestr(start,dat[i]);
103 if (href && (found>href))
106 if (((found!=start) && isword(found[-1])) ||
107 isword(found[strlen(dat[i])]))
116 } while (strlen(start) && !found && href);
122 int main(int argc, char *argv[])
124 static char *desc[] = {
125 "[TT]hrefify[tt] adds href's for all the words in the input file which are not",
126 "already hyperlinked and which appear in the file specified with the",
127 "option [TT]-l[tt].[PAR]",
128 "If the href's should call a script, text can be added",
129 "with the [TT]-t[tt] option."
134 char **text,**str,line[1024],*ptr,*ref,
135 start[STRLEN],word[STRLEN],end[STRLEN];
136 int n_text,n_str,i_str;
137 gmx_bool bInHREF,bIn;
143 { efDAT, "-l", "links", ffLIBRD },
145 #define NFILE asize(fnm)
146 static char *in=NULL,*out=NULL,*excl=NULL,*link_text=NULL;
147 static gmx_bool peratom=FALSE;
149 { "-f", FALSE, etSTR, { &in } , "HTML input" },
150 { "-o", FALSE, etSTR, { &out } , "HTML output" },
151 { "-e", FALSE, etSTR, { &excl } , "Exclude a string from HREF's, "
152 "when this option is not set, the filename without path and extension "
153 "will be excluded from HREF's"},
154 { "-t", FALSE, etSTR, { &link_text } , "Insert a string in front of the "
155 "href file name, useful for scripts" }
158 CopyRight(stderr,argv[0]);
159 parse_common_args(&argc,argv,0,NFILE,fnm,asize(pa),pa,
160 asize(desc),desc,0,NULL);
163 gmx_fatal(FARGS,"Input or output filename is not set");
165 n_text = get_file(in, &text);
166 fprintf(stderr,"Read %d lines from %s\n",n_text,in);
168 n_str=get_file(ftp2fn(efDAT,NFILE,fnm),&str);
169 fprintf(stderr,"Read %d strings %s\n",n_str,ftp2fn(efDAT,NFILE,fnm));
171 for (i=strlen(in)-1; i>0 && in[i-1]!='/'; i--);
173 for(i=strlen(excl)-1; i>0 && (excl[i]!='.'); i--);
177 fprintf(stderr,"Excluding '%s' from references\n",excl);
178 for(l=0; l<n_str && strcasecmp(str[l],excl); l++);
180 for(i=l+1; i<n_str; i++)
186 link_text=strdup("\0");
188 fprintf(stderr,"Adding '%s' to href's\n",link_text);
195 for(l=0; l<n_text; l++) {
196 strcpy(line,text[l]);
199 ptr=strstr_href(line,&bIn,&i_str,n_str,str);
202 if ((ref!=line) && (ref[-1]=='.')) {
204 while((ref>line) && isword(ref[-1]))
208 start[ref-line]='\0';
210 word[ptr-ref+strlen(str[i_str])]='\0';
211 strcpy(end,ptr+strlen(str[i_str]));
212 sprintf(line,"%s<a href=\"%s%s.html\">%s</a>%s",
213 start,link_text,str[i_str],word,end);
214 fprintf(stderr,"line %d: %s\n",l+1,str[i_str]);
219 fprintf(fp,"%s\n",line);
224 fprintf(stderr,"Added %d HTML references\n",n_repl);