DESIGN revision 3f54fd611f536639ec30dd53c48e5ec1897cc7d9
f3ad877eb05befbc862b0233d985758c0caef29aEvan HuntHere is an overview of the source code organization for ksh93.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt
f3ad877eb05befbc862b0233d985758c0caef29aEvan HuntDirectory layout:
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt The directory include contains header files for ksh93.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt The files nval.h and shell.h are intended to be public
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt headers and can be used to add runtime builtin command.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt The remainder are private.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt The directory data contains readonly data files for ksh93.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt The man pages for built-ins are in builtins.c rather
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt than included as statics with the implementations in the
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt bltins directory because some systems don't make static const
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt data readonly and we want these to be shared by all running
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt shells.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt The directory edit contains the code for command line
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt editing and history.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt The fun directory contains some shell function such as
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt pushd, popd, and dirs.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt The directory features contains files that are used to generate
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt header files in the FEATURE directory. Most of these files
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt are in a format that is processed by iffe.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt The directory bltins contains code for most of the built-in
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt commands. Additional built-in commands are part of libcmd.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt The directory sh contains most of the code for ksh93.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt The directory tests contains a number of regression tests.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt In most cases, when a bug gets fixed, a test is added to
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt one of these files. The regression tests can be run by
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt going to this directory and running
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt SHELL=shell_path shell_path shtests
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt where shell_path is an absolute pathname for the shell to
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt be tested.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt The top level directory contains the nmake Makefile, the
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt RELEASE file, the ksh93 man file (sh.1) and nval.3 and shell.3
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt documentation files. The RELEASE file contains the list of bug
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt fixes and new features since the original ksh93 release. The file
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt COMPATIBILITY is a list of all known incompatibilities with ksh88.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt The data/bash_pre_rc.sh is a startup script used when emulating
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt bash if the shell is compiled with SHOPT_BASH and the shell
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt is invoked as bash. The bash emulation is not complete.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt
f3ad877eb05befbc862b0233d985758c0caef29aEvan HuntInclude directory:
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt 1. argnod.h contains the type definitions for command
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt nodes, io nodes, argument nodes, and for positional
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt parameters.a It defines the prototypes for
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt all the positional parameters functions.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt 2. builtins.h contains prototypes for builtins as well
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt as symbolic constants that refer to the name-pairs
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt that are associated with some of the built-ins.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt It also contains prototypes for many of the strings.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt 3. defs.h is the catch all for all definitions that
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt don't fit elsewhere and it includes several other
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt headers. It defines a structure that contains ksh
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt global data, sh, and a structure that contains per
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt function data, sh.st.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt 4. edit.h contains definitions that are common to both
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt vi and emacs edit modes.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt 5. env.h contains an alternative interfaces for creating and
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt modifying environment variables.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt 6. fault.h contains prototypes for signal related
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt functions and trap and fault handling.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt 7. fcin.h contains macro and function definitions for
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt reading from a file or string.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt 8. history.h contains macros and functions definitions
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt related to history file processing.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt 9. jobs.h contains the definitions relating to job
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt processing and control.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt 10. lexstates.h contains the states associated with
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt lexical processing.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt 11. name.h contains the internal definitions related
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt to name-value pair processing.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt 12. national.h contains a few I18N definitions, mostly
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt obsolete.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt 13. nval.h is the public interface to the name-value
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt pair library that is documented with nval.3.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt 14. path.h contains the interface for pathname processing
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt and pathname searching.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt 15. shell.h is the public interface for shell functions
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt that are documented int shell.3.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt 16. shlex.h contains the lexical token definitions and
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt interfaces for lexical analysis.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt 17. shnodes.h contains the definition of the structures
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt for each of the parse nodes and flags for the attributes.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt 18. shtable.h contains some interfaces and functions for
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt table lookup.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt 19. streval.h contains the interface to the arithmetic
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt functions.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt 20. terminal.h is a header file that includes the appropriate
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt terminal include.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt 21. test.h contains the definitions for the test and [[...]]
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt commands.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt 22. timeout.h contains the define constant for the maximum
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt shell timeout.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt 23. ulimit.h includes the appropriate resource header.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt 24. variables.h contains symbolic constants for the built-in
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt shell variables.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt 25. version.h contains the version string for this release.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt
f3ad877eb05befbc862b0233d985758c0caef29aEvan Huntsh directory:
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt 1. args.c contains functions for parsing shell options
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt and for processing positional parameters.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt 2. arith.c contains callback functions for the streval.c
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt library and the interface to shell arithmetic.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt 3. array.c contains the code for indexed and associative
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt arrays.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt 4. bash.c contains code used when compiling with SHOPT_BASH
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt to add bash specific features such as shopt.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt 5. defs.c contains the data definitions for global symbols.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt 6. deparse.c contains code to generate shell script from
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt a parse tree.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt 7. env.c contains code to add and delete environment variables
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt to an environment list.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt 8. expand.c contains code for file name expansion and
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt file name generation.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt 9. fault.c contains code for signal processing, trap
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt handling and termination.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt 10. fcin.c contains code for reading and writing a character
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt at a time from a file or string.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt 11. init.c contains initialization code and callbacks
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt for get and set functions for built-in variables.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt 12. io.o contains code for redirections and managing file
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt descriptors and file streams.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt 13. jobs.c contains the code for job management.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt 14. lex.c contains the code for the lexical analyzer.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt 15. macro.c contains code for the $ macro expansions, including
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt here-documents.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt 16. main.c contains the calls to initialization, profile
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt processing and the main evaluation loop as well as
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt mail processing.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt 17. name.c contains the name-value pair routines that are
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt built on the hash library in libast.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt 18. nvdisc.c contains code related to name-value pair disciplines.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt 19. nvtree.c contains code for compound variables and for
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt walking the namespace.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt 20. nvtype.c contains most of the code related to types that
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt are created with typeset -T.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt 21. parse.c contains the code for the shell parser.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt 22. path.c contains the code for pathname lookup and
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt some path functions. It also contains the code
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt that executes commands and scripts.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt 23. pmain.c is just a calls sh_main() so that all of the
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt rest of the shell can be in a shared library.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt 24. shcomp.c contains the main program to the shell
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt compiler. This program parses a script and creates
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt a file that the shell can read containing the parse tree.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt 25. streval.c is an C arithmetic evaluator.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt 26. string.c contains some string related functions.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt 27. subshell.c contains the code to save and restore
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt environments so that subshells can run without creating
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt a new process.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt 28. suid_exec.c contains the program from running execute
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt only and/or setuid/setgid scripts.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt 29. tdump.c contains the code to dump a parse tree into
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt a file.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt 30. timers.c contains code for multiple event timeouts.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt 31. trestore contains the code for restoring the parse
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt tree from the file created by tdump.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt 32. userinit.c contains a dummy userinit() function.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt This is now obsolete with the new version of sh_main().
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt 33. waitevent.c contains the sh_waitnotify function so
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt that builtins can handle processing events when the
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt shell is waiting for input or for process completion.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt 34. xec.c is the main shell execution loop.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Huntedit directory:
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt 1. completion.c contains code for command and file generation and
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt completion.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt 2. edit.c contains common editing and terminal code for vi and
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt emacs.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt 3. emacs.c contains code for the emacs editor.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt 4. hexpand.c contains code for C-shell style history expansions.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt 5. history.c contains code for creating managing the history file.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt 6. vi.c contains the code for the vi editor.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt