MCPcopy Create free account
hub / github.com/RsyncProject/rsync / singleOptionUsage

Function singleOptionUsage

popt/popthelp.c:657–711  ·  view source on GitHub ↗

* Display usage 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

655 * @param translation_domain translation domain
656 */
657static size_t singleOptionUsage(FILE * fp, columns_t columns,
658 const struct poptOption * opt,
659 const char *translation_domain)
660{
661 size_t len = sizeof(" []")-1;
662 const char * argDescrip = getArgDescrip(opt, translation_domain);
663 /* Display shortName iff printable non-space. */
664 int prtshort = (int)(isprint((int)opt->shortName) && opt->shortName != ' ');
665
666#define prtlong (opt->longName != NULL) /* XXX splint needs a clue */
667 if (!(prtshort || prtlong))
668 return columns->cur;
669
670 len = sizeof(" []")-1;
671 if (prtshort)
672 len += sizeof("-c")-1;
673 if (prtlong) {
674 if (prtshort) len += sizeof("|")-1;
675 len += (F_ISSET(opt, ONEDASH) ? sizeof("-") : sizeof("--")) - 1;
676 len += strlen(opt->longName);
677 }
678
679 if (argDescrip) {
680
681 /* XXX argDescrip[0] determines "--foo=bar" or "--foo bar". */
682 if (!strchr(" =(", argDescrip[0])) len += sizeof("=")-1;
683
684 /* Adjust for (possible) wide characters. */
685 len += stringDisplayWidth(argDescrip);
686 }
687
688 if ((columns->cur + len) > columns->max) {
689 fprintf(fp, "\n ");
690 columns->cur = (size_t)7;
691 }
692
693 fprintf(fp, " [");
694 if (prtshort)
695 fprintf(fp, "-%c", opt->shortName);
696 if (prtlong)
697 fprintf(fp, "%s%s%s",
698 (prtshort ? "|" : ""),
699 (F_ISSET(opt, ONEDASH) ? "-" : "--"),
700 opt->longName);
701#undef prtlong
702
703 if (argDescrip) {
704 /* XXX argDescrip[0] determines "--foo=bar" or "--foo bar". */
705 if (!strchr(" =(", argDescrip[0])) fputc(opt->longName == NULL ? ' ' : '=', fp);
706 fprintf(fp, "%s", argDescrip);
707 }
708 fprintf(fp, "]");
709
710 return columns->cur + len + 1;
711}
712
713/**
714 * Display popt alias and exec usage.

Callers 2

itemUsageFunction · 0.85
singleTableUsageFunction · 0.85

Calls 2

getArgDescripFunction · 0.85
stringDisplayWidthFunction · 0.85

Tested by

no test coverage detected