]>
git.ipfire.org Git - thirdparty/bash.git/blob - lib/readline/shell.c
1 /* shell.c -- readline utility functions that are normally provided by
2 bash when readline is linked as part of the shell. */
4 /* Copyright (C) 1997 Free Software Foundation, Inc.
6 This file is part of the GNU Readline Library, a library for
7 reading lines of text with interactive input and history editing.
9 The GNU Readline Library is free software; you can redistribute it
10 and/or modify it under the terms of the GNU General Public License
11 as published by the Free Software Foundation; either version 2, or
12 (at your option) any later version.
14 The GNU Readline Library is distributed in the hope that it will be
15 useful, but WITHOUT ANY WARRANTY; without even the implied warranty
16 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 The GNU General Public License is often shipped with GNU software, and
20 is generally kept in a file called COPYING or LICENSE. If you do not
21 have a copy of the license, write to the Free Software Foundation,
22 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
23 #define READLINE_LIBRARY
25 #if defined (HAVE_CONFIG_H)
29 #include <sys/types.h>
31 #if defined (HAVE_UNISTD_H)
33 #endif /* HAVE_UNISTD_H */
35 #if defined (HAVE_STDLIB_H)
38 # include "ansi_stdlib.h"
39 #endif /* HAVE_STDLIB_H */
41 #if defined (HAVE_STRING_H)
45 #endif /* !HAVE_STRING_H */
56 #if !defined (HAVE_GETPW_DECLS)
57 extern struct passwd
*getpwuid
__P((uid_t
));
58 #endif /* !HAVE_GETPW_DECLS */
64 /* All of these functions are resolved from bash if we are linking readline
67 /* Does shell-like quoting using single quotes. */
69 sh_single_quote (string
)
75 result
= (char *)xmalloc (3 + (4 * strlen (string
)));
79 for (s
= string
; s
&& (c
= *s
); s
++)
85 *r
++ = '\\'; /* insert escaped single quote */
87 *r
++ = '\''; /* start new quoted string */
97 /* Set the environment variables LINES and COLUMNS to lines and cols,
100 sh_set_lines_and_columns (lines
, cols
)
105 #if defined (HAVE_PUTENV)
107 sprintf (b
, "LINES=%d", lines
);
110 sprintf (b
, "COLUMNS=%d", cols
);
112 #else /* !HAVE_PUTENV */
113 # if defined (HAVE_SETENV)
115 sprintf (b
, "%d", lines
);
116 setenv ("LINES", b
, 1);
118 sprintf (b
, "%d", cols
);
119 setenv ("COLUMNS", b
, 1);
120 # endif /* HAVE_SETENV */
121 #endif /* !HAVE_PUTENV */
125 sh_get_env_value (varname
)
128 return ((char *)getenv (varname
));
135 struct passwd
*entry
;
137 home_dir
= (char *)NULL
;
138 entry
= getpwuid (getuid ());
140 home_dir
= entry
->pw_dir
;
144 #if !defined (O_NDELAY)
145 # if defined (FNDELAY)
146 # define O_NDELAY FNDELAY
151 sh_unset_nodelay_mode (fd
)
156 if ((flags
= fcntl (fd
, F_GETFL
, 0)) < 0)
162 bflags
|= O_NONBLOCK
;
172 return (fcntl (fd
, F_SETFL
, flags
));