optimise (struct padding, function→macro, etc.)
This commit is contained in:
26
edit.c
26
edit.c
@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
#include "sh.h"
|
#include "sh.h"
|
||||||
|
|
||||||
__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.115 2007/10/14 13:43:41 tg Exp $");
|
__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.116 2007/10/25 15:19:15 tg Exp $");
|
||||||
|
|
||||||
/* tty driver characters we are interested in */
|
/* tty driver characters we are interested in */
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@ -26,8 +26,7 @@ X_chars edchars;
|
|||||||
#define XCF_COMMAND_FILE (XCF_COMMAND|XCF_FILE)
|
#define XCF_COMMAND_FILE (XCF_COMMAND|XCF_FILE)
|
||||||
|
|
||||||
static int x_getc(void);
|
static int x_getc(void);
|
||||||
static void x_flush(void);
|
static void x_putcf(int);
|
||||||
static void x_putc(int);
|
|
||||||
static bool x_mode(bool);
|
static bool x_mode(bool);
|
||||||
static int x_do_comment(char *, int, int *);
|
static int x_do_comment(char *, int, int *);
|
||||||
static void x_print_expansions(int, char *const *, int);
|
static void x_print_expansions(int, char *const *, int);
|
||||||
@ -43,6 +42,9 @@ static void x_init_prompt(void);
|
|||||||
static int x_vi(char *, size_t);
|
static int x_vi(char *, size_t);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define x_flush() shf_flush(shl_out)
|
||||||
|
#define x_putc(c) shf_putc((c), shl_out)
|
||||||
|
|
||||||
#ifdef TIOCGWINSZ
|
#ifdef TIOCGWINSZ
|
||||||
static void chkwinsz(void);
|
static void chkwinsz(void);
|
||||||
#endif
|
#endif
|
||||||
@ -141,13 +143,7 @@ x_getc(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
x_flush(void)
|
x_putcf(int c)
|
||||||
{
|
|
||||||
shf_flush(shl_out);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
x_putc(int c)
|
|
||||||
{
|
{
|
||||||
shf_putc(c, shl_out);
|
shf_putc(c, shl_out);
|
||||||
}
|
}
|
||||||
@ -443,8 +439,8 @@ x_command_glob(int flags, const char *str, int slen, char ***wordsp)
|
|||||||
return nwords;
|
return nwords;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define IS_WORDC(c) !( ctype(c, C_LEX1) || (c) == '\'' || (c) == '"' || \
|
#define IS_WORDC(c) (!ctype(c, C_LEX1) && (c) != '\'' && (c) != '"' && \
|
||||||
(c) == '`' || (c) == '=' || (c) == ':' )
|
(c) != '`' && (c) != '=' && (c) != ':')
|
||||||
|
|
||||||
static int
|
static int
|
||||||
x_locate_word(const char *buf, int buflen, int pos, int *startp,
|
x_locate_word(const char *buf, int buflen, int pos, int *startp,
|
||||||
@ -2988,7 +2984,7 @@ x_e_putc3(const char **cp)
|
|||||||
|
|
||||||
width = utf_widthadj(*cp, (const char **)&cp2);
|
width = utf_widthadj(*cp, (const char **)&cp2);
|
||||||
while (*cp < cp2)
|
while (*cp < cp2)
|
||||||
x_putc(*(*cp)++);
|
x_putcf(*(*cp)++);
|
||||||
} else {
|
} else {
|
||||||
(*cp)++;
|
(*cp)++;
|
||||||
x_putc(c);
|
x_putc(c);
|
||||||
@ -5193,7 +5189,7 @@ ed_mov_opt(int col, char *wb)
|
|||||||
pprompt(prompt, prompt_trunc);
|
pprompt(prompt, prompt_trunc);
|
||||||
cur_col = pwidth;
|
cur_col = pwidth;
|
||||||
while (cur_col++ < col)
|
while (cur_col++ < col)
|
||||||
x_putc(*wb++);
|
x_putcf(*wb++);
|
||||||
} else {
|
} else {
|
||||||
while (cur_col-- > col)
|
while (cur_col-- > col)
|
||||||
x_putc('\b');
|
x_putc('\b');
|
||||||
@ -5201,7 +5197,7 @@ ed_mov_opt(int col, char *wb)
|
|||||||
} else {
|
} else {
|
||||||
wb = &wb[cur_col - pwidth];
|
wb = &wb[cur_col - pwidth];
|
||||||
while (cur_col++ < col)
|
while (cur_col++ < col)
|
||||||
x_putc(*wb++);
|
x_putcf(*wb++);
|
||||||
}
|
}
|
||||||
cur_col = col;
|
cur_col = col;
|
||||||
}
|
}
|
||||||
|
9
expr.c
9
expr.c
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
#include "sh.h"
|
#include "sh.h"
|
||||||
|
|
||||||
__RCSID("$MirOS: src/bin/mksh/expr.c,v 1.12 2007/07/22 14:01:48 tg Exp $");
|
__RCSID("$MirOS: src/bin/mksh/expr.c,v 1.13 2007/10/25 15:19:16 tg Exp $");
|
||||||
|
|
||||||
/* The order of these enums is constrained by the order of opinfo[] */
|
/* The order of these enums is constrained by the order of opinfo[] */
|
||||||
enum token {
|
enum token {
|
||||||
@ -111,13 +111,10 @@ struct expr_state {
|
|||||||
const char *tokp; /* lexical position */
|
const char *tokp; /* lexical position */
|
||||||
enum token tok; /* token from token() */
|
enum token tok; /* token from token() */
|
||||||
int noassign; /* don't do assigns (for ?:,&&,||) */
|
int noassign; /* don't do assigns (for ?:,&&,||) */
|
||||||
bool arith; /* true if evaluating an $(())
|
|
||||||
* expression
|
|
||||||
*/
|
|
||||||
struct tbl *val; /* value from token() */
|
struct tbl *val; /* value from token() */
|
||||||
struct tbl *evaling; /* variable that is being recursively
|
struct tbl *evaling; /* variable that is being recursively
|
||||||
* expanded (EXPRINEVAL flag set)
|
* expanded (EXPRINEVAL flag set) */
|
||||||
*/
|
bool arith; /* evaluating an $(()) expression? */
|
||||||
};
|
};
|
||||||
|
|
||||||
enum error_type {
|
enum error_type {
|
||||||
|
12
main.c
12
main.c
@ -13,7 +13,7 @@
|
|||||||
#include <locale.h>
|
#include <locale.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.87 2007/08/19 22:06:26 tg Exp $");
|
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.88 2007/10/25 15:19:16 tg Exp $");
|
||||||
|
|
||||||
extern char **environ;
|
extern char **environ;
|
||||||
|
|
||||||
@ -713,11 +713,9 @@ reclaim(void)
|
|||||||
static void
|
static void
|
||||||
remove_temps(struct temp *tp)
|
remove_temps(struct temp *tp)
|
||||||
{
|
{
|
||||||
|
|
||||||
for (; tp != NULL; tp = tp->next)
|
for (; tp != NULL; tp = tp->next)
|
||||||
if (tp->pid == procpid) {
|
if (tp->pid == procpid)
|
||||||
unlink(tp->name);
|
unlink(tp->name);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Initialise tty_fd. Used for saving/reseting tty modes upon
|
/* Initialise tty_fd. Used for saving/reseting tty modes upon
|
||||||
@ -1268,12 +1266,6 @@ ktenter(struct table *tp, const char *n, unsigned int h)
|
|||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
ktdelete(struct tbl *p)
|
|
||||||
{
|
|
||||||
p->flag = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ktwalk(struct tstate *ts, struct table *tp)
|
ktwalk(struct tstate *ts, struct table *tp)
|
||||||
{
|
{
|
||||||
|
8
misc.c
8
misc.c
@ -6,7 +6,7 @@
|
|||||||
#include <grp.h>
|
#include <grp.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.66 2007/09/09 18:06:41 tg Exp $\t"
|
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.67 2007/10/25 15:19:16 tg Exp $\t"
|
||||||
MKSH_SH_H_ID);
|
MKSH_SH_H_ID);
|
||||||
|
|
||||||
#undef USE_CHVT
|
#undef USE_CHVT
|
||||||
@ -481,11 +481,11 @@ getn(const char *s, int *ai)
|
|||||||
int
|
int
|
||||||
bi_getn(const char *as, int *ai)
|
bi_getn(const char *as, int *ai)
|
||||||
{
|
{
|
||||||
int rv = getn(as, ai);
|
int rv;
|
||||||
|
|
||||||
if (!rv)
|
if (!(rv = getn(as, ai)))
|
||||||
bi_errorf("%s: bad number", as);
|
bi_errorf("%s: bad number", as);
|
||||||
return rv;
|
return (rv);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------- gmatch.c -------- */
|
/* -------- gmatch.c -------- */
|
||||||
|
22
sh.h
22
sh.h
@ -8,7 +8,7 @@
|
|||||||
/* $OpenBSD: c_test.h,v 1.4 2004/12/20 11:34:26 otto Exp $ */
|
/* $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 $ */
|
/* $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.181 2007/10/25 14:26:53 tg Exp $"
|
#define MKSH_SH_H_ID "$MirOS: src/bin/mksh/sh.h,v 1.182 2007/10/25 15:19:16 tg Exp $"
|
||||||
#define MKSH_VERSION "R32 2007/10/25"
|
#define MKSH_VERSION "R32 2007/10/25"
|
||||||
|
|
||||||
#if HAVE_SYS_PARAM_H
|
#if HAVE_SYS_PARAM_H
|
||||||
@ -333,14 +333,14 @@ EXTERN Area aperm; /* permanent object space */
|
|||||||
* parsing & execution environment
|
* parsing & execution environment
|
||||||
*/
|
*/
|
||||||
EXTERN struct env {
|
EXTERN struct env {
|
||||||
short type; /* environment type - see below */
|
|
||||||
short flags; /* EF_* */
|
|
||||||
Area area; /* temporary allocation area */
|
Area area; /* temporary allocation area */
|
||||||
struct block *loc; /* local variables and functions */
|
struct block *loc; /* local variables and functions */
|
||||||
short *savefd; /* original redirected fds */
|
short *savefd; /* original redirected fds */
|
||||||
struct env *oenv; /* link to previous environment */
|
struct env *oenv; /* link to previous environment */
|
||||||
sigjmp_buf jbuf; /* long jump back to env creator */
|
|
||||||
struct temp *temps; /* temp files */
|
struct temp *temps; /* temp files */
|
||||||
|
sigjmp_buf jbuf; /* long jump back to env creator */
|
||||||
|
short type; /* environment type - see below */
|
||||||
|
short flags; /* EF_* */
|
||||||
} *e;
|
} *e;
|
||||||
|
|
||||||
/* struct env.type values */
|
/* struct env.type values */
|
||||||
@ -686,8 +686,8 @@ extern struct shf shf_iob[];
|
|||||||
|
|
||||||
struct table {
|
struct table {
|
||||||
Area *areap; /* area to allocate entries */
|
Area *areap; /* area to allocate entries */
|
||||||
short size, nfree; /* hash size (always 2^^n), free entries */
|
|
||||||
struct tbl **tbls; /* hashed table items */
|
struct tbl **tbls; /* hashed table items */
|
||||||
|
short size, nfree; /* hash size (always 2^^n), free entries */
|
||||||
};
|
};
|
||||||
|
|
||||||
struct tbl { /* table item */
|
struct tbl { /* table item */
|
||||||
@ -857,11 +857,6 @@ EXTERN int current_lineno; /* LINENO value */
|
|||||||
* Description of a command or an operation on commands.
|
* Description of a command or an operation on commands.
|
||||||
*/
|
*/
|
||||||
struct op {
|
struct op {
|
||||||
short type; /* operation type, see below */
|
|
||||||
union { /* WARNING: newtp(), tcopy() use evalflags = 0 to clear union */
|
|
||||||
short evalflags; /* TCOM: arg expansion eval() flags */
|
|
||||||
short ksh_func; /* TFUNC: function x (vs x()) */
|
|
||||||
} u;
|
|
||||||
const char **args; /* arguments to a command */
|
const char **args; /* arguments to a command */
|
||||||
char **vars; /* variable assignments */
|
char **vars; /* variable assignments */
|
||||||
struct ioword **ioact; /* IO actions (eg, < > >>) */
|
struct ioword **ioact; /* IO actions (eg, < > >>) */
|
||||||
@ -872,6 +867,11 @@ struct op {
|
|||||||
* time hook for TCOM.
|
* time hook for TCOM.
|
||||||
*/
|
*/
|
||||||
int lineno; /* TCOM/TFUNC: LINENO for this */
|
int lineno; /* TCOM/TFUNC: LINENO for this */
|
||||||
|
short type; /* operation type, see below */
|
||||||
|
union { /* WARNING: newtp(), tcopy() use evalflags = 0 to clear union */
|
||||||
|
short evalflags; /* TCOM: arg expansion eval() flags */
|
||||||
|
short ksh_func; /* TFUNC: function x (vs x()) */
|
||||||
|
} u;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Tree.type values */
|
/* Tree.type values */
|
||||||
@ -1394,7 +1394,7 @@ unsigned int hash(const char *);
|
|||||||
void ktinit(struct table *, Area *, int);
|
void ktinit(struct table *, Area *, int);
|
||||||
struct tbl *ktsearch(struct table *, const char *, unsigned int);
|
struct tbl *ktsearch(struct table *, const char *, unsigned int);
|
||||||
struct tbl *ktenter(struct table *, const char *, unsigned int);
|
struct tbl *ktenter(struct table *, const char *, unsigned int);
|
||||||
void ktdelete(struct tbl *);
|
#define ktdelete(p) do { p->flag = 0 } while (0)
|
||||||
void ktwalk(struct tstate *, struct table *);
|
void ktwalk(struct tstate *, struct table *);
|
||||||
struct tbl *ktnext(struct tstate *);
|
struct tbl *ktnext(struct tstate *);
|
||||||
struct tbl **ktsort(struct table *);
|
struct tbl **ktsort(struct table *);
|
||||||
|
26
tree.c
26
tree.c
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
#include "sh.h"
|
#include "sh.h"
|
||||||
|
|
||||||
__RCSID("$MirOS: src/bin/mksh/tree.c,v 1.11 2007/07/06 01:53:36 tg Exp $");
|
__RCSID("$MirOS: src/bin/mksh/tree.c,v 1.12 2007/10/25 15:19:16 tg Exp $");
|
||||||
|
|
||||||
#define INDENT 4
|
#define INDENT 4
|
||||||
|
|
||||||
@ -336,29 +336,29 @@ tputS(char *wp, struct shf *shf)
|
|||||||
int
|
int
|
||||||
fptreef(struct shf *shf, int indent, const char *fmt, ...)
|
fptreef(struct shf *shf, int indent, const char *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list va;
|
va_list va;
|
||||||
|
|
||||||
va_start(va, fmt);
|
va_start(va, fmt);
|
||||||
|
|
||||||
vfptreef(shf, indent, fmt, va);
|
vfptreef(shf, indent, fmt, va);
|
||||||
va_end(va);
|
va_end(va);
|
||||||
return 0;
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* VARARGS */
|
/* VARARGS */
|
||||||
char *
|
char *
|
||||||
snptreef(char *s, int n, const char *fmt, ...)
|
snptreef(char *s, int n, const char *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list va;
|
va_list va;
|
||||||
struct shf shf;
|
struct shf shf;
|
||||||
|
|
||||||
shf_sopen(s, n, SHF_WR | (s ? 0 : SHF_DYNAMIC), &shf);
|
shf_sopen(s, n, SHF_WR | (s ? 0 : SHF_DYNAMIC), &shf);
|
||||||
|
|
||||||
va_start(va, fmt);
|
va_start(va, fmt);
|
||||||
vfptreef(&shf, 0, fmt, va);
|
vfptreef(&shf, 0, fmt, va);
|
||||||
va_end(va);
|
va_end(va);
|
||||||
|
|
||||||
return shf_sclose(&shf); /* null terminates */
|
return (shf_sclose(&shf)); /* null terminates */
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
Reference in New Issue
Block a user