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-2004, The GROMACS development team,
6 * check out http://www.gromacs.org for more information.
7 * Copyright (c) 2012,2013, 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.
55 /* The source code in this file should be thread-safe.
56 Please keep it that way. */
60 const char *search,*replace;
64 char *search,*replace;
67 /* The order of these arrays is significant. Text search and replace
68 * for each element occurs in order, so earlier changes can induce
69 * subsequent changes even though the original text might not appear
70 * to invoke the latter changes. */
72 const t_sandr_const sandrTeX[] = {
80 /* Escaping underscore for LaTeX is no longer necessary, and it breaks
81 * text searching and the index if you do. */
86 { "<=", "\\ensuremath{\\leq{}}"},
87 { ">=", "\\ensuremath{\\geq{}}"},
88 { "<", "\\textless{}" },
89 { ">", "\\textgreater{}" },
91 { "\\^{}t", "\\ensuremath{^t}" },
92 { "\\^{}a", "\\ensuremath{^a}" },
93 { "\\^{}b", "\\ensuremath{^b}" },
94 { "\\^{}2", "\\ensuremath{^2}" },
95 { "\\^{}3", "\\ensuremath{^3}" },
96 { "\\^{}6", "\\ensuremath{^6}" },
101 /* The next couple of lines allow true Greek symbols to be written to the
102 manual, which makes it look pretty */
103 { "[GRK]", "\\ensuremath{\\" },
105 { "[MATH]","\\ensuremath{" },
107 { "[CHEVRON]", "\\ensuremath{<}" },
108 { "[chevron]", "\\ensuremath{>}" },
109 { "[MAG]", "\\ensuremath{|}" },
110 { "[mag]", "\\ensuremath{|}" },
111 { "[INT]","\\ensuremath{\\int" },
117 { "[SUM]","\\ensuremath{\\sum" },
119 { "[SUB]","\\ensuremath{_{" },
121 { "[SQRT]","\\ensuremath{\\sqrt{" },
123 { "[EXP]","\\ensuremath{\\exp{(" },
125 { "[LN]","\\ensuremath{\\ln{(" },
127 { "[LOG]","\\ensuremath{\\log{(" },
129 { "[COS]","\\ensuremath{\\cos{(" },
131 { "[SIN]","\\ensuremath{\\sin{(" },
133 { "[TAN]","\\ensuremath{\\tan{(" },
135 { "[COSH]","\\ensuremath{\\cosh{(" },
137 { "[SINH]","\\ensuremath{\\sinh{(" },
139 { "[TANH]","\\ensuremath{\\tanh{(" },
142 #define NSRTEX asize(sandrTeX)
144 const t_sandr_const sandrTty[] = {
157 { "[INT]","integral" },
158 { "[FROM]"," from " },
167 { "[SQRT]","sqrt(" },
181 { "[COSH]","cosh(" },
183 { "[SINH]","sinh(" },
185 { "[TANH]","tanh(" },
192 #define NSRTTY asize(sandrTty)
194 const t_sandr_const sandrWiki[] = {
198 { "[TT]", "<code>" },
199 { "[tt]", "</code>" },
210 { "[INT]","integral" },
211 { "[FROM]"," from " },
220 { "[SQRT]","sqrt(" },
234 { "[COSH]","cosh(" },
236 { "[SINH]","sinh(" },
238 { "[TANH]","tanh(" },
245 #define NSRWIKI asize(sandrWiki)
247 const t_sandr_const sandrNROFF[] = {
260 { "[INT]","integral" },
261 { "[FROM]"," from " },
270 { "[SQRT]","sqrt(" },
284 { "[COSH]","cosh(" },
286 { "[SINH]","sinh(" },
288 { "[TANH]","tanh(" },
301 #define NSRNROFF asize(sandrNROFF)
303 const t_sandr_const sandrHTML[] = {
318 { "[INT]","integral" },
319 { "[FROM]"," from " },
328 { "[SQRT]","sqrt(" },
342 { "[COSH]","cosh(" },
344 { "[SINH]","sinh(" },
346 { "[TANH]","tanh(" },
353 #define NSRHTML asize(sandrHTML)
355 const t_sandr_const sandrXML[] = {
359 { "[tt]", "</arg>" },
361 { "[bb]", "</emp>" },
370 { "[INT]","integral" },
371 { "[FROM]"," from " },
380 { "[SQRT]","sqrt(" },
394 { "[COSH]","cosh(" },
396 { "[SINH]","sinh(" },
398 { "[TANH]","tanh(" },
400 { "[PAR]","</par>\n<par>" },
401 { "[BR]", "<br />" },
405 #define NSRXML asize(sandrXML)
407 static void mynum(char *buf,int n)
410 sprintf(buf,"%2d",n);
412 sprintf(buf,"0%1d",n);
415 static char *mydate(char buf[], int maxsize,gmx_bool bWiki)
417 const char *mon[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun",
418 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
419 const char *day[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
420 const char *num[] = { "01", "02", "03", "04", "05", "06","07", "08", "09" };
425 #ifdef GMX_NATIVE_WINDOWS
427 localtime_s(&tm,&now);
429 localtime_r(&now,&tm);
432 /* subtract one from maxsize, so we have room for \0. */
434 char dd[8],mm[8],ss[8],hh[8],mn[8];
436 mynum(dd,tm.tm_mday);
439 mynum(hh,tm.tm_hour);
441 sprintf(buf,"%4d-%2s-%2sT%2s:%2s:%2sZ",
442 tm.tm_year+1900,mm,dd,hh,mn,ss);
445 sprintf(buf,"%s %d %s %d",day[tm.tm_wday],tm.tm_mday,
446 mon[tm.tm_mon],tm.tm_year+1900);
451 /* Data structure for saved HTML links */
452 typedef struct t_linkdata {
457 static t_linkdata *init_linkdata()
467 static void finish_linkdata(t_linkdata *p)
471 for(i=0;i<p->nsr;i++) {
472 sfree(p->sr[i].search);
473 sfree(p->sr[i].replace);
479 static char *repall(const char *s,int nsr,const t_sandr_const sa[])
484 /* Copy input to a non-constant char buffer.
485 * buf1 is allocated here
489 for(i=0; (i<nsr); i++) {
490 /* Replace in buffer1, put result in buffer2.
491 * buf2 is allocated here.
493 buf2=replace(buf1,sa[i].search,sa[i].replace);
501 static char *repallww(const char *s,int nsr,const t_sandr sa[])
506 /* Copy input to a non-constant char buffer.
507 * buf1 is allocated here
511 for(i=0; (i<nsr); i++) {
512 /* Replace in buffer1, put result in buffer2.
513 * buf2 is allocated here.
515 buf2=replaceww(buf1,sa[i].search,sa[i].replace);
522 static char *html_xref(char *s,const char *program, t_linkdata *links,gmx_bool bWiki)
524 char buf[256],**filestr;
527 if (links->sr == NULL) {
528 n=get_file("links.dat",&(filestr));
531 for(i=0,j=0; (i<n); i++) {
532 if (!program || (gmx_strcasecmp(program,filestr[i]) != 0)) {
533 links->sr[j].search=gmx_strdup(filestr[i]);
535 sprintf(buf,"[[%s]]",filestr[i]);
537 sprintf(buf,"<a href=\"%s.html\">%s</a>",filestr[i],filestr[i]);
538 links->sr[j].replace=gmx_strdup(buf);
547 return repallww(s,links->nsr,links->sr);
550 char *check_tex(const char *s)
552 return repall(s,NSRTEX,sandrTeX);
555 static char *check_nroff(const char *s)
557 return repall(s,NSRNROFF,sandrNROFF);
560 static char *check_wiki(const char *s,const char *program, t_linkdata *links)
564 buf = repall(s,NSRWIKI,sandrWiki);
565 buf = html_xref(buf,program,links,TRUE);
570 static char *check_html(const char *s,const char *program, t_linkdata *links)
574 buf = repall(s,NSRHTML,sandrHTML);
575 buf = html_xref(buf,program,links,FALSE);
580 #define NWR(s) check_wiki(s,program,links)
581 #define NSR(s) check_html(s,program,links)
583 #define FLAG_SET(flag, mask) ((flag & mask) == mask)
584 char *fileopt(unsigned long flag,char buf[],int maxsize)
588 if (FLAG_SET(flag, ffRW))
589 sprintf(tmp,"In/Out");
590 else if (FLAG_SET(flag, ffREAD))
591 sprintf(tmp,"Input");
592 else if (FLAG_SET(flag, ffWRITE))
593 sprintf(tmp,"Output");
595 sprintf(tmp,"Dunno");
597 if (FLAG_SET(flag, ffOPT)) {
599 if (FLAG_SET(flag, ffSET))
604 if (FLAG_SET(flag, ffLIB))
605 strcat(tmp,", Lib.");
606 if (FLAG_SET(flag, ffMULT))
607 strcat(tmp,", Mult.");
609 sprintf(buf,"%s",tmp);
614 static void write_texman(FILE *out,const char *program,
615 int nldesc,const char **desc,
616 int nfile,t_filenm *fnm,
617 int npargs,t_pargs *pa,
618 int nbug,const char **bugs,
624 fprintf(out,"\\section{\\normindex{%s}}\\label{%s}\n\n",check_tex(program),check_tex(program));
627 for(i=0; (i<nldesc); i++)
628 fprintf(out,"%s\n",check_tex(desc[i]));
631 fprintf(out,"\\vspace{-2ex}\\begin{tabbing}\n");
632 fprintf(out,"\n{\\normalsize \\bf Files}\\nopagebreak\\\\\n");
633 fprintf(out,"{\\tt ~~~~~~~} \\= {\\tt ~~~~~~~~~~~~~~} \\= "
634 "~~~~~~~~~~~~~~~~~~~~~~ \\= \\nopagebreak\\kill\n");
635 for(i=0; (i<nfile); i++)
636 fprintf(out,"\\>{\\tt %s} \\'\\> {\\tt %s} \\' %s \\> "
637 "\\parbox[t]{0.55\\linewidth}{%s} \\\\\n",
638 check_tex(fnm[i].opt),check_tex(fnm[i].fns[0]),
639 check_tex(fileopt(fnm[i].flag,tmp,255)),
640 check_tex(ftp2desc(fnm[i].ftp)));
641 fprintf(out,"\\end{tabbing}\\vspace{-4ex}\n");
644 fprintf(out,"\\vspace{-2ex}\\begin{tabbing}\n");
645 fprintf(out,"\n{\\normalsize \\bf Other options}\\nopagebreak\\\\\n");
646 fprintf(out,"{\\tt ~~~~~~~~~~} \\= vector \\= "
647 "{\\tt ~~~~~~~} \\= \\nopagebreak\\kill\n");
648 for(i=0; (i<npargs); i++) {
649 if (strlen(check_tex(pa_val(&(pa[i]),tmp,255))) <= 8)
650 fprintf(out,"\\> {\\tt %s} \\'\\> %s \\'\\> {\\tt %s} \\' "
651 "\\parbox[t]{0.68\\linewidth}{%s}\\\\\n",
652 check_tex(pa[i].option),argtp[pa[i].type],
653 check_tex(pa_val(&(pa[i]),tmp,255)),
654 check_tex(pa[i].desc));
656 fprintf(out,"\\> {\\tt %s} \\'\\> %s \\'\\>\\\\\n"
657 "\\> \\'\\> \\'\\> {\\tt %s} \\' "
658 "\\parbox[t]{0.7\\linewidth}{%s}\\\\\n",
659 check_tex(pa[i].option),argtp[pa[i].type],
660 check_tex(pa_val(&(pa[i]),tmp,255)),
661 check_tex(pa[i].desc));
663 fprintf(out,"\\end{tabbing}\\vspace{-4ex}\n");
667 fprintf(out,"\\begin{itemize}\n");
668 for(i=0; (i<nbug); i++)
669 fprintf(out,"\\item %s\n",check_tex(bugs[i]));
670 fprintf(out,"\\end{itemize}\n");
672 /* fprintf(out,"\n\\newpage\n"); */
675 static void write_nroffman(FILE *out,
677 int nldesc,const char **desc,
678 int nfile,t_filenm *fnm,
679 int npargs,t_pargs *pa,
680 int nbug,const char **bugs,
688 fprintf(out,".TH %s 1 \"%s\" \"\" \"GROMACS suite, %s\"\n",program,mydate(tmp,255,FALSE),GromacsVersion());
689 fprintf(out,".SH NAME\n");
690 fprintf(out,"%s@DESC@\n\n",program);
691 fprintf(out,".B %s\n",GromacsVersion());
693 fprintf(out,".SH SYNOPSIS\n");
694 fprintf(out,"\\f3%s\\fP\n",program);
696 /* command line arguments */
698 for(i=0; (i<nfile); i++)
699 fprintf(out,".BI \"%s\" \" %s \"\n",check_nroff(fnm[i].opt),
700 check_nroff(fnm[i].fns[0]));
703 for(i=0; (i<npargs); i++)
704 if (pa[i].type == etBOOL)
705 fprintf(out,".BI \"\\-[no]%s\" \"\"\n",check_nroff(pa[i].option+1));
707 fprintf(out,".BI \"%s\" \" %s \"\n",check_nroff(pa[i].option),
708 check_nroff(argtp[pa[i].type]));
713 fprintf(out,".SH DESCRIPTION\n");
714 for(i=0; (i<nldesc); i++)
715 fprintf(out,"\\&%s\n",check_nroff(desc[i]));
720 fprintf(out,".SH FILES\n");
721 for(i=0; (i<nfile); i++)
722 fprintf(out,".BI \"%s\" \" %s\" \n.B %s\n %s \n\n",
723 check_nroff(fnm[i].opt),
724 check_nroff(fnm[i].fns[0]),
725 check_nroff(fileopt(fnm[i].flag,tmp,255)),
726 check_nroff(ftp2desc(fnm[i].ftp)));
730 fprintf(out,".SH OTHER OPTIONS\n");
732 for(i=0; (i<npargs); i++) {
733 if (pa[i].type == etBOOL)
734 fprintf(out,".BI \"\\-[no]%s\" \"%s\"\n %s\n\n",
735 check_nroff(pa[i].option+1),
736 check_nroff(pa_val(&(pa[i]),tmp,255)),
737 check_nroff(pa[i].desc));
739 fprintf(out,".BI \"%s\" \" %s\" \" %s\" \n %s\n\n",
740 check_nroff(pa[i].option),
741 check_nroff(argtp[pa[i].type]),
742 check_nroff(pa_val(&(pa[i]),tmp,255)),
743 check_nroff(pa[i].desc));
748 fprintf(out,".SH KNOWN PROBLEMS\n");
749 for(i=0; (i<nbug); i++)
750 fprintf(out,"\\- %s\n\n",check_nroff(bugs[i]));
753 fprintf(out,".SH SEE ALSO\n.BR gromacs(7)\n\n");
754 fprintf(out,"More information about \\fBGROMACS\\fR is available at <\\fIhttp://www.gromacs.org/\\fR>.\n");
758 char *check_tty(const char *s)
760 return repall(s,NSRTTY,sandrTty);
764 print_tty_formatted(FILE *out, int nldesc, const char **desc,int indent,
765 t_linkdata *links,const char *program,gmx_bool bWiki)
773 for(i=0; (i<nldesc); i++) {
774 if ((strlen(buf)>0) &&
775 (buf[strlen(buf)-1] !=' ') && (buf[strlen(buf)-1] !='\n'))
780 temp=check_tty(desc[i]);
781 if (strlen(buf) + strlen(temp) >= (size_t)(buflen-2)) {
782 buflen += strlen(temp);
788 /* Make lines of at most 79 characters */
789 temp = wrap_lines(buf,78,indent,FALSE);
790 fprintf(out,"%s\n",temp);
795 static void write_ttyman(FILE *out,
797 int nldesc,const char **desc,
798 int nfile,t_filenm *fnm,
799 int npargs,t_pargs *pa,
800 int nbug,const char **bugs,gmx_bool bHeader,
808 fprintf(out,"%s\n\n",check_tty(program));
809 fprintf(out,"%s\n%s\n",GromacsVersion(),mydate(buf,255,FALSE));
812 fprintf(out,"DESCRIPTION\n-----------\n");
813 print_tty_formatted(out,nldesc,desc,0,links,program,FALSE);
817 fprintf(out,"KNOWN PROBLEMS\n----------\n");
818 for(i=0; i<nbug; i++) {
819 snew(tmp,strlen(bugs[i])+3);
821 strcpy(tmp+2,check_tty(bugs[i]));
822 fprintf(out,"%s\n",wrap_lines(tmp,78,2,FALSE));
828 pr_fns(out,nfile,fnm);
831 print_pargs(out,npargs,pa,FALSE);
835 static void pr_html_files(FILE *out,int nfile,t_filenm fnm[],
836 const char *program,t_linkdata *links,gmx_bool bWiki)
839 char link[10],tmp[255];
842 fprintf(out," %-10s %-12s %-12s %-s\n"
843 " -----------------------------------------------------\n",
844 "Option","Filename","Type","Description");
847 "<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=2>\n"
852 "<TH>description</TH>"
855 for(i=0; (i<nfile); i++) {
856 strcpy(link,ftp2ext(fnm[i].ftp));
857 if (strcmp(link,"???")==0)
858 strcpy(link,"files");
860 fprintf(out," %-10s %-16s %-12s %-s\n",
863 fileopt(fnm[i].flag,tmp,255),
864 NWR(ftp2desc(fnm[i].ftp)));
868 "<TD ALIGN=RIGHT> <b><tt>%s</tt></b> </TD>"
869 "<TD ALIGN=RIGHT> <tt><a href=\"%s.html\">%12s</a></tt> </TD>"
873 fnm[i].opt,link,fnm[i].fns[0],fileopt(fnm[i].flag,tmp,255),
874 NSR(ftp2desc(fnm[i].ftp)));
877 fprintf(out,"</TABLE>\n");
880 static void write_wikiman(FILE *out,
882 int nldesc,const char **desc,
883 int nfile,t_filenm *fnm,
884 int npargs,t_pargs *pa,
885 int nbug,const char **bugs,gmx_bool bHeader,
889 char buf[256],link[10];
891 fprintf(out,"<page>\n<title>Manual:%s_%s</title>\n",program,
893 fprintf(out,"<revision>\n");
894 fprintf(out,"<timestamp>%s</timestamp>\n",mydate(buf,255,TRUE));
895 fprintf(out,"<text xml:space=\"preserve\">\n");
897 fprintf(out,"== Description ==\n");
898 print_tty_formatted(out,nldesc,desc,0,links,program,TRUE);
902 fprintf(out,"== Known Problems ==\n");
903 for(i=0; i<nbug; i++) {
904 snew(tmp,strlen(bugs[i])+3);
906 strcpy(tmp+2,bugs[i]);
907 fprintf(out,"%s\n",NWR(tmp));
912 fprintf(out,"\n== Files ==\n");
913 pr_html_files(out,nfile,fnm,program,links,TRUE);
916 fprintf(out,"\n== Options ==\n");
917 fprintf(out," %-12s %-6s %-6s %-s\n",
918 "Option","Type","Value","Description");
919 fprintf(out," ------------------------------------------------------\n");
920 for(i=0; (i<npargs); i++) {
921 tmp = NWR(pargs_print_line(&pa[i],TRUE));
922 fprintf(out,"%s",tmp);
926 fprintf(out,"[[category:Manual_Pages_%s|%s]]\n",VERSION,program);
927 fprintf(out,"</text>\n");
928 fprintf(out,"</revision>\n");
929 fprintf(out,"</page>\n\n");
932 static void write_htmlman(FILE *out,
934 int nldesc,const char **desc,
935 int nfile,t_filenm *fnm,
936 int npargs,t_pargs *pa,
937 int nbug,const char **bugs,
941 char link[10],tmp[255];
943 fprintf(out,"<HTML>\n<HEAD>\n<TITLE>%s</TITLE>\n",program);
944 fprintf(out,"<LINK rel=stylesheet href=\"style.css\" type=\"text/css\">\n");
945 fprintf(out,"<BODY text=\"#000000\" bgcolor=\"#FFFFFF\" link=\"#0000FF\" vlink=\"#990000\" alink=\"#FF0000\">\n");
946 fprintf(out,"<TABLE WIDTH=\"98%%\" NOBORDER >\n<TR><TD WIDTH=400>\n");
947 fprintf(out,"<TABLE WIDTH=400 NOBORDER>\n<TD WIDTH=116>\n");
948 fprintf(out,"<a href=\"http://www.gromacs.org/\">"
949 "<img SRC=\"../images/gmxlogo_small.png\""
950 "BORDER=0 </a></td>\n");
951 fprintf(out,"<td ALIGN=LEFT VALIGN=TOP WIDTH=280>"
952 "<br><h2>%s</h2>",program);
953 fprintf(out,"<font size=-1><A HREF=\"../online.html\">Main Table of Contents</A></font><br>");
954 fprintf(out,"<br></td>\n</TABLE></TD><TD WIDTH=\"*\" ALIGN=RIGHT VALIGN=BOTTOM><p><B>%s<br>\n",GromacsVersion());
955 fprintf(out,"%s</B></td></tr></TABLE>\n<HR>\n",mydate(tmp,255,FALSE));
958 fprintf(out,"<H3>Description</H3>\n<p>\n");
959 for(i=0; (i<nldesc); i++)
960 fprintf(out,"%s\n",NSR(desc[i]));
963 fprintf(out,"<P>\n");
964 fprintf(out,"<H3>Files</H3>\n");
965 pr_html_files(out,nfile,fnm,program,links,FALSE);
968 fprintf(out,"<P>\n");
969 fprintf(out,"<H3>Other options</H3>\n");
971 "<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=2>\n"
976 "<TH>description</TH>"
978 for(i=0; (i<npargs); i++)
981 "<TD ALIGN=RIGHT> <b><tt>%s%s</tt></b> </TD>"
982 "<TD ALIGN=RIGHT> %s </TD>"
983 "<TD ALIGN=RIGHT> <tt>%s</tt> </TD>"
986 (pa[i].type == etBOOL)?"-[no]":"-",pa[i].option+1,
987 argtp[pa[i].type],pa_val(&(pa[i]),tmp,255),NSR(pa[i].desc));
988 fprintf(out,"</TABLE>\n");
991 fprintf(out,"<P>\n");
992 fprintf(out,"<H3>Known problems</H3>\n");
993 fprintf(out,"<UL>\n");
994 for(i=0; (i<nbug); i++)
995 fprintf(out,"<LI>%s\n",NSR(bugs[i]));
996 fprintf(out,"</UL>\n");
998 fprintf(out,"<P>\n");
999 fprintf(out,"<hr>\n<div ALIGN=RIGHT>\n");
1000 fprintf(out,"<font size=\"-1\"><a href=\"http://www.gromacs.org\">"
1001 "http://www.gromacs.org</a></font><br>\n");
1002 fprintf(out,"<font size=\"-1\"><a href=\"mailto:gromacs@gromacs.org\">"
1003 "gromacs@gromacs.org</a></font><br>\n");
1004 fprintf(out,"</div>\n");
1005 fprintf(out,"</BODY>\n");
1008 char *check_xml(const char *s,const char *program,t_linkdata *links)
1012 buf=repall(s,NSRXML,sandrXML);
1013 buf=html_xref(buf,program,links,FALSE); /* the same in html and xml */
1018 static void write_xmlman(FILE *out,
1019 const char *program,
1020 int nldesc,const char **desc,
1021 int nfile,t_filenm *fnm,
1022 int npargs,t_pargs *pa,
1023 int nbug,const char **bugs,
1027 char link[10],buf[256],opt[10];
1029 #define NSR2(s) check_xml(s,program,links)
1030 #define FLAG(w,f) (((w) & (f))==(f))
1032 fprintf(out,"<gromacs-manual version=\"%s\" date=\"%s\" www=\"http://www.gromacs.org\">\n",GromacsVersion(),mydate(buf,255,FALSE));
1033 /* fprintf(out,"<LINK rel=stylesheet href=\"style.css\" type=\"text/css\">\n"); */
1035 fprintf(out,"<program name=\"%s\">",program);
1037 fprintf(out,"\n<description>\n<par>\n");
1038 for(i=0; (i<nldesc); i++)
1039 fprintf(out,"%s\n",NSR2(desc[i]));
1041 fprintf(out,"</par>\n</description>\n");
1044 fprintf(out,"\n<files>\n");
1045 for(i=0; (i<nfile); i++) {
1046 strcpy(link,ftp2ext(fnm[i].ftp));
1047 if (strcmp(link,"???")==0)
1048 strcpy(link,"files");
1049 if (fnm[i].opt[0]=='-') strcpy(opt,fnm[i].opt+1);
1050 else strcpy(opt,fnm[i].opt);
1052 "<file type=\"%s\" typeid=\"%d\">\n"
1053 "\t<flags read=\"%d\" write=\"%d\" optional=\"%d\"/>\n"
1054 "\t<option>%s</option>\n"
1055 "\t<default-name link=\"%s.html\">%s</default-name>\n"
1056 "\t<description>%s</description>\n"
1058 ftp2defnm(fnm[i].ftp), /* from gmxlib/filenm.c */
1060 FLAG(fnm[i].flag,ffREAD), FLAG(fnm[i].flag,ffWRITE), FLAG(fnm[i].flag,ffOPT),
1061 opt,link,fnm[i].fn,/*fileopt(fnm[i].flag),*/
1062 NSR(ftp2desc(fnm[i].ftp)));
1064 fprintf(out,"</files>\n");
1068 fprintf(out,"\n<options>\n");
1069 for(i=0; (i<npargs); i++)
1071 "<option type=\"%s\" hidden=\"%d\">\n"
1072 "\t<name >%s</name>\n"
1073 "\t<default-value>%s</default-value>\n"
1074 "\t<description>%s</description>\n"
1076 argtp[pa[i].type], is_hidden(&pa[i]),
1077 pa[i].option+1, /* +1 - with no trailing '-' */
1078 pa_val(&(pa[i]),buf,255),pa[i].desc); /*argtp[pa[i].type],*/
1079 fprintf(out,"</options>\n");
1083 fprintf(out,"\n<bugs>\n");
1084 for(i=0; (i<nbug); i++)
1085 fprintf(out,"\t<bug>%s</bug>\n",NSR(bugs[i]));
1086 fprintf(out,"</bugs>\n");
1088 fprintf(out,"\n</program>\n</gromacs-manual>\n");
1092 static void pr_opts(FILE *fp,
1093 int nfile, t_filenm *fnm,
1094 int npargs, t_pargs pa[], int shell)
1100 fprintf(fp," \"c/-/(");
1101 for (i=0; i<nfile; i++)
1102 fprintf(fp," %s",fnm[i].opt+1);
1103 for (i=0; i<npargs; i++)
1104 if ( (pa[i].type==etBOOL) && *(pa[i].u.b) )
1105 fprintf(fp," no%s",pa[i].option+1);
1107 fprintf(fp," %s",pa[i].option+1);
1111 fprintf(fp,"if (( $COMP_CWORD <= 1 )) || [[ $c == -* ]]; then COMPREPLY=( $(compgen -W '");
1112 for (i=0; i<nfile; i++)
1113 fprintf(fp," -%s",fnm[i].opt+1);
1114 for (i=0; i<npargs; i++)
1115 if ( (pa[i].type==etBOOL) && *(pa[i].u.b) )
1116 fprintf(fp," -no%s",pa[i].option+1);
1118 fprintf(fp," -%s",pa[i].option+1);
1119 fprintf(fp,"' -- $c)); return 0; fi\n");
1122 fprintf(fp," -x 's[-]' -s \"");
1123 for (i=0; i<nfile; i++)
1124 fprintf(fp," %s",fnm[i].opt+1);
1125 for (i=0; i<npargs; i++)
1126 if ( (pa[i].type==etBOOL) && *(pa[i].u.b) )
1127 fprintf(fp," no%s",pa[i].option+1);
1129 fprintf(fp," %s",pa[i].option+1);
1135 static void write_cshcompl(FILE *out,
1136 int nfile, t_filenm *fnm,
1137 int npargs, t_pargs *pa)
1139 fprintf(out,"complete %s",ShortProgram());
1140 pr_enums(out,npargs,pa,eshellCSH);
1141 pr_fopts(out,nfile,fnm,eshellCSH);
1142 pr_opts(out,nfile,fnm,npargs,pa,eshellCSH);
1146 static void write_zshcompl(FILE *out,
1147 int nfile, t_filenm *fnm,
1148 int npargs, t_pargs *pa)
1150 fprintf(out,"compctl ");
1152 /* start with options, since they are always present */
1153 pr_opts(out,nfile,fnm,npargs,pa,eshellZSH);
1154 pr_enums(out,npargs,pa,eshellZSH);
1155 pr_fopts(out,nfile,fnm,eshellZSH);
1156 fprintf(out,"-- %s\n",ShortProgram());
1159 static void write_bashcompl(FILE *out,
1160 int nfile, t_filenm *fnm,
1161 int npargs, t_pargs *pa)
1163 /* Advanced bash completions are handled by shell functions.
1164 * p and c hold the previous and current word on the command line.
1165 * We need to use extended globbing, so write it in each completion file */
1166 fprintf(out,"shopt -s extglob\n");
1167 fprintf(out,"_%s_compl() {\nlocal p c\n",ShortProgram());
1168 fprintf(out,"COMPREPLY=() c=${COMP_WORDS[COMP_CWORD]} p=${COMP_WORDS[COMP_CWORD-1]}\n");
1169 pr_opts(out,nfile,fnm,npargs,pa,eshellBASH);
1170 fprintf(out,"case \"$p\" in\n");
1172 pr_enums(out,npargs,pa,eshellBASH);
1173 pr_fopts(out,nfile,fnm,eshellBASH);
1174 fprintf(out,"esac }\ncomplete -F _%s_compl %s\n",ShortProgram(),ShortProgram());
1177 static void write_py(FILE *out,const char *program,
1178 int nldesc,const char **desc,
1179 int nfile,t_filenm *fnm,
1180 int npargs,t_pargs *pa,
1181 int nbug,const char **bugs,
1185 const char *cls = program;
1190 fprintf(out,"#!/usr/bin/python\n\nfrom GmxDialog import *\n\n");
1192 /* Class definition */
1193 fprintf(out,"class %s:\n",cls);
1194 fprintf(out," def __init__(self,tk):\n");
1197 fprintf(out," %s_help = \"\"\"\n",cls);
1198 fprintf(out," DESCRIPTION\n");
1199 print_tty_formatted(out,nldesc,desc,8,links,program,FALSE);
1201 fprintf(out,"\n BUGS and PROBLEMS\n");
1202 for(i=0; i<nbug; i++) {
1203 snew(tmp,strlen(bugs[i])+3);
1205 strcpy(tmp+2,check_tty(bugs[i]));
1206 fprintf(out,"%s\n",wrap_lines(tmp,78,10,TRUE));
1210 fprintf(out," \"\"\"\n\n # Command line options\n");
1212 fprintf(out," flags = []\n");
1213 for(i=0; (i<nfile); i++)
1214 fprintf(out," flags.append(pca_file('%s',\"%s\",0,%d))\n",
1215 ftp2ext_generic(fnm[i].ftp),fnm[i].opt ? fnm[i].opt : "k",
1216 is_optional(&(fnm[i])));
1220 for(i=0; (i<npargs); i++) {
1221 switch(pa[i].type) {
1223 fprintf(out," flags.append(pca_int(\"%s\",\"%s\",%d,%d))\n",
1224 pa[i].option,pa[i].desc,*pa[i].u.i,is_hidden(&(pa[i])));
1228 fprintf(out," flags.append(pca_float(\"%s\",\"%s\",%f,%d))\n",
1229 pa[i].option,pa[i].desc,*pa[i].u.r,is_hidden(&(pa[i])));
1233 fprintf(out," flags.append(pca_gmx_bool(\"%s\",\"%s\",%d,%d))\n",
1234 pa[i].option,pa[i].desc,*pa[i].u.b,is_hidden(&(pa[i])));
1237 fprintf(stderr,"Sorry, no rvecs yet...\n");
1240 fprintf(out," flags.append(pca_enum(\"%s\",\"%s\",\n",
1241 pa[i].option,pa[i].desc);
1242 fprintf(out," ['%s'",pa[i].u.c[1]);
1243 for(j=2; (pa[i].u.c[j] != NULL); j++)
1244 fprintf(out,",'%s'",pa[i].u.c[j]);
1245 fprintf(out,"],%d))\n",is_hidden(&(pa[i])));
1252 /* Make the dialog box */
1253 fprintf(out," gmxd = gmx_dialog(tk,\"%s\",flags,%s_help)\n\n",
1257 fprintf(out,"#####################################################\n");
1258 fprintf(out,"tk = Tk()\n");
1259 fprintf(out,"my%s = %s(tk)\n",cls,cls);
1260 fprintf(out,"tk.mainloop()\n");
1263 void write_man(FILE *out,const char *mantp,
1264 const char *program,
1265 int nldesc,const char **desc,
1266 int nfile,t_filenm *fnm,
1267 int npargs,t_pargs *pa,
1268 int nbug,const char **bugs,
1277 links=init_linkdata();
1279 /* Don't write hidden options to completions, it just
1280 * makes the options more complicated for normal users
1290 for(i=0;i<npargs;i++)
1291 if (!is_hidden(&pa[i])) {
1297 if ((pr=strrchr(program,DIR_SEPARATOR)) == NULL)
1301 if (strcmp(mantp,"tex")==0)
1302 write_texman(out,pr,nldesc,desc,nfile,fnm,npar,par,nbug,bugs,links);
1303 if (strcmp(mantp,"nroff")==0)
1304 write_nroffman(out,pr,nldesc,desc,nfile,fnm,npar,par,nbug,bugs,links);
1305 if (strcmp(mantp,"ascii")==0)
1306 write_ttyman(out,pr,nldesc,desc,nfile,fnm,npar,par,nbug,bugs,TRUE,links);
1307 if (strcmp(mantp,"wiki")==0)
1308 write_wikiman(out,pr,nldesc,desc,nfile,fnm,npar,par,nbug,bugs,TRUE,links);
1309 if (strcmp(mantp,"help")==0)
1310 write_ttyman(out,pr,nldesc,desc,nfile,fnm,npar,par,nbug,bugs,FALSE,links);
1311 if (strcmp(mantp,"html")==0)
1312 write_htmlman(out,pr,nldesc,desc,nfile,fnm,npar,par,nbug,bugs,links);
1313 if (strcmp(mantp,"py")==0)
1314 write_py(out,pr,nldesc,desc,nfile,fnm,npar,par,nbug,bugs,links);
1315 if (strcmp(mantp,"xml")==0)
1316 write_xmlman(out,pr,nldesc,desc,nfile,fnm,npargs,pa,nbug,bugs,links);
1317 if (strcmp(mantp,"completion-zsh")==0)
1318 write_zshcompl(out,nfile,fnm,npar,par);
1319 if (strcmp(mantp,"completion-bash")==0)
1320 write_bashcompl(out,nfile,fnm,npar,par);
1321 if (strcmp(mantp,"completion-csh")==0)
1322 write_cshcompl(out,nfile,fnm,npar,par);
1327 finish_linkdata(links);