shell.c (47563) | shell.c (58314) |
---|---|
1/* $FreeBSD: head/contrib/libreadline/shell.c 58314 2000-03-19 22:00:57Z ache $ */ |
|
1/* shell.c -- readline utility functions that are normally provided by 2 bash when readline is linked as part of the shell. */ 3 4/* Copyright (C) 1997 Free Software Foundation, Inc. 5 6 This file is part of the GNU Readline Library, a library for 7 reading lines of text with interactive input and history editing. 8 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 | 2/* shell.c -- readline utility functions that are normally provided by 3 bash when readline is linked as part of the shell. */ 4 5/* Copyright (C) 1997 Free Software Foundation, Inc. 6 7 This file is part of the GNU Readline Library, a library for 8 reading lines of text with interactive input and history editing. 9 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 |
11 as published by the Free Software Foundation; either version 1, or | 12 as published by the Free Software Foundation; either version 2, or |
12 (at your option) any later version. 13 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. 18 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, | 13 (at your option) any later version. 14 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. 19 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, |
22 675 Mass Ave, Cambridge, MA 02139, USA. */ | 23 59 Temple Place, Suite 330, Boston, MA 02111 USA. */ |
23#define READLINE_LIBRARY 24 25#if defined (HAVE_CONFIG_H) 26# include <config.h> 27#endif 28 29#include <sys/types.h> 30 --- 8 unchanged lines hidden (view full) --- 39#endif /* HAVE_STDLIB_H */ 40 41#if defined (HAVE_STRING_H) 42# include <string.h> 43#else 44# include <strings.h> 45#endif /* !HAVE_STRING_H */ 46 | 24#define READLINE_LIBRARY 25 26#if defined (HAVE_CONFIG_H) 27# include <config.h> 28#endif 29 30#include <sys/types.h> 31 --- 8 unchanged lines hidden (view full) --- 40#endif /* HAVE_STDLIB_H */ 41 42#if defined (HAVE_STRING_H) 43# include <string.h> 44#else 45# include <strings.h> 46#endif /* !HAVE_STRING_H */ 47 |
48#include <fcntl.h> |
|
47#include <pwd.h> 48 | 49#include <pwd.h> 50 |
51#include <stdio.h> 52 53#include "rlshell.h" 54#include "xmalloc.h" 55 |
|
49#if !defined (HAVE_GETPW_DECLS) 50extern struct passwd *getpwuid (); 51#endif /* !HAVE_GETPW_DECLS */ 52 | 56#if !defined (HAVE_GETPW_DECLS) 57extern struct passwd *getpwuid (); 58#endif /* !HAVE_GETPW_DECLS */ 59 |
53extern char *xmalloc (); | 60#ifndef NULL 61# define NULL 0 62#endif |
54 55/* All of these functions are resolved from bash if we are linking readline 56 as part of bash. */ 57 58/* Does shell-like quoting using single quotes. */ 59char * 60single_quote (string) 61 char *string; 62{ 63 register int c; 64 char *result, *r, *s; 65 | 63 64/* All of these functions are resolved from bash if we are linking readline 65 as part of bash. */ 66 67/* Does shell-like quoting using single quotes. */ 68char * 69single_quote (string) 70 char *string; 71{ 72 register int c; 73 char *result, *r, *s; 74 |
66 result = (char *)xmalloc (3 + (3 * strlen (string))); | 75 result = (char *)xmalloc (3 + (4 * strlen (string))); |
67 r = result; 68 *r++ = '\''; 69 70 for (s = string; s && (c = *s); s++) 71 { 72 *r++ = c; 73 74 if (c == '\'') --- 51 unchanged lines hidden (view full) --- 126 struct passwd *entry; 127 128 home_dir = (char *)NULL; 129 entry = getpwuid (getuid ()); 130 if (entry) 131 home_dir = entry->pw_dir; 132 return (home_dir); 133} | 76 r = result; 77 *r++ = '\''; 78 79 for (s = string; s && (c = *s); s++) 80 { 81 *r++ = c; 82 83 if (c == '\'') --- 51 unchanged lines hidden (view full) --- 135 struct passwd *entry; 136 137 home_dir = (char *)NULL; 138 entry = getpwuid (getuid ()); 139 if (entry) 140 home_dir = entry->pw_dir; 141 return (home_dir); 142} |
143 144#if !defined (O_NDELAY) 145# if defined (FNDELAY) 146# define O_NDELAY FNDELAY 147# endif 148#endif 149 150int 151unset_nodelay_mode (fd) 152 int fd; 153{ 154 int flags, bflags; 155 156 if ((flags = fcntl (fd, F_GETFL, 0)) < 0) 157 return -1; 158 159 bflags = 0; 160 161#ifdef O_NONBLOCK 162 bflags |= O_NONBLOCK; 163#endif 164 165#ifdef O_NDELAY 166 bflags |= O_NDELAY; 167#endif 168 169 if (flags & bflags) 170 { 171 flags &= ~bflags; 172 return (fcntl (fd, F_SETFL, flags)); 173 } 174 175 return 0; 176} |
|