if MKSH_SMALL, disable persistent history code as well (like on Solaris,

where it can't work anyway), and fix that code to shrink
saves 2071t 20d 5i
This commit is contained in:
tg 2006-11-10 05:23:14 +00:00
parent 7c4f8d7e16
commit 493ad928e3
5 changed files with 32 additions and 24 deletions

View File

@ -3,11 +3,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/histrap.c,v 1.30 2006/11/10 04:22:13 tg Exp $");
#if !defined(__sun__)
#define DO_HISTORY
#endif
__RCSID("$MirOS: src/bin/mksh/histrap.c,v 1.31 2006/11/10 05:23:12 tg Exp $");
#ifndef mksh_siglist
#if defined(BSD) || defined(__APPLE__)
@ -27,7 +23,7 @@ __RCSID("$MirOS: src/bin/mksh/histrap.c,v 1.30 2006/11/10 04:22:13 tg Exp $");
Trap sigtraps[NSIG + 1];
static struct sigaction Sigact_ign, Sigact_trap;
#ifdef DO_HISTORY
#ifdef V_HISTFILE
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);
@ -44,12 +40,14 @@ static char **hist_get_oldest(void);
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;
#ifdef V_HISTFILE
static char *hname; /* current name of history file */
static int histfd;
static int hsize;
#endif
int
c_fc(char **wp)
@ -518,6 +516,7 @@ sethistsize(int n)
}
}
#ifdef V_HISTFILE
/*
* set history file
* This can mean reloading/resetting/starting history file
@ -551,6 +550,7 @@ sethistfile(const char *name)
hist_init(hist_source);
}
#endif
/*
* initialise the history vector
@ -589,7 +589,7 @@ histsave(int lno __attribute__((unused)), const char *cmd,
if ((cp = strchr(c, '\n')) != NULL)
*cp = '\0';
#ifdef DO_HISTORY
#ifdef V_HISTFILE
if (histfd && dowrite)
writehistfile(lno, c);
#endif
@ -632,7 +632,7 @@ histsave(int lno __attribute__((unused)), const char *cmd,
void
hist_init(Source *s)
{
#ifdef DO_HISTORY
#ifdef V_HISTFILE
unsigned char *base;
int lines;
int fd;
@ -645,7 +645,7 @@ hist_init(Source *s)
hist_source = s;
#ifdef DO_HISTORY
#ifdef V_HISTFILE
hname = str_val(global("HISTFILE"));
if (hname == NULL)
return;
@ -702,12 +702,10 @@ hist_init(Source *s)
}
(void) flock(histfd, LOCK_UN);
hsize = lseek(histfd, 0L, SEEK_END);
#else
hname = NULL;
histfd = 0;
#endif
}
#ifdef V_HISTFILE
typedef enum state {
shdr, /* expecting a header */
sline, /* looking for a null byte to end the line */
@ -715,7 +713,6 @@ typedef enum state {
sn2, sn3, sn4
} State;
#ifdef DO_HISTORY
static int
hist_count_lines(unsigned char *base, int bytes)
{
@ -947,19 +944,15 @@ writehistfile(int lno, char *cmd)
bad:
hist_finish();
}
#endif
void
hist_finish(void)
{
#ifdef DO_HISTORY
(void) flock(histfd, LOCK_UN);
(void) close(histfd);
#endif
histfd = 0;
}
#ifdef DO_HISTORY
/*
* add magic to the history file
*/

4
main.c
View File

@ -13,7 +13,7 @@
#include <locale.h>
#endif
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.54 2006/11/10 03:23:49 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.55 2006/11/10 05:23:12 tg Exp $");
extern char **environ;
@ -597,8 +597,10 @@ quitenv(struct shf *shf)
*/
if (ep->oenv == NULL) {
if (ep->type == E_NONE) { /* Main shell exiting? */
#ifdef V_HISTFILE
if (Flag(FTALKING))
hist_finish();
#endif
j_exit();
if (ep->flags & EF_FAKE_SIGDIE) {
int sig = exstat - 128;

9
mksh.1
View File

@ -1,7 +1,7 @@
.\" $MirOS: src/bin/mksh/mksh.1,v 1.64 2006/11/09 22:11:08 tg Exp $
.\" $MirOS: src/bin/mksh/mksh.1,v 1.65 2006/11/10 05:23:12 tg Exp $
.\" $OpenBSD: ksh.1,v 1.116 2006/07/26 10:13:25 jmc Exp $
.\"
.Dd November 9, 2006
.Dd November 10, 2006
.Dt MKSH 1
.Os MirBSD
.Sh NAME
@ -5292,7 +5292,10 @@ projects and patches and suggestions from users
and many other persons.
.Sh BUGS
This document attempts to describe
.Nm "" R29 .
.Nm "" R29 ,
compiled without
.Dv MKSH_SMALL
or similar functionality-reducing options.
Please report bugs in
.Nm
to the

8
sh.h
View File

@ -8,7 +8,7 @@
/* $OpenBSD: c_test.h,v 1.4 2004/12/20 11:34:26 otto Exp $ */
/* $OpenBSD: tty.h,v 1.5 2004/12/20 11:34:26 otto Exp $ */
#define MKSH_SH_H_ID "$MirOS: src/bin/mksh/sh.h,v 1.73 2006/11/10 03:45:57 tg Exp $"
#define MKSH_SH_H_ID "$MirOS: src/bin/mksh/sh.h,v 1.74 2006/11/10 05:23:13 tg Exp $"
#define MKSH_VERSION "R29 2006/11/10"
#if HAVE_SYS_PARAM_H
@ -688,7 +688,9 @@ extern const struct builtin shbuiltins [], kshbuiltins [];
#define V_OPTIND 4
#define V_RANDOM 8
#define V_HISTSIZE 9
#if !defined(__sun__) && !defined(MKSH_SMALL)
#define V_HISTFILE 10
#endif
#define V_COLUMNS 13
#define V_TMOUT 15
#define V_TMPDIR 16
@ -1119,11 +1121,15 @@ int c_test(char **);
/* histrap.c */
void init_histvec(void);
void hist_init(Source *);
#ifdef V_HISTFILE
void hist_finish(void);
#endif
void histsave(int, const char *, int);
int c_fc(char **);
void sethistsize(int);
#ifdef V_HISTFILE
void sethistfile(const char *);
#endif
char **histpos(void);
int histnum(int);
int findhist(int, int, const char *, int);

6
var.c
View File

@ -2,7 +2,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.25 2006/11/10 04:22:13 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.26 2006/11/10 05:23:14 tg Exp $");
/*
* Variables
@ -88,7 +88,9 @@ initvar(void)
{ "OPTIND", V_OPTIND },
{ "PATH", V_PATH },
{ "TMPDIR", V_TMPDIR },
#ifdef V_HISTFILE
{ "HISTFILE", V_HISTFILE },
#endif
{ "HISTSIZE", V_HISTSIZE },
{ "RANDOM", V_RANDOM },
{ "SECONDS", V_SECONDS },
@ -991,9 +993,11 @@ setspec(struct tbl *vp)
sethistsize((int) intval(vp));
vp->flag |= SPECIAL;
break;
#ifdef V_HISTFILE
case V_HISTFILE:
sethistfile(str_val(vp));
break;
#endif
case V_COLUMNS:
if ((x_cols = intval(vp)) <= MIN_COLS)
x_cols = MIN_COLS;