1 /* $FreeBSD: src/contrib/libreadline/shell.c,v 1.4.2.2 2000/07/06 23:04:24 ache Exp $ */
2 /* $DragonFly: src/contrib/libreadline/Attic/shell.c,v 1.2 2003/06/17 04:24:03 dillon Exp $ */
3 /* shell.c -- readline utility functions that are normally provided by
4 bash when readline is linked as part of the shell. */
6 /* Copyright (C) 1997 Free Software Foundation, Inc.
8 This file is part of the GNU Readline Library, a library for
9 reading lines of text with interactive input and history editing.
11 The GNU Readline Library is free software; you can redistribute it
12 and/or modify it under the terms of the GNU General Public License
13 as published by the Free Software Foundation; either version 2, or
14 (at your option) any later version.
16 The GNU Readline Library is distributed in the hope that it will be
17 useful, but WITHOUT ANY WARRANTY; without even the implied warranty
18 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 The GNU General Public License is often shipped with GNU software, and
22 is generally kept in a file called COPYING or LICENSE. If you do not
23 have a copy of the license, write to the Free Software Foundation,
24 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
25 #define READLINE_LIBRARY
27 #if defined (HAVE_CONFIG_H)
31 #include <sys/types.h>
33 #if defined (HAVE_UNISTD_H)
35 #endif /* HAVE_UNISTD_H */
37 #if defined (HAVE_STDLIB_H)
40 # include "ansi_stdlib.h"
41 #endif /* HAVE_STDLIB_H */
43 #if defined (HAVE_STRING_H)
47 #endif /* !HAVE_STRING_H */
57 #if !defined (HAVE_GETPW_DECLS)
58 extern struct passwd *getpwuid ();
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. */
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 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 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 unset_nodelay_mode (fd)
157 if ((flags = fcntl (fd, F_GETFL, 0)) < 0)
163 bflags |= O_NONBLOCK;
173 return (fcntl (fd, F_SETFL, flags));