Main Page   Modules   Data Structures   File List   Data Fields   Globals   Related Pages  

popt/popthelp.c

Go to the documentation of this file.
00001 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
00002 
00003 /*@-type@*/
00008 /* (C) 1998-2002 Red Hat, Inc. -- Licensing details are in the COPYING
00009    file accompanying popt source distributions, available from 
00010    ftp://ftp.rpm.org/pub/rpm/dist. */
00011 
00012 #include "system.h"
00013 #include "poptint.h"
00014 
00023 static void displayArgs(poptContext con,
00024                 /*@unused@*/ enum poptCallbackReason foo,
00025                 struct poptOption * key, 
00026                 /*@unused@*/ const char * arg, /*@unused@*/ void * data)
00027         /*@globals fileSystem@*/
00028         /*@modifies fileSystem@*/
00029 {
00030     if (key->shortName == '?')
00031         poptPrintHelp(con, stdout, 0);
00032     else
00033         poptPrintUsage(con, stdout, 0);
00034     exit(0);
00035 }
00036 
00037 #ifdef  NOTYET
00038 /*@unchecked@*/
00039 static int show_option_defaults = 0;
00040 #endif
00041 
00045 /*@observer@*/ /*@unchecked@*/
00046 struct poptOption poptAliasOptions[] = {
00047     POPT_TABLEEND
00048 };
00049 
00053 /*@-castfcnptr@*/
00054 /*@observer@*/ /*@unchecked@*/
00055 struct poptOption poptHelpOptions[] = {
00056 #if NOTYET
00057   { NULL, '\0', POPT_ARG_INTL_DOMAIN, PACKAGE, 0, NULL, NULL},
00058 #endif
00059   { NULL, '\0', POPT_ARG_CALLBACK, (void *)&displayArgs, '\0', NULL, NULL },
00060   { "help", '?', 0, NULL, '?', N_("Show this help message"), NULL },
00061   { "usage", '\0', 0, NULL, 'u', N_("Display brief usage message"), NULL },
00062 #ifdef  NOTYET
00063   { "defaults", '\0', POPT_ARG_NONE, &show_option_defaults, 0,
00064         N_("Display option defaults in message"), NULL },
00065 #endif
00066     POPT_TABLEEND
00067 } ;
00068 /*@=castfcnptr@*/
00069 
00073 /*@observer@*/ /*@null@*/ static const char *const
00074 getTableTranslationDomain(/*@null@*/ const struct poptOption *table)
00075         /*@*/
00076 {
00077     const struct poptOption *opt;
00078 
00079     if (table != NULL)
00080     for (opt = table; opt->longName || opt->shortName || opt->arg; opt++) {
00081         if (opt->argInfo == POPT_ARG_INTL_DOMAIN)
00082             return opt->arg;
00083     }
00084     return NULL;
00085 }
00086 
00091 /*@observer@*/ /*@null@*/ static const char *const
00092 getArgDescrip(const struct poptOption * opt,
00093                 /*@-paramuse@*/ /* FIX: i18n macros disabled with lclint */
00094                 /*@null@*/ const char * translation_domain)
00095                 /*@=paramuse@*/
00096         /*@*/
00097 {
00098     if (!(opt->argInfo & POPT_ARG_MASK)) return NULL;
00099 
00100     if (opt == (poptHelpOptions + 1) || opt == (poptHelpOptions + 2))
00101         if (opt->argDescrip) return POPT_(opt->argDescrip);
00102 
00103     if (opt->argDescrip) return D_(translation_domain, opt->argDescrip);
00104 
00105     switch (opt->argInfo & POPT_ARG_MASK) {
00106     case POPT_ARG_NONE:         return POPT_("NONE");
00107 #ifdef  DYING
00108     case POPT_ARG_VAL:          return POPT_("VAL");
00109 #else
00110     case POPT_ARG_VAL:          return NULL;
00111 #endif
00112     case POPT_ARG_INT:          return POPT_("INT");
00113     case POPT_ARG_LONG:         return POPT_("LONG");
00114     case POPT_ARG_STRING:       return POPT_("STRING");
00115     case POPT_ARG_FLOAT:        return POPT_("FLOAT");
00116     case POPT_ARG_DOUBLE:       return POPT_("DOUBLE");
00117     default:                    return POPT_("ARG");
00118     }
00119 }
00120 
00128 static /*@only@*/ /*@null@*/ char *
00129 singleOptionDefaultValue(int lineLength,
00130                 const struct poptOption * opt,
00131                 /*@-paramuse@*/ /* FIX: i18n macros disabled with lclint */
00132                 /*@null@*/ const char * translation_domain)
00133                 /*@=paramuse@*/
00134         /*@*/
00135 {
00136     const char * defstr = D_(translation_domain, "default");
00137     char * le = malloc(4*lineLength + 1);
00138     char * l = le;
00139 
00140     if (le == NULL) return NULL;        /* XXX can't happen */
00141 /*@-boundswrite@*/
00142     *le = '\0';
00143     *le++ = '(';
00144     strcpy(le, defstr); le += strlen(le);
00145     *le++ = ':';
00146     *le++ = ' ';
00147     if (opt->arg)       /* XXX programmer error */
00148     switch (opt->argInfo & POPT_ARG_MASK) {
00149     case POPT_ARG_VAL:
00150     case POPT_ARG_INT:
00151     {   long aLong = *((int *)opt->arg);
00152         le += sprintf(le, "%ld", aLong);
00153     }   break;
00154     case POPT_ARG_LONG:
00155     {   long aLong = *((long *)opt->arg);
00156         le += sprintf(le, "%ld", aLong);
00157     }   break;
00158     case POPT_ARG_FLOAT:
00159     {   double aDouble = *((float *)opt->arg);
00160         le += sprintf(le, "%g", aDouble);
00161     }   break;
00162     case POPT_ARG_DOUBLE:
00163     {   double aDouble = *((double *)opt->arg);
00164         le += sprintf(le, "%g", aDouble);
00165     }   break;
00166     case POPT_ARG_STRING:
00167     {   const char * s = *(const char **)opt->arg;
00168         if (s == NULL) {
00169             strcpy(le, "null"); le += strlen(le);
00170         } else {
00171             size_t slen = 4*lineLength - (le - l) - sizeof("\"...\")");
00172             *le++ = '"';
00173             strncpy(le, s, slen); le[slen] = '\0'; le += strlen(le);    
00174             if (slen < strlen(s)) {
00175                 strcpy(le, "...");      le += strlen(le);
00176             }
00177             *le++ = '"';
00178         }
00179     }   break;
00180     case POPT_ARG_NONE:
00181     default:
00182         l = _free(l);
00183         return NULL;
00184         /*@notreached@*/ break;
00185     }
00186     *le++ = ')';
00187     *le = '\0';
00188 /*@=boundswrite@*/
00189 
00190     return l;
00191 }
00192 
00200 static void singleOptionHelp(FILE * fp, int maxLeftCol, 
00201                 const struct poptOption * opt,
00202                 /*@null@*/ const char * translation_domain)
00203         /*@globals fileSystem @*/
00204         /*@modifies *fp, fileSystem @*/
00205 {
00206     int indentLength = maxLeftCol + 5;
00207     int lineLength = 79 - indentLength;
00208     const char * help = D_(translation_domain, opt->descrip);
00209     const char * argDescrip = getArgDescrip(opt, translation_domain);
00210     int helpLength;
00211     char * defs = NULL;
00212     char * left;
00213     int nb = maxLeftCol + 1;
00214 
00215     /* Make sure there's more than enough room in target buffer. */
00216     if (opt->longName)  nb += strlen(opt->longName);
00217     if (argDescrip)     nb += strlen(argDescrip);
00218 
00219 /*@-boundswrite@*/
00220     left = malloc(nb);
00221     if (left == NULL) return;   /* XXX can't happen */
00222     left[0] = '\0';
00223     left[maxLeftCol] = '\0';
00224 
00225     if (opt->longName && opt->shortName)
00226         sprintf(left, "-%c, %s%s", opt->shortName,
00227                 ((opt->argInfo & POPT_ARGFLAG_ONEDASH) ? "-" : "--"),
00228                 opt->longName);
00229     else if (opt->shortName != '\0') 
00230         sprintf(left, "-%c", opt->shortName);
00231     else if (opt->longName)
00232         sprintf(left, "%s%s",
00233                 ((opt->argInfo & POPT_ARGFLAG_ONEDASH) ? "-" : "--"),
00234                 opt->longName);
00235     if (!*left) goto out;
00236 
00237     if (argDescrip) {
00238         char * le = left + strlen(left);
00239 
00240         if (opt->argInfo & POPT_ARGFLAG_OPTIONAL)
00241             *le++ = '[';
00242 
00243         /* Choose type of output */
00244         /*@-branchstate@*/
00245         if (opt->argInfo & POPT_ARGFLAG_SHOW_DEFAULT) {
00246             defs = singleOptionDefaultValue(lineLength, opt, translation_domain);
00247             if (defs) {
00248                 char * t = malloc((help ? strlen(help) : 0) +
00249                                 strlen(defs) + sizeof(" "));
00250                 if (t) {
00251                     char * te = t;
00252                     *te = '\0';
00253                     if (help) {
00254                         strcpy(te, help);       te += strlen(te);
00255                     }
00256                     *te++ = ' ';
00257                     strcpy(te, defs);
00258                     defs = _free(defs);
00259                 }
00260                 defs = t;
00261             }
00262         }
00263         /*@=branchstate@*/
00264 
00265         if (opt->argDescrip == NULL) {
00266             switch (opt->argInfo & POPT_ARG_MASK) {
00267             case POPT_ARG_NONE:
00268                 break;
00269             case POPT_ARG_VAL:
00270 #ifdef  NOTNOW  /* XXX pug ugly nerdy output */
00271             {   long aLong = opt->val;
00272                 int ops = (opt->argInfo & POPT_ARGFLAG_LOGICALOPS);
00273                 int negate = (opt->argInfo & POPT_ARGFLAG_NOT);
00274 
00275                 /* Don't bother displaying typical values */
00276                 if (!ops && (aLong == 0L || aLong == 1L || aLong == -1L))
00277                     break;
00278                 *le++ = '[';
00279                 switch (ops) {
00280                 case POPT_ARGFLAG_OR:
00281                     *le++ = '|';
00282                     /*@innerbreak@*/ break;
00283                 case POPT_ARGFLAG_AND:
00284                     *le++ = '&';
00285                     /*@innerbreak@*/ break;
00286                 case POPT_ARGFLAG_XOR:
00287                     *le++ = '^';
00288                     /*@innerbreak@*/ break;
00289                 default:
00290                     /*@innerbreak@*/ break;
00291                 }
00292                 *le++ = '=';
00293                 if (negate) *le++ = '~';
00294                 /*@-formatconst@*/
00295                 le += sprintf(le, (ops ? "0x%lx" : "%ld"), aLong);
00296                 /*@=formatconst@*/
00297                 *le++ = ']';
00298             }
00299 #endif
00300                 break;
00301             case POPT_ARG_INT:
00302             case POPT_ARG_LONG:
00303             case POPT_ARG_FLOAT:
00304             case POPT_ARG_DOUBLE:
00305             case POPT_ARG_STRING:
00306                 *le++ = '=';
00307                 strcpy(le, argDescrip);         le += strlen(le);
00308                 break;
00309             default:
00310                 break;
00311             }
00312         } else {
00313             *le++ = '=';
00314             strcpy(le, argDescrip);             le += strlen(le);
00315         }
00316         if (opt->argInfo & POPT_ARGFLAG_OPTIONAL)
00317             *le++ = ']';
00318         *le = '\0';
00319     }
00320 /*@=boundswrite@*/
00321 
00322     if (help)
00323         fprintf(fp,"  %-*s   ", maxLeftCol, left);
00324     else {
00325         fprintf(fp,"  %s\n", left); 
00326         goto out;
00327     }
00328 
00329     left = _free(left);
00330     if (defs) {
00331         help = defs; defs = NULL;
00332     }
00333 
00334     helpLength = strlen(help);
00335 /*@-boundsread@*/
00336     while (helpLength > lineLength) {
00337         const char * ch;
00338         char format[16];
00339 
00340         ch = help + lineLength - 1;
00341         while (ch > help && !isspace(*ch)) ch--;
00342         if (ch == help) break;          /* give up */
00343         while (ch > (help + 1) && isspace(*ch)) ch--;
00344         ch++;
00345 
00346         sprintf(format, "%%.%ds\n%%%ds", (int) (ch - help), indentLength);
00347         /*@-formatconst@*/
00348         fprintf(fp, format, help, " ");
00349         /*@=formatconst@*/
00350         help = ch;
00351         while (isspace(*help) && *help) help++;
00352         helpLength = strlen(help);
00353     }
00354 /*@=boundsread@*/
00355 
00356     if (helpLength) fprintf(fp, "%s\n", help);
00357 
00358 out:
00359     /*@-dependenttrans@*/
00360     defs = _free(defs);
00361     /*@=dependenttrans@*/
00362     left = _free(left);
00363 }
00364 
00369 static int maxArgWidth(const struct poptOption * opt,
00370                        /*@null@*/ const char * translation_domain)
00371         /*@*/
00372 {
00373     int max = 0;
00374     int len = 0;
00375     const char * s;
00376     
00377     if (opt != NULL)
00378     while (opt->longName || opt->shortName || opt->arg) {
00379         if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_INCLUDE_TABLE) {
00380             if (opt->arg)       /* XXX program error */
00381             len = maxArgWidth(opt->arg, translation_domain);
00382             if (len > max) max = len;
00383         } else if (!(opt->argInfo & POPT_ARGFLAG_DOC_HIDDEN)) {
00384             len = sizeof("  ")-1;
00385             if (opt->shortName != '\0') len += sizeof("-X")-1;
00386             if (opt->shortName != '\0' && opt->longName) len += sizeof(", ")-1;
00387             if (opt->longName) {
00388                 len += ((opt->argInfo & POPT_ARGFLAG_ONEDASH)
00389                         ? sizeof("-")-1 : sizeof("--")-1);
00390                 len += strlen(opt->longName);
00391             }
00392 
00393             s = getArgDescrip(opt, translation_domain);
00394             if (s)
00395                 len += sizeof("=")-1 + strlen(s);
00396             if (opt->argInfo & POPT_ARGFLAG_OPTIONAL) len += sizeof("[]")-1;
00397             if (len > max) max = len;
00398         }
00399 
00400         opt++;
00401     }
00402     
00403     return max;
00404 }
00405 
00414 static void itemHelp(FILE * fp,
00415                 /*@null@*/ poptItem items, int nitems, int left,
00416                 /*@null@*/ const char * translation_domain)
00417         /*@globals fileSystem @*/
00418         /*@modifies *fp, fileSystem @*/
00419 {
00420     poptItem item;
00421     int i;
00422 
00423     if (items != NULL)
00424     for (i = 0, item = items; i < nitems; i++, item++) {
00425         const struct poptOption * opt;
00426         opt = &item->option;
00427         if ((opt->longName || opt->shortName) && 
00428             !(opt->argInfo & POPT_ARGFLAG_DOC_HIDDEN))
00429             singleOptionHelp(fp, left, opt, translation_domain);
00430     }
00431 }
00432 
00441 static void singleTableHelp(poptContext con, FILE * fp,
00442                 /*@null@*/ const struct poptOption * table, int left,
00443                 /*@null@*/ const char * translation_domain)
00444         /*@globals fileSystem @*/
00445         /*@modifies *fp, fileSystem @*/
00446 {
00447     const struct poptOption * opt;
00448     const char *sub_transdom;
00449 
00450     if (table == poptAliasOptions) {
00451         itemHelp(fp, con->aliases, con->numAliases, left, NULL);
00452         itemHelp(fp, con->execs, con->numExecs, left, NULL);
00453         return;
00454     }
00455 
00456     if (table != NULL)
00457     for (opt = table; (opt->longName || opt->shortName || opt->arg); opt++) {
00458         if ((opt->longName || opt->shortName) && 
00459             !(opt->argInfo & POPT_ARGFLAG_DOC_HIDDEN))
00460             singleOptionHelp(fp, left, opt, translation_domain);
00461     }
00462 
00463     if (table != NULL)
00464     for (opt = table; (opt->longName || opt->shortName || opt->arg); opt++) {
00465         if ((opt->argInfo & POPT_ARG_MASK) != POPT_ARG_INCLUDE_TABLE)
00466             continue;
00467         sub_transdom = getTableTranslationDomain(opt->arg);
00468         if (sub_transdom == NULL)
00469             sub_transdom = translation_domain;
00470             
00471         if (opt->descrip)
00472             fprintf(fp, "\n%s\n", D_(sub_transdom, opt->descrip));
00473 
00474         singleTableHelp(con, fp, opt->arg, left, sub_transdom);
00475     }
00476 }
00477 
00482 static int showHelpIntro(poptContext con, FILE * fp)
00483         /*@globals fileSystem @*/
00484         /*@modifies *fp, fileSystem @*/
00485 {
00486     int len = 6;
00487     const char * fn;
00488 
00489     fprintf(fp, POPT_("Usage:"));
00490     if (!(con->flags & POPT_CONTEXT_KEEP_FIRST)) {
00491 /*@-boundsread@*/
00492         /*@-nullderef@*/        /* LCL: wazzup? */
00493         fn = con->optionStack->argv[0];
00494         /*@=nullderef@*/
00495 /*@=boundsread@*/
00496         if (fn == NULL) return len;
00497         if (strchr(fn, '/')) fn = strrchr(fn, '/') + 1;
00498         fprintf(fp, " %s", fn);
00499         len += strlen(fn) + 1;
00500     }
00501 
00502     return len;
00503 }
00504 
00505 void poptPrintHelp(poptContext con, FILE * fp, /*@unused@*/ int flags)
00506 {
00507     int leftColWidth;
00508 
00509     (void) showHelpIntro(con, fp);
00510     if (con->otherHelp)
00511         fprintf(fp, " %s\n", con->otherHelp);
00512     else
00513         fprintf(fp, " %s\n", POPT_("[OPTION...]"));
00514 
00515     leftColWidth = maxArgWidth(con->options, NULL);
00516     singleTableHelp(con, fp, con->options, leftColWidth, NULL);
00517 }
00518 
00525 static int singleOptionUsage(FILE * fp, int cursor, 
00526                 const struct poptOption * opt,
00527                 /*@null@*/ const char *translation_domain)
00528         /*@globals fileSystem @*/
00529         /*@modifies *fp, fileSystem @*/
00530 {
00531     int len = 4;
00532     char shortStr[2] = { '\0', '\0' };
00533     const char * item = shortStr;
00534     const char * argDescrip = getArgDescrip(opt, translation_domain);
00535 
00536     if (opt->shortName != '\0' && opt->longName != NULL) {
00537         len += 2;
00538         if (!(opt->argInfo & POPT_ARGFLAG_ONEDASH)) len++;
00539         len += strlen(opt->longName);
00540     } else if (opt->shortName != '\0') {
00541         len++;
00542         shortStr[0] = opt->shortName;
00543         shortStr[1] = '\0';
00544     } else if (opt->longName) {
00545         len += strlen(opt->longName);
00546         if (!(opt->argInfo & POPT_ARGFLAG_ONEDASH)) len++;
00547         item = opt->longName;
00548     }
00549 
00550     if (len == 4) return cursor;
00551 
00552     if (argDescrip) 
00553         len += strlen(argDescrip) + 1;
00554 
00555     if ((cursor + len) > 79) {
00556         fprintf(fp, "\n       ");
00557         cursor = 7;
00558     } 
00559 
00560     if (opt->longName && opt->shortName) {
00561         fprintf(fp, " [-%c|-%s%s%s%s]",
00562             opt->shortName, ((opt->argInfo & POPT_ARGFLAG_ONEDASH) ? "" : "-"),
00563             opt->longName,
00564             (argDescrip ? " " : ""),
00565             (argDescrip ? argDescrip : ""));
00566     } else {
00567         fprintf(fp, " [-%s%s%s%s]",
00568             ((opt->shortName || (opt->argInfo & POPT_ARGFLAG_ONEDASH)) ? "" : "-"),
00569             item,
00570             (argDescrip ? (opt->shortName != '\0' ? " " : "=") : ""),
00571             (argDescrip ? argDescrip : ""));
00572     }
00573 
00574     return cursor + len + 1;
00575 }
00576 
00585 static int itemUsage(FILE * fp, int cursor, poptItem item, int nitems,
00586                 /*@null@*/ const char * translation_domain)
00587         /*@globals fileSystem @*/
00588         /*@modifies *fp, fileSystem @*/
00589 {
00590     int i;
00591 
00592     /*@-branchstate@*/          /* FIX: W2DO? */
00593     if (item != NULL)
00594     for (i = 0; i < nitems; i++, item++) {
00595         const struct poptOption * opt;
00596         opt = &item->option;
00597         if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_INTL_DOMAIN) {
00598             translation_domain = (const char *)opt->arg;
00599         } else if ((opt->longName || opt->shortName) &&
00600                  !(opt->argInfo & POPT_ARGFLAG_DOC_HIDDEN)) {
00601             cursor = singleOptionUsage(fp, cursor, opt, translation_domain);
00602         }
00603     }
00604     /*@=branchstate@*/
00605 
00606     return cursor;
00607 }
00608 
00612 typedef struct poptDone_s {
00613     int nopts;
00614     int maxopts;
00615     const void ** opts;
00616 } * poptDone;
00617 
00628 static int singleTableUsage(poptContext con, FILE * fp, int cursor,
00629                 /*@null@*/ const struct poptOption * opt,
00630                 /*@null@*/ const char * translation_domain,
00631                 /*@null@*/ poptDone done)
00632         /*@globals fileSystem @*/
00633         /*@modifies *fp, done, fileSystem @*/
00634 {
00635     /*@-branchstate@*/          /* FIX: W2DO? */
00636     if (opt != NULL)
00637     for (; (opt->longName || opt->shortName || opt->arg) ; opt++) {
00638         if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_INTL_DOMAIN) {
00639             translation_domain = (const char *)opt->arg;
00640         } else if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_INCLUDE_TABLE) {
00641             if (done) {
00642                 int i = 0;
00643                 for (i = 0; i < done->nopts; i++) {
00644 /*@-boundsread@*/
00645                     const void * that = done->opts[i];
00646 /*@=boundsread@*/
00647                     if (that == NULL || that != opt->arg)
00648                         /*@innercontinue@*/ continue;
00649                     /*@innerbreak@*/ break;
00650                 }
00651                 /* Skip if this table has already been processed. */
00652                 if (opt->arg == NULL || i < done->nopts)
00653                     continue;
00654 /*@-boundswrite@*/
00655                 if (done->nopts < done->maxopts)
00656                     done->opts[done->nopts++] = (const void *) opt->arg;
00657 /*@=boundswrite@*/
00658             }
00659             cursor = singleTableUsage(con, fp, cursor, opt->arg,
00660                         translation_domain, done);
00661         } else if ((opt->longName || opt->shortName) &&
00662                  !(opt->argInfo & POPT_ARGFLAG_DOC_HIDDEN)) {
00663             cursor = singleOptionUsage(fp, cursor, opt, translation_domain);
00664         }
00665     }
00666     /*@=branchstate@*/
00667 
00668     return cursor;
00669 }
00670 
00679 static int showShortOptions(const struct poptOption * opt, FILE * fp,
00680                 /*@null@*/ char * str)
00681         /*@globals fileSystem @*/
00682         /*@modifies *str, *fp, fileSystem @*/
00683         /*@requires maxRead(str) >= 0 @*/
00684 {
00685     /* bufsize larger then the ascii set, lazy alloca on top level call. */
00686     char * s = (str != NULL ? str : memset(alloca(300), 0, 300));
00687     int len = 0;
00688 
00689 /*@-boundswrite@*/
00690     if (opt != NULL)
00691     for (; (opt->longName || opt->shortName || opt->arg); opt++) {
00692         if (opt->shortName && !(opt->argInfo & POPT_ARG_MASK))
00693             s[strlen(s)] = opt->shortName;
00694         else if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_INCLUDE_TABLE)
00695             if (opt->arg)       /* XXX program error */
00696                 len = showShortOptions(opt->arg, fp, s);
00697     } 
00698 /*@=boundswrite@*/
00699 
00700     /* On return to top level, print the short options, return print length. */
00701     if (s == str && *s != '\0') {
00702         fprintf(fp, " [-%s]", s);
00703         len = strlen(s) + sizeof(" [-]")-1;
00704     }
00705     return len;
00706 }
00707 
00708 void poptPrintUsage(poptContext con, FILE * fp, /*@unused@*/ int flags)
00709 {
00710     poptDone done = memset(alloca(sizeof(*done)), 0, sizeof(*done));
00711     int cursor;
00712 
00713     done->nopts = 0;
00714     done->maxopts = 64;
00715     cursor = done->maxopts * sizeof(*done->opts);
00716 /*@-boundswrite@*/
00717     done->opts = memset(alloca(cursor), 0, cursor);
00718     done->opts[done->nopts++] = (const void *) con->options;
00719 /*@=boundswrite@*/
00720 
00721     cursor = showHelpIntro(con, fp);
00722     cursor += showShortOptions(con->options, fp, NULL);
00723     cursor = singleTableUsage(con, fp, cursor, con->options, NULL, done);
00724     cursor = itemUsage(fp, cursor, con->aliases, con->numAliases, NULL);
00725     cursor = itemUsage(fp, cursor, con->execs, con->numExecs, NULL);
00726 
00727     if (con->otherHelp) {
00728         cursor += strlen(con->otherHelp) + 1;
00729         if (cursor > 79) fprintf(fp, "\n       ");
00730         fprintf(fp, " %s", con->otherHelp);
00731     }
00732 
00733     fprintf(fp, "\n");
00734 }
00735 
00736 void poptSetOtherOptionHelp(poptContext con, const char * text)
00737 {
00738     con->otherHelp = _free(con->otherHelp);
00739     con->otherHelp = xstrdup(text);
00740 }
00741 /*@=type@*/

Generated on Sun Oct 26 13:02:01 2003 for rpm by doxygen1.2.18