* Find display width for longest argument string. * @param opt option(s) * @param translation_domain translation domain * @return display width */
| 486 | * @return display width |
| 487 | */ |
| 488 | static size_t maxArgWidth(const struct poptOption * opt, |
| 489 | const char * translation_domain) |
| 490 | { |
| 491 | size_t max = 0; |
| 492 | size_t len = 0; |
| 493 | const char * argDescrip; |
| 494 | |
| 495 | if (opt != NULL) |
| 496 | while (opt->longName || opt->shortName || opt->arg) { |
| 497 | if (poptArgType(opt) == POPT_ARG_INCLUDE_TABLE) { |
| 498 | void * arg = opt->arg; |
| 499 | /* XXX sick hack to preserve pretense of ABI. */ |
| 500 | if (arg == poptHelpOptions) |
| 501 | arg = poptHelpOptionsI18N; |
| 502 | if (arg) /* XXX program error */ |
| 503 | len = maxArgWidth(arg, translation_domain); |
| 504 | if (len > max) max = len; |
| 505 | } else if (!F_ISSET(opt, DOC_HIDDEN)) { |
| 506 | len = sizeof(" ")-1; |
| 507 | /* XXX --long always padded for alignment with/without "-X, ". */ |
| 508 | len += sizeof("-X, ")-1; |
| 509 | if (opt->longName) { |
| 510 | len += (F_ISSET(opt, ONEDASH) ? sizeof("-") : sizeof("--")) - 1; |
| 511 | len += strlen(opt->longName); |
| 512 | } |
| 513 | |
| 514 | argDescrip = getArgDescrip(opt, translation_domain); |
| 515 | |
| 516 | if (argDescrip) { |
| 517 | |
| 518 | /* XXX argDescrip[0] determines "--foo=bar" or "--foo bar". */ |
| 519 | if (!strchr(" =(", argDescrip[0])) len += sizeof("=")-1; |
| 520 | |
| 521 | /* Adjust for (possible) wide characters. */ |
| 522 | len += stringDisplayWidth(argDescrip); |
| 523 | } |
| 524 | |
| 525 | if (F_ISSET(opt, OPTIONAL)) len += sizeof("[]")-1; |
| 526 | if (len > max) max = len; |
| 527 | } |
| 528 | opt++; |
| 529 | } |
| 530 | |
| 531 | return max; |
| 532 | } |
| 533 | |
| 534 | /** |
| 535 | * Display popt alias and exec help. |
no test coverage detected