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