4 * This source code is part of
8 * GROningen MAchine for Chemical Simulations
12 * Copyright (c) 1991-1999
13 * BIOSON Research Institute, Dept. of Biophysical Chemistry
14 * University of Groningen, The Netherlands
17 * GROMACS: A message-passing parallel molecular dynamics implementation
18 * H.J.C. Berendsen, D. van der Spoel and R. van Drunen
19 * Comp. Phys. Comm. 91, 43-56 (1995)
21 * Also check out our WWW page:
22 * http://md.chem.rug.nl/~gmx
27 * Great Red Oystrich Makes All Chemists Sane
29 static char *SRCID_hrefify_c = "$Id$";
45 return (isalnum(c) || (c=='-') || (c=='_'));
48 char *strncasestr(char *line,char *str)
54 while (strlen(dum) && strncasecmp(dum,str,strlen(str)))
63 char *strstr_href(char *line,bool *bInHREF,int *i_dat,int n_dat,char **dat)
65 char *start,*found,*href;
75 while (strlen(start) && (strncasecmp(start,"</a",3) != 0))
77 if (strlen(start)>0) {
83 href=strncasestr(start,"<a href");
87 while((i<n_dat) && !found) {
88 found=strncasestr(start,dat[i]);
90 if (href && (found>href))
93 if (((found!=start) && isword(found[-1])) ||
94 isword(found[strlen(dat[i])]))
101 } while (strlen(start) && !found && href);
107 int main(int argc, char *argv[])
109 static char *desc[] = {
110 "hrefify adds href's for all the words in the input file which are not",
111 "already hyperlinked and which appear in the file specified with the",
112 "option [TT]-l[tt].[PAR]",
113 "If the href's should call a script, text can be added",
114 "with the [TT]-t[tt] option."
119 char **text,**str,line[1024],*ptr,*ref,
120 start[STRLEN],word[STRLEN],end[STRLEN];
121 int n_text,n_str,i_str;
128 { efDAT, "-l", "links", ffLIBRD },
130 #define NFILE asize(fnm)
131 static char *in=NULL,*out=NULL,*excl=NULL,*link_text=NULL;
132 static bool peratom=FALSE;
134 { "-f", FALSE, etSTR, &in, "HTML input" },
135 { "-o", FALSE, etSTR, &out, "HTML output" },
136 { "-e", FALSE, etSTR, &excl, "Exclude a string from HREF's, "
137 "when this option is not set, the filename without path and extension "
138 "will be excluded from HREF's"},
139 { "-t", FALSE, etSTR, &link_text, "Insert a string in front of the "
140 "href file name, useful for scripts" }
143 CopyRight(stderr,argv[0]);
144 parse_common_args(&argc,argv,0,FALSE,NFILE,fnm,asize(pa),pa,
145 asize(desc),desc,0,NULL);
148 fatal_error(0,"Input or output filename is not set");
150 n_text = get_file(in, &text);
151 fprintf(stderr,"Read %d lines from %s\n",n_text,in);
153 n_str=get_file(ftp2fn(efDAT,NFILE,fnm),&str);
154 fprintf(stderr,"Read %d strings %s\n",n_str,ftp2fn(efDAT,NFILE,fnm));
156 for (i=strlen(in)-1; i>0 && in[i-1]!='/'; i--);
158 for(i=strlen(excl)-1; i>0 && (excl[i]!='.'); i--);
162 fprintf(stderr,"Excluding '%s' from references\n",excl);
163 for(l=0; l<n_str && strcasecmp(str[l],excl); l++);
165 for(i=l+1; i<n_str; i++)
171 link_text=strdup("\0");
173 fprintf(stderr,"Adding '%s' to href's\n",link_text);
180 for(l=0; l<n_text; l++) {
181 strcpy(line,text[l]);
184 ptr=strstr_href(line,&bIn,&i_str,n_str,str);
187 if ((ref!=line) && (ref[-1]=='.')) {
189 while((ref>line) && isword(ref[-1]))
193 start[ref-line]='\0';
195 word[ptr-ref+strlen(str[i_str])]='\0';
196 strcpy(end,ptr+strlen(str[i_str]));
197 sprintf(line,"%s<a href=\"%s%s.html\">%s</a>%s\0",
198 start,link_text,str[i_str],word,end);
199 fprintf(stderr,"line %d: %s\n",l+1,str[i_str]);
204 fprintf(fp,"%s\n",line);
209 fprintf(stderr,"Added %d HTML references\n",n_repl);