13 const char * ,
void * ) {
23 {
"help",
'?', 0, NULL,
'?',
N_(
"Show this help message"), NULL },
24 {
"usage",
'u', 0, NULL,
'u',
N_(
"Display brief usage message"), NULL },
25 { NULL,
'\0', 0, NULL, 0, NULL, NULL }
29 static const char *
const
30 getTableTranslationDomain(
const struct poptOption *table)
38 return (
const char*
const)opt->
arg;
44 static const char *
const
45 getArgDescrip(
const struct poptOption * opt,
const char *translation_domain)
56 static void singleOptionHelp(FILE * f,
int maxLeftCol,
58 const char *translation_domain) {
59 int indentLength = maxLeftCol + 5;
60 int lineLength = 79 - indentLength;
61 const char * help =
D_(translation_domain, opt->
descrip);
66 const char *
argDescrip = getArgDescrip(opt, translation_domain);
68 left = (
char*)malloc(maxLeftCol + 1);
76 sprintf(left,
"--%s", opt->
longName);
84 fprintf(f,
" %-*s ", maxLeftCol, left);
86 fprintf(f,
" %s\n", left);
90 helpLength = strlen(help);
91 while (helpLength > lineLength) {
92 ch = help + lineLength - 1;
93 while (ch > help && !isspace(*ch)) ch--;
94 if (ch == help)
break;
95 while (ch > (help + 1) && isspace(*ch)) ch--;
98 sprintf(format,
"%%.%ds\n%%%ds", (
int) (ch - help), indentLength);
99 fprintf(f, format, help,
" ");
101 while (isspace(*help) && *help) help++;
102 helpLength = strlen(help);
105 if (helpLength) fprintf(f,
"%s\n", help);
111 static int maxArgWidth(
const struct poptOption * opt,
112 const char * translation_domain) {
119 thiS = maxArgWidth((
struct poptOption*)opt->
arg, translation_domain);
120 if (thiS >
max)
max = thiS;
128 s = getArgDescrip(opt, translation_domain);
130 thiS += strlen(s) + 1;
131 if (thiS >
max)
max = thiS;
140 static void singleTableHelp(FILE * f,
const struct poptOption * table,
142 const char *translation_domain) {
144 const char *sub_transdom;
150 singleOptionHelp(f, left, opt, translation_domain);
157 sub_transdom = getTableTranslationDomain((
struct poptOption*)opt->
arg);
159 sub_transdom = translation_domain;
162 fprintf(f,
"\n%s\n",
D_(sub_transdom, opt->
descrip));
164 singleTableHelp(f, (
struct poptOption*)opt->
arg, left, sub_transdom);
171 static int showHelpIntro(
poptContext con, FILE * f) {
175 fprintf(f,
POPT_(
"Usage:"));
178 if (strchr(fn,
'/')) fn = strchr(fn,
'/') + 1;
179 fprintf(f,
" %s", fn);
180 len += strlen(fn) + 1;
189 showHelpIntro(con, f);
193 fprintf(f,
" %s\n",
POPT_(
"[OPTION...]"));
195 leftColWidth = maxArgWidth(con->
options, NULL);
196 singleTableHelp(f, con->
options, leftColWidth, NULL);
199 static int singleOptionUsage(FILE * f,
int cursor,
201 const char *translation_domain) {
203 char shortStr[2] = {
'\0',
'\0' };
204 const char * item = shortStr;
205 const char *
argDescrip = getArgDescrip(opt, translation_domain);
218 if (
len == 3)
return cursor;
223 if ((cursor +
len) > 79) {
228 fprintf(f,
" [-%s%s%s%s]", opt->
shortName ?
"" :
"-", item,
232 return cursor +
len + 1;
235 static int singleTableUsage(FILE * f,
int cursor,
const struct poptOption * table,
236 const char *translation_domain) {
242 translation_domain = (
const char *)opt->
arg;
244 cursor = singleTableUsage(f, cursor, (
struct poptOption*)opt->
arg,
248 cursor = singleOptionUsage(f, cursor, opt, translation_domain);
256 static int showShortOptions(
const struct poptOption * opt, FILE * f,
263 memset(s, 0,
sizeof(s));
279 fprintf(f,
" [-%s]", s);
280 return strlen(s) + 4;
286 cursor = showHelpIntro(con, f);
287 cursor += showShortOptions(con->
options, f, NULL);
288 singleTableUsage(f, cursor, con->
options, NULL);
292 if (cursor > 79) fprintf(f,
"\n ");
#define POPT_CONTEXT_KEEP_FIRST
#define POPT_ARGFLAG_DOC_HIDDEN
#define POPT_ARG_INTL_DOMAIN
#define POPT_ARG_INCLUDE_TABLE
#define POPT_ARG_CALLBACK
struct poptOption poptHelpOptions[]
void poptPrintHelp(poptContext con, FILE *f, int)
void poptSetOtherOptionHelp(poptContext con, const char *text)
void poptPrintUsage(poptContext con, FILE *f, int)
const struct poptOption * options
struct optionStackEntry optionStack[POPT_OPTION_DEPTH]
char * xstrdup(const char *str)