Module Name: src
Committed By: kamil
Date: Thu Jun 22 14:11:28 UTC 2017
Modified Files:
src/bin/ksh: c_ksh.c c_sh.c c_ulimit.c config.h edit.c emacs.c eval.c
exec.c history.c io.c jobs.c lex.c main.c misc.c path.c sh.h shf.c
trap.c tree.h vi.c
Log Message:
Temporarily revert previous.
emacs.* gets wrong code in generation
To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/bin/ksh/c_ksh.c
cvs rdiff -u -r1.17 -r1.18 src/bin/ksh/c_sh.c src/bin/ksh/eval.c
cvs rdiff -u -r1.13 -r1.14 src/bin/ksh/c_ulimit.c src/bin/ksh/history.c
cvs rdiff -u -r1.12 -r1.13 src/bin/ksh/config.h
cvs rdiff -u -r1.28 -r1.29 src/bin/ksh/edit.c
cvs rdiff -u -r1.33 -r1.34 src/bin/ksh/emacs.c
cvs rdiff -u -r1.16 -r1.17 src/bin/ksh/exec.c src/bin/ksh/lex.c \
src/bin/ksh/main.c
cvs rdiff -u -r1.10 -r1.11 src/bin/ksh/io.c src/bin/ksh/path.c \
src/bin/ksh/sh.h
cvs rdiff -u -r1.11 -r1.12 src/bin/ksh/jobs.c
cvs rdiff -u -r1.19 -r1.20 src/bin/ksh/misc.c
cvs rdiff -u -r1.8 -r1.9 src/bin/ksh/shf.c
cvs rdiff -u -r1.9 -r1.10 src/bin/ksh/trap.c
cvs rdiff -u -r1.5 -r1.6 src/bin/ksh/tree.h
cvs rdiff -u -r1.14 -r1.15 src/bin/ksh/vi.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/bin/ksh/c_ksh.c
diff -u src/bin/ksh/c_ksh.c:1.21 src/bin/ksh/c_ksh.c:1.22
--- src/bin/ksh/c_ksh.c:1.21 Thu Jun 22 13:35:47 2017
+++ src/bin/ksh/c_ksh.c Thu Jun 22 14:11:27 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: c_ksh.c,v 1.21 2017/06/22 13:35:47 kamil Exp $ */
+/* $NetBSD: c_ksh.c,v 1.22 2017/06/22 14:11:27 kamil Exp $ */
/*
* built-in Korn commands: c_*
@@ -6,13 +6,17 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: c_ksh.c,v 1.21 2017/06/22 13:35:47 kamil Exp $");
+__RCSID("$NetBSD: c_ksh.c,v 1.22 2017/06/22 14:11:27 kamil Exp $");
#endif
#include "sh.h"
#include "ksh_stat.h"
#include <ctype.h>
+#ifdef __CYGWIN__
+#include <sys/cygwin.h>
+#endif /* __CYGWIN__ */
+
int
c_cd(wp)
char **wp;
@@ -141,7 +145,15 @@ c_cd(wp)
setstr(oldpwd_s, current_wd, KSH_RETURN_ERROR);
if (!ISABSPATH(Xstring(xs, xp))) {
+#ifdef OS2
+ /* simplify_path() doesn't know about os/2's drive contexts,
+ * so it can't set current_wd when changing to a:foo.
+ * Handle this by calling getcwd()...
+ */
+ pwd = ksh_get_wd((char *) 0, 0);
+#else /* OS2 */
pwd = (char *) 0;
+#endif /* OS2 */
} else
#ifdef S_ISLNK
if (!physical || !(pwd = get_phys_path(Xstring(xs, xp))))
@@ -150,7 +162,12 @@ c_cd(wp)
/* Set PWD */
if (pwd) {
+#ifdef __CYGWIN__
+ char ptmp[PATH]; /* larger than MAX_PATH */
+ cygwin_conv_to_full_posix_path(pwd, ptmp);
+#else /* __CYGWIN__ */
char *ptmp = pwd;
+#endif /* __CYGWIN__ */
set_current_wd(ptmp);
/* Ignore failure (happens if readonly or integer) */
setstr(pwd_s, ptmp, KSH_RETURN_ERROR);
@@ -224,6 +241,7 @@ c_print(wp)
#define PO_PMINUSMINUS BIT(2) /* print a -- argument */
#define PO_HIST BIT(3) /* print to history instead of stdout */
#define PO_COPROC BIT(4) /* printing to coprocess: block SIGPIPE */
+#define PO_FSLASH BIT(5) /* swap slash for backslash (for os2 ) */
int fd = 1;
int flags = PO_EXPAND|PO_NL;
char *s;
@@ -264,7 +282,11 @@ c_print(wp)
}
} else {
int optc;
+#if OS2
+ const char *options = "Rnpfrsu,"; /* added f flag */
+#else
const char *options = "Rnprsu,";
+#endif
while ((optc = ksh_getopt(wp, &builtin_opt, options)) != EOF)
switch (optc) {
case 'R': /* fake BSD echo command */
@@ -275,6 +297,11 @@ c_print(wp)
case 'e':
flags |= PO_EXPAND;
break;
+#ifdef OS2
+ case 'f':
+ flags |= PO_FSLASH;
+ break;
+#endif
case 'n':
flags &= ~PO_NL;
break;
@@ -320,12 +347,19 @@ c_print(wp)
s = *wp;
while ((c = *s++) != '\0') {
Xcheck(xs, xp);
+#ifdef OS2
+ if ((flags & PO_FSLASH) && c == '\\')
+ if (*s == '\\')
+ *s++;
+ else
+ c = '/';
+#endif /* OS2 */
if ((flags & PO_EXPAND) && c == '\\') {
int i;
switch ((c = *s++)) {
/* Oddly enough, \007 seems more portable than
- * \a (due to Ultrix cc, old pcc's,
+ * \a (due to HP-UX cc, Ultrix cc, old pcc's,
* etc.).
*/
case 'a': c = '\007'; break;
Index: src/bin/ksh/c_sh.c
diff -u src/bin/ksh/c_sh.c:1.17 src/bin/ksh/c_sh.c:1.18
--- src/bin/ksh/c_sh.c:1.17 Thu Jun 22 13:33:39 2017
+++ src/bin/ksh/c_sh.c Thu Jun 22 14:11:27 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: c_sh.c,v 1.17 2017/06/22 13:33:39 kamil Exp $ */
+/* $NetBSD: c_sh.c,v 1.18 2017/06/22 14:11:27 kamil Exp $ */
/*
* built-in Bourne commands
@@ -6,7 +6,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: c_sh.c,v 1.17 2017/06/22 13:33:39 kamil Exp $");
+__RCSID("$NetBSD: c_sh.c,v 1.18 2017/06/22 14:11:27 kamil Exp $");
#endif
@@ -331,6 +331,9 @@ c_read(wp)
while (1) {
c = shf_getc(shf);
if (c == '\0'
+#ifdef OS2
+ || c == '\r'
+#endif /* OS2 */
)
continue;
if (c == EOF && shf_error(shf)
@@ -902,5 +905,13 @@ const struct builtin shbuiltins [] = {
{"ulimit", c_ulimit},
{"+umask", c_umask},
{"*=unset", c_unset},
+#ifdef OS2
+ /* In OS2, the first line of a file can be "extproc name", which
+ * tells the command interpreter (cmd.exe) to use name to execute
+ * the file. For this to be useful, ksh must ignore commands
+ * starting with extproc and this does the trick...
+ */
+ {"extproc", c_label},
+#endif /* OS2 */
{NULL, NULL}
};
Index: src/bin/ksh/eval.c
diff -u src/bin/ksh/eval.c:1.17 src/bin/ksh/eval.c:1.18
--- src/bin/ksh/eval.c:1.17 Thu Jun 22 13:33:39 2017
+++ src/bin/ksh/eval.c Thu Jun 22 14:11:27 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: eval.c,v 1.17 2017/06/22 13:33:39 kamil Exp $ */
+/* $NetBSD: eval.c,v 1.18 2017/06/22 14:11:27 kamil Exp $ */
/*
* Expansion - quoting, separation, substitution, globbing
@@ -6,7 +6,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: eval.c,v 1.17 2017/06/22 13:33:39 kamil Exp $");
+__RCSID("$NetBSD: eval.c,v 1.18 2017/06/22 14:11:27 kamil Exp $");
#endif
#include <stdint.h>
@@ -1062,7 +1062,15 @@ globit(xs, xpp, sp, wp, check)
*xp = '\0';
}
}
+#ifdef OS2 /* Done this way to avoid bug in gcc 2.7.2... */
+ /* Ugly kludge required for command
+ * completion - see how search_access()
+ * is implemented for OS/2...
+ */
+# define KLUDGE_VAL 4
+#else /* OS2 */
# define KLUDGE_VAL 0
+#endif /* OS2 */
XPput(*wp, str_nsave(Xstring(*xs, xp), Xlength(*xs, xp)
+ KLUDGE_VAL, ATEMP));
return;
@@ -1288,6 +1296,10 @@ homedir(name)
ap = tenter(&homedirs, name, hash(name));
if (!(ap->flag & ISSET)) {
+#ifdef OS2
+ /* No usernames in OS2 - punt */
+ return NULL;
+#else /* OS2 */
struct passwd *pw;
size_t n;
@@ -1303,6 +1315,7 @@ homedir(name)
ap->val.s = str_save(pw->pw_dir, APERM);
}
ap->flag |= DEFINED|ISSET|ALLOC;
+#endif /* OS2 */
}
return ap->val.s;
}
Index: src/bin/ksh/c_ulimit.c
diff -u src/bin/ksh/c_ulimit.c:1.13 src/bin/ksh/c_ulimit.c:1.14
--- src/bin/ksh/c_ulimit.c:1.13 Thu Jun 22 13:35:47 2017
+++ src/bin/ksh/c_ulimit.c Thu Jun 22 14:11:27 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: c_ulimit.c,v 1.13 2017/06/22 13:35:47 kamil Exp $ */
+/* $NetBSD: c_ulimit.c,v 1.14 2017/06/22 14:11:27 kamil Exp $ */
/*
ulimit -- handle "ulimit" builtin
@@ -20,7 +20,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: c_ulimit.c,v 1.13 2017/06/22 13:35:47 kamil Exp $");
+__RCSID("$NetBSD: c_ulimit.c,v 1.14 2017/06/22 14:11:27 kamil Exp $");
#endif
@@ -113,6 +113,9 @@ c_ulimit(wp)
# ifdef UL_GETBREAK /* osf/1 */
{ "vmemory(maxaddr)", ULIMIT, UL_GETBREAK, -1, 1, 'v' },
# else /* UL_GETBREAK */
+# ifdef UL_GETMAXBRK /* hpux */
+ { "vmemory(maxaddr)", ULIMIT, UL_GETMAXBRK, -1, 1, 'v' },
+# endif /* UL_GETMAXBRK */
# endif /* UL_GETBREAK */
# endif /* UL_GMEMLIM */
#endif /* RLIMIT_VMEM */
Index: src/bin/ksh/history.c
diff -u src/bin/ksh/history.c:1.13 src/bin/ksh/history.c:1.14
--- src/bin/ksh/history.c:1.13 Thu Jun 22 13:33:39 2017
+++ src/bin/ksh/history.c Thu Jun 22 14:11:27 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: history.c,v 1.13 2017/06/22 13:33:39 kamil Exp $ */
+/* $NetBSD: history.c,v 1.14 2017/06/22 14:11:27 kamil Exp $ */
/*
* command history
@@ -19,7 +19,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: history.c,v 1.13 2017/06/22 13:33:39 kamil Exp $");
+__RCSID("$NetBSD: history.c,v 1.14 2017/06/22 14:11:27 kamil Exp $");
#endif
@@ -30,7 +30,11 @@ __RCSID("$NetBSD: history.c,v 1.13 2017/
# ifdef EASY_HISTORY
# ifndef HISTFILE
+# ifdef OS2
+# define HISTFILE "history.ksh"
+# else /* OS2 */
# define HISTFILE ".pdksh_history"
+# endif /* OS2 */
# endif
# else
Index: src/bin/ksh/config.h
diff -u src/bin/ksh/config.h:1.12 src/bin/ksh/config.h:1.13
--- src/bin/ksh/config.h:1.12 Thu Jun 22 13:37:16 2017
+++ src/bin/ksh/config.h Thu Jun 22 14:11:27 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: config.h,v 1.12 2017/06/22 13:37:16 kamil Exp $ */
+/* $NetBSD: config.h,v 1.13 2017/06/22 14:11:27 kamil Exp $ */
/* config.h. Generated automatically by configure. */
/* config.h.in. Generated automatically from configure.in by autoheader. */
@@ -11,6 +11,13 @@
#ifndef CONFIG_H
#define CONFIG_H
+/* Define if on AIX 3.
+ System headers sometimes define this.
+ We just want to avoid a redefinition error message. */
+#ifndef _ALL_SOURCE
+/* #undef _ALL_SOURCE */
+#endif
+
/* Define if the closedir function returns void instead of int. */
/* #undef CLOSEDIR_VOID */
@@ -171,9 +178,15 @@
/* Define if the pgrp of setpgrp() can't be the pid of a zombie process */
/* #undef NEED_PGRP_SYNC */
+/* Define if you arg running SCO unix */
+/* #undef OS_SCO */
+
/* Define if you arg running ISC unix */
/* #undef OS_ISC */
+/* Define if you arg running OS2 with the EMX library */
+/* #undef OS2 */
+
/* Define if you have a POSIX.1 compatible <sys/wait.h> */
#define POSIX_SYS_WAIT 1
@@ -187,6 +200,10 @@
#define DEFAULT_PATH "/bin:/usr/bin:/sbin:/usr/sbin"
#endif
+/* Define if your C library's getwd/getcwd function dumps core in unreadable
+ * directories. */
+/* #undef HPUX_GETWD_BUG */
+
/* Include ksh features? */
#define KSH 1
Index: src/bin/ksh/edit.c
diff -u src/bin/ksh/edit.c:1.28 src/bin/ksh/edit.c:1.29
--- src/bin/ksh/edit.c:1.28 Thu Jun 22 13:34:48 2017
+++ src/bin/ksh/edit.c Thu Jun 22 14:11:27 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: edit.c,v 1.28 2017/06/22 13:34:48 kamil Exp $ */
+/* $NetBSD: edit.c,v 1.29 2017/06/22 14:11:27 kamil Exp $ */
/*
* Command line editing - common code
@@ -7,7 +7,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: edit.c,v 1.28 2017/06/22 13:34:48 kamil Exp $");
+__RCSID("$NetBSD: edit.c,v 1.29 2017/06/22 14:11:27 kamil Exp $");
#endif
@@ -19,6 +19,10 @@ __RCSID("$NetBSD: edit.c,v 1.28 2017/06/
#define EXTERN
#include "edit.h"
#undef EXTERN
+#ifdef OS_SCO /* SCO Unix 3.2v4.1 */
+# include <sys/stream.h> /* needed for <sys/ptem.h> */
+# include <sys/ptem.h> /* needed for struct winsize */
+#endif /* OS_SCO */
#include <sys/ioctl.h>
#include <ctype.h>
#include "ksh_stat.h"
@@ -157,6 +161,10 @@ x_read(buf, len)
int
x_getc()
{
+#ifdef OS2
+ unsigned char c = _read_kbd(0, 1, 0);
+ return c == 0 ? 0xE0 : c;
+#else /* OS2 */
char c;
int n;
@@ -169,6 +177,7 @@ x_getc()
if (n != 1)
return -1;
return (int) (unsigned char) c;
+#endif /* OS2 */
}
void
@@ -284,6 +293,11 @@ x_mode(onoff)
set_tty(tty_fd, &cb, TF_WAIT);
+#ifdef __CYGWIN__
+ if (edchars.eof == '\0')
+ edchars.eof = '\4';
+#endif /* __CYGWIN__ */
+
/* Convert unset values to internal `unset' value */
if (edchars.erase == vdisable_c)
edchars.erase = -1;
Index: src/bin/ksh/emacs.c
diff -u src/bin/ksh/emacs.c:1.33 src/bin/ksh/emacs.c:1.34
--- src/bin/ksh/emacs.c:1.33 Thu Jun 22 13:33:39 2017
+++ src/bin/ksh/emacs.c Thu Jun 22 14:11:27 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: emacs.c,v 1.33 2017/06/22 13:33:39 kamil Exp $ */
+/* $NetBSD: emacs.c,v 1.34 2017/06/22 14:11:27 kamil Exp $ */
/*
* Emacs-like command line editing and history
@@ -10,7 +10,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: emacs.c,v 1.33 2017/06/22 13:33:39 kamil Exp $");
+__RCSID("$NetBSD: emacs.c,v 1.34 2017/06/22 14:11:27 kamil Exp $");
#endif
@@ -62,8 +62,17 @@ struct x_defbindings {
#define is_cfs(c) (c == ' ' || c == '\t' || c == '"' || c == '\'')
#define is_mfs(c) (!(isalnum((unsigned char)c) || c == '_' || c == '$')) /* Separator for motion */
+#ifdef OS2
+ /* Deal with 8 bit chars & an extra prefix for function key (these two
+ * changes increase memory usage from 9,216 bytes to 24,416 bytes...)
+ */
+# define CHARMASK 0xFF /* 8-bit ASCII character mask */
+# define X_NTABS 4 /* normal, meta1, meta2, meta3 */
+static int x_prefix3 = 0xE0;
+#else /* OS2 */
# define CHARMASK 0xFF /* 8-bit character mask */
# define X_NTABS 3 /* normal, meta1, meta2 */
+#endif /* OS2 */
#define X_TABSZ (CHARMASK+1) /* size of keydef tables etc */
/* Arguments for do_complete()
@@ -225,6 +234,9 @@ static const struct x_ftab x_ftab[] = {
#else
{ 0, 0, 0 },
#endif
+#ifdef OS2
+ { x_meta3, "prefix-3", XF_PREFIX },
+#else
{ 0, 0, 0 },
#endif
/* @END-FUNC-TAB@ */
@@ -304,6 +316,13 @@ static struct x_defbindings const x_defb
{ XFUNC_fold_lower, 1, 'l' },
{ XFUNC_fold_capitalize, 1, 'C' },
{ XFUNC_fold_capitalize, 1, 'c' },
+#ifdef OS2
+ { XFUNC_meta3, 0, 0xE0 },
+ { XFUNC_mv_back, 3, 'K' },
+ { XFUNC_mv_forw, 3, 'M' },
+ { XFUNC_next_com, 3, 'P' },
+ { XFUNC_prev_com, 3, 'H' },
+#endif /* OS2 */
/* These for ansi arrow keys: arguablely shouldn't be here by
* default, but its simpler/faster/smaller than using termcap
* entries.
@@ -1190,6 +1209,16 @@ x_meta2(c)
return KSTD;
}
+#ifdef OS2
+static int
+x_meta3(c)
+ int c;
+{
+ x_curprefix = 3;
+ return KSTD;
+}
+#endif /* OS2 */
+
static int
x_kill(c)
int c;
@@ -1329,6 +1358,11 @@ x_mapin(cp, area)
/* XXX -- should handle \^ escape? */
if (*cp == '^') {
cp++;
+#ifdef OS2
+ if (*cp == '0') /* To define function keys */
+ *op++ = 0xE0;
+ else
+#endif /* OS2 */
if (*cp >= '?') /* includes '?'; ASCII */
*op++ = CTRL(*cp);
else {
@@ -1351,6 +1385,12 @@ x_mapout(c)
static char buf[8];
register char *p = buf;
+#ifdef OS2
+ if (c == 0xE0) {
+ *p++ = '^';
+ *p++ = '0';
+ } else
+#endif /* OS2 */
if (iscntrl((unsigned char)c)) {
*p++ = '^';
*p++ = UNCTRL(c);
@@ -1368,7 +1408,10 @@ x_print(prefix, key)
shprintf("%s", x_mapout(x_prefix1));
if (prefix == 2)
shprintf("%s", x_mapout(x_prefix2));
-
+#ifdef OS2
+ if (prefix == 3)
+ shprintf("%s", x_mapout(x_prefix3));
+#endif /* OS2 */
shprintf("%s = ", x_mapout(key));
if (x_tab[prefix][key] != XFUNC_ins_string)
shprintf("%s\n", x_ftab[x_tab[prefix][key]].xf_name);
@@ -1421,6 +1464,10 @@ x_bind(a1, a2, macro, list)
prefix = 1;
else if (x_tab[prefix][key] == XFUNC_meta2)
prefix = 2;
+#ifdef OS2
+ else if (x_tab[prefix][key] == XFUNC_meta3)
+ prefix = 3;
+#endif /* OS2 */
else
break;
}
Index: src/bin/ksh/exec.c
diff -u src/bin/ksh/exec.c:1.16 src/bin/ksh/exec.c:1.17
--- src/bin/ksh/exec.c:1.16 Thu Jun 22 13:33:39 2017
+++ src/bin/ksh/exec.c Thu Jun 22 14:11:27 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: exec.c,v 1.16 2017/06/22 13:33:39 kamil Exp $ */
+/* $NetBSD: exec.c,v 1.17 2017/06/22 14:11:27 kamil Exp $ */
/*
* execute command tree
@@ -6,7 +6,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: exec.c,v 1.16 2017/06/22 13:33:39 kamil Exp $");
+__RCSID("$NetBSD: exec.c,v 1.17 2017/06/22 14:11:27 kamil Exp $");
#endif
@@ -38,6 +38,10 @@ static int dbteste_eval ARGS((Test_env *
const char *, int));
static void dbteste_error ARGS((Test_env *, int, const char *));
#endif /* KSH */
+#ifdef OS2
+static int search_access1 ARGS((const char *, int, int *));
+#endif /* OS2 */
+
/*
* handle systems that don't have F_SETFD
@@ -420,7 +424,8 @@ execute(t, flags)
#endif
restoresigs();
cleanup_proc_env();
- ksh_execve(t->str, t->args, ap, flags);
+ /* XINTACT bit is for OS2 */
+ ksh_execve(t->str, t->args, ap, (flags & XINTACT) ? 1 : 0);
if (errno == ENOEXEC)
scriptexec(t, ap);
else
@@ -777,16 +782,32 @@ scriptexec(tp, ap)
(void) close(fd);
}
if ((buf[0] == '#' && buf[1] == '!' && (cp = &buf[2]))
+# ifdef OS2
+ || (strncmp(buf, "extproc", 7) == 0 && isspace((unsigned char)buf[7])
+ && (cp = &buf[7]))
+# endif /* OS2 */
)
{
while (*cp && (*cp == ' ' || *cp == '\t'))
cp++;
if (*cp && *cp != '\n') {
char *a0 = cp, *a1 = (char *) 0;
+# ifdef OS2
+ char *a2 = cp;
+# endif /* OS2 */
while (*cp && *cp != '\n' && *cp != ' '
&& *cp != '\t')
{
+# ifdef OS2
+ /* Allow shell search without prepended path
+ * if shell with / in pathname cannot be found.
+ * Use / explicitly so \ can be used if explicit
+ * needs to be forced.
+ */
+ if (*cp == '/')
+ a2 = cp + 1;
+# endif /* OS2 */
cp++;
}
if (*cp && *cp != '\n') {
@@ -805,9 +826,38 @@ scriptexec(tp, ap)
*cp = '\0';
if (a1)
*tp->args-- = a1;
+# ifdef OS2
+ if (a0 != a2) {
+ char *tmp_a0 = str_nsave(a0,
+ strlen(a0) + 5, ATEMP);
+ if (search_access(tmp_a0, X_OK,
+ (int *) 0))
+ a0 = a2;
+ afree(tmp_a0, ATEMP);
+ }
+# endif /* OS2 */
shellv = a0;
}
}
+# ifdef OS2
+ } else {
+ /* Use ksh documented shell default if present
+ * else use OS2_SHELL which is assumed to need
+ * the /c option and '\' as dir separator.
+ */
+ char *p = shellv;
+
+ shellv = str_val(global("EXECSHELL"));
+ if (shellv && *shellv)
+ shellv = search(shellv, path, X_OK, (int *) 0);
+ if (!shellv || !*shellv) {
+ shellv = p;
+ *tp->args-- = "/c";
+ for (p = tp->str; *p; p++)
+ if (*p == '/')
+ *p = '\\';
+ }
+# endif /* OS2 */
}
}
#endif /* SHARPBANG */
@@ -1066,6 +1116,7 @@ search_access(pathx, mode, errnop)
int mode;
int *errnop; /* set if candidate found, but not suitable */
{
+#ifndef OS2
int ret, err = 0;
struct stat statb;
@@ -1085,8 +1136,74 @@ search_access(pathx, mode, errnop)
if (err && errnop && !*errnop)
*errnop = err;
return ret;
+#else /* !OS2 */
+ /*
+ * NOTE: ASSUMES path can be modified and has enough room at the
+ * end of the string for a suffix (ie, 4 extra characters).
+ * Certain code knows this (eg, eval.c(globit()),
+ * exec.c(search())).
+ */
+ static char *xsuffixes[] = { ".ksh", ".exe", ".", ".sh", ".cmd",
+ ".com", ".bat", (char *) 0
+ };
+ static char *rsuffixes[] = { ".ksh", ".", ".sh", ".cmd", ".bat",
+ (char *) 0
+ };
+ int i;
+ char *mpath = (char *) pathx;
+ char *tp = mpath + strlen(mpath);
+ char *p;
+ char **sfx;
+
+ /* If a suffix has been specified, check if it is one of the
+ * suffixes that indicate the file is executable - if so, change
+ * the access test to R_OK...
+ * This code assumes OS/2 files can have only one suffix...
+ */
+ if ((p = strrchr((p = ksh_strrchr_dirsep(mpath)) ? p : mpath, '.'))) {
+ if (mode == X_OK)
+ mode = R_OK;
+ return search_access1(mpath, mode, errnop);
+ }
+ /* Try appending the various suffixes. Different suffixes for
+ * read and execute 'cause we don't want to read an executable...
+ */
+ sfx = mode == R_OK ? rsuffixes : xsuffixes;
+ for (i = 0; sfx[i]; i++) {
+ strcpy(tp, p = sfx[i]);
+ if (search_access1(mpath, R_OK, errnop) == 0)
+ return 0;
+ *tp = '\0';
+ }
+ return -1;
+#endif /* !OS2 */
}
+#ifdef OS2
+static int
+search_access1(pathx, mode, errnop)
+ const char *pathx;
+ int mode;
+ int *errnop; /* set if candidate found, but not suitable */
+{
+ int ret, err = 0;
+ struct stat statb;
+
+ if (stat(pathx, &statb) < 0)
+ return -1;
+ ret = eaccess(pathx, mode);
+ if (ret < 0)
+ err = errno; /* File exists, but we can't access it */
+ else if (!S_ISREG(statb.st_mode)) {
+ ret = -1;
+ err = S_ISDIR(statb.st_mode) ? EISDIR : EACCES;
+ }
+ if (err && errnop && !*errnop)
+ *errnop = err;
+ return ret;
+}
+#endif /* OS2 */
+
/*
* search for command with PATH
*/
@@ -1104,7 +1221,25 @@ search(name, pathx, mode, errnop)
if (errnop)
*errnop = 0;
+#ifdef OS2
+ /* Xinit() allocates 8 additional bytes, so appended suffixes won't
+ * overflow the memory.
+ */
+ namelen = strlen(name) + 1;
+ Xinit(xs, xp, namelen, ATEMP);
+ memcpy(Xstring(xs, xp), name, namelen);
+
+ if (ksh_strchr_dirsep(name)) {
+ if (search_access(Xstring(xs, xp), mode, errnop) >= 0)
+ return Xstring(xs, xp); /* not Xclose() - see above */
+ Xfree(xs, xp);
+ return NULL;
+ }
+ /* Look in current context always. (os2 style) */
+ if (search_access(Xstring(xs, xp), mode, errnop) == 0)
+ return Xstring(xs, xp); /* not Xclose() - xp may be wrong */
+#else /* OS2 */
if (ksh_strchr_dirsep(name)) {
if (search_access(name, mode, errnop) == 0)
return (char *)__UNCONST(name);
@@ -1113,6 +1248,7 @@ search(name, pathx, mode, errnop)
namelen = strlen(name) + 1;
Xinit(xs, xp, 128, ATEMP);
+#endif /* OS2 */
sp = pathx;
while (sp != NULL) {
@@ -1129,7 +1265,11 @@ search(name, pathx, mode, errnop)
XcheckN(xs, xp, namelen);
memcpy(xp, name, namelen);
if (search_access(Xstring(xs, xp), mode, errnop) == 0)
+#ifdef OS2
+ return Xstring(xs, xp); /* Not Xclose() - see above */
+#else /* OS2 */
return Xclose(xs, xp + namelen);
+#endif /* OS2 */
if (*sp++ == '\0')
sp = NULL;
}
@@ -1242,6 +1382,10 @@ iosetup(iop, tp)
return -1;
}
u = open(cp, flags, 0666);
+#ifdef OS2
+ if (u < 0 && strcmp(cp, "/dev/null") == 0)
+ u = open("nul", flags, 0666);
+#endif /* OS2 */
}
if (u < 0) {
/* herein() may already have printed message */
Index: src/bin/ksh/lex.c
diff -u src/bin/ksh/lex.c:1.16 src/bin/ksh/lex.c:1.17
--- src/bin/ksh/lex.c:1.16 Thu Jun 22 13:33:39 2017
+++ src/bin/ksh/lex.c Thu Jun 22 14:11:27 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: lex.c,v 1.16 2017/06/22 13:33:39 kamil Exp $ */
+/* $NetBSD: lex.c,v 1.17 2017/06/22 14:11:27 kamil Exp $ */
/*
* lexical analysis and source input
@@ -6,7 +6,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: lex.c,v 1.16 2017/06/22 13:33:39 kamil Exp $");
+__RCSID("$NetBSD: lex.c,v 1.17 2017/06/22 14:11:27 kamil Exp $");
#endif
@@ -220,6 +220,12 @@ yylex(cf)
switch (c) {
case '\\':
c = getsc();
+#ifdef OS2
+ if (isalnum((unsigned char)c)) {
+ *wp++ = CHAR, *wp++ = '\\';
+ *wp++ = CHAR, *wp++ = c;
+ } else
+#endif
if (c) /* trailing \ is lost */
*wp++ = QCHAR, *wp++ = c;
break;
Index: src/bin/ksh/main.c
diff -u src/bin/ksh/main.c:1.16 src/bin/ksh/main.c:1.17
--- src/bin/ksh/main.c:1.16 Thu Jun 22 13:33:39 2017
+++ src/bin/ksh/main.c Thu Jun 22 14:11:27 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: main.c,v 1.16 2017/06/22 13:33:39 kamil Exp $ */
+/* $NetBSD: main.c,v 1.17 2017/06/22 14:11:27 kamil Exp $ */
/*
* startup, main loop, environments and error handling
@@ -7,7 +7,7 @@
#include <locale.h>
#ifndef lint
-__RCSID("$NetBSD: main.c,v 1.16 2017/06/22 13:33:39 kamil Exp $");
+__RCSID("$NetBSD: main.c,v 1.17 2017/06/22 14:11:27 kamil Exp $");
#endif
@@ -106,6 +106,11 @@ main(int argc, char *argv[])
/* chmem_push("+c", 1); */
#endif /* MEM_DEBUG */
+#ifdef OS2
+ setmode (0, O_BINARY);
+ setmode (1, O_TEXT);
+#endif
+
/* make sure argv[] is sane */
if (!*argv) {
static const char *empty_argv[] = {
@@ -298,7 +303,18 @@ main(int argc, char *argv[])
kshname = argv[argi++];
} else if (argi < argc && !Flag(FSTDIN)) {
s = pushs(SFILE, ATEMP);
+#ifdef OS2
+ /* a bug in os2 extproc shell processing doesn't
+ * pass full pathnames so we have to search for it.
+ * This changes the behavior of 'ksh arg' to search
+ * the users search path but it can't be helped.
+ */
+ s->file = search(argv[argi++], path, R_OK, (int *) 0);
+ if (!s->file || !*s->file)
+ s->file = argv[argi - 1];
+#else
s->file = argv[argi++];
+#endif /* OS2 */
s->u.shf = shf_open(s->file, O_RDONLY, 0, SHF_MAPHI|SHF_CLEXEC);
if (s->u.shf == NULL) {
exstat = 127; /* POSIX */
@@ -358,10 +374,27 @@ main(int argc, char *argv[])
warningf(FALSE, "Cannot determine current working directory");
if (Flag(FLOGIN)) {
+#ifdef OS2
+ char *profile;
+
+ /* Try to find a profile - first see if $INIT has a value,
+ * then try /etc/profile.ksh, then c:/usr/etc/profile.ksh.
+ */
+ if (!Flag(FPRIVILEGED)
+ && strcmp(profile = substitute("$INIT/profile.ksh", 0),
+ "/profile.ksh"))
+ include(profile, 0, (char **) 0, 1);
+ else if (include("/etc/profile.ksh", 0, (char **) 0, 1) < 0)
+ include("c:/usr/etc/profile.ksh", 0, (char **) 0, 1);
+ if (!Flag(FPRIVILEGED))
+ include(substitute("$HOME/profile.ksh", 0), 0,
+ (char **) 0, 1);
+#else /* OS2 */
include(KSH_SYSTEM_PROFILE, 0, (char **) 0, 1);
if (!Flag(FPRIVILEGED))
include(substitute("$HOME/.profile", 0), 0,
(char **) 0, 1);
+#endif /* OS2 */
}
if (Flag(FPRIVILEGED))
@@ -385,9 +418,11 @@ main(int argc, char *argv[])
env_file = substitute(env_file, DOTILDE);
if (*env_file != '\0')
include(env_file, 0, (char **) 0, 1);
+#ifdef OS2
else if (Flag(FTALKING))
include(substitute("$HOME/kshrc.ksh", 0), 0,
(char **) 0, 1);
+#endif /* OS2 */
}
if (is_restricted(argv[0]) || is_restricted(str_val(global("SHELL"))))
@@ -769,9 +804,44 @@ static void
remove_temps(tp)
struct temp *tp;
{
+#ifdef OS2
+ static struct temp *delayed_remove;
+ struct temp *t, **tprev;
+
+ if (delayed_remove) {
+ for (tprev = &delayed_remove, t = delayed_remove; t; t = *tprev)
+ /* No need to check t->pid here... */
+ if (unlink(t->name) >= 0 || errno == ENOENT) {
+ *tprev = t->next;
+ afree(t, APERM);
+ } else
+ tprev = &t->next;
+ }
+#endif /* OS2 */
+
for (; tp != NULL; tp = tp->next)
if (tp->pid == procpid) {
+#ifdef OS2
+ /* OS/2 (and dos) do not allow files that are currently
+ * open to be removed, so we cache it away for future
+ * removal.
+ * XXX should only do this if errno
+ * is Efile-still-open-can't-remove
+ * (but I don't know what that is...)
+ */
+ if (unlink(tp->name) < 0 && errno != ENOENT) {
+ t = (struct temp *) alloc(
+ sizeof(struct temp) + strlen(tp->name) + 1,
+ APERM);
+ memset(t, 0, sizeof(struct temp));
+ t->name = (char *) &t[1];
+ strlcpy(t->name, tp->name, strlen(tp->name) + 1);
+ t->next = delayed_remove;
+ delayed_remove = t;
+ }
+#else /* OS2 */
unlink(tp->name);
+#endif /* OS2 */
}
}
Index: src/bin/ksh/io.c
diff -u src/bin/ksh/io.c:1.10 src/bin/ksh/io.c:1.11
--- src/bin/ksh/io.c:1.10 Thu Jun 22 13:33:39 2017
+++ src/bin/ksh/io.c Thu Jun 22 14:11:27 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: io.c,v 1.10 2017/06/22 13:33:39 kamil Exp $ */
+/* $NetBSD: io.c,v 1.11 2017/06/22 14:11:27 kamil Exp $ */
/*
* shell buffered IO and formatted output
@@ -6,7 +6,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: io.c,v 1.10 2017/06/22 13:33:39 kamil Exp $");
+__RCSID("$NetBSD: io.c,v 1.11 2017/06/22 14:11:27 kamil Exp $");
#endif
@@ -370,7 +370,20 @@ check_fd(name, mode, emsgp)
return -1;
}
fl &= O_ACCMODE;
-
+#ifdef OS2
+ if (mode == W_OK ) {
+ if (setmode(fd, O_TEXT) == -1) {
+ if (emsgp)
+ *emsgp = "couldn't set write mode";
+ return -1;
+ }
+ } else if (mode == R_OK)
+ if (setmode(fd, O_BINARY) == -1) {
+ if (emsgp)
+ *emsgp = "couldn't set read mode";
+ return -1;
+ }
+#else /* OS2 */
/* X_OK is a kludge to disable this check for dups (x<&1):
* historical shells never did this check (XXX don't know what
* posix has to say).
@@ -385,6 +398,7 @@ check_fd(name, mode, emsgp)
: "fd not open for writing";
return -1;
}
+#endif /* OS2 */
return fd;
}
#ifdef KSH
Index: src/bin/ksh/path.c
diff -u src/bin/ksh/path.c:1.10 src/bin/ksh/path.c:1.11
--- src/bin/ksh/path.c:1.10 Thu Jun 22 13:33:39 2017
+++ src/bin/ksh/path.c Thu Jun 22 14:11:27 2017
@@ -1,8 +1,8 @@
-/* $NetBSD: path.c,v 1.10 2017/06/22 13:33:39 kamil Exp $ */
+/* $NetBSD: path.c,v 1.11 2017/06/22 14:11:27 kamil Exp $ */
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: path.c,v 1.10 2017/06/22 13:33:39 kamil Exp $");
+__RCSID("$NetBSD: path.c,v 1.11 2017/06/22 14:11:27 kamil Exp $");
#endif
@@ -130,6 +130,10 @@ simplify_path(pathx)
if ((isrooted = ISROOTEDPATH(pathx)))
very_start++;
+#if defined (OS2) || defined (__CYGWIN__)
+ if (pathx[0] && pathx[1] == ':') /* skip a: */
+ very_start += 2;
+#endif /* OS2 || __CYGWIN__ */
/* Before After
* /foo/ /foo
@@ -139,8 +143,19 @@ simplify_path(pathx)
* .. ..
* ./foo foo
* foo/../../../bar ../../bar
+ * OS2 and CYGWIN:
+ * a:/foo/../.. a:/
+ * a:. a:
+ * a:.. a:..
+ * a:foo/../../blah a:../blah
*/
+#ifdef __CYGWIN__
+ /* preserve leading double-slash on pathnames (for UNC paths) */
+ if (pathx[0] && ISDIRSEP(pathx[0]) && pathx[1] && ISDIRSEP(pathx[1]))
+ very_start++;
+#endif /* __CYGWIN__ */
+
for (cur = t = start = very_start; ; ) {
/* treat multiple '/'s as one '/' */
while (ISDIRSEP(*t))
Index: src/bin/ksh/sh.h
diff -u src/bin/ksh/sh.h:1.10 src/bin/ksh/sh.h:1.11
--- src/bin/ksh/sh.h:1.10 Thu Jun 22 13:37:16 2017
+++ src/bin/ksh/sh.h Thu Jun 22 14:11:27 2017
@@ -1,10 +1,10 @@
-/* $NetBSD: sh.h,v 1.10 2017/06/22 13:37:16 kamil Exp $ */
+/* $NetBSD: sh.h,v 1.11 2017/06/22 14:11:27 kamil Exp $ */
/*
* Public Domain Bourne/Korn shell
*/
-/* $Id: sh.h,v 1.10 2017/06/22 13:37:16 kamil Exp $ */
+/* $Id: sh.h,v 1.11 2017/06/22 14:11:27 kamil Exp $ */
#include "config.h" /* system and option configuration info */
@@ -203,6 +203,9 @@ typedef RETSIGTYPE (*handler_t) ARGS((in
#endif /* !HAVE_KILLPG */
/* Special cases for execve(2) */
+#ifdef OS2
+extern int ksh_execve(char *cmd, char **args, char **env, int flags);
+#else /* OS2 */
# if defined(OS_ISC) && defined(_POSIX_SOURCE)
/* Kludge for ISC 3.2 (and other versions?) so programs will run correctly. */
# define ksh_execve(p, av, ev, flags) \
@@ -214,6 +217,7 @@ typedef RETSIGTYPE (*handler_t) ARGS((in
# else /* OS_ISC && _POSIX */
# define ksh_execve(p, av, ev, flags) execve(p, av, ev)
# endif /* OS_ISC && _POSIX */
+#endif /* OS2 */
/* this is a hang-over from older versions of the os2 port */
#define ksh_dupbase(fd, base) fcntl(fd, F_DUPFD, base)
@@ -269,10 +273,19 @@ extern int dup2 ARGS((int, int));
# define EXTERN_DEFINED
#endif
+#ifdef OS2
+# define inDOS() (!(_emx_env & 0x200))
+#endif
+
#ifndef EXECSHELL
/* shell to exec scripts (see also $SHELL initialization in main.c) */
+# ifdef OS2
+# define EXECSHELL (inDOS() ? "c:\\command.com" : "c:\\os2\\cmd.exe")
+# define EXECSHELL_STR (inDOS() ? "COMSPEC" : "OS2_SHELL")
+# else /* OS2 */
# define EXECSHELL "/bin/sh"
# define EXECSHELL_STR "EXECSHELL"
+# endif /* OS2 */
#endif
/* ISABSPATH() means path is fully and completely specified,
@@ -283,19 +296,48 @@ extern int dup2 ARGS((int, int));
* unix /foo yes yes no
* unix foo no no yes
* unix ../foo no no yes
- */
+ * os2+cyg a:/foo yes yes no
+ * os2+cyg a:foo no no no
+ * os2+cyg /foo no yes no
+ * os2+cyg foo no no yes
+ * os2+cyg ../foo no no yes
+ * cyg //foo yes yes no
+ */
+#ifdef OS2
+# define PATHSEP ';'
+# define DIRSEP '/' /* even though \ is native */
+# define DIRSEPSTR "\\"
+# define ISDIRSEP(c) ((c) == '\\' || (c) == '/')
+# define ISABSPATH(s) (((s)[0] && (s)[1] == ':' && ISDIRSEP((s)[2])))
+# define ISROOTEDPATH(s) (ISDIRSEP((s)[0]) || ISABSPATH(s))
+# define ISRELPATH(s) (!(s)[0] || ((s)[1] != ':' && !ISDIRSEP((s)[0])))
+# define FILECHCONV(c) (isascii(c) && isupper(c) ? tolower(c) : c)
+# define FILECMP(s1, s2) stricmp(s1, s2)
+# define FILENCMP(s1, s2, n) strnicmp(s1, s2, n)
+extern char *ksh_strchr_dirsep(const char *path);
+extern char *ksh_strrchr_dirsep(const char *path);
+# define chdir _chdir2
+# define getcwd _getcwd2
+#else
# define PATHSEP ':'
# define DIRSEP '/'
# define DIRSEPSTR "/"
# define ISDIRSEP(c) ((c) == '/')
+#ifdef __CYGWIN__
+# define ISABSPATH(s) \
+ (((s)[0] && (s)[1] == ':' && ISDIRSEP((s)[2])) || ISDIRSEP((s)[0]))
+# define ISRELPATH(s) (!(s)[0] || ((s)[1] != ':' && !ISDIRSEP((s)[0])))
+#else /* __CYGWIN__ */
# define ISABSPATH(s) ISDIRSEP((s)[0])
# define ISRELPATH(s) (!ISABSPATH(s))
+#endif /* __CYGWIN__ */
# define ISROOTEDPATH(s) ISABSPATH(s)
# define FILECHCONV(c) c
# define FILECMP(s1, s2) strcmp(s1, s2)
# define FILENCMP(s1, s2, n) strncmp(s1, s2, n)
# define ksh_strchr_dirsep(p) strchr(p, DIRSEP)
# define ksh_strrchr_dirsep(p) strrchr(p, DIRSEP)
+#endif
typedef int bool_t;
#define FALSE 0
@@ -545,7 +587,10 @@ typedef struct trap {
EXTERN int volatile trap; /* traps pending? */
EXTERN int volatile intrsig; /* pending trap interrupts executing command */
EXTERN int volatile fatal_trap;/* received a fatal signal */
+#ifndef FROM_TRAP_C
+/* Kludge to avoid bogus re-declaration of sigtraps[] error on AIX 3.2.5 */
extern Trap sigtraps[SIGNALS+1];
+#endif /* !FROM_TRAP_C */
#ifdef KSH
/*
Index: src/bin/ksh/jobs.c
diff -u src/bin/ksh/jobs.c:1.11 src/bin/ksh/jobs.c:1.12
--- src/bin/ksh/jobs.c:1.11 Thu Jun 22 13:33:39 2017
+++ src/bin/ksh/jobs.c Thu Jun 22 14:11:27 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: jobs.c,v 1.11 2017/06/22 13:33:39 kamil Exp $ */
+/* $NetBSD: jobs.c,v 1.12 2017/06/22 14:11:27 kamil Exp $ */
/*
* Process and job control
@@ -26,7 +26,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: jobs.c,v 1.11 2017/06/22 13:33:39 kamil Exp $");
+__RCSID("$NetBSD: jobs.c,v 1.12 2017/06/22 14:11:27 kamil Exp $");
#endif
@@ -648,6 +648,10 @@ exchild(t, flags, close_fd)
Flag(FMONITOR) = 0;
#endif /* JOBS */
Flag(FTALKING) = 0;
+#ifdef OS2
+ if (tty_fd >= 0)
+ flags |= XINTACT;
+#endif /* OS2 */
tty_close();
cleartraps();
execute(t, (flags & XERROK) | XEXEC); /* no return */
Index: src/bin/ksh/misc.c
diff -u src/bin/ksh/misc.c:1.19 src/bin/ksh/misc.c:1.20
--- src/bin/ksh/misc.c:1.19 Thu Jun 22 13:35:47 2017
+++ src/bin/ksh/misc.c Thu Jun 22 14:11:27 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: misc.c,v 1.19 2017/06/22 13:35:47 kamil Exp $ */
+/* $NetBSD: misc.c,v 1.20 2017/06/22 14:11:27 kamil Exp $ */
/*
* Miscellaneous functions
@@ -6,7 +6,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: misc.c,v 1.19 2017/06/22 13:35:47 kamil Exp $");
+__RCSID("$NetBSD: misc.c,v 1.20 2017/06/22 14:11:27 kamil Exp $");
#endif
@@ -323,10 +323,14 @@ change_flag(f, what, newval)
#endif /* EDIT */
/* Turning off -p? */
if (f == FPRIVILEGED && oldval && !newval) {
+#ifdef OS2
+ ;
+#else /* OS2 */
seteuid(ksheuid = getuid());
setuid(ksheuid);
setegid(getgid());
setgid(getgid());
+#endif /* OS2 */
} else if (f == FPOSIX && newval) {
#ifdef BRACE_EXPAND
Flag(FBRACEEXPAND) = 0
@@ -1284,6 +1288,25 @@ reset_nonblock(fd)
# define MAXPATHLEN PATH
#endif /* MAXPATHLEN */
+#ifdef HPUX_GETWD_BUG
+# include "ksh_dir.h"
+
+/*
+ * Work around bug in hpux 10.x C library - getwd/getcwd dump core
+ * if current directory is not readable. Done in macro 'cause code
+ * is needed in GETWD and GETCWD cases.
+ */
+# define HPUX_GETWD_BUG_CODE \
+ { \
+ DIR *d = ksh_opendir("."); \
+ if (!d) \
+ return (char *) 0; \
+ closedir(d); \
+ }
+#else /* HPUX_GETWD_BUG */
+# define HPUX_GETWD_BUG_CODE
+#endif /* HPUX_GETWD_BUG */
+
/* Like getcwd(), except bsize is ignored if buf is 0 (MAXPATHLEN is used) */
char *
ksh_get_wd(buf, bsize)
@@ -1294,6 +1317,9 @@ ksh_get_wd(buf, bsize)
char *b;
char *ret;
+ /* Before memory allocated */
+ HPUX_GETWD_BUG_CODE
+
/* Assume getcwd() available */
if (!buf) {
bsize = MAXPATHLEN;
@@ -1316,6 +1342,9 @@ ksh_get_wd(buf, bsize)
char *b;
int len;
+ /* Before memory allocated */
+ HPUX_GETWD_BUG_CODE
+
if (buf && bsize > MAXPATHLEN)
b = buf;
else
Index: src/bin/ksh/shf.c
diff -u src/bin/ksh/shf.c:1.8 src/bin/ksh/shf.c:1.9
--- src/bin/ksh/shf.c:1.8 Thu Jun 22 13:33:39 2017
+++ src/bin/ksh/shf.c Thu Jun 22 14:11:27 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: shf.c,v 1.8 2017/06/22 13:33:39 kamil Exp $ */
+/* $NetBSD: shf.c,v 1.9 2017/06/22 14:11:27 kamil Exp $ */
/*
* Shell file I/O routines
@@ -6,7 +6,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: shf.c,v 1.8 2017/06/22 13:33:39 kamil Exp $");
+__RCSID("$NetBSD: shf.c,v 1.9 2017/06/22 14:11:27 kamil Exp $");
#endif
@@ -577,6 +577,13 @@ shf_getse(buf, bsize, shf)
shf->rnleft -= ncopy;
buf += ncopy;
bsize -= ncopy;
+#ifdef OS2
+ if (end && buf > orig_buf + 1 && buf[-2] == '\r') {
+ buf--;
+ bsize++;
+ buf[-1] = '\n';
+ }
+#endif
} while (!end && bsize);
*buf = '\0';
Index: src/bin/ksh/trap.c
diff -u src/bin/ksh/trap.c:1.9 src/bin/ksh/trap.c:1.10
--- src/bin/ksh/trap.c:1.9 Thu Jun 22 13:37:16 2017
+++ src/bin/ksh/trap.c Thu Jun 22 14:11:27 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: trap.c,v 1.9 2017/06/22 13:37:16 kamil Exp $ */
+/* $NetBSD: trap.c,v 1.10 2017/06/22 14:11:27 kamil Exp $ */
/*
* signal handling
@@ -6,9 +6,12 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: trap.c,v 1.9 2017/06/22 13:37:16 kamil Exp $");
+__RCSID("$NetBSD: trap.c,v 1.10 2017/06/22 14:11:27 kamil Exp $");
#endif
+
+/* Kludge to avoid bogus re-declaration of sigtraps[] error on AIX 3.2.5 */
+#define FROM_TRAP_C
#include "sh.h"
/* Table is indexed by signal number
Index: src/bin/ksh/tree.h
diff -u src/bin/ksh/tree.h:1.5 src/bin/ksh/tree.h:1.6
--- src/bin/ksh/tree.h:1.5 Thu Jun 22 13:33:39 2017
+++ src/bin/ksh/tree.h Thu Jun 22 14:11:27 2017
@@ -1,10 +1,10 @@
-/* $NetBSD: tree.h,v 1.5 2017/06/22 13:33:39 kamil Exp $ */
+/* $NetBSD: tree.h,v 1.6 2017/06/22 14:11:27 kamil Exp $ */
/*
* command trees for compile/execute
*/
-/* $Id: tree.h,v 1.5 2017/06/22 13:33:39 kamil Exp $ */
+/* $Id: tree.h,v 1.6 2017/06/22 14:11:27 kamil Exp $ */
#define NOBLOCK ((struct op *)NULL)
#define NOWORD ((char *)NULL)
@@ -110,6 +110,7 @@ struct ioword {
#define XERROK BIT(8) /* non-zero exit ok (for set -e) */
#define XCOPROC BIT(9) /* starting a co-process */
#define XTIME BIT(10) /* timing TCOM command */
+#define XINTACT BIT(11) /* OS2: proc started from interactive session */
/*
* flags to control expansion of words (assumed by t->evalflags to fit
Index: src/bin/ksh/vi.c
diff -u src/bin/ksh/vi.c:1.14 src/bin/ksh/vi.c:1.15
--- src/bin/ksh/vi.c:1.14 Thu Jun 22 13:33:39 2017
+++ src/bin/ksh/vi.c Thu Jun 22 14:11:27 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: vi.c,v 1.14 2017/06/22 13:33:39 kamil Exp $ */
+/* $NetBSD: vi.c,v 1.15 2017/06/22 14:11:27 kamil Exp $ */
/*
* vi command editing
@@ -9,7 +9,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: vi.c,v 1.14 2017/06/22 13:33:39 kamil Exp $");
+__RCSID("$NetBSD: vi.c,v 1.15 2017/06/22 14:11:27 kamil Exp $");
#endif
#include "config.h"
@@ -274,8 +274,32 @@ vi_hook(ch)
}
switch (vi_insert(ch)) {
case -1:
+#ifdef OS2
+ /* Arrow keys generate 0xe0X, where X is H.. */
+ state = VCMD;
+ argc1 = 1;
+ switch (x_getc()) {
+ case 'H':
+ *curcmd='k';
+ break;
+ case 'K':
+ *curcmd='h';
+ break;
+ case 'P':
+ *curcmd='j';
+ break;
+ case 'M':
+ *curcmd='l';
+ break;
+ default:
+ vi_error();
+ state = VNORMAL;
+ }
+ break;
+#else /* OS2 */
vi_error();
state = VNORMAL;
+#endif /* OS2 */
break;
case 0:
if (state == VLIT) {
@@ -633,6 +657,9 @@ vi_insert(ch)
saved_inslen = 0;
switch (ch) {
+#ifdef OS2
+ case 224: /* function key prefix */
+#endif /* OS2 */
case '\0':
return -1;