X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=utils%2Ftextclient.c;h=f0d7fe898d65f82877ad862db9aeba4b7c4c0d2d;hb=aa75c7476aeaa84cf3abc192b376a8b03c325213;hp=794441f9c71d33913320d4566876b300cfe691b5;hpb=6afd6db0ae9396cd7ff897ade597cd5483f49b0e;p=xscreensaver diff --git a/utils/textclient.c b/utils/textclient.c index 794441f9..f0d7fe89 100644 --- a/utils/textclient.c +++ b/utils/textclient.c @@ -1,4 +1,4 @@ -/* xscreensaver, Copyright (c) 2012-2014 Jamie Zawinski +/* xscreensaver, Copyright (c) 2012-2016 Jamie Zawinski * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that @@ -16,11 +16,13 @@ * usePty: bool Whether to run the command interactively. * metaSendsESC: bool Whether to send Alt-x as ESC x in pty-mode. * swapBSDEL: bool Swap Backspace and Delete in pty-mode. + * + * On iOS and Android, textclient-mobile.c is used instead. */ #include "utils.h" -#ifndef USE_IPHONE /* whole file -- see OSX/iostextclient.m */ +#if !defined(USE_IPHONE) && !defined(HAVE_ANDROID) /* whole file */ #include "textclient.h" #include "resources.h" @@ -50,6 +52,9 @@ # ifdef HAVE_UTIL_H # include # endif +# ifdef HAVE_SYS_TERMIOS_H +# include +# endif #endif /* HAVE_FORKPTY */ #undef DEBUG @@ -93,16 +98,40 @@ subproc_cb (XtPointer closure, int *source, XtInputId *id) } +# define BACKSLASH(c) \ + (! ((c >= 'a' && c <= 'z') || \ + (c >= 'A' && c <= 'Z') || \ + (c >= '0' && c <= '9') || \ + c == '.' || c == '_' || c == '-' || c == '+' || c == '/')) + static void launch_text_generator (text_data *d) { XtAppContext app = XtDisplayToApplicationContext (d->dpy); char buf[255]; const char *oprogram = d->program; - char *program = (char *) malloc (strlen (oprogram) + 50); + char *s; + +# ifdef HAVE_COCOA + /* /bin/sh on OS X 10.10 wipes out the PATH. */ + const char *path = getenv("PATH"); + char *cmd = s = malloc ((strlen(oprogram) + strlen(path)) * 2 + 100); + strcpy (s, "export PATH="); + s += strlen (s); + while (*path) { + char c = *path++; + if (BACKSLASH(c)) *s++ = '\\'; + *s++ = c; + } + strcpy (s, "; "); + s += strlen (s); +# else + char *cmd = s = malloc ((strlen(oprogram)) * 2 + 100); +# endif - strcpy (program, "( "); - strcat (program, oprogram); + strcpy (s, "( "); + strcat (s, oprogram); + s += strlen (s); /* Kludge! Special-case "xscreensaver-text" to tell it how wide the screen is. We used to do this by just always feeding @@ -113,15 +142,16 @@ launch_text_generator (text_data *d) if (!strcmp (oprogram, "xscreensaver-text")) { if (d->char_w) - sprintf (program + strlen(program), " --cols %d", d->char_w); + sprintf (s, " --cols %d", d->char_w); if (d->max_lines) - sprintf (program + strlen(program), " --lines %d", d->max_lines); + sprintf (s, " --lines %d", d->max_lines); + s += strlen(s); } - strcat (program, " ) 2>&1"); + strcpy (s, " ) 2>&1"); # ifdef DEBUG - fprintf (stderr, "%s: textclient: launch %s: %s\n", progname, + fprintf (stderr, "%s: textclient: launch %s: %s\n", cmd, (d->pty_p ? "pty" : "pipe"), program); # endif @@ -152,7 +182,7 @@ launch_text_generator (text_data *d) abort(); av[i++] = "/bin/sh"; av[i++] = "-c"; - av[i++] = program; + av[i++] = cmd; av[i] = 0; execvp (av[0], av); sprintf (buf, "%.100s: %.100s", progname, oprogram); @@ -186,7 +216,7 @@ launch_text_generator (text_data *d) } if (d->pipe) abort(); - if ((d->pipe = popen (program, "r"))) + if ((d->pipe = popen (cmd, "r"))) { if (d->pipe_id) abort(); d->pipe_id = @@ -199,12 +229,12 @@ launch_text_generator (text_data *d) } else { - sprintf (buf, "%.100s: %.100s", progname, program); + sprintf (buf, "%.100s: %.100s", progname, cmd); perror (buf); } } - free (program); + free (cmd); }