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 const t_sandr_const sandrTeX[] = {
72 /* Escaping underscore for LaTeX is no longer necessary, and it breaks
73 * text searching and the index if you do. */
78 { "<=", "\\ensuremath{\\leq{}}"},
79 { ">=", "\\ensuremath{\\geq{}}"},
80 { "<", "\\textless{}" },
81 { ">", "\\textgreater{}" },
83 { "\\^{}t", "\\ensuremath{^t}" },
84 { "\\^{}a", "\\ensuremath{^a}" },
85 { "\\^{}b", "\\ensuremath{^b}" },
86 { "\\^{}2", "\\ensuremath{^2}" },
87 { "\\^{}3", "\\ensuremath{^3}" },
88 { "\\^{}6", "\\ensuremath{^6}" },
93 /* The next couple of lines allow true Greek symbols to be written to the
94 manual, which makes it look pretty */
97 /* The next two lines used to substitute "|" and "||" to "or", but only
98 * g_angle used that functionality, so that was changed to a textual
99 * "or" there, so that other places could use those symbols to indicate
101 { "||", "\\textbar{}\\textbar" },
102 { "|", "\\textbar{}" }
104 #define NSRTEX asize(sandrTeX)
106 const t_sandr_const sandrTty[] = {
118 #define NSRTTY asize(sandrTty)
120 const t_sandr_const sandrWiki[] = {
124 { "[TT]", "<code>" },
125 { "[tt]", "</code>" },
133 #define NSRWIKI asize(sandrWiki)
135 const t_sandr_const sandrNROFF[] = {
151 #define NSRNROFF asize(sandrNROFF)
153 const t_sandr_const sandrHTML[] = {
167 #define NSRHTML asize(sandrHTML)
169 const t_sandr_const sandrXML[] = {
173 { "[tt]", "</arg>" },
175 { "[bb]", "</emp>" },
178 { "[PAR]","</par>\n<par>" },
181 #define NSRXML asize(sandrXML)
183 static void mynum(char *buf,int n)
186 sprintf(buf,"%2d",n);
188 sprintf(buf,"0%1d",n);
191 static char *mydate(char buf[], int maxsize,gmx_bool bWiki)
193 const char *mon[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun",
194 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
195 const char *day[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
196 const char *num[] = { "01", "02", "03", "04", "05", "06","07", "08", "09" };
201 #if ((defined WIN32 || defined _WIN32 || defined WIN64 || defined _WIN64) && !defined __CYGWIN__ && !defined __CYGWIN32__)
203 localtime_s(&tm,&now);
205 localtime_r(&now,&tm);
208 /* subtract one from maxsize, so we have room for \0. */
210 char dd[8],mm[8],ss[8],hh[8],mn[8];
212 mynum(dd,tm.tm_mday);
215 mynum(hh,tm.tm_hour);
217 sprintf(buf,"%4d-%2s-%2sT%2s:%2s:%2sZ",
218 tm.tm_year+1900,mm,dd,hh,mn,ss);
221 sprintf(buf,"%s %d %s %d",day[tm.tm_wday],tm.tm_mday,
222 mon[tm.tm_mon],tm.tm_year+1900);
227 /* Data structure for saved HTML links */
228 typedef struct t_linkdata {
233 static t_linkdata *init_linkdata()
243 static void finish_linkdata(t_linkdata *p)
247 for(i=0;i<p->nsr;i++) {
248 sfree(p->sr[i].search);
249 sfree(p->sr[i].replace);
255 static char *repall(const char *s,int nsr,const t_sandr_const sa[])
260 /* Copy input to a non-constant char buffer.
261 * buf1 is allocated here
265 for(i=0; (i<nsr); i++) {
266 /* Replace in buffer1, put result in buffer2.
267 * buf2 is allocated here.
269 buf2=replace(buf1,sa[i].search,sa[i].replace);
277 static char *repallww(const char *s,int nsr,const t_sandr sa[])
282 /* Copy input to a non-constant char buffer.
283 * buf1 is allocated here
287 for(i=0; (i<nsr); i++) {
288 /* Replace in buffer1, put result in buffer2.
289 * buf2 is allocated here.
291 buf2=replaceww(buf1,sa[i].search,sa[i].replace);
298 static char *html_xref(char *s,const char *program, t_linkdata *links,gmx_bool bWiki)
300 char buf[256],**filestr;
303 if (links->sr == NULL) {
304 n=get_file("links.dat",&(filestr));
307 for(i=0,j=0; (i<n); i++) {
308 if (!program || (gmx_strcasecmp(program,filestr[i]) != 0)) {
309 links->sr[j].search=gmx_strdup(filestr[i]);
311 sprintf(buf,"[[%s]]",filestr[i]);
313 sprintf(buf,"<a href=\"%s.html\">%s</a>",filestr[i],filestr[i]);
314 links->sr[j].replace=gmx_strdup(buf);
323 return repallww(s,links->nsr,links->sr);
326 char *check_tex(const char *s)
328 return repall(s,NSRTEX,sandrTeX);
331 static char *check_nroff(const char *s)
333 return repall(s,NSRNROFF,sandrNROFF);
336 static char *check_wiki(const char *s,const char *program, t_linkdata *links)
340 buf = repall(s,NSRWIKI,sandrWiki);
341 buf = html_xref(buf,program,links,TRUE);
346 static char *check_html(const char *s,const char *program, t_linkdata *links)
350 buf = repall(s,NSRHTML,sandrHTML);
351 buf = html_xref(buf,program,links,FALSE);
356 #define NWR(s) check_wiki(s,program,links)
357 #define NSR(s) check_html(s,program,links)
359 #define FLAG_SET(flag, mask) ((flag & mask) == mask)
360 char *fileopt(unsigned long flag,char buf[],int maxsize)
364 if (FLAG_SET(flag, ffRW))
365 sprintf(tmp,"In/Out");
366 else if (FLAG_SET(flag, ffREAD))
367 sprintf(tmp,"Input");
368 else if (FLAG_SET(flag, ffWRITE))
369 sprintf(tmp,"Output");
371 sprintf(tmp,"Dunno");
373 if (FLAG_SET(flag, ffOPT)) {
375 if (FLAG_SET(flag, ffSET))
380 if (FLAG_SET(flag, ffLIB))
381 strcat(tmp,", Lib.");
382 if (FLAG_SET(flag, ffMULT))
383 strcat(tmp,", Mult.");
385 sprintf(buf,"%s",tmp);
390 static void write_texman(FILE *out,const char *program,
391 int nldesc,const char **desc,
392 int nfile,t_filenm *fnm,
393 int npargs,t_pargs *pa,
394 int nbug,const char **bugs,
400 fprintf(out,"\\section{\\normindex{%s}}\\label{%s}\n\n",check_tex(program),check_tex(program));
403 for(i=0; (i<nldesc); i++)
404 fprintf(out,"%s\n",check_tex(desc[i]));
407 fprintf(out,"\\vspace{-2ex}\\begin{tabbing}\n");
408 fprintf(out,"\n{\\normalsize \\bf Files}\\nopagebreak\\\\\n");
409 fprintf(out,"{\\tt ~~~~~~~} \\= {\\tt ~~~~~~~~~~~~~~} \\= "
410 "~~~~~~~~~~~~~~~~~~~~~~ \\= \\nopagebreak\\kill\n");
411 for(i=0; (i<nfile); i++)
412 fprintf(out,"\\>{\\tt %s} \\'\\> {\\tt %s} \\' %s \\> "
413 "\\parbox[t]{0.55\\linewidth}{%s} \\\\\n",
414 check_tex(fnm[i].opt),check_tex(fnm[i].fns[0]),
415 check_tex(fileopt(fnm[i].flag,tmp,255)),
416 check_tex(ftp2desc(fnm[i].ftp)));
417 fprintf(out,"\\end{tabbing}\\vspace{-4ex}\n");
420 fprintf(out,"\\vspace{-2ex}\\begin{tabbing}\n");
421 fprintf(out,"\n{\\normalsize \\bf Other options}\\nopagebreak\\\\\n");
422 fprintf(out,"{\\tt ~~~~~~~~~~} \\= vector \\= "
423 "{\\tt ~~~~~~~} \\= \\nopagebreak\\kill\n");
424 for(i=0; (i<npargs); i++) {
425 if (strlen(check_tex(pa_val(&(pa[i]),tmp,255))) <= 8)
426 fprintf(out,"\\> {\\tt %s} \\'\\> %s \\'\\> {\\tt %s} \\' "
427 "\\parbox[t]{0.68\\linewidth}{%s}\\\\\n",
428 check_tex(pa[i].option),argtp[pa[i].type],
429 check_tex(pa_val(&(pa[i]),tmp,255)),
430 check_tex(pa[i].desc));
432 fprintf(out,"\\> {\\tt %s} \\'\\> %s \\'\\>\\\\\n"
433 "\\> \\'\\> \\'\\> {\\tt %s} \\' "
434 "\\parbox[t]{0.7\\linewidth}{%s}\\\\\n",
435 check_tex(pa[i].option),argtp[pa[i].type],
436 check_tex(pa_val(&(pa[i]),tmp,255)),
437 check_tex(pa[i].desc));
439 fprintf(out,"\\end{tabbing}\\vspace{-4ex}\n");
443 fprintf(out,"\\begin{itemize}\n");
444 for(i=0; (i<nbug); i++)
445 fprintf(out,"\\item %s\n",check_tex(bugs[i]));
446 fprintf(out,"\\end{itemize}\n");
448 /* fprintf(out,"\n\\newpage\n"); */
451 static void write_nroffman(FILE *out,
453 int nldesc,const char **desc,
454 int nfile,t_filenm *fnm,
455 int npargs,t_pargs *pa,
456 int nbug,const char **bugs,
464 fprintf(out,".TH %s 1 \"%s\" \"\" \"GROMACS suite, %s\"\n",program,mydate(tmp,255,FALSE),GromacsVersion());
465 fprintf(out,".SH NAME\n");
466 fprintf(out,"%s\n",program);
467 fprintf(out,".B %s\n",GromacsVersion());
469 fprintf(out,".SH SYNOPSIS\n");
470 fprintf(out,"\\f3%s\\fP\n",program);
472 /* command line arguments */
474 for(i=0; (i<nfile); i++)
475 fprintf(out,".BI \"%s\" \" %s \"\n",check_nroff(fnm[i].opt),
476 check_nroff(fnm[i].fns[0]));
479 for(i=0; (i<npargs); i++)
480 if (pa[i].type == etBOOL)
481 fprintf(out,".BI \"\\-[no]%s\" \"\"\n",check_nroff(pa[i].option+1));
483 fprintf(out,".BI \"%s\" \" %s \"\n",check_nroff(pa[i].option),
484 check_nroff(argtp[pa[i].type]));
489 fprintf(out,".SH DESCRIPTION\n");
490 for(i=0; (i<nldesc); i++)
491 fprintf(out,"\\&%s\n",check_nroff(desc[i]));
496 fprintf(out,".SH FILES\n");
497 for(i=0; (i<nfile); i++)
498 fprintf(out,".BI \"%s\" \" %s\" \n.B %s\n %s \n\n",
499 check_nroff(fnm[i].opt),
500 check_nroff(fnm[i].fns[0]),
501 check_nroff(fileopt(fnm[i].flag,tmp,255)),
502 check_nroff(ftp2desc(fnm[i].ftp)));
506 fprintf(out,".SH OTHER OPTIONS\n");
508 for(i=0; (i<npargs); i++) {
509 if (pa[i].type == etBOOL)
510 fprintf(out,".BI \"\\-[no]%s\" \"%s\"\n %s\n\n",
511 check_nroff(pa[i].option+1),
512 check_nroff(pa_val(&(pa[i]),tmp,255)),
513 check_nroff(pa[i].desc));
515 fprintf(out,".BI \"%s\" \" %s\" \" %s\" \n %s\n\n",
516 check_nroff(pa[i].option),
517 check_nroff(argtp[pa[i].type]),
518 check_nroff(pa_val(&(pa[i]),tmp,255)),
519 check_nroff(pa[i].desc));
524 fprintf(out,".SH KNOWN PROBLEMS\n");
525 for(i=0; (i<nbug); i++)
526 fprintf(out,"\\- %s\n\n",check_nroff(bugs[i]));
529 fprintf(out,".SH SEE ALSO\n.BR gromacs(7)\n\n");
530 fprintf(out,"More information about \\fBGROMACS\\fR is available at <\\fIhttp://www.gromacs.org/\\fR>.\n");
534 char *check_tty(const char *s)
536 return repall(s,NSRTTY,sandrTty);
540 print_tty_formatted(FILE *out, int nldesc, const char **desc,int indent,
541 t_linkdata *links,const char *program,gmx_bool bWiki)
549 for(i=0; (i<nldesc); i++) {
550 if ((strlen(buf)>0) &&
551 (buf[strlen(buf)-1] !=' ') && (buf[strlen(buf)-1] !='\n'))
556 temp=check_tty(desc[i]);
557 if (strlen(buf) + strlen(temp) >= (size_t)(buflen-2)) {
558 buflen += strlen(temp);
564 /* Make lines of at most 79 characters */
565 temp = wrap_lines(buf,78,indent,FALSE);
566 fprintf(out,"%s\n",temp);
571 static void write_ttyman(FILE *out,
573 int nldesc,const char **desc,
574 int nfile,t_filenm *fnm,
575 int npargs,t_pargs *pa,
576 int nbug,const char **bugs,gmx_bool bHeader,
584 fprintf(out,"%s\n\n",check_tty(program));
585 fprintf(out,"%s\n%s\n",GromacsVersion(),mydate(buf,255,FALSE));
588 fprintf(out,"DESCRIPTION\n-----------\n");
589 print_tty_formatted(out,nldesc,desc,0,links,program,FALSE);
593 fprintf(out,"KNOWN PROBLEMS\n----------\n");
594 for(i=0; i<nbug; i++) {
595 snew(tmp,strlen(bugs[i])+3);
597 strcpy(tmp+2,check_tty(bugs[i]));
598 fprintf(out,"%s\n",wrap_lines(tmp,78,2,FALSE));
604 pr_fns(out,nfile,fnm);
607 print_pargs(out,npargs,pa,FALSE);
611 static void pr_html_files(FILE *out,int nfile,t_filenm fnm[],
612 const char *program,t_linkdata *links,gmx_bool bWiki)
615 char link[10],tmp[255];
618 fprintf(out," %-10s %-12s %-12s %-s\n"
619 " -----------------------------------------------------\n",
620 "Option","Filename","Type","Description");
623 "<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=2>\n"
628 "<TH>description</TH>"
631 for(i=0; (i<nfile); i++) {
632 strcpy(link,ftp2ext(fnm[i].ftp));
633 if (strcmp(link,"???")==0)
634 strcpy(link,"files");
636 fprintf(out," %-10s %-16s %-12s %-s\n",
639 fileopt(fnm[i].flag,tmp,255),
640 NWR(ftp2desc(fnm[i].ftp)));
644 "<TD ALIGN=RIGHT> <b><tt>%s</tt></b> </TD>"
645 "<TD ALIGN=RIGHT> <tt><a href=\"%s.html\">%12s</a></tt> </TD>"
649 fnm[i].opt,link,fnm[i].fns[0],fileopt(fnm[i].flag,tmp,255),
650 NSR(ftp2desc(fnm[i].ftp)));
653 fprintf(out,"</TABLE>\n");
656 static void write_wikiman(FILE *out,
658 int nldesc,const char **desc,
659 int nfile,t_filenm *fnm,
660 int npargs,t_pargs *pa,
661 int nbug,const char **bugs,gmx_bool bHeader,
665 char buf[256],link[10];
667 fprintf(out,"<page>\n<title>Manual:%s_%s</title>\n",program,
669 fprintf(out,"<revision>\n");
670 fprintf(out,"<timestamp>%s</timestamp>\n",mydate(buf,255,TRUE));
671 fprintf(out,"<text xml:space=\"preserve\">\n");
673 fprintf(out,"== Description ==\n");
674 print_tty_formatted(out,nldesc,desc,0,links,program,TRUE);
678 fprintf(out,"== Known Problems ==\n");
679 for(i=0; i<nbug; i++) {
680 snew(tmp,strlen(bugs[i])+3);
682 strcpy(tmp+2,bugs[i]);
683 fprintf(out,"%s\n",NWR(tmp));
688 fprintf(out,"\n== Files ==\n");
689 pr_html_files(out,nfile,fnm,program,links,TRUE);
692 fprintf(out,"\n== Options ==\n");
693 fprintf(out," %-12s %-6s %-6s %-s\n",
694 "Option","Type","Value","Description");
695 fprintf(out," ------------------------------------------------------\n");
696 for(i=0; (i<npargs); i++) {
697 tmp = NWR(pargs_print_line(&pa[i],TRUE));
698 fprintf(out,"%s",tmp);
702 fprintf(out,"[[category:Manual_Pages_%s|%s]]\n",VERSION,program);
703 fprintf(out,"</text>\n");
704 fprintf(out,"</revision>\n");
705 fprintf(out,"</page>\n\n");
708 static void write_htmlman(FILE *out,
710 int nldesc,const char **desc,
711 int nfile,t_filenm *fnm,
712 int npargs,t_pargs *pa,
713 int nbug,const char **bugs,
717 char link[10],tmp[255];
719 fprintf(out,"<HTML>\n<HEAD>\n<TITLE>%s</TITLE>\n",program);
720 fprintf(out,"<LINK rel=stylesheet href=\"style.css\" type=\"text/css\">\n");
721 fprintf(out,"<BODY text=\"#000000\" bgcolor=\"#FFFFFF\" link=\"#0000FF\" vlink=\"#990000\" alink=\"#FF0000\">\n");
722 fprintf(out,"<TABLE WIDTH=\"98%%\" NOBORDER >\n<TR><TD WIDTH=400>\n");
723 fprintf(out,"<TABLE WIDTH=400 NOBORDER>\n<TD WIDTH=116>\n");
724 fprintf(out,"<a href=\"http://www.gromacs.org/\">"
725 "<img SRC=\"../images/gmxlogo_small.png\""
726 "BORDER=0 </a></td>\n");
727 fprintf(out,"<td ALIGN=LEFT VALIGN=TOP WIDTH=280>"
728 "<br><h2>%s</h2>",program);
729 fprintf(out,"<font size=-1><A HREF=\"../online.html\">Main Table of Contents</A></font><br>");
730 fprintf(out,"<br></td>\n</TABLE></TD><TD WIDTH=\"*\" ALIGN=RIGHT VALIGN=BOTTOM><p><B>%s<br>\n",GromacsVersion());
731 fprintf(out,"%s</B></td></tr></TABLE>\n<HR>\n",mydate(tmp,255,FALSE));
734 fprintf(out,"<H3>Description</H3>\n<p>\n");
735 for(i=0; (i<nldesc); i++)
736 fprintf(out,"%s\n",NSR(desc[i]));
739 fprintf(out,"<P>\n");
740 fprintf(out,"<H3>Files</H3>\n");
741 pr_html_files(out,nfile,fnm,program,links,FALSE);
744 fprintf(out,"<P>\n");
745 fprintf(out,"<H3>Other options</H3>\n");
747 "<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=2>\n"
752 "<TH>description</TH>"
754 for(i=0; (i<npargs); i++)
757 "<TD ALIGN=RIGHT> <b><tt>%s%s</tt></b> </TD>"
758 "<TD ALIGN=RIGHT> %s </TD>"
759 "<TD ALIGN=RIGHT> <tt>%s</tt> </TD>"
762 (pa[i].type == etBOOL)?"-[no]":"-",pa[i].option+1,
763 argtp[pa[i].type],pa_val(&(pa[i]),tmp,255),NSR(pa[i].desc));
764 fprintf(out,"</TABLE>\n");
767 fprintf(out,"<P>\n");
768 fprintf(out,"<H3>Known problems</H3>\n");
769 fprintf(out,"<UL>\n");
770 for(i=0; (i<nbug); i++)
771 fprintf(out,"<LI>%s\n",NSR(bugs[i]));
772 fprintf(out,"</UL>\n");
774 fprintf(out,"<P>\n");
775 fprintf(out,"<hr>\n<div ALIGN=RIGHT>\n");
776 fprintf(out,"<font size=\"-1\"><a href=\"http://www.gromacs.org\">"
777 "http://www.gromacs.org</a></font><br>\n");
778 fprintf(out,"<font size=\"-1\"><a href=\"mailto:gromacs@gromacs.org\">"
779 "gromacs@gromacs.org</a></font><br>\n");
780 fprintf(out,"</div>\n");
781 fprintf(out,"</BODY>\n");
784 char *check_xml(const char *s,const char *program,t_linkdata *links)
788 buf=repall(s,NSRXML,sandrXML);
789 buf=html_xref(buf,program,links,FALSE); /* the same in html and xml */
794 static void write_xmlman(FILE *out,
796 int nldesc,const char **desc,
797 int nfile,t_filenm *fnm,
798 int npargs,t_pargs *pa,
799 int nbug,const char **bugs,
803 char link[10],buf[256],opt[10];
805 #define NSR2(s) check_xml(s,program,links)
806 #define FLAG(w,f) (((w) & (f))==(f))
808 fprintf(out,"<gromacs-manual version=\"%s\" date=\"%s\" www=\"http://www.gromacs.org\">\n",GromacsVersion(),mydate(buf,255,FALSE));
809 /* fprintf(out,"<LINK rel=stylesheet href=\"style.css\" type=\"text/css\">\n"); */
811 fprintf(out,"<program name=\"%s\">",program);
813 fprintf(out,"\n<description>\n<par>\n");
814 for(i=0; (i<nldesc); i++)
815 fprintf(out,"%s\n",NSR2(desc[i]));
817 fprintf(out,"</par>\n</description>\n");
820 fprintf(out,"\n<files>\n");
821 for(i=0; (i<nfile); i++) {
822 strcpy(link,ftp2ext(fnm[i].ftp));
823 if (strcmp(link,"???")==0)
824 strcpy(link,"files");
825 if (fnm[i].opt[0]=='-') strcpy(opt,fnm[i].opt+1);
826 else strcpy(opt,fnm[i].opt);
828 "<file type=\"%s\" typeid=\"%d\">\n"
829 "\t<flags read=\"%d\" write=\"%d\" optional=\"%d\"/>\n"
830 "\t<option>%s</option>\n"
831 "\t<default-name link=\"%s.html\">%s</default-name>\n"
832 "\t<description>%s</description>\n"
834 ftp2defnm(fnm[i].ftp), /* from gmxlib/filenm.c */
836 FLAG(fnm[i].flag,ffREAD), FLAG(fnm[i].flag,ffWRITE), FLAG(fnm[i].flag,ffOPT),
837 opt,link,fnm[i].fn,/*fileopt(fnm[i].flag),*/
838 NSR(ftp2desc(fnm[i].ftp)));
840 fprintf(out,"</files>\n");
844 fprintf(out,"\n<options>\n");
845 for(i=0; (i<npargs); i++)
847 "<option type=\"%s\" hidden=\"%d\">\n"
848 "\t<name >%s</name>\n"
849 "\t<default-value>%s</default-value>\n"
850 "\t<description>%s</description>\n"
852 argtp[pa[i].type], is_hidden(&pa[i]),
853 pa[i].option+1, /* +1 - with no trailing '-' */
854 pa_val(&(pa[i]),buf,255),pa[i].desc); /*argtp[pa[i].type],*/
855 fprintf(out,"</options>\n");
859 fprintf(out,"\n<bugs>\n");
860 for(i=0; (i<nbug); i++)
861 fprintf(out,"\t<bug>%s</bug>\n",NSR(bugs[i]));
862 fprintf(out,"</bugs>\n");
864 fprintf(out,"\n</program>\n</gromacs-manual>\n");
868 static void pr_opts(FILE *fp,
869 int nfile, t_filenm *fnm,
870 int npargs, t_pargs pa[], int shell)
876 fprintf(fp," \"c/-/(");
877 for (i=0; i<nfile; i++)
878 fprintf(fp," %s",fnm[i].opt+1);
879 for (i=0; i<npargs; i++)
880 if ( (pa[i].type==etBOOL) && *(pa[i].u.b) )
881 fprintf(fp," no%s",pa[i].option+1);
883 fprintf(fp," %s",pa[i].option+1);
887 fprintf(fp,"if (( $COMP_CWORD <= 1 )) || [[ $c == -* ]]; then COMPREPLY=( $(compgen -W '");
888 for (i=0; i<nfile; i++)
889 fprintf(fp," -%s",fnm[i].opt+1);
890 for (i=0; i<npargs; i++)
891 if ( (pa[i].type==etBOOL) && *(pa[i].u.b) )
892 fprintf(fp," -no%s",pa[i].option+1);
894 fprintf(fp," -%s",pa[i].option+1);
895 fprintf(fp,"' -- $c)); return 0; fi\n");
898 fprintf(fp," -x 's[-]' -s \"");
899 for (i=0; i<nfile; i++)
900 fprintf(fp," %s",fnm[i].opt+1);
901 for (i=0; i<npargs; i++)
902 if ( (pa[i].type==etBOOL) && *(pa[i].u.b) )
903 fprintf(fp," no%s",pa[i].option+1);
905 fprintf(fp," %s",pa[i].option+1);
911 static void write_cshcompl(FILE *out,
912 int nfile, t_filenm *fnm,
913 int npargs, t_pargs *pa)
915 fprintf(out,"complete %s",ShortProgram());
916 pr_enums(out,npargs,pa,eshellCSH);
917 pr_fopts(out,nfile,fnm,eshellCSH);
918 pr_opts(out,nfile,fnm,npargs,pa,eshellCSH);
922 static void write_zshcompl(FILE *out,
923 int nfile, t_filenm *fnm,
924 int npargs, t_pargs *pa)
926 fprintf(out,"compctl ");
928 /* start with options, since they are always present */
929 pr_opts(out,nfile,fnm,npargs,pa,eshellZSH);
930 pr_enums(out,npargs,pa,eshellZSH);
931 pr_fopts(out,nfile,fnm,eshellZSH);
932 fprintf(out,"-- %s\n",ShortProgram());
935 static void write_bashcompl(FILE *out,
936 int nfile, t_filenm *fnm,
937 int npargs, t_pargs *pa)
939 /* Advanced bash completions are handled by shell functions.
940 * p and c hold the previous and current word on the command line.
941 * We need to use extended globbing, so write it in each completion file */
942 fprintf(out,"shopt -s extglob\n");
943 fprintf(out,"_%s_compl() {\nlocal p c\n",ShortProgram());
944 fprintf(out,"COMPREPLY=() c=${COMP_WORDS[COMP_CWORD]} p=${COMP_WORDS[COMP_CWORD-1]}\n");
945 pr_opts(out,nfile,fnm,npargs,pa,eshellBASH);
946 fprintf(out,"case \"$p\" in\n");
948 pr_enums(out,npargs,pa,eshellBASH);
949 pr_fopts(out,nfile,fnm,eshellBASH);
950 fprintf(out,"esac }\ncomplete -F _%s_compl %s\n",ShortProgram(),ShortProgram());
953 static void write_py(FILE *out,const char *program,
954 int nldesc,const char **desc,
955 int nfile,t_filenm *fnm,
956 int npargs,t_pargs *pa,
957 int nbug,const char **bugs,
961 const char *cls = program;
966 fprintf(out,"#!/usr/bin/python\n\nfrom GmxDialog import *\n\n");
968 /* Class definition */
969 fprintf(out,"class %s:\n",cls);
970 fprintf(out," def __init__(self,tk):\n");
973 fprintf(out," %s_help = \"\"\"\n",cls);
974 fprintf(out," DESCRIPTION\n");
975 print_tty_formatted(out,nldesc,desc,8,links,program,FALSE);
977 fprintf(out,"\n BUGS and PROBLEMS\n");
978 for(i=0; i<nbug; i++) {
979 snew(tmp,strlen(bugs[i])+3);
981 strcpy(tmp+2,check_tty(bugs[i]));
982 fprintf(out,"%s\n",wrap_lines(tmp,78,10,TRUE));
986 fprintf(out," \"\"\"\n\n # Command line options\n");
988 fprintf(out," flags = []\n");
989 for(i=0; (i<nfile); i++)
990 fprintf(out," flags.append(pca_file('%s',\"%s\",0,%d))\n",
991 ftp2ext_generic(fnm[i].ftp),fnm[i].opt ? fnm[i].opt : "k",
992 is_optional(&(fnm[i])));
996 for(i=0; (i<npargs); i++) {
999 fprintf(out," flags.append(pca_int(\"%s\",\"%s\",%d,%d))\n",
1000 pa[i].option,pa[i].desc,*pa[i].u.i,is_hidden(&(pa[i])));
1004 fprintf(out," flags.append(pca_float(\"%s\",\"%s\",%f,%d))\n",
1005 pa[i].option,pa[i].desc,*pa[i].u.r,is_hidden(&(pa[i])));
1009 fprintf(out," flags.append(pca_gmx_bool(\"%s\",\"%s\",%d,%d))\n",
1010 pa[i].option,pa[i].desc,*pa[i].u.b,is_hidden(&(pa[i])));
1013 fprintf(stderr,"Sorry, no rvecs yet...\n");
1016 fprintf(out," flags.append(pca_enum(\"%s\",\"%s\",\n",
1017 pa[i].option,pa[i].desc);
1018 fprintf(out," ['%s'",pa[i].u.c[1]);
1019 for(j=2; (pa[i].u.c[j] != NULL); j++)
1020 fprintf(out,",'%s'",pa[i].u.c[j]);
1021 fprintf(out,"],%d))\n",is_hidden(&(pa[i])));
1027 /* Make the dialog box */
1028 fprintf(out," gmxd = gmx_dialog(tk,\"%s\",flags,%s_help)\n\n",
1032 fprintf(out,"#####################################################\n");
1033 fprintf(out,"tk = Tk()\n");
1034 fprintf(out,"my%s = %s(tk)\n",cls,cls);
1035 fprintf(out,"tk.mainloop()\n");
1038 void write_man(FILE *out,const char *mantp,
1039 const char *program,
1040 int nldesc,const char **desc,
1041 int nfile,t_filenm *fnm,
1042 int npargs,t_pargs *pa,
1043 int nbug,const char **bugs,
1052 links=init_linkdata();
1054 /* Don't write hidden options to completions, it just
1055 * makes the options more complicated for normal users
1065 for(i=0;i<npargs;i++)
1066 if (!is_hidden(&pa[i])) {
1072 if ((pr=strrchr(program,DIR_SEPARATOR)) == NULL)
1076 if (strcmp(mantp,"tex")==0)
1077 write_texman(out,pr,nldesc,desc,nfile,fnm,npar,par,nbug,bugs,links);
1078 if (strcmp(mantp,"nroff")==0)
1079 write_nroffman(out,pr,nldesc,desc,nfile,fnm,npar,par,nbug,bugs,links);
1080 if (strcmp(mantp,"ascii")==0)
1081 write_ttyman(out,pr,nldesc,desc,nfile,fnm,npar,par,nbug,bugs,TRUE,links);
1082 if (strcmp(mantp,"wiki")==0)
1083 write_wikiman(out,pr,nldesc,desc,nfile,fnm,npar,par,nbug,bugs,TRUE,links);
1084 if (strcmp(mantp,"help")==0)
1085 write_ttyman(out,pr,nldesc,desc,nfile,fnm,npar,par,nbug,bugs,FALSE,links);
1086 if (strcmp(mantp,"html")==0)
1087 write_htmlman(out,pr,nldesc,desc,nfile,fnm,npar,par,nbug,bugs,links);
1088 if (strcmp(mantp,"py")==0)
1089 write_py(out,pr,nldesc,desc,nfile,fnm,npar,par,nbug,bugs,links);
1090 if (strcmp(mantp,"xml")==0)
1091 write_xmlman(out,pr,nldesc,desc,nfile,fnm,npargs,pa,nbug,bugs,links);
1092 if (strcmp(mantp,"completion-zsh")==0)
1093 write_zshcompl(out,nfile,fnm,npar,par);
1094 if (strcmp(mantp,"completion-bash")==0)
1095 write_bashcompl(out,nfile,fnm,npar,par);
1096 if (strcmp(mantp,"completion-csh")==0)
1097 write_cshcompl(out,nfile,fnm,npar,par);
1102 finish_linkdata(links);