Commit Graph

200 Commits

Author SHA1 Message Date
tg f3b3b4b1fb remove some debugging code 2010-01-25 14:38:04 +00:00
tg 1ac42c1c1c fix © year 2010-01-25 14:07:39 +00:00
tg 6115f5a91c • re-implement wcswidth-like behaviour for ${%foo} even in !UTFMODE
• merge the rest of branch tg-wcswidth-behaviour
• enhance test cases for wcswidth-like behaviour
• switch hash table collision resolution algorithm to Python’s as announced
• bump vsn
2010-01-01 17:44:10 +00:00
tg 8213a28403 llvm/clang scan-build is now content… 2009-12-05 17:43:50 +00:00
tg f7ef72cbd7 Kürzen! 2009-12-05 13:02:26 +00:00
tg fa3acb939b fix 'mksh -U -i' and 'mksh +U -i' 2009-11-28 15:38:30 +00:00
tg f0bec87228 • fix 「mksh -lT1」 (it was broken due to getpgrp() et al. being
moved to early)
• allow ‘-T’ for MKSH_SMALL too, the installer needs it

sync clog
2009-10-30 14:37:43 +00:00
tg eafe88aa74 • overhaul handling of special variables
• use a combination of the one-at-a-time hash and an LCG for handling
  the $RANDOM special if !HAVE_ARC4RANDOM instead of rand(3)/srand(3)
  and get rid of time(3) usage to reduce import footprint
• raise entropy state (mostly in the !HAVE_ARC4RANDOM case though…)
• simplify handling of the $RANDOM_SPECIAL generally
• tweak hash() to save a temp var for non-optimising compilers
• some int → mksh_ari_t and other type fixes
• general tweaking of code and comments
2009-10-17 21:16:05 +00:00
tg 33b9f8b666 * rename "set -o posix" (FPOSIX) to "set -o sh" (FSH) because it's not
just a "somewhat more POSIX" but also a "/bin/sh legacy kludge" mode
* consistently capitalise POSIX and SUSv3/SUSv4 (same as AT&T ksh) and
  Bourne shell
2009-10-02 18:08:37 +00:00
tg ff8b75f46f SUSv4 says that there be exit 127; the old code tried but failed, so it
was an actual programmatical bug…
2009-09-29 12:28:13 +00:00
tg c8955138ec • avoid calling arc4random_pushb for inheritance and other redundant items;
call it only if $RANDOM is indeed set (although pool extension would be a
  possibility we do have arc4random_atexit which does it nicely too)
• avoid calling setspec for int→str conversion just before execve()
2009-09-27 10:31:06 +00:00
tg a59d14b565 further optimise and simplify the handling of $RANDOM, reads and writes
to it are now either arc4random or rand/srand, but srand retains the old
state; set +o arc4random is no longer possible, but if it's there we use
arc4random(3), if not, we use rand(3) for $RANDOM reads; optimise special
variable handling too and fix a few consts and other minor things
2009-09-26 03:40:03 +00:00
tg b50b43e3bf get rid of "U getenv" 2009-09-26 01:08:27 +00:00
tg 1dfb13b603 change undef/def MKSH_NOVI into 0/1 MKSH_S_NOVI flag (with more to come:
MKSH_S_EDIT for small (Emacs) editing mode, MKSH_S_FEAT for all the dis-
abled language features), which can be set to 0 despite MKSH_SMALL being
defined to re-enable the Vi command line editing mode (which I wouldn't,
but fits into the general mastermind scheme)
2009-09-24 17:15:33 +00:00
tg 1a28786229 * shrink MKSH_SMALL even further by removing functionality like
some GNU bash extensions (suggested by cnuke@) and bind macros
* make the random cache more efficient (and the code potentially
  smaller, although we have a new implementation of the oaat hash
  function, alongside the old one, now) and pushb only if needed
  (i.e. state has changed or user has set $RANDOM, but not onfork)
2009-09-23 18:04:58 +00:00
tg 588921333e more of this:
• shell flags are now handled in one single place (sh_flags.h)
• sync comments (between enum and array) and manpage with reality
• FMONITOR is now no longer needed for Hartz IV shells
2009-09-20 16:40:58 +00:00
tg 9531e12b36 merge the nameref code, using mksh standard scoping as discussed 2009-09-06 17:42:15 +00:00
tg 3a288c105f a couple of overnight, phone call and code/doku read ideas:
• we must not set the item pointer to NULL, since subsequent ktscan()
  would stop there and not find any later occurrences
  possible resolution strategies:
  ‣ still keep tablep; store a dummy value (either (void *)-1 or, probably
    more portable, &ktenter or something like that) as is-free marker
    ⇒ retains benefit of keeping count of actually used entries
    ⇒ see below for further discussion
  ‣ don't keep tablep; revert back to setting entry->flag = 0
    ⇒ need to ktwalk() or ktsort() for getting number of entries
    ⇒ most simple code
  ‣ same but with a twist: make ktscan() set pp to the first one with
    !(entry->flag & DEFINED)¹ so that it can subsequently be re-used,
    or, more accurate, free’d and the entry pointer re-used
    ⇒ less chance of texpand()ing when not needed
  ‣ similar (from kabelaffe@): in ktsearch(), move the one we DID find
    to the first unused one
    ⇒ doesn’t need tablep or something, but has the overall best
      memory use
    ⇒ more complicated ktscan(): needs to check pointer for NULL, for
      dummyval, then entry->flag
    ⇒ makes lookup more expensive
    ⇒ benefit: self-optimising hash tables
    ⇒ loss: still need ktwalk() or ktsort()
• when afree()ing in ktremove(), …
  ① need to take FINUSE into account
• Python-2.5.4/Objects/dictnotes.txt talks about cache lines
  ‣ linear backward scan is much worse than linear forward scan
    (even if we have to calculate the upper C-array bound)
  ‣ dereferencing the entry pointer in ktscan() is a penalty
• Python-2.5.4/Objects/dictobject.c has a lot of comments and
  a rather interesting collision resolution algorithm, which
  seems to de-cluster better than linear search at not much
  more cost
• clib and libobjfw have unusable (for looking-at-for-ideas)
  hash table implementations

this is a no-op change breaking ifdef-out-d code; the most likely
to happen is to switch to the following scheme:
• keep tablep in struct tbl
• use a magic pointer value for ktremove’d entries, deallocate
  the struct tbl as soon as possible – if not FINUSE, immediately
  inside ktremove()
  ‣ memory gain, despite needing to have tablep around
• nuke ktdelete, so that all ops go through kt{enter,remove}
  ‣ gains us accurate fill information
  ‣ speed gain: ktscan() needs no longer dereference removed entries
  ‣ memory (ktsort) and speed (ktwalk) gain: removed entries are now
    ignored right from the beginning, so tstate->left and the size
    of the sorted array are accurate
  ‣ removed entries no longer can cause texpand() to be invoked
⇒ this does not give us self-optimising tables, but a speed and
  memory benefit plus, probably, simplicity of code; we accurately
  know how many non-deleted entries are in a keytab so we can cal-
  culate if we need to expand, how much space ktsort() is going to
  need, and, for when indexed arrays will be converted to use key-
  tabs instead of singly linked linear lists, ${#foo[*]} is fast
  (although ${!foo[*]}² and ${foo[*]}³ will need some tweaking and
  may run a little less quickly)
• shuffle code around, so that things like search/scan and garbage
  collection can be re-used
• use Python’s collision resolution algorithm ipv linear search

② the list of keys needs to be sorted, at least for indexed arrays⁴
③ this needs to be sorted by keys, at least for indexed arrays⁴
④ … but this is a nice-to-have for associative arrays⁵ as well
⑤ which we however do not have
2009-08-29 11:26:44 +00:00
tg 9b8d4023fa … but since I liked the bonus of having the hval stored so much, merge
it with the array index; var.c says that
│ 1244         /* The table entry is always [0] */
so that we can have a special flag and a union which stores hval for
the table index, the array index otherwise (coïncidentally *hint hint*
they have the same size)
2009-08-28 21:01:27 +00:00
tg bb7a720a00 for now, until we really use kt*() otherwise, ifdef out tablep/hval 2009-08-28 20:38:43 +00:00
tg 4ccdfc8508 much better solution: save tablep and hash value¹ in the struct tbl entry
① also saves time during texpand :D

XXX this doesn’t work well with the current indexed-array implementation
2009-08-28 20:30:59 +00:00
tg 7240c843ce this is a rather stupid diff: give ktsearch/ktenter the capability to
return information needed to do a real ktremove instead of the pseudo
ktdelete operation which merely unsets the DEFINED flag to mark it as
eligible for texpand garbage collection (even worse, !DEFINED entries
are still counted)
2009-08-28 19:57:43 +00:00
tg ca1f967a45 • use Jenkins’ one-at-a-time hash for mksh keytabs, as it has
much better avalanche and no known funnels
• improve comments
• fix some types (uint32_t for hash, size_t for sizes)
• optimise ktsort()

no functional change, I think
2009-08-28 18:54:01 +00:00
tg 0e1266ef90 While mksh R39 builds fine on MirOS #7s8E on my trusty sparc, pgcc 2.95.3
throws out quite some warnings – fix most of them except most emitted via
-Wconversion; work around some others; discard bogus warnings.

sync clog
2009-08-08 13:08:53 +00:00
tg 758dc5c6fe * improve CPPFLAGS vs #define handling again: do not touch CPPFLAGS from
Build.sh but use 'if defined(PRECOND) && !defined(TOBEDEFINED)'if possible
* for all of the source code, drop annotations "imake style" (if we check
  for specific OSes, bad, instead of using mirtoconf checks proper) and
  "conditions correct?" (if I'm not entirely sure if that #if catches all
  cases and no false positives) where I can see it by grepping immediately
* bump mksh patchlevel
* refresh Makefiles
2009-07-25 21:31:27 +00:00
tg cfe6688a36 in an interesting piece of self humour, remove the stop and suspend
aliases from shells requiring the Arbeitsamt to get a job ;-)
2009-07-25 20:52:41 +00:00
tg bcf4080793 improve MKSH_NOPWNAM handling, whether MKSH_SMALL or not; it will cause
the entire ~fac/ expansion code to be omitted
2009-07-25 20:26:33 +00:00
tg e1d8d7ed01 capitalise AT&T® 2009-06-11 12:42:21 +00:00
tg 0432f97ffe more KNF, mostly whitespace, this time more manual labour applying style(9) 2009-06-10 18:12:51 +00:00
tg 6b2ad96bac some rather mechanical KNF, now that style(9) clarified on the status
of sizeof() as a function-like unary operator; use parenthesēs around
sizeof and return args consistently too
2009-06-08 20:06:50 +00:00
tg 848e237b76 new feature: -DMKSH_ASSUME_UTF8=0 assumes utf-8 is *not* set and skips
environment inspection; useful for initrd and the likes
2009-06-07 22:28:05 +00:00
tg da5dc48cd0 implement an extension that an interactive mode input line, when
starting with an ‘!’ exclamation mark at the beginning of a com-
mand (PS1 not PS2), shall have the same effect as the predefined
“r” alias, to be compatible with csh and GNU bash’s “!string” to
«Execute last used command starting with string» – documentation
and feature request provided by wbx@ (Waldemar Brodkorb)
2009-05-27 19:52:38 +00:00
tg 361dee04f3 laffer1 agreed they will need -DMKSH_MIDNIGHTBSD01ASH_COMPAT in the
short term, but only for /bin/sh – thus recommend to also define
-DMKSH_BINSHREDUCED and make it dependent on FPOSIX
2009-05-16 21:00:52 +00:00
tg b6ce748064 • remove “#if 0” and “#ifdef notdef” style old debugging code
• expose “#ifdef MKSH_MIDNIGHTBSD01ASH_COMPAT” just in case they decide to
  require it and show it in the ksh version automatically
• sync the use of non-ASCII characters over files (unification)
2009-05-16 18:40:09 +00:00
tg b145ca5c9f • sync distrib/special/mksh/Makefile with bin/mksh/Build.sh and
fix the regression test’s results while here, which have been
  broken since cid 10049D9BE5254CE65B8
• get rid of separate copyright file which was intended for De-
  bian; track down commits in all files of oksh-mirbsd and mksh
  to get correct copyright years per-file, as is BSD custom
2009-05-16 16:59:42 +00:00
tg 8cc7fdb834 "evil" workaround to the alignment issues: embed an ALLOC_ITEM into
struct env (other structures defined have no "foreign type with pos-
sible alignment constraints" members) and take care of it while dea-
ling in a struct env instance
2009-04-07 19:43:28 +00:00
tg 398be9867a fix jobless mksh so much to make it work on Minix 3 2009-04-05 12:35:32 +00:00
tg efbdae7892 add (commented out) compatibility to MidnightBSD 0.1 /bin/sh – not
desired, because it defaces standards compliance

cf. https://www.mirbsd.org/permalinks/wlog-10_e20090329-tg-g10024.htm
2009-04-05 11:44:56 +00:00
tg b20f49adae patch from oksh (except manpage, I'll merge that later):
pass "xerrok" status across the execution call stack to more closely
match what both POSIX and [18]ksh.1 already describe in regards to set
-e/errexit's behavior in determining when to exit from nonzero return
values.

specifically, the truth values tested as operands to &&' and ||', as
well as the resulting compound expression itself, along with the truth
value resulting from a negated command (i.e. a pipeline prefixed !'),
should not make the shell exit when -e is in effect.

issue reported by matthieu.
testing matthieu, naddy.
ok miod (earlier version), otto.
man page ok jmc.
2009-03-22 17:47:38 +00:00
tg 0fe20ab25f sync with oksh (nop) 2009-03-22 17:31:17 +00:00
tg 32bc1dc40e sprinkle mksh_ari_t to limit arithmetics to 32 bit even
on Debian Lenny/amd64 (XXX need more verification; this
can be used for 64 bit arithmetics later too)

PPID, PGRP, RANDOM, USER_ID are now unsigned by default
2009-03-14 18:12:55 +00:00
tg 177b1b4cf9 always set COLUMNS and LINES; make use of the fact in dot.mkshrc 2008-12-29 21:34:22 +00:00
tg d6d2f03e5f do not lie 2008-12-29 20:52:10 +00:00
tg 2fb7225499 give tty_init() another argument for silent initialisation 2008-12-29 20:47:16 +00:00
tg 31d1499219 * back out almost all of the memory allocator related changes, as aalloc
was hard to type and hard to fix, galloc is also hard to fix, and some
  things I learned will probably improve things more but make me use the
  original form as base (especially for space savings)
* let sizeofN die though, remove even more casts
* optimise, polish
* regen Makefiles
* sprinkle a few /* CONSTCOND */ while here
2008-12-13 17:02:18 +00:00
tg 042086e49e rename utf8-hack to utf8-mode (use set -U or set +U instead, anyway)
and announce less hackish things
2008-12-04 18:11:08 +00:00
tg c0703f5f26 if MKSH_SMALL and HAVE_ARC4RANDOM, there is no need to use rand()/srand(3)
ever, since MKSH_SMALL is not required to be as close to compatibility as
normal/generic shells; we can also get rid of time(3) calls
2008-11-30 10:33:40 +00:00
tg 546d5d0def give hints to anew() according to aalloc stats output for testsuite and a
little interactive use, to reduce the number realloc(3) must be called
2008-11-15 09:00:19 +00:00
tg 6b9cdbbfd6 globalise internal_verrorf() 2008-11-15 08:42:36 +00:00
tg 32e1ecf5b3 enable passing of a hint how many pointers we’ll need to anew()
if 0, the default is used
2008-11-15 07:35:25 +00:00