BGSH: A VxWorks Shell With Command Line Editing

Robert Geer

Updated December 18, 1998


VxWorks is a real-time operating system that is somewhat Unix-like. Since 1989, I have written code for VxWorks to implement various flight simulation devices such as and for communications terminals, routers, & switches.

VxWorks includes a command line shell which requires:

Not being a vi user, I wanted something that worked like the Unix tcsh; hence bgsh, a standalone sort-of emacs-like command line editor with recallable command history.

bgsh:  A VxWorks command line shell similar to Unix tcsh.

The term "bgsh" refers collectively to this list of source & header
files:

Source Files:
	bgsh.c        A wrapper for building standalone shell
	bgshhelp.c    Help text (optional)
	bgshile.c     Input line editor functions
	bgshio.c      Unix to VxWorks command line parser
	find_symbol.c Symbol lookup function
	runscript.c   Script file executor
	token.c       Convert a sentence into tokens.


Header Files:
	find_symbol.h
	[see .c's for VxWorks header files]

Example compile command:
	cc68k -c -fno-builtin -O                          \
	         -DMVME162 -DCPU=MC68040 -DVX_REV=531     \
	         -o bgsh.vxMVME162                        \
	         -I.                                      \
		 -I/software/vx/531.68k/target/h          \
	         -I/software/vx/531.68k/target/config     \
	         -I/software/vx/531/68k/target/config/all \
	         bgsh.c

Example lib command:
	ar68k r libbgsh-MVME162.a     \
	        bgshhelp.vxMVME162    \
	        bgshile.vxMVME162     \
		bgshio.vxMVME162      \
		find_symbol.vxMVME162 \
		runscript.vxMVME162   \
		token.vxMVME162

Example link command:
	ld68k -r -o bgeersh.vxMVME162 \
	        bgsh.vxMVME162        \
		-L. -lbgsh-MVME162


Notes & other drivel:

First, the usual disclaimer stuff: I make no guarantees that bgsh will
do anything useful or not do anything harmful.  I will say that it
works for me & it may also work for you.  If you use or extend or
change bgsh, please let me know - it sure would brighten up my day!

In the spirit of Free Software Foundation's GPL, you may include bgsh
code in any project & it must be supplied free of charge.  I want the
"bgeercredit" text string left intact.  I can use all the credit I can
get.

static char* bgeercredit=
   "Robert Geer: bgeer@xmission.com & http://www.xmission.com/~bgeer" ;

I use the .vxMVME162 suffix for identifying compiled object output for
the MVME162 68040 processor board.  I routinely work with Motorola,
Radstone, Heurikon, National Semiconductor, other boards & other
processors, so I use this method to distinguish between their
respective libraries & linked loadables.  There is no intrinisic
reason preventing the use of .o for the object suffix.

I have not as yet compiled bgsh for other boards, tho every part comes
from code which has run on other processor boards.

The ile code does not depend on termcap.  It does everything the hard
way, by overwriting previously displayed characters.

At one time I created a version of bgshio.c that converted Unix-like
input to VxWorks ledLib input - trying its best to put commas & quotes
where ledLib expects them.  Complexity & arbitrary assumptions, while
not horrible (it is, after all, a straightforward state machine), made
a bigger mess than I wanted to contend with.  So, this version of bgsh
has its own execution function, the latter being much easier for me to
deal with.

The file bgsh.c is merely a wrapper for making bgsh a standalone
loadable.  Normally, I create a utility package for each project that
includes time-of-day clock support, dosFs file date support, nvram
&/or flashrom support, configuration file parsing, & a number of
handee(tm) functions such as cat, more, strings, etc.  The bgsh files
are linked in with all this mess hence I usually have no need for
bgsh.c.


Blatant shortcomings:

Floating point arguments are not supported, tho this support is
trivial to add.  I just haven't needed it yet.

No command or filename completion.

No scripting language logical constructs.  I sure could use them,
tho...

Redirectors (< & >) aren't supported; I haven't made bgsh nor
runscript() re-entrant yet.


Overloaded commands:

Some commands beg to be overloaded for one reason or another.  They
are:

o backspace

This command toggles bgsh's backspace key meanings between BS (0x08) &
DEL (0x7f).  This helps configure "delete left char" for xterm's &
rxvt's as well as serially connected terminals.  I can't seem to get
it to work properly with M$ Win95's telnet & terminal emulators,
however.  It is overloaded since I also include a similar command for
use from the VxWorks shell.

o exit, logout, quit

After screwing around with what these should mean, I decided to
intercept these commands &, when intercepted, tidy up bgsh & exit to
VxWorks shell.  So, from bgsh, 2 commands are necessary to truly exit
or logout of the system.  Treating quit as a synonym is a free added
bonus command.

o ld

This command is overloaded to handle the various forms of the ld
command; i.e., "ld < filename" & the same command without the space in
between the redirector & the filename.  Likely this could have been
accomplished with much more elegant code, but I just don't have the
time.  My preferred use is "ld 0, 0, filename" since it doesn't need a
redirector & is as easy to type.  Life would have been a lot happier
if the original coder of ld made the filename the first arg...so much
for user friendlyness!

o shellPromptSet

This command changes the bgsh shell prompt without changing the
VxWorks shell prompt.

o sp

This command is overloaded to prevent confusion over whether to
include quotes or not around the function name to be spawned.  In
bgsh, no quotes are required - well, none are required in the VxWorks
shell, either, but it can be confusing for newbie's.

The process for creating overloaded commands is easy to extend.  Look
at the function local_command() in bgshio.c.  The localcommands[]
table includes a string identifying the command to be intercepted & a
function to be called when the command is used.


File Manifest:

    size     date    time file
    ----     ----    ---- ----
     112 1998-12-18 09:05 bgsh.list
    6487 1998-12-18 09:38 bgsh.txt
     364 1998-08-31 15:53 bgsh.c
    4455 1998-07-14 15:34 bgshhelp.c
   32334 1998-08-31 15:54 bgshile.c
   21494 1998-12-17 15:07 bgshio.c
    2131 1998-03-09 18:50 find_symbol.c
     497 1998-03-09 18:46 find_symbol.h
   11407 1998-12-17 15:20 runscript.c
    6706 1997-05-20 20:54 token.c
     968 1995-06-13 08:24 token.h       


Created using:

	tar zcvf bgsh.tgz --files-from bgsh.list


Future plans:

I am attempting to port Gnu readline to VxWorks.  The primary problem
is VxWorks' lack of password & permission support.  If/when I succeed,
the readline version should support filename completion & the other
stuff readline does that bgshile.c does not do.  I'm sure, however,
that the readline version will consume significantly greater ram.

Robert Geer
bgeer@xmission.com