Imported from ../bash-2.02.tar.gz.
This commit is contained in:
parent
e8ce775db8
commit
cce855bc5b
323 changed files with 33916 additions and 12321 deletions
|
|
@ -1,41 +1,64 @@
|
|||
#
|
||||
# Simple makefile for the sample loadable builtins
|
||||
#
|
||||
CC = cc
|
||||
# This includes some boilerplate definitions added by configure, but will
|
||||
# still need hand-editing
|
||||
#
|
||||
# Include some boilerplate Gnu makefile definitions.
|
||||
prefix = @prefix@
|
||||
|
||||
exec_prefix = @exec_prefix@
|
||||
bindir = @bindir@
|
||||
libdir = @libdir@
|
||||
infodir = @infodir@
|
||||
includedir = @includedir@
|
||||
|
||||
topdir = @top_srcdir@
|
||||
BUILD_DIR = @BUILD_DIR@
|
||||
srcdir = @srcdir@
|
||||
VPATH = .:@srcdir@
|
||||
|
||||
@SET_MAKE@
|
||||
CC = @CC@
|
||||
RM = rm -f
|
||||
|
||||
SHELL = /bin/sh
|
||||
|
||||
# SunOS 4
|
||||
PICFLAG = -pic
|
||||
#PICFLAG = -pic
|
||||
# Some versions of gcc, esp. on NetBSD and FreeBSD
|
||||
#PICFLAG = -fpic
|
||||
PICFLAG = -fpic
|
||||
# Linux -- could also be -fpic
|
||||
#PICFLAG = -fPIC
|
||||
# SunOS 5
|
||||
#PICFLAG = -K pic
|
||||
# SVR4, SVR4.2, Irix
|
||||
#PICFLAG = -K PIC
|
||||
# BSD/OS 2.1
|
||||
# BSD/OS 2.1, BSD/OS 3.x
|
||||
#PICFLAG =
|
||||
# AIX 4.2
|
||||
#PICFLAG = -K
|
||||
|
||||
# SunOS 4, BSD/OS 2.1, SVR4.2, SVR4, Linux, AIX 4.2, etc.
|
||||
# SunOS 4, BSD/OS 2.1, BSD/OS 3.x, SVR4.2, SVR4, Linux, AIX 4.2, etc.
|
||||
LD = ld
|
||||
# SunOS 5, Linux
|
||||
#LD = cc
|
||||
#LD = ${CC}
|
||||
|
||||
# SunOS 4
|
||||
LDOPT = -assert pure-text
|
||||
#LDOPT = -assert pure-text
|
||||
# OSF/1, Digital UNIX
|
||||
#LDOPT = -shared -soname $@ -expect_unresolved '*'
|
||||
# SunOS 5
|
||||
# SunOS 5 using sun cc
|
||||
#LDOPT = -dy -z text -G -i -h $@
|
||||
# SunOS 5 using gcc with Sun ld
|
||||
#LDOPT = -shared -Wl,-dy -Wl,-G -Wl,-i
|
||||
# SVR4, SVR4.2
|
||||
#LDOPT = -dy -z text -G -h $@
|
||||
# NetBSD, FreeBSD -- might also need -r
|
||||
#LDOPT = -x -Bshareable
|
||||
LDOPT = -x -Bshareable
|
||||
# Linux
|
||||
#LDOPT = -shared
|
||||
# BSD/OS 2.1
|
||||
# BSD/OS 2.1, BSD/OS 3.x
|
||||
#LDOPT = -r
|
||||
# AIX 4.2
|
||||
#LDOPT = -bdynamic -bnoentry -bexpall -G
|
||||
|
|
@ -43,19 +66,25 @@ LDOPT = -assert pure-text
|
|||
# other libraries to link the shared object against
|
||||
# BSD/OS 2.1
|
||||
#LDLIBS = -lc_s.2.1.0
|
||||
# BSD/OS 3.0, BSD/OS 3.1
|
||||
#LDLIBS = -lc_s.3.0.0
|
||||
|
||||
srcdir = ../..
|
||||
INC= -I$(srcdir) -I$(srcdir)/builtins -I$(srcdir)/lib
|
||||
|
||||
INC = -I. -I.. -I$(topdir) -I$(topdir)/lib -I$(topdir)/builtins \
|
||||
-I$(BUILD_DIR) -I$(BUILD_DIR)/lib -I$(BUILD_DIR)/builtins
|
||||
|
||||
.c.o:
|
||||
$(CC) $(PICFLAG) $(CFLAGS) $(INC) -c -o $@ $<
|
||||
|
||||
all: printf print truefalse sleep pushd finfo logname basename dirname \
|
||||
tty pathchk tee head rmdir sprintf
|
||||
others: necho getconf hello cat
|
||||
|
||||
printf: printf.o
|
||||
$(LD) $(LDOPT) -o $@ printf.o $(LDLIBS)
|
||||
ALLPROG = print truefalse sleep pushd finfo logname basename dirname \
|
||||
tty pathchk tee head rmdir sprintf
|
||||
OTHERPROG = necho getconf hello cat
|
||||
|
||||
all: $(ALLPROG)
|
||||
others: $(OTHERPROG)
|
||||
|
||||
everything: all others
|
||||
|
||||
sprintf: sprintf.o
|
||||
$(LD) $(LDOPT) -o $@ sprintf.o $(LDLIBS)
|
||||
|
|
@ -110,3 +139,31 @@ rmdir: rmdir.o
|
|||
|
||||
head: head.o
|
||||
$(LD) $(LDOPT) -o $@ head.o $(LDLIBS)
|
||||
|
||||
clean:
|
||||
$(RM) $(ALLPROG) $(OTHERPROG) *.o
|
||||
|
||||
mostlyclean: clean
|
||||
|
||||
distclean maintainer-clean: clean
|
||||
$(RM) Makefile
|
||||
|
||||
print.o: print.c
|
||||
truefalse.o: truefalse.c
|
||||
sleep.o: sleep.c
|
||||
pushd.o: pushd.c
|
||||
finfo.o: finfo.c
|
||||
logname.o: logname.c
|
||||
basename.o: basename.c
|
||||
dirname.o: dirname.c
|
||||
tty.o: tty.c
|
||||
pathchk.o: pathchk.c
|
||||
tee.o: tee.c
|
||||
head.o: head.c
|
||||
rmdir.o: rmdir.c
|
||||
sprintf.o: sprintf.c
|
||||
necho.o: necho.c
|
||||
getconf.o: getconf.c
|
||||
hello.o: hello.c
|
||||
cat.o: cat.c
|
||||
|
||||
|
|
@ -1,4 +1,6 @@
|
|||
/*
|
||||
* ORIGINAL COPYRIGHT STATEMENT:
|
||||
*
|
||||
* Copyright (c) 1994 Winning Strategies, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
|
|
@ -31,14 +33,13 @@
|
|||
/*
|
||||
* POSIX.2 getconf utility
|
||||
*
|
||||
* Written by:
|
||||
* Originally Written by:
|
||||
* J.T. Conklin (jtc@wimsey.com), Winning Strategies, Inc.
|
||||
*
|
||||
* Heavily modified for inclusion in bash by
|
||||
* Chet Ramey <chet@po.cwru.edu>
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char rcsid[] = "$Id: getconf.c,v 1.2 1994/05/10 00:04:12 jtc Exp $";
|
||||
#endif /* not lint */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <limits.h>
|
||||
#include <locale.h>
|
||||
|
|
@ -48,7 +49,8 @@ static char rcsid[] = "$Id: getconf.c,v 1.2 1994/05/10 00:04:12 jtc Exp $";
|
|||
#include "shell.h"
|
||||
#include "builtins.h"
|
||||
#include "stdc.h"
|
||||
|
||||
#include "common.h"
|
||||
#include "bashgetopt.h"
|
||||
|
||||
struct conf_variable
|
||||
{
|
||||
|
|
@ -57,25 +59,66 @@ struct conf_variable
|
|||
long value;
|
||||
};
|
||||
|
||||
/* BSD/OS does not define this; use Posix.2 recommended minimum value. */
|
||||
/* Some systems do not define these; use POSIX.2 minimum recommended values. */
|
||||
#ifndef _POSIX2_COLL_WEIGHTS_MAX
|
||||
#define _POSIX2_COLL_WEIGHTS_MAX 2
|
||||
# define _POSIX2_COLL_WEIGHTS_MAX 2
|
||||
#endif
|
||||
|
||||
static const struct conf_variable conf_table[] =
|
||||
{
|
||||
/* POSIX.2 Configurable Variable Values */
|
||||
{ "PATH", CONFSTR, _CS_PATH },
|
||||
{ "CS_PATH", CONFSTR, _CS_PATH },
|
||||
|
||||
/* Utility Limit Minimum Values */
|
||||
/* POSIX.1 Configurable Variable Values (only Solaris?) */
|
||||
#if defined (_CS_LFS_CFLAGS)
|
||||
{ "LFS_CFLAGS", CONFSTR, _CS_LFS_CFLAGS },
|
||||
{ "LFS_LDFLAGS", CONFSTR, _CS_LFS_LDFLAGS },
|
||||
{ "LFS_LIBS", CONFSTR, _CS_LFS_LIBS },
|
||||
{ "LFS_LINTFLAGS", CONFSTR, _CS_LFS_LINTFLAGS },
|
||||
#endif
|
||||
#if defined (_CS_LFS64_CFLAGS)
|
||||
{ "LFS64_CFLAGS", CONFSTR, _CS_LFS64_CFLAGS },
|
||||
{ "LFS64_LDFLAGS", CONFSTR, _CS_LFS64_LDFLAGS },
|
||||
{ "LFS64_LIBS", CONFSTR, _CS_LFS64_LIBS },
|
||||
{ "LFS64_LINTFLAGS", CONFSTR, _CS_LFS64_LINTFLAGS },
|
||||
#endif
|
||||
|
||||
/* Single UNIX Specification version 2 Configurable Variable Values */
|
||||
#if defined (_CS_XBS5_ILP32_OFF32_CFLAGS)
|
||||
{ "XBS5_ILP32_OFF32_CFLAGS", CONFSTR, _CS_XBS5_ILP32_OFF32_CFLAGS },
|
||||
{ "XBS5_ILP32_OFF32_LDFLAGS", CONFSTR, _CS_XBS5_ILP32_OFF32_LDFLAGS },
|
||||
{ "XBS5_ILP32_OFF32_LIBS", CONFSTR, _CS_XBS5_ILP32_OFF32_LIBS },
|
||||
{ "XBS5_ILP32_OFF32_LINTFLAGS", CONFSTR, _CS_XBS5_ILP32_OFF32_LINTFLAGS },
|
||||
{ "XBS5_ILP32_OFFBIG_CFLAGS", CONFSTR, _CS_XBS5_ILP32_OFFBIG_CFLAGS },
|
||||
{ "XBS5_ILP32_OFFBIG_LDFLAGS", CONFSTR, _CS_XBS5_ILP32_OFFBIG_LDFLAGS },
|
||||
{ "XBS5_ILP32_OFFBIG_LIBS", CONFSTR, _CS_XBS5_ILP32_OFFBIG_LIBS },
|
||||
{ "XBS5_ILP32_OFFBIG_LINTFLAGS", CONFSTR, _CS_XBS5_ILP32_OFFBIG_LINTFLAGS },
|
||||
{ "XBS5_LP64_OFF64_CFLAGS", CONFSTR, _CS_XBS5_LP64_OFF64_CFLAGS },
|
||||
{ "XBS5_LP64_OFF64_LDFLAGS", CONFSTR, _CS_XBS5_LP64_OFF64_LDFLAGS },
|
||||
{ "XBS5_LP64_OFF64_LIBS", CONFSTR, _CS_XBS5_LP64_OFF64_LIBS },
|
||||
{ "XBS5_LP64_OFF64_LINTFLAGS", CONFSTR, _CS_XBS5_LP64_OFF64_LINTFLAGS },
|
||||
{ "XBS5_LPBIG_OFFBIG_CFLAGS", CONFSTR, _CS_XBS5_LPBIG_OFFBIG_CFLAGS },
|
||||
{ "XBS5_LPBIG_OFFBIG_LDFLAGS", CONFSTR, _CS_XBS5_LPBIG_OFFBIG_LDFLAGS },
|
||||
{ "XBS5_LPBIG_OFFBIG_LIBS", CONFSTR, _CS_XBS5_LPBIG_OFFBIG_LIBS },
|
||||
{ "XBS5_LPBIG_OFFBIG_LINTFLAGS", CONFSTR, _CS_XBS5_LPBIG_OFFBIG_LINTFLAGS },
|
||||
#endif /* _CS_XBS5_ILP32_OFF32_CFLAGS */
|
||||
|
||||
/* POSIX.2 Utility Limit Minimum Values */
|
||||
{ "POSIX2_BC_BASE_MAX", CONSTANT, _POSIX2_BC_BASE_MAX },
|
||||
{ "POSIX2_BC_DIM_MAX", CONSTANT, _POSIX2_BC_DIM_MAX },
|
||||
{ "POSIX2_BC_SCALE_MAX", CONSTANT, _POSIX2_BC_SCALE_MAX },
|
||||
{ "POSIX2_BC_STRING_MAX", CONSTANT, _POSIX2_BC_STRING_MAX },
|
||||
{ "POSIX2_COLL_WEIGHTS_MAX", CONSTANT, _POSIX2_COLL_WEIGHTS_MAX },
|
||||
#if defined (_POSIX2_EQUIV_CLASS_MAX)
|
||||
{ "POSIX2_EQUIV_CLASS_MAX", CONSTANT, _POSIX2_EQUIV_CLASS_MAX },
|
||||
#endif
|
||||
{ "POSIX2_EXPR_NEST_MAX", CONSTANT, _POSIX2_EXPR_NEST_MAX },
|
||||
{ "POSIX2_LINE_MAX", CONSTANT, _POSIX2_LINE_MAX },
|
||||
{ "POSIX2_RE_DUP_MAX", CONSTANT, _POSIX2_RE_DUP_MAX },
|
||||
#if defined (_POSIX2_VERSION)
|
||||
{ "POSIX2_VERSION", CONSTANT, _POSIX2_VERSION },
|
||||
#endif
|
||||
|
||||
/* POSIX.1 Minimum Values */
|
||||
{ "_POSIX_ARG_MAX", CONSTANT, _POSIX_ARG_MAX },
|
||||
|
|
@ -92,7 +135,7 @@ static const struct conf_variable conf_table[] =
|
|||
{ "_POSIX_STREAM_MAX", CONSTANT, _POSIX_STREAM_MAX },
|
||||
{ "_POSIX_TZNAME_MAX", CONSTANT, _POSIX_TZNAME_MAX },
|
||||
|
||||
/* Symbolic Utility Limits */
|
||||
/* POSIX.2 Symbolic Utility Limits */
|
||||
{ "BC_BASE_MAX", SYSCONF, _SC_BC_BASE_MAX },
|
||||
{ "BC_DIM_MAX", SYSCONF, _SC_BC_DIM_MAX },
|
||||
{ "BC_SCALE_MAX", SYSCONF, _SC_BC_SCALE_MAX },
|
||||
|
|
@ -102,15 +145,25 @@ static const struct conf_variable conf_table[] =
|
|||
{ "LINE_MAX", SYSCONF, _SC_LINE_MAX },
|
||||
{ "RE_DUP_MAX", SYSCONF, _SC_RE_DUP_MAX },
|
||||
|
||||
/* Optional Facility Configuration Values */
|
||||
/* POSIX.2 Optional Facility Configuration Values */
|
||||
{ "POSIX2_C_BIND", SYSCONF, _SC_2_C_BIND },
|
||||
{ "POSIX2_C_DEV", SYSCONF, _SC_2_C_DEV },
|
||||
#if defined (_SC_2_C_VERSION)
|
||||
{ "POSIX2_C_VERSION", SYSCONF, _SC_2_C_VERSION },
|
||||
#endif
|
||||
#if defined (_SC_2_CHAR_TERM)
|
||||
{ "POSIX2_CHAR_TERM", SYSCONF, _SC_2_CHAR_TERM },
|
||||
#endif
|
||||
{ "POSIX2_FORT_DEV", SYSCONF, _SC_2_FORT_DEV },
|
||||
{ "POSIX2_FORT_RUN", SYSCONF, _SC_2_FORT_RUN },
|
||||
{ "POSIX2_LOCALEDEF", SYSCONF, _SC_2_LOCALEDEF },
|
||||
{ "POSIX2_SW_DEV", SYSCONF, _SC_2_SW_DEV },
|
||||
#if defined (_SC2_UPE)
|
||||
{ "POSIX2_UPE", SYSCONF, _SC_2_UPE },
|
||||
#endif
|
||||
#if !defined (_POSIX2_VERSION) && defined (_SC_2_VERSION)
|
||||
{ "POSIX2_VERSION" SYSCONF, _SC_2_VERSION },
|
||||
#endif
|
||||
|
||||
/* POSIX.1 Configurable System Variables */
|
||||
{ "ARG_MAX", SYSCONF, _SC_ARG_MAX },
|
||||
|
|
@ -124,6 +177,140 @@ static const struct conf_variable conf_table[] =
|
|||
{ "_POSIX_SAVED_IDS", SYSCONF, _SC_SAVED_IDS },
|
||||
{ "_POSIX_VERSION", SYSCONF, _SC_VERSION },
|
||||
|
||||
/* POSIX.1 Optional Facility Configuration Values */
|
||||
#if defined (_SC_ASYNCHRONOUS_IO)
|
||||
{ "_POSIX_ASYNCHRONOUS_IO", SYSCONF, _SC_ASYNCHRONOUS_IO },
|
||||
#endif
|
||||
#if defined (_SC_FSYNC)
|
||||
{ "_POSIX_FSYNC", SYSCONF, _SC_FSYNC },
|
||||
#endif
|
||||
#if defined (_SC_MAPPED_FILES)
|
||||
{ "_POSIX_MAPPED_FILES", SYSCONF, _SC_MAPPED_FILES },
|
||||
#endif
|
||||
#if defined (_SC_MEMLOCK)
|
||||
{ "_POSIX_MEMLOCK", SYSCONF, _SC_MEMLOCK },
|
||||
#endif
|
||||
#if defined (_SC_MEMLOCK_RANGE)
|
||||
{ "_POSIX_MEMLOCK_RANGE", SYSCONF, _SC_MEMLOCK_RANGE },
|
||||
#endif
|
||||
#if defined (_SC_MEMORY_PROTECTION)
|
||||
{ "_POSIX_MEMORY_PROTECTION", SYSCONF, _SC_MEMORY_PROTECTION },
|
||||
#endif
|
||||
#if defined (_SC_MESSAGE_PASSING)
|
||||
{ "_POSIX_MESSAGE_PASSING", SYSCONF, _SC_MESSAGE_PASSING },
|
||||
#endif
|
||||
#if defined (SC_PRIORITIZED_IO)
|
||||
{ "_POSIX_PRIORITIZED_IO", SYSCONF, _SC_PRIORITIZED_IO },
|
||||
#endif
|
||||
#if defined (_SC_PRIORITY_SCHEDULING)
|
||||
{ "_POSIX_PRIORITY_SCHEDULING", SYSCONF, _SC_PRIORITY_SCHEDULING },
|
||||
#endif
|
||||
#if defined (_SC_REALTIME_SIGNALS)
|
||||
{ "_POSIX_REALTIME_SIGNALS", SYSCONF, _SC_REALTIME_SIGNALS },
|
||||
#endif
|
||||
#if defined (_SC_SEMAPHORES)
|
||||
{ "_POSIX_SEMAPHORES", SYSCONF, _SC_SEMAPHORES },
|
||||
#endif
|
||||
#if defined (_SC_SHARED_MEMORY_OBJECTS)
|
||||
{ "_POSIX_SHARED_MEMORY_OBJECTS", SYSCONF, _SC_SHARED_MEMORY_OBJECTS },
|
||||
#endif
|
||||
#if defined (_SC_SYNCHRONIZED_IO)
|
||||
{ "_POSIX_SYNCHRONIZED_IO", SYSCONF, _SC_SYNCHRONIZED_IO },
|
||||
#endif
|
||||
#if defined (_SC_TIMERS)
|
||||
{ "_POSIX_TIMERS", SYSCONF, _SC_TIMERS },
|
||||
#endif
|
||||
#if defined (_SC_THREADS)
|
||||
{ "_POSIX_THREADS", SYSCONF, _SC_THREADS },
|
||||
{ "_POSIX_THREAD_ATTR_STACKADDR", SYSCONF, _SC_THREAD_ATTR_STACKADDR },
|
||||
{ "_POSIX_THREAD_ATTR_STACKSIZE", SYSCONF, _SC_THREAD_ATTR_STACKSIZE },
|
||||
{ "_POSIX_THREAD_PRIORITY_SCHEDULING", SYSCONF, _SC_THREAD_PRIORITY_SCHEDULING },
|
||||
{ "_POSIX_THREAD_PRIO_INHERIT", SYSCONF, _SC_THREAD_PRIO_INHERIT },
|
||||
{ "_POSIX_THREAD_PRIO_PROTECT", SYSCONF, _SC_THREAD_PRIO_PROTECT },
|
||||
{ "_POSIX_THREAD_PROCESS_SHARED", SYSCONF, _SC_THREAD_PROCESS_SHARED },
|
||||
# if defined (_SC_THREAD_SAFE_FUNCTIONS)
|
||||
{ "_POSIX_THREAD_SAFE_FUNCTIONS", SYSCONF, _SC_THREAD_SAFE_FUNCTIONS },
|
||||
# endif
|
||||
#endif /* _SC_THREADS */
|
||||
|
||||
/* XPG 4.2 Configurable System Variables. */
|
||||
#if defined (_SC_ATEXIT_MAX)
|
||||
{ "ATEXIT_MAX", SYSCONF, _SC_ATEXIT_MAX },
|
||||
#endif
|
||||
#if defined (_SC_IOV_MAX)
|
||||
{ "IOV_MAX", SYSCONF, _SC_IOV_MAX },
|
||||
#endif
|
||||
#if defined (_SC_PAGESIZE)
|
||||
{ "PAGESIZE", SYSCONF, _SC_PAGESIZE },
|
||||
#endif
|
||||
#if defined (_SC_PAGE_SIZE)
|
||||
{ "PAGE_SIZE", SYSCONF, _SC_PAGE_SIZE },
|
||||
#endif
|
||||
|
||||
#if defined (_SC_AIO_LISTIO_MAX)
|
||||
{ "AIO_LISTIO_MAX", SYSCONF, _SC_AIO_LISTIO_MAX },
|
||||
{ "AIO_MAX", SYSCONF, _SC_AIO_MAX },
|
||||
{ "AIO_PRIO_DELTA_MAX", SYSCONF, _SC_AIO_PRIO_DELTA_MAX },
|
||||
{ "DELAYTIMER_MAX", SYSCONF, _SC_DELAYTIMER_MAX },
|
||||
#if defined (_SC_GETGR_R_SIZE_MAX)
|
||||
{ "GETGR_R_SIZE_MAX", SYSCONF, _SC_GETGR_R_SIZE_MAX },
|
||||
#endif
|
||||
#if defined (_SC_GETPW_R_SIZE_MAX)
|
||||
{ "GETPW_R_SIZE_MAX", SYSCONF, _SC_GETPW_R_SIZE_MAX },
|
||||
#endif
|
||||
{ "MQ_OPEN_MAX", SYSCONF, _SC_MQ_OPEN_MAX },
|
||||
{ "MQ_PRIO_MAX", SYSCONF, _SC_MQ_PRIO_MAX },
|
||||
{ "RTSIG_MAX", SYSCONF, _SC_RTSIG_MAX },
|
||||
{ "SEM_NSEMS_MAX", SYSCONF, _SC_SEM_NSEMS_MAX },
|
||||
{ "SEM_VALUE_MAX", SYSCONF, _SC_SEM_VALUE_MAX },
|
||||
{ "SIGQUEUE_MAX", SYSCONF, _SC_SIGQUEUE_MAX },
|
||||
{ "TIMER_MAX", SYSCONF, _SC_TIMER_MAX },
|
||||
#endif /* _SC_AIO_LISTIO_MAX */
|
||||
#if defined (_SC_LOGIN_NAME_MAX)
|
||||
{ "LOGIN_NAME_MAX", SYSCONF, _SC_LOGIN_NAME_MAX },
|
||||
#endif
|
||||
#if defined (_SC_LOGNAME_MAX)
|
||||
{ "LOGNAME_MAX", SYSCONF, _SC_LOGNAME_MAX },
|
||||
#endif
|
||||
#if defined (_SC_TTY_NAME_MAX)
|
||||
{ "TTY_NAME_MAX", SYSCONF, _SC_TTY_NAME_MAX },
|
||||
#endif
|
||||
|
||||
#if defined (_SC_PTHREAD_DESTRUCTOR_ITERATIONS)
|
||||
{ "PTHREAD_DESTRUCTOR_ITERATIONS", SYSCONF, _SC_THREAD_DESTRUCTOR_ITERATIONS },
|
||||
{ "PTHREAD_KEYS_MAX", SYSCONF, _SC_THREAD_KEYS_MAX },
|
||||
{ "PTHREAD_STACK_MIN", SYSCONF, _SC_THREAD_STACK_MIN },
|
||||
{ "PTHREAD_THREADS_MAX", SYSCONF, _SC_THREAD_THREADS_MAX },
|
||||
#endif /* _SC_PTHREAD_DESTRUCTOR_ITERATIONS */
|
||||
|
||||
/* XPG 4.2 Optional Facility Configuration Values */
|
||||
#if defined (_SC_XOPEN_UNIX)
|
||||
{ "_XOPEN_UNIX", SYSCONF, _SC_XOPEN_UNIX },
|
||||
{ "_XOPEN_CRYPT", SYSCONF, _SC_XOPEN_CRYPT },
|
||||
{ "_XOPEN_ENH_I18N", SYSCONF, _SC_XOPEN_ENH_I18N },
|
||||
{ "_XOPEN_SHM", SYSCONF, _SC_XOPEN_SHM },
|
||||
{ "_XOPEN_VERSION", SYSCONF, _SC_XOPEN_VERSION },
|
||||
# if defined (_SC_XOPEN_XCU_VERSION)
|
||||
{ "_XOPEN_XCU_VERSION", SYSCONF, _SC_XOPEN_XCU_VERSION },
|
||||
# endif
|
||||
#endif
|
||||
#if defined (_SC_XOPEN_REALTIME)
|
||||
{ "_XOPEN_REALTIME", SYSCONF, _SC_XOPEN_REALTIME },
|
||||
{ "_XOPEN_REALTIME_THREADS", SYSCONF, _SC_XOPEN_REALTIME_THREADS },
|
||||
#endif
|
||||
#if defined (_SC_XOPEN_LEGACY)
|
||||
{ "_XOPEN_LEGACY", SYSCONF, _SC_XOPEN_LEGACY },
|
||||
#endif /* _SC_XOPEN_LEGACY */
|
||||
|
||||
/* Single UNIX Specification version 2 Optional Facility Configuration Values */
|
||||
#if defined (_SC_XBS5_ILP32_OFF32)
|
||||
{ "_XBS5_ILP32_OFF32", SYSCONF, _SC_XBS5_ILP32_OFF32 },
|
||||
{ "_XBS5_ILP32_OFFBIG", SYSCONF, _SC_XBS5_ILP32_OFFBIG },
|
||||
{ "_XBS5_LP64_OFF64", SYSCONF, _SC_XBS5_LP64_OFF64 },
|
||||
{ "_XBS5_LPBIG_OFFBIG", SYSCONF, _SC_XBS5_LPBIG_OFFBIG },
|
||||
#endif /* _SC_XBS5_ILP32_OFF32 */
|
||||
|
||||
/* POSIX.1 Configurable Pathname Values */
|
||||
{ "LINK_MAX", PATHCONF, _PC_LINK_MAX },
|
||||
{ "MAX_CANON", PATHCONF, _PC_MAX_CANON },
|
||||
{ "MAX_INPUT", PATHCONF, _PC_MAX_INPUT },
|
||||
|
|
@ -134,81 +321,93 @@ static const struct conf_variable conf_table[] =
|
|||
{ "_POSIX_NO_TRUNC", PATHCONF, _PC_NO_TRUNC },
|
||||
{ "_POSIX_VDISABLE", PATHCONF, _PC_VDISABLE },
|
||||
|
||||
/* XPG 4.2 Configurable Pathname Values */
|
||||
#if defined (_PC_FILESIZEBITS)
|
||||
{ "FILESIZEBITS", PATHCONF, _PC_FILESIZEBITS },
|
||||
#endif
|
||||
#if defined (_PC_ASYNC_IO)
|
||||
{ "_POSIX_ASYNC_IO", PATHCONF, _PC_ASYNC_IO },
|
||||
#endif
|
||||
#if defined (_PC_PRIO_IO)
|
||||
{ "_POSIX_PRIO_IO", PATHCONF, _PC_PRIO_IO },
|
||||
#endif
|
||||
#if defined (_PC_SYNC_IO)
|
||||
{ "_POSIX_SYNC_IO", PATHCONF, _PC_SYNC_IO },
|
||||
#endif
|
||||
|
||||
{ NULL }
|
||||
};
|
||||
|
||||
static int num_getconf_variables = sizeof(conf_table) / sizeof(struct conf_variable) - 1;
|
||||
|
||||
extern char *this_command_name;
|
||||
extern char *xmalloc ();
|
||||
extern char **make_builtin_argv ();
|
||||
static int getconf_main ();
|
||||
|
||||
static void getconf_help ();
|
||||
static int getconf_print ();
|
||||
static int getconf_one ();
|
||||
static int getconf_all ();
|
||||
|
||||
int
|
||||
getconf_builtin (list)
|
||||
WORD_LIST *list;
|
||||
{
|
||||
int c, r;
|
||||
int c, r, opt, aflag;
|
||||
char **v;
|
||||
WORD_LIST *l;
|
||||
|
||||
v = make_builtin_argv (list, &c);
|
||||
r = getconf_main (c, v);
|
||||
free (v);
|
||||
aflag = 0;
|
||||
reset_internal_getopt();
|
||||
while ((opt = internal_getopt (list, "ah")) != -1) {
|
||||
switch (opt) {
|
||||
case 'a':
|
||||
aflag = 1;
|
||||
break;
|
||||
case 'h':
|
||||
getconf_help();
|
||||
return(EXECUTION_SUCCESS);
|
||||
default:
|
||||
builtin_usage();
|
||||
return(EX_USAGE);
|
||||
}
|
||||
}
|
||||
|
||||
list = loptend;
|
||||
if ((aflag == 0 && list == 0) || (aflag && list) || list_length(list) > 2) {
|
||||
builtin_usage();
|
||||
return(EX_USAGE);
|
||||
}
|
||||
|
||||
r = aflag ? getconf_all() : getconf_one(list);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
static int
|
||||
getconf_main(argc, argv)
|
||||
int argc;
|
||||
char **argv;
|
||||
static void
|
||||
getconf_help()
|
||||
{
|
||||
int ch;
|
||||
const struct conf_variable *cp;
|
||||
register int i, column;
|
||||
|
||||
long val;
|
||||
size_t slen;
|
||||
char *sval;
|
||||
|
||||
setlocale(LC_ALL, "");
|
||||
|
||||
while ((ch = getopt(argc, argv, "")) != -1) {
|
||||
switch (ch) {
|
||||
case '?':
|
||||
default:
|
||||
builtin_usage();
|
||||
return(EX_USAGE);
|
||||
/* NOTREACHED */
|
||||
}
|
||||
}
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
if (argc < 1 || argc > 2) {
|
||||
builtin_usage();
|
||||
return(EX_USAGE);
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
||||
builtin_usage();
|
||||
printf("Acceptable variable names are:\n");
|
||||
for (cp = conf_table; cp->name != NULL; cp++) {
|
||||
if (strcmp(*argv, cp->name) == 0)
|
||||
break;
|
||||
}
|
||||
if (cp->name == NULL) {
|
||||
builtin_error ("%s: unknown variable", *argv);
|
||||
return (EXECUTION_FAILURE);
|
||||
if (cp->type == PATHCONF)
|
||||
printf("%s pathname\n", cp->name);
|
||||
else
|
||||
printf("%s\n", cp->name);
|
||||
}
|
||||
}
|
||||
|
||||
if (cp->type == PATHCONF) {
|
||||
if (argc != 2) {
|
||||
builtin_usage();
|
||||
return(EX_USAGE);
|
||||
}
|
||||
} else {
|
||||
if (argc != 1) {
|
||||
builtin_usage();
|
||||
return(EX_USAGE);
|
||||
}
|
||||
}
|
||||
static int
|
||||
getconf_print(cp, vpath, all)
|
||||
struct conf_variable *cp;
|
||||
char *vpath;
|
||||
int all;
|
||||
{
|
||||
long val;
|
||||
char *sval;
|
||||
size_t slen;
|
||||
|
||||
switch (cp->type) {
|
||||
case CONSTANT:
|
||||
|
|
@ -216,19 +415,33 @@ getconf_main(argc, argv)
|
|||
break;
|
||||
|
||||
case CONFSTR:
|
||||
errno = 0;
|
||||
slen = confstr (cp->value, (char *) 0, (size_t) 0);
|
||||
|
||||
if (slen == 0) {
|
||||
if (errno != 0) {
|
||||
if (all)
|
||||
printf ("getconf: %s\n", strerror(errno));
|
||||
else
|
||||
builtin_error ("%s", strerror(errno));
|
||||
} else
|
||||
printf ("undefined\n");
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
sval = xmalloc(slen);
|
||||
|
||||
confstr(cp->value, sval, slen);
|
||||
printf("%s\n", sval);
|
||||
free(sval);
|
||||
break;
|
||||
|
||||
case SYSCONF:
|
||||
errno = 0;
|
||||
if ((val = sysconf(cp->value)) == -1) {
|
||||
if (errno != 0) {
|
||||
builtin_error ("%s", strerror (errno));
|
||||
if (all)
|
||||
printf("getconf: %s\n", strerror (errno));
|
||||
else
|
||||
builtin_error ("%s", strerror (errno));
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
|
||||
|
|
@ -240,9 +453,12 @@ getconf_main(argc, argv)
|
|||
|
||||
case PATHCONF:
|
||||
errno = 0;
|
||||
if ((val = pathconf(argv[1], cp->value)) == -1) {
|
||||
if ((val = pathconf(vpath, cp->value)) == -1) {
|
||||
if (errno != 0) {
|
||||
builtin_error ("%s: %s", argv[1], strerror (errno));
|
||||
if (all)
|
||||
printf("getconf: %s: %s\n", vpath, strerror (errno));
|
||||
else
|
||||
builtin_error ("%s: %s", vpath, strerror (errno));
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
|
||||
|
|
@ -256,6 +472,56 @@ getconf_main(argc, argv)
|
|||
return (ferror(stdout) ? EXECUTION_FAILURE : EXECUTION_SUCCESS);
|
||||
}
|
||||
|
||||
static int
|
||||
getconf_all()
|
||||
{
|
||||
const struct conf_variable *cp;
|
||||
int ret;
|
||||
|
||||
ret = EXECUTION_SUCCESS;
|
||||
for (cp = conf_table; cp->name != NULL; cp++) {
|
||||
printf("%-35s", cp->name);
|
||||
if (getconf_print(cp, ".", 1) == EXECUTION_FAILURE)
|
||||
ret = EXECUTION_FAILURE;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int
|
||||
getconf_one(list)
|
||||
WORD_LIST *list;
|
||||
{
|
||||
const struct conf_variable *cp;
|
||||
char *vname, *vpath;
|
||||
|
||||
vname = list->word->word;
|
||||
vpath = (list->next && list->next->word) ? list->next->word->word
|
||||
: (char *)NULL;
|
||||
|
||||
for (cp = conf_table; cp->name != NULL; cp++) {
|
||||
if (strcmp(vname, cp->name) == 0)
|
||||
break;
|
||||
}
|
||||
if (cp->name == NULL) {
|
||||
builtin_error ("%s: unknown variable", vname);
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
|
||||
if (cp->type == PATHCONF) {
|
||||
if (list->next == 0) {
|
||||
builtin_usage();
|
||||
return(EX_USAGE);
|
||||
}
|
||||
} else {
|
||||
if (list->next) {
|
||||
builtin_usage();
|
||||
return(EX_USAGE);
|
||||
}
|
||||
}
|
||||
|
||||
return (getconf_print(cp, vpath, 0));
|
||||
}
|
||||
|
||||
static char *getconf_doc[] = {
|
||||
"getconf writes the current value of a configurable system limit or",
|
||||
"option variable to the standard output.",
|
||||
|
|
@ -267,6 +533,6 @@ struct builtin getconf_struct = {
|
|||
getconf_builtin,
|
||||
BUILTIN_ENABLED,
|
||||
getconf_doc,
|
||||
"getconf sysvar or getconf pathvar pathname",
|
||||
"getconf -a or getconf -h or getconf sysvar or getconf pathvar pathname",
|
||||
0
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,37 +1,4 @@
|
|||
/*
|
||||
* Copyright (c) 1989, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include "bashtypes.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
|
|
@ -47,44 +14,15 @@
|
|||
extern int errno;
|
||||
#endif
|
||||
|
||||
#define PF(f, func) { \
|
||||
if (fieldwidth) \
|
||||
if (precision) \
|
||||
(void)fprintf(ofp, f, fieldwidth, precision, func); \
|
||||
else \
|
||||
(void)fprintf(ofp, f, fieldwidth, func); \
|
||||
else if (precision) \
|
||||
(void)fprintf(ofp, f, precision, func); \
|
||||
else \
|
||||
(void)fprintf(ofp, f, func); \
|
||||
}
|
||||
|
||||
static int asciicode __P((void));
|
||||
static void escape __P((char *));
|
||||
static int getchr __P((void));
|
||||
static double getdouble __P((void));
|
||||
static int getint __P((int *));
|
||||
static int getlong __P((long *));
|
||||
static char *getstr __P((void));
|
||||
static char *mklong __P((char *, int));
|
||||
static void usage __P((void));
|
||||
|
||||
static char **gargv;
|
||||
|
||||
int print_builtin ();
|
||||
static int printf_main ();
|
||||
static int printargs ();
|
||||
|
||||
static FILE *ofp;
|
||||
|
||||
extern char *ansicstr ();
|
||||
extern char *single_quote ();
|
||||
extern char **make_builtin_argv ();
|
||||
|
||||
extern char *this_command_name;
|
||||
|
||||
extern int optind;
|
||||
|
||||
static char *print_doc[] = {
|
||||
"Output the arguments. The -f option means to use the argument as a",
|
||||
"format string as would be supplied to printf(1). The rest of the",
|
||||
|
|
@ -168,12 +106,15 @@ opt_end:
|
|||
|
||||
if (pfmt)
|
||||
{
|
||||
v = word_list_to_argv (list, 0, 2, &c);
|
||||
v[0] = this_command_name;
|
||||
v[1] = pfmt;
|
||||
r = printf_main (c, v);
|
||||
free (v);
|
||||
return r;
|
||||
WORD_DESC *w;
|
||||
WORD_LIST *nlist;
|
||||
|
||||
w = make_word (pfmt);
|
||||
nlist = make_word_list (w, list);
|
||||
r = printf_builtin (nlist);
|
||||
nlist->next = (WORD_LIST *)NULL;
|
||||
dispose_words (nlist);
|
||||
return (r);
|
||||
}
|
||||
|
||||
if (raw)
|
||||
|
|
@ -198,7 +139,8 @@ opt_end:
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int printargs (list, ofp)
|
||||
static int
|
||||
printargs (list, ofp)
|
||||
WORD_LIST *list;
|
||||
FILE *ofp;
|
||||
{
|
||||
|
|
@ -208,7 +150,7 @@ static int printargs (list, ofp)
|
|||
|
||||
for (sawc = 0, l = list; l; l = l->next)
|
||||
{
|
||||
ostr = ansicstr (l->word->word, strlen (l->word->word), &sawc);
|
||||
ostr = ansicstr (l->word->word, strlen (l->word->word), &sawc, (int *)0);
|
||||
fprintf (ofp, "%s", ostr);
|
||||
free (ostr);
|
||||
if (sawc)
|
||||
|
|
@ -219,335 +161,3 @@ static int printargs (list, ofp)
|
|||
return (1);
|
||||
}
|
||||
|
||||
static int
|
||||
printf_main(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
static char *skip1, *skip2;
|
||||
int ch, end, fieldwidth, precision;
|
||||
char convch, nextch, *format, *fmt, *start;
|
||||
|
||||
while ((ch = getopt(argc, argv, "")) != EOF)
|
||||
switch (ch) {
|
||||
case '?':
|
||||
default:
|
||||
usage();
|
||||
return (1);
|
||||
}
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
if (argc < 1) {
|
||||
usage();
|
||||
return (1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Basic algorithm is to scan the format string for conversion
|
||||
* specifications -- once one is found, find out if the field
|
||||
* width or precision is a '*'; if it is, gather up value. Note,
|
||||
* format strings are reused as necessary to use up the provided
|
||||
* arguments, arguments of zero/null string are provided to use
|
||||
* up the format string.
|
||||
*/
|
||||
skip1 = "#-+ 0";
|
||||
skip2 = "*0123456789";
|
||||
|
||||
escape(fmt = format = *argv); /* backslash interpretation */
|
||||
gargv = ++argv;
|
||||
for (;;) {
|
||||
end = 0;
|
||||
/* find next format specification */
|
||||
next: for (start = fmt;; ++fmt) {
|
||||
if (!*fmt) {
|
||||
/* avoid infinite loop */
|
||||
if (end == 1) {
|
||||
warnx("missing format character",
|
||||
NULL, NULL);
|
||||
return (1);
|
||||
}
|
||||
end = 1;
|
||||
if (fmt > start)
|
||||
(void)printf("%s", start);
|
||||
if (!*gargv)
|
||||
return (0);
|
||||
fmt = format;
|
||||
goto next;
|
||||
}
|
||||
/* %% prints a % */
|
||||
if (*fmt == '%') {
|
||||
if (*++fmt != '%')
|
||||
break;
|
||||
*fmt++ = '\0';
|
||||
(void)printf("%s", start);
|
||||
goto next;
|
||||
}
|
||||
}
|
||||
|
||||
/* skip to field width */
|
||||
for (; strchr(skip1, *fmt); ++fmt);
|
||||
if (*fmt == '*') {
|
||||
if (getint(&fieldwidth))
|
||||
return (1);
|
||||
} else
|
||||
fieldwidth = 0;
|
||||
|
||||
/* skip to possible '.', get following precision */
|
||||
for (; strchr(skip2, *fmt); ++fmt);
|
||||
if (*fmt == '.')
|
||||
++fmt;
|
||||
if (*fmt == '*') {
|
||||
if (getint(&precision))
|
||||
return (1);
|
||||
} else
|
||||
precision = 0;
|
||||
|
||||
/* skip to conversion char */
|
||||
for (; strchr(skip2, *fmt); ++fmt);
|
||||
if (!*fmt) {
|
||||
warnx("missing format character", NULL, NULL);
|
||||
return (1);
|
||||
}
|
||||
|
||||
convch = *fmt;
|
||||
nextch = *++fmt;
|
||||
*fmt = '\0';
|
||||
switch(convch) {
|
||||
case 'c': {
|
||||
char p;
|
||||
|
||||
p = getchr();
|
||||
PF(start, p);
|
||||
break;
|
||||
}
|
||||
case 's': {
|
||||
char *p;
|
||||
|
||||
p = getstr();
|
||||
PF(start, p);
|
||||
break;
|
||||
}
|
||||
case 'b': { /* expand escapes in argument */
|
||||
char *p;
|
||||
|
||||
p = getstr();
|
||||
escape(p);
|
||||
PF(start, p);
|
||||
break;
|
||||
}
|
||||
case 'q': { /* print with shell single quoting */
|
||||
char *p, *p2;
|
||||
|
||||
p = getstr();
|
||||
p2 = single_quote(p);
|
||||
PF(start, p2);
|
||||
free(p2);
|
||||
break;
|
||||
}
|
||||
case 'd': case 'i': case 'o': case 'u': case 'x': case 'X': {
|
||||
long p;
|
||||
char *f;
|
||||
|
||||
if ((f = mklong(start, convch)) == NULL)
|
||||
return (1);
|
||||
if (getlong(&p))
|
||||
return (1);
|
||||
PF(f, p);
|
||||
break;
|
||||
}
|
||||
case 'e': case 'E': case 'f': case 'g': case 'G': {
|
||||
double p;
|
||||
|
||||
p = getdouble();
|
||||
PF(start, p);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
warnx("illegal format character", NULL, NULL);
|
||||
return (1);
|
||||
}
|
||||
*fmt = nextch;
|
||||
}
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
||||
static char *
|
||||
mklong(str, ch)
|
||||
char *str;
|
||||
int ch;
|
||||
{
|
||||
static char copy[64];
|
||||
int len;
|
||||
|
||||
len = strlen(str) + 2;
|
||||
memmove(copy, str, len - 3);
|
||||
copy[len - 3] = 'l';
|
||||
copy[len - 2] = ch;
|
||||
copy[len - 1] = '\0';
|
||||
return (copy);
|
||||
}
|
||||
|
||||
static void
|
||||
escape(fmt)
|
||||
register char *fmt;
|
||||
{
|
||||
register char *store;
|
||||
register int value, c;
|
||||
|
||||
for (store = fmt; c = *fmt; ++fmt, ++store) {
|
||||
if (c != '\\') {
|
||||
*store = c;
|
||||
continue;
|
||||
}
|
||||
switch (*++fmt) {
|
||||
case '\0': /* EOS, user error */
|
||||
*store = '\\';
|
||||
*++store = '\0';
|
||||
return;
|
||||
case '\\': /* backslash */
|
||||
case '\'': /* single quote */
|
||||
*store = *fmt;
|
||||
break;
|
||||
case 'a': /* bell/alert */
|
||||
*store = '\7';
|
||||
break;
|
||||
case 'b': /* backspace */
|
||||
*store = '\b';
|
||||
break;
|
||||
case 'c':
|
||||
return;
|
||||
case 'e':
|
||||
case 'E':
|
||||
*store = '\033';
|
||||
break;
|
||||
case 'f': /* form-feed */
|
||||
*store = '\f';
|
||||
break;
|
||||
case 'n': /* newline */
|
||||
*store = '\n';
|
||||
break;
|
||||
case 'r': /* carriage-return */
|
||||
*store = '\r';
|
||||
break;
|
||||
case 't': /* horizontal tab */
|
||||
*store = '\t';
|
||||
break;
|
||||
case 'v': /* vertical tab */
|
||||
*store = '\13';
|
||||
break;
|
||||
/* octal constant */
|
||||
case '0': case '1': case '2': case '3':
|
||||
case '4': case '5': case '6': case '7':
|
||||
for (c = 3, value = 0;
|
||||
c-- && *fmt >= '0' && *fmt <= '7'; ++fmt) {
|
||||
value <<= 3;
|
||||
value += *fmt - '0';
|
||||
}
|
||||
--fmt;
|
||||
*store = value;
|
||||
break;
|
||||
default:
|
||||
*store = *fmt;
|
||||
break;
|
||||
}
|
||||
}
|
||||
*store = '\0';
|
||||
}
|
||||
|
||||
static int
|
||||
getchr()
|
||||
{
|
||||
if (!*gargv)
|
||||
return ('\0');
|
||||
return ((int)**gargv++);
|
||||
}
|
||||
|
||||
static char *
|
||||
getstr()
|
||||
{
|
||||
if (!*gargv)
|
||||
return ("");
|
||||
return (*gargv++);
|
||||
}
|
||||
|
||||
static char *Number = "+-.0123456789";
|
||||
static int
|
||||
getint(ip)
|
||||
int *ip;
|
||||
{
|
||||
long val;
|
||||
|
||||
if (getlong(&val))
|
||||
return (1);
|
||||
if (val > INT_MAX) {
|
||||
warnx("%s: %s", *gargv, strerror(ERANGE));
|
||||
return (1);
|
||||
}
|
||||
*ip = val;
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
getlong(lp)
|
||||
long *lp;
|
||||
{
|
||||
long val;
|
||||
char *ep;
|
||||
|
||||
if (!*gargv) {
|
||||
*lp = 0;
|
||||
return (0);
|
||||
}
|
||||
if (strchr(Number, **gargv)) {
|
||||
errno = 0;
|
||||
val = strtol(*gargv, &ep, 0);
|
||||
if (*ep != '\0') {
|
||||
warnx("%s: illegal number", *gargv, NULL);
|
||||
return (1);
|
||||
}
|
||||
if (errno == ERANGE)
|
||||
if (val == LONG_MAX) {
|
||||
warnx("%s: %s", *gargv, strerror(ERANGE));
|
||||
return (1);
|
||||
}
|
||||
if (val == LONG_MIN) {
|
||||
warnx("%s: %s", *gargv, strerror(ERANGE));
|
||||
return (1);
|
||||
}
|
||||
|
||||
*lp = val;
|
||||
++gargv;
|
||||
return (0);
|
||||
}
|
||||
*lp = (long)asciicode();
|
||||
return (0);
|
||||
}
|
||||
|
||||
static double
|
||||
getdouble()
|
||||
{
|
||||
if (!*gargv)
|
||||
return ((double)0);
|
||||
if (strchr(Number, **gargv))
|
||||
return (atof(*gargv++));
|
||||
return ((double)asciicode());
|
||||
}
|
||||
|
||||
static int
|
||||
asciicode()
|
||||
{
|
||||
register int ch;
|
||||
|
||||
ch = **gargv;
|
||||
if (ch == '\'' || ch == '"')
|
||||
ch = (*gargv)[1];
|
||||
++gargv;
|
||||
return (ch);
|
||||
}
|
||||
|
||||
static void
|
||||
usage()
|
||||
{
|
||||
(void)fprintf(stderr, "usage: print [-Rnprs] [-u unit] [-f format] [arg ...]\n");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,460 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 1989, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#if !defined(BUILTIN) && !defined(SHELL)
|
||||
#ifndef lint
|
||||
static char copyright[] =
|
||||
"@(#) Copyright (c) 1989, 1993\n\
|
||||
The Regents of the University of California. All rights reserved.\n";
|
||||
#endif /* not lint */
|
||||
#endif
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)printf.c 8.1 (Berkeley) 7/20/93";
|
||||
#endif /* not lint */
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "bashansi.h"
|
||||
#include "shell.h"
|
||||
#include "builtins.h"
|
||||
#include "stdc.h"
|
||||
|
||||
#if !defined (errno)
|
||||
extern int errno;
|
||||
#endif
|
||||
|
||||
#define PF(f, func) { \
|
||||
if (fieldwidth) \
|
||||
if (precision) \
|
||||
(void)printf(f, fieldwidth, precision, func); \
|
||||
else \
|
||||
(void)printf(f, fieldwidth, func); \
|
||||
else if (precision) \
|
||||
(void)printf(f, precision, func); \
|
||||
else \
|
||||
(void)printf(f, func); \
|
||||
}
|
||||
|
||||
static int asciicode __P((void));
|
||||
static void escape __P((char *));
|
||||
static int getchr __P((void));
|
||||
static double getdouble __P((void));
|
||||
static int getint __P((int *));
|
||||
static int getlong __P((long *));
|
||||
static char *getstr __P((void));
|
||||
static char *mklong __P((char *, int));
|
||||
static void usage __P((void));
|
||||
|
||||
static char **gargv;
|
||||
|
||||
int printf_builtin ();
|
||||
static int printf_main ();
|
||||
extern char *this_command_name;
|
||||
extern char *single_quote ();
|
||||
extern char **make_builtin_argv ();
|
||||
|
||||
static char *printf_doc[] = {
|
||||
"printf formats and prints its arguments, after the first, under control",
|
||||
"of the format. The format is a character string which contains three",
|
||||
"types of objects: plain characters, which are simply copied to standard",
|
||||
"output, character escape sequences which are converted and copied to the",
|
||||
"standard output, and format specifications, each of which causes printing",
|
||||
"of the next successive argument. In addition to the standard printf(1)",
|
||||
"formats, %%b means to expand escapes in the corresponding argument, and",
|
||||
"%%q means to quote the argument in a way that can be reused as shell input.",
|
||||
(char *)NULL
|
||||
};
|
||||
|
||||
struct builtin printf_struct = {
|
||||
"printf",
|
||||
printf_builtin,
|
||||
BUILTIN_ENABLED,
|
||||
printf_doc,
|
||||
"printf format [arguments]",
|
||||
(char *)0
|
||||
};
|
||||
|
||||
int
|
||||
printf_builtin (list)
|
||||
WORD_LIST *list;
|
||||
{
|
||||
int c, r;
|
||||
char **v;
|
||||
WORD_LIST *l;
|
||||
|
||||
v = make_builtin_argv (list, &c);
|
||||
r = printf_main (c, v);
|
||||
free (v);
|
||||
fflush(stdout);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
static int
|
||||
printf_main(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
extern int optind;
|
||||
static char *skip1, *skip2;
|
||||
int ch, end, fieldwidth, precision;
|
||||
char convch, nextch, *format, *fmt, *start;
|
||||
|
||||
while ((ch = getopt(argc, argv, "")) != EOF)
|
||||
switch (ch) {
|
||||
case '?':
|
||||
default:
|
||||
usage();
|
||||
return (1);
|
||||
}
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
if (argc < 1) {
|
||||
usage();
|
||||
return (1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Basic algorithm is to scan the format string for conversion
|
||||
* specifications -- once one is found, find out if the field
|
||||
* width or precision is a '*'; if it is, gather up value. Note,
|
||||
* format strings are reused as necessary to use up the provided
|
||||
* arguments, arguments of zero/null string are provided to use
|
||||
* up the format string.
|
||||
*/
|
||||
skip1 = "#-+ 0";
|
||||
skip2 = "*0123456789";
|
||||
|
||||
escape(fmt = format = *argv); /* backslash interpretation */
|
||||
gargv = ++argv;
|
||||
for (;;) {
|
||||
end = 0;
|
||||
/* find next format specification */
|
||||
next: for (start = fmt;; ++fmt) {
|
||||
if (!*fmt) {
|
||||
/* avoid infinite loop */
|
||||
if (end == 1) {
|
||||
warnx("missing format character",
|
||||
NULL, NULL);
|
||||
return (1);
|
||||
}
|
||||
end = 1;
|
||||
if (fmt > start)
|
||||
(void)printf("%s", start);
|
||||
if (!*gargv)
|
||||
return (0);
|
||||
fmt = format;
|
||||
goto next;
|
||||
}
|
||||
/* %% prints a % */
|
||||
if (*fmt == '%') {
|
||||
if (*++fmt != '%')
|
||||
break;
|
||||
*fmt++ = '\0';
|
||||
(void)printf("%s", start);
|
||||
goto next;
|
||||
}
|
||||
}
|
||||
|
||||
/* skip to field width */
|
||||
for (; strchr(skip1, *fmt); ++fmt);
|
||||
if (*fmt == '*') {
|
||||
if (getint(&fieldwidth))
|
||||
return (1);
|
||||
} else
|
||||
fieldwidth = 0;
|
||||
|
||||
/* skip to possible '.', get following precision */
|
||||
for (; strchr(skip2, *fmt); ++fmt);
|
||||
if (*fmt == '.')
|
||||
++fmt;
|
||||
if (*fmt == '*') {
|
||||
if (getint(&precision))
|
||||
return (1);
|
||||
} else
|
||||
precision = 0;
|
||||
|
||||
/* skip to conversion char */
|
||||
for (; strchr(skip2, *fmt); ++fmt);
|
||||
if (!*fmt) {
|
||||
warnx("missing format character", NULL, NULL);
|
||||
return (1);
|
||||
}
|
||||
|
||||
convch = *fmt;
|
||||
nextch = *++fmt;
|
||||
*fmt = '\0';
|
||||
switch(convch) {
|
||||
case 'c': {
|
||||
char p;
|
||||
|
||||
p = getchr();
|
||||
PF(start, p);
|
||||
break;
|
||||
}
|
||||
case 's': {
|
||||
char *p;
|
||||
|
||||
p = getstr();
|
||||
PF(start, p);
|
||||
break;
|
||||
}
|
||||
case 'b': { /* expand escapes in argument */
|
||||
char *p;
|
||||
|
||||
p = getstr();
|
||||
escape(p);
|
||||
PF("%s", p);
|
||||
break;
|
||||
}
|
||||
case 'q': { /* print with shell single quoting */
|
||||
char *p, *p2;
|
||||
|
||||
p = getstr();
|
||||
p2 = single_quote(p);
|
||||
PF("%s", p2);
|
||||
free(p2);
|
||||
break;
|
||||
}
|
||||
case 'd': case 'i': case 'o': case 'u': case 'x': case 'X': {
|
||||
long p;
|
||||
char *f;
|
||||
|
||||
if ((f = mklong(start, convch)) == NULL)
|
||||
return (1);
|
||||
if (getlong(&p))
|
||||
return (1);
|
||||
PF(f, p);
|
||||
break;
|
||||
}
|
||||
case 'e': case 'E': case 'f': case 'g': case 'G': {
|
||||
double p;
|
||||
|
||||
p = getdouble();
|
||||
PF(start, p);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
warnx("illegal format character", NULL, NULL);
|
||||
return (1);
|
||||
}
|
||||
*fmt = nextch;
|
||||
}
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
||||
static char *
|
||||
mklong(str, ch)
|
||||
char *str;
|
||||
int ch;
|
||||
{
|
||||
static char copy[64];
|
||||
int len;
|
||||
|
||||
len = strlen(str) + 2;
|
||||
memmove(copy, str, len - 3);
|
||||
copy[len - 3] = 'l';
|
||||
copy[len - 2] = ch;
|
||||
copy[len - 1] = '\0';
|
||||
return (copy);
|
||||
}
|
||||
|
||||
static void
|
||||
escape(fmt)
|
||||
register char *fmt;
|
||||
{
|
||||
register char *store;
|
||||
register int value, c;
|
||||
|
||||
for (store = fmt; c = *fmt; ++fmt, ++store) {
|
||||
if (c != '\\') {
|
||||
*store = c;
|
||||
continue;
|
||||
}
|
||||
switch (*++fmt) {
|
||||
case '\0': /* EOS, user error */
|
||||
*store = '\\';
|
||||
*++store = '\0';
|
||||
return;
|
||||
case '\\': /* backslash */
|
||||
case '\'': /* single quote */
|
||||
*store = *fmt;
|
||||
break;
|
||||
case 'a': /* bell/alert */
|
||||
*store = '\7';
|
||||
break;
|
||||
case 'b': /* backspace */
|
||||
*store = '\b';
|
||||
break;
|
||||
case 'c':
|
||||
return;
|
||||
case 'e':
|
||||
case 'E':
|
||||
*store = '\033';
|
||||
break;
|
||||
case 'f': /* form-feed */
|
||||
*store = '\f';
|
||||
break;
|
||||
case 'n': /* newline */
|
||||
*store = '\n';
|
||||
break;
|
||||
case 'r': /* carriage-return */
|
||||
*store = '\r';
|
||||
break;
|
||||
case 't': /* horizontal tab */
|
||||
*store = '\t';
|
||||
break;
|
||||
case 'v': /* vertical tab */
|
||||
*store = '\13';
|
||||
break;
|
||||
/* octal constant */
|
||||
case '0': case '1': case '2': case '3':
|
||||
case '4': case '5': case '6': case '7':
|
||||
for (c = 3, value = 0;
|
||||
c-- && *fmt >= '0' && *fmt <= '7'; ++fmt) {
|
||||
value <<= 3;
|
||||
value += *fmt - '0';
|
||||
}
|
||||
--fmt;
|
||||
*store = value;
|
||||
break;
|
||||
default:
|
||||
*store = *fmt;
|
||||
break;
|
||||
}
|
||||
}
|
||||
*store = '\0';
|
||||
}
|
||||
|
||||
static int
|
||||
getchr()
|
||||
{
|
||||
if (!*gargv)
|
||||
return ('\0');
|
||||
return ((int)**gargv++);
|
||||
}
|
||||
|
||||
static char *
|
||||
getstr()
|
||||
{
|
||||
if (!*gargv)
|
||||
return ("");
|
||||
return (*gargv++);
|
||||
}
|
||||
|
||||
static char *Number = "+-.0123456789";
|
||||
static int
|
||||
getint(ip)
|
||||
int *ip;
|
||||
{
|
||||
long val;
|
||||
|
||||
if (getlong(&val))
|
||||
return (1);
|
||||
if (val > INT_MAX) {
|
||||
warnx("%s: %s", *gargv, strerror(ERANGE));
|
||||
return (1);
|
||||
}
|
||||
*ip = val;
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
getlong(lp)
|
||||
long *lp;
|
||||
{
|
||||
long val;
|
||||
char *ep;
|
||||
|
||||
if (!*gargv) {
|
||||
*lp = 0;
|
||||
return (0);
|
||||
}
|
||||
if (strchr(Number, **gargv)) {
|
||||
errno = 0;
|
||||
val = strtol(*gargv, &ep, 0);
|
||||
if (*ep != '\0') {
|
||||
warnx("%s: illegal number", *gargv, NULL);
|
||||
return (1);
|
||||
}
|
||||
if (errno == ERANGE)
|
||||
if (val == LONG_MAX) {
|
||||
warnx("%s: %s", *gargv, strerror(ERANGE));
|
||||
return (1);
|
||||
}
|
||||
if (val == LONG_MIN) {
|
||||
warnx("%s: %s", *gargv, strerror(ERANGE));
|
||||
return (1);
|
||||
}
|
||||
|
||||
*lp = val;
|
||||
++gargv;
|
||||
return (0);
|
||||
}
|
||||
*lp = (long)asciicode();
|
||||
return (0);
|
||||
}
|
||||
|
||||
static double
|
||||
getdouble()
|
||||
{
|
||||
if (!*gargv)
|
||||
return ((double)0);
|
||||
if (strchr(Number, **gargv))
|
||||
return (atof(*gargv++));
|
||||
return ((double)asciicode());
|
||||
}
|
||||
|
||||
static int
|
||||
asciicode()
|
||||
{
|
||||
register int ch;
|
||||
|
||||
ch = **gargv;
|
||||
if (ch == '\'' || ch == '"')
|
||||
ch = (*gargv)[1];
|
||||
++gargv;
|
||||
return (ch);
|
||||
}
|
||||
|
||||
static void
|
||||
usage()
|
||||
{
|
||||
(void)fprintf(stderr, "usage: printf format [arg ...]\n");
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue