system/ksh-openbsd: Renamed from "ksh" and updated to 20110909

Signed-off-by: Robby Workman <rworkman@slackbuilds.org>
This commit is contained in:
Daniel LEVAI 2011-10-08 20:29:28 -05:00 committed by Robby Workman
parent 0b9d751630
commit 7fc7de8808
37 changed files with 2037 additions and 82 deletions

View File

@ -27,9 +27,9 @@
# Build script for the Linux port of OpenBSD's ksh
PRGNAM=ksh
VERSION=openbsd49
BUILD=${BUILD:-3}
PRGNAM=ksh-openbsd
VERSION=20110911
BUILD=${BUILD:-1}
TAG=${TAG:-_SBo}
if [ -z "$ARCH" ]; then
@ -64,9 +64,9 @@ set -e
rm -Rf $PKG
mkdir -p $TMP $PKG $OUTPUT
cd $TMP
rm -Rf $PRGNAM-$VERSION
tar xvf $CWD/$PRGNAM-$VERSION.tar.gz
cd $PRGNAM-$VERSION
rm -Rf $PRGNAM
tar xvf $CWD/$PRGNAM.tar.gz
cd $PRGNAM
chown -R root:root .
find . \
\( -perm 777 -o -perm 775 -o -perm 711 -o -perm 555 -o -perm 511 \) \
@ -78,7 +78,7 @@ for patch in "${CWD}"/patches/linux/*.diff;do
patch -p1 < "${patch}"
done
for patch in "${CWD}"/patches/*.diff;do
patch -p1 < "${patch}"
patch -p0 < "${patch}"
done
CFLAGS="$SLKCFLAGS $(getconf LFS_CFLAGS)" make
@ -91,6 +91,7 @@ mkdir -p $PKG/usr/doc/$PRGNAM-$VERSION
cp -a \
INSTALL LEGAL NOTES PROJECTS README \
$PKG/usr/doc/$PRGNAM-$VERSION
cat $CWD/$PRGNAM.SlackBuild > $PKG/usr/doc/$PRGNAM-$VERSION/$PRGNAM.SlackBuild
mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc

View File

@ -0,0 +1,10 @@
PRGNAM="ksh-openbsd"
VERSION="20110909"
HOMEPAGE="http://leva.ecentrum.hu/slackbuilds/ksh-openbsd.tar.gz"
DOWNLOAD="http://leva.ecentrum.hu/slackbuilds/ksh-openbsd.tar.gz"
MD5SUM="636c07775c9d8cd049f670fc916501e7"
DOWNLOAD_x86_64=""
MD5SUM_x86_64=""
MAINTAINER="Daniel LEVAI"
EMAIL="leva@ecentrum.hu"
APPROVED="rworkman"

View File

@ -15,10 +15,10 @@ Subject: [PATCH 1/8] ksh/vi mode: complete as command on Ctrl-f.
vi.c | 22 +++++++++++-----------
3 files changed, 17 insertions(+), 14 deletions(-)
diff --git a/edit.c b/edit.c
diff --git edit.c edit.c
index 6c357a7..0b1ff7d 100644
--- a/edit.c
+++ b/edit.c
--- edit.c
+++ edit.c
@@ -599,6 +599,8 @@ x_cf_glob(int flags, const char *buf, int buflen, int pos, int *startp,
len = x_locate_word(buf, buflen, pos, startp, &is_command);
if (!(flags & XCF_COMMAND))
@ -28,10 +28,10 @@ index 6c357a7..0b1ff7d 100644
/* Don't do command globing on zero length strings - it takes too
* long and isn't very useful. File globs are more likely to be
* useful, so allow these.
diff --git a/edit.h b/edit.h
diff --git edit.h edit.h
index f966fe4..9c75ffc 100644
--- a/edit.h
+++ b/edit.h
--- edit.h
+++ edit.h
@@ -38,9 +38,10 @@ typedef struct {
EXTERN X_chars edchars;
@ -46,10 +46,10 @@ index f966fe4..9c75ffc 100644
#define XCF_COMMAND_FILE (XCF_COMMAND|XCF_FILE)
/* edit.c */
diff --git a/vi.c b/vi.c
diff --git vi.c vi.c
index 889b35a..e4173c7 100644
--- a/vi.c
+++ b/vi.c
--- vi.c
+++ vi.c
@@ -58,7 +58,7 @@ static int newcol(int, int);
static void display(char *, char *, int);
static void ed_mov_opt(int, char *);

View File

@ -0,0 +1,217 @@
Remove disabled FP support.
From Okan Demirmen.
Index: ksh_limval.h
===================================================================
RCS file: /home/okan/hack/open/cvs/src/bin/ksh/ksh_limval.h,v
retrieving revision 1.2
diff -u -p -r1.2 ksh_limval.h
--- ksh_limval.h 18 Dec 2004 20:55:52 -0000 1.2
+++ ksh_limval.h 14 Mar 2011 10:03:41 -0000
@@ -4,10 +4,6 @@
/* limits.h is included in sh.h */
-#ifndef DMAXEXP
-# define DMAXEXP 128 /* should be big enough */
-#endif
-
#ifndef BITS
# define BITS(t) (CHAR_BIT * sizeof(t))
#endif
Index: shf.c
===================================================================
RCS file: /home/okan/hack/open/cvs/src/bin/ksh/shf.c,v
retrieving revision 1.15
diff -u -p -r1.15 shf.c
--- shf.c 2 Apr 2006 00:48:33 -0000 1.15
+++ shf.c 14 Mar 2011 10:03:19 -0000
@@ -705,15 +705,7 @@ shf_smprintf(const char *fmt, ...)
return shf_sclose(&shf); /* null terminates */
}
-#undef FP /* if you want floating point stuff */
-
#define BUF_SIZE 128
-#define FPBUF_SIZE (DMAXEXP+16)/* this must be >
- * MAX(DMAXEXP, log10(pow(2, DSIGNIF)))
- * + ceil(log10(DMAXEXP)) + 8 (I think).
- * Since this is hard to express as a
- * constant, just use a large buffer.
- */
/*
* What kinda of machine we on? Hopefully the C compiler will optimize
@@ -744,18 +736,6 @@ shf_smprintf(const char *fmt, ...)
#define FL_NUMBER 0x200 /* a number was formated %[douxefg] */
-#ifdef FP
-#include <math.h>
-
-static double
-my_ceil(double d)
-{
- double i;
-
- return d - modf(d, &i) + (d < 0 ? -1 : 1);
-}
-#endif /* FP */
-
int
shf_vfprintf(struct shf *shf, const char *fmt, va_list args)
{
@@ -769,17 +749,6 @@ shf_vfprintf(struct shf *shf, const char
char numbuf[(BITS(long) + 2) / 3 + 1];
/* this stuff for dealing with the buffer */
int nwritten = 0;
-#ifdef FP
- /* should be in <math.h>
- * extern double frexp();
- */
- extern char *ecvt();
-
- double fpnum;
- int expo, decpt;
- char style;
- char fpbuf[FPBUF_SIZE];
-#endif /* FP */
if (!fmt)
return 0;
@@ -946,134 +915,6 @@ shf_vfprintf(struct shf *shf, const char
precision = len; /* no loss */
}
break;
-
-#ifdef FP
- case 'e':
- case 'g':
- case 'f':
- {
- char *p;
-
- /*
- * This could probably be done better,
- * but it seems to work. Note that gcvt()
- * is not used, as you cannot tell it to
- * not strip the zeros.
- */
- flags |= FL_NUMBER;
- if (!(flags & FL_DOT))
- precision = 6; /* default */
- /*
- * Assumes doubles are pushed on
- * the stack. If this is not so, then
- * FL_LONG/FL_SHORT should be checked.
- */
- fpnum = va_arg(args, double);
- s = fpbuf;
- style = c;
- /*
- * This is the same as
- * expo = ceil(log10(fpnum))
- * but doesn't need -lm. This is an
- * approximation as expo is rounded up.
- */
- (void) frexp(fpnum, &expo);
- expo = my_ceil(expo / LOG2_10);
-
- if (expo < 0)
- expo = 0;
-
- p = ecvt(fpnum, precision + 1 + expo,
- &decpt, &tmp);
- if (c == 'g') {
- if (decpt < -4 || decpt > precision)
- style = 'e';
- else
- style = 'f';
- if (decpt > 0 && (precision -= decpt) < 0)
- precision = 0;
- }
- if (tmp)
- *s++ = '-';
- else if (flags & FL_PLUS)
- *s++ = '+';
- else if (flags & FL_BLANK)
- *s++ = ' ';
-
- if (style == 'e')
- *s++ = *p++;
- else {
- if (decpt > 0) {
- /* Overflow check - should
- * never have this problem.
- */
- if (decpt > &fpbuf[sizeof(fpbuf)] - s - 8)
- decpt = &fpbuf[sizeof(fpbuf)] - s - 8;
- (void) memcpy(s, p, decpt);
- s += decpt;
- p += decpt;
- } else
- *s++ = '0';
- }
-
- /* print the fraction? */
- if (precision > 0) {
- *s++ = '.';
- /* Overflow check - should
- * never have this problem.
- */
- if (precision > &fpbuf[sizeof(fpbuf)] - s - 7)
- precision = &fpbuf[sizeof(fpbuf)] - s - 7;
- for (tmp = decpt; tmp++ < 0 &&
- precision > 0 ; precision--)
- *s++ = '0';
- tmp = strlen(p);
- if (precision > tmp)
- precision = tmp;
- /* Overflow check - should
- * never have this problem.
- */
- if (precision > &fpbuf[sizeof(fpbuf)] - s - 7)
- precision = &fpbuf[sizeof(fpbuf)] - s - 7;
- (void) memcpy(s, p, precision);
- s += precision;
- /*
- * `g' format strips trailing
- * zeros after the decimal.
- */
- if (c == 'g' && !(flags & FL_HASH)) {
- while (*--s == '0')
- ;
- if (*s != '.')
- s++;
- }
- } else if (flags & FL_HASH)
- *s++ = '.';
-
- if (style == 'e') {
- *s++ = (flags & FL_UPPER) ? 'E' : 'e';
- if (--decpt >= 0)
- *s++ = '+';
- else {
- *s++ = '-';
- decpt = -decpt;
- }
- p = &numbuf[sizeof(numbuf)];
- for (tmp = 0; tmp < 2 || decpt ; tmp++) {
- *--p = '0' + decpt % 10;
- decpt /= 10;
- }
- tmp = &numbuf[sizeof(numbuf)] - p;
- (void) memcpy(s, p, tmp);
- s += tmp;
- }
-
- len = s - fpbuf;
- s = fpbuf;
- precision = len;
- break;
- }
-#endif /* FP */
case 's':
if (!(s = va_arg(args, char *)))

View File

@ -9,10 +9,10 @@ Subject: [PATCH 3/8] ksh/vi: Ctrl-l in insert mode to clear the screen.
vi.c | 6 ++++++
2 files changed, 9 insertions(+), 0 deletions(-)
diff --git a/ksh.1 b/ksh.1
diff --git ksh.1 ksh.1
index f4b5815..01130ea 100644
--- a/ksh.1
+++ b/ksh.1
--- ksh.1
+++ ksh.1
@@ -5215,6 +5215,9 @@ List all the commands or files that match the current big-word.
Macro expansion.
Execute the commands found in the alias
@ -23,10 +23,10 @@ index f4b5815..01130ea 100644
.El
.Pp
Intra-line movement commands:
diff --git a/vi.c b/vi.c
diff --git vi.c vi.c
index e4173c7..d0de478 100644
--- a/vi.c
+++ b/vi.c
--- vi.c
+++ vi.c
@@ -646,6 +646,12 @@ vi_insert(int ch)
return redo_insert(lastac - 1);

View File

@ -8,10 +8,10 @@ Subject: [PATCH 4/8] ksh/vi: make Ctrl-f in command mode behave the same as
vi.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/vi.c b/vi.c
diff --git vi.c vi.c
index d0de478..6eb5d8c 100644
--- a/vi.c
+++ b/vi.c
--- vi.c
+++ vi.c
@@ -1132,7 +1132,7 @@ vi_cmd(int argcnt, const char *cmd)
return -1;
case '\\': /* at&t ksh */

View File

@ -18,10 +18,10 @@ Subject: [PATCH 5/8] ksh: print expansions like a "menu" (with numbers) in vi
vi.c | 4 ++--
4 files changed, 10 insertions(+), 7 deletions(-)
diff --git a/edit.c b/edit.c
diff --git edit.c edit.c
index 0b1ff7d..9cdcc6d 100644
--- a/edit.c
+++ b/edit.c
--- edit.c
+++ edit.c
@@ -292,7 +292,7 @@ static void glob_path(int flags, const char *pat, XPtrV *wp,
const char *path);
@ -43,10 +43,10 @@ index 0b1ff7d..9cdcc6d 100644
if (use_copy)
XPfree(l); /* not x_free_words() */
diff --git a/edit.h b/edit.h
diff --git edit.h edit.h
index 37ccf28..258affe 100644
--- a/edit.h
+++ b/edit.h
--- edit.h
+++ edit.h
@@ -52,7 +52,7 @@ void x_puts(const char *);
bool x_mode(bool);
int promptlen(const char *, const char **);
@ -56,10 +56,10 @@ index 37ccf28..258affe 100644
int x_cf_glob(int, const char *, int, int, int *, int *, char ***, int *);
int x_longest_prefix(int , char *const *);
int x_basename(const char *, const char *);
diff --git a/emacs.c b/emacs.c
diff --git emacs.c emacs.c
index 0bfda96..3b2d083 100644
--- a/emacs.c
+++ b/emacs.c
--- emacs.c
+++ emacs.c
@@ -1684,7 +1684,7 @@ do_complete(int flags, /* XCF_{COMMAND,FILE,COMMAND_FILE} */
}
@ -78,10 +78,10 @@ index 0bfda96..3b2d083 100644
completed = 1;
}
diff --git a/vi.c b/vi.c
diff --git vi.c vi.c
index 6eb5d8c..95d192c 100644
--- a/vi.c
+++ b/vi.c
--- vi.c
+++ vi.c
@@ -1990,7 +1990,7 @@ complete_word(int command, int count, int flags)
count--;
if (count >= nwords) {

View File

@ -8,6 +8,9 @@ Subject: [PATCH 6/8] ksh: remove backslashes in filenames using lex.
be the filename of an existing file, right? i think
so.
* change stat() to lstat() to complete broken links
(from LEVAI Daniel).
Why:
* less ugly code
@ -19,10 +22,10 @@ Subject: [PATCH 6/8] ksh: remove backslashes in filenames using lex.
lex.h | 1 +
3 files changed, 12 insertions(+), 24 deletions(-)
diff --git a/edit.c b/edit.c
diff --git edit.c edit.c
index 9cdcc6d..01c2fe6 100644
--- a/edit.c
+++ b/edit.c
--- edit.c
+++ edit.c
@@ -351,7 +351,7 @@ x_file_glob(int flags, const char *str, int slen, char ***wordsp)
{
char *toglob;
@ -79,14 +82,14 @@ index 9cdcc6d..01c2fe6 100644
*/
- if ((strcmp(words[0], toglob) == 0 &&
- stat(words[0], &statb) < 0) ||
+ if((stat(words[0], &statb) < 0) ||
+ if((lstat(words[0], &statb) < 0) ||
words[0][0] == '\0') {
x_free_words(nwords, words);
words = NULL;
diff --git a/lex.c b/lex.c
diff --git lex.c lex.c
index ef741c6..fe3d91d 100644
--- a/lex.c
+++ b/lex.c
--- lex.c
+++ lex.c
@@ -299,6 +299,10 @@ yylex(int cf)
}
/* FALLTHROUGH */
@ -98,10 +101,10 @@ index ef741c6..fe3d91d 100644
Xcheck(ws, wp);
if (c) { /* trailing \ is lost */
*wp++ = CHAR, *wp++ = '\\';
diff --git a/lex.h b/lex.h
diff --git lex.h lex.h
index 0904fbd..6a0dbf9 100644
--- a/lex.h
+++ b/lex.h
--- lex.h
+++ lex.h
@@ -113,6 +113,7 @@ typedef union {
#define CMDWORD BIT(8) /* parsing simple command (alias related) */
#define HEREDELIM BIT(9) /* parsing <<,<<- delimiter */

View File

@ -13,10 +13,10 @@ Subject: [PATCH 7/8] ksh/vi: compensate for cursor move on command mode
vi.c | 15 ++++++++++++++-
1 files changed, 14 insertions(+), 1 deletions(-)
diff --git a/vi.c b/vi.c
diff --git vi.c vi.c
index 95d192c..0bac6be 100644
--- a/vi.c
+++ b/vi.c
--- vi.c
+++ vi.c
@@ -1956,6 +1956,7 @@ complete_word(int command, int count, int flags)
int match_len;
int is_unique;

View File

@ -9,10 +9,10 @@ This allows things like $HOME/bi<tab> complete to /home/username/bin.
edit.c | 8 ++++----
1 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/edit.c b/edit.c
diff --git edit.c edit.c
index 01c2fe6..2702dab 100644
--- a/edit.c
+++ b/edit.c
--- edit.c
+++ edit.c
@@ -627,14 +627,14 @@ add_glob(const char *str, int slen)
/*

View File

@ -0,0 +1,584 @@
From: Marco Peereboom
To: tech@openbsd.org
Subject: ksh history corruption
I have had enough of corrupt ksh history so I had a look at the code to
try to fix it. The magical code was very magical so I basically deleted
most of it and made ksh history into a flat text file. It handles
multiple ksh instances writing to the same text file with locks just
like the current ksh does. I haven't noticed any differences in
behavior running this.
Code is much simpler and it shaves ~4k of the binary too.
Index: alloc.c
===================================================================
RCS file: /cvs/src/bin/ksh/alloc.c,v
retrieving revision 1.8
diff -u -p -r1.8 alloc.c
--- alloc.c 21 Jul 2008 17:30:08 -0000 1.8
+++ alloc.c 30 Aug 2011 18:05:47 -0000
@@ -62,7 +62,7 @@ alloc(size_t size, Area *ap)
{
struct link *l;
- l = malloc(sizeof(struct link) + size);
+ l = calloc(1, sizeof(struct link) + size);
if (l == NULL)
internal_errorf(1, "unable to allocate memory");
l->next = ap->freelist;
Index: history.c
===================================================================
RCS file: /cvs/src/bin/ksh/history.c,v
retrieving revision 1.39
diff -u -p -r1.39 history.c
--- history.c 19 May 2010 17:36:08 -0000 1.39
+++ history.c 31 Aug 2011 19:33:24 -0000
@@ -11,8 +11,7 @@
* a) the original in-memory history mechanism
* b) a more complicated mechanism done by pc@hillside.co.uk
* that more closely follows the real ksh way of doing
- * things. You need to have the mmap system call for this
- * to work on your system
+ * things.
*/
#include "sh.h"
@@ -22,19 +21,10 @@
# include <sys/file.h>
# include <sys/mman.h>
-/*
- * variables for handling the data file
- */
-static int histfd;
-static int hsize;
-
-static int hist_count_lines(unsigned char *, int);
-static int hist_shrink(unsigned char *, int);
-static unsigned char *hist_skip_back(unsigned char *,int *,int);
-static void histload(Source *, unsigned char *, int);
-static void histinsert(Source *, int, unsigned char *);
-static void writehistfile(int, char *);
-static int sprinkle(int);
+static void writehistfile(FILE *);
+static FILE *history_open(int *);
+static int history_load(FILE *, Source *);
+static void history_close(FILE *);
static int hist_execute(char *);
static int hist_replace(char **, const char *, const char *, int);
@@ -45,8 +35,8 @@ static void histbackup(void);
static char **current; /* current position in history[] */
static char *hname; /* current name of history file */
static int hstarted; /* set after hist_init() called */
-static Source *hist_source;
-
+static Source *hist_source;
+static struct stat last_sb;
int
c_fc(char **wp)
@@ -529,15 +519,10 @@ sethistfile(const char *name)
/* if the name is the same as the name we have */
if (hname && strcmp(hname, name) == 0)
return;
-
/*
* its a new name - possibly
*/
- if (histfd) {
- /* yes the file is open */
- (void) close(histfd);
- histfd = 0;
- hsize = 0;
+ if (hname) {
afree(hname, APERM);
hname = NULL;
/* let's reset the history */
@@ -577,18 +562,26 @@ init_histvec(void)
void
histsave(int lno, const char *cmd, int dowrite)
{
- char **hp;
- char *c, *cp;
+ char **hp;
+ char *c, *cp;
+ int changed;
+ FILE *f = NULL;
+
+ if (dowrite) {
+ f = history_open(&changed);
+ if (f && changed) {
+ /* reset history */
+ histptr = history - 1;
+ hist_source->line = 0;
+ history_load(f, hist_source);
+ }
+ }
c = str_save(cmd, APERM);
if ((cp = strchr(c, '\n')) != NULL)
*cp = '\0';
- if (histfd && dowrite)
- writehistfile(lno, c);
-
hp = histptr;
-
if (++hp >= history + histsize) { /* remove oldest command */
afree((void*)*history, APERM);
for (hp = history; hp < history + histsize - 1; hp++)
@@ -596,371 +589,125 @@ histsave(int lno, const char *cmd, int d
}
*hp = c;
histptr = hp;
-}
-
-/*
- * Write history data to a file nominated by HISTFILE
- * if HISTFILE is unset then history still happens, but
- * the data is not written to a file
- * All copies of ksh looking at the file will maintain the
- * same history. This is ksh behaviour.
- *
- * This stuff uses mmap()
- * if your system ain't got it - then you'll have to undef HISTORYFILE
- */
-/*
- * Open a history file
- * Format is:
- * Bytes 1, 2: HMAGIC - just to check that we are dealing with
- * the correct object
- * Then follows a number of stored commands
- * Each command is
- * <command byte><command number(4 bytes)><bytes><null>
- */
-#define HMAGIC1 0xab
-#define HMAGIC2 0xcd
-#define COMMAND 0xff
+ if (dowrite && f) {
+ writehistfile(f);
+ history_close(f);
+ }
+}
-void
-hist_init(Source *s)
+static FILE *
+history_open(int *changed)
{
- unsigned char *base;
- int lines;
- int fd;
-
- if (Flag(FTALKING) == 0)
- return;
-
- hstarted = 1;
-
- hist_source = s;
-
- hname = str_val(global("HISTFILE"));
- if (hname == NULL)
- return;
- hname = str_save(hname, APERM);
+ int fd;
+ FILE *f = NULL;
+ struct stat sb;
- retry:
- /* we have a file and are interactive */
- if ((fd = open(hname, O_RDWR|O_CREAT|O_APPEND, 0600)) < 0)
- return;
-
- histfd = savefd(fd);
- if (histfd != fd)
+ if ((fd = open(hname, O_RDWR | O_CREAT | O_EXLOCK, 0600)) == -1)
+ return (NULL);
+ f = fdopen(fd, "r+");
+ if (f == NULL) {
close(fd);
+ goto bad;
+ }
- (void) flock(histfd, LOCK_EX);
+ if (fstat(fileno(f), &sb) == -1)
+ goto bad;
+ if (timespeccmp(&sb.st_mtim, &last_sb.st_mtim, ==))
+ *changed = 0;
+ else
+ *changed = 1;
- hsize = lseek(histfd, 0L, SEEK_END);
+ return (f);
+bad:
+ if (f)
+ fclose(f);
- if (hsize == 0) {
- /* add magic */
- if (sprinkle(histfd)) {
- hist_finish();
- return;
- }
- }
- else if (hsize > 0) {
- /*
- * we have some data
- */
- base = (unsigned char *)mmap(0, hsize, PROT_READ,
- MAP_FILE|MAP_PRIVATE, histfd, 0);
- /*
- * check on its validity
- */
- if (base == MAP_FAILED || *base != HMAGIC1 || base[1] != HMAGIC2) {
- if (base != MAP_FAILED)
- munmap((caddr_t)base, hsize);
- hist_finish();
- if (unlink(hname) != 0)
- return;
- goto retry;
- }
- if (hsize > 2) {
- lines = hist_count_lines(base+2, hsize-2);
- if (lines > histsize) {
- /* we need to make the file smaller */
- if (hist_shrink(base, hsize))
- if (unlink(hname) != 0)
- return;
- munmap((caddr_t)base, hsize);
- hist_finish();
- goto retry;
- }
- }
- histload(hist_source, base+2, hsize-2);
- munmap((caddr_t)base, hsize);
- }
- (void) flock(histfd, LOCK_UN);
- hsize = lseek(histfd, 0L, SEEK_END);
+ return (NULL);
}
-typedef enum state {
- shdr, /* expecting a header */
- sline, /* looking for a null byte to end the line */
- sn1, /* bytes 1 to 4 of a line no */
- sn2, sn3, sn4
-} State;
+static void
+history_close(FILE *f)
+{
+ fflush(f);
+ fstat(fileno(f), &last_sb);
+ fclose(f);
+}
static int
-hist_count_lines(unsigned char *base, int bytes)
+history_load(FILE *f, Source *s)
{
- State state = shdr;
- int lines = 0;
+ char *p, line[LINE + 1];
+ uint32_t i;
- while (bytes--) {
- switch (state) {
- case shdr:
- if (*base == COMMAND)
- state = sn1;
+ /* just read it all; will auto resize history upon next command */
+ for (i = 1; ; i++) {
+ p = fgets(line, sizeof line, f);
+ if (p == NULL || feof(f) || ferror(f))
break;
- case sn1:
- state = sn2; break;
- case sn2:
- state = sn3; break;
- case sn3:
- state = sn4; break;
- case sn4:
- state = sline; break;
- case sline:
- if (*base == '\0')
- lines++, state = shdr;
+ if ((p = strchr(line, '\n')) == NULL) {
+ bi_errorf("history file is corrupt");
+ return (1);
}
- base++;
+ *p = '\0';
+
+ s->line = i;
+ s->cmd_offset = i;
+ histsave(i, (char *)line, 0);
}
- return lines;
+
+ return (0);
}
-/*
- * Shrink the history file to histsize lines
- */
-static int
-hist_shrink(unsigned char *oldbase, int oldbytes)
+void
+hist_init(Source *s)
{
- int fd;
- char nfile[1024];
- struct stat statb;
- unsigned char *nbase = oldbase;
- int nbytes = oldbytes;
-
- nbase = hist_skip_back(nbase, &nbytes, histsize);
- if (nbase == NULL)
- return 1;
- if (nbase == oldbase)
- return 0;
-
- /*
- * create temp file
- */
- (void) shf_snprintf(nfile, sizeof(nfile), "%s.%d", hname, procpid);
- if ((fd = open(nfile, O_CREAT | O_TRUNC | O_WRONLY, 0600)) < 0)
- return 1;
+ FILE *f = NULL;
+ int changed;
- if (sprinkle(fd)) {
- close(fd);
- unlink(nfile);
- return 1;
- }
- if (write(fd, nbase, nbytes) != nbytes) {
- close(fd);
- unlink(nfile);
- return 1;
- }
- /*
- * worry about who owns this file
- */
- if (fstat(histfd, &statb) >= 0)
- fchown(fd, statb.st_uid, statb.st_gid);
- close(fd);
+ if (Flag(FTALKING) == 0)
+ return;
- /*
- * rename
- */
- if (rename(nfile, hname) < 0)
- return 1;
- return 0;
-}
+ hstarted = 1;
+ hist_source = s;
-/*
- * find a pointer to the data `no' back from the end of the file
- * return the pointer and the number of bytes left
- */
-static unsigned char *
-hist_skip_back(unsigned char *base, int *bytes, int no)
-{
- int lines = 0;
- unsigned char *ep;
+ hname = str_val(global("HISTFILE"));
+ if (hname == NULL)
+ return;
+ hname = str_save(hname, APERM);
- for (ep = base + *bytes; --ep > base; ) {
- /* this doesn't really work: the 4 byte line number that is
- * encoded after the COMMAND byte can itself contain the
- * COMMAND byte....
- */
- for (; ep > base && *ep != COMMAND; ep--)
- ;
- if (ep == base)
- break;
- if (++lines == no) {
- *bytes = *bytes - ((char *)ep - (char *)base);
- return ep;
- }
- }
- return NULL;
-}
+ f = history_open(&changed);
+ if (f == NULL)
+ return;
-/*
- * load the history structure from the stored data
- */
-static void
-histload(Source *s, unsigned char *base, int bytes)
-{
- State state;
- int lno = 0;
- unsigned char *line = NULL;
-
- for (state = shdr; bytes-- > 0; base++) {
- switch (state) {
- case shdr:
- if (*base == COMMAND)
- state = sn1;
- break;
- case sn1:
- lno = (((*base)&0xff)<<24);
- state = sn2;
- break;
- case sn2:
- lno |= (((*base)&0xff)<<16);
- state = sn3;
- break;
- case sn3:
- lno |= (((*base)&0xff)<<8);
- state = sn4;
- break;
- case sn4:
- lno |= (*base)&0xff;
- line = base+1;
- state = sline;
- break;
- case sline:
- if (*base == '\0') {
- /* worry about line numbers */
- if (histptr >= history && lno-1 != s->line) {
- /* a replacement ? */
- histinsert(s, lno, line);
- }
- else {
- s->line = lno;
- s->cmd_offset = lno;
- histsave(lno, (char *)line, 0);
- }
- state = shdr;
- }
- }
- }
+ history_load(f, s);
+ history_close(f);
}
-/*
- * Insert a line into the history at a specified number
- */
static void
-histinsert(Source *s, int lno, unsigned char *line)
+writehistfile(FILE *f)
{
- char **hp;
+ int i;
+ char *cmd;
- if (lno >= s->line-(histptr-history) && lno <= s->line) {
- hp = &histptr[lno-s->line];
- if (*hp)
- afree((void*)*hp, APERM);
- *hp = str_save((char *)line, APERM);
- }
-}
+ if (ftruncate(fileno(f), 0) == -1)
+ return;
+ rewind(f);
-/*
- * write a command to the end of the history file
- * This *MAY* seem easy but it's also necessary to check
- * that the history file has not changed in size.
- * If it has - then some other shell has written to it
- * and we should read those commands to update our history
- */
-static void
-writehistfile(int lno, char *cmd)
-{
- int sizenow;
- unsigned char *base;
- unsigned char *new;
- int bytes;
- unsigned char hdr[5];
-
- (void) flock(histfd, LOCK_EX);
- sizenow = lseek(histfd, 0L, SEEK_END);
- if (sizenow != hsize) {
- /*
- * Things have changed
- */
- if (sizenow > hsize) {
- /* someone has added some lines */
- bytes = sizenow - hsize;
- base = (unsigned char *)mmap(0, sizenow,
- PROT_READ, MAP_FILE|MAP_PRIVATE, histfd, 0);
- if (base == MAP_FAILED)
- goto bad;
- new = base + hsize;
- if (*new != COMMAND) {
- munmap((caddr_t)base, sizenow);
- goto bad;
- }
- hist_source->line--;
- histload(hist_source, new, bytes);
- hist_source->line++;
- lno = hist_source->line;
- munmap((caddr_t)base, sizenow);
- hsize = sizenow;
- } else {
- /* it has shrunk */
- /* but to what? */
- /* we'll give up for now */
- goto bad;
- }
+ for (i = 0; i < histsize; i++) {
+ cmd = history[i];
+ if (cmd == NULL)
+ break;
+ if (fprintf(f, "%s\n", cmd) == -1)
+ return;
}
- /*
- * we can write our bit now
- */
- hdr[0] = COMMAND;
- hdr[1] = (lno>>24)&0xff;
- hdr[2] = (lno>>16)&0xff;
- hdr[3] = (lno>>8)&0xff;
- hdr[4] = lno&0xff;
- (void) write(histfd, hdr, 5);
- (void) write(histfd, cmd, strlen(cmd)+1);
- hsize = lseek(histfd, 0L, SEEK_END);
- (void) flock(histfd, LOCK_UN);
- return;
-bad:
- hist_finish();
}
void
hist_finish(void)
{
- (void) flock(histfd, LOCK_UN);
- (void) close(histfd);
- histfd = 0;
}
-
-/*
- * add magic to the history file
- */
-static int
-sprinkle(int fd)
-{
- static unsigned char mag[] = { HMAGIC1, HMAGIC2 };
-
- return(write(fd, mag, 2) != 2);
-}
-
#else /* HISTORY */
/* No history to be compiled in: dummy routines to avoid lots more ifdefs */

View File

@ -0,0 +1,36 @@
Linux specific modifications:
- #include stdint.h for uint32_t
- #define timespeccmp() which is sys/time.h in OpenBSD
- Linux doesn't have any LOCK flags for open(2), so use flock(2) instead
--- ../ksh-openbsd49/history.c 2011-09-01 08:09:51.486181269 +0200
+++ history.c 2011-09-01 08:08:59.657181265 +0200
@@ -17,11 +17,17 @@
#include "sh.h"
#include <sys/stat.h>
#include "strlcat.h"
+#include "stdint.h"
#ifdef HISTORY
# include <sys/file.h>
# include <sys/mman.h>
+#define timespeccmp(tsp, usp, cmp) \
+ (((tsp)->tv_sec == (usp)->tv_sec) ? \
+ ((tsp)->tv_nsec cmp (usp)->tv_nsec) : \
+ ((tsp)->tv_sec cmp (usp)->tv_sec))
+
static void writehistfile(FILE *);
static FILE *history_open(int *);
static int history_load(FILE *, Source *);
@@ -604,7 +610,9 @@
FILE *f = NULL;
struct stat sb;
- if ((fd = open(hname, O_RDWR | O_CREAT | O_EXLOCK, 0600)) == -1)
+ if ((fd = open(hname, O_RDWR | O_CREAT, 0600)) == -1)
+ return (NULL);
+ if (flock(fd, LOCK_EX) == -1)
return (NULL);
f = fdopen(fd, "r+");
if (f == NULL) {

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,18 @@
# HOW TO EDIT THIS FILE:
# The "handy ruler" below makes it easier to edit a package description. Line
# up the first '|' above the ':' following the base package name, and the '|'
# on the right side marks the last column you can put a character in. You must
# make exactly 11 lines for the formatting to be correct. It's also
# customary to leave one space after the ':'.
|-----handy-ruler------------------------------------------------------|
ksh-openbsd: ksh-openbsd (OpenBSD ksh ported to Linux)
ksh-openbsd:
ksh-openbsd: This package is a patched and ported version of the OpenBSD ksh,
ksh-openbsd: which is based on the original PD-ksh, but heavily modified and
ksh-openbsd: maintained by OpenBSD developers.
ksh-openbsd: "Ported" means ported to Linux. "Patched" means it includes patches
ksh-openbsd: (improvements, bug fixes) separate from the OpenBSD tree.
ksh-openbsd:
ksh-openbsd:
ksh-openbsd:

View File

@ -1,10 +0,0 @@
PRGNAM="ksh"
VERSION="openbsd49"
HOMEPAGE="http://leva.ecentrum.hu/slackbuilds/ksh-openbsd49.tar.gz"
DOWNLOAD="http://leva.ecentrum.hu/slackbuilds/ksh-openbsd49.tar.gz"
MD5SUM="a625102e5961f76bc9918484b2f05940"
DOWNLOAD_x86_64=""
MD5SUM_x86_64=""
MAINTAINER="Daniel LEVAI"
EMAIL="leva@ecentrum.hu"
APPROVED="dsomero"

View File

@ -1,19 +0,0 @@
# HOW TO EDIT THIS FILE:
# The "handy ruler" below makes it easier to edit a package description. Line
# up the first '|' above the ':' following the base package name, and the '|'
# on the right side marks the last column you can put a character in. You must
# make exactly 11 lines for the formatting to be correct. It's also
# customary to leave one space after the ':'.
|-----handy-ruler------------------------------------------------------|
ksh: ksh (OpenBSD ksh ported to Linux)
ksh:
ksh: This package is a patched version of the OpenBSD ksh, which is based
ksh: on the original PD-ksh, but heavily modified and maintained by
ksh: OpenBSD developers. "Patched" means ported to Linux.
ksh:
ksh:
ksh:
ksh:
ksh:
ksh: