2 /* shell.c -- readline utility functions that are normally provided by
3 bash when readline is linked as part of the shell. */
5 /* Copyright (C) 1997 Free Software Foundation, Inc.
7 This file is part of the GNU Readline Library, a library for
8 reading lines of text with interactive input and history editing.
10 The GNU Readline Library is free software; you can redistribute it
11 and/or modify it under the terms of the GNU General Public License
12 as published by the Free Software Foundation; either version 2, or
13 (at your option) any later version.
15 The GNU Readline Library is distributed in the hope that it will be
16 useful, but WITHOUT ANY WARRANTY; without even the implied warranty
17 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 The GNU General Public License is often shipped with GNU software, and
21 is generally kept in a file called COPYING or LICENSE. If you do not
22 have a copy of the license, write to the Free Software Foundation,
23 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
24 #define READLINE_LIBRARY
26 #if defined (HAVE_CONFIG_H)
30 #include <sys/types.h>
32 #if defined (HAVE_UNISTD_H)
34 #endif /* HAVE_UNISTD_H */
36 #if defined (HAVE_STDLIB_H)
39 # include "ansi_stdlib.h"
40 #endif /* HAVE_STDLIB_H */
42 #if defined (HAVE_STRING_H)
46 #endif /* !HAVE_STRING_H */
57 #if !defined (HAVE_GETPW_DECLS)
58 extern struct passwd *getpwuid __P((uid_t));
59 #endif /* !HAVE_GETPW_DECLS */
65 /* All of these functions are resolved from bash if we are linking readline
68 /* Does shell-like quoting using single quotes. */
70 sh_single_quote (string)
76 result = (char *)xmalloc (3 + (4 * strlen (string)));
80 for (s = string; s && (c = *s); s++)
86 *r++ = '\\'; /* insert escaped single quote */
88 *r++ = '\''; /* start new quoted string */
98 /* Set the environment variables LINES and COLUMNS to lines and cols,
101 sh_set_lines_and_columns (lines, cols)
106 #if defined (HAVE_PUTENV)
108 sprintf (b, "LINES=%d", lines);
111 sprintf (b, "COLUMNS=%d", cols);
113 #else /* !HAVE_PUTENV */
114 # if defined (HAVE_SETENV)
116 sprintf (b, "%d", lines);
117 setenv ("LINES", b, 1);
119 sprintf (b, "%d", cols);
120 setenv ("COLUMNS", b, 1);
121 # endif /* HAVE_SETENV */
122 #endif /* !HAVE_PUTENV */
126 sh_get_env_value (varname)
129 return ((char *)getenv (varname));
136 struct passwd *entry;
138 home_dir = (char *)NULL;
139 entry = getpwuid (getuid ());
141 home_dir = entry->pw_dir;
145 #if !defined (O_NDELAY)
146 # if defined (FNDELAY)
147 # define O_NDELAY FNDELAY
152 sh_unset_nodelay_mode (fd)
157 if ((flags = fcntl (fd, F_GETFL, 0)) < 0)
163 bflags |= O_NONBLOCK;
173 return (fcntl (fd, F_SETFL, flags));