merge non-Plan9-specific stuff from the branch, add KNF, etc.
This commit is contained in:
parent
38e8974e3e
commit
c81966621a
7
Build.sh
7
Build.sh
@ -1,8 +1,13 @@
|
||||
#!/bin/sh
|
||||
# $MirOS: src/bin/mksh/Build.sh,v 1.49 2006/08/22 22:01:59 tg Exp $
|
||||
# $MirOS: src/bin/mksh/Build.sh,v 1.50 2006/08/24 20:32:52 tg Exp $
|
||||
#-
|
||||
# Environment: CC, CFLAGS, CPPFLAGS, LDFLAGS, LIBS, NROFF
|
||||
|
||||
if test -d mksh; then
|
||||
echo "$0: Error: ./mksh is a directory!" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
: ${CFLAGS='-O2 -fno-strict-aliasing -fno-strength-reduce -Wall'}
|
||||
: ${CC=gcc} ${NROFF=nroff}
|
||||
curdir=`pwd` srcdir=`dirname "$0"`
|
||||
|
14
edit.c
14
edit.c
@ -5,7 +5,7 @@
|
||||
|
||||
#include "sh.h"
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.37 2006/08/22 22:49:34 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.38 2006/08/24 20:32:52 tg Exp $");
|
||||
|
||||
/* tty driver characters we are interested in */
|
||||
typedef struct {
|
||||
@ -42,9 +42,11 @@ void x_init_emacs(void);
|
||||
void x_emacs_keys(X_chars *);
|
||||
int x_vi(char *, size_t);
|
||||
|
||||
#if defined(TIOCGWINSZ) && defined(SIGWINCH)
|
||||
static void x_sigwinch(int);
|
||||
static volatile sig_atomic_t got_sigwinch;
|
||||
static void check_sigwinch(void);
|
||||
#endif
|
||||
|
||||
static int path_order_cmp(const void *aa, const void *bb);
|
||||
static char *add_glob(const char *, int);
|
||||
@ -66,14 +68,17 @@ x_init(void)
|
||||
/* default value for deficient systems */
|
||||
edchars.werase = 027; /* ^W */
|
||||
|
||||
#if defined(TIOCGWINSZ) && defined(SIGWINCH)
|
||||
if (setsig(&sigtraps[SIGWINCH], x_sigwinch,
|
||||
SS_RESTORE_ORIG | SS_SHTRAP))
|
||||
sigtraps[SIGWINCH].flags |= TF_SHELL_USES;
|
||||
check_sigwinch(); /* force initial check */
|
||||
#endif
|
||||
|
||||
x_init_emacs();
|
||||
}
|
||||
|
||||
#if defined(TIOCGWINSZ) && defined(SIGWINCH)
|
||||
/* ARGSUSED */
|
||||
static void
|
||||
x_sigwinch(int sig __attribute__((unused)))
|
||||
@ -106,6 +111,7 @@ check_sigwinch(void)
|
||||
setint(vp, (long)ws.ws_row);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* read an edited command line
|
||||
@ -123,7 +129,9 @@ x_read(char *buf, size_t len)
|
||||
else
|
||||
i = -1; /* internal error */
|
||||
x_mode(false);
|
||||
#if defined(TIOCGWINSZ) && defined(SIGWINCH)
|
||||
check_sigwinch();
|
||||
#endif
|
||||
return i;
|
||||
}
|
||||
|
||||
@ -188,11 +196,15 @@ x_mode(bool onoff)
|
||||
edchars.intr = cb.c_cc[VINTR];
|
||||
edchars.quit = cb.c_cc[VQUIT];
|
||||
edchars.eof = cb.c_cc[VEOF];
|
||||
#ifdef VWERASE
|
||||
edchars.werase = cb.c_cc[VWERASE];
|
||||
#endif
|
||||
cb.c_iflag &= ~(INLCR | ICRNL);
|
||||
cb.c_lflag &= ~(ISIG | ICANON | ECHO);
|
||||
#ifdef VLNEXT
|
||||
/* osf/1 processes lnext when ~icanon */
|
||||
cb.c_cc[VLNEXT] = _POSIX_VDISABLE;
|
||||
#endif
|
||||
/* sunos 4.1.x & osf/1 processes discard(flush) when ~icanon */
|
||||
#ifdef VDISCARD
|
||||
cb.c_cc[VDISCARD] = _POSIX_VDISABLE;
|
||||
|
18
funcs.c
18
funcs.c
@ -5,7 +5,7 @@
|
||||
|
||||
#include "sh.h"
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.29 2006/08/01 13:43:26 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.30 2006/08/24 20:32:52 tg Exp $");
|
||||
|
||||
int
|
||||
c_cd(char **wp)
|
||||
@ -2049,13 +2049,17 @@ c_times(char **wp __attribute__((unused)))
|
||||
{
|
||||
struct rusage usage;
|
||||
|
||||
#ifdef RUSAGE_SELF
|
||||
(void) getrusage(RUSAGE_SELF, &usage);
|
||||
p_time(shl_stdout, 0, &usage.ru_utime, 0, NULL, " ");
|
||||
p_time(shl_stdout, 0, &usage.ru_stime, 0, NULL, "\n");
|
||||
#endif
|
||||
|
||||
#ifdef RUSAGE_CHILDREN
|
||||
(void) getrusage(RUSAGE_CHILDREN, &usage);
|
||||
p_time(shl_stdout, 0, &usage.ru_utime, 0, NULL, " ");
|
||||
p_time(shl_stdout, 0, &usage.ru_stime, 0, NULL, "\n");
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -2069,6 +2073,9 @@ timex(struct op *t, int f)
|
||||
#define TF_NOARGS BIT(0)
|
||||
#define TF_NOREAL BIT(1) /* don't report real time */
|
||||
#define TF_POSIX BIT(2) /* report in posix format */
|
||||
#if !defined(RUSAGE_SELF) || !defined(RUSAGE_CHILDREN)
|
||||
return (0);
|
||||
#else
|
||||
int rv = 0;
|
||||
struct rusage ru0, ru1, cru0, cru1;
|
||||
struct timeval usrtime, systime, tv0, tv1;
|
||||
@ -2129,7 +2136,8 @@ timex(struct op *t, int f)
|
||||
p_time(shl_out, 0, &systime, 5, NULL, " system\n");
|
||||
shf_flush(shl_out);
|
||||
|
||||
return rv;
|
||||
return (rv);
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
@ -2549,8 +2557,12 @@ test_eval(Test_env *te, Test_op op, const char *opnd1, const char *opnd2,
|
||||
return stat(opnd1, &b1) == 0 &&
|
||||
(b1.st_mode & S_ISGID) == S_ISGID;
|
||||
case TO_FILSTCK: /* -k */
|
||||
#ifdef S_ISVTX
|
||||
return stat(opnd1, &b1) == 0 &&
|
||||
(b1.st_mode & S_ISVTX) == S_ISVTX;
|
||||
#else
|
||||
return (0);
|
||||
#endif
|
||||
case TO_FILGZ: /* -s */
|
||||
return stat(opnd1, &b1) == 0 && b1.st_size > 0L;
|
||||
case TO_FILTT: /* -t */
|
||||
@ -3013,5 +3025,5 @@ c_ulimit(char **wp)
|
||||
shprintf("%ld\n", (long) val);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
return (0);
|
||||
}
|
||||
|
22
jobs.c
22
jobs.c
@ -2,7 +2,7 @@
|
||||
|
||||
#include "sh.h"
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/jobs.c,v 1.9 2006/08/01 13:43:27 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/jobs.c,v 1.10 2006/08/24 20:32:53 tg Exp $");
|
||||
|
||||
/* Order important! */
|
||||
#define PRUNNING 0
|
||||
@ -54,8 +54,10 @@ struct job {
|
||||
pid_t pgrp; /* process group of job */
|
||||
pid_t ppid; /* pid of process that forked job */
|
||||
int32_t age; /* number of jobs started */
|
||||
#ifdef RUSAGE_CHILDREN
|
||||
struct timeval systime; /* system time used by job */
|
||||
struct timeval usrtime; /* user time used by job */
|
||||
#endif
|
||||
Proc *proc_list; /* process list */
|
||||
Proc *last_proc; /* last process in list */
|
||||
Coproc_id coproc_id; /* 0 or id of coprocess output pipe */
|
||||
@ -83,7 +85,9 @@ static const char *const lookup_msgs[] = {
|
||||
NULL
|
||||
};
|
||||
|
||||
#ifdef RUSAGE_CHILDREN
|
||||
struct timeval j_systime, j_usrtime; /* user and system time of last j_waitjed job */
|
||||
#endif
|
||||
|
||||
static Job *job_list; /* job list */
|
||||
static Job *last_job;
|
||||
@ -336,8 +340,10 @@ exchild(struct op *t, int flags,
|
||||
*/
|
||||
j->flags = (flags & XXCOM) ? JF_XXCOM :
|
||||
((flags & XBGND) ? 0 : (JF_FG|JF_USETTYMODE));
|
||||
#ifdef RUSAGE_CHILDREN
|
||||
timerclear(&j->usrtime);
|
||||
timerclear(&j->systime);
|
||||
#endif
|
||||
j->state = PRUNNING;
|
||||
j->pgrp = 0;
|
||||
j->ppid = procpid;
|
||||
@ -989,8 +995,10 @@ j_waitj(Job *j,
|
||||
trapsig(WTERMSIG(status));
|
||||
}
|
||||
|
||||
#ifdef RUSAGE_CHILDREN
|
||||
j_usrtime = j->usrtime;
|
||||
j_systime = j->systime;
|
||||
#endif
|
||||
rv = j->status;
|
||||
|
||||
if (!(flags & JW_ASYNCNOTIFY) &&
|
||||
@ -1018,7 +1026,9 @@ j_sigchld(int sig __attribute__((unused)))
|
||||
Proc *p = NULL;
|
||||
int pid;
|
||||
int status;
|
||||
#ifdef RUSAGE_CHILDREN
|
||||
struct rusage ru0, ru1;
|
||||
#endif
|
||||
|
||||
/* Don't wait for any processes if a job is partially started.
|
||||
* This is so we don't do away with the process group leader
|
||||
@ -1031,14 +1041,18 @@ j_sigchld(int sig __attribute__((unused)))
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef RUSAGE_CHILDREN
|
||||
getrusage(RUSAGE_CHILDREN, &ru0);
|
||||
#endif
|
||||
do {
|
||||
pid = waitpid(-1, &status, (WNOHANG|WUNTRACED));
|
||||
|
||||
if (pid <= 0) /* return if would block (0) ... */
|
||||
break; /* ... or no children or interrupted (-1) */
|
||||
|
||||
#ifdef RUSAGE_CHILDREN
|
||||
getrusage(RUSAGE_CHILDREN, &ru1);
|
||||
#endif
|
||||
|
||||
/* find job and process structures for this pid */
|
||||
for (j = job_list; j != NULL; j = j->next)
|
||||
@ -1051,15 +1065,19 @@ j_sigchld(int sig __attribute__((unused)))
|
||||
warningf(true, "bad process waited for (pid = %d)",
|
||||
pid);
|
||||
*/
|
||||
#ifdef RUSAGE_CHILDREN
|
||||
ru0 = ru1;
|
||||
#endif
|
||||
continue;
|
||||
}
|
||||
|
||||
#ifdef RUSAGE_CHILDREN
|
||||
timeradd(&j->usrtime, &ru1.ru_utime, &j->usrtime);
|
||||
timersub(&j->usrtime, &ru0.ru_utime, &j->usrtime);
|
||||
timeradd(&j->systime, &ru1.ru_stime, &j->systime);
|
||||
timersub(&j->systime, &ru0.ru_stime, &j->systime);
|
||||
ru0 = ru1;
|
||||
#endif
|
||||
p->status = status;
|
||||
if (WIFSTOPPED(status))
|
||||
p->state = PSTOPPED;
|
||||
@ -1233,8 +1251,10 @@ j_print(Job *j, int how, struct shf *shf)
|
||||
WEXITSTATUS(p->status));
|
||||
break;
|
||||
case PSIGNALLED:
|
||||
#ifdef WCOREDUMP
|
||||
if (WCOREDUMP(p->status))
|
||||
coredumped = 1;
|
||||
#endif
|
||||
/* kludge for not reporting 'normal termination signals'
|
||||
* (ie, SIGINT, SIGPIPE)
|
||||
*/
|
||||
|
4
main.c
4
main.c
@ -6,7 +6,7 @@
|
||||
#define EXTERN
|
||||
#include "sh.h"
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.47 2006/08/22 22:49:35 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.48 2006/08/24 20:32:53 tg Exp $");
|
||||
|
||||
extern char **environ;
|
||||
|
||||
@ -114,7 +114,7 @@ main(int argc, char *argv[])
|
||||
init_histvec();
|
||||
|
||||
def_path = _PATH_DEFPATH;
|
||||
#if !defined(__CYGWIN__)
|
||||
#ifdef _CS_PATH
|
||||
{
|
||||
size_t len;
|
||||
char *new;
|
||||
|
8
misc.c
8
misc.c
@ -3,7 +3,7 @@
|
||||
|
||||
#include "sh.h"
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.15 2006/08/22 22:49:36 tg Exp $\t"
|
||||
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.16 2006/08/24 20:32:53 tg Exp $\t"
|
||||
MKSH_SH_H_ID);
|
||||
|
||||
short chtypes[UCHAR_MAX+1]; /* type bits for unsigned char */
|
||||
@ -1129,7 +1129,7 @@ reset_nonblock(int fd)
|
||||
}
|
||||
|
||||
|
||||
/* Like getcwd(), except bsize is ignored if buf is 0 (MAXPATHLEN is used) */
|
||||
/* Like getcwd(), except bsize is ignored if buf is 0 (PATH_MAX is used) */
|
||||
char *
|
||||
ksh_get_wd(char *buf, int bsize)
|
||||
{
|
||||
@ -1140,8 +1140,8 @@ ksh_get_wd(char *buf, int bsize)
|
||||
* inject possibly allocated space into the ATEMP area. */
|
||||
/* Assume getcwd() available */
|
||||
if (!buf) {
|
||||
bsize = MAXPATHLEN;
|
||||
b = alloc(MAXPATHLEN + 1, ATEMP);
|
||||
bsize = PATH_MAX;
|
||||
b = alloc(PATH_MAX + 1, ATEMP);
|
||||
} else
|
||||
b = buf;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user