Ignore:
Timestamp:
Dec 16, 2007, 12:55:14 PM (14 years ago)
Author:
Sam Hocevar
Message:
  • The SLang and ncurses drivers now put back the TERM environment variable if they modified it.
File:
1 edited

Legend:

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

    r2138 r2142  
    111111#endif
    112112#if defined(HAVE_GETENV) && defined(HAVE_PUTENV)
    113 static void slang_check_terminal(void);
    114 #endif
     113static void slang_install_terminal(caca_display_t *);
     114static void slang_uninstall_terminal(caca_display_t *);
     115#endif
     116
     117struct driver_private
     118{
     119    char *term;
     120};
    115121
    116122static int slang_init_graphics(caca_display_t *dp)
    117123{
     124    dp->drv.p = malloc(sizeof(struct driver_private));
     125
    118126#if defined(HAVE_GETENV) && defined(HAVE_PUTENV)
    119     slang_check_terminal();
     127    slang_install_terminal(dp);
    120128#endif
    121129
     
    184192    SLang_reset_tty();
    185193    SLsmg_reset_smg();
     194
     195#if defined HAVE_GETENV && defined HAVE_PUTENV
     196    slang_uninstall_terminal(dp);
     197#endif
     198
     199    free(dp->drv.p);
    186200
    187201    return 0;
     
    495509
    496510#if defined(HAVE_GETENV) && defined(HAVE_PUTENV)
    497 static void slang_check_terminal(void)
     511static void slang_install_terminal(caca_display_t *dp)
    498512{
    499513    char *term, *colorterm;
     514
     515    dp->drv.p->term = NULL;
    500516
    501517    term = getenv("TERM");
     
    512528    {
    513529        (void)putenv("TERM=xterm-16color");
     530        dp->drv.p->term = strdup(term);
    514531        return;
    515532    }
     533}
     534
     535static void slang_uninstall_terminal(caca_display_t *dp)
     536{
     537    /* Needs to be persistent because we use putenv() */
     538    static char termenv[1024];
     539
     540    if(!dp->drv.p->term)
     541        return;
     542
     543    snprintf(termenv, 1023, "TERM=%s", dp->drv.p->term);
     544    free(dp->drv.p->term);
     545    (void)putenv(termenv);
    516546}
    517547#endif
Note: See TracChangeset for help on using the changeset viewer.