How the code comes out, when you’re ready to pass out

# message for commit 041a7343eb452b827dbd97a0c82c8538597f86f6:
#
# read built-in command implemented


sub read_bin {

my ($prmpt, $time);
my $line = "";
my @argv = @_;
my %opts = ( 'p=s' => $prmpt,
't=s' => $time,
'e' => sub { "no-op" },
);

do_getopt(@argv, %opts);
unless (@argv) {
warn "I can't read into thin air!";
return 0;
}

if ($prmpt and -t *STDIN) {
print $prmpt;
}

eval {
# remove custom die for ease of error check/report
local %SIG;
$SIG{__DIE__} = sub { die @_ };
$SIG{ALRM} = sub { die "timed-outn" };
if ($time) {
# an s, m, or h suffix causes sleep for sec, min, or hour
#
if ($time =~ /^(d*)([smh])/) {
if ($2 eq 's') {
$time = $1;
} elsif ($2 eq 'm') {
$time = $1 * 60;
} elsif ($2 eq 'h') {
$time = $1 * 3600;
} else {
warn "internal error on ", __LINE__;
# NOTREACHED
}
}
alarm $time;
}
chomp($line = );
alarm 0 if $time;
};
if ($@) {
warn $@ unless $@ eq "timed-outn";
# on time out, init the vars to empty strings
@ENV{@argv} = ('') x scalar @argv;
return 0;
} else {
# set each var to the words
#
# XXX because ifsplit has no notion of a &split 'LIMIT'
# if we used ifsplit here instead of a manual split,
# read x y
# foo bar ham
# would set $y to 'bar' instead of 'bar ham'
#
my $ifs = defined $ENV{IFS} ? qr/[$ENV{IFS}]/ : qr/s/;
@ENV{@argv} = grep !/^$/, split $ifs, $line, scalar(@argv);
return 1;
}
}

from the manual page updated in commit b1317d7e6e7f91b6c3a2650f44cd4f425e381d42 with message:

read built-in command documented

and blockquoted here using the pod2html output

read [-p prompt] [-t timeout] variable …]

Read a line from standard input, split by fields, and assign each field to the indicated variables. If the number of variables is less then the number of fields, the remaining fields will be stored ‘as is’ in the last variable. If there are more variables then fields, the excess variables will be undefined. A prompt may be printed before reading input, by using the -p option. The -t option may be used to specify a timeout in which to abort the operation, should the user take their sweet time about pressing CR. The timeout value can take an optional s, m, or h suffix to denote seconds, minutes, or hours. If no suffix is given, s will be assumed.

It’s not the greatest… but hey, I ain’t had any sleep since this mornings roll out… lol. It’ll do fine for an initial implementation, until I’ve actually got a functioning brain to deal with it 😛

QOTD

Don’t worry about avoiding temptation — as you grow older, it starts
avoiding you.
— The Old Farmer’s Almanac

I wonder, if I’ll ever live to be that old lol.

The wonders of Raven Shield….

Ok, not so surprising I slice ’round the corner, spot the X-Ray on the top of the stairs -> squeeze off a shot from my M16A2 on 3-round burst. Ok, no effect not even a flinch so 1ce more… 2ce more…. POW he shoots me.

The evil thing?

Trigger pulls -> 3×9 rounds should have been fired
Magazine -> 23/31 rounds remaining (on HUD)
Score board -> 8 rounds fired

the guy should have a least 7 holes in him, 9 if I didn’t hit the rail below the POI by some work of magic… but 8 rounds on the score board, with 0 hits to a slow tango rofl!!!!!

Now if I didn’t have to be awake in ~4 and a half hours, I could get the . / source commands implemented, so handling tpsh_profile / .tpshrc files on startup could be done… and have more of the manual page written out :. Hmm, that reminds me another big thing I need to work on is the shell special variables ($0…$9…, $*, $@, $#, $?) and the rest of ${parameter expansion} syntax.

If I could get anything done during the day here, and actually sleep at night… instead of coding odd hours, now that would just be heavenly lol.

$ git log | sed 's/my name/<snip>/g' | sed 's//<sed@removed.it>/g' | vim -

commit 4835c4091e59af282ee98952568f0e9ac91c8d09
Author: Terry <snip> <sed@removed.it>
Date: Sat Mar 21 09:27:41 2009 +0000

do_getop() made generic, `set [options]` now works.

The do_getopt() function now takes an array ref and hash to pass onto
Getopt::Long::GetOptionsFromArray, and twists it in place.

set_bin() now calls do_getopt() with it’s argument vector and a global
hash; startup code now calls do_getopt() with @ARGV and that same hash.
Because of that, `set -x`, `set -o xtrace`, and such work but `set +o
xtrace` and such can’t be used to turn the option off yet lol. (+o atm
is just an alias for -o.)

commit 90bf68e8b5f0aed867ae4a9fd2eca2c8d99dc1fd
Author: Terry <snip> <sed@removed.it>
Date: Sat Mar 21 08:16:39 2009 +0000

tpsh -o longname now works

further more as an extension, ‘-o logname1,longname2’ also works but is
not documented yet.

commit dcffa41bb57d70c82f502b08ea8c76ebeb559b1c
Author: Terry <snip> <sed@removed.it>
Date: Sat Mar 21 07:49:28 2009 +0000

which built-in command added and documents

see Built-in Commands and CEVEATS & BUGS in tpsh.1.pod for details.

It is really time to make do_getopt() a generic wrapper around
Getopt::Long, the current functionality in do_getopt() needs to be moved
into set_bin() anyway…

Thanks Wiz… lol

After a few other commits, I’ve finally buckled down and made do_getopt() a simple helper, previously it did parsing for @ARGV via the Getopt::Long module, and twiddle %Options accordingly; now it takes an array ref and a hash to do the job. The wonderful thing? Now both tpsh [options] and the built in `set [options]` command work with half a line of duplicated code 🙂

In prepping my code for commit, I wanted to take one last look at do_getopt(), so I went for a quick jump over with the vi/vim :tag command. Wiz IM’d me, so he ended up getting the :ta command instead of vim haha! After alt+tabbing back to the editor, I tried something different just for the heck of it, :ta do_ and guess what!? Vims ex mode completion works on tags as well…. this is so going to spoil me lol. ex/vi lacked command completion, history, and editing; but vim added them. One of these days, I need a refresher on the improved tag commands, my muscle memory is pretty vi compatible until we get into tab completion, :split windows, and multiple tabs lol.

So thanks to Wiz, I’ve just found a lovely Vi IMproved feature that I never dreamed existed xD

more recent tpsh commits

commit 6f94f751ac76177a23138a1ad014b4af1af50de7
Author: Terry <snip> <sed@removed.it>
Date: Fri Mar 20 18:29:43 2009 +0000

%Aliases renamed %Macros

because it stores all named macros, whether defined with function, macro, or alias

commit 2a83cbc45daf78cb41cba40c28735252e521f965
Author: Terry <snip> <sed@removed.it>
Date: Fri Mar 20 18:24:55 2009 +0000

is_macro() and is_builtin() subroutines added

commit 1853b61eff14d35ddf1f89282ed26a8f3957d373
Author: Terry <snip> <sed@removed.it>
Date: Fri Mar 20 08:43:50 2009 +0000

type built-in documented

documented the type built-in command, and tweaked type_bin; it now
prints macro instead of alias, and will stop at the first match found.

commit 39a9824ca29d7beea6c5a054f970b86968861568
Author: Terry <snip> <sed@removed.it>
Date: Fri Mar 20 08:30:12 2009 +0000

pwd built-in added and documented

commit 488aa51ed2c430848aa80fb26ad093ccec604237
Author: Terry <snip> <sed@removed.it>
Date: Fri Mar 20 08:08:04 2009 +0000

function and macro built-in commands documented

commit 273b7f8bbbf0b3db8759053969e854f1de963003
Author: Terry <snip> <sed@removed.it>
Date: Fri Mar 20 08:02:41 2009 +0000

pipes and I/O redirection can be used inside a named macro definition created with the macro built-in

commit 7aa70dd6873e147f3bfdec7460312dc54482696b
Author: Terry <snip> <sed@removed.it>
Date: Fri Mar 20 07:53:06 2009 +0000

macro_bin now reports `macro name()` as an error, correctly

commit e52aed3dec5455c6488dc4465aa75d20aca4e696
Author: Terry <snip> <sed@removed.it>
Date: Fri Mar 20 07:22:39 2009 +0000

hash built-in documented

commit 843a0de91b3c2df2b1fed8b9416426bc0e7c01af
Author: Terry <snip> <sed@removed.it>
Date: Fri Mar 20 07:21:22 2009 +0000

hash built-in now has an -r option that nukes the %Path hash table

commit 27526bb013cc1ab7b425ee1f3b685585746a0160
Author: Terry <snip> <sed@removed.it>
Date: Fri Mar 20 07:17:36 2009 +0000

hash_bin now displays an error if the item to be deleted does not exist

commit 45c71f7c54faa81106de5e68290884150823e10c
Author: Terry <snip> <sed@removed.it>
Date: Fri Mar 20 07:12:50 2009 +0000

hash_bin can now remove elements from %Path

When the only damn time I can get any sleep… is when I’m ready to pass out, why can’t anyone let me sleep? Some days it feels like a game: keep spidey01 awake. *sigh*, and to be waken up early tomorrow…. really, why do I even try to sleep anymore?

Home at last for the rest of the day; got off work early enough for a quick sandwich and some kartoffelchips before taking Willow for her checkup.

13.04 lbs (~5.915kg) and strong as an ox, gained 1lb since last year lol. It’s funny though, she’s like a little bully at home but as soon as we get within earshot of the vets office…. petrified chihuahua! I’m standing in the examination room with Willow on my one arm, and her and my mom are nervous wrecks; ma asked me how I could be so calm, my reply? It would take something like a zombie invasion to worry me lol.

Pardoning grocery shopping (dang), I’m off until Tuesday; maybe I might actually get some sleep for a change.

Want a dirty look? Try telling a dog she’s fat >_<.

Oh for korn sake….

Willow saw the mouse cursor move, and tried to lick the screen! I gave her a hug, “Willow, I love you but you’re a silly girl” lol.

May as well hit the hay, before the dog tries anything else with the laptop… lol. Tomorrows gonna be a wreck anyway, need to take the dog to the Victor Echo Tango for a checkup after work, that will be a bark-fest once we arrive, haha!

a few notes from the last time I got to code

now if only I had time to do things tonight… really what I need to get done, is move much of what’s left in main_loop() further into a subroutine, so I can implement source_bin() for the . / source built-ins and set it up to handle .tpsh_profile/.tpshrc files on startup through init_sh.

a few other serious things that need doing: hook our completion function into Term::ReadLine::Perl (I’m using Term::ReadLine::Zoid on my workstation; which is very easy to hook up to an app specific completion function); finish coding the completion hooks; implement `tpsh -c “cmds”`, in fact `(cmds)` could probably be expanded to that for sub-shell grouping, lol; write eval_bin(), the code needed for an eval built-in command is there, just needs the sub to bind it together; make `backquotes/backticks` needs to be handled by a pipe opened sub shell, rather then running the command directly with a pipe; and also support for an arbitrary number of pipes in commands, the place holder code in exec_pipe() only allows ‘lhs | rhs’; adding ${} expansion to variable expansion, $TMPDIR works but ${TMPDIR:-/tmp} and things don’t yet, but that’s trivial to code.

Really the only thing that worries me, is how to implement job control :. Setting up the built-in test command, [ which is gonna be interesting of course but actually doable, like control flow: fun but simple. The job control though, I’ve no freaking idea how to implement in pure Perl under unix/win32, yet…

# last stream of commits; html fixed

$ git log d59b9f864e916cd914be55b223702ec618c1ec4f..HEAD | sed 's/.../<snip>/g' | sed 's/.../sed@removed.it/g' | vim - 

commit 9450eca02b4dffcce6802b8fd72ba4e307ff7b9b
Author: Terry <snip> <sed@removed.it>
Date: Thu Mar 19 10:12:25 2009 +0000

exec and exit commands documented

Also CAVEATS & BUGS section updated about argumentless cd/chdir behaviour.

commit c24135e3748b9dbe8520b5794311af92e3affb36
Author: Terry <snip> <sed@removed.it>
Date: Thu Mar 19 10:06:20 2009 +0000

tpsh now exits with $? >> 8 if no exit status was given to the exit built-in

commit a9138f5991142960114f6898e7d57185eff00256
Author: Terry <snip> <sed@removed.it>
Date: Thu Mar 19 09:59:59 2009 +0000

cd and chdir commands documented

commit 3145e1a5672330fc913e93b3992b7c6591ff58a8
Author: Terry <snip> <sed@removed.it>
Date: Thu Mar 19 09:53:58 2009 +0000

CDPATH handling skipped if path starts with / or .

commit e6f8690d05308789a31fb906a28b1dbeba304ec4
Author: Terry <snip> <sed@removed.it>
Date: Thu Mar 19 09:20:22 2009 +0000

builtin command documented

commit b789721176eeb7d157d7c42e38044b1c111fa3dc
Author: Terry <snip> <sed@removed.it>
Date: Thu Mar 19 09:16:44 2009 +0000

bugfix: alias expansion turned off for builtin command

noticed that after `alias echo foo`, that `builtin echo …` would
expand to ‘builtin foo …’

commit a6a7eeddb5309af903569aee31bb5f15ceef9d6e
Author: Terry <snip> <sed@removed.it>
Date: Thu Mar 19 08:46:20 2009 +0000

alias name now displays ‘name’ => ‘definition’

Also alias expansion is now disabled on the alias command as well as
unalias. This prevents expanding the lhs (name) of an alias when name is
given, but definition is not (e.g. `alias name`)

commit 99a57b1b88d58f4ad6b318c181668cf5f5e9eeda
Author: Terry <snip> <sed@removed.it>
Date: Thu Mar 19 08:21:19 2009 +0000

bugfix: rhs of alias definition is no longer sh_eval()’d by alias_bin

alias_bin has ran sh_eval() before storing the macro since commit
2da5a0e38e3d14c29b0fb93ad89797826a41ddac, which was causing expansion of
things like `alias lah=’ls -a $HOME’ to be stored as ‘lah’ => ‘ls -a
/home/Terry’ instead of ‘ls -a $HOME’; as the quotes were pre-expanded
on the command line, alias would receive and expand the environment
variable itself.

commit a9177482c3398a6272382672e45ea9d5e8254960
Author: Terry <snip> <sed@removed.it>
Date: Thu Mar 19 08:11:23 2009 +0000

alias built-in documented

commit 8296bb37be75e1e7c301c1ed316db13aa6c9c26d
Author: Terry <snip> <sed@removed.it>
Date: Thu Mar 19 07:34:16 2009 +0000

bugfix: SIGPIPE now handled by exec_pipe()

Previously a construct like `ls | head 1` would cause tpsh to terminate,
due to receiving an unhandled SIGPIPE on unix. tpsh now traps the signal
and will report an error if desired.

Display of the error message can be turned with the ‘reportpipe’ option,
which defaults to off.

commit b44b8f3b4cf6adedf972bf719f4de1546fc8a8b1
Author: Terry <snip> <sed@removed.it>
Date: Tue Mar 17 23:44:38 2009 +0000

noclobber mode is now implemented

commit 842d3a308e2663c15dc75600c19eb7f096664341
Author: Terry <snip> <sed@removed.it>
Date: Tue Mar 17 23:21:58 2009 +0000

+flag is allowed, i.e. +a

commit 289837932bf4af21c41c538e32e2d886d6f9a03b
Author: Terry <snip> <sed@removed.it>
Date: Tue Mar 17 09:26:30 2009 +0000

added set built in command and command line arguments to the manual

commit e1badaaf1e873ae0808eecb79b1b3a07219752f5
Author: Terry <snip> <sed@removed.it>
Date: Tue Mar 17 08:18:07 2009 +0000

the verbose option now works

xtrace now also prints to stderr, IAW with ash