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
[] = {
87 #define NSRTEX asize(sandrTeX)
89 const t_sandr_const sandrTty
[] = {
99 #define NSRTTY asize(sandrTty)
101 const t_sandr_const sandrWiki
[] = {
105 { "[TT]", "<code>" },
106 { "[tt]", "</code>" },
114 #define NSRWIKI asize(sandrWiki)
116 const t_sandr_const sandrNROFF
[] = {
132 #define NSRNROFF asize(sandrNROFF)
134 const t_sandr_const sandrHTML
[] = {
146 #define NSRHTML asize(sandrHTML)
148 const t_sandr_const sandrXML
[] = {
152 { "[tt]", "</arg>" },
154 { "[bb]", "</emp>" },
157 { "[PAR]","</par>\n<par>" },
160 #define NSRXML asize(sandrXML)
162 static void mynum(char *buf
,int n
)
165 sprintf(buf
,"%2d",n
);
167 sprintf(buf
,"0%1d",n
);
170 static char *mydate(char buf
[], int maxsize
,bool bWiki
)
172 const char *mon
[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun",
173 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
174 const char *day
[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
175 const char *num
[] = { "01", "02", "03", "04", "05", "06","07", "08", "09" };
180 tm
= localtime(&now
);
181 /* subtract one from maxsize, so we have room for \0. */
183 char dd
[8],mm
[8],ss
[8],hh
[8],mn
[8];
185 mynum(dd
,tm
->tm_mday
);
186 mynum(mm
,tm
->tm_mon
);
187 mynum(ss
,tm
->tm_sec
);
188 mynum(hh
,tm
->tm_hour
);
189 mynum(mn
,tm
->tm_min
);
190 sprintf(buf
,"%4d-%2s-%2sT%2s:%2s:%2sZ",
191 tm
->tm_year
+1900,mm
,dd
,hh
,mn
,ss
);
194 sprintf(buf
,"%s %d %s %d",day
[tm
->tm_wday
],tm
->tm_mday
,
195 mon
[tm
->tm_mon
],tm
->tm_year
+1900);
200 /* Data structure for saved HTML links */
206 static t_linkdata
*init_linkdata()
216 static void finish_linkdata(t_linkdata
*p
)
220 for(i
=0;i
<p
->nsr
;i
++) {
221 sfree(p
->sr
[i
].search
);
222 sfree(p
->sr
[i
].replace
);
228 static char *repall(const char *s
,int nsr
,const t_sandr_const sa
[])
233 /* Copy input to a non-constant char buffer.
234 * buf1 is allocated here
238 for(i
=0; (i
<nsr
); i
++) {
239 /* Replace in buffer1, put result in buffer2.
240 * buf2 is allocated here.
242 buf2
=replace(buf1
,sa
[i
].search
,sa
[i
].replace
);
250 static char *repallww(const char *s
,int nsr
,const t_sandr sa
[])
255 /* Copy input to a non-constant char buffer.
256 * buf1 is allocated here
260 for(i
=0; (i
<nsr
); i
++) {
261 /* Replace in buffer1, put result in buffer2.
262 * buf2 is allocated here.
264 buf2
=replaceww(buf1
,sa
[i
].search
,sa
[i
].replace
);
271 static char *html_xref(char *s
,const char *program
, t_linkdata
*links
,bool bWiki
)
273 char buf
[256],**filestr
;
276 if (links
->sr
== NULL
) {
277 n
=get_file("links.dat",&(filestr
));
280 for(i
=0,j
=0; (i
<n
); i
++) {
281 if (!program
|| (strcasecmp(program
,filestr
[i
]) != 0)) {
282 links
->sr
[j
].search
=strdup(filestr
[i
]);
284 sprintf(buf
,"[[%s]]",filestr
[i
]);
286 sprintf(buf
,"<a href=\"%s.html\">%s</a>",filestr
[i
],filestr
[i
]);
287 links
->sr
[j
].replace
=strdup(buf
);
296 return repallww(s
,links
->nsr
,links
->sr
);
299 char *check_tex(const char *s
)
301 return repall(s
,NSRTEX
,sandrTeX
);
304 static char *check_nroff(const char *s
)
306 return repall(s
,NSRNROFF
,sandrNROFF
);
309 static char *check_wiki(const char *s
,const char *program
, t_linkdata
*links
)
313 buf
= repall(s
,NSRWIKI
,sandrWiki
);
314 buf
= html_xref(buf
,program
,links
,TRUE
);
319 static char *check_html(const char *s
,const char *program
, t_linkdata
*links
)
323 buf
= repall(s
,NSRHTML
,sandrHTML
);
324 buf
= html_xref(buf
,program
,links
,FALSE
);
329 #define NWR(s) check_wiki(s,program,links)
330 #define NSR(s) check_html(s,program,links)
332 #define FLAG_SET(flag, mask) ((flag & mask) == mask)
333 char *fileopt(unsigned long flag
,char buf
[],int maxsize
)
337 if (FLAG_SET(flag
, ffRW
))
338 sprintf(tmp
,"In/Out");
339 else if (FLAG_SET(flag
, ffREAD
))
340 sprintf(tmp
,"Input");
341 else if (FLAG_SET(flag
, ffWRITE
))
342 sprintf(tmp
,"Output");
344 sprintf(tmp
,"Dunno");
346 if (FLAG_SET(flag
, ffOPT
)) {
348 if (FLAG_SET(flag
, ffSET
))
353 if (FLAG_SET(flag
, ffLIB
))
354 strcat(tmp
,", Lib.");
355 if (FLAG_SET(flag
, ffMULT
))
356 strcat(tmp
,", Mult.");
358 sprintf(buf
,"%s",tmp
);
363 static void write_texman(FILE *out
,const char *program
,
364 int nldesc
,const char **desc
,
365 int nfile
,t_filenm
*fnm
,
366 int npargs
,t_pargs
*pa
,
367 int nbug
,const char **bugs
,
373 fprintf(out
,"\\section{\\normindex{%s}}\n\n",check_tex(program
));
376 for(i
=0; (i
<nldesc
); i
++)
377 fprintf(out
,"%s\n",check_tex(desc
[i
]));
380 fprintf(out
,"\\vspace{-2ex}\\begin{tabbing}\n");
381 fprintf(out
,"\n{\\normalsize \\bf Files}\\nopagebreak\\\\\n");
382 fprintf(out
,"{\\tt ~~~~~~~} \\= {\\tt ~~~~~~~~~~~~~~} \\= "
383 "~~~~~~~~~~~~~~~~~~~~~~ \\= \\nopagebreak\\kill\n");
384 for(i
=0; (i
<nfile
); i
++)
385 fprintf(out
,"\\>{\\tt %s} \\'\\> {\\tt %s} \\' %s \\> "
386 "\\parbox[t]{0.55\\linewidth}{%s} \\\\\n",
387 check_tex(fnm
[i
].opt
),check_tex(fnm
[i
].fns
[0]),
388 check_tex(fileopt(fnm
[i
].flag
,tmp
,255)),
389 check_tex(ftp2desc(fnm
[i
].ftp
)));
390 fprintf(out
,"\\end{tabbing}\\vspace{-4ex}\n");
393 fprintf(out
,"\\vspace{-2ex}\\begin{tabbing}\n");
394 fprintf(out
,"\n{\\normalsize \\bf Other options}\\nopagebreak\\\\\n");
395 fprintf(out
,"{\\tt ~~~~~~~~~~} \\= vector \\= "
396 "{\\tt ~~~~~~~} \\= \\nopagebreak\\kill\n");
397 for(i
=0; (i
<npargs
); i
++) {
398 if (strlen(check_tex(pa_val(&(pa
[i
]),tmp
,255))) <= 8)
399 fprintf(out
,"\\> {\\tt %s} \\'\\> %s \\'\\> {\\tt %s} \\' "
400 "\\parbox[t]{0.68\\linewidth}{%s}\\\\\n",
401 check_tex(pa
[i
].option
),argtp
[pa
[i
].type
],
402 check_tex(pa_val(&(pa
[i
]),tmp
,255)),
403 check_tex(pa
[i
].desc
));
405 fprintf(out
,"\\> {\\tt %s} \\'\\> %s \\'\\>\\\\\n"
406 "\\> \\'\\> \\'\\> {\\tt %s} \\' "
407 "\\parbox[t]{0.7\\linewidth}{%s}\\\\\n",
408 check_tex(pa
[i
].option
),argtp
[pa
[i
].type
],
409 check_tex(pa_val(&(pa
[i
]),tmp
,255)),
410 check_tex(pa
[i
].desc
));
412 fprintf(out
,"\\end{tabbing}\\vspace{-4ex}\n");
416 fprintf(out
,"\\begin{itemize}\n");
417 for(i
=0; (i
<nbug
); i
++)
418 fprintf(out
,"\\item %s\n",check_tex(bugs
[i
]));
419 fprintf(out
,"\\end{itemize}\n");
421 /* fprintf(out,"\n\\newpage\n"); */
424 static void write_nroffman(FILE *out
,
426 int nldesc
,const char **desc
,
427 int nfile
,t_filenm
*fnm
,
428 int npargs
,t_pargs
*pa
,
429 int nbug
,const char **bugs
,
437 fprintf(out
,".TH %s 1 \"%s\" \"\" \"GROMACS suite, %s\"\n",program
,mydate(tmp
,255,FALSE
),GromacsVersion());
438 fprintf(out
,".SH NAME\n");
439 fprintf(out
,"%s\n",program
);
440 fprintf(out
,".B %s\n",GromacsVersion());
442 fprintf(out
,".SH SYNOPSIS\n");
443 fprintf(out
,"\\f3%s\\fP\n",program
);
445 /* command line arguments */
447 for(i
=0; (i
<nfile
); i
++)
448 fprintf(out
,".BI \"%s\" \" %s \"\n",check_nroff(fnm
[i
].opt
),
449 check_nroff(fnm
[i
].fns
[0]));
452 for(i
=0; (i
<npargs
); i
++)
453 if (pa
[i
].type
== etBOOL
)
454 fprintf(out
,".BI \"\\-[no]%s\" \"\"\n",check_nroff(pa
[i
].option
+1));
456 fprintf(out
,".BI \"%s\" \" %s \"\n",check_nroff(pa
[i
].option
),
457 check_nroff(argtp
[pa
[i
].type
]));
462 fprintf(out
,".SH DESCRIPTION\n");
463 for(i
=0; (i
<nldesc
); i
++)
464 fprintf(out
,"\\&%s\n",check_nroff(desc
[i
]));
469 fprintf(out
,".SH FILES\n");
470 for(i
=0; (i
<nfile
); i
++)
471 fprintf(out
,".BI \"%s\" \" %s\" \n.B %s\n %s \n\n",
472 check_nroff(fnm
[i
].opt
),
473 check_nroff(fnm
[i
].fns
[0]),
474 check_nroff(fileopt(fnm
[i
].flag
,tmp
,255)),
475 check_nroff(ftp2desc(fnm
[i
].ftp
)));
479 fprintf(out
,".SH OTHER OPTIONS\n");
481 for(i
=0; (i
<npargs
); i
++) {
482 if (pa
[i
].type
== etBOOL
)
483 fprintf(out
,".BI \"\\-[no]%s\" \"%s\"\n %s\n\n",
484 check_nroff(pa
[i
].option
+1),
485 check_nroff(pa_val(&(pa
[i
]),tmp
,255)),
486 check_nroff(pa
[i
].desc
));
488 fprintf(out
,".BI \"%s\" \" %s\" \" %s\" \n %s\n\n",
489 check_nroff(pa
[i
].option
),
490 check_nroff(argtp
[pa
[i
].type
]),
491 check_nroff(pa_val(&(pa
[i
]),tmp
,255)),
492 check_nroff(pa
[i
].desc
));
497 fprintf(out
,".SH KNOWN PROBLEMS\n");
498 for(i
=0; (i
<nbug
); i
++)
499 fprintf(out
,"\\- %s\n\n",check_nroff(bugs
[i
]));
502 fprintf(out
,".SH SEE ALSO\n.BR gromacs(7)\n\n");
503 fprintf(out
,"More information about \\fBGROMACS\\fR is available at <\\fIhttp://www.gromacs.org/\\fR>.\n");
507 char *check_tty(const char *s
)
509 return repall(s
,NSRTTY
,sandrTty
);
513 print_tty_formatted(FILE *out
, int nldesc
, const char **desc
,int indent
,
514 t_linkdata
*links
,const char *program
,bool bWiki
)
522 for(i
=0; (i
<nldesc
); i
++) {
523 if ((strlen(buf
)>0) &&
524 (buf
[strlen(buf
)-1] !=' ') && (buf
[strlen(buf
)-1] !='\n'))
529 temp
=check_tty(desc
[i
]);
530 if (strlen(buf
) + strlen(temp
) >= (size_t)(buflen
-2)) {
531 buflen
+= strlen(temp
);
537 /* Make lines of at most 79 characters */
538 temp
= wrap_lines(buf
,78,indent
,FALSE
);
539 fprintf(out
,"%s\n",temp
);
544 static void write_ttyman(FILE *out
,
546 int nldesc
,const char **desc
,
547 int nfile
,t_filenm
*fnm
,
548 int npargs
,t_pargs
*pa
,
549 int nbug
,const char **bugs
,bool bHeader
,
557 fprintf(out
,"%s\n\n",check_tty(program
));
558 fprintf(out
,"%s\n%s\n",GromacsVersion(),mydate(buf
,255,FALSE
));
561 fprintf(out
,"DESCRIPTION\n-----------\n");
562 print_tty_formatted(out
,nldesc
,desc
,0,links
,program
,FALSE
);
566 fprintf(out
,"KNOWN PROBLEMS\n----------\n");
567 for(i
=0; i
<nbug
; i
++) {
568 snew(tmp
,strlen(bugs
[i
])+3);
570 strcpy(tmp
+2,check_tty(bugs
[i
]));
571 fprintf(out
,"%s\n",wrap_lines(tmp
,78,2,FALSE
));
577 pr_fns(out
,nfile
,fnm
);
580 print_pargs(out
,npargs
,pa
,FALSE
);
584 static void pr_html_files(FILE *out
,int nfile
,t_filenm fnm
[],
585 const char *program
,t_linkdata
*links
,bool bWiki
)
588 char link
[10],tmp
[255];
591 fprintf(out
," %-10s %-12s %-12s %-s\n"
592 " -----------------------------------------------------\n",
593 "Option","Filename","Type","Description");
596 "<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=2>\n"
601 "<TH>description</TH>"
604 for(i
=0; (i
<nfile
); i
++) {
605 strcpy(link
,ftp2ext(fnm
[i
].ftp
));
606 if (strcmp(link
,"???")==0)
607 strcpy(link
,"files");
609 fprintf(out
," %-10s %-16s %-12s %-s\n",
612 fileopt(fnm
[i
].flag
,tmp
,255),
613 NWR(ftp2desc(fnm
[i
].ftp
)));
617 "<TD ALIGN=RIGHT> <b><tt>%s</tt></b> </TD>"
618 "<TD ALIGN=RIGHT> <tt><a href=\"%s.html\">%12s</a></tt> </TD>"
622 fnm
[i
].opt
,link
,fnm
[i
].fns
[0],fileopt(fnm
[i
].flag
,tmp
,255),
623 NSR(ftp2desc(fnm
[i
].ftp
)));
626 fprintf(out
,"</TABLE>\n");
629 static void write_wikiman(FILE *out
,
631 int nldesc
,const char **desc
,
632 int nfile
,t_filenm
*fnm
,
633 int npargs
,t_pargs
*pa
,
634 int nbug
,const char **bugs
,bool bHeader
,
638 char buf
[256],link
[10];
640 fprintf(out
,"<page>\n<title>Manual:%s_%s</title>\n",program
,
642 fprintf(out
,"<revision>\n");
643 fprintf(out
,"<timestamp>%s</timestamp>\n",mydate(buf
,255,TRUE
));
644 fprintf(out
,"<text xml:space=\"preserve\">\n");
646 fprintf(out
,"== Description ==\n");
647 print_tty_formatted(out
,nldesc
,desc
,0,links
,program
,TRUE
);
651 fprintf(out
,"== Known Problems ==\n");
652 for(i
=0; i
<nbug
; i
++) {
653 snew(tmp
,strlen(bugs
[i
])+3);
655 strcpy(tmp
+2,bugs
[i
]);
656 fprintf(out
,"%s\n",NWR(tmp
));
661 fprintf(out
,"\n== Files ==\n");
662 pr_html_files(out
,nfile
,fnm
,program
,links
,TRUE
);
665 fprintf(out
,"\n== Options ==\n");
666 fprintf(out
," %-12s %-6s %-6s %-s\n",
667 "Option","Type","Value","Description");
668 fprintf(out
," ------------------------------------------------------\n");
669 for(i
=0; (i
<npargs
); i
++) {
670 tmp
= NWR(pargs_print_line(&pa
[i
],TRUE
));
671 fprintf(out
,"%s",tmp
);
675 fprintf(out
,"[[category:Manual_Pages_%s|%s]]\n",VERSION
,program
);
676 fprintf(out
,"</text>\n");
677 fprintf(out
,"</revision>\n");
678 fprintf(out
,"</page>\n\n");
681 static void write_htmlman(FILE *out
,
683 int nldesc
,const char **desc
,
684 int nfile
,t_filenm
*fnm
,
685 int npargs
,t_pargs
*pa
,
686 int nbug
,const char **bugs
,
690 char link
[10],tmp
[255];
692 fprintf(out
,"<HTML>\n<HEAD>\n<TITLE>%s</TITLE>\n",program
);
693 fprintf(out
,"<LINK rel=stylesheet href=\"style.css\" type=\"text/css\">\n");
694 fprintf(out
,"<BODY text=\"#000000\" bgcolor=\"#FFFFFF\" link=\"#0000FF\" vlink=\"#990000\" alink=\"#FF0000\">\n");
695 fprintf(out
,"<TABLE WIDTH=\"98%%\" NOBORDER >\n<TR><TD WIDTH=400>\n");
696 fprintf(out
,"<TABLE WIDTH=400 NOBORDER>\n<TD WIDTH=116>\n");
697 fprintf(out
,"<a href=\"http://www.gromacs.org/\">"
698 "<img SRC=\"../images/gmxlogo_small.png\""
699 "BORDER=0 </a></td>\n");
700 fprintf(out
,"<td ALIGN=LEFT VALIGN=TOP WIDTH=280>"
701 "<br><h2>%s</h2>",program
);
702 fprintf(out
,"<font size=-1><A HREF=\"../online.html\">Main Table of Contents</A></font><br>");
703 fprintf(out
,"<br></td>\n</TABLE></TD><TD WIDTH=\"*\" ALIGN=RIGHT VALIGN=BOTTOM><p><B>%s<br>\n",GromacsVersion());
704 fprintf(out
,"%s</B></td></tr></TABLE>\n<HR>\n",mydate(tmp
,255,FALSE
));
707 fprintf(out
,"<H3>Description</H3>\n<p>\n");
708 for(i
=0; (i
<nldesc
); i
++)
709 fprintf(out
,"%s\n",NSR(desc
[i
]));
712 fprintf(out
,"<P>\n");
713 fprintf(out
,"<H3>Files</H3>\n");
714 pr_html_files(out
,nfile
,fnm
,program
,links
,FALSE
);
717 fprintf(out
,"<P>\n");
718 fprintf(out
,"<H3>Other options</H3>\n");
720 "<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=2>\n"
725 "<TH>description</TH>"
727 for(i
=0; (i
<npargs
); i
++)
730 "<TD ALIGN=RIGHT> <b><tt>%s%s</tt></b> </TD>"
731 "<TD ALIGN=RIGHT> %s </TD>"
732 "<TD ALIGN=RIGHT> <tt>%s</tt> </TD>"
735 (pa
[i
].type
== etBOOL
)?"-[no]":"-",pa
[i
].option
+1,
736 argtp
[pa
[i
].type
],pa_val(&(pa
[i
]),tmp
,255),NSR(pa
[i
].desc
));
737 fprintf(out
,"</TABLE>\n");
740 fprintf(out
,"<P>\n");
741 fprintf(out
,"<H3>Known problems</H3>\n");
742 fprintf(out
,"<UL>\n");
743 for(i
=0; (i
<nbug
); i
++)
744 fprintf(out
,"<LI>%s\n",NSR(bugs
[i
]));
745 fprintf(out
,"</UL>\n");
747 fprintf(out
,"<P>\n");
748 fprintf(out
,"<hr>\n<div ALIGN=RIGHT>\n");
749 fprintf(out
,"<font size=\"-1\"><a href=\"http://www.gromacs.org\">"
750 "http://www.gromacs.org</a></font><br>\n");
751 fprintf(out
,"<font size=\"-1\"><a href=\"mailto:gromacs@gromacs.org\">"
752 "gromacs@gromacs.org</a></font><br>\n");
753 fprintf(out
,"</div>\n");
754 fprintf(out
,"</BODY>\n");
757 char *check_xml(const char *s
,const char *program
,t_linkdata
*links
)
761 buf
=repall(s
,NSRXML
,sandrXML
);
762 buf
=html_xref(buf
,program
,links
,FALSE
); /* the same in html and xml */
767 static void write_xmlman(FILE *out
,
769 int nldesc
,const char **desc
,
770 int nfile
,t_filenm
*fnm
,
771 int npargs
,t_pargs
*pa
,
772 int nbug
,const char **bugs
,
776 char link
[10],buf
[256],opt
[10];
778 #define NSR2(s) check_xml(s,program,links)
779 #define FLAG(w,f) (((w) & (f))==(f))
781 fprintf(out
,"<gromacs-manual version=\"%s\" date=\"%s\" www=\"http://www.gromacs.org\">\n",GromacsVersion(),mydate(buf
,255,FALSE
));
782 /* fprintf(out,"<LINK rel=stylesheet href=\"style.css\" type=\"text/css\">\n"); */
784 fprintf(out
,"<program name=\"%s\">",program
);
786 fprintf(out
,"\n<description>\n<par>\n");
787 for(i
=0; (i
<nldesc
); i
++)
788 fprintf(out
,"%s\n",NSR2(desc
[i
]));
790 fprintf(out
,"</par>\n</description>\n");
793 fprintf(out
,"\n<files>\n");
794 for(i
=0; (i
<nfile
); i
++) {
795 strcpy(link
,ftp2ext(fnm
[i
].ftp
));
796 if (strcmp(link
,"???")==0)
797 strcpy(link
,"files");
798 if (fnm
[i
].opt
[0]=='-') strcpy(opt
,fnm
[i
].opt
+1);
799 else strcpy(opt
,fnm
[i
].opt
);
801 "<file type=\"%s\" typeid=\"%d\">\n"
802 "\t<flags read=\"%d\" write=\"%d\" optional=\"%d\"/>\n"
803 "\t<option>%s</option>\n"
804 "\t<default-name link=\"%s.html\">%s</default-name>\n"
805 "\t<description>%s</description>\n"
807 ftp2defnm(fnm
[i
].ftp
), /* from gmxlib/filenm.c */
809 FLAG(fnm
[i
].flag
,ffREAD
), FLAG(fnm
[i
].flag
,ffWRITE
), FLAG(fnm
[i
].flag
,ffOPT
),
810 opt
,link
,fnm
[i
].fn
,/*fileopt(fnm[i].flag),*/
811 NSR(ftp2desc(fnm
[i
].ftp
)));
813 fprintf(out
,"</files>\n");
817 fprintf(out
,"\n<options>\n");
818 for(i
=0; (i
<npargs
); i
++)
820 "<option type=\"%s\" hidden=\"%d\">\n"
821 "\t<name >%s</name>\n"
822 "\t<default-value>%s</default-value>\n"
823 "\t<description>%s</description>\n"
825 argtp
[pa
[i
].type
], is_hidden(&pa
[i
]),
826 pa
[i
].option
+1, /* +1 - with no trailing '-' */
827 pa_val(&(pa
[i
]),buf
,255),pa
[i
].desc
); /*argtp[pa[i].type],*/
828 fprintf(out
,"</options>\n");
832 fprintf(out
,"\n<bugs>\n");
833 for(i
=0; (i
<nbug
); i
++)
834 fprintf(out
,"\t<bug>%s</bug>\n",NSR(bugs
[i
]));
835 fprintf(out
,"</bugs>\n");
837 fprintf(out
,"\n</program>\n</gromacs-manual>\n");
841 static void pr_opts(FILE *fp
,
842 int nfile
, t_filenm
*fnm
,
843 int npargs
, t_pargs pa
[], int shell
)
849 fprintf(fp
," \"c/-/(");
850 for (i
=0; i
<nfile
; i
++)
851 fprintf(fp
," %s",fnm
[i
].opt
+1);
852 for (i
=0; i
<npargs
; i
++)
853 if ( (pa
[i
].type
==etBOOL
) && *(pa
[i
].u
.b
) )
854 fprintf(fp
," no%s",pa
[i
].option
+1);
856 fprintf(fp
," %s",pa
[i
].option
+1);
860 fprintf(fp
,"if (( $COMP_CWORD <= 1 )) || [[ $c == -* ]]; then COMPREPLY=( $(compgen -W '");
861 for (i
=0; i
<nfile
; i
++)
862 fprintf(fp
," -%s",fnm
[i
].opt
+1);
863 for (i
=0; i
<npargs
; i
++)
864 if ( (pa
[i
].type
==etBOOL
) && *(pa
[i
].u
.b
) )
865 fprintf(fp
," -no%s",pa
[i
].option
+1);
867 fprintf(fp
," -%s",pa
[i
].option
+1);
868 fprintf(fp
,"' -- $c)); return 0; fi\n");
871 fprintf(fp
," -x 's[-]' -s \"");
872 for (i
=0; i
<nfile
; i
++)
873 fprintf(fp
," %s",fnm
[i
].opt
+1);
874 for (i
=0; i
<npargs
; i
++)
875 if ( (pa
[i
].type
==etBOOL
) && *(pa
[i
].u
.b
) )
876 fprintf(fp
," no%s",pa
[i
].option
+1);
878 fprintf(fp
," %s",pa
[i
].option
+1);
884 static void write_cshcompl(FILE *out
,
885 int nfile
, t_filenm
*fnm
,
886 int npargs
, t_pargs
*pa
)
888 fprintf(out
,"complete %s",ShortProgram());
889 pr_enums(out
,npargs
,pa
,eshellCSH
);
890 pr_fopts(out
,nfile
,fnm
,eshellCSH
);
891 pr_opts(out
,nfile
,fnm
,npargs
,pa
,eshellCSH
);
895 static void write_zshcompl(FILE *out
,
896 int nfile
, t_filenm
*fnm
,
897 int npargs
, t_pargs
*pa
)
899 fprintf(out
,"compctl ");
901 /* start with options, since they are always present */
902 pr_opts(out
,nfile
,fnm
,npargs
,pa
,eshellZSH
);
903 pr_enums(out
,npargs
,pa
,eshellZSH
);
904 pr_fopts(out
,nfile
,fnm
,eshellZSH
);
905 fprintf(out
,"-- %s\n",ShortProgram());
908 static void write_bashcompl(FILE *out
,
909 int nfile
, t_filenm
*fnm
,
910 int npargs
, t_pargs
*pa
)
912 /* Advanced bash completions are handled by shell functions.
913 * p and c hold the previous and current word on the command line.
914 * We need to use extended globbing, so write it in each completion file */
915 fprintf(out
,"shopt -s extglob\n");
916 fprintf(out
,"_%s_compl() {\nlocal p c\n",ShortProgram());
917 fprintf(out
,"COMPREPLY=() c=${COMP_WORDS[COMP_CWORD]} p=${COMP_WORDS[COMP_CWORD-1]}\n");
918 pr_opts(out
,nfile
,fnm
,npargs
,pa
,eshellBASH
);
919 fprintf(out
,"case \"$p\" in\n");
921 pr_enums(out
,npargs
,pa
,eshellBASH
);
922 pr_fopts(out
,nfile
,fnm
,eshellBASH
);
923 fprintf(out
,"esac }\ncomplete -F _%s_compl %s\n",ShortProgram(),ShortProgram());
926 static void write_py(FILE *out
,const char *program
,
927 int nldesc
,const char **desc
,
928 int nfile
,t_filenm
*fnm
,
929 int npargs
,t_pargs
*pa
,
930 int nbug
,const char **bugs
,
934 const char *cls
= program
;
939 fprintf(out
,"#!/usr/bin/python\n\nfrom GmxDialog import *\n\n");
941 /* Class definition */
942 fprintf(out
,"class %s:\n",cls
);
943 fprintf(out
," def __init__(self,tk):\n");
946 fprintf(out
," %s_help = \"\"\"\n",cls
);
947 fprintf(out
," DESCRIPTION\n");
948 print_tty_formatted(out
,nldesc
,desc
,8,links
,program
,FALSE
);
950 fprintf(out
,"\n BUGS and PROBLEMS\n");
951 for(i
=0; i
<nbug
; i
++) {
952 snew(tmp
,strlen(bugs
[i
])+3);
954 strcpy(tmp
+2,check_tty(bugs
[i
]));
955 fprintf(out
,"%s\n",wrap_lines(tmp
,78,10,TRUE
));
959 fprintf(out
," \"\"\"\n\n # Command line options\n");
961 fprintf(out
," flags = []\n");
962 for(i
=0; (i
<nfile
); i
++)
963 fprintf(out
," flags.append(pca_file('%s',\"%s\",0,%d))\n",
964 ftp2ext_generic(fnm
[i
].ftp
),fnm
[i
].opt
? fnm
[i
].opt
: "k",
965 is_optional(&(fnm
[i
])));
969 for(i
=0; (i
<npargs
); i
++) {
972 fprintf(out
," flags.append(pca_int(\"%s\",\"%s\",%d,%d))\n",
973 pa
[i
].option
,pa
[i
].desc
,*pa
[i
].u
.i
,is_hidden(&(pa
[i
])));
977 fprintf(out
," flags.append(pca_float(\"%s\",\"%s\",%f,%d))\n",
978 pa
[i
].option
,pa
[i
].desc
,*pa
[i
].u
.r
,is_hidden(&(pa
[i
])));
982 fprintf(out
," flags.append(pca_bool(\"%s\",\"%s\",%d,%d))\n",
983 pa
[i
].option
,pa
[i
].desc
,*pa
[i
].u
.b
,is_hidden(&(pa
[i
])));
986 fprintf(stderr
,"Sorry, no rvecs yet...\n");
989 fprintf(out
," flags.append(pca_enum(\"%s\",\"%s\",\n",
990 pa
[i
].option
,pa
[i
].desc
);
991 fprintf(out
," ['%s'",pa
[i
].u
.c
[1]);
992 for(j
=2; (pa
[i
].u
.c
[j
] != NULL
); j
++)
993 fprintf(out
,",'%s'",pa
[i
].u
.c
[j
]);
994 fprintf(out
,"],%d))\n",is_hidden(&(pa
[i
])));
1000 /* Make the dialog box */
1001 fprintf(out
," gmxd = gmx_dialog(tk,\"%s\",flags,%s_help)\n\n",
1005 fprintf(out
,"#####################################################\n");
1006 fprintf(out
,"tk = Tk()\n");
1007 fprintf(out
,"my%s = %s(tk)\n",cls
,cls
);
1008 fprintf(out
,"tk.mainloop()\n");
1011 void write_man(FILE *out
,const char *mantp
,
1012 const char *program
,
1013 int nldesc
,const char **desc
,
1014 int nfile
,t_filenm
*fnm
,
1015 int npargs
,t_pargs
*pa
,
1016 int nbug
,const char **bugs
,
1025 links
=init_linkdata();
1027 /* Don't write hidden options to completions, it just
1028 * makes the options more complicated for normal users
1038 for(i
=0;i
<npargs
;i
++)
1039 if (!is_hidden(&pa
[i
])) {
1045 if ((pr
=strrchr(program
,'/')) == NULL
)
1049 if (strcmp(mantp
,"tex")==0)
1050 write_texman(out
,pr
,nldesc
,desc
,nfile
,fnm
,npar
,par
,nbug
,bugs
,links
);
1051 if (strcmp(mantp
,"nroff")==0)
1052 write_nroffman(out
,pr
,nldesc
,desc
,nfile
,fnm
,npar
,par
,nbug
,bugs
,links
);
1053 if (strcmp(mantp
,"ascii")==0)
1054 write_ttyman(out
,pr
,nldesc
,desc
,nfile
,fnm
,npar
,par
,nbug
,bugs
,TRUE
,links
);
1055 if (strcmp(mantp
,"wiki")==0)
1056 write_wikiman(out
,pr
,nldesc
,desc
,nfile
,fnm
,npar
,par
,nbug
,bugs
,TRUE
,links
);
1057 if (strcmp(mantp
,"help")==0)
1058 write_ttyman(out
,pr
,nldesc
,desc
,nfile
,fnm
,npar
,par
,nbug
,bugs
,FALSE
,links
);
1059 if (strcmp(mantp
,"html")==0)
1060 write_htmlman(out
,pr
,nldesc
,desc
,nfile
,fnm
,npar
,par
,nbug
,bugs
,links
);
1061 if (strcmp(mantp
,"py")==0)
1062 write_py(out
,pr
,nldesc
,desc
,nfile
,fnm
,npar
,par
,nbug
,bugs
,links
);
1063 if (strcmp(mantp
,"xml")==0)
1064 write_xmlman(out
,pr
,nldesc
,desc
,nfile
,fnm
,npargs
,pa
,nbug
,bugs
,links
);
1065 if (strcmp(mantp
,"completion-zsh")==0)
1066 write_zshcompl(out
,nfile
,fnm
,npar
,par
);
1067 if (strcmp(mantp
,"completion-bash")==0)
1068 write_bashcompl(out
,nfile
,fnm
,npar
,par
);
1069 if (strcmp(mantp
,"completion-csh")==0)
1070 write_cshcompl(out
,nfile
,fnm
,npar
,par
);
1075 finish_linkdata(links
);