3 * This source code is part of
7 * GROningen MAchine for Chemical Simulations
9 * VERSION 3.3.99_development_20071104
10 * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
11 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
12 * Copyright (c) 2001-2006, The GROMACS development team,
13 * check out http://www.gromacs.org for more information.
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * as published by the Free Software Foundation; either version 2
18 * of the License, or (at your option) any later version.
20 * If you want to redistribute modifications, please consider that
21 * scientific software is very special. Version control is crucial -
22 * bugs must be traceable. We will be happy to consider code for
23 * inclusion in the official distribution, but derived work must not
24 * be called official GROMACS. Details are found in the README & COPYING
25 * files - if they are missing, get the official version at www.gromacs.org.
27 * To help us fund GROMACS development, we humbly ask that you cite
28 * the papers on the package - you can find them in the top README file.
30 * For more info, check our website at http://www.gromacs.org
33 * Groningen Machine for Chemical Simulation
42 #include "gromacs/utility/smalloc.h"
45 #include "gromacs/utility/cstringutil.h"
46 #include "gromacs/fileio/confio.h"
47 #include "gromacs/math/vec.h"
48 #include "gromacs/commandline/pargs.h"
50 #include "gromacs/fileio/pdbio.h"
51 #include "gromacs/fileio/strdb.h"
53 gmx_bool isword(char c)
55 return (isalnum(c) || (c=='-') || (c=='_'));
58 char *strncasestr(char *line,char *str)
64 while (strlen(dum) && strncasecmp(dum,str,strlen(str)))
73 char *strstr_href(char *line,gmx_bool *bInHREF,int *i_dat,int n_dat,char **dat)
75 char *start,*found,*href=NULL;
85 while (strlen(start) && (strncasecmp(start,"</a",3) != 0))
87 if (strlen(start)>0) {
93 href=strncasestr(start,"<a href");
97 while((i<n_dat) && !found) {
98 found=strncasestr(start,dat[i]);
100 if (href && (found>href))
103 if (((found!=start) && isword(found[-1])) ||
104 isword(found[strlen(dat[i])]))
113 } while (strlen(start) && !found && href);
119 int main(int argc, char *argv[])
121 static char *desc[] = {
122 "[TT]hrefify[tt] adds href's for all the words in the input file which are not",
123 "already hyperlinked and which appear in the file specified with the",
124 "option [TT]-l[tt].[PAR]",
125 "If the href's should call a script, text can be added",
126 "with the [TT]-t[tt] option."
131 char **text,**str,line[1024],*ptr,*ref,
132 start[STRLEN],word[STRLEN],end[STRLEN];
133 int n_text,n_str,i_str;
134 gmx_bool bInHREF,bIn;
140 { efDAT, "-l", "links", ffLIBRD },
142 #define NFILE asize(fnm)
143 static char *in=NULL,*out=NULL,*excl=NULL,*link_text=NULL;
144 static gmx_bool peratom=FALSE;
146 { "-f", FALSE, etSTR, { &in } , "HTML input" },
147 { "-o", FALSE, etSTR, { &out } , "HTML output" },
148 { "-e", FALSE, etSTR, { &excl } , "Exclude a string from HREF's, "
149 "when this option is not set, the filename without path and extension "
150 "will be excluded from HREF's"},
151 { "-t", FALSE, etSTR, { &link_text } , "Insert a string in front of the "
152 "href file name, useful for scripts" }
155 CopyRight(stderr,argv[0]);
156 parse_common_args(&argc,argv,0,NFILE,fnm,asize(pa),pa,
157 asize(desc),desc,0,NULL);
160 gmx_fatal(FARGS,"Input or output filename is not set");
162 n_text = get_file(in, &text);
163 fprintf(stderr,"Read %d lines from %s\n",n_text,in);
165 n_str=get_file(ftp2fn(efDAT,NFILE,fnm),&str);
166 fprintf(stderr,"Read %d strings %s\n",n_str,ftp2fn(efDAT,NFILE,fnm));
168 for (i=strlen(in)-1; i>0 && in[i-1]!='/'; i--);
170 for(i=strlen(excl)-1; i>0 && (excl[i]!='.'); i--);
174 fprintf(stderr,"Excluding '%s' from references\n",excl);
175 for(l=0; l<n_str && strcasecmp(str[l],excl); l++);
177 for(i=l+1; i<n_str; i++)
183 link_text=strdup("\0");
185 fprintf(stderr,"Adding '%s' to href's\n",link_text);
187 fp=gmx_ffopen(out,"w");
192 for(l=0; l<n_text; l++) {
193 strcpy(line,text[l]);
196 ptr=strstr_href(line,&bIn,&i_str,n_str,str);
199 if ((ref!=line) && (ref[-1]=='.')) {
201 while((ref>line) && isword(ref[-1]))
205 start[ref-line]='\0';
207 word[ptr-ref+strlen(str[i_str])]='\0';
208 strcpy(end,ptr+strlen(str[i_str]));
209 sprintf(line,"%s<a href=\"%s%s.html\">%s</a>%s",
210 start,link_text,str[i_str],word,end);
211 fprintf(stderr,"line %d: %s\n",l+1,str[i_str]);
216 fprintf(fp,"%s\n",line);
221 fprintf(stderr,"Added %d HTML references\n",n_repl);