3 * This source code is part of
7 * GROningen MAchine for Chemical Simulations
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-2004, 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 Mixture of Alchemy and Childrens' Stories
52 /* The source code in this file should be thread-safe.
53 Please keep it that way. */
57 const char *search,*replace;
61 char *search,*replace;
64 /* The order of these arrays is significant. Text search and replace
65 * for each element occurs in order, so earlier changes can induce
66 * subsequent changes even though the original text might not appear
67 * to invoke the latter changes. */
69 const t_sandr_const sandrTeX[] = {
77 /* Escaping underscore for LaTeX is no longer necessary, and it breaks
78 * text searching and the index if you do. */
83 { "<=", "\\ensuremath{\\leq{}}"},
84 { ">=", "\\ensuremath{\\geq{}}"},
85 { "<", "\\textless{}" },
86 { ">", "\\textgreater{}" },
88 { "\\^{}t", "\\ensuremath{^t}" },
89 { "\\^{}a", "\\ensuremath{^a}" },
90 { "\\^{}b", "\\ensuremath{^b}" },
91 { "\\^{}2", "\\ensuremath{^2}" },
92 { "\\^{}3", "\\ensuremath{^3}" },
93 { "\\^{}6", "\\ensuremath{^6}" },
98 /* The next couple of lines allow true Greek symbols to be written to the
99 manual, which makes it look pretty */
100 { "[GRK]", "\\ensuremath{\\" },
102 { "[MATH]","\\ensuremath{" },
104 { "[CHEVRON]", "\\ensuremath{<}" },
105 { "[chevron]", "\\ensuremath{>}" },
106 { "[MAG]", "\\ensuremath{|}" },
107 { "[mag]", "\\ensuremath{|}" },
108 { "[INT]","\\ensuremath{\\int" },
114 { "[SUM]","\\ensuremath{\\sum" },
116 { "[SUB]","\\ensuremath{_{" },
118 { "[SQRT]","\\ensuremath{\\sqrt{" },
120 { "[EXP]","\\ensuremath{\\exp{(" },
122 { "[LN]","\\ensuremath{\\ln{(" },
124 { "[LOG]","\\ensuremath{\\log{(" },
126 { "[COS]","\\ensuremath{\\cos{(" },
128 { "[SIN]","\\ensuremath{\\sin{(" },
130 { "[TAN]","\\ensuremath{\\tan{(" },
132 { "[COSH]","\\ensuremath{\\cosh{(" },
134 { "[SINH]","\\ensuremath{\\sinh{(" },
136 { "[TANH]","\\ensuremath{\\tanh{(" },
139 #define NSRTEX asize(sandrTeX)
141 const t_sandr_const sandrTty[] = {
154 { "[INT]","integral" },
155 { "[FROM]"," from " },
164 { "[SQRT]","sqrt(" },
178 { "[COSH]","cosh(" },
180 { "[SINH]","sinh(" },
182 { "[TANH]","tanh(" },
189 #define NSRTTY asize(sandrTty)
191 const t_sandr_const sandrWiki[] = {
195 { "[TT]", "<code>" },
196 { "[tt]", "</code>" },
207 { "[INT]","integral" },
208 { "[FROM]"," from " },
217 { "[SQRT]","sqrt(" },
231 { "[COSH]","cosh(" },
233 { "[SINH]","sinh(" },
235 { "[TANH]","tanh(" },
242 #define NSRWIKI asize(sandrWiki)
244 const t_sandr_const sandrNROFF[] = {
257 { "[INT]","integral" },
258 { "[FROM]"," from " },
267 { "[SQRT]","sqrt(" },
281 { "[COSH]","cosh(" },
283 { "[SINH]","sinh(" },
285 { "[TANH]","tanh(" },
298 #define NSRNROFF asize(sandrNROFF)
300 const t_sandr_const sandrHTML[] = {
315 { "[INT]","integral" },
316 { "[FROM]"," from " },
325 { "[SQRT]","sqrt(" },
339 { "[COSH]","cosh(" },
341 { "[SINH]","sinh(" },
343 { "[TANH]","tanh(" },
350 #define NSRHTML asize(sandrHTML)
352 const t_sandr_const sandrXML[] = {
356 { "[tt]", "</arg>" },
358 { "[bb]", "</emp>" },
367 { "[INT]","integral" },
368 { "[FROM]"," from " },
377 { "[SQRT]","sqrt(" },
391 { "[COSH]","cosh(" },
393 { "[SINH]","sinh(" },
395 { "[TANH]","tanh(" },
397 { "[PAR]","</par>\n<par>" },
398 { "[BR]", "<br />" },
402 #define NSRXML asize(sandrXML)
404 static void mynum(char *buf,int n)
407 sprintf(buf,"%2d",n);
409 sprintf(buf,"0%1d",n);
412 static char *mydate(char buf[], int maxsize,gmx_bool bWiki)
414 const char *mon[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun",
415 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
416 const char *day[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
417 const char *num[] = { "01", "02", "03", "04", "05", "06","07", "08", "09" };
422 #if ((defined WIN32 || defined _WIN32 || defined WIN64 || defined _WIN64) && !defined __CYGWIN__ && !defined __CYGWIN32__)
424 localtime_s(&tm,&now);
426 localtime_r(&now,&tm);
429 /* subtract one from maxsize, so we have room for \0. */
431 char dd[8],mm[8],ss[8],hh[8],mn[8];
433 mynum(dd,tm.tm_mday);
436 mynum(hh,tm.tm_hour);
438 sprintf(buf,"%4d-%2s-%2sT%2s:%2s:%2sZ",
439 tm.tm_year+1900,mm,dd,hh,mn,ss);
442 sprintf(buf,"%s %d %s %d",day[tm.tm_wday],tm.tm_mday,
443 mon[tm.tm_mon],tm.tm_year+1900);
448 /* Data structure for saved HTML links */
449 typedef struct t_linkdata {
454 static t_linkdata *init_linkdata()
464 static void finish_linkdata(t_linkdata *p)
468 for(i=0;i<p->nsr;i++) {
469 sfree(p->sr[i].search);
470 sfree(p->sr[i].replace);
476 static char *repall(const char *s,int nsr,const t_sandr_const sa[])
481 /* Copy input to a non-constant char buffer.
482 * buf1 is allocated here
486 for(i=0; (i<nsr); i++) {
487 /* Replace in buffer1, put result in buffer2.
488 * buf2 is allocated here.
490 buf2=replace(buf1,sa[i].search,sa[i].replace);
498 static char *repallww(const char *s,int nsr,const t_sandr sa[])
503 /* Copy input to a non-constant char buffer.
504 * buf1 is allocated here
508 for(i=0; (i<nsr); i++) {
509 /* Replace in buffer1, put result in buffer2.
510 * buf2 is allocated here.
512 buf2=replaceww(buf1,sa[i].search,sa[i].replace);
519 static char *html_xref(char *s,const char *program, t_linkdata *links,gmx_bool bWiki)
521 char buf[256],**filestr;
524 if (links->sr == NULL) {
525 n=get_file("links.dat",&(filestr));
528 for(i=0,j=0; (i<n); i++) {
529 if (!program || (gmx_strcasecmp(program,filestr[i]) != 0)) {
530 links->sr[j].search=gmx_strdup(filestr[i]);
532 sprintf(buf,"[[%s]]",filestr[i]);
534 sprintf(buf,"<a href=\"%s.html\">%s</a>",filestr[i],filestr[i]);
535 links->sr[j].replace=gmx_strdup(buf);
544 return repallww(s,links->nsr,links->sr);
547 char *check_tex(const char *s)
549 return repall(s,NSRTEX,sandrTeX);
552 static char *check_nroff(const char *s)
554 return repall(s,NSRNROFF,sandrNROFF);
557 static char *check_wiki(const char *s,const char *program, t_linkdata *links)
561 buf = repall(s,NSRWIKI,sandrWiki);
562 buf = html_xref(buf,program,links,TRUE);
567 static char *check_html(const char *s,const char *program, t_linkdata *links)
571 buf = repall(s,NSRHTML,sandrHTML);
572 buf = html_xref(buf,program,links,FALSE);
577 #define NWR(s) check_wiki(s,program,links)
578 #define NSR(s) check_html(s,program,links)
580 #define FLAG_SET(flag, mask) ((flag & mask) == mask)
581 char *fileopt(unsigned long flag,char buf[],int maxsize)
585 if (FLAG_SET(flag, ffRW))
586 sprintf(tmp,"In/Out");
587 else if (FLAG_SET(flag, ffREAD))
588 sprintf(tmp,"Input");
589 else if (FLAG_SET(flag, ffWRITE))
590 sprintf(tmp,"Output");
592 sprintf(tmp,"Dunno");
594 if (FLAG_SET(flag, ffOPT)) {
596 if (FLAG_SET(flag, ffSET))
601 if (FLAG_SET(flag, ffLIB))
602 strcat(tmp,", Lib.");
603 if (FLAG_SET(flag, ffMULT))
604 strcat(tmp,", Mult.");
606 sprintf(buf,"%s",tmp);
611 static void write_texman(FILE *out,const char *program,
612 int nldesc,const char **desc,
613 int nfile,t_filenm *fnm,
614 int npargs,t_pargs *pa,
615 int nbug,const char **bugs,
621 fprintf(out,"\\section{\\normindex{%s}}\\label{%s}\n\n",check_tex(program),check_tex(program));
624 for(i=0; (i<nldesc); i++)
625 fprintf(out,"%s\n",check_tex(desc[i]));
628 fprintf(out,"\\vspace{-2ex}\\begin{tabbing}\n");
629 fprintf(out,"\n{\\normalsize \\bf Files}\\nopagebreak\\\\\n");
630 fprintf(out,"{\\tt ~~~~~~~} \\= {\\tt ~~~~~~~~~~~~~~} \\= "
631 "~~~~~~~~~~~~~~~~~~~~~~ \\= \\nopagebreak\\kill\n");
632 for(i=0; (i<nfile); i++)
633 fprintf(out,"\\>{\\tt %s} \\'\\> {\\tt %s} \\' %s \\> "
634 "\\parbox[t]{0.55\\linewidth}{%s} \\\\\n",
635 check_tex(fnm[i].opt),check_tex(fnm[i].fns[0]),
636 check_tex(fileopt(fnm[i].flag,tmp,255)),
637 check_tex(ftp2desc(fnm[i].ftp)));
638 fprintf(out,"\\end{tabbing}\\vspace{-4ex}\n");
641 fprintf(out,"\\vspace{-2ex}\\begin{tabbing}\n");
642 fprintf(out,"\n{\\normalsize \\bf Other options}\\nopagebreak\\\\\n");
643 fprintf(out,"{\\tt ~~~~~~~~~~} \\= vector \\= "
644 "{\\tt ~~~~~~~} \\= \\nopagebreak\\kill\n");
645 for(i=0; (i<npargs); i++) {
646 if (strlen(check_tex(pa_val(&(pa[i]),tmp,255))) <= 8)
647 fprintf(out,"\\> {\\tt %s} \\'\\> %s \\'\\> {\\tt %s} \\' "
648 "\\parbox[t]{0.68\\linewidth}{%s}\\\\\n",
649 check_tex(pa[i].option),argtp[pa[i].type],
650 check_tex(pa_val(&(pa[i]),tmp,255)),
651 check_tex(pa[i].desc));
653 fprintf(out,"\\> {\\tt %s} \\'\\> %s \\'\\>\\\\\n"
654 "\\> \\'\\> \\'\\> {\\tt %s} \\' "
655 "\\parbox[t]{0.7\\linewidth}{%s}\\\\\n",
656 check_tex(pa[i].option),argtp[pa[i].type],
657 check_tex(pa_val(&(pa[i]),tmp,255)),
658 check_tex(pa[i].desc));
660 fprintf(out,"\\end{tabbing}\\vspace{-4ex}\n");
664 fprintf(out,"\\begin{itemize}\n");
665 for(i=0; (i<nbug); i++)
666 fprintf(out,"\\item %s\n",check_tex(bugs[i]));
667 fprintf(out,"\\end{itemize}\n");
669 /* fprintf(out,"\n\\newpage\n"); */
672 static void write_nroffman(FILE *out,
674 int nldesc,const char **desc,
675 int nfile,t_filenm *fnm,
676 int npargs,t_pargs *pa,
677 int nbug,const char **bugs,
685 fprintf(out,".TH %s 1 \"%s\" \"\" \"GROMACS suite, %s\"\n",program,mydate(tmp,255,FALSE),GromacsVersion());
686 fprintf(out,".SH NAME\n");
687 fprintf(out,"%s\n",program);
688 fprintf(out,".B %s\n",GromacsVersion());
690 fprintf(out,".SH SYNOPSIS\n");
691 fprintf(out,"\\f3%s\\fP\n",program);
693 /* command line arguments */
695 for(i=0; (i<nfile); i++)
696 fprintf(out,".BI \"%s\" \" %s \"\n",check_nroff(fnm[i].opt),
697 check_nroff(fnm[i].fns[0]));
700 for(i=0; (i<npargs); i++)
701 if (pa[i].type == etBOOL)
702 fprintf(out,".BI \"\\-[no]%s\" \"\"\n",check_nroff(pa[i].option+1));
704 fprintf(out,".BI \"%s\" \" %s \"\n",check_nroff(pa[i].option),
705 check_nroff(argtp[pa[i].type]));
710 fprintf(out,".SH DESCRIPTION\n");
711 for(i=0; (i<nldesc); i++)
712 fprintf(out,"\\&%s\n",check_nroff(desc[i]));
717 fprintf(out,".SH FILES\n");
718 for(i=0; (i<nfile); i++)
719 fprintf(out,".BI \"%s\" \" %s\" \n.B %s\n %s \n\n",
720 check_nroff(fnm[i].opt),
721 check_nroff(fnm[i].fns[0]),
722 check_nroff(fileopt(fnm[i].flag,tmp,255)),
723 check_nroff(ftp2desc(fnm[i].ftp)));
727 fprintf(out,".SH OTHER OPTIONS\n");
729 for(i=0; (i<npargs); i++) {
730 if (pa[i].type == etBOOL)
731 fprintf(out,".BI \"\\-[no]%s\" \"%s\"\n %s\n\n",
732 check_nroff(pa[i].option+1),
733 check_nroff(pa_val(&(pa[i]),tmp,255)),
734 check_nroff(pa[i].desc));
736 fprintf(out,".BI \"%s\" \" %s\" \" %s\" \n %s\n\n",
737 check_nroff(pa[i].option),
738 check_nroff(argtp[pa[i].type]),
739 check_nroff(pa_val(&(pa[i]),tmp,255)),
740 check_nroff(pa[i].desc));
745 fprintf(out,".SH KNOWN PROBLEMS\n");
746 for(i=0; (i<nbug); i++)
747 fprintf(out,"\\- %s\n\n",check_nroff(bugs[i]));
750 fprintf(out,".SH SEE ALSO\n.BR gromacs(7)\n\n");
751 fprintf(out,"More information about \\fBGROMACS\\fR is available at <\\fIhttp://www.gromacs.org/\\fR>.\n");
755 char *check_tty(const char *s)
757 return repall(s,NSRTTY,sandrTty);
761 print_tty_formatted(FILE *out, int nldesc, const char **desc,int indent,
762 t_linkdata *links,const char *program,gmx_bool bWiki)
770 for(i=0; (i<nldesc); i++) {
771 if ((strlen(buf)>0) &&
772 (buf[strlen(buf)-1] !=' ') && (buf[strlen(buf)-1] !='\n'))
777 temp=check_tty(desc[i]);
778 if (strlen(buf) + strlen(temp) >= (size_t)(buflen-2)) {
779 buflen += strlen(temp);
785 /* Make lines of at most 79 characters */
786 temp = wrap_lines(buf,78,indent,FALSE);
787 fprintf(out,"%s\n",temp);
792 static void write_ttyman(FILE *out,
794 int nldesc,const char **desc,
795 int nfile,t_filenm *fnm,
796 int npargs,t_pargs *pa,
797 int nbug,const char **bugs,gmx_bool bHeader,
805 fprintf(out,"%s\n\n",check_tty(program));
806 fprintf(out,"%s\n%s\n",GromacsVersion(),mydate(buf,255,FALSE));
809 fprintf(out,"DESCRIPTION\n-----------\n");
810 print_tty_formatted(out,nldesc,desc,0,links,program,FALSE);
814 fprintf(out,"KNOWN PROBLEMS\n----------\n");
815 for(i=0; i<nbug; i++) {
816 snew(tmp,strlen(bugs[i])+3);
818 strcpy(tmp+2,check_tty(bugs[i]));
819 fprintf(out,"%s\n",wrap_lines(tmp,78,2,FALSE));
825 pr_fns(out,nfile,fnm);
828 print_pargs(out,npargs,pa,FALSE);
832 static void pr_html_files(FILE *out,int nfile,t_filenm fnm[],
833 const char *program,t_linkdata *links,gmx_bool bWiki)
836 char link[10],tmp[255];
839 fprintf(out," %-10s %-12s %-12s %-s\n"
840 " -----------------------------------------------------\n",
841 "Option","Filename","Type","Description");
844 "<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=2>\n"
849 "<TH>description</TH>"
852 for(i=0; (i<nfile); i++) {
853 strcpy(link,ftp2ext(fnm[i].ftp));
854 if (strcmp(link,"???")==0)
855 strcpy(link,"files");
857 fprintf(out," %-10s %-16s %-12s %-s\n",
860 fileopt(fnm[i].flag,tmp,255),
861 NWR(ftp2desc(fnm[i].ftp)));
865 "<TD ALIGN=RIGHT> <b><tt>%s</tt></b> </TD>"
866 "<TD ALIGN=RIGHT> <tt><a href=\"%s.html\">%12s</a></tt> </TD>"
870 fnm[i].opt,link,fnm[i].fns[0],fileopt(fnm[i].flag,tmp,255),
871 NSR(ftp2desc(fnm[i].ftp)));
874 fprintf(out,"</TABLE>\n");
877 static void write_wikiman(FILE *out,
879 int nldesc,const char **desc,
880 int nfile,t_filenm *fnm,
881 int npargs,t_pargs *pa,
882 int nbug,const char **bugs,gmx_bool bHeader,
886 char buf[256],link[10];
888 fprintf(out,"<page>\n<title>Manual:%s_%s</title>\n",program,
890 fprintf(out,"<revision>\n");
891 fprintf(out,"<timestamp>%s</timestamp>\n",mydate(buf,255,TRUE));
892 fprintf(out,"<text xml:space=\"preserve\">\n");
894 fprintf(out,"== Description ==\n");
895 print_tty_formatted(out,nldesc,desc,0,links,program,TRUE);
899 fprintf(out,"== Known Problems ==\n");
900 for(i=0; i<nbug; i++) {
901 snew(tmp,strlen(bugs[i])+3);
903 strcpy(tmp+2,bugs[i]);
904 fprintf(out,"%s\n",NWR(tmp));
909 fprintf(out,"\n== Files ==\n");
910 pr_html_files(out,nfile,fnm,program,links,TRUE);
913 fprintf(out,"\n== Options ==\n");
914 fprintf(out," %-12s %-6s %-6s %-s\n",
915 "Option","Type","Value","Description");
916 fprintf(out," ------------------------------------------------------\n");
917 for(i=0; (i<npargs); i++) {
918 tmp = NWR(pargs_print_line(&pa[i],TRUE));
919 fprintf(out,"%s",tmp);
923 fprintf(out,"[[category:Manual_Pages_%s|%s]]\n",VERSION,program);
924 fprintf(out,"</text>\n");
925 fprintf(out,"</revision>\n");
926 fprintf(out,"</page>\n\n");
929 static void write_htmlman(FILE *out,
931 int nldesc,const char **desc,
932 int nfile,t_filenm *fnm,
933 int npargs,t_pargs *pa,
934 int nbug,const char **bugs,
938 char link[10],tmp[255];
940 fprintf(out,"<HTML>\n<HEAD>\n<TITLE>%s</TITLE>\n",program);
941 fprintf(out,"<LINK rel=stylesheet href=\"style.css\" type=\"text/css\">\n");
942 fprintf(out,"<BODY text=\"#000000\" bgcolor=\"#FFFFFF\" link=\"#0000FF\" vlink=\"#990000\" alink=\"#FF0000\">\n");
943 fprintf(out,"<TABLE WIDTH=\"98%%\" NOBORDER >\n<TR><TD WIDTH=400>\n");
944 fprintf(out,"<TABLE WIDTH=400 NOBORDER>\n<TD WIDTH=116>\n");
945 fprintf(out,"<a href=\"http://www.gromacs.org/\">"
946 "<img SRC=\"../images/gmxlogo_small.png\""
947 "BORDER=0 </a></td>\n");
948 fprintf(out,"<td ALIGN=LEFT VALIGN=TOP WIDTH=280>"
949 "<br><h2>%s</h2>",program);
950 fprintf(out,"<font size=-1><A HREF=\"../online.html\">Main Table of Contents</A></font><br>");
951 fprintf(out,"<br></td>\n</TABLE></TD><TD WIDTH=\"*\" ALIGN=RIGHT VALIGN=BOTTOM><p><B>%s<br>\n",GromacsVersion());
952 fprintf(out,"%s</B></td></tr></TABLE>\n<HR>\n",mydate(tmp,255,FALSE));
955 fprintf(out,"<H3>Description</H3>\n<p>\n");
956 for(i=0; (i<nldesc); i++)
957 fprintf(out,"%s\n",NSR(desc[i]));
960 fprintf(out,"<P>\n");
961 fprintf(out,"<H3>Files</H3>\n");
962 pr_html_files(out,nfile,fnm,program,links,FALSE);
965 fprintf(out,"<P>\n");
966 fprintf(out,"<H3>Other options</H3>\n");
968 "<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=2>\n"
973 "<TH>description</TH>"
975 for(i=0; (i<npargs); i++)
978 "<TD ALIGN=RIGHT> <b><tt>%s%s</tt></b> </TD>"
979 "<TD ALIGN=RIGHT> %s </TD>"
980 "<TD ALIGN=RIGHT> <tt>%s</tt> </TD>"
983 (pa[i].type == etBOOL)?"-[no]":"-",pa[i].option+1,
984 argtp[pa[i].type],pa_val(&(pa[i]),tmp,255),NSR(pa[i].desc));
985 fprintf(out,"</TABLE>\n");
988 fprintf(out,"<P>\n");
989 fprintf(out,"<H3>Known problems</H3>\n");
990 fprintf(out,"<UL>\n");
991 for(i=0; (i<nbug); i++)
992 fprintf(out,"<LI>%s\n",NSR(bugs[i]));
993 fprintf(out,"</UL>\n");
995 fprintf(out,"<P>\n");
996 fprintf(out,"<hr>\n<div ALIGN=RIGHT>\n");
997 fprintf(out,"<font size=\"-1\"><a href=\"http://www.gromacs.org\">"
998 "http://www.gromacs.org</a></font><br>\n");
999 fprintf(out,"<font size=\"-1\"><a href=\"mailto:gromacs@gromacs.org\">"
1000 "gromacs@gromacs.org</a></font><br>\n");
1001 fprintf(out,"</div>\n");
1002 fprintf(out,"</BODY>\n");
1005 char *check_xml(const char *s,const char *program,t_linkdata *links)
1009 buf=repall(s,NSRXML,sandrXML);
1010 buf=html_xref(buf,program,links,FALSE); /* the same in html and xml */
1015 static void write_xmlman(FILE *out,
1016 const char *program,
1017 int nldesc,const char **desc,
1018 int nfile,t_filenm *fnm,
1019 int npargs,t_pargs *pa,
1020 int nbug,const char **bugs,
1024 char link[10],buf[256],opt[10];
1026 #define NSR2(s) check_xml(s,program,links)
1027 #define FLAG(w,f) (((w) & (f))==(f))
1029 fprintf(out,"<gromacs-manual version=\"%s\" date=\"%s\" www=\"http://www.gromacs.org\">\n",GromacsVersion(),mydate(buf,255,FALSE));
1030 /* fprintf(out,"<LINK rel=stylesheet href=\"style.css\" type=\"text/css\">\n"); */
1032 fprintf(out,"<program name=\"%s\">",program);
1034 fprintf(out,"\n<description>\n<par>\n");
1035 for(i=0; (i<nldesc); i++)
1036 fprintf(out,"%s\n",NSR2(desc[i]));
1038 fprintf(out,"</par>\n</description>\n");
1041 fprintf(out,"\n<files>\n");
1042 for(i=0; (i<nfile); i++) {
1043 strcpy(link,ftp2ext(fnm[i].ftp));
1044 if (strcmp(link,"???")==0)
1045 strcpy(link,"files");
1046 if (fnm[i].opt[0]=='-') strcpy(opt,fnm[i].opt+1);
1047 else strcpy(opt,fnm[i].opt);
1049 "<file type=\"%s\" typeid=\"%d\">\n"
1050 "\t<flags read=\"%d\" write=\"%d\" optional=\"%d\"/>\n"
1051 "\t<option>%s</option>\n"
1052 "\t<default-name link=\"%s.html\">%s</default-name>\n"
1053 "\t<description>%s</description>\n"
1055 ftp2defnm(fnm[i].ftp), /* from gmxlib/filenm.c */
1057 FLAG(fnm[i].flag,ffREAD), FLAG(fnm[i].flag,ffWRITE), FLAG(fnm[i].flag,ffOPT),
1058 opt,link,fnm[i].fn,/*fileopt(fnm[i].flag),*/
1059 NSR(ftp2desc(fnm[i].ftp)));
1061 fprintf(out,"</files>\n");
1065 fprintf(out,"\n<options>\n");
1066 for(i=0; (i<npargs); i++)
1068 "<option type=\"%s\" hidden=\"%d\">\n"
1069 "\t<name >%s</name>\n"
1070 "\t<default-value>%s</default-value>\n"
1071 "\t<description>%s</description>\n"
1073 argtp[pa[i].type], is_hidden(&pa[i]),
1074 pa[i].option+1, /* +1 - with no trailing '-' */
1075 pa_val(&(pa[i]),buf,255),pa[i].desc); /*argtp[pa[i].type],*/
1076 fprintf(out,"</options>\n");
1080 fprintf(out,"\n<bugs>\n");
1081 for(i=0; (i<nbug); i++)
1082 fprintf(out,"\t<bug>%s</bug>\n",NSR(bugs[i]));
1083 fprintf(out,"</bugs>\n");
1085 fprintf(out,"\n</program>\n</gromacs-manual>\n");
1089 static void pr_opts(FILE *fp,
1090 int nfile, t_filenm *fnm,
1091 int npargs, t_pargs pa[], int shell)
1097 fprintf(fp," \"c/-/(");
1098 for (i=0; i<nfile; i++)
1099 fprintf(fp," %s",fnm[i].opt+1);
1100 for (i=0; i<npargs; i++)
1101 if ( (pa[i].type==etBOOL) && *(pa[i].u.b) )
1102 fprintf(fp," no%s",pa[i].option+1);
1104 fprintf(fp," %s",pa[i].option+1);
1108 fprintf(fp,"if (( $COMP_CWORD <= 1 )) || [[ $c == -* ]]; then COMPREPLY=( $(compgen -W '");
1109 for (i=0; i<nfile; i++)
1110 fprintf(fp," -%s",fnm[i].opt+1);
1111 for (i=0; i<npargs; i++)
1112 if ( (pa[i].type==etBOOL) && *(pa[i].u.b) )
1113 fprintf(fp," -no%s",pa[i].option+1);
1115 fprintf(fp," -%s",pa[i].option+1);
1116 fprintf(fp,"' -- $c)); return 0; fi\n");
1119 fprintf(fp," -x 's[-]' -s \"");
1120 for (i=0; i<nfile; i++)
1121 fprintf(fp," %s",fnm[i].opt+1);
1122 for (i=0; i<npargs; i++)
1123 if ( (pa[i].type==etBOOL) && *(pa[i].u.b) )
1124 fprintf(fp," no%s",pa[i].option+1);
1126 fprintf(fp," %s",pa[i].option+1);
1132 static void write_cshcompl(FILE *out,
1133 int nfile, t_filenm *fnm,
1134 int npargs, t_pargs *pa)
1136 fprintf(out,"complete %s",ShortProgram());
1137 pr_enums(out,npargs,pa,eshellCSH);
1138 pr_fopts(out,nfile,fnm,eshellCSH);
1139 pr_opts(out,nfile,fnm,npargs,pa,eshellCSH);
1143 static void write_zshcompl(FILE *out,
1144 int nfile, t_filenm *fnm,
1145 int npargs, t_pargs *pa)
1147 fprintf(out,"compctl ");
1149 /* start with options, since they are always present */
1150 pr_opts(out,nfile,fnm,npargs,pa,eshellZSH);
1151 pr_enums(out,npargs,pa,eshellZSH);
1152 pr_fopts(out,nfile,fnm,eshellZSH);
1153 fprintf(out,"-- %s\n",ShortProgram());
1156 static void write_bashcompl(FILE *out,
1157 int nfile, t_filenm *fnm,
1158 int npargs, t_pargs *pa)
1160 /* Advanced bash completions are handled by shell functions.
1161 * p and c hold the previous and current word on the command line.
1162 * We need to use extended globbing, so write it in each completion file */
1163 fprintf(out,"shopt -s extglob\n");
1164 fprintf(out,"_%s_compl() {\nlocal p c\n",ShortProgram());
1165 fprintf(out,"COMPREPLY=() c=${COMP_WORDS[COMP_CWORD]} p=${COMP_WORDS[COMP_CWORD-1]}\n");
1166 pr_opts(out,nfile,fnm,npargs,pa,eshellBASH);
1167 fprintf(out,"case \"$p\" in\n");
1169 pr_enums(out,npargs,pa,eshellBASH);
1170 pr_fopts(out,nfile,fnm,eshellBASH);
1171 fprintf(out,"esac }\ncomplete -F _%s_compl %s\n",ShortProgram(),ShortProgram());
1174 static void write_py(FILE *out,const char *program,
1175 int nldesc,const char **desc,
1176 int nfile,t_filenm *fnm,
1177 int npargs,t_pargs *pa,
1178 int nbug,const char **bugs,
1182 const char *cls = program;
1187 fprintf(out,"#!/usr/bin/python\n\nfrom GmxDialog import *\n\n");
1189 /* Class definition */
1190 fprintf(out,"class %s:\n",cls);
1191 fprintf(out," def __init__(self,tk):\n");
1194 fprintf(out," %s_help = \"\"\"\n",cls);
1195 fprintf(out," DESCRIPTION\n");
1196 print_tty_formatted(out,nldesc,desc,8,links,program,FALSE);
1198 fprintf(out,"\n BUGS and PROBLEMS\n");
1199 for(i=0; i<nbug; i++) {
1200 snew(tmp,strlen(bugs[i])+3);
1202 strcpy(tmp+2,check_tty(bugs[i]));
1203 fprintf(out,"%s\n",wrap_lines(tmp,78,10,TRUE));
1207 fprintf(out," \"\"\"\n\n # Command line options\n");
1209 fprintf(out," flags = []\n");
1210 for(i=0; (i<nfile); i++)
1211 fprintf(out," flags.append(pca_file('%s',\"%s\",0,%d))\n",
1212 ftp2ext_generic(fnm[i].ftp),fnm[i].opt ? fnm[i].opt : "k",
1213 is_optional(&(fnm[i])));
1217 for(i=0; (i<npargs); i++) {
1218 switch(pa[i].type) {
1220 fprintf(out," flags.append(pca_int(\"%s\",\"%s\",%d,%d))\n",
1221 pa[i].option,pa[i].desc,*pa[i].u.i,is_hidden(&(pa[i])));
1225 fprintf(out," flags.append(pca_float(\"%s\",\"%s\",%f,%d))\n",
1226 pa[i].option,pa[i].desc,*pa[i].u.r,is_hidden(&(pa[i])));
1230 fprintf(out," flags.append(pca_gmx_bool(\"%s\",\"%s\",%d,%d))\n",
1231 pa[i].option,pa[i].desc,*pa[i].u.b,is_hidden(&(pa[i])));
1234 fprintf(stderr,"Sorry, no rvecs yet...\n");
1237 fprintf(out," flags.append(pca_enum(\"%s\",\"%s\",\n",
1238 pa[i].option,pa[i].desc);
1239 fprintf(out," ['%s'",pa[i].u.c[1]);
1240 for(j=2; (pa[i].u.c[j] != NULL); j++)
1241 fprintf(out,",'%s'",pa[i].u.c[j]);
1242 fprintf(out,"],%d))\n",is_hidden(&(pa[i])));
1249 /* Make the dialog box */
1250 fprintf(out," gmxd = gmx_dialog(tk,\"%s\",flags,%s_help)\n\n",
1254 fprintf(out,"#####################################################\n");
1255 fprintf(out,"tk = Tk()\n");
1256 fprintf(out,"my%s = %s(tk)\n",cls,cls);
1257 fprintf(out,"tk.mainloop()\n");
1260 void write_man(FILE *out,const char *mantp,
1261 const char *program,
1262 int nldesc,const char **desc,
1263 int nfile,t_filenm *fnm,
1264 int npargs,t_pargs *pa,
1265 int nbug,const char **bugs,
1274 links=init_linkdata();
1276 /* Don't write hidden options to completions, it just
1277 * makes the options more complicated for normal users
1287 for(i=0;i<npargs;i++)
1288 if (!is_hidden(&pa[i])) {
1294 if ((pr=strrchr(program,DIR_SEPARATOR)) == NULL)
1298 if (strcmp(mantp,"tex")==0)
1299 write_texman(out,pr,nldesc,desc,nfile,fnm,npar,par,nbug,bugs,links);
1300 if (strcmp(mantp,"nroff")==0)
1301 write_nroffman(out,pr,nldesc,desc,nfile,fnm,npar,par,nbug,bugs,links);
1302 if (strcmp(mantp,"ascii")==0)
1303 write_ttyman(out,pr,nldesc,desc,nfile,fnm,npar,par,nbug,bugs,TRUE,links);
1304 if (strcmp(mantp,"wiki")==0)
1305 write_wikiman(out,pr,nldesc,desc,nfile,fnm,npar,par,nbug,bugs,TRUE,links);
1306 if (strcmp(mantp,"help")==0)
1307 write_ttyman(out,pr,nldesc,desc,nfile,fnm,npar,par,nbug,bugs,FALSE,links);
1308 if (strcmp(mantp,"html")==0)
1309 write_htmlman(out,pr,nldesc,desc,nfile,fnm,npar,par,nbug,bugs,links);
1310 if (strcmp(mantp,"py")==0)
1311 write_py(out,pr,nldesc,desc,nfile,fnm,npar,par,nbug,bugs,links);
1312 if (strcmp(mantp,"xml")==0)
1313 write_xmlman(out,pr,nldesc,desc,nfile,fnm,npargs,pa,nbug,bugs,links);
1314 if (strcmp(mantp,"completion-zsh")==0)
1315 write_zshcompl(out,nfile,fnm,npar,par);
1316 if (strcmp(mantp,"completion-bash")==0)
1317 write_bashcompl(out,nfile,fnm,npar,par);
1318 if (strcmp(mantp,"completion-csh")==0)
1319 write_cshcompl(out,nfile,fnm,npar,par);
1324 finish_linkdata(links);