2012-09-21 19:20:22 +02:00
|
|
|
|
/* $OpenBSD: sh.h,v 1.31 2012/09/10 01:25:30 tedu Exp $ */
|
2006-01-29 21:04:54 +01:00
|
|
|
|
/* $OpenBSD: shf.h,v 1.6 2005/12/11 18:53:51 deraadt Exp $ */
|
2012-03-03 22:30:59 +01:00
|
|
|
|
/* $OpenBSD: table.h,v 1.8 2012/02/19 07:52:30 otto Exp $ */
|
2005-05-23 05:06:10 +02:00
|
|
|
|
/* $OpenBSD: tree.h,v 1.10 2005/03/28 21:28:22 deraadt Exp $ */
|
|
|
|
|
/* $OpenBSD: expand.h,v 1.6 2005/03/30 17:16:37 deraadt Exp $ */
|
2013-06-01 02:15:58 +02:00
|
|
|
|
/* $OpenBSD: lex.h,v 1.13 2013/03/03 19:11:34 guenther Exp $ */
|
2012-06-28 22:01:01 +02:00
|
|
|
|
/* $OpenBSD: proto.h,v 1.34 2012/06/27 07:17:19 otto Exp $ */
|
2005-05-23 05:06:10 +02:00
|
|
|
|
/* $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 $ */
|
|
|
|
|
|
2009-05-16 18:59:42 +02:00
|
|
|
|
/*-
|
2012-01-03 01:58:09 +01:00
|
|
|
|
* Copyright © 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
|
2013-01-01 21:45:04 +01:00
|
|
|
|
* 2011, 2012, 2013
|
2009-05-16 18:59:42 +02:00
|
|
|
|
* Thorsten Glaser <tg@mirbsd.org>
|
|
|
|
|
*
|
|
|
|
|
* Provided that these terms and disclaimer and all copyright notices
|
|
|
|
|
* are retained or reproduced in an accompanying document, permission
|
2011-07-07 00:22:02 +02:00
|
|
|
|
* is granted to deal in this work without restriction, including un‐
|
2009-05-16 18:59:42 +02:00
|
|
|
|
* limited rights to use, publicly perform, distribute, sell, modify,
|
|
|
|
|
* merge, give away, or sublicence.
|
|
|
|
|
*
|
2011-07-07 00:22:02 +02:00
|
|
|
|
* This work is provided “AS IS” and WITHOUT WARRANTY of any kind, to
|
2009-05-16 18:59:42 +02:00
|
|
|
|
* the utmost extent permitted by applicable law, neither express nor
|
|
|
|
|
* implied; without malicious intent or gross negligence. In no event
|
|
|
|
|
* may a licensor, author or contributor be held liable for indirect,
|
|
|
|
|
* direct, other damage, loss, or other issues arising in any way out
|
|
|
|
|
* of dealing in the work, even if advised of the possibility of such
|
|
|
|
|
* damage or existence of a defect, except proven that it results out
|
2011-07-07 00:22:02 +02:00
|
|
|
|
* of said person’s immediate fault when using the work as intended.
|
2009-05-16 18:59:42 +02:00
|
|
|
|
*/
|
|
|
|
|
|
2008-05-17 22:10:52 +02:00
|
|
|
|
#ifdef __dietlibc__
|
2009-07-25 23:31:27 +02:00
|
|
|
|
/* XXX imake style */
|
2011-07-07 00:22:02 +02:00
|
|
|
|
#define _BSD_SOURCE /* live, BSD, live❣ */
|
2008-05-17 22:10:52 +02:00
|
|
|
|
#endif
|
|
|
|
|
|
2006-11-09 01:11:39 +01:00
|
|
|
|
#if HAVE_SYS_PARAM_H
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
|
#endif
|
|
|
|
|
#include <sys/types.h>
|
2012-12-17 22:55:06 +01:00
|
|
|
|
#if HAVE_BOTH_TIME_H
|
2005-10-25 21:53:29 +02:00
|
|
|
|
#include <sys/time.h>
|
2012-12-17 22:55:06 +01:00
|
|
|
|
#include <time.h>
|
|
|
|
|
#elif HAVE_SYS_TIME_H
|
|
|
|
|
#include <sys/time.h>
|
|
|
|
|
#elif HAVE_TIME_H
|
|
|
|
|
#include <time.h>
|
|
|
|
|
#endif
|
2005-10-25 21:53:29 +02:00
|
|
|
|
#include <sys/ioctl.h>
|
2007-06-05 21:35:13 +02:00
|
|
|
|
#if HAVE_SYS_SYSMACROS_H
|
|
|
|
|
#include <sys/sysmacros.h>
|
|
|
|
|
#endif
|
2007-01-18 16:50:32 +01:00
|
|
|
|
#if HAVE_SYS_MKDEV_H
|
|
|
|
|
#include <sys/mkdev.h>
|
|
|
|
|
#endif
|
2007-03-04 05:36:45 +01:00
|
|
|
|
#if HAVE_SYS_MMAN_H
|
2005-10-25 21:53:29 +02:00
|
|
|
|
#include <sys/mman.h>
|
2007-03-04 05:36:45 +01:00
|
|
|
|
#endif
|
2012-12-17 22:55:06 +01:00
|
|
|
|
#if HAVE_SYS_RESOURCE_H
|
2005-10-25 21:53:29 +02:00
|
|
|
|
#include <sys/resource.h>
|
2012-12-17 22:55:06 +01:00
|
|
|
|
#endif
|
2005-10-25 21:53:29 +02:00
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
#include <sys/wait.h>
|
|
|
|
|
#include <dirent.h>
|
2005-05-23 05:06:10 +02:00
|
|
|
|
#include <errno.h>
|
|
|
|
|
#include <fcntl.h>
|
2007-01-17 23:51:47 +01:00
|
|
|
|
#if HAVE_LIBGEN_H
|
2005-10-25 21:53:29 +02:00
|
|
|
|
#include <libgen.h>
|
2007-01-17 23:51:47 +01:00
|
|
|
|
#endif
|
2007-07-01 23:47:08 +02:00
|
|
|
|
#if HAVE_LIBUTIL_H
|
|
|
|
|
#include <libutil.h>
|
|
|
|
|
#endif
|
2005-05-23 05:06:10 +02:00
|
|
|
|
#include <limits.h>
|
2007-01-18 16:50:32 +01:00
|
|
|
|
#if HAVE_PATHS_H
|
2005-05-23 05:06:10 +02:00
|
|
|
|
#include <paths.h>
|
|
|
|
|
#endif
|
2005-10-25 21:53:29 +02:00
|
|
|
|
#include <pwd.h>
|
2005-05-23 05:06:10 +02:00
|
|
|
|
#include <setjmp.h>
|
|
|
|
|
#include <signal.h>
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
#include <stddef.h>
|
2007-03-04 05:36:45 +01:00
|
|
|
|
#if HAVE_STDINT_H
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
#endif
|
2005-05-23 05:06:10 +02:00
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
2008-11-02 23:29:36 +01:00
|
|
|
|
#if HAVE_STRINGS_H
|
|
|
|
|
#include <strings.h>
|
|
|
|
|
#endif
|
2012-05-05 00:18:27 +02:00
|
|
|
|
#if HAVE_TERMIOS_H
|
2005-05-23 05:06:10 +02:00
|
|
|
|
#include <termios.h>
|
2012-05-05 00:18:27 +02:00
|
|
|
|
#else
|
2012-05-05 00:44:34 +02:00
|
|
|
|
/* shudder… */
|
2012-05-05 00:18:27 +02:00
|
|
|
|
#include <termio.h>
|
|
|
|
|
#endif
|
2012-12-18 00:18:11 +01:00
|
|
|
|
#ifdef _ISC_UNIX
|
|
|
|
|
/* XXX imake style */
|
|
|
|
|
#include <sys/sioctl.h>
|
|
|
|
|
#endif
|
2007-01-18 16:50:32 +01:00
|
|
|
|
#if HAVE_ULIMIT_H
|
2006-08-23 00:49:38 +02:00
|
|
|
|
#include <ulimit.h>
|
|
|
|
|
#endif
|
2007-01-18 16:50:32 +01:00
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#if HAVE_VALUES_H
|
2006-08-23 00:49:38 +02:00
|
|
|
|
#include <values.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2007-06-04 23:27:53 +02:00
|
|
|
|
#undef __attribute__
|
2009-12-12 23:27:10 +01:00
|
|
|
|
#if HAVE_ATTRIBUTE_BOUNDED
|
2011-04-09 23:01:03 +02:00
|
|
|
|
#define MKSH_A_BOUNDED(x,y,z) __attribute__((__bounded__ (x, y, z)))
|
2007-06-04 23:27:53 +02:00
|
|
|
|
#else
|
2009-12-12 23:27:10 +01:00
|
|
|
|
#define MKSH_A_BOUNDED(x,y,z) /* nothing */
|
2007-06-04 23:27:53 +02:00
|
|
|
|
#endif
|
2009-12-12 23:27:10 +01:00
|
|
|
|
#if HAVE_ATTRIBUTE_FORMAT
|
2011-04-09 23:01:03 +02:00
|
|
|
|
#define MKSH_A_FORMAT(x,y,z) __attribute__((__format__ (x, y, z)))
|
2009-12-12 23:27:10 +01:00
|
|
|
|
#else
|
|
|
|
|
#define MKSH_A_FORMAT(x,y,z) /* nothing */
|
|
|
|
|
#endif
|
|
|
|
|
#if HAVE_ATTRIBUTE_NORETURN
|
2011-04-09 23:01:03 +02:00
|
|
|
|
#define MKSH_A_NORETURN __attribute__((__noreturn__))
|
2009-12-12 23:27:10 +01:00
|
|
|
|
#else
|
|
|
|
|
#define MKSH_A_NORETURN /* nothing */
|
|
|
|
|
#endif
|
|
|
|
|
#if HAVE_ATTRIBUTE_UNUSED
|
2011-04-09 23:01:03 +02:00
|
|
|
|
#define MKSH_A_UNUSED __attribute__((__unused__))
|
2007-06-04 23:27:53 +02:00
|
|
|
|
#else
|
2009-12-12 23:27:10 +01:00
|
|
|
|
#define MKSH_A_UNUSED /* nothing */
|
2007-06-04 23:27:53 +02:00
|
|
|
|
#endif
|
|
|
|
|
#if HAVE_ATTRIBUTE_USED
|
2011-04-09 23:01:03 +02:00
|
|
|
|
#define MKSH_A_USED __attribute__((__used__))
|
2007-06-04 23:27:53 +02:00
|
|
|
|
#else
|
2009-12-12 23:27:10 +01:00
|
|
|
|
#define MKSH_A_USED /* nothing */
|
2007-06-04 23:27:53 +02:00
|
|
|
|
#endif
|
|
|
|
|
|
2010-01-28 16:13:25 +01:00
|
|
|
|
#if defined(MirBSD) && (MirBSD >= 0x09A1) && \
|
|
|
|
|
defined(__ELF__) && defined(__GNUC__) && \
|
|
|
|
|
!defined(__llvm__) && !defined(__NWCC__)
|
2009-07-30 20:42:31 +02:00
|
|
|
|
/*
|
|
|
|
|
* We got usable __IDSTRING __COPYRIGHT __RCSID __SCCSID macros
|
|
|
|
|
* which work for all cases; no need to redefine them using the
|
|
|
|
|
* "portable" macros from below when we might have the "better"
|
|
|
|
|
* gcc+ELF specific macros or other system dependent ones.
|
|
|
|
|
*/
|
|
|
|
|
#else
|
2007-06-04 23:27:53 +02:00
|
|
|
|
#undef __IDSTRING
|
|
|
|
|
#undef __IDSTRING_CONCAT
|
|
|
|
|
#undef __IDSTRING_EXPAND
|
2009-07-30 20:42:31 +02:00
|
|
|
|
#undef __COPYRIGHT
|
2007-06-04 23:27:53 +02:00
|
|
|
|
#undef __RCSID
|
|
|
|
|
#undef __SCCSID
|
|
|
|
|
#define __IDSTRING_CONCAT(l,p) __LINTED__ ## l ## _ ## p
|
|
|
|
|
#define __IDSTRING_EXPAND(l,p) __IDSTRING_CONCAT(l,p)
|
2010-09-14 23:15:11 +02:00
|
|
|
|
#ifdef MKSH_DONT_EMIT_IDSTRING
|
|
|
|
|
#define __IDSTRING(prefix, string) /* nothing */
|
|
|
|
|
#else
|
2007-06-04 23:27:53 +02:00
|
|
|
|
#define __IDSTRING(prefix, string) \
|
|
|
|
|
static const char __IDSTRING_EXPAND(__LINE__,prefix) [] \
|
2009-12-12 23:27:10 +01:00
|
|
|
|
MKSH_A_USED = "@(""#)" #prefix ": " string
|
2010-09-14 23:15:11 +02:00
|
|
|
|
#endif
|
2009-07-30 20:42:31 +02:00
|
|
|
|
#define __COPYRIGHT(x) __IDSTRING(copyright,x)
|
|
|
|
|
#define __RCSID(x) __IDSTRING(rcsid,x)
|
|
|
|
|
#define __SCCSID(x) __IDSTRING(sccsid,x)
|
|
|
|
|
#endif
|
2007-06-04 23:27:53 +02:00
|
|
|
|
|
2008-04-22 20:57:26 +02:00
|
|
|
|
#ifdef EXTERN
|
2013-07-24 20:03:57 +02:00
|
|
|
|
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.661 2013/07/24 18:03:57 tg Exp $");
|
2008-04-22 20:57:26 +02:00
|
|
|
|
#endif
|
2013-07-24 20:03:57 +02:00
|
|
|
|
#define MKSH_VERSION "R47 2013/07/24"
|
2008-04-22 20:57:26 +02:00
|
|
|
|
|
2012-01-03 01:58:09 +01:00
|
|
|
|
/* arithmetic types: C implementation */
|
|
|
|
|
#if !HAVE_CAN_INTTYPES
|
|
|
|
|
#if !HAVE_CAN_UCBINTS
|
|
|
|
|
typedef signed int int32_t;
|
|
|
|
|
typedef unsigned int uint32_t;
|
|
|
|
|
#else
|
|
|
|
|
typedef u_int32_t uint32_t;
|
|
|
|
|
#endif
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/* arithmetic types: shell arithmetics */
|
2012-06-28 22:17:39 +02:00
|
|
|
|
#ifdef MKSH_LEGACY_MODE
|
2012-03-28 00:49:47 +02:00
|
|
|
|
/*
|
2012-06-28 22:17:39 +02:00
|
|
|
|
* POSIX demands these to be the C environment's long type
|
|
|
|
|
*/
|
|
|
|
|
typedef long mksh_ari_t;
|
|
|
|
|
typedef unsigned long mksh_uari_t;
|
|
|
|
|
#else
|
|
|
|
|
/*
|
|
|
|
|
* These types are exactly 32 bit wide; signed and unsigned
|
|
|
|
|
* integer wraparound, even across division and modulo, for
|
|
|
|
|
* any shell code using them, is guaranteed.
|
2012-03-28 00:49:47 +02:00
|
|
|
|
*/
|
2011-12-03 01:01:28 +01:00
|
|
|
|
typedef int32_t mksh_ari_t;
|
|
|
|
|
typedef uint32_t mksh_uari_t;
|
2012-06-28 22:17:39 +02:00
|
|
|
|
#endif
|
2011-12-03 01:01:28 +01:00
|
|
|
|
|
|
|
|
|
/* boolean type (no <stdbool.h> deliberately) */
|
|
|
|
|
typedef unsigned char mksh_bool;
|
|
|
|
|
#undef bool
|
2011-12-31 01:27:27 +01:00
|
|
|
|
/* false MUST equal the same 0 as written by static storage initialisation */
|
2011-12-03 01:01:28 +01:00
|
|
|
|
#undef false
|
|
|
|
|
#undef true
|
|
|
|
|
/* access macros for boolean type */
|
|
|
|
|
#define bool mksh_bool
|
|
|
|
|
/* values must have identity mapping between mksh_bool and short */
|
|
|
|
|
#define false 0
|
|
|
|
|
#define true 1
|
|
|
|
|
/* make any-type into bool or short */
|
|
|
|
|
#define tobool(cond) ((cond) ? true : false)
|
|
|
|
|
|
2012-01-03 01:58:09 +01:00
|
|
|
|
/* char (octet) type: C implementation */
|
|
|
|
|
#if !HAVE_CAN_INT8TYPE
|
|
|
|
|
#if !HAVE_CAN_UCBINT8
|
|
|
|
|
typedef unsigned char uint8_t;
|
|
|
|
|
#else
|
|
|
|
|
typedef u_int8_t uint8_t;
|
|
|
|
|
#endif
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/* other standard types */
|
|
|
|
|
|
|
|
|
|
#if !HAVE_RLIM_T
|
2012-03-26 23:10:44 +02:00
|
|
|
|
typedef unsigned long rlim_t;
|
2012-01-03 01:58:09 +01:00
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#if !HAVE_SIG_T
|
|
|
|
|
#undef sig_t
|
|
|
|
|
typedef void (*sig_t)(int);
|
|
|
|
|
#endif
|
|
|
|
|
|
2012-04-14 16:02:40 +02:00
|
|
|
|
#ifdef MKSH_TYPEDEF_SIG_ATOMIC_T
|
|
|
|
|
typedef MKSH_TYPEDEF_SIG_ATOMIC_T sig_atomic_t;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifdef MKSH_TYPEDEF_SSIZE_T
|
|
|
|
|
typedef MKSH_TYPEDEF_SSIZE_T ssize_t;
|
|
|
|
|
#endif
|
|
|
|
|
|
2012-03-28 00:41:17 +02:00
|
|
|
|
/* un-do vendor damage */
|
|
|
|
|
|
|
|
|
|
#undef BAD /* AIX defines that somewhere */
|
2012-04-06 13:51:43 +02:00
|
|
|
|
#undef PRINT /* LynxOS defines that somewhere */
|
2012-03-28 00:41:17 +02:00
|
|
|
|
#undef flock /* SCO UnixWare defines that to flock64 but ENOENT */
|
|
|
|
|
|
|
|
|
|
|
2007-04-23 22:37:16 +02:00
|
|
|
|
#ifndef MKSH_INCLUDES_ONLY
|
|
|
|
|
|
2007-01-18 00:18:55 +01:00
|
|
|
|
/* extra types */
|
|
|
|
|
|
2009-04-03 11:39:07 +02:00
|
|
|
|
#if !HAVE_GETRUSAGE
|
|
|
|
|
#undef rusage
|
|
|
|
|
#undef RUSAGE_SELF
|
|
|
|
|
#undef RUSAGE_CHILDREN
|
|
|
|
|
#define rusage mksh_rusage
|
2011-08-27 19:30:07 +02:00
|
|
|
|
#define RUSAGE_SELF 0
|
|
|
|
|
#define RUSAGE_CHILDREN -1
|
2009-04-03 11:39:07 +02:00
|
|
|
|
|
|
|
|
|
struct rusage {
|
|
|
|
|
struct timeval ru_utime;
|
|
|
|
|
struct timeval ru_stime;
|
|
|
|
|
};
|
|
|
|
|
#endif
|
|
|
|
|
|
2006-08-23 00:49:38 +02:00
|
|
|
|
/* extra macros */
|
|
|
|
|
|
2007-07-24 23:47:14 +02:00
|
|
|
|
#ifndef timerclear
|
2008-12-13 18:02:18 +01:00
|
|
|
|
#define timerclear(tvp) \
|
|
|
|
|
do { \
|
|
|
|
|
(tvp)->tv_sec = (tvp)->tv_usec = 0; \
|
|
|
|
|
} while (/* CONSTCOND */ 0)
|
2007-07-24 23:47:14 +02:00
|
|
|
|
#endif
|
2006-08-23 00:49:38 +02:00
|
|
|
|
#ifndef timeradd
|
2006-11-16 14:35:00 +01:00
|
|
|
|
#define timeradd(tvp, uvp, vvp) \
|
2006-08-23 00:49:38 +02:00
|
|
|
|
do { \
|
|
|
|
|
(vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec; \
|
|
|
|
|
(vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec; \
|
|
|
|
|
if ((vvp)->tv_usec >= 1000000) { \
|
|
|
|
|
(vvp)->tv_sec++; \
|
|
|
|
|
(vvp)->tv_usec -= 1000000; \
|
|
|
|
|
} \
|
2008-12-13 18:02:18 +01:00
|
|
|
|
} while (/* CONSTCOND */ 0)
|
2006-08-23 00:49:38 +02:00
|
|
|
|
#endif
|
|
|
|
|
#ifndef timersub
|
2006-11-16 14:35:00 +01:00
|
|
|
|
#define timersub(tvp, uvp, vvp) \
|
2006-08-23 00:49:38 +02:00
|
|
|
|
do { \
|
|
|
|
|
(vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec; \
|
|
|
|
|
(vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec; \
|
|
|
|
|
if ((vvp)->tv_usec < 0) { \
|
|
|
|
|
(vvp)->tv_sec--; \
|
|
|
|
|
(vvp)->tv_usec += 1000000; \
|
|
|
|
|
} \
|
2008-12-13 18:02:18 +01:00
|
|
|
|
} while (/* CONSTCOND */ 0)
|
2006-08-23 00:49:38 +02:00
|
|
|
|
#endif
|
|
|
|
|
|
2006-11-10 07:53:27 +01:00
|
|
|
|
#define ksh_isdigit(c) (((c) >= '0') && ((c) <= '9'))
|
|
|
|
|
#define ksh_islower(c) (((c) >= 'a') && ((c) <= 'z'))
|
|
|
|
|
#define ksh_isupper(c) (((c) >= 'A') && ((c) <= 'Z'))
|
|
|
|
|
#define ksh_tolower(c) (((c) >= 'A') && ((c) <= 'Z') ? (c) - 'A' + 'a' : (c))
|
|
|
|
|
#define ksh_toupper(c) (((c) >= 'a') && ((c) <= 'z') ? (c) - 'a' + 'A' : (c))
|
• remove strcasestr.c, use home-grown implementation¹, call it stricmp,
and have it return an API-correct const char *
• enhance and stylify comments
• a little KNF and simplifications
• #ifdef DEBUG: replace strchr and strstr with ucstrchr and ucstrstr
that take and return a non-const char *, and fix the violations
• new cstrchr, cstrstr (take and give const char *)
• new vstrchr, vstrstr (take const or not, give boolean value)
• new afreechk(x) = afreechv(x,x) = if (x1) afree(x2, ATEMP)
• new ksh_isdash(str) = (str != NULL) && !strcmp(str, "-")
• replace the only use of strrchr with inlined code to shrink
• minor man page fixes
• Minix 3 signames are autogenerated with gcc
• rename strlfun.c to strlcpy.c since we don't do strlcat(3) anyway,
only strlcpy(3), and shorten it
• dot.mkshrc: move MKSH=… down to the export line
to not disturb the PS1 visual impression ☺
• dot.mkshrc: Lstripcom(): optimise
• bump version
¹) side effect from creating API-correct cstrchr, cstrstr, etc.
uses goto so it must be better ☻
tested on mirbsd-current via both Makefile and Build.sh
2007-03-04 04:04:28 +01:00
|
|
|
|
#define ksh_isdash(s) (((s) != NULL) && ((s)[0] == '-') && ((s)[1] == '\0'))
|
2008-10-28 15:32:43 +01:00
|
|
|
|
#define ksh_isspace(c) ((((c) >= 0x09) && ((c) <= 0x0D)) || ((c) == 0x20))
|
2012-10-21 23:39:06 +02:00
|
|
|
|
#define ksh_min(x,y) ((x) < (y) ? (x) : (y))
|
|
|
|
|
#define ksh_max(x,y) ((x) > (y) ? (x) : (y))
|
2006-11-10 08:18:58 +01:00
|
|
|
|
|
2012-05-05 19:37:44 +02:00
|
|
|
|
#ifdef MKSH__NO_PATH_MAX
|
2009-10-27 18:00:02 +01:00
|
|
|
|
#undef PATH_MAX
|
|
|
|
|
#else
|
2008-05-17 20:27:57 +02:00
|
|
|
|
#ifndef PATH_MAX
|
|
|
|
|
#define PATH_MAX 1024
|
|
|
|
|
#endif
|
2009-10-27 18:00:02 +01:00
|
|
|
|
#endif
|
2009-04-07 20:46:07 +02:00
|
|
|
|
#ifndef SIZE_MAX
|
|
|
|
|
#ifdef SIZE_T_MAX
|
|
|
|
|
#define SIZE_MAX SIZE_T_MAX
|
|
|
|
|
#else
|
|
|
|
|
#define SIZE_MAX ((size_t)-1)
|
|
|
|
|
#endif
|
|
|
|
|
#endif
|
2008-03-25 22:34:45 +01:00
|
|
|
|
#ifndef S_ISLNK
|
|
|
|
|
#define S_ISLNK(m) ((m & 0170000) == 0120000)
|
|
|
|
|
#endif
|
2007-03-04 06:14:10 +01:00
|
|
|
|
#ifndef S_ISSOCK
|
|
|
|
|
#define S_ISSOCK(m) ((m & 0170000) == 0140000)
|
|
|
|
|
#endif
|
2011-03-27 03:30:38 +02:00
|
|
|
|
#if !defined(S_ISCDF) && defined(S_CDF)
|
|
|
|
|
#define S_ISCDF(m) (S_ISDIR(m) && ((m) & S_CDF))
|
|
|
|
|
#endif
|
2006-11-09 00:23:41 +01:00
|
|
|
|
#ifndef DEFFILEMODE
|
• remove strcasestr.c, use home-grown implementation¹, call it stricmp,
and have it return an API-correct const char *
• enhance and stylify comments
• a little KNF and simplifications
• #ifdef DEBUG: replace strchr and strstr with ucstrchr and ucstrstr
that take and return a non-const char *, and fix the violations
• new cstrchr, cstrstr (take and give const char *)
• new vstrchr, vstrstr (take const or not, give boolean value)
• new afreechk(x) = afreechv(x,x) = if (x1) afree(x2, ATEMP)
• new ksh_isdash(str) = (str != NULL) && !strcmp(str, "-")
• replace the only use of strrchr with inlined code to shrink
• minor man page fixes
• Minix 3 signames are autogenerated with gcc
• rename strlfun.c to strlcpy.c since we don't do strlcat(3) anyway,
only strlcpy(3), and shorten it
• dot.mkshrc: move MKSH=… down to the export line
to not disturb the PS1 visual impression ☺
• dot.mkshrc: Lstripcom(): optimise
• bump version
¹) side effect from creating API-correct cstrchr, cstrstr, etc.
uses goto so it must be better ☻
tested on mirbsd-current via both Makefile and Build.sh
2007-03-04 04:04:28 +01:00
|
|
|
|
#define DEFFILEMODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)
|
2006-11-09 00:23:41 +01:00
|
|
|
|
#endif
|
2006-08-23 00:49:38 +02:00
|
|
|
|
|
2007-03-04 06:04:54 +01:00
|
|
|
|
#ifndef NSIG
|
2008-03-05 19:21:45 +01:00
|
|
|
|
#if defined(_NSIG)
|
2007-03-04 06:04:54 +01:00
|
|
|
|
#define NSIG _NSIG
|
2008-03-05 19:21:45 +01:00
|
|
|
|
#elif defined(SIGMAX)
|
|
|
|
|
#define NSIG (SIGMAX+1)
|
2012-12-28 04:35:34 +01:00
|
|
|
|
#elif defined(_SIGMAX)
|
|
|
|
|
#define NSIG (_SIGMAX+1)
|
2008-03-05 19:21:45 +01:00
|
|
|
|
#endif
|
2007-03-04 06:04:54 +01:00
|
|
|
|
#endif
|
|
|
|
|
|
2007-04-23 16:04:38 +02:00
|
|
|
|
|
2007-04-24 12:42:02 +02:00
|
|
|
|
/* OS-dependent additions (functions, variables, by OS) */
|
|
|
|
|
|
2008-03-05 19:49:15 +01:00
|
|
|
|
#if !HAVE_FLOCK_DECL
|
|
|
|
|
extern int flock(int, int);
|
|
|
|
|
#endif
|
|
|
|
|
|
2012-11-20 19:50:46 +01:00
|
|
|
|
#if !HAVE_GETTIMEOFDAY
|
|
|
|
|
#define mksh_TIME(tv) do { \
|
|
|
|
|
(tv).tv_usec = 0; \
|
|
|
|
|
(tv).tv_sec = time(NULL); \
|
|
|
|
|
} while (/* CONSTCOND */ 0)
|
|
|
|
|
#else
|
|
|
|
|
#define mksh_TIME(tv) gettimeofday(&(tv), NULL)
|
|
|
|
|
#endif
|
|
|
|
|
|
2009-04-03 11:39:07 +02:00
|
|
|
|
#if !HAVE_GETRUSAGE
|
|
|
|
|
extern int getrusage(int, struct rusage *);
|
|
|
|
|
#endif
|
|
|
|
|
|
2012-12-17 23:14:27 +01:00
|
|
|
|
#if !HAVE_MEMMOVE
|
|
|
|
|
/* we assume either memmove or bcopy exist, at the moment */
|
|
|
|
|
#define memmove(dst, src, len) bcopy((src), (dst), (len))
|
|
|
|
|
#endif
|
|
|
|
|
|
2008-03-05 18:06:50 +01:00
|
|
|
|
#if !HAVE_REVOKE_DECL
|
|
|
|
|
extern int revoke(const char *);
|
|
|
|
|
#endif
|
|
|
|
|
|
2012-12-18 00:18:11 +01:00
|
|
|
|
#if defined(DEBUG) || !HAVE_STRERROR
|
2013-04-26 19:23:15 +02:00
|
|
|
|
#undef strerror
|
2012-12-22 23:15:21 +01:00
|
|
|
|
#define strerror /* poisoned */ dontuse_strerror
|
|
|
|
|
#define cstrerror /* replaced */ cstrerror
|
2012-12-18 00:18:11 +01:00
|
|
|
|
extern const char *cstrerror(int);
|
|
|
|
|
#else
|
|
|
|
|
#define cstrerror(errnum) ((const char *)strerror(errnum))
|
2012-12-17 23:14:27 +01:00
|
|
|
|
#endif
|
|
|
|
|
|
2006-11-09 00:50:47 +01:00
|
|
|
|
#if !HAVE_STRLCPY
|
2006-08-23 00:49:38 +02:00
|
|
|
|
size_t strlcpy(char *, const char *, size_t);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifdef __INTERIX
|
2009-07-25 23:31:27 +02:00
|
|
|
|
/* XXX imake style */
|
2007-01-18 16:50:32 +01:00
|
|
|
|
#define makedev mkdev
|
2006-08-23 00:49:38 +02:00
|
|
|
|
extern int __cdecl seteuid(uid_t);
|
|
|
|
|
extern int __cdecl setegid(gid_t);
|
|
|
|
|
#endif
|
2005-05-23 05:06:10 +02:00
|
|
|
|
|
2012-05-04 23:47:04 +02:00
|
|
|
|
#if defined(__COHERENT__)
|
2012-05-05 00:18:27 +02:00
|
|
|
|
#ifndef O_ACCMODE
|
|
|
|
|
/* this need not work everywhere, take care */
|
|
|
|
|
#define O_ACCMODE (O_RDONLY | O_WRONLY | O_RDWR)
|
|
|
|
|
#endif
|
2012-05-04 23:47:04 +02:00
|
|
|
|
#endif
|
|
|
|
|
|
2012-05-05 00:05:02 +02:00
|
|
|
|
#ifdef MKSH__NO_SYMLINK
|
|
|
|
|
#undef S_ISLNK
|
|
|
|
|
#define S_ISLNK(m) (/* CONSTCOND */ 0)
|
|
|
|
|
#define mksh_lstat stat
|
|
|
|
|
#else
|
|
|
|
|
#define mksh_lstat lstat
|
|
|
|
|
#endif
|
|
|
|
|
|
2012-05-05 00:18:27 +02:00
|
|
|
|
#if HAVE_TERMIOS_H
|
|
|
|
|
#define mksh_ttyst struct termios
|
|
|
|
|
#define mksh_tcget(fd,st) tcgetattr((fd), (st))
|
|
|
|
|
#define mksh_tcset(fd,st) tcsetattr((fd), TCSADRAIN, (st))
|
|
|
|
|
#else
|
|
|
|
|
#define mksh_ttyst struct termio
|
|
|
|
|
#define mksh_tcget(fd,st) ioctl((fd), TCGETA, (st))
|
|
|
|
|
#define mksh_tcset(fd,st) ioctl((fd), TCSETAW, (st))
|
|
|
|
|
#endif
|
|
|
|
|
|
2012-04-06 17:23:11 +02:00
|
|
|
|
/* remove redundancies */
|
2010-08-14 23:35:13 +02:00
|
|
|
|
|
2013-06-01 01:27:14 +02:00
|
|
|
|
#if defined(MirBSD) && (MirBSD >= 0x0AB3) && !defined(MKSH_OPTSTATIC)
|
2010-08-14 23:35:13 +02:00
|
|
|
|
#define MKSH_mirbsd_wcwidth
|
|
|
|
|
#define utf_wcwidth(i) wcwidth((__WCHAR_TYPE__)i)
|
|
|
|
|
extern int wcwidth(__WCHAR_TYPE__);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
2005-05-23 05:06:10 +02:00
|
|
|
|
/* some useful #defines */
|
|
|
|
|
#ifdef EXTERN
|
2011-09-07 17:24:22 +02:00
|
|
|
|
# define E_INIT(i) = i
|
2005-05-23 05:06:10 +02:00
|
|
|
|
#else
|
2011-09-07 17:24:22 +02:00
|
|
|
|
# define E_INIT(i)
|
2005-05-23 05:06:10 +02:00
|
|
|
|
# define EXTERN extern
|
|
|
|
|
# define EXTERN_DEFINED
|
|
|
|
|
#endif
|
2006-08-23 00:21:20 +02:00
|
|
|
|
|
2011-06-21 23:10:12 +02:00
|
|
|
|
/* define bit in flag */
|
|
|
|
|
#define BIT(i) (1 << (i))
|
2009-06-08 22:06:50 +02:00
|
|
|
|
#define NELEM(a) (sizeof(a) / sizeof((a)[0]))
|
2005-05-23 05:06:10 +02:00
|
|
|
|
|
2011-06-21 23:10:12 +02:00
|
|
|
|
/*
|
|
|
|
|
* Make MAGIC a char that might be printed to make bugs more obvious, but
|
2006-08-23 00:16:04 +02:00
|
|
|
|
* not a char that is used often. Also, can't use the high bit as it causes
|
2012-03-28 00:58:39 +02:00
|
|
|
|
* portability problems (calling strchr(x, 0x80 | 'x') is error prone).
|
2005-05-23 05:06:10 +02:00
|
|
|
|
*/
|
2006-11-16 14:35:00 +01:00
|
|
|
|
#define MAGIC (7) /* prefix for *?[!{,} during expand */
|
2005-05-23 05:06:10 +02:00
|
|
|
|
#define ISMAGIC(c) ((unsigned char)(c) == MAGIC)
|
|
|
|
|
|
2006-11-16 14:35:00 +01:00
|
|
|
|
#define LINE 4096 /* input line size */
|
2005-05-23 05:06:10 +02:00
|
|
|
|
|
• remove strcasestr.c, use home-grown implementation¹, call it stricmp,
and have it return an API-correct const char *
• enhance and stylify comments
• a little KNF and simplifications
• #ifdef DEBUG: replace strchr and strstr with ucstrchr and ucstrstr
that take and return a non-const char *, and fix the violations
• new cstrchr, cstrstr (take and give const char *)
• new vstrchr, vstrstr (take const or not, give boolean value)
• new afreechk(x) = afreechv(x,x) = if (x1) afree(x2, ATEMP)
• new ksh_isdash(str) = (str != NULL) && !strcmp(str, "-")
• replace the only use of strrchr with inlined code to shrink
• minor man page fixes
• Minix 3 signames are autogenerated with gcc
• rename strlfun.c to strlcpy.c since we don't do strlcat(3) anyway,
only strlcpy(3), and shorten it
• dot.mkshrc: move MKSH=… down to the export line
to not disturb the PS1 visual impression ☺
• dot.mkshrc: Lstripcom(): optimise
• bump version
¹) side effect from creating API-correct cstrchr, cstrstr, etc.
uses goto so it must be better ☻
tested on mirbsd-current via both Makefile and Build.sh
2007-03-04 04:04:28 +01:00
|
|
|
|
EXTERN const char *safe_prompt; /* safe prompt if PS1 substitution fails */
|
2012-06-25 18:05:10 +02:00
|
|
|
|
|
|
|
|
|
#ifdef MKSH_LEGACY_MODE
|
|
|
|
|
#define KSH_VERSIONNAME "LEGACY"
|
|
|
|
|
#else
|
|
|
|
|
#define KSH_VERSIONNAME "MIRBSD"
|
|
|
|
|
#endif
|
|
|
|
|
EXTERN const char initvsn[] E_INIT("KSH_VERSION=@(#)" KSH_VERSIONNAME \
|
|
|
|
|
" KSH " MKSH_VERSION);
|
• remove strcasestr.c, use home-grown implementation¹, call it stricmp,
and have it return an API-correct const char *
• enhance and stylify comments
• a little KNF and simplifications
• #ifdef DEBUG: replace strchr and strstr with ucstrchr and ucstrstr
that take and return a non-const char *, and fix the violations
• new cstrchr, cstrstr (take and give const char *)
• new vstrchr, vstrstr (take const or not, give boolean value)
• new afreechk(x) = afreechv(x,x) = if (x1) afree(x2, ATEMP)
• new ksh_isdash(str) = (str != NULL) && !strcmp(str, "-")
• replace the only use of strrchr with inlined code to shrink
• minor man page fixes
• Minix 3 signames are autogenerated with gcc
• rename strlfun.c to strlcpy.c since we don't do strlcat(3) anyway,
only strlcpy(3), and shorten it
• dot.mkshrc: move MKSH=… down to the export line
to not disturb the PS1 visual impression ☺
• dot.mkshrc: Lstripcom(): optimise
• bump version
¹) side effect from creating API-correct cstrchr, cstrstr, etc.
uses goto so it must be better ☻
tested on mirbsd-current via both Makefile and Build.sh
2007-03-04 04:04:28 +01:00
|
|
|
|
#define KSH_VERSION (initvsn + /* "KSH_VERSION=@(#)" */ 16)
|
2005-05-23 05:06:10 +02:00
|
|
|
|
|
2011-09-07 17:24:22 +02:00
|
|
|
|
EXTERN const char digits_uc[] E_INIT("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ");
|
|
|
|
|
EXTERN const char digits_lc[] E_INIT("0123456789abcdefghijklmnopqrstuvwxyz");
|
2009-09-20 15:08:12 +02:00
|
|
|
|
|
2007-03-04 01:13:17 +01:00
|
|
|
|
/*
|
|
|
|
|
* Evil hack for const correctness due to API brokenness
|
|
|
|
|
*/
|
|
|
|
|
union mksh_cchack {
|
|
|
|
|
char *rw;
|
|
|
|
|
const char *ro;
|
|
|
|
|
};
|
|
|
|
|
union mksh_ccphack {
|
|
|
|
|
char **rw;
|
|
|
|
|
const char **ro;
|
|
|
|
|
};
|
• remove strcasestr.c, use home-grown implementation¹, call it stricmp,
and have it return an API-correct const char *
• enhance and stylify comments
• a little KNF and simplifications
• #ifdef DEBUG: replace strchr and strstr with ucstrchr and ucstrstr
that take and return a non-const char *, and fix the violations
• new cstrchr, cstrstr (take and give const char *)
• new vstrchr, vstrstr (take const or not, give boolean value)
• new afreechk(x) = afreechv(x,x) = if (x1) afree(x2, ATEMP)
• new ksh_isdash(str) = (str != NULL) && !strcmp(str, "-")
• replace the only use of strrchr with inlined code to shrink
• minor man page fixes
• Minix 3 signames are autogenerated with gcc
• rename strlfun.c to strlcpy.c since we don't do strlcat(3) anyway,
only strlcpy(3), and shorten it
• dot.mkshrc: move MKSH=… down to the export line
to not disturb the PS1 visual impression ☺
• dot.mkshrc: Lstripcom(): optimise
• bump version
¹) side effect from creating API-correct cstrchr, cstrstr, etc.
uses goto so it must be better ☻
tested on mirbsd-current via both Makefile and Build.sh
2007-03-04 04:04:28 +01:00
|
|
|
|
|
2013-04-01 04:37:53 +02:00
|
|
|
|
/*
|
|
|
|
|
* Evil hack since casting uint to sint is implementation-defined
|
|
|
|
|
*/
|
|
|
|
|
typedef union {
|
|
|
|
|
mksh_ari_t i;
|
|
|
|
|
mksh_uari_t u;
|
|
|
|
|
} mksh_ari_u;
|
|
|
|
|
|
• remove strcasestr.c, use home-grown implementation¹, call it stricmp,
and have it return an API-correct const char *
• enhance and stylify comments
• a little KNF and simplifications
• #ifdef DEBUG: replace strchr and strstr with ucstrchr and ucstrstr
that take and return a non-const char *, and fix the violations
• new cstrchr, cstrstr (take and give const char *)
• new vstrchr, vstrstr (take const or not, give boolean value)
• new afreechk(x) = afreechv(x,x) = if (x1) afree(x2, ATEMP)
• new ksh_isdash(str) = (str != NULL) && !strcmp(str, "-")
• replace the only use of strrchr with inlined code to shrink
• minor man page fixes
• Minix 3 signames are autogenerated with gcc
• rename strlfun.c to strlcpy.c since we don't do strlcat(3) anyway,
only strlcpy(3), and shorten it
• dot.mkshrc: move MKSH=… down to the export line
to not disturb the PS1 visual impression ☺
• dot.mkshrc: Lstripcom(): optimise
• bump version
¹) side effect from creating API-correct cstrchr, cstrstr, etc.
uses goto so it must be better ☻
tested on mirbsd-current via both Makefile and Build.sh
2007-03-04 04:04:28 +01:00
|
|
|
|
/* for const debugging */
|
2007-06-09 23:59:21 +02:00
|
|
|
|
#if defined(DEBUG) && defined(__GNUC__) && !defined(__ICC) && \
|
|
|
|
|
!defined(__INTEL_COMPILER) && !defined(__SUNPRO_C)
|
• remove strcasestr.c, use home-grown implementation¹, call it stricmp,
and have it return an API-correct const char *
• enhance and stylify comments
• a little KNF and simplifications
• #ifdef DEBUG: replace strchr and strstr with ucstrchr and ucstrstr
that take and return a non-const char *, and fix the violations
• new cstrchr, cstrstr (take and give const char *)
• new vstrchr, vstrstr (take const or not, give boolean value)
• new afreechk(x) = afreechv(x,x) = if (x1) afree(x2, ATEMP)
• new ksh_isdash(str) = (str != NULL) && !strcmp(str, "-")
• replace the only use of strrchr with inlined code to shrink
• minor man page fixes
• Minix 3 signames are autogenerated with gcc
• rename strlfun.c to strlcpy.c since we don't do strlcat(3) anyway,
only strlcpy(3), and shorten it
• dot.mkshrc: move MKSH=… down to the export line
to not disturb the PS1 visual impression ☺
• dot.mkshrc: Lstripcom(): optimise
• bump version
¹) side effect from creating API-correct cstrchr, cstrstr, etc.
uses goto so it must be better ☻
tested on mirbsd-current via both Makefile and Build.sh
2007-03-04 04:04:28 +01:00
|
|
|
|
char *ucstrchr(char *, int);
|
|
|
|
|
char *ucstrstr(char *, const char *);
|
2009-12-05 23:19:42 +01:00
|
|
|
|
#undef strchr
|
• remove strcasestr.c, use home-grown implementation¹, call it stricmp,
and have it return an API-correct const char *
• enhance and stylify comments
• a little KNF and simplifications
• #ifdef DEBUG: replace strchr and strstr with ucstrchr and ucstrstr
that take and return a non-const char *, and fix the violations
• new cstrchr, cstrstr (take and give const char *)
• new vstrchr, vstrstr (take const or not, give boolean value)
• new afreechk(x) = afreechv(x,x) = if (x1) afree(x2, ATEMP)
• new ksh_isdash(str) = (str != NULL) && !strcmp(str, "-")
• replace the only use of strrchr with inlined code to shrink
• minor man page fixes
• Minix 3 signames are autogenerated with gcc
• rename strlfun.c to strlcpy.c since we don't do strlcat(3) anyway,
only strlcpy(3), and shorten it
• dot.mkshrc: move MKSH=… down to the export line
to not disturb the PS1 visual impression ☺
• dot.mkshrc: Lstripcom(): optimise
• bump version
¹) side effect from creating API-correct cstrchr, cstrstr, etc.
uses goto so it must be better ☻
tested on mirbsd-current via both Makefile and Build.sh
2007-03-04 04:04:28 +01:00
|
|
|
|
#define strchr ucstrchr
|
|
|
|
|
#define strstr ucstrstr
|
2007-06-10 00:01:42 +02:00
|
|
|
|
#define cstrchr(s,c) ({ \
|
2007-03-04 01:13:17 +01:00
|
|
|
|
union mksh_cchack in, out; \
|
|
|
|
|
\
|
|
|
|
|
in.ro = (s); \
|
2007-06-09 23:59:21 +02:00
|
|
|
|
out.rw = ucstrchr(in.rw, (c)); \
|
2007-03-04 01:13:17 +01:00
|
|
|
|
(out.ro); \
|
|
|
|
|
})
|
2007-06-10 00:01:42 +02:00
|
|
|
|
#define cstrstr(b,l) ({ \
|
• remove strcasestr.c, use home-grown implementation¹, call it stricmp,
and have it return an API-correct const char *
• enhance and stylify comments
• a little KNF and simplifications
• #ifdef DEBUG: replace strchr and strstr with ucstrchr and ucstrstr
that take and return a non-const char *, and fix the violations
• new cstrchr, cstrstr (take and give const char *)
• new vstrchr, vstrstr (take const or not, give boolean value)
• new afreechk(x) = afreechv(x,x) = if (x1) afree(x2, ATEMP)
• new ksh_isdash(str) = (str != NULL) && !strcmp(str, "-")
• replace the only use of strrchr with inlined code to shrink
• minor man page fixes
• Minix 3 signames are autogenerated with gcc
• rename strlfun.c to strlcpy.c since we don't do strlcat(3) anyway,
only strlcpy(3), and shorten it
• dot.mkshrc: move MKSH=… down to the export line
to not disturb the PS1 visual impression ☺
• dot.mkshrc: Lstripcom(): optimise
• bump version
¹) side effect from creating API-correct cstrchr, cstrstr, etc.
uses goto so it must be better ☻
tested on mirbsd-current via both Makefile and Build.sh
2007-03-04 04:04:28 +01:00
|
|
|
|
union mksh_cchack in, out; \
|
|
|
|
|
\
|
|
|
|
|
in.ro = (b); \
|
2007-06-09 23:59:21 +02:00
|
|
|
|
out.rw = ucstrstr(in.rw, (l)); \
|
• remove strcasestr.c, use home-grown implementation¹, call it stricmp,
and have it return an API-correct const char *
• enhance and stylify comments
• a little KNF and simplifications
• #ifdef DEBUG: replace strchr and strstr with ucstrchr and ucstrstr
that take and return a non-const char *, and fix the violations
• new cstrchr, cstrstr (take and give const char *)
• new vstrchr, vstrstr (take const or not, give boolean value)
• new afreechk(x) = afreechv(x,x) = if (x1) afree(x2, ATEMP)
• new ksh_isdash(str) = (str != NULL) && !strcmp(str, "-")
• replace the only use of strrchr with inlined code to shrink
• minor man page fixes
• Minix 3 signames are autogenerated with gcc
• rename strlfun.c to strlcpy.c since we don't do strlcat(3) anyway,
only strlcpy(3), and shorten it
• dot.mkshrc: move MKSH=… down to the export line
to not disturb the PS1 visual impression ☺
• dot.mkshrc: Lstripcom(): optimise
• bump version
¹) side effect from creating API-correct cstrchr, cstrstr, etc.
uses goto so it must be better ☻
tested on mirbsd-current via both Makefile and Build.sh
2007-03-04 04:04:28 +01:00
|
|
|
|
(out.ro); \
|
|
|
|
|
})
|
|
|
|
|
#define vstrchr(s,c) (cstrchr((s), (c)) != NULL)
|
|
|
|
|
#define vstrstr(b,l) (cstrstr((b), (l)) != NULL)
|
2007-06-09 23:59:21 +02:00
|
|
|
|
#else /* !DEBUG, !gcc */
|
2007-06-05 21:48:47 +02:00
|
|
|
|
#define cstrchr(s,c) ((const char *)strchr((s), (c)))
|
|
|
|
|
#define cstrstr(s,c) ((const char *)strstr((s), (c)))
|
2007-06-09 23:59:21 +02:00
|
|
|
|
#define vstrchr(s,c) (strchr((s), (c)) != NULL)
|
|
|
|
|
#define vstrstr(b,l) (strstr((b), (l)) != NULL)
|
2012-12-04 02:18:34 +01:00
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#if defined(DEBUG) || defined(__COVERITY__)
|
2012-12-28 05:47:50 +01:00
|
|
|
|
#define mkssert(e) do { if (!(e)) exit(255); } while (/* CONSTCOND */ 0)
|
2013-02-10 18:41:06 +01:00
|
|
|
|
#ifndef DEBUG_LEAKS
|
|
|
|
|
#define DEBUG_LEAKS
|
|
|
|
|
#endif
|
2012-12-04 02:18:34 +01:00
|
|
|
|
#else
|
2012-12-28 05:47:50 +01:00
|
|
|
|
#define mkssert(e) do { } while (/* CONSTCOND */ 0)
|
• remove strcasestr.c, use home-grown implementation¹, call it stricmp,
and have it return an API-correct const char *
• enhance and stylify comments
• a little KNF and simplifications
• #ifdef DEBUG: replace strchr and strstr with ucstrchr and ucstrstr
that take and return a non-const char *, and fix the violations
• new cstrchr, cstrstr (take and give const char *)
• new vstrchr, vstrstr (take const or not, give boolean value)
• new afreechk(x) = afreechv(x,x) = if (x1) afree(x2, ATEMP)
• new ksh_isdash(str) = (str != NULL) && !strcmp(str, "-")
• replace the only use of strrchr with inlined code to shrink
• minor man page fixes
• Minix 3 signames are autogenerated with gcc
• rename strlfun.c to strlcpy.c since we don't do strlcat(3) anyway,
only strlcpy(3), and shorten it
• dot.mkshrc: move MKSH=… down to the export line
to not disturb the PS1 visual impression ☺
• dot.mkshrc: Lstripcom(): optimise
• bump version
¹) side effect from creating API-correct cstrchr, cstrstr, etc.
uses goto so it must be better ☻
tested on mirbsd-current via both Makefile and Build.sh
2007-03-04 04:04:28 +01:00
|
|
|
|
#endif
|
2007-03-04 01:13:17 +01:00
|
|
|
|
|
2013-07-21 20:47:24 +02:00
|
|
|
|
#if (!defined(MKSH_BUILDMAKEFILE4BSD) && !defined(MKSH_BUILDSH)) || (MKSH_BUILD_R != 471)
|
2012-03-27 23:23:52 +02:00
|
|
|
|
#error Must run Build.sh to compile this.
|
2013-05-08 13:16:19 +02:00
|
|
|
|
extern void thiswillneverbedefinedIhope(void);
|
2012-03-29 01:09:24 +02:00
|
|
|
|
int
|
|
|
|
|
im_sorry_dave(void)
|
|
|
|
|
{
|
|
|
|
|
/* I’m sorry, Dave. I’m afraid I can’t do that. */
|
|
|
|
|
return (thiswillneverbedefinedIhope());
|
|
|
|
|
}
|
2012-03-27 23:23:52 +02:00
|
|
|
|
#endif
|
|
|
|
|
|
2007-05-13 21:14:05 +02:00
|
|
|
|
/* use this ipv strchr(s, 0) but no side effects in s! */
|
|
|
|
|
#define strnul(s) ((s) + strlen(s))
|
|
|
|
|
|
2008-10-28 15:32:43 +01:00
|
|
|
|
#define utf_ptradjx(src, dst) do { \
|
2009-05-16 17:09:07 +02:00
|
|
|
|
(dst) = (src) + utf_ptradj(src); \
|
2008-10-28 15:32:43 +01:00
|
|
|
|
} while (/* CONSTCOND */ 0)
|
|
|
|
|
|
2012-07-01 17:55:00 +02:00
|
|
|
|
#if defined(MKSH_SMALL) && !defined(MKSH_SMALL_BUT_FAST)
|
2011-10-26 00:36:39 +02:00
|
|
|
|
#define strdupx(d, s, ap) do { \
|
|
|
|
|
(d) = strdup_i((s), (ap)); \
|
2008-10-28 15:51:06 +01:00
|
|
|
|
} while (/* CONSTCOND */ 0)
|
2011-10-26 00:36:39 +02:00
|
|
|
|
#define strndupx(d, s, n, ap) do { \
|
|
|
|
|
(d) = strndup_i((s), (n), (ap)); \
|
2008-10-28 15:51:06 +01:00
|
|
|
|
} while (/* CONSTCOND */ 0)
|
|
|
|
|
#else
|
2008-10-28 15:32:43 +01:00
|
|
|
|
/* be careful to evaluate arguments only once! */
|
|
|
|
|
#define strdupx(d, s, ap) do { \
|
|
|
|
|
const char *strdup_src = (s); \
|
|
|
|
|
char *strdup_dst = NULL; \
|
|
|
|
|
\
|
|
|
|
|
if (strdup_src != NULL) { \
|
2009-08-01 22:32:45 +02:00
|
|
|
|
size_t strdup_len = strlen(strdup_src) + 1; \
|
|
|
|
|
strdup_dst = alloc(strdup_len, (ap)); \
|
2009-08-01 22:29:25 +02:00
|
|
|
|
memcpy(strdup_dst, strdup_src, strdup_len); \
|
2008-10-28 15:32:43 +01:00
|
|
|
|
} \
|
|
|
|
|
(d) = strdup_dst; \
|
|
|
|
|
} while (/* CONSTCOND */ 0)
|
|
|
|
|
#define strndupx(d, s, n, ap) do { \
|
|
|
|
|
const char *strdup_src = (s); \
|
|
|
|
|
char *strdup_dst = NULL; \
|
|
|
|
|
\
|
|
|
|
|
if (strdup_src != NULL) { \
|
2009-08-01 22:32:45 +02:00
|
|
|
|
size_t strndup_len = (n); \
|
|
|
|
|
strdup_dst = alloc(strndup_len + 1, (ap)); \
|
|
|
|
|
memcpy(strdup_dst, strdup_src, strndup_len); \
|
|
|
|
|
strdup_dst[strndup_len] = '\0'; \
|
2008-10-28 15:32:43 +01:00
|
|
|
|
} \
|
|
|
|
|
(d) = strdup_dst; \
|
|
|
|
|
} while (/* CONSTCOND */ 0)
|
2008-10-28 15:51:06 +01:00
|
|
|
|
#endif
|
2008-10-28 15:32:43 +01:00
|
|
|
|
|
2012-06-25 18:05:10 +02:00
|
|
|
|
#ifdef MKSH_LEGACY_MODE
|
|
|
|
|
#ifndef MKSH_NO_CMDLINE_EDITING
|
|
|
|
|
#define MKSH_NO_CMDLINE_EDITING /* defined */
|
|
|
|
|
#endif
|
2012-07-01 17:44:31 +02:00
|
|
|
|
#ifndef MKSH_CONSERVATIVE_FDS
|
|
|
|
|
#define MKSH_CONSERVATIVE_FDS /* defined */
|
|
|
|
|
#endif
|
2012-06-25 18:05:10 +02:00
|
|
|
|
#undef MKSH_S_NOVI
|
|
|
|
|
#define MKSH_S_NOVI 1
|
|
|
|
|
#endif
|
|
|
|
|
|
2009-07-25 22:26:33 +02:00
|
|
|
|
#ifdef MKSH_SMALL
|
2009-07-25 23:31:27 +02:00
|
|
|
|
#ifndef MKSH_CONSERVATIVE_FDS
|
2009-09-24 19:15:33 +02:00
|
|
|
|
#define MKSH_CONSERVATIVE_FDS /* defined */
|
2009-07-25 23:31:27 +02:00
|
|
|
|
#endif
|
2009-07-25 22:26:33 +02:00
|
|
|
|
#ifndef MKSH_NOPWNAM
|
2009-09-24 19:15:33 +02:00
|
|
|
|
#define MKSH_NOPWNAM /* defined */
|
2009-07-25 22:26:33 +02:00
|
|
|
|
#endif
|
2009-09-24 19:15:33 +02:00
|
|
|
|
#ifndef MKSH_S_NOVI
|
|
|
|
|
#define MKSH_S_NOVI 1
|
2007-06-15 23:55:20 +02:00
|
|
|
|
#endif
|
2009-07-25 22:26:33 +02:00
|
|
|
|
#endif
|
2007-06-15 23:55:20 +02:00
|
|
|
|
|
2009-09-24 19:15:33 +02:00
|
|
|
|
#ifndef MKSH_S_NOVI
|
|
|
|
|
#define MKSH_S_NOVI 0
|
|
|
|
|
#endif
|
|
|
|
|
|
2011-01-30 02:35:35 +01:00
|
|
|
|
#if defined(MKSH_NOPROSPECTOFWORK) && !defined(MKSH_UNEMPLOYED)
|
2011-08-27 19:30:07 +02:00
|
|
|
|
#define MKSH_UNEMPLOYED 1
|
2011-01-30 02:35:35 +01:00
|
|
|
|
#endif
|
|
|
|
|
|
2012-07-01 17:41:56 +02:00
|
|
|
|
/* these shall be smaller than 100 */
|
|
|
|
|
#ifdef MKSH_CONSERVATIVE_FDS
|
|
|
|
|
#define NUFILE 32 /* Number of user-accessible files */
|
|
|
|
|
#define FDBASE 10 /* First file usable by Shell */
|
|
|
|
|
#else
|
|
|
|
|
#define NUFILE 56 /* Number of user-accessible files */
|
|
|
|
|
#define FDBASE 24 /* First file usable by Shell */
|
|
|
|
|
#endif
|
|
|
|
|
|
2008-12-13 18:02:18 +01:00
|
|
|
|
/*
|
2009-03-22 17:55:38 +01:00
|
|
|
|
* simple grouping allocator
|
2008-12-13 18:02:18 +01:00
|
|
|
|
*/
|
2009-04-07 20:56:51 +02:00
|
|
|
|
|
2011-03-05 22:43:18 +01:00
|
|
|
|
|
|
|
|
|
/* 0. OS API: where to get memory from and how to free it (grouped) */
|
|
|
|
|
|
2011-03-05 22:48:09 +01:00
|
|
|
|
/* malloc(3)/realloc(3) -> free(3) for use by the memory allocator */
|
|
|
|
|
#define malloc_osi(sz) malloc(sz)
|
|
|
|
|
#define realloc_osi(p,sz) realloc((p), (sz))
|
|
|
|
|
#define free_osimalloc(p) free(p)
|
|
|
|
|
|
|
|
|
|
/* malloc(3)/realloc(3) -> free(3) for use by mksh code */
|
|
|
|
|
#define malloc_osfunc(sz) malloc(sz)
|
|
|
|
|
#define realloc_osfunc(p,sz) realloc((p), (sz))
|
|
|
|
|
#define free_osfunc(p) free(p)
|
2011-03-05 22:43:18 +01:00
|
|
|
|
|
|
|
|
|
#if HAVE_MKNOD
|
|
|
|
|
/* setmode(3) -> free(3) */
|
|
|
|
|
#define free_ossetmode(p) free(p)
|
|
|
|
|
#endif
|
|
|
|
|
|
2012-05-05 19:37:44 +02:00
|
|
|
|
#ifdef MKSH__NO_PATH_MAX
|
2011-03-05 22:43:18 +01:00
|
|
|
|
/* GNU libc: get_current_dir_name(3) -> free(3) */
|
|
|
|
|
#define free_gnu_gcdn(p) free(p)
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
2009-04-07 20:56:51 +02:00
|
|
|
|
/* 1. internal structure */
|
|
|
|
|
struct lalloc {
|
2009-03-24 09:53:45 +01:00
|
|
|
|
struct lalloc *next;
|
2009-04-07 20:56:51 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* 2. sizes */
|
|
|
|
|
#define ALLOC_ITEM struct lalloc
|
2009-06-08 22:06:50 +02:00
|
|
|
|
#define ALLOC_SIZE (sizeof(ALLOC_ITEM))
|
2009-04-07 20:56:51 +02:00
|
|
|
|
|
|
|
|
|
/* 3. group structure (only the same for lalloc.c) */
|
|
|
|
|
typedef struct lalloc Area;
|
|
|
|
|
|
2008-12-13 18:02:18 +01:00
|
|
|
|
|
|
|
|
|
EXTERN Area aperm; /* permanent object space */
|
|
|
|
|
#define APERM &aperm
|
|
|
|
|
#define ATEMP &e->area
|
2005-05-23 05:06:10 +02:00
|
|
|
|
|
2010-07-04 19:33:58 +02:00
|
|
|
|
/*
|
|
|
|
|
* flags (the order of these enums MUST match the order in misc.c(options[]))
|
|
|
|
|
*/
|
|
|
|
|
enum sh_flag {
|
|
|
|
|
#define SHFLAGS_ENUMS
|
|
|
|
|
#include "sh_flags.h"
|
|
|
|
|
FNFLAGS /* (place holder: how many flags are there) */
|
|
|
|
|
};
|
|
|
|
|
|
2011-01-21 22:04:48 +01:00
|
|
|
|
#define Flag(f) (shell_flags[(int)(f)])
|
2010-07-04 19:33:58 +02:00
|
|
|
|
#define UTFMODE Flag(FUNICODE)
|
|
|
|
|
|
2005-05-23 05:06:10 +02:00
|
|
|
|
/*
|
|
|
|
|
* parsing & execution environment
|
2012-07-22 17:56:51 +02:00
|
|
|
|
*
|
|
|
|
|
* note that kshlongjmp MUST NOT be passed 0 as second argument!
|
2005-05-23 05:06:10 +02:00
|
|
|
|
*/
|
2012-04-14 16:07:47 +02:00
|
|
|
|
#ifdef MKSH_NO_SIGSETJMP
|
2012-03-31 19:30:00 +02:00
|
|
|
|
#define kshjmp_buf jmp_buf
|
|
|
|
|
#define kshsetjmp(jbuf) _setjmp(jbuf)
|
|
|
|
|
#define kshlongjmp _longjmp
|
|
|
|
|
#else
|
|
|
|
|
#define kshjmp_buf sigjmp_buf
|
|
|
|
|
#define kshsetjmp(jbuf) sigsetjmp((jbuf), 0)
|
|
|
|
|
#define kshlongjmp siglongjmp
|
|
|
|
|
#endif
|
|
|
|
|
|
2012-10-30 21:49:44 +01:00
|
|
|
|
struct sretrace_info;
|
2012-10-30 21:07:15 +01:00
|
|
|
|
struct yyrecursive_state;
|
|
|
|
|
|
2012-12-05 19:54:10 +01:00
|
|
|
|
EXTERN struct sretrace_info *retrace_info E_INIT(NULL);
|
|
|
|
|
EXTERN int subshell_nesting_type E_INIT(0);
|
2012-10-30 21:49:44 +01:00
|
|
|
|
|
2008-10-15 12:25:01 +02:00
|
|
|
|
extern struct env {
|
2011-09-07 17:24:22 +02:00
|
|
|
|
ALLOC_ITEM alloc_INT; /* internal, do not touch */
|
2008-12-13 18:02:18 +01:00
|
|
|
|
Area area; /* temporary allocation area */
|
2009-04-07 21:43:28 +02:00
|
|
|
|
struct env *oenv; /* link to previous environment */
|
2006-08-23 00:21:20 +02:00
|
|
|
|
struct block *loc; /* local variables and functions */
|
|
|
|
|
short *savefd; /* original redirected fds */
|
|
|
|
|
struct temp *temps; /* temp files */
|
2012-10-30 21:07:15 +01:00
|
|
|
|
/* saved parser recursion state */
|
|
|
|
|
struct yyrecursive_state *yyrecursive_statep;
|
2012-03-31 19:30:00 +02:00
|
|
|
|
kshjmp_buf jbuf; /* long jump back to env creator */
|
2012-03-29 21:23:01 +02:00
|
|
|
|
uint8_t type; /* environment type - see below */
|
|
|
|
|
uint8_t flags; /* EF_* */
|
2005-05-23 05:06:10 +02:00
|
|
|
|
} *e;
|
|
|
|
|
|
|
|
|
|
/* struct env.type values */
|
2006-11-16 14:35:00 +01:00
|
|
|
|
#define E_NONE 0 /* dummy environment */
|
|
|
|
|
#define E_PARSE 1 /* parsing command # */
|
|
|
|
|
#define E_FUNC 2 /* executing function # */
|
|
|
|
|
#define E_INCL 3 /* including a file via . # */
|
|
|
|
|
#define E_EXEC 4 /* executing command tree */
|
|
|
|
|
#define E_LOOP 5 /* executing for/while # */
|
|
|
|
|
#define E_ERRH 6 /* general error handler # */
|
2013-02-10 22:17:07 +01:00
|
|
|
|
#define E_GONE 7 /* hidden in child */
|
2005-05-23 05:06:10 +02:00
|
|
|
|
/* # indicates env has valid jbuf (see unwind()) */
|
|
|
|
|
|
|
|
|
|
/* struct env.flag values */
|
|
|
|
|
#define EF_BRKCONT_PASS BIT(1) /* set if E_LOOP must pass break/continue on */
|
|
|
|
|
#define EF_FAKE_SIGDIE BIT(2) /* hack to get info from unwind to quitenv */
|
|
|
|
|
|
|
|
|
|
/* Do breaks/continues stop at env type e? */
|
2012-03-29 21:23:01 +02:00
|
|
|
|
#define STOP_BRKCONT(t) ((t) == E_NONE || (t) == E_PARSE || \
|
|
|
|
|
(t) == E_FUNC || (t) == E_INCL)
|
2005-05-23 05:06:10 +02:00
|
|
|
|
/* Do returns stop at env type e? */
|
|
|
|
|
#define STOP_RETURN(t) ((t) == E_FUNC || (t) == E_INCL)
|
|
|
|
|
|
2012-03-31 19:30:00 +02:00
|
|
|
|
/* values for kshlongjmp(e->jbuf, i) */
|
2012-07-22 17:56:51 +02:00
|
|
|
|
/* note that i MUST NOT be zero */
|
2006-08-23 00:21:20 +02:00
|
|
|
|
#define LRETURN 1 /* return statement */
|
2006-11-16 14:35:00 +01:00
|
|
|
|
#define LEXIT 2 /* exit statement */
|
2006-08-23 00:21:20 +02:00
|
|
|
|
#define LERROR 3 /* errorf() called */
|
|
|
|
|
#define LLEAVE 4 /* untrappable exit/error */
|
|
|
|
|
#define LINTR 5 /* ^C noticed */
|
2006-11-16 14:35:00 +01:00
|
|
|
|
#define LBREAK 6 /* break statement */
|
|
|
|
|
#define LCONTIN 7 /* continue statement */
|
2006-08-23 00:21:20 +02:00
|
|
|
|
#define LSHELL 8 /* return to interactive shell() */
|
|
|
|
|
#define LAEXPR 9 /* error in arithmetic expression */
|
2005-05-23 05:06:10 +02:00
|
|
|
|
|
2011-01-21 22:04:48 +01:00
|
|
|
|
/* sort of shell global state */
|
|
|
|
|
EXTERN pid_t procpid; /* PID of executing process */
|
|
|
|
|
EXTERN int exstat; /* exit status */
|
|
|
|
|
EXTERN int subst_exstat; /* exit status of last $(..)/`..` */
|
2011-02-18 23:26:13 +01:00
|
|
|
|
EXTERN struct tbl *vp_pipest; /* global PIPESTATUS array */
|
2011-01-21 22:04:48 +01:00
|
|
|
|
EXTERN short trap_exstat; /* exit status before running a trap */
|
|
|
|
|
EXTERN uint8_t trap_nested; /* running nested traps */
|
|
|
|
|
EXTERN uint8_t shell_flags[FNFLAGS];
|
|
|
|
|
EXTERN const char *kshname; /* $0 */
|
|
|
|
|
EXTERN struct {
|
2011-09-07 17:24:22 +02:00
|
|
|
|
uid_t kshuid_v; /* real UID of shell */
|
|
|
|
|
uid_t ksheuid_v; /* effective UID of shell */
|
|
|
|
|
gid_t kshgid_v; /* real GID of shell */
|
|
|
|
|
gid_t kshegid_v; /* effective GID of shell */
|
|
|
|
|
pid_t kshpgrp_v; /* process group of shell */
|
|
|
|
|
pid_t kshppid_v; /* PID of parent of shell */
|
|
|
|
|
pid_t kshpid_v; /* $$, shell PID */
|
2011-01-21 22:04:48 +01:00
|
|
|
|
} rndsetupstate;
|
|
|
|
|
|
2011-09-07 17:24:22 +02:00
|
|
|
|
#define kshpid rndsetupstate.kshpid_v
|
|
|
|
|
#define kshpgrp rndsetupstate.kshpgrp_v
|
|
|
|
|
#define kshuid rndsetupstate.kshuid_v
|
|
|
|
|
#define ksheuid rndsetupstate.ksheuid_v
|
|
|
|
|
#define kshgid rndsetupstate.kshgid_v
|
|
|
|
|
#define kshegid rndsetupstate.kshegid_v
|
|
|
|
|
#define kshppid rndsetupstate.kshppid_v
|
2010-07-04 19:33:58 +02:00
|
|
|
|
|
|
|
|
|
|
2005-05-23 05:06:10 +02:00
|
|
|
|
/* option processing */
|
|
|
|
|
#define OF_CMDLINE 0x01 /* command line */
|
|
|
|
|
#define OF_SET 0x02 /* set builtin */
|
|
|
|
|
#define OF_SPECIAL 0x04 /* a special variable changing */
|
|
|
|
|
#define OF_INTERNAL 0x08 /* set internally by shell */
|
|
|
|
|
#define OF_FIRSTTIME 0x10 /* as early as possible, once */
|
|
|
|
|
#define OF_ANY (OF_CMDLINE | OF_SET | OF_SPECIAL | OF_INTERNAL)
|
|
|
|
|
|
2007-07-01 18:49:18 +02:00
|
|
|
|
struct shoption {
|
2006-08-23 00:16:04 +02:00
|
|
|
|
const char *name; /* long name of option */
|
|
|
|
|
char c; /* character flag (if any) */
|
2007-03-10 19:16:28 +01:00
|
|
|
|
unsigned char flags; /* OF_* */
|
2005-05-23 05:06:10 +02:00
|
|
|
|
};
|
2007-07-01 18:49:18 +02:00
|
|
|
|
extern const struct shoption options[];
|
2005-05-23 05:06:10 +02:00
|
|
|
|
|
2011-08-14 00:19:41 +02:00
|
|
|
|
/* null value for variable; comparison pointer for unset */
|
2011-09-07 17:24:22 +02:00
|
|
|
|
EXTERN char null[] E_INIT("");
|
2007-08-20 01:12:23 +02:00
|
|
|
|
/* helpers for string pooling */
|
2011-09-07 17:24:22 +02:00
|
|
|
|
EXTERN const char Tintovfl[] E_INIT("integer overflow %zu %c %zu prevented");
|
2013-06-04 00:28:33 +02:00
|
|
|
|
EXTERN const char Toomem[] E_INIT("can't allocate %zu data bytes");
|
2010-10-01 21:04:38 +02:00
|
|
|
|
#if defined(__GNUC__)
|
|
|
|
|
/* trust this to have string pooling; -Wformat bitches otherwise */
|
2011-09-07 17:24:22 +02:00
|
|
|
|
#define Tsynerr "syntax error"
|
2010-10-01 21:04:38 +02:00
|
|
|
|
#else
|
2011-09-07 17:24:22 +02:00
|
|
|
|
EXTERN const char Tsynerr[] E_INIT("syntax error");
|
|
|
|
|
#endif
|
|
|
|
|
EXTERN const char Tselect[] E_INIT("select");
|
|
|
|
|
EXTERN const char Tr_fc_e_dash[] E_INIT("r=fc -e -");
|
|
|
|
|
#define Tfc_e_dash (Tr_fc_e_dash + 2) /* "fc -e -" */
|
|
|
|
|
#define Zfc_e_dash 7 /* strlen(Tfc_e_dash) */
|
|
|
|
|
EXTERN const char Tlocal_typeset[] E_INIT("local=typeset");
|
|
|
|
|
#define T_typeset (Tlocal_typeset + 5) /* "=typeset" */
|
|
|
|
|
#define Ttypeset (Tlocal_typeset + 6) /* "typeset" */
|
2013-04-26 23:22:50 +02:00
|
|
|
|
EXTERN const char Talias[] E_INIT("alias");
|
|
|
|
|
EXTERN const char Tunalias[] E_INIT("unalias");
|
2011-09-07 17:24:22 +02:00
|
|
|
|
EXTERN const char Tsgset[] E_INIT("*=set");
|
|
|
|
|
#define Tset (Tsgset + 2) /* "set" */
|
2012-05-10 01:21:00 +02:00
|
|
|
|
EXTERN const char Tsgunset[] E_INIT("*=unset");
|
|
|
|
|
#define Tunset (Tsgunset + 2) /* "unset" */
|
|
|
|
|
EXTERN const char Tsgexport[] E_INIT("*=export");
|
|
|
|
|
#define Texport (Tsgexport + 2) /* "export" */
|
|
|
|
|
EXTERN const char Tsgreadonly[] E_INIT("*=readonly");
|
|
|
|
|
#define Treadonly (Tsgreadonly + 2) /* "readonly" */
|
2011-09-07 17:24:22 +02:00
|
|
|
|
EXTERN const char Tgbuiltin[] E_INIT("=builtin");
|
|
|
|
|
#define Tbuiltin (Tgbuiltin + 1) /* "builtin" */
|
|
|
|
|
EXTERN const char T_function[] E_INIT(" function");
|
|
|
|
|
#define Tfunction (T_function + 1) /* "function" */
|
2012-07-30 23:37:17 +02:00
|
|
|
|
EXTERN const char TC_LEX1[] E_INIT("|&;<>() \t\n");
|
|
|
|
|
#define TC_IFSWS (TC_LEX1 + 7) /* space tab newline */
|
2005-05-23 05:06:10 +02:00
|
|
|
|
|
2012-04-14 18:07:48 +02:00
|
|
|
|
typedef uint8_t Temp_type;
|
|
|
|
|
/* expanded heredoc */
|
|
|
|
|
#define TT_HEREDOC_EXP 0
|
2012-10-22 22:19:18 +02:00
|
|
|
|
/* temporary file used for history editing (fc -e) */
|
2012-04-14 18:07:48 +02:00
|
|
|
|
#define TT_HIST_EDIT 1
|
2012-10-22 22:19:18 +02:00
|
|
|
|
/* temporary file used during in-situ command substitution */
|
|
|
|
|
#define TT_FUNSUB 2
|
2012-04-14 18:07:48 +02:00
|
|
|
|
|
2006-08-23 00:16:04 +02:00
|
|
|
|
/* temp/heredoc files. The file is removed when the struct is freed. */
|
2005-05-23 05:06:10 +02:00
|
|
|
|
struct temp {
|
2006-08-23 00:16:04 +02:00
|
|
|
|
struct temp *next;
|
|
|
|
|
struct shf *shf;
|
2012-04-14 18:07:48 +02:00
|
|
|
|
/* pid of process parsed here-doc */
|
|
|
|
|
pid_t pid;
|
2006-08-23 00:16:04 +02:00
|
|
|
|
Temp_type type;
|
2012-04-14 18:07:48 +02:00
|
|
|
|
/* actually longer: name (variable length) */
|
|
|
|
|
char tffn[3];
|
2005-05-23 05:06:10 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* stdio and our IO routines
|
|
|
|
|
*/
|
|
|
|
|
|
2013-07-21 20:47:24 +02:00
|
|
|
|
#define shl_xtrace (&shf_iob[0]) /* for set -x */
|
2005-05-23 05:06:10 +02:00
|
|
|
|
#define shl_stdout (&shf_iob[1])
|
|
|
|
|
#define shl_out (&shf_iob[2])
|
2012-03-23 20:38:12 +01:00
|
|
|
|
#ifdef DF
|
|
|
|
|
#define shl_dbg (&shf_iob[3]) /* for DF() */
|
|
|
|
|
#endif
|
2010-08-28 17:39:20 +02:00
|
|
|
|
EXTERN bool shl_stdout_ok;
|
2005-05-23 05:06:10 +02:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* trap handlers
|
|
|
|
|
*/
|
|
|
|
|
typedef struct trap {
|
|
|
|
|
const char *name; /* short name */
|
|
|
|
|
const char *mess; /* descriptive name */
|
2006-08-23 00:16:04 +02:00
|
|
|
|
char *trap; /* trap command */
|
2005-05-23 05:06:10 +02:00
|
|
|
|
sig_t cursig; /* current handler (valid if TF_ORIG_* set) */
|
|
|
|
|
sig_t shtrap; /* shell signal handler */
|
2009-04-07 20:41:37 +02:00
|
|
|
|
int signal; /* signal number */
|
|
|
|
|
int flags; /* TF_* */
|
|
|
|
|
volatile sig_atomic_t set; /* trap pending */
|
2005-05-23 05:06:10 +02:00
|
|
|
|
} Trap;
|
|
|
|
|
|
|
|
|
|
/* values for Trap.flags */
|
|
|
|
|
#define TF_SHELL_USES BIT(0) /* shell uses signal, user can't change */
|
|
|
|
|
#define TF_USER_SET BIT(1) /* user has (tried to) set trap */
|
|
|
|
|
#define TF_ORIG_IGN BIT(2) /* original action was SIG_IGN */
|
|
|
|
|
#define TF_ORIG_DFL BIT(3) /* original action was SIG_DFL */
|
|
|
|
|
#define TF_EXEC_IGN BIT(4) /* restore SIG_IGN just before exec */
|
|
|
|
|
#define TF_EXEC_DFL BIT(5) /* restore SIG_DFL just before exec */
|
|
|
|
|
#define TF_DFL_INTR BIT(6) /* when received, default action is LINTR */
|
|
|
|
|
#define TF_TTY_INTR BIT(7) /* tty generated signal (see j_waitj) */
|
|
|
|
|
#define TF_CHANGED BIT(8) /* used by runtrap() to detect trap changes */
|
|
|
|
|
#define TF_FATAL BIT(9) /* causes termination if not trapped */
|
|
|
|
|
|
|
|
|
|
/* values for setsig()/setexecsig() flags argument */
|
|
|
|
|
#define SS_RESTORE_MASK 0x3 /* how to restore a signal before an exec() */
|
|
|
|
|
#define SS_RESTORE_CURR 0 /* leave current handler in place */
|
|
|
|
|
#define SS_RESTORE_ORIG 1 /* restore original handler */
|
|
|
|
|
#define SS_RESTORE_DFL 2 /* restore to SIG_DFL */
|
|
|
|
|
#define SS_RESTORE_IGN 3 /* restore to SIG_IGN */
|
|
|
|
|
#define SS_FORCE BIT(3) /* set signal even if original signal ignored */
|
|
|
|
|
#define SS_USER BIT(4) /* user is doing the set (ie, trap command) */
|
2010-07-04 19:45:17 +02:00
|
|
|
|
#define SS_SHTRAP BIT(5) /* trap for internal use (ALRM, CHLD, WINCH) */
|
2005-05-23 05:06:10 +02:00
|
|
|
|
|
2011-09-07 17:24:22 +02:00
|
|
|
|
#define ksh_SIGEXIT 0 /* for trap EXIT */
|
|
|
|
|
#define ksh_SIGERR NSIG /* for trap ERR */
|
2005-05-23 05:06:10 +02:00
|
|
|
|
|
• remove strcasestr.c, use home-grown implementation¹, call it stricmp,
and have it return an API-correct const char *
• enhance and stylify comments
• a little KNF and simplifications
• #ifdef DEBUG: replace strchr and strstr with ucstrchr and ucstrstr
that take and return a non-const char *, and fix the violations
• new cstrchr, cstrstr (take and give const char *)
• new vstrchr, vstrstr (take const or not, give boolean value)
• new afreechk(x) = afreechv(x,x) = if (x1) afree(x2, ATEMP)
• new ksh_isdash(str) = (str != NULL) && !strcmp(str, "-")
• replace the only use of strrchr with inlined code to shrink
• minor man page fixes
• Minix 3 signames are autogenerated with gcc
• rename strlfun.c to strlcpy.c since we don't do strlcat(3) anyway,
only strlcpy(3), and shorten it
• dot.mkshrc: move MKSH=… down to the export line
to not disturb the PS1 visual impression ☺
• dot.mkshrc: Lstripcom(): optimise
• bump version
¹) side effect from creating API-correct cstrchr, cstrstr, etc.
uses goto so it must be better ☻
tested on mirbsd-current via both Makefile and Build.sh
2007-03-04 04:04:28 +01:00
|
|
|
|
EXTERN volatile sig_atomic_t trap; /* traps pending? */
|
|
|
|
|
EXTERN volatile sig_atomic_t intrsig; /* pending trap interrupts command */
|
2010-08-28 17:48:20 +02:00
|
|
|
|
EXTERN volatile sig_atomic_t fatal_trap; /* received a fatal signal */
|
2005-05-23 05:06:10 +02:00
|
|
|
|
extern Trap sigtraps[NSIG+1];
|
|
|
|
|
|
2010-07-25 13:35:43 +02:00
|
|
|
|
/* got_winch = 1 when we need to re-adjust the window size */
|
2010-07-04 19:45:17 +02:00
|
|
|
|
#ifdef SIGWINCH
|
2011-09-07 17:24:22 +02:00
|
|
|
|
EXTERN volatile sig_atomic_t got_winch E_INIT(1);
|
2010-07-04 19:45:17 +02:00
|
|
|
|
#else
|
|
|
|
|
#define got_winch true
|
|
|
|
|
#endif
|
|
|
|
|
|
2005-05-23 05:06:10 +02:00
|
|
|
|
/*
|
|
|
|
|
* TMOUT support
|
|
|
|
|
*/
|
|
|
|
|
/* values for ksh_tmout_state */
|
|
|
|
|
enum tmout_enum {
|
• remove strcasestr.c, use home-grown implementation¹, call it stricmp,
and have it return an API-correct const char *
• enhance and stylify comments
• a little KNF and simplifications
• #ifdef DEBUG: replace strchr and strstr with ucstrchr and ucstrstr
that take and return a non-const char *, and fix the violations
• new cstrchr, cstrstr (take and give const char *)
• new vstrchr, vstrstr (take const or not, give boolean value)
• new afreechk(x) = afreechv(x,x) = if (x1) afree(x2, ATEMP)
• new ksh_isdash(str) = (str != NULL) && !strcmp(str, "-")
• replace the only use of strrchr with inlined code to shrink
• minor man page fixes
• Minix 3 signames are autogenerated with gcc
• rename strlfun.c to strlcpy.c since we don't do strlcat(3) anyway,
only strlcpy(3), and shorten it
• dot.mkshrc: move MKSH=… down to the export line
to not disturb the PS1 visual impression ☺
• dot.mkshrc: Lstripcom(): optimise
• bump version
¹) side effect from creating API-correct cstrchr, cstrstr, etc.
uses goto so it must be better ☻
tested on mirbsd-current via both Makefile and Build.sh
2007-03-04 04:04:28 +01:00
|
|
|
|
TMOUT_EXECUTING = 0, /* executing commands */
|
2005-05-23 05:06:10 +02:00
|
|
|
|
TMOUT_READING, /* waiting for input */
|
|
|
|
|
TMOUT_LEAVING /* have timed out */
|
|
|
|
|
};
|
|
|
|
|
EXTERN unsigned int ksh_tmout;
|
2011-09-07 17:24:22 +02:00
|
|
|
|
EXTERN enum tmout_enum ksh_tmout_state E_INIT(TMOUT_EXECUTING);
|
2005-05-23 05:06:10 +02:00
|
|
|
|
|
|
|
|
|
/* For "You have stopped jobs" message */
|
2012-05-04 23:15:34 +02:00
|
|
|
|
EXTERN bool really_exit;
|
2005-05-23 05:06:10 +02:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* fast character classes
|
|
|
|
|
*/
|
2006-11-16 14:35:00 +01:00
|
|
|
|
#define C_ALPHA BIT(0) /* a-z_A-Z */
|
|
|
|
|
#define C_DIGIT BIT(1) /* 0-9 */
|
2009-06-10 20:12:51 +02:00
|
|
|
|
#define C_LEX1 BIT(2) /* \t \n\0|&;<>() */
|
2006-11-16 14:35:00 +01:00
|
|
|
|
#define C_VAR1 BIT(3) /* *@#!$-? */
|
|
|
|
|
#define C_IFSWS BIT(4) /* \t \n (IFS white space) */
|
|
|
|
|
#define C_SUBOP1 BIT(5) /* "=-+?" */
|
2009-10-30 01:57:39 +01:00
|
|
|
|
#define C_QUOTE BIT(6) /* \t\n "#$&'()*;<=>?[\]`| (needing quoting) */
|
2006-11-16 14:35:00 +01:00
|
|
|
|
#define C_IFS BIT(7) /* $IFS */
|
2008-03-01 22:10:26 +01:00
|
|
|
|
#define C_SUBOP2 BIT(8) /* "#%" (magic, see below) */
|
2005-05-23 05:06:10 +02:00
|
|
|
|
|
2006-11-10 00:39:16 +01:00
|
|
|
|
extern unsigned char chtypes[];
|
2005-05-23 05:06:10 +02:00
|
|
|
|
|
2011-03-07 21:30:41 +01:00
|
|
|
|
#define ctype(c, t) tobool( ((t) == C_SUBOP2) ? \
|
2008-03-01 22:10:26 +01:00
|
|
|
|
(((c) == '#' || (c) == '%') ? 1 : 0) : \
|
2011-03-07 21:30:41 +01:00
|
|
|
|
(chtypes[(unsigned char)(c)] & (t)) )
|
2006-11-10 08:52:04 +01:00
|
|
|
|
#define ksh_isalphx(c) ctype((c), C_ALPHA)
|
|
|
|
|
#define ksh_isalnux(c) ctype((c), C_ALPHA | C_DIGIT)
|
2005-05-23 05:06:10 +02:00
|
|
|
|
|
2011-09-07 17:24:22 +02:00
|
|
|
|
EXTERN int ifs0 E_INIT(' '); /* for "$*" */
|
2005-05-23 05:06:10 +02:00
|
|
|
|
|
|
|
|
|
/* Argument parsing for built-in commands and getopts command */
|
|
|
|
|
|
|
|
|
|
/* Values for Getopt.flags */
|
|
|
|
|
#define GF_ERROR BIT(0) /* call errorf() if there is an error */
|
|
|
|
|
#define GF_PLUSOPT BIT(1) /* allow +c as an option */
|
|
|
|
|
#define GF_NONAME BIT(2) /* don't print argv[0] in errors */
|
|
|
|
|
|
|
|
|
|
/* Values for Getopt.info */
|
|
|
|
|
#define GI_MINUS BIT(0) /* an option started with -... */
|
|
|
|
|
#define GI_PLUS BIT(1) /* an option started with +... */
|
|
|
|
|
#define GI_MINUSMINUS BIT(2) /* arguments were ended with -- */
|
|
|
|
|
|
2011-08-27 20:06:52 +02:00
|
|
|
|
/* in case some OS defines these */
|
|
|
|
|
#undef optarg
|
|
|
|
|
#undef optind
|
|
|
|
|
|
2005-05-23 05:06:10 +02:00
|
|
|
|
typedef struct {
|
2010-08-28 17:48:20 +02:00
|
|
|
|
const char *optarg;
|
|
|
|
|
int optind;
|
|
|
|
|
int uoptind; /* what user sees in $OPTIND */
|
|
|
|
|
int flags; /* see GF_* */
|
|
|
|
|
int info; /* see GI_* */
|
|
|
|
|
unsigned int p; /* 0 or index into argv[optind - 1] */
|
|
|
|
|
char buf[2]; /* for bad option OPTARG value */
|
2005-05-23 05:06:10 +02:00
|
|
|
|
} Getopt;
|
|
|
|
|
|
|
|
|
|
EXTERN Getopt builtin_opt; /* for shell builtin commands */
|
|
|
|
|
EXTERN Getopt user_opt; /* parsing state for getopts builtin command */
|
|
|
|
|
|
|
|
|
|
/* This for co-processes */
|
|
|
|
|
|
2011-06-21 23:10:12 +02:00
|
|
|
|
/* something that won't (realisticly) wrap */
|
|
|
|
|
typedef int32_t Coproc_id;
|
|
|
|
|
|
2005-05-23 05:06:10 +02:00
|
|
|
|
struct coproc {
|
2009-04-07 20:41:37 +02:00
|
|
|
|
void *job; /* 0 or job of co-process using input pipe */
|
2006-08-23 00:16:04 +02:00
|
|
|
|
int read; /* pipe from co-process's stdout */
|
|
|
|
|
int readw; /* other side of read (saved temporarily) */
|
|
|
|
|
int write; /* pipe to co-process's stdin */
|
|
|
|
|
int njobs; /* number of live jobs using output pipe */
|
2009-04-07 20:41:37 +02:00
|
|
|
|
Coproc_id id; /* id of current output pipe */
|
2005-05-23 05:06:10 +02:00
|
|
|
|
};
|
|
|
|
|
EXTERN struct coproc coproc;
|
|
|
|
|
|
2011-01-30 02:35:35 +01:00
|
|
|
|
#ifndef MKSH_NOPROSPECTOFWORK
|
2011-02-11 01:41:38 +01:00
|
|
|
|
/* used in jobs.c and by coprocess stuff in exec.c and select() calls */
|
2005-05-23 05:06:10 +02:00
|
|
|
|
EXTERN sigset_t sm_default, sm_sigchld;
|
2011-01-30 02:35:35 +01:00
|
|
|
|
#endif
|
2005-05-23 05:06:10 +02:00
|
|
|
|
|
|
|
|
|
/* name of called builtin function (used by error functions) */
|
2007-03-04 01:13:17 +01:00
|
|
|
|
EXTERN const char *builtin_argv0;
|
2011-06-21 23:10:12 +02:00
|
|
|
|
/* flags of called builtin (SPEC_BI, etc.) */
|
2011-07-05 22:12:20 +02:00
|
|
|
|
EXTERN uint32_t builtin_flag;
|
2005-05-23 05:06:10 +02:00
|
|
|
|
|
2011-04-22 14:21:55 +02:00
|
|
|
|
/* current working directory */
|
2005-05-23 05:06:10 +02:00
|
|
|
|
EXTERN char *current_wd;
|
|
|
|
|
|
2011-06-21 23:10:12 +02:00
|
|
|
|
/*
|
|
|
|
|
* Minimum required space to work with on a line - if the prompt leaves
|
|
|
|
|
* less space than this on a line, the prompt is truncated.
|
2005-05-23 05:06:10 +02:00
|
|
|
|
*/
|
|
|
|
|
#define MIN_EDIT_SPACE 7
|
2011-06-21 23:10:12 +02:00
|
|
|
|
/*
|
|
|
|
|
* Minimum allowed value for x_cols: 2 for prompt, 3 for " < " at end of line
|
2005-05-23 05:06:10 +02:00
|
|
|
|
*/
|
|
|
|
|
#define MIN_COLS (2 + MIN_EDIT_SPACE + 3)
|
2008-12-29 21:53:48 +01:00
|
|
|
|
#define MIN_LINS 3
|
2011-09-07 17:24:22 +02:00
|
|
|
|
EXTERN mksh_ari_t x_cols E_INIT(80); /* tty columns */
|
2012-03-23 22:58:24 +01:00
|
|
|
|
EXTERN mksh_ari_t x_lins E_INIT(24); /* tty lines */
|
2005-05-23 05:06:10 +02:00
|
|
|
|
|
2011-07-16 19:08:21 +02:00
|
|
|
|
|
2005-05-23 05:06:10 +02:00
|
|
|
|
/* Determine the location of the system (common) profile */
|
2011-07-16 19:08:21 +02:00
|
|
|
|
|
2012-08-24 21:09:10 +02:00
|
|
|
|
#ifndef MKSH_DEFAULT_PROFILEDIR
|
2011-07-16 19:08:21 +02:00
|
|
|
|
#if defined(ANDROID)
|
2012-08-24 21:09:10 +02:00
|
|
|
|
#define MKSH_DEFAULT_PROFILEDIR "/system/etc"
|
2011-07-16 19:08:21 +02:00
|
|
|
|
#else
|
2012-08-24 21:09:10 +02:00
|
|
|
|
#define MKSH_DEFAULT_PROFILEDIR "/etc"
|
|
|
|
|
#endif
|
2011-07-16 19:08:21 +02:00
|
|
|
|
#endif
|
|
|
|
|
|
2012-08-24 21:09:10 +02:00
|
|
|
|
#define MKSH_SYSTEM_PROFILE MKSH_DEFAULT_PROFILEDIR "/profile"
|
|
|
|
|
#define MKSH_SUID_PROFILE MKSH_DEFAULT_PROFILEDIR "/suid_profile"
|
2011-07-16 19:08:21 +02:00
|
|
|
|
|
2005-05-23 05:06:10 +02:00
|
|
|
|
|
|
|
|
|
/* Used by v_evaluate() and setstr() to control action when error occurs */
|
2012-03-31 19:30:00 +02:00
|
|
|
|
#define KSH_UNWIND_ERROR 0 /* unwind the stack (kshlongjmp) */
|
2005-05-23 05:06:10 +02:00
|
|
|
|
#define KSH_RETURN_ERROR 1 /* return 1/0 for success/failure */
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Shell file I/O routines
|
|
|
|
|
*/
|
|
|
|
|
|
2011-07-16 19:07:35 +02:00
|
|
|
|
#define SHF_BSIZE 512
|
2005-05-23 05:06:10 +02:00
|
|
|
|
|
2011-07-16 19:07:35 +02:00
|
|
|
|
#define shf_fileno(shf) ((shf)->fd)
|
2005-05-23 05:06:10 +02:00
|
|
|
|
#define shf_setfileno(shf,nfd) ((shf)->fd = (nfd))
|
2011-10-26 00:36:39 +02:00
|
|
|
|
#define shf_getc_i(shf) ((shf)->rnleft > 0 ? \
|
2010-01-29 10:34:31 +01:00
|
|
|
|
(shf)->rnleft--, *(shf)->rp++ : \
|
|
|
|
|
shf_getchar(shf))
|
2011-10-26 00:36:39 +02:00
|
|
|
|
#define shf_putc_i(c, shf) ((shf)->wnleft == 0 ? \
|
2010-01-29 10:34:31 +01:00
|
|
|
|
shf_putchar((c), (shf)) : \
|
2005-05-23 05:06:10 +02:00
|
|
|
|
((shf)->wnleft--, *(shf)->wp++ = (c)))
|
|
|
|
|
#define shf_eof(shf) ((shf)->flags & SHF_EOF)
|
|
|
|
|
#define shf_error(shf) ((shf)->flags & SHF_ERROR)
|
2011-09-07 17:24:22 +02:00
|
|
|
|
#define shf_errno(shf) ((shf)->errnosv)
|
2005-05-23 05:06:10 +02:00
|
|
|
|
#define shf_clearerr(shf) ((shf)->flags &= ~(SHF_EOF | SHF_ERROR))
|
|
|
|
|
|
|
|
|
|
/* Flags passed to shf_*open() */
|
|
|
|
|
#define SHF_RD 0x0001
|
|
|
|
|
#define SHF_WR 0x0002
|
|
|
|
|
#define SHF_RDWR (SHF_RD|SHF_WR)
|
|
|
|
|
#define SHF_ACCMODE 0x0003 /* mask */
|
|
|
|
|
#define SHF_GETFL 0x0004 /* use fcntl() to figure RD/WR flags */
|
|
|
|
|
#define SHF_UNBUF 0x0008 /* unbuffered I/O */
|
|
|
|
|
#define SHF_CLEXEC 0x0010 /* set close on exec flag */
|
|
|
|
|
#define SHF_MAPHI 0x0020 /* make fd > FDBASE (and close orig)
|
|
|
|
|
* (shf_open() only) */
|
|
|
|
|
#define SHF_DYNAMIC 0x0040 /* string: increase buffer as needed */
|
|
|
|
|
#define SHF_INTERRUPT 0x0080 /* EINTR in read/write causes error */
|
|
|
|
|
/* Flags used internally */
|
|
|
|
|
#define SHF_STRING 0x0100 /* a string, not a file */
|
|
|
|
|
#define SHF_ALLOCS 0x0200 /* shf and shf->buf were alloc()ed */
|
|
|
|
|
#define SHF_ALLOCB 0x0400 /* shf->buf was alloc()ed */
|
|
|
|
|
#define SHF_ERROR 0x0800 /* read()/write() error */
|
|
|
|
|
#define SHF_EOF 0x1000 /* read eof (sticky) */
|
|
|
|
|
#define SHF_READING 0x2000 /* currently reading: rnleft,rp valid */
|
|
|
|
|
#define SHF_WRITING 0x4000 /* currently writing: wnleft,wp valid */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct shf {
|
2009-04-07 20:41:37 +02:00
|
|
|
|
Area *areap; /* area shf/buf were allocated in */
|
2005-05-23 05:06:10 +02:00
|
|
|
|
unsigned char *rp; /* read: current position in buffer */
|
2009-04-07 20:41:37 +02:00
|
|
|
|
unsigned char *wp; /* write: current position in buffer */
|
|
|
|
|
unsigned char *buf; /* buffer */
|
2011-08-27 20:06:52 +02:00
|
|
|
|
ssize_t bsize; /* actual size of buf */
|
|
|
|
|
ssize_t rbsize; /* size of buffer (1 if SHF_UNBUF) */
|
|
|
|
|
ssize_t rnleft; /* read: how much data left in buffer */
|
|
|
|
|
ssize_t wbsize; /* size of buffer (0 if SHF_UNBUF) */
|
|
|
|
|
ssize_t wnleft; /* write: how much space left in buffer */
|
2009-04-07 20:41:37 +02:00
|
|
|
|
int flags; /* see SHF_* */
|
2005-05-23 05:06:10 +02:00
|
|
|
|
int fd; /* file descriptor */
|
2011-09-07 17:24:22 +02:00
|
|
|
|
int errnosv; /* saved value of errno after error */
|
2005-05-23 05:06:10 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
extern struct shf shf_iob[];
|
|
|
|
|
|
|
|
|
|
struct table {
|
2008-12-13 18:02:18 +01:00
|
|
|
|
Area *areap; /* area to allocate entries */
|
2006-08-23 00:16:04 +02:00
|
|
|
|
struct tbl **tbls; /* hashed table items */
|
2011-08-27 20:06:52 +02:00
|
|
|
|
size_t nfree; /* free table entries */
|
2011-06-05 21:58:21 +02:00
|
|
|
|
uint8_t tshift; /* table size (2^tshift) */
|
2005-05-23 05:06:10 +02:00
|
|
|
|
};
|
|
|
|
|
|
2011-07-05 22:12:20 +02:00
|
|
|
|
/* table item */
|
|
|
|
|
struct tbl {
|
|
|
|
|
/* Area to allocate from */
|
|
|
|
|
Area *areap;
|
|
|
|
|
/* value */
|
2005-05-23 05:06:10 +02:00
|
|
|
|
union {
|
2011-07-05 22:12:20 +02:00
|
|
|
|
char *s; /* string */
|
|
|
|
|
mksh_ari_t i; /* integer */
|
|
|
|
|
mksh_uari_t u; /* unsigned integer */
|
|
|
|
|
int (*f)(const char **); /* built-in command */
|
|
|
|
|
struct op *t; /* "function" tree */
|
|
|
|
|
} val;
|
2005-05-23 05:06:10 +02:00
|
|
|
|
union {
|
|
|
|
|
struct tbl *array; /* array values */
|
2006-11-12 15:58:16 +01:00
|
|
|
|
const char *fpath; /* temporary path to undef function */
|
2005-05-23 05:06:10 +02:00
|
|
|
|
} u;
|
2009-08-28 20:33:05 +02:00
|
|
|
|
union {
|
2011-07-05 22:12:20 +02:00
|
|
|
|
int field; /* field with for -L/-R/-Z */
|
2011-09-07 17:24:22 +02:00
|
|
|
|
int errnov; /* CEXEC/CTALIAS */
|
2009-08-28 20:33:05 +02:00
|
|
|
|
} u2;
|
2009-08-28 23:01:27 +02:00
|
|
|
|
union {
|
|
|
|
|
uint32_t hval; /* hash(name) */
|
|
|
|
|
uint32_t index; /* index for an array */
|
|
|
|
|
} ua;
|
2011-07-05 22:12:20 +02:00
|
|
|
|
/*
|
|
|
|
|
* command type (see below), base (if INTEGER),
|
|
|
|
|
* offset from val.s of value (if EXPORT)
|
|
|
|
|
*/
|
|
|
|
|
int type;
|
|
|
|
|
/* flags (see below) */
|
|
|
|
|
uint32_t flag;
|
|
|
|
|
|
|
|
|
|
/* actually longer: name (variable length) */
|
|
|
|
|
char name[4];
|
2005-05-23 05:06:10 +02:00
|
|
|
|
};
|
|
|
|
|
|
2012-06-28 22:02:29 +02:00
|
|
|
|
EXTERN struct tbl vtemp;
|
|
|
|
|
|
2005-05-23 05:06:10 +02:00
|
|
|
|
/* common flag bits */
|
2006-11-16 14:35:00 +01:00
|
|
|
|
#define ALLOC BIT(0) /* val.s has been allocated */
|
|
|
|
|
#define DEFINED BIT(1) /* is defined in block */
|
|
|
|
|
#define ISSET BIT(2) /* has value, vp->val.[si] */
|
|
|
|
|
#define EXPORT BIT(3) /* exported variable/function */
|
|
|
|
|
#define TRACE BIT(4) /* var: user flagged, func: execution tracing */
|
2005-05-23 05:06:10 +02:00
|
|
|
|
/* (start non-common flags at 8) */
|
|
|
|
|
/* flag bits used for variables */
|
2006-11-16 14:35:00 +01:00
|
|
|
|
#define SPECIAL BIT(8) /* PATH, IFS, SECONDS, etc */
|
|
|
|
|
#define INTEGER BIT(9) /* val.i contains integer value */
|
|
|
|
|
#define RDONLY BIT(10) /* read-only variable */
|
|
|
|
|
#define LOCAL BIT(11) /* for local typeset() */
|
2005-05-23 05:06:10 +02:00
|
|
|
|
#define ARRAY BIT(13) /* array */
|
|
|
|
|
#define LJUST BIT(14) /* left justify */
|
|
|
|
|
#define RJUST BIT(15) /* right justify */
|
|
|
|
|
#define ZEROFIL BIT(16) /* 0 filled if RJUSTIFY, strip 0s if LJUSTIFY */
|
|
|
|
|
#define LCASEV BIT(17) /* convert to lower case */
|
2009-08-28 20:33:05 +02:00
|
|
|
|
#define UCASEV_AL BIT(18) /* convert to upper case / autoload function */
|
2005-05-23 05:06:10 +02:00
|
|
|
|
#define INT_U BIT(19) /* unsigned integer */
|
2011-02-18 23:26:13 +01:00
|
|
|
|
#define INT_L BIT(20) /* long integer (no-op but used as magic) */
|
2005-05-23 05:06:10 +02:00
|
|
|
|
#define IMPORT BIT(21) /* flag to typeset(): no arrays, must have = */
|
|
|
|
|
#define LOCAL_COPY BIT(22) /* with LOCAL - copy attrs from existing var */
|
|
|
|
|
#define EXPRINEVAL BIT(23) /* contents currently being evaluated */
|
|
|
|
|
#define EXPRLVALUE BIT(24) /* useable as lvalue (temp flag) */
|
2009-08-28 23:01:27 +02:00
|
|
|
|
#define AINDEX BIT(25) /* array index >0 = ua.index filled in */
|
2009-09-06 19:42:15 +02:00
|
|
|
|
#define ASSOC BIT(26) /* ARRAY ? associative : reference */
|
2005-05-23 05:06:10 +02:00
|
|
|
|
/* flag bits used for taliases/builtins/aliases/keywords/functions */
|
|
|
|
|
#define KEEPASN BIT(8) /* keep command assignments (eg, var=x cmd) */
|
|
|
|
|
#define FINUSE BIT(9) /* function being executed */
|
|
|
|
|
#define FDELETE BIT(10) /* function deleted while it was executing */
|
|
|
|
|
#define FKSH BIT(11) /* function defined with function x (vs x()) */
|
|
|
|
|
#define SPEC_BI BIT(12) /* a POSIX special builtin */
|
2011-06-21 23:10:12 +02:00
|
|
|
|
/*
|
|
|
|
|
* Attributes that can be set by the user (used to decide if an unset
|
|
|
|
|
* param should be repoted by set/typeset). Does not include ARRAY or
|
|
|
|
|
* LOCAL.
|
2005-05-23 05:06:10 +02:00
|
|
|
|
*/
|
2009-06-10 20:12:51 +02:00
|
|
|
|
#define USERATTRIB (EXPORT|INTEGER|RDONLY|LJUST|RJUST|ZEROFIL|\
|
|
|
|
|
LCASEV|UCASEV_AL|INT_U|INT_L)
|
2005-05-23 05:06:10 +02:00
|
|
|
|
|
2009-09-06 19:42:15 +02:00
|
|
|
|
#define arrayindex(vp) ((unsigned long)((vp)->flag & AINDEX ? \
|
|
|
|
|
(vp)->ua.index : 0))
|
|
|
|
|
|
2011-06-21 23:11:21 +02:00
|
|
|
|
EXTERN enum {
|
|
|
|
|
SRF_NOP,
|
|
|
|
|
SRF_ENABLE,
|
|
|
|
|
SRF_DISABLE
|
2011-09-07 17:24:22 +02:00
|
|
|
|
} set_refflag E_INIT(SRF_NOP);
|
2011-06-21 23:11:21 +02:00
|
|
|
|
|
2005-05-23 05:06:10 +02:00
|
|
|
|
/* command types */
|
• remove strcasestr.c, use home-grown implementation¹, call it stricmp,
and have it return an API-correct const char *
• enhance and stylify comments
• a little KNF and simplifications
• #ifdef DEBUG: replace strchr and strstr with ucstrchr and ucstrstr
that take and return a non-const char *, and fix the violations
• new cstrchr, cstrstr (take and give const char *)
• new vstrchr, vstrstr (take const or not, give boolean value)
• new afreechk(x) = afreechv(x,x) = if (x1) afree(x2, ATEMP)
• new ksh_isdash(str) = (str != NULL) && !strcmp(str, "-")
• replace the only use of strrchr with inlined code to shrink
• minor man page fixes
• Minix 3 signames are autogenerated with gcc
• rename strlfun.c to strlcpy.c since we don't do strlcat(3) anyway,
only strlcpy(3), and shorten it
• dot.mkshrc: move MKSH=… down to the export line
to not disturb the PS1 visual impression ☺
• dot.mkshrc: Lstripcom(): optimise
• bump version
¹) side effect from creating API-correct cstrchr, cstrstr, etc.
uses goto so it must be better ☻
tested on mirbsd-current via both Makefile and Build.sh
2007-03-04 04:04:28 +01:00
|
|
|
|
#define CNONE 0 /* undefined */
|
|
|
|
|
#define CSHELL 1 /* built-in */
|
|
|
|
|
#define CFUNC 2 /* function */
|
|
|
|
|
#define CEXEC 4 /* executable command */
|
|
|
|
|
#define CALIAS 5 /* alias */
|
|
|
|
|
#define CKEYWD 6 /* keyword */
|
|
|
|
|
#define CTALIAS 7 /* tracked alias */
|
2005-05-23 05:06:10 +02:00
|
|
|
|
|
|
|
|
|
/* Flags for findcom()/comexec() */
|
|
|
|
|
#define FC_SPECBI BIT(0) /* special builtin */
|
2013-04-26 23:22:50 +02:00
|
|
|
|
#define FC_FUNC BIT(1) /* function */
|
|
|
|
|
#define FC_NORMBI BIT(2) /* not special builtin */
|
|
|
|
|
#define FC_BI (FC_SPECBI | FC_NORMBI)
|
|
|
|
|
#define FC_PATH BIT(3) /* do path search */
|
|
|
|
|
#define FC_DEFPATH BIT(4) /* use default path in path search */
|
2005-05-23 05:06:10 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define AF_ARGV_ALLOC 0x1 /* argv[] array allocated */
|
|
|
|
|
#define AF_ARGS_ALLOCED 0x2 /* argument strings allocated */
|
|
|
|
|
#define AI_ARGV(a, i) ((i) == 0 ? (a).argv[0] : (a).argv[(i) - (a).skip])
|
2011-09-07 17:24:22 +02:00
|
|
|
|
#define AI_ARGC(a) ((a).ai_argc - (a).skip)
|
2005-05-23 05:06:10 +02:00
|
|
|
|
|
2006-08-23 00:16:04 +02:00
|
|
|
|
/* Argument info. Used for $#, $* for shell, functions, includes, etc. */
|
2005-05-23 05:06:10 +02:00
|
|
|
|
struct arg_info {
|
• remove strcasestr.c, use home-grown implementation¹, call it stricmp,
and have it return an API-correct const char *
• enhance and stylify comments
• a little KNF and simplifications
• #ifdef DEBUG: replace strchr and strstr with ucstrchr and ucstrstr
that take and return a non-const char *, and fix the violations
• new cstrchr, cstrstr (take and give const char *)
• new vstrchr, vstrstr (take const or not, give boolean value)
• new afreechk(x) = afreechv(x,x) = if (x1) afree(x2, ATEMP)
• new ksh_isdash(str) = (str != NULL) && !strcmp(str, "-")
• replace the only use of strrchr with inlined code to shrink
• minor man page fixes
• Minix 3 signames are autogenerated with gcc
• rename strlfun.c to strlcpy.c since we don't do strlcat(3) anyway,
only strlcpy(3), and shorten it
• dot.mkshrc: move MKSH=… down to the export line
to not disturb the PS1 visual impression ☺
• dot.mkshrc: Lstripcom(): optimise
• bump version
¹) side effect from creating API-correct cstrchr, cstrstr, etc.
uses goto so it must be better ☻
tested on mirbsd-current via both Makefile and Build.sh
2007-03-04 04:04:28 +01:00
|
|
|
|
const char **argv;
|
2009-04-07 20:41:37 +02:00
|
|
|
|
int flags; /* AF_* */
|
2011-09-07 17:24:22 +02:00
|
|
|
|
int ai_argc;
|
2005-05-23 05:06:10 +02:00
|
|
|
|
int skip; /* first arg is argv[0], second is argv[1 + skip] */
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* activation record for function blocks
|
|
|
|
|
*/
|
|
|
|
|
struct block {
|
2008-12-13 18:02:18 +01:00
|
|
|
|
Area area; /* area to allocate things */
|
2007-03-04 01:13:17 +01:00
|
|
|
|
const char **argv;
|
2006-08-23 00:16:04 +02:00
|
|
|
|
char *error; /* error handler */
|
|
|
|
|
char *exit; /* exit handler */
|
|
|
|
|
struct block *next; /* enclosing block */
|
2009-04-07 20:41:37 +02:00
|
|
|
|
struct table vars; /* local variables */
|
|
|
|
|
struct table funs; /* local functions */
|
|
|
|
|
Getopt getopts_state;
|
|
|
|
|
int argc;
|
|
|
|
|
int flags; /* see BF_* */
|
2005-05-23 05:06:10 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* Values for struct block.flags */
|
|
|
|
|
#define BF_DOGETOPTS BIT(0) /* save/restore getopts state */
|
|
|
|
|
|
|
|
|
|
/*
|
2006-01-29 21:04:54 +01:00
|
|
|
|
* Used by ktwalk() and ktnext() routines.
|
2005-05-23 05:06:10 +02:00
|
|
|
|
*/
|
|
|
|
|
struct tstate {
|
|
|
|
|
struct tbl **next;
|
2009-08-28 20:59:01 +02:00
|
|
|
|
ssize_t left;
|
2005-05-23 05:06:10 +02:00
|
|
|
|
};
|
|
|
|
|
|
• remove strcasestr.c, use home-grown implementation¹, call it stricmp,
and have it return an API-correct const char *
• enhance and stylify comments
• a little KNF and simplifications
• #ifdef DEBUG: replace strchr and strstr with ucstrchr and ucstrstr
that take and return a non-const char *, and fix the violations
• new cstrchr, cstrstr (take and give const char *)
• new vstrchr, vstrstr (take const or not, give boolean value)
• new afreechk(x) = afreechv(x,x) = if (x1) afree(x2, ATEMP)
• new ksh_isdash(str) = (str != NULL) && !strcmp(str, "-")
• replace the only use of strrchr with inlined code to shrink
• minor man page fixes
• Minix 3 signames are autogenerated with gcc
• rename strlfun.c to strlcpy.c since we don't do strlcat(3) anyway,
only strlcpy(3), and shorten it
• dot.mkshrc: move MKSH=… down to the export line
to not disturb the PS1 visual impression ☺
• dot.mkshrc: Lstripcom(): optimise
• bump version
¹) side effect from creating API-correct cstrchr, cstrstr, etc.
uses goto so it must be better ☻
tested on mirbsd-current via both Makefile and Build.sh
2007-03-04 04:04:28 +01:00
|
|
|
|
EXTERN struct table taliases; /* tracked aliases */
|
|
|
|
|
EXTERN struct table builtins; /* built-in commands */
|
|
|
|
|
EXTERN struct table aliases; /* aliases */
|
|
|
|
|
EXTERN struct table keywords; /* keywords */
|
2009-07-25 22:26:33 +02:00
|
|
|
|
#ifndef MKSH_NOPWNAM
|
• remove strcasestr.c, use home-grown implementation¹, call it stricmp,
and have it return an API-correct const char *
• enhance and stylify comments
• a little KNF and simplifications
• #ifdef DEBUG: replace strchr and strstr with ucstrchr and ucstrstr
that take and return a non-const char *, and fix the violations
• new cstrchr, cstrstr (take and give const char *)
• new vstrchr, vstrstr (take const or not, give boolean value)
• new afreechk(x) = afreechv(x,x) = if (x1) afree(x2, ATEMP)
• new ksh_isdash(str) = (str != NULL) && !strcmp(str, "-")
• replace the only use of strrchr with inlined code to shrink
• minor man page fixes
• Minix 3 signames are autogenerated with gcc
• rename strlfun.c to strlcpy.c since we don't do strlcat(3) anyway,
only strlcpy(3), and shorten it
• dot.mkshrc: move MKSH=… down to the export line
to not disturb the PS1 visual impression ☺
• dot.mkshrc: Lstripcom(): optimise
• bump version
¹) side effect from creating API-correct cstrchr, cstrstr, etc.
uses goto so it must be better ☻
tested on mirbsd-current via both Makefile and Build.sh
2007-03-04 04:04:28 +01:00
|
|
|
|
EXTERN struct table homedirs; /* homedir() cache */
|
2007-01-11 01:32:31 +01:00
|
|
|
|
#endif
|
2005-05-23 05:06:10 +02:00
|
|
|
|
|
|
|
|
|
struct builtin {
|
2006-08-23 00:16:04 +02:00
|
|
|
|
const char *name;
|
2007-03-04 01:13:17 +01:00
|
|
|
|
int (*func)(const char **);
|
2005-05-23 05:06:10 +02:00
|
|
|
|
};
|
|
|
|
|
|
2007-08-20 00:06:27 +02:00
|
|
|
|
extern const struct builtin mkshbuiltins[];
|
2005-05-23 05:06:10 +02:00
|
|
|
|
|
|
|
|
|
/* values for set_prompt() */
|
2006-08-23 00:21:20 +02:00
|
|
|
|
#define PS1 0 /* command */
|
|
|
|
|
#define PS2 1 /* command continuation */
|
2005-05-23 05:06:10 +02:00
|
|
|
|
|
|
|
|
|
EXTERN char *path; /* copy of either PATH or def_path */
|
|
|
|
|
EXTERN const char *def_path; /* path to use if PATH not set */
|
|
|
|
|
EXTERN char *tmpdir; /* TMPDIR value */
|
|
|
|
|
EXTERN const char *prompt;
|
|
|
|
|
EXTERN int cur_prompt; /* PS1 or PS2 */
|
|
|
|
|
EXTERN int current_lineno; /* LINENO value */
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Description of a command or an operation on commands.
|
|
|
|
|
*/
|
|
|
|
|
struct op {
|
2007-03-04 01:13:17 +01:00
|
|
|
|
const char **args; /* arguments to a command */
|
2006-08-23 00:16:04 +02:00
|
|
|
|
char **vars; /* variable assignments */
|
|
|
|
|
struct ioword **ioact; /* IO actions (eg, < > >>) */
|
2005-05-23 05:06:10 +02:00
|
|
|
|
struct op *left, *right; /* descendents */
|
2006-08-23 00:16:04 +02:00
|
|
|
|
char *str; /* word for case; identifier for for,
|
2005-05-23 05:06:10 +02:00
|
|
|
|
* select, and functions;
|
|
|
|
|
* path to execute for TEXEC;
|
|
|
|
|
* time hook for TCOM.
|
|
|
|
|
*/
|
2006-08-23 00:16:04 +02:00
|
|
|
|
int lineno; /* TCOM/TFUNC: LINENO for this */
|
2007-10-25 17:19:16 +02:00
|
|
|
|
short type; /* operation type, see below */
|
2011-05-29 04:18:57 +02:00
|
|
|
|
/* WARNING: newtp(), tcopy() use evalflags = 0 to clear union */
|
2011-04-09 17:14:55 +02:00
|
|
|
|
union {
|
2011-05-29 04:18:57 +02:00
|
|
|
|
/* TCOM: arg expansion eval() flags */
|
|
|
|
|
short evalflags;
|
|
|
|
|
/* TFUNC: function x (vs x()) */
|
|
|
|
|
short ksh_func;
|
|
|
|
|
/* TPAT: termination character */
|
|
|
|
|
char charflag;
|
2007-10-25 17:19:16 +02:00
|
|
|
|
} u;
|
2005-05-23 05:06:10 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* Tree.type values */
|
2006-11-16 14:35:00 +01:00
|
|
|
|
#define TEOF 0
|
|
|
|
|
#define TCOM 1 /* command */
|
|
|
|
|
#define TPAREN 2 /* (c-list) */
|
|
|
|
|
#define TPIPE 3 /* a | b */
|
|
|
|
|
#define TLIST 4 /* a ; b */
|
|
|
|
|
#define TOR 5 /* || */
|
|
|
|
|
#define TAND 6 /* && */
|
2005-05-23 05:06:10 +02:00
|
|
|
|
#define TBANG 7 /* ! */
|
|
|
|
|
#define TDBRACKET 8 /* [[ .. ]] */
|
2006-11-16 14:35:00 +01:00
|
|
|
|
#define TFOR 9
|
2005-05-23 05:06:10 +02:00
|
|
|
|
#define TSELECT 10
|
2006-11-16 14:35:00 +01:00
|
|
|
|
#define TCASE 11
|
|
|
|
|
#define TIF 12
|
|
|
|
|
#define TWHILE 13
|
|
|
|
|
#define TUNTIL 14
|
|
|
|
|
#define TELIF 15
|
|
|
|
|
#define TPAT 16 /* pattern in case */
|
|
|
|
|
#define TBRACE 17 /* {c-list} */
|
|
|
|
|
#define TASYNC 18 /* c & */
|
|
|
|
|
#define TFUNCT 19 /* function name { command; } */
|
|
|
|
|
#define TTIME 20 /* time pipeline */
|
|
|
|
|
#define TEXEC 21 /* fork/exec eval'd TCOM */
|
2005-05-23 05:06:10 +02:00
|
|
|
|
#define TCOPROC 22 /* coprocess |& */
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* prefix codes for words in command tree
|
|
|
|
|
*/
|
2006-11-16 14:35:00 +01:00
|
|
|
|
#define EOS 0 /* end of string */
|
|
|
|
|
#define CHAR 1 /* unquoted character */
|
|
|
|
|
#define QCHAR 2 /* quoted character */
|
|
|
|
|
#define COMSUB 3 /* $() substitution (0 terminated) */
|
2011-03-13 00:04:48 +01:00
|
|
|
|
#define EXPRSUB 4 /* $(()) substitution (0 terminated) */
|
2006-11-16 14:35:00 +01:00
|
|
|
|
#define OQUOTE 5 /* opening " or ' */
|
|
|
|
|
#define CQUOTE 6 /* closing " or ' */
|
|
|
|
|
#define OSUBST 7 /* opening ${ subst (followed by { or X) */
|
|
|
|
|
#define CSUBST 8 /* closing } of above (followed by } or X) */
|
2006-08-23 00:21:20 +02:00
|
|
|
|
#define OPAT 9 /* open pattern: *(, @(, etc. */
|
|
|
|
|
#define SPAT 10 /* separate pattern: | */
|
|
|
|
|
#define CPAT 11 /* close pattern: ) */
|
2007-07-06 03:53:36 +02:00
|
|
|
|
#define ADELIM 12 /* arbitrary delimiter: ${foo:2:3} ${foo/bar/baz} */
|
2012-10-22 22:19:18 +02:00
|
|
|
|
#define FUNSUB 14 /* ${ foo;} substitution (NUL terminated) */
|
2013-05-02 23:59:54 +02:00
|
|
|
|
#define VALSUB 15 /* ${|foo;} substitution (NUL terminated) */
|
2005-05-23 05:06:10 +02:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* IO redirection
|
|
|
|
|
*/
|
|
|
|
|
struct ioword {
|
2010-08-28 17:48:20 +02:00
|
|
|
|
int unit; /* unit affected */
|
|
|
|
|
int flag; /* action (below) */
|
|
|
|
|
char *name; /* file name (unused if heredoc) */
|
|
|
|
|
char *delim; /* delimiter for <<,<<- */
|
|
|
|
|
char *heredoc; /* content of heredoc */
|
2005-05-23 05:06:10 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* ioword.flag - type of redirection */
|
2011-05-05 02:05:01 +02:00
|
|
|
|
#define IOTYPE 0xF /* type: bits 0:3 */
|
|
|
|
|
#define IOREAD 0x1 /* < */
|
|
|
|
|
#define IOWRITE 0x2 /* > */
|
|
|
|
|
#define IORDWR 0x3 /* <>: todo */
|
|
|
|
|
#define IOHERE 0x4 /* << (here file) */
|
|
|
|
|
#define IOCAT 0x5 /* >> */
|
|
|
|
|
#define IODUP 0x6 /* <&/>& */
|
|
|
|
|
#define IOEVAL BIT(4) /* expand in << */
|
|
|
|
|
#define IOSKIP BIT(5) /* <<-, skip ^\t* */
|
|
|
|
|
#define IOCLOB BIT(6) /* >|, override -o noclobber */
|
|
|
|
|
#define IORDUP BIT(7) /* x<&y (as opposed to x>&y) */
|
|
|
|
|
#define IONAMEXP BIT(8) /* name has been expanded */
|
|
|
|
|
#define IOBASH BIT(9) /* &> etc. */
|
|
|
|
|
#define IOHERESTR BIT(10) /* <<< (here string) */
|
|
|
|
|
#define IONDELIM BIT(11) /* null delimiter (<<) */
|
2005-05-23 05:06:10 +02:00
|
|
|
|
|
|
|
|
|
/* execute/exchild flags */
|
2006-11-16 14:35:00 +01:00
|
|
|
|
#define XEXEC BIT(0) /* execute without forking */
|
|
|
|
|
#define XFORK BIT(1) /* fork before executing */
|
|
|
|
|
#define XBGND BIT(2) /* command & */
|
|
|
|
|
#define XPIPEI BIT(3) /* input is pipe */
|
|
|
|
|
#define XPIPEO BIT(4) /* output is pipe */
|
|
|
|
|
#define XXCOM BIT(5) /* `...` command */
|
|
|
|
|
#define XPCLOSE BIT(6) /* exchild: close close_fd in parent */
|
|
|
|
|
#define XCCLOSE BIT(7) /* exchild: close close_fd in child */
|
2005-05-23 05:06:10 +02:00
|
|
|
|
#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 */
|
2011-02-18 23:26:13 +01:00
|
|
|
|
#define XPIPEST BIT(11) /* want PIPESTATUS */
|
2005-05-23 05:06:10 +02:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* flags to control expansion of words (assumed by t->evalflags to fit
|
|
|
|
|
* in a short)
|
|
|
|
|
*/
|
2006-11-16 14:35:00 +01:00
|
|
|
|
#define DOBLANK BIT(0) /* perform blank interpretation */
|
|
|
|
|
#define DOGLOB BIT(1) /* expand [?* */
|
|
|
|
|
#define DOPAT BIT(2) /* quote *?[ */
|
|
|
|
|
#define DOTILDE BIT(3) /* normal ~ expansion (first char) */
|
2005-05-23 05:06:10 +02:00
|
|
|
|
#define DONTRUNCOMMAND BIT(4) /* do not run $(command) things */
|
|
|
|
|
#define DOASNTILDE BIT(5) /* assignment ~ expansion (after =, :) */
|
2011-09-07 17:24:22 +02:00
|
|
|
|
#define DOBRACE BIT(6) /* used by expand(): do brace expansion */
|
|
|
|
|
#define DOMAGIC BIT(7) /* used by expand(): string contains MAGIC */
|
|
|
|
|
#define DOTEMP BIT(8) /* dito: in word part of ${..[%#=?]..} */
|
2005-05-23 05:06:10 +02:00
|
|
|
|
#define DOVACHECK BIT(9) /* var assign check (for typeset, set, etc) */
|
|
|
|
|
#define DOMARKDIRS BIT(10) /* force markdirs behaviour */
|
2012-11-30 21:19:16 +01:00
|
|
|
|
#if !defined(MKSH_SMALL)
|
2012-10-21 23:26:41 +02:00
|
|
|
|
#define DOTCOMEXEC BIT(11) /* not an eval flag, used by sh -c hack */
|
|
|
|
|
#endif
|
2005-05-23 05:06:10 +02:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* The arguments of [[ .. ]] expressions are kept in t->args[] and flags
|
|
|
|
|
* indicating how the arguments have been munged are kept in t->vars[].
|
|
|
|
|
* The contents of t->vars[] are stuffed strings (so they can be treated
|
|
|
|
|
* like all other t->vars[]) in which the second character is the one that
|
2006-08-23 00:16:04 +02:00
|
|
|
|
* is examined. The DB_* defines are the values for these second characters.
|
2005-05-23 05:06:10 +02:00
|
|
|
|
*/
|
2006-08-23 00:21:20 +02:00
|
|
|
|
#define DB_NORM 1 /* normal argument */
|
|
|
|
|
#define DB_OR 2 /* || -> -o conversion */
|
|
|
|
|
#define DB_AND 3 /* && -> -a conversion */
|
|
|
|
|
#define DB_BE 4 /* an inserted -BE */
|
|
|
|
|
#define DB_PAT 5 /* a pattern argument */
|
2005-05-23 05:06:10 +02:00
|
|
|
|
|
2011-01-09 22:57:29 +01:00
|
|
|
|
#define X_EXTRA 20 /* this many extra bytes in X string */
|
2005-05-23 05:06:10 +02:00
|
|
|
|
|
|
|
|
|
typedef struct XString {
|
2006-08-23 00:16:04 +02:00
|
|
|
|
char *end, *beg; /* end, begin of string */
|
|
|
|
|
size_t len; /* length */
|
2008-12-13 18:02:18 +01:00
|
|
|
|
Area *areap; /* area to allocate/free from */
|
2005-05-23 05:06:10 +02:00
|
|
|
|
} XString;
|
|
|
|
|
|
|
|
|
|
typedef char *XStringP;
|
|
|
|
|
|
2007-01-12 11:18:22 +01:00
|
|
|
|
/* initialise expandable string */
|
2008-03-28 14:46:53 +01:00
|
|
|
|
#define XinitN(xs, length, area) do { \
|
|
|
|
|
(xs).len = (length); \
|
|
|
|
|
(xs).areap = (area); \
|
2008-12-13 18:02:18 +01:00
|
|
|
|
(xs).beg = alloc((xs).len + X_EXTRA, (xs).areap); \
|
2008-03-28 14:46:53 +01:00
|
|
|
|
(xs).end = (xs).beg + (xs).len; \
|
2008-12-13 18:02:18 +01:00
|
|
|
|
} while (/* CONSTCOND */ 0)
|
2008-03-28 14:46:53 +01:00
|
|
|
|
#define Xinit(xs, xp, length, area) do { \
|
|
|
|
|
XinitN((xs), (length), (area)); \
|
|
|
|
|
(xp) = (xs).beg; \
|
2008-12-13 18:02:18 +01:00
|
|
|
|
} while (/* CONSTCOND */ 0)
|
2005-05-23 05:06:10 +02:00
|
|
|
|
|
|
|
|
|
/* stuff char into string */
|
2006-11-16 14:35:00 +01:00
|
|
|
|
#define Xput(xs, xp, c) (*xp++ = (c))
|
2005-05-23 05:06:10 +02:00
|
|
|
|
|
|
|
|
|
/* check if there are at least n bytes left */
|
2008-03-28 14:46:53 +01:00
|
|
|
|
#define XcheckN(xs, xp, n) do { \
|
2011-08-27 20:06:52 +02:00
|
|
|
|
ssize_t more = ((xp) + (n)) - (xs).end; \
|
2008-03-28 14:46:53 +01:00
|
|
|
|
if (more > 0) \
|
2011-10-26 00:25:07 +02:00
|
|
|
|
(xp) = Xcheck_grow(&(xs), (xp), more); \
|
2008-12-13 18:02:18 +01:00
|
|
|
|
} while (/* CONSTCOND */ 0)
|
2005-05-23 05:06:10 +02:00
|
|
|
|
|
|
|
|
|
/* check for overflow, expand string */
|
2008-03-28 14:46:53 +01:00
|
|
|
|
#define Xcheck(xs, xp) XcheckN((xs), (xp), 1)
|
2005-05-23 05:06:10 +02:00
|
|
|
|
|
|
|
|
|
/* free string */
|
2008-11-12 01:54:52 +01:00
|
|
|
|
#define Xfree(xs, xp) afree((xs).beg, (xs).areap)
|
2005-05-23 05:06:10 +02:00
|
|
|
|
|
|
|
|
|
/* close, return string */
|
2008-12-13 18:02:18 +01:00
|
|
|
|
#define Xclose(xs, xp) aresize((xs).beg, (xp) - (xs).beg, (xs).areap)
|
|
|
|
|
|
2005-05-23 05:06:10 +02:00
|
|
|
|
/* begin of string */
|
2006-11-16 14:35:00 +01:00
|
|
|
|
#define Xstring(xs, xp) ((xs).beg)
|
2005-05-23 05:06:10 +02:00
|
|
|
|
|
2008-12-13 18:02:18 +01:00
|
|
|
|
#define Xnleft(xs, xp) ((xs).end - (xp)) /* may be less than 0 */
|
|
|
|
|
#define Xlength(xs, xp) ((xp) - (xs).beg)
|
|
|
|
|
#define Xsize(xs, xp) ((xs).end - (xs).beg)
|
|
|
|
|
#define Xsavepos(xs, xp) ((xp) - (xs).beg)
|
|
|
|
|
#define Xrestpos(xs, xp, n) ((xs).beg + (n))
|
2005-05-23 05:06:10 +02:00
|
|
|
|
|
2011-10-26 00:25:07 +02:00
|
|
|
|
char *Xcheck_grow(XString *, const char *, size_t);
|
2005-05-23 05:06:10 +02:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* expandable vector of generic pointers
|
|
|
|
|
*/
|
|
|
|
|
|
2012-10-03 17:50:32 +02:00
|
|
|
|
typedef struct {
|
|
|
|
|
/* begin of allocated area */
|
|
|
|
|
void **beg;
|
|
|
|
|
/* currently used number of entries */
|
|
|
|
|
size_t len;
|
|
|
|
|
/* allocated number of entries */
|
|
|
|
|
size_t siz;
|
2005-05-23 05:06:10 +02:00
|
|
|
|
} XPtrV;
|
|
|
|
|
|
2012-10-03 17:50:32 +02:00
|
|
|
|
#define XPinit(x, n) do { \
|
|
|
|
|
(x).siz = (n); \
|
|
|
|
|
(x).len = 0; \
|
|
|
|
|
(x).beg = alloc2((x).siz, sizeof(void *), ATEMP); \
|
|
|
|
|
} while (/* CONSTCOND */ 0) \
|
|
|
|
|
|
|
|
|
|
#define XPput(x, p) do { \
|
|
|
|
|
if ((x).len == (x).siz) { \
|
|
|
|
|
(x).beg = aresize2((x).beg, (x).siz, \
|
|
|
|
|
2 * sizeof(void *), ATEMP); \
|
|
|
|
|
(x).siz <<= 1; \
|
2008-03-28 14:46:53 +01:00
|
|
|
|
} \
|
2012-10-03 17:50:32 +02:00
|
|
|
|
(x).beg[(x).len++] = (p); \
|
2008-12-13 18:02:18 +01:00
|
|
|
|
} while (/* CONSTCOND */ 0)
|
2005-05-23 05:06:10 +02:00
|
|
|
|
|
2006-11-16 14:35:00 +01:00
|
|
|
|
#define XPptrv(x) ((x).beg)
|
2012-10-03 17:50:32 +02:00
|
|
|
|
#define XPsize(x) ((x).len)
|
2010-09-14 23:26:19 +02:00
|
|
|
|
#define XPclose(x) aresize2((x).beg, XPsize(x), sizeof(void *), ATEMP)
|
2008-11-12 01:54:52 +01:00
|
|
|
|
#define XPfree(x) afree((x).beg, ATEMP)
|
2005-05-23 05:06:10 +02:00
|
|
|
|
|
2012-10-03 17:50:32 +02:00
|
|
|
|
/*
|
|
|
|
|
* Lexer internals
|
|
|
|
|
*/
|
2005-05-23 05:06:10 +02:00
|
|
|
|
|
|
|
|
|
typedef struct source Source;
|
|
|
|
|
struct source {
|
|
|
|
|
const char *str; /* input pointer */
|
|
|
|
|
const char *start; /* start of current buffer */
|
|
|
|
|
union {
|
2009-06-10 20:12:51 +02:00
|
|
|
|
const char **strv; /* string [] */
|
|
|
|
|
struct shf *shf; /* shell file */
|
|
|
|
|
struct tbl *tblp; /* alias (SF_HASALIAS) */
|
|
|
|
|
char *freeme; /* also for SREREAD */
|
2005-05-23 05:06:10 +02:00
|
|
|
|
} u;
|
2009-04-07 20:41:37 +02:00
|
|
|
|
const char *file; /* input file name */
|
|
|
|
|
int type; /* input type */
|
2005-05-23 05:06:10 +02:00
|
|
|
|
int line; /* line number */
|
|
|
|
|
int errline; /* line the error occurred on (0 if not set) */
|
|
|
|
|
int flags; /* SF_* */
|
2008-12-13 18:02:18 +01:00
|
|
|
|
Area *areap;
|
2005-05-23 05:06:10 +02:00
|
|
|
|
Source *next; /* stacked source */
|
2009-04-07 20:41:37 +02:00
|
|
|
|
XString xs; /* input buffer */
|
2007-03-10 19:16:28 +01:00
|
|
|
|
char ugbuf[2]; /* buffer for ungetsc() (SREREAD) and
|
|
|
|
|
* alias (SALIAS) */
|
2005-05-23 05:06:10 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* Source.type values */
|
2006-11-16 14:35:00 +01:00
|
|
|
|
#define SEOF 0 /* input EOF */
|
|
|
|
|
#define SFILE 1 /* file input */
|
2005-05-23 05:06:10 +02:00
|
|
|
|
#define SSTDIN 2 /* read stdin */
|
2006-11-16 14:35:00 +01:00
|
|
|
|
#define SSTRING 3 /* string */
|
|
|
|
|
#define SWSTR 4 /* string without \n */
|
|
|
|
|
#define SWORDS 5 /* string[] */
|
|
|
|
|
#define SWORDSEP 6 /* string[] separator */
|
|
|
|
|
#define SALIAS 7 /* alias expansion */
|
2005-05-23 05:06:10 +02:00
|
|
|
|
#define SREREAD 8 /* read ahead to be re-scanned */
|
2012-06-28 22:05:11 +02:00
|
|
|
|
#define SSTRINGCMDLINE 9 /* string from "mksh -c ..." */
|
2005-05-23 05:06:10 +02:00
|
|
|
|
|
|
|
|
|
/* Source.flags values */
|
|
|
|
|
#define SF_ECHO BIT(0) /* echo input to shlout */
|
|
|
|
|
#define SF_ALIAS BIT(1) /* faking space at end of alias */
|
|
|
|
|
#define SF_ALIASEND BIT(2) /* faking space at end of alias */
|
|
|
|
|
#define SF_TTY BIT(3) /* type == SSTDIN & it is a tty */
|
2011-03-13 17:03:54 +01:00
|
|
|
|
#define SF_HASALIAS BIT(4) /* u.tblp valid (SALIAS, SEOF) */
|
2012-11-30 21:19:16 +01:00
|
|
|
|
#if !defined(MKSH_SMALL)
|
2012-10-21 23:26:41 +02:00
|
|
|
|
#define SF_MAYEXEC BIT(5) /* special sh -c optimisation hack */
|
|
|
|
|
#endif
|
2005-05-23 05:06:10 +02:00
|
|
|
|
|
|
|
|
|
typedef union {
|
2006-08-23 00:16:04 +02:00
|
|
|
|
int i;
|
|
|
|
|
char *cp;
|
|
|
|
|
char **wp;
|
2005-05-23 05:06:10 +02:00
|
|
|
|
struct op *o;
|
|
|
|
|
struct ioword *iop;
|
|
|
|
|
} YYSTYPE;
|
|
|
|
|
|
|
|
|
|
/* If something is added here, add it to tokentab[] in syn.c as well */
|
2006-11-16 14:35:00 +01:00
|
|
|
|
#define LWORD 256
|
|
|
|
|
#define LOGAND 257 /* && */
|
|
|
|
|
#define LOGOR 258 /* || */
|
|
|
|
|
#define BREAK 259 /* ;; */
|
|
|
|
|
#define IF 260
|
|
|
|
|
#define THEN 261
|
|
|
|
|
#define ELSE 262
|
|
|
|
|
#define ELIF 263
|
|
|
|
|
#define FI 264
|
|
|
|
|
#define CASE 265
|
|
|
|
|
#define ESAC 266
|
|
|
|
|
#define FOR 267
|
2005-05-23 05:06:10 +02:00
|
|
|
|
#define SELECT 268
|
2006-11-16 14:35:00 +01:00
|
|
|
|
#define WHILE 269
|
|
|
|
|
#define UNTIL 270
|
|
|
|
|
#define DO 271
|
|
|
|
|
#define DONE 272
|
|
|
|
|
#define IN 273
|
|
|
|
|
#define FUNCTION 274
|
|
|
|
|
#define TIME 275
|
|
|
|
|
#define REDIR 276
|
2005-05-23 05:06:10 +02:00
|
|
|
|
#define MDPAREN 277 /* (( )) */
|
|
|
|
|
#define BANG 278 /* ! */
|
|
|
|
|
#define DBRACKET 279 /* [[ .. ]] */
|
|
|
|
|
#define COPROC 280 /* |& */
|
2011-05-29 04:18:57 +02:00
|
|
|
|
#define BRKEV 281 /* ;| */
|
|
|
|
|
#define BRKFT 282 /* ;& */
|
2006-11-16 14:35:00 +01:00
|
|
|
|
#define YYERRCODE 300
|
2005-05-23 05:06:10 +02:00
|
|
|
|
|
|
|
|
|
/* flags to yylex */
|
2006-11-16 14:35:00 +01:00
|
|
|
|
#define CONTIN BIT(0) /* skip new lines to complete command */
|
|
|
|
|
#define ONEWORD BIT(1) /* single word for substitute() */
|
2007-01-12 11:18:22 +01:00
|
|
|
|
#define ALIAS BIT(2) /* recognise alias */
|
|
|
|
|
#define KEYWORD BIT(3) /* recognise keywords */
|
2005-05-23 05:06:10 +02:00
|
|
|
|
#define LETEXPR BIT(4) /* get expression inside (( )) */
|
|
|
|
|
#define VARASN BIT(5) /* check for var=word */
|
|
|
|
|
#define ARRAYVAR BIT(6) /* parse x[1 & 2] as one word */
|
|
|
|
|
#define ESACONLY BIT(7) /* only accept esac keyword */
|
|
|
|
|
#define CMDWORD BIT(8) /* parsing simple command (alias related) */
|
|
|
|
|
#define HEREDELIM BIT(9) /* parsing <<,<<- delimiter */
|
2006-11-16 14:35:00 +01:00
|
|
|
|
#define LQCHAR BIT(10) /* source string contains QCHAR */
|
2013-02-17 06:40:17 +01:00
|
|
|
|
#define HEREDOC BIT(11) /* parsing a here document body */
|
2005-05-23 05:06:10 +02:00
|
|
|
|
|
2011-06-04 18:11:20 +02:00
|
|
|
|
#define HERES 10 /* max number of << in line */
|
2005-05-23 05:06:10 +02:00
|
|
|
|
|
2009-09-19 23:54:46 +02:00
|
|
|
|
#undef CTRL
|
|
|
|
|
#define CTRL(x) ((x) == '?' ? 0x7F : (x) & 0x1F) /* ASCII */
|
|
|
|
|
#define UNCTRL(x) ((x) ^ 0x40) /* ASCII */
|
|
|
|
|
|
2012-10-03 17:50:32 +02:00
|
|
|
|
#define IDENT 64
|
|
|
|
|
|
• remove strcasestr.c, use home-grown implementation¹, call it stricmp,
and have it return an API-correct const char *
• enhance and stylify comments
• a little KNF and simplifications
• #ifdef DEBUG: replace strchr and strstr with ucstrchr and ucstrstr
that take and return a non-const char *, and fix the violations
• new cstrchr, cstrstr (take and give const char *)
• new vstrchr, vstrstr (take const or not, give boolean value)
• new afreechk(x) = afreechv(x,x) = if (x1) afree(x2, ATEMP)
• new ksh_isdash(str) = (str != NULL) && !strcmp(str, "-")
• replace the only use of strrchr with inlined code to shrink
• minor man page fixes
• Minix 3 signames are autogenerated with gcc
• rename strlfun.c to strlcpy.c since we don't do strlcat(3) anyway,
only strlcpy(3), and shorten it
• dot.mkshrc: move MKSH=… down to the export line
to not disturb the PS1 visual impression ☺
• dot.mkshrc: Lstripcom(): optimise
• bump version
¹) side effect from creating API-correct cstrchr, cstrstr, etc.
uses goto so it must be better ☻
tested on mirbsd-current via both Makefile and Build.sh
2007-03-04 04:04:28 +01:00
|
|
|
|
EXTERN Source *source; /* yyparse/yylex source */
|
2011-08-27 20:06:52 +02:00
|
|
|
|
EXTERN YYSTYPE yylval; /* result from yylex */
|
|
|
|
|
EXTERN struct ioword *heres[HERES], **herep;
|
2012-10-03 17:50:32 +02:00
|
|
|
|
EXTERN char ident[IDENT + 1];
|
2005-05-23 05:06:10 +02:00
|
|
|
|
|
2011-12-30 22:00:32 +01:00
|
|
|
|
EXTERN char **history; /* saved commands */
|
|
|
|
|
EXTERN char **histptr; /* last history item */
|
|
|
|
|
EXTERN mksh_ari_t histsize; /* history size */
|
2005-05-23 05:06:10 +02:00
|
|
|
|
|
2007-03-10 19:16:28 +01:00
|
|
|
|
/* user and system time of last j_waitjed job */
|
|
|
|
|
EXTERN struct timeval j_usrtime, j_systime;
|
|
|
|
|
|
2012-10-03 18:16:15 +02:00
|
|
|
|
#define notok2mul(max, val, c) (((val) != 0) && ((c) != 0) && \
|
|
|
|
|
(((max) / (c)) < (val)))
|
|
|
|
|
#define notok2add(max, val, c) ((val) > ((max) - (c)))
|
|
|
|
|
#define notoktomul(val, cnst) notok2mul(SIZE_MAX, (val), (cnst))
|
|
|
|
|
#define notoktoadd(val, cnst) notok2add(SIZE_MAX, (val), (cnst))
|
2010-09-14 23:26:19 +02:00
|
|
|
|
#define checkoktoadd(val, cnst) do { \
|
|
|
|
|
if (notoktoadd((val), (cnst))) \
|
2011-09-07 17:24:22 +02:00
|
|
|
|
internal_errorf(Tintovfl, (size_t)(val), \
|
2011-08-27 20:06:52 +02:00
|
|
|
|
'+', (size_t)(cnst)); \
|
2010-09-14 23:26:19 +02:00
|
|
|
|
} while (/* CONSTCOND */ 0)
|
|
|
|
|
|
2011-07-07 00:22:02 +02:00
|
|
|
|
|
2012-04-22 23:50:35 +02:00
|
|
|
|
/* NZAAT hash based on Bob Jenkins' one-at-a-time hash */
|
2011-07-07 00:22:02 +02:00
|
|
|
|
|
2011-07-18 02:35:46 +02:00
|
|
|
|
/* From: src/kern/include/nzat.h,v 1.2 2011/07/18 00:35:40 tg Exp $ */
|
2011-07-07 00:22:02 +02:00
|
|
|
|
|
|
|
|
|
#define NZATInit(h) do { \
|
|
|
|
|
(h) = 0; \
|
2011-01-21 22:04:48 +01:00
|
|
|
|
} while (/* CONSTCOND */ 0)
|
2011-07-07 00:22:02 +02:00
|
|
|
|
|
|
|
|
|
#define NZATUpdateByte(h,b) do { \
|
|
|
|
|
(h) += (uint8_t)(b); \
|
|
|
|
|
++(h); \
|
|
|
|
|
(h) += (h) << 10; \
|
|
|
|
|
(h) ^= (h) >> 6; \
|
2011-01-21 22:04:48 +01:00
|
|
|
|
} while (/* CONSTCOND */ 0)
|
2011-07-07 00:22:02 +02:00
|
|
|
|
|
|
|
|
|
#define NZATUpdateMem(h,p,z) do { \
|
|
|
|
|
register const uint8_t *NZATUpdateMem_p; \
|
|
|
|
|
register size_t NZATUpdateMem_z = (z); \
|
|
|
|
|
\
|
|
|
|
|
NZATUpdateMem_p = (const void *)(p); \
|
|
|
|
|
while (NZATUpdateMem_z--) \
|
|
|
|
|
NZATUpdateByte((h), *NZATUpdateMem_p++); \
|
|
|
|
|
} while (/* CONSTCOND */ 0)
|
|
|
|
|
|
|
|
|
|
#define NZATUpdateString(h,s) do { \
|
|
|
|
|
register const char *NZATUpdateString_s; \
|
|
|
|
|
register uint8_t NZATUpdateString_c; \
|
|
|
|
|
\
|
|
|
|
|
NZATUpdateString_s = (const void *)(s); \
|
|
|
|
|
while ((NZATUpdateString_c = *NZATUpdateString_s++)) \
|
|
|
|
|
NZATUpdateByte((h), NZATUpdateString_c); \
|
2011-01-21 22:04:48 +01:00
|
|
|
|
} while (/* CONSTCOND */ 0)
|
2011-07-07 00:22:02 +02:00
|
|
|
|
|
|
|
|
|
#define NZAATFinish(h) do { \
|
2011-07-18 02:35:46 +02:00
|
|
|
|
(h) += (h) << 10; \
|
|
|
|
|
(h) ^= (h) >> 6; \
|
2011-07-07 00:22:02 +02:00
|
|
|
|
(h) += (h) << 3; \
|
|
|
|
|
(h) ^= (h) >> 11; \
|
|
|
|
|
(h) += (h) << 15; \
|
|
|
|
|
} while (/* CONSTCOND */ 0)
|
|
|
|
|
|
|
|
|
|
|
2009-03-22 17:55:38 +01:00
|
|
|
|
/* lalloc.c */
|
|
|
|
|
void ainit(Area *);
|
2008-12-13 18:02:18 +01:00
|
|
|
|
void afreeall(Area *);
|
2009-03-22 17:55:38 +01:00
|
|
|
|
/* these cannot fail and can take NULL (not for ap) */
|
2010-09-14 23:26:19 +02:00
|
|
|
|
#define alloc(n, ap) aresize(NULL, (n), (ap))
|
|
|
|
|
#define alloc2(m, n, ap) aresize2(NULL, (m), (n), (ap))
|
2008-12-13 18:02:18 +01:00
|
|
|
|
void *aresize(void *, size_t, Area *);
|
2010-09-14 23:26:19 +02:00
|
|
|
|
void *aresize2(void *, size_t, size_t, Area *);
|
2008-12-13 18:02:18 +01:00
|
|
|
|
void afree(void *, Area *); /* can take NULL */
|
2005-10-21 14:41:56 +02:00
|
|
|
|
/* edit.c */
|
2012-05-04 22:49:08 +02:00
|
|
|
|
#ifndef MKSH_NO_CMDLINE_EDITING
|
2010-02-23 19:13:04 +01:00
|
|
|
|
#ifndef MKSH_SMALL
|
|
|
|
|
int x_bind(const char *, const char *, bool, bool);
|
|
|
|
|
#else
|
|
|
|
|
int x_bind(const char *, const char *, bool);
|
|
|
|
|
#endif
|
2006-08-23 00:16:04 +02:00
|
|
|
|
void x_init(void);
|
2013-02-10 18:41:06 +01:00
|
|
|
|
#ifdef DEBUG_LEAKS
|
2013-02-10 18:38:15 +01:00
|
|
|
|
void x_done(void);
|
2013-02-10 18:39:38 +01:00
|
|
|
|
#endif
|
2006-08-23 00:16:04 +02:00
|
|
|
|
int x_read(char *, size_t);
|
2012-05-04 22:49:08 +02:00
|
|
|
|
#endif
|
2012-05-05 00:18:27 +02:00
|
|
|
|
void x_mkraw(int, mksh_ttyst *, bool);
|
2005-10-21 14:41:56 +02:00
|
|
|
|
/* eval.c */
|
2006-08-23 00:16:04 +02:00
|
|
|
|
char *substitute(const char *, int);
|
2007-03-04 01:13:17 +01:00
|
|
|
|
char **eval(const char **, int);
|
|
|
|
|
char *evalstr(const char *cp, int);
|
|
|
|
|
char *evalonestr(const char *cp, int);
|
2006-08-23 00:16:04 +02:00
|
|
|
|
char *debunk(char *, const char *, size_t);
|
2007-03-04 01:13:17 +01:00
|
|
|
|
void expand(const char *, XPtrV *, int);
|
2012-08-24 21:02:57 +02:00
|
|
|
|
int glob_str(char *, XPtrV *, bool);
|
2012-08-24 22:57:46 +02:00
|
|
|
|
char *tilde(char *);
|
2005-10-21 14:41:56 +02:00
|
|
|
|
/* exec.c */
|
2009-03-25 22:45:28 +01:00
|
|
|
|
int execute(struct op * volatile, volatile int, volatile int * volatile);
|
2007-03-04 01:13:17 +01:00
|
|
|
|
int shcomexec(const char **);
|
2009-08-28 22:30:59 +02:00
|
|
|
|
struct tbl *findfunc(const char *, uint32_t, bool);
|
2006-08-23 00:16:04 +02:00
|
|
|
|
int define(const char *, struct op *);
|
• more comment and int→bool cleanup, add and improve some comments
• in interactive mode, always look up {LC_{ALL,CTYPE},LANG} environment
variables if setlocale/nl_langinfo(CODESET) doesn’t suffice
• add the ability to call any builtin (some don't make sense or wouldn't
work) directly by analysing argv[0]
• for direct builtin calls, the {LC_{ALL,CTYPE},LANG} environment
variables determine utf8-mode, even if MKSH_ASSUME_UTF8 was set
• when called as builtin, echo behaves POSIXish
• add domainname as alias for true on MirBSD only, to be able to link it
• sync mksh Makefiles with Build.sh output
• adjust manpage wrt release plans
• link some things to mksh now that we have callable builtins:
bin/echo bin/kill bin/pwd bin/sleep (exact matches)
bin/test bin/[ (were scripts before)
bin/domainname=usr/bin/true usr/bin/false (move to /bin/ now)
• drop linked utilities and, except for echo and kill, their manpages
• adjust instbin and link a few more there as well
2011-02-11 02:18:23 +01:00
|
|
|
|
const char *builtin(const char *, int (*)(const char **));
|
2006-08-23 00:16:04 +02:00
|
|
|
|
struct tbl *findcom(const char *, int);
|
• more comment and int→bool cleanup, add and improve some comments
• in interactive mode, always look up {LC_{ALL,CTYPE},LANG} environment
variables if setlocale/nl_langinfo(CODESET) doesn’t suffice
• add the ability to call any builtin (some don't make sense or wouldn't
work) directly by analysing argv[0]
• for direct builtin calls, the {LC_{ALL,CTYPE},LANG} environment
variables determine utf8-mode, even if MKSH_ASSUME_UTF8 was set
• when called as builtin, echo behaves POSIXish
• add domainname as alias for true on MirBSD only, to be able to link it
• sync mksh Makefiles with Build.sh output
• adjust manpage wrt release plans
• link some things to mksh now that we have callable builtins:
bin/echo bin/kill bin/pwd bin/sleep (exact matches)
bin/test bin/[ (were scripts before)
bin/domainname=usr/bin/true usr/bin/false (move to /bin/ now)
• drop linked utilities and, except for echo and kill, their manpages
• adjust instbin and link a few more there as well
2011-02-11 02:18:23 +01:00
|
|
|
|
void flushcom(bool);
|
2011-09-07 17:24:22 +02:00
|
|
|
|
const char *search_path(const char *, const char *, int, int *);
|
2012-10-03 17:13:34 +02:00
|
|
|
|
void pr_menu(const char * const *);
|
|
|
|
|
void pr_list(char * const *);
|
2005-10-21 14:41:56 +02:00
|
|
|
|
/* expr.c */
|
2009-03-14 19:12:55 +01:00
|
|
|
|
int evaluate(const char *, mksh_ari_t *, int, bool);
|
2006-08-23 00:16:04 +02:00
|
|
|
|
int v_evaluate(struct tbl *, const char *, volatile int, bool);
|
2009-09-26 06:01:34 +02:00
|
|
|
|
/* UTF-8 stuff */
|
|
|
|
|
size_t utf_mbtowc(unsigned int *, const char *);
|
|
|
|
|
size_t utf_wctomb(char *, unsigned int);
|
|
|
|
|
int utf_widthadj(const char *, const char **);
|
2011-08-27 20:06:52 +02:00
|
|
|
|
size_t utf_mbswidth(const char *);
|
2009-09-26 06:01:34 +02:00
|
|
|
|
const char *utf_skipcols(const char *, int);
|
|
|
|
|
size_t utf_ptradj(const char *);
|
2010-08-14 23:35:13 +02:00
|
|
|
|
#ifndef MKSH_mirbsd_wcwidth
|
2009-09-26 06:01:34 +02:00
|
|
|
|
int utf_wcwidth(unsigned int);
|
2010-08-14 23:35:13 +02:00
|
|
|
|
#endif
|
2011-09-07 17:24:22 +02:00
|
|
|
|
int ksh_access(const char *, int);
|
2012-06-28 22:02:29 +02:00
|
|
|
|
struct tbl *tempvar(void);
|
2005-10-21 14:41:56 +02:00
|
|
|
|
/* funcs.c */
|
2007-03-04 01:13:17 +01:00
|
|
|
|
int c_hash(const char **);
|
|
|
|
|
int c_pwd(const char **);
|
|
|
|
|
int c_print(const char **);
|
2009-07-30 21:11:12 +02:00
|
|
|
|
#ifdef MKSH_PRINTF_BUILTIN
|
|
|
|
|
int c_printf(const char **);
|
|
|
|
|
#endif
|
2007-03-04 01:13:17 +01:00
|
|
|
|
int c_whence(const char **);
|
|
|
|
|
int c_command(const char **);
|
|
|
|
|
int c_typeset(const char **);
|
|
|
|
|
int c_alias(const char **);
|
|
|
|
|
int c_unalias(const char **);
|
|
|
|
|
int c_let(const char **);
|
|
|
|
|
int c_jobs(const char **);
|
2009-04-05 14:35:32 +02:00
|
|
|
|
#ifndef MKSH_UNEMPLOYED
|
2007-03-04 01:13:17 +01:00
|
|
|
|
int c_fgbg(const char **);
|
2009-04-05 14:35:32 +02:00
|
|
|
|
#endif
|
2007-03-04 01:13:17 +01:00
|
|
|
|
int c_kill(const char **);
|
2006-08-23 00:16:04 +02:00
|
|
|
|
void getopts_reset(int);
|
2007-03-04 01:13:17 +01:00
|
|
|
|
int c_getopts(const char **);
|
2012-05-04 22:49:08 +02:00
|
|
|
|
#ifndef MKSH_NO_CMDLINE_EDITING
|
2007-03-04 01:13:17 +01:00
|
|
|
|
int c_bind(const char **);
|
2012-05-04 22:49:08 +02:00
|
|
|
|
#endif
|
2007-03-04 01:13:17 +01:00
|
|
|
|
int c_shift(const char **);
|
|
|
|
|
int c_umask(const char **);
|
|
|
|
|
int c_dot(const char **);
|
|
|
|
|
int c_wait(const char **);
|
|
|
|
|
int c_read(const char **);
|
|
|
|
|
int c_eval(const char **);
|
|
|
|
|
int c_trap(const char **);
|
|
|
|
|
int c_brkcont(const char **);
|
|
|
|
|
int c_exitreturn(const char **);
|
|
|
|
|
int c_set(const char **);
|
|
|
|
|
int c_unset(const char **);
|
|
|
|
|
int c_ulimit(const char **);
|
|
|
|
|
int c_times(const char **);
|
2009-03-22 18:47:38 +01:00
|
|
|
|
int timex(struct op *, int, volatile int *);
|
2006-08-23 00:16:04 +02:00
|
|
|
|
void timex_hook(struct op *, char ** volatile *);
|
2007-03-04 01:13:17 +01:00
|
|
|
|
int c_exec(const char **);
|
2010-09-05 21:51:35 +02:00
|
|
|
|
/* dummy function (just need pointer value), special case in comexec() */
|
|
|
|
|
#define c_builtin shcomexec
|
2007-03-04 01:13:17 +01:00
|
|
|
|
int c_test(const char **);
|
2007-08-20 00:06:27 +02:00
|
|
|
|
#if HAVE_MKNOD
|
|
|
|
|
int c_mknod(const char **);
|
|
|
|
|
#endif
|
2008-05-17 20:27:57 +02:00
|
|
|
|
int c_realpath(const char **);
|
2007-08-20 00:06:27 +02:00
|
|
|
|
int c_rename(const char **);
|
2010-08-28 19:21:46 +02:00
|
|
|
|
int c_cat(const char **);
|
2011-02-11 01:41:38 +01:00
|
|
|
|
int c_sleep(const char **);
|
2005-05-23 05:06:10 +02:00
|
|
|
|
/* histrap.c */
|
2006-08-23 00:16:04 +02:00
|
|
|
|
void init_histvec(void);
|
|
|
|
|
void hist_init(Source *);
|
2007-03-03 22:36:08 +01:00
|
|
|
|
#if HAVE_PERSISTENT_HISTORY
|
2006-08-23 00:16:04 +02:00
|
|
|
|
void hist_finish(void);
|
2006-11-10 06:23:14 +01:00
|
|
|
|
#endif
|
2008-09-30 21:25:51 +02:00
|
|
|
|
void histsave(int *, const char *, bool, bool);
|
2010-01-25 17:12:57 +01:00
|
|
|
|
#if !defined(MKSH_SMALL) && HAVE_PERSISTENT_HISTORY
|
|
|
|
|
bool histsync(void);
|
|
|
|
|
#endif
|
2007-03-04 01:13:17 +01:00
|
|
|
|
int c_fc(const char **);
|
2011-12-30 22:00:32 +01:00
|
|
|
|
void sethistsize(mksh_ari_t);
|
2007-03-03 22:36:08 +01:00
|
|
|
|
#if HAVE_PERSISTENT_HISTORY
|
2006-08-23 00:16:04 +02:00
|
|
|
|
void sethistfile(const char *);
|
2006-11-10 06:23:14 +01:00
|
|
|
|
#endif
|
2012-05-04 22:49:08 +02:00
|
|
|
|
#if !defined(MKSH_NO_CMDLINE_EDITING) && !MKSH_S_NOVI
|
2006-08-23 00:16:04 +02:00
|
|
|
|
char **histpos(void);
|
|
|
|
|
int histnum(int);
|
2011-12-31 01:27:27 +01:00
|
|
|
|
#endif
|
2006-08-23 00:16:04 +02:00
|
|
|
|
int findhist(int, int, const char *, int);
|
2010-01-25 17:12:57 +01:00
|
|
|
|
char **hist_get_newest(bool);
|
2006-08-23 00:16:04 +02:00
|
|
|
|
void inittraps(void);
|
|
|
|
|
void alarm_init(void);
|
2012-04-06 15:29:01 +02:00
|
|
|
|
Trap *gettrap(const char *, bool);
|
2006-08-23 00:16:04 +02:00
|
|
|
|
void trapsig(int);
|
|
|
|
|
void intrcheck(void);
|
|
|
|
|
int fatal_trap_check(void);
|
|
|
|
|
int trap_pending(void);
|
|
|
|
|
void runtraps(int intr);
|
2010-11-01 18:29:05 +01:00
|
|
|
|
void runtrap(Trap *, bool);
|
2006-08-23 00:16:04 +02:00
|
|
|
|
void cleartraps(void);
|
|
|
|
|
void restoresigs(void);
|
2007-03-04 01:13:17 +01:00
|
|
|
|
void settrap(Trap *, const char *);
|
2006-08-23 00:16:04 +02:00
|
|
|
|
int block_pipe(void);
|
|
|
|
|
void restore_pipe(int);
|
|
|
|
|
int setsig(Trap *, sig_t, int);
|
|
|
|
|
void setexecsig(Trap *, int);
|
2012-03-28 00:36:53 +02:00
|
|
|
|
#if HAVE_FLOCK || HAVE_LOCK_FCNTL
|
|
|
|
|
void mksh_lockfd(int);
|
|
|
|
|
void mksh_unlkfd(int);
|
|
|
|
|
#endif
|
2005-05-23 05:06:10 +02:00
|
|
|
|
/* jobs.c */
|
2009-04-05 14:35:32 +02:00
|
|
|
|
void j_init(void);
|
2006-08-23 00:16:04 +02:00
|
|
|
|
void j_exit(void);
|
2009-04-05 14:35:32 +02:00
|
|
|
|
#ifndef MKSH_UNEMPLOYED
|
2006-08-23 00:16:04 +02:00
|
|
|
|
void j_change(void);
|
2009-04-05 14:35:32 +02:00
|
|
|
|
#endif
|
2009-03-22 18:47:38 +01:00
|
|
|
|
int exchild(struct op *, int, volatile int *, int);
|
2006-08-23 00:16:04 +02:00
|
|
|
|
void startlast(void);
|
|
|
|
|
int waitlast(void);
|
|
|
|
|
int waitfor(const char *, int *);
|
|
|
|
|
int j_kill(const char *, int);
|
2009-04-05 14:35:32 +02:00
|
|
|
|
#ifndef MKSH_UNEMPLOYED
|
2006-08-23 00:16:04 +02:00
|
|
|
|
int j_resume(const char *, int);
|
2009-04-05 14:35:32 +02:00
|
|
|
|
#endif
|
2006-08-23 00:16:04 +02:00
|
|
|
|
int j_jobs(const char *, int, int);
|
|
|
|
|
void j_notify(void);
|
|
|
|
|
pid_t j_async(void);
|
|
|
|
|
int j_stopped_running(void);
|
2005-05-23 05:06:10 +02:00
|
|
|
|
/* lex.c */
|
2006-08-23 00:16:04 +02:00
|
|
|
|
int yylex(int);
|
2012-12-05 19:54:10 +01:00
|
|
|
|
void yyskiputf8bom(void);
|
2007-01-17 23:51:47 +01:00
|
|
|
|
void yyerror(const char *, ...)
|
2009-12-12 23:27:10 +01:00
|
|
|
|
MKSH_A_NORETURN
|
2011-04-09 23:01:03 +02:00
|
|
|
|
MKSH_A_FORMAT(__printf__, 1, 2);
|
2008-12-13 18:02:18 +01:00
|
|
|
|
Source *pushs(int, Area *);
|
2006-08-23 00:16:04 +02:00
|
|
|
|
void set_prompt(int, Source *);
|
|
|
|
|
void pprompt(const char *, int);
|
|
|
|
|
int promptlen(const char *);
|
2005-05-23 05:06:10 +02:00
|
|
|
|
/* main.c */
|
2012-10-30 21:13:20 +01:00
|
|
|
|
int include(const char *, int, const char **, bool);
|
2010-05-22 14:49:16 +02:00
|
|
|
|
int command(const char *, int);
|
2012-05-04 23:15:34 +02:00
|
|
|
|
int shell(Source * volatile, volatile bool);
|
2012-07-22 17:56:51 +02:00
|
|
|
|
/* argument MUST NOT be 0 */
|
2009-12-12 23:27:10 +01:00
|
|
|
|
void unwind(int) MKSH_A_NORETURN;
|
2006-08-23 00:16:04 +02:00
|
|
|
|
void newenv(int);
|
|
|
|
|
void quitenv(struct shf *);
|
|
|
|
|
void cleanup_parents_env(void);
|
|
|
|
|
void cleanup_proc_env(void);
|
2007-01-17 23:51:47 +01:00
|
|
|
|
void errorf(const char *, ...)
|
2009-12-12 23:27:10 +01:00
|
|
|
|
MKSH_A_NORETURN
|
2011-04-09 23:01:03 +02:00
|
|
|
|
MKSH_A_FORMAT(__printf__, 1, 2);
|
2011-03-27 20:50:06 +02:00
|
|
|
|
void errorfx(int, const char *, ...)
|
|
|
|
|
MKSH_A_NORETURN
|
2011-04-09 23:01:03 +02:00
|
|
|
|
MKSH_A_FORMAT(__printf__, 2, 3);
|
2006-11-10 02:13:52 +01:00
|
|
|
|
void warningf(bool, const char *, ...)
|
2011-04-09 23:01:03 +02:00
|
|
|
|
MKSH_A_FORMAT(__printf__, 2, 3);
|
2006-08-23 00:16:04 +02:00
|
|
|
|
void bi_errorf(const char *, ...)
|
2011-04-09 23:01:03 +02:00
|
|
|
|
MKSH_A_FORMAT(__printf__, 1, 2);
|
2012-11-30 20:58:48 +01:00
|
|
|
|
#define errorfz() errorf(NULL)
|
|
|
|
|
#define errorfxz(rc) errorfx((rc), NULL)
|
|
|
|
|
#define bi_errorfz() bi_errorf(NULL)
|
2007-05-13 19:51:24 +02:00
|
|
|
|
void internal_errorf(const char *, ...)
|
2009-12-12 23:27:10 +01:00
|
|
|
|
MKSH_A_NORETURN
|
2011-04-09 23:01:03 +02:00
|
|
|
|
MKSH_A_FORMAT(__printf__, 1, 2);
|
2007-05-13 19:51:24 +02:00
|
|
|
|
void internal_warningf(const char *, ...)
|
2011-04-09 23:01:03 +02:00
|
|
|
|
MKSH_A_FORMAT(__printf__, 1, 2);
|
2006-11-10 02:13:52 +01:00
|
|
|
|
void error_prefix(bool);
|
2006-08-23 00:16:04 +02:00
|
|
|
|
void shellf(const char *, ...)
|
2011-04-09 23:01:03 +02:00
|
|
|
|
MKSH_A_FORMAT(__printf__, 1, 2);
|
2006-08-23 00:16:04 +02:00
|
|
|
|
void shprintf(const char *, ...)
|
2011-04-09 23:01:03 +02:00
|
|
|
|
MKSH_A_FORMAT(__printf__, 1, 2);
|
2006-08-23 00:16:04 +02:00
|
|
|
|
int can_seek(int);
|
|
|
|
|
void initio(void);
|
2008-04-01 22:40:22 +02:00
|
|
|
|
int ksh_dup2(int, int, bool);
|
2007-06-07 01:28:17 +02:00
|
|
|
|
short savefd(int);
|
2006-08-23 00:16:04 +02:00
|
|
|
|
void restfd(int, int);
|
|
|
|
|
void openpipe(int *);
|
|
|
|
|
void closepipe(int *);
|
2007-03-04 01:13:17 +01:00
|
|
|
|
int check_fd(const char *, int, const char **);
|
2006-08-23 00:16:04 +02:00
|
|
|
|
void coproc_init(void);
|
|
|
|
|
void coproc_read_close(int);
|
|
|
|
|
void coproc_readw_close(int);
|
|
|
|
|
void coproc_write_close(int);
|
|
|
|
|
int coproc_getfd(int, const char **);
|
|
|
|
|
void coproc_cleanup(int);
|
2008-12-13 18:02:18 +01:00
|
|
|
|
struct temp *maketemp(Area *, Temp_type, struct temp **);
|
2012-07-01 17:38:09 +02:00
|
|
|
|
void ktinit(Area *, struct table *, uint8_t);
|
2011-06-05 21:58:21 +02:00
|
|
|
|
struct tbl *ktscan(struct table *, const char *, uint32_t, struct tbl ***);
|
|
|
|
|
/* table, name (key) to search for, hash(n) */
|
|
|
|
|
#define ktsearch(tp, s, h) ktscan((tp), (s), (h), NULL)
|
2009-08-28 22:30:59 +02:00
|
|
|
|
struct tbl *ktenter(struct table *, const char *, uint32_t);
|
2009-08-28 22:38:43 +02:00
|
|
|
|
#define ktdelete(p) do { p->flag = 0; } while (/* CONSTCOND */ 0)
|
2006-08-23 00:16:04 +02:00
|
|
|
|
void ktwalk(struct tstate *, struct table *);
|
|
|
|
|
struct tbl *ktnext(struct tstate *);
|
|
|
|
|
struct tbl **ktsort(struct table *);
|
2012-03-23 20:38:12 +01:00
|
|
|
|
#ifdef DF
|
|
|
|
|
void DF(const char *, ...)
|
|
|
|
|
MKSH_A_FORMAT(__printf__, 1, 2);
|
|
|
|
|
#endif
|
2005-05-23 05:06:10 +02:00
|
|
|
|
/* misc.c */
|
2006-08-23 00:16:04 +02:00
|
|
|
|
void setctypes(const char *, int);
|
|
|
|
|
void initctypes(void);
|
2007-05-13 20:33:29 +02:00
|
|
|
|
size_t option(const char *);
|
2006-08-23 00:16:04 +02:00
|
|
|
|
char *getoptions(void);
|
2012-12-05 20:38:25 +01:00
|
|
|
|
void change_flag(enum sh_flag, int, bool);
|
2013-07-21 20:47:24 +02:00
|
|
|
|
void change_xtrace(unsigned char, bool);
|
2009-12-05 18:43:50 +01:00
|
|
|
|
int parse_args(const char **, int, bool *);
|
2006-08-23 00:16:04 +02:00
|
|
|
|
int getn(const char *, int *);
|
2008-02-27 02:00:10 +01:00
|
|
|
|
int gmatchx(const char *, const char *, bool);
|
2006-08-23 00:16:04 +02:00
|
|
|
|
int has_globbing(const char *, const char *);
|
2006-11-10 04:23:50 +01:00
|
|
|
|
int xstrcmp(const void *, const void *);
|
2006-08-23 00:16:04 +02:00
|
|
|
|
void ksh_getopt_reset(Getopt *, int);
|
2007-03-04 01:13:17 +01:00
|
|
|
|
int ksh_getopt(const char **, Getopt *, const char *);
|
2011-12-29 23:54:22 +01:00
|
|
|
|
void print_value_quoted(struct shf *, const char *);
|
2011-01-09 22:57:29 +01:00
|
|
|
|
char *quote_value(const char *);
|
2012-10-03 17:13:34 +02:00
|
|
|
|
void print_columns(struct shf *, unsigned int,
|
|
|
|
|
char *(*)(char *, size_t, unsigned int, const void *),
|
2011-08-27 20:06:52 +02:00
|
|
|
|
const void *, size_t, size_t, bool);
|
2006-11-10 04:45:57 +01:00
|
|
|
|
void strip_nuls(char *, int);
|
2010-08-28 18:47:11 +02:00
|
|
|
|
ssize_t blocking_read(int, char *, size_t)
|
2011-04-09 23:01:03 +02:00
|
|
|
|
MKSH_A_BOUNDED(__buffer__, 2, 3);
|
2006-08-23 00:16:04 +02:00
|
|
|
|
int reset_nonblock(int);
|
2011-03-24 20:05:49 +01:00
|
|
|
|
char *ksh_get_wd(void);
|
|
|
|
|
char *do_realpath(const char *);
|
2006-08-23 00:16:04 +02:00
|
|
|
|
void simplify_path(char *);
|
2011-03-26 20:43:49 +01:00
|
|
|
|
void set_current_wd(const char *);
|
2011-03-24 20:05:49 +01:00
|
|
|
|
int c_cd(const char **);
|
2012-07-01 17:55:00 +02:00
|
|
|
|
#if defined(MKSH_SMALL) && !defined(MKSH_SMALL_BUT_FAST)
|
2011-10-26 00:36:39 +02:00
|
|
|
|
char *strdup_i(const char *, Area *);
|
|
|
|
|
char *strndup_i(const char *, size_t, Area *);
|
2008-10-28 15:51:06 +01:00
|
|
|
|
#endif
|
2009-09-19 23:54:46 +02:00
|
|
|
|
int unbksl(bool, int (*)(void), void (*)(int));
|
2005-10-21 14:41:56 +02:00
|
|
|
|
/* shf.c */
|
|
|
|
|
struct shf *shf_open(const char *, int, int, int);
|
|
|
|
|
struct shf *shf_fdopen(int, int, struct shf *);
|
|
|
|
|
struct shf *shf_reopen(int, int, struct shf *);
|
2011-08-27 20:06:52 +02:00
|
|
|
|
struct shf *shf_sopen(char *, ssize_t, int, struct shf *);
|
2006-08-23 00:16:04 +02:00
|
|
|
|
int shf_close(struct shf *);
|
|
|
|
|
int shf_fdclose(struct shf *);
|
|
|
|
|
char *shf_sclose(struct shf *);
|
|
|
|
|
int shf_flush(struct shf *);
|
2011-08-27 20:06:52 +02:00
|
|
|
|
ssize_t shf_read(char *, ssize_t, struct shf *);
|
|
|
|
|
char *shf_getse(char *, ssize_t, struct shf *);
|
2006-08-23 00:16:04 +02:00
|
|
|
|
int shf_getchar(struct shf *s);
|
|
|
|
|
int shf_ungetc(int, struct shf *);
|
2012-07-01 17:55:00 +02:00
|
|
|
|
#if defined(MKSH_SMALL) && !defined(MKSH_SMALL_BUT_FAST)
|
2011-07-16 19:07:35 +02:00
|
|
|
|
int shf_getc(struct shf *);
|
|
|
|
|
int shf_putc(int, struct shf *);
|
|
|
|
|
#else
|
2011-10-26 00:36:39 +02:00
|
|
|
|
#define shf_getc shf_getc_i
|
|
|
|
|
#define shf_putc shf_putc_i
|
2011-07-16 19:07:35 +02:00
|
|
|
|
#endif
|
2006-08-23 00:16:04 +02:00
|
|
|
|
int shf_putchar(int, struct shf *);
|
2011-08-27 20:06:52 +02:00
|
|
|
|
ssize_t shf_puts(const char *, struct shf *);
|
|
|
|
|
ssize_t shf_write(const char *, ssize_t, struct shf *);
|
|
|
|
|
ssize_t shf_fprintf(struct shf *, const char *, ...)
|
2011-04-09 23:01:03 +02:00
|
|
|
|
MKSH_A_FORMAT(__printf__, 2, 3);
|
2011-08-27 20:06:52 +02:00
|
|
|
|
ssize_t shf_snprintf(char *, ssize_t, const char *, ...)
|
2011-04-09 23:01:03 +02:00
|
|
|
|
MKSH_A_FORMAT(__printf__, 3, 4)
|
|
|
|
|
MKSH_A_BOUNDED(__string__, 1, 2);
|
2006-11-10 02:13:52 +01:00
|
|
|
|
char *shf_smprintf(const char *, ...)
|
2011-04-09 23:01:03 +02:00
|
|
|
|
MKSH_A_FORMAT(__printf__, 1, 2);
|
2011-08-27 20:06:52 +02:00
|
|
|
|
ssize_t shf_vfprintf(struct shf *, const char *, va_list)
|
2011-04-09 23:01:03 +02:00
|
|
|
|
MKSH_A_FORMAT(__printf__, 2, 0);
|
2005-05-23 05:06:10 +02:00
|
|
|
|
/* syn.c */
|
2006-08-23 00:16:04 +02:00
|
|
|
|
void initkeywords(void);
|
2011-03-13 17:03:54 +01:00
|
|
|
|
struct op *compile(Source *, bool);
|
2011-02-11 01:41:38 +01:00
|
|
|
|
bool parse_usec(const char *, struct timeval *);
|
2012-10-22 22:19:18 +02:00
|
|
|
|
char *yyrecursive(int);
|
2012-10-30 21:49:44 +01:00
|
|
|
|
void yyrecursive_pop(bool);
|
2005-05-23 05:06:10 +02:00
|
|
|
|
/* tree.c */
|
2011-03-06 18:08:14 +01:00
|
|
|
|
void fptreef(struct shf *, int, const char *, ...);
|
2011-08-27 20:06:52 +02:00
|
|
|
|
char *snptreef(char *, ssize_t, const char *, ...);
|
2008-12-13 18:02:18 +01:00
|
|
|
|
struct op *tcopy(struct op *, Area *);
|
|
|
|
|
char *wdcopy(const char *, Area *);
|
2006-11-12 15:58:16 +01:00
|
|
|
|
const char *wdscan(const char *, int);
|
2011-05-03 00:52:54 +02:00
|
|
|
|
#define WDS_TPUTS BIT(0) /* tputS (dumpwdvar) mode */
|
|
|
|
|
#define WDS_KEEPQ BIT(1) /* keep quote characters */
|
|
|
|
|
#define WDS_MAGIC BIT(2) /* make MAGIC */
|
|
|
|
|
char *wdstrip(const char *, int);
|
2008-12-13 18:02:18 +01:00
|
|
|
|
void tfree(struct op *, Area *);
|
2011-03-17 22:58:40 +01:00
|
|
|
|
void dumpchar(struct shf *, int);
|
2011-03-08 19:49:51 +01:00
|
|
|
|
void dumptree(struct shf *, struct op *);
|
2011-03-12 22:41:15 +01:00
|
|
|
|
void dumpwdvar(struct shf *, const char *);
|
2011-12-29 23:54:22 +01:00
|
|
|
|
void dumpioact(struct shf *shf, struct op *t);
|
2011-03-06 18:08:14 +01:00
|
|
|
|
void vistree(char *, size_t, struct op *)
|
2011-04-09 23:01:03 +02:00
|
|
|
|
MKSH_A_BOUNDED(__string__, 1, 2);
|
2011-03-06 18:08:14 +01:00
|
|
|
|
void fpFUNCTf(struct shf *, int, bool, const char *, struct op *);
|
2005-05-23 05:06:10 +02:00
|
|
|
|
/* var.c */
|
2006-08-23 00:16:04 +02:00
|
|
|
|
void newblock(void);
|
|
|
|
|
void popblock(void);
|
|
|
|
|
void initvar(void);
|
2012-05-10 01:21:00 +02:00
|
|
|
|
struct block *varsearch(struct block *, struct tbl **, const char *, uint32_t);
|
2006-08-23 00:16:04 +02:00
|
|
|
|
struct tbl *global(const char *);
|
|
|
|
|
struct tbl *local(const char *, bool);
|
|
|
|
|
char *str_val(struct tbl *);
|
|
|
|
|
int setstr(struct tbl *, const char *, int);
|
2005-05-23 05:06:10 +02:00
|
|
|
|
struct tbl *setint_v(struct tbl *, struct tbl *, bool);
|
2009-03-14 19:12:55 +01:00
|
|
|
|
void setint(struct tbl *, mksh_ari_t);
|
2011-11-08 23:07:15 +01:00
|
|
|
|
void setint_n(struct tbl *, mksh_ari_t, int);
|
2012-12-01 02:36:30 +01:00
|
|
|
|
struct tbl *typeset(const char *, uint32_t, uint32_t, int, int);
|
2006-08-23 00:16:04 +02:00
|
|
|
|
void unset(struct tbl *, int);
|
2006-11-12 15:58:16 +01:00
|
|
|
|
const char *skip_varname(const char *, int);
|
2011-06-05 21:58:21 +02:00
|
|
|
|
const char *skip_wdvarname(const char *, bool);
|
|
|
|
|
int is_wdvarname(const char *, bool);
|
2006-08-23 00:16:04 +02:00
|
|
|
|
int is_wdvarassign(const char *);
|
2011-05-29 04:18:57 +02:00
|
|
|
|
struct tbl *arraysearch(struct tbl *, uint32_t);
|
2006-08-23 00:16:04 +02:00
|
|
|
|
char **makenv(void);
|
2008-12-29 22:05:15 +01:00
|
|
|
|
void change_winsz(void);
|
2011-08-27 20:06:52 +02:00
|
|
|
|
size_t array_ref_len(const char *);
|
2006-08-23 00:16:04 +02:00
|
|
|
|
char *arrayname(const char *);
|
2009-08-29 00:23:34 +02:00
|
|
|
|
mksh_uari_t set_array(const char *, bool, const char **);
|
2011-01-21 22:04:48 +01:00
|
|
|
|
uint32_t hash(const void *);
|
2012-04-14 16:35:13 +02:00
|
|
|
|
mksh_ari_t rndget(void);
|
2013-04-01 04:37:53 +02:00
|
|
|
|
void rndset(unsigned long);
|
2005-05-23 05:06:10 +02:00
|
|
|
|
|
|
|
|
|
enum Test_op {
|
2011-06-21 23:10:12 +02:00
|
|
|
|
/* non-operator */
|
|
|
|
|
TO_NONOP = 0,
|
2005-05-23 05:06:10 +02:00
|
|
|
|
/* unary operators */
|
|
|
|
|
TO_STNZE, TO_STZER, TO_OPTION,
|
|
|
|
|
TO_FILAXST,
|
|
|
|
|
TO_FILEXST,
|
|
|
|
|
TO_FILREG, TO_FILBDEV, TO_FILCDEV, TO_FILSYM, TO_FILFIFO, TO_FILSOCK,
|
|
|
|
|
TO_FILCDF, TO_FILID, TO_FILGID, TO_FILSETG, TO_FILSTCK, TO_FILUID,
|
|
|
|
|
TO_FILRD, TO_FILGZ, TO_FILTT, TO_FILSETU, TO_FILWR, TO_FILEX,
|
|
|
|
|
/* binary operators */
|
|
|
|
|
TO_STEQL, TO_STNEQ, TO_STLT, TO_STGT, TO_INTEQ, TO_INTNE, TO_INTGT,
|
2010-07-18 00:09:40 +02:00
|
|
|
|
TO_INTGE, TO_INTLT, TO_INTLE, TO_FILEQ, TO_FILNT, TO_FILOT,
|
|
|
|
|
/* not an operator */
|
|
|
|
|
TO_NONNULL /* !TO_NONOP */
|
2005-05-23 05:06:10 +02:00
|
|
|
|
};
|
|
|
|
|
typedef enum Test_op Test_op;
|
|
|
|
|
|
|
|
|
|
/* Used by Test_env.isa() (order important - used to index *_tokens[] arrays) */
|
|
|
|
|
enum Test_meta {
|
|
|
|
|
TM_OR, /* -o or || */
|
|
|
|
|
TM_AND, /* -a or && */
|
|
|
|
|
TM_NOT, /* ! */
|
|
|
|
|
TM_OPAREN, /* ( */
|
|
|
|
|
TM_CPAREN, /* ) */
|
|
|
|
|
TM_UNOP, /* unary operator */
|
|
|
|
|
TM_BINOP, /* binary operator */
|
|
|
|
|
TM_END /* end of input */
|
|
|
|
|
};
|
|
|
|
|
typedef enum Test_meta Test_meta;
|
|
|
|
|
|
|
|
|
|
#define TEF_ERROR BIT(0) /* set if we've hit an error */
|
|
|
|
|
#define TEF_DBRACKET BIT(1) /* set if [[ .. ]] test */
|
|
|
|
|
|
2010-07-18 00:09:40 +02:00
|
|
|
|
typedef struct test_env {
|
2005-05-23 05:06:10 +02:00
|
|
|
|
union {
|
2010-08-28 17:48:20 +02:00
|
|
|
|
const char **wp; /* used by ptest_* */
|
|
|
|
|
XPtrV *av; /* used by dbtestp_* */
|
2005-05-23 05:06:10 +02:00
|
|
|
|
} pos;
|
2010-08-28 17:48:20 +02:00
|
|
|
|
const char **wp_end; /* used by ptest_* */
|
2010-07-18 00:09:40 +02:00
|
|
|
|
Test_op (*isa)(struct test_env *, Test_meta);
|
|
|
|
|
const char *(*getopnd) (struct test_env *, Test_op, bool);
|
|
|
|
|
int (*eval)(struct test_env *, Test_op, const char *, const char *, bool);
|
|
|
|
|
void (*error)(struct test_env *, int, const char *);
|
2010-08-28 17:48:20 +02:00
|
|
|
|
int flags; /* TEF_* */
|
2010-07-18 00:09:40 +02:00
|
|
|
|
} Test_env;
|
2005-05-23 05:06:10 +02:00
|
|
|
|
|
2012-12-28 03:28:39 +01:00
|
|
|
|
extern const char * const dbtest_tokens[];
|
2007-06-07 01:28:17 +02:00
|
|
|
|
|
2005-10-08 21:31:00 +02:00
|
|
|
|
Test_op test_isop(Test_meta, const char *);
|
2008-04-02 00:20:20 +02:00
|
|
|
|
int test_eval(Test_env *, Test_op, const char *, const char *, bool);
|
2006-08-23 00:16:04 +02:00
|
|
|
|
int test_parse(Test_env *);
|
2005-05-23 05:06:10 +02:00
|
|
|
|
|
2011-09-07 17:24:22 +02:00
|
|
|
|
EXTERN int tty_fd E_INIT(-1); /* dup'd tty file descriptor */
|
2011-02-27 20:29:32 +01:00
|
|
|
|
EXTERN bool tty_devtty; /* true if tty_fd is from /dev/tty */
|
2012-05-05 00:18:27 +02:00
|
|
|
|
EXTERN mksh_ttyst tty_state; /* saved tty state */
|
2012-11-30 20:25:08 +01:00
|
|
|
|
EXTERN bool tty_hasstate; /* true if tty_state is valid */
|
2005-05-23 05:06:10 +02:00
|
|
|
|
|
2012-11-30 20:25:08 +01:00
|
|
|
|
extern int tty_init_fd(void); /* initialise tty_fd, tty_devtty */
|
2006-08-01 14:22:26 +02:00
|
|
|
|
|
2005-05-23 05:06:10 +02:00
|
|
|
|
/* be sure not to interfere with anyone else's idea about EXTERN */
|
|
|
|
|
#ifdef EXTERN_DEFINED
|
|
|
|
|
# undef EXTERN_DEFINED
|
|
|
|
|
# undef EXTERN
|
|
|
|
|
#endif
|
2011-09-07 17:24:22 +02:00
|
|
|
|
#undef E_INIT
|
2007-04-23 22:37:16 +02:00
|
|
|
|
|
|
|
|
|
#endif /* !MKSH_INCLUDES_ONLY */
|