#include "parser_local_proto.h"
static void print_escaped_for_html(FILE * f, const char *str);
static void print_escaped_for_html_options(FILE * f, const char *str);
/*!
\brief Print module usage description in HTML format.
*/
void G__usage_html(void)
{
struct Option *opt;
struct Flag *flag;
const char *type;
int new_prompt = 0;
new_prompt = G__uses_new_gisprompt();
if (!st->pgm_name) /* v.dave && r.michael */
st->pgm_name = G_program_name();
if (!st->pgm_name)
st->pgm_name = "??";
fprintf(stdout,
"\n");
fprintf(stdout, "\n\n");
fprintf(stdout, "GRASS GIS manual: %s \n", st->pgm_name);
fprintf(stdout,
" \n");
fprintf(stdout,
" \n");
fprintf(stdout, "\n");
fprintf(stdout, "\n\n");
fprintf(stdout,
" \n\n");
fprintf(stdout, "%s \n", _("NAME"));
fprintf(stdout, "%s ", st->pgm_name);
if (st->module_info.label || st->module_info.description)
fprintf(stdout, " - ");
if (st->module_info.label)
fprintf(stdout, "%s \n", st->module_info.label);
if (st->module_info.description)
fprintf(stdout, "%s\n", st->module_info.description);
fprintf(stdout, "%s \n", _("KEYWORDS"));
if (st->module_info.keywords) {
G__print_keywords(stdout, NULL);
fprintf(stdout, "\n");
}
fprintf(stdout, "%s \n", _("SYNOPSIS"));
fprintf(stdout, "%s
\n", st->pgm_name);
fprintf(stdout, "%s help \n", st->pgm_name);
fprintf(stdout, "%s ", st->pgm_name);
/* print short version first */
if (st->n_flags) {
flag = &st->first_flag;
fprintf(stdout, " [-");
while (flag != NULL) {
fprintf(stdout, "%c", flag->key);
flag = flag->next_flag;
}
fprintf(stdout, " ] ");
}
else
fprintf(stdout, " ");
if (st->n_opts) {
opt = &st->first_option;
while (opt != NULL) {
if (opt->key_desc != NULL)
type = opt->key_desc;
else
switch (opt->type) {
case TYPE_INTEGER:
type = "integer";
break;
case TYPE_DOUBLE:
type = "float";
break;
case TYPE_STRING:
type = "string";
break;
default:
type = "string";
break;
}
if (!opt->required)
fprintf(stdout, " [");
fprintf(stdout, "%s =%s ", opt->key, type);
if (opt->multiple) {
fprintf(stdout, "[,%s ,...]", type);
}
if (!opt->required)
fprintf(stdout, "] ");
opt = opt->next_opt;
fprintf(stdout, " ");
}
}
if (new_prompt)
fprintf(stdout, " [--overwrite ] ");
fprintf(stdout, " [--verbose ] ");
fprintf(stdout, " [--quiet ] ");
fprintf(stdout, "\n
\n");
/* now long version */
fprintf(stdout, "\n");
fprintf(stdout, "\n");
if (st->n_flags || new_prompt) {
flag = &st->first_flag;
fprintf(stdout, "
%s: \n", _("Flags"));
fprintf(stdout, "
\n");
while (st->n_flags && flag != NULL) {
fprintf(stdout, "-%c \n", flag->key);
if (flag->label) {
fprintf(stdout, "");
fprintf(stdout, "%s", flag->label);
fprintf(stdout, " \n");
}
if (flag->description) {
fprintf(stdout, "");
fprintf(stdout, "%s", flag->description);
fprintf(stdout, " \n");
}
flag = flag->next_flag;
fprintf(stdout, "\n");
}
if (new_prompt) {
fprintf(stdout, "--overwrite \n");
fprintf(stdout, "%s \n",
_("Allow output files to overwrite existing files"));
}
fprintf(stdout, "--verbose \n");
fprintf(stdout, "%s \n", _("Verbose module output"));
fprintf(stdout, "--quiet \n");
fprintf(stdout, "%s \n", _("Quiet module output"));
fprintf(stdout, " \n");
}
fprintf(stdout, "
\n");
fprintf(stdout, "\n");
fprintf(stdout, "\n");
if (st->n_opts) {
opt = &st->first_option;
fprintf(stdout, "
%s: \n", _("Parameters"));
fprintf(stdout, "
\n");
while (opt != NULL) {
/* TODO: make this a enumeration type? */
if (opt->key_desc != NULL)
type = opt->key_desc;
else
switch (opt->type) {
case TYPE_INTEGER:
type = "integer";
break;
case TYPE_DOUBLE:
type = "float";
break;
case TYPE_STRING:
type = "string";
break;
default:
type = "string";
break;
}
fprintf(stdout, "%s =%s", opt->key, type);
if (opt->multiple) {
fprintf(stdout, "[,%s ,...]", type);
}
fprintf(stdout, " ");
if (opt->required) {
fprintf(stdout, " [required] ");
}
fprintf(stdout, " \n");
if (opt->label) {
fprintf(stdout, "");
print_escaped_for_html(stdout, opt->label);
fprintf(stdout, " \n");
}
if (opt->description) {
fprintf(stdout, "");
print_escaped_for_html(stdout, opt->description);
fprintf(stdout, " \n");
}
if (opt->options) {
fprintf(stdout, "%s: ", _("Options"));
print_escaped_for_html_options(stdout, opt->options);
fprintf(stdout, " \n");
}
if (opt->def) {
fprintf(stdout, "%s: ", _("Default"));
print_escaped_for_html(stdout, opt->def);
fprintf(stdout, " \n");
}
if (opt->descs) {
int i = 0;
while (opt->opts[i]) {
if (opt->descs[i]) {
fprintf(stdout, "");
print_escaped_for_html(stdout, opt->opts[i]);
fprintf(stdout, " : ");
print_escaped_for_html(stdout, opt->descs[i]);
fprintf(stdout, " \n");
}
i++;
}
}
opt = opt->next_opt;
fprintf(stdout, "\n");
}
fprintf(stdout, " \n");
}
fprintf(stdout, "
\n");
fprintf(stdout, "\n\n");
}
/*!
* \brief Format text for HTML output
*/
#define do_escape(c,escaped) case c: fputs(escaped,f);break
void print_escaped_for_html(FILE * f, const char *str)
{
const char *s;
for (s = str; *s; s++) {
switch (*s) {
do_escape('&', "&");
do_escape('<', "<");
do_escape('>', ">");
do_escape('\n', " ");
do_escape('\t', " ");
default:
fputc(*s, f);
}
}
}
void print_escaped_for_html_options(FILE * f, const char *str)
{
const char *s;
for (s = str; *s; s++) {
switch (*s) {
do_escape('&', "&");
do_escape('<', "<");
do_escape('>', ">");
do_escape('\n', " ");
do_escape('\t', " ");
do_escape(',', ", ");
default:
fputc(*s, f);
}
}
}
#undef do_escape