#include "bashintl.h"
#include "shell.h"
+#include "parser.h"
+#include "flags.h"
+#include "findcmd.h"
#include "test.h"
#include "trap.h"
+#include "builtins/common.h"
+
#if defined (HAVE_MBSTR_H) && defined (HAVE_MBSCHR)
# include <mbstr.h> /* mbschr */
#endif
extern int errno;
#endif /* !errno */
-extern int expand_aliases;
-extern int interactive_comments;
-extern int check_hashed_filenames;
-extern int source_uses_path;
-extern int source_searches_cwd;
-extern int posixly_correct;
-extern int inherit_errexit;
+#ifdef __CYGWIN__
+# include <sys/cygwin.h>
+#endif
static char *bash_special_tilde_expansions __P((char *));
static int unquoted_tilde_word __P((const char *));
/* A standard error message to use when getcwd() returns NULL. */
const char * const bash_getcwd_errstr = N_("getcwd: cannot access parent directories");
-/* Do whatever is necessary to initialize `Posix mode'. */
+/* Do whatever is necessary to initialize `Posix mode'. This currently
+ modifies the following variables which are controlled via shopt:
+ interactive_comments
+ source_uses_path
+ expand_aliases
+ inherit_errexit
+ print_shift_error
+
+ and the following variables which cannot be user-modified:
+
+ source_searches_cwd
+
+ If we add to the first list, we need to change the table and functions
+ below */
+
+static struct {
+ int *posix_mode_var;
+} posix_vars[] =
+{
+ &interactive_comments,
+ &source_uses_path,
+ &expand_aliases,
+ &inherit_errexit,
+ &print_shift_error,
+ 0
+};
+
void
posix_initialize (on)
int on;
interactive_comments = source_uses_path = expand_aliases = 1;
inherit_errexit = 1;
source_searches_cwd = 0;
+ print_shift_error = 1;
+
}
/* Things that should be turned on when posix mode is disabled. */
{
source_searches_cwd = 1;
expand_aliases = interactive_shell;
+ print_shift_error = 0;
}
}
+int
+num_posix_options ()
+{
+ return ((sizeof (posix_vars) / sizeof (posix_vars[0])) - 1);
+}
+
+char *
+get_posix_options (bitmap)
+ char *bitmap;
+{
+ register int i;
+
+ if (bitmap == 0)
+ bitmap = (char *)xmalloc (num_posix_options ()); /* no trailing NULL */
+ for (i = 0; posix_vars[i].posix_mode_var; i++)
+ bitmap[i] = *(posix_vars[i].posix_mode_var);
+ return bitmap;
+}
+
+void
+set_posix_options (bitmap)
+ const char *bitmap;
+{
+ register int i;
+
+ for (i = 0; posix_vars[i].posix_mode_var; i++)
+ *(posix_vars[i].posix_mode_var) = bitmap[i];
+}
+
/* **************************************************************** */
/* */
/* Functions to convert to and from and display non-standard types */
#if defined (ARRAY_VARS)
if (valid_array_reference (value, 0))
{
- t = array_variable_name (value, (char **)NULL, (int *)NULL);
+ t = array_variable_name (value, 0, (char **)NULL, (int *)NULL);
if (t && STREQ (name, t))
{
free (t);
}
/* Returns non-zero if STRING is an assignment statement. The returned value
- is the index of the `=' sign. */
+ is the index of the `=' sign. If FLAGS&1 we are expecting a compound assignment
+ and don't want an array subscript before the `='. */
int
assignment (string, flags)
const char *string;
c = string[indx = 0];
#if defined (ARRAY_VARS)
- if ((legal_variable_starter (c) == 0) && (flags == 0 || c != '[')) /* ] */
+ if ((legal_variable_starter (c) == 0) && ((flags&1) == 0 || c != '[')) /* ] */
#else
if (legal_variable_starter (c) == 0)
#endif
#if defined (ARRAY_VARS)
if (c == '[')
{
- newi = skipsubscript (string, indx, 0);
+ newi = skipsubscript (string, indx, (flags & 2) ? 1 : 0);
+ /* XXX - why not check for blank subscripts here, if we do in
+ valid_array_reference? */
if (string[newi++] != ']')
return (0);
if (string[newi] == '+' && string[newi+1] == '=')
return (0);
}
+int
+line_isblank (line)
+ const char *line;
+{
+ register int i;
+
+ if (line == 0)
+ return 0; /* XXX */
+ for (i = 0; line[i]; i++)
+ if (isblank ((unsigned char)line[i]) == 0)
+ break;
+ return (line[i] == '\0');
+}
+
/* **************************************************************** */
/* */
/* Functions to manage files and file descriptors */
return 0;
}
+/* Just a wrapper for the define in include/filecntl.h */
+int
+sh_setclexec (fd)
+ int fd;
+{
+ return (SET_CLOSE_ON_EXEC (fd));
+}
+
/* Return 1 if file descriptor FD is valid; 0 otherwise. */
int
sh_validfd (fd)
{
char pathbuf[PATH_MAX + 1];
- cygwin_conv_to_full_posix_path (string, pathbuf);
+ /* WAS cygwin_conv_to_full_posix_path (string, pathbuf); */
+ cygwin_conv_path (CCP_WIN_A_TO_POSIX, string, pathbuf, PATH_MAX);
result = savestring (pathbuf);
}
#else
# endif /* !CS_PATH */
#endif /* !_CS_PATH || !HAVE_CONFSTR */
}
+
+int
+default_columns ()
+{
+ char *v;
+ int c;
+
+ c = -1;
+ v = get_string_value ("COLUMNS");
+ if (v && *v)
+ {
+ c = atoi (v);
+ if (c > 0)
+ return c;
+ }
+
+ if (check_window_size)
+ get_new_window_size (0, (int *)0, &c);
+
+ return (c > 0 ? c : 80);
+}
+
+