direct-io.hg

changeset 1624:236a9f2698a3

bitkeeper revision 1.1029 (40e1c6ce1NufVIrsLOg06kNbotFFZA)

Merge ssh://xenbk@gandalf.hpl.hp.com//var/bk/xeno-unstable.bk
into scramble.cl.cam.ac.uk:/local/scratch/kaf24/hp.bk
author kaf24@scramble.cl.cam.ac.uk
date Tue Jun 29 19:45:18 2004 +0000 (2004-06-29)
parents 498a8eca0ab9 7a572a6fa64d
children 489b925b0e22
files .rootkeys BitKeeper/etc/ignore tools/Make.defs tools/Makefile tools/examples/Makefile tools/examples/vifctl tools/examples/xm_dom_create.py tools/examples/xmdefaults tools/lib/allocate.c tools/lib/allocate.h tools/lib/debug.h tools/lib/enum.c tools/lib/enum.h tools/lib/file_stream.c tools/lib/file_stream.h tools/lib/gzip_stream.c tools/lib/gzip_stream.h tools/lib/hash_table.c tools/lib/hash_table.h tools/lib/iostream.c tools/lib/iostream.h tools/lib/kernel_stream.c tools/lib/kernel_stream.h tools/lib/lexis.c tools/lib/lexis.h tools/lib/lzi_stream.c tools/lib/lzi_stream.h tools/lib/lzo_stream.c tools/lib/lzo_stream.h tools/lib/marshal.c tools/lib/marshal.h tools/lib/socket_stream.c tools/lib/socket_stream.h tools/lib/string_stream.c tools/lib/string_stream.h tools/lib/sxpr.c tools/lib/sxpr.h tools/lib/sxpr_parser.c tools/lib/sxpr_parser.h tools/lib/sys_ctype.h tools/lib/sys_net.c tools/lib/sys_net.h tools/lib/sys_string.c tools/lib/sys_string.h tools/lib/xdr.c tools/lib/xdr.h tools/libxc/Makefile tools/libxc/rpm.spec tools/libxc/xc.h tools/libxc/xc_atropos.c tools/libxc/xc_bvtsched.c tools/libxc/xc_domain.c tools/libxc/xc_elf.h tools/libxc/xc_evtchn.c tools/libxc/xc_io.c tools/libxc/xc_io.h tools/libxc/xc_linux_build.c tools/libxc/xc_linux_restore.c tools/libxc/xc_linux_save.c tools/libxc/xc_misc.c tools/libxc/xc_netbsd_build.c tools/libxc/xc_physdev.c tools/libxc/xc_private.c tools/libxc/xc_private.h tools/libxc/xc_rrobin.c tools/libxutil/Makefile tools/libxutil/allocate.c tools/libxutil/allocate.h tools/libxutil/debug.h tools/libxutil/enum.c tools/libxutil/enum.h tools/libxutil/file_stream.c tools/libxutil/file_stream.h tools/libxutil/gzip_stream.c tools/libxutil/gzip_stream.h tools/libxutil/hash_table.c tools/libxutil/hash_table.h tools/libxutil/iostream.c tools/libxutil/iostream.h tools/libxutil/kernel_stream.c tools/libxutil/kernel_stream.h tools/libxutil/lexis.c tools/libxutil/lexis.h tools/libxutil/lzi_stream.c tools/libxutil/lzi_stream.h tools/libxutil/lzo_stream.c tools/libxutil/lzo_stream.h tools/libxutil/marshal.c tools/libxutil/marshal.h tools/libxutil/socket_stream.c tools/libxutil/socket_stream.h tools/libxutil/string_stream.c tools/libxutil/string_stream.h tools/libxutil/sxpr.c tools/libxutil/sxpr.h tools/libxutil/sxpr_parser.c tools/libxutil/sxpr_parser.h tools/libxutil/sys_ctype.h tools/libxutil/sys_net.c tools/libxutil/sys_net.h tools/libxutil/sys_string.c tools/libxutil/sys_string.h tools/libxutil/xdr.c tools/libxutil/xdr.h tools/misc/Makefile tools/misc/netfix tools/misc/xend tools/misc/xm tools/python/Makefile tools/python/setup.py tools/python/xen/__init__.py tools/python/xen/ext/__init__.py tools/python/xen/ext/xc/Makefile tools/python/xen/ext/xc/setup.py tools/python/xen/ext/xc/xc.c tools/python/xen/ext/xu/__init__.py tools/python/xen/ext/xu/domain_controller.h tools/python/xen/ext/xu/xu.c tools/python/xen/util/Brctl.py tools/python/xen/util/__init__.py tools/python/xen/util/console_client.py tools/python/xen/util/ip.py tools/python/xen/util/tempfile.py tools/python/xen/xend/Args.py tools/python/xen/xend/EventServer.py tools/python/xen/xend/EventTypes.py tools/python/xen/xend/PrettyPrint.py tools/python/xen/xend/Vifctl.py tools/python/xen/xend/XendClient.py tools/python/xen/xend/XendConsole.py tools/python/xen/xend/XendDB.py tools/python/xen/xend/XendDomain.py tools/python/xen/xend/XendDomainConfig.py tools/python/xen/xend/XendDomainInfo.py tools/python/xen/xend/XendMigrate.py tools/python/xen/xend/XendNode.py tools/python/xen/xend/XendRoot.py tools/python/xen/xend/XendVnet.py tools/python/xen/xend/__init__.py tools/python/xen/xend/encode.py tools/python/xen/xend/server/SrvBase.py tools/python/xen/xend/server/SrvConsole.py tools/python/xen/xend/server/SrvConsoleDir.py tools/python/xen/xend/server/SrvDaemon.py tools/python/xen/xend/server/SrvDeviceDir.py tools/python/xen/xend/server/SrvDir.py tools/python/xen/xend/server/SrvDomain.py tools/python/xen/xend/server/SrvDomainDir.py tools/python/xen/xend/server/SrvEventDir.py tools/python/xen/xend/server/SrvNode.py tools/python/xen/xend/server/SrvRoot.py tools/python/xen/xend/server/SrvServer.py tools/python/xen/xend/server/SrvVnetDir.py tools/python/xen/xend/server/__init__.py tools/python/xen/xend/server/blkif.py tools/python/xen/xend/server/channel.py tools/python/xen/xend/server/console.py tools/python/xen/xend/server/controller.py tools/python/xen/xend/server/cstruct.py tools/python/xen/xend/server/domain.py tools/python/xen/xend/server/messages.py tools/python/xen/xend/server/netif.py tools/python/xen/xend/server/params.py tools/python/xen/xend/sxp.py tools/python/xen/xm/__init__.py tools/python/xen/xm/create.py tools/python/xen/xm/main.py tools/python/xen/xm/opts.py tools/python/xen/xm/shutdown.py tools/xc/Makefile tools/xc/lib/Makefile tools/xc/lib/rpm.spec tools/xc/lib/xc.h tools/xc/lib/xc_atropos.c tools/xc/lib/xc_bvtsched.c tools/xc/lib/xc_domain.c tools/xc/lib/xc_elf.h tools/xc/lib/xc_evtchn.c tools/xc/lib/xc_io.c tools/xc/lib/xc_io.h tools/xc/lib/xc_linux_build.c tools/xc/lib/xc_linux_restore.c tools/xc/lib/xc_linux_save.c tools/xc/lib/xc_misc.c tools/xc/lib/xc_netbsd_build.c tools/xc/lib/xc_physdev.c tools/xc/lib/xc_private.c tools/xc/lib/xc_private.h tools/xc/lib/xc_rrobin.c tools/xc/py/Makefile tools/xc/py/Xc.c tools/xc/py/setup.py tools/xen/Makefile tools/xen/lib/__init__.py tools/xen/lib/ext/__init__.py tools/xen/lib/util/__init__.py tools/xen/lib/util/console_client.py tools/xen/lib/util/ip.py tools/xen/lib/util/tempfile.py tools/xen/lib/xend/Args.py tools/xen/lib/xend/EventServer.py tools/xen/lib/xend/EventTypes.py tools/xen/lib/xend/PrettyPrint.py tools/xen/lib/xend/XendBridge.py tools/xen/lib/xend/XendClient.py tools/xen/lib/xend/XendConsole.py tools/xen/lib/xend/XendDB.py tools/xen/lib/xend/XendDomain.py tools/xen/lib/xend/XendDomainConfig.py tools/xen/lib/xend/XendDomainInfo.py tools/xen/lib/xend/XendMigrate.py tools/xen/lib/xend/XendNode.py tools/xen/lib/xend/XendRoot.py tools/xen/lib/xend/XendVnet.py tools/xen/lib/xend/__init__.py tools/xen/lib/xend/encode.py tools/xen/lib/xend/server/SrvBase.py tools/xen/lib/xend/server/SrvConsole.py tools/xen/lib/xend/server/SrvConsoleDir.py tools/xen/lib/xend/server/SrvDaemon.py tools/xen/lib/xend/server/SrvDeviceDir.py tools/xen/lib/xend/server/SrvDir.py tools/xen/lib/xend/server/SrvDomain.py tools/xen/lib/xend/server/SrvDomainDir.py tools/xen/lib/xend/server/SrvEventDir.py tools/xen/lib/xend/server/SrvNode.py tools/xen/lib/xend/server/SrvRoot.py tools/xen/lib/xend/server/SrvServer.py tools/xen/lib/xend/server/SrvVnetDir.py tools/xen/lib/xend/server/__init__.py tools/xen/lib/xend/server/blkif.py tools/xen/lib/xend/server/channel.py tools/xen/lib/xend/server/console.py tools/xen/lib/xend/server/controller.py tools/xen/lib/xend/server/cstruct.py tools/xen/lib/xend/server/domain.py tools/xen/lib/xend/server/messages.py tools/xen/lib/xend/server/netif.py tools/xen/lib/xend/server/params.py tools/xen/lib/xend/sxp.py tools/xen/lib/xm/__init__.py tools/xen/lib/xm/create.py tools/xen/lib/xm/main.py tools/xen/lib/xm/opts.py tools/xen/lib/xm/shutdown.py tools/xen/setup.py tools/xen/xend tools/xen/xm tools/xentrace/Makefile tools/xentrace/xentrace.c tools/xu/Makefile tools/xu/lib/__init__.py tools/xu/lib/domain_controller.h tools/xu/lib/xu.c tools/xu/setup.py
line diff
     1.1 --- a/.rootkeys	Tue Jun 29 14:14:38 2004 +0000
     1.2 +++ b/.rootkeys	Tue Jun 29 19:45:18 2004 +0000
     1.3 @@ -151,6 +151,7 @@ 3f108af5VxPkLv13tXpXgoRKALQtXQ linux-2.4
     1.4  3e5a4e681xMPdF9xCMwpyfuYMySU5g linux-2.4.26-xen-sparse/mm/mremap.c
     1.5  409ba2e7akOFqQUg6Qyg2s28xcXiMg linux-2.4.26-xen-sparse/mm/page_alloc.c
     1.6  3e5a4e683HKVU-sxtagrDasRB8eBVw linux-2.4.26-xen-sparse/mm/swapfile.c
     1.7 +40e1b09db5mN69Ijj0X_Eol-S7dXiw tools/Make.defs
     1.8  3f776bd1Hy9rn69ntXBhPReUFw9IEA tools/Makefile
     1.9  401d7e160vaxMBAUSLSicuZ7AQjJ3w tools/examples/Makefile
    1.10  401d7e16UgeqroJQTIhwkrDVkoWgZQ tools/examples/README
    1.11 @@ -159,49 +160,69 @@ 401d7e16NoWaBGC1RXbBcqAOr5Uaag tools/exa
    1.12  405ff55dawQyCHFEnJ067ChPRoXBBA tools/examples/init.d/xend
    1.13  40278d94cIUWl2eRgnwZtr4hTyWT1Q tools/examples/init.d/xendomains
    1.14  40278d91ZjLhxdjjrGe8HEdwHLj5xQ tools/examples/netbsd
    1.15 +40e15b7edWEtBf_oe3eBwGKuh1dyzQ tools/examples/vifctl
    1.16  401d7e16NpnVrFSsR7lKKKfTwCYvWA tools/examples/xc_dom_control.py
    1.17  401d7e16RJj-lbtsVEjua6HYAIiKiA tools/examples/xc_dom_create.py
    1.18 -40c9c468pXANclL7slGaoD0kSrIwoQ tools/examples/xm_dom_create.py
    1.19  40cf2937oKlROYOJTN8GWwWM5AmjBg tools/examples/xmdefaults
    1.20  40dfd40auJwNnb8NoiSnRkvZaaXkUg tools/examples/xmnetbsd
    1.21 -40e033325Sjqs-_4TuzeUEprP_gYFg tools/lib/allocate.c
    1.22 -40e03332KYz7o1bn2MG_KPbBlyoIMA tools/lib/allocate.h
    1.23 -40e03332IyRttYoXKoJla5qCC514SQ tools/lib/debug.h
    1.24 -40e03332qV5tJ-GJZjo-LBCeGuEjJA tools/lib/enum.c
    1.25 -40e03332wwMVxfobgA1PSMTSAGLiCw tools/lib/enum.h
    1.26 -40e03332p5Dc_owJQRuN72ymJZddFQ tools/lib/file_stream.c
    1.27 -40e03332jWfB2viAhLSkq1WK0r_iDQ tools/lib/file_stream.h
    1.28 -40e03332rUjNMGg11n2rN6V4DCrvOg tools/lib/gzip_stream.c
    1.29 -40e033321O5Qg22haLoq5lpmk4tooQ tools/lib/gzip_stream.h
    1.30 -40e03332QrTR96tc6yS2rMBpd2mq1A tools/lib/hash_table.c
    1.31 -40e033325KoIb0d_uy8s7b5DUR9fPQ tools/lib/hash_table.h
    1.32 -40e03332ihnBGzHykVwZnFmkAppb4g tools/lib/iostream.c
    1.33 -40e03332UGwbLR4wsw4ft14p0Yw5pg tools/lib/iostream.h
    1.34 -40e0333245DLDzJemeSVBLuutHtzEQ tools/lib/kernel_stream.c
    1.35 -40e03332aK0GkgpDdc-PVTkWKTeOBg tools/lib/kernel_stream.h
    1.36 -40e03332HJ0cDcZDKDUUT-tEiBWOZw tools/lib/lexis.c
    1.37 -40e03332tnH9Ggzxbfi3xY9Vh2hUlg tools/lib/lexis.h
    1.38 -40e03332aYIW0BNBh6wXuKKn_P7Yyg tools/lib/lzi_stream.c
    1.39 -40e0333233voTffE4cJSMGJARfiSSQ tools/lib/lzi_stream.h
    1.40 -40e03332FXuMoUnfsAKSgV8X4rFbYQ tools/lib/lzo_stream.c
    1.41 -40e03332InJaiLfpDcIXBy2fI0RFGQ tools/lib/lzo_stream.h
    1.42 -40e03332a5SCuRsejHStTuWzMQNv8Q tools/lib/marshal.c
    1.43 -40e03332TwKyJrZQiiQfNq4vc2hpgw tools/lib/marshal.h
    1.44 -40e033328ccHlJuTR1FswYL_EC6LFA tools/lib/socket_stream.c
    1.45 -40e03332P0KVQGkmahj47aafo1X0nA tools/lib/socket_stream.h
    1.46 -40e03332KT_tnnoAMbPVAZBB7kSOAQ tools/lib/string_stream.c
    1.47 -40e03332-VtK6_OZa1vMHXFil8uq6w tools/lib/string_stream.h
    1.48 -40e03332dDtczi6YX7_mMxhYjJeAdQ tools/lib/sxpr.c
    1.49 -40e03332QPuyNKDOTIYVvkwK5qO-vg tools/lib/sxpr.h
    1.50 -40e03332Pi0_osJ3XPBi38ADPqdl4A tools/lib/sxpr_parser.c
    1.51 -40e033324v5QFMvWEXXzv38uUT9kHg tools/lib/sxpr_parser.h
    1.52 -40e03332gKUInsqtxQOV4mPiMqf_dg tools/lib/sys_ctype.h
    1.53 -40e03332Rkvq6nn_UNjzAAK_Tk9v1g tools/lib/sys_net.c
    1.54 -40e03332lQHvQHw4Rh7VsT1_sui29A tools/lib/sys_net.h
    1.55 -40e033321smklZd7bDSdWvQCeIshtg tools/lib/sys_string.c
    1.56 -40e03332h5V611rRWURRLqb1Ekatxg tools/lib/sys_string.h
    1.57 -40e03332u4q5kgF0N7RfqB4s0pZVew tools/lib/xdr.c
    1.58 -40e03332hY16nfRXF4gGd5S1aUJUBw tools/lib/xdr.h
    1.59 +3fbba6dbDfYvJSsw9500b4SZyUhxjQ tools/libxc/Makefile
    1.60 +3fbba6dc1uU7U3IFeF6A-XEOYF2MkQ tools/libxc/rpm.spec
    1.61 +3fbba6dcrNxtygEcgJYAJJ1gCQqfsA tools/libxc/xc.h
    1.62 +40589968oCfoUlXd460CjVAkBE8IBA tools/libxc/xc_atropos.c
    1.63 +3fbba6dbEVkVMX0JuDFzap9jeaucGA tools/libxc/xc_bvtsched.c
    1.64 +3fbba6dbasJQV-MVElDC0DGSHMiL5w tools/libxc/xc_domain.c
    1.65 +40278d99BLsfUv3qxv0I8C1sClZ0ow tools/libxc/xc_elf.h
    1.66 +403e0977Bjsm_e82pwvl9VvaJxh8Gg tools/libxc/xc_evtchn.c
    1.67 +40e03333Eegw8czSWvHsbKxrRZJjRA tools/libxc/xc_io.c
    1.68 +40e03333vrWGbLAhyJjXlqCHaJt7eA tools/libxc/xc_io.h
    1.69 +3fbba6dbNCU7U6nsMYiXzKkp3ztaJg tools/libxc/xc_linux_build.c
    1.70 +3fbba6dbl267zZOAVHYLOdLCdhcZMw tools/libxc/xc_linux_restore.c
    1.71 +3fbba6db7li3FJiABYtCmuGxOJxEGw tools/libxc/xc_linux_save.c
    1.72 +3fbba6db7WnnJr0KFrIFrqNlSKvFYg tools/libxc/xc_misc.c
    1.73 +40278d9ctaHVDaEuwhXI3Om2JOjx9w tools/libxc/xc_netbsd_build.c
    1.74 +4051bce6CHAsYh8P5t2OHDtRWOP9og tools/libxc/xc_physdev.c
    1.75 +3fbba6dctWRWlFJkYb6hdix2X4WMuw tools/libxc/xc_private.c
    1.76 +3fbba6dcbVrG2hPzEzwdeV_UC8kydQ tools/libxc/xc_private.h
    1.77 +40589968UQFnJeOMn8UIFLbXBuwXjw tools/libxc/xc_rrobin.c
    1.78 +40e1b09dMYB4ItGCqcMIzirdMd9I-w tools/libxutil/Makefile
    1.79 +40e033325Sjqs-_4TuzeUEprP_gYFg tools/libxutil/allocate.c
    1.80 +40e03332KYz7o1bn2MG_KPbBlyoIMA tools/libxutil/allocate.h
    1.81 +40e03332IyRttYoXKoJla5qCC514SQ tools/libxutil/debug.h
    1.82 +40e03332qV5tJ-GJZjo-LBCeGuEjJA tools/libxutil/enum.c
    1.83 +40e03332wwMVxfobgA1PSMTSAGLiCw tools/libxutil/enum.h
    1.84 +40e03332p5Dc_owJQRuN72ymJZddFQ tools/libxutil/file_stream.c
    1.85 +40e03332jWfB2viAhLSkq1WK0r_iDQ tools/libxutil/file_stream.h
    1.86 +40e03332rUjNMGg11n2rN6V4DCrvOg tools/libxutil/gzip_stream.c
    1.87 +40e033321O5Qg22haLoq5lpmk4tooQ tools/libxutil/gzip_stream.h
    1.88 +40e03332QrTR96tc6yS2rMBpd2mq1A tools/libxutil/hash_table.c
    1.89 +40e033325KoIb0d_uy8s7b5DUR9fPQ tools/libxutil/hash_table.h
    1.90 +40e03332ihnBGzHykVwZnFmkAppb4g tools/libxutil/iostream.c
    1.91 +40e03332UGwbLR4wsw4ft14p0Yw5pg tools/libxutil/iostream.h
    1.92 +40e0333245DLDzJemeSVBLuutHtzEQ tools/libxutil/kernel_stream.c
    1.93 +40e03332aK0GkgpDdc-PVTkWKTeOBg tools/libxutil/kernel_stream.h
    1.94 +40e03332HJ0cDcZDKDUUT-tEiBWOZw tools/libxutil/lexis.c
    1.95 +40e03332tnH9Ggzxbfi3xY9Vh2hUlg tools/libxutil/lexis.h
    1.96 +40e03332aYIW0BNBh6wXuKKn_P7Yyg tools/libxutil/lzi_stream.c
    1.97 +40e0333233voTffE4cJSMGJARfiSSQ tools/libxutil/lzi_stream.h
    1.98 +40e03332FXuMoUnfsAKSgV8X4rFbYQ tools/libxutil/lzo_stream.c
    1.99 +40e03332InJaiLfpDcIXBy2fI0RFGQ tools/libxutil/lzo_stream.h
   1.100 +40e03332a5SCuRsejHStTuWzMQNv8Q tools/libxutil/marshal.c
   1.101 +40e03332TwKyJrZQiiQfNq4vc2hpgw tools/libxutil/marshal.h
   1.102 +40e033328ccHlJuTR1FswYL_EC6LFA tools/libxutil/socket_stream.c
   1.103 +40e03332P0KVQGkmahj47aafo1X0nA tools/libxutil/socket_stream.h
   1.104 +40e03332KT_tnnoAMbPVAZBB7kSOAQ tools/libxutil/string_stream.c
   1.105 +40e03332-VtK6_OZa1vMHXFil8uq6w tools/libxutil/string_stream.h
   1.106 +40e03332dDtczi6YX7_mMxhYjJeAdQ tools/libxutil/sxpr.c
   1.107 +40e03332QPuyNKDOTIYVvkwK5qO-vg tools/libxutil/sxpr.h
   1.108 +40e03332Pi0_osJ3XPBi38ADPqdl4A tools/libxutil/sxpr_parser.c
   1.109 +40e033324v5QFMvWEXXzv38uUT9kHg tools/libxutil/sxpr_parser.h
   1.110 +40e03332gKUInsqtxQOV4mPiMqf_dg tools/libxutil/sys_ctype.h
   1.111 +40e03332Rkvq6nn_UNjzAAK_Tk9v1g tools/libxutil/sys_net.c
   1.112 +40e03332lQHvQHw4Rh7VsT1_sui29A tools/libxutil/sys_net.h
   1.113 +40e033321smklZd7bDSdWvQCeIshtg tools/libxutil/sys_string.c
   1.114 +40e03332h5V611rRWURRLqb1Ekatxg tools/libxutil/sys_string.h
   1.115 +40e03332u4q5kgF0N7RfqB4s0pZVew tools/libxutil/xdr.c
   1.116 +40e03332hY16nfRXF4gGd5S1aUJUBw tools/libxutil/xdr.h
   1.117  3f776bd2Xd-dUcPKlPN2vG89VGtfvQ tools/misc/Makefile
   1.118  40ab2cfawIw8tsYo0dQKtp83h4qfTQ tools/misc/fakei386xen
   1.119  3f6dc136ZKOjd8PIqLbFBl_v-rnkGg tools/misc/miniterm/Makefile
   1.120 @@ -213,97 +234,76 @@ 3f5ef5a2ir1kVAthS14Dc5QIRCEFWg tools/mis
   1.121  3f5ef5a2dTZP0nnsFoeq2jRf3mWDDg tools/misc/xen-clone.README
   1.122  3f870808zS6T6iFhqYPGelroZlVfGQ tools/misc/xen_cpuperf.c
   1.123  405eedf6_nnNhFQ1I85lhCkLK6jFGA tools/misc/xencons
   1.124 +40c9c4697z76HDfkCLdMhmaEwzFoNQ tools/misc/xend
   1.125  4056f5155QYZdsk-1fLdjsZPFTnlhg tools/misc/xensymoops.py
   1.126 -3fbca441SjQr8vJwTQIgH1laysaWog tools/xc/Makefile
   1.127 -3fbba6dbDfYvJSsw9500b4SZyUhxjQ tools/xc/lib/Makefile
   1.128 -3fbba6dc1uU7U3IFeF6A-XEOYF2MkQ tools/xc/lib/rpm.spec
   1.129 -3fbba6dcrNxtygEcgJYAJJ1gCQqfsA tools/xc/lib/xc.h
   1.130 -40589968oCfoUlXd460CjVAkBE8IBA tools/xc/lib/xc_atropos.c
   1.131 -3fbba6dbEVkVMX0JuDFzap9jeaucGA tools/xc/lib/xc_bvtsched.c
   1.132 -3fbba6dbasJQV-MVElDC0DGSHMiL5w tools/xc/lib/xc_domain.c
   1.133 -40278d99BLsfUv3qxv0I8C1sClZ0ow tools/xc/lib/xc_elf.h
   1.134 -403e0977Bjsm_e82pwvl9VvaJxh8Gg tools/xc/lib/xc_evtchn.c
   1.135 -40e03333Eegw8czSWvHsbKxrRZJjRA tools/xc/lib/xc_io.c
   1.136 -40e03333vrWGbLAhyJjXlqCHaJt7eA tools/xc/lib/xc_io.h
   1.137 -3fbba6dbNCU7U6nsMYiXzKkp3ztaJg tools/xc/lib/xc_linux_build.c
   1.138 -3fbba6dbl267zZOAVHYLOdLCdhcZMw tools/xc/lib/xc_linux_restore.c
   1.139 -3fbba6db7li3FJiABYtCmuGxOJxEGw tools/xc/lib/xc_linux_save.c
   1.140 -3fbba6db7WnnJr0KFrIFrqNlSKvFYg tools/xc/lib/xc_misc.c
   1.141 -40278d9ctaHVDaEuwhXI3Om2JOjx9w tools/xc/lib/xc_netbsd_build.c
   1.142 -4051bce6CHAsYh8P5t2OHDtRWOP9og tools/xc/lib/xc_physdev.c
   1.143 -3fbba6dctWRWlFJkYb6hdix2X4WMuw tools/xc/lib/xc_private.c
   1.144 -3fbba6dcbVrG2hPzEzwdeV_UC8kydQ tools/xc/lib/xc_private.h
   1.145 -40589968UQFnJeOMn8UIFLbXBuwXjw tools/xc/lib/xc_rrobin.c
   1.146 -3fbd0a3dTwnDcfdw0-v46dPbX98zDw tools/xc/py/Makefile
   1.147 -3fbd0a42l40lM0IICw2jXbQBVZSdZg tools/xc/py/Xc.c
   1.148 -3fbd0a40yT6G3M9hMpaz5xTUdl0E4g tools/xc/py/setup.py
   1.149 -40c9c468icGyC5RAF1bRKsCXPDCvsA tools/xen/Makefile
   1.150 -40dc4076hGpwa8-sWRN0jtXZeQJuKg tools/xen/lib/__init__.py
   1.151 -40dfd40aMOhnw_cQLve9462UR5yYxQ tools/xen/lib/ext/__init__.py
   1.152 -40dfd40aGqGkiopOOgJxSF4iCbHM0Q tools/xen/lib/util/__init__.py
   1.153 -4055ee4dwy4l0MghZosxoiu6zmhc9Q tools/xen/lib/util/console_client.py
   1.154 -40c9c468IienauFHQ_xJIcqnPJ8giQ tools/xen/lib/util/ip.py
   1.155 -4059c6a0pnxhG8hwSOivXybbGOwuXw tools/xen/lib/util/tempfile.py
   1.156 -40c9c468SNuObE_YWARyS0hzTPSzKg tools/xen/lib/xend/Args.py
   1.157 -40c9c468Um_qc66OQeLEceIz1pgD5g tools/xen/lib/xend/EventServer.py
   1.158 -40c9c468U8EVl0d3G--8YXVg6VJD3g tools/xen/lib/xend/EventTypes.py
   1.159 -40c9c468QJTEuk9g4qHxGpmIi70PEQ tools/xen/lib/xend/PrettyPrint.py
   1.160 -40d8915cyoVA0hJxiBFNymL7YvDaRg tools/xen/lib/xend/XendBridge.py
   1.161 -40c9c4688m3eqnC8fhLu1APm36VOVA tools/xen/lib/xend/XendClient.py
   1.162 -40c9c468t6iIKTjwuYoe-UMCikDcOQ tools/xen/lib/xend/XendConsole.py
   1.163 -40c9c468WnXs6eOUSff23IIGI4kMfQ tools/xen/lib/xend/XendDB.py
   1.164 -40c9c468fSl3H3IypyT0ppkbb0ZT9A tools/xen/lib/xend/XendDomain.py
   1.165 -40c9c468bbKq3uC7_fuNUkiMMjArdw tools/xen/lib/xend/XendDomainConfig.py
   1.166 -40c9c4685ykq87_n1kVUbMr9flx9fg tools/xen/lib/xend/XendDomainInfo.py
   1.167 -40c9c46854nsHmuxHQHncKk5rAs5NA tools/xen/lib/xend/XendMigrate.py
   1.168 -40c9c468M96gA1EYDvNa5w5kQNYLFA tools/xen/lib/xend/XendNode.py
   1.169 -40c9c4686jruMyZIqiaZRMiMoqMJtg tools/xen/lib/xend/XendRoot.py
   1.170 -40c9c468xzANp6o2D_MeCYwNmOIUsQ tools/xen/lib/xend/XendVnet.py
   1.171 -40c9c468x191zetrVlMnExfsQWHxIQ tools/xen/lib/xend/__init__.py
   1.172 -40c9c468S2YnCEKmk4ey8XQIST7INg tools/xen/lib/xend/encode.py
   1.173 -40c9c468DCpMe542varOolW1Xc68ew tools/xen/lib/xend/server/SrvBase.py
   1.174 -40c9c468IxQabrKJSWs0aEjl-27mRQ tools/xen/lib/xend/server/SrvConsole.py
   1.175 -40c9c4689Io5bxfbYIfRiUvsiLX0EQ tools/xen/lib/xend/server/SrvConsoleDir.py
   1.176 -40c9c468woSmBByfeXA4o_jGf2gCgA tools/xen/lib/xend/server/SrvDaemon.py
   1.177 -40c9c468kACsmkqjxBWKHRo071L26w tools/xen/lib/xend/server/SrvDeviceDir.py
   1.178 -40c9c468EQZJVkCLds-OhesJVVyZbQ tools/xen/lib/xend/server/SrvDir.py
   1.179 -40c9c468TyHZUq8sk0FF_vxM6Sozrg tools/xen/lib/xend/server/SrvDomain.py
   1.180 -40c9c469WzajDjutou3X7FmL9hMf3g tools/xen/lib/xend/server/SrvDomainDir.py
   1.181 -40c9c469-8mYEJJTAR6w_ClrJRAfwQ tools/xen/lib/xend/server/SrvEventDir.py
   1.182 -40c9c4694eu5759Dehr4Uhakei0EMg tools/xen/lib/xend/server/SrvNode.py
   1.183 -40c9c469TaZ83ypsrktmPSHLEZiP5w tools/xen/lib/xend/server/SrvRoot.py
   1.184 -40c9c469W3sgDMbBJYQdz5wbQweL0Q tools/xen/lib/xend/server/SrvServer.py
   1.185 -40c9c469aq7oXrE1Ngqf3_lBqL0RoQ tools/xen/lib/xend/server/SrvVnetDir.py
   1.186 -40c9c469Y_aimoOFfUZoS-4eV8gEKg tools/xen/lib/xend/server/__init__.py
   1.187 -40c9c4692hckPol_EK0EGB16ZyDsyQ tools/xen/lib/xend/server/blkif.py
   1.188 -40c9c469N2-b3GqpLHHHPZykJPLVvA tools/xen/lib/xend/server/channel.py
   1.189 -40c9c469hJ_IlatRne-9QEa0-wlquw tools/xen/lib/xend/server/console.py
   1.190 -40c9c469UcNJh_NuLU0ytorM0Lk5Ow tools/xen/lib/xend/server/controller.py
   1.191 -40c9c469vHh-qLiiubdbKEQbJf18Zw tools/xen/lib/xend/server/cstruct.py
   1.192 -40d83983OXjt-y3HjSCcuoPp9rzvmw tools/xen/lib/xend/server/domain.py
   1.193 -40c9c469yrm31i60pGKslTi2Zgpotg tools/xen/lib/xend/server/messages.py
   1.194 -40c9c46925x-Rjb0Cv2f1-l2jZrPYg tools/xen/lib/xend/server/netif.py
   1.195 -40c9c469ZqILEQ8x6yWy0_51jopiCg tools/xen/lib/xend/server/params.py
   1.196 -40c9c469LNxLVizOUpOjEaTKKCm8Aw tools/xen/lib/xend/sxp.py
   1.197 -40d05079aFRp6NQdo5wIh5Ly31c0cg tools/xen/lib/xm/__init__.py
   1.198 -40cf2937gKQcATgXKGtNeWb1PDH5nA tools/xen/lib/xm/create.py
   1.199 -40cf2937isyS250zyd0Q2GuEDoNXfQ tools/xen/lib/xm/main.py
   1.200 -40cf2937PSslwBliN1g7ofDy2H_RhA tools/xen/lib/xm/opts.py
   1.201 -40cf2937Z8WCNOnO2FcWdubvEAF9QQ tools/xen/lib/xm/shutdown.py
   1.202 -40c9c469n2RRwCmjWdjdyyVRWKmgWg tools/xen/setup.py
   1.203 -40c9c4697z76HDfkCLdMhmaEwzFoNQ tools/xen/xend
   1.204 -40cf2937dqM1jWW87O5OoOYND8leuA tools/xen/xm
   1.205 +40cf2937dqM1jWW87O5OoOYND8leuA tools/misc/xm
   1.206 +40c9c468icGyC5RAF1bRKsCXPDCvsA tools/python/Makefile
   1.207 +40c9c469n2RRwCmjWdjdyyVRWKmgWg tools/python/setup.py
   1.208 +40dc4076hGpwa8-sWRN0jtXZeQJuKg tools/python/xen/__init__.py
   1.209 +40dfd40aMOhnw_cQLve9462UR5yYxQ tools/python/xen/ext/__init__.py
   1.210 +3fbd0a3dTwnDcfdw0-v46dPbX98zDw tools/python/xen/ext/xc/Makefile
   1.211 +3fbd0a40yT6G3M9hMpaz5xTUdl0E4g tools/python/xen/ext/xc/setup.py
   1.212 +3fbd0a42l40lM0IICw2jXbQBVZSdZg tools/python/xen/ext/xc/xc.c
   1.213 +40dc4076St6AmPTmQPrtQ6LGHPxGmw tools/python/xen/ext/xu/__init__.py
   1.214 +40dc4076pVeE1kEEWzcUaNZin65kCA tools/python/xen/ext/xu/domain_controller.h
   1.215 +40dc4076CwBYRTUQDdbdU1L6KcLgSw tools/python/xen/ext/xu/xu.c
   1.216 +40d8915cyoVA0hJxiBFNymL7YvDaRg tools/python/xen/util/Brctl.py
   1.217 +40dfd40aGqGkiopOOgJxSF4iCbHM0Q tools/python/xen/util/__init__.py
   1.218 +4055ee4dwy4l0MghZosxoiu6zmhc9Q tools/python/xen/util/console_client.py
   1.219 +40c9c468IienauFHQ_xJIcqnPJ8giQ tools/python/xen/util/ip.py
   1.220 +4059c6a0pnxhG8hwSOivXybbGOwuXw tools/python/xen/util/tempfile.py
   1.221 +40c9c468SNuObE_YWARyS0hzTPSzKg tools/python/xen/xend/Args.py
   1.222 +40c9c468Um_qc66OQeLEceIz1pgD5g tools/python/xen/xend/EventServer.py
   1.223 +40c9c468U8EVl0d3G--8YXVg6VJD3g tools/python/xen/xend/EventTypes.py
   1.224 +40c9c468QJTEuk9g4qHxGpmIi70PEQ tools/python/xen/xend/PrettyPrint.py
   1.225 +40e15b7eeQxWE_hUPB2YTgM9fsZ1PQ tools/python/xen/xend/Vifctl.py
   1.226 +40c9c4688m3eqnC8fhLu1APm36VOVA tools/python/xen/xend/XendClient.py
   1.227 +40c9c468t6iIKTjwuYoe-UMCikDcOQ tools/python/xen/xend/XendConsole.py
   1.228 +40c9c468WnXs6eOUSff23IIGI4kMfQ tools/python/xen/xend/XendDB.py
   1.229 +40c9c468fSl3H3IypyT0ppkbb0ZT9A tools/python/xen/xend/XendDomain.py
   1.230 +40c9c468bbKq3uC7_fuNUkiMMjArdw tools/python/xen/xend/XendDomainConfig.py
   1.231 +40c9c4685ykq87_n1kVUbMr9flx9fg tools/python/xen/xend/XendDomainInfo.py
   1.232 +40c9c46854nsHmuxHQHncKk5rAs5NA tools/python/xen/xend/XendMigrate.py
   1.233 +40c9c468M96gA1EYDvNa5w5kQNYLFA tools/python/xen/xend/XendNode.py
   1.234 +40c9c4686jruMyZIqiaZRMiMoqMJtg tools/python/xen/xend/XendRoot.py
   1.235 +40c9c468xzANp6o2D_MeCYwNmOIUsQ tools/python/xen/xend/XendVnet.py
   1.236 +40c9c468x191zetrVlMnExfsQWHxIQ tools/python/xen/xend/__init__.py
   1.237 +40c9c468S2YnCEKmk4ey8XQIST7INg tools/python/xen/xend/encode.py
   1.238 +40c9c468DCpMe542varOolW1Xc68ew tools/python/xen/xend/server/SrvBase.py
   1.239 +40c9c468IxQabrKJSWs0aEjl-27mRQ tools/python/xen/xend/server/SrvConsole.py
   1.240 +40c9c4689Io5bxfbYIfRiUvsiLX0EQ tools/python/xen/xend/server/SrvConsoleDir.py
   1.241 +40c9c468woSmBByfeXA4o_jGf2gCgA tools/python/xen/xend/server/SrvDaemon.py
   1.242 +40c9c468kACsmkqjxBWKHRo071L26w tools/python/xen/xend/server/SrvDeviceDir.py
   1.243 +40c9c468EQZJVkCLds-OhesJVVyZbQ tools/python/xen/xend/server/SrvDir.py
   1.244 +40c9c468TyHZUq8sk0FF_vxM6Sozrg tools/python/xen/xend/server/SrvDomain.py
   1.245 +40c9c469WzajDjutou3X7FmL9hMf3g tools/python/xen/xend/server/SrvDomainDir.py
   1.246 +40c9c469-8mYEJJTAR6w_ClrJRAfwQ tools/python/xen/xend/server/SrvEventDir.py
   1.247 +40c9c4694eu5759Dehr4Uhakei0EMg tools/python/xen/xend/server/SrvNode.py
   1.248 +40c9c469TaZ83ypsrktmPSHLEZiP5w tools/python/xen/xend/server/SrvRoot.py
   1.249 +40c9c469W3sgDMbBJYQdz5wbQweL0Q tools/python/xen/xend/server/SrvServer.py
   1.250 +40c9c469aq7oXrE1Ngqf3_lBqL0RoQ tools/python/xen/xend/server/SrvVnetDir.py
   1.251 +40c9c469Y_aimoOFfUZoS-4eV8gEKg tools/python/xen/xend/server/__init__.py
   1.252 +40c9c4692hckPol_EK0EGB16ZyDsyQ tools/python/xen/xend/server/blkif.py
   1.253 +40c9c469N2-b3GqpLHHHPZykJPLVvA tools/python/xen/xend/server/channel.py
   1.254 +40c9c469hJ_IlatRne-9QEa0-wlquw tools/python/xen/xend/server/console.py
   1.255 +40c9c469UcNJh_NuLU0ytorM0Lk5Ow tools/python/xen/xend/server/controller.py
   1.256 +40c9c469vHh-qLiiubdbKEQbJf18Zw tools/python/xen/xend/server/cstruct.py
   1.257 +40d83983OXjt-y3HjSCcuoPp9rzvmw tools/python/xen/xend/server/domain.py
   1.258 +40c9c469yrm31i60pGKslTi2Zgpotg tools/python/xen/xend/server/messages.py
   1.259 +40c9c46925x-Rjb0Cv2f1-l2jZrPYg tools/python/xen/xend/server/netif.py
   1.260 +40c9c469ZqILEQ8x6yWy0_51jopiCg tools/python/xen/xend/server/params.py
   1.261 +40c9c469LNxLVizOUpOjEaTKKCm8Aw tools/python/xen/xend/sxp.py
   1.262 +40d05079aFRp6NQdo5wIh5Ly31c0cg tools/python/xen/xm/__init__.py
   1.263 +40cf2937gKQcATgXKGtNeWb1PDH5nA tools/python/xen/xm/create.py
   1.264 +40cf2937isyS250zyd0Q2GuEDoNXfQ tools/python/xen/xm/main.py
   1.265 +40cf2937PSslwBliN1g7ofDy2H_RhA tools/python/xen/xm/opts.py
   1.266 +40cf2937Z8WCNOnO2FcWdubvEAF9QQ tools/python/xen/xm/shutdown.py
   1.267  403a3edbrr8RE34gkbR40zep98SXbg tools/xentrace/Makefile
   1.268  40a107afN60pFdURgBv9KwEzgRl5mQ tools/xentrace/formats
   1.269  4050c413PhhLNAYk3TEwP37i_iLw9Q tools/xentrace/xentrace.8
   1.270  403a3edbVpV2E_wq1zeEkJ_n4Uu2eg tools/xentrace/xentrace.c
   1.271  403a3edblCUrzSj0mmKhO5HOPrOrSQ tools/xentrace/xentrace_format
   1.272  4050c413NtuyIq5lsYJV4P7KIjujXw tools/xentrace/xentrace_format.1
   1.273 -40dfd40a0QtsSGigB9TCpVGWZmhlNA tools/xu/Makefile
   1.274 -40dc4076St6AmPTmQPrtQ6LGHPxGmw tools/xu/lib/__init__.py
   1.275 -40dc4076pVeE1kEEWzcUaNZin65kCA tools/xu/lib/domain_controller.h
   1.276 -40dc4076CwBYRTUQDdbdU1L6KcLgSw tools/xu/lib/xu.c
   1.277 -40dc4076FyWUYS2nX9YufgglUzKX2A tools/xu/setup.py
   1.278  3f72f1bdJPsV3JCnBqs9ddL9tr6D2g xen/COPYING
   1.279  3ddb79bcbOVHh38VJzc97-JEGD4dJQ xen/Makefile
   1.280  3ddb79bcWnTwYsQRWl_PaneJfa6p0w xen/Rules.mk
     2.1 --- a/BitKeeper/etc/ignore	Tue Jun 29 14:14:38 2004 +0000
     2.2 +++ b/BitKeeper/etc/ignore	Tue Jun 29 19:45:18 2004 +0000
     2.3 @@ -52,3 +52,23 @@ xen/tools/figlet/figlet
     2.4  xen/xen
     2.5  xen/xen-syms
     2.6  xen/xen.*
     2.7 +tools/xc/lib/.xc_rrobin.o.d
     2.8 +tools/libxc/.xc_atropos.o.d
     2.9 +tools/libxc/.xc_bvtsched.o.d
    2.10 +tools/libxc/.xc_domain.o.d
    2.11 +tools/libxc/.xc_evtchn.o.d
    2.12 +tools/libxc/.xc_io.o.d
    2.13 +tools/libxc/.xc_linux_build.o.d
    2.14 +tools/libxc/.xc_linux_restore.o.d
    2.15 +tools/libxc/.xc_linux_save.o.d
    2.16 +tools/libxc/.xc_misc.o.d
    2.17 +tools/libxc/.xc_netbsd_build.o.d
    2.18 +tools/libxc/.xc_physdev.o.d
    2.19 +tools/libxc/.xc_private.o.d
    2.20 +tools/libxc/.xc_rrobin.o.d
    2.21 +tools/libxutil/.allocate.o.d
    2.22 +tools/libxutil/.file_stream.o.d
    2.23 +tools/libxutil/.gzip_stream.o.d
    2.24 +tools/libxutil/.iostream.o.d
    2.25 +tools/libxutil/.sys_net.o.d
    2.26 +tools/libxutil/.sys_string.o.d
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/tools/Make.defs	Tue Jun 29 19:45:18 2004 +0000
     3.3 @@ -0,0 +1,7 @@
     3.4 +#  -*- mode: Makefile; -*-
     3.5 +XEN_HYPERVISOR_IFS = $(XEN_ROOT)/xen/include/hypervisor-ifs
     3.6 +XEN_LINUX_INCLUDE  = $(XEN_ROOT)/linux-xen-sparse/include
     3.7 +XEN_XU             = $(XEN_ROOT)/tools/python/xen/ext/xu
     3.8 +XEN_XC             = $(XEN_ROOT)/tools/python/xen/ext/xc
     3.9 +XEN_LIBXC          = $(XEN_ROOT)/tools/libxc
    3.10 +XEN_LIBXUTIL       = $(XEN_ROOT)/tools/libxutil
     4.1 --- a/tools/Makefile	Tue Jun 29 14:14:38 2004 +0000
     4.2 +++ b/tools/Makefile	Tue Jun 29 19:45:18 2004 +0000
     4.3 @@ -1,29 +1,29 @@
     4.4  
     4.5  all:	
     4.6 -	$(MAKE) -C xc
     4.7 -	$(MAKE) -C xu
     4.8 +	$(MAKE) -C libxutil
     4.9 +	$(MAKE) -C libxc
    4.10  	$(MAKE) -C misc
    4.11  	$(MAKE) -C examples
    4.12  	$(MAKE) -C xentrace
    4.13 -	$(MAKE) -C xen
    4.14 +	$(MAKE) -C python
    4.15  
    4.16  install: all
    4.17 -	$(MAKE) -C xc install
    4.18 -	$(MAKE) -C xu install
    4.19 +	$(MAKE) -C libxutil install
    4.20 +	$(MAKE) -C libxc install
    4.21  	$(MAKE) -C misc install
    4.22  	$(MAKE) -C examples install
    4.23  	$(MAKE) -C xentrace install
    4.24 -	$(MAKE) -C xen install
    4.25 +	$(MAKE) -C python install
    4.26  
    4.27  dist: $(TARGET)
    4.28  	$(MAKE) prefix=`pwd`/../../install dist=yes install
    4.29  
    4.30  
    4.31  clean:
    4.32 -	$(MAKE) -C xc clean
    4.33 -	$(MAKE) -C xu clean
    4.34 +	$(MAKE) -C libxutil clean
    4.35 +	$(MAKE) -C libxc clean
    4.36  	$(MAKE) -C misc clean
    4.37  	$(MAKE) -C examples clean
    4.38  	$(MAKE) -C xentrace clean
    4.39 -	$(MAKE) -C xen clean
    4.40 +	$(MAKE) -C python clean
    4.41  
     5.1 --- a/tools/examples/Makefile	Tue Jun 29 14:14:38 2004 +0000
     5.2 +++ b/tools/examples/Makefile	Tue Jun 29 19:45:18 2004 +0000
     5.3 @@ -1,21 +1,40 @@
     5.4  
     5.5  INSTALL  = $(wildcard *.py)
     5.6 +
     5.7  ETC	 = defaults democd netbsd xmdefaults
     5.8  ETCDIR   = /etc/xen
     5.9 +
    5.10  INITD    = init.d/xendomains init.d/xend
    5.11  
    5.12 +XEND     = vifctl
    5.13 +XEND_DIR = $(ETCDIR)/xend
    5.14 +
    5.15  all: 
    5.16  
    5.17 -install: all
    5.18 +install: all install-bin install-initd install-etc install-xend
    5.19 +
    5.20 +install-bin:
    5.21  	mkdir -p $(prefix)/usr/bin
    5.22 +	install -m0755 $(INSTALL) $(prefix)/usr/bin
    5.23 +
    5.24 +install-initd:
    5.25 +	mkdir -p $(prefix)/etc/init.d
    5.26 +	install -m0755 $(INITD) $(prefix)/etc/init.d
    5.27 +
    5.28 +install-etc:
    5.29  	mkdir -p $(prefix)$(ETCDIR)
    5.30  	mkdir -p $(prefix)$(ETCDIR)/auto
    5.31 -	mkdir -p $(prefix)/etc/init.d
    5.32 -	install -m0755 $(INSTALL) $(prefix)/usr/bin
    5.33  	for i in $(ETC); \
    5.34  	    do [ -a $(prefix)/$(ETCDIR)/$$i ] || \
    5.35  	    install -m0644 $$i $(prefix)$(ETCDIR); \
    5.36  	done
    5.37 -	install -m0755 $(INITD) $(prefix)/etc/init.d
    5.38 +
    5.39 +install-xend:
    5.40 +	mkdir -p $(prefix)$(XEND_DIR)
    5.41 +	for i in $(XEND); \
    5.42 +	    do [ -a $(prefix)/$(XEND_DIR)/$$i ] || \
    5.43 +	    install -m0755 $$i $(prefix)$(XEND_DIR); \
    5.44 +	done
    5.45 +
    5.46  
    5.47  clean:
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/tools/examples/vifctl	Tue Jun 29 19:45:18 2004 +0000
     6.3 @@ -0,0 +1,149 @@
     6.4 +#!/usr/bin/python
     6.5 +#  -*- mode: python; -*-
     6.6 +#============================================================================
     6.7 +# Xen vif control script. Lives in /etc/xen/xend.
     6.8 +#
     6.9 +# vifctl init [bridge=<bridge>] [interface=<interface>]
    6.10 +#
    6.11 +#    Called when xend starts up. Default behaviour is to create <bridge>
    6.12 +#    and add <interface> to it, moving its IP address to <bridge> and adjusting routes.
    6.13 +#
    6.14 +# vifctl (up|down) vif=<vif> mac=<mac> [bridge=<bridge>] (ipaddr=<ipaddr>)*
    6.15 +#
    6.16 +#    Called when a vif is brought up or down. Default behaviour is to add
    6.17 +#    the vif to <bridge> on up and remove it from the bridge on down.
    6.18 +#    If ipaddr is specified, iptables rules for the ip addresses are
    6.19 +#    added on up and removed on down. The bridge a vif is added to can
    6.20 +#    be set in the vm config.
    6.21 +#
    6.22 +# The default bridge is nbe-br.
    6.23 +# The default interface is eth0.
    6.24 +#
    6.25 +#============================================================================
    6.26 +
    6.27 +import sys
    6.28 +import types
    6.29 +
    6.30 +from xen.util import Brctl
    6.31 +
    6.32 +from xen.xend import XendRoot
    6.33 +xroot = XendRoot.instance()
    6.34 +
    6.35 +class VifControl:
    6.36 +
    6.37 +    prefix = 'vifctl_'
    6.38 +
    6.39 +    DEFAULT_BRIDGE = 'nbe-br'
    6.40 +    DEFAULT_INTERFACE = 'eth0'
    6.41 +
    6.42 +    def __init__(self):
    6.43 +        self.name = 'vifctl'
    6.44 +    
    6.45 +    def main(self, args):
    6.46 +        #print self.name, args
    6.47 +        if len(args) < 2:
    6.48 +            usage(args)
    6.49 +        self.name = args[0]
    6.50 +        cmd = self.prefix + args[1]
    6.51 +        meth = getattr(self, cmd, self.unknown)
    6.52 +        meth(args[1:])
    6.53 +
    6.54 +    def usage(self, args, out=sys.stderr):
    6.55 +        print >>out, 'Missing command, try \n%s help' % self.name
    6.56 +
    6.57 +    def unknown(self, args, out=sys.stderr):
    6.58 +        print >>out, 'Unknown command:', args[1]
    6.59 +        self.help(out=out)
    6.60 +        sys.exit(1)
    6.61 +
    6.62 +    def help(self, out=sys.stdout):
    6.63 +        print >>out, 'Commands are:',
    6.64 +        for x in vars(self):
    6.65 +            if x.startswith(prefix):
    6.66 +                cmd = x[len(prefix):]
    6.67 +                print  >>out, cmd,
    6.68 +        print >>out
    6.69 +
    6.70 +    def getparams(self, d, args, req=[]):
    6.71 +        """Parse args of the form 'key=val'. Valid keys are the ones
    6.72 +        in the dict 'd' passed in. If entries in 'd' have list values the
    6.73 +        values of the keys are appended.
    6.74 +
    6.75 +        If 'req' is specified it is a list of required keys.
    6.76 +        """
    6.77 +        for x in args:
    6.78 +            (k, v) = x.split('=')
    6.79 +            k = k.strip()
    6.80 +            v = v.strip()
    6.81 +            if k not in d:
    6.82 +                print >>sys.stderr, 'Invalid parameter: ', k
    6.83 +                sys.exit(1)
    6.84 +            vold = d[k]
    6.85 +            if isinstance(vold , types.ListType):
    6.86 +                d[k] = vold + v
    6.87 +            else:
    6.88 +                d[k] = v
    6.89 +        for x in req:
    6.90 +            if not d[x]:
    6.91 +                print >>sys.stderr, 'Missing parameter:', x
    6.92 +                sys.exit(1)
    6.93 +        return d
    6.94 +            
    6.95 +    def vifctl_help(self, args):
    6.96 +        self.help()
    6.97 +
    6.98 +    def default_bridge(self):
    6.99 +        return xroot.get_config_value('bridge', self.DEFAULT_BRIDGE)
   6.100 +
   6.101 +    def default_interface(self):
   6.102 +        return xroot.get_config_value('interface', self.DEFAULT_INTERFACE)
   6.103 +    
   6.104 +    def vifctl_init(self, args):
   6.105 +        """Entry point for 'vifctl init'.
   6.106 +        """
   6.107 +        d = { 'bridge'   : self.default_bridge(),
   6.108 +              'interface': self.default_interface() }
   6.109 +        params = self.getparams(d, args[1:])
   6.110 +        interface = params['interface']
   6.111 +        bridge = params['bridge']
   6.112 +        # Create bridge 'bridge'.
   6.113 +        Brctl.bridge_create(bridge)
   6.114 +        # Reconfigure so that 'interface' is added to 'bridge',
   6.115 +        # and 'bridge' has the IP address from 'interface'.
   6.116 +        Brctl.reconfigure(interface, bridge)
   6.117 +        
   6.118 +    def vifparams(self, args):
   6.119 +        d = { 'vif'   : None,
   6.120 +              'mac'   : None,
   6.121 +              'bridge': self.default_bridge(),
   6.122 +              'ipaddr': [] }
   6.123 +        d = self.getparams(d, args, req=['vif', 'mac'])
   6.124 +        return d
   6.125 +
   6.126 +    def vifctl_up(self, args):
   6.127 +        """Entry point for 'vifctl up'.
   6.128 +        """
   6.129 +        params = self.vifparams(args[1:])
   6.130 +        # Add the vif to its bridge.
   6.131 +        Brctl.vif_bridge_add(params)
   6.132 +        if params['ipaddr']:
   6.133 +            # Add iptables rules for the ip addresses.
   6.134 +            vif = params['vif']
   6.135 +            for ipaddr in params['ipaddr']:
   6.136 +               Brctl.vif_restrict_addr(vif, ipaddr)
   6.137 +
   6.138 +    def vifctl_down(self, args):
   6.139 +        """Entry point for 'vifctl down'.
   6.140 +        """
   6.141 +        params = self.vifparams(args[1:])
   6.142 +        # Remove the vif from its bridge.
   6.143 +        Brctl.vif_bridge_rem(params)
   6.144 +        if params['ip']:
   6.145 +            # Remove iptables rules for the ip addresses.
   6.146 +            vif = params['vif']
   6.147 +            for ip in params['ip']:
   6.148 +               Brctl.vif_restrict_addr(vif, ip, delete=1)
   6.149 +
   6.150 +
   6.151 +if __name__ == "__main__":
   6.152 +    VifControl().main(sys.argv)
     7.1 --- a/tools/examples/xm_dom_create.py	Tue Jun 29 14:14:38 2004 +0000
     7.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.3 @@ -1,406 +0,0 @@
     7.4 -#!/usr/bin/env python
     7.5 -
     7.6 -import string
     7.7 -import sys
     7.8 -import os
     7.9 -import os.path
    7.10 -import time
    7.11 -import socket
    7.12 -import getopt
    7.13 -import signal
    7.14 -import syslog
    7.15 -import xenctl.ip
    7.16 -import xenctl.utils
    7.17 -import xenctl.console_client
    7.18 -
    7.19 -from xenmgr import sxp
    7.20 -from xenmgr import PrettyPrint
    7.21 -from xenmgr.XendClient import server
    7.22 -
    7.23 -config_dir  = '/etc/xc/'
    7.24 -config_file = xc_config_file = config_dir + 'defaults'
    7.25 -
    7.26 -def main_usage ():
    7.27 -    print >>sys.stderr,"""
    7.28 -Usage: %s <args>
    7.29 -
    7.30 -This tool is used to create and start new domains. It reads defaults
    7.31 -from a file written in Python, having allowed variables to be set and
    7.32 -passed into the file. Further command line arguments allow the
    7.33 -defaults to be overridden. The defaults for each parameter are listed
    7.34 -in [] brackets. Arguments are as follows:
    7.35 -
    7.36 -Arguments to control the parsing of the defaults file:
    7.37 - -f config_file   -- Use the specified defaults script. 
    7.38 -                     Default: ['%s']
    7.39 - -L state_file    -- Load virtual machine memory state from state_file
    7.40 - -D foo=bar       -- Set variable foo=bar before parsing config
    7.41 -                     E.g. '-D vmid=3;ip=1.2.3.4'
    7.42 - -h               -- Print extended help message, including all arguments
    7.43 - -n               -- Dry run only, don't actually create domain
    7.44 -                     Prints the config, suitable for -F.
    7.45 - -q               -- Quiet - write output only to the system log
    7.46 - -F domain_config -- Build domain using the config in the file.
    7.47 -                     Suitable files can be made using '-n' to output a config.
    7.48 -""" % (sys.argv[0], xc_config_file)
    7.49 -
    7.50 -def extra_usage ():
    7.51 -    print >>sys.stderr,"""
    7.52 -Arguments to override current config read from '%s':
    7.53 - -c               -- Turn into console terminal after domain is created
    7.54 - -k image         -- Path to kernel image ['%s']
    7.55 - -r ramdisk       -- Path to ramdisk (or empty) ['%s']
    7.56 - -b builder_fn    -- Function to use to build domain ['%s']
    7.57 - -m mem_size      -- Initial memory allocation in MB [%dMB]
    7.58 - -N domain_name   -- Set textual name of domain ['%s']
    7.59 - -a auto_restart  -- Restart domain on exit, yes/no ['%d']
    7.60 - -e vbd_expert    -- Safety catch to avoid some disk accidents ['%s'] 
    7.61 - -d udisk,dev,rw  -- Add disk, partition, or virtual disk to domain. E.g. to 
    7.62 -                     make partion sda4 available to the domain as hda1 with 
    7.63 -                     read-write access: '-d phy:sda4,hda1,rw' To add 
    7.64 -                     multiple disks use multiple -d flags or seperate with ';'
    7.65 -                     Default: ['%s']
    7.66 - -i vfr_ipaddr    -- Add IP address to the list which Xen will route to
    7.67 -                     the domain. Use multiple times to add more IP addrs.
    7.68 -		     Default: ['%s']
    7.69 -
    7.70 -Args to override the kernel command line, which is concatenated from these:
    7.71 - -I cmdline_ip    -- Override 'ip=ipaddr:nfsserv:gateway:netmask::eth0:off'
    7.72 -                     Default: ['%s']
    7.73 - -R cmdline_root  -- Override root device parameters.
    7.74 -                     Default: ['%s']
    7.75 - -E cmdline_extra -- Override extra kernel args and rc script env vars.
    7.76 -                     Default: ['%s']
    7.77 -
    7.78 -""" % (config_file,
    7.79 -       image, ramdisk, builder_fn, mem_size, domain_name, auto_restart,
    7.80 -       vbd_expert, 
    7.81 -       printvbds( vbd_list ), 
    7.82 -       reduce ( (lambda a,b: a+':'+b), vfr_ipaddr,'' )[1:],
    7.83 -       cmdline_ip, cmdline_root, cmdline_extra)
    7.84 -
    7.85 -def config_usage (): pass
    7.86 -
    7.87 -def answer ( s ):
    7.88 -    s = string.lower(s)
    7.89 -    if s == 'yes' or s == 'true' or s == '1': return 1
    7.90 -    return 0
    7.91 -
    7.92 -def printvbds ( v ):
    7.93 -    s=''
    7.94 -    for (a,b,c) in v:
    7.95 -	s = s + '; %s,%s,%s' % (a,b,c)
    7.96 -    return s[2:]
    7.97 -
    7.98 -def output(string):
    7.99 -    global quiet
   7.100 -    syslog.syslog(string)
   7.101 -    if not quiet:
   7.102 -        print string
   7.103 -    return
   7.104 -
   7.105 -bail=False; dryrun=False; extrahelp=False; quiet = False
   7.106 -image=''; ramdisk=''; builder_fn='linux'; restore=0; state_file=''
   7.107 -mem_size=0; domain_name=''; vfr_ipaddr=[];
   7.108 -vbd_expert='rr'; auto_restart=False;
   7.109 -vbd_list = []; cmdline_ip = ''; cmdline_root=''; cmdline_extra=''
   7.110 -pci_device_list = []; console_port = -1
   7.111 -auto_console = False
   7.112 -config_from_file = False
   7.113 -
   7.114 -##### Determine location of defaults file
   7.115 -#####
   7.116 -
   7.117 -try:
   7.118 -    opts, args = getopt.getopt(sys.argv[1:], "h?nqcf:F:D:k:r:b:m:N:a:e:d:i:I:R:E:L:" )
   7.119 -
   7.120 -    for opt in opts:
   7.121 -	if opt[0] == '-f': config_file= opt[1]
   7.122 -	if opt[0] == '-h' or opt[0] == '-?' : bail=True; extrahelp=True
   7.123 -	if opt[0] == '-n': dryrun=True
   7.124 -	if opt[0] == '-D': 
   7.125 -	    for o in string.split( opt[1], ';' ):
   7.126 -		(l,r) = string.split( o, '=' )
   7.127 -		exec "%s='%s'" % (l,r)
   7.128 -        if opt[0] == '-q': quiet = True
   7.129 -        if opt[0] == '-L': restore = True; state_file = opt[1]
   7.130 -        if opt[0] == '-F': config_from_file = True; domain_config = opt[1]
   7.131 -
   7.132 -
   7.133 -except getopt.GetoptError:
   7.134 -    bail=True
   7.135 -
   7.136 -if not config_from_file:
   7.137 -    try:
   7.138 -        os.stat( config_file )
   7.139 -    except:
   7.140 -        try:
   7.141 -            d = config_dir + config_file
   7.142 -            os.stat( d )
   7.143 -            config_file = d
   7.144 -        except:
   7.145 -            print >> sys.stderr, "Unable to open config file '%s'" % config_file
   7.146 -            bail = True
   7.147 -
   7.148 -
   7.149 -##### Parse the config file
   7.150 -#####
   7.151 -
   7.152 -if not config_from_file:
   7.153 -    if not quiet:
   7.154 -        print "Parsing config file '%s'" % config_file
   7.155 -
   7.156 -    try:
   7.157 -        execfile ( config_file )
   7.158 -    except (AssertionError,IOError):
   7.159 -        print >>sys.stderr,"Exiting %s" % sys.argv[0]
   7.160 -        bail = True
   7.161 -
   7.162 -##### Print out config if necessary 
   7.163 -##### 
   7.164 -
   7.165 -def bailout():
   7.166 -    global extrahelp
   7.167 -    main_usage()
   7.168 -    config_usage()
   7.169 -    if extrahelp: extra_usage()
   7.170 -    sys.exit(1)
   7.171 -
   7.172 -if bail:
   7.173 -    bailout()
   7.174 -
   7.175 -##### Parse any command line overrides 
   7.176 -##### 
   7.177 -
   7.178 -x_vbd_list = []
   7.179 -x_vfr_ipaddr  = []
   7.180 -
   7.181 -for opt in opts:
   7.182 -    if opt[0] == '-k': image = opt[1]
   7.183 -    if opt[0] == '-r': ramdisk = opt[1]
   7.184 -    if opt[0] == '-b': builder_fn = opt[1]  
   7.185 -    if opt[0] == '-m': mem_size = int(opt[1])
   7.186 -    if opt[0] == '-C': cpu = int(opt[1])
   7.187 -    if opt[0] == '-N': domain_name = opt[1]
   7.188 -    if opt[0] == '-a': auto_restart = answer(opt[1])
   7.189 -    if opt[0] == '-e': vbd_expert = opt[1]
   7.190 -    if opt[0] == '-I': cmdline_ip = opt[1]
   7.191 -    if opt[0] == '-R': cmdline_root = opt[1]
   7.192 -    if opt[0] == '-E': cmdline_extra = opt[1]
   7.193 -    if opt[0] == '-i': x_vfr_ipaddr.append(opt[1])
   7.194 -    if opt[0] == '-c': auto_console = True
   7.195 -    if opt[0] == '-d':
   7.196 -	try:
   7.197 -	    vv = string.split(opt[1],';')	    
   7.198 -	    for v in vv:
   7.199 -		(udisk,dev,mode) = string.split(v,',')
   7.200 -		x_vbd_list.append( (udisk,dev,mode) )
   7.201 -	except:
   7.202 -	    print >>sys.stderr, "Invalid block device specification : %s" % opt[1]
   7.203 -	    sys.exit(1)
   7.204 -
   7.205 -if x_vbd_list: vbd_list = x_vbd_list
   7.206 -if x_vfr_ipaddr: vfr_ipaddr = x_vfr_ipaddr
   7.207 -
   7.208 -syslog.openlog('xc_dom_create.py %s' % config_file, 0, syslog.LOG_DAEMON)
   7.209 -
   7.210 -def strip(pre, s):
   7.211 -    if s.startswith(pre):
   7.212 -        return s[len(pre):]
   7.213 -    else:
   7.214 -        return s
   7.215 -
   7.216 -def make_domain_config():
   7.217 -    global builder_fn, image, ramdisk, mem_size, domain_name
   7.218 -    global cpu
   7.219 -    global cmdline, cmdline_ip, cmdline_root
   7.220 -    global vfr_ipaddr, vbd_list, vbd_expert
   7.221 -    
   7.222 -    config = ['config',
   7.223 -              ['name', domain_name ],
   7.224 -              ['memory', mem_size ],
   7.225 -              ]
   7.226 -    if cpu:
   7.227 -        config.append(['cpu', cpu])
   7.228 -    
   7.229 -    config_image = [ builder_fn ]
   7.230 -    config_image.append([ 'kernel', os.path.abspath(image) ])
   7.231 -    if ramdisk:
   7.232 -        config_image.append([ 'ramdisk', os.path.abspath(ramdisk) ])
   7.233 -    if cmdline_ip:
   7.234 -        cmdline_ip = strip("ip=", cmdline_ip)
   7.235 -        config_image.append(['ip', cmdline_ip])
   7.236 -    if cmdline_root:
   7.237 -        cmdline_root = strip("root=", cmdline_root)
   7.238 -        config_image.append(['root', cmdline_root])
   7.239 -    if cmdline_extra:
   7.240 -        config_image.append(['args', cmdline_extra])
   7.241 -    config.append(['image', config_image ])
   7.242 -    	
   7.243 -    config_devs = []
   7.244 -    for (uname, dev, mode) in vbd_list:
   7.245 -        config_vbd = ['vbd',
   7.246 -                      ['uname', uname],
   7.247 -                      ['dev', dev ],
   7.248 -                      ['mode', mode ] ]
   7.249 -        if vbd_expert != 'rr':
   7.250 -            config_vbd.append(['sharing', vbd_expert])
   7.251 -        config_devs.append(['device', config_vbd])
   7.252 -
   7.253 -    for (bus, dev, func) in pci_device_list:
   7.254 -        config_pci = ['pci',
   7.255 -                      ['bus', bus ],
   7.256 -                      ['dev', dev ],
   7.257 -                      ['func', func] ]
   7.258 -        config_devs.append(['device', config_pci])
   7.259 -
   7.260 -    # Add one vif with unspecified MAC.
   7.261 -    config_devs.append(['device', ['vif']])
   7.262 -
   7.263 -    config += config_devs
   7.264 -    
   7.265 -    config_vfr = ['vfr']
   7.266 -    idx = 0 # No way of saying which IP is for which vif?
   7.267 -    for ip in vfr_ipaddr:
   7.268 -        config_vfr.append(['vif', ['id', idx], ['ip', ip]])
   7.269 -
   7.270 -    config.append(config_vfr)
   7.271 -    return config
   7.272 -
   7.273 -def parse_config_file(domain_file):
   7.274 -    config = None
   7.275 -    fin = None
   7.276 -    try:
   7.277 -        fin = file(domain_file, "rb")
   7.278 -        config = sxp.parse(fin)
   7.279 -        if len(config) >= 1:
   7.280 -            config = config[0]
   7.281 -        else:
   7.282 -            raise StandardError("Invalid configuration")
   7.283 -    except StandardError, ex:
   7.284 -        print >> sys.stderr, "Error :", ex
   7.285 -        sys.exit(1)
   7.286 -    #finally:
   7.287 -    if fin: fin.close()
   7.288 -    return config
   7.289 -
   7.290 -# This function creates, builds and starts a domain, using the values
   7.291 -# in the global variables, set above.  It is used in the subsequent
   7.292 -# code for starting the new domain and rebooting it if appropriate.
   7.293 -def make_domain(config):
   7.294 -    """Create, build and start a domain.
   7.295 -    Returns: [int] the ID of the new domain.
   7.296 -    """
   7.297 -    global restore
   7.298 -
   7.299 -    if restore:
   7.300 -        dominfo = server.xend_domain_restore(state_file, config)
   7.301 -    else:
   7.302 -        dominfo = server.xend_domain_create(config)
   7.303 -
   7.304 -    dom = int(sxp.child_value(dominfo, 'id'))
   7.305 -    console_info = sxp.child(dominfo, 'console')
   7.306 -    if console_info:
   7.307 -        console_port = int(sxp.child_value(console_info, 'port'))
   7.308 -    else:
   7.309 -        console_port = None
   7.310 -    
   7.311 -    if server.xend_domain_unpause(dom) < 0:
   7.312 -        print "Error starting domain"
   7.313 -        server.xend_domain_halt(dom)
   7.314 -        sys.exit()
   7.315 -
   7.316 -    return (dom, console_port)
   7.317 -
   7.318 -PID_DIR = '/var/run/xendomains/'
   7.319 -
   7.320 -def pidfile(dom):
   7.321 -    return PID_DIR + '%d.pid' % dom
   7.322 -
   7.323 -def mkpidfile():
   7.324 -    global current_id
   7.325 -    if not os.path.isdir(PID_DIR):
   7.326 -        os.mkdir(PID_DIR)
   7.327 -
   7.328 -    fd = open(pidfile(current_id), 'w')
   7.329 -    print >> fd, str(os.getpid())
   7.330 -    fd.close()
   7.331 -    return
   7.332 -
   7.333 -def rmpidfile():
   7.334 -    global current_id
   7.335 -    os.unlink(pidfile(current_id))
   7.336 -
   7.337 -def death_handler(dummy1,dummy2):
   7.338 -    global current_id
   7.339 -    os.unlink(pidfile(current_id))
   7.340 -    output('Auto-restart daemon: daemon PID = %d for domain %d is now exiting'
   7.341 -              % (os.getpid(), current_id))
   7.342 -    sys.exit(0)
   7.343 -    return
   7.344 -
   7.345 -#============================================================================
   7.346 -# The starting / monitoring of the domain actually happens here...
   7.347 -
   7.348 -if config_from_file:
   7.349 -    config = parse_config_file(domain_config)
   7.350 -else:
   7.351 -    config = make_domain_config()
   7.352 -
   7.353 -if dryrun:
   7.354 -    print "# %s" % ' '.join(sys.argv)
   7.355 -    PrettyPrint.prettyprint(config)
   7.356 -    sys.exit(0)
   7.357 -elif quiet:
   7.358 -    pass
   7.359 -else:
   7.360 -    PrettyPrint.prettyprint(config)
   7.361 -
   7.362 -# start the domain and record its ID number
   7.363 -(current_id, current_port) = make_domain(config)
   7.364 -
   7.365 -def start_msg(prefix, dom, port):
   7.366 -    output(prefix + "VM started in domain %d" % dom)
   7.367 -    if port:
   7.368 -        output(prefix + "Console I/O available on TCP port %d." % port)
   7.369 -
   7.370 -start_msg('', current_id, current_port)
   7.371 -
   7.372 -if current_port and auto_console:
   7.373 -    xenctl.console_client.connect('127.0.0.1', current_port)
   7.374 -
   7.375 -# if the auto_restart flag is set then keep polling to see if the domain is
   7.376 -# alive - restart if it is not by calling make_domain() again (it's necessary
   7.377 -# to update the id variable, since the new domain may have a new ID)
   7.378 -
   7.379 -#todo: Replace this - get xend to watch them.
   7.380 -if auto_restart:
   7.381 -    ARD = "Auto-restart daemon: "
   7.382 -    # turn ourselves into a background daemon
   7.383 -    try:
   7.384 -	pid = os.fork()
   7.385 -	if pid > 0:
   7.386 -	    sys.exit(0)
   7.387 -	os.setsid()
   7.388 -	pid = os.fork()
   7.389 -	if pid > 0:
   7.390 -            output(ARD + 'PID = %d' % pid)
   7.391 -	    sys.exit(0)
   7.392 -        signal.signal(signal.SIGTERM,death_handler)
   7.393 -    except OSError:
   7.394 -	print >> sys.stderr, ARD+'Startup failed'
   7.395 -	sys.exit(1)
   7.396 -
   7.397 -    mkpidfile()
   7.398 -
   7.399 -    while True:
   7.400 -	time.sleep(1)
   7.401 -        # todo: use new interface
   7.402 -        info = xc.domain_getinfo(current_id, 1)
   7.403 -	if info == [] or info[0]['dom'] != current_id:
   7.404 -	    output(ARD + "Domain %d terminated, restarting VM in new domain"
   7.405 -                                     % current_id)
   7.406 -            rmpidfile()
   7.407 -	    (current_id, current_port) = make_domain()
   7.408 -            mkpidfile()
   7.409 -            start_msg(ARD, current_id, current_port)
     8.1 --- a/tools/examples/xmdefaults	Tue Jun 29 14:14:38 2004 +0000
     8.2 +++ b/tools/examples/xmdefaults	Tue Jun 29 19:45:18 2004 +0000
     8.3 @@ -16,7 +16,7 @@ if vmid <= 0:
     8.4  
     8.5  #----------------------------------------------------------------------------
     8.6  # Kernel image file.
     8.7 -kernel = "../../../install/boot/vmlinuz-2.4.26-xen"
     8.8 +kernel = "../../../install/boot/vmlinuz-2.4.26-xenU"
     8.9  
    8.10  # Optional ramdisk.
    8.11  #ramdisk = "/boot/initrd.gz"
     9.1 --- a/tools/lib/allocate.c	Tue Jun 29 14:14:38 2004 +0000
     9.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.3 @@ -1,116 +0,0 @@
     9.4 -/*
     9.5 - * Copyright (C) 2001 - 2004 Mike Wray <mike.wray@hp.com>
     9.6 - *
     9.7 - * This library is free software; you can redistribute it and/or modify
     9.8 - * it under the terms of the GNU Lesser General Public License as published by
     9.9 - * the Free Software Foundation; either version 2.1 of the License, or
    9.10 - * (at your option) any later version.
    9.11 - *
    9.12 - * This library is distributed in the hope that it will be useful,
    9.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
    9.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    9.15 - * GNU Lesser General Public License for more details.
    9.16 - *
    9.17 - * You should have received a copy of the GNU Lesser General Public License
    9.18 - * along with this library; if not, write to the Free Software
    9.19 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    9.20 - */
    9.21 -
    9.22 -#include "allocate.h"
    9.23 -
    9.24 -/** @file
    9.25 - * Support for allocating memory.
    9.26 - * Usable from user code or kernel code (with __KERNEL__ defined).
    9.27 - * In user code will use GC if USE_GC is defined.
    9.28 - */
    9.29 -
    9.30 -#ifdef __KERNEL__
    9.31 -/*----------------------------------------------------------------------------*/
    9.32 -#  include <linux/config.h>
    9.33 -#  include <linux/slab.h>
    9.34 -#  include <linux/string.h>
    9.35 -#  include <linux/types.h>
    9.36 -
    9.37 -#  define DEFAULT_TYPE    0
    9.38 -#  define MALLOC(n, type) kmalloc(n, type)
    9.39 -#  define FREE(ptr)       kfree(ptr)
    9.40 -
    9.41 -/*----------------------------------------------------------------------------*/
    9.42 -#else /* ! __KERNEL__ */
    9.43 -
    9.44 -#  include <stdlib.h>
    9.45 -#  include <string.h>
    9.46 -
    9.47 -#  define DEFAULT_TYPE    0
    9.48 -
    9.49 -#ifdef USE_GC
    9.50 -#  include "gc.h"
    9.51 -#  define MALLOC(n, typ)  GC_malloc(n)
    9.52 -#  define FREE(ptr)       (ptr=NULL)
    9.53 -//typedef void *GC_PTR;
    9.54 -//GC_PTR (*GC_oom_fn)(size_t n);
    9.55 -#else
    9.56 -#  define MALLOC(n, type) malloc(n)
    9.57 -#  define FREE(ptr)       free(ptr)
    9.58 -#endif
    9.59 -
    9.60 -/*----------------------------------------------------------------------------*/
    9.61 -#endif
    9.62 -
    9.63 -/** Function to call when memory cannot be allocated. */
    9.64 -AllocateFailedFn *allocate_failed_fn = NULL;
    9.65 -
    9.66 -/** Allocate memory and zero it.
    9.67 - * The type is only relevant when calling from kernel code,
    9.68 - * from user code it is ignored.
    9.69 - * In kernel code the values accepted by kmalloc can be used:
    9.70 - * GFP_USER, GFP_ATOMIC, GFP_KERNEL.
    9.71 - *
    9.72 - * @param size number of bytes to allocate
    9.73 - * @param type memory type to allocate (kernel only)
    9.74 - * @return pointer to the allocated memory or zero
    9.75 - * if malloc failed
    9.76 - */
    9.77 -void *allocate_type(int size, int type){
    9.78 -    void *p = MALLOC(size, type);
    9.79 -    if(p){
    9.80 -        memzero(p, size);
    9.81 -    } else if(allocate_failed_fn){
    9.82 -        allocate_failed_fn(size, type);
    9.83 -    }
    9.84 -    return p;
    9.85 -}
    9.86 -
    9.87 -/** Allocate memory and zero it.
    9.88 - *
    9.89 - * @param size number of bytes to allocate
    9.90 - * @return pointer to the allocated memory or zero
    9.91 - * if malloc failed
    9.92 - */
    9.93 -void *allocate(int size){
    9.94 -    return allocate_type(size, DEFAULT_TYPE);
    9.95 -}
    9.96 -
    9.97 -/** Free memory allocated by allocate().
    9.98 - * No-op if 'p' is null.
    9.99 - *
   9.100 - * @param p memory to free
   9.101 - */
   9.102 -void deallocate(void *p){
   9.103 -    if(p){
   9.104 -        FREE(p);
   9.105 -    }
   9.106 -}
   9.107 -
   9.108 -/** Set bytes to zero.
   9.109 - * No-op if 'p' is null.
   9.110 - *
   9.111 - * @param p memory to zero
   9.112 - * @param size number of bytes to zero
   9.113 - */
   9.114 -void memzero(void *p, int size){
   9.115 -    if(p){
   9.116 -        memset(p, 0, (size_t)size);
   9.117 -    }
   9.118 -}
   9.119 -
    10.1 --- a/tools/lib/allocate.h	Tue Jun 29 14:14:38 2004 +0000
    10.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.3 @@ -1,45 +0,0 @@
    10.4 -/*
    10.5 - * Copyright (C) 2001 - 2004 Mike Wray <mike.wray@hp.com>
    10.6 - *
    10.7 - * This library is free software; you can redistribute it and/or modify
    10.8 - * it under the terms of the GNU Lesser General Public License as published by
    10.9 - * the Free Software Foundation; either version 2.1 of the License, or
   10.10 - * (at your option) any later version.
   10.11 - *
   10.12 - * This library is distributed in the hope that it will be useful,
   10.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
   10.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   10.15 - * GNU Lesser General Public License for more details.
   10.16 - *
   10.17 - * You should have received a copy of the GNU Lesser General Public License
   10.18 - * along with this library; if not, write to the Free Software
   10.19 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   10.20 - */
   10.21 -
   10.22 -#ifndef _XEN_LIB_ALLOCATE_H_
   10.23 -#define _XEN_LIB_ALLOCATE_H_
   10.24 -
   10.25 -/** Allocate memory for a given type, and cast. */
   10.26 -#define ALLOCATE(ctype) (ctype *)allocate(sizeof(ctype))
   10.27 -
   10.28 -/** Allocate memory for a given type, and cast. */
   10.29 -#define ALLOCATE_TYPE(ctype, type) (ctype *)allocate(sizeof(ctype))
   10.30 -
   10.31 -extern void *allocate_type(int size, int type);
   10.32 -extern void *allocate(int size);
   10.33 -extern void deallocate(void *);
   10.34 -extern void memzero(void *p, int size);
   10.35 -
   10.36 -typedef void AllocateFailedFn(int size, int type);
   10.37 -extern AllocateFailedFn *allocate_failed_fn;
   10.38 -
   10.39 -#endif /* _XEN_LIB_ALLOCATE_H_ */
   10.40 -
   10.41 -
   10.42 -
   10.43 -
   10.44 -
   10.45 -
   10.46 -
   10.47 -
   10.48 -
    11.1 --- a/tools/lib/debug.h	Tue Jun 29 14:14:38 2004 +0000
    11.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.3 @@ -1,72 +0,0 @@
    11.4 -/*
    11.5 - * Copyright (C) 2004 Mike Wray <mike.wray@hp.com>
    11.6 - *
    11.7 - * This library is free software; you can redistribute it and/or modify
    11.8 - * it under the terms of the GNU Lesser General Public License as published by
    11.9 - * the Free Software Foundation; either version 2.1 of the License, or
   11.10 - * (at your option) any later version.
   11.11 - *
   11.12 - * This library is distributed in the hope that it will be useful,
   11.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
   11.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   11.15 - * GNU Lesser General Public License for more details.
   11.16 - *
   11.17 - * You should have received a copy of the GNU Lesser General Public License
   11.18 - * along with this library; if not, write to the Free Software
   11.19 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   11.20 - */
   11.21 -#ifndef _XEN_LIB_DEBUG_H_
   11.22 -#define _XEN_LIB_DEBUG_H_
   11.23 -
   11.24 -#ifndef MODULE_NAME
   11.25 -#define MODULE_NAME ""
   11.26 -#endif
   11.27 -
   11.28 -#ifdef __KERNEL__
   11.29 -#include <linux/config.h>
   11.30 -#include <linux/kernel.h>
   11.31 -
   11.32 -#ifdef DEBUG
   11.33 -
   11.34 -#define dprintf(fmt, args...) printk(KERN_DEBUG   "[DBG] " MODULE_NAME ">%s" fmt, __FUNCTION__, ##args)
   11.35 -#define wprintf(fmt, args...) printk(KERN_WARNING "[WRN] " MODULE_NAME ">%s" fmt, __FUNCTION__, ##args)
   11.36 -#define iprintf(fmt, args...) printk(KERN_INFO    "[INF] " MODULE_NAME ">%s" fmt, __FUNCTION__, ##args)
   11.37 -#define eprintf(fmt, args...) printk(KERN_ERR     "[ERR] " MODULE_NAME ">%s" fmt, __FUNCTION__, ##args)
   11.38 -
   11.39 -#else
   11.40 -
   11.41 -#define dprintf(fmt, args...) do {} while(0)
   11.42 -#define wprintf(fmt, args...) printk(KERN_WARNING "[WRN] " MODULE_NAME fmt, ##args)
   11.43 -#define iprintf(fmt, args...) printk(KERN_INFO    "[INF] " MODULE_NAME fmt, ##args)
   11.44 -#define eprintf(fmt, args...) printk(KERN_ERR     "[ERR] " MODULE_NAME fmt, ##args)
   11.45 -
   11.46 -#endif
   11.47 -
   11.48 -#else
   11.49 -
   11.50 -#include <stdio.h>
   11.51 -
   11.52 -#ifdef DEBUG
   11.53 -
   11.54 -#define dprintf(fmt, args...) fprintf(stdout, "[DBG] " MODULE_NAME ">%s" fmt, __FUNCTION__, ##args)
   11.55 -#define wprintf(fmt, args...) fprintf(stderr, "[WRN] " MODULE_NAME ">%s" fmt, __FUNCTION__, ##args)
   11.56 -#define iprintf(fmt, args...) fprintf(stderr, "[INF] " MODULE_NAME ">%s" fmt, __FUNCTION__, ##args)
   11.57 -#define eprintf(fmt, args...) fprintf(stderr, "[ERR] " MODULE_NAME ">%s" fmt, __FUNCTION__, ##args)
   11.58 -
   11.59 -#else
   11.60 -
   11.61 -#define dprintf(fmt, args...) do {} while(0)
   11.62 -#define wprintf(fmt, args...) fprintf(stderr, "[WRN] " MODULE_NAME fmt, ##args)
   11.63 -#define iprintf(fmt, args...) fprintf(stderr, "[INF] " MODULE_NAME fmt, ##args)
   11.64 -#define eprintf(fmt, args...) fprintf(stderr, "[ERR] " MODULE_NAME fmt, ##args)
   11.65 -
   11.66 -#endif
   11.67 -
   11.68 -#endif
   11.69 -
   11.70 -/** Print format for an IP address.
   11.71 - * See NIPQUAD(), HIPQUAD()
   11.72 - */
   11.73 -#define IPFMT "%u.%u.%u.%u"
   11.74 -
   11.75 -#endif /* ! _XEN_LIB_DEBUG_H_ */
    12.1 --- a/tools/lib/enum.c	Tue Jun 29 14:14:38 2004 +0000
    12.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.3 @@ -1,61 +0,0 @@
    12.4 -/*
    12.5 - * Copyright (C) 2002, 2004 Mike Wray <mike.wray@hp.com>
    12.6 - *
    12.7 - * This library is free software; you can redistribute it and/or modify
    12.8 - * it under the terms of the GNU Lesser General Public License as
    12.9 - * published by the Free Software Foundation; either version 2.1 of the
   12.10 - * License, or  (at your option) any later version. This library is 
   12.11 - * distributed in the  hope that it will be useful, but WITHOUT ANY
   12.12 - * WARRANTY; without even the implied warranty of MERCHANTABILITY or
   12.13 - * FITNESS FOR A PARTICULAR PURPOSE.
   12.14 - * See the GNU Lesser General Public License for more details.
   12.15 - *
   12.16 - * You should have received a copy of the GNU Lesser General Public License
   12.17 - * along with this library; if not, write to the Free Software Foundation,
   12.18 - * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
   12.19 - */
   12.20 -
   12.21 -#ifdef __KERNEL__
   12.22 -#include <linux/errno.h>
   12.23 -#else
   12.24 -#include <errno.h>
   12.25 -#endif
   12.26 -
   12.27 -#include "sys_string.h"
   12.28 -#include "enum.h"
   12.29 -
   12.30 -/** Map an enum name to its value using a table.
   12.31 - *
   12.32 - * @param name enum name
   12.33 - * @param defs enum definitions
   12.34 - * @return enum value or -1 if not known
   12.35 - */
   12.36 -int enum_name_to_val(char *name, EnumDef *defs){
   12.37 -    int val = -1;
   12.38 -    for(; defs->name; defs++){
   12.39 -	if(!strcmp(defs->name, name)){
   12.40 -	    val = defs->val;
   12.41 -	    break;
   12.42 -	}
   12.43 -    }
   12.44 -    return val;
   12.45 -}
   12.46 -
   12.47 -/** Map an enum value to its name using a table.
   12.48 - *
   12.49 - * @param val enum value
   12.50 - * @param defs enum definitions
   12.51 - * @param defs_n number of definitions
   12.52 - * @return enum name or NULL if not known
   12.53 - */
   12.54 -char *enum_val_to_name(int val, EnumDef *defs){
   12.55 -    char *name = NULL;
   12.56 -    for(; defs->name; defs++){
   12.57 -	if(val == defs->val){
   12.58 -	    name = defs->name;
   12.59 -	    break;
   12.60 -	}
   12.61 -    }
   12.62 -    return name;
   12.63 -}
   12.64 -
    13.1 --- a/tools/lib/enum.h	Tue Jun 29 14:14:38 2004 +0000
    13.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.3 @@ -1,30 +0,0 @@
    13.4 -/*
    13.5 - * Copyright (C) 2002, 2004 Mike Wray <mike.wray@hp.com>
    13.6 - *
    13.7 - * This library is free software; you can redistribute it and/or modify
    13.8 - * it under the terms of the GNU Lesser General Public License as
    13.9 - * published by the Free Software Foundation; either version 2.1 of the
   13.10 - * License, or  (at your option) any later version. This library is 
   13.11 - * distributed in the  hope that it will be useful, but WITHOUT ANY
   13.12 - * WARRANTY; without even the implied warranty of MERCHANTABILITY or
   13.13 - * FITNESS FOR A PARTICULAR PURPOSE.
   13.14 - * See the GNU Lesser General Public License for more details.
   13.15 - *
   13.16 - * You should have received a copy of the GNU Lesser General Public License
   13.17 - * along with this library; if not, write to the Free Software Foundation,
   13.18 - * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
   13.19 - */
   13.20 -
   13.21 -#ifndef _XEN_LIB_ENUM_H_
   13.22 -#define _XEN_LIB_ENUM_H_
   13.23 -
   13.24 -/** Mapping of an enum value to a name. */
   13.25 -typedef struct EnumDef {
   13.26 -    int val;
   13.27 -    char *name;
   13.28 -} EnumDef;
   13.29 -
   13.30 -extern int enum_name_to_val(char *name, EnumDef *defs);
   13.31 -extern char *enum_val_to_name(int val, EnumDef *defs);
   13.32 -
   13.33 -#endif /* _XEN_LIB_ENUM_H_ */
    14.1 --- a/tools/lib/file_stream.c	Tue Jun 29 14:14:38 2004 +0000
    14.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    14.3 @@ -1,202 +0,0 @@
    14.4 -/*
    14.5 - * Copyright (C) 2001 - 2004 Mike Wray <mike.wray@hp.com>
    14.6 - *
    14.7 - * This library is free software; you can redistribute it and/or modify
    14.8 - * it under the terms of the GNU Lesser General Public License as published by
    14.9 - * the Free Software Foundation; either version 2.1 of the License, or
   14.10 - * (at your option) any later version.
   14.11 - *
   14.12 - * This library is distributed in the hope that it will be useful,
   14.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
   14.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   14.15 - * GNU Lesser General Public License for more details.
   14.16 - *
   14.17 - * You should have received a copy of the GNU Lesser General Public License
   14.18 - * along with this library; if not, write to the Free Software
   14.19 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   14.20 - */
   14.21 -
   14.22 -/** @file
   14.23 - * An IOStream implementation using FILE*.
   14.24 - */
   14.25 -#ifndef __KERNEL__
   14.26 -#include <stdio.h>
   14.27 -#include <stdlib.h>
   14.28 -#include "allocate.h"
   14.29 -#include "file_stream.h"
   14.30 -
   14.31 -static int file_read(IOStream *s, void *buf, size_t n);
   14.32 -static int file_write(IOStream *s, const void *buf, size_t n);
   14.33 -static int file_error(IOStream *s);
   14.34 -static int file_close(IOStream *s);
   14.35 -static void file_free(IOStream *s);
   14.36 -static int file_flush(IOStream *s);
   14.37 -
   14.38 -/** Methods used by a FILE* IOStream. */
   14.39 -static const IOMethods file_methods = {
   14.40 -    read:  file_read,
   14.41 -    write: file_write,
   14.42 -    error: file_error,
   14.43 -    close: file_close,
   14.44 -    free:  file_free,
   14.45 -    flush: file_flush,
   14.46 -};
   14.47 -
   14.48 -/** IOStream for stdin. */
   14.49 -static IOStream _iostdin = {
   14.50 -    methods: &file_methods,
   14.51 -    data: (void*)1,
   14.52 -};
   14.53 -
   14.54 -/** IOStream for stdout. */
   14.55 -static IOStream _iostdout = {
   14.56 -    methods: &file_methods,
   14.57 -    data: (void*)2,
   14.58 -};
   14.59 -
   14.60 -/** IOStream for stderr. */
   14.61 -static IOStream _iostderr = {
   14.62 -    methods: &file_methods,
   14.63 -    data: (void*)3,
   14.64 -};
   14.65 -
   14.66 -/** IOStream for stdin. */
   14.67 -IOStream *iostdin = &_iostdin;
   14.68 -
   14.69 -/** IOStream for stdout. */
   14.70 -IOStream *iostdout = &_iostdout;
   14.71 -
   14.72 -/** IOStream for stderr. */
   14.73 -IOStream *iostderr = &_iostderr;
   14.74 -
   14.75 -/** Get the underlying FILE*.
   14.76 - * 
   14.77 - * @param s file stream
   14.78 - * @return the stream s wraps
   14.79 - */
   14.80 -static inline FILE *get_file(IOStream *s){
   14.81 -    switch((long)s->data){
   14.82 -    case 1: s->data = stdin; break;
   14.83 -    case 2: s->data = stdout; break;
   14.84 -    case 3: s->data = stderr; break;
   14.85 -    }
   14.86 -    return (FILE*)s->data;
   14.87 -}
   14.88 -
   14.89 -/** Control buffering on the underlying stream, like setvbuf().
   14.90 - *
   14.91 - * @param io file stream
   14.92 - * @param buf buffer
   14.93 - * @param mode buffering mode (see man setvbuf())
   14.94 - * @param size buffer size
   14.95 - * @return 0 on success, non-zero otherwise
   14.96 - */
   14.97 -int file_stream_setvbuf(IOStream *io, char *buf, int mode, size_t size){
   14.98 -    return setvbuf(get_file(io), buf, mode, size);
   14.99 -}
  14.100 -
  14.101 -/** Write to the underlying stream using fwrite();
  14.102 - *
  14.103 - * @param stream input
  14.104 - * @param buf where to put input
  14.105 - * @param n number of bytes to write
  14.106 - * @return number of bytes written
  14.107 - */
  14.108 -static int file_write(IOStream *s, const void *buf, size_t n){
  14.109 -    return fwrite(buf, 1, n, get_file(s));
  14.110 -}
  14.111 -
  14.112 -/** Read from the underlying stream using fread();
  14.113 - *
  14.114 - * @param stream input
  14.115 - * @param buf where to put input
  14.116 - * @param n number of bytes to read
  14.117 - * @return number of bytes read
  14.118 - */
  14.119 -static int file_read(IOStream *s, void *buf, size_t n){
  14.120 -    return fread(buf, 1, n, get_file(s));
  14.121 -}
  14.122 -
  14.123 -/** Fush the underlying stream using fflush().
  14.124 - *
  14.125 - * @param s file stream
  14.126 - * @return 0 on success, error code otherwise
  14.127 - */
  14.128 -static int file_flush(IOStream *s){
  14.129 -    return fflush(get_file(s));
  14.130 -}
  14.131 -
  14.132 -/** Check if a stream has an error.
  14.133 - *
  14.134 - * @param s file stream
  14.135 - * @return 1 if has an error, 0 otherwise
  14.136 - */
  14.137 -static int file_error(IOStream *s){
  14.138 -    return ferror(get_file(s));
  14.139 -}
  14.140 -
  14.141 -/** Close a file stream.
  14.142 - *
  14.143 - * @param s file stream to close
  14.144 - * @return result of the close
  14.145 - */
  14.146 -static int file_close(IOStream *s){
  14.147 -    return fclose(get_file(s));
  14.148 -}
  14.149 -
  14.150 -/** Free a file stream.
  14.151 - *
  14.152 - * @param s file stream
  14.153 - */
  14.154 -static void file_free(IOStream *s){
  14.155 -    // Do nothing - fclose does it all?
  14.156 -}
  14.157 -
  14.158 -/** Create an IOStream for a stream.
  14.159 - *
  14.160 - * @param f stream to wrap
  14.161 - * @return new IOStream using f for i/o
  14.162 - */
  14.163 -IOStream *file_stream_new(FILE *f){
  14.164 -    IOStream *io = ALLOCATE(IOStream);
  14.165 -    if(io){
  14.166 -	io->methods = &file_methods;
  14.167 -	io->data = (void*)f;
  14.168 -    }
  14.169 -    return io;
  14.170 -}
  14.171 -
  14.172 -/** IOStream version of fopen().
  14.173 - *
  14.174 - * @param file name of the file to open
  14.175 - * @param flags giving the mode to open in (as for fopen())
  14.176 - * @return new stream for the open file, or 0 if failed
  14.177 - */
  14.178 -IOStream *file_stream_fopen(const char *file, const char *flags){
  14.179 -    IOStream *io = 0;
  14.180 -    FILE *fin = fopen(file, flags);
  14.181 -    if(fin){
  14.182 -	io = file_stream_new(fin);
  14.183 -	if(!io){
  14.184 -	    fclose(fin);
  14.185 -	    //free(fin); // fclose frees ?
  14.186 -	}
  14.187 -    }
  14.188 -    return io;
  14.189 -}
  14.190 -
  14.191 -/** IOStream version of fdopen().
  14.192 - *
  14.193 - * @param fd file descriptor
  14.194 - * @param flags giving the mode to open in (as for fdopen())
  14.195 - * @return new stream for the open file, or 0 if failed
  14.196 - */
  14.197 -IOStream *file_stream_fdopen(int fd, const char *flags){
  14.198 -    IOStream *io = 0;
  14.199 -    FILE *fin = fdopen(fd, flags);
  14.200 -    if(fin){
  14.201 -	io = file_stream_new(fin);
  14.202 -    }
  14.203 -    return io;
  14.204 -}
  14.205 -#endif
    15.1 --- a/tools/lib/file_stream.h	Tue Jun 29 14:14:38 2004 +0000
    15.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    15.3 @@ -1,35 +0,0 @@
    15.4 -/*
    15.5 - * Copyright (C) 2001 - 2004 Mike Wray <mike.wray@hp.com>
    15.6 - *
    15.7 - * This library is free software; you can redistribute it and/or modify
    15.8 - * it under the terms of the GNU Lesser General Public License as published by
    15.9 - * the Free Software Foundation; either version 2.1 of the License, or
   15.10 - * (at your option) any later version.
   15.11 - *
   15.12 - * This library is distributed in the hope that it will be useful,
   15.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
   15.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   15.15 - * GNU Lesser General Public License for more details.
   15.16 - *
   15.17 - * You should have received a copy of the GNU Lesser General Public License
   15.18 - * along with this library; if not, write to the Free Software
   15.19 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   15.20 - */
   15.21 -
   15.22 -#ifndef _XEN_LIB_FILE_STREAM_H_
   15.23 -#define _XEN_LIB_FILE_STREAM_H_
   15.24 -
   15.25 -#ifndef __KERNEL__
   15.26 -#include "iostream.h"
   15.27 -#include <stdio.h>
   15.28 -
   15.29 -extern IOStream *file_stream_new(FILE *f);
   15.30 -extern IOStream *file_stream_fopen(const char *file, const char *flags);
   15.31 -extern IOStream *file_stream_fdopen(int fd, const char *flags);
   15.32 -extern IOStream get_stream_stdout(void);
   15.33 -extern IOStream get_stream_stderr(void);
   15.34 -extern IOStream get_stream_stdin(void);
   15.35 -
   15.36 -extern int file_stream_setvbuf(IOStream *io, char *buf, int mode, size_t size);
   15.37 -#endif
   15.38 -#endif /* !_XEN_LIB_FILE_STREAM_H_ */
    16.1 --- a/tools/lib/gzip_stream.c	Tue Jun 29 14:14:38 2004 +0000
    16.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    16.3 @@ -1,171 +0,0 @@
    16.4 -/* $Id: gzip_stream.c,v 1.4 2003/09/30 15:22:53 mjw Exp $ */
    16.5 -/*
    16.6 - * Copyright (C) 2003 Hewlett-Packard Company.
    16.7 - *
    16.8 - * This library is free software; you can redistribute it and/or modify
    16.9 - * it under the terms of the GNU Lesser General Public License as published by
   16.10 - * the Free Software Foundation; either version 2.1 of the License, or
   16.11 - * (at your option) any later version.
   16.12 - *
   16.13 - * This library is distributed in the hope that it will be useful,
   16.14 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
   16.15 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   16.16 - * GNU Lesser General Public License for more details.
   16.17 - *
   16.18 - * You should have received a copy of the GNU Lesser General Public License
   16.19 - * along with this library; if not, write to the Free Software
   16.20 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   16.21 - */
   16.22 -
   16.23 -/** @file
   16.24 - * An IOStream implementation using zlib gzFile to provide
   16.25 - * compression and decompression.
   16.26 - */
   16.27 -#ifndef __KERNEL__
   16.28 -
   16.29 -#include <stdio.h>
   16.30 -#include <stdlib.h>
   16.31 -
   16.32 -#include "zlib.h"
   16.33 -
   16.34 -#include "allocate.h"
   16.35 -#include "gzip_stream.h"
   16.36 -
   16.37 -static int gzip_read(IOStream *s, void *buf, size_t n);
   16.38 -static int gzip_write(IOStream *s, const void *buf, size_t n);
   16.39 -static int gzip_error(IOStream *s);
   16.40 -static int gzip_close(IOStream *s);
   16.41 -static void gzip_free(IOStream *s);
   16.42 -static int gzip_flush(IOStream *s);
   16.43 -
   16.44 -/** Methods used by a gzFile* IOStream. */
   16.45 -static const IOMethods gzip_methods = {
   16.46 -    read: gzip_read,
   16.47 -    write: gzip_write,
   16.48 -    error: gzip_error,
   16.49 -    close: gzip_close,
   16.50 -    free:  gzip_free,
   16.51 -    flush: gzip_flush,
   16.52 -};
   16.53 -
   16.54 -/** Get the underlying gzFile*.
   16.55 - * 
   16.56 - * @param s gzip stream
   16.57 - * @return the stream s wraps
   16.58 - */
   16.59 -static inline gzFile get_gzfile(IOStream *s){
   16.60 -    return (gzFile)s->data;
   16.61 -}
   16.62 -
   16.63 -/** Write to the underlying stream.
   16.64 - *
   16.65 - * @param stream destination
   16.66 - * @param buf data
   16.67 - * @param n number of bytes to write
   16.68 - * @return number of bytes written
   16.69 - */
   16.70 -static int gzip_write(IOStream *s, const void *buf, size_t n){
   16.71 -    return gzwrite(get_gzfile(s), (void*)buf, n);
   16.72 -}
   16.73 -
   16.74 -/** Read from the underlying stream.
   16.75 - *
   16.76 - * @param stream input
   16.77 - * @param buf where to put input
   16.78 - * @param n number of bytes to read
   16.79 - * @return number of bytes read
   16.80 - */
   16.81 -static int gzip_read(IOStream *s, void *buf, size_t n){
   16.82 -    return gzread(get_gzfile(s), buf, n);
   16.83 -}
   16.84 -
   16.85 -/** Flush the underlying stream.
   16.86 - *
   16.87 - * @param s gzip stream
   16.88 - * @return 0 on success, error code otherwise
   16.89 - */
   16.90 -static int gzip_flush(IOStream *s){
   16.91 -    //return gzflush(get_gzfile(s), Z_NO_FLUSH);
   16.92 -    return gzflush(get_gzfile(s), Z_SYNC_FLUSH);
   16.93 -    //return gzflush(get_gzfile(s), Z_FULL_FLUSH);
   16.94 -}
   16.95 -
   16.96 -/** Check if a stream has an error.
   16.97 - *
   16.98 - * @param s gzip stream
   16.99 - * @return 1 if has an error, 0 otherwise
  16.100 - */
  16.101 -static int gzip_error(IOStream *s){
  16.102 -    int err;
  16.103 -    gzFile *gz = get_gzfile(s);
  16.104 -    gzerror(gz, &err);
  16.105 -    return (err == Z_ERRNO ? 1 /* ferror(gzfile(gz)) */ : err);
  16.106 -}
  16.107 -
  16.108 -/** Close a gzip stream.
  16.109 - *
  16.110 - * @param s gzip stream to close
  16.111 - * @return result of the close
  16.112 - */
  16.113 -static int gzip_close(IOStream *s){
  16.114 -    return gzclose(get_gzfile(s));
  16.115 -}
  16.116 -
  16.117 -/** Free a gzip stream.
  16.118 - *
  16.119 - * @param s gzip stream
  16.120 - */
  16.121 -static void gzip_free(IOStream *s){
  16.122 -    // Do nothing - fclose does it all?
  16.123 -}
  16.124 -
  16.125 -/** Create an IOStream for a gzip stream.
  16.126 - *
  16.127 - * @param f stream to wrap
  16.128 - * @return new IOStream using f for i/o
  16.129 - */
  16.130 -IOStream *gzip_stream_new(gzFile *f){
  16.131 -    IOStream *io = ALLOCATE(IOStream);
  16.132 -    if(io){
  16.133 -	io->methods = &gzip_methods;
  16.134 -	io->data = (void*)f;
  16.135 -    }
  16.136 -    return io;
  16.137 -}
  16.138 -
  16.139 -/** IOStream version of fopen().
  16.140 - *
  16.141 - * @param file name of the file to open
  16.142 - * @param flags giving the mode to open in (as for fopen())
  16.143 - * @return new stream for the open file, or NULL if failed
  16.144 - */
  16.145 -IOStream *gzip_stream_fopen(const char *file, const char *flags){
  16.146 -    IOStream *io = NULL;
  16.147 -    gzFile *fgz;
  16.148 -    fgz = gzopen(file, flags);
  16.149 -    if(fgz){
  16.150 -	io = gzip_stream_new(fgz);
  16.151 -	if(!io){
  16.152 -	    gzclose(fgz);
  16.153 -	    //free(fgz); // gzclose frees ?
  16.154 -	}
  16.155 -    }
  16.156 -    return io;
  16.157 -}
  16.158 -
  16.159 -/** IOStream version of fdopen().
  16.160 - *
  16.161 - * @param fd file descriptor
  16.162 - * @param flags giving the mode to open in (as for fdopen())
  16.163 - * @return new stream for the open file, or NULL if failed
  16.164 - */
  16.165 -IOStream *gzip_stream_fdopen(int fd, const char *flags){
  16.166 -    IOStream *io = NULL;
  16.167 -    gzFile *fgz;
  16.168 -    fgz = gzdopen(fd, flags);
  16.169 -    if(fgz){
  16.170 -	io = gzip_stream_new(fgz);
  16.171 -    }
  16.172 -    return io;
  16.173 -}
  16.174 -#endif
    17.1 --- a/tools/lib/gzip_stream.h	Tue Jun 29 14:14:38 2004 +0000
    17.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    17.3 @@ -1,31 +0,0 @@
    17.4 -#/* $Id: gzip_stream.h,v 1.3 2003/09/30 15:22:53 mjw Exp $ */
    17.5 -/*
    17.6 - * Copyright (C) 2003 Hewlett-Packard Company.
    17.7 - *
    17.8 - * This library is free software; you can redistribute it and/or modify
    17.9 - * it under the terms of the GNU Lesser General Public License as published by
   17.10 - * the Free Software Foundation; either version 2.1 of the License, or
   17.11 - * (at your option) any later version.
   17.12 - *
   17.13 - * This library is distributed in the hope that it will be useful,
   17.14 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
   17.15 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   17.16 - * GNU Lesser General Public License for more details.
   17.17 - *
   17.18 - * You should have received a copy of the GNU Lesser General Public License
   17.19 - * along with this library; if not, write to the Free Software
   17.20 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   17.21 - */
   17.22 -
   17.23 -#ifndef _SP_GZIP_STREAM_H_
   17.24 -#define _SP_GZIP_STREAM_H_
   17.25 -
   17.26 -#ifndef __KERNEL__
   17.27 -#include "iostream.h"
   17.28 -#include "zlib.h"
   17.29 -
   17.30 -extern IOStream *gzip_stream_new(gzFile *f);
   17.31 -extern IOStream *gzip_stream_fopen(const char *file, const char *flags);
   17.32 -extern IOStream *gzip_stream_fdopen(int fd, const char *flags);
   17.33 -#endif
   17.34 -#endif /* !_SP_FILE_STREAM_H_ */
    18.1 --- a/tools/lib/hash_table.c	Tue Jun 29 14:14:38 2004 +0000
    18.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    18.3 @@ -1,640 +0,0 @@
    18.4 -/*
    18.5 - * Copyright (C) 2001 - 2004 Mike Wray <mike.wray@hp.com>
    18.6 - *
    18.7 - * This library is free software; you can redistribute it and/or modify
    18.8 - * it under the terms of the GNU Lesser General Public License as published by
    18.9 - * the Free Software Foundation; either version 2.1 of the License, or
   18.10 - * (at your option) any later version.
   18.11 - *
   18.12 - * This library is distributed in the hope that it will be useful,
   18.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
   18.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   18.15 - * GNU Lesser General Public License for more details.
   18.16 - *
   18.17 - * You should have received a copy of the GNU Lesser General Public License
   18.18 - * along with this library; if not, write to the Free Software
   18.19 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   18.20 - */
   18.21 -
   18.22 -#ifdef __KERNEL__
   18.23 -#  include <linux/config.h>
   18.24 -#  include <linux/module.h>
   18.25 -#  include <linux/kernel.h>
   18.26 -#  include <linux/errno.h>
   18.27 -#else
   18.28 -#  include <errno.h>
   18.29 -#  include <stddef.h>
   18.30 -#endif
   18.31 -
   18.32 -//#include <limits.h>
   18.33 -
   18.34 -#include "allocate.h"
   18.35 -#include "hash_table.h"
   18.36 -
   18.37 -/** @file
   18.38 - * Base support for hashtables.
   18.39 - *
   18.40 - * Hash codes are reduced modulo the number of buckets to index tables,
   18.41 - * so there is no need for hash functions to limit the range of hashcodes.
   18.42 - * In fact it is assumed that hashcodes do not change when the number of
   18.43 - * buckets in the table changes.
   18.44 - */
   18.45 -
   18.46 -/*==========================================================================*/
   18.47 -/** Number of bits in half a word. */
   18.48 -//#if __WORDSIZE == 64
   18.49 -//#define HALF_WORD_BITS 32
   18.50 -//#else
   18.51 -#define HALF_WORD_BITS 16
   18.52 -//#endif
   18.53 -
   18.54 -/** Mask for lo half of a word. On 32-bit this is 
   18.55 - * (1<<16) - 1 = 65535 = 0xffff
   18.56 - * It's 4294967295 = 0xffffffff on 64-bit.
   18.57 - */
   18.58 -#define LO_HALF_MASK ((1 << HALF_WORD_BITS) - 1)
   18.59 -
   18.60 -/** Get the lo half of a word. */
   18.61 -#define LO_HALF(x) ((x) & LO_HALF_MASK)
   18.62 -
   18.63 -/** Get the hi half of a word. */
   18.64 -#define HI_HALF(x) ((x) >> HALF_WORD_BITS)
   18.65 -
   18.66 -/** Do a full hash on both inputs, using DES-style non-linear scrambling.
   18.67 - * Both inputs are replaced with the results of the hash.
   18.68 - *
   18.69 - * @param pleft input/output word
   18.70 - * @param pright input/output word
   18.71 - */
   18.72 -void pseudo_des(unsigned long *pleft, unsigned long *pright){
   18.73 -    // Bit-rich mixing constant.
   18.74 -    static const unsigned long a_mixer[] = {
   18.75 -        0xbaa96887L, 0x1e17d32cL, 0x03bcdc3cL, 0x0f33d1b2L, };
   18.76 -
   18.77 -    // Bit-rich mixing constant.
   18.78 -    static const unsigned long b_mixer[] = {
   18.79 -        0x4b0f3b58L, 0xe874f0c3L, 0x6955c5a6L, 0x55a7ca46L, };
   18.80 -
   18.81 -    // Number of iterations - must be 2 or 4.
   18.82 -    static const int ncycle = 4;
   18.83 -    //static const int ncycle = 2;
   18.84 -
   18.85 -    unsigned long left = *pleft, right = *pright;
   18.86 -    unsigned long v, v_hi, v_lo;
   18.87 -    int i;
   18.88 -
   18.89 -    for(i=0; i<ncycle; i++){
   18.90 -        // Flip some bits in right to get v.
   18.91 -        v = right;
   18.92 -        v ^= a_mixer[i];
   18.93 -        // Get lo and hi halves of v.
   18.94 -        v_lo = LO_HALF(v);
   18.95 -        v_hi = HI_HALF(v);
   18.96 -        // Non-linear mix of the halves of v.
   18.97 -        v = ((v_lo * v_lo) + ~(v_hi * v_hi));
   18.98 -        // Swap the halves of v.
   18.99 -        v = (HI_HALF(v) | (LO_HALF(v) << HALF_WORD_BITS));
  18.100 -        // Flip some bits.
  18.101 -        v ^= b_mixer[i];
  18.102 -        // More non-linear mixing.
  18.103 -        v += (v_lo * v_hi);
  18.104 -        v ^= left;
  18.105 -        left = right;
  18.106 -        right = v;
  18.107 -    }
  18.108 -    *pleft = left;
  18.109 -    *pright = right;
  18.110 -}
  18.111 -
  18.112 -/** Hash a string.
  18.113 - *
  18.114 - * @param s input to hash
  18.115 - * @return hashcode
  18.116 - */
  18.117 -Hashcode hash_string(char *s){
  18.118 -    Hashcode h = 0;
  18.119 -    if(s){
  18.120 -        for( ; *s; s++){
  18.121 -            h = hash_2ul(h, *s);
  18.122 -        }
  18.123 -    }
  18.124 -    return h;
  18.125 -}
  18.126 -
  18.127 -/** Get the bucket for a hashcode in a hash table.
  18.128 - *
  18.129 - * @param table to get bucket from
  18.130 - * @param hashcode to get bucket for
  18.131 - * @return bucket
  18.132 - */
  18.133 -inline HTBucket * get_bucket(HashTable *table, Hashcode hashcode){
  18.134 -    return table->buckets + (hashcode % table->buckets_n);
  18.135 -}
  18.136 -
  18.137 -/** Initialize a hash table.
  18.138 - * Can be safely called more than once.
  18.139 - *
  18.140 - * @param table to initialize
  18.141 - */
  18.142 -void HashTable_init(HashTable *table){
  18.143 -    int i;
  18.144 -
  18.145 -    if(!table->init_done){
  18.146 -        table->init_done = 1;
  18.147 -        table->next_id = 0;
  18.148 -        for(i=0; i<table->buckets_n; i++){
  18.149 -            HTBucket *bucket = get_bucket(table, i);
  18.150 -            bucket->head = 0;
  18.151 -            bucket->count = 0;
  18.152 -        }
  18.153 -        table->entry_count = 0;
  18.154 -    }
  18.155 -}
  18.156 -
  18.157 -/** Allocate a new hashtable.
  18.158 - * If the number of buckets is not positive the default is used.
  18.159 - * The number of buckets should usually be prime.
  18.160 - *
  18.161 - * @param buckets_n number of buckets
  18.162 - * @return new hashtable or null
  18.163 - */
  18.164 -HashTable *HashTable_new(int buckets_n){
  18.165 -    HashTable *z = ALLOCATE(HashTable);
  18.166 -    if(!z) goto exit;
  18.167 -    if(buckets_n <= 0){
  18.168 -        buckets_n = HT_BUCKETS_N;
  18.169 -    }
  18.170 -    z->buckets = (HTBucket*)allocate(buckets_n * sizeof(HTBucket));
  18.171 -    if(!z->buckets){
  18.172 -        deallocate(z);
  18.173 -        z = 0;
  18.174 -        goto exit;
  18.175 -    }
  18.176 -    z->buckets_n = buckets_n;
  18.177 -    HashTable_init(z);
  18.178 -  exit:
  18.179 -    return z;
  18.180 -}
  18.181 -
  18.182 -/** Free a hashtable.
  18.183 - * Any entries are removed and freed.
  18.184 - *
  18.185 - * @param h hashtable (ignored if null)
  18.186 - */
  18.187 -void HashTable_free(HashTable *h){
  18.188 -    if(h){
  18.189 -        HashTable_clear(h);
  18.190 -        deallocate(h->buckets);
  18.191 -        deallocate(h);
  18.192 -    }
  18.193 -}
  18.194 -
  18.195 -/** Push an entry on the list in the bucket for a given hashcode.
  18.196 - *
  18.197 - * @param table to add entry to
  18.198 - * @param hashcode for the entry
  18.199 - * @param entry to add
  18.200 - */
  18.201 -static inline void push_on_bucket(HashTable *table, Hashcode hashcode,
  18.202 -				  HTEntry *entry){
  18.203 -    HTBucket *bucket;
  18.204 -    HTEntry *old_head;
  18.205 -
  18.206 -    bucket = get_bucket(table, hashcode);
  18.207 -    old_head = bucket->head;
  18.208 -    bucket->count++;
  18.209 -    bucket->head = entry;
  18.210 -    entry->next = old_head;
  18.211 -}
  18.212 -
  18.213 -/** Change the number of buckets in a hashtable.
  18.214 - * No-op if the number of buckets is not positive.
  18.215 - * Existing entries are reallocated to buckets based on their hashcodes.
  18.216 - * The table is unmodified if the number of buckets cannot be changed.
  18.217 - *
  18.218 - * @param table hashtable
  18.219 - * @param buckets_n new number of buckets
  18.220 - * @return 0 on success, error code otherwise
  18.221 - */
  18.222 -int HashTable_set_buckets_n(HashTable *table, int buckets_n){
  18.223 -    int err = 0;
  18.224 -    HTBucket *old_buckets = table->buckets;
  18.225 -    int old_buckets_n = table->buckets_n;
  18.226 -    int i;
  18.227 -
  18.228 -    if(buckets_n <= 0){
  18.229 -        err = -EINVAL;
  18.230 -        goto exit;
  18.231 -    }
  18.232 -    table->buckets = (HTBucket*)allocate(buckets_n * sizeof(HTBucket));
  18.233 -    if(!table->buckets){
  18.234 -        err = -ENOMEM;
  18.235 -        table->buckets = old_buckets;
  18.236 -        goto exit;
  18.237 -    }
  18.238 -    table->buckets_n = buckets_n;
  18.239 -    for(i=0; i<old_buckets_n; i++){
  18.240 -        HTBucket *bucket = old_buckets + i;
  18.241 -        HTEntry *entry, *next;
  18.242 -        for(entry = bucket->head; entry; entry = next){
  18.243 -            next = entry->next;
  18.244 -            push_on_bucket(table, entry->hashcode, entry);
  18.245 -        }
  18.246 -    }
  18.247 -    deallocate(old_buckets);
  18.248 -  exit:
  18.249 -    return err;
  18.250 -}
  18.251 -
  18.252 -/** Adjust the number of buckets so the table is neither too full nor too empty.
  18.253 - * The table is unmodified if adjusting fails.
  18.254 - *
  18.255 - * @param table hash table
  18.256 - * @param buckets_min minimum number of buckets (use default if 0 or negative)
  18.257 - * @return 0 on success, error code otherwise
  18.258 - */
  18.259 -int HashTable_adjust(HashTable *table, int buckets_min){
  18.260 -    int buckets_n = 0;
  18.261 -    int err = 0;
  18.262 -    if(buckets_min <= 0) buckets_min = HT_BUCKETS_N;
  18.263 -    if(table->entry_count >= table->buckets_n){
  18.264 -        // The table is dense - expand it.
  18.265 -        buckets_n = 2 * table->buckets_n;
  18.266 -    } else if((table->buckets_n > buckets_min) &&
  18.267 -              (4 * table->entry_count < table->buckets_n)){
  18.268 -        // The table is more than minimum size and sparse - shrink it.
  18.269 -        buckets_n = 2 * table->entry_count;
  18.270 -        if(buckets_n < buckets_min) buckets_n = buckets_min;
  18.271 -    }
  18.272 -    if(buckets_n){
  18.273 -        err = HashTable_set_buckets_n(table, buckets_n);
  18.274 -    }
  18.275 -    return err;
  18.276 -}
  18.277 -
  18.278 -/** Allocate a new entry for a given value.
  18.279 - *
  18.280 - * @param value to put in the entry
  18.281 - * @return entry, or 0 on failure
  18.282 - */
  18.283 -HTEntry * HTEntry_new(Hashcode hashcode, void *key, void *value){
  18.284 -    HTEntry *z = ALLOCATE(HTEntry);
  18.285 -    if(z){
  18.286 -        z->hashcode = hashcode;
  18.287 -        z->key = key;
  18.288 -        z->value = value;
  18.289 -    }
  18.290 -    return z;
  18.291 -}
  18.292 -
  18.293 -/** Free an entry.
  18.294 - *
  18.295 - * @param z entry to free
  18.296 - */
  18.297 -inline void HTEntry_free(HTEntry *z){
  18.298 -    if(z){
  18.299 -        deallocate(z);
  18.300 -    }
  18.301 -}
  18.302 -
  18.303 -/** Free an entry in a hashtable.
  18.304 - * The table's entry_free_fn is used is defined, otherwise 
  18.305 - * the HTEntry itself is freed.
  18.306 - *
  18.307 - * @param table hashtable
  18.308 - * @param entry to free
  18.309 - */
  18.310 -inline void HashTable_free_entry(HashTable *table, HTEntry *entry){
  18.311 -    if(!entry)return;
  18.312 -    if(table && table->entry_free_fn){
  18.313 -        table->entry_free_fn(table, entry);
  18.314 -    } else {
  18.315 -        HTEntry_free(entry);
  18.316 -    }
  18.317 -}
  18.318 -
  18.319 -/** Get the first entry satisfying a test from the bucket for the
  18.320 - * given hashcode.
  18.321 - *
  18.322 - * @param table to look in
  18.323 - * @param hashcode indicates the bucket
  18.324 - * @param test_fn test to apply to elements
  18.325 - * @param arg first argument to calls to test_fn
  18.326 - * @return entry found, or 0
  18.327 - */
  18.328 -inline HTEntry * HashTable_find_entry(HashTable *table, Hashcode hashcode,
  18.329 -				      TableTestFn *test_fn, TableArg arg){
  18.330 -    HTBucket *bucket;
  18.331 -    HTEntry *entry = 0;
  18.332 -    HTEntry *next;
  18.333 -
  18.334 -    bucket = get_bucket(table, hashcode);
  18.335 -    for(entry = bucket->head; entry; entry = next){
  18.336 -        next = entry->next;
  18.337 -        if(test_fn(arg, table, entry)){
  18.338 -            break;
  18.339 -        }
  18.340 -    }
  18.341 -    return entry;
  18.342 -}
  18.343 -
  18.344 -/** Test hashtable keys for equality.
  18.345 - * Uses the table's key_equal_fn if defined, otherwise pointer equality.
  18.346 - *
  18.347 - * @param key1 key to compare
  18.348 - * @param key2 key to compare
  18.349 - * @return 1 if equal, 0 otherwise
  18.350 - */
  18.351 -inline int HashTable_key_equal(HashTable *table, void *key1, void *key2){
  18.352 -    return (table->key_equal_fn ? table->key_equal_fn(key1, key2) : key1==key2);
  18.353 -}
  18.354 -
  18.355 -/** Compute the hashcode of a hashtable key.
  18.356 - * The table's key_hash_fn is used if defined, otherwise the address of
  18.357 - * the key is hashed.
  18.358 - *
  18.359 - * @param table hashtable
  18.360 - * @param key to hash
  18.361 - * @return hashcode
  18.362 - */
  18.363 -inline Hashcode HashTable_key_hash(HashTable *table, void *key){
  18.364 -    return (table->key_hash_fn ? table->key_hash_fn(key) : hash_ul((unsigned long)key));
  18.365 -}
  18.366 -
  18.367 -/** Test if an entry has a given key.
  18.368 - *
  18.369 - * @param arg containing key to test for
  18.370 - * @param table the entry is in
  18.371 - * @param entry to test
  18.372 - * @return 1 if the entry has the key, 0 otherwise
  18.373 - */
  18.374 -static inline int has_key(TableArg arg, HashTable *table, HTEntry *entry){
  18.375 -    return HashTable_key_equal(table, arg.ptr, entry->key);
  18.376 -}
  18.377 -
  18.378 -/** Get an entry with a given key.
  18.379 - *
  18.380 - * @param table to search
  18.381 - * @param key to look for
  18.382 - * @return entry if found, null otherwise
  18.383 - */
  18.384 -#if 0
  18.385 -inline HTEntry * HashTable_get_entry(HashTable *table, void *key){
  18.386 -    TableArg arg = { ptr: key };
  18.387 -    return HashTable_find_entry(table, HashTable_key_hash(table, key), has_key, arg);
  18.388 -}
  18.389 -#else
  18.390 -inline HTEntry * HashTable_get_entry(HashTable *table, void *key){
  18.391 -    Hashcode hashcode;
  18.392 -    HTBucket *bucket;
  18.393 -    HTEntry *entry = 0;
  18.394 -    HTEntry *next;
  18.395 -
  18.396 -    hashcode = HashTable_key_hash(table, key);
  18.397 -    bucket = get_bucket(table, hashcode);
  18.398 -    for(entry = bucket->head; entry; entry = next){
  18.399 -        next = entry->next;
  18.400 -        if(HashTable_key_equal(table, key, entry->key)){
  18.401 -            break;
  18.402 -        }
  18.403 -    }
  18.404 -    return entry;
  18.405 -}
  18.406 -#endif
  18.407 -
  18.408 -/** Get the value of an entry with a given key.
  18.409 - *
  18.410 - * @param table to search
  18.411 - * @param key to look for
  18.412 - * @return value if an entry was found, null otherwise
  18.413 - */
  18.414 -inline void * HashTable_get(HashTable *table, void *key){
  18.415 -    HTEntry *entry = HashTable_get_entry(table, key);
  18.416 -    return (entry ? entry->value : 0);
  18.417 -}
  18.418 -
  18.419 -/** Print the buckets in a table.
  18.420 - *
  18.421 - * @param table to print
  18.422 - */
  18.423 -void show_buckets(HashTable *table, IOStream *io){
  18.424 -    int i,j ;
  18.425 -    IOStream_print(io, "entry_count=%d buckets_n=%d\n", table->entry_count, table->buckets_n);
  18.426 -    for(i=0; i<table->buckets_n; i++){
  18.427 -        if(0 || table->buckets[i].count>0){
  18.428 -            IOStream_print(io, "bucket %3d %3d %10p ", i,
  18.429 -                        table->buckets[i].count,
  18.430 -                        table->buckets[i].head);
  18.431 -            for(j = table->buckets[i].count; j>0; j--){
  18.432 -                IOStream_print(io, "+");
  18.433 -            }
  18.434 -            IOStream_print(io, "\n");
  18.435 -        }
  18.436 -    }
  18.437 -    HashTable_print(table, io); 
  18.438 -}
  18.439 -    
  18.440 -/** Print an entry in a table.
  18.441 - *
  18.442 - * @param entry to print
  18.443 - * @param arg a pointer to an IOStream to print to
  18.444 - * @return 0
  18.445 - */
  18.446 -static int print_entry(TableArg arg, HashTable *table, HTEntry *entry){
  18.447 -    IOStream *io = (IOStream*)arg.ptr;
  18.448 -    IOStream_print(io, " b=%4lx h=%08lx i=%08lx |-> e=%8p k=%8p v=%8p\n",
  18.449 -                entry->hashcode % table->buckets_n,
  18.450 -                entry->hashcode,
  18.451 -                entry->index,
  18.452 -                entry, entry->key, entry->value);
  18.453 -    return 0;
  18.454 -}
  18.455 -
  18.456 -/** Print a hash table.
  18.457 - *
  18.458 - * @param table to print
  18.459 - */
  18.460 -void HashTable_print(HashTable *table, IOStream *io){
  18.461 -    IOStream_print(io, "{\n");
  18.462 -    HashTable_map(table, print_entry, (TableArg){ ptr: io });
  18.463 -    IOStream_print(io, "}\n");
  18.464 -}
  18.465 -/*==========================================================================*/
  18.466 -
  18.467 -/** Get the next entry id to use for a table.
  18.468 - *
  18.469 - * @param table hash table
  18.470 - * @return non-zero entry id
  18.471 - */
  18.472 -static inline unsigned long get_next_id(HashTable *table){
  18.473 -    unsigned long id;
  18.474 -
  18.475 -    if(table->next_id == 0){
  18.476 -        table->next_id = 1;
  18.477 -    }
  18.478 -    id = table->next_id++;
  18.479 -    return id;
  18.480 -}
  18.481 -
  18.482 -/** Add an entry to the bucket for the
  18.483 - * given hashcode.
  18.484 - *
  18.485 - * @param table to insert in
  18.486 - * @param hashcode indicates the bucket
  18.487 - * @param key to add an entry for
  18.488 - * @param value to add an entry for
  18.489 - * @return entry on success, 0 on failure
  18.490 - */
  18.491 -inline HTEntry * HashTable_add_entry(HashTable *table, Hashcode hashcode, void *key, void *value){
  18.492 -    HTEntry *entry = HTEntry_new(hashcode, key, value);
  18.493 -    if(entry){
  18.494 -        entry->index = get_next_id(table);
  18.495 -        push_on_bucket(table, hashcode, entry);
  18.496 -        table->entry_count++;
  18.497 -    }
  18.498 -    return entry;
  18.499 -}
  18.500 -
  18.501 -/** Move the front entry for a bucket to the correct point in the bucket order as
  18.502 - * defined by the order function. If this is called every time a new entry is added
  18.503 - * the bucket will be maintained in sorted order.
  18.504 - *
  18.505 - * @param table to modify
  18.506 - * @param hashcode indicates the bucket
  18.507 - * @param order entry comparison function
  18.508 - * @return 0 if an entry was moved, 1 if not
  18.509 - */
  18.510 -int HashTable_order_bucket(HashTable *table, Hashcode hashcode, TableOrderFn *order){
  18.511 -    HTEntry *new_entry = NULL, *prev = NULL, *entry = NULL;
  18.512 -    HTBucket *bucket;
  18.513 -    int err = 1;
  18.514 -
  18.515 -    bucket = get_bucket(table, hashcode);
  18.516 -    new_entry = bucket->head;
  18.517 -    if(!new_entry || !new_entry->next) goto exit;
  18.518 -    for(entry = new_entry->next; entry; prev = entry, entry = entry->next){
  18.519 -        if(order(new_entry, entry) <= 0) break;
  18.520 -    }
  18.521 -    if(prev){
  18.522 -        err = 0;
  18.523 -        bucket->head = new_entry->next; 
  18.524 -        new_entry->next = entry;
  18.525 -        prev->next = new_entry;
  18.526 -    }
  18.527 -  exit:
  18.528 -    return err;
  18.529 -}
  18.530 -
  18.531 -/** Add an entry to a hashtable.
  18.532 - * The entry is added to the bucket for its key's hashcode.
  18.533 - *
  18.534 - * @param table to insert in
  18.535 - * @param key to add an entry for
  18.536 - * @param value to add an entry for
  18.537 - * @return entry on success, 0 on failure
  18.538 - */
  18.539 -inline HTEntry * HashTable_add(HashTable *table, void *key, void *value){
  18.540 -    return HashTable_add_entry(table, HashTable_key_hash(table, key), key, value);
  18.541 -}
  18.542 -
  18.543 -
  18.544 -/** Remove entries satisfying a test from the bucket for the
  18.545 - * given hashcode. 
  18.546 - *
  18.547 - * @param table to remove from
  18.548 - * @param hashcode indicates the bucket
  18.549 - * @param test_fn test to apply to elements
  18.550 - * @param arg first argument to calls to test_fn
  18.551 - * @return number of entries removed
  18.552 - */
  18.553 -inline int HashTable_remove_entry(HashTable *table, Hashcode hashcode,
  18.554 -				  TableTestFn *test_fn, TableArg arg){
  18.555 -    HTBucket *bucket;
  18.556 -    HTEntry *entry, *prev = 0, *next;
  18.557 -    int removed_count = 0;
  18.558 -
  18.559 -    bucket = get_bucket(table, hashcode);
  18.560 -    for(entry = bucket->head; entry; entry = next){
  18.561 -        next = entry->next;
  18.562 -        if(test_fn(arg, table, entry)){
  18.563 -            if(prev){
  18.564 -                prev->next = next;
  18.565 -            } else {
  18.566 -                bucket->head = next;
  18.567 -            }
  18.568 -            bucket->count--;
  18.569 -            table->entry_count--;
  18.570 -            removed_count++;
  18.571 -            HashTable_free_entry(table, entry);
  18.572 -            entry = 0;
  18.573 -        }
  18.574 -        prev = entry;
  18.575 -    }
  18.576 -    return removed_count;
  18.577 -}
  18.578 -
  18.579 -/** Remove entries with a given key. 
  18.580 - *
  18.581 - * @param table to remove from
  18.582 - * @param key of entries to remove
  18.583 - * @return number of entries removed
  18.584 - */
  18.585 -inline int HashTable_remove(HashTable *table, void *key){
  18.586 -#if 1
  18.587 -    Hashcode hashcode;
  18.588 -    HTBucket *bucket;
  18.589 -    HTEntry *entry, *prev = 0, *next;
  18.590 -    int removed_count = 0;
  18.591 -
  18.592 -    hashcode = HashTable_key_hash(table, key);
  18.593 -    bucket = get_bucket(table, hashcode);
  18.594 -    for(entry = bucket->head; entry; entry = next){
  18.595 -        next = entry->next;
  18.596 -        if(HashTable_key_equal(table, key, entry->key)){
  18.597 -            if(prev){
  18.598 -                prev->next = next;
  18.599 -            } else {
  18.600 -                bucket->head = next;
  18.601 -            }
  18.602 -            bucket->count--;
  18.603 -            table->entry_count--;
  18.604 -            removed_count++;
  18.605 -            HashTable_free_entry(table, entry);
  18.606 -            entry = 0;
  18.607 -        }
  18.608 -        prev = entry;
  18.609 -    }
  18.610 -    return removed_count;
  18.611 -#else
  18.612 -    return HashTable_remove_entry(table, HashTable_key_hash(table, key),
  18.613 -				  has_key, (TableArg){ ptr: key});
  18.614 -#endif
  18.615 -}
  18.616 -
  18.617 -/** Remove (and free) all the entries in a bucket.
  18.618 - *
  18.619 - * @param bucket to clear
  18.620 - */
  18.621 -static inline void bucket_clear(HashTable *table, HTBucket *bucket){
  18.622 -    HTEntry *entry, *next;
  18.623 -
  18.624 -    for(entry = bucket->head; entry; entry = next){
  18.625 -        next = entry->next;
  18.626 -        HashTable_free_entry(table, entry);
  18.627 -    }
  18.628 -    bucket->head = 0;
  18.629 -    table->entry_count -= bucket->count;
  18.630 -    bucket->count = 0;
  18.631 -}
  18.632 -
  18.633 -/** Remove (and free) all the entries in a table.
  18.634 - *
  18.635 - * @param table to clear
  18.636 - */
  18.637 -void HashTable_clear(HashTable *table){
  18.638 -    int i, n = table->buckets_n;
  18.639 -
  18.640 -    for(i=0; i<n; i++){
  18.641 -        bucket_clear(table, table->buckets + i);
  18.642 -    }
  18.643 -}
    19.1 --- a/tools/lib/hash_table.h	Tue Jun 29 14:14:38 2004 +0000
    19.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    19.3 @@ -1,295 +0,0 @@
    19.4 -/* $Id: hash_table.h,v 1.1 2004/03/30 16:21:26 mjw Exp $ */
    19.5 -/*
    19.6 - * Copyright (C) 2001 - 2004 Mike Wray <mike.wray@hp.com>
    19.7 - *
    19.8 - * This library is free software; you can redistribute it and/or modify
    19.9 - * it under the terms of the GNU Lesser General Public License as published by
   19.10 - * the Free Software Foundation; either version 2.1 of the License, or
   19.11 - * (at your option) any later version.
   19.12 - *
   19.13 - * This library is distributed in the hope that it will be useful,
   19.14 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
   19.15 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   19.16 - * GNU Lesser General Public License for more details.
   19.17 - *
   19.18 - * You should have received a copy of the GNU Lesser General Public License
   19.19 - * along with this library; if not, write to the Free Software
   19.20 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   19.21 - */
   19.22 -
   19.23 -#ifndef _XEN_LIB_HASH_TABLE_H_
   19.24 -#define _XEN_LIB_HASH_TABLE_H_
   19.25 -
   19.26 -#include "iostream.h"
   19.27 -
   19.28 -typedef unsigned long Hashcode;
   19.29 -
   19.30 -/** Type used to pass parameters to table functions. */
   19.31 -typedef union TableArg {
   19.32 -    unsigned long ul;
   19.33 -    void *ptr;
   19.34 -} TableArg;
   19.35 -
   19.36 -/** An entry in a bucket list. */
   19.37 -typedef struct HTEntry {
   19.38 -    /** Hashcode of the entry's key. */
   19.39 -    Hashcode hashcode;
   19.40 -    /** Identifier for this entry in the table. */
   19.41 -    int index;
   19.42 -    /** The key for this entry. */
   19.43 -    void *key;
   19.44 -    /** The value in this entry. */
   19.45 -    void *value;
   19.46 -    /** The next entry in the list. */
   19.47 -    struct HTEntry *next;
   19.48 -} HTEntry;
   19.49 -
   19.50 -/** A bucket in a rule table. */
   19.51 -typedef struct HTBucket {
   19.52 -    /** Number of entries in the bucket. */
   19.53 -    int count;
   19.54 -    /** First entry in the bucket (may be null). */
   19.55 -    HTEntry *head;
   19.56 -} HTBucket;
   19.57 -
   19.58 -/** Default number of buckets in a hash table.
   19.59 - * You want enough buckets so the lists in the buckets will typically be short.
   19.60 - * It's a good idea if this is prime, since that will help to spread hashcodes
   19.61 - * around the table.
   19.62 - */
   19.63 -//#define HT_BUCKETS_N 1
   19.64 -//#define HT_BUCKETS_N 3
   19.65 -//#define HT_BUCKETS_N 7
   19.66 -//#define HT_BUCKETS_N 17
   19.67 -//#define HT_BUCKETS_N 97
   19.68 -//#define HT_BUCKETS_N 211
   19.69 -//#define HT_BUCKETS_N 401
   19.70 -#define HT_BUCKETS_N 1021
   19.71 -
   19.72 -typedef struct HashTable HashTable;
   19.73 -
   19.74 -/** Type for a function used to select table entries. */
   19.75 -typedef int TableTestFn(TableArg arg, HashTable *table, HTEntry *entry);
   19.76 -
   19.77 -/** Type for a function to map over table entries. */
   19.78 -typedef int TableMapFn(TableArg arg, HashTable *table, HTEntry *entry);
   19.79 -
   19.80 -/** Type for a function to free table entries. */
   19.81 -typedef void TableFreeFn(HashTable *table, HTEntry *entry);
   19.82 -
   19.83 -/** Type for a function to hash table keys. */
   19.84 -typedef Hashcode TableHashFn(void *key);
   19.85 -
   19.86 -/** Type for a function to test table keys for equality. */
   19.87 -typedef int TableEqualFn(void *key1, void *key2);
   19.88 -
   19.89 -/** Type for a function to order table entries. */
   19.90 -typedef int TableOrderFn(HTEntry *e1, HTEntry *e2);
   19.91 -
   19.92 -/** General hash table.
   19.93 - * A hash table with a list in each bucket.
   19.94 - * Functions can be supplied for freeing entries, hashing keys, and comparing keys.
   19.95 - * These all default to 0, when default behaviour treating keys as integers is used.
   19.96 - */
   19.97 -struct HashTable {
   19.98 -    /** Flag indicating whether the table has been initialised. */
   19.99 -    int init_done;
  19.100 -    /** Next value for the id field in inserted rules. */
  19.101 -    unsigned long next_id;
  19.102 -    /** Number of buckets in the bucket array. */
  19.103 -    int buckets_n;
  19.104 -    /** Array of buckets, each with its own list. */
  19.105 -    HTBucket *buckets;
  19.106 -    /** Number of entries in the table. */
  19.107 -    int entry_count;
  19.108 -    /** Function to free keys and values in entries. */
  19.109 -    TableFreeFn *entry_free_fn;
  19.110 -    /** Function to hash keys. */
  19.111 -    TableHashFn *key_hash_fn;
  19.112 -    /** Function to compare keys for equality. */
  19.113 -    TableEqualFn *key_equal_fn;
  19.114 -    /** Place for the user of the table to hang extra data. */
  19.115 -    void *user_data;
  19.116 -};
  19.117 -
  19.118 -extern HashTable *HashTable_new(int bucket_n);
  19.119 -extern void HashTable_free(HashTable *table);
  19.120 -extern HTEntry * HTEntry_new(Hashcode hashcode, void *key, void *value);
  19.121 -extern void HTEntry_free(HTEntry *entry);
  19.122 -extern int HashTable_set_bucket_n(HashTable *table, int bucket_n);
  19.123 -extern void HashTable_clear(HashTable *table);
  19.124 -extern HTEntry * HashTable_add_entry(HashTable *table, Hashcode hashcode, void *key, void *value);
  19.125 -extern HTEntry * HashTable_get_entry(HashTable *table, void *key);
  19.126 -extern HTEntry * HashTable_add(HashTable *table, void *key, void *value);
  19.127 -extern void * HashTable_get(HashTable *table, void *key);
  19.128 -extern int HashTable_remove(HashTable *table, void *key);
  19.129 -extern HTEntry * HashTable_find_entry(HashTable *table, Hashcode hashcode,
  19.130 -                                      TableTestFn *test_fn, TableArg arg);
  19.131 -extern int HashTable_remove_entry(HashTable *table, Hashcode hashcode,
  19.132 -                                   TableTestFn *test_fn, TableArg arg);
  19.133 -//extern int HashTable_map(HashTable *table, TableMapFn *map_fn, TableArg arg);
  19.134 -extern void HashTable_print(HashTable *table, IOStream *out);
  19.135 -extern int HashTable_set_buckets_n(HashTable *table, int buckets_n);
  19.136 -extern int HashTable_adjust(HashTable *table, int buckets_min);
  19.137 -extern void pseudo_des(unsigned long *pleft, unsigned long *pright);
  19.138 -extern Hashcode hash_string(char *s);
  19.139 -
  19.140 -extern int HashTable_order_bucket(HashTable *table, Hashcode hashcode, TableOrderFn *order);
  19.141 -
  19.142 -/** Control whether to use hashing based on DES or simple
  19.143 - * hashing. DES hashing is `more random' but much more expensive.
  19.144 - */
  19.145 -#define HASH_PSEUDO_DES 0
  19.146 -
  19.147 -/** Hash a long using a quick and dirty linear congruential random number generator.
  19.148 - *  See `Numerical Recipes in C', Chapter 7, "An Even Quicker Generator".
  19.149 - *
  19.150 - * @param a value to hash
  19.151 - * @return hashed input
  19.152 - */
  19.153 -static inline unsigned long lcrng_hash(unsigned long a){
  19.154 -    return (1664525L * a + 1013904223L);
  19.155 -}
  19.156 -
  19.157 -/** Hash an unsigned long.
  19.158 - *
  19.159 - * @param a input to hash
  19.160 - * @return hashcode
  19.161 - */
  19.162 -static inline Hashcode hash_ul(unsigned long a){
  19.163 -#if HASH_PSEUDO_DES
  19.164 -    unsigned long left = a;
  19.165 -    unsigned long right = 0L;
  19.166 -    pseudo_des(&left, &right);
  19.167 -    return right;
  19.168 -#else
  19.169 -    a = lcrng_hash(a);
  19.170 -    a = lcrng_hash(a);
  19.171 -    return a;
  19.172 -#endif
  19.173 -}
  19.174 -
  19.175 -/** Hash two unsigned longs together.
  19.176 - *
  19.177 - * @param a input to hash
  19.178 - * @param b input to hash
  19.179 - * @return hashcode
  19.180 - */
  19.181 -static inline Hashcode hash_2ul(unsigned long a, unsigned long b){
  19.182 -#if HASH_PSEUDO_DES
  19.183 -    unsigned long left = a;
  19.184 -    unsigned long right = b;
  19.185 -    pseudo_des(&left, &right);
  19.186 -    return right;
  19.187 -#else
  19.188 -    a = lcrng_hash(a);
  19.189 -    a ^= b;
  19.190 -    a = lcrng_hash(a);
  19.191 -    return a;
  19.192 -#endif
  19.193 -}
  19.194 -
  19.195 -/** Hash a hashcode and an unsigned long together.
  19.196 - *
  19.197 - * @param a input hashcode
  19.198 - * @param b input to hash
  19.199 - * @return hashcode
  19.200 - */
  19.201 -static inline Hashcode hash_hul(Hashcode a, unsigned long b){
  19.202 -#if HASH_PSEUDO_DES
  19.203 -    unsigned long left = a;
  19.204 -    unsigned long right = b;
  19.205 -    pseudo_des(&left, &right);
  19.206 -    return right;
  19.207 -#else
  19.208 -    a ^= b;
  19.209 -    a = lcrng_hash(a);
  19.210 -    return a;
  19.211 -#endif
  19.212 -}
  19.213 -
  19.214 -/** Macro to declare variables for HashTable_for_each() to use.
  19.215 - *
  19.216 - * @param entry variable that is set to entries in the table
  19.217 - */
  19.218 -#define HashTable_for_decl(entry) \
  19.219 -  HashTable *_var_table; \
  19.220 -  HTBucket *_var_bucket; \
  19.221 -  HTBucket *_var_end; \
  19.222 -  HTEntry *_var_next; \
  19.223 -  HTEntry *entry
  19.224 -
  19.225 -/** Macro to iterate over the entries in a hashtable.
  19.226 - * Must be in a scope where HashTable_for_decl() has been used to declare
  19.227 - * variables for it to use.
  19.228 - * The variable 'entry' is iterated over entries in the table.
  19.229 - * The code produced is syntactically a loop, so it must be followed by
  19.230 - * a loop body, typically some statements in braces:
  19.231 - * HashTable_for_each(entry, table){ ...loop body... }
  19.232 - *
  19.233 - * HashTable_for_each() and HashTable_for_decl() cannot be used for nested
  19.234 - * loops as variables will clash.
  19.235 - *
  19.236 - * @note The simplest way to code a direct loop over the entries in a hashtable
  19.237 - * is to use a loop over the buckets, with a nested loop over the entries
  19.238 - * in a bucket. Using this approach in a macro means the macro contains
  19.239 - * an opening brace, and calls to it must be followed by 2 braces!
  19.240 - * To avoid this the code has been restructured so that it is a for loop.
  19.241 - * So that statements could be used in the test expression of the for loop,
  19.242 - * we have used the gcc statement expression extension ({ ... }).
  19.243 - *
  19.244 - * @param entry variable to iterate over the entries
  19.245 - * @param table to iterate over (non-null)
  19.246 - */
  19.247 -#define HashTable_for_each(entry, table) \
  19.248 -  _var_table = table; \
  19.249 -  _var_bucket = _var_table->buckets; \
  19.250 -  _var_end = _var_bucket + _var_table->buckets_n; \
  19.251 -  for(entry=0, _var_next=0; \
  19.252 -      ({ if(_var_next){ \
  19.253 -             entry = _var_next; \
  19.254 -             _var_next = entry->next; \
  19.255 -          } else { \
  19.256 -             while(_var_bucket < _var_end){ \
  19.257 -                 entry = _var_bucket->head; \
  19.258 -                 _var_bucket++; \
  19.259 -                 if(entry){ \
  19.260 -                      _var_next = entry->next; \
  19.261 -                      break; \
  19.262 -                 } \
  19.263 -             } \
  19.264 -          }; \
  19.265 -         entry; }); \
  19.266 -      entry = _var_next )
  19.267 -
  19.268 -/** Map a function over the entries in a table.
  19.269 - * Mapping stops when the function returns a non-zero value.
  19.270 - * Uses the gcc statement expression extension ({ ... }).
  19.271 - *
  19.272 - * @param table to map over
  19.273 - * @param fn function to apply to entries
  19.274 - * @param arg first argument to call the function with
  19.275 - * @return 0 if fn always returned 0, first non-zero value otherwise
  19.276 - */
  19.277 -#define HashTable_map(table, fn, arg) \
  19.278 -  ({ HashTable_for_decl(_var_entry); \
  19.279 -    TableArg _var_arg = arg; \
  19.280 -    int _var_value = 0; \
  19.281 -    HashTable_for_each(_var_entry, table){ \
  19.282 -        if((_var_value = fn(_var_arg, _var_table, _var_entry))) break; \
  19.283 -    } \
  19.284 -    _var_value; })
  19.285 -
  19.286 -/** Cast x to the type for a key or value in a hash table.
  19.287 - * This avoids compiler warnings when using short integers
  19.288 - * as keys or values (especially on 64-bit platforms).
  19.289 - */
  19.290 -#define HKEY(x) ((void*)(unsigned long)(x))
  19.291 -
  19.292 -/** Cast x from the type for a key or value in a hash table.
  19.293 - * to an unsigned long. This avoids compiler warnings when using
  19.294 - * short integers as keys or values (especially on 64-bit platforms).
  19.295 - */
  19.296 -#define HVAL(x) ((unsigned long)(x))
  19.297 -
  19.298 -#endif /* !_XEN_LIB_HASH_TABLE_H_ */
    20.1 --- a/tools/lib/iostream.c	Tue Jun 29 14:14:38 2004 +0000
    20.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    20.3 @@ -1,37 +0,0 @@
    20.4 -#include "iostream.h"
    20.5 -#include "sys_string.h"
    20.6 -
    20.7 -/** Print on a stream, like vfprintf().
    20.8 - *
    20.9 - * @param stream to print to
   20.10 - * @param format for the print (as fprintf())
   20.11 - * @param args arguments to print
   20.12 - * @return result code from the print
   20.13 - */
   20.14 -int IOStream_vprint(IOStream *stream, const char *format, va_list args){
   20.15 -  char buffer[1024];
   20.16 -  int k = sizeof(buffer), n;
   20.17 -
   20.18 -  n = vsnprintf(buffer, k, (char*)format, args);
   20.19 -  if(n < 0 || n > k ){
   20.20 -      n = k;
   20.21 -  }
   20.22 -  n = IOStream_write(stream, buffer, n);
   20.23 -  return n;
   20.24 -}
   20.25 -
   20.26 -/** Print on a stream, like fprintf().
   20.27 - *
   20.28 - * @param stream to print to
   20.29 - * @param format for the print (as fprintf())
   20.30 - * @return result code from the print
   20.31 - */
   20.32 -int IOStream_print(IOStream *stream, const char *format, ...){
   20.33 -  va_list args;
   20.34 -  int result = -1;
   20.35 -
   20.36 -  va_start(args, format);
   20.37 -  result = IOStream_vprint(stream, format, args);
   20.38 -  va_end(args);
   20.39 -  return result;
   20.40 -}
    21.1 --- a/tools/lib/iostream.h	Tue Jun 29 14:14:38 2004 +0000
    21.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    21.3 @@ -1,243 +0,0 @@
    21.4 -#ifndef _XC_LINUX_SAVE_H_
    21.5 -#define _XC_LINUX_SAVE_H_
    21.6 -
    21.7 -#include <stdarg.h>
    21.8 -#include <stdint.h>
    21.9 -#include <stddef.h>
   21.10 -
   21.11 -#ifdef __KERNEL__
   21.12 -#include <linux/errno.h>
   21.13 -#else
   21.14 -#include <errno.h>
   21.15 -#endif
   21.16 -
   21.17 -#include "allocate.h"
   21.18 -
   21.19 -/** End of input return value. */
   21.20 -#define IOSTREAM_EOF -1
   21.21 -
   21.22 -/** An input/output abstraction.
   21.23 - */
   21.24 -typedef struct IOStream IOStream;
   21.25 -
   21.26 -/** Record of the functions to use for operations on an
   21.27 - * IOStream implementation.
   21.28 - */
   21.29 -typedef struct IOMethods {
   21.30 -    /** Read function.  Called with the user data, buffer to read into
   21.31 -     * and number of bytes to read.  Must return number of bytes read
   21.32 -     * on success, less than zero on error.
   21.33 -     */
   21.34 -    int (*read)(IOStream *stream, void *buf, size_t n);
   21.35 -
   21.36 -    /** Write function. Called with user data, buffer to write and
   21.37 -     * number of bytes to write. Must return number of bytes written on
   21.38 -     * success, less than zero otherwise.
   21.39 -     */
   21.40 -    int (*write)(IOStream *stream, const void *buf, size_t n);
   21.41 -
   21.42 -    int (*flush)(IOStream *s);
   21.43 -
   21.44 -    int (*error)(IOStream *s);
   21.45 -
   21.46 -    int (*close)(IOStream *s);
   21.47 -
   21.48 -    void (*free)(IOStream *s);
   21.49 -
   21.50 -    void (*lock)(IOStream *s);
   21.51 -    void (*unlock)(IOStream *s);
   21.52 -
   21.53 -} IOMethods;
   21.54 -
   21.55 -/** Abstract i/o object.
   21.56 - */
   21.57 -struct IOStream {
   21.58 -    /** Methods to use to implement operations. */
   21.59 -    const IOMethods *methods;
   21.60 -    /** Private state for the implementation. */
   21.61 -    const void *data;
   21.62 -    /** Flag indicating whether the stream is closed. */
   21.63 -    int closed;
   21.64 -    /** Number of bytes written. */
   21.65 -    int written;
   21.66 -    /** Number of bytes read. */
   21.67 -    int read;
   21.68 -};
   21.69 -
   21.70 -
   21.71 -/** IOStream version of stdin. */
   21.72 -extern IOStream *iostdin;
   21.73 -
   21.74 -/** IOStream version of stdout, */
   21.75 -extern IOStream *iostdout;
   21.76 -
   21.77 -/** IOStream version of stderr. */
   21.78 -extern IOStream *iostderr;
   21.79 -
   21.80 -extern int IOStream_print(IOStream *io, const char *format, ...);
   21.81 -extern int IOStream_vprint(IOStream *io, const char *format, va_list args);
   21.82 -
   21.83 -/** Read from a stream.
   21.84 - *
   21.85 - * @param stream input
   21.86 - * @param buf where to put input
   21.87 - * @param n number of bytes to read
   21.88 - * @return if ok, number of bytes read, otherwise negative error code
   21.89 - */
   21.90 -static inline int IOStream_read(IOStream *stream, void *buf, size_t n){
   21.91 -    int result = 0;
   21.92 -    if(stream->closed) goto exit;
   21.93 -    if(!stream->methods || !stream->methods->read){
   21.94 -        result = -EINVAL;
   21.95 -        goto exit;
   21.96 -    }
   21.97 -    result = stream->methods->read(stream, buf, n);
   21.98 -    if(result > 0){
   21.99 -        stream->read += result;
  21.100 -    }
  21.101 -  exit:
  21.102 -    return result;
  21.103 -}
  21.104 -
  21.105 -/** Write to a stream.
  21.106 - *
  21.107 - * @param stream input
  21.108 - * @param buf where to put input
  21.109 - * @param n number of bytes to write
  21.110 - * @return if ok, number of bytes read, otherwise negative error code
  21.111 - */
  21.112 -static inline int IOStream_write(IOStream *stream, const void *buf, size_t n){
  21.113 -    int result = 0;
  21.114 -    if(stream->closed) goto exit;
  21.115 -    if(!stream->methods || !stream->methods->write){
  21.116 -        result = -EINVAL;
  21.117 -        goto exit;
  21.118 -    }
  21.119 -    result = stream->methods->write(stream, buf, n);
  21.120 -    if(result > 0){
  21.121 -        stream->written += result;
  21.122 -    }
  21.123 -  exit:
  21.124 -    return result;
  21.125 -}
  21.126 -
  21.127 -/** Flush the stream.
  21.128 - *
  21.129 - * @param stream stream
  21.130 - * @return 0 on success, IOSTREAM_EOF otherwise
  21.131 - */
  21.132 -static inline int IOStream_flush(IOStream *stream){
  21.133 -    int result = 0;
  21.134 -    if(stream->closed){
  21.135 -        result = IOSTREAM_EOF;
  21.136 -    } else if(stream->methods->flush){
  21.137 -        result = stream->methods->flush(stream);
  21.138 -        if(result < 0) result = IOSTREAM_EOF;
  21.139 -    }
  21.140 -    return result;
  21.141 -}
  21.142 -
  21.143 -/** Check whether the stream has an error.
  21.144 - *
  21.145 - * @param stream to check
  21.146 - * @return 1 for error, 0 otherwise
  21.147 - */
  21.148 -static inline int IOStream_error(IOStream *stream){
  21.149 -    int err = 0;
  21.150 -    if(stream->methods && stream->methods->error){
  21.151 -       err = stream->methods->error(stream);
  21.152 -    }
  21.153 -    return err;
  21.154 -}
  21.155 -
  21.156 -/** Close the stream.
  21.157 - *
  21.158 - * @param stream to close
  21.159 - * @return 1 for error, 0 otherwise
  21.160 - */
  21.161 -static inline int IOStream_close(IOStream *stream){
  21.162 -    int err = 1;
  21.163 -    if(stream->methods && stream->methods->close){
  21.164 -        err = stream->methods->close(stream);
  21.165 -    }
  21.166 -    return err;
  21.167 -}
  21.168 -
  21.169 -/** Test if the stream has been closed.
  21.170 - *
  21.171 - * @param stream to check
  21.172 - * @return 1 if closed, 0 otherwise
  21.173 - */
  21.174 -static inline int IOStream_is_closed(IOStream *stream){
  21.175 -  return stream->closed;
  21.176 -}
  21.177 -
  21.178 -/** Free the memory used by the stream.
  21.179 - *
  21.180 - * @param stream to free
  21.181 - */
  21.182 -static inline void IOStream_free(IOStream *stream){
  21.183 -  if(stream->methods && stream->methods->free){
  21.184 -    stream->methods->free(stream);
  21.185 -  }
  21.186 -  *stream = (IOStream){};
  21.187 -  deallocate(stream);
  21.188 -}
  21.189 -
  21.190 -
  21.191 -/** Print a character to a stream, like fputc().
  21.192 - *
  21.193 - * @param stream to print to
  21.194 - * @param c character to print
  21.195 - * @return result code from the print
  21.196 - */
  21.197 -static inline int IOStream_putc(IOStream *stream, int c){
  21.198 -    int err;
  21.199 -    unsigned char b = (unsigned char)c;
  21.200 -    err = IOStream_write(stream, &b, 1);
  21.201 -    if(err < 1){
  21.202 -        err = IOSTREAM_EOF;
  21.203 -    } else {
  21.204 -        err = b;
  21.205 -    }
  21.206 -    return err;
  21.207 -}
  21.208 -
  21.209 -/** Read from a stream, like fgetc().
  21.210 - *
  21.211 - * @param stream to read from
  21.212 - * @return IOSTREAM_EOF on error, character read otherwise
  21.213 - */
  21.214 -static inline int IOStream_getc(IOStream *stream){
  21.215 -    int err, rc;
  21.216 -    unsigned char b;
  21.217 -
  21.218 -    err = IOStream_read(stream, &b, 1);
  21.219 -    if(err < 1){
  21.220 -        rc = IOSTREAM_EOF;
  21.221 -    } else {
  21.222 -        rc = b;
  21.223 -    }
  21.224 -    return rc;
  21.225 -}
  21.226 -
  21.227 -/** Get number of bytes read.
  21.228 - *
  21.229 - * @param stream to get from
  21.230 - * @return number of bytes read
  21.231 - */
  21.232 -static inline int IOStream_get_read(IOStream *stream){
  21.233 -    return stream->read;
  21.234 -}
  21.235 -
  21.236 -/** Get number of bytes written.
  21.237 - *
  21.238 - * @param stream to get from
  21.239 - * @return number of bytes written
  21.240 - */
  21.241 -static inline int IOStream_get_written(IOStream *stream){
  21.242 -    return stream->written;
  21.243 -}
  21.244 -
  21.245 -
  21.246 -#endif /* ! _XC_LINUX_SAVE_H_ */
    22.1 --- a/tools/lib/kernel_stream.c	Tue Jun 29 14:14:38 2004 +0000
    22.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    22.3 @@ -1,177 +0,0 @@
    22.4 -/*
    22.5 - * Copyright (C) 2001 - 2004 Mike Wray <mike.wray@hp.com>
    22.6 - *
    22.7 - * This library is free software; you can redistribute it and/or modify
    22.8 - * it under the terms of the GNU Lesser General Public License as published by
    22.9 - * the Free Software Foundation; either version 2.1 of the License, or
   22.10 - * (at your option) any later version.
   22.11 - *
   22.12 - * This library is distributed in the hope that it will be useful,
   22.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
   22.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   22.15 - * GNU Lesser General Public License for more details.
   22.16 - *
   22.17 - * You should have received a copy of the GNU Lesser General Public License
   22.18 - * along with this library; if not, write to the Free Software
   22.19 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   22.20 - */
   22.21 -
   22.22 -/** @file
   22.23 - * An IOStream implementation using printk() for output.
   22.24 - * Input is not implemented.
   22.25 - */
   22.26 -#ifdef __KERNEL__
   22.27 -
   22.28 -#include <linux/config.h>
   22.29 -#include <linux/module.h>
   22.30 -#include <linux/kernel.h>
   22.31 -#include <linux/types.h>
   22.32 -#include <linux/errno.h>
   22.33 -#include <linux/slab.h>
   22.34 -#include <linux/spinlock.h>
   22.35 -
   22.36 -#include "kernel_stream.h"
   22.37 -#include "allocate.h"
   22.38 -
   22.39 -/** Number of characters in the output buffer.
   22.40 - * The kernel uses 1024 for printk, so that should suffice.
   22.41 - */
   22.42 -#define BUF_N 1024
   22.43 -
   22.44 -/** State for a kernel stream. */
   22.45 -typedef struct KernelData {
   22.46 -    /** Stream lock. We need a lock to serialize access to the stream. */
   22.47 -    spinlock_t lock;
   22.48 -    /** Saved flags for locking. */
   22.49 -    unsigned long flags;
   22.50 -    /** Size of the output buffer. */
   22.51 -    int buf_n;
   22.52 -    /** Output buffer. */
   22.53 -    char buf[BUF_N];
   22.54 -} KernelData;
   22.55 -
   22.56 -static int kernel_write(IOStream *s, const char *msg, int n);
   22.57 -static void kernel_free(IOStream *s);
   22.58 -static void kernel_stream_lock(IOStream *s);
   22.59 -static void kernel_stream_unlock(IOStream *s);
   22.60 -
   22.61 -/** Methods for a kernel stream. Output only. */
   22.62 -static const IOMethods kernel_methods = {
   22.63 -  write:  kernel_write,
   22.64 -  free:   kernel_free,
   22.65 -  lock:   kernel_stream_lock,
   22.66 -  unlock: kernel_stream_unlock,
   22.67 -};
   22.68 -
   22.69 -/** Shared state for kernel streams.
   22.70 - * All implementations write using printk, so we can use
   22.71 - * shared state and avoid allocating it.
   22.72 - */
   22.73 -static const KernelData kernel_data = {
   22.74 -  lock: SPIN_LOCK_UNLOCKED,
   22.75 -  flags: 0,
   22.76 -  buf_n: BUF_N,
   22.77 -};
   22.78 -
   22.79 -/** Stream for kernel printk. */
   22.80 -static IOStream iokernel = {
   22.81 -    methods: &kernel_methods,
   22.82 -    data:    &kernel_data,
   22.83 -};
   22.84 -
   22.85 -/** Stream for kernel printk. */
   22.86 -IOStream *iostdout = &iokernel;
   22.87 -
   22.88 -/** Stream for kernel printk. */
   22.89 -IOStream *iostdin = &iokernel;
   22.90 -
   22.91 -/** Stream for kernel printk. */
   22.92 -IOStream *iostderr = &iokernel;
   22.93 -
   22.94 -/** Get an output-only stream implementation using
   22.95 - * printk(). The stream uses static storage, and must not be freed.
   22.96 - *
   22.97 - * @return kernel stream
   22.98 - */
   22.99 -IOStream get_stream_kernel(void){
  22.100 -  return iokernel;
  22.101 -}
  22.102 -
  22.103 -/** Obtain the lock on the stream state.
  22.104 - *
  22.105 - * @param kdata stream state
  22.106 - */
  22.107 -static inline void KernelData_lock(KernelData *kdata){
  22.108 -  spin_lock_irqsave(&kdata->lock, kdata->flags);
  22.109 -}
  22.110 -
  22.111 -/** Release the lock on the stream state.
  22.112 - *
  22.113 - * @param kdata stream state
  22.114 - */
  22.115 -static inline void KernelData_unlock(KernelData *kdata){
  22.116 -  spin_unlock_irqrestore(&kdata->lock, kdata->flags);
  22.117 -}
  22.118 -
  22.119 -/** Get the stream state.
  22.120 - *
  22.121 - * @param s kernel stream
  22.122 - * @return stream state
  22.123 - */
  22.124 -static inline KernelData *get_kernel_data(IOStream *s){
  22.125 -  return (KernelData*)s->data;
  22.126 -}
  22.127 -
  22.128 -/** Obtain the lock on the stream state.
  22.129 - *
  22.130 - * @param s stream
  22.131 - */
  22.132 -void kernel_stream_lock(IOStream *s){
  22.133 -    KernelData_lock(get_kernel_data(s));
  22.134 -}
  22.135 -
  22.136 -/** Release the lock on the stream state.
  22.137 - *
  22.138 - * @param s stream
  22.139 - */
  22.140 -void kernel_stream_unlock(IOStream *s){
  22.141 -    KernelData_unlock(get_kernel_data(s));
  22.142 -}
  22.143 -
  22.144 -/** Write to a kernel stream.
  22.145 - *
  22.146 - * @param stream kernel stream
  22.147 - * @param format print format
  22.148 - * @param args print arguments
  22.149 - * @return result of the print
  22.150 - */
  22.151 -static int kernel_write(IOStream *stream, const char *buf, int n){
  22.152 -  KernelData *kdata = get_kernel_data(stream);
  22.153 -  int k;
  22.154 -  k = kdata->buf_n - 1;
  22.155 -  if(n < k) k = n;
  22.156 -  memcpy(kdata->buf, buf, k);
  22.157 -  kdata->buf[k] = '\0'
  22.158 -  printk(kdata->buf);
  22.159 -  return k;
  22.160 -}
  22.161 -
  22.162 -/** Free a kernel stream.
  22.163 - * Frees the internal state of the stream.
  22.164 - * Do not call this unless the stream was dynamically allocated.
  22.165 - * Do not call this on a stream returned from get_stream_kernel().
  22.166 - *
  22.167 - * @param io stream to free
  22.168 - */
  22.169 -static void kernel_free(IOStream *io){
  22.170 -  KernelData *kdata;
  22.171 -  if(io == &iokernel) return;
  22.172 -  kdata = get_kernel_data(io);
  22.173 -  zero(kdata, sizeof(*kdata));
  22.174 -  deallocate(kdata);
  22.175 -}
  22.176 -#endif /* __KERNEL__ */
  22.177 -
  22.178 -
  22.179 -
  22.180 -
    23.1 --- a/tools/lib/kernel_stream.h	Tue Jun 29 14:14:38 2004 +0000
    23.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    23.3 @@ -1,29 +0,0 @@
    23.4 -/*
    23.5 - * Copyright (C) 2001 - 2004 Mike Wray <mike.wray@hp.com>
    23.6 - *
    23.7 - * This library is free software; you can redistribute it and/or modify
    23.8 - * it under the terms of the GNU Lesser General Public License as published by
    23.9 - * the Free Software Foundation; either version 2.1 of the License, or
   23.10 - * (at your option) any later version.
   23.11 - *
   23.12 - * This library is distributed in the hope that it will be useful,
   23.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
   23.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   23.15 - * GNU Lesser General Public License for more details.
   23.16 - *
   23.17 - * You should have received a copy of the GNU Lesser General Public License
   23.18 - * along with this library; if not, write to the Free Software
   23.19 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   23.20 - */
   23.21 -
   23.22 -#ifndef _XEN_LIB_KERNEL_STREAM_H_
   23.23 -#define _XEN_LIB_KERNEL_STREAM_H_
   23.24 -
   23.25 -#ifdef __KERNEL__
   23.26 -#include "iostream.h"
   23.27 -
   23.28 -extern IOStream get_stream_kernel(void);
   23.29 -#define get_stream_stdout get_stream_kernel
   23.30 -
   23.31 -#endif /* __KERNEL__ */
   23.32 -#endif /* !_XEN_LIB_KERNEL_STREAM_H_ */
    24.1 --- a/tools/lib/lexis.c	Tue Jun 29 14:14:38 2004 +0000
    24.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    24.3 @@ -1,93 +0,0 @@
    24.4 -/*
    24.5 - *
    24.6 - * This library is free software; you can redistribute it and/or modify
    24.7 - * it under the terms of the GNU Lesser General Public License as
    24.8 - * published by the Free Software Foundation; either version 2.1 of the
    24.9 - * License, or  (at your option) any later version. This library is 
   24.10 - * distributed in the  hope that it will be useful, but WITHOUT ANY
   24.11 - * WARRANTY; without even the implied warranty of MERCHANTABILITY or
   24.12 - * FITNESS FOR A PARTICULAR PURPOSE.
   24.13 - * See the GNU Lesser General Public License for more details.
   24.14 - *
   24.15 - * You should have received a copy of the GNU Lesser General Public License
   24.16 - * along with this library; if not, write to the Free Software Foundation,
   24.17 - * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
   24.18 - */
   24.19 -
   24.20 -/** @file
   24.21 - * Lexical analysis.
   24.22 - */
   24.23 -
   24.24 -#include "sys_string.h"
   24.25 -#include "lexis.h"
   24.26 -#include <errno.h>
   24.27 -
   24.28 -/** Check if a value lies in a (closed) range.
   24.29 - *
   24.30 - * @param x value to test
   24.31 - * @param lo low end of the range
   24.32 - * @param hi high end of the range
   24.33 - * @return 1 if x is in the interval [lo, hi], 0 otherwise
   24.34 - */
   24.35 -inline static int in_range(int x, int lo, int hi){
   24.36 -    return (lo <= x) && (x <= hi);
   24.37 -}
   24.38 -
   24.39 -/** Determine if a string is an (unsigned) decimal number.
   24.40 - * 
   24.41 - * @param s pointer to characters to test
   24.42 - * @param n length of string
   24.43 - * @return 1 if s is a decimal number, 0 otherwise.
   24.44 - */
   24.45 -int is_decimal_number(const char *s, int n){
   24.46 -    int i;
   24.47 -    if(n <= 0)return 0;
   24.48 -    for(i = 0; i < n; i++){
   24.49 -        if(!in_decimal_digit_class(s[i])) return 0;
   24.50 -    }
   24.51 -    return 1;
   24.52 -}
   24.53 -
   24.54 -/** Determine if a string is a hex number.
   24.55 - * Hex numbers are 0, or start with 0x or 0X followed
   24.56 - * by a non-zero number of hex digits (0-9,a-f,A-F).
   24.57 - * 
   24.58 - * @param s pointer to characters to test
   24.59 - * @param n length of string
   24.60 - * @return 1 if s is a hex number, 0 otherwise.
   24.61 - */
   24.62 -int is_hex_number(const char *s, int n){
   24.63 -    int i;
   24.64 -    if(n <= 0) return 0;
   24.65 -    if(n == 1){
   24.66 -        return s[0]=='0';
   24.67 -    }
   24.68 -    if(n <= 3) return 0;
   24.69 -    if(s[0] != '0' || (s[1] != 'x' && s[1] != 'X')) return 0;
   24.70 -    for(i = 2; i < n; i++){
   24.71 -        if(!in_hex_digit_class(s[i])) return 0;
   24.72 -    }
   24.73 -    return 1;
   24.74 -}
   24.75 -
   24.76 -/** Test if a string matches a keyword.
   24.77 - * The comparison is case-insensitive.
   24.78 - * The comparison fails if either argument is null.
   24.79 - *
   24.80 - * @param s string
   24.81 - * @param k keyword
   24.82 - * @return 1 if they match, 0 otherwise
   24.83 - */
   24.84 -int is_keyword(const char *s, const char *k){
   24.85 -  return s && k && !strcasecmp(s, k);
   24.86 -}
   24.87 -
   24.88 -/** Test if a string matches a character.
   24.89 - *
   24.90 - * @param s string
   24.91 - * @param c character (non-null)
   24.92 - * @return 1 if s contains exactly c, 0 otherwise
   24.93 - */
   24.94 -int is_keychar(const char *s, char c){
   24.95 -  return c && (s[0] == c) && !s[1];
   24.96 -}
    25.1 --- a/tools/lib/lexis.h	Tue Jun 29 14:14:38 2004 +0000
    25.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    25.3 @@ -1,122 +0,0 @@
    25.4 -/*
    25.5 - *
    25.6 - * This library is free software; you can redistribute it and/or modify
    25.7 - * it under the terms of the GNU Lesser General Public License as
    25.8 - * published by the Free Software Foundation; either version 2.1 of the
    25.9 - * License, or  (at your option) any later version. This library is 
   25.10 - * distributed in the  hope that it will be useful, but WITHOUT ANY
   25.11 - * WARRANTY; without even the implied warranty of MERCHANTABILITY or
   25.12 - * FITNESS FOR A PARTICULAR PURPOSE.
   25.13 - * See the GNU Lesser General Public License for more details.
   25.14 - *
   25.15 - * You should have received a copy of the GNU Lesser General Public License
   25.16 - * along with this library; if not, write to the Free Software Foundation,
   25.17 - * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
   25.18 - */
   25.19 -
   25.20 -#ifndef _SP_LEXIS_H_
   25.21 -#define _SP_LEXIS_H_
   25.22 -
   25.23 -#include "sys_string.h"
   25.24 -#include "sys_ctype.h"
   25.25 -
   25.26 -/** @file
   25.27 - * Lexical analysis.
   25.28 - */
   25.29 -
   25.30 -/** Class of characters treated as space. */
   25.31 -#define space_class ((char []){ '\n', '\r', '\t', ' ', '\f' , 0 })
   25.32 -
   25.33 -/** Class of separator characters. */
   25.34 -#define sep_class "{}()<>[]@!;"
   25.35 -
   25.36 -#define comment_class "#"
   25.37 -
   25.38 -/** Determine if a character is in a given class.
   25.39 - * 
   25.40 - * @param c character to test
   25.41 - * @param s null-terminated string of characters in the class
   25.42 - * @return 1 if c is in the class, 0 otherwise.
   25.43 - */
   25.44 -static inline int in_class(int c, const char *s){
   25.45 -  return s && (strchr(s, c) != 0);
   25.46 -}
   25.47 -
   25.48 -/** Determine if a character is in the space class.
   25.49 - * 
   25.50 - * @param c character to test
   25.51 - * @return 1 if c is in the class, 0 otherwise.
   25.52 - */
   25.53 -static inline int in_space_class(int c){
   25.54 -    return in_class(c, space_class);
   25.55 -}
   25.56 -
   25.57 -static inline int in_comment_class(int c){
   25.58 -    return in_class(c, comment_class);
   25.59 -}
   25.60 -
   25.61 -/** Determine if a character is in the separator class.
   25.62 - * Separator characters terminate tokens, and do not need space
   25.63 - * to separate them.
   25.64 - * 
   25.65 - * @param c character to test
   25.66 - * @return 1 if c is in the class, 0 otherwise.
   25.67 - */
   25.68 -static inline int in_sep_class(int c){
   25.69 -    return in_class(c, sep_class);
   25.70 -}
   25.71 -
   25.72 -/** Determine if a character is in the alpha class.
   25.73 - * 
   25.74 - * @param c character to test
   25.75 - * @return 1 if c is in the class, 0 otherwise.
   25.76 - */
   25.77 -static inline int in_alpha_class(int c){
   25.78 -    return isalpha(c);
   25.79 -}
   25.80 -
   25.81 -/** Determine if a character is in the octal digit class.
   25.82 - * 
   25.83 - * @param c character to test
   25.84 - * @return 1 if c is in the class, 0 otherwise.
   25.85 - */
   25.86 -static inline int in_octal_digit_class(int c){
   25.87 -    return '0' <= c && c <= '7';
   25.88 -}
   25.89 -
   25.90 -/** Determine if a character is in the decimal digit class.
   25.91 - * 
   25.92 - * @param c character to test
   25.93 - * @return 1 if c is in the class, 0 otherwise.
   25.94 - */
   25.95 -static inline int in_decimal_digit_class(int c){
   25.96 -    return isdigit(c);
   25.97 -}
   25.98 -
   25.99 -/** Determine if a character is in the hex digit class.
  25.100 - * 
  25.101 - * @param c character to test
  25.102 - * @return 1 if c is in the class, 0 otherwise.
  25.103 - */
  25.104 -static inline int in_hex_digit_class(int c){
  25.105 -    return isdigit(c) || in_class(c, "abcdefABCDEF");
  25.106 -}
  25.107 -
  25.108 -
  25.109 -static inline int in_string_quote_class(int c){
  25.110 -    return in_class(c, "'\"");
  25.111 -}
  25.112 -
  25.113 -static inline int in_printable_class(int c){
  25.114 -    return ('A' <= c && c <= 'Z')
  25.115 -        || ('a' <= c && c <= 'z')
  25.116 -        || ('0' <= c && c <= '9')
  25.117 -        || in_class(c, "!$%&*+,-./:;<=>?@^_`{|}~");
  25.118 -}
  25.119 -
  25.120 -extern int is_decimal_number(const char *s, int n);
  25.121 -extern int is_hex_number(const char *s, int n);
  25.122 -extern int is_keyword(const char *s, const char *k);
  25.123 -extern int is_keychar(const char *s, char c);
  25.124 -
  25.125 -#endif /* !_SP_LEXIS_H_ */
    26.1 --- a/tools/lib/lzi_stream.c	Tue Jun 29 14:14:38 2004 +0000
    26.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    26.3 @@ -1,590 +0,0 @@
    26.4 -/* $Id: lzi_stream.c,v 1.4 2003/09/30 15:22:53 mjw Exp $ */
    26.5 -#define __FILE_ID_INFO "$Id: lzi_stream.c,v 1.4 2003/09/30 15:22:53 mjw Exp $"
    26.6 -#include <what.h>
    26.7 -static char __rcsid[] __attribute__((unused)) = WHAT_ID __FILE_ID_INFO;
    26.8 -/*
    26.9 - * Copyright (C) 2003 Hewlett-Packard Company.
   26.10 - *
   26.11 - * This library is free software; you can redistribute it and/or modify
   26.12 - * it under the terms of the GNU Lesser General Public License as published by
   26.13 - * the Free Software Foundation; either version 2.1 of the License, or
   26.14 - * (at your option) any later version.
   26.15 - *
   26.16 - * This library is distributed in the hope that it will be useful,
   26.17 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
   26.18 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   26.19 - * GNU Lesser General Public License for more details.
   26.20 - *
   26.21 - * You should have received a copy of the GNU Lesser General Public License
   26.22 - * along with this library; if not, write to the Free Software
   26.23 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   26.24 - */
   26.25 -
   26.26 -/** @file
   26.27 - * An IOStream implementation using LZI to provide compression and decompression.
   26.28 - * This is designed to provide compression without output latency.
   26.29 - * Flushing an LZI stream flushes all pending data to the underlying stream.
   26.30 - * This is essential for stream-based (e.g. networked) applications.
   26.31 - *
   26.32 - * A compressed data stream is a sequence of blocks.
   26.33 - * Each block is the block size followed by the compressed data.
   26.34 - * The last block has size zero.
   26.35 - * Sizes are 4-byte unsigned in network order.
   26.36 - *
   26.37 - * This format allows compressed data to be read from a stream without reading
   26.38 - * past the logical end of compressed data.
   26.39 - *
   26.40 - * @author Mike Wray <mike.wray@hpl.hp.com>
   26.41 - */
   26.42 -#ifndef __KERNEL__
   26.43 -
   26.44 -#include <stdio.h>
   26.45 -#include <stdlib.h>
   26.46 -#include <errno.h>
   26.47 -#include <string.h>
   26.48 -
   26.49 -#include "zlib.h"
   26.50 -
   26.51 -#include "allocate.h"
   26.52 -#include "lzi_stream.h"
   26.53 -#include "file_stream.h"
   26.54 -#include "marshal.h"
   26.55 -
   26.56 -#define dprintf(fmt, args...) fprintf(stdout, "[DEBUG] LZI>%s" fmt, __FUNCTION__, ##args)
   26.57 -#define wprintf(fmt, args...) fprintf(stderr, "[WARN]  LZI>%s" fmt, __FUNCTION__, ##args)
   26.58 -#define iprintf(fmt, args...) fprintf(stdout, "[INFO]  LZI>%s" fmt, __FUNCTION__, ##args)
   26.59 -#define eprintf(fmt, args...) fprintf(stderr, "[ERROR] LZI>%s" fmt, __FUNCTION__, ##args)
   26.60 -
   26.61 -static int lzi_read(IOStream *s, void *buf, size_t size, size_t count);
   26.62 -static int lzi_write(IOStream *s, const void *buf, size_t size, size_t count);
   26.63 -static int lzi_print(IOStream *s, const char *msg, va_list args);
   26.64 -static int lzi_getc(IOStream *s);
   26.65 -static int lzi_error(IOStream *s);
   26.66 -static int lzi_close(IOStream *s);
   26.67 -static void lzi_free(IOStream *s);
   26.68 -static int lzi_flush(IOStream *s);
   26.69 -
   26.70 -enum {
   26.71 -    LZI_WRITE = 1,
   26.72 -    LZI_READ = 2,
   26.73 -};
   26.74 -
   26.75 -/** Methods used by a gzFile* IOStream. */
   26.76 -static const IOMethods lzi_methods = {
   26.77 -    read: lzi_read,
   26.78 -    write: lzi_write,
   26.79 -    print: lzi_print,
   26.80 -    getc:  lzi_getc,
   26.81 -    error: lzi_error,
   26.82 -    close: lzi_close,
   26.83 -    free:  lzi_free,
   26.84 -    flush: lzi_flush,
   26.85 -};
   26.86 -
   26.87 -#define BUFFER_SIZE (512 * 1024)
   26.88 -
   26.89 -typedef struct LZIState {
   26.90 -    z_stream zstream;
   26.91 -    void *inbuf;
   26.92 -    uint32_t inbuf_size;
   26.93 -    void *outbuf;
   26.94 -    uint32_t outbuf_size;
   26.95 -    /** Underlying stream for I/O. */
   26.96 -    IOStream *io;
   26.97 -    /** Flags. */
   26.98 -    int flags;
   26.99 -    /** Error indicator. */
  26.100 -    int error;
  26.101 -    int eof;
  26.102 -    int plain_bytes;
  26.103 -    int comp_bytes;
  26.104 -    int zstream_initialized;
  26.105 -    int flushed;
  26.106 -} LZIState;
  26.107 -
  26.108 -static inline int LZIState_writeable(LZIState *s){
  26.109 -    return (s->flags & LZI_WRITE) != 0;
  26.110 -}
  26.111 -
  26.112 -static inline int LZIState_readable(LZIState *s){
  26.113 -    return (s->flags & LZI_READ) != 0;
  26.114 -}
  26.115 -
  26.116 -void LZIState_free(LZIState *z){
  26.117 -    if(!z) return;
  26.118 -    if(z->zstream_initialized){
  26.119 -        if(LZIState_writeable(z)){
  26.120 -            deflateEnd(&z->zstream);
  26.121 -        } else if(LZIState_readable(z)){
  26.122 -            inflateEnd(&z->zstream);
  26.123 -        }
  26.124 -    }
  26.125 -    deallocate(z->inbuf);
  26.126 -    deallocate(z->outbuf);
  26.127 -    deallocate(z);
  26.128 -}
  26.129 -
  26.130 -static int mode_flags(const char *mode, int *flags){
  26.131 -    int err = 0;
  26.132 -    int r=0, w=0;
  26.133 -    if(!mode){
  26.134 -        err = -EINVAL;
  26.135 -        goto exit;
  26.136 -    }
  26.137 -    for(; *mode; mode++){
  26.138 -        if(*mode == 'w') w = 1;
  26.139 -        if(*mode == 'r') r = 1;
  26.140 -    }
  26.141 -    if(r + w != 1){
  26.142 -        err = -EINVAL;
  26.143 -        goto exit;
  26.144 -    }
  26.145 -    if(r) *flags |= LZI_READ;
  26.146 -    if(w) *flags |= LZI_WRITE;
  26.147 -  exit:
  26.148 -    return err;
  26.149 -}
  26.150 -
  26.151 -/** Get the stream state.
  26.152 - * 
  26.153 - * @param s lzi stream
  26.154 - * @return stream state.
  26.155 - */
  26.156 -static inline LZIState * lzi_state(IOStream *io){
  26.157 -    return io->data;
  26.158 -}
  26.159 -
  26.160 -IOStream *lzi_stream_io(IOStream *io){
  26.161 -    LZIState *s = lzi_state(io);
  26.162 -    return s->io;
  26.163 -}
  26.164 -
  26.165 -static inline void set_error(LZIState *s, int err){
  26.166 -    if(err < 0 && !s->error){
  26.167 -        s->error = err;
  26.168 -    }
  26.169 -}
  26.170 -
  26.171 -static int zerror(LZIState *s, int err){
  26.172 -    if(err){
  26.173 -        //dprintf("> err=%d\n", err);
  26.174 -        if(err < 0) set_error(s, -EIO);
  26.175 -    }
  26.176 -    return s->error;
  26.177 -}
  26.178 -
  26.179 -int lzi_stream_plain_bytes(IOStream *io){
  26.180 -    LZIState *s = lzi_state(io);
  26.181 -    return s->plain_bytes;
  26.182 -}
  26.183 -
  26.184 -int lzi_stream_comp_bytes(IOStream *io){
  26.185 -    LZIState *s = lzi_state(io);
  26.186 -    return s->comp_bytes;
  26.187 -}
  26.188 -
  26.189 -float lzi_stream_ratio(IOStream *io){
  26.190 -    LZIState *s = lzi_state(io);
  26.191 -    float ratio = 0.0;
  26.192 -    if(s->comp_bytes){
  26.193 -        ratio = ((float) s->comp_bytes)/((float) s->plain_bytes);
  26.194 -    }
  26.195 -    return ratio;
  26.196 -}
  26.197 -
  26.198 -static int alloc(void **p, int n){
  26.199 -    *p = allocate(n);
  26.200 -    return (p ? 0 : -ENOMEM);
  26.201 -}
  26.202 -
  26.203 -LZIState * LZIState_new(IOStream *io, int flags){
  26.204 -    int err = -ENOMEM;
  26.205 -    int zlevel = Z_BEST_SPEED; // Level 1 compression - fastest.
  26.206 -    int zstrategy = Z_DEFAULT_STRATEGY;
  26.207 -    int zwindow = MAX_WBITS;
  26.208 -    int zmemory = 8;
  26.209 -    LZIState *z = ALLOCATE(LZIState);
  26.210 -
  26.211 -    //dprintf(">\n");
  26.212 -    if(!z) goto exit;
  26.213 -    z->io = io;
  26.214 -    z->flags = flags;
  26.215 -
  26.216 -    if(LZIState_writeable(z)){
  26.217 -        z->outbuf_size = BUFFER_SIZE;
  26.218 -        /* windowBits is passed < 0 to suppress zlib header */
  26.219 -        err = deflateInit2(&z->zstream, zlevel, Z_DEFLATED, -zwindow, zmemory, zstrategy);
  26.220 -        if (err != Z_OK) goto exit;
  26.221 -        z->zstream_initialized = 1;
  26.222 -        err = alloc(&z->outbuf, z->outbuf_size);
  26.223 -        if(err) goto exit;
  26.224 -        z->zstream.next_out = z->outbuf;
  26.225 -        z->zstream.avail_out = z->outbuf_size;
  26.226 -    } else {
  26.227 -        z->inbuf_size = BUFFER_SIZE;
  26.228 -        err = alloc(&z->inbuf, z->inbuf_size);
  26.229 -        if(err) goto exit;
  26.230 -        ///z->zstream.next_in  = z->inbuf;
  26.231 -
  26.232 -        /* windowBits is passed < 0 to tell that there is no zlib header.
  26.233 -         * Note that in this case inflate *requires* an extra "dummy" byte
  26.234 -         * after the compressed stream in order to complete decompression and
  26.235 -         * return Z_STREAM_END. Here the gzip CRC32 ensures that 4 bytes are
  26.236 -         * present after the compressed stream.
  26.237 -         */
  26.238 -        err = inflateInit2(&z->zstream, -zwindow);
  26.239 -        if(err != Z_OK) goto exit;
  26.240 -        z->zstream_initialized = 1;
  26.241 -    }
  26.242 -        
  26.243 -  exit:
  26.244 -    if(err){
  26.245 -        LZIState_free(z);
  26.246 -        z = NULL;
  26.247 -    }
  26.248 -    //dprintf("< z=%p\n", z);
  26.249 -    return z;
  26.250 -}
  26.251 -
  26.252 -int read_block(LZIState *s){
  26.253 -    int err = 0, k = 0;
  26.254 -    //dprintf(">\n");
  26.255 -    if(s->eof) goto exit;
  26.256 -    err = unmarshal_uint32(s->io, &k);
  26.257 -    if(err) goto exit;
  26.258 -    if(k > s->inbuf_size){
  26.259 -        err = -EINVAL;
  26.260 -        goto exit;
  26.261 -    }
  26.262 -    if(k){
  26.263 -        err = unmarshal_bytes(s->io, s->inbuf, k);
  26.264 -        if(err) goto exit;
  26.265 -    } else {
  26.266 -        s->eof = 1;
  26.267 -    }        
  26.268 -    s->zstream.avail_in = k;
  26.269 -    s->zstream.next_in = s->inbuf;
  26.270 -    s->comp_bytes += 4;
  26.271 -    s->comp_bytes += k;
  26.272 -  exit:
  26.273 -    //dprintf("< err=%d\n", err);
  26.274 -    return err;
  26.275 -}
  26.276 -
  26.277 -int write_block(LZIState *s){
  26.278 -    int err = 0;
  26.279 -    int k = ((char*)s->zstream.next_out) - ((char*)s->outbuf);
  26.280 -    int k2 = s->outbuf_size - s->zstream.avail_out;
  26.281 -    //dprintf("> k=%d k2=%d\n", k, k2);
  26.282 -    if(!k) goto exit;
  26.283 -    err = marshal_uint32(s->io, k);
  26.284 -    if(err) goto exit;
  26.285 -    err = marshal_bytes(s->io, s->outbuf, k);
  26.286 -    if(err) goto exit;
  26.287 -    s->zstream.next_out = s->outbuf;
  26.288 -    s->zstream.avail_out = s->outbuf_size;
  26.289 -    s->comp_bytes += 4;
  26.290 -    s->comp_bytes += k;
  26.291 -  exit:
  26.292 -    //dprintf("< err=%d\n", err);
  26.293 -    return err;
  26.294 -}
  26.295 -
  26.296 -int write_terminator(LZIState *s){
  26.297 -    int err = 0;
  26.298 -    char c = 0;
  26.299 -    err = marshal_uint32(s->io, 1);
  26.300 -    if(err) goto exit;
  26.301 -    err = marshal_bytes(s->io, &c, 1);
  26.302 -    if(err) goto exit;
  26.303 -    err = marshal_uint32(s->io, 0);
  26.304 -    if(err) goto exit;
  26.305 -    s->comp_bytes += 9;
  26.306 -  exit:
  26.307 -    return err;
  26.308 -}
  26.309 -
  26.310 -/** Write to the underlying stream using fwrite();
  26.311 - *
  26.312 - * @param io destination
  26.313 - * @param buf data
  26.314 - * @param size size of data elements
  26.315 - * @param count number of data elements to write
  26.316 - * @return number of data elements written
  26.317 - */
  26.318 -static int lzi_write(IOStream *io, const void *buf, size_t size, size_t count){
  26.319 -    int err = 0;
  26.320 -    int n = size * count;
  26.321 -    LZIState *s = lzi_state(io);
  26.322 -
  26.323 -    //dprintf("> buf=%p size=%d count=%d n=%d\n", buf, size, count, n);
  26.324 -    if(!LZIState_writeable(s)){
  26.325 -        err = -EINVAL;
  26.326 -        goto exit;
  26.327 -    }
  26.328 -    s->flushed = 0;
  26.329 -    s->zstream.next_in = (void*)buf;
  26.330 -    s->zstream.avail_in = n;
  26.331 -    while(s->zstream.avail_in){
  26.332 -        if(s->zstream.avail_out == 0){
  26.333 -            err = write_block(s);
  26.334 -            if(err) goto exit;
  26.335 -        }
  26.336 -        //dprintf("> 1 deflate avail_in=%d avail_out=%d\n", s->zstream.avail_in, s->zstream.avail_out);
  26.337 -        //dprintf("> 1 deflate next_in=%p next_out=%p\n", s->zstream.next_in, s->zstream.next_out);
  26.338 -        err = zerror(s, deflate(&s->zstream, Z_NO_FLUSH));
  26.339 -        //dprintf("> 2 deflate avail_in=%d avail_out=%d\n", s->zstream.avail_in, s->zstream.avail_out);
  26.340 -        //dprintf("> 2 deflate next_in=%p next_out=%p\n", s->zstream.next_in, s->zstream.next_out);
  26.341 -        if(err) goto exit;
  26.342 -    }
  26.343 -    err = n;
  26.344 -    s->plain_bytes += n;
  26.345 -    if(size != 1) err /= size;
  26.346 -  exit:
  26.347 -    //dprintf("< err=%d\n", err);
  26.348 -    return err;
  26.349 -}
  26.350 -
  26.351 -
  26.352 -/** Read from the underlying stream.
  26.353 - *
  26.354 - * @param io input
  26.355 - * @param buf where to put input
  26.356 - * @param size size of data elements
  26.357 - * @param count number of data elements to read
  26.358 - * @return number of data elements read
  26.359 - */
  26.360 -static int lzi_read(IOStream *io, void *buf, size_t size, size_t count){
  26.361 -    int err, zerr;
  26.362 -    int n = size * count;
  26.363 -    LZIState *s = lzi_state(io);
  26.364 -
  26.365 -    //dprintf("> size=%d count=%d n=%d\n", size, count, n);
  26.366 -    if(!LZIState_readable(s)){
  26.367 -        err = -EINVAL;
  26.368 -        goto exit;
  26.369 -    }
  26.370 -    s->zstream.next_out = buf;
  26.371 -    s->zstream.avail_out = n;
  26.372 -    while(s->zstream.avail_out){
  26.373 -        if(s->zstream.avail_in == 0){
  26.374 -            err = read_block(s);
  26.375 -        }
  26.376 -        //dprintf("> 1 deflate avail_in=%d avail_out=%d\n", s->zstream.avail_in, s->zstream.avail_out);
  26.377 -        zerr = inflate(&s->zstream, Z_NO_FLUSH);
  26.378 -        //dprintf("> 2 deflate avail_in=%d avail_out=%d\n", s->zstream.avail_in, s->zstream.avail_out);
  26.379 -        if(zerr == Z_STREAM_END) break;
  26.380 -        //dprintf("> zerr=%d\n", zerr);
  26.381 -        err = zerror(s, zerr);
  26.382 -        if(err) goto exit;
  26.383 -    }
  26.384 -    err = n - s->zstream.avail_out;
  26.385 -    s->plain_bytes += err;
  26.386 -    if(size != 1) err /= size;
  26.387 -  exit:
  26.388 -    set_error(s, err);
  26.389 -    //dprintf("< err=%d\n", err);
  26.390 -    return err;
  26.391 -}
  26.392 -
  26.393 -/** Print to the underlying stream.
  26.394 - * Returns 0 if the formatted output is too big for the internal buffer.
  26.395 - *
  26.396 - * @param io lzi stream
  26.397 - * @param msg format to use
  26.398 - * @param args arguments
  26.399 - * @return result of the print
  26.400 - */
  26.401 -static int lzi_print(IOStream *io, const char *msg, va_list args){
  26.402 -    char buf[1024];
  26.403 -    int buf_n = sizeof(buf);
  26.404 -    int n;
  26.405 -    LZIState *s = lzi_state(io);
  26.406 -    if(!LZIState_writeable(s)){
  26.407 -        n = -EINVAL;
  26.408 -        goto exit;
  26.409 -    }
  26.410 -    n = vsnprintf(buf, buf_n, (char*)msg, args);
  26.411 -    if(n < 0) goto exit;
  26.412 -    if(n > buf_n){
  26.413 -        n = 0;
  26.414 -    } else {
  26.415 -        n = lzi_write(io, buf, 1, n);
  26.416 -    }
  26.417 -  exit:
  26.418 -    return n;
  26.419 -}
  26.420 -
  26.421 -/** Read a character from the underlying stream
  26.422 - *
  26.423 - * @param io lzi stream
  26.424 - * @return character read, IOSTREAM_EOF on end of file (or error)
  26.425 - */
  26.426 -static int lzi_getc(IOStream *io){
  26.427 -    int err;
  26.428 -    char c;
  26.429 -    err = lzi_read(io, &c, 1, 1);
  26.430 -    if(err < 1) c = EOF;
  26.431 -    err = (c==EOF ? IOSTREAM_EOF : c);
  26.432 -    return err;
  26.433 -}
  26.434 -
  26.435 -static int flush_output(LZIState *s, int mode){
  26.436 -    int err = 0, zerr;
  26.437 -    int done = 0;
  26.438 -    int avail_out_old;
  26.439 -    int count = 10;
  26.440 -
  26.441 -    //dprintf("> avail_in=%d avail_out=%d\n", s->zstream.avail_in, s->zstream.avail_out);
  26.442 -    if(s->flushed == 1 + mode) goto exit;
  26.443 -    //s->zstream.avail_in = 0; /* should be zero already anyway */
  26.444 -    for(;;){
  26.445 -        // Write any available output.
  26.446 -        if(done || s->zstream.avail_out == 0){
  26.447 -            err = write_block(s);
  26.448 -            if(err) goto exit;
  26.449 -            if(done) break;
  26.450 -        }
  26.451 -        //dprintf("> 1 deflate avail_in=%d avail_out=%d\n", s->zstream.avail_in, s->zstream.avail_out);
  26.452 -        avail_out_old = s->zstream.avail_out;
  26.453 -        zerr = deflate(&s->zstream, mode);
  26.454 -        err = zerror(s, zerr);
  26.455 -        //dprintf("> 2 deflate avail_in=%d avail_out=%d\n", s->zstream.avail_in, s->zstream.avail_out);
  26.456 -        //dprintf("> deflate=%d\n", err);
  26.457 -        //done = (s->zstream.avail_out != 0);
  26.458 -        //done = (s->zstream.avail_in == 0) && (s->zstream.avail_out == avail_out_old);
  26.459 -        if(0 && mode == Z_FINISH){
  26.460 -            done = (zerr ==  Z_STREAM_END);
  26.461 -        } else {
  26.462 -            done = (s->zstream.avail_in == 0)
  26.463 -                //&& (s->zstream.avail_out == avail_out_old)
  26.464 -                && (s->zstream.avail_out != 0);
  26.465 -        }
  26.466 -    }
  26.467 -    s->flushed = 1 + mode;
  26.468 -  exit:
  26.469 -    //dprintf("< err=%d\n", err);
  26.470 -    return err;
  26.471 -}
  26.472 -
  26.473 -/** Flush any pending input to the underlying stream.
  26.474 - *
  26.475 - * @param s lzi stream
  26.476 - * @return 0 on success, error code otherwise
  26.477 - */
  26.478 -static int lzi_flush(IOStream *io){
  26.479 -    int err = 0;
  26.480 -    LZIState *s = lzi_state(io);
  26.481 -    //dprintf(">\n");
  26.482 -    if(!LZIState_writeable(s)){
  26.483 -        err = -EINVAL;
  26.484 -        goto exit;
  26.485 -    }
  26.486 -    err = flush_output(s, Z_SYNC_FLUSH);
  26.487 -    if(err) goto exit;
  26.488 -    err = IOStream_flush(s->io);
  26.489 -  exit:
  26.490 -    set_error(s, err);
  26.491 -    //dprintf("< err=%d\n", err);
  26.492 -    return (err < 0 ? err : 0);
  26.493 -}
  26.494 -
  26.495 -/** Check if a stream has an error.
  26.496 - *
  26.497 - * @param s lzi stream
  26.498 - * @return code if has an error, 0 otherwise
  26.499 - */
  26.500 -static int lzi_error(IOStream *s){
  26.501 -    int err = 0;
  26.502 -    LZIState *state = lzi_state(s);
  26.503 -    err = state->error;
  26.504 -    if(err) goto exit;
  26.505 -    err = IOStream_error(state->io);
  26.506 -  exit:
  26.507 -    return err;
  26.508 -}
  26.509 -
  26.510 -/** Close an lzi stream.
  26.511 - *
  26.512 - * @param s lzi stream to close
  26.513 - * @return result of the close
  26.514 - */
  26.515 -static int lzi_close(IOStream *io){
  26.516 -    int err = 0;
  26.517 -    LZIState *s = lzi_state(io);
  26.518 -    if(LZIState_writeable(s)){
  26.519 -        err = flush_output(s, Z_FINISH);
  26.520 -        if(err) goto exit;
  26.521 -        err = write_terminator(s);
  26.522 -        if(err) goto exit;
  26.523 -        err = IOStream_flush(s->io);
  26.524 -    }   
  26.525 -  exit:
  26.526 -    err = IOStream_close(s->io);
  26.527 -    set_error(s, err);
  26.528 -    return err;
  26.529 -}
  26.530 -
  26.531 -/** Free an lzi stream.
  26.532 - *
  26.533 - * @param s lzi stream
  26.534 - */
  26.535 -static void lzi_free(IOStream *s){
  26.536 -    LZIState *state = lzi_state(s);
  26.537 -    IOStream_free(state->io);
  26.538 -    LZIState_free(state);
  26.539 -    s->data = NULL;
  26.540 -}
  26.541 -
  26.542 -/** Create an lzi stream for an IOStream.
  26.543 - *
  26.544 - * @param io stream to wrap
  26.545 - * @return new IOStream using f for i/o
  26.546 - */
  26.547 -IOStream *lzi_stream_new(IOStream *io, const char *mode){
  26.548 -    int err = -ENOMEM;
  26.549 -    int flags = 0;
  26.550 -    IOStream *zio = NULL;
  26.551 -    LZIState *state = NULL;
  26.552 -
  26.553 -    zio = ALLOCATE(IOStream);
  26.554 -    if(!zio) goto exit;
  26.555 -    err = mode_flags(mode, &flags);
  26.556 -    if(err) goto exit;
  26.557 -    state = LZIState_new(io, flags);
  26.558 -    if(!state) goto exit;
  26.559 -    err = 0;
  26.560 -    zio->data = state;
  26.561 -    zio->methods = &lzi_methods;
  26.562 -  exit:
  26.563 -    if(err){
  26.564 -        if(state) LZIState_free(state);
  26.565 -        if(zio) deallocate(zio);
  26.566 -        zio = NULL;
  26.567 -    }
  26.568 -    return zio;
  26.569 -}
  26.570 -
  26.571 -/** IOStream version of fdopen().
  26.572 - *
  26.573 - * @param fd file descriptor
  26.574 - * @param flags giving the mode to open in (as for fdopen())
  26.575 - * @return new stream for the open file, or NULL if failed
  26.576 - */
  26.577 -IOStream *lzi_stream_fdopen(int fd, const char *mode){
  26.578 -    int err = -ENOMEM;
  26.579 -    IOStream *io = NULL, *zio = NULL;
  26.580 -    io = file_stream_fdopen(fd, mode);
  26.581 -    if(!io) goto exit;
  26.582 -    zio = lzi_stream_new(io, mode);
  26.583 -    if(!io) goto exit;
  26.584 -    err = 0;
  26.585 -  exit:
  26.586 -    if(err){
  26.587 -        IOStream_free(io);
  26.588 -        IOStream_free(zio);
  26.589 -        zio = NULL;
  26.590 -    }
  26.591 -    return zio;
  26.592 -}
  26.593 -#endif
    27.1 --- a/tools/lib/lzi_stream.h	Tue Jun 29 14:14:38 2004 +0000
    27.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    27.3 @@ -1,36 +0,0 @@
    27.4 -#/* $Id: lzi_stream.h,v 1.3 2003/09/30 15:22:53 mjw Exp $ */
    27.5 -/*
    27.6 - * Copyright (C) 2003 Hewlett-Packard Company.
    27.7 - *
    27.8 - * This library is free software; you can redistribute it and/or modify
    27.9 - * it under the terms of the GNU Lesser General Public License as published by
   27.10 - * the Free Software Foundation; either version 2.1 of the License, or
   27.11 - * (at your option) any later version.
   27.12 - *
   27.13 - * This library is distributed in the hope that it will be useful,
   27.14 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
   27.15 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   27.16 - * GNU Lesser General Public License for more details.
   27.17 - *
   27.18 - * You should have received a copy of the GNU Lesser General Public License
   27.19 - * along with this library; if not, write to the Free Software
   27.20 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   27.21 - */
   27.22 -
   27.23 -#ifndef _SP_LZI_STREAM_H_
   27.24 -#define _SP_LZI_STREAM_H_
   27.25 -
   27.26 -#ifndef __KERNEL__
   27.27 -#include "iostream.h"
   27.28 -
   27.29 -extern IOStream *lzi_stream_new(IOStream *io, const char *mode);
   27.30 -extern IOStream *lzi_stream_fopen(const char *file, const char *mode);
   27.31 -extern IOStream *lzi_stream_fdopen(int fd, const char *mode);
   27.32 -extern IOStream *lzi_stream_io(IOStream *zio);
   27.33 -
   27.34 -extern int lzi_stream_plain_bytes(IOStream *io);
   27.35 -extern int lzi_stream_comp_bytes(IOStream *io);
   27.36 -extern float lzi_stream_ratio(IOStream *io);
   27.37 -
   27.38 -#endif
   27.39 -#endif /* !_SP_FILE_STREAM_H_ */
    28.1 --- a/tools/lib/lzo_stream.c	Tue Jun 29 14:14:38 2004 +0000
    28.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    28.3 @@ -1,596 +0,0 @@
    28.4 -/* $Id: lzo_stream.c,v 1.4 2003/09/30 15:22:53 mjw Exp $ */
    28.5 -#define __FILE_ID_INFO "$Id: lzo_stream.c,v 1.4 2003/09/30 15:22:53 mjw Exp $"
    28.6 -#include <what.h>
    28.7 -static char __rcsid[] __attribute__((unused)) = WHAT_ID __FILE_ID_INFO;
    28.8 -/*
    28.9 - * Copyright (C) 2003 Hewlett-Packard Company.
   28.10 - *
   28.11 - * This library is free software; you can redistribute it and/or modify
   28.12 - * it under the terms of the GNU Lesser General Public License as published by
   28.13 - * the Free Software Foundation; either version 2.1 of the License, or
   28.14 - * (at your option) any later version.
   28.15 - *
   28.16 - * This library is distributed in the hope that it will be useful,
   28.17 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
   28.18 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   28.19 - * GNU Lesser General Public License for more details.
   28.20 - *
   28.21 - * You should have received a copy of the GNU Lesser General Public License
   28.22 - * along with this library; if not, write to the Free Software
   28.23 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   28.24 - */
   28.25 -
   28.26 -/** @file
   28.27 - * An IOStream implementation using LZO to provide compression and decompression.
   28.28 - * This is designed to provide reasonable compression without output latency.
   28.29 - * Flushing an LZO stream flushes all pending data to the underlying stream.
   28.30 - * This is essential for stream-based (e.g. networked) applications.
   28.31 - *
   28.32 - * A compressed data stream is a sequence of blocks.
   28.33 - * Each block except the last is the plain data size followed by the compressed data size
   28.34 - * and the compressed data. The last block has plain data size zero and omits the rest.
   28.35 - * Sizes are 4-byte unsigned in network order. If the compressed size is smaller than
   28.36 - * the plain size the block data is compressed, otherwise it is plain (uncompressed).
   28.37 - *
   28.38 - * This format allows compressed data to be read from a stream without reading
   28.39 - * past the logical end of compressed data.
   28.40 - *
   28.41 - * @author Mike Wray <mike.wray@hpl.hp.com>
   28.42 - */
   28.43 -#ifndef __KERNEL__
   28.44 -
   28.45 -#include <stdio.h>
   28.46 -#include <stdlib.h>
   28.47 -#include <errno.h>
   28.48 -#include <string.h>
   28.49 -
   28.50 -#include "lzo1x.h"
   28.51 -
   28.52 -#include "allocate.h"
   28.53 -#include "lzo_stream.h"
   28.54 -#include "file_stream.h"
   28.55 -#include "marshal.h"
   28.56 -
   28.57 -#define dprintf(fmt, args...) fprintf(stdout, "[DEBUG] LZO>%s" fmt, __FUNCTION__, ##args)
   28.58 -#define wprintf(fmt, args...) fprintf(stderr, "[WARN]  LZO>%s" fmt, __FUNCTION__, ##args)
   28.59 -#define iprintf(fmt, args...) fprintf(stdout, "[INFO]  LZO>%s" fmt, __FUNCTION__, ##args)
   28.60 -#define eprintf(fmt, args...) fprintf(stderr, "[ERROR] LZO>%s" fmt, __FUNCTION__, ##args)
   28.61 -
   28.62 -static int lzo_read(IOStream *s, void *buf, size_t size, size_t count);
   28.63 -static int lzo_write(IOStream *s, const void *buf, size_t size, size_t count);
   28.64 -static int lzo_print(IOStream *s, const char *msg, va_list args);
   28.65 -static int lzo_getc(IOStream *s);
   28.66 -static int lzo_error(IOStream *s);
   28.67 -static int lzo_close(IOStream *s);
   28.68 -static void lzo_free(IOStream *s);
   28.69 -static int lzo_flush(IOStream *s);
   28.70 -
   28.71 -enum {
   28.72 -    LZO_WRITE = 1,
   28.73 -    LZO_READ = 2,
   28.74 -};
   28.75 -
   28.76 -/** Methods used by a gzFile* IOStream. */
   28.77 -static const IOMethods lzo_methods = {
   28.78 -    read: lzo_read,
   28.79 -    write: lzo_write,
   28.80 -    print: lzo_print,
   28.81 -    getc:  lzo_getc,
   28.82 -    error: lzo_error,
   28.83 -    close: lzo_close,
   28.84 -    free:  lzo_free,
   28.85 -    flush: lzo_flush,
   28.86 -};
   28.87 -
   28.88 -//#define PLAIN_SIZE (64 * 1024)
   28.89 -//#define PLAIN_SIZE (128 * 1024)
   28.90 -#define PLAIN_SIZE (512 * 1024)
   28.91 -
   28.92 -//#define NOCOMPRESS
   28.93 -
   28.94 -typedef struct LZOState {
   28.95 -    /** Flags. */
   28.96 -    int flags;
   28.97 -    /** Error indicator. */
   28.98 -    int error;
   28.99 -    /** Underlying stream for I/O. */
  28.100 -    IOStream *io;
  28.101 -    /** Working memory (only needed for compression, not decompression). */
  28.102 -    lzo_byte *memory;
  28.103 -    /** Buffer for plain (uncompressed) data. */
  28.104 -    lzo_byte *plain;
  28.105 -    /** Size of the plain buffer. */
  28.106 -    lzo_uint plain_size;
  28.107 -    /** Pointer into the plain buffer. */
  28.108 -    lzo_byte *plain_ptr;
  28.109 -    /** Number of bytes of plain data available. */
  28.110 -    lzo_uint plain_n;
  28.111 -    /** Buffer for compressed data. */
  28.112 -    lzo_byte *comp;
  28.113 -    /** Size of the compressed buffer. */
  28.114 -    lzo_uint comp_size;
  28.115 -
  28.116 -    int plain_bytes;
  28.117 -    int comp_bytes;
  28.118 -} LZOState;
  28.119 -
  28.120 -void LZOState_free(LZOState *z){
  28.121 -    if(!z) return;
  28.122 -    deallocate(z->memory);
  28.123 -    deallocate(z->plain);
  28.124 -    deallocate(z->comp);
  28.125 -    deallocate(z);
  28.126 -}
  28.127 -
  28.128 -/** Maximum size of compressed data for the given plain data size.
  28.129 - *
  28.130 - * @param plain_size size of plain data
  28.131 - * @return maximum size of compressed data
  28.132 - */
  28.133 -static int comp_size(int plain_size){
  28.134 -    return plain_size + (plain_size / 64) + 16 + 3;
  28.135 -}
  28.136 -
  28.137 -static int mode_flags(const char *mode, int *flags){
  28.138 -    int err = 0;
  28.139 -    int r=0, w=0;
  28.140 -    if(!mode){
  28.141 -        err = -EINVAL;
  28.142 -        goto exit;
  28.143 -    }
  28.144 -    for(; *mode; mode++){
  28.145 -        if(*mode == 'w') w = 1;
  28.146 -        if(*mode == 'r') r = 1;
  28.147 -    }
  28.148 -    if(r + w != 1){
  28.149 -        err = -EINVAL;
  28.150 -        goto exit;
  28.151 -    }
  28.152 -    if(r) *flags |= LZO_READ;
  28.153 -    if(w) *flags |= LZO_WRITE;
  28.154 -  exit:
  28.155 -    return err;
  28.156 -}
  28.157 -
  28.158 -/** Get the stream state.
  28.159 - * 
  28.160 - * @param s lzo stream
  28.161 - * @return stream state.
  28.162 - */
  28.163 -static inline LZOState * lzo_state(IOStream *s){
  28.164 -    return s->data;
  28.165 -}
  28.166 -
  28.167 -IOStream *lzo_stream_io(IOStream *s){
  28.168 -    LZOState *state = lzo_state(s);
  28.169 -    return state->io;
  28.170 -}
  28.171 -
  28.172 -static inline void set_error(LZOState *state, int err){
  28.173 -    if(err < 0 && !state->error){
  28.174 -        state->error = err;
  28.175 -    }
  28.176 -}
  28.177 -
  28.178 -int lzo_stream_plain_bytes(IOStream *s){
  28.179 -    LZOState *state = lzo_state(s);
  28.180 -    return state->plain_bytes;
  28.181 -}
  28.182 -
  28.183 -int lzo_stream_comp_bytes(IOStream *s){
  28.184 -    LZOState *state = lzo_state(s);
  28.185 -    return state->comp_bytes;
  28.186 -}
  28.187 -
  28.188 -float lzo_stream_ratio(IOStream *s){
  28.189 -    LZOState *state = lzo_state(s);
  28.190 -    float ratio = 0.0;
  28.191 -    if(state->comp_bytes){
  28.192 -        ratio = ((float) state->comp_bytes)/((float) state->plain_bytes);
  28.193 -    }
  28.194 -    return ratio;
  28.195 -}
  28.196 -
  28.197 -static inline int LZOState_writeable(LZOState *state){
  28.198 -    return (state->flags & LZO_WRITE) != 0;
  28.199 -}
  28.200 -
  28.201 -static inline int LZOState_readable(LZOState *state){
  28.202 -    return (state->flags & LZO_READ) != 0;
  28.203 -}
  28.204 -
  28.205 -LZOState * LZOState_new(IOStream *io, int flags){
  28.206 -    int err = -ENOMEM;
  28.207 -    LZOState *z = ALLOCATE(LZOState);
  28.208 -    //dprintf(">\n");
  28.209 -    if(!z) goto exit;
  28.210 -    z->io = io;
  28.211 -    z->flags = flags;
  28.212 -    if(LZOState_writeable(z)){
  28.213 -        z->memory = allocate(LZO1X_1_MEM_COMPRESS);
  28.214 -        if(!z->memory) goto exit;
  28.215 -    }
  28.216 -    z->plain_size = PLAIN_SIZE;
  28.217 -    z->plain = allocate(z->plain_size);
  28.218 -    if(!z->plain) goto exit;
  28.219 -    z->plain_ptr = z->plain;
  28.220 -    z->comp_size = comp_size(z->plain_size);
  28.221 -    z->comp = allocate(z->comp_size);
  28.222 -    if(!z->comp) goto exit;
  28.223 -    err = 0;
  28.224 -  exit:
  28.225 -    if(err){
  28.226 -        LZOState_free(z);
  28.227 -        z = NULL;
  28.228 -    }
  28.229 -    //dprintf("< z=%p\n", z);
  28.230 -    return z;
  28.231 -}
  28.232 -
  28.233 -static int lzo_compress(LZOState *state){
  28.234 -    int err = 0;
  28.235 -    int k, comp_n;
  28.236 -    //dprintf(">\n");
  28.237 -    //dprintf(">plain=%p plain_n=%d comp=%p memory=%p\n", state->plain, state->plain_n, state->comp, state->memory);
  28.238 -    // Compress the plain buffer.
  28.239 -    err = lzo1x_1_compress(state->plain, state->plain_n,
  28.240 -                           state->comp, &comp_n,
  28.241 -                           state->memory);
  28.242 -    //dprintf("> err=%d plain_n=%d comp_n=%d\n", err, state->plain_n, comp_n);
  28.243 -    // Write plain size, compressed size.
  28.244 -    err = marshal_uint32(state->io, state->plain_n);
  28.245 -    if(err) goto exit;
  28.246 -    err = marshal_uint32(state->io, comp_n);
  28.247 -    if(err) goto exit;
  28.248 -    //dprintf("> write data...\n");
  28.249 -    // Write the smaller of the compressed and plain data.
  28.250 -    if(state->plain_n < comp_n){
  28.251 -        k = state->plain_n;
  28.252 -        err = marshal_bytes(state->io, state->plain, state->plain_n);
  28.253 -    } else {
  28.254 -        k = comp_n;
  28.255 -        err = marshal_bytes(state->io, state->comp, comp_n);
  28.256 -    }
  28.257 -    if(err) goto exit;
  28.258 -    // Total output bytes.
  28.259 -    k+= 8;
  28.260 -    //dprintf("> wrote %d bytes\n", k);
  28.261 -    state->plain_bytes += state->plain_n;
  28.262 -    state->comp_bytes += k;
  28.263 -    //dprintf("> plain=%d, comp=%d, ratio=%3.2f\n",
  28.264 -    //        state->plain_bytes, state->comp_bytes,
  28.265 -    //        ((float)state->comp_bytes)/((float)state->plain_bytes));
  28.266 -    // Reset the plain buffer.
  28.267 -    state->plain_ptr = state->plain;
  28.268 -    state->plain_n = 0;
  28.269 -    err = k;
  28.270 -  exit:
  28.271 -    //dprintf("< err=%d\n", err);
  28.272 -    return err;
  28.273 -}
  28.274 -
  28.275 -static int lzo_decompress(LZOState *state){
  28.276 -    int plain_n, comp_n;
  28.277 -    int err, k;
  28.278 -    //dprintf(">\n");
  28.279 -    err = unmarshal_uint32(state->io, &plain_n);
  28.280 -    //dprintf("> err=%d plain_n=%d\n", err, plain_n);
  28.281 -    if(err) goto exit;
  28.282 -    state->comp_bytes += 4;
  28.283 -    if(plain_n == 0) goto exit;
  28.284 -    err = unmarshal_uint32(state->io, &comp_n);
  28.285 -    //dprintf("> err=%d comp_n=%d\n", err, comp_n);
  28.286 -    if(err) goto exit;
  28.287 -    state->comp_bytes += 4;
  28.288 -    if(plain_n > state->plain_size){
  28.289 -        err = -EINVAL;
  28.290 -        goto exit;
  28.291 -    }
  28.292 -    if(comp_n > plain_n){
  28.293 -        //dprintf("> reading plain data %d...\n", plain_n);
  28.294 -        k = plain_n;
  28.295 -        err = unmarshal_bytes(state->io, state->plain, plain_n);
  28.296 -        state->plain_n = plain_n;
  28.297 -    } else {
  28.298 -        //dprintf("> reading comp data %d...\n", comp_n);
  28.299 -        k = comp_n;
  28.300 -        err = unmarshal_bytes(state->io, state->comp, comp_n);
  28.301 -        //dprintf("> decompress comp_n=%d\n", comp_n);
  28.302 -        err = lzo1x_decompress(state->comp, comp_n,
  28.303 -                               state->plain, &state->plain_n,
  28.304 -                               state->memory);
  28.305 -        //dprintf("> err=%d plain=%d state->plain_n=%d\n", err, plain_n, state->plain_n);
  28.306 -        if(err != LZO_E_OK || state->plain_n != plain_n){
  28.307 -            // Bad. Corrupted input.
  28.308 -            err = -EINVAL;
  28.309 -            eprintf("> Corrupted!\n");
  28.310 -            goto exit;
  28.311 -        }
  28.312 -    }
  28.313 -    state->comp_bytes += k;
  28.314 -    state->plain_bytes += state->plain_n;
  28.315 -    state->plain_ptr = state->plain;
  28.316 -    err = k;
  28.317 -  exit:
  28.318 -    //dprintf("< err=%d\n", err);
  28.319 -    return err;
  28.320 -}
  28.321 -
  28.322 -/** Write to the underlying stream using fwrite();
  28.323 - *
  28.324 - * @param stream destination
  28.325 - * @param buf data
  28.326 - * @param size size of data elements
  28.327 - * @param count number of data elements to write
  28.328 - * @return number of data elements written
  28.329 - */
  28.330 -static int lzo_write(IOStream *s, const void *buf, size_t size, size_t count){
  28.331 -    int err = 0;
  28.332 -    int n = size * count; // Total number of bytes to write.
  28.333 -    int chunk;            // Size of chunk to write.
  28.334 -    int remaining;        // Number of bytes remaining to write.
  28.335 -    int space;            // Amount of space left in plain buffer.
  28.336 -    LZOState *state = lzo_state(s);
  28.337 -#ifdef NOCOMPRESS
  28.338 -    //dprintf("> buf=%p size=%d count=%d\n", buf, size, count);
  28.339 -    err = IOStream_write(state->io, buf, size, count);
  28.340 -    //dprintf("< err=%d\n", err);
  28.341 -#else
  28.342 -    //dprintf("> buf=%p size=%d count=%d n=%d\n", buf, size, count, n);
  28.343 -    remaining = n;
  28.344 -    space = state->plain_size - state->plain_n;
  28.345 -    //dprintf("> plain=%p plain_ptr=%p plain_n=%d space=%d\n",
  28.346 -    //        state->plain, state->plain_ptr, state->plain_n, space);
  28.347 -    while(remaining){
  28.348 -        chunk = remaining;
  28.349 -        if(chunk > space) chunk = space;
  28.350 -        //dprintf("> memcpy %p %p %d\n", state->plain_ptr, buf, chunk);
  28.351 -        memcpy(state->plain_ptr, buf, chunk);
  28.352 -        remaining -= chunk;
  28.353 -        space -= chunk;
  28.354 -        state->plain_ptr += chunk;
  28.355 -        state->plain_n += chunk;
  28.356 -        if(space == 0){
  28.357 -            // Input buffer is full. Compress and write it.
  28.358 -            err = lzo_compress(state);
  28.359 -            if(err < 0) goto exit;
  28.360 -            space = state->plain_size - state->plain_n;
  28.361 -        }
  28.362 -    }
  28.363 -    err = (size > 1 ? n / size : n);
  28.364 -  exit:
  28.365 -    set_error(state, err);
  28.366 -#endif
  28.367 -    return err;
  28.368 -}
  28.369 -
  28.370 -
  28.371 -/** Read from the underlying stream.
  28.372 - *
  28.373 - * @param stream input
  28.374 - * @param buf where to put input
  28.375 - * @param size size of data elements
  28.376 - * @param count number of data elements to read
  28.377 - * @return number of data elements read
  28.378 - */
  28.379 -static int lzo_read(IOStream *s, void *buf, size_t size, size_t count){
  28.380 -    int err = 0;
  28.381 -    int k = 0;                     // Number of (plain) bytes read.
  28.382 -    int remaining = size * count;  // Number of bytes remaining to read.
  28.383 -    int chunk;                     // Size of chunk to read.
  28.384 -    LZOState *state = lzo_state(s);
  28.385 -#ifdef NOCOMPRESS
  28.386 -    //dprintf("> buf=%p size=%d count=%d\n", buf, size, count);
  28.387 -    err = IOStream_read(state->io, buf, size, count);
  28.388 -    //dprintf("< err=%d\n", err);
  28.389 -#else
  28.390 -    if(!(state->flags & LZO_READ)){
  28.391 -        err = -EINVAL;
  28.392 -        goto exit;
  28.393 -    }
  28.394 -    while(remaining){
  28.395 -        if(state->plain_n == 0){
  28.396 -            // No more plain input, decompress some more.
  28.397 -            err = lzo_decompress(state);
  28.398 -            if(err < 0) goto exit;
  28.399 -            // Stop reading if there is no more input.
  28.400 -            if(err == 0 || state->plain_n == 0) break;
  28.401 -        }
  28.402 -        chunk = remaining;
  28.403 -        if(chunk > state->plain_n) chunk = state->plain_n;
  28.404 -        memcpy(buf, state->plain_ptr, chunk);
  28.405 -        k += chunk;
  28.406 -        buf += chunk;
  28.407 -        state->plain_ptr += chunk;
  28.408 -        state->plain_n -= chunk;
  28.409 -        remaining -= chunk;
  28.410 -    }
  28.411 -    err = k;
  28.412 -  exit:
  28.413 -    set_error(state, err);
  28.414 -#endif
  28.415 -    return err;
  28.416 -}
  28.417 -
  28.418 -/** Print to the underlying stream.
  28.419 - * Returns 0 if the formatted output is too big for the internal buffer.
  28.420 - *
  28.421 - * @param s lzo stream
  28.422 - * @param msg format to use
  28.423 - * @param args arguments
  28.424 - * @return result of the print
  28.425 - */
  28.426 -static int lzo_print(IOStream *s, const char *msg, va_list args){
  28.427 -    char buf[1024];
  28.428 -    int buf_n = sizeof(buf);
  28.429 -    int n;
  28.430 -    LZOState *state = lzo_state(s);
  28.431 -    if(!LZOState_writeable(state)){
  28.432 -        n = -EINVAL;
  28.433 -        goto exit;
  28.434 -    }
  28.435 -    n = vsnprintf(buf, buf_n, (char*)msg, args);
  28.436 -    if(n < 0) goto exit;
  28.437 -    if(n > buf_n){
  28.438 -        n = 0;
  28.439 -    } else {
  28.440 -        n = lzo_write(s, buf, 1, n);
  28.441 -    }
  28.442 -  exit:
  28.443 -    return n;
  28.444 -}
  28.445 -
  28.446 -/** Read a character from the underlying stream
  28.447 - *
  28.448 - * @param s lzo stream
  28.449 - * @return character read, IOSTREAM_EOF on end of file (or error)
  28.450 - */
  28.451 -static int lzo_getc(IOStream *s){
  28.452 -    int err;
  28.453 -    char c;
  28.454 -    err = lzo_read(s, &c, 1, 1);
  28.455 -    if(err < 1) c = EOF;
  28.456 -    err = (c==EOF ? IOSTREAM_EOF : c);
  28.457 -    return err;
  28.458 -}
  28.459 -
  28.460 -/** Flush any pending input to the underlying stream.
  28.461 - *
  28.462 - * @param s lzo stream
  28.463 - * @return 0 on success, error code otherwise
  28.464 - */
  28.465 -static int lzo_flush(IOStream *s){
  28.466 -    int err = 0;
  28.467 -    LZOState *state = lzo_state(s);
  28.468 -    //dprintf(">\n");
  28.469 -#ifdef NOCOMPRESS
  28.470 -    err = IOStream_flush(state->io);
  28.471 -#else    
  28.472 -    if(!LZOState_writeable(state)){
  28.473 -        err = -EINVAL;
  28.474 -        goto exit;
  28.475 -    }
  28.476 -    if(state->plain_n){
  28.477 -        err = lzo_compress(state);
  28.478 -        if(err < 0) goto exit;
  28.479 -    }
  28.480 -    err = IOStream_flush(state->io);
  28.481 -  exit:
  28.482 -    set_error(state, err);
  28.483 -#endif
  28.484 -    //dprintf("< err=%d\n", err);
  28.485 -    return (err < 0 ? err : 0);
  28.486 -}
  28.487 -
  28.488 -/** Check if a stream has an error.
  28.489 - *
  28.490 - * @param s lzo stream
  28.491 - * @return code if has an error, 0 otherwise
  28.492 - */
  28.493 -static int lzo_error(IOStream *s){
  28.494 -    int err = 0;
  28.495 -    LZOState *state = lzo_state(s);
  28.496 -    err = state->error;
  28.497 -    if(err) goto exit;
  28.498 -    err = IOStream_error(state->io);
  28.499 -  exit:
  28.500 -    return err;
  28.501 -}
  28.502 -
  28.503 -int lzo_stream_finish(IOStream *s){
  28.504 -    int err = 0;
  28.505 -    LZOState *state = lzo_state(s);
  28.506 -    if(!LZOState_writeable(state)){
  28.507 -        err = -EINVAL;
  28.508 -        goto exit;
  28.509 -    }
  28.510 -    err = lzo_flush(s);
  28.511 -    if(err < 0) goto exit;
  28.512 -    err = marshal_int32(state->io, 0);
  28.513 -  exit:
  28.514 -    return err;
  28.515 -}        
  28.516 -
  28.517 -/** Close an lzo stream.
  28.518 - *
  28.519 - * @param s lzo stream to close
  28.520 - * @return result of the close
  28.521 - */
  28.522 -static int lzo_close(IOStream *s){
  28.523 -    int err = 0;
  28.524 -    LZOState *state = lzo_state(s);
  28.525 -#ifdef NOCOMPRESS
  28.526 -    err = IOStream_close(state->io);
  28.527 -#else    
  28.528 -    if(LZOState_writeable(state)){
  28.529 -        err = lzo_stream_finish(s);
  28.530 -    }        
  28.531 -    err = IOStream_close(state->io);
  28.532 -    set_error(state, err);
  28.533 -#endif
  28.534 -    return err;
  28.535 -}
  28.536 -
  28.537 -/** Free an lzo stream.
  28.538 - *
  28.539 - * @param s lzo stream
  28.540 - */
  28.541 -static void lzo_free(IOStream *s){
  28.542 -    LZOState *state = lzo_state(s);
  28.543 -    IOStream_free(state->io);
  28.544 -    LZOState_free(state);
  28.545 -    s->data = NULL;
  28.546 -}
  28.547 -
  28.548 -/** Create an lzo stream for an IOStream.
  28.549 - *
  28.550 - * @param io stream to wrap
  28.551 - * @return new IOStream using f for i/o
  28.552 - */
  28.553 -IOStream *lzo_stream_new(IOStream *io, const char *mode){
  28.554 -    int err = -ENOMEM;
  28.555 -    int flags = 0;
  28.556 -    IOStream *zio = NULL;
  28.557 -    LZOState *state = NULL;
  28.558 -
  28.559 -    zio = ALLOCATE(IOStream);
  28.560 -    if(!zio) goto exit;
  28.561 -    err = mode_flags(mode, &flags);
  28.562 -    if(err) goto exit;
  28.563 -    state = LZOState_new(io, flags);
  28.564 -    if(!state) goto exit;
  28.565 -    err = 0;
  28.566 -    zio->data = state;
  28.567 -    zio->methods = &lzo_methods;
  28.568 -  exit:
  28.569 -    if(err){
  28.570 -        if(state) LZOState_free(state);
  28.571 -        if(zio) deallocate(zio);
  28.572 -        zio = NULL;
  28.573 -    }
  28.574 -    return zio;
  28.575 -}
  28.576 -
  28.577 -/** IOStream version of fdopen().
  28.578 - *
  28.579 - * @param fd file descriptor
  28.580 - * @param flags giving the mode to open in (as for fdopen())
  28.581 - * @return new stream for the open file, or NULL if failed
  28.582 - */
  28.583 -IOStream *lzo_stream_fdopen(int fd, const char *mode){
  28.584 -    int err = -ENOMEM;
  28.585 -    IOStream *io = NULL, *zio = NULL;
  28.586 -    io = file_stream_fdopen(fd, mode);
  28.587 -    if(!io) goto exit;
  28.588 -    zio = lzo_stream_new(io, mode);
  28.589 -    if(!io) goto exit;
  28.590 -    err = 0;
  28.591 -  exit:
  28.592 -    if(err){
  28.593 -        IOStream_free(io);
  28.594 -        IOStream_free(zio);
  28.595 -        zio = NULL;
  28.596 -    }
  28.597 -    return zio;
  28.598 -}
  28.599 -#endif
    29.1 --- a/tools/lib/lzo_stream.h	Tue Jun 29 14:14:38 2004 +0000
    29.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    29.3 @@ -1,36 +0,0 @@
    29.4 -#/* $Id: lzo_stream.h,v 1.3 2003/09/30 15:22:53 mjw Exp $ */
    29.5 -/*
    29.6 - * Copyright (C) 2003 Hewlett-Packard Company.
    29.7 - *
    29.8 - * This library is free software; you can redistribute it and/or modify
    29.9 - * it under the terms of the GNU Lesser General Public License as published by
   29.10 - * the Free Software Foundation; either version 2.1 of the License, or
   29.11 - * (at your option) any later version.
   29.12 - *
   29.13 - * This library is distributed in the hope that it will be useful,
   29.14 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
   29.15 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   29.16 - * GNU Lesser General Public License for more details.
   29.17 - *
   29.18 - * You should have received a copy of the GNU Lesser General Public License
   29.19 - * along with this library; if not, write to the Free Software
   29.20 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   29.21 - */
   29.22 -
   29.23 -#ifndef _SP_LZO_STREAM_H_
   29.24 -#define _SP_LZO_STREAM_H_
   29.25 -
   29.26 -#ifndef __KERNEL__
   29.27 -#include "iostream.h"
   29.28 -
   29.29 -extern IOStream *lzo_stream_new(IOStream *io, const char *mode);
   29.30 -extern IOStream *lzo_stream_fopen(const char *file, const char *mode);
   29.31 -extern IOStream *lzo_stream_fdopen(int fd, const char *mode);
   29.32 -extern IOStream *lzo_stream_io(IOStream *zio);
   29.33 -
   29.34 -extern int lzo_stream_plain_bytes(IOStream *io);
   29.35 -extern int lzo_stream_comp_bytes(IOStream *io);
   29.36 -extern float lzo_stream_ratio(IOStream *io);
   29.37 -
   29.38 -#endif
   29.39 -#endif /* !_SP_FILE_STREAM_H_ */
    30.1 --- a/tools/lib/marshal.c	Tue Jun 29 14:14:38 2004 +0000
    30.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    30.3 @@ -1,207 +0,0 @@
    30.4 -#include <errno.h>
    30.5 -#include "sys_net.h"
    30.6 -#include "allocate.h"
    30.7 -#include "marshal.h"
    30.8 -
    30.9 -#define dprintf(fmt, args...) IOStream_print(iostdout, "[DEBUG] %s" fmt, __FUNCTION__, ##args)
   30.10 -#define wprintf(fmt, args...) IOStream_print(iostderr, "[WARN]  %s" fmt, __FUNCTION__, ##args)
   30.11 -#define iprintf(fmt, args...) IOStream_print(iostdout, "[INFO]  %s" fmt, __FUNCTION__, ##args)
   30.12 -#define eprintf(fmt, args...) IOStream_print(iostderr, "[ERROR] %s" fmt, __FUNCTION__, ##args)
   30.13 -
   30.14 -
   30.15 -#define ARRAY_SIZE(ary) (sizeof(ary)/sizeof((ary)[0]))
   30.16 -
   30.17 -/* Messages are coded as msgid followed by message fields.
   30.18 - * Initial message on any channel is hello - so can check version
   30.19 - * compatibility.
   30.20 - *
   30.21 - * char* -> uint16_t:n <n bytes>
   30.22 - * ints/uints go as suitable number of bytes (e.g. uint16_t is 2 bytes).
   30.23 - * optional fields go as '1' <val> or '0' (the 0/1 is 1 byte).
   30.24 - * lists go as ('1' <elt>)* '0'
   30.25 - */
   30.26 -
   30.27 -int marshal_flush(IOStream *io){
   30.28 -    int err  = 0;
   30.29 -    err = IOStream_flush(io);
   30.30 -    return err;
   30.31 -}
   30.32 -
   30.33 -int marshal_bytes(IOStream *io, void *s, uint32_t s_n){
   30.34 -    int err = 0;
   30.35 -    int n;
   30.36 -    n = IOStream_write(io, s, s_n);
   30.37 -    if(n < 0){
   30.38 -        err = n;
   30.39 -    } else if (n < s_n){
   30.40 -        wprintf("> Wanted %d, got %d\n", s_n, n);
   30.41 -        err = -EIO;
   30.42 -    }
   30.43 -    return err;
   30.44 -}
   30.45 -
   30.46 -int unmarshal_bytes(IOStream *io, void *s, uint32_t s_n){
   30.47 -    int err = 0;
   30.48 -    int n;
   30.49 -    //dprintf("> s_n=%d\n", s_n);
   30.50 -    n = IOStream_read(io, s, s_n);
   30.51 -    //dprintf("> n=%d\n", n);
   30.52 -    if(n < 0){
   30.53 -        err = n;
   30.54 -    } else if(n < s_n){
   30.55 -        wprintf("> Wanted %d, got %d\n", s_n, n);
   30.56 -        err = -EIO;
   30.57 -    }
   30.58 -    //dprintf("< err=%d\n", err);
   30.59 -    return err;
   30.60 -}
   30.61 -
   30.62 -int marshal_uint8(IOStream *io, uint8_t x){
   30.63 -    return marshal_bytes(io, &x, sizeof(x));
   30.64 -}
   30.65 -
   30.66 -int unmarshal_uint8(IOStream *io, uint8_t *x){
   30.67 -    return unmarshal_bytes(io, x, sizeof(*x));
   30.68 -}
   30.69 -
   30.70 -int marshal_uint16(IOStream *io, uint16_t x){
   30.71 -    x = htons(x);
   30.72 -    return marshal_bytes(io, &x, sizeof(x));
   30.73 -}
   30.74 -
   30.75 -int unmarshal_uint16(IOStream *io, uint16_t *x){
   30.76 -    int err = 0;
   30.77 -    err = unmarshal_bytes(io, x, sizeof(*x));
   30.78 -    *x = ntohs(*x);
   30.79 -    return err;
   30.80 -}
   30.81 -
   30.82 -int marshal_int32(IOStream *io, int32_t x){
   30.83 -    int err = 0;
   30.84 -    //dprintf("> x=%d\n", x);
   30.85 -    x = htonl(x);
   30.86 -    err = marshal_bytes(io, &x, sizeof(x));
   30.87 -    //dprintf("< err=%d\n", err);
   30.88 -    return err;
   30.89 -}
   30.90 -
   30.91 -int unmarshal_int32(IOStream *io, int32_t *x){
   30.92 -    int err = 0;
   30.93 -    //dprintf(">\n");
   30.94 -    err = unmarshal_bytes(io, x, sizeof(*x));
   30.95 -    *x = ntohl(*x);
   30.96 -    //dprintf("< err=%d x=%d\n", err, *x);
   30.97 -    return err;
   30.98 -}
   30.99 -
  30.100 -int marshal_uint32(IOStream *io, uint32_t x){
  30.101 -    int err = 0;
  30.102 -    //dprintf("> x=%u\n", x);
  30.103 -    x = htonl(x);
  30.104 -    err = marshal_bytes(io, &x, sizeof(x));
  30.105 -    //dprintf("< err=%d\n", err);
  30.106 -    return err;
  30.107 -}
  30.108 -
  30.109 -int unmarshal_uint32(IOStream *io, uint32_t *x){
  30.110 -    int err = 0;
  30.111 -    //dprintf(">\n");
  30.112 -    err = unmarshal_bytes(io, x, sizeof(*x));
  30.113 -    *x = ntohl(*x);
  30.114 -    //dprintf("< err=%d x=%u\n", err, *x);
  30.115 -    return err;
  30.116 -}
  30.117 -
  30.118 -int marshal_uint64(IOStream *io, uint64_t x){
  30.119 -    int err;
  30.120 -    err = marshal_uint32(io, (uint32_t) ((x >> 32) & 0xffffffff));
  30.121 -    if(err) goto exit;
  30.122 -    err = marshal_uint32(io, (uint32_t) ( x        & 0xffffffff));
  30.123 -  exit:
  30.124 -    return err;
  30.125 -}
  30.126 -
  30.127 -int unmarshal_uint64(IOStream *io, uint64_t *x){
  30.128 -    int err = 0;
  30.129 -    uint32_t hi, lo;
  30.130 -    err = unmarshal_uint32(io, &hi);
  30.131 -    if(err) goto exit;
  30.132 -    err = unmarshal_uint32(io, &lo);
  30.133 -    *x = (((uint64_t) hi) << 32) | lo;
  30.134 -  exit:
  30.135 -    return err;
  30.136 -}
  30.137 -
  30.138 -int marshal_net16(IOStream *io, net16_t x){
  30.139 -    return marshal_bytes(io, &x, sizeof(x));
  30.140 -}
  30.141 -
  30.142 -int unmarshal_net16(IOStream *io, net16_t *x){
  30.143 -    int err = 0;
  30.144 -    err = unmarshal_bytes(io, x, sizeof(*x));
  30.145 -    return err;
  30.146 -}
  30.147 -
  30.148 -int marshal_net32(IOStream *io, net32_t x){
  30.149 -    return marshal_bytes(io, &x, sizeof(x));
  30.150 -}
  30.151 -
  30.152 -int unmarshal_net32(IOStream *io, net32_t *x){
  30.153 -    int err = 0;
  30.154 -    err = unmarshal_bytes(io, x, sizeof(*x));
  30.155 -    return err;
  30.156 -}
  30.157 -
  30.158 -int marshal_string(IOStream *io, char *s, uint32_t s_n){
  30.159 -    int err;
  30.160 -    //dprintf("> s=%s\n", s);
  30.161 -    err = marshal_uint32(io, s_n);
  30.162 -    if(err) goto exit;
  30.163 -    err = marshal_bytes(io, s, s_n);
  30.164 -  exit:
  30.165 -    //dprintf("< err=%d\n", err);
  30.166 -    return err;
  30.167 -}
  30.168 -
  30.169 -int unmarshal_string(IOStream *io, char *s, uint32_t s_n){
  30.170 -    int err = 0, val_n = 0;
  30.171 -    //dprintf(">\n");
  30.172 -    err = unmarshal_uint32(io, &val_n);
  30.173 -    if(err) goto exit;
  30.174 -    if(val_n >= s_n){
  30.175 -        err = -EINVAL;
  30.176 -        goto exit;
  30.177 -    }
  30.178 -    err = unmarshal_bytes(io, s, val_n);
  30.179 -    if(err) goto exit;
  30.180 -    s[val_n] = '\0';
  30.181 -  exit:
  30.182 -    //dprintf("< err=%d s=%s\n", err, s);
  30.183 -    return err;
  30.184 -}
  30.185 -
  30.186 -int unmarshal_new_string(IOStream *io, char **s, uint32_t *s_n){
  30.187 -    int err = 0, val_n = 0;
  30.188 -    char *val = NULL;
  30.189 -    //dprintf(">\n");
  30.190 -    err = unmarshal_uint32(io, &val_n);
  30.191 -    if(err) goto exit;
  30.192 -    val = allocate(val_n + 1);
  30.193 -    if(!val){
  30.194 -        err = -ENOMEM;
  30.195 -        goto exit;
  30.196 -    }
  30.197 -    err = unmarshal_bytes(io, val, val_n);
  30.198 -    if(err) goto exit;
  30.199 -    val[val_n] = '\0';
  30.200 -  exit:
  30.201 -    if(err){
  30.202 -        if(val) deallocate(val);
  30.203 -        val = NULL;
  30.204 -        val_n = 0;
  30.205 -    }
  30.206 -    *s = val;
  30.207 -    if(s_n) *s_n = val_n;
  30.208 -    //dprintf("< err=%d s=%s\n", err, *s);
  30.209 -    return err;
  30.210 -}
    31.1 --- a/tools/lib/marshal.h	Tue Jun 29 14:14:38 2004 +0000
    31.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    31.3 @@ -1,43 +0,0 @@
    31.4 -/* $Id: marshal.h,v 1.1 2003/10/17 15:48:43 mjw Exp $ */
    31.5 -#ifndef _SP_MARSHAL_H_
    31.6 -#define _SP_MARSHAL_H_
    31.7 -
    31.8 -#include "iostream.h"
    31.9 -
   31.10 -/** A 16-bit uint in network order, e.g. a port number. */
   31.11 -typedef uint16_t net16_t;
   31.12 -
   31.13 -/** A 32-bit uint in network order, e.g. an IP address. */
   31.14 -typedef uint32_t net32_t;
   31.15 -
   31.16 -extern int marshal_flush(IOStream *io);
   31.17 -
   31.18 -extern int marshal_bytes(IOStream *io, void *s, uint32_t s_n);
   31.19 -extern int unmarshal_bytes(IOStream *io, void *s, uint32_t s_n);
   31.20 -
   31.21 -extern int marshal_uint8(IOStream *io, uint8_t x);
   31.22 -extern int unmarshal_uint8(IOStream *io, uint8_t *x);
   31.23 -
   31.24 -extern int marshal_uint16(IOStream *io, uint16_t x);
   31.25 -extern int unmarshal_uint16(IOStream *io, uint16_t *x);
   31.26 -
   31.27 -extern int marshal_uint32(IOStream *io, uint32_t x);
   31.28 -extern int unmarshal_uint32(IOStream *io, uint32_t *x);
   31.29 -
   31.30 -extern int marshal_int32(IOStream *io, int32_t x);
   31.31 -extern int unmarshal_int32(IOStream *io, int32_t *x);
   31.32 -
   31.33 -extern int marshal_uint64(IOStream *io, uint64_t x);
   31.34 -extern int unmarshal_uint64(IOStream *io, uint64_t *x);
   31.35 -
   31.36 -extern int marshal_net16(IOStream *io, net16_t x);
   31.37 -extern int unmarshal_net16(IOStream *io, net16_t *x);
   31.38 -
   31.39 -extern int marshal_net32(IOStream *io, net32_t x);
   31.40 -extern int unmarshal_net32(IOStream *io, net32_t *x);
   31.41 -
   31.42 -extern int marshal_string(IOStream *io, char *s, uint32_t s_n);
   31.43 -extern int unmarshal_string(IOStream *io, char *s, uint32_t s_n);
   31.44 -extern int unmarshal_new_string(IOStream *io, char **s, uint32_t *s_n);
   31.45 -
   31.46 -#endif /* ! _SP_MARSHAL_H_ */
    32.1 --- a/tools/lib/socket_stream.c	Tue Jun 29 14:14:38 2004 +0000
    32.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    32.3 @@ -1,259 +0,0 @@
    32.4 -/* $Id: socket_stream.c,v 1.9 2004/03/05 14:45:34 mjw Exp $ */
    32.5 -/*
    32.6 - * Copyright (C) 2004 Mike Wray <mike.wray@hp.com>
    32.7 - *
    32.8 - * This library is free software; you can redistribute it and/or modify
    32.9 - * it under the terms of the GNU Lesser General Public License as published by
   32.10 - * the Free Software Foundation; either version 2.1 of the License, or
   32.11 - * (at your option) any later version.
   32.12 - *
   32.13 - * This library is distributed in the hope that it will be useful,
   32.14 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
   32.15 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   32.16 - * GNU Lesser General Public License for more details.
   32.17 - *
   32.18 - * You should have received a copy of the GNU Lesser General Public License
   32.19 - * along with this library; if not, write to the Free Software
   32.20 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   32.21 - */
   32.22 -
   32.23 -/** @file
   32.24 - * An IOStream implementation using sockets.
   32.25 - */
   32.26 -
   32.27 -#include <stdio.h>
   32.28 -#include <stdlib.h>
   32.29 -#include <string.h>
   32.30 -#include <unistd.h>
   32.31 -#include <errno.h>
   32.32 -#include "allocate.h"
   32.33 -#include "socket_stream.h"
   32.34 -
   32.35 -#define MODULE_NAME "sock"
   32.36 -#define DEBUG 0
   32.37 -//#undef DEBUG
   32.38 -#include "debug.h"
   32.39 -
   32.40 -static int socket_read(IOStream *s, void *buf, size_t n);
   32.41 -static int socket_write(IOStream *s, const void *buf, size_t n);
   32.42 -static int socket_error(IOStream *s);
   32.43 -static int socket_close(IOStream *s);
   32.44 -static void socket_free(IOStream *s);
   32.45 -static int socket_flush(IOStream *s);
   32.46 -
   32.47 -/** Methods used by a socket IOStream. */
   32.48 -static const IOMethods socket_methods = {
   32.49 -    read:  socket_read,
   32.50 -    write: socket_write,
   32.51 -    error: socket_error,
   32.52 -    close: socket_close,
   32.53 -    free:  socket_free,
   32.54 -    flush: socket_flush,
   32.55 -};
   32.56 -
   32.57 -/** Get the socket data.
   32.58 - * 
   32.59 - * @param io socket stream
   32.60 - * @return data
   32.61 - */
   32.62 -static inline SocketData * socket_data(IOStream *io){
   32.63 -    return (SocketData *)io->data;
   32.64 -}
   32.65 -
   32.66 -/** Test if a stream is a socket stream.
   32.67 - *
   32.68 - * @param io stream
   32.69 - * @return 0 if a socket stream, -EINVAL if not
   32.70 - */
   32.71 -int socket_stream_check(IOStream *io){
   32.72 -    return (io && io->methods == &socket_methods ? 0 : -EINVAL);
   32.73 -}
   32.74 -
   32.75 -/** Get the data for a socket stream.
   32.76 - *
   32.77 - * @param io stream
   32.78 - * @param data return value for the data
   32.79 - * @return 0 if a socket stream, -EINVAL if not
   32.80 - */
   32.81 -int socket_stream_data(IOStream *io, SocketData **data){
   32.82 -    int err = socket_stream_check(io);
   32.83 -    if(err){
   32.84 -        *data = NULL;
   32.85 -    } else {
   32.86 -        *data = socket_data(io);
   32.87 -    }
   32.88 -    return err;
   32.89 -}
   32.90 -
   32.91 -/** Set the destination address for a socket stream.
   32.92 - *
   32.93 - * @param io stream
   32.94 - * @param addr address
   32.95 - * @return 0 if a socket stream, -EINVAL if not
   32.96 - */
   32.97 -int socket_stream_set_addr(IOStream *io, struct sockaddr_in *addr){
   32.98 -    int err = 0;
   32.99 -    SocketData *data = NULL;
  32.100 -    err = socket_stream_data(io, &data);
  32.101 -    if(!err){
  32.102 -        data->daddr = *addr;
  32.103 -    }
  32.104 -    return err;
  32.105 -}
  32.106 -
  32.107 -/** Set the send flags for a socket stream.
  32.108 - *
  32.109 - * @param io stream
  32.110 - * @param flags flags
  32.111 - * @return 0 if a socket stream, -EINVAL if not
  32.112 - */
  32.113 -int socket_stream_set_flags(IOStream *io, int flags){
  32.114 -    int err = 0;
  32.115 -    SocketData *data = NULL;
  32.116 -    err = socket_stream_data(io, &data);
  32.117 -    if(!err){
  32.118 -        data->flags = flags;
  32.119 -    }
  32.120 -    return err;
  32.121 -}
  32.122 -
  32.123 -/** Write to the underlying socket using sendto.
  32.124 - *
  32.125 - * @param stream input
  32.126 - * @param buf where to put input
  32.127 - * @param n number of bytes to write
  32.128 - * @return number of bytes written
  32.129 - */
  32.130 -static int socket_write(IOStream *s, const void *buf, size_t n){
  32.131 -    SocketData *data = socket_data(s);
  32.132 -    struct sockaddr *daddr = (struct sockaddr *)&data->daddr;
  32.133 -    socklen_t daddr_n = sizeof(data->daddr);
  32.134 -    int k;
  32.135 -    dprintf("> sock=%d addr=%s:%d n=%d\n",
  32.136 -            data->fd, inet_ntoa(data->daddr.sin_addr), ntohs(data->daddr.sin_port), n);
  32.137 -    if(0){
  32.138 -        struct sockaddr_in self = {};
  32.139 -        socklen_t self_n;
  32.140 -        getsockname(data->fd, (struct sockaddr *)&self, &self_n);
  32.141 -        dprintf("> sockname sock=%d %s:%d\n",
  32.142 -                data->fd, inet_ntoa(self.sin_addr), ntohs(self.sin_port));
  32.143 -    }
  32.144 -    k = sendto(data->fd, buf, n, data->flags, daddr, daddr_n);
  32.145 -    dprintf("> sendto=%d\n", k);
  32.146 -    return k;
  32.147 -}
  32.148 -
  32.149 -/** Read from the underlying stream using recv();
  32.150 - *
  32.151 - * @param stream input
  32.152 - * @param buf where to put input
  32.153 - * @param n number of bytes to read
  32.154 - * @return number of bytes read
  32.155 - */
  32.156 -static int socket_read(IOStream *s, void *buf, size_t n){
  32.157 -    SocketData *data = socket_data(s);
  32.158 -    int k;
  32.159 -    struct sockaddr *saddr = (struct sockaddr *)&data->saddr;
  32.160 -    socklen_t saddr_n = sizeof(data->saddr);
  32.161 -    k = recvfrom(data->fd, buf, n, data->flags, saddr, &saddr_n);
  32.162 -    return k;
  32.163 -}
  32.164 -
  32.165 -/** Print to the underlying socket.
  32.166 - *
  32.167 - * @param s socket stream
  32.168 - * @param msg format to use
  32.169 - * @param args arguments
  32.170 - * @return result of the print
  32.171 - */
  32.172 -static int socket_print(IOStream *s, const char *msg, va_list args){
  32.173 -    SocketData *data = socket_data(s);
  32.174 -    int n;
  32.175 -    n = vsnprintf(data->buf, data->buf_n - 1, msg, args);
  32.176 -    if(0 < n && n < data->buf_n){
  32.177 -        socket_write(s, data->buf, n);
  32.178 -    }
  32.179 -    return n;
  32.180 -}
  32.181 -
  32.182 -/** Read a character from the underlying socket
  32.183 - *
  32.184 - * @param s socket stream
  32.185 - * @return character read, IOSTREAM_EOF on end of socket (or error)
  32.186 - */
  32.187 -static int socket_getc(IOStream *s){
  32.188 -    char b;
  32.189 -    int n, c;
  32.190 -    n = socket_read(s, &b, 1);
  32.191 -    c = (n <= 0 ? IOSTREAM_EOF : b);
  32.192 -    return c;
  32.193 -}
  32.194 -
  32.195 -/** Flush the socket (no-op).
  32.196 - *
  32.197 - * @param s socket stream
  32.198 - * @return 0 on success, error code otherwise
  32.199 - */
  32.200 -static int socket_flush(IOStream *s){
  32.201 -    return 0;
  32.202 -}
  32.203 -
  32.204 -/** Check if a socket stream has an error (no-op).
  32.205 - *
  32.206 - * @param s socket stream
  32.207 - * @return 1 if has an error, 0 otherwise
  32.208 - */
  32.209 -static int socket_error(IOStream *s){
  32.210 -    // Read SOL_SOCKET/SO_ERROR ?
  32.211 -    return 0;
  32.212 -}
  32.213 -
  32.214 -/** Close a socket stream.
  32.215 - *
  32.216 - * @param s socket stream to close
  32.217 - * @return result of the close
  32.218 - */
  32.219 -static int socket_close(IOStream *s){
  32.220 -    SocketData *data = socket_data(s);
  32.221 -    return close(data->fd);
  32.222 -}
  32.223 -
  32.224 -/** Free a socket stream.
  32.225 - *
  32.226 - * @param s socket stream
  32.227 - */
  32.228 -static void socket_free(IOStream *s){
  32.229 -    SocketData *data = socket_data(s);
  32.230 -    deallocate(data);
  32.231 -}
  32.232 -
  32.233 -/** Create an IOStream for a socket.
  32.234 - *
  32.235 - * @param fd socket to wtap
  32.236 - * @return new IOStream using fd for i/o
  32.237 - */
  32.238 -IOStream *socket_stream_new(int fd){
  32.239 -    int err = -ENOMEM;
  32.240 -    IOStream *io = NULL;
  32.241 -    SocketData *data = NULL;
  32.242 -
  32.243 -    io = ALLOCATE(IOStream);
  32.244 -    if(!io) goto exit;
  32.245 -    io->methods = &socket_methods;
  32.246 -    data = ALLOCATE(SocketData);
  32.247 -    if(!data) goto exit;
  32.248 -    io->data = data;
  32.249 -    data->fd = fd;
  32.250 -    data->buf_n = sizeof(data->buf);
  32.251 -    err = 0;
  32.252 -  exit:
  32.253 -    if(err){
  32.254 -        if(io){
  32.255 -            if(data) deallocate(data);
  32.256 -            deallocate(io);
  32.257 -            io = NULL;
  32.258 -        }
  32.259 -    }
  32.260 -    return io;
  32.261 -}
  32.262 -
    33.1 --- a/tools/lib/socket_stream.h	Tue Jun 29 14:14:38 2004 +0000
    33.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    33.3 @@ -1,54 +0,0 @@
    33.4 -/* $Id: socket_stream.h,v 1.2 2004/03/04 17:38:13 mjw Exp $ */
    33.5 -/*
    33.6 - * Copyright (C) 2004 Mike Wray <mike.wray@hp.com>
    33.7 - *
    33.8 - * This library is free software; you can redistribute it and/or modify
    33.9 - * it under the terms of the GNU Lesser General Public License as published by
   33.10 - * the Free Software Foundation; either version 2.1 of the License, or
   33.11 - * (at your option) any later version.
   33.12 - *
   33.13 - * This library is distributed in the hope that it will be useful,
   33.14 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
   33.15 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   33.16 - * GNU Lesser General Public License for more details.
   33.17 - *
   33.18 - * You should have received a copy of the GNU Lesser General Public License
   33.19 - * along with this library; if not, write to the Free Software
   33.20 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   33.21 - */
   33.22 -
   33.23 -#ifndef _XEN_LIB_SOCKET_STREAM_H_
   33.24 -#define _XEN_LIB_SOCKET_STREAM_H_
   33.25 -
   33.26 -#ifndef __KERNEL__
   33.27 -#include "iostream.h"
   33.28 -#include <stdio.h>
   33.29 -
   33.30 -#include <sys/socket.h>
   33.31 -#include <netinet/in.h>
   33.32 -#include <arpa/inet.h>
   33.33 -
   33.34 -/** Data associated with a socket stream. */
   33.35 -typedef struct SocketData {
   33.36 -    /** The socket file descriptor. */
   33.37 -    int fd;
   33.38 -    /** Source address from last read (recvfrom). */
   33.39 -    struct sockaddr_in saddr;
   33.40 -    /** Destination address for writes (sendto). */
   33.41 -    struct sockaddr_in daddr;
   33.42 -    /** Write flags (sendto). */
   33.43 -    int flags;
   33.44 -    /** Buffer size. */
   33.45 -    int buf_n;
   33.46 -    /** Buffer for formatted printing. */
   33.47 -    char buf[1024];
   33.48 -} SocketData;
   33.49 -
   33.50 -extern IOStream *socket_stream_new(int fd);
   33.51 -extern int socket_stream_data(IOStream *io, SocketData **data);
   33.52 -extern int socket_stream_check(IOStream *io);
   33.53 -extern int socket_stream_set_addr(IOStream *io, struct sockaddr_in *addr);
   33.54 -extern int socket_stream_set_flags(IOStream *io, int flags);
   33.55 -
   33.56 -#endif
   33.57 -#endif /* !_XEN_LIB_SOCKET_STREAM_H_ */
    34.1 --- a/tools/lib/string_stream.c	Tue Jun 29 14:14:38 2004 +0000
    34.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    34.3 @@ -1,174 +0,0 @@
    34.4 -/*
    34.5 - * Copyright (C) 2001, 2002 Hewlett-Packard Company.
    34.6 - *
    34.7 - * This library is free software; you can redistribute it and/or modify
    34.8 - * it under the terms of the GNU Lesser General Public License as published by
    34.9 - * the Free Software Foundation; either version 2.1 of the License, or
   34.10 - * (at your option) any later version.
   34.11 - *
   34.12 - * This library is distributed in the hope that it will be useful,
   34.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
   34.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   34.15 - * GNU Lesser General Public License for more details.
   34.16 - *
   34.17 - * You should have received a copy of the GNU Lesser General Public License
   34.18 - * along with this library; if not, write to the Free Software
   34.19 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   34.20 - */
   34.21 -
   34.22 -/** @file
   34.23 - * IOStream subtype for input and output to strings.
   34.24 - * Usable from user or kernel code (with __KERNEL__ defined).
   34.25 - */
   34.26 -
   34.27 -#include "sys_string.h"
   34.28 -#include "string_stream.h"
   34.29 -#include "allocate.h"
   34.30 -
   34.31 -static int string_print(IOStream *io, const char *msg, va_list args);
   34.32 -static int string_getc(IOStream *io);
   34.33 -static int string_error(IOStream *io);
   34.34 -static int string_close(IOStream *io);
   34.35 -static void string_free(IOStream *io);
   34.36 -
   34.37 -/** Methods for a string stream. */
   34.38 -static IOMethods string_methods = {
   34.39 -    //print: string_print,
   34.40 -    //getc:  string_getc,
   34.41 -    error: string_error,
   34.42 -    close: string_close,
   34.43 -    free:  string_free,
   34.44 -};
   34.45 -
   34.46 -/** Get the string stream state.
   34.47 - *
   34.48 - * @param io string stream
   34.49 - * @return state
   34.50 - */
   34.51 -static inline StringData *get_string_data(IOStream *io){
   34.52 -    return (StringData*)io->data;
   34.53 -}
   34.54 -
   34.55 -/** Read a character from a string stream.
   34.56 - *
   34.57 - * @param io string stream
   34.58 - * @return character read, IOSTREAM_EOF if no more input
   34.59 - */
   34.60 -static int string_getc(IOStream *io){
   34.61 -    StringData *data = get_string_data(io);
   34.62 -    int c = IOSTREAM_EOF;
   34.63 -    char *s = data->in;
   34.64 -
   34.65 -    if(s && s < data->end){
   34.66 -        c = (unsigned)*s;
   34.67 -        data->in = s+1;
   34.68 -    }
   34.69 -    return c;
   34.70 -}
   34.71 -
   34.72 -/** Print to a string stream.
   34.73 - * Formats the data to an internal buffer and prints it.
   34.74 - * The formatted data must fit into the internal buffer.
   34.75 - *
   34.76 - * @param io string stream
   34.77 - * @param format print format
   34.78 - * @param args print arguments
   34.79 - * @return result of the print
   34.80 - */
   34.81 -static int string_print(IOStream *io, const char *msg, va_list args){
   34.82 -    StringData *data = get_string_data(io);
   34.83 -    int k = data->end - data->out;
   34.84 -    int n = vsnprintf(data->out, k, (char*)msg, args);
   34.85 -    if(n < 0 || n > k ){
   34.86 -        n = k;
   34.87 -        IOStream_close(io);
   34.88 -    } else {
   34.89 -        data->out += n;
   34.90 -    }
   34.91 -    return n;
   34.92 -}
   34.93 -
   34.94 -/** Test if a string stream has an error.
   34.95 - *
   34.96 - * @param io string stream
   34.97 - * @return 0 if ok, error code otherwise
   34.98 - */
   34.99 -static int string_error(IOStream *io){
  34.100 -    StringData *data = get_string_data(io);
  34.101 -    return data->out == NULL;
  34.102 -}
  34.103 -
  34.104 -/** Close a string stream.
  34.105 - *
  34.106 - * @param io string stream
  34.107 - * @return 0
  34.108 - */
  34.109 -static int string_close(IOStream *io){
  34.110 -    StringData *data = get_string_data(io);
  34.111 -    data->in = NULL;
  34.112 -    data->out = NULL;
  34.113 -    return 0;
  34.114 -}
  34.115 -
  34.116 -/** Free a string stream.
  34.117 - * The stream must have been allocated, not statically created.
  34.118 - * The stream state is freed, but the underlying string is not.
  34.119 - *
  34.120 - * @param io string stream
  34.121 - */
  34.122 -static void string_free(IOStream *io){
  34.123 -    StringData *data = get_string_data(io);
  34.124 -    zero(data, sizeof(*data));
  34.125 -    deallocate(data);
  34.126 -}
  34.127 -
  34.128 -/** Get the methods to use for a string stream.
  34.129 - *
  34.130 - * @return methods
  34.131 - */
  34.132 -IOMethods *string_stream_get_methods(void){
  34.133 -    return &string_methods;
  34.134 -}
  34.135 -
  34.136 -/** Initialise a string stream, usually from static data.
  34.137 - *
  34.138 - * @param io address of IOStream to fill in
  34.139 - * @param data address of StringData to fill in
  34.140 - * @param s string to use
  34.141 - * @param n length of the string
  34.142 - */
  34.143 -void string_stream_init(IOStream *io, StringData *data, char *s, int n){
  34.144 -    if(data && io){
  34.145 -        zero(data, sizeof(*data));
  34.146 -        data->string = (char*)s;
  34.147 -        data->in = data->string;
  34.148 -        data->out = data->string;
  34.149 -        data->size = n;
  34.150 -        data->end = data->string + n;
  34.151 -        zero(io, sizeof(*io));
  34.152 -        io->methods = &string_methods;
  34.153 -        io->data = data;
  34.154 -    }
  34.155 -}
  34.156 -
  34.157 -/** Allocate and initialise a string stream.
  34.158 - *
  34.159 - * @param s string to use
  34.160 - * @param n length of the string
  34.161 - * @return new stream (free using IOStream_free)
  34.162 - */
  34.163 -IOStream *string_stream_new(char *s, int n){
  34.164 -    int ok = 0;
  34.165 -    StringData *data = ALLOCATE(StringData);
  34.166 -    IOStream *io = ALLOCATE(IOStream);
  34.167 -    if(data && io){
  34.168 -        ok = 1;
  34.169 -        string_stream_init(io, data, s, n);
  34.170 -    }
  34.171 -    if(!ok){
  34.172 -        deallocate(data);
  34.173 -        deallocate(io);
  34.174 -        io = NULL;
  34.175 -    }
  34.176 -    return io;
  34.177 -}
    35.1 --- a/tools/lib/string_stream.h	Tue Jun 29 14:14:38 2004 +0000
    35.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    35.3 @@ -1,46 +0,0 @@
    35.4 -/* $Id: string_stream.h,v 1.1 2003/08/22 14:25:48 mjw Exp $ */
    35.5 -/*
    35.6 - * Copyright (C) 2001, 2002 Hewlett-Packard Company.
    35.7 - *
    35.8 - * This library is free software; you can redistribute it and/or modify
    35.9 - * it under the terms of the GNU Lesser General Public License as published by
   35.10 - * the Free Software Foundation; either version 2.1 of the License, or
   35.11 - * (at your option) any later version.
   35.12 - *
   35.13 - * This library is distributed in the hope that it will be useful,
   35.14 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
   35.15 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   35.16 - * GNU Lesser General Public License for more details.
   35.17 - *
   35.18 - * You should have received a copy of the GNU Lesser General Public License
   35.19 - * along with this library; if not, write to the Free Software
   35.20 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   35.21 - */
   35.22 -
   35.23 -#ifndef _SP_STRING_STREAM_H_
   35.24 -#define _SP_STRING_STREAM_H_
   35.25 -
   35.26 -#include "iostream.h"
   35.27 -
   35.28 -/** Internal state for a string stream.
   35.29 - * Exposed here so that string streams can be statically created, using
   35.30 - * string_stream_init().
   35.31 - */
   35.32 -typedef struct {
   35.33 -    /** The string used for input and ouput. */
   35.34 -    char *string;
   35.35 -    /** Output pointer. */
   35.36 -    char *out;
   35.37 -    /** Input pointer. */
   35.38 -    char *in;
   35.39 -    /** Length of string. */
   35.40 -    int size;
   35.41 -    /** End marker. */
   35.42 -    char *end;
   35.43 -} StringData;
   35.44 -
   35.45 -extern IOMethods *string_stream_get_methods(void);
   35.46 -extern IOStream *string_stream_new(char *s, int n);
   35.47 -extern void string_stream_init(IOStream *stream, StringData *data, char *s, int n);
   35.48 -
   35.49 -#endif /* !_SP_STRING_STREAM_H_ */
    36.1 --- a/tools/lib/sxpr.c	Tue Jun 29 14:14:38 2004 +0000
    36.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    36.3 @@ -1,935 +0,0 @@
    36.4 -/*
    36.5 - *
    36.6 - * This library is free software; you can redistribute it and/or modify
    36.7 - * it under the terms of the GNU Lesser General Public License as
    36.8 - * published by the Free Software Foundation; either version 2.1 of the
    36.9 - * License, or  (at your option) any later version. This library is 
   36.10 - * distributed in the  hope that it will be useful, but WITHOUT ANY
   36.11 - * WARRANTY; without even the implied warranty of MERCHANTABILITY or
   36.12 - * FITNESS FOR A PARTICULAR PURPOSE.
   36.13 - * See the GNU Lesser General Public License for more details.
   36.14 - *
   36.15 - * You should have received a copy of the GNU Lesser General Public License
   36.16 - * along with this library; if not, write to the Free Software Foundation,
   36.17 - * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
   36.18 - */
   36.19 -
   36.20 -#include <stdarg.h>
   36.21 -#include "sys_string.h"
   36.22 -#include "lexis.h"
   36.23 -#include "sys_net.h"
   36.24 -#include "hash_table.h"
   36.25 -#include "sxpr.h"
   36.26 -
   36.27 -#include <errno.h>
   36.28 -#undef free
   36.29 -
   36.30 -/** @file
   36.31 - * General representation of sxprs.
   36.32 - * Includes print, equal, and free functions for the sxpr types.
   36.33 - *
   36.34 - * Zero memory containing an Sxpr will have the value ONONE - this is intentional.
   36.35 - * When a function returning an sxpr cannot allocate memory we return ONOMEM.
   36.36 - *
   36.37 - */
   36.38 -
   36.39 -static int atom_print(IOStream *io, Sxpr obj, unsigned flags);
   36.40 -static int atom_equal(Sxpr x, Sxpr y);
   36.41 -static void atom_free(Sxpr obj);
   36.42 -
   36.43 -static int string_print(IOStream *io, Sxpr obj, unsigned flags);
   36.44 -static int string_equal(Sxpr x, Sxpr y);
   36.45 -static void string_free(Sxpr obj);
   36.46 -
   36.47 -static int cons_print(IOStream *io, Sxpr obj, unsigned flags);
   36.48 -static int cons_equal(Sxpr x, Sxpr y);
   36.49 -static void cons_free(Sxpr obj);
   36.50 -
   36.51 -static int null_print(IOStream *io, Sxpr obj, unsigned flags);
   36.52 -static int none_print(IOStream *io, Sxpr obj, unsigned flags);
   36.53 -static int int_print(IOStream *io, Sxpr obj, unsigned flags);
   36.54 -static int bool_print(IOStream *io, Sxpr obj, unsigned flags);
   36.55 -
   36.56 -/** Type definitions. */
   36.57 -static SxprType types[1024] = {
   36.58 -    [T_NONE]     { type:    T_NONE,     name: "none",       print: none_print      },
   36.59 -    [T_NULL]     { type:    T_NULL,     name: "null",       print: null_print      },
   36.60 -    [T_UINT]     { type:    T_UINT,     name: "int",        print: int_print,      },
   36.61 -    [T_BOOL]     { type:    T_BOOL,     name: "bool",       print: bool_print,     },
   36.62 -    [T_ATOM]     { type:    T_ATOM,     name: "atom",       print: atom_print,
   36.63 -		   pointer: TRUE,
   36.64 -		   free:    atom_free,
   36.65 -		   equal:   atom_equal,
   36.66 -		 },
   36.67 -    [T_STRING]   { type:    T_STRING,   name: "string",     print: string_print,
   36.68 -		   pointer: TRUE,
   36.69 -		   free:    string_free,
   36.70 -		   equal:   string_equal,
   36.71 -		 },
   36.72 -    [T_CONS]     { type:    T_CONS,     name: "cons",       print: cons_print,
   36.73 -		   pointer: TRUE,
   36.74 -		   free:    cons_free,
   36.75 -		   equal:   cons_equal,
   36.76 -		 },
   36.77 -};
   36.78 -
   36.79 -/** Number of entries in the types array. */
   36.80 -static int type_sup = sizeof(types)/sizeof(types[0]);
   36.81 -
   36.82 -/** Get the type definition for a given type code.
   36.83 - *
   36.84 - * @param ty type code
   36.85 - * @return type definition or null
   36.86 - */
   36.87 -SxprType *get_sxpr_type(int ty){
   36.88 -    if(0 <= ty && ty < type_sup){
   36.89 -        return types+ty;
   36.90 -    }
   36.91 -    return NULL;
   36.92 -}
   36.93 -
   36.94 -/** The default print function.
   36.95 - *
   36.96 - * @param io stream to print to
   36.97 - * @param x sxpr to print
   36.98 - * @param flags print flags
   36.99 - * @return number of bytes written on success
  36.100 - */
  36.101 -int default_print(IOStream *io, Sxpr x, unsigned flags){
  36.102 -    return IOStream_print(io, "#<%u %lu>\n", get_type(x), get_ul(x));
  36.103 -}
  36.104 -
  36.105 -/** The default equal function.
  36.106 - * Uses eq().
  36.107 - *
  36.108 - * @param x sxpr to compare
  36.109 - * @param y sxpr to compare
  36.110 - * @return 1 if equal, 0 otherwise
  36.111 - */
  36.112 -int default_equal(Sxpr x, Sxpr y){
  36.113 -    return eq(x, y);
  36.114 -}
  36.115 -
  36.116 -/** General sxpr print function.
  36.117 - * Prints an sxpr on a stream using the print function for the sxpr type.
  36.118 - * Printing is controlled by flags from the PrintFlags enum.
  36.119 - * If PRINT_TYPE is in the flags the sxpr type is printed before the sxpr
  36.120 - * (for debugging).
  36.121 - *
  36.122 - * @param io stream to print to
  36.123 - * @param x sxpr to print
  36.124 - * @param flags print flags
  36.125 - * @return number of bytes written
  36.126 - */
  36.127 -int objprint(IOStream *io, Sxpr x, unsigned flags){
  36.128 -    SxprType *def = get_sxpr_type(get_type(x));
  36.129 -    ObjPrintFn *print_fn = (def && def->print ? def->print : default_print);
  36.130 -    int k = 0;
  36.131 -    if(!io) return k;
  36.132 -    if(flags & PRINT_TYPE){
  36.133 -	k += IOStream_print(io, "%s:", def->name);
  36.134 -    }
  36.135 -    k += print_fn(io, x, flags);
  36.136 -    return k;
  36.137 -}
  36.138 -
  36.139 -/** General sxpr free function.
  36.140 - * Frees an sxpr using the free function for its type.
  36.141 - * Free functions must recursively free any subsxprs.
  36.142 - * If no function is defined then the default is to
  36.143 - * free sxprs whose type has pointer true.
  36.144 - * Sxprs must not be used after freeing.
  36.145 - *
  36.146 - * @param x sxpr to free
  36.147 - */
  36.148 -void objfree(Sxpr x){
  36.149 -    SxprType *def = get_sxpr_type(get_type(x));
  36.150 -
  36.151 -    if(def){
  36.152 -	if(def->free){
  36.153 -	    def->free(x);
  36.154 -	} else if (def->pointer){
  36.155 -	    hfree(x);
  36.156 -	}
  36.157 -    }
  36.158 -}
  36.159 -
  36.160 -/** General sxpr equality function.
  36.161 - * Compares x and y using the equal function for x.
  36.162 - * Uses default_equal() if x has no equal function.
  36.163 - *
  36.164 - * @param x sxpr to compare
  36.165 - * @param y sxpr to compare
  36.166 - * @return 1 if equal, 0 otherwise
  36.167 - */
  36.168 -int objequal(Sxpr x, Sxpr y){
  36.169 -    SxprType *def = get_sxpr_type(get_type(x));
  36.170 -    ObjEqualFn *equal_fn = (def && def->equal ? def->equal : default_equal);
  36.171 -    return equal_fn(x, y);
  36.172 -}
  36.173 -
  36.174 -/** Search for a key in an alist.
  36.175 - * An alist is a list of conses, where the cars
  36.176 - * of the conses are the keys. Compares keys using equality.
  36.177 - *
  36.178 - * @param k key
  36.179 - * @param l alist to search
  36.180 - * @return first element of l with car k, or ONULL
  36.181 - */
  36.182 -Sxpr assoc(Sxpr k, Sxpr l){
  36.183 -    for( ; CONSP(l) ; l = CDR(l)){
  36.184 -        Sxpr x = CAR(l);
  36.185 -        if(CONSP(x) && objequal(k, CAR(x))){
  36.186 -            return x;   
  36.187 -        }
  36.188 -    }
  36.189 -    return ONULL;
  36.190 -}
  36.191 -
  36.192 -/** Search for a key in an alist.
  36.193 - * An alist is a list of conses, where the cars
  36.194 - * of the conses are the keys. Compares keys using eq.
  36.195 - *
  36.196 - * @param k key
  36.197 - * @param l alist to search
  36.198 - * @return first element of l with car k, or ONULL
  36.199 - */
  36.200 -Sxpr assocq(Sxpr k, Sxpr l){
  36.201 -    for( ; CONSP(l); l = CDR(l)){
  36.202 -        Sxpr x = CAR(l);
  36.203 -        if(CONSP(x) && eq(k, CAR(x))){
  36.204 -            return x;
  36.205 -        }
  36.206 -    }
  36.207 -    return ONULL;
  36.208 -}
  36.209 -
  36.210 -/** Add a new key and value to an alist.
  36.211 - *
  36.212 - * @param k key
  36.213 - * @param l value
  36.214 - * @param l alist
  36.215 - * @return l with the new cell added to the front
  36.216 - */
  36.217 -Sxpr acons(Sxpr k, Sxpr v, Sxpr l){
  36.218 -    Sxpr x, y;
  36.219 -    x = cons_new(k, v);
  36.220 -    if(NOMEMP(x)) return x;
  36.221 -    y = cons_new(x, l);
  36.222 -    if(NOMEMP(y)) cons_free_cells(x);
  36.223 -    return y;
  36.224 -}
  36.225 -
  36.226 -/** Test if a list contains an element.
  36.227 - * Uses sxpr equality.
  36.228 - *
  36.229 - * @param l list
  36.230 - * @param x element to look for
  36.231 - * @return a tail of l with x as car, or ONULL
  36.232 - */
  36.233 -Sxpr cons_member(Sxpr l, Sxpr x){
  36.234 -    for( ; CONSP(l) && !eq(x, CAR(l)); l = CDR(l)){}
  36.235 -    return l;
  36.236 -}
  36.237 -
  36.238 -/** Test if a list contains an element satisfying a test.
  36.239 - * The test function is called with v and an element of the list.
  36.240 - *
  36.241 - * @param l list
  36.242 - * @param test_fn test function to use
  36.243 - * @param v value for first argument to the test
  36.244 - * @return a tail of l with car satisfying the test, or 0
  36.245 - */
  36.246 -Sxpr cons_member_if(Sxpr l, ObjEqualFn *test_fn, Sxpr v){
  36.247 -    for( ; CONSP(l) && !test_fn(v, CAR(l)); l = CDR(l)){ }
  36.248 -    return l;
  36.249 -}
  36.250 -
  36.251 -/** Test if the elements of list 't' are a subset of the elements
  36.252 - * of list 's'. Element order is not significant.
  36.253 - *
  36.254 - * @param s element list to check subset of
  36.255 - * @param t element list to check if is a subset
  36.256 - * @return 1 if is a subset, 0 otherwise
  36.257 - */
  36.258 -int cons_subset(Sxpr s, Sxpr t){
  36.259 -    for( ; CONSP(t); t = CDR(t)){
  36.260 -	if(!CONSP(cons_member(s, CAR(t)))){
  36.261 -	    return 0;
  36.262 -	}
  36.263 -    }
  36.264 -    return 1;
  36.265 -}
  36.266 -
  36.267 -/** Test if two lists have equal sets of elements.
  36.268 - * Element order is not significant.
  36.269 - *
  36.270 - * @param s list to check
  36.271 - * @param t list to check
  36.272 - * @return 1 if equal, 0 otherwise
  36.273 - */
  36.274 -int cons_set_equal(Sxpr s, Sxpr t){
  36.275 -    return cons_subset(s, t) && cons_subset(t, s);
  36.276 -}
  36.277 -
  36.278 -#ifdef USE_GC
  36.279 -/*============================================================================*/
  36.280 -/* The functions inside this ifdef are only safe if GC is used.
  36.281 - * Otherwise they may leak memory.
  36.282 - */
  36.283 -
  36.284 -/** Remove an element from a list (GC only).
  36.285 - * Uses sxpr equality and removes all instances, even
  36.286 - * if there are more than one.
  36.287 - *
  36.288 - * @param l list to remove elements from
  36.289 - * @param x element to remove
  36.290 - * @return modified input list
  36.291 - */
  36.292 -Sxpr cons_remove(Sxpr l, Sxpr x){
  36.293 -    return cons_remove_if(l, eq, x);
  36.294 -}
  36.295 -
  36.296 -/** Remove elements satisfying a test (GC only).
  36.297 - * The test function is called with v and an element of the set.
  36.298 - *
  36.299 - * @param l list to remove elements from
  36.300 - * @param test_fn function to use to decide if an element should be removed
  36.301 - * @return modified input list
  36.302 - */
  36.303 -Sxpr cons_remove_if(Sxpr l, ObjEqualFn *test_fn, Sxpr v){
  36.304 -    Sxpr prev = ONULL, elt, next;
  36.305 -
  36.306 -    for(elt = l; CONSP(elt); elt = next){
  36.307 -        next = CDR(elt);
  36.308 -        if(test_fn(v, CAR(elt))){
  36.309 -            if(NULLP(prev)){
  36.310 -                l = next;
  36.311 -            } else {
  36.312 -                CDR(prev) = next;
  36.313 -            }
  36.314 -        }
  36.315 -    }
  36.316 -    return l;
  36.317 -}
  36.318 -
  36.319 -/** Set the value for a key in an alist (GC only).
  36.320 - * If the key is present, changes the value, otherwise
  36.321 - * adds a new cell.
  36.322 - *
  36.323 - * @param k key
  36.324 - * @param v value
  36.325 - * @param l alist
  36.326 - * @return modified or extended list
  36.327 - */
  36.328 -Sxpr setf(Sxpr k, Sxpr v, Sxpr l){
  36.329 -    Sxpr e = assoc(k, l);
  36.330 -    if(NULLP(e)){
  36.331 -        l = acons(k, v, l);
  36.332 -    } else {
  36.333 -        CAR(CDR(e)) = v;
  36.334 -    }
  36.335 -    return l;
  36.336 -}
  36.337 -/*============================================================================*/
  36.338 -#endif /* USE_GC */
  36.339 -
  36.340 -/** Create a new atom with the given name.
  36.341 - *
  36.342 - * @param name the name
  36.343 - * @return new atom
  36.344 - */
  36.345 -Sxpr atom_new(char *name){
  36.346 -    Sxpr n, obj = ONOMEM;
  36.347 -
  36.348 -    n = string_new(name);
  36.349 -    if(NOMEMP(n)) goto exit;
  36.350 -    obj = HALLOC(ObjAtom, T_ATOM);
  36.351 -    if(NOMEMP(obj)) goto exit;
  36.352 -    OBJ_ATOM(obj)->name = n;
  36.353 -  exit:
  36.354 -    return obj;
  36.355 -}
  36.356 -
  36.357 -/** Free an atom.
  36.358 - *
  36.359 - * @param obj to free
  36.360 - */
  36.361 -void atom_free(Sxpr obj){
  36.362 -    // Interned atoms are shared, so do not free.
  36.363 -    if(OBJ_ATOM(obj)->interned) return;
  36.364 -    objfree(OBJ_ATOM(obj)->name);
  36.365 -    hfree(obj);
  36.366 -}
  36.367 -
  36.368 -/** Print an atom. Prints the atom name.
  36.369 - *
  36.370 - * @param io stream to print to
  36.371 - * @param obj to print
  36.372 - * @param flags print flags
  36.373 - * @return number of bytes printed
  36.374 - */
  36.375 -int atom_print(IOStream *io, Sxpr obj, unsigned flags){
  36.376 -    //return string_print(io, OBJ_ATOM(obj)->name, (flags | PRINT_RAW));
  36.377 -    return string_print(io, OBJ_ATOM(obj)->name, flags);
  36.378 -}
  36.379 -
  36.380 -/** Atom equality.
  36.381 - *
  36.382 - * @param x to compare
  36.383 - * @param y to compare
  36.384 - * @return 1 if equal, 0 otherwise
  36.385 - */
  36.386 -int atom_equal(Sxpr x, Sxpr y){
  36.387 -    int ok;
  36.388 -    ok = eq(x, y);
  36.389 -    if(ok) goto exit;
  36.390 -    ok = ATOMP(y) && string_equal(OBJ_ATOM(x)->name, OBJ_ATOM(y)->name);
  36.391 -    if(ok) goto exit;
  36.392 -    ok = STRINGP(y) && string_equal(OBJ_ATOM(x)->name, y);
  36.393 -  exit:
  36.394 -    return ok;
  36.395 -}
  36.396 -
  36.397 -/** Get the name of an atom.
  36.398 - *
  36.399 - * @param obj atom
  36.400 - * @return name
  36.401 - */
  36.402 -char * atom_name(Sxpr obj){
  36.403 -    return string_string(OBJ_ATOM(obj)->name);
  36.404 -}
  36.405 -
  36.406 -/** Get the C string from a string sxpr.
  36.407 - *
  36.408 - * @param obj string sxpr
  36.409 - * @return string
  36.410 - */
  36.411 -char * string_string(Sxpr obj){
  36.412 -    return OBJ_STRING(obj);
  36.413 -}
  36.414 -
  36.415 -/** Get the length of a string.
  36.416 - *
  36.417 - * @param obj string
  36.418 - * @return length
  36.419 - */
  36.420 -int string_length(Sxpr obj){
  36.421 -    return strlen(OBJ_STRING(obj));
  36.422 -}
  36.423 -
  36.424 -/** Create a new string. The input string is copied,
  36.425 - * and must be null-terminated.
  36.426 - *
  36.427 - * @param s characters to put in the string
  36.428 - * @return new sxpr
  36.429 - */
  36.430 -Sxpr string_new(char *s){
  36.431 -    int n = (s ? strlen(s) : 0);
  36.432 -    Sxpr obj;
  36.433 -    obj = halloc(n+1, T_STRING);
  36.434 -    if(!NOMEMP(obj)){
  36.435 -        char *str = OBJ_STRING(obj);
  36.436 -        strncpy(str, s, n);
  36.437 -        str[n] = '\0';
  36.438 -    }
  36.439 -    return obj;
  36.440 -}
  36.441 -
  36.442 -/** Free a string.
  36.443 - *
  36.444 - * @param obj to free
  36.445 - */
  36.446 -void string_free(Sxpr obj){
  36.447 -    hfree(obj);
  36.448 -}
  36.449 -
  36.450 -/** Determine if a string needs escapes when printed
  36.451 - * using the given flags.
  36.452 - *
  36.453 - * @param str string to check
  36.454 - * @param flags print flags
  36.455 - * @return 1 if needs escapes, 0 otherwise
  36.456 - */
  36.457 -int needs_escapes(char *str, unsigned flags){
  36.458 -    char *c;
  36.459 -    int val = 0;
  36.460 -
  36.461 -    if(str){
  36.462 -	for(c=str; *c; c++){
  36.463 -	    if(in_alpha_class(*c)) continue;
  36.464 -	    if(in_decimal_digit_class(*c)) continue;
  36.465 -	    if(in_class(*c, "/._+:@~-")) continue;
  36.466 -	    val = 1;
  36.467 -	    break;
  36.468 -	}
  36.469 -    }
  36.470 -    //printf("\n> val=%d str=|%s|\n", val, str);
  36.471 -    return val;
  36.472 -}
  36.473 -
  36.474 -/** Print a string to a stream, with escapes if necessary.
  36.475 - *
  36.476 - * @param io stream to print to
  36.477 - * @param str string
  36.478 - * @param flags print flags
  36.479 - * @return number of bytes written
  36.480 - */
  36.481 -int _string_print(IOStream *io, char *str, unsigned flags){
  36.482 -    int k = 0;
  36.483 -    if((flags & PRINT_RAW) || !needs_escapes(str, flags)){
  36.484 -        k += IOStream_print(io, str);
  36.485 -    } else {
  36.486 -	k += IOStream_print(io, "\"");
  36.487 -	if(str){
  36.488 -            char *s;
  36.489 -            for(s = str; *s; s++){
  36.490 -                if(*s < ' ' || *s >= 127 ){
  36.491 -                    switch(*s){
  36.492 -                    case '\a': k += IOStream_print(io, "\\a");  break;
  36.493 -                    case '\b': k += IOStream_print(io, "\\b");  break;
  36.494 -                    case '\f': k += IOStream_print(io, "\\f");  break;
  36.495 -                    case '\n': k += IOStream_print(io, "\\n");  break;
  36.496 -                    case '\r': k += IOStream_print(io, "\\r");  break;
  36.497 -                    case '\t': k += IOStream_print(io, "\\t");  break;
  36.498 -                    case '\v': k += IOStream_print(io, "\\v");  break;
  36.499 -                    default:
  36.500 -                        // Octal escape;
  36.501 -                        k += IOStream_print(io, "\\%o", *s);
  36.502 -                        break;
  36.503 -                    }
  36.504 -                } else if(*s == c_double_quote ||
  36.505 -                          *s == c_single_quote ||
  36.506 -                          *s == c_escape){
  36.507 -                    k += IOStream_print(io, "\\%c", *s);
  36.508 -                } else {
  36.509 -                    k+= IOStream_print(io, "%c", *s);
  36.510 -                }
  36.511 -            }
  36.512 -	}
  36.513 -	k += IOStream_print(io, "\"");
  36.514 -    }
  36.515 -    return k;
  36.516 -}
  36.517 -
  36.518 -/** Print a string to a stream, with escapes if necessary.
  36.519 - *
  36.520 - * @param io stream to print to
  36.521 - * @param obj string
  36.522 - * @param flags print flags
  36.523 - * @return number of bytes written
  36.524 - */
  36.525 -int string_print(IOStream *io, Sxpr obj, unsigned flags){
  36.526 -    return _string_print(io, OBJ_STRING(obj), flags);
  36.527 -}
  36.528 -
  36.529 -/** Compare an sxpr with a string for equality.
  36.530 - *
  36.531 - * @param x string to compare with
  36.532 - * @param y sxpr to compare
  36.533 - * @return 1 if equal, 0 otherwise
  36.534 - */
  36.535 -int string_equal(Sxpr x, Sxpr y){
  36.536 -    int ok = 0;
  36.537 -    ok = eq(x,y);
  36.538 -    if(ok) goto exit;
  36.539 -    ok = has_type(y, T_STRING) && !strcmp(OBJ_STRING(x), OBJ_STRING(y));
  36.540 -    if(ok) goto exit;
  36.541 -    ok = has_type(y, T_ATOM) && !strcmp(OBJ_STRING(x), atom_name(y));
  36.542 -  exit:
  36.543 -    return ok;
  36.544 -}
  36.545 -
  36.546 -/** Create a new cons cell.
  36.547 - * The cell is ONOMEM if either argument is.
  36.548 - *
  36.549 - * @param car sxpr for the car
  36.550 - * @param cdr sxpr for the cdr
  36.551 - * @return new cons
  36.552 - */
  36.553 -Sxpr cons_new(Sxpr car, Sxpr cdr){
  36.554 -    Sxpr obj;
  36.555 -    if(NOMEMP(car) || NOMEMP(cdr)){
  36.556 -        obj = ONOMEM;
  36.557 -    } else {
  36.558 -        obj = HALLOC(ObjCons, T_CONS);
  36.559 -        if(!NOMEMP(obj)){
  36.560 -            ObjCons *z = OBJ_CONS(obj);
  36.561 -            z->car = car;
  36.562 -            z->cdr = cdr;
  36.563 -        }
  36.564 -    }
  36.565 -    return obj;
  36.566 -}
  36.567 -
  36.568 -/** Push a new element onto a list.
  36.569 - *
  36.570 - * @param list list to add to
  36.571 - * @param elt element to add
  36.572 - * @return 0 if successful, error code otherwise
  36.573 - */
  36.574 -int cons_push(Sxpr *list, Sxpr elt){
  36.575 -    Sxpr l;
  36.576 -    l = cons_new(elt, *list);
  36.577 -    if(NOMEMP(l)) return -ENOMEM;
  36.578 -    *list = l;
  36.579 -    return 0;
  36.580 -}
  36.581 -
  36.582 -/** Free a cons. Recursively frees the car and cdr.
  36.583 - *
  36.584 - * @param obj to free
  36.585 - */
  36.586 -void cons_free(Sxpr obj){
  36.587 -    Sxpr next;
  36.588 -    for(; CONSP(obj); obj = next){
  36.589 -	next = CDR(obj);
  36.590 -	objfree(CAR(obj));
  36.591 -	hfree(obj);
  36.592 -    }
  36.593 -    if(!NULLP(obj)){
  36.594 -	objfree(obj);
  36.595 -    }
  36.596 -}
  36.597 -
  36.598 -/** Free a cons and its cdr cells, but not the car sxprs.
  36.599 - * Does nothing if called on something that is not a cons.
  36.600 - *
  36.601 - * @param obj to free
  36.602 - */
  36.603 -void cons_free_cells(Sxpr obj){
  36.604 -    Sxpr next;
  36.605 -    for(; CONSP(obj); obj = next){
  36.606 -	next = CDR(obj);
  36.607 -	hfree(obj);
  36.608 -    }
  36.609 -}
  36.610 -
  36.611 -/** Print a cons.
  36.612 - * Prints the cons in list format if the cdrs are conses.
  36.613 - * uses pair (dot) format if the last cdr is not a cons (or null).
  36.614 - *
  36.615 - * @param io stream to print to
  36.616 - * @param obj to print
  36.617 - * @param flags print flags
  36.618 - * @return number of bytes written
  36.619 - */
  36.620 -int cons_print(IOStream *io, Sxpr obj, unsigned flags){
  36.621 -    int first = 1;
  36.622 -    int k = 0;
  36.623 -    k += IOStream_print(io, "(");
  36.624 -    for( ; CONSP(obj) ; obj = CDR(obj)){
  36.625 -        if(first){ 
  36.626 -            first = 0;
  36.627 -        } else {
  36.628 -            k += IOStream_print(io, " ");
  36.629 -        }
  36.630 -        k += objprint(io, CAR(obj), flags);
  36.631 -    }
  36.632 -    if(!NULLP(obj)){
  36.633 -        k += IOStream_print(io, " . ");
  36.634 -        k += objprint(io, obj, flags);
  36.635 -    }
  36.636 -    k += IOStream_print(io, ")");
  36.637 -    return (IOStream_error(io) ? -1 : k);
  36.638 -}
  36.639 -
  36.640 -/** Compare a cons with another sxpr for equality.
  36.641 - * If y is a cons, compares the cars and cdrs recursively.
  36.642 - *
  36.643 - * @param x cons to compare
  36.644 - * @param y sxpr to compare
  36.645 - * @return 1 if equal, 0 otherwise
  36.646 - */
  36.647 -int cons_equal(Sxpr x, Sxpr y){
  36.648 -    return CONSP(y) &&
  36.649 -        objequal(CAR(x), CAR(y)) &&
  36.650 -        objequal(CDR(x), CDR(y));
  36.651 -}
  36.652 -
  36.653 -/** Return the length of a cons list.
  36.654 - *
  36.655 - * @param obj list
  36.656 - * @return length
  36.657 - */
  36.658 -int cons_length(Sxpr obj){
  36.659 -    int count = 0;
  36.660 -    for( ; CONSP(obj); obj = CDR(obj)){
  36.661 -        count++;
  36.662 -    }
  36.663 -    return count;
  36.664 -}
  36.665 -
  36.666 -/** Destructively reverse a cons list in-place.
  36.667 - * If the argument is not a cons it is returned unchanged.
  36.668 - * 
  36.669 - * @param l to reverse
  36.670 - * @return reversed list
  36.671 - */
  36.672 -Sxpr nrev(Sxpr l){
  36.673 -    if(CONSP(l)){
  36.674 -	// Iterate down the cells in the list making the cdr of
  36.675 -	// each cell point to the previous cell. The last cell 
  36.676 -	// is the head of the reversed list.
  36.677 -	Sxpr prev = ONULL;
  36.678 -	Sxpr cell = l;
  36.679 -	Sxpr next;
  36.680 -
  36.681 -	while(1){
  36.682 -	    next = CDR(cell);
  36.683 -	    CDR(cell) = prev;
  36.684 -	    if(!CONSP(next)) break;
  36.685 -	    prev = cell;
  36.686 -	    cell = next;
  36.687 -	}
  36.688 -	l = cell;
  36.689 -    }
  36.690 -    return l;
  36.691 -}
  36.692 -
  36.693 -/** Print the null sxpr.	
  36.694 - *
  36.695 - * @param io stream to print to
  36.696 - * @param obj to print
  36.697 - * @param flags print flags
  36.698 - * @return number of bytes written
  36.699 - */
  36.700 -static int null_print(IOStream *io, Sxpr obj, unsigned flags){
  36.701 -    return IOStream_print(io, "()");
  36.702 -}
  36.703 -
  36.704 -/** Print the `unspecified' sxpr none.
  36.705 - *
  36.706 - * @param io stream to print to
  36.707 - * @param obj to print
  36.708 - * @param flags print flags
  36.709 - * @return number of bytes written
  36.710 - */
  36.711 -static int none_print(IOStream *io, Sxpr obj, unsigned flags){
  36.712 -    return IOStream_print(io, "<none>");
  36.713 -}
  36.714 -
  36.715 -/** Print an integer.
  36.716 - *
  36.717 - * @param io stream to print to
  36.718 - * @param obj to print
  36.719 - * @param flags print flags
  36.720 - * @return number of bytes written
  36.721 - */
  36.722 -static int int_print(IOStream *io, Sxpr obj, unsigned flags){
  36.723 -    return IOStream_print(io, "%d", OBJ_INT(obj));
  36.724 -}
  36.725 -
  36.726 -/** Print a boolean.
  36.727 - *
  36.728 - * @param io stream to print to
  36.729 - * @param obj to print
  36.730 - * @param flags print flags
  36.731 - * @return number of bytes written
  36.732 - */
  36.733 -static int bool_print(IOStream *io, Sxpr obj, unsigned flags){
  36.734 -    return IOStream_print(io, (OBJ_UINT(obj) ? k_true : k_false));
  36.735 -}
  36.736 -
  36.737 -int sxprp(Sxpr obj, Sxpr name){
  36.738 -    return CONSP(obj) && objequal(CAR(obj), name);
  36.739 -}
  36.740 -
  36.741 -/** Get the name of an element.
  36.742 - * 
  36.743 - * @param obj element
  36.744 - * @return name
  36.745 - */
  36.746 -Sxpr sxpr_name(Sxpr obj){
  36.747 -    Sxpr val = ONONE;
  36.748 -    if(CONSP(obj)){
  36.749 -        val = CAR(obj);
  36.750 -    } else if(STRINGP(obj) || ATOMP(obj)){
  36.751 -        val = obj;
  36.752 -    }
  36.753 -    return val;
  36.754 -}
  36.755 -
  36.756 -int sxpr_is(Sxpr obj, char *s){
  36.757 -    if(ATOMP(obj)) return !strcmp(atom_name(obj), s);
  36.758 -    if(STRINGP(obj)) return !strcmp(string_string(obj), s);
  36.759 -    return 0;
  36.760 -}
  36.761 -
  36.762 -int sxpr_elementp(Sxpr obj, Sxpr name){
  36.763 -    return CONSP(obj) && objequal(CAR(obj), name);
  36.764 -}
  36.765 -
  36.766 -/** Get the attributes of an sxpr.
  36.767 - * 
  36.768 - * @param obj sxpr
  36.769 - * @return attributes
  36.770 - */
  36.771 -Sxpr sxpr_attributes(Sxpr obj){
  36.772 -    Sxpr val = ONULL;
  36.773 -    if(CONSP(obj)){
  36.774 -        obj = CDR(obj);
  36.775 -        if(CONSP(obj)){
  36.776 -            obj = CAR(obj);
  36.777 -            if(sxprp(obj, intern("@"))){
  36.778 -                val = CDR(obj);
  36.779 -            }
  36.780 -        }
  36.781 -    }
  36.782 -    return val;
  36.783 -}
  36.784 -
  36.785 -Sxpr sxpr_attribute(Sxpr obj, Sxpr key, Sxpr def){
  36.786 -    Sxpr val = ONONE;
  36.787 -    val = assoc(sxpr_attributes(obj), key);
  36.788 -    if(CONSP(val) && CONSP(CDR(val))){
  36.789 -        val = CADR(def);
  36.790 -    } else {
  36.791 -        val = def;
  36.792 -    }
  36.793 -    return val;
  36.794 -}
  36.795 -
  36.796 -/** Get the children of an sxpr.
  36.797 - * 
  36.798 - * @param obj sxpr
  36.799 - * @return children
  36.800 - */
  36.801 -Sxpr sxpr_children(Sxpr obj){
  36.802 -    Sxpr val = ONULL;
  36.803 -    if(CONSP(obj)){
  36.804 -        val = CDR(obj);
  36.805 -        if(CONSP(val) && sxprp(CAR(val), intern("@"))){
  36.806 -            val = CDR(val);
  36.807 -        }
  36.808 -    }
  36.809 -    return val;
  36.810 -}
  36.811 -
  36.812 -Sxpr sxpr_child(Sxpr obj, Sxpr name, Sxpr def){
  36.813 -    Sxpr val = ONONE;
  36.814 -    Sxpr l;
  36.815 -    for(l = sxpr_children(obj); CONSP(l); l = CDR(l)){
  36.816 -        if(sxprp(CAR(l), name)){
  36.817 -            val = CAR(l);
  36.818 -            break;
  36.819 -        }
  36.820 -    }
  36.821 -    if(NONEP(val)) val = def;
  36.822 -    return val;
  36.823 -}
  36.824 -
  36.825 -Sxpr sxpr_child0(Sxpr obj, Sxpr def){
  36.826 -    Sxpr val = ONONE;
  36.827 -    Sxpr l = sxpr_children(obj);
  36.828 -    if(CONSP(l)){
  36.829 -        val = CAR(l);
  36.830 -    } else {
  36.831 -        val = def;
  36.832 -    }
  36.833 -    return val;
  36.834 -}
  36.835 -
  36.836 -Sxpr sxpr_child_value(Sxpr obj, Sxpr name, Sxpr def){
  36.837 -    Sxpr val = ONONE;
  36.838 -    val = sxpr_child(obj, name, ONONE);
  36.839 -    if(NONEP(val)){
  36.840 -        val = def;
  36.841 -    } else {
  36.842 -        val = sxpr_child0(val, def);
  36.843 -    }
  36.844 -    return val;
  36.845 -}
  36.846 -
  36.847 -/** Table of interned symbols. Indexed by symbol name. */
  36.848 -static HashTable *symbols = NULL;
  36.849 -
  36.850 -/** Hash function for entries in the symbol table.
  36.851 - *
  36.852 - * @param key to hash
  36.853 - * @return hashcode
  36.854 - */
  36.855 -static Hashcode sym_hash_fn(void *key){
  36.856 -    return hash_string((char*)key);
  36.857 -}
  36.858 -
  36.859 -/** Key equality function for the symbol table.
  36.860 - *
  36.861 - * @param x to compare
  36.862 - * @param y to compare
  36.863 - * @return 1 if equal, 0 otherwise
  36.864 - */
  36.865 -static int sym_equal_fn(void *x, void *y){
  36.866 -    return !strcmp((char*)x, (char*)y);
  36.867 -}
  36.868 -
  36.869 -/** Entry free function for the symbol table.
  36.870 - *
  36.871 - * @param table the entry is in
  36.872 - * @param entry being freed
  36.873 - */
  36.874 -static void sym_free_fn(HashTable *table, HTEntry *entry){
  36.875 -    if(entry){
  36.876 -	objfree(((ObjAtom*)entry->value)->name);
  36.877 -	HTEntry_free(entry);
  36.878 -    }
  36.879 -}
  36.880 -	
  36.881 -/** Initialize the symbol table.
  36.882 - *
  36.883 - * @return 0 on sucess, error code otherwise
  36.884 - */
  36.885 -static int init_symbols(void){
  36.886 -    symbols = HashTable_new(100);
  36.887 -    if(symbols){
  36.888 -        symbols->key_hash_fn = sym_hash_fn;
  36.889 -        symbols->key_equal_fn = sym_equal_fn;
  36.890 -	symbols->entry_free_fn = sym_free_fn;
  36.891 -        return 0;
  36.892 -    }
  36.893 -    return -1;
  36.894 -}
  36.895 -
  36.896 -/** Cleanup the symbol table. Frees the table and all its symbols.
  36.897 - */
  36.898 -void cleanup_symbols(void){
  36.899 -    HashTable_free(symbols);
  36.900 -    symbols = NULL;
  36.901 -}
  36.902 -
  36.903 -/** Get the interned symbol with the given name.
  36.904 - * No new symbol is created.
  36.905 - *
  36.906 - * @return symbol or null
  36.907 - */
  36.908 -Sxpr get_symbol(char *sym){
  36.909 -    HTEntry *entry;
  36.910 -    if(!symbols){
  36.911 -	if(init_symbols()) return ONOMEM;
  36.912 -	return ONULL;
  36.913 -    }
  36.914 -    entry = HashTable_get_entry(symbols, sym);
  36.915 -    if(entry){
  36.916 -        return OBJP(T_ATOM, entry->value);
  36.917 -    } else {
  36.918 -        return ONULL;
  36.919 -    }
  36.920 -}
  36.921 -
  36.922 -/** Get the interned symbol with the given name.
  36.923 - * Creates a new symbol if necessary.
  36.924 - *
  36.925 - * @return symbol
  36.926 - */
  36.927 -Sxpr intern(char *sym){
  36.928 -    Sxpr symbol = get_symbol(sym);
  36.929 -    if(NULLP(symbol)){
  36.930 -	if(!symbols) return ONOMEM;
  36.931 -        symbol = atom_new(sym);
  36.932 -        if(!NOMEMP(symbol)){
  36.933 -	    OBJ_ATOM(symbol)->interned = TRUE;
  36.934 -            HashTable_add(symbols, atom_name(symbol), get_ptr(symbol));
  36.935 -        }
  36.936 -    }
  36.937 -    return symbol;
  36.938 -}
    37.1 --- a/tools/lib/sxpr.h	Tue Jun 29 14:14:38 2004 +0000
    37.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    37.3 @@ -1,413 +0,0 @@
    37.4 -/*
    37.5 - *
    37.6 - * This library is free software; you can redistribute it and/or modify
    37.7 - * it under the terms of the GNU Lesser General Public License as
    37.8 - * published by the Free Software Foundation; either version 2.1 of the
    37.9 - * License, or  (at your option) any later version. This library is 
   37.10 - * distributed in the  hope that it will be useful, but WITHOUT ANY
   37.11 - * WARRANTY; without even the implied warranty of MERCHANTABILITY or
   37.12 - * FITNESS FOR A PARTICULAR PURPOSE.
   37.13 - * See the GNU Lesser General Public License for more details.
   37.14 - *
   37.15 - * You should have received a copy of the GNU Lesser General Public License
   37.16 - * along with this library; if not, write to the Free Software Foundation,
   37.17 - * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
   37.18 - */
   37.19 -#ifndef _XEN_LIB_SXPR_H_
   37.20 -#define _XEN_LIB_SXPR_H_
   37.21 -
   37.22 -#include <stdint.h>
   37.23 -
   37.24 -#include "hash_table.h"
   37.25 -#include "iostream.h"
   37.26 -#include "allocate.h"
   37.27 -
   37.28 -/** @file
   37.29 - * Definitions for rules and sxprs.
   37.30 - */
   37.31 -
   37.32 -#ifndef NULL
   37.33 -#define NULL 0
   37.34 -#endif
   37.35 -
   37.36 -#ifndef TRUE
   37.37 -#define TRUE 1
   37.38 -#endif
   37.39 -
   37.40 -#ifndef FALSE
   37.41 -#define FALSE 0
   37.42 -#endif
   37.43 -
   37.44 -/** Sxpr type. */
   37.45 -typedef int16_t TypeCode;
   37.46 -
   37.47 -/** A typed sxpr handle.*/
   37.48 -typedef struct Sxpr {
   37.49 -    /** Sxpr type. */
   37.50 -    TypeCode type;
   37.51 -    union {
   37.52 -	/** Sxpr value. */
   37.53 -        unsigned long ul;
   37.54 -	/** Pointer. */
   37.55 -        void *ptr;
   37.56 -    } v;
   37.57 -} Sxpr;
   37.58 -
   37.59 -/** Sxpr type to indicate out of memory. */
   37.60 -#define T_NOMEM      ((TypeCode)-1)
   37.61 -/** The 'unspecified' sxpr. */
   37.62 -#define T_NONE       ((TypeCode)0)
   37.63 -/** The empty list. */
   37.64 -#define T_NULL       ((TypeCode)1)
   37.65 -/** Unsigned integer. */
   37.66 -#define T_UINT       ((TypeCode)2)
   37.67 -/** A string. */
   37.68 -#define T_STRING     ((TypeCode)3)
   37.69 -/** An atom. */
   37.70 -#define T_ATOM       ((TypeCode)4)
   37.71 -/** A boolean. */
   37.72 -#define T_BOOL       ((TypeCode)5)
   37.73 -
   37.74 -/** A cons (pair or list). */
   37.75 -#define T_CONS       ((TypeCode)10)
   37.76 -
   37.77 -/** An error. */
   37.78 -#define T_ERR        ((TypeCode)40)
   37.79 -
   37.80 -/** An atom. */
   37.81 -typedef struct ObjAtom {
   37.82 -    Sxpr name;
   37.83 -    Hashcode hashcode;
   37.84 -    int interned;
   37.85 -} ObjAtom;
   37.86 -
   37.87 -/** A cons (pair). */
   37.88 -typedef struct ObjCons {
   37.89 -    Sxpr car;
   37.90 -    Sxpr cdr;
   37.91 -} ObjCons;
   37.92 -
   37.93 -/** A vector. */
   37.94 -typedef struct ObjVector {
   37.95 -    int n;
   37.96 -    Sxpr data[0];
   37.97 -} ObjVector;
   37.98 -
   37.99 -/** Flags for sxpr printing. */
  37.100 -enum PrintFlags {
  37.101 -    PRINT_RAW           = 0x001,
  37.102 -    PRINT_TYPE          = 0x002,
  37.103 -    PRINT_PRETTY        = 0x004,
  37.104 -    PRINT_NUM           = 0x008,
  37.105 -};
  37.106 -
  37.107 -/** An integer sxpr.
  37.108 - *
  37.109 - * @param ty type
  37.110 - * @param val integer value
  37.111 - */
  37.112 -#define OBJI(ty, val) (Sxpr){ type: (ty), v: { ul: (val) }}
  37.113 -
  37.114 -/** A pointer sxpr.
  37.115 - * If the pointer is non-null, returns an sxpr containing it.
  37.116 - * If the pointer is null, returns ONOMEM.
  37.117 - *
  37.118 - * @param ty type
  37.119 - * @param val pointer
  37.120 - */
  37.121 -#define OBJP(ty, val) ((val) ? (Sxpr){ type: (ty), v: { ptr: (val) }} : ONOMEM)
  37.122 -
  37.123 -/** Make an integer sxpr containing a pointer.
  37.124 - *
  37.125 - * @param val pointer
  37.126 - */
  37.127 -#define PTR(val) OBJP(T_UINT, (void*)(val))
  37.128 -
  37.129 -/** Make an integer sxpr.
  37.130 - * @param x value
  37.131 - */
  37.132 -#define OINT(x)       OBJI(T_UINT,  x)
  37.133 -
  37.134 -/** Make an error sxpr.
  37.135 - *
  37.136 - * @param x value
  37.137 - */
  37.138 -#define OERR(x)       OBJI(T_ERR,   x)
  37.139 -
  37.140 -/** Out of memory constant. */
  37.141 -#define ONOMEM        OBJI(T_NOMEM, 0)
  37.142 -
  37.143 -/** The `unspecified' constant. */
  37.144 -#define ONONE         OBJI(T_NONE,  0)
  37.145 -
  37.146 -/** Empty list constant. */
  37.147 -#define ONULL         OBJI(T_NULL,  0)
  37.148 -
  37.149 -/** False constant. */
  37.150 -#define OFALSE        OBJI(T_BOOL,  0)
  37.151 -
  37.152 -/** True constant. */
  37.153 -#define OTRUE         OBJI(T_BOOL,  1)
  37.154 -
  37.155 -/* Recognizers for the various sxpr types.  */
  37.156 -#define ATOMP(obj)        has_type(obj, T_ATOM)
  37.157 -#define BOOLP(obj)        has_type(obj, T_BOOL)
  37.158 -#define CONSP(obj)        has_type(obj, T_CONS)
  37.159 -#define ERRP(obj)         has_type(obj, T_ERR)
  37.160 -#define INTP(obj)         has_type(obj, T_UINT)
  37.161 -#define NOMEMP(obj)       has_type(obj, T_NOMEM)
  37.162 -#define NONEP(obj)        has_type(obj, T_NONE)
  37.163 -#define NULLP(obj)        has_type(obj, T_NULL)
  37.164 -#define STRINGP(obj)      has_type(obj, T_STRING)
  37.165 -
  37.166 -#define TRUEP(obj)    get_ul(obj)
  37.167 -
  37.168 -/** Convert an sxpr to an unsigned integer. */
  37.169 -#define OBJ_UINT(x)   get_ul(x)
  37.170 -/** Convert an sxpr to an integer. */
  37.171 -#define OBJ_INT(x)    (int)get_ul(x)
  37.172 -
  37.173 -/* Conversions of sxprs to their values.
  37.174 - * No checking is done.
  37.175 - */
  37.176 -#define OBJ_STRING(x)  ((char*)get_ptr(x))
  37.177 -#define OBJ_CONS(x)    ((ObjCons*)get_ptr(x))
  37.178 -#define OBJ_ATOM(x)    ((ObjAtom*)get_ptr(x))
  37.179 -#define OBJ_SET(x)     ((ObjSet*)get_ptr(x))
  37.180 -#define CAR(x)         (OBJ_CONS(x)->car)
  37.181 -#define CDR(x)         (OBJ_CONS(x)->cdr)
  37.182 -
  37.183 -#define CAAR(x)        (CAR(CAR(x)))
  37.184 -#define CADR(x)        (CAR(CDR(x)))
  37.185 -#define CDAR(x)        (CDR(CAR(x)))
  37.186 -#define CDDR(x)        (CDR(CDR(x)))
  37.187 -
  37.188 -/** Get the integer value from an sxpr.
  37.189 - *
  37.190 - * @param obj sxpr
  37.191 - * @return value
  37.192 - */
  37.193 -static inline unsigned long get_ul(Sxpr obj){
  37.194 -    return obj.v.ul;
  37.195 -}
  37.196 -
  37.197 -/** Get the pointer value from an sxpr.
  37.198 - *
  37.199 - * @param obj sxpr
  37.200 - * @return value
  37.201 - */
  37.202 -static inline void * get_ptr(Sxpr obj){
  37.203 -    return obj.v.ptr;
  37.204 -}
  37.205 -
  37.206 -/** Create an sxpr containing a pointer.
  37.207 - *
  37.208 - * @param type typecode
  37.209 - * @param val pointer
  37.210 - * @return sxpr
  37.211 - */
  37.212 -static inline Sxpr obj_ptr(TypeCode type, void *val){
  37.213 -    return (Sxpr){ type: type, v: { ptr: val } };
  37.214 -}
  37.215 -
  37.216 -/** Create an sxpr containing an integer.
  37.217 - *
  37.218 - * @param type typecode
  37.219 - * @param val integer
  37.220 - * @return sxpr
  37.221 - */
  37.222 -static inline Sxpr obj_ul(TypeCode type, unsigned long val){
  37.223 -    return (Sxpr){ type: type, v: { ul: val } };
  37.224 -}
  37.225 -
  37.226 -/** Get the type of an sxpr.
  37.227 - *
  37.228 - * @param obj sxpr
  37.229 - * @return type
  37.230 - */
  37.231 -static inline TypeCode get_type(Sxpr obj){
  37.232 -    return obj.type;
  37.233 -}
  37.234 -
  37.235 -/** Check the type of an sxpr.
  37.236 - *
  37.237 - * @param obj sxpr
  37.238 - * @param type to check
  37.239 - * @return 1 if has the type, 0 otherwise
  37.240 - */
  37.241 -static inline int has_type(Sxpr obj, TypeCode type){
  37.242 -    return get_type(obj) == type;
  37.243 -}
  37.244 -
  37.245 -/** Compare sxprs for literal equality of type and value.
  37.246 - *
  37.247 - * @param x sxpr to compare
  37.248 - * @param y sxpr to compare
  37.249 - * @return 1 if equal, 0 otherwise
  37.250 - */
  37.251 -static inline int eq(Sxpr x, Sxpr y){
  37.252 -    return ((get_type(x) == get_type(y)) && (get_ul(x) == get_ul(y)));
  37.253 -}
  37.254 -
  37.255 -/** Checked version of CAR
  37.256 - *
  37.257 - * @param x sxpr
  37.258 - * @return CAR if a cons, x otherwise
  37.259 - */
  37.260 -static inline Sxpr car(Sxpr x){
  37.261 -    return (CONSP(x) ? CAR(x) : x);
  37.262 -}
  37.263 -
  37.264 -/** Checked version of CDR.
  37.265 - *
  37.266 - * @param x sxpr
  37.267 - * @return CDR if a cons, null otherwise
  37.268 - */
  37.269 -static inline Sxpr cdr(Sxpr x){
  37.270 -    return (CONSP(x) ? CDR(x) : ONULL);
  37.271 -}
  37.272 -
  37.273 -/** Allocate some memory and return an sxpr containing it.
  37.274 - * Returns ONOMEM if allocation failed.
  37.275 - *
  37.276 - * @param n number of bytes to allocate
  37.277 - * @param ty typecode
  37.278 - * @return sxpr
  37.279 - */
  37.280 -static inline Sxpr halloc(size_t n,  TypeCode ty){
  37.281 -    return OBJP(ty, allocate(n));
  37.282 -}
  37.283 -
  37.284 -/** Allocate an sxpr containing a pointer to the given type.
  37.285 - *
  37.286 - * @param ty type (uses sizeof to determine how many bytes to allocate)
  37.287 - * @param code typecode
  37.288 - * @return sxpr, ONOMEM if allocation failed
  37.289 - */
  37.290 -#define HALLOC(ty, code) halloc(sizeof(ty), code)
  37.291 -
  37.292 -typedef int ObjPrintFn(IOStream *io, Sxpr obj, unsigned flags);
  37.293 -typedef int ObjEqualFn(Sxpr obj, Sxpr other);
  37.294 -typedef void ObjFreeFn(Sxpr obj);
  37.295 -
  37.296 -/** An sxpr type definition. */
  37.297 -typedef struct SxprType {
  37.298 -    TypeCode type;
  37.299 -    char *name;
  37.300 -    int pointer;
  37.301 -    ObjPrintFn *print;
  37.302 -    ObjEqualFn *equal;
  37.303 -    ObjFreeFn *free;
  37.304 -} SxprType;
  37.305 -
  37.306 -
  37.307 -extern SxprType *get_sxpr_type(int ty);
  37.308 -
  37.309 -/** Free the pointer in an sxpr.
  37.310 - *
  37.311 - * @param x sxpr containing a pointer
  37.312 - */
  37.313 -static inline void hfree(Sxpr x){
  37.314 -    deallocate(get_ptr(x));
  37.315 -}
  37.316 -
  37.317 -extern int objprint(IOStream *io, Sxpr x, unsigned flags);
  37.318 -extern int objequal(Sxpr x, Sxpr y);
  37.319 -extern void objfree(Sxpr x);
  37.320 -
  37.321 -extern void cons_free_cells(Sxpr obj);
  37.322 -extern Sxpr intern(char *s);
  37.323 -
  37.324 -extern Sxpr assoc(Sxpr k, Sxpr l);
  37.325 -extern Sxpr assocq(Sxpr k, Sxpr l);
  37.326 -extern Sxpr acons(Sxpr k, Sxpr v, Sxpr l);
  37.327 -extern Sxpr nrev(Sxpr l);
  37.328 -extern Sxpr cons_member(Sxpr l, Sxpr x);
  37.329 -extern Sxpr cons_member_if(Sxpr l, ObjEqualFn *test_fn, Sxpr v);
  37.330 -extern int cons_subset(Sxpr s, Sxpr t);
  37.331 -extern int cons_set_equal(Sxpr s, Sxpr t);
  37.332 -
  37.333 -#ifdef USE_GC
  37.334 -extern Sxpr cons_remove(Sxpr l, Sxpr x);
  37.335 -extern Sxpr cons_remove_if(Sxpr l, ObjEqualFn *test_fn, Sxpr v);
  37.336 -#endif
  37.337 -
  37.338 -extern Sxpr atom_new(char *name);
  37.339 -extern char * atom_name(Sxpr obj);
  37.340 -
  37.341 -extern Sxpr string_new(char *s);
  37.342 -extern char * string_string(Sxpr obj);
  37.343 -extern int string_length(Sxpr obj);
  37.344 -
  37.345 -extern Sxpr cons_new(Sxpr car, Sxpr cdr);
  37.346 -extern int cons_push(Sxpr *list, Sxpr elt);
  37.347 -extern int cons_length(Sxpr obj);
  37.348 -
  37.349 -Sxpr sxpr_name(Sxpr obj);
  37.350 -int sxpr_is(Sxpr obj, char *s);
  37.351 -int sxpr_elementp(Sxpr obj, Sxpr name);
  37.352 -Sxpr sxpr_attributes(Sxpr obj);
  37.353 -Sxpr sxpr_attribute(Sxpr obj, Sxpr key, Sxpr def);
  37.354 -Sxpr sxpr_children(Sxpr obj);
  37.355 -Sxpr sxpr_child(Sxpr obj, Sxpr name, Sxpr def);
  37.356 -Sxpr sxpr_child0(Sxpr obj, Sxpr def);
  37.357 -Sxpr sxpr_child_value(Sxpr obj, Sxpr name, Sxpr def);
  37.358 -
  37.359 -/** Create a new atom.
  37.360 - *
  37.361 - * @param s atom name
  37.362 - * @return new atom
  37.363 - */
  37.364 -static inline Sxpr mkatom(char *s){
  37.365 -    return atom_new(s);
  37.366 -}
  37.367 -
  37.368 -/** Create a new string sxpr.
  37.369 - *
  37.370 - * @param s string bytes (copied)
  37.371 - * @return new string
  37.372 - */
  37.373 -static inline Sxpr mkstring(char *s){
  37.374 -    return string_new(s);
  37.375 -}
  37.376 -
  37.377 -/** Create an integer sxpr.
  37.378 - *
  37.379 - * @param i value
  37.380 - * @return sxpr
  37.381 - */
  37.382 -static inline Sxpr mkint(int i){
  37.383 -    return OBJI(T_UINT, i);
  37.384 -}
  37.385 -
  37.386 -/** Create a boolean sxpr.
  37.387 - *
  37.388 - * @param b value
  37.389 - * @return sxpr
  37.390 - */
  37.391 -static inline Sxpr mkbool(int b){
  37.392 -    return OBJI(T_BOOL, (b ? 1 : 0));
  37.393 -}
  37.394 -
  37.395 -/* Constants used in parsing and printing. */
  37.396 -#define k_list_open    "("
  37.397 -#define c_list_open    '('
  37.398 -#define k_list_close   ")"
  37.399 -#define c_list_close   ')'
  37.400 -#define k_true         "true"
  37.401 -#define k_false        "false"
  37.402 -
  37.403 -#define c_var          '$'
  37.404 -#define c_escape       '\\'
  37.405 -#define c_single_quote '\''
  37.406 -#define c_double_quote '"'
  37.407 -#define c_string_open  c_double_quote
  37.408 -#define c_string_close c_double_quote
  37.409 -#define c_data_open    '['
  37.410 -#define c_data_close   ']'
  37.411 -#define c_binary       '*'
  37.412 -#define c_eval         '!'
  37.413 -#define c_concat_open  '{'
  37.414 -#define c_concat_close '}'
  37.415 -
  37.416 -#endif /* ! _XEN_LIB_SXPR_H_ */
    38.1 --- a/tools/lib/sxpr_parser.c	Tue Jun 29 14:14:38 2004 +0000
    38.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    38.3 @@ -1,897 +0,0 @@
    38.4 -
    38.5 -#ifdef __KERNEL__
    38.6 -#  include <linux/config.h>
    38.7 -#  include <linux/module.h>
    38.8 -#  include <linux/kernel.h>
    38.9 -#  include <linux/string.h>
   38.10 -#  include <linux/errno.h>
   38.11 -#else
   38.12 -#  include <stdlib.h>
   38.13 -#  include <errno.h>
   38.14 -#endif
   38.15 -
   38.16 -#include "iostream.h"
   38.17 -#include "lexis.h"
   38.18 -#include "sxpr_parser.h"
   38.19 -#include "sys_string.h"
   38.20 -
   38.21 -/** @file
   38.22 - * Sxpr parsing.
   38.23 - *
   38.24 - * So that the parser does not leak memory, all sxprs constructed by
   38.25 - * the parser must be freed on error.  On successful parse the sxpr
   38.26 - * returned becomes the responsibility of the caller.
   38.27 - *
   38.28 - * @author Mike Wray <mike.wray@hpl.hp.com>
   38.29 - */
   38.30 -
   38.31 -#define dprintf(fmt, args...) IOStream_print(iostdout, "[DEBUG] %s" fmt, __FUNCTION__, ##args)
   38.32 -#define printf(fmt, args...)   IOStream_print(iostdout, fmt, ##args)
   38.33 -
   38.34 -static void reset(Parser *z);
   38.35 -static int inputchar(Parser *p, char c);
   38.36 -static int savechar(Parser *p, char c);
   38.37 -extern void parse_error(Parser *in);
   38.38 -extern void parse_error_id(Parser *in, ParseErrorId id);
   38.39 -
   38.40 -static int begin_start(Parser *p, char c);
   38.41 -static int state_start(Parser *p, char c);
   38.42 -static int end_start(Parser *p);
   38.43 -
   38.44 -static int begin_comment(Parser *p, char c);
   38.45 -static int state_comment(Parser *p, char c);
   38.46 -static int end_comment(Parser *p);
   38.47 -
   38.48 -static int begin_string(Parser *p, char c);
   38.49 -static int state_string(Parser *p, char c);
   38.50 -static int end_string(Parser *p);
   38.51 -static int state_escape(Parser *p, char c);
   38.52 -static int state_octal(Parser *p, char c);
   38.53 -static int state_hex(Parser *p, char c);
   38.54 -
   38.55 -static int begin_atom(Parser *p, char c);
   38.56 -static int state_atom(Parser *p, char c);
   38.57 -static int end_atom(Parser *p);
   38.58 -
   38.59 -static int state_list(Parser *p, char c);
   38.60 -static int begin_list(Parser *p, char c);
   38.61 -static int end_list(Parser *p);
   38.62 -
   38.63 -/** Print a parse error.
   38.64 - *
   38.65 - * @param in parser
   38.66 - * @param msg format followed by printf arguments
   38.67 - */
   38.68 -void eprintf(Parser *in, char *msg, ...){
   38.69 -    va_list args;
   38.70 -    if(in->error_out){
   38.71 -        va_start(args, msg);
   38.72 -        IOStream_vprint(in->error_out, msg, args);
   38.73 -        va_end(args);
   38.74 -    }
   38.75 -}
   38.76 -
   38.77 -/** Print a parse warning.
   38.78 - *
   38.79 - * @param in parser
   38.80 - * @param msg format followed by printf arguments
   38.81 - */
   38.82 -void wprintf(Parser *in, char *msg, ...){
   38.83 -    va_list args;
   38.84 -    if(in->error_out){
   38.85 -        va_start(args, msg);
   38.86 -        IOStream_vprint(in->error_out, msg, args);
   38.87 -        va_end(args);
   38.88 -    }
   38.89 -}
   38.90 -
   38.91 -/*============================================================================*/
   38.92 -
   38.93 -/** Record defining the message for a parse error. */
   38.94 -typedef struct {
   38.95 -  ParseErrorId id;
   38.96 -  char *message;
   38.97 -} ParseError;
   38.98 -
   38.99 -/** Format for printing parse error messages. */
  38.100 -#define PARSE_ERR_FMT "parse error> line %3d, column %2d: %s"
  38.101 -
  38.102 -/** Message catalog for the parse error codes. */
  38.103 -static ParseError catalog[] = {
  38.104 -  { PARSE_ERR_UNSPECIFIED,            "unspecified error" },
  38.105 -  { PARSE_ERR_NOMEM,                  "out of memory" },
  38.106 -  { PARSE_ERR_UNEXPECTED_EOF,         "unexpected end of input" },
  38.107 -  { PARSE_ERR_TOKEN_TOO_LONG,         "token too long" },
  38.108 -  { PARSE_ERR_INVALID_SYNTAX,         "syntax error" },
  38.109 -  { PARSE_ERR_INVALID_ESCAPE,         "invalid escape" },
  38.110 -  { 0, NULL }
  38.111 -};
  38.112 -
  38.113 -/** Number of entries in the message catalog. */
  38.114 -const static int catalog_n = sizeof(catalog)/sizeof(ParseError);
  38.115 -
  38.116 -void ParserState_free(ParserState *z){
  38.117 -    if(!z) return;
  38.118 -    objfree(z->val);
  38.119 -    deallocate(z);
  38.120 -}
  38.121 -
  38.122 -int ParserState_new(ParserStateFn *fn, ParserState *parent, ParserState **val){
  38.123 -    int err = 0;
  38.124 -    ParserState *z;
  38.125 -    z = ALLOCATE(ParserState);
  38.126 -    if(z){
  38.127 -        z->fn = fn;
  38.128 -        z->parent = parent;
  38.129 -        z->val = ONULL;
  38.130 -    } else {
  38.131 -        err = -ENOMEM;
  38.132 -    }
  38.133 -    if(!err) *val = z;
  38.134 -    return err;
  38.135 -}
  38.136 -
  38.137 -/** Free a parser.
  38.138 - * No-op if the parser is null.
  38.139 - *
  38.140 - * @param z parser 
  38.141 - */
  38.142 -void Parser_free(Parser *z){
  38.143 -    if(!z) return;
  38.144 -    objfree(z->val);
  38.145 -    z->val = ONONE;
  38.146 -    deallocate(z);
  38.147 -}
  38.148 -
  38.149 -/** Create a new parser. The error stream defaults to null.
  38.150 - */
  38.151 -Parser * Parser_new(void){
  38.152 -    Parser *z = ALLOCATE(Parser);
  38.153 -    int err = -ENOMEM;
  38.154 -  
  38.155 -    if(!z) goto exit;
  38.156 -    err = 0;
  38.157 -    reset(z);
  38.158 -  exit:
  38.159 -    if(err){
  38.160 -        Parser_free(z);
  38.161 -        z = NULL;
  38.162 -    }
  38.163 -    return z;
  38.164 -}
  38.165 -
  38.166 -/** Get the next character.
  38.167 - * Records the character read in the parser,
  38.168 - * and sets the line and character counts.
  38.169 - *
  38.170 - * @param p parser
  38.171 - * @return error flag: 0 on success, non-zero on error
  38.172 - */
  38.173 -static int inputchar(Parser *p, char c){
  38.174 -    int err = 0;
  38.175 -    if(c=='\n'){
  38.176 -        p->line_no++;
  38.177 -        p->char_no = 0;
  38.178 -    } else {
  38.179 -        p->char_no++;
  38.180 -    }
  38.181 -    return err;
  38.182 -}
  38.183 -
  38.184 -static int savechar(Parser *p, char c){
  38.185 -    int err = 0;
  38.186 -    if(p->buf_i >= p->buf_n){
  38.187 -        err = -ENOMEM;
  38.188 -        goto exit;
  38.189 -    }
  38.190 -    p->buf[p->buf_i] = c;
  38.191 -    p->buf_i++;
  38.192 -  exit:
  38.193 -    return err;
  38.194 -}
  38.195 -
  38.196 -int Parser_input_char(Parser *p, char c){
  38.197 -    int err = 0;
  38.198 -    if(at_eof(p)){
  38.199 -        //skip;
  38.200 -    } else {
  38.201 -        inputchar(p, c);
  38.202 -    }
  38.203 -    if(!p->state){
  38.204 -        err = begin_start(p, c);
  38.205 -        if(err) goto exit;
  38.206 -    }
  38.207 -    err = p->state->fn(p, c);
  38.208 -  exit:
  38.209 -    return err;
  38.210 -}
  38.211 -
  38.212 -int Parser_input_eof(Parser *p){
  38.213 -    int err = 0;
  38.214 -    p->eof = 1;
  38.215 -    err = Parser_input_char(p, IOSTREAM_EOF);
  38.216 -    return err;
  38.217 -}
  38.218 -
  38.219 -int Parser_input(Parser *p, char *buf, int buf_n){
  38.220 -    int err = 0;
  38.221 -    int i = 0;
  38.222 -    if(buf_n <= 0){
  38.223 -        err = Parser_input_eof(p);
  38.224 -        goto exit;
  38.225 -    }
  38.226 -    for(i = 0; i<buf_n; i++){
  38.227 -        err = Parser_input_char(p, buf[i]);
  38.228 -        if(err) goto exit;
  38.229 -    }
  38.230 -  exit:
  38.231 -    err = (err < 0 ? err : buf_n);
  38.232 -    return err;
  38.233 -}
  38.234 -
  38.235 -int Parser_push(Parser *p, ParserStateFn *fn){
  38.236 -    int err = 0;
  38.237 -    err = ParserState_new(fn, p->state, &p->state);
  38.238 -    return err;
  38.239 -}
  38.240 -        
  38.241 -int Parser_pop(Parser *p){
  38.242 -    int err = 0;
  38.243 -    ParserState *s = p->state;
  38.244 -    p->state = s->parent;
  38.245 -    ParserState_free(s);
  38.246 -    return err;
  38.247 -}
  38.248 -
  38.249 -int Parser_return(Parser *p){
  38.250 -    int err = 0;
  38.251 -    Sxpr val = ONONE;
  38.252 -    if(!p->state){
  38.253 -        err = -EINVAL;
  38.254 -        goto exit;
  38.255 -    }
  38.256 -    val = p->state->val;
  38.257 -    p->state->val = ONONE;
  38.258 -    err = Parser_pop(p);
  38.259 -    if(err) goto exit;
  38.260 -    if(p->state){
  38.261 -        err = cons_push(&p->state->val, val);
  38.262 -    } else {
  38.263 -        val = nrev(val);
  38.264 -        p->val = val;
  38.265 -    }
  38.266 -  exit:
  38.267 -    if(err){
  38.268 -        objfree(val);
  38.269 -    }
  38.270 -    return err;
  38.271 -}
  38.272 -
  38.273 -/** Determine if a character is a separator.
  38.274 - *
  38.275 - * @param p parser
  38.276 - * @param c character to test
  38.277 - * @return 1 if a separator, 0 otherwise
  38.278 - */
  38.279 -static int is_separator(Parser *p, char c){
  38.280 -    return in_sep_class(c);
  38.281 -}
  38.282 -
  38.283 -/** Return the current token.
  38.284 - * The return value points at the internal buffer, so
  38.285 - * it must not be modified (or freed). Use copy_token() if you need a copy.
  38.286 - *
  38.287 - * @param p parser
  38.288 - * @return token
  38.289 - */
  38.290 -char *peek_token(Parser *p){
  38.291 -    return p->buf;
  38.292 -}
  38.293 -
  38.294 -/** Return a copy of the current token.
  38.295 - * The returned value should be freed when finished with.
  38.296 - *
  38.297 - * @param p parser
  38.298 - * @return copy of token
  38.299 - */
  38.300 -char *copy_token(Parser *p){
  38.301 -    return strdup(peek_token(p));
  38.302 -}
  38.303 -
  38.304 -static int do_intern(Parser *p){
  38.305 -    int err = 0;
  38.306 -    Sxpr obj = intern(peek_token(p));
  38.307 -    if(NOMEMP(obj)){
  38.308 -        err = -ENOMEM;
  38.309 -    } else {
  38.310 -        p->state->val = obj;
  38.311 -    }
  38.312 -    return err;
  38.313 -}
  38.314 -
  38.315 -static int do_string(Parser *p){
  38.316 -    int err = 0;
  38.317 -    Sxpr obj;
  38.318 -    obj = string_new(peek_token(p));
  38.319 -    if(NOMEMP(obj)){
  38.320 -        err = -ENOMEM;
  38.321 -    } else {
  38.322 -        p->state->val = obj;
  38.323 -    }
  38.324 -    return err;
  38.325 -}
  38.326 -
  38.327 -void newtoken(Parser *p){
  38.328 -    memset(p->buf, 0, p->buf_n);
  38.329 -    p->buf_i = 0;
  38.330 -    p->tok_begin_line = p->line_no;
  38.331 -    p->tok_begin_char = p->char_no;
  38.332 -}
  38.333 -
  38.334 -int get_escape(char c, char *d){
  38.335 -    int err = 0;
  38.336 -    switch(c){
  38.337 -    case 'a':            *d = '\a'; break;
  38.338 -    case 'b':            *d = '\b'; break;
  38.339 -    case 'f':            *d = '\f'; break;
  38.340 -    case 'n':            *d = '\n'; break;
  38.341 -    case 'r':            *d = '\r'; break;
  38.342 -    case 't':            *d = '\t'; break;
  38.343 -    case 'v':            *d = '\v'; break;
  38.344 -    case c_escape:       *d = c_escape; break;
  38.345 -    case c_single_quote: *d = c_single_quote; break;
  38.346 -    case c_double_quote: *d = c_double_quote; break;
  38.347 -    default:
  38.348 -        err = -EINVAL;
  38.349 -    }
  38.350 -    return err;
  38.351 -}
  38.352 -
  38.353 -
  38.354 -int begin_start(Parser *p, char c){
  38.355 -    return Parser_push(p, state_start);
  38.356 -}
  38.357 -
  38.358 -int state_start(Parser *p, char c){
  38.359 -    int err = 0;
  38.360 -    if(at_eof(p)){
  38.361 -        err = end_start(p);
  38.362 -    } else if(in_space_class(c)){
  38.363 -        //skip
  38.364 -    } else if(in_comment_class(c)){
  38.365 -        begin_comment(p, c);
  38.366 -    } else if(c == c_list_open){
  38.367 -        begin_list(p, c);
  38.368 -    } else if(c == c_list_close){
  38.369 -        parse_error(p);
  38.370 -        err = -EINVAL;
  38.371 -    } else if(in_string_quote_class(c)){
  38.372 -        begin_string(p, c);
  38.373 -    } else if(in_printable_class(c)){
  38.374 -        begin_atom(p, c);
  38.375 -    } else if(c == 0x04){
  38.376 -        //ctrl-D, EOT: end-of-text.
  38.377 -        Parser_input_eof(p);
  38.378 -    } else {
  38.379 -        parse_error(p);
  38.380 -        err = -EINVAL;
  38.381 -    }
  38.382 -    return err;
  38.383 -}
  38.384 -
  38.385 -int end_start(Parser *p){
  38.386 -    int err = 0;
  38.387 -    err = Parser_return(p);
  38.388 -    return err;
  38.389 -}
  38.390 -
  38.391 -int begin_comment(Parser *p, char c){
  38.392 -    int err = 0;
  38.393 -    err = Parser_push(p, state_comment);
  38.394 -    if(err) goto exit;
  38.395 -    err = inputchar(p, c);
  38.396 -  exit:
  38.397 -    return err;
  38.398 -}
  38.399 -
  38.400 -int state_comment(Parser *p, char c){
  38.401 -    int err = 0;
  38.402 -    if(c == '\n' || at_eof(p)){
  38.403 -        err = end_comment(p);
  38.404 -    } else {
  38.405 -        err = inputchar(p, c);
  38.406 -    }
  38.407 -    return err;
  38.408 -}
  38.409 -
  38.410 -int end_comment(Parser *p){
  38.411 -    return Parser_pop(p);
  38.412 -}
  38.413 -
  38.414 -int begin_string(Parser *p, char c){
  38.415 -    int err = 0;
  38.416 -    err = Parser_push(p, state_string);
  38.417 -    if(err) goto exit;
  38.418 -    newtoken(p);
  38.419 -    p->state->delim = c;
  38.420 -  exit:
  38.421 -    return err;
  38.422 -}
  38.423 -
  38.424 -int state_string(Parser *p, char c){
  38.425 -    int err = 0;
  38.426 -    if(at_eof(p)){
  38.427 -        parse_error_id(p, PARSE_ERR_UNEXPECTED_EOF);
  38.428 -        err = -EINVAL;
  38.429 -    } else if(c == p->state->delim){
  38.430 -        err = end_string(p);
  38.431 -    } else if(c == '\\'){
  38.432 -        err = Parser_push(p, state_escape);
  38.433 -    } else {
  38.434 -        err = savechar(p, c);
  38.435 -    }
  38.436 -    return err;
  38.437 -}
  38.438 -
  38.439 -int end_string(Parser *p){
  38.440 -    int err = 0;
  38.441 -    err = do_string(p);
  38.442 -    if(err) goto exit;
  38.443 -    err = Parser_return(p);
  38.444 -  exit:
  38.445 -    return err;
  38.446 -}
  38.447 -
  38.448 -int state_escape(Parser *p, char c){
  38.449 -    int err = 0;
  38.450 -    char d;
  38.451 -    if(at_eof(p)){
  38.452 -        parse_error_id(p, PARSE_ERR_UNEXPECTED_EOF);
  38.453 -        err = -EINVAL;
  38.454 -        goto exit;
  38.455 -    }
  38.456 -    if(get_escape(c, &d) == 0){
  38.457 -        err = savechar(p, d);
  38.458 -        if(err) goto exit;
  38.459 -        err = Parser_pop(p);
  38.460 -    } else if(c == 'x'){
  38.461 -        p->state->fn = state_hex;
  38.462 -        p->state->ival = 0;
  38.463 -        p->state->count = 0;
  38.464 -    } else {
  38.465 -        p->state->fn = state_octal;
  38.466 -        p->state->ival = 0;
  38.467 -        p->state->count = 0;
  38.468 -        err = Parser_input_char(p, c);
  38.469 -    }
  38.470 -  exit:
  38.471 -    return err;
  38.472 -}
  38.473 -
  38.474 -int octaldone(Parser *p){
  38.475 -    int err = 0;
  38.476 -    char d = (char)(p->state->ival & 0xff);
  38.477 -    err = Parser_pop(p);
  38.478 -    if(err) goto exit;
  38.479 -    err = Parser_input_char(p, d);
  38.480 -  exit:
  38.481 -    return err;
  38.482 -}
  38.483 -
  38.484 -int octaldigit(Parser *p, char c){
  38.485 -    int err = 0;
  38.486 -    p->state->ival *= 8;
  38.487 -    p->state->ival += c - '0'; 
  38.488 -    p->state->count++;
  38.489 -    if(err) goto exit;
  38.490 -    if(p->state->ival < 0 || p->state->ival > 0xff){
  38.491 -        parse_error(p);
  38.492 -        err = -EINVAL;
  38.493 -        goto exit;
  38.494 -    }
  38.495 -    if(p->state->count == 3){
  38.496 -        err = octaldone(p);
  38.497 -    }
  38.498 -  exit:
  38.499 -    return err;
  38.500 -}
  38.501 -
  38.502 -int state_octal(Parser *p, char c){
  38.503 -    int err = 0;
  38.504 -    if(at_eof(p)){
  38.505 -        parse_error_id(p, PARSE_ERR_UNEXPECTED_EOF);
  38.506 -        err = -EINVAL;
  38.507 -        goto exit;
  38.508 -    } else if('0' <= c && c <= '7'){
  38.509 -        err = octaldigit(p, c);
  38.510 -    } else {
  38.511 -        err = octaldone(p);
  38.512 -        if(err) goto exit;
  38.513 -        Parser_input_char(p, c);
  38.514 -    }
  38.515 -  exit:
  38.516 -    return err;
  38.517 -}
  38.518 -
  38.519 -int hexdone(Parser *p){
  38.520 -    int err = 0;
  38.521 -    char d = (char)(p->state->ival & 0xff);
  38.522 -    err = Parser_pop(p);
  38.523 -    if(err) goto exit;
  38.524 -    err = Parser_input_char(p, d);
  38.525 -  exit:
  38.526 -    return err;
  38.527 -}
  38.528 -    
  38.529 -int hexdigit(Parser *p, char c, char d){
  38.530 -    int err = 0;
  38.531 -    p->state->ival *= 16;
  38.532 -    p->state->ival += c - d; 
  38.533 -    p->state->count++;
  38.534 -    if(err) goto exit;
  38.535 -    if(p->state->ival < 0 || p->state->ival > 0xff){
  38.536 -        parse_error(p);
  38.537 -        err = -EINVAL;
  38.538 -        goto exit;
  38.539 -    }
  38.540 -    if(p->state->count == 2){
  38.541 -        err = hexdone(p);
  38.542 -    }
  38.543 -  exit:
  38.544 -    return err;
  38.545 -}
  38.546 -    
  38.547 -int state_hex(Parser *p, char c){
  38.548 -    int err = 0;
  38.549 -    if(at_eof(p)){
  38.550 -        parse_error_id(p, PARSE_ERR_UNEXPECTED_EOF);
  38.551 -        err = -EINVAL;
  38.552 -        goto exit;
  38.553 -    } else if('0' <= c && c <= '9'){
  38.554 -        err = hexdigit(p, c, '0');
  38.555 -    } else if('A' <= c && c <= 'F'){
  38.556 -        err = hexdigit(p, c, 'A');
  38.557 -    } else if('a' <= c && c <= 'f'){
  38.558 -        err = hexdigit(p, c, 'a');
  38.559 -    } else if(p->state->count){
  38.560 -        err =hexdone(p);
  38.561 -        if(err) goto exit;
  38.562 -        Parser_input_char(p, c);
  38.563 -    }
  38.564 -  exit:
  38.565 -    return err;
  38.566 -}
  38.567 -
  38.568 -int begin_atom(Parser *p, char c){
  38.569 -    int err = 0;
  38.570 -    err = Parser_push(p, state_atom);
  38.571 -    if(err) goto exit;
  38.572 -    newtoken(p);
  38.573 -    err = savechar(p, c);
  38.574 -  exit:
  38.575 -    return err;
  38.576 -}
  38.577 -
  38.578 -int state_atom(Parser *p, char c){
  38.579 -    int err = 0;
  38.580 -    if(at_eof(p)){
  38.581 -        err = end_atom(p);
  38.582 -    } else if(is_separator(p, c) ||
  38.583 -              in_space_class(c) ||
  38.584 -              in_comment_class(c)){
  38.585 -        err = end_atom(p);
  38.586 -        if(err) goto exit;
  38.587 -        err = Parser_input_char(p, c);
  38.588 -    } else {
  38.589 -        err = savechar(p, c);
  38.590 -    }
  38.591 -  exit:
  38.592 -    return err;
  38.593 -}
  38.594 -
  38.595 -int end_atom(Parser *p){
  38.596 -    int err = 0;
  38.597 -    err = do_intern(p);
  38.598 -    if(err) goto exit;
  38.599 -    err = Parser_return(p);
  38.600 -  exit:
  38.601 -    return err;
  38.602 -}
  38.603 -
  38.604 -int state_list(Parser *p, char c){
  38.605 -    int err = 0;
  38.606 -    if(at_eof(p)){
  38.607 -        parse_error_id(p, PARSE_ERR_UNEXPECTED_EOF);
  38.608 -        err = -EINVAL;
  38.609 -    } else if(c == c_list_close){
  38.610 -        p->state->val = nrev(p->state->val);
  38.611 -        err = end_list(p);
  38.612 -    } else {
  38.613 -        err = state_start(p, c);
  38.614 -    }
  38.615 -    return err;
  38.616 -    
  38.617 -}
  38.618 -
  38.619 -int begin_list(Parser *p, char c){
  38.620 -    return Parser_push(p, state_list);
  38.621 -}
  38.622 -
  38.623 -int end_list(Parser *p){
  38.624 -    return Parser_return(p);
  38.625 -}
  38.626 -
  38.627 -/** Reset the fields of a parser to initial values.
  38.628 - *
  38.629 - * @param z parser
  38.630 - */
  38.631 -static void reset(Parser *z){
  38.632 -  IOStream *error_out = z->error_out;
  38.633 -  int flags = z->flags;
  38.634 -  zero(z, sizeof(Parser));
  38.635 -  z->buf_n = sizeof(z->buf) - 1;
  38.636 -  z->buf_i = 0;
  38.637 -  z->line_no = 1;
  38.638 -  z->char_no = 0;
  38.639 -  z->error_out = error_out;
  38.640 -  z->flags = flags;
  38.641 -}
  38.642 -
  38.643 -/** Set the parser error stream.
  38.644 - * Parse errors are reported on the the error stream if it is non-null.
  38.645 - * 
  38.646 - * @param z parser
  38.647 - * @param error_out error stream
  38.648 - */
  38.649 -void set_error_stream(Parser *z, IOStream *error_out){
  38.650 -  if(z){
  38.651 -    z->error_out = error_out;
  38.652 -  }
  38.653 -}
  38.654 -
  38.655 -/** Get the parser error message for an error code.
  38.656 - *
  38.657 - * @param id error code
  38.658 - * @return error message (empty string if the code is unknown)
  38.659 - */
  38.660 -static char *get_message(ParseErrorId id){
  38.661 -  int i;
  38.662 -  for(i=0; i<catalog_n; i++){
  38.663 -    if(id == catalog[i].id){
  38.664 -      return catalog[i].message;
  38.665 -    }
  38.666 -  }
  38.667 -  return "";
  38.668 -}
  38.669 -
  38.670 -/** Get the line number.
  38.671 - *
  38.672 - * @param in parser
  38.673 - */
  38.674 -int get_line(Parser *in){
  38.675 -  return in->line_no;
  38.676 -}
  38.677 -
  38.678 -/** Get the column number.
  38.679 - *
  38.680 - * @param in parser
  38.681 - */
  38.682 -int get_column(Parser *in){
  38.683 -  return in->char_no;
  38.684 -}
  38.685 -
  38.686 -/** Get the line number the current token started on.
  38.687 - *
  38.688 - * @param in parser
  38.689 - */
  38.690 -int get_tok_line(Parser *in){
  38.691 -  return in->tok_begin_line;
  38.692 -}
  38.693 -
  38.694 -/** Get the column number the current token started on.
  38.695 - *
  38.696 - * @param in parser
  38.697 - */
  38.698 -int get_tok_column(Parser *in){
  38.699 -  return in->tok_begin_char;
  38.700 -}
  38.701 -
  38.702 -/** Report a parse error.
  38.703 - * Does nothing if the error stream is null or there is no error.
  38.704 - *
  38.705 - * @param in parser
  38.706 - */
  38.707 -static void report_error(Parser *in){
  38.708 -  if(in->error_out && in->err){
  38.709 -    char *msg = get_message(in->err);
  38.710 -    char *tok = peek_token(in);
  38.711 -    IOStream_print(in->error_out, PARSE_ERR_FMT,
  38.712 -		   get_tok_line(in), get_tok_column(in), msg);
  38.713 -    if(tok && tok[0]){
  38.714 -        IOStream_print(in->error_out, " '%s'", tok);
  38.715 -    }
  38.716 -    IOStream_print(in->error_out, "\n");
  38.717 -  }
  38.718 -}
  38.719 -
  38.720 -/** Get the error message for the current parse error code.
  38.721 - * Does nothing if there is no error.
  38.722 - *
  38.723 - * @param in parser
  38.724 - * @param buf where to place the message
  38.725 - * @param n maximum number of characters to place in buf
  38.726 - * @return current error code (zero for no error)
  38.727 - */
  38.728 -int parse_error_message(Parser *in, char *buf, int n){
  38.729 -    if(in->err){
  38.730 -        char *msg = get_message(in->err);
  38.731 -        snprintf(buf, n, PARSE_ERR_FMT, get_tok_line(in), get_tok_column(in), msg);
  38.732 -    }
  38.733 -    return in->err;
  38.734 -}
  38.735 -
  38.736 -/** Flag an unspecified parse error. All subsequent reads will fail.
  38.737 - *
  38.738 - * @param in parser
  38.739 - */
  38.740 -void parse_error(Parser *in){
  38.741 -    parse_error_id(in, PARSE_ERR_INVALID_SYNTAX);
  38.742 -}
  38.743 -
  38.744 -/** Flag a parse error. All subsequent reads will fail.
  38.745 - * Does not change the parser error code if it is already set.
  38.746 - *
  38.747 - * @param in parser
  38.748 - * @param id error code
  38.749 - */
  38.750 -void parse_error_id(Parser *in, ParseErrorId id){
  38.751 -    if(!in->err){
  38.752 -        in->err = id;
  38.753 -        report_error(in);
  38.754 -    }
  38.755 -}
  38.756 -
  38.757 -/** Test if the parser's error flag is set.
  38.758 - *
  38.759 - * @param in parser
  38.760 - * @return 1 if set, 0 otherwise
  38.761 - */
  38.762 -int has_error(Parser *in){
  38.763 -    return (in->err > 0);
  38.764 -}
  38.765 -
  38.766 -/** Test if the parser is at end of input.
  38.767 - *
  38.768 - * @param in parser
  38.769 - * @return 1 if at EOF, 0 otherwise
  38.770 - */
  38.771 -int at_eof(Parser *p){
  38.772 -    return p->eof;
  38.773 -}
  38.774 -
  38.775 -#ifdef SXPR_PARSER_MAIN
  38.776 -/* Stuff for standalone testing. */
  38.777 -
  38.778 -#include "file_stream.h"
  38.779 -#include "string_stream.h"
  38.780 -
  38.781 -int stringof(Sxpr exp, char **s){
  38.782 -    int err = 0;
  38.783 -    if(ATOMP(exp)){
  38.784 -        *s = atom_name(exp);
  38.785 -    } else if(STRINGP(exp)){
  38.786 -        *s = string_string(exp);
  38.787 -    } else {
  38.788 -        err = -EINVAL;
  38.789 -        *s = NULL;
  38.790 -    }
  38.791 -    return err;
  38.792 -}
  38.793 -
  38.794 -int child_string(Sxpr exp, Sxpr key, char **s){
  38.795 -    int err = 0;
  38.796 -    Sxpr val = sxpr_child_value(exp, key, ONONE);
  38.797 -    err = stringof(val, s);
  38.798 -    return err;
  38.799 -}
  38.800 -
  38.801 -int intof(Sxpr exp, int *v){
  38.802 -    int err = 0;
  38.803 -    char *s;
  38.804 -    unsigned long l;
  38.805 -    if(INTP(exp)){
  38.806 -        *v = OBJ_INT(exp);
  38.807 -    } else {
  38.808 -        err = stringof(exp, &s);
  38.809 -        if(err) goto exit;
  38.810 -        err = convert_atoul(s, &l);
  38.811 -        *v = (int)l;
  38.812 -    }
  38.813 - exit:
  38.814 -    return err;
  38.815 -}
  38.816 -
  38.817 -int child_int(Sxpr exp, Sxpr key, int *v){
  38.818 -    int err = 0;
  38.819 -    Sxpr val = sxpr_child_value(exp, key, ONONE);
  38.820 -    err = intof(val, v);
  38.821 -    return err;
  38.822 -}
  38.823 -
  38.824 -int eval_vnet(Sxpr exp){
  38.825 -    int err = 0;
  38.826 -    Sxpr oid = intern("id");
  38.827 -    int id;
  38.828 -    err = child_int(exp, oid, &id);
  38.829 -    if(err) goto exit;
  38.830 -    dprintf("> vnet id=%d\n", id);
  38.831 - exit:
  38.832 -    dprintf("< err=%d\n", err);
  38.833 -    return err;
  38.834 -}
  38.835 -
  38.836 -int eval_connect(Sxpr exp){
  38.837 -    int err = 0;
  38.838 -    Sxpr ovif = intern("vif");
  38.839 -    Sxpr ovnet = intern("vnet");
  38.840 -    char *vif;
  38.841 -    int vnet;
  38.842 -
  38.843 -    err = child_string(exp, ovif, &vif);
  38.844 -    if(err) goto exit;
  38.845 -    err = child_int(exp, ovnet, &vnet);
  38.846 -    if(err) goto exit;
  38.847 -    dprintf("> connect vif=%s vnet=%d\n", vif, vnet);
  38.848 - exit:
  38.849 -    dprintf("< err=%d\n", err);
  38.850 -    return err;
  38.851 -}
  38.852 -
  38.853 -int eval(Sxpr exp){
  38.854 -    int err = 0;
  38.855 -    Sxpr oconnect = intern("connect");
  38.856 -    Sxpr ovnet = intern("vnet");
  38.857 -    
  38.858 -    if(sxpr_elementp(exp, ovnet)){
  38.859 -        err = eval_vnet(exp);
  38.860 -    } else if(sxpr_elementp(exp, oconnect)){
  38.861 -        err = eval_connect(exp);
  38.862 -    } else {
  38.863 -        err = -EINVAL;
  38.864 -    }
  38.865 -    return err;
  38.866 -}
  38.867 -
  38.868 -/** Main program for testing.
  38.869 - * Parses input and prints it.
  38.870 - *
  38.871 - * @param argc number of arguments
  38.872 - * @param argv arguments
  38.873 - * @return error code
  38.874 - */
  38.875 -int main(int argc, char *argv[]){
  38.876 -    Parser *pin;
  38.877 -    int err = 0;
  38.878 -    char buf[1024];
  38.879 -    int k;
  38.880 -    Sxpr obj, l, x;
  38.881 -
  38.882 -    pin = Parser_new();
  38.883 -    set_error_stream(pin, iostdout);
  38.884 -    dprintf("> parse...\n");
  38.885 -    while(1){
  38.886 -        k = fread(buf, 1, 1024, stdin);
  38.887 -        err = Parser_input(pin, buf, k);
  38.888 -        dprintf("> Parser_input=%d\n", err);
  38.889 -        if(k <= 0) break;
  38.890 -    }
  38.891 -    obj = pin->val;
  38.892 -    for(l = obj ; CONSP(l); l = CDR(l)){
  38.893 -        x = CAR(l);
  38.894 -        objprint(iostdout, x, 0); printf("\n");
  38.895 -        eval(x);
  38.896 -    }
  38.897 -    dprintf("> err=%d\n", err);
  38.898 -    return 0;
  38.899 -}
  38.900 -#endif
    39.1 --- a/tools/lib/sxpr_parser.h	Tue Jun 29 14:14:38 2004 +0000
    39.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    39.3 @@ -1,125 +0,0 @@
    39.4 -/*
    39.5 - *
    39.6 - * This library is free software; you can redistribute it and/or modify
    39.7 - * it under the terms of the GNU Lesser General Public License as
    39.8 - * published by the Free Software Foundation; either version 2.1 of the
    39.9 - * License, or  (at your option) any later version. This library is 
   39.10 - * distributed in the  hope that it will be useful, but WITHOUT ANY
   39.11 - * WARRANTY; without even the implied warranty of MERCHANTABILITY or
   39.12 - * FITNESS FOR A PARTICULAR PURPOSE.
   39.13 - * See the GNU Lesser General Public License for more details.
   39.14 - *
   39.15 - * You should have received a copy of the GNU Lesser General Public License
   39.16 - * along with this library; if not, write to the Free Software Foundation,
   39.17 - * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
   39.18 - */
   39.19 -
   39.20 -#ifndef _XEN_LIB_SXPR_PARSER_H_
   39.21 -#define _XEN_LIB_SXPR_PARSER_H_
   39.22 -
   39.23 -#include "sxpr.h"
   39.24 -#include "iostream.h"
   39.25 -
   39.26 -/** @file
   39.27 - * Sxpr parsing definitions.
   39.28 - */
   39.29 -
   39.30 -/** Size of a parser input buffer.
   39.31 - * Tokens read must fit into this size (including trailing null).
   39.32 - */
   39.33 -#define PARSER_BUF_SIZE 1024
   39.34 -
   39.35 -struct Parser;
   39.36 -typedef int ParserStateFn(struct Parser *, char c);
   39.37 -
   39.38 -typedef struct ParserState {
   39.39 -    struct ParserState *parent;
   39.40 -    Sxpr val;
   39.41 -    int ival;
   39.42 -    int count;
   39.43 -    char delim;
   39.44 -    ParserStateFn *fn;
   39.45 -} ParserState;
   39.46 -
   39.47 -/** Structure representing an input source for the parser.
   39.48 - * Can read from any IOStream implementation.
   39.49 - */
   39.50 -typedef struct Parser {
   39.51 -    Sxpr val;
   39.52 -    /** Error reporting stream (null for no reports). */
   39.53 -    IOStream *error_out;
   39.54 -    int eof;
   39.55 -    /** Error flag. Non-zero if there has been a read error. */
   39.56 -    int err;
   39.57 -    /** Line number on input (from 1). */
   39.58 -    int line_no;
   39.59 -    /** Column number of input (reset on new line). */
   39.60 -    int char_no;
   39.61 -    /** Lookahead character. */
   39.62 -    char c;
   39.63 -    /** Buffer for reading tokens. */
   39.64 -    char buf[PARSER_BUF_SIZE];
   39.65 -    /** Size of token buffer. */
   39.66 -    int buf_n;
   39.67 -    int buf_i;
   39.68 -    /** Line the last token started on. */
   39.69 -    int tok_begin_line;
   39.70 -    /** Character number the last token started on. */
   39.71 -    int tok_begin_char;
   39.72 -    /** Parsing flags. */
   39.73 -    int flags;
   39.74 -    ParserState *state;
   39.75 -} Parser;
   39.76 -
   39.77 -/** Parser error codes. */
   39.78 -typedef enum {
   39.79 -    PARSE_ERR_NONE=0,
   39.80 -    PARSE_ERR_UNSPECIFIED,
   39.81 -    PARSE_ERR_NOMEM,
   39.82 -    PARSE_ERR_UNEXPECTED_EOF,
   39.83 -    PARSE_ERR_TOKEN_TOO_LONG,
   39.84 -    PARSE_ERR_INVALID_SYNTAX,
   39.85 -    PARSE_ERR_INVALID_ESCAPE,
   39.86 -} ParseErrorId;
   39.87 -
   39.88 -
   39.89 -/** Parser flags. */
   39.90 -//enum {
   39.91 -//};
   39.92 -
   39.93 -/** Raise some parser flags.
   39.94 - *
   39.95 - * @param in parser
   39.96 - * @param flags flags mask
   39.97 - */
   39.98 -inline static void parser_flags_raise(Parser *in, int flags){
   39.99 -    in->flags |= flags;
  39.100 -}
  39.101 -
  39.102 -/** Lower some parser flags.
  39.103 - *
  39.104 - * @param in parser
  39.105 - * @param flags flags mask
  39.106 - */
  39.107 -inline static void parser_flags_lower(Parser *in, int flags){
  39.108 -    in->flags &= ~flags;
  39.109 -}
  39.110 -
  39.111 -/** Clear all parser flags.
  39.112 - *
  39.113 - * @param in parser
  39.114 - */
  39.115 -inline static void parser_flags_clear(Parser *in){
  39.116 -    in->flags = 0;
  39.117 -}
  39.118 -
  39.119 -extern void Parser_free(Parser *z);
  39.120 -extern Parser * Parser_new(void);
  39.121 -extern int Parser_input(Parser *p, char *buf, int buf_n);
  39.122 -extern int Parser_input_eof(Parser *p);
  39.123 -
  39.124 -extern int parse_error_message(Parser *in, char *buf, int n);
  39.125 -extern int has_error(Parser *in);
  39.126 -extern int at_eof(Parser *in);
  39.127 -
  39.128 -#endif /* ! _XEN_LIB_SXPR_PARSER_H_ */
    40.1 --- a/tools/lib/sys_ctype.h	Tue Jun 29 14:14:38 2004 +0000
    40.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    40.3 @@ -1,12 +0,0 @@
    40.4 -#ifndef _XENO_SYS_CTYPE_H_
    40.5 -#define _XENO_SYS_CTYPE_H_
    40.6 -/** @file
    40.7 - ** Replacement for ctype include that can be used
    40.8 - * from user or kernel code.
    40.9 - */
   40.10 -#ifdef __KERNEL__
   40.11 -#  include <linux/ctype.h>
   40.12 -#else
   40.13 -#  include <ctype.h>
   40.14 -#endif
   40.15 -#endif /* ! _XENO_SYS_CTYPE_H_ */
    41.1 --- a/tools/lib/sys_net.c	Tue Jun 29 14:14:38 2004 +0000
    41.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    41.3 @@ -1,309 +0,0 @@
    41.4 -/*
    41.5 - * Copyright (C) 2001 - 2004 Mike Wray <mike.wray@hp.com>
    41.6 - *
    41.7 - * This library is free software; you can redistribute it and/or modify
    41.8 - * it under the terms of the GNU Lesser General Public License as
    41.9 - * published by the Free Software Foundation; either version 2.1 of the
   41.10 - * License, or  (at your option) any later version. This library is 
   41.11 - * distributed in the  hope that it will be useful, but WITHOUT ANY
   41.12 - * WARRANTY; without even the implied warranty of MERCHANTABILITY or
   41.13 - * FITNESS FOR A PARTICULAR PURPOSE.
   41.14 - * See the GNU Lesser General Public License for more details.
   41.15 - *
   41.16 - * You should have received a copy of the GNU Lesser General Public License
   41.17 - * along with this library; if not, write to the Free Software Foundation,
   41.18 - * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
   41.19 - */
   41.20 -
   41.21 -#include "sys_net.h"
   41.22 -#include "sys_string.h"
   41.23 -
   41.24 -/** @file
   41.25 - * All network data are kept in network order and only converted to
   41.26 - * host order for display. Network data includes IP addresses, port numbers and
   41.27 - * network masks.
   41.28 - */
   41.29 -
   41.30 -/** Maximum value for a port. */
   41.31 -#define PORT_MAX 0xffff
   41.32 -
   41.33 -/** Convert a number of bits to a network mask
   41.34 - * for IP addresses. The number of bits must
   41.35 - * be in the range 1-31.
   41.36 - *
   41.37 - * @param n number of bits to set in the mask
   41.38 - * @return value with n high bits set (in network order)
   41.39 - */
   41.40 -unsigned long bits_to_mask(int n){
   41.41 -    unsigned long mask = (n ? (1 << 31) : 0);
   41.42 -    int i;
   41.43 -    for(i=1; i<n; i++){
   41.44 -        mask |= (mask >> 1);
   41.45 -    }
   41.46 -    return htonl(mask);
   41.47 -}
   41.48 -
   41.49 -/** Convert a network mask to a number of bits.
   41.50 - *
   41.51 - * @param mask network mask in network order
   41.52 - * @return number of bits in mask
   41.53 - */
   41.54 -int mask_to_bits(unsigned long mask){
   41.55 -    // Start with n set to the number of bits in the mask. Then reduce n by
   41.56 -    // the number of low zero bits in the mask.
   41.57 -    int n = 32;
   41.58 -    for(mask = ntohl(mask);
   41.59 -        (mask & 1)==0 && n>0;
   41.60 -        mask >>= 1){
   41.61 -        n--;
   41.62 -    }
   41.63 -    return n;
   41.64 -}
   41.65 -
   41.66 -/** Get the index of the first occurrence of a character in a string.
   41.67 - * Stops at end of string or after n characters.
   41.68 - *
   41.69 - * @param s input string
   41.70 - * @param n maximum number of charactes to search
   41.71 - * @param c character to look for
   41.72 - * @return index of first occurrence, -1 if not found
   41.73 - */
   41.74 -inline static int indexof(const char *s, int n, char c){
   41.75 -    int i;
   41.76 -    for(i=0; i<n && *s; i++, s++){
   41.77 -        if(*s == c) return i;
   41.78 -    }
   41.79 -    return -1;
   41.80 -}
   41.81 -
   41.82 -/** Convert an IPv4 address in dot notation into an unsigned long (in network order).
   41.83 - *
   41.84 - * @param s input string
   41.85 - * @param address where to put the address
   41.86 - * @return 0 on success, -1 on error
   41.87 - */
   41.88 -int get_inet_addr(const char *s, unsigned long *address){
   41.89 -    // Number of bits in a byte.
   41.90 -    const int BYTE_BITS = 8;
   41.91 -    // Number of bytes in a word.
   41.92 -    const int WORD_BYTES = 4;
   41.93 -    // Max value for a component of an address.
   41.94 -    const int ADDR_MAX  = 255;
   41.95 -    // Separator for components of an address.
   41.96 -    const char dot = '.';
   41.97 -
   41.98 -    int n;
   41.99 -    unsigned long addr = 0;
  41.100 -    unsigned long v;
  41.101 -    int i;
  41.102 -    int err = -1;
  41.103 -    // Bit shift for the current byte.
  41.104 -    int shift = BYTE_BITS * (WORD_BYTES - 1);
  41.105 -    char buf[64];
  41.106 -
  41.107 -    n = strlen(s);
  41.108 -    if(n >= sizeof(buf)){
  41.109 -        goto exit;
  41.110 -    }
  41.111 -    for(i=0; i < WORD_BYTES; i++){
  41.112 -        int idx = indexof(s, n, dot);
  41.113 -        idx = (idx < 0 ? strlen(s) : idx);
  41.114 -        strncpy(buf, s, idx); buf[idx]='\0';
  41.115 -        if(convert_atoul(buf, &v)){
  41.116 -            goto exit;
  41.117 -        }
  41.118 -        if(v < 0 || v > ADDR_MAX){
  41.119 -            goto exit;
  41.120 -        }
  41.121 -        addr |= (v << shift);
  41.122 -        if(idx == n) break;
  41.123 -        shift -= BYTE_BITS;
  41.124 -        s += idx+1;
  41.125 -    }
  41.126 -    err = 0;
  41.127 -  exit:
  41.128 -    addr = htonl(addr);
  41.129 -    *address = (err ? 0 : addr);
  41.130 -    return err;
  41.131 -}
  41.132 -
  41.133 -#ifdef __KERNEL__
  41.134 -/** Convert an address in network order to IPv4 dot notation.
  41.135 - * The return value is a static buffer which is overwritten on each call.
  41.136 - *
  41.137 - * @param inaddr address (in network order)
  41.138 - * @return address in dot notation
  41.139 - */
  41.140 -char *inet_ntoa(struct in_addr inaddr){
  41.141 -    static char address[16] = {};
  41.142 -    uint32_t addr = ntohl(inaddr.s_addr);
  41.143 -    snprintf(address, sizeof(address), "%d.%d.%d.%d",
  41.144 -            (unsigned)((addr >> 24) & 0xff),
  41.145 -            (unsigned)((addr >> 16) & 0xff),
  41.146 -            (unsigned)((addr >>  8) & 0xff),
  41.147 -            (unsigned)((addr      ) & 0xff));
  41.148 -    return address;
  41.149 -}
  41.150 -
  41.151 -
  41.152 -/** Convert a string in IPv4 dot notation to an int in network order.
  41.153 - *
  41.154 - * @param address address in dot notation
  41.155 - * @param inp result of conversion (in network order)
  41.156 - * @return 0 on success, error code on error
  41.157 - */
  41.158 -int inet_aton(const char *address, struct in_addr *inp){
  41.159 -    int err = 0; 
  41.160 -    unsigned long addr;
  41.161 -    
  41.162 -    err = get_inet_addr(address, &addr);
  41.163 -    if(err) goto exit;
  41.164 -    inp->s_addr = addr;
  41.165 -  exit:
  41.166 -    return err;
  41.167 -}
  41.168 -#endif
  41.169 -
  41.170 -/** Convert a hostname or IPv4 address string to an address in network order.
  41.171 - *
  41.172 - * @param name input hostname or address string
  41.173 - * @param address where to put the address
  41.174 - * @return 1 if address found OK, 0 otherwise
  41.175 - */
  41.176 -int get_host_address(const char *name, unsigned long *address){
  41.177 -#ifdef __KERNEL__
  41.178 -    return get_inet_addr(name, address) == 0;
  41.179 -#else
  41.180 -    struct hostent *host = gethostbyname(name);
  41.181 -    if(!host){
  41.182 -        return 0;
  41.183 -    }
  41.184 -    *address = ((struct in_addr *)(host->h_addr))->s_addr;
  41.185 -    return 1;
  41.186 -#endif
  41.187 -}
  41.188 -
  41.189 -/** Convert a service name to a port (in network order).
  41.190 - *
  41.191 - * @param name service name
  41.192 - * @param port where to put the port
  41.193 - * @return 1 if service port found OK, 0 otherwise
  41.194 - */
  41.195 -int get_service_port(const char *name, unsigned long *port){
  41.196 -#ifdef __KERNEL__
  41.197 -    return 0;
  41.198 -#else
  41.199 -    struct servent *service;
  41.200 -    service = getservbyname(name, 0);
  41.201 -    if(!service){
  41.202 -        return 0;
  41.203 -    }
  41.204 -    *port = service->s_port;
  41.205 -    return 1;
  41.206 -#endif
  41.207 -}
  41.208 -
  41.209 -/** Convert a port number (in network order) to a service name.
  41.210 - *
  41.211 - * @param port the port number
  41.212 - * @return service name if found OK, 0 otherwise
  41.213 - */
  41.214 -char *get_port_service(unsigned long port){
  41.215 -#ifdef __KERNEL__
  41.216 -    return 0;
  41.217 -#else
  41.218 -    struct servent *service = getservbyport(port, 0);
  41.219 -    return (service ? service->s_name : 0);
  41.220 -#endif
  41.221 -}
  41.222 -
  41.223 -/** Convert a decimal integer or service name to a port (in network order).
  41.224 - *
  41.225 - * @param s input to convert
  41.226 - * @param port where to put the port
  41.227 - * @return 1 if port found OK, 0 otherwise
  41.228 - */
  41.229 -int convert_service_to_port(const char *s, unsigned long *port){
  41.230 -    int ok = 0;
  41.231 -    unsigned long value;
  41.232 -    if(convert_atoul(s, &value)){
  41.233 -        ok = get_service_port(s, &value);
  41.234 -    } else {
  41.235 -        ok = (0 <= value) && (value <= PORT_MAX);
  41.236 -        value = htons((unsigned short)value);
  41.237 -    }
  41.238 -    *port = (ok ? value : 0);
  41.239 -    return ok;
  41.240 -}
  41.241 -
  41.242 -#define MAC_ELEMENT_N  6 // Number of elements in a MAC address.
  41.243 -#define MAC_DIGIT_N    2 // Number of digits in an element in a MAC address.
  41.244 -#define MAC_LENGTH    17 //((MAC_ELEMENT_N * MAC_DIGIT_N) + MAC_ELEMENT_N - 1)
  41.245 -
  41.246 -/** Convert a mac address from a string of the form
  41.247 - * XX:XX:XX:XX:XX:XX to numerical form (an array of 6 unsigned chars).
  41.248 - * Each X denotes a hex digit: 0..9, a..f, A..F.
  41.249 - * Also supports using '-' as the separator instead of ':'.
  41.250 - *
  41.251 - * @param mac_in string to convert
  41.252 - * @param mac destination for the value
  41.253 - * @return 0 on success, -1 on error
  41.254 - */
  41.255 -int mac_aton(const char *mac_in, unsigned char *mac){
  41.256 -    int err = 0;
  41.257 -    int i, j;
  41.258 -    const char *p;
  41.259 -    char sep = 0;
  41.260 -    unsigned char d;
  41.261 -    if(!mac_in || strlen(mac_in) != MAC_LENGTH){
  41.262 -        err = -1;
  41.263 -        goto exit;
  41.264 -    }
  41.265 -    for(i = 0, p = mac_in; i < MAC_ELEMENT_N; i++){
  41.266 -        d = 0;
  41.267 -        if(i){
  41.268 -            if(!sep){
  41.269 -                if(*p == ':' || *p == '-') sep = *p;
  41.270 -            }
  41.271 -            if(sep && *p == sep){
  41.272 -                p++;
  41.273 -            } else {
  41.274 -                err = -1;
  41.275 -                goto exit;
  41.276 -            }
  41.277 -        }
  41.278 -        for(j = 0; j < MAC_DIGIT_N; j++, p++){
  41.279 -            if(j) d <<= 4;
  41.280 -            if(*p >= '0' && *p <= '9'){
  41.281 -                d += (*p - '0');
  41.282 -            } else if(*p >= 'A' && *p <= 'F'){
  41.283 -                d += (*p - 'A') + 10;
  41.284 -            } else if(*p >= 'a' && *p <= 'f'){
  41.285 -                d += (*p - 'a') + 10;
  41.286 -            } else {
  41.287 -                err = -1;
  41.288 -                goto exit;
  41.289 -            }
  41.290 -        }
  41.291 -        mac[i] = d;
  41.292 -    }
  41.293 -  exit:
  41.294 -    return err;
  41.295 -}
  41.296 -
  41.297 -/** Convert a MAC address from numerical form to a string.
  41.298 - *
  41.299 - * @param mac address to convert
  41.300 - * @return static string value
  41.301 - */
  41.302 -char *mac_ntoa(const unsigned char *mac){
  41.303 -    static char buf[MAC_LENGTH + 1];
  41.304 -    int buf_n = sizeof(buf);
  41.305 -
  41.306 -    memset(buf, buf_n, 0);
  41.307 -    snprintf(buf, buf_n, "%02x:%02x:%02x:%02x:%02x:%02x",
  41.308 -             mac[0], mac[1], mac[2],
  41.309 -             mac[3], mac[4], mac[5]);
  41.310 -    buf[buf_n - 1] = '\0';
  41.311 -    return buf;
  41.312 -}
    42.1 --- a/tools/lib/sys_net.h	Tue Jun 29 14:14:38 2004 +0000
    42.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    42.3 @@ -1,78 +0,0 @@
    42.4 -/*
    42.5 - * Copyright (C) 2001 - 2004 Mike Wray <mike.wray@hp.com>
    42.6 - *
    42.7 - * This library is free software; you can redistribute it and/or modify
    42.8 - * it under the terms of the GNU Lesser General Public License as published by
    42.9 - * the Free Software Foundation; either version 2.1 of the License, or
   42.10 - * (at your option) any later version.
   42.11 - *
   42.12 - * This library is distributed in the hope that it will be useful,
   42.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
   42.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   42.15 - * GNU Lesser General Public License for more details.
   42.16 - *
   42.17 - * You should have received a copy of the GNU Lesser General Public License
   42.18 - * along with this library; if not, write to the Free Software
   42.19 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   42.20 - */
   42.21 -
   42.22 -#ifndef _XEN_LIB_SYS_NET_H_
   42.23 -#define _XEN_LIB_SYS_NET_H_
   42.24 -/** @file
   42.25 - *
   42.26 - * Replacement for standard network includes.
   42.27 - * Works in user or kernel code.
   42.28 - */
   42.29 -
   42.30 -extern int get_inet_addr(const char *s, unsigned long *address);
   42.31 -extern unsigned long bits_to_mask(int n);
   42.32 -extern int mask_to_bits(unsigned long mask);
   42.33 -extern int get_host_address(const char *name, unsigned long *address);
   42.34 -extern int get_service_port(const char *name, unsigned long *port);
   42.35 -extern char *get_port_service(unsigned long port);
   42.36 -extern int convert_service_to_port(const char *s, unsigned long *port);
   42.37 -
   42.38 -#ifdef __KERNEL__
   42.39 -#include <linux/kernel.h>
   42.40 -#include <linux/types.h>
   42.41 -#include <linux/errno.h>
   42.42 -#include <linux/slab.h>
   42.43 -#include <asm/byteorder.h> 
   42.44 -
   42.45 -#ifndef htonl
   42.46 -#define htonl(x) __constant_htonl(x)
   42.47 -#endif
   42.48 -
   42.49 -#ifndef ntohl
   42.50 -#define ntohl(x) __constant_ntohl(x)
   42.51 -#endif
   42.52 -
   42.53 -#ifndef htons
   42.54 -#define htons(x) __constant_htons(x)
   42.55 -#endif
   42.56 -
   42.57 -#ifndef ntohs
   42.58 -#define ntohs(x) __constant_ntohs(x)
   42.59 -#endif
   42.60 -
   42.61 -#include <linux/in.h>
   42.62 -extern char *inet_ntoa(struct in_addr inaddr);
   42.63 -extern int inet_aton(const char *address, struct in_addr *inp);
   42.64 -
   42.65 -#else
   42.66 -
   42.67 -#include <limits.h>
   42.68 -#include <sys/socket.h>
   42.69 -#include <netinet/in.h>
   42.70 -#include <netdb.h>
   42.71 -#include <arpa/inet.h>
   42.72 -
   42.73 -#endif
   42.74 -
   42.75 -extern char *mac_ntoa(const unsigned char *macaddr);
   42.76 -extern int mac_aton(const char *addr, unsigned char *macaddr);
   42.77 -
   42.78 -#endif /* !_SP_SYS_NET_H_ */
   42.79 -
   42.80 -
   42.81 -
    43.1 --- a/tools/lib/sys_string.c	Tue Jun 29 14:14:38 2004 +0000
    43.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    43.3 @@ -1,138 +0,0 @@
    43.4 -/*
    43.5 - * Copyright (C) 2001 - 2004 Mike Wray <mike.wray@hp.com>
    43.6 - *
    43.7 - * This library is free software; you can redistribute it and/or modify
    43.8 - * it under the terms of the GNU Lesser General Public License as published by
    43.9 - * the Free Software Foundation; either version 2.1 of the License, or
   43.10 - * (at your option) any later version.
   43.11 - *
   43.12 - * This library is distributed in the hope that it will be useful,
   43.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
   43.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   43.15 - * GNU Lesser General Public License for more details.
   43.16 - *
   43.17 - * You should have received a copy of the GNU Lesser General Public License
   43.18 - * along with this library; if not, write to the Free Software
   43.19 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   43.20 - */
   43.21 -
   43.22 -#ifdef __KERNEL__
   43.23 -#  include <linux/config.h>
   43.24 -#  include <linux/module.h>
   43.25 -#  include <linux/kernel.h>
   43.26 -#  include <linux/errno.h>
   43.27 -#else
   43.28 -#  include <errno.h>
   43.29 -#endif
   43.30 -
   43.31 -#include "allocate.h"
   43.32 -#include "sys_string.h"
   43.33 -
   43.34 -/** Set the base to use for converting a string to a number.  Base is
   43.35 - * hex if starts with 0x, otherwise decimal.
   43.36 - *
   43.37 - * @param s input string
   43.38 - * @param base where to put the base
   43.39 - * @return rest of s to parse as a number
   43.40 - */
   43.41 -inline static const char * convert_set_base(const char *s, int *base){
   43.42 -    *base = 10;
   43.43 -    if(s){
   43.44 -        if(*s=='0'){
   43.45 -            s++;
   43.46 -            if(*s=='x' || *s=='X'){
   43.47 -                *base = 16;
   43.48 -                s++;
   43.49 -            }
   43.50 -        }
   43.51 -    }
   43.52 -    return s;
   43.53 -}
   43.54 -
   43.55 -/** Get the numerical value of a digit in the given base.
   43.56 - *
   43.57 - * @param c digit character
   43.58 - * @param base to use
   43.59 - * @return numerical value of digit in range 0..base-1 or
   43.60 - * -1 if not in range for the base
   43.61 - */
   43.62 -inline static int convert_get_digit(char c, int base){
   43.63 -    int d;
   43.64 -
   43.65 -    if('0'<=c  && c<='9'){
   43.66 -        d = c - '0';
   43.67 -    } else if('a'<=c && c<='f'){
   43.68 -        d = c - 'a' + 10;
   43.69 -    } else if('A'<=c && c<='F'){
   43.70 -        d = c - 'A' + 10;
   43.71 -    } else {
   43.72 -        d = -1;
   43.73 -    }
   43.74 -    return (d < base ? d : -1);
   43.75 -}
   43.76 -
   43.77 -/** Convert a string to an unsigned long by parsing it as a number.
   43.78 - * Will accept hex or decimal in usual C syntax.
   43.79 - *
   43.80 - * @param str input string
   43.81 - * @param val where to put the result
   43.82 - * @return 0 if converted OK, negative otherwise
   43.83 - */
   43.84 -int convert_atoul(const char *str, unsigned long *val){
   43.85 -    int err = 0;
   43.86 -    unsigned long v = 0;
   43.87 -    int base;
   43.88 -    const char *s = str;
   43.89 -
   43.90 -    if(!s) {
   43.91 -        err = -EINVAL;
   43.92 -        goto exit;
   43.93 -    }
   43.94 -    s = convert_set_base(s, &base);
   43.95 -    for( ; !err && *s; s++){
   43.96 -        int digit = convert_get_digit(*s, base);
   43.97 -        if(digit<0){
   43.98 -            err = -EINVAL;
   43.99 -            goto exit;
  43.100 -        }
  43.101 -        v *= base;
  43.102 -        v += digit;
  43.103 -    } 
  43.104 -  exit:
  43.105 -    *val = (err ? 0 : v);
  43.106 -    return err;
  43.107 -}
  43.108 -
  43.109 -/** Combine a directory path with a relative path to produce
  43.110 - * a new path.
  43.111 - *
  43.112 - * @param s directory path
  43.113 - * @param t relative path
  43.114 - * @return new combined path s/t
  43.115 - */
  43.116 -int path_concat(char *s, char *t, char **val){
  43.117 -    int err = 0;
  43.118 -    int sn, tn, vn;
  43.119 -    char *v;
  43.120 -    sn = strlen(s);
  43.121 -    if(sn > 0 && s[sn-1] == '/'){
  43.122 -        sn--;
  43.123 -    }
  43.124 -    tn = strlen(t);
  43.125 -    if(tn > 0 && t[0] == '/'){
  43.126 -        tn--;
  43.127 -    }
  43.128 -    vn = sn+tn+1;
  43.129 -    v = (char*)allocate(vn+1);
  43.130 -    if(!v){
  43.131 -        err = -ENOMEM;
  43.132 -        goto exit;
  43.133 -    }
  43.134 -    strncpy(v, s, sn);
  43.135 -    v[sn] = '/';
  43.136 -    strncpy(v+sn+1, t, tn);
  43.137 -    v[vn] = '\0';
  43.138 -  exit:
  43.139 -    *val = (err ? NULL : v);
  43.140 -    return err;    
  43.141 -}
    44.1 --- a/tools/lib/sys_string.h	Tue Jun 29 14:14:38 2004 +0000
    44.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    44.3 @@ -1,91 +0,0 @@
    44.4 -/*
    44.5 - * Copyright (C) 2001 - 2004 Mike Wray <mike.wray@hp.com>
    44.6 - *
    44.7 - * This library is free software; you can redistribute it and/or modify
    44.8 - * it under the terms of the GNU Lesser General Public License as published by
    44.9 - * the Free Software Foundation; either version 2.1 of the License, or
   44.10 - * (at your option) any later version.
   44.11 - *
   44.12 - * This library is distributed in the hope that it will be useful,
   44.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
   44.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   44.15 - * GNU Lesser General Public License for more details.
   44.16 - *
   44.17 - * You should have received a copy of the GNU Lesser General Public License
   44.18 - * along with this library; if not, write to the Free Software
   44.19 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   44.20 - */
   44.21 -
   44.22 -#ifndef _XEN_LIB_SYS_STRING_H_
   44.23 -#define _XEN_LIB_SYS_STRING_H_
   44.24 -/** @file
   44.25 - * Replacement for standard string includes.
   44.26 - * Works in user or kernel code.
   44.27 - */
   44.28 -/*============================================================================*/
   44.29 -#ifdef __KERNEL__
   44.30 -
   44.31 -#include <linux/config.h>
   44.32 -#include <linux/kernel.h>
   44.33 -#include <linux/string.h>
   44.34 -#include <linux/types.h>
   44.35 -#include <stdarg.h>
   44.36 -#include "allocate.h"
   44.37 -
   44.38 -#if 0
   44.39 -static inline int tolower(int c){
   44.40 -    return (c>='A' && c<='Z' ? (c-'A')+'a' : c);
   44.41 -}
   44.42 -#endif
   44.43 -
   44.44 -static inline int isalpha(int c){
   44.45 -    return (c>='A' && c<='Z') || (c>='a' && c<='z');
   44.46 -}
   44.47 -
   44.48 -static inline int isdigit(int c){
   44.49 -   return (c>='0' && c<='9');
   44.50 -}
   44.51 -
   44.52 -#if 0
   44.53 -static inline int strcasecmp(const char *s1, const char *s2){
   44.54 -	int c1, c2;
   44.55 -
   44.56 -	do {
   44.57 -		c1 = tolower(*s1++);
   44.58 -		c2 = tolower(*s2++);
   44.59 -	} while (c1 && c1 == c2);
   44.60 -	return c1 - c2;
   44.61 -}
   44.62 -#endif
   44.63 -
   44.64 -static inline char * strdup(const char *s){
   44.65 -    int n = (s ? 1+strlen(s) : 0);
   44.66 -    char *copy = (n ? allocate(n) : NULL);
   44.67 -    if(copy){
   44.68 -        strcpy(copy, s);
   44.69 -    }
   44.70 -    return copy;
   44.71 -}
   44.72 -
   44.73 -/*============================================================================*/
   44.74 -#else
   44.75 -#include <string.h>
   44.76 -#include <stdio.h>
   44.77 -
   44.78 -#ifndef _GNU_SOURCE
   44.79 -static inline size_t strnlen(const char *s, size_t n){
   44.80 -    int k = 0;
   44.81 -    if(s){
   44.82 -	for(k=0; *s && k<n; s++, k++){}
   44.83 -    }
   44.84 -    return k;
   44.85 -}
   44.86 -#endif
   44.87 -
   44.88 -#endif
   44.89 -/*============================================================================*/
   44.90 -
   44.91 -extern int convert_atoul(const char *s, unsigned long *v);
   44.92 -extern int path_concat(char *s, char *t, char **val);
   44.93 -
   44.94 -#endif /* !_XEN_LIB_SYS_STRING_H_ */
    45.1 --- a/tools/lib/xdr.c	Tue Jun 29 14:14:38 2004 +0000
    45.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    45.3 @@ -1,246 +0,0 @@
    45.4 -/* $Id: xdr.c,v 1.3 2003/09/29 13:40:00 mjw Exp $ */
    45.5 -#include "xdr.h"
    45.6 -#include <errno.h>
    45.7 -/** @file
    45.8 - * XDR packer/unpacker for elements.
    45.9 - *
   45.10 - * string -> [T_STRING] [len:u32] <len bytes>
   45.11 - * atom   -> [T_ATOM]   [len:u32] <len bytes>
   45.12 - * uint   -> [T_UINT]   [value]
   45.13 - * cons   -> [T_CONS]   <car> <cdr>
   45.14 - * null   -> [T_NULL]
   45.15 - * none   -> [T_NONE]
   45.16 - * bool   -> [T_BOOL]   { 0:u8 | 1:u8 }
   45.17 - *
   45.18 - * types packed as u16.
   45.19 - *
   45.20 - * So (a b c) -> [T_CONS] a [T_CONS] b [T_CONS] c [T_NULL]
   45.21 - *    ()      -> [T_NULL]
   45.22 - */
   45.23 -
   45.24 -int pack_bool(IOStream *io, int x){
   45.25 -    int err=0;
   45.26 -    err = IOStream_print(io, "%c", 0xff & x);
   45.27 -    if(err > 0) err = 0;
   45.28 -    return err;
   45.29 -}
   45.30 -
   45.31 -int unpack_bool(IOStream *io, int *x){
   45.32 -    int err = 0;
   45.33 -    int c;
   45.34 -    c = IOStream_getc(io);
   45.35 -    *x = (c < 0 ? 0 : c);
   45.36 -    err = IOStream_error(io);
   45.37 -    if(c < 0 && !err) err = -EIO;
   45.38 -    return err;
   45.39 -}
   45.40 -
   45.41 -int pack_ushort(IOStream *io, unsigned short x){
   45.42 -    int err=0;
   45.43 -    err = IOStream_print(io, "%c%c",
   45.44 -                         0xff & (x >>  8),
   45.45 -                         0xff & (x      ));
   45.46 -    if(err > 0) err = 0;
   45.47 -    return err;
   45.48 -}
   45.49 -
   45.50 -int unpack_ushort(IOStream *io, unsigned short *x){
   45.51 -    int err = 0;
   45.52 -    int i, c = 0;
   45.53 -    *x = 0;
   45.54 -    for(i = 0; i< 2; i++){
   45.55 -        c = IOStream_getc(io);
   45.56 -        if(c < 0) break;
   45.57 -        *x <<= 8;
   45.58 -        *x |= (0xff & c);
   45.59 -    }
   45.60 -    err = IOStream_error(io);
   45.61 -    if(c < 0 && !err) err = -EIO;
   45.62 -    return err;
   45.63 -}
   45.64 -
   45.65 -int pack_uint(IOStream *io, unsigned int x){
   45.66 -    int err=0;
   45.67 -    err = IOStream_print(io, "%c%c%c%c",
   45.68 -                         0xff & (x >> 24),
   45.69 -                         0xff & (x >> 16),
   45.70 -                         0xff & (x >>  8),
   45.71 -                         0xff & (x      ));
   45.72 -    if(err > 0) err = 0;
   45.73 -    return err;
   45.74 -}
   45.75 -
   45.76 -int unpack_uint(IOStream *io, unsigned int *x){
   45.77 -    int err = 0;
   45.78 -    int i, c = 0;
   45.79 -    *x = 0;
   45.80 -    for(i = 0; i< 4; i++){
   45.81 -        c = IOStream_getc(io);
   45.82 -        if(c < 0) break;
   45.83 -        *x <<= 8;
   45.84 -        *x |= (0xff & c);
   45.85 -    }
   45.86 -    err = IOStream_error(io);
   45.87 -    if(c < 0 && !err) err = -EIO;
   45.88 -    return err;
   45.89 -}
   45.90 -
   45.91 -int pack_string(IOStream *io, Sxpr x){
   45.92 -    int err = 0;
   45.93 -    int n = string_length(x);
   45.94 -    char *s = string_string(x);
   45.95 -    int i;
   45.96 -    err = pack_uint(io, n);
   45.97 -    if(err) goto exit;
   45.98 -    for(i = 0; i < n; i++){
   45.99 -        err = IOStream_print(io, "%c", s[i]);
  45.100 -        if(err < 0) break;
  45.101 -    }
  45.102 -    if(err > 0) err = 0;
  45.103 -  exit:
  45.104 -    return err;
  45.105 -}
  45.106 -
  45.107 -int unpack_string(IOStream *io, Sxpr *x){
  45.108 -    int err;
  45.109 -    unsigned int n;
  45.110 -    int i, c = 0;
  45.111 -    char *s;
  45.112 -    Sxpr val = ONONE;
  45.113 -    
  45.114 -    err = unpack_uint(io, &n);
  45.115 -    if(err) goto exit;
  45.116 -    val = halloc(n+1, T_STRING);
  45.117 -    if(NOMEMP(val)){
  45.118 -        err = -ENOMEM;
  45.119 -        goto exit;
  45.120 -    }
  45.121 -    s = string_string(val);
  45.122 -    for(i=0; i<n; i++){
  45.123 -        c = IOStream_getc(io);
  45.124 -        if(c < 0) break;
  45.125 -        s[i] = (char)c;
  45.126 -    }
  45.127 -    s[n] = '\0';
  45.128 -  exit:
  45.129 -    err = IOStream_error(io);
  45.130 -    if(c < 0 && !err) err = -EIO;
  45.131 -    if(err){
  45.132 -        objfree(val);
  45.133 -        val = ONONE;
  45.134 -    }
  45.135 -    *x = val;
  45.136 -    return err;
  45.137 -}
  45.138 -
  45.139 -int pack_cons(IOStream *io, Sxpr x){
  45.140 -    int err = 0;
  45.141 -    err = pack_sxpr(io, CAR(x));
  45.142 -    if(err) goto exit;
  45.143 -    err = pack_sxpr(io, CDR(x));
  45.144 -  exit:
  45.145 -    return err;
  45.146 -}
  45.147 -
  45.148 -int unpack_cons(IOStream *io, Sxpr *x){
  45.149 -    int err = 0;
  45.150 -    Sxpr u = ONONE, v = ONONE, val = ONONE;
  45.151 -    err = unpack_sxpr(io, &u);
  45.152 -    if(err) goto exit;
  45.153 -    err = unpack_sxpr(io, &v);
  45.154 -    if(err) goto exit;
  45.155 -    val = cons_new(u, v);
  45.156 -    if(NOMEMP(val)){
  45.157 -        err = -ENOMEM;
  45.158 -    }
  45.159 -  exit:
  45.160 -    if(err){
  45.161 -        objfree(u);
  45.162 -        objfree(v);
  45.163 -        val = ONONE;
  45.164 -    }        
  45.165 -    *x = val;
  45.166 -    return err;
  45.167 -}
  45.168 -
  45.169 -int pack_sxpr(IOStream *io, Sxpr x){
  45.170 -    int err = 0;
  45.171 -    unsigned short type = get_type(x);
  45.172 -    err = pack_ushort(io, type);
  45.173 -    if(err) goto exit;
  45.174 -    switch(type){
  45.175 -    case T_NULL:
  45.176 -        break;
  45.177 -    case T_NONE:
  45.178 -        break;
  45.179 -        break;
  45.180 -    case T_BOOL:
  45.181 -        err = pack_bool(io, get_ul(x));
  45.182 -        break;
  45.183 -    case T_CONS:
  45.184 -        err = pack_cons(io, x);
  45.185 -        break;
  45.186 -    case T_ATOM:
  45.187 -        err = pack_string(io, OBJ_ATOM(x)->name);
  45.188 -        break;
  45.189 -    case T_STRING:
  45.190 -        err = pack_string(io, x);
  45.191 -        break;
  45.192 -    case T_UINT:
  45.193 -        err = pack_uint(io, get_ul(x));
  45.194 -        break;
  45.195 -    default:
  45.196 -        err = -EINVAL;
  45.197 -        IOStream_print(iostderr, "%s> invalid type %d\n", __FUNCTION__, type);
  45.198 -        break;
  45.199 -    }
  45.200 -  exit:
  45.201 -    return err;
  45.202 -}
  45.203 -
  45.204 -int unpack_sxpr(IOStream *io, Sxpr *x){
  45.205 -    int err = 0;
  45.206 -    unsigned short type;
  45.207 -    unsigned int u;
  45.208 -    Sxpr val = ONONE, y;
  45.209 -
  45.210 -    err = unpack_ushort(io, &type);
  45.211 -    if(err) goto exit;
  45.212 -    switch(type){
  45.213 -    case T_NULL:
  45.214 -        val = ONULL;
  45.215 -        break;
  45.216 -    case T_NONE:
  45.217 -        val = ONONE;
  45.218 -        break;
  45.219 -    case T_CONS:
  45.220 -        err = unpack_cons(io, &val);
  45.221 -        break;
  45.222 -    case T_BOOL:
  45.223 -        err = unpack_bool(io, &u);
  45.224 -        if(err) goto exit;
  45.225 -        val = (u ? OTRUE : OFALSE);
  45.226 -        break;
  45.227 -    case T_ATOM:
  45.228 -        err = unpack_string(io, &y);
  45.229 -        if(err) goto exit;
  45.230 -        val = intern(string_string(y));
  45.231 -        objfree(y);
  45.232 -        break;
  45.233 -    case T_STRING:
  45.234 -        err = unpack_string(io, &val);
  45.235 -        break;
  45.236 -    case T_UINT:
  45.237 -        err = unpack_uint(io, &u);
  45.238 -        if(err) goto exit;
  45.239 -        val = OBJI(type, u);
  45.240 -        break;
  45.241 -    default:
  45.242 -        err = -EINVAL;
  45.243 -        IOStream_print(iostderr, "%s> invalid type %d\n", __FUNCTION__, type);
  45.244 -        break;
  45.245 -    }
  45.246 -  exit:
  45.247 -    *x = (err ? ONONE : val);
  45.248 -    return err;
  45.249 -}
    46.1 --- a/tools/lib/xdr.h	Tue Jun 29 14:14:38 2004 +0000
    46.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    46.3 @@ -1,14 +0,0 @@
    46.4 -/* $Id: xdr.h,v 1.2 2003/09/29 13:40:00 mjw Exp $ */
    46.5 -#ifndef _SP_XDR_H_
    46.6 -#define _SP_XDR_H_
    46.7 -#include "iostream.h"
    46.8 -#include "sxpr.h"
    46.9 -int pack_uint(IOStream *out, unsigned int x);
   46.10 -int unpack_uint(IOStream *in, unsigned int *x);
   46.11 -int pack_string(IOStream *out, Sxpr x);
   46.12 -int unpack_string(IOStream *in, Sxpr *x);
   46.13 -int pack_cons(IOStream *out, Sxpr x);
   46.14 -int unpack_cons(IOStream *in, Sxpr *x);
   46.15 -int pack_sxpr(IOStream *out, Sxpr x);
   46.16 -int unpack_sxpr(IOStream *in, Sxpr *x);
   46.17 -#endif /* _SP_XDR_H_ */
    47.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    47.2 +++ b/tools/libxc/Makefile	Tue Jun 29 19:45:18 2004 +0000
    47.3 @@ -0,0 +1,115 @@
    47.4 +
    47.5 +MAJOR    = 1.3
    47.6 +MINOR    = 0
    47.7 +SONAME   = libxc.so.$(MAJOR)
    47.8 +
    47.9 +CC       = gcc
   47.10 +
   47.11 +XEN_ROOT = ../..
   47.12 +include $(XEN_ROOT)/tools/Make.defs
   47.13 +
   47.14 +vpath %.h      $(XEN_HYPERVISOR_IFS)
   47.15 +INCLUDES += -I $(XEN_HYPERVISOR_IFS)
   47.16 +
   47.17 +vpath %h       $(XEN_LINUX_INCLUDE)
   47.18 +INCLUDES += -I $(XEN_LINUX_INCLUDE)
   47.19 +
   47.20 +vpath %.h      $(XEN_XU)
   47.21 +INCLUDES += -I $(XEN_XU)
   47.22 +
   47.23 +vpath %c       $(XEN_LIBXUTIL)
   47.24 +INCLUDES += -I $(XEN_LIBXUTIL)
   47.25 +
   47.26 +LIB_SRCS :=
   47.27 +LIB_SRCS += allocate.c
   47.28 +#LIB_SRCS += enum.c
   47.29 +LIB_SRCS += file_stream.c
   47.30 +LIB_SRCS += gzip_stream.c
   47.31 +#LIB_SRCS += hash_table.c
   47.32 +LIB_SRCS += iostream.c
   47.33 +#LIB_SRCS += kernel_stream.c
   47.34 +#LIB_SRCS += lexis.c
   47.35 +#LIB_SRCS += lzi_stream.c
   47.36 +#LIB_SRCS += lzo_stream.c
   47.37 +#LIB_SRCS += marshal.c
   47.38 +#LIB_SRCS += socket_stream.c
   47.39 +#LIB_SRCS += string_stream.c
   47.40 +#LIB_SRCS += sxpr.c
   47.41 +#LIB_SRCS += sxpr_parser.c
   47.42 +LIB_SRCS += sys_net.c
   47.43 +LIB_SRCS += sys_string.c
   47.44 +#LIB_SRCS += xdr.c
   47.45 +
   47.46 +SRCS     :=
   47.47 +SRCS     += xc_atropos.c
   47.48 +SRCS     += xc_bvtsched.c
   47.49 +SRCS     += xc_domain.c
   47.50 +SRCS     += xc_evtchn.c
   47.51 +SRCS     += xc_io.c
   47.52 +SRCS     += xc_linux_build.c
   47.53 +SRCS     += xc_linux_restore.c
   47.54 +SRCS     += xc_linux_save.c
   47.55 +SRCS     += xc_misc.c
   47.56 +SRCS     += xc_netbsd_build.c
   47.57 +SRCS     += xc_physdev.c
   47.58 +SRCS     += xc_private.c
   47.59 +SRCS     += xc_rrobin.c
   47.60 +
   47.61 +#SRCS     += $(LIB_SRCS)
   47.62 +
   47.63 +CFLAGS   += -Wall
   47.64 +CFLAGS   += -Werror
   47.65 +CFLAGS   += -g
   47.66 +CFLAGS   += -O3
   47.67 +CFLAGS   += -fno-strict-aliasing
   47.68 +CFLAGS   += $(INCLUDES)
   47.69 +# Get gcc to generate the dependencies for us.
   47.70 +CFLAGS   += -Wp,-MD,.$(@F).d
   47.71 +DEPS     = .*.d
   47.72 +
   47.73 +OBJS     = $(patsubst %.c,%.o,$(SRCS))
   47.74 +
   47.75 +LIB      = libxc.so libxc.so.$(MAJOR) libxc.so.$(MAJOR).$(MINOR)
   47.76 +
   47.77 +all: check-for-zlib $(LIB)
   47.78 +
   47.79 +check-for-zlib:
   47.80 +	@if [ ! -e /usr/include/zlib.h ]; then \
   47.81 +	echo "***********************************************************"; \
   47.82 +	echo "ERROR: install zlib header files (http://www.gzip.org/zlib)"; \
   47.83 +	echo "***********************************************************"; \
   47.84 +	false; \
   47.85 +	fi
   47.86 +
   47.87 +install: all
   47.88 +	mkdir -p $(prefix)/usr/lib
   47.89 +	mkdir -p $(prefix)/usr/include
   47.90 +	install -m0755 $(LIB) $(prefix)/usr/lib
   47.91 +	install -m0644 xc.h $(prefix)/usr/include
   47.92 +
   47.93 +clean:
   47.94 +	$(RM) *.a *.so *.o *.rpm $(LIB)
   47.95 +	$(RM) *~
   47.96 +	$(RM) $(DEPS)
   47.97 +
   47.98 +rpm: all
   47.99 +	rm -rf staging
  47.100 +	mkdir staging
  47.101 +	mkdir staging/i386
  47.102 +	rpmbuild --define "staging$$PWD/staging" --define '_builddir.' \
  47.103 +		--define "_rpmdir$$PWD/staging" -bb rpm.spec
  47.104 +	mv staging/i386/*.rpm .
  47.105 +	rm -rf staging
  47.106 +
  47.107 +libxc.so:
  47.108 +	ln -sf libxc.so.$(MAJOR) $@
  47.109 +libxc.so.$(MAJOR):
  47.110 +	ln -sf libxc.so.$(MAJOR).$(MINOR) $@
  47.111 +libxc.so.$(MAJOR).$(MINOR): $(OBJS)
  47.112 +	$(CC) -Wl,-soname -Wl,$(SONAME) -shared -o $@ $^ ../libxutil/libxutil.a -lz 
  47.113 +
  47.114 +%.o: %.c Makefile
  47.115 +
  47.116 +#	$(CC) $(CFLAGS) -o $@ $<
  47.117 +
  47.118 +-include $(DEPS)
    48.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    48.2 +++ b/tools/libxc/rpm.spec	Tue Jun 29 19:45:18 2004 +0000
    48.3 @@ -0,0 +1,28 @@
    48.4 +Summary: Xen control interface library
    48.5 +Name: xen-internal-library
    48.6 +Version: 1.2
    48.7 +Release: 1
    48.8 +License: Xen
    48.9 +Group: Xen
   48.10 +BuildRoot: %{staging}
   48.11 +%description
   48.12 +Library to make it easier to access the Xen control interfaces.
   48.13 +
   48.14 +%pre
   48.15 +%preun
   48.16 +%install
   48.17 +install -m 0755 -d $RPM_BUILD_ROOT/lib
   48.18 +install -m 0755 libxc.a $RPM_BUILD_ROOT/lib/libxc.a
   48.19 +install -m 0755 libxc.so $RPM_BUILD_ROOT/lib/libxc.so
   48.20 +install -m 0755 -d $RPM_BUILD_ROOT/include
   48.21 +install -m 0644 xc.h $RPM_BUILD_ROOT/include/xc.h
   48.22 +%clean
   48.23 +%post
   48.24 +%postun
   48.25 +%files
   48.26 +%defattr(-,root,root)
   48.27 +%dir /lib
   48.28 +/lib/libxc.a
   48.29 +/lib/libxc.so
   48.30 +%dir /include
   48.31 +/include/xc.h
    49.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    49.2 +++ b/tools/libxc/xc.h	Tue Jun 29 19:45:18 2004 +0000
    49.3 @@ -0,0 +1,203 @@
    49.4 +/******************************************************************************
    49.5 + * xc.h
    49.6 + * 
    49.7 + * A library for low-level access to the Xen control interfaces.
    49.8 + * 
    49.9 + * Copyright (c) 2003, K A Fraser.
   49.10 + */
   49.11 +
   49.12 +#ifndef __XC_H__
   49.13 +#define __XC_H__
   49.14 +
   49.15 +typedef unsigned char      u8;
   49.16 +typedef unsigned short     u16;
   49.17 +typedef unsigned long      u32;
   49.18 +typedef unsigned long long u64;
   49.19 +typedef signed char        s8;
   49.20 +typedef signed short       s16;
   49.21 +typedef signed long        s32;
   49.22 +typedef signed long long   s64;
   49.23 +
   49.24 +/* Obtain or relinquish a handle on the 'xc' library. */
   49.25 +int xc_interface_open(void);
   49.26 +int xc_interface_close(int xc_handle);
   49.27 +
   49.28 +typedef struct {
   49.29 +    u32           domid;
   49.30 +    unsigned int  cpu;
   49.31 +    unsigned int  dying:1, crashed:1, shutdown:1, 
   49.32 +                  paused:1, blocked:1, running:1;
   49.33 +    unsigned int  shutdown_reason; /* only meaningful if shutdown==1 */
   49.34 +    unsigned long nr_pages;
   49.35 +    unsigned long shared_info_frame;
   49.36 +    u64           cpu_time;
   49.37 +#define XC_DOMINFO_MAXNAME 16
   49.38 +    char          name[XC_DOMINFO_MAXNAME];
   49.39 +    unsigned long max_memkb;
   49.40 +} xc_dominfo_t;
   49.41 +
   49.42 +typedef struct xc_shadow_control_stats_st
   49.43 +{
   49.44 +    unsigned long fault_count;
   49.45 +    unsigned long dirty_count;
   49.46 +    unsigned long dirty_net_count;     
   49.47 +    unsigned long dirty_block_count;     
   49.48 +} xc_shadow_control_stats_t;
   49.49 +
   49.50 +int xc_domain_create(int xc_handle, 
   49.51 +                     unsigned int mem_kb, 
   49.52 +                     const char *name,
   49.53 +                     int cpu,
   49.54 +                     u32 *pdomid);
   49.55 +int xc_domain_pause(int xc_handle, 
   49.56 +                    u32 domid);
   49.57 +int xc_domain_unpause(int xc_handle, 
   49.58 +                      u32 domid);
   49.59 +int xc_domain_destroy(int xc_handle, 
   49.60 +                      u32 domid);
   49.61 +int xc_domain_pincpu(int xc_handle,
   49.62 +                     u32 domid,
   49.63 +                     int cpu);
   49.64 +int xc_domain_getinfo(int xc_handle,
   49.65 +                      u32 first_domid, 
   49.66 +                      unsigned int max_doms,
   49.67 +                      xc_dominfo_t *info);
   49.68 +
   49.69 +int xc_shadow_control(int xc_handle,
   49.70 +                      u32 domid, 
   49.71 +                      unsigned int sop,
   49.72 +                      unsigned long *dirty_bitmap,
   49.73 +                      unsigned long pages,
   49.74 +                      xc_shadow_control_stats_t *stats);
   49.75 +
   49.76 +
   49.77 +#define XCFLAGS_VERBOSE 1
   49.78 +#define XCFLAGS_LIVE    2
   49.79 +#define XCFLAGS_DEBUG   4
   49.80 +
   49.81 +struct XcIOContext;
   49.82 +int xc_linux_save(int xc_handle, struct XcIOContext *ioctxt);
   49.83 +int xc_linux_restore(int xc_handle, struct XcIOContext *ioctxt);
   49.84 +
   49.85 +int xc_linux_build(int xc_handle,
   49.86 +                   u32 domid,
   49.87 +                   const char *image_name,
   49.88 +                   const char *ramdisk_name,
   49.89 +                   const char *cmdline,
   49.90 +                   unsigned int control_evtchn,
   49.91 +                   unsigned long flags);
   49.92 +
   49.93 +int xc_netbsd_build(int xc_handle,
   49.94 +                    u32 domid,
   49.95 +                    const char *image_name,
   49.96 +                    const char *cmdline,
   49.97 +                    unsigned int control_evtchn);
   49.98 +
   49.99 +int xc_bvtsched_global_set(int xc_handle,
  49.100 +                           unsigned long ctx_allow);
  49.101 +
  49.102 +int xc_bvtsched_domain_set(int xc_handle,
  49.103 +                           u32 domid,
  49.104 +                           unsigned long mcuadv,
  49.105 +                           unsigned long warp,
  49.106 +                           unsigned long warpl,
  49.107 +                           unsigned long warpu);
  49.108 +
  49.109 +int xc_bvtsched_global_get(int xc_handle,
  49.110 +                           unsigned long *ctx_allow);
  49.111 +
  49.112 +int xc_bvtsched_domain_get(int xc_handle,
  49.113 +                           u32 domid,
  49.114 +                           unsigned long *mcuadv,
  49.115 +                           unsigned long *warp,
  49.116 +                           unsigned long *warpl,
  49.117 +                           unsigned long *warpu);
  49.118 +
  49.119 +int xc_atropos_domain_set(int xc_handle,
  49.120 +                          u32 domid,
  49.121 +                          u64 period, u64 slice, u64 latency,
  49.122 +                          int xtratime);
  49.123 +
  49.124 +int xc_atropos_domain_get(int xc_handle,
  49.125 +                          u32 domid,
  49.126 +                          u64* period, u64 *slice, u64 *latency,
  49.127 +                          int *xtratime);
  49.128 +
  49.129 +int xc_rrobin_global_set(int xc_handle, u64 slice);
  49.130 +
  49.131 +int xc_rrobin_global_get(int xc_handle, u64 *slice);
  49.132 +
  49.133 +#define DOMID_SELF              (0x7FFFFFFEU)
  49.134 +
  49.135 +typedef struct {
  49.136 +#define EVTCHNSTAT_closed       0  /* Chennel is not in use.                 */
  49.137 +#define EVTCHNSTAT_unbound      1  /* Channel is not bound to a source.      */
  49.138 +#define EVTCHNSTAT_interdomain  2  /* Channel is connected to remote domain. */
  49.139 +#define EVTCHNSTAT_pirq         3  /* Channel is bound to a phys IRQ line.   */
  49.140 +#define EVTCHNSTAT_virq         4  /* Channel is bound to a virtual IRQ line */
  49.141 +    int status;
  49.142 +    union {
  49.143 +        struct {
  49.144 +            u32 dom;
  49.145 +            int port;
  49.146 +        } interdomain;
  49.147 +        int pirq;
  49.148 +        int virq;
  49.149 +    } u;
  49.150 +} xc_evtchn_status_t;
  49.151 +
  49.152 +int xc_evtchn_bind_interdomain(int xc_handle,
  49.153 +                               u32 dom1,   /* may be DOMID_SELF */
  49.154 +                               u32 dom2,   /* may be DOMID_SELF */
  49.155 +                               int *port1,
  49.156 +                               int *port2);
  49.157 +int xc_evtchn_bind_virq(int xc_handle,
  49.158 +                        int virq,
  49.159 +                        int *port);
  49.160 +int xc_evtchn_close(int xc_handle,
  49.161 +                    u32 dom,   /* may be DOMID_SELF */
  49.162 +                    int port);
  49.163 +int xc_evtchn_send(int xc_handle,
  49.164 +                   int local_port);
  49.165 +int xc_evtchn_status(int xc_handle,
  49.166 +                     u32 dom, /* may be DOMID_SELF */
  49.167 +                     int port,
  49.168 +                     xc_evtchn_status_t *status);
  49.169 +
  49.170 +int xc_physdev_pci_access_modify(int xc_handle,
  49.171 +                                 u32 domid,
  49.172 +                                 int bus,
  49.173 +                                 int dev,
  49.174 +                                 int func,
  49.175 +                                 int enable);
  49.176 +
  49.177 +int xc_readconsolering(int xc_handle,
  49.178 +                       char *str, 
  49.179 +                       unsigned int max_chars, 
  49.180 +                       int clear);
  49.181 +
  49.182 +typedef struct {
  49.183 +    int ht_per_core;
  49.184 +    int cores;
  49.185 +    unsigned long total_pages;
  49.186 +    unsigned long free_pages;
  49.187 +    unsigned long cpu_khz;
  49.188 +} xc_physinfo_t;
  49.189 +
  49.190 +int xc_physinfo(int xc_handle,
  49.191 +                xc_physinfo_t *info);
  49.192 +
  49.193 +int xc_domain_setname(int xc_handle,
  49.194 +                      u32 domid, 
  49.195 +                      char *name);
  49.196 +
  49.197 +int xc_domain_setinitialmem(int xc_handle,
  49.198 +                            u32 domid, 
  49.199 +                            unsigned int initial_memkb);
  49.200 +
  49.201 +int xc_domain_setmaxmem(int xc_handle,
  49.202 +                            u32 domid, 
  49.203 +                            unsigned int max_memkb);
  49.204 +
  49.205 +
  49.206 +#endif /* __XC_H__ */
    50.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    50.2 +++ b/tools/libxc/xc_atropos.c	Tue Jun 29 19:45:18 2004 +0000
    50.3 @@ -0,0 +1,51 @@
    50.4 +/******************************************************************************
    50.5 + * xc_atropos.c
    50.6 + * 
    50.7 + * API for manipulating parameters of the Atropos scheduler.
    50.8 + * 
    50.9 + * by Mark Williamson, Copyright (c) 2004 Intel Research Cambridge.
   50.10 + */
   50.11 +
   50.12 +#include "xc_private.h"
   50.13 +
   50.14 +int xc_atropos_domain_set(int xc_handle,
   50.15 +                          u32 domid, u64 period, u64 slice, u64 latency,
   50.16 +                          int xtratime)
   50.17 +{
   50.18 +    dom0_op_t op;
   50.19 +    struct atropos_adjdom *p = &op.u.adjustdom.u.atropos;
   50.20 +
   50.21 +    op.cmd = DOM0_ADJUSTDOM;
   50.22 +    op.u.adjustdom.domain  = (domid_t)domid;
   50.23 +    op.u.adjustdom.sched_id = SCHED_ATROPOS;
   50.24 +    op.u.adjustdom.direction = SCHED_INFO_PUT;
   50.25 +
   50.26 +    p->nat_period   = period;
   50.27 +    p->nat_slice    = slice;
   50.28 +    p->latency  = latency;
   50.29 +    p->xtratime = xtratime;
   50.30 +
   50.31 +    return do_dom0_op(xc_handle, &op);
   50.32 +}
   50.33 +
   50.34 +int xc_atropos_domain_get(int xc_handle, u32 domid, u64 *period,
   50.35 +                          u64 *slice, u64 *latency, int *xtratime)
   50.36 +{
   50.37 +    dom0_op_t op;
   50.38 +    int ret;
   50.39 +    struct atropos_adjdom *p = &op.u.adjustdom.u.atropos;
   50.40 +
   50.41 +    op.cmd = DOM0_ADJUSTDOM;    
   50.42 +    op.u.adjustdom.domain = (domid_t)domid;
   50.43 +    op.u.adjustdom.sched_id = SCHED_ATROPOS;
   50.44 +    op.u.adjustdom.direction = SCHED_INFO_GET;
   50.45 +
   50.46 +    ret = do_dom0_op(xc_handle, &op);
   50.47 +
   50.48 +    *period   = p->nat_period;
   50.49 +    *slice    = p->nat_slice;
   50.50 +    *latency  = p->latency;
   50.51 +    *xtratime = p->xtratime;
   50.52 +
   50.53 +    return ret;
   50.54 +}
    51.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    51.2 +++ b/tools/libxc/xc_bvtsched.c	Tue Jun 29 19:45:18 2004 +0000
    51.3 @@ -0,0 +1,88 @@
    51.4 +/******************************************************************************
    51.5 + * xc_bvtsched.c
    51.6 + * 
    51.7 + * API for manipulating parameters of the Borrowed Virtual Time scheduler.
    51.8 + * 
    51.9 + * Copyright (c) 2003, K A Fraser.
   51.10 + */
   51.11 +
   51.12 +#include "xc_private.h"
   51.13 +
   51.14 +int xc_bvtsched_global_set(int xc_handle,
   51.15 +                           unsigned long ctx_allow)
   51.16 +{
   51.17 +    dom0_op_t op;
   51.18 +
   51.19 +    op.cmd = DOM0_SCHEDCTL;
   51.20 +    op.u.schedctl.sched_id = SCHED_BVT;
   51.21 +    op.u.schedctl.direction = SCHED_INFO_PUT;
   51.22 +    op.u.schedctl.u.bvt.ctx_allow = ctx_allow;
   51.23 +
   51.24 +    return do_dom0_op(xc_handle, &op);
   51.25 +}
   51.26 +
   51.27 +int xc_bvtsched_global_get(int xc_handle,
   51.28 +                           unsigned long *ctx_allow)
   51.29 +{
   51.30 +    dom0_op_t op;
   51.31 +    int ret;
   51.32 +    
   51.33 +    op.cmd = DOM0_SCHEDCTL;
   51.34 +    op.u.schedctl.sched_id = SCHED_BVT;
   51.35 +    op.u.schedctl.direction = SCHED_INFO_GET;
   51.36 +
   51.37 +    ret = do_dom0_op(xc_handle, &op);
   51.38 +
   51.39 +    *ctx_allow = op.u.schedctl.u.bvt.ctx_allow;
   51.40 +
   51.41 +    return ret;
   51.42 +}
   51.43 +
   51.44 +int xc_bvtsched_domain_set(int xc_handle,
   51.45 +                           u32 domid,
   51.46 +                           unsigned long mcuadv,
   51.47 +                           unsigned long warp,
   51.48 +                           unsigned long warpl,
   51.49 +                           unsigned long warpu)
   51.50 +{
   51.51 +    dom0_op_t op;
   51.52 +    struct bvt_adjdom *bvtadj = &op.u.adjustdom.u.bvt;
   51.53 +
   51.54 +    op.cmd = DOM0_ADJUSTDOM;
   51.55 +    op.u.adjustdom.domain  = (domid_t)domid;
   51.56 +    op.u.adjustdom.sched_id = SCHED_BVT;
   51.57 +    op.u.adjustdom.direction = SCHED_INFO_PUT;
   51.58 +
   51.59 +    bvtadj->mcu_adv = mcuadv;
   51.60 +    bvtadj->warp    = warp;
   51.61 +    bvtadj->warpl   = warpl;
   51.62 +    bvtadj->warpu   = warpu;
   51.63 +    return do_dom0_op(xc_handle, &op);
   51.64 +}
   51.65 +
   51.66 +
   51.67 +int xc_bvtsched_domain_get(int xc_handle,
   51.68 +                           u32 domid,
   51.69 +                           unsigned long *mcuadv,
   51.70 +                           unsigned long *warp,
   51.71 +                           unsigned long *warpl,
   51.72 +                           unsigned long *warpu)
   51.73 +{
   51.74 +    
   51.75 +    dom0_op_t op;
   51.76 +    int ret;
   51.77 +    struct bvt_adjdom *adjptr = &op.u.adjustdom.u.bvt;
   51.78 +
   51.79 +    op.cmd = DOM0_ADJUSTDOM;
   51.80 +    op.u.adjustdom.domain  = (domid_t)domid;
   51.81 +    op.u.adjustdom.sched_id = SCHED_BVT;
   51.82 +    op.u.adjustdom.direction = SCHED_INFO_GET;
   51.83 +
   51.84 +    ret = do_dom0_op(xc_handle, &op);
   51.85 +
   51.86 +    *mcuadv = adjptr->mcu_adv;
   51.87 +    *warp   = adjptr->warp;
   51.88 +    *warpl  = adjptr->warpl;
   51.89 +    *warpu  = adjptr->warpu;
   51.90 +    return ret;
   51.91 +}
    52.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    52.2 +++ b/tools/libxc/xc_domain.c	Tue Jun 29 19:45:18 2004 +0000
    52.3 @@ -0,0 +1,194 @@
    52.4 +/******************************************************************************
    52.5 + * xc_domain.c
    52.6 + * 
    52.7 + * API for manipulating and obtaining information on domains.
    52.8 + * 
    52.9 + * Copyright (c) 2003, K A Fraser.
   52.10 + */
   52.11 +
   52.12 +#include "xc_private.h"
   52.13 +
   52.14 +int xc_domain_create(int xc_handle,
   52.15 +                     unsigned int mem_kb, 
   52.16 +                     const char *name,
   52.17 +                     int cpu,
   52.18 +                     u32 *pdomid)
   52.19 +{
   52.20 +    int err;
   52.21 +    dom0_op_t op;
   52.22 +
   52.23 +    op.cmd = DOM0_CREATEDOMAIN;
   52.24 +    op.u.createdomain.memory_kb = mem_kb;
   52.25 +    strncpy(op.u.createdomain.name, name, MAX_DOMAIN_NAME);
   52.26 +    op.u.createdomain.name[MAX_DOMAIN_NAME-1] = '\0';
   52.27 +    op.u.createdomain.cpu = cpu;
   52.28 +
   52.29 +    if ( (err = do_dom0_op(xc_handle, &op)) == 0 )
   52.30 +        *pdomid = (u32)op.u.createdomain.domain;
   52.31 +
   52.32 +    return err;
   52.33 +}    
   52.34 +
   52.35 +
   52.36 +int xc_domain_pause(int xc_handle, 
   52.37 +                    u32 domid)
   52.38 +{
   52.39 +    dom0_op_t op;
   52.40 +    op.cmd = DOM0_PAUSEDOMAIN;
   52.41 +    op.u.pausedomain.domain = (domid_t)domid;
   52.42 +    return do_dom0_op(xc_handle, &op);
   52.43 +}    
   52.44 +
   52.45 +
   52.46 +int xc_domain_unpause(int xc_handle,
   52.47 +                      u32 domid)
   52.48 +{
   52.49 +    dom0_op_t op;
   52.50 +    op.cmd = DOM0_UNPAUSEDOMAIN;
   52.51 +    op.u.unpausedomain.domain = (domid_t)domid;
   52.52 +    return do_dom0_op(xc_handle, &op);
   52.53 +}    
   52.54 +
   52.55 +
   52.56 +int xc_domain_destroy(int xc_handle,
   52.57 +                      u32 domid)
   52.58 +{
   52.59 +    dom0_op_t op;
   52.60 +    op.cmd = DOM0_DESTROYDOMAIN;
   52.61 +    op.u.destroydomain.domain = (domid_t)domid;
   52.62 +    return do_dom0_op(xc_handle, &op);
   52.63 +}
   52.64 +
   52.65 +int xc_domain_pincpu(int xc_handle,
   52.66 +                     u32 domid, 
   52.67 +                     int cpu)
   52.68 +{
   52.69 +    dom0_op_t op;
   52.70 +    op.cmd = DOM0_PINCPUDOMAIN;
   52.71 +    op.u.pincpudomain.domain = (domid_t)domid;
   52.72 +    op.u.pincpudomain.cpu  = cpu;
   52.73 +    return do_dom0_op(xc_handle, &op);
   52.74 +}
   52.75 +
   52.76 +
   52.77 +int xc_domain_getinfo(int xc_handle,
   52.78 +                      u32 first_domid,
   52.79 +                      unsigned int max_doms,
   52.80 +                      xc_dominfo_t *info)
   52.81 +{
   52.82 +    unsigned int nr_doms;
   52.83 +    u32 next_domid = first_domid;
   52.84 +    dom0_op_t op;
   52.85 +
   52.86 +    for ( nr_doms = 0; nr_doms < max_doms; nr_doms++ )
   52.87 +    {
   52.88 +        op.cmd = DOM0_GETDOMAININFO;
   52.89 +        op.u.getdomaininfo.domain = (domid_t)next_domid;
   52.90 +        op.u.getdomaininfo.ctxt = NULL; /* no exec context info, thanks. */
   52.91 +        if ( do_dom0_op(xc_handle, &op) < 0 )
   52.92 +            break;
   52.93 +        info->domid   = (u32)op.u.getdomaininfo.domain;
   52.94 +
   52.95 +        info->cpu     =
   52.96 +            (op.u.getdomaininfo.flags>>DOMFLAGS_CPUSHIFT) & DOMFLAGS_CPUMASK;
   52.97 +
   52.98 +        info->dying    = !!(op.u.getdomaininfo.flags & DOMFLAGS_DYING);
   52.99 +        info->crashed  = !!(op.u.getdomaininfo.flags & DOMFLAGS_CRASHED);
  52.100 +        info->shutdown = !!(op.u.getdomaininfo.flags & DOMFLAGS_SHUTDOWN);
  52.101 +        info->paused   = !!(op.u.getdomaininfo.flags & DOMFLAGS_PAUSED);
  52.102 +        info->blocked  = !!(op.u.getdomaininfo.flags & DOMFLAGS_BLOCKED);
  52.103 +        info->running  = !!(op.u.getdomaininfo.flags & DOMFLAGS_RUNNING);
  52.104 +
  52.105 +        info->shutdown_reason = 
  52.106 +            (op.u.getdomaininfo.flags>>DOMFLAGS_SHUTDOWNSHIFT) & 
  52.107 +            DOMFLAGS_SHUTDOWNMASK;
  52.108 +
  52.109 +        info->nr_pages = op.u.getdomaininfo.tot_pages;
  52.110 +        info->max_memkb = op.u.getdomaininfo.max_pages<<(PAGE_SHIFT-10);
  52.111 +        info->shared_info_frame = op.u.getdomaininfo.shared_info_frame;
  52.112 +        info->cpu_time = op.u.getdomaininfo.cpu_time;
  52.113 +        strncpy(info->name, op.u.getdomaininfo.name, XC_DOMINFO_MAXNAME);
  52.114 +        info->name[XC_DOMINFO_MAXNAME-1] = '\0';
  52.115 +
  52.116 +        next_domid = (u32)op.u.getdomaininfo.domain + 1;
  52.117 +        info++;
  52.118 +    }
  52.119 +
  52.120 +    return nr_doms;
  52.121 +}
  52.122 +
  52.123 +int xc_domain_getfullinfo(int xc_handle,
  52.124 +                          u32 domid,
  52.125 +                          dom0_op_t *op,
  52.126 +                          full_execution_context_t *ctxt )
  52.127 +{
  52.128 +    int rc;
  52.129 +    op->cmd = DOM0_GETDOMAININFO;
  52.130 +    op->u.getdomaininfo.domain = (domid_t)domid;
  52.131 +    op->u.getdomaininfo.ctxt = ctxt;
  52.132 +
  52.133 +    rc = do_dom0_op(xc_handle, op);
  52.134 +    if ( ((u32)op->u.getdomaininfo.domain != domid) && rc > 0 )
  52.135 +        return -ESRCH;
  52.136 +    else
  52.137 +        return rc;
  52.138 +}
  52.139 +
  52.140 +
  52.141 +int xc_shadow_control(int xc_handle,
  52.142 +                      u32 domid, 
  52.143 +                      unsigned int sop,
  52.144 +                      unsigned long *dirty_bitmap,
  52.145 +                      unsigned long pages,
  52.146 +                      xc_shadow_control_stats_t *stats )
  52.147 +{
  52.148 +    int rc;
  52.149 +    dom0_op_t op;
  52.150 +    op.cmd = DOM0_SHADOW_CONTROL;
  52.151 +    op.u.shadow_control.domain = (domid_t)domid;
  52.152 +    op.u.shadow_control.op     = sop;
  52.153 +    op.u.shadow_control.dirty_bitmap = dirty_bitmap;
  52.154 +    op.u.shadow_control.pages  = pages;
  52.155 +
  52.156 +    rc = do_dom0_op(xc_handle, &op);
  52.157 +
  52.158 +    if ( stats )
  52.159 +        memcpy(stats, &op.u.shadow_control.stats,
  52.160 +               sizeof(xc_shadow_control_stats_t));
  52.161 +
  52.162 +    return (rc == 0) ? op.u.shadow_control.pages : rc;
  52.163 +}
  52.164 +
  52.165 +int xc_domain_setname(int xc_handle,
  52.166 +                      u32 domid, 
  52.167 +                      char *name)
  52.168 +{
  52.169 +    dom0_op_t op;
  52.170 +    op.cmd = DOM0_SETDOMAINNAME;
  52.171 +    op.u.setdomainname.domain = (domid_t)domid;
  52.172 +    strncpy(op.u.setdomainname.name, name, MAX_DOMAIN_NAME);
  52.173 +    return do_dom0_op(xc_handle, &op);
  52.174 +}
  52.175 +
  52.176 +int xc_domain_setinitialmem(int xc_handle,
  52.177 +                            u32 domid, 
  52.178 +                            unsigned int initial_memkb)
  52.179 +{
  52.180 +    dom0_op_t op;
  52.181 +    op.cmd = DOM0_SETDOMAININITIALMEM;
  52.182 +    op.u.setdomaininitialmem.domain = (domid_t)domid;
  52.183 +    op.u.setdomaininitialmem.initial_memkb = initial_memkb;
  52.184 +    return do_dom0_op(xc_handle, &op);
  52.185 +}
  52.186 +
  52.187 +int xc_domain_setmaxmem(int xc_handle,
  52.188 +                        u32 domid, 
  52.189 +                        unsigned int max_memkb)
  52.190 +{
  52.191 +    dom0_op_t op;
  52.192 +    op.cmd = DOM0_SETDOMAINMAXMEM;
  52.193 +    op.u.setdomainmaxmem.domain = (domid_t)domid;
  52.194 +    op.u.setdomainmaxmem.max_memkb = max_memkb;
  52.195 +    return do_dom0_op(xc_handle, &op);
  52.196 +}
  52.197 +
    53.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    53.2 +++ b/tools/libxc/xc_elf.h	Tue Jun 29 19:45:18 2004 +0000
    53.3 @@ -0,0 +1,523 @@
    53.4 +/*
    53.5 + * Copyright (c) 1995, 1996 Erik Theisen.  All rights reserved.
    53.6 + *
    53.7 + * Redistribution and use in source and binary forms, with or without
    53.8 + * modification, are permitted provided that the following conditions
    53.9 + * are met:
   53.10 + * 1. Redistributions of source code must retain the above copyright
   53.11 + *    notice, this list of conditions and the following disclaimer.
   53.12 + * 2. Redistributions in binary form must reproduce the above copyright
   53.13 + *    notice, this list of conditions and the following disclaimer in the
   53.14 + *    documentation and/or other materials provided with the distribution.
   53.15 + * 3. The name of the author may not be used to endorse or promote products
   53.16 + *    derived from this software without specific prior written permission
   53.17 + *
   53.18 + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
   53.19 + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   53.20 + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
   53.21 + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
   53.22 + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
   53.23 + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
   53.24 + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
   53.25 + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
   53.26 + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
   53.27 + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   53.28 + */
   53.29 +
   53.30 +typedef u_int8_t	Elf_Byte;
   53.31 +
   53.32 +typedef u_int32_t	Elf32_Addr;	/* Unsigned program address */
   53.33 +typedef u_int32_t	Elf32_Off;	/* Unsigned file offset */
   53.34 +typedef int32_t		Elf32_Sword;	/* Signed large integer */
   53.35 +typedef u_int32_t	Elf32_Word;	/* Unsigned large integer */
   53.36 +typedef u_int16_t	Elf32_Half;	/* Unsigned medium integer */
   53.37 +
   53.38 +typedef u_int64_t	Elf64_Addr;
   53.39 +typedef u_int64_t	Elf64_Off;
   53.40 +typedef int32_t		Elf64_Shalf;
   53.41 +
   53.42 +typedef int32_t		Elf64_Sword;
   53.43 +typedef u_int32_t	Elf64_Word;
   53.44 +
   53.45 +typedef int64_t		Elf64_Sxword;
   53.46 +typedef u_int64_t	Elf64_Xword;
   53.47 +
   53.48 +typedef u_int32_t	Elf64_Half;
   53.49 +typedef u_int16_t	Elf64_Quarter;
   53.50 +
   53.51 +/*
   53.52 + * e_ident[] identification indexes 
   53.53 + * See http://www.caldera.com/developers/gabi/2000-07-17/ch4.eheader.html
   53.54 + */
   53.55 +#define EI_MAG0		0		/* file ID */
   53.56 +#define EI_MAG1		1		/* file ID */
   53.57 +#define EI_MAG2		2		/* file ID */
   53.58 +#define EI_MAG3		3		/* file ID */
   53.59 +#define EI_CLASS	4		/* file class */
   53.60 +#define EI_DATA		5		/* data encoding */
   53.61 +#define EI_VERSION	6		/* ELF header version */
   53.62 +#define EI_OSABI	7		/* OS/ABI ID */
   53.63 +#define EI_ABIVERSION	8		/* ABI version */ 
   53.64 +#define EI_PAD		9		/* start of pad bytes */
   53.65 +#define EI_NIDENT	16		/* Size of e_ident[] */
   53.66 +
   53.67 +/* e_ident[] magic number */
   53.68 +#define	ELFMAG0		0x7f		/* e_ident[EI_MAG0] */
   53.69 +#define	ELFMAG1		'E'		/* e_ident[EI_MAG1] */
   53.70 +#define	ELFMAG2		'L'		/* e_ident[EI_MAG2] */
   53.71 +#define	ELFMAG3		'F'		/* e_ident[EI_MAG3] */
   53.72 +#define	ELFMAG		"\177ELF"	/* magic */
   53.73 +#define	SELFMAG		4		/* size of magic */
   53.74 +
   53.75 +/* e_ident[] file class */
   53.76 +#define	ELFCLASSNONE	0		/* invalid */
   53.77 +#define	ELFCLASS32	1		/* 32-bit objs */
   53.78 +#define	ELFCLASS64	2		/* 64-bit objs */
   53.79 +#define	ELFCLASSNUM	3		/* number of classes */
   53.80 +
   53.81 +/* e_ident[] data encoding */
   53.82 +#define ELFDATANONE	0		/* invalid */
   53.83 +#define ELFDATA2LSB	1		/* Little-Endian */
   53.84 +#define ELFDATA2MSB	2		/* Big-Endian */
   53.85 +#define ELFDATANUM	3		/* number of data encode defines */
   53.86 +
   53.87 +/* e_ident[] Operating System/ABI */
   53.88 +#define ELFOSABI_SYSV		0	/* UNIX System V ABI */
   53.89 +#define ELFOSABI_HPUX		1	/* HP-UX operating system */
   53.90 +#define ELFOSABI_NETBSD		2	/* NetBSD */
   53.91 +#define ELFOSABI_LINUX		3	/* GNU/Linux */
   53.92 +#define ELFOSABI_HURD		4	/* GNU/Hurd */
   53.93 +#define ELFOSABI_86OPEN		5	/* 86Open common IA32 ABI */
   53.94 +#define ELFOSABI_SOLARIS	6	/* Solaris */
   53.95 +#define ELFOSABI_MONTEREY	7	/* Monterey */
   53.96 +#define ELFOSABI_IRIX		8	/* IRIX */
   53.97 +#define ELFOSABI_FREEBSD	9	/* FreeBSD */
   53.98 +#define ELFOSABI_TRU64		10	/* TRU64 UNIX */
   53.99 +#define ELFOSABI_MODESTO	11	/* Novell Modesto */
  53.100 +#define ELFOSABI_OPENBSD	12	/* OpenBSD */
  53.101 +#define ELFOSABI_ARM		97	/* ARM */
  53.102 +#define ELFOSABI_STANDALONE	255	/* Standalone (embedded) application */
  53.103 +
  53.104 +/* e_ident */
  53.105 +#define IS_ELF(ehdr) ((ehdr).e_ident[EI_MAG0] == ELFMAG0 && \
  53.106 +                      (ehdr).e_ident[EI_MAG1] == ELFMAG1 && \
  53.107 +                      (ehdr).e_ident[EI_MAG2] == ELFMAG2 && \
  53.108 +                      (ehdr).e_ident[EI_MAG3] == ELFMAG3)
  53.109 +
  53.110 +/* ELF Header */
  53.111 +typedef struct elfhdr {
  53.112 +	unsigned char	e_ident[EI_NIDENT]; /* ELF Identification */
  53.113 +	Elf32_Half	e_type;		/* object file type */
  53.114 +	Elf32_Half	e_machine;	/* machine */
  53.115 +	Elf32_Word	e_version;	/* object file version */
  53.116 +	Elf32_Addr	e_entry;	/* virtual entry point */
  53.117 +	Elf32_Off	e_phoff;	/* program header table offset */
  53.118 +	Elf32_Off	e_shoff;	/* section header table offset */
  53.119 +	Elf32_Word	e_flags;	/* processor-specific flags */
  53.120 +	Elf32_Half	e_ehsize;	/* ELF header size */
  53.121 +	Elf32_Half	e_phentsize;	/* program header entry size */
  53.122 +	Elf32_Half	e_phnum;	/* number of program header entries */
  53.123 +	Elf32_Half	e_shentsize;	/* section header entry size */
  53.124 +	Elf32_Half	e_shnum;	/* number of section header entries */
  53.125 +	Elf32_Half	e_shstrndx;	/* section header table's "section 
  53.126 +					   header string table" entry offset */
  53.127 +} Elf32_Ehdr;
  53.128 +
  53.129 +typedef struct {
  53.130 +	unsigned char	e_ident[EI_NIDENT];	/* Id bytes */
  53.131 +	Elf64_Quarter	e_type;			/* file type */
  53.132 +	Elf64_Quarter	e_machine;		/* machine type */
  53.133 +	Elf64_Half	e_version;		/* version number */
  53.134 +	Elf64_Addr	e_entry;		/* entry point */
  53.135 +	Elf64_Off	e_phoff;		/* Program hdr offset */
  53.136 +	Elf64_Off	e_shoff;		/* Section hdr offset */
  53.137 +	Elf64_Half	e_flags;		/* Processor flags */
  53.138 +	Elf64_Quarter	e_ehsize;		/* sizeof ehdr */
  53.139 +	Elf64_Quarter	e_phentsize;		/* Program header entry size */
  53.140 +	Elf64_Quarter	e_phnum;		/* Number of program headers */
  53.141 +	Elf64_Quarter	e_shentsize;		/* Section header entry size */
  53.142 +	Elf64_Quarter	e_shnum;		/* Number of section headers */
  53.143 +	Elf64_Quarter	e_shstrndx;		/* String table index */
  53.144 +} Elf64_Ehdr;
  53.145 +
  53.146 +/* e_type */
  53.147 +#define ET_NONE		0		/* No file type */
  53.148 +#define ET_REL		1		/* relocatable file */
  53.149 +#define ET_EXEC		2		/* executable file */
  53.150 +#define ET_DYN		3		/* shared object file */
  53.151 +#define ET_CORE		4		/* core file */
  53.152 +#define ET_NUM		5		/* number of types */
  53.153 +#define ET_LOPROC	0xff00		/* reserved range for processor */
  53.154 +#define ET_HIPROC	0xffff		/*  specific e_type */
  53.155 +
  53.156 +/* e_machine */
  53.157 +#define EM_NONE		0		/* No Machine */
  53.158 +#define EM_M32		1		/* AT&T WE 32100 */
  53.159 +#define EM_SPARC	2		/* SPARC */
  53.160 +#define EM_386		3		/* Intel 80386 */
  53.161 +#define EM_68K		4		/* Motorola 68000 */
  53.162 +#define EM_88K		5		/* Motorola 88000 */
  53.163 +#define EM_486		6		/* Intel 80486 - unused? */
  53.164 +#define EM_860		7		/* Intel 80860 */
  53.165 +#define EM_MIPS		8		/* MIPS R3000 Big-Endian only */
  53.166 +/* 
  53.167 + * Don't know if EM_MIPS_RS4_BE,
  53.168 + * EM_SPARC64, EM_PARISC,
  53.169 + * or EM_PPC are ABI compliant
  53.170 + */
  53.171 +#define EM_MIPS_RS4_BE	10		/* MIPS R4000 Big-Endian */
  53.172 +#define EM_SPARC64	11		/* SPARC v9 64-bit unoffical */
  53.173 +#define EM_PARISC	15		/* HPPA */
  53.174 +#define EM_SPARC32PLUS	18		/* Enhanced instruction set SPARC */
  53.175 +#define EM_PPC		20		/* PowerPC */
  53.176 +#define EM_ARM		40		/* Advanced RISC Machines ARM */
  53.177 +#define EM_ALPHA	41		/* DEC ALPHA */
  53.178 +#define EM_SPARCV9	43		/* SPARC version 9 */
  53.179 +#define EM_ALPHA_EXP	0x9026		/* DEC ALPHA */
  53.180 +#define EM_X86_64	62		/* AMD x86-64 architecture */
  53.181 +#define EM_VAX		75		/* DEC VAX */
  53.182 +#define EM_NUM		15		/* number of machine types */
  53.183 +
  53.184 +/* Version */
  53.185 +#define EV_NONE		0		/* Invalid */
  53.186 +#define EV_CURRENT	1		/* Current */
  53.187 +#define EV_NUM		2		/* number of versions */
  53.188 +
  53.189 +/* Section Header */
  53.190 +typedef struct {
  53.191 +	Elf32_Word	sh_name;	/* name - index into section header
  53.192 +					   string table section */
  53.193 +	Elf32_Word	sh_type;	/* type */
  53.194 +	Elf32_Word	sh_flags;	/* flags */
  53.195 +	Elf32_Addr	sh_addr;	/* address */
  53.196 +	Elf32_Off	sh_offset;	/* file offset */
  53.197 +	Elf32_Word	sh_size;	/* section size */
  53.198 +	Elf32_Word	sh_link;	/* section header table index link */
  53.199 +	Elf32_Word	sh_info;	/* extra information */
  53.200 +	Elf32_Word	sh_addralign;	/* address alignment */
  53.201 +	Elf32_Word	sh_entsize;	/* section entry size */
  53.202 +} Elf32_Shdr;
  53.203 +
  53.204 +typedef struct {
  53.205 +	Elf64_Half	sh_name;	/* section name */
  53.206 +	Elf64_Half	sh_type;	/* section type */
  53.207 +	Elf64_Xword	sh_flags;	/* section flags */
  53.208 +	Elf64_Addr	sh_addr;	/* virtual address */
  53.209 +	Elf64_Off	sh_offset;	/* file offset */
  53.210 +	Elf64_Xword	sh_size;	/* section size */
  53.211 +	Elf64_Half	sh_link;	/* link to another */
  53.212 +	Elf64_Half	sh_info;	/* misc info */
  53.213 +	Elf64_Xword	sh_addralign;	/* memory alignment */
  53.214 +	Elf64_Xword	sh_entsize;	/* table entry size */
  53.215 +} Elf64_Shdr;
  53.216 +
  53.217 +/* Special Section Indexes */
  53.218 +#define SHN_UNDEF	0		/* undefined */
  53.219 +#define SHN_LORESERVE	0xff00		/* lower bounds of reserved indexes */
  53.220 +#define SHN_LOPROC	0xff00		/* reserved range for processor */
  53.221 +#define SHN_HIPROC	0xff1f		/*   specific section indexes */
  53.222 +#define SHN_ABS		0xfff1		/* absolute value */
  53.223 +#define SHN_COMMON	0xfff2		/* common symbol */
  53.224 +#define SHN_HIRESERVE	0xffff		/* upper bounds of reserved indexes */
  53.225 +
  53.226 +/* sh_type */
  53.227 +#define SHT_NULL	0		/* inactive */
  53.228 +#define SHT_PROGBITS	1		/* program defined information */
  53.229 +#define SHT_SYMTAB	2		/* symbol table section */
  53.230 +#define SHT_STRTAB	3		/* string table section */
  53.231 +#define SHT_RELA	4		/* relocation section with addends*/
  53.232 +#define SHT_HASH	5		/* symbol hash table section */
  53.233 +#define SHT_DYNAMIC	6		/* dynamic section */
  53.234 +#define SHT_NOTE	7		/* note section */
  53.235 +#define SHT_NOBITS	8		/* no space section */
  53.236 +#define SHT_REL		9		/* relation section without addends */
  53.237 +#define SHT_SHLIB	10		/* reserved - purpose unknown */
  53.238 +#define SHT_DYNSYM	11		/* dynamic symbol table section */
  53.239 +#define SHT_NUM		12		/* number of section types */
  53.240 +#define SHT_LOPROC	0x70000000	/* reserved range for processor */
  53.241 +#define SHT_HIPROC	0x7fffffff	/*  specific section header types */
  53.242 +#define SHT_LOUSER	0x80000000	/* reserved range for application */
  53.243 +#define SHT_HIUSER	0xffffffff	/*  specific indexes */
  53.244 +
  53.245 +/* Section names */
  53.246 +#define ELF_BSS         ".bss"		/* uninitialized data */
  53.247 +#define ELF_DATA        ".data"		/* initialized data */
  53.248 +#define ELF_DEBUG       ".debug"	/* debug */
  53.249 +#define ELF_DYNAMIC     ".dynamic"	/* dynamic linking information */
  53.250 +#define ELF_DYNSTR      ".dynstr"	/* dynamic string table */
  53.251 +#define ELF_DYNSYM      ".dynsym"	/* dynamic symbol table */
  53.252 +#define ELF_FINI        ".fini"		/* termination code */
  53.253 +#define ELF_GOT         ".got"		/* global offset table */
  53.254 +#define ELF_HASH        ".hash"		/* symbol hash table */
  53.255 +#define ELF_INIT        ".init"		/* initialization code */
  53.256 +#define ELF_REL_DATA    ".rel.data"	/* relocation data */
  53.257 +#define ELF_REL_FINI    ".rel.fini"	/* relocation termination code */
  53.258 +#define ELF_REL_INIT    ".rel.init"	/* relocation initialization code */
  53.259 +#define ELF_REL_DYN     ".rel.dyn"	/* relocaltion dynamic link info */
  53.260 +#define ELF_REL_RODATA  ".rel.rodata"	/* relocation read-only data */
  53.261 +#define ELF_REL_TEXT    ".rel.text"	/* relocation code */
  53.262 +#define ELF_RODATA      ".rodata"	/* read-only data */
  53.263 +#define ELF_SHSTRTAB    ".shstrtab"	/* section header string table */
  53.264 +#define ELF_STRTAB      ".strtab"	/* string table */
  53.265 +#define ELF_SYMTAB      ".symtab"	/* symbol table */
  53.266 +#define ELF_TEXT        ".text"		/* code */
  53.267 +
  53.268 +
  53.269 +/* Section Attribute Flags - sh_flags */
  53.270 +#define SHF_WRITE	0x1		/* Writable */
  53.271 +#define SHF_ALLOC	0x2		/* occupies memory */
  53.272 +#define SHF_EXECINSTR	0x4		/* executable */
  53.273 +#define SHF_MASKPROC	0xf0000000	/* reserved bits for processor */
  53.274 +					/*  specific section attributes */
  53.275 +
  53.276 +/* Symbol Table Entry */
  53.277 +typedef struct elf32_sym {
  53.278 +	Elf32_Word	st_name;	/* name - index into string table */
  53.279 +	Elf32_Addr	st_value;	/* symbol value */
  53.280 +	Elf32_Word	st_size;	/* symbol size */
  53.281 +	unsigned char	st_info;	/* type and binding */
  53.282 +	unsigned char	st_other;	/* 0 - no defined meaning */
  53.283 +	Elf32_Half	st_shndx;	/* section header index */
  53.284 +} Elf32_Sym;
  53.285 +
  53.286 +typedef struct {
  53.287 +	Elf64_Half	st_name;	/* Symbol name index in str table */
  53.288 +	Elf_Byte	st_info;	/* type / binding attrs */
  53.289 +	Elf_Byte	st_other;	/* unused */
  53.290 +	Elf64_Quarter	st_shndx;	/* section index of symbol */
  53.291 +	Elf64_Xword	st_value;	/* value of symbol */
  53.292 +	Elf64_Xword	st_size;	/* size of symbol */
  53.293 +} Elf64_Sym;
  53.294 +
  53.295 +/* Symbol table index */
  53.296 +#define STN_UNDEF	0		/* undefined */
  53.297 +
  53.298 +/* Extract symbol info - st_info */
  53.299 +#define ELF32_ST_BIND(x)	((x) >> 4)
  53.300 +#define ELF32_ST_TYPE(x)	(((unsigned int) x) & 0xf)
  53.301 +#define ELF32_ST_INFO(b,t)	(((b) << 4) + ((t) & 0xf))
  53.302 +
  53.303 +#define ELF64_ST_BIND(x)	((x) >> 4)
  53.304 +#define ELF64_ST_TYPE(x)	(((unsigned int) x) & 0xf)
  53.305 +#define ELF64_ST_INFO(b,t)	(((b) << 4) + ((t) & 0xf))
  53.306 +
  53.307 +/* Symbol Binding - ELF32_ST_BIND - st_info */
  53.308 +#define STB_LOCAL	0		/* Local symbol */
  53.309 +#define STB_GLOBAL	1		/* Global symbol */
  53.310 +#define STB_WEAK	2		/* like global - lower precedence */
  53.311 +#define STB_NUM		3		/* number of symbol bindings */
  53.312 +#define STB_LOPROC	13		/* reserved range for processor */
  53.313 +#define STB_HIPROC	15		/*  specific symbol bindings */