MCPcopy Index your code
hub / github.com/RsyncProject/rsync / singleOptionHelp

Function singleOptionHelp

popt/popthelp.c:284–480  ·  view source on GitHub ↗

* Display help text for an option. * @param fp output file handle * @param columns output display width control * @param opt option(s) * @param translation_domain translation domain */

Source from the content-addressed store, hash-verified

282 * @param translation_domain translation domain
283 */
284static void singleOptionHelp(FILE * fp, columns_t columns,
285 const struct poptOption * opt,
286 const char * translation_domain)
287{
288 size_t maxLeftCol = columns->cur;
289 size_t indentLength = maxLeftCol + 5;
290 size_t lineLength = columns->max - indentLength;
291 const char * help = D_(translation_domain, opt->descrip);
292 const char * argDescrip = getArgDescrip(opt, translation_domain);
293 /* Display shortName iff printable non-space. */
294 int prtshort = (int)(isprint((int)opt->shortName) && opt->shortName != ' ');
295 size_t helpLength;
296 char * defs = NULL;
297 char * left;
298 size_t nb = maxLeftCol + 1;
299 int displaypad = 0;
300
301 /* Make sure there's more than enough room in target buffer. */
302 if (opt->longName) nb += strlen(opt->longName);
303 if (F_ISSET(opt, TOGGLE)) nb += sizeof("[no]") - 1;
304 if (argDescrip) nb += strlen(argDescrip);
305
306 left = malloc(nb);
307 if (left == NULL) return; /* XXX can't happen */
308 left[0] = '\0';
309 left[maxLeftCol] = '\0';
310
311#define prtlong (opt->longName != NULL) /* XXX splint needs a clue */
312 if (!(prtshort || prtlong))
313 goto out;
314 if (prtshort && prtlong) {
315 const char *dash = F_ISSET(opt, ONEDASH) ? "-" : "--";
316 left[0] = '-';
317 left[1] = opt->shortName;
318 (void) stpcpy(stpcpy(stpcpy(left+2, ", "), dash), opt->longName);
319 } else if (prtshort) {
320 left[0] = '-';
321 left[1] = opt->shortName;
322 left[2] = '\0';
323 } else if (prtlong) {
324 /* XXX --long always padded for alignment with/without "-X, ". */
325 const char *dash = poptArgType(opt) == POPT_ARG_MAINCALL ? ""
326 : (F_ISSET(opt, ONEDASH) ? "-" : "--");
327 const char *longName = opt->longName;
328 const char *toggle;
329 if (F_ISSET(opt, TOGGLE)) {
330 toggle = "[no]";
331 if (longName[0] == 'n' && longName[1] == 'o') {
332 longName += sizeof("no") - 1;
333 if (longName[0] == '-')
334 longName++;
335 }
336 } else
337 toggle = "";
338 (void) stpcpy(stpcpy(stpcpy(stpcpy(left, " "), dash), toggle), longName);
339 }
340#undef prtlong
341

Callers 2

itemHelpFunction · 0.85
singleTableHelpFunction · 0.85

Calls 8

getArgDescripFunction · 0.85
stpcpyFunction · 0.85
singleOptionDefaultValueFunction · 0.85
_freeFunction · 0.85
stringDisplayWidthFunction · 0.85
POPT_fprintfFunction · 0.85
POPT_prev_charFunction · 0.85
POPT_next_charFunction · 0.85

Tested by

no test coverage detected