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
43 #include "gromacs/utility/exceptions.h"
44 #include "gromacs/utility/stringutil.h"
46 #include "gmx_fatal.h"
58 /* The source code in this file should be thread-safe.
59 Please keep it that way. */
63 const char *search, *replace;
67 char *search, *replace;
70 /* The order of these arrays is significant. Text search and replace
71 * for each element occurs in order, so earlier changes can induce
72 * subsequent changes even though the original text might not appear
73 * to invoke the latter changes. */
75 const t_sandr_const sandrTeX[] = {
83 /* Escaping underscore for LaTeX is no longer necessary, and it breaks
84 * text searching and the index if you do. */
89 { "<=", "\\ensuremath{\\leq{}}"},
90 { ">=", "\\ensuremath{\\geq{}}"},
91 { "<", "\\textless{}" },
92 { ">", "\\textgreater{}" },
94 { "\\^{}t", "\\ensuremath{^t}" },
95 { "\\^{}a", "\\ensuremath{^a}" },
96 { "\\^{}b", "\\ensuremath{^b}" },
97 { "\\^{}2", "\\ensuremath{^2}" },
98 { "\\^{}3", "\\ensuremath{^3}" },
99 { "\\^{}6", "\\ensuremath{^6}" },
104 /* The next couple of lines allow true Greek symbols to be written to the
105 manual, which makes it look pretty */
106 { "[GRK]", "\\ensuremath{\\" },
108 { "[MATH]", "\\ensuremath{" },
110 { "[CHEVRON]", "\\ensuremath{<}" },
111 { "[chevron]", "\\ensuremath{>}" },
112 { "[MAG]", "\\ensuremath{|}" },
113 { "[mag]", "\\ensuremath{|}" },
114 { "[INT]", "\\ensuremath{\\int" },
120 { "[SUM]", "\\ensuremath{\\sum" },
122 { "[SUB]", "\\ensuremath{_{" },
124 { "[SQRT]", "\\ensuremath{\\sqrt{" },
126 { "[EXP]", "\\ensuremath{\\exp{(" },
128 { "[LN]", "\\ensuremath{\\ln{(" },
130 { "[LOG]", "\\ensuremath{\\log{(" },
132 { "[COS]", "\\ensuremath{\\cos{(" },
134 { "[SIN]", "\\ensuremath{\\sin{(" },
136 { "[TAN]", "\\ensuremath{\\tan{(" },
138 { "[COSH]", "\\ensuremath{\\cosh{(" },
140 { "[SINH]", "\\ensuremath{\\sinh{(" },
142 { "[TANH]", "\\ensuremath{\\tanh{(" },
145 #define NSRTEX asize(sandrTeX)
147 const t_sandr_const sandrTty[] = {
156 { "[CHEVRON]", "<" },
157 { "[chevron]", ">" },
160 { "[INT]", "integral" },
161 { "[FROM]", " from " },
170 { "[SQRT]", "sqrt(" },
184 { "[COSH]", "cosh(" },
186 { "[SINH]", "sinh(" },
188 { "[TANH]", "tanh(" },
195 #define NSRTTY asize(sandrTty)
197 const t_sandr_const sandrWiki[] = {
201 { "[TT]", "<code>" },
202 { "[tt]", "</code>" },
209 { "[CHEVRON]", "<" },
210 { "[chevron]", ">" },
213 { "[INT]", "integral" },
214 { "[FROM]", " from " },
223 { "[SQRT]", "sqrt(" },
237 { "[COSH]", "cosh(" },
239 { "[SINH]", "sinh(" },
241 { "[TANH]", "tanh(" },
248 #define NSRWIKI asize(sandrWiki)
250 const t_sandr_const sandrNROFF[] = {
259 { "[CHEVRON]", "<" },
260 { "[chevron]", ">" },
263 { "[INT]", "integral" },
264 { "[FROM]", " from " },
273 { "[SQRT]", "sqrt(" },
287 { "[COSH]", "cosh(" },
289 { "[SINH]", "sinh(" },
291 { "[TANH]", "tanh(" },
304 #define NSRNROFF asize(sandrNROFF)
306 const t_sandr_const sandrHTML[] = {
317 { "[CHEVRON]", "<" },
318 { "[chevron]", ">" },
321 { "[INT]", "integral" },
322 { "[FROM]", " from " },
331 { "[SQRT]", "sqrt(" },
345 { "[COSH]", "cosh(" },
347 { "[SINH]", "sinh(" },
349 { "[TANH]", "tanh(" },
356 #define NSRHTML asize(sandrHTML)
358 const t_sandr_const sandrXML[] = {
362 { "[tt]", "</arg>" },
364 { "[bb]", "</emp>" },
369 { "[CHEVRON]", "<" },
370 { "[chevron]", ">" },
373 { "[INT]", "integral" },
374 { "[FROM]", " from " },
383 { "[SQRT]", "sqrt(" },
397 { "[COSH]", "cosh(" },
399 { "[SINH]", "sinh(" },
401 { "[TANH]", "tanh(" },
403 { "[PAR]", "</par>\n<par>" },
404 { "[BR]", "<br />" },
408 #define NSRXML asize(sandrXML)
410 static void mynum(char *buf, int n)
414 sprintf(buf, "%2d", n);
418 sprintf(buf, "0%1d", n);
422 static char *mydate(char buf[], int maxsize, gmx_bool bWiki)
424 const char *mon[] = {
425 "Jan", "Feb", "Mar", "Apr", "May", "Jun",
426 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
428 const char *day[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
433 #ifdef GMX_NATIVE_WINDOWS
435 localtime_s(&tm, &now);
437 localtime_r(&now, &tm);
440 /* subtract one from maxsize, so we have room for \0. */
443 char dd[8], mm[8], ss[8], hh[8], mn[8];
445 mynum(dd, tm.tm_mday);
446 mynum(mm, tm.tm_mon);
447 mynum(ss, tm.tm_sec);
448 mynum(hh, tm.tm_hour);
449 mynum(mn, tm.tm_min);
450 sprintf(buf, "%4d-%2s-%2sT%2s:%2s:%2sZ",
451 tm.tm_year+1900, mm, dd, hh, mn, ss);
455 sprintf(buf, "%s %d %s %d", day[tm.tm_wday], tm.tm_mday,
456 mon[tm.tm_mon], tm.tm_year+1900);
462 /* Data structure for saved HTML links */
463 typedef struct t_linkdata {
468 static t_linkdata *init_linkdata()
478 static void finish_linkdata(t_linkdata *p)
482 for (i = 0; i < p->nsr; i++)
484 sfree(p->sr[i].search);
485 sfree(p->sr[i].replace);
491 static char *repall(const char *s, int nsr, const t_sandr_const sa[])
495 std::string result(s);
496 for (int i = 0; i < nsr; ++i)
498 result = gmx::replaceAll(result, sa[i].search, sa[i].replace);
500 return gmx_strdup(result.c_str());
502 GMX_CATCH_ALL_AND_EXIT_WITH_FATAL_ERROR;
505 static char *repallww(const char *s, int nsr, const t_sandr sa[])
509 std::string result(s);
510 for (int i = 0; i < nsr; ++i)
512 result = gmx::replaceAllWords(result, sa[i].search, sa[i].replace);
514 return gmx_strdup(result.c_str());
516 GMX_CATCH_ALL_AND_EXIT_WITH_FATAL_ERROR;
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)
526 n = get_file("links.dat", &(filestr));
529 for (i = 0, j = 0; (i < n); i++)
531 if (!program || (gmx_strcasecmp(program, filestr[i]) != 0))
533 links->sr[j].search = gmx_strdup(filestr[i]);
536 sprintf(buf, "[[%s]]", filestr[i]);
540 sprintf(buf, "<a href=\"%s.html\">%s</a>", filestr[i], filestr[i]);
542 links->sr[j].replace = gmx_strdup(buf);
547 for (i = 0; i < n; i++)
553 return repallww(s, links->nsr, links->sr);
556 char *check_tex(const char *s)
558 return repall(s, NSRTEX, sandrTeX);
561 static char *check_nroff(const char *s)
563 return repall(s, NSRNROFF, sandrNROFF);
566 static char *check_wiki(const char *s, const char *program, t_linkdata *links)
570 buf = repall(s, NSRWIKI, sandrWiki);
571 buf = html_xref(buf, program, links, TRUE);
576 static char *check_html(const char *s, const char *program, t_linkdata *links)
580 buf = repall(s, NSRHTML, sandrHTML);
581 buf = html_xref(buf, program, links, FALSE);
586 #define NWR(s) check_wiki(s, program, links)
587 #define NSR(s) check_html(s, program, links)
589 #define FLAG_SET(flag, mask) ((flag &mask) == mask)
590 char *fileopt(unsigned long flag, char buf[], int maxsize)
594 if (FLAG_SET(flag, ffRW))
596 sprintf(tmp, "In/Out");
598 else if (FLAG_SET(flag, ffREAD))
600 sprintf(tmp, "Input");
602 else if (FLAG_SET(flag, ffWRITE))
604 sprintf(tmp, "Output");
608 sprintf(tmp, "Dunno");
611 if (FLAG_SET(flag, ffOPT))
613 strcat(tmp, ", Opt");
614 if (FLAG_SET(flag, ffSET))
623 if (FLAG_SET(flag, ffLIB))
625 strcat(tmp, ", Lib.");
627 if (FLAG_SET(flag, ffMULT))
629 strcat(tmp, ", Mult.");
632 sprintf(buf, "%s", tmp);
637 static void write_texman(FILE *out, const char *program,
638 int nldesc, const char **desc,
639 int nfile, t_filenm *fnm,
640 int npargs, t_pargs *pa,
641 int nbug, const char **bugs,
647 fprintf(out, "\\section{\\normindex{%s}}\\label{%s}\n\n", check_tex(program), check_tex(program));
651 for (i = 0; (i < nldesc); i++)
653 fprintf(out, "%s\n", check_tex(desc[i]));
659 fprintf(out, "\\vspace{-2ex}\\begin{tabbing}\n");
660 fprintf(out, "\n{\\normalsize \\bf Files}\\nopagebreak\\\\\n");
661 fprintf(out, "{\\tt ~~~~~~~} \\= {\\tt ~~~~~~~~~~~~~~} \\= "
662 "~~~~~~~~~~~~~~~~~~~~~~ \\= \\nopagebreak\\kill\n");
663 for (i = 0; (i < nfile); i++)
665 fprintf(out, "\\>{\\tt %s} \\'\\> {\\tt %s} \\' %s \\> "
666 "\\parbox[t]{0.55\\linewidth}{%s} \\\\\n",
667 check_tex(fnm[i].opt), check_tex(fnm[i].fns[0]),
668 check_tex(fileopt(fnm[i].flag, tmp, 255)),
669 check_tex(ftp2desc(fnm[i].ftp)));
671 fprintf(out, "\\end{tabbing}\\vspace{-4ex}\n");
675 fprintf(out, "\\vspace{-2ex}\\begin{tabbing}\n");
676 fprintf(out, "\n{\\normalsize \\bf Other options}\\nopagebreak\\\\\n");
677 fprintf(out, "{\\tt ~~~~~~~~~~} \\= vector \\= "
678 "{\\tt ~~~~~~~} \\= \\nopagebreak\\kill\n");
679 for (i = 0; (i < npargs); i++)
681 if (strlen(check_tex(pa_val(&(pa[i]), tmp, 255))) <= 8)
683 fprintf(out, "\\> {\\tt %s} \\'\\> %s \\'\\> {\\tt %s} \\' "
684 "\\parbox[t]{0.68\\linewidth}{%s}\\\\\n",
685 check_tex(pa[i].option), get_arg_desc(pa[i].type),
686 check_tex(pa_val(&(pa[i]), tmp, 255)),
687 check_tex(pa[i].desc));
691 fprintf(out, "\\> {\\tt %s} \\'\\> %s \\'\\>\\\\\n"
692 "\\> \\'\\> \\'\\> {\\tt %s} \\' "
693 "\\parbox[t]{0.7\\linewidth}{%s}\\\\\n",
694 check_tex(pa[i].option), get_arg_desc(pa[i].type),
695 check_tex(pa_val(&(pa[i]), tmp, 255)),
696 check_tex(pa[i].desc));
699 fprintf(out, "\\end{tabbing}\\vspace{-4ex}\n");
704 fprintf(out, "\\begin{itemize}\n");
705 for (i = 0; (i < nbug); i++)
707 fprintf(out, "\\item %s\n", check_tex(bugs[i]));
709 fprintf(out, "\\end{itemize}\n");
711 /* fprintf(out,"\n\\newpage\n"); */
714 static void write_nroffman(FILE *out,
716 int nldesc, const char **desc,
717 int nfile, t_filenm *fnm,
718 int npargs, t_pargs *pa,
719 int nbug, const char **bugs,
727 fprintf(out, ".TH %s 1 \"%s\" \"\" \"GROMACS suite, %s\"\n", program, mydate(tmp, 255, FALSE), GromacsVersion());
728 fprintf(out, ".SH NAME\n");
729 fprintf(out, "%s@DESC@\n\n", program);
730 fprintf(out, ".B %s\n", GromacsVersion());
732 fprintf(out, ".SH SYNOPSIS\n");
733 fprintf(out, "\\f3%s\\fP\n", program);
735 /* command line arguments */
738 for (i = 0; (i < nfile); i++)
740 fprintf(out, ".BI \"%s\" \" %s \"\n", check_nroff(fnm[i].opt),
741 check_nroff(fnm[i].fns[0]));
746 for (i = 0; (i < npargs); i++)
748 if (pa[i].type == etBOOL)
750 fprintf(out, ".BI \"\\-[no]%s\" \"\"\n", check_nroff(pa[i].option+1));
754 fprintf(out, ".BI \"%s\" \" %s \"\n", check_nroff(pa[i].option),
755 check_nroff(get_arg_desc(pa[i].type)));
763 fprintf(out, ".SH DESCRIPTION\n");
764 for (i = 0; (i < nldesc); i++)
766 fprintf(out, "\\&%s\n", check_nroff(desc[i]));
773 fprintf(out, ".SH FILES\n");
774 for (i = 0; (i < nfile); i++)
776 fprintf(out, ".BI \"%s\" \" %s\" \n.B %s\n %s \n\n",
777 check_nroff(fnm[i].opt),
778 check_nroff(fnm[i].fns[0]),
779 check_nroff(fileopt(fnm[i].flag, tmp, 255)),
780 check_nroff(ftp2desc(fnm[i].ftp)));
785 fprintf(out, ".SH OTHER OPTIONS\n");
788 for (i = 0; (i < npargs); i++)
790 if (pa[i].type == etBOOL)
792 fprintf(out, ".BI \"\\-[no]%s\" \"%s\"\n %s\n\n",
793 check_nroff(pa[i].option+1),
794 check_nroff(pa_val(&(pa[i]), tmp, 255)),
795 check_nroff(pa[i].desc));
799 fprintf(out, ".BI \"%s\" \" %s\" \" %s\" \n %s\n\n",
800 check_nroff(pa[i].option),
801 check_nroff(get_arg_desc(pa[i].type)),
802 check_nroff(pa_val(&(pa[i]), tmp, 255)),
803 check_nroff(pa[i].desc));
810 fprintf(out, ".SH KNOWN PROBLEMS\n");
811 for (i = 0; (i < nbug); i++)
813 fprintf(out, "\\- %s\n\n", check_nroff(bugs[i]));
817 fprintf(out, ".SH SEE ALSO\n.BR gromacs(7)\n\n");
818 fprintf(out, "More information about \\fBGROMACS\\fR is available at <\\fIhttp://www.gromacs.org/\\fR>.\n");
822 char *check_tty(const char *s)
824 return repall(s, NSRTTY, sandrTty);
828 print_tty_formatted(FILE *out, int nldesc, const char **desc, int indent,
829 t_linkdata *links, const char *program, gmx_bool bWiki)
837 for (i = 0; (i < nldesc); i++)
839 if ((strlen(buf) > 0) &&
840 (buf[strlen(buf)-1] != ' ') && (buf[strlen(buf)-1] != '\n'))
850 temp = check_tty(desc[i]);
852 if (strlen(buf) + strlen(temp) >= (size_t)(buflen-2))
854 buflen += strlen(temp);
860 /* Make lines of at most 79 characters */
861 temp = wrap_lines(buf, 78, indent, FALSE);
862 fprintf(out, "%s\n", temp);
867 static void write_ttyman(FILE *out,
869 int nldesc, const char **desc,
870 int nfile, t_filenm *fnm,
871 int npargs, t_pargs *pa,
872 int nbug, const char **bugs, gmx_bool bHeader,
881 fprintf(out, "%s\n\n", check_tty(program));
882 fprintf(out, "%s\n%s\n", GromacsVersion(), mydate(buf, 255, FALSE));
886 fprintf(out, "DESCRIPTION\n-----------\n");
887 print_tty_formatted(out, nldesc, desc, 0, links, program, FALSE);
892 fprintf(out, "KNOWN PROBLEMS\n----------\n");
893 for (i = 0; i < nbug; i++)
895 snew(tmp, strlen(bugs[i])+3);
897 strcpy(tmp+2, check_tty(bugs[i]));
898 fprintf(out, "%s\n", wrap_lines(tmp, 78, 2, FALSE));
905 pr_fns(out, nfile, fnm);
909 print_pargs(out, npargs, pa, FALSE);
913 static void pr_html_files(FILE *out, int nfile, t_filenm fnm[],
914 const char *program, t_linkdata *links, gmx_bool bWiki)
917 char link[10], tmp[255];
921 fprintf(out, " %-10s %-12s %-12s %-s\n"
922 " -----------------------------------------------------\n",
923 "Option", "Filename", "Type", "Description");
928 "<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=2>\n"
933 "<TH>description</TH>"
937 for (i = 0; (i < nfile); i++)
939 strcpy(link, ftp2ext(fnm[i].ftp));
940 if (strcmp(link, "???") == 0)
942 strcpy(link, "files");
946 fprintf(out, " %-10s %-16s %-12s %-s\n",
949 fileopt(fnm[i].flag, tmp, 255),
950 NWR(ftp2desc(fnm[i].ftp)));
956 "<TD ALIGN=RIGHT> <b><tt>%s</tt></b> </TD>"
957 "<TD ALIGN=RIGHT> <tt><a href=\"%s.html\">%12s</a></tt> </TD>"
961 fnm[i].opt, link, fnm[i].fns[0], fileopt(fnm[i].flag, tmp, 255),
962 NSR(ftp2desc(fnm[i].ftp)));
967 fprintf(out, "</TABLE>\n");
971 static void write_wikiman(FILE *out,
973 int nldesc, const char **desc,
974 int nfile, t_filenm *fnm,
975 int npargs, t_pargs *pa,
976 int nbug, const char **bugs, gmx_bool bHeader,
982 fprintf(out, "<page>\n<title>Manual:%s_%s</title>\n", program,
984 fprintf(out, "<revision>\n");
985 fprintf(out, "<timestamp>%s</timestamp>\n", mydate(buf, 255, TRUE));
986 fprintf(out, "<text xml:space=\"preserve\">\n");
989 fprintf(out, "== Description ==\n");
990 print_tty_formatted(out, nldesc, desc, 0, links, program, TRUE);
995 fprintf(out, "== Known Problems ==\n");
996 for (i = 0; i < nbug; i++)
998 snew(tmp, strlen(bugs[i])+3);
1000 strcpy(tmp+2, bugs[i]);
1001 fprintf(out, "%s\n", NWR(tmp));
1007 fprintf(out, "\n== Files ==\n");
1008 pr_html_files(out, nfile, fnm, program, links, TRUE);
1012 fprintf(out, "\n== Options ==\n");
1013 fprintf(out, " %-12s %-6s %-6s %-s\n",
1014 "Option", "Type", "Value", "Description");
1015 fprintf(out, " ------------------------------------------------------\n");
1016 for (i = 0; (i < npargs); i++)
1018 tmp = NWR(pargs_print_line(&pa[i], TRUE));
1019 fprintf(out, "%s", tmp);
1023 fprintf(out, "[[category:Manual_Pages_%s|%s]]\n", VERSION, program);
1024 fprintf(out, "</text>\n");
1025 fprintf(out, "</revision>\n");
1026 fprintf(out, "</page>\n\n");
1029 static void write_htmlman(FILE *out,
1030 const char *program,
1031 int nldesc, const char **desc,
1032 int nfile, t_filenm *fnm,
1033 int npargs, t_pargs *pa,
1034 int nbug, const char **bugs,
1040 fprintf(out, "<HTML>\n<HEAD>\n<TITLE>%s</TITLE>\n", program);
1041 fprintf(out, "<LINK rel=stylesheet href=\"style.css\" type=\"text/css\">\n");
1042 fprintf(out, "<BODY text=\"#000000\" bgcolor=\"#FFFFFF\" link=\"#0000FF\" vlink=\"#990000\" alink=\"#FF0000\">\n");
1043 fprintf(out, "<TABLE WIDTH=\"98%%\" NOBORDER >\n<TR><TD WIDTH=400>\n");
1044 fprintf(out, "<TABLE WIDTH=400 NOBORDER>\n<TD WIDTH=116>\n");
1045 fprintf(out, "<a href=\"http://www.gromacs.org/\">"
1046 "<img SRC=\"../images/gmxlogo_small.png\""
1047 "BORDER=0 </a></td>\n");
1048 fprintf(out, "<td ALIGN=LEFT VALIGN=TOP WIDTH=280>"
1049 "<br><h2>%s</h2>", program);
1050 fprintf(out, "<font size=-1><A HREF=\"../online.html\">Main Table of Contents</A></font><br>");
1051 fprintf(out, "<br></td>\n</TABLE></TD><TD WIDTH=\"*\" ALIGN=RIGHT VALIGN=BOTTOM><p><B>%s<br>\n", GromacsVersion());
1052 fprintf(out, "%s</B></td></tr></TABLE>\n<HR>\n", mydate(tmp, 255, FALSE));
1056 fprintf(out, "<H3>Description</H3>\n<p>\n");
1057 for (i = 0; (i < nldesc); i++)
1059 fprintf(out, "%s\n", NSR(desc[i]));
1064 fprintf(out, "<P>\n");
1065 fprintf(out, "<H3>Files</H3>\n");
1066 pr_html_files(out, nfile, fnm, program, links, FALSE);
1070 fprintf(out, "<P>\n");
1071 fprintf(out, "<H3>Other options</H3>\n");
1073 "<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=2>\n"
1078 "<TH>description</TH>"
1080 for (i = 0; (i < npargs); i++)
1084 "<TD ALIGN=RIGHT> <b><tt>%s%s</tt></b> </TD>"
1085 "<TD ALIGN=RIGHT> %s </TD>"
1086 "<TD ALIGN=RIGHT> <tt>%s</tt> </TD>"
1089 (pa[i].type == etBOOL) ? "-[no]" : "-", pa[i].option+1,
1090 get_arg_desc(pa[i].type), pa_val(&(pa[i]), tmp, 255), NSR(pa[i].desc));
1092 fprintf(out, "</TABLE>\n");
1096 fprintf(out, "<P>\n");
1097 fprintf(out, "<H3>Known problems</H3>\n");
1098 fprintf(out, "<UL>\n");
1099 for (i = 0; (i < nbug); i++)
1101 fprintf(out, "<LI>%s\n", NSR(bugs[i]));
1103 fprintf(out, "</UL>\n");
1105 fprintf(out, "<P>\n");
1106 fprintf(out, "<hr>\n<div ALIGN=RIGHT>\n");
1107 fprintf(out, "<font size=\"-1\"><a href=\"http://www.gromacs.org\">"
1108 "http://www.gromacs.org</a></font><br>\n");
1109 fprintf(out, "<font size=\"-1\"><a href=\"mailto:gromacs@gromacs.org\">"
1110 "gromacs@gromacs.org</a></font><br>\n");
1111 fprintf(out, "</div>\n");
1112 fprintf(out, "</BODY>\n");
1115 char *check_xml(const char *s, const char *program, t_linkdata *links)
1119 buf = repall(s, NSRXML, sandrXML);
1120 buf = html_xref(buf, program, links, FALSE); /* the same in html and xml */
1125 static void write_xmlman(FILE *out,
1126 const char *program,
1127 int nldesc, const char **desc,
1128 int nfile, t_filenm *fnm,
1129 int npargs, t_pargs *pa,
1130 int nbug, const char **bugs,
1134 char link[10], buf[256], opt[10];
1136 #define NSR2(s) check_xml(s, program, links)
1137 #define FLAG(w, f) (((w) & (f)) == (f))
1139 fprintf(out, "<gromacs-manual version=\"%s\" date=\"%s\" www=\"http://www.gromacs.org\">\n", GromacsVersion(), mydate(buf, 255, FALSE));
1140 /* fprintf(out,"<LINK rel=stylesheet href=\"style.css\" type=\"text/css\">\n"); */
1142 fprintf(out, "<program name=\"%s\">", program);
1145 fprintf(out, "\n<description>\n<par>\n");
1146 for (i = 0; (i < nldesc); i++)
1148 fprintf(out, "%s\n", NSR2(desc[i]));
1151 fprintf(out, "</par>\n</description>\n");
1155 fprintf(out, "\n<files>\n");
1156 for (i = 0; (i < nfile); i++)
1158 strcpy(link, ftp2ext(fnm[i].ftp));
1159 if (strcmp(link, "???") == 0)
1161 strcpy(link, "files");
1163 if (fnm[i].opt[0] == '-')
1165 strcpy(opt, fnm[i].opt+1);
1169 strcpy(opt, fnm[i].opt);
1172 "<file type=\"%s\" typeid=\"%d\">\n"
1173 "\t<flags read=\"%d\" write=\"%d\" optional=\"%d\"/>\n"
1174 "\t<option>%s</option>\n"
1175 "\t<default-name link=\"%s.html\">%s</default-name>\n"
1176 "\t<description>%s</description>\n"
1178 ftp2defnm(fnm[i].ftp), /* from gmxlib/filenm.c */
1180 FLAG(fnm[i].flag, ffREAD), FLAG(fnm[i].flag, ffWRITE), FLAG(fnm[i].flag, ffOPT),
1181 opt, link, fnm[i].fn, /*fileopt(fnm[i].flag),*/
1182 NSR(ftp2desc(fnm[i].ftp)));
1184 fprintf(out, "</files>\n");
1189 fprintf(out, "\n<options>\n");
1190 for (i = 0; (i < npargs); i++)
1193 "<option type=\"%s\" hidden=\"%d\">\n"
1194 "\t<name >%s</name>\n"
1195 "\t<default-value>%s</default-value>\n"
1196 "\t<description>%s</description>\n"
1198 get_arg_desc(pa[i].type), is_hidden(&pa[i]),
1199 pa[i].option+1, /* +1 - with no trailing '-' */
1200 pa_val(&(pa[i]), buf, 255), pa[i].desc); /*get_argtp()[pa[i].type],*/
1202 fprintf(out, "</options>\n");
1207 fprintf(out, "\n<bugs>\n");
1208 for (i = 0; (i < nbug); i++)
1210 fprintf(out, "\t<bug>%s</bug>\n", NSR(bugs[i]));
1212 fprintf(out, "</bugs>\n");
1214 fprintf(out, "\n</program>\n</gromacs-manual>\n");
1218 static void pr_opts(FILE *fp,
1219 int nfile, t_filenm *fnm,
1220 int npargs, t_pargs pa[], int shell)
1227 fprintf(fp, " \"c/-/(");
1228 for (i = 0; i < nfile; i++)
1230 fprintf(fp, " %s", fnm[i].opt+1);
1232 for (i = 0; i < npargs; i++)
1234 if ( (pa[i].type == etBOOL) && *(pa[i].u.b) )
1236 fprintf(fp, " no%s", pa[i].option+1);
1240 fprintf(fp, " %s", pa[i].option+1);
1243 fprintf(fp, ")/\"");
1246 fprintf(fp, "if (( $COMP_CWORD <= 1 )) || [[ $c == -* ]]; then COMPREPLY=( $(compgen -W '");
1247 for (i = 0; i < nfile; i++)
1249 fprintf(fp, " -%s", fnm[i].opt+1);
1251 for (i = 0; i < npargs; i++)
1253 if ( (pa[i].type == etBOOL) && *(pa[i].u.b) )
1255 fprintf(fp, " -no%s", pa[i].option+1);
1259 fprintf(fp, " -%s", pa[i].option+1);
1262 fprintf(fp, "' -- $c)); return 0; fi\n");
1265 fprintf(fp, " -x 's[-]' -s \"");
1266 for (i = 0; i < nfile; i++)
1268 fprintf(fp, " %s", fnm[i].opt+1);
1270 for (i = 0; i < npargs; i++)
1272 if ( (pa[i].type == etBOOL) && *(pa[i].u.b) )
1274 fprintf(fp, " no%s", pa[i].option+1);
1278 fprintf(fp, " %s", pa[i].option+1);
1286 static void write_cshcompl(FILE *out,
1287 int nfile, t_filenm *fnm,
1288 int npargs, t_pargs *pa)
1290 fprintf(out, "complete %s", ShortProgram());
1291 pr_enums(out, npargs, pa, eshellCSH);
1292 pr_fopts(out, nfile, fnm, eshellCSH);
1293 pr_opts(out, nfile, fnm, npargs, pa, eshellCSH);
1297 static void write_zshcompl(FILE *out,
1298 int nfile, t_filenm *fnm,
1299 int npargs, t_pargs *pa)
1301 fprintf(out, "compctl ");
1303 /* start with options, since they are always present */
1304 pr_opts(out, nfile, fnm, npargs, pa, eshellZSH);
1305 pr_enums(out, npargs, pa, eshellZSH);
1306 pr_fopts(out, nfile, fnm, eshellZSH);
1307 fprintf(out, "-- %s\n", ShortProgram());
1310 static void write_bashcompl(FILE *out,
1311 int nfile, t_filenm *fnm,
1312 int npargs, t_pargs *pa)
1314 /* Advanced bash completions are handled by shell functions.
1315 * p and c hold the previous and current word on the command line.
1316 * We need to use extended globbing, so write it in each completion file */
1317 fprintf(out, "shopt -s extglob\n");
1318 fprintf(out, "_%s_compl() {\nlocal p c\n", ShortProgram());
1319 fprintf(out, "COMPREPLY=() c=${COMP_WORDS[COMP_CWORD]} p=${COMP_WORDS[COMP_CWORD-1]}\n");
1320 pr_opts(out, nfile, fnm, npargs, pa, eshellBASH);
1321 fprintf(out, "case \"$p\" in\n");
1323 pr_enums(out, npargs, pa, eshellBASH);
1324 pr_fopts(out, nfile, fnm, eshellBASH);
1325 fprintf(out, "esac }\ncomplete -F _%s_compl %s\n", ShortProgram(), ShortProgram());
1328 static void write_py(FILE *out, const char *program,
1329 int nldesc, const char **desc,
1330 int nfile, t_filenm *fnm,
1331 int npargs, t_pargs *pa,
1332 int nbug, const char **bugs,
1335 const char *cls = program;
1340 fprintf(out, "#!/usr/bin/python\n\nfrom GmxDialog import *\n\n");
1342 /* Class definition */
1343 fprintf(out, "class %s:\n", cls);
1344 fprintf(out, " def __init__(self,tk):\n");
1347 fprintf(out, " %s_help = \"\"\"\n", cls);
1348 fprintf(out, " DESCRIPTION\n");
1349 print_tty_formatted(out, nldesc, desc, 8, links, program, FALSE);
1352 fprintf(out, "\n BUGS and PROBLEMS\n");
1353 for (i = 0; i < nbug; i++)
1355 snew(tmp, strlen(bugs[i])+3);
1357 strcpy(tmp+2, check_tty(bugs[i]));
1358 fprintf(out, "%s\n", wrap_lines(tmp, 78, 10, TRUE));
1362 fprintf(out, " \"\"\"\n\n # Command line options\n");
1364 fprintf(out, " flags = []\n");
1365 for (i = 0; (i < nfile); i++)
1367 fprintf(out, " flags.append(pca_file('%s',\"%s\",0,%d))\n",
1368 ftp2ext_generic(fnm[i].ftp), fnm[i].opt ? fnm[i].opt : "k",
1369 is_optional(&(fnm[i])));
1374 for (i = 0; (i < npargs); i++)
1379 fprintf(out, " flags.append(pca_int(\"%s\",\"%s\",%d,%d))\n",
1380 pa[i].option, pa[i].desc, *pa[i].u.i, is_hidden(&(pa[i])));
1384 fprintf(out, " flags.append(pca_float(\"%s\",\"%s\",%f,%d))\n",
1385 pa[i].option, pa[i].desc, *pa[i].u.r, is_hidden(&(pa[i])));
1389 fprintf(out, " flags.append(pca_gmx_bool(\"%s\",\"%s\",%d,%d))\n",
1390 pa[i].option, pa[i].desc, *pa[i].u.b, is_hidden(&(pa[i])));
1393 fprintf(stderr, "Sorry, no rvecs yet...\n");
1396 fprintf(out, " flags.append(pca_enum(\"%s\",\"%s\",\n",
1397 pa[i].option, pa[i].desc);
1398 fprintf(out, " ['%s'", pa[i].u.c[1]);
1399 for (j = 2; (pa[i].u.c[j] != NULL); j++)
1401 fprintf(out, ",'%s'", pa[i].u.c[j]);
1403 fprintf(out, "],%d))\n", is_hidden(&(pa[i])));
1410 /* Make the dialog box */
1411 fprintf(out, " gmxd = gmx_dialog(tk,\"%s\",flags,%s_help)\n\n",
1415 fprintf(out, "#####################################################\n");
1416 fprintf(out, "tk = Tk()\n");
1417 fprintf(out, "my%s = %s(tk)\n", cls, cls);
1418 fprintf(out, "tk.mainloop()\n");
1421 void write_man(FILE *out, const char *mantp,
1422 const char *program,
1423 int nldesc, const char **desc,
1424 int nfile, t_filenm *fnm,
1425 int npargs, t_pargs *pa,
1426 int nbug, const char **bugs,
1435 links = init_linkdata();
1437 /* Don't write hidden options to completions, it just
1438 * makes the options more complicated for normal users
1450 for (i = 0; i < npargs; i++)
1452 if (!is_hidden(&pa[i]))
1460 if ((pr = strrchr(program, DIR_SEPARATOR)) == NULL)
1468 if (strcmp(mantp, "tex") == 0)
1470 write_texman(out, pr, nldesc, desc, nfile, fnm, npar, par, nbug, bugs, links);
1472 if (strcmp(mantp, "nroff") == 0)
1474 write_nroffman(out, pr, nldesc, desc, nfile, fnm, npar, par, nbug, bugs, links);
1476 if (strcmp(mantp, "ascii") == 0)
1478 write_ttyman(out, pr, nldesc, desc, nfile, fnm, npar, par, nbug, bugs, TRUE, links);
1480 if (strcmp(mantp, "wiki") == 0)
1482 write_wikiman(out, pr, nldesc, desc, nfile, fnm, npar, par, nbug, bugs, TRUE, links);
1484 if (strcmp(mantp, "help") == 0)
1486 write_ttyman(out, pr, nldesc, desc, nfile, fnm, npar, par, nbug, bugs, FALSE, links);
1488 if (strcmp(mantp, "html") == 0)
1490 write_htmlman(out, pr, nldesc, desc, nfile, fnm, npar, par, nbug, bugs, links);
1492 if (strcmp(mantp, "py") == 0)
1494 write_py(out, pr, nldesc, desc, nfile, fnm, npar, par, nbug, bugs, links);
1496 if (strcmp(mantp, "xml") == 0)
1498 write_xmlman(out, pr, nldesc, desc, nfile, fnm, npargs, pa, nbug, bugs, links);
1500 if (strcmp(mantp, "completion-zsh") == 0)
1502 write_zshcompl(out, nfile, fnm, npar, par);
1504 if (strcmp(mantp, "completion-bash") == 0)
1506 write_bashcompl(out, nfile, fnm, npar, par);
1508 if (strcmp(mantp, "completion-csh") == 0)
1510 write_cshcompl(out, nfile, fnm, npar, par);
1518 finish_linkdata(links);
1521 const char *get_arg_desc(int type)
1523 static const char *argtp[etNR] = {
1524 "int", "step", "real", "time", "string", "bool", "vector", "enum"