Changeset 1319


Ignore:
Timestamp:
11/10/06 08:47:17 (7 years ago)
Author:
sam
Message:
  • Use "-F list" to list available filters.
  • Use "-E" to specify export format, "-E list" to list them.
Location:
toilet/trunk/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • toilet/trunk/src/filter.c

    r1317 r1319  
    4040    char const *name; 
    4141    void (*function)(context_t *); 
     42    char const *description; 
    4243} 
    4344const lookup[] = 
    4445{ 
    45     { "crop", filter_crop }, 
    46     { "gay", filter_gay }, 
    47     { "metal", filter_metal }, 
    48     { "flip", filter_flip }, 
    49     { "flop", filter_flop }, 
    50     { "rotate", filter_rotate }, 
     46    { "crop", filter_crop, "crop unused blanks" }, 
     47    { "gay", filter_gay, "add a rainbow colour effect" }, 
     48    { "metal", filter_metal, "add a metallic colour effect" }, 
     49    { "flip", filter_flip, "flip horizontally" }, 
     50    { "flop", filter_flop, "flip vertically" }, 
     51    { "rotate", filter_rotate, "perform a 180 degrees rotation" }, 
    5152}; 
     53 
     54int filter_list(void) 
     55{ 
     56    int i; 
     57 
     58    fprintf(stderr, "Available filters:\n"); 
     59    for(i = 0; i < sizeof(lookup) / sizeof(lookup[0]); i++) 
     60        fprintf(stderr, "\"%s\": %s\n", lookup[i].name, lookup[i].description); 
     61 
     62    return 0; 
     63} 
    5264 
    5365int filter_add(context_t *cx, char const *filter) 
  • toilet/trunk/src/filter.h

    r1241 r1319  
    1616 */ 
    1717 
     18extern int filter_list(void); 
    1819extern int filter_add(context_t *, char const *); 
    1920extern int filter_do(context_t *); 
  • toilet/trunk/src/main.c

    r1293 r1319  
    2929#include <stdio.h> 
    3030#include <stdlib.h> 
     31#include <string.h> 
    3132#include <cucul.h> 
    3233 
     
    3940static void usage(void); 
    4041#endif 
     42static int export_list(void); 
    4143 
    4244int main(int argc, char *argv[]) 
     
    7274            { "gay", 0, NULL, 130 }, 
    7375            { "metal", 0, NULL, 131 }, 
     76            { "export", 1, NULL, 'E' }, 
    7477            { "irc", 0, NULL, 140 }, 
    7578            { "html", 0, NULL, 141 }, 
    76             { "tga", 0, NULL, 142 }, 
    7779            { "help", 0, NULL, 'h' }, 
    7880            { "infocode", 1, NULL, 'I' }, 
     
    8183        }; 
    8284 
    83         int c = getopt_long(argc, argv, "f:d:w:tF:hI:v", 
     85        int c = getopt_long(argc, argv, "f:d:w:tF:E:hI:v", 
    8486                            long_options, &option_index); 
    8587#   else 
    8688#       define MOREINFO "Try `%s -h' for more information.\n" 
    87         int c = getopt(argc, argv, "f:d:w:tF:hI:v"); 
     89        int c = getopt(argc, argv, "f:d:w:tF:E:hI:v"); 
    8890#   endif 
    8991        if(c == -1) 
     
    108110            break; 
    109111        case 'F': /* --filter */ 
    110             if(filter_add(cx, optarg)) 
     112            if(!strcmp(optarg, "list")) 
     113                return filter_list(); 
     114            if(filter_add(cx, optarg) < 0) 
    111115                return -1; 
    112116            break; 
     
    132136            break; 
    133137        } 
     138        case 'E': /* --export */ 
     139            if(!strcmp(optarg, "list")) 
     140                return export_list(); 
     141            cx->export = optarg; 
     142            break; 
    134143        case 140: /* --irc */ 
    135144            cx->export = "irc"; 
     
    137146        case 141: /* --html */ 
    138147            cx->export = "html"; 
    139             break; 
    140         case 142: /* --tga */ 
    141             cx->export = "tga"; 
    142148            break; 
    143149        case '?': 
     
    196202    "Usage: toilet [ -htv ] [ -d fontdirectory ]\n" \ 
    197203    "              [ -f fontfile ] [ -F filter ] [ -w outputwidth ]\n" \ 
    198     "              [ -I infocode ] [ message ]\n" 
     204    "              [ -I infocode ] [ -E format ] [ message ]\n" 
    199205#else 
    200206#   define USAGE "" 
     
    228234    printf("  -w, --width <width>      set output width\n"); 
    229235    printf("  -t, --termwidth          adapt to terminal's width\n"); 
    230     printf("  -F, --filter <name>      apply one or several filters to the text\n"); 
     236    printf("  -F, --filter <filters>   apply one or several filters to the text\n"); 
     237    printf("  -F, --filter list        list available filters\n"); 
    231238    printf("      --gay                rainbow filter (same as -F gay)\n"); 
    232239    printf("      --metal              metal filter (same as -F metal)\n"); 
    233     printf("      --irc                output IRC colour codes\n"); 
    234     printf("      --html               output an HTML document\n"); 
    235     printf("      --tga                output a TGA image\n"); 
     240    printf("  -E, --export <format>    select export format\n"); 
     241    printf("  -E, --export list        list available export formats\n"); 
     242    printf("      --irc                output IRC colour codes (same as -E irc)\n"); 
     243    printf("      --html               output an HTML document (same as -E html)\n"); 
    236244    printf("  -h, --help               display this help and exit\n"); 
    237245    printf("  -I, --infocode <code>    print FIGlet-compatible infocode\n"); 
     
    242250    printf("  -w <width>       set output width\n"); 
    243251    printf("  -t               adapt to terminal's width\n"); 
    244     printf("  -F <name>        apply one or several filters to the text\n"); 
     252    printf("  -F <filters>     apply one or several filters to the text\n"); 
     253    printf("  -F list          list available filters\n"); 
     254    printf("  -E <format>      select export format\n"); 
     255    printf("  -E list          list available export formats\n"); 
    245256    printf("  -h               display this help and exit\n"); 
    246257    printf("  -I <code>        print FIGlet-compatible infocode\n"); 
     
    250261#endif 
    251262 
     263static int export_list(void) 
     264{ 
     265    char const * const * exports, * const * p; 
     266 
     267    exports = cucul_get_export_list(); 
     268 
     269    printf("Available export formats:\n"); 
     270    for(p = exports; *p; p += 2) 
     271        printf("\"%s\": %s\n", *p, *(p + 1)); 
     272 
     273    return 0; 
     274} 
     275 
Note: See TracChangeset for help on using the changeset viewer.