Ignore:
Timestamp:
Mar 24, 2006, 10:48:20 AM (14 years ago)
Author:
Sam Hocevar
Message:
  • Allow the driver initialisation to fail, for instance when $DISPLAY = "".
Location:
libcaca/trunk/caca
Files:
10 edited

Legend:

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

    r681 r684  
    123123    {
    124124#if defined(USE_WIN32)
    125         if(!strcasecmp(var, "win32"))
    126             win32_init_driver(kk);
    127         else
     125        if(!strcasecmp(var, "win32")) return win32_install(kk);
    128126#endif
    129127#if defined(USE_CONIO)
    130         if(!strcasecmp(var, "conio"))
    131             conio_init_driver(kk);
    132         else
     128        if(!strcasecmp(var, "conio")) return conio_install(kk);
    133129#endif
    134130#if defined(USE_X11)
    135         if(!strcasecmp(var, "x11"))
    136             x11_init_driver(kk);
    137         else
     131        if(!strcasecmp(var, "x11")) return x11_install(kk);
    138132#endif
    139133#if defined(USE_GL)
    140         if(!strcasecmp(var, "gl"))
    141             gl_init_driver(kk);
    142         else
     134        if(!strcasecmp(var, "gl")) return gl_install(kk);
    143135#endif
    144136#if defined(USE_SLANG)
    145         if(!strcasecmp(var, "slang"))
    146             slang_init_driver(kk);
    147         else
     137        if(!strcasecmp(var, "slang")) return slang_install(kk);
    148138#endif
    149139#if defined(USE_NCURSES)
    150         if(!strcasecmp(var, "ncurses"))
    151             ncurses_init_driver(kk);
    152         else
     140        if(!strcasecmp(var, "ncurses")) return ncurses_install(kk);
    153141#endif
    154142#if defined(USE_NETWORK)
    155         if(!strcasecmp(var, "network"))
    156             network_init_driver(kk);
    157         else
     143        if(!strcasecmp(var, "network")) return network_install(kk);
    158144#endif
    159145#if defined(USE_VGA)
    160         if(!strcasecmp(var, "vga"))
    161             vga_init_driver(kk);
    162         else
     146        if(!strcasecmp(var, "vga")) return vga_install(kk);
    163147#endif
    164             return -1;
    165 
    166         return 0;
     148        return -1;
    167149    }
    168150#endif
    169151
    170152#if defined(USE_WIN32)
    171     win32_init_driver(kk);
    172     return 0;
     153    if(win32_install(kk) == 0) return 0;
    173154#endif
    174155#if defined(USE_CONIO)
    175     conio_init_driver(kk);
    176     return 0;
     156    if(conio_install(kk) == 0) return 0;
    177157#endif
    178158#if defined(USE_VGA)
    179     vga_init_driver(kk);
    180     return 0;
     159    if(vga_install(kk) == 0) return 0;
    181160#endif
    182161#if defined(USE_X11)
    183 #if defined(HAVE_GETENV)
    184     if(getenv("DISPLAY") && *(getenv("DISPLAY")))
    185 #endif
    186     {
    187         x11_init_driver(kk);
    188         return 0;
    189     }
     162    if(x11_install(kk) == 0) return 0;
    190163#endif
    191164#if defined(USE_GL)
    192 #if defined(HAVE_GETENV) && defined(GLUT_XLIB_IMPLEMENTATION)
    193     if(getenv("DISPLAY") && *(getenv("DISPLAY")))
    194 #endif
    195     {
    196         gl_init_driver(kk);
    197         return 0;
    198     }
     165    if(gl_install(kk) == 0) return 0;
    199166#endif
    200167#if defined(USE_SLANG)
    201     slang_init_driver(kk);
    202     return 0;
     168    if(slang_install(kk) == 0) return 0;
    203169#endif
    204170#if defined(USE_NCURSES)
    205     ncurses_init_driver(kk);
    206     return 0;
     171    if(ncurses_install(kk) == 0) return 0;
    207172#endif
    208173#if defined(USE_NETWORK)
    209     network_init_driver(kk);
    210     return 0;
     174    if(network_install(kk) == 0) return 0;
    211175#endif
    212176
  • libcaca/trunk/caca/caca_internals.h

    r681 r684  
    3939enum caca_driver
    4040{
     41    CACA_DRIVER_NONE = 0,
    4142#if defined(USE_CONIO)
    4243    CACA_DRIVER_CONIO = 1,
     
    6364    CACA_DRIVER_VGA = 8,
    6465#endif
    65     CACA_DRIVER_NONE = 0
    6666};
    6767
    6868/* Available drivers */
    6969#if defined(USE_CONIO)
    70 void conio_init_driver(caca_t *);
     70int conio_install(caca_t *);
    7171#endif
    7272#if defined(USE_GL)
    73 void gl_init_driver(caca_t *);
     73int gl_install(caca_t *);
    7474#endif
    7575#if defined(USE_NCURSES)
    76 void ncurses_init_driver(caca_t *);
     76int ncurses_install(caca_t *);
    7777#endif
    7878#if defined(USE_SLANG)
    79 void slang_init_driver(caca_t *);
     79int slang_install(caca_t *);
    8080#endif
    8181#if defined(USE_WIN32)
    82 void win32_init_driver(caca_t *);
     82int win32_install(caca_t *);
    8383#endif
    8484#if defined(USE_X11)
    85 void x11_init_driver(caca_t *);
     85int x11_install(caca_t *);
    8686#endif
    8787#if defined(USE_NETWORK)
    88 void network_init_driver(caca_t *);
     88int network_install(caca_t *);
    8989#endif
    9090#if defined(USE_VGA)
    91 void vga_init_driver(caca_t *);
     91int vga_install(caca_t *);
    9292#endif
     93
    9394/* Timer structure */
    9495struct caca_timer
     
    129130    {
    130131        int resized;   /* A resize event was requested */
    131         //int acked;     /* The event has been acknowledged by the user */
    132132        unsigned w, h; /* Requested width and height */
    133133    } resize;
  • libcaca/trunk/caca/driver_conio.c

    r681 r684  
    152152 */
    153153
    154 void conio_init_driver(caca_t *kk)
     154int conio_install(caca_t *kk)
    155155{
    156156    kk->drv.driver = CACA_DRIVER_CONIO;
     
    164164    kk->drv.handle_resize = conio_handle_resize;
    165165    kk->drv.get_event = conio_get_event;
     166
     167    return 0;
    166168}
    167169
  • libcaca/trunk/caca/driver_gl.c

    r681 r684  
    107107    gl_kk = kk;
    108108
     109#if defined(HAVE_GETENV)
    109110    geometry = getenv("CACA_GEOMETRY");
    110111    if(geometry && *geometry)
    111112        sscanf(geometry, "%ux%u", &width, &height);
     113#endif
    112114
    113115    if(width && height)
     
    446448 */
    447449
    448 void gl_init_driver(caca_t *kk)
    449 {
     450int gl_install(caca_t *kk)
     451{
     452#if defined(HAVE_GETENV) && defined(GLUT_XLIB_IMPLEMENTATION)
     453    if(!getenv("DISPLAY") || !*(getenv("DISPLAY")))
     454        return -1;
     455#endif
     456
    450457    kk->drv.driver = CACA_DRIVER_GL;
    451458
     
    458465    kk->drv.handle_resize = gl_handle_resize;
    459466    kk->drv.get_event = gl_get_event;
     467
     468    return 0;
    460469}
    461470
  • libcaca/trunk/caca/driver_ncurses.c

    r681 r684  
    531531 */
    532532
    533 void ncurses_init_driver(caca_t *kk)
     533int ncurses_install(caca_t *kk)
    534534{
    535535    kk->drv.driver = CACA_DRIVER_NCURSES;
     
    543543    kk->drv.handle_resize = ncurses_handle_resize;
    544544    kk->drv.get_event = ncurses_get_event;
     545
     546    return 0;
    545547}
    546548
  • libcaca/trunk/caca/driver_network.c

    r681 r684  
    551551 */
    552552
    553 void network_init_driver(caca_t *kk)
     553int network_install(caca_t *kk)
    554554{
    555555    kk->drv.driver = CACA_DRIVER_NETWORK;
     
    563563    kk->drv.handle_resize = network_handle_resize;
    564564    kk->drv.get_event = network_get_event;
     565
     566    return 0;
    565567}
    566568
  • libcaca/trunk/caca/driver_slang.c

    r681 r684  
    469469 */
    470470
    471 void slang_init_driver(caca_t *kk)
     471int slang_install(caca_t *kk)
    472472{
    473473    kk->drv.driver = CACA_DRIVER_SLANG;
     
    481481    kk->drv.handle_resize = slang_handle_resize;
    482482    kk->drv.get_event = slang_get_event;
     483
     484    return 0;
    483485}
    484486
  • libcaca/trunk/caca/driver_vga.c

    r681 r684  
    146146 */
    147147
    148 void vga_init_driver(caca_t *kk)
     148int vga_install(caca_t *kk)
    149149{
    150150    kk->drv.driver = CACA_DRIVER_VGA;
     
    158158    kk->drv.handle_resize = vga_handle_resize;
    159159    kk->drv.get_event = vga_get_event;
     160
     161    return 0;
    160162}
    161163
  • libcaca/trunk/caca/driver_win32.c

    r681 r684  
    334334 */
    335335
    336 void win32_init_driver(caca_t *kk)
     336int win32_install(caca_t *kk)
    337337{
    338338    kk->drv.driver = CACA_DRIVER_WIN32;
     
    346346    kk->drv.handle_resize = win32_handle_resize;
    347347    kk->drv.get_event = win32_get_event;
     348
     349    return 0;
    348350}
    349351
  • libcaca/trunk/caca/driver_x11.c

    r681 r684  
    9393    kk->drv.p = malloc(sizeof(struct driver_private));
    9494
     95#if defined(HAVE_GETENV)
    9596    geometry = getenv("CACA_GEOMETRY");
    9697    if(geometry && *geometry)
    9798        sscanf(geometry, "%ux%u", &width, &height);
     99#endif
    98100
    99101    if(width && height)
     
    104106        return -1;
    105107
     108#if defined(HAVE_GETENV)
    106109    fonts[0] = getenv("CACA_FONT");
    107110    if(fonts[0] && *fonts[0])
    108111        parser = fonts;
    109112    else
     113#endif
    110114        parser = fonts + 1;
    111115
     
    544548 */
    545549
    546 void x11_init_driver(caca_t *kk)
    547 {
     550int x11_install(caca_t *kk)
     551{
     552#if defined(HAVE_GETENV)
     553    if(!getenv("DISPLAY") || !*(getenv("DISPLAY")))
     554        return -1;
     555#endif
     556
    548557    kk->drv.driver = CACA_DRIVER_X11;
    549558
     
    556565    kk->drv.handle_resize = x11_handle_resize;
    557566    kk->drv.get_event = x11_get_event;
     567
     568    return 0;
    558569}
    559570
Note: See TracChangeset for help on using the changeset viewer.