]> git.pld-linux.org Git - packages/elinks.git/blob - elinks-mailcap_DISPLAY.patch
- added (commented out) old_incremental patch, sorted bconds
[packages/elinks.git] / elinks-mailcap_DISPLAY.patch
1 bug 638: Save, set and restore the DISPLAY environment variable.
2
3 Thanks to this trick the appropriate handler is executed,
4 even in a mixed (X11, framebuffer) environment.
5
6 ---
7 commit 65a3518a912d6cc6aa38cee4a4142299d7a25cc7
8 tree 47b6a1c4af22420fef498ac26dd0955e79428024
9 parent 81f8ee1fa2b94ef40460eb4a42710e1ed9e22c98
10 author Witold Filipczyk <witekfl@poczta.onet.pl> Sun, 16 Mar 2008 16:29:32 +0100
11 committer Witold Filipczyk <nobody@nowhere> Sun, 16 Mar 2008 16:29:32 +0100
12
13  configure.in               |    1 +
14  src/mime/backend/mailcap.c |   58 +++++++++++++++++++++++++++++++++++++++++++-
15  2 files changed, 58 insertions(+), 1 deletions(-)
16
17 diff --git a/configure.in b/configure.in
18 index 0a867ae..5cfeaa9 100644
19 --- a/configure.in
20 +++ b/configure.in
21 @@ -307,6 +307,7 @@ AC_CHECK_FUNCS(gettimeofday clock_gettime)
22  AC_CHECK_FUNCS([cygwin_conv_to_full_win32_path])
23  
24  AC_CHECK_FUNCS(setenv putenv, HAVE_SETENV_OR_PUTENV=yes)
25 +AC_CHECK_FUNCS(unsetenv)
26  AC_CHECK_FUNCS(getuid, HAVE_GETUID=yes)
27  AC_CHECK_FUNCS(geteuid, HAVE_GETEUID=yes)
28  
29 diff --git a/src/mime/backend/mailcap.c b/src/mime/backend/mailcap.c
30 index 76ea78b..70e270d 100644
31 --- a/src/mime/backend/mailcap.c
32 +++ b/src/mime/backend/mailcap.c
33 @@ -646,8 +646,57 @@ get_mailcap_entry(unsigned char *type)
34         return entry;
35  }
36  
37 +#if defined(HAVE_SETENV) || defined(HAVE_PUTENV)
38 +/* restore == 0 set DISPLAY
39 + * restore == 1 restore DISPLAY
40 + */
41 +static void
42 +set_display(int xwin, int restore)
43 +{
44 +       static unsigned char *display = NULL;
45 +
46 +       if (!restore) {
47 +               display = getenv("DISPLAY");
48 +               if (display) display = stracpy(display);
49 +               if (xwin) {
50 +#ifdef HAVE_SETENV
51 +                       setenv("DISPLAY", ":0", 1);
52 +#else
53 +                       putenv("DISPLAY=:0");
54 +#endif
55 +               } else {
56 +#ifdef HAVE_UNSETENV
57 +                       unsetenv("DISPLAY");
58 +#else
59 +                       putenv("DISPLAY");
60 +#endif
61 +               }
62 +       } else { /* restore DISPLAY */
63 +               if (display) {
64 +#ifdef HAVE_SETENV
65 +                       setenv("DISPLAY", display, 1);
66 +#else
67 +                       {
68 +                               static unsigned char DISPLAY[1024] = { 'D','I','S','P','L','A','Y','=' };
69 +
70 +                               strncpy(DISPLAY + 8, display, 1023 - 8);
71 +                               putenv(DISPLAY);
72 +                       }
73 +#endif
74 +                       mem_free(display);
75 +               } else {
76 +#ifdef HAVE_UNSETENV
77 +                       unsetenv("DISPLAY");
78 +#else
79 +                       putenv("DISPLAY");
80 +#endif
81 +               }
82 +       }
83 +}
84 +#endif
85 +
86  static struct mime_handler *
87 -get_mime_handler_mailcap(unsigned char *type, int options)
88 +get_mime_handler_mailcap(unsigned char *type, int xwin)
89  {
90         struct mailcap_entry *entry;
91         struct mime_handler *handler;
92 @@ -658,7 +707,14 @@ get_mime_handler_mailcap(unsigned char *type, int options)
93             || (!mailcap_map && !init_mailcap_map()))
94                 return NULL;
95  
96 +#if defined(HAVE_SETENV) || defined(HAVE_PUTENV)
97 +       set_display(xwin, 0);
98 +#endif
99         entry = get_mailcap_entry(type);
100 +
101 +#if defined(HAVE_SETENV) || defined(HAVE_PUTENV)
102 +       set_display(xwin, 1);
103 +#endif
104         if (!entry) return NULL;
105  
106         program = format_command(entry->command, type, entry->copiousoutput);
This page took 0.109584 seconds and 3 git commands to generate.