client/X11: Improve man page generation

This patch contains several improvements:
- add missing colons before format strings
- always print format string after argument
- do not duplicate format string before description
- use <replaceable> only for variables in format string
- use +/- for boolean arguments
- print also default value for all kinds of arguments
This commit is contained in:
Ondrej Holy 2017-09-25 11:37:43 +02:00
parent a49c856d78
commit 7538c86ce3

View File

@ -9,10 +9,10 @@
* the argument struct. */
#include "../common/cmdline.c"
LPSTR tr_esc_str(LPCSTR arg)
LPSTR tr_esc_str(LPCSTR arg, bool format)
{
LPSTR tmp = NULL;
size_t cs = 0, x, ds;
size_t cs = 0, x, ds, len;
size_t s;
if(NULL == arg)
return NULL;
@ -36,30 +36,34 @@ LPSTR tr_esc_str(LPCSTR arg)
switch(arg[x])
{
case '<':
ds += 3;
len = format ? 13 : 4;
ds += len - 1;
tmp = (LPSTR)realloc(tmp, ds * sizeof(CHAR));
if(NULL == tmp)
{
WLog_ERR(TAG, "Could not reallocate string buffer.");
exit(-3);
}
tmp[cs++] = '&';
tmp[cs++] = 'l';
tmp[cs++] = 't';
tmp[cs++] = ';';
if (format)
strncpy (&tmp[cs], "<replaceable>", len);
else
strncpy (&tmp[cs], "&lt;", len);
cs += len;
break;
case '>':
ds += 3;
len = format ? 14 : 4;
ds += len - 1;
tmp = (LPSTR)realloc(tmp, ds * sizeof(CHAR));
if(NULL == tmp)
{
WLog_ERR(TAG, "Could not reallocate string buffer.");
exit(-4);
}
tmp[cs++] = '&';
tmp[cs++] = 'g';
tmp[cs++] = 't';
tmp[cs++] = ';';
if (format)
strncpy (&tmp[cs], "</replaceable>", len);
else
strncpy (&tmp[cs], "&lt;", len);
cs += len;
break;
case '\'':
ds += 5;
@ -142,27 +146,47 @@ int main(int argc, char *argv[])
for(x=0; x<elements - 1; x++)
{
const COMMAND_LINE_ARGUMENT_A *arg = &args[x];
char *name = tr_esc_str((LPSTR) arg->Name);
char *format = tr_esc_str(arg->Format);
char *text = tr_esc_str((LPSTR) arg->Text);
char *name = tr_esc_str((LPSTR) arg->Name, FALSE);
char *format = tr_esc_str(arg->Format, TRUE);
char *text = tr_esc_str((LPSTR) arg->Text, FALSE);
fprintf(fp, "\t\t\t<varlistentry>\n");
fprintf(fp, "\t\t\t\t<term><option>/%s</option>", name);
if ((arg->Flags == COMMAND_LINE_VALUE_REQUIRED) && format)
fprintf(fp, " <replaceable>%s</replaceable>\n", format);
fprintf(fp, "\t\t\t\t<term><option>");
if (arg->Flags == COMMAND_LINE_VALUE_BOOL)
fprintf(fp, "%s", arg->Default ? "-" : "+");
else
fprintf(fp, "/");
fprintf(fp, "%s</option>", name);
if (format)
{
if (arg->Flags == COMMAND_LINE_VALUE_OPTIONAL)
fprintf(fp, "[");
fprintf(fp, ":%s", format);
if (arg->Flags == COMMAND_LINE_VALUE_OPTIONAL)
fprintf(fp, "]");
}
fprintf(fp, "</term>\n");
if (format || text)
if (text)
{
fprintf(fp, "\t\t\t\t<listitem>\n");
fprintf(fp, "\t\t\t\t\t<para>%s\n", format ? format : "");
fprintf(fp, "\t\t\t\t\t<para>");
if (text)
{
if (format)
fprintf(fp, " - ");
fprintf(fp, "%s", text);
if (arg->Flags == COMMAND_LINE_VALUE_BOOL)
fprintf(fp, " (default:%s)", arg->Default ? "on" : "off");
else if (arg->Default)
{
char *value = tr_esc_str((LPSTR) arg->Default, FALSE);
fprintf(fp, " (default:%s)", value);
free (value);
}
fprintf(fp, "</para>\n");
fprintf(fp, "\t\t\t\t</listitem>\n");
}