Changeset 706


Ignore:
Timestamp:
Mar 28, 2006, 12:16:58 AM (15 years ago)
Author:
Sam Hocevar
Message:
  • Changed the 2nd argument of cucul_create_export to a string. This way we can add new exporters without changing the API.
Location:
libcaca/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • libcaca/trunk/cucul/cucul.c

    r701 r706  
    318318}
    319319
    320 struct cucul_export * cucul_create_export(cucul_t *qq, enum cucul_format format)
     320struct cucul_export * cucul_create_export(cucul_t *qq, char const *format)
    321321{
    322322    struct cucul_export *ex;
     
    324324    ex = malloc(sizeof(struct cucul_export));
    325325
    326     switch(format)
    327     {
    328         case CUCUL_FORMAT_ANSI:
    329             _cucul_get_ansi(qq, ex);
    330             break;
    331         case CUCUL_FORMAT_HTML:
    332             _cucul_get_html(qq, ex);
    333             break;
    334         case CUCUL_FORMAT_HTML3:
    335             _cucul_get_html3(qq, ex);
    336             break;
    337         case CUCUL_FORMAT_IRC:
    338             _cucul_get_irc(qq, ex);
    339             break;
    340         case CUCUL_FORMAT_PS:
    341             _cucul_get_ps(qq, ex);
    342             break;
    343         case CUCUL_FORMAT_SVG:
    344             _cucul_get_svg(qq, ex);
    345             break;
    346         default:
    347             free(ex);
    348             return NULL;
     326    if(!strcasecmp("ansi", format))
     327        _cucul_get_ansi(qq, ex);
     328    else if(!strcasecmp("html", format))
     329        _cucul_get_html(qq, ex);
     330    else if(!strcasecmp("html3", format))
     331        _cucul_get_html3(qq, ex);
     332    else if(!strcasecmp("irc", format))
     333        _cucul_get_irc(qq, ex);
     334    else if(!strcasecmp("ps", format))
     335        _cucul_get_ps(qq, ex);
     336    else if(!strcasecmp("svg", format))
     337        _cucul_get_svg(qq, ex);
     338    else
     339    {
     340        free(ex);
     341        return NULL;
    349342    }
    350343
  • libcaca/trunk/cucul/cucul.h

    r701 r706  
    5353};
    5454
    55 /** \brief Export formats
    56  *
    57  *  Export formats understood by libcucul.
    58  */
    59 enum cucul_format
    60 {
    61     CUCUL_FORMAT_ANSI = 0, /**< Export to ANSI format. */
    62     CUCUL_FORMAT_HTML = 1, /**< Export to HTML format. */
    63     CUCUL_FORMAT_HTML3 = 2, /**< Export to old HTMLv3 format. */
    64     CUCUL_FORMAT_IRC = 3, /**< Export to text with mIRC colours. */
    65     CUCUL_FORMAT_PS = 4, /**< Export to PostScript. */
    66     CUCUL_FORMAT_SVG = 5, /**< Export to Scalable Vector Graphics format. */
    67 };
    68 
    6955/** \brief Internal features.
    7056 *
     
    242228};
    243229
    244 struct cucul_export * cucul_create_export(cucul_t *, enum cucul_format);
     230struct cucul_export * cucul_create_export(cucul_t *, char const *);
    245231void cucul_free_export(struct cucul_export *);
    246232
  • libcaca/trunk/src/cacaserver.c

    r703 r706  
    196196        /* Get ANSI representation of the image and skip the end-of buffer
    197197         * linefeed ("\r\n\0", 3 bytes) */
    198         server->ex = cucul_create_export(qq, CUCUL_FORMAT_ANSI);
     198        server->ex = cucul_create_export(qq, "ansi");
    199199        server->ex->size -= 3;
    200200
  • libcaca/trunk/test/export.c

    r678 r706  
    3636{
    3737    cucul_t *qq;
    38     enum cucul_format format;
    3938    struct cucul_bitmap *bitmap;
    4039    struct cucul_export *buffer;
     
    4948    }
    5049
    51     if(!strcasecmp(argv[1], "ansi"))
    52         format = CUCUL_FORMAT_ANSI;
    53     else if(!strcasecmp(argv[1], "html"))
    54         format = CUCUL_FORMAT_HTML;
    55     else if(!strcasecmp(argv[1], "html3"))
    56         format = CUCUL_FORMAT_HTML3;
    57     else if(!strcasecmp(argv[1], "irc"))
    58         format = CUCUL_FORMAT_IRC;
    59     else if(!strcasecmp(argv[1], "ps"))
    60         format = CUCUL_FORMAT_PS;
    61     else if(!strcasecmp(argv[1], "svg"))
    62         format = CUCUL_FORMAT_SVG;
    63     else
     50    if(strcasecmp(argv[1], "ansi")
     51        && strcasecmp(argv[1], "html")
     52        && strcasecmp(argv[1], "html3")
     53        && strcasecmp(argv[1], "irc")
     54        && strcasecmp(argv[1], "ps")
     55        && strcasecmp(argv[1], "svg"))
    6456    {
    6557        fprintf(stderr, "%s: unknown format `%s'\n", argv[0], argv[1]);
     
    9991    cucul_putstr(qq, WIDTH / 2 - 7, HEIGHT / 2, "    LIBCACA    ");
    10092
    101     buffer = cucul_create_export(qq, format);
     93    buffer = cucul_create_export(qq, argv[1]);
    10294    fwrite(buffer->buffer, buffer->size - 1, 1, stdout);
    10395    cucul_free_export(buffer);
Note: See TracChangeset for help on using the changeset viewer.