/* this function should be deprecated because it doesnt consider optional argument values (ARG_HASOPTVALUE) */ void arg_print_option (FILE* fp, const char* shortopts, const char* longopts, const char* datatype, const char* suffix) { char syntax[200] = ""; suffix = suffix ? suffix : ""; /* there is no way of passing the proper optvalue for optional argument values here, so we must ignore it */ arg_cat_optionv (syntax, sizeof (syntax), shortopts, longopts, datatype, 0, "|"); fputs (syntax, fp); fputs (suffix, fp); }
void arg_print_glossary (FILE* fp, void** argtable, const char* format) { struct arg_hdr** table = (struct arg_hdr**) argtable; int tabindex; format = format ? format : " %-20s %s\n"; for (tabindex = 0; ! (table[tabindex]->flag & ARG_TERMINATOR); tabindex++) { if (table[tabindex]->glossary) { char syntax[200] = ""; const char* shortopts = table[tabindex]->shortopts; const char* longopts = table[tabindex]->longopts; const char* datatype = table[tabindex]->datatype; const char* glossary = table[tabindex]->glossary; arg_cat_optionv (syntax, sizeof (syntax), shortopts, longopts, datatype, table[tabindex]->flag & ARG_HASOPTVALUE, ", "); fprintf (fp, format, syntax, glossary); } } }
void arg_print_syntaxv (FILE* fp, void** argtable, const char* suffix) { struct arg_hdr** table = (struct arg_hdr**) argtable; int i, tabindex; /* print remaining options in abbreviated style */ for (tabindex = 0; table[tabindex] && ! (table[tabindex]->flag & ARG_TERMINATOR); tabindex++) { char syntax[200] = ""; const char* shortopts, *longopts, *datatype; shortopts = table[tabindex]->shortopts; longopts = table[tabindex]->longopts; datatype = table[tabindex]->datatype; arg_cat_optionv (syntax, sizeof (syntax), shortopts, longopts, datatype, table[tabindex]->flag & ARG_HASOPTVALUE, "|"); /* print mandatory options */ for (i = 0; i < table[tabindex]->mincount; i++) { fprintf (fp, " %s", syntax); } /* print optional args enclosed in "[..]" */ switch (table[tabindex]->maxcount - table[tabindex]->mincount) { case 0: break; case 1: fprintf (fp, " [%s]", syntax); break; case 2: fprintf (fp, " [%s] [%s]", syntax, syntax); break; default: fprintf (fp, " [%s]...", syntax); break; } } if (suffix) { fprintf (fp, "%s", suffix); } }
/** * Prints the glossary in strict GNU format. * Differences to arg_print_glossary() are: * - wraps lines after 80 chars * - indents lines without shortops * - does not accept formatstrings * * Contributed by Uli Fouquet */ void arg_print_glossary_gnu(FILE *fp, void **argtable ) { struct arg_hdr **table = (struct arg_hdr**)argtable; int tabindex; for(tabindex=0; !(table[tabindex]->flag&ARG_TERMINATOR); tabindex++) { if (table[tabindex]->glossary) { char syntax[200]=""; const char *shortopts = table[tabindex]->shortopts; const char *longopts = table[tabindex]->longopts; const char *datatype = table[tabindex]->datatype; const char *glossary = table[tabindex]->glossary; if ( !shortopts && longopts ) { /* Indent trailing line by 4 spaces... */ memset( syntax, ' ', 4 ); *(syntax+4) = '\0'; } arg_cat_optionv(syntax,sizeof(syntax),shortopts,longopts,datatype,table[tabindex]->flag&ARG_HASOPTVALUE,", "); /* If syntax fits not into column, print glossary in new line... */ if ( strlen(syntax) > 25 ) { fprintf( fp, " %-25s %s\n", syntax, "" ); *syntax = '\0'; } fprintf( fp, " %-25s ", syntax ); arg_print_formatted( fp, 28, 79, glossary ); } } /* for each table entry */ fputc( '\n', fp ); }