From 879c6a09115da97ba81540f78990ad7ccfbc6d6d Mon Sep 17 00:00:00 2001 From: tg Date: Fri, 12 Aug 2016 16:48:05 +0000 Subject: [PATCH 1/2] fix refactoro, spotted by Natureshadow; add (working) testsuite for all operators --- check.t | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- exprtok.h | 4 +-- sh.h | 4 +-- 3 files changed, 101 insertions(+), 7 deletions(-) diff --git a/check.t b/check.t index 45479b0..f221442 100644 --- a/check.t +++ b/check.t @@ -1,4 +1,4 @@ -# $MirOS: src/bin/mksh/check.t,v 1.750 2016/08/10 18:20:03 tg Exp $ +# $MirOS: src/bin/mksh/check.t,v 1.751 2016/08/12 16:48:02 tg Exp $ # -*- mode: sh -*- #- # Copyright © 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, @@ -30,7 +30,7 @@ # (2013/12/02 20:39:44) http://cvsweb.openbsd.org/cgi-bin/cvsweb/src/regress/bin/ksh/?sortby=date expected-stdout: - @(#)MIRBSD KSH R53 2016/08/04 + @(#)MIRBSD KSH R53 2016/08/12 description: Check version of shell. stdin: @@ -39,7 +39,7 @@ name: KSH_VERSION category: shell:legacy-no --- expected-stdout: - @(#)LEGACY KSH R53 2016/08/04 + @(#)LEGACY KSH R53 2016/08/12 description: Check version of legacy shell. stdin: @@ -6423,6 +6423,100 @@ description: stdin: for s in s; do break; done; print -s s --- +name: regression-68 +description: + Check that all common arithmetic operators work as expected +stdin: + echo 1 $(( a = 5 )) . + echo 2 $(( ++a )) , $(( a++ )) , $(( a )) . + echo 3 $(( --a )) , $(( a-- )) , $(( a )) . + echo 4 $(( a == 5 )) , $(( a == 6 )) . + echo 5 $(( a != 5 )) , $(( a != 6 )) . + echo 6 $(( a *= 3 )) . + echo 7 $(( a /= 5 )) . + echo 8 $(( a %= 2 )) . + echo 9 $(( a += 9 )) . + echo 10 $(( a -= 4 )) . + echo 11 $(( a <<= 1 )) . + echo 12 $(( a >>= 1 )) . + echo 13 $(( a &= 4 )) . + echo 14 $(( a ^= a )) . + echo 15 $(( a |= 5 )) . + echo 16 $(( 5 << 1 )) . + echo 17 $(( 5 >> 1 )) . + echo 18 $(( 5 <= 6 )) , $(( 5 <= 5 )) , $(( 5 <= 4 )) . + echo 19 $(( 5 >= 6 )) , $(( 5 >= 5 )) , $(( 5 >= 4 )) . + echo 20 $(( 5 < 6 )) , $(( 5 < 5 )) , $(( 5 < 4 )) . + echo 21 $(( 5 > 6 )) , $(( 5 > 5 )) , $(( 5 > 4 )) . + echo 22 $(( 0 && 0 )) , $(( 0 && 1 )) , $(( 1 && 0 )) , $(( 1 && 1 )) . + echo 23 $(( 0 || 0 )) , $(( 0 || 1 )) , $(( 1 || 0 )) , $(( 1 || 1 )) . + echo 24 $(( 5 * 3 )) . + echo 25 $(( 7 / 2 )) . + echo 26 $(( 5 % 5 )) , $(( 5 % 4 )) , $(( 5 % 1 )) , $(( 5 % -1 )) , $(( 5 % -2 )) . + echo 27 $(( 5 + 2 )) , $(( 5 + 0 )) , $(( 5 + -2 )) . + echo 28 $(( 5 - 2 )) , $(( 5 - 0 )) , $(( 5 - -2 )) . + echo 29 $(( 6 & 4 )) , $(( 6 & 8 )) . + echo 30 $(( 4 ^ 2 )) , $(( 4 ^ 4 )) . + echo 31 $(( 4 | 2 )) , $(( 4 | 4 )) , $(( 4 | 0 )) . + echo 32 $(( 0 ? 1 : 2 )) , $(( 3 ? 4 : 5 )) . + echo 33 $(( 5 , 2 , 3 )) . + echo 34 $(( ~0 )) , $(( ~1 )) , $(( ~~1 )) , $(( ~~2 )) . + echo 35 $(( !0 )) , $(( !1 )) , $(( !!1 )) , $(( !!2 )) . + echo 36 $(( (5) )) . +expected-stdout: + 1 5 . + 2 6 , 6 , 7 . + 3 6 , 6 , 5 . + 4 1 , 0 . + 5 0 , 1 . + 6 15 . + 7 3 . + 8 1 . + 9 10 . + 10 6 . + 11 12 . + 12 6 . + 13 4 . + 14 0 . + 15 5 . + 16 10 . + 17 2 . + 18 1 , 1 , 0 . + 19 0 , 1 , 1 . + 20 1 , 0 , 0 . + 21 0 , 0 , 1 . + 22 0 , 0 , 0 , 1 . + 23 0 , 1 , 1 , 1 . + 24 15 . + 25 3 . + 26 0 , 1 , 0 , 0 , 1 . + 27 7 , 5 , 3 . + 28 3 , 5 , 7 . + 29 4 , 0 . + 30 6 , 0 . + 31 6 , 4 , 4 . + 32 2 , 4 . + 33 3 . + 34 -1 , -2 , 1 , 2 . + 35 1 , 0 , 1 , 1 . + 36 5 . +--- +name: regression-69 +description: + Check that all non-lksh arithmetic operators work as expected +category: shell:legacy-no +stdin: + a=5 b=0x80000005 + echo 1 $(( a ^<= 1 )) , $(( b ^<= 1 )) . + echo 2 $(( a ^>= 2 )) , $(( b ^>= 2 )) . + echo 3 $(( 5 ^< 1 )) . + echo 4 $(( 5 ^> 1 )) . +expected-stdout: + 1 10 , 11 . + 2 -2147483646 , -1073741822 . + 3 10 . + 4 -2147483646 . +--- name: readonly-0 description: Ensure readonly is honoured for assignments and unset diff --git a/exprtok.h b/exprtok.h index 8a98926..e4329da 100644 --- a/exprtok.h +++ b/exprtok.h @@ -19,7 +19,7 @@ */ #if defined(EXPRTOK_DEFNS) -__RCSID("$MirOS: src/bin/mksh/exprtok.h,v 1.1 2016/07/27 00:55:27 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/exprtok.h,v 1.2 2016/08/12 16:48:05 tg Exp $"); /* see range comment below */ #define IS_ASSIGNOP(op) ((int)(op) >= (int)O_ASN && (int)(op) <= (int)O_BORASN) #define FN(name, len, prec, enum) /* nothing */ @@ -61,7 +61,7 @@ FN("!=", 2, P_EQUALITY, O_NE) /* before ! */ /* assignments are assumed to be in range O_ASN .. O_BORASN */ FN("=", 1, P_ASSIGN, O_ASN) FN("*=", 2, P_ASSIGN, O_TIMESASN) -FN("/-", 2, P_ASSIGN, O_DIVASN) +FN("/=", 2, P_ASSIGN, O_DIVASN) FN("%=", 2, P_ASSIGN, O_MODASN) FN("+=", 2, P_ASSIGN, O_PLUSASN) FN("-=", 2, P_ASSIGN, O_MINUSASN) diff --git a/sh.h b/sh.h index dc28bd9..a6cfb6f 100644 --- a/sh.h +++ b/sh.h @@ -175,9 +175,9 @@ #endif #ifdef EXTERN -__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.785 2016/08/10 18:20:18 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.786 2016/08/12 16:48:05 tg Exp $"); #endif -#define MKSH_VERSION "R53 2016/08/04" +#define MKSH_VERSION "R53 2016/08/12" /* arithmetic types: C implementation */ #if !HAVE_CAN_INTTYPES From 61a50ea6ba94a05520f92e420f1c00c4ddf6be44 Mon Sep 17 00:00:00 2001 From: root Date: Fri, 12 Aug 2016 16:48:06 +0000 Subject: [PATCH 2/2] This commit was manufactured by cvs2svn to create tag 'mksh-R53a'. Sprout from master 2016-08-12 16:48:05 UTC tg 'fix refactoro, spotted by Natureshadow; add (working) testsuite for all operators' Delete: Makefile --- Makefile | 195 ------------------------------------------------------- 1 file changed, 195 deletions(-) delete mode 100644 Makefile diff --git a/Makefile b/Makefile deleted file mode 100644 index 0157493..0000000 --- a/Makefile +++ /dev/null @@ -1,195 +0,0 @@ -# $MirOS: src/bin/mksh/Makefile,v 1.151 2016/08/10 18:20:17 tg Exp $ -#- -# Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, -# 2011, 2012, 2013, 2014, 2015, 2016 -# mirabilos -# -# Provided that these terms and disclaimer and all copyright notices -# are retained or reproduced in an accompanying document, permission -# is granted to deal in this work without restriction, including un- -# limited rights to use, publicly perform, distribute, sell, modify, -# merge, give away, or sublicence. -# -# This work is provided "AS IS" and WITHOUT WARRANTY of any kind, to -# 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 -# of said person's immediate fault when using the work as intended. - -.ifmake d -__CRAZY= Yes -MKC_DEBG= cpp -DEBUGFILE= Yes -NOMAN= Yes -.endif - -.include - -SRCDIR= ${.CURDIR} - -PROG= mksh -SRCS= edit.c eval.c exec.c expr.c funcs.c histrap.c jobs.c \ - lalloc.c lex.c main.c misc.c shf.c syn.c tree.c var.c -.if !make(test-build) -CPPFLAGS+= -DMKSH_ASSUME_UTF8 -DMKSH_DISABLE_DEPRECATED \ - -DHAVE_ATTRIBUTE_BOUNDED=1 -DHAVE_ATTRIBUTE_FORMAT=1 \ - -DHAVE_ATTRIBUTE_NORETURN=1 -DHAVE_ATTRIBUTE_PURE=1 \ - -DHAVE_ATTRIBUTE_UNUSED=1 -DHAVE_ATTRIBUTE_USED=1 \ - -DHAVE_SYS_TIME_H=1 -DHAVE_TIME_H=1 -DHAVE_BOTH_TIME_H=1 \ - -DHAVE_SYS_BSDTYPES_H=0 -DHAVE_SYS_FILE_H=1 \ - -DHAVE_SYS_MKDEV_H=0 -DHAVE_SYS_MMAN_H=1 -DHAVE_SYS_PARAM_H=1 \ - -DHAVE_SYS_RESOURCE_H=1 -DHAVE_SYS_SELECT_H=1 \ - -DHAVE_SYS_SYSMACROS_H=0 -DHAVE_BSTRING_H=0 -DHAVE_GRP_H=1 \ - -DHAVE_IO_H=0 -DHAVE_LIBGEN_H=1 -DHAVE_LIBUTIL_H=0 \ - -DHAVE_PATHS_H=1 -DHAVE_STDINT_H=1 -DHAVE_STRINGS_H=1 \ - -DHAVE_TERMIOS_H=1 -DHAVE_ULIMIT_H=0 -DHAVE_VALUES_H=0 \ - -DHAVE_CAN_INTTYPES=1 -DHAVE_CAN_UCBINTS=1 \ - -DHAVE_CAN_INT8TYPE=1 -DHAVE_CAN_UCBINT8=1 -DHAVE_RLIM_T=1 \ - -DHAVE_SIG_T=1 -DHAVE_SYS_ERRLIST=1 -DHAVE_SYS_SIGNAME=1 \ - -DHAVE_SYS_SIGLIST=1 -DHAVE_FLOCK=1 -DHAVE_LOCK_FCNTL=1 \ - -DHAVE_GETRUSAGE=1 -DHAVE_GETSID=1 -DHAVE_GETTIMEOFDAY=1 \ - -DHAVE_KILLPG=1 -DHAVE_MEMMOVE=1 -DHAVE_MKNOD=0 -DHAVE_MMAP=1 \ - -DHAVE_NICE=1 -DHAVE_REVOKE=1 -DHAVE_SETLOCALE_CTYPE=0 \ - -DHAVE_LANGINFO_CODESET=0 -DHAVE_SELECT=1 -DHAVE_SETRESUGID=1 \ - -DHAVE_SETGROUPS=1 -DHAVE_STRERROR=0 -DHAVE_STRSIGNAL=0 \ - -DHAVE_STRLCPY=1 -DHAVE_FLOCK_DECL=1 -DHAVE_REVOKE_DECL=1 \ - -DHAVE_SYS_ERRLIST_DECL=1 -DHAVE_SYS_SIGLIST_DECL=1 \ - -DHAVE_PERSISTENT_HISTORY=1 -DMKSH_BUILD_R=530 -CPPFLAGS+= -D${${PROG:L}_tf:C/(Mir${MAN:E}{0,1}){2}/4/:S/x/mksh_BUILD/:U} -CPPFLAGS+= -I. -COPTS+= -std=c89 -Wall -.endif - -USE_PRINTF_BUILTIN?= 0 -.if ${USE_PRINTF_BUILTIN} == 1 -.PATH: ${BSDSRCDIR}/usr.bin/printf -SRCS+= printf.c -CPPFLAGS+= -DMKSH_PRINTF_BUILTIN -.endif - -DEBUGFILE?= No -.if ${DEBUGFILE:L} == "yes" -CPPFLAGS+= -DDF=mksh_debugtofile -.endif - -MANLINKS= [ false pwd sh sleep test true -BINLINKS= ${MANLINKS} echo domainname kill -.for _i in ${BINLINKS} -LINKS+= ${BINDIR}/${PROG} ${BINDIR}/${_i} -.endfor -.for _i in ${MANLINKS} -MLINKS+= ${PROG}.1 ${_i}.1 -.endfor - -OPTGENS!= cd ${SRCDIR:Q} && echo *.opt -.for _i in ${OPTGENS} -GENERATED+= ${_i:R}.gen -${_i:R}.gen: ${_i} ${SRCDIR}/Build.sh - /bin/sh ${SRCDIR:Q}/Build.sh -G ${SRCDIR:Q}/${_i:Q} -.endfor -CLEANFILES+= ${GENERATED} - -${PROG} beforedepend: ${GENERATED} - -regress: ${PROG} check.pl check.t - -rm -rf regress-dir - mkdir -p regress-dir - echo export FNORD=666 >regress-dir/.mkshrc - HOME=$$(realpath regress-dir) perl ${SRCDIR}/check.pl \ - -s ${SRCDIR}/check.t -v -p ./${PROG} \ - -C shell:legacy-no,int:32,fastbox - -TEST_BUILD_ENV:= TARGET_OS= CPP= -TEST_BUILD_ENV+= HAVE_STRING_POOLING=0 - -test-build: .PHONY - -rm -rf build-dir - mkdir -p build-dir -.if ${USE_PRINTF_BUILTIN} == 1 - cp ${BSDSRCDIR}/usr.bin/printf/printf.c build-dir/ -.endif - cd build-dir; env CC=${CC:Q} CFLAGS=${CFLAGS:M*:Q} \ - CPPFLAGS=${CPPFLAGS:M*:Q} LDFLAGS=${LDFLAGS:M*:Q} \ - LIBS= NOWARN=-Wno-error ${TEST_BUILD_ENV} /bin/sh \ - ${SRCDIR}/Build.sh -Q -r ${_TBF} && ./test.sh -v -f - -CLEANFILES+= lksh.cat1 -test-build-lksh: .PHONY - cd ${SRCDIR} && exec ${MAKE} lksh.cat1 test-build _TBF=-L - -bothmans: .PHONY - cd ${SRCDIR} && exec ${MAKE} MAN='lksh.1 mksh.1' __MANALL - -cleandir: clean-extra - -clean-extra: .PHONY - -rm -rf build-dir regress-dir printf.o printf.ln - -mksh_tf=xMakefile${OStype:S/${MACHINE_OS}/1/1g}${OSNAME} -distribution: - sed 's!\$$I''d\([:$$]\)!$$M''irSecuCron\1!g' \ - ${SRCDIR}/dot.mkshrc >${DESTDIR}/etc/skel/.mkshrc - chown ${BINOWN}:${CONFGRP} ${DESTDIR}/etc/skel/.mkshrc - chmod 0644 ${DESTDIR}/etc/skel/.mkshrc - -.include - -.ifmake cats -V_GROFF!= pkg_info -e 'groff-*' -V_GHOSTSCRIPT!= pkg_info -e 'ghostscript-*' -. if empty(V_GROFF) || empty(V_GHOSTSCRIPT) -. error empty V_GROFF=${V_GROFF} or V_GHOSTSCRIPT=${V_GHOSTSCRIPT} -. endif -.endif - -CLEANFILES+= ${MANALL:S/.cat/.ps/} ${MAN:S/$/.pdf/} ${MANALL:S/$/.gz/} -CLEANFILES+= ${MAN:S/$/.htm/} ${MAN:S/$/.htm.gz/} -CLEANFILES+= ${MAN:S/$/.txt/} ${MAN:S/$/.txt.gz/} -CATS_KW= mksh, ksh, sh -CATS_TITLE_mksh_1=mksh - The MirBSD Korn Shell -cats: ${MANALL} ${MANALL:S/.cat/.ps/} -.if "${MANALL:Nlksh.cat1:Nmksh.cat1}" != "" -. error Adjust here. -.endif -.for _m _n in mksh 1 - x=$$(ident ${SRCDIR:Q}/${_m}.${_n} | \ - awk '/Mir''OS:/ { print $$4$$5; }' | \ - tr -dc 0-9); (( $${#x} == 14 )) || exit 1; exec \ - ${MKSH} ${BSDSRCDIR:Q}/contrib/hosted/tg/ps2pdfmir -p pa4 -c \ - -o ${_m}.${_n}.pdf '[' /Author '(The MirOS Project)' \ - /Title '('${CATS_TITLE_${_m}_${_n}:Q}')' \ - /Subject '(BSD Reference Manual)' /ModDate "(D:$$x)" \ - /Creator '(GNU groff version ${V_GROFF:S/groff-//} \(MirPorts\))' \ - /Producer '(Artifex Ghostscript ${V_GHOSTSCRIPT:S/ghostscript-//:S/-artifex//} \(MirPorts\))' \ - /Keywords '('${CATS_KW:Q}')' /DOCINFO pdfmark \ - -f ${_m}.ps${_n} -.endfor - set -e; . ${BSDSRCDIR:Q}/scripts/roff2htm; set_target_absolute; \ - for m in ${MANALL}; do \ - bn=$${m%.*}; ext=$${m##*.cat}; \ - [[ $$bn != $$m ]]; [[ $$ext != $$m ]]; \ - gzip -n9 <"$$m" >"$$m.gz"; \ - col -bx <"$$m" >"$$bn.$$ext.txt"; \ - rm -f "$$bn.$$ext.txt.gz"; gzip -n9 "$$bn.$$ext.txt"; \ - do_conversion_verbose "$$bn" "$$ext" "$$m" "$$bn.$$ext.htm"; \ - rm -f "$$bn.$$ext.htm.gz"; gzip -n9 "$$bn.$$ext.htm"; \ - done - -.ifmake d -. ifmake obj || depend || all || install || regress || test-build -d: -. else -d: all -. endif -.endif - -dr: - p=$$(realpath ${PROG:Q}) && cd ${SRCDIR:Q} && exec ${MKSH} \ - ${BSDSRCDIR:Q}/contrib/hosted/tg/sdmksh "$$p" - -repool: - cd ${.CURDIR:Q} && \ - exec ${MKSH} ${BSDSRCDIR:Q}/scripts/stringpool.sh sh.h