2013-08-05 18:39:49 +04:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
|
|
|
|
#include <winpr/cmdline.h>
|
|
|
|
|
|
|
|
/* We need to include the command line c file to get access to
|
|
|
|
* the argument struct. */
|
|
|
|
#include "../common/cmdline.c"
|
|
|
|
|
2014-01-25 03:08:06 +04:00
|
|
|
LPSTR tr_esc_str(LPCSTR arg)
|
2013-08-05 18:39:49 +04:00
|
|
|
{
|
2014-05-23 15:07:37 +04:00
|
|
|
LPSTR tmp = NULL;
|
2013-08-05 18:39:49 +04:00
|
|
|
size_t cs = 0, x, ds;
|
|
|
|
size_t s;
|
2014-05-23 15:07:37 +04:00
|
|
|
if(NULL == arg)
|
2013-08-05 18:39:49 +04:00
|
|
|
return NULL;
|
|
|
|
s = strlen(arg);
|
|
|
|
/* Find trailing whitespaces */
|
2014-05-23 15:07:37 +04:00
|
|
|
while((s > 0) && isspace(arg[s-1]))
|
2013-08-05 18:39:49 +04:00
|
|
|
s--;
|
|
|
|
/* Prepare a initial buffer with the size of the result string. */
|
2014-05-23 15:07:37 +04:00
|
|
|
ds = s + 1;
|
|
|
|
if(s)
|
|
|
|
tmp = (LPSTR)realloc(tmp, ds * sizeof(CHAR));
|
|
|
|
if(NULL == tmp)
|
2013-08-05 18:39:49 +04:00
|
|
|
{
|
2014-09-12 19:13:01 +04:00
|
|
|
WLog_ERR(TAG, "Could not allocate string buffer.");
|
2013-08-05 18:39:49 +04:00
|
|
|
exit(-2);
|
|
|
|
}
|
|
|
|
/* Copy character for character and check, if it is necessary to escape. */
|
2014-05-23 15:07:37 +04:00
|
|
|
memset(tmp, 0, ds * sizeof(CHAR));
|
2013-08-05 18:39:49 +04:00
|
|
|
for(x=0; x<s; x++)
|
|
|
|
{
|
|
|
|
switch(arg[x])
|
|
|
|
{
|
|
|
|
case '<':
|
|
|
|
ds += 3;
|
2013-08-30 16:19:50 +04:00
|
|
|
tmp = (LPSTR)realloc(tmp, ds * sizeof(CHAR));
|
2014-05-23 15:07:37 +04:00
|
|
|
if(NULL == tmp)
|
2013-08-05 18:39:49 +04:00
|
|
|
{
|
2014-09-12 19:13:01 +04:00
|
|
|
WLog_ERR(TAG, "Could not reallocate string buffer.");
|
2013-08-05 18:39:49 +04:00
|
|
|
exit(-3);
|
|
|
|
}
|
|
|
|
tmp[cs++] = '&';
|
|
|
|
tmp[cs++] = 'l';
|
|
|
|
tmp[cs++] = 't';
|
|
|
|
tmp[cs++] = ';';
|
|
|
|
break;
|
|
|
|
case '>':
|
|
|
|
ds += 3;
|
2013-08-30 16:19:50 +04:00
|
|
|
tmp = (LPSTR)realloc(tmp, ds * sizeof(CHAR));
|
2014-05-23 15:07:37 +04:00
|
|
|
if(NULL == tmp)
|
2013-08-05 18:39:49 +04:00
|
|
|
{
|
2014-09-12 19:13:01 +04:00
|
|
|
WLog_ERR(TAG, "Could not reallocate string buffer.");
|
2013-08-05 18:39:49 +04:00
|
|
|
exit(-4);
|
|
|
|
}
|
|
|
|
tmp[cs++] = '&';
|
|
|
|
tmp[cs++] = 'g';
|
|
|
|
tmp[cs++] = 't';
|
|
|
|
tmp[cs++] = ';';
|
|
|
|
break;
|
|
|
|
case '\'':
|
|
|
|
ds += 5;
|
2013-08-30 16:19:50 +04:00
|
|
|
tmp = (LPSTR)realloc(tmp, ds * sizeof(CHAR));
|
2014-05-23 15:07:37 +04:00
|
|
|
if(NULL == tmp)
|
2013-08-05 18:39:49 +04:00
|
|
|
{
|
2014-09-12 19:13:01 +04:00
|
|
|
WLog_ERR(TAG, "Could not reallocate string buffer.");
|
2013-08-05 18:39:49 +04:00
|
|
|
exit(-5);
|
|
|
|
}
|
|
|
|
tmp[cs++] = '&';
|
|
|
|
tmp[cs++] = 'a';
|
|
|
|
tmp[cs++] = 'p';
|
|
|
|
tmp[cs++] = 'o';
|
|
|
|
tmp[cs++] = 's';
|
|
|
|
tmp[cs++] = ';';
|
|
|
|
break;
|
|
|
|
case '"':
|
|
|
|
ds += 5;
|
2013-08-30 16:19:50 +04:00
|
|
|
tmp = (LPSTR)realloc(tmp, ds * sizeof(CHAR));
|
2014-05-23 15:07:37 +04:00
|
|
|
if(NULL == tmp)
|
2013-08-05 18:39:49 +04:00
|
|
|
{
|
2014-09-12 19:13:01 +04:00
|
|
|
WLog_ERR(TAG, "Could not reallocate string buffer.");
|
2013-08-05 18:39:49 +04:00
|
|
|
exit(-6);
|
|
|
|
}
|
|
|
|
tmp[cs++] = '&';
|
|
|
|
tmp[cs++] = 'q';
|
|
|
|
tmp[cs++] = 'u';
|
|
|
|
tmp[cs++] = 'o';
|
|
|
|
tmp[cs++] = 't';
|
|
|
|
tmp[cs++] = ';';
|
|
|
|
break;
|
|
|
|
case '&':
|
|
|
|
ds += 4;
|
2013-08-30 16:19:50 +04:00
|
|
|
tmp = (LPSTR)realloc(tmp, ds * sizeof(CHAR));
|
2014-05-23 15:07:37 +04:00
|
|
|
if(NULL == tmp)
|
2013-08-05 18:39:49 +04:00
|
|
|
{
|
2014-09-12 19:13:01 +04:00
|
|
|
WLog_ERR(TAG, "Could not reallocate string buffer.");
|
2013-08-05 18:39:49 +04:00
|
|
|
exit(-7);
|
|
|
|
}
|
|
|
|
tmp[cs++] = '&';
|
|
|
|
tmp[cs++] = 'a';
|
|
|
|
tmp[cs++] = 'm';
|
|
|
|
tmp[cs++] = 'p';
|
|
|
|
tmp[cs++] = ';';
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
tmp[cs++] = arg[x];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* Assure, the string is '\0' terminated. */
|
|
|
|
tmp[ds-1] = '\0';
|
|
|
|
}
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2013-08-06 12:23:43 +04:00
|
|
|
size_t elements = sizeof(args)/sizeof(args[0]);
|
2013-08-05 18:39:49 +04:00
|
|
|
size_t x;
|
|
|
|
const char *fname = "xfreerdp-argument.1.xml";
|
|
|
|
FILE *fp = NULL;
|
|
|
|
/* Open output file for writing, truncate if existing. */
|
|
|
|
fp = fopen(fname, "w");
|
2014-05-23 15:07:37 +04:00
|
|
|
if(NULL == fp)
|
2013-08-05 18:39:49 +04:00
|
|
|
{
|
2014-09-12 19:13:01 +04:00
|
|
|
WLog_ERR(TAG, "Could not open '%s' for writing.", fname);
|
2013-08-05 18:39:49 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
/* The tag used as header in the manpage */
|
|
|
|
fprintf(fp, "<refsect1>\n");
|
2013-08-06 13:41:38 +04:00
|
|
|
fprintf(fp, "\t<title>Options</title>\n");
|
2013-08-05 18:39:49 +04:00
|
|
|
fprintf(fp, "\t\t<variablelist>\n");
|
2014-05-23 15:07:37 +04:00
|
|
|
/* Iterate over argument struct and write data to docbook 4.5
|
2013-08-05 18:39:49 +04:00
|
|
|
* compatible XML */
|
2014-05-23 15:07:37 +04:00
|
|
|
if(elements < 2)
|
2013-08-06 12:23:43 +04:00
|
|
|
{
|
2014-09-12 19:13:01 +04:00
|
|
|
WLog_ERR(TAG, "The argument array 'args' is empty, writing an empty file.");
|
2013-08-06 12:23:43 +04:00
|
|
|
elements = 1;
|
|
|
|
}
|
|
|
|
for(x=0; x<elements - 1; x++)
|
2013-08-05 18:39:49 +04:00
|
|
|
{
|
|
|
|
const COMMAND_LINE_ARGUMENT_A *arg = &args[x];
|
2017-09-25 12:33:03 +03:00
|
|
|
char *name = tr_esc_str((LPSTR) arg->Name);
|
|
|
|
char *format = tr_esc_str(arg->Format);
|
|
|
|
char *text = tr_esc_str((LPSTR) arg->Text);
|
|
|
|
|
2013-08-05 18:39:49 +04:00
|
|
|
fprintf(fp, "\t\t\t<varlistentry>\n");
|
2016-06-15 23:39:03 +03:00
|
|
|
|
|
|
|
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, "</term>\n");
|
|
|
|
|
|
|
|
if (format || text)
|
|
|
|
{
|
|
|
|
fprintf(fp, "\t\t\t\t<listitem>\n");
|
|
|
|
fprintf(fp, "\t\t\t\t\t<para>%s\n", format ? format : "");
|
|
|
|
if (text)
|
|
|
|
{
|
|
|
|
if (format)
|
|
|
|
fprintf(fp, " - ");
|
|
|
|
fprintf(fp, "%s", text);
|
|
|
|
}
|
|
|
|
fprintf(fp, "</para>\n");
|
|
|
|
fprintf(fp, "\t\t\t\t</listitem>\n");
|
|
|
|
}
|
2013-08-05 18:39:49 +04:00
|
|
|
fprintf(fp, "\t\t\t</varlistentry>\n");
|
2017-09-25 12:33:03 +03:00
|
|
|
free(name);
|
|
|
|
free(format);
|
|
|
|
free(text);
|
2013-08-05 18:39:49 +04:00
|
|
|
}
|
|
|
|
fprintf(fp, "\t\t</variablelist>\n");
|
|
|
|
fprintf(fp, "\t</refsect1>\n");
|
|
|
|
fclose(fp);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|