├── Config ├── Makefile ├── installer ├── 150_easy_install.lua ├── 200_install.lua ├── 300_rescueconfig.lua ├── 350_resetpassword.lua ├── 400_configure.lua ├── 500_create_geom_mirror.lua ├── 950_reboot.lua ├── Makefile ├── conf │ └── BSDInstaller.lua ├── configure │ ├── 100_choose_where_from.lua │ ├── 200_select_disk.lua │ ├── 300_select_part.lua │ ├── 400_mount_target_system.lua │ ├── 450_init_configuration.lua │ ├── 500_menu.lua │ ├── 550_write_configuration.lua │ ├── 600_unmount_target_system.lua │ ├── main.lua │ └── menu │ │ ├── 100_set_root_password.lua │ │ ├── 200_add_user.lua │ │ ├── 300_set_timezone.lua │ │ ├── 350_set_datetime.lua │ │ ├── 400_change_console_settings.lua │ │ └── main.lua ├── easy_install │ ├── 200_select_disk.lua │ ├── 210_select_mode.lua │ ├── 220_format_disk.lua │ ├── 250_partition_disk.lua │ ├── 270_install_bootblocks.lua │ ├── 300_select_part.lua │ ├── 400_select_subparts.lua │ ├── 407_create_subparts.lua │ ├── 500_install_os.lua │ ├── 599_after_installation_tasks.lua │ ├── 900_reboot.lua │ └── main.lua ├── install │ ├── 100_welcome.lua │ ├── 200_select_disk.lua │ ├── 220_format_disk.lua │ ├── 250_partition_disk.lua │ ├── 270_install_bootblocks.lua │ ├── 300_select_part.lua │ ├── 400_select_subparts.lua │ ├── 407_create_subparts.lua │ ├── 500_install_os.lua │ ├── 599_after_installation_tasks.lua │ ├── 900_reboot.lua │ └── main.lua ├── lib │ ├── bitwise.lua │ ├── cmdchain.lua │ ├── configvars.lua │ ├── flow.lua │ ├── menu.lua │ ├── storage.lua │ ├── storage_ui.lua │ ├── target_system.lua │ ├── target_system_ui.lua │ └── uinav.lua ├── main.lua └── pit │ ├── 050_welcome.lua │ ├── 150_configure_console.lua │ └── main.lua ├── lib ├── Makefile ├── libaura │ ├── Makefile │ ├── README │ ├── buffer.c │ ├── buffer.h │ ├── dict.c │ ├── dict.h │ ├── fspred.c │ ├── fspred.h │ ├── mem.c │ ├── mem.h │ ├── popen.c │ ├── popen.h │ └── test.c ├── libdfui │ ├── Makefile │ ├── README │ ├── conn_caps.c │ ├── conn_caps.h │ ├── conn_npipe.c │ ├── conn_npipe.h │ ├── conn_tcp.c │ ├── conn_tcp.h │ ├── connection.c │ ├── decode.c │ ├── dfui.h │ ├── dump.c │ ├── dump.h │ ├── encode.c │ ├── encoding.h │ ├── form.c │ ├── lang.c │ ├── lang.h │ ├── system.c │ └── system.h └── lua │ ├── Makefile │ ├── README │ ├── app │ ├── Makefile │ └── app.lua │ ├── compat-5.1 │ ├── Makefile │ ├── compat-5.1.c │ ├── compat-5.1.h │ ├── compat-5.1.lua │ └── lua50c51.sh │ ├── dfui │ ├── Makefile │ ├── common.c │ ├── dfui.c │ ├── dfui.lua │ ├── lua_dfui.h │ └── progress.c │ ├── filename │ ├── Makefile │ └── filename.lua │ ├── lcurses │ ├── Makefile │ ├── curses.lua │ ├── lcurses.c │ ├── lpanel.c │ └── test.lua │ ├── luasocket │ ├── INSTALL │ ├── LICENSE │ ├── Makefile │ ├── NEW │ ├── README │ ├── auxiliar.c │ ├── auxiliar.h │ ├── buffer.c │ ├── buffer.h │ ├── except.c │ ├── except.h │ ├── inet.c │ ├── inet.h │ ├── io.c │ ├── io.h │ ├── lua │ │ ├── README │ │ ├── ftp.lua │ │ ├── http.lua │ │ ├── ltn12.lua │ │ ├── mime.lua │ │ ├── smtp.lua │ │ ├── socket.lua │ │ ├── tp.lua │ │ └── url.lua │ ├── luasocket.c │ ├── luasocket.h │ ├── mime.c │ ├── mime.h │ ├── options.c │ ├── options.h │ ├── select.c │ ├── select.h │ ├── socket.h │ ├── tcp.c │ ├── tcp.h │ ├── timeout.c │ ├── timeout.h │ ├── udp.c │ ├── udp.h │ ├── usocket.c │ ├── usocket.h │ ├── wsocket.c │ └── wsocket.h │ ├── posix │ ├── Makefile │ ├── README │ ├── lposix.c │ ├── modemuncher.c │ └── posix.lua │ ├── pty │ ├── Makefile │ ├── pty.c │ └── pty.lua │ └── transceiver │ ├── Makefile │ └── transceiver.lua ├── lua ├── COPYRIGHT ├── DIFFS ├── HISTORY ├── INSTALL ├── MANIFEST ├── Makefile ├── README ├── UPDATE ├── build ├── config ├── configure ├── include │ ├── lauxlib.h │ ├── lua.h │ └── lualib.h └── src │ ├── Makefile │ ├── README │ ├── lapi.c │ ├── lapi.h │ ├── lcode.c │ ├── lcode.h │ ├── ldebug.c │ ├── ldebug.h │ ├── ldo.c │ ├── ldo.h │ ├── ldump.c │ ├── lfunc.c │ ├── lfunc.h │ ├── lgc.c │ ├── lgc.h │ ├── lib │ ├── Makefile │ ├── README │ ├── lauxlib.c │ ├── lbaselib.c │ ├── ldblib.c │ ├── liolib.c │ ├── lmathlib.c │ ├── loadlib.c │ ├── lstrlib.c │ └── ltablib.c │ ├── llex.c │ ├── llex.h │ ├── llimits.h │ ├── lmem.c │ ├── lmem.h │ ├── lobject.c │ ├── lobject.h │ ├── lopcodes.c │ ├── lopcodes.h │ ├── lparser.c │ ├── lparser.h │ ├── lstate.c │ ├── lstate.h │ ├── lstring.c │ ├── lstring.h │ ├── ltable.c │ ├── ltable.h │ ├── ltests.c │ ├── ltm.c │ ├── ltm.h │ ├── lua │ ├── Makefile │ ├── README │ └── lua.c │ ├── luac │ ├── Makefile │ ├── README │ ├── luac.c │ └── print.c │ ├── lundump.c │ ├── lundump.h │ ├── lvm.c │ ├── lvm.h │ ├── lzio.c │ └── lzio.h └── ncurses ├── Makefile ├── curses_bar.c ├── curses_bar.h ├── curses_form.c ├── curses_form.h ├── curses_util.c ├── curses_util.h ├── curses_widget.c ├── curses_widget.h ├── curses_xlat.c ├── curses_xlat.h ├── fred.txt ├── hourglass.txt ├── main.c └── puffy.txt /Config: -------------------------------------------------------------------------------- 1 | # 2 | # Global configuration file for BSD Installer Makefiles. 3 | # $Id: Config,v 1.7 2005/08/29 20:49:36 cpressey Exp $ 4 | # 5 | 6 | # This file should be included by all other Makefiles in the following way: 7 | # BASE?= ../.. 8 | # include ${BASE}/Config 9 | 10 | # 11 | # First, load in Lua configuration. This file can override any settings 12 | # in that file; see the comments in that file for settings that you might 13 | # want to tweak in here. 14 | # 15 | include ${BASE}/lua/config 16 | 17 | # 18 | # Locations/names of build tools. 19 | # 20 | CC?=cc 21 | AR?=ar 22 | RANLIB?=ranlib 23 | STRIP?=strip 24 | RM?=rm 25 | LN?=ln 26 | 27 | # 28 | # Standard warning flags. 29 | # 30 | WARNS= -W -Wstrict-prototypes -Wmissing-prototypes \ 31 | -Wpointer-arith -Wno-uninitialized -Wreturn-type -Wcast-qual \ 32 | -Wswitch -Wshadow -Wcast-align -Wchar-subscripts \ 33 | -Winline -Wnested-externs -Wredundant-decls 34 | 35 | # 36 | # For shared libraries 37 | # 38 | ANAME= lib${LIB}.a 39 | SONAME= lib${LIB}.so.${LIB_VER} 40 | SOLINK= lib${LIB}.so 41 | #DLLIB= -ldl # for Lua, uncomment on systems that need it 42 | 43 | # 44 | # For 'make distribution' 45 | # 46 | DESTDIR?=/usr/local 47 | 48 | # 49 | # For systems that don't support strlcpy: 50 | # 51 | #CFLAGS+=-Dstrlcpy=strncpy 52 | 53 | # 54 | # For systems that don't define (or even support) __unused: 55 | # 56 | #CFLAGS+=-D__unused="__attribute__((__unused__))" 57 | #CFLAGS+=-D__unused='' 58 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | SUBDIR= lua lib ncurses installer 2 | 3 | upgrade: 4 | .for DIR in ${SUBDIR} 5 | @${MAKE} -C ${DIR} all 6 | .endfor 7 | .for DIR in ${SUBDIR} 8 | @${MAKE} -C ${DIR} install 9 | .endfor 10 | .for DIR in ${SUBDIR} 11 | @${MAKE} -C ${DIR} clean 12 | .endfor 13 | 14 | test: 15 | -killall lua50 16 | lua50c51 /usr/local/share/dfuibe_lua/main.lua \ 17 | /usr/local/share/dfuibe_lua/conf/BSDInstaller.lua 18 | 19 | .include 20 | -------------------------------------------------------------------------------- /installer/150_easy_install.lua: -------------------------------------------------------------------------------- 1 | -- $Id: 800_easy_install.lua,v 1.3 2005/04/12 13:28:31 den Exp $ 2 | 3 | return { 4 | id = "set_up_easy_install", 5 | name = _("Guided installation"), 6 | short_desc = _("Invoke Installer with minimal questions"), 7 | effect = function() 8 | App.descend("easy_install") 9 | return Menu.CONTINUE 10 | end 11 | } 12 | 13 | -------------------------------------------------------------------------------- /installer/200_install.lua: -------------------------------------------------------------------------------- 1 | -- $Id: 200_install.lua,v 1.12 2005/08/30 00:39:05 cpressey Exp $ 2 | 3 | -- 4 | -- Menu.Item scriptlet that generates the install menu item. 5 | -- 6 | 7 | return { 8 | id = "install_os", 9 | name = _("Manual installation"), 10 | short_desc = _("Perform a custom installation of %s on this computer system", 11 | App.conf.product.name), 12 | effect = function() 13 | -- 14 | -- Make a recording of the install session. 15 | -- XXX this might make more sense elsewhere, like as 16 | -- Flow.Steps during the install itself? 17 | -- 18 | CmdChain.record_to(App.expand("${tmp}install-session.sh")) 19 | App.descend("install") 20 | CmdChain.stop_recording() 21 | 22 | return Menu.CONTINUE 23 | end 24 | } 25 | -------------------------------------------------------------------------------- /installer/300_rescueconfig.lua: -------------------------------------------------------------------------------- 1 | -- 2 | -- Copyright (c) 2009 Scott Ullrich 3 | -- Copyright (c) 2014-2018 Franco Fichtner 4 | -- All rights reserved. 5 | -- 6 | -- Redistribution and use in source and binary forms, with or without 7 | -- modification, are permitted provided that the following conditions 8 | -- are met: 9 | -- 10 | -- 1. Redistributions of source code must retain the above copyright 11 | -- notices, this list of conditions and the following disclaimer. 12 | -- 2. Redistributions in binary form must reproduce the above copyright 13 | -- notices, this list of conditions, and the following disclaimer in 14 | -- the documentation and/or other materials provided with the 15 | -- distribution. 16 | -- 3. Neither the names of the copyright holders nor the names of their 17 | -- contributors may be used to endorse or promote products derived 18 | -- from this software without specific prior written permission. 19 | -- 20 | -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | -- ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES INCLUDING, BUT NOT 22 | -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 | -- FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 | -- COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 | -- INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26 | -- BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 27 | -- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | -- CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 | -- LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 30 | -- ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | -- POSSIBILITY OF SUCH DAMAGE. 32 | -- 33 | 34 | local POSIX = require("posix") 35 | 36 | return { 37 | id = "rescue_config", 38 | name = _("Import configuration"), 39 | req_state = { "configure" }, 40 | short_desc = _("Import the previous configuration from hard disk"), 41 | effect = function() 42 | local dd = StorageUI.select_disk({ 43 | sd = App.state.storage, 44 | zfs = true, 45 | short_desc = _( 46 | "This tool will help you import the configuration of " .. 47 | "a previous hard disk installation including backups.\n\n" .. 48 | "Please select a disk to continue:"), 49 | cancel_desc = _("Cancel") 50 | }) 51 | 52 | if not dd then 53 | return Menu.CONTINUE 54 | end 55 | 56 | local disk1 = dd:get_name() 57 | 58 | if not disk1 then 59 | return Menu.CONTINUE 60 | end 61 | 62 | local cmds = CmdChain.new() 63 | 64 | cmds:add("${root}${OPNSENSE_IMPORTER} " .. disk1); 65 | 66 | if not cmds:execute() then 67 | App.ui:inform(_("The configuration import was aborted internally.")) 68 | return Menu.CONTINUE 69 | end 70 | 71 | App.ui:inform(_( 72 | "The configuration has been sucessfully restored. You " .. 73 | "may now choose to continue the installation or bring " .. 74 | "up a live system by exiting this installer." 75 | )) 76 | 77 | return Menu.CONTINUE 78 | 79 | end 80 | } 81 | -------------------------------------------------------------------------------- /installer/400_configure.lua: -------------------------------------------------------------------------------- 1 | -- $Id: 400_configure.lua,v 1.7 2005/08/26 04:25:24 cpressey Exp $ 2 | 3 | return { 4 | id = "configure_installed_system", 5 | name = _("Configure an Installed System"), 6 | short_desc = _("Configure an existing %s installation", 7 | App.conf.product.name), 8 | effect = function() 9 | -- 10 | -- If there is currently a target system mounted, 11 | -- unmount it before starting. 12 | -- 13 | if App.state.target ~= nil and App.state.target:is_mounted() then 14 | if not App.state.target:unmount() then 15 | App.ui:inform( 16 | _("Warning: already-mounted target system could " .. 17 | "not be correctly unmounted first.") 18 | ) 19 | return step:prev() 20 | end 21 | end 22 | 23 | App.descend("configure") 24 | return Menu.CONTINUE 25 | end 26 | } 27 | -------------------------------------------------------------------------------- /installer/950_reboot.lua: -------------------------------------------------------------------------------- 1 | -- $Id: 950_reboot.lua,v 1.2 2005/08/13 18:46:09 cpressey Exp $ 2 | 3 | return { 4 | id = "reboot", 5 | name = _("Reboot"), 6 | short_desc = _("Reboot this computer"), 7 | effect = function() 8 | if TargetSystemUI.ask_reboot{ 9 | cancel_desc = _("Return to Select Task") -- XXX this_menu_name 10 | } then 11 | App.state.do_reboot = true 12 | local cmds = CmdChain.new() 13 | cmds:add("/usr/bin/touch /tmp/install_complete") 14 | cmds:execute() 15 | return nil 16 | else 17 | return Menu.CONTINUE 18 | end 19 | end 20 | } 21 | -------------------------------------------------------------------------------- /installer/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for dfuibe_lua. 2 | # $Id: Makefile,v 1.55 2005/08/27 08:04:49 cpressey Exp $ 3 | 4 | BASE?=.. 5 | .include "${BASE}/Config" 6 | 7 | all: 8 | clean: 9 | 10 | install: 11 | mkdir -p ${DESTDIR}${PREFIX}/share/dfuibe_lua 12 | cp *.lua ${DESTDIR}${PREFIX}/share/dfuibe_lua/ 13 | for _subdir in lib conf easy_install pit install configure configure/menu; do \ 14 | mkdir -p ${DESTDIR}${PREFIX}/share/dfuibe_lua/$${_subdir}; \ 15 | cp $${_subdir}/*.lua ${DESTDIR}${PREFIX}/share/dfuibe_lua/$${_subdir}; \ 16 | done 17 | 18 | .PHONY: install 19 | -------------------------------------------------------------------------------- /installer/configure/100_choose_where_from.lua: -------------------------------------------------------------------------------- 1 | -- $Id: 100_choose_where_from.lua,v 1.16 2005/08/30 00:39:05 cpressey Exp $ 2 | 3 | -- 4 | -- Allow the user to select which system to configure. 5 | -- 6 | 7 | return { 8 | id = "choose_target_system", 9 | name = _("Choose Target System"), 10 | effect = function(step) 11 | -- 12 | -- If the user has already selected a TargetSystem (e.g. they are 13 | -- coming here directly from the end of an install,) skip ahead. 14 | -- 15 | if App.state.target ~= nil then 16 | return step:next() 17 | end 18 | 19 | -- 20 | -- Ask the user where to configure. 21 | -- 22 | local action_id = App.ui:present({ 23 | id = "choose_target_system", 24 | name = _("Choose Target System"), 25 | short_desc = _( 26 | "Please choose which installed system you want to configure." 27 | ), 28 | actions = { 29 | { 30 | id = "this", 31 | name = _("Configure the Running System") 32 | }, 33 | { 34 | id = "disk", 35 | name = _("Configure a System on Disk") 36 | }, 37 | { 38 | id = "cancel", 39 | accelerator = "ESC", 40 | name = _("Return to %s", step:get_prev_name()), 41 | } 42 | }, 43 | role = "menu" 44 | }).action_id 45 | 46 | if action_id == "cancel" then 47 | return step:prev() 48 | elseif action_id == "disk" then 49 | return step:next() 50 | else -- "this" 51 | App.state.target = App.state.source 52 | -- Jump straight to the menu. 53 | return "configuration_menu" 54 | end 55 | end 56 | } 57 | -------------------------------------------------------------------------------- /installer/configure/200_select_disk.lua: -------------------------------------------------------------------------------- 1 | -- $Id: 200_select_disk.lua,v 1.15 2005/08/26 04:25:24 cpressey Exp $ 2 | 3 | -- 4 | -- Allow the user to select the disk where the OS installation 5 | -- they want to configure resides. 6 | -- 7 | 8 | return { 9 | id = "select_disk", 10 | name = _("Select Disk"), 11 | req_state = { "storage" }, 12 | effect = function(step) 13 | -- 14 | -- If the user has already selected a TargetSystem (e.g. they are 15 | -- coming here directly from the end of an install,) skip ahead. 16 | -- 17 | if App.state.target ~= nil then 18 | return step:next() 19 | end 20 | 21 | -- 22 | -- Allow the user to select a disk. 23 | -- 24 | App.state.sel_disk = nil 25 | App.state.sel_part = nil 26 | 27 | -- XXX there might be a better place to handle this. 28 | if App.state.storage:get_disk_count() == 0 then 29 | App.ui:inform(_( 30 | "The installer could not find any suitable disks " .. 31 | "attached to this computer. If you wish to " .. 32 | "configure an installation of %s " .. 33 | "on an unorthodox storage device, you will have to " .. 34 | "exit to a %s command prompt and configure it " .. 35 | "manually, using the file /README as a guide.", 36 | App.conf.product.name, App.conf.media_name) 37 | ) 38 | return nil 39 | end 40 | 41 | local dd = StorageUI.select_disk({ 42 | sd = App.state.storage, 43 | short_desc = _( 44 | "Select the disk on which the installation of %s " .. 45 | "that you wish to configure resides.", 46 | App.conf.product.name), 47 | cancel_desc = _("Return to %s", step:get_prev_name()) 48 | }) 49 | 50 | if dd then 51 | App.state.sel_disk = dd 52 | return step:next() 53 | else 54 | return step:prev() 55 | end 56 | end 57 | } 58 | -------------------------------------------------------------------------------- /installer/configure/300_select_part.lua: -------------------------------------------------------------------------------- 1 | -- $Id: 300_select_part.lua,v 1.13 2005/08/26 04:25:24 cpressey Exp $ 2 | 3 | -- 4 | -- Allow the user to select the BIOS partition where the OS 5 | -- they want to configure resides. 6 | -- 7 | 8 | return { 9 | id = "select_part", 10 | name = _("Select Partition"), 11 | req_state = { "storage", "sel_disk" }, 12 | effect = function(step) 13 | -- 14 | -- If the user has already selected a TargetSystem (e.g. they are 15 | -- coming here directly from the end of an install,) skip ahead. 16 | -- 17 | if App.state.target ~= nil then 18 | return step:next() 19 | end 20 | 21 | -- 22 | -- Allow the user to select a partition. 23 | -- 24 | App.state.sel_part = nil 25 | local pd = StorageUI.select_part({ 26 | dd = App.state.sel_disk, 27 | short_desc = _( 28 | "Select the primary partition of %s " .. 29 | "on which the installation of %s resides.", 30 | App.state.sel_disk:get_name(), 31 | App.conf.product.name), 32 | cancel_desc = _("Return to %s", step:get_prev_name()) 33 | }) 34 | 35 | if pd then 36 | if pd:is_mounted() then 37 | App.ui:inform(_( 38 | "One or more subpartitions on the selected " .. 39 | "primary partition already in use (they are " .. 40 | "currently mounted in the filesystem.) " .. 41 | "You should unmount them before proceeding." 42 | )) 43 | return step 44 | end 45 | 46 | App.state.sel_part = pd 47 | return step:next() 48 | else 49 | return step:prev() 50 | end 51 | end 52 | } 53 | -------------------------------------------------------------------------------- /installer/configure/400_mount_target_system.lua: -------------------------------------------------------------------------------- 1 | -- $Id: 400_mount_target_system.lua,v 1.22 2005/08/04 22:00:40 cpressey Exp $ 2 | 3 | -- 4 | -- Mount the chosen system as the target system for configuration. 5 | -- 6 | 7 | return { 8 | id = "mount_target_system", 9 | name = _("Mount Target System"), 10 | interactive = false, 11 | req_state = { "storage", "sel_disk", "sel_part" }, 12 | effect = function(step) 13 | -- 14 | -- If the user has already mounted a TargetSystem (e.g. they are 15 | -- coming here directly from the end of an install,) skip ahead. 16 | -- 17 | if App.state.target ~= nil and App.state.target:is_mounted() then 18 | return step:next() 19 | end 20 | 21 | App.state.target = TargetSystem.new{ 22 | partition = App.state.sel_part, 23 | base = "mnt" 24 | } 25 | local ok, errmsg = App.state.target:probe() 26 | if not ok then 27 | App.log(errmsg) 28 | App.ui:inform(_( 29 | "The target system could not be successfully probed:\n\n%s", 30 | errmsg 31 | )) 32 | App.state.target = nil 33 | return step:prev() 34 | end 35 | local ok, errmsg = App.state.target:mount() 36 | if not ok then 37 | App.log(errmsg) 38 | App.ui:inform(_( 39 | "The target system could not be successfully mounted:\n\n%s", 40 | errmsg 41 | )) 42 | App.state.target = nil 43 | return step:prev() 44 | end 45 | 46 | return step:next() 47 | end 48 | } 49 | -------------------------------------------------------------------------------- /installer/configure/450_init_configuration.lua: -------------------------------------------------------------------------------- 1 | -- $Id: 450_init_configuration.lua,v 1.1 2005/07/12 21:15:05 cpressey Exp $ 2 | 3 | -- 4 | -- Initialize the configuration variables. 5 | -- 6 | 7 | return { 8 | id = "init_configuation", 9 | name = _("Initialize Configuration"), 10 | interactive = false, 11 | req_state = { "storage", "sel_disk", "sel_part" }, 12 | effect = function(step) 13 | 14 | App.state.rc_conf = ConfigVars.new() 15 | 16 | return step:next() 17 | end 18 | } 19 | -------------------------------------------------------------------------------- /installer/configure/500_menu.lua: -------------------------------------------------------------------------------- 1 | -- $Id: 500_menu.lua,v 1.8 2005/07/08 21:24:09 cpressey Exp $ 2 | 3 | -- 4 | -- Display the configuration menu. 5 | -- 6 | 7 | return { 8 | id = "configuration_menu", 9 | name = _("Configuration Menu"), 10 | req_state = { "target" }, 11 | effect = function(step) 12 | App.descend("menu") 13 | return step:next() 14 | end 15 | } 16 | -------------------------------------------------------------------------------- /installer/configure/550_write_configuration.lua: -------------------------------------------------------------------------------- 1 | -- $Id: 550_write_configuration.lua,v 1.4 2005/08/01 20:29:59 cpressey Exp $ 2 | 3 | -- 4 | -- Write the configuration variables out to the files they belong in. 5 | -- XXX non-interactive for now, but could easily be turned into an 6 | -- interactive "are you sure you wish to write these settings?" in the future. 7 | -- 8 | 9 | return { 10 | id = "write_configuration", 11 | name = _("Write Configuration"), 12 | interactive = false, 13 | req_state = { "storage", "sel_disk", "sel_part", "target", "rc_conf" }, 14 | effect = function(step) 15 | local cmds = CmdChain.new() 16 | 17 | App.state.rc_conf:cmds_write(cmds, App.expand("${root}${base}etc/rc.conf", { 18 | base = App.state.target:get_base() 19 | }), "sh") 20 | 21 | if not cmds:execute() then 22 | App.ui:inform(_( 23 | "Couldn't write changes to configuration files for some reason." 24 | )) 25 | end 26 | 27 | return step:next() 28 | end 29 | } 30 | -------------------------------------------------------------------------------- /installer/configure/600_unmount_target_system.lua: -------------------------------------------------------------------------------- 1 | -- $Id: 600_unmount_target_system.lua,v 1.9 2005/07/13 04:32:22 cpressey Exp $ 2 | 3 | -- 4 | -- Unmount the target system once we are done with it. 5 | -- 6 | 7 | return { 8 | id = "unmount_target_system", 9 | name = _("Unmount Target System"), 10 | interactive = false, 11 | req_state = { "target" }, 12 | effect = function(step) 13 | if App.state.target:unmount() then 14 | App.state.target = nil 15 | return step:next() 16 | else 17 | App.ui:inform( 18 | _("Target system could not be unmounted!") 19 | ) 20 | return nil 21 | end 22 | end 23 | } 24 | -------------------------------------------------------------------------------- /installer/configure/main.lua: -------------------------------------------------------------------------------- 1 | -- configure/main.lua 2 | -- $Id: main.lua,v 1.13 2005/07/08 21:24:09 cpressey Exp $ 3 | 4 | -- 5 | -- Flow drive for Configuration Flow. 6 | -- 7 | 8 | Flow.new{ 9 | id = "configure", 10 | name = _("Configure an Installed System"), 11 | }:populate("."):run() 12 | -------------------------------------------------------------------------------- /installer/configure/menu/100_set_root_password.lua: -------------------------------------------------------------------------------- 1 | -- $Id: 100_set_root_password.lua,v 1.10 2005/08/04 22:00:40 cpressey Exp $ 2 | 3 | return { 4 | id = "set_root_password", 5 | name = _("Set Root Password"), 6 | effect = function() 7 | TargetSystemUI.set_root_password(App.state.target) 8 | return Menu.CONTINUE 9 | end 10 | } 11 | -------------------------------------------------------------------------------- /installer/configure/menu/200_add_user.lua: -------------------------------------------------------------------------------- 1 | -- $Id: 200_add_user.lua,v 1.12 2005/08/04 22:00:40 cpressey Exp $ 2 | 3 | return { 4 | id = "add_user", 5 | name = _("Add User"), 6 | effect = function() 7 | TargetSystemUI.add_user(App.state.target) 8 | return Menu.CONTINUE 9 | end 10 | } 11 | -------------------------------------------------------------------------------- /installer/configure/menu/300_set_timezone.lua: -------------------------------------------------------------------------------- 1 | -- $Id: 300_set_timezone.lua,v 1.7 2005/06/16 01:07:30 cpressey Exp $ 2 | 3 | local set_timezone = function() 4 | local cmds, files, dir, filename, full_filename, found_file 5 | 6 | if App.ui:present({ 7 | id = "internal_clock_type", 8 | name = _("Local or UTC (Greenwich Mean Time) clock"), 9 | short_desc = _( 10 | "Is this machine's internal clock set to local time " .. 11 | "or UTC (Universal Coordinated Time, roughly the same " .. 12 | "as Greenwich Mean Time)?\n\n" .. 13 | "If you don't know, assume local time for now." 14 | ), 15 | 16 | actions = { 17 | { 18 | id = "local", 19 | name = _("Local Time") 20 | }, 21 | { 22 | id = "utc", 23 | name = _("UTC Time") 24 | } 25 | } 26 | }).action_id == "utc" then 27 | cmds = CmdChain.new() 28 | 29 | cmds:add({ 30 | cmdline = "${root}${TOUCH} ${root}${base}etc/wall_cmos_clock", 31 | replacements = { 32 | base = App.state.target:get_base() 33 | } 34 | }) 35 | cmds:execute() 36 | end 37 | 38 | -- 39 | -- Select a file. 40 | -- 41 | dir = App.expand("${root}${base}usr/share/zoneinfo", 42 | { 43 | base = App.state.target:get_base() 44 | } 45 | ) 46 | local orig_dir = dir 47 | 48 | found_file = false 49 | while not found_file do 50 | filename = App.ui:select_file{ 51 | title = _("Select Time Zone"), 52 | short_desc = _("Select a Time Zone appropriate to your physical location."), 53 | cancel_desc = _("Return to Utilities Menu"), 54 | dir = dir, 55 | predicate = function(filename) 56 | if filename == "." then return false end 57 | if dir == orig_dir and filename == ".." then return false end 58 | return true 59 | end 60 | } 61 | if filename == "cancel" then 62 | return false 63 | end 64 | if filename == ".." then 65 | local found, len 66 | found, len, full_filename = string.find(dir, "^(.*)/.-$") 67 | else 68 | full_filename = dir .. "/" .. filename 69 | end 70 | if FileName.is_dir(full_filename) then 71 | dir = full_filename 72 | else 73 | filename = full_filename 74 | found_file = true 75 | end 76 | end 77 | 78 | cmds = CmdChain.new() 79 | cmds:add({ 80 | cmdline = "${root}${CP} ${filename} ${root}${base}etc/localtime", 81 | replacements = { 82 | filename = filename, 83 | base = App.state.target:get_base() 84 | } 85 | }) 86 | if cmds:execute() then 87 | App.ui:inform(_( 88 | "The Time Zone has been successfully set to %s.", 89 | filename 90 | )) 91 | end 92 | end 93 | 94 | return { 95 | id = "set timezone", 96 | name = _("Set Timezone"), 97 | effect = function() 98 | set_timezone() 99 | return Menu.CONTINUE 100 | end 101 | } 102 | -------------------------------------------------------------------------------- /installer/configure/menu/350_set_datetime.lua: -------------------------------------------------------------------------------- 1 | -- $Id: 350_set_datetime.lua,v 1.5 2005/06/18 00:52:07 cpressey Exp $ 2 | 3 | local set_datetime = function() 4 | local cmds, date_tab, form, response 5 | 6 | date_tab = os.date("*t") 7 | 8 | form = { 9 | id = "set_datetime", 10 | name = _("Set Time and Date"), 11 | short_desc = _( 12 | "Enter the current date and time of day to set " .. 13 | "this computer's internal timekeeping clock." 14 | ), 15 | 16 | fields = { 17 | { 18 | id = "year", 19 | name = _("Year"), 20 | short_desc = _("Enter the current year (e.g. `2004')") 21 | }, 22 | { 23 | id = "month", 24 | name = _("Month"), 25 | short_desc = _("Enter the current month (e.g. `07')") 26 | }, 27 | { 28 | id = "day", 29 | name = _("Day"), 30 | short_desc = _("Enter the current day of month (e.g. `30')") 31 | }, 32 | { 33 | id = "hour", 34 | name = _("Hour"), 35 | short_desc = _("Enter the current hour (e.g. `07')") 36 | }, 37 | { 38 | id = "min", 39 | name = _("Minute"), 40 | short_desc = _("Enter the current minute (e.g. `59')") 41 | } 42 | }, 43 | 44 | datasets = { 45 | { 46 | year = tostring(date_tab.year), 47 | month = tostring(date_tab.month), 48 | day = tostring(date_tab.day), 49 | hour = tostring(date_tab.hour), 50 | min = tostring(date_tab.min) 51 | } 52 | }, 53 | 54 | actions = { 55 | { 56 | id = "ok", 57 | name = _("OK") 58 | }, 59 | { 60 | id = "cancel", 61 | accelerator = "ESC", 62 | name = _("Cancel") 63 | } 64 | } 65 | } 66 | 67 | while not done do 68 | response = App.ui:present(form) 69 | if response.action_id ~= "ok" then 70 | return false 71 | end 72 | 73 | date_tab = { 74 | year = tonumber(response.datasets[1].year), 75 | month = tonumber(response.datasets[1].month), 76 | day = tonumber(response.datasets[1].day), 77 | hour = tonumber(response.datasets[1].hour), 78 | min = tonumber(response.datasets[1].min) 79 | } 80 | 81 | -- 82 | -- Validate the given date and time. 83 | -- 84 | 85 | if date_tab.year > 0 and 86 | date_tab.month >= 1 and date_tab.month <= 12 and 87 | date_tab.day >= 1 and date_tab.day <= 31 and 88 | date_tab.hour >= 0 and date_tab.hour <= 23 and 89 | date_tab.min >= 0 and date_tab.min <= 59 then 90 | 91 | cmds = CmdChain.new() 92 | cmds:add("${root}${DATE} -n " .. string.format( 93 | "%04d%02d%02d%02d%02d", 94 | date_tab.year, 95 | date_tab.month, 96 | date_tab.day, 97 | date_tab.hour, 98 | date_tab.min 99 | )) 100 | if cmds:execute() then 101 | App.ui:inform(_( 102 | "The time and date have successfully been set." 103 | )) 104 | done = true 105 | else 106 | App.ui:inform(_( 107 | "An error occurred while attempting to set " .. 108 | "time and date." 109 | )) 110 | end 111 | else 112 | App.ui:inform(_( 113 | "Please enter numbers within acceptable ranges " .. 114 | "for year, month, day of month, hour, and minute." 115 | )) 116 | end 117 | end 118 | 119 | return true 120 | end 121 | 122 | return { 123 | id = "set_datetime", 124 | name = _("Set Time and Date"), 125 | effect = function() 126 | set_datetime() 127 | return Menu.CONTINUE 128 | end 129 | } 130 | -------------------------------------------------------------------------------- /installer/configure/menu/400_change_console_settings.lua: -------------------------------------------------------------------------------- 1 | -- $Id: 400_change_console_settings.lua,v 1.8 2005/08/04 22:00:40 cpressey Exp $ 2 | 3 | return { 4 | id = "change_console_settings", 5 | name = _("Change Console Settings"), 6 | effect = function() 7 | TargetSystemUI.configure_console{ 8 | ts = App.state.target, 9 | allow_cancel = true, 10 | cancel_desc = _("Return to Configure Menu") 11 | } 12 | return Menu.CONTINUE 13 | end 14 | } 15 | -------------------------------------------------------------------------------- /installer/configure/menu/main.lua: -------------------------------------------------------------------------------- 1 | -- $Id: main.lua,v 1.6 2005/04/22 04:57:07 cpressey Exp $ 2 | 3 | Menu.new{ 4 | id = "configure", 5 | name = _("Select Component to Configure"), 6 | short_desc = _("Choose one of the following things to configure."), 7 | }:populate("."):loop() 8 | -------------------------------------------------------------------------------- /installer/easy_install/200_select_disk.lua: -------------------------------------------------------------------------------- 1 | -- $Id: 200_select_disk.lua,v 1.34 2005/08/26 04:25:24 cpressey Exp $ 2 | 3 | -- 4 | -- Select disk onto which to install. 5 | -- 6 | 7 | return { 8 | id = "select_disk", 9 | name = _("Select Disk"), 10 | req_state = { "storage" }, 11 | effect = function(step) 12 | App.state.sel_disk = nil 13 | App.state.sel_part = nil 14 | 15 | local memory_cur = App.state.storage:measure_memory() 16 | 17 | -- hard cap is a little bit lower than printed minimum 18 | if memory_cur < 975 then 19 | App.ui:warn(_( 20 | "The installer detected only %s MB of RAM. Since " .. 21 | "this is a LiveCD-like image, copying the full " .. 22 | "file system to another disk requires at least " .. 23 | "1024 MB of RAM and is generally advised for " .. 24 | "proper operation of %s afterwards, too.\n\nIf your " .. 25 | "target disk is greater than 30 GB feel free to " .. 26 | "ignore this, otherwise adjust your RAM " .. 27 | "accordingly to prevent the installation from " .. 28 | "failing.", 29 | memory_cur, App.conf.product.name) 30 | ) 31 | end 32 | 33 | if App.state.storage:get_disk_count() == 0 then 34 | App.ui:inform(_( 35 | "The installer could not find any disks suitable " .. 36 | "for installation (IDE or SCSI) attached to this " .. 37 | "computer. If you wish to install %s" .. 38 | " on an unorthodox storage device, you will have to " .. 39 | "exit to a %s command prompt and install it " .. 40 | "manually, using the file /README as a guide.", 41 | App.conf.product.name, App.conf.media_name) 42 | ) 43 | return nil 44 | end 45 | 46 | local dd = StorageUI.select_disk{ 47 | sd = App.state.storage, 48 | short_desc = _( 49 | "This will automatically install %s with all current " .. 50 | "settings without asking many questions.\n\n" .. 51 | "WARNING: All contents of the selected hard disk will be erased! " .. 52 | "This action is irreversible.\n\n" .. 53 | "Please select a disk to continue:", 54 | App.conf.product.name), 55 | cancel_desc = _("Return to %s", step:get_prev_name()) 56 | } 57 | 58 | if dd then 59 | App.state.sel_disk = dd 60 | 61 | local disk_min_capacity = Storage.Capacity.new( 62 | App.conf.limits.part_min 63 | ) 64 | if disk_min_capacity:exceeds(dd:get_capacity()) then 65 | App.ui:inform(_( 66 | "WARNING: the disk\n\n%s\n\nappears to have a capacity " .. 67 | "of %s, which is less than the absolute minimum " .. 68 | "recommended capacity, %s. You may encounter " .. 69 | "problems while trying to install %s.", 70 | dd:get_name(), 71 | dd:get_capacity():format(), 72 | disk_min_capacity:format(), 73 | App.conf.product.name) 74 | ) 75 | end 76 | 77 | return step:next() 78 | else 79 | return nil 80 | end 81 | end 82 | } 83 | -------------------------------------------------------------------------------- /installer/easy_install/210_select_mode.lua: -------------------------------------------------------------------------------- 1 | -- 2 | -- Select disk install mode. 3 | -- 4 | 5 | return { 6 | id = "select_mode", 7 | name = _("Select install mode"), 8 | req_state = { "storage" }, 9 | effect = function(step) 10 | if App.state.sel_disk:is_mounted() then 11 | local response = App.ui:present{ 12 | id = "partition_disk", 13 | name = _("Partition Disk?"), 14 | short_desc = _( 15 | "One or more subpartitions of one or more " .. 16 | "primary partitions of the selected disk " .. 17 | "are already in use (they are currently " .. 18 | "mounted on mountpoints in the filesystem.) " .. 19 | "You cannot repartition the disk under " .. 20 | "these circumstances. If you wish to do so, " .. 21 | "you must unmount the subpartitions before " .. 22 | "proceeding." 23 | ), 24 | actions = { 25 | { 26 | id = "unmount", 27 | name = _("Unmount Subpartitions"), 28 | effect = function() 29 | local cmds = CmdChain.new() 30 | App.state.sel_disk:cmds_unmount_all_under(cmds) 31 | if not cmds:execute() then 32 | return nil 33 | end 34 | return step 35 | end 36 | }, 37 | { 38 | id = "cancel", 39 | name = _("Return to %s", step:get_prev_name()), 40 | accelerator = "ESC", 41 | effect = function() 42 | return step:prev() 43 | end 44 | } 45 | } 46 | } 47 | return response.result 48 | end 49 | 50 | local mode = 0 51 | 52 | local cmd = App.expand("uname -m") 53 | local pty = Pty.Logged.open(cmd, App.log_string) 54 | local line = pty:readline() 55 | pty:close() 56 | 57 | -- UEFI only works on amd64 58 | if string.find(line, "^amd64") then 59 | mode = StorageUI.select_mode({ 60 | dd = App.state.sel_disk, 61 | cancel_desc = _("Return to %s", step:get_prev_name()) 62 | }) 63 | end 64 | 65 | if mode then 66 | return step:next() 67 | else 68 | return step:prev() 69 | end 70 | end 71 | } 72 | -------------------------------------------------------------------------------- /installer/easy_install/220_format_disk.lua: -------------------------------------------------------------------------------- 1 | -- $Id: 220_format_disk.lua,v 1.15 2006/02/03 22:54:13 sullrich Exp $ 2 | 3 | -- 4 | -- Allow the user to format the selected disk, if they so desire. 5 | -- 6 | 7 | -- 8 | -- Utility function which asks the user what geometry they'd like to use. 9 | -- 10 | local select_geometry = function(step, dd) 11 | if dd:is_geometry_bios_friendly() then 12 | local c_cyl, c_head, c_sec = dd:get_geometry() 13 | else 14 | local c_cyl, c_head, c_sec = dd:get_normalized_geometry() 15 | end 16 | 17 | dd:set_geometry(c_cyl, c_head, c_sec) 18 | 19 | return true 20 | end 21 | 22 | -- 23 | -- Utility function which confirms that the user would like to proceed, 24 | -- and actually executes the formatting commands. 25 | -- 26 | local format_disk = function(step, dd) 27 | local cmds = CmdChain.new() 28 | 29 | if not select_geometry(step, dd) then 30 | return false 31 | end 32 | 33 | local cmdsGPT = CmdChain.new() 34 | local disk = dd:get_name() 35 | cmdsGPT:set_replacements{ 36 | disk = disk 37 | } 38 | cmdsGPT:add("${root}${GPART} destroy -F ${disk} || true"); 39 | if not cmdsGPT:execute() then 40 | return false 41 | end 42 | 43 | dd:cmds_format(cmds) 44 | 45 | if not cmds:execute() then 46 | App.ui:inform(_( 47 | "The disk\n\n%s\n\nwas " .. 48 | "not correctly formatted, and may " .. 49 | "now be in an inconsistent state. " .. 50 | "We recommend trying to format it again " .. 51 | "before attempting to install " .. 52 | "%s on it.", 53 | dd:get_desc(), App.conf.product.name 54 | )) 55 | return false 56 | end 57 | 58 | -- 59 | -- The extents of the Storage.System have probably 60 | -- changed, so refresh our knowledge of it. 61 | -- 62 | local result 63 | result, App.state.sel_disk, App.state.sel_part, dd = 64 | StorageUI.refresh_storage( 65 | App.state.sel_disk, App.state.sel_part, dd 66 | ) 67 | if not result then 68 | return false 69 | end 70 | 71 | -- 72 | -- Mark the disk as having been 'touched' 73 | -- (modified destructively, i.e. partitioned) by us. 74 | -- This should prevent us from asking for further 75 | -- confirmation for changes we might do to it in 76 | -- the future. 77 | -- 78 | dd:touch() 79 | 80 | return true 81 | end 82 | 83 | return { 84 | id = "format_disk", 85 | name = _("Format Disk"), 86 | req_state = { "storage", "sel_disk" }, 87 | effect = function(step) 88 | print("\nFormatting disk...") 89 | 90 | if format_disk(step, App.state.sel_disk) then 91 | App.state.sel_part = 92 | App.state.sel_disk:get_part_by_number(1) 93 | return step:next() 94 | else 95 | return nil 96 | end 97 | end 98 | } 99 | -------------------------------------------------------------------------------- /installer/easy_install/270_install_bootblocks.lua: -------------------------------------------------------------------------------- 1 | -- 2 | -- Install bootblocks on the disks that the user selects. 3 | -- 4 | 5 | return { 6 | id = "install_bootblocks", 7 | name = _("Install Bootblocks"), 8 | req_state = { "storage" }, 9 | effect = function(step) 10 | local datasets_list = {} 11 | local dd 12 | local disk_ref = {} -- map from raw name to ref to Storage.Disk 13 | 14 | for dd in App.state.storage:get_disks() do 15 | local raw_name = dd:get_raw_device_name() 16 | 17 | disk_ref[raw_name] = dd 18 | 19 | -- 20 | -- Only install to selected disk 21 | -- 22 | if App.state.sel_disk == dd then 23 | local dataset = { 24 | disk = raw_name, 25 | boot0cfg = "Y", 26 | packet = "N" 27 | } 28 | -- 29 | -- For disks larger than 8 gigabytes in size, 30 | -- enable "packet mode" booting by default. 31 | -- 32 | if dd:get_capacity():in_units("G") >= 8 then 33 | dataset.packet = "Y" 34 | end 35 | if raw_name == App.state.sel_disk:get_name() then 36 | table.insert(datasets_list, dataset) 37 | end 38 | end 39 | end 40 | 41 | local cmds = CmdChain.new() 42 | local i, dataset 43 | 44 | for i, dataset in ipairs(datasets_list) do 45 | if dataset.boot0cfg == "Y" then 46 | dd = disk_ref[dataset.disk] 47 | dd:cmds_install_bootblock(cmds, 48 | (dataset.packet == "Y")) 49 | disk = dd:get_name() 50 | cmds:set_replacements{ 51 | disk = disk 52 | } 53 | -- XXX this doesn't belong here... 54 | if dd:set_uefi() == 0 then 55 | cmds:add("${root}${BOOT0CFG} -B -b /boot/boot0 /dev/${disk}") 56 | end 57 | end 58 | end 59 | 60 | if not cmds:execute() then 61 | return nil 62 | end 63 | 64 | return step:next() 65 | end 66 | } 67 | -------------------------------------------------------------------------------- /installer/easy_install/300_select_part.lua: -------------------------------------------------------------------------------- 1 | -- $Id: 300_select_part.lua,v 1.37 2005/08/26 04:25:24 cpressey Exp $ 2 | 3 | -- 4 | -- Select partition onto which to install. 5 | -- 6 | 7 | return { 8 | id = "select_part", 9 | name = _("Select Partition"), 10 | req_state = { "storage", "sel_disk" }, 11 | effect = function(step) 12 | pd = App.state.sel_part 13 | 14 | if pd then 15 | if pd:is_mounted() then 16 | App.ui:inform(_( 17 | "One or more subpartitions on the selected " .. 18 | "primary partition already in use (they are " .. 19 | "currently mounted in the filesystem.) " .. 20 | "You should either unmount them before " .. 21 | "proceeding, or select a different partition " .. 22 | "or disk on which to install %s.", 23 | App.conf.product.name 24 | )) 25 | return nil 26 | end 27 | 28 | if pd:get_activated_swap():in_units("K") > 0 then 29 | local response = App.ui:present{ 30 | name = _("Cannot swapoff; reboot?"), 31 | short_desc = _( 32 | "Some subpartitions on the selected primary " .. 33 | "partition are already activated as swap. " .. 34 | "Since there is no way to deactivate swap in " .. 35 | "%s once it is activated, in order " .. 36 | "to edit the subpartition layout of this " .. 37 | "primary partition, you must first reboot.", 38 | App.conf.product.name 39 | ), 40 | actions = { 41 | { 42 | id = "reboot", 43 | name = _("Reboot"), 44 | effect = function() return "reboot" end 45 | }, 46 | { 47 | id = "cancel", 48 | name = _("Return to %s", step:get_prev_name()), 49 | accelerator = "ESC", 50 | effect = function() return nil end 51 | } 52 | } 53 | } 54 | return response.result 55 | end 56 | 57 | App.state.sel_part = pd 58 | 59 | local part_min_capacity = Storage.Capacity.new( 60 | App.conf.limits.part_min 61 | ) 62 | if part_min_capacity:exceeds(pd:get_capacity()) then 63 | App.ui:inform(_( 64 | "WARNING: primary partition #%d appears to have " .. 65 | "a capacity of %s, which is less than the minimum " .. 66 | "recommended capacity, %s. You may encounter " .. 67 | "problems while trying to install %s onto it.", 68 | pd:get_number(), 69 | pd:get_capacity():format(), 70 | part_min_capacity:format(), 71 | App.conf.product.name) 72 | ) 73 | end 74 | 75 | local cmds = CmdChain.new() 76 | 77 | pd:cmds_set_sysid(cmds, App.conf.default_sysid) 78 | pd:cmds_initialize_disklabel(cmds) 79 | 80 | if cmds:execute() then 81 | return step:next() 82 | else 83 | return nil 84 | end 85 | else 86 | return nil 87 | end 88 | end 89 | } 90 | -------------------------------------------------------------------------------- /installer/easy_install/407_create_subparts.lua: -------------------------------------------------------------------------------- 1 | -- $Id: 407_create_subparts.lua,v 1.3 2005/08/27 19:42:10 cpressey Exp $ 2 | 3 | return { 4 | id = "create_subparts", 5 | name = _("Create Subpartitions"), 6 | req_state = { "sel_disk", "sel_part" }, 7 | interactive = false, 8 | effect = function(step) 9 | local cmds = CmdChain.new() 10 | 11 | App.state.sel_part:cmds_disklabel(cmds) 12 | App.state.sel_part:cmds_install_bootstrap(cmds) 13 | App.state.sel_part:cmds_initialize_filesystems(cmds) 14 | 15 | if not cmds:execute() then 16 | App.ui:inform(_( 17 | "The subpartitions you have chosen were " .. 18 | "not correctly created, and the " .. 19 | "primary partition may now be in an " .. 20 | "inconsistent state. We recommend " .. 21 | "re-formatting it before proceeding." 22 | )) 23 | return nil 24 | end 25 | 26 | return step:next() 27 | end 28 | } 29 | -------------------------------------------------------------------------------- /installer/easy_install/599_after_installation_tasks.lua: -------------------------------------------------------------------------------- 1 | -- 2 | -- This file cleans up after a normal install. 3 | -- 4 | 5 | return { 6 | id = "after_install_routines", 7 | name = _("Post-installation tasks"), 8 | effect = function(step) 9 | local cmds = CmdChain.new() 10 | 11 | -- Execute post-install scripts 12 | App.state.target:cmds_post_install(cmds) 13 | 14 | -- Remove currently active swap used for installation 15 | if App.state.storage:get_activated_swap():in_units("K") > 0 then 16 | local spd 17 | 18 | for spd in App.state.sel_part:get_subparts() do 19 | if spd:get_fstype() == "swap" then 20 | local dev = spd:get_device_name() 21 | if App.state.sel_part:set_uefi() == 1 then 22 | -- only one partition matches 23 | dev = App.state.sel_part:get_parent():get_device_name() .. "p4" 24 | end 25 | -- swap may or may not be mounted 26 | cmds:add("${root}${SWAPOFF} ${root}dev/" .. dev .. " || true"); 27 | end 28 | end 29 | end 30 | 31 | if not cmds:execute() then 32 | return nil 33 | end 34 | 35 | -- Force a password change 36 | TargetSystemUI.set_root_password(App.state.target) 37 | 38 | local cmds2 = CmdChain.new() 39 | 40 | -- Run the necessary cleanups 41 | App.state.target:cmds_post_cleanup(cmds2) 42 | 43 | if not cmds2:execute() then 44 | return nil 45 | end 46 | 47 | return step:next() 48 | end 49 | } 50 | -------------------------------------------------------------------------------- /installer/easy_install/900_reboot.lua: -------------------------------------------------------------------------------- 1 | -- $Id: 900_reboot.lua,v 1.15 2005/08/13 18:46:09 cpressey Exp $ 2 | 3 | -- 4 | -- Reboot the system, so that the user can test booting from 5 | -- their newly-installed system. 6 | -- 7 | 8 | return { 9 | id = "reboot", 10 | name = _("Reboot"), 11 | effect = function(step) 12 | App.state.do_reboot = TargetSystemUI.ask_reboot{ 13 | cancel_desc = _("Return to %s", step:get_upper_name()) 14 | } 15 | return nil 16 | end 17 | } 18 | -------------------------------------------------------------------------------- /installer/easy_install/main.lua: -------------------------------------------------------------------------------- 1 | -- install/main.lua 2 | -- $Id: main.lua,v 1.12 2005/07/08 20:18:20 cpressey Exp $ 3 | 4 | -- 5 | -- Flow driver for Install Flow. 6 | -- 7 | 8 | Flow.new{ 9 | id = "install", 10 | name = _("Install OS") 11 | }:populate("."):run() 12 | -------------------------------------------------------------------------------- /installer/install/100_welcome.lua: -------------------------------------------------------------------------------- 1 | -- $Id: 100_welcome.lua,v 1.14 2005/08/26 04:25:24 cpressey Exp $ 2 | 3 | -- 4 | -- Show welcome information. 5 | -- 6 | 7 | return { 8 | id = "welcome", 9 | name = _("Welcome"), 10 | effect = function(step) 11 | return App.ui:present({ 12 | id = "begin_install", 13 | name = _("Begin Installation"), 14 | short_desc = _( 15 | "This experimental application will install %s" .. 16 | " on one of the hard disk drives attached to this computer. " .. 17 | "It has been designed to make it easy to install " .. 18 | "%s in the typical case. " .. 19 | "If you have special requirements that are not addressed " .. 20 | "by this installer, or if you have problems using it, you " .. 21 | "are welcome to install %s manually. " .. 22 | "\n\n" .. 23 | "NOTE! As with any installation process, YOU ARE " .. 24 | "STRONGLY ENCOURAGED TO BACK UP ANY IMPORTANT DATA ON THIS " .. 25 | "COMPUTER BEFORE PROCEEDING!", 26 | App.conf.product.name, App.conf.product.name, App.conf.product.name), 27 | long_desc = _( 28 | "Some situations in which you might not wish to use this " .. 29 | "installer are:\n\n" .. 30 | "- you want to install %s onto a " .. 31 | "logical/extended partition;\n" .. 32 | "- you want to install %s " .. 33 | "onto a ``dangerously dedicated'' disk; or\n" .. 34 | "- you want full and utter control over the install process.", 35 | App.conf.product.name, App.conf.product.name), 36 | 37 | actions = { 38 | { 39 | id = "proceed", 40 | name = _("Install %s", App.conf.product.name), 41 | effect = function() 42 | return step:next() 43 | end 44 | }, 45 | { 46 | id = "cancel", 47 | name = _("Return to %s", step:get_prev_name()), 48 | accelerator = "ESC", 49 | effect = function() 50 | return nil 51 | end 52 | } 53 | } 54 | }).result 55 | end 56 | } 57 | -------------------------------------------------------------------------------- /installer/install/200_select_disk.lua: -------------------------------------------------------------------------------- 1 | -- $Id: 200_select_disk.lua,v 1.34 2005/08/26 04:25:24 cpressey Exp $ 2 | 3 | -- 4 | -- Select disk onto which to install. 5 | -- 6 | 7 | return { 8 | id = "select_disk", 9 | name = _("Select Disk"), 10 | req_state = { "storage" }, 11 | effect = function(step) 12 | App.state.sel_disk = nil 13 | App.state.sel_part = nil 14 | 15 | local memory_cur = App.state.storage:measure_memory() 16 | 17 | -- hard cap is a little bit lower than printed minimum 18 | if memory_cur < 975 then 19 | App.ui:warn(_( 20 | "The installer detected only %s MB of RAM. Since " .. 21 | "this is a LiveCD-like image, copying the full " .. 22 | "file system to another disk requires at least " .. 23 | "1024 MB of RAM and is generally advised for " .. 24 | "proper operation of %s afterwards, too.\n\nIf your " .. 25 | "target disk is greater than 30 GB feel free to " .. 26 | "ignore this, otherwise adjust your RAM " .. 27 | "accordingly to prevent the installation from " .. 28 | "failing.", 29 | memory_cur, App.conf.product.name) 30 | ) 31 | end 32 | 33 | if App.state.storage:get_disk_count() == 0 then 34 | App.ui:inform(_( 35 | "The installer could not find any disks suitable " .. 36 | "for installation (IDE or SCSI) attached to this " .. 37 | "computer. If you wish to install %s" .. 38 | " on an unorthodox storage device, you will have to " .. 39 | "exit to a %s command prompt and install it " .. 40 | "manually, using the file /README as a guide.", 41 | App.conf.product.name, App.conf.media_name) 42 | ) 43 | return nil 44 | end 45 | 46 | local dd = StorageUI.select_disk{ 47 | sd = App.state.storage, 48 | short_desc = _("Select a disk on which to install %s.", 49 | App.conf.product.name), 50 | cancel_desc = _("Return to %s", step:get_prev_name()) 51 | } 52 | 53 | if dd then 54 | App.state.sel_disk = dd 55 | 56 | local disk_min_capacity = Storage.Capacity.new( 57 | App.conf.limits.part_min 58 | ) 59 | if disk_min_capacity:exceeds(dd:get_capacity()) then 60 | App.ui:inform(_( 61 | "WARNING: the disk\n\n%s\n\nappears to have a capacity " .. 62 | "of %s, which is less than the absolute minimum " .. 63 | "recommended capacity, %s. You may encounter " .. 64 | "problems while trying to install %s.", 65 | dd:get_name(), 66 | dd:get_capacity():format(), 67 | disk_min_capacity:format(), 68 | App.conf.product.name) 69 | ) 70 | end 71 | 72 | return step:next() 73 | else 74 | return step:prev() 75 | end 76 | end 77 | } 78 | -------------------------------------------------------------------------------- /installer/install/407_create_subparts.lua: -------------------------------------------------------------------------------- 1 | -- $Id: 407_create_subparts.lua,v 1.3 2005/08/27 19:42:10 cpressey Exp $ 2 | 3 | return { 4 | id = "create_subparts", 5 | name = _("Create Subpartitions"), 6 | req_state = { "sel_disk", "sel_part" }, 7 | interactive = false, 8 | effect = function(step) 9 | local cmds = CmdChain.new() 10 | 11 | App.state.sel_part:cmds_disklabel(cmds) 12 | App.state.sel_part:cmds_install_bootstrap(cmds) 13 | App.state.sel_part:cmds_initialize_filesystems(cmds) 14 | 15 | if not cmds:execute() then 16 | App.ui:inform(_( 17 | "The subpartitions you have chosen were " .. 18 | "not correctly created, and the " .. 19 | "primary partition may now be in an " .. 20 | "inconsistent state. We recommend " .. 21 | "re-formatting it before proceeding." 22 | )) 23 | return step:prev() 24 | end 25 | 26 | return step:next() 27 | end 28 | } 29 | -------------------------------------------------------------------------------- /installer/install/599_after_installation_tasks.lua: -------------------------------------------------------------------------------- 1 | -- 2 | -- This file cleans up after a normal install. 3 | -- 4 | 5 | return { 6 | id = "after_install_routines", 7 | name = _("Post-installation tasks"), 8 | effect = function(step) 9 | local cmds = CmdChain.new() 10 | 11 | -- Execute post-install scripts 12 | App.state.target:cmds_post_install(cmds) 13 | 14 | -- Remove currently active swap used for installation 15 | if App.state.storage:get_activated_swap():in_units("K") > 0 then 16 | local spd 17 | 18 | for spd in App.state.sel_part:get_subparts() do 19 | if spd:get_fstype() == "swap" then 20 | cmds:add{ 21 | cmdline = "${root}${SWAPOFF} ${root}dev/${dev}", 22 | replacements = { 23 | dev = spd:get_device_name() 24 | } 25 | } 26 | end 27 | end 28 | end 29 | 30 | cmds:execute() 31 | 32 | -- Force a password change 33 | TargetSystemUI.set_root_password(App.state.target) 34 | 35 | local cmds2 = CmdChain.new() 36 | 37 | -- Run the necessary cleanups 38 | App.state.target:cmds_post_cleanup(cmds2) 39 | 40 | cmds2:execute() 41 | 42 | return step:next() 43 | end 44 | } 45 | -------------------------------------------------------------------------------- /installer/install/900_reboot.lua: -------------------------------------------------------------------------------- 1 | -- $Id: 900_reboot.lua,v 1.15 2005/08/13 18:46:09 cpressey Exp $ 2 | 3 | -- 4 | -- Reboot the system, so that the user can test booting from 5 | -- their newly-installed system. 6 | -- 7 | 8 | return { 9 | id = "reboot", 10 | name = _("Reboot"), 11 | effect = function(step) 12 | App.state.do_reboot = TargetSystemUI.ask_reboot{ 13 | cancel_desc = _("Return to %s", step:get_upper_name()) 14 | } 15 | return nil 16 | end 17 | } 18 | -------------------------------------------------------------------------------- /installer/install/main.lua: -------------------------------------------------------------------------------- 1 | -- install/main.lua 2 | -- $Id: main.lua,v 1.12 2005/07/08 20:18:20 cpressey Exp $ 3 | 4 | -- 5 | -- Flow driver for Install Flow. 6 | -- 7 | 8 | Flow.new{ 9 | id = "install", 10 | name = _("Install OS") 11 | }:populate("."):run() 12 | -------------------------------------------------------------------------------- /installer/lib/bitwise.lua: -------------------------------------------------------------------------------- 1 | -- $Id: Bitwise.lua,v 1.4 2005/07/23 19:26:26 cpressey Exp $ 2 | -- Package for (pure-Lua portable but extremely slow) bitwise arithmetic. 3 | 4 | -- 5 | -- Copyright (c)2005 Chris Pressey. All rights reserved. 6 | -- 7 | -- Redistribution and use in source and binary forms, with or without 8 | -- modification, are permitted provided that the following conditions 9 | -- are met: 10 | -- 11 | -- 1. Redistributions of source code must retain the above copyright 12 | -- notices, this list of conditions and the following disclaimer. 13 | -- 2. Redistributions in binary form must reproduce the above copyright 14 | -- notices, this list of conditions, and the following disclaimer in 15 | -- the documentation and/or other materials provided with the 16 | -- distribution. 17 | -- 3. Neither the names of the copyright holders nor the names of their 18 | -- contributors may be used to endorse or promote products derived 19 | -- from this software without specific prior written permission. 20 | -- 21 | -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 | -- ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES INCLUDING, BUT NOT 23 | -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 24 | -- FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 25 | -- COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 26 | -- INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 27 | -- BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28 | -- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 29 | -- CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 | -- LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 31 | -- ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | -- POSSIBILITY OF SUCH DAMAGE. 33 | -- 34 | 35 | -- BEGIN lib/bitwise.lua -- 36 | 37 | module "bitwise" 38 | 39 | --[[---------]]-- 40 | --[[ Bitwise ]]-- 41 | --[[---------]]-- 42 | 43 | local odd = function(x) 44 | return x ~= math.floor(x / 2) * 2 45 | end 46 | 47 | Bitwise = {} 48 | 49 | Bitwise.bw_and = function(a, b) 50 | local c, pow = 0, 1 51 | while a > 0 or b > 0 do 52 | if odd(a) and odd(b) then 53 | c = c + pow 54 | end 55 | a = math.floor(a / 2) 56 | b = math.floor(b / 2) 57 | pow = pow * 2 58 | end 59 | return c 60 | end 61 | 62 | Bitwise.bw_or = function(a, b) 63 | local c, pow = 0, 1 64 | while a > 0 or b > 0 do 65 | if odd(a) or odd(b) then 66 | c = c + pow 67 | end 68 | a = math.floor(a / 2) 69 | b = math.floor(b / 2) 70 | pow = pow * 2 71 | end 72 | return c 73 | end 74 | 75 | return Bitwise 76 | 77 | -- END of lib/bitwise.lua -- 78 | -------------------------------------------------------------------------------- /installer/pit/050_welcome.lua: -------------------------------------------------------------------------------- 1 | -- $Id: 050_welcome.lua,v 1.10 2005/08/26 04:25:25 cpressey Exp $ 2 | 3 | -- 4 | -- "Welcome screen" for the BSD Installer. 5 | -- 6 | 7 | return { 8 | id = "welcome", 9 | name = _("Welcome Screen"), 10 | effect = function(step) 11 | local result = App.ui:present({ 12 | id = "welcome", 13 | name = App.conf.product.name .. " " .. 14 | App.conf.product.version, 15 | short_desc = 16 | "Welcome to the " .. App.conf.product.name .. " " .. 17 | " " .. App.conf.product.version .. " installer!\n\n" .. 18 | "Before we begin, you will be asked a few questions " .. 19 | "so that this installation environment can be set up " .. 20 | "to suit your needs.\n\n" .. 21 | "You will then be presented a menu of items from which " .. 22 | "you may select to install a new system, with or " .. 23 | "without importing a previous configuration.", 24 | actions = { 25 | { 26 | id = "ok", 27 | name = _("Ok, let's go."), 28 | short_desc = _("Set up the installation environment and continue") 29 | } 30 | } 31 | }).action_id 32 | 33 | if result == "ok" then 34 | return step:next() 35 | end 36 | end 37 | } 38 | -------------------------------------------------------------------------------- /installer/pit/150_configure_console.lua: -------------------------------------------------------------------------------- 1 | -- $Id: 150_configure_console.lua,v 1.4 2005/08/04 22:00:40 cpressey Exp $ 2 | 3 | return { 4 | id = "configure_console", 5 | name = _("Configure Console"), 6 | effect = function(step) 7 | TargetSystemUI.configure_console{ 8 | ts = App.state.source, 9 | allow_cancel = false 10 | } 11 | return step:next() 12 | end 13 | } 14 | -------------------------------------------------------------------------------- /installer/pit/main.lua: -------------------------------------------------------------------------------- 1 | -- pit/main.lua 2 | -- $Id: main.lua,v 1.10 2005/04/22 04:57:07 cpressey Exp $ 3 | -- Flow for "pre-install tasks" 4 | 5 | Flow.new{ 6 | id = "pre_install_tasks", 7 | name = _("Pre-Install Tasks") 8 | }:populate("."):run() 9 | -------------------------------------------------------------------------------- /lib/Makefile: -------------------------------------------------------------------------------- 1 | SUBDIR= libaura libdfui lua 2 | 3 | .include 4 | -------------------------------------------------------------------------------- /lib/libaura/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for libaura. 2 | # $Id: Makefile,v 1.20 2005/08/26 22:44:37 cpressey Exp $ 3 | 4 | BASE?=../.. 5 | include ${BASE}/Config 6 | 7 | LIB= aura 8 | LIB_VER=3 9 | 10 | OBJS= mem.o popen.o fspred.o \ 11 | dict.o buffer.o 12 | 13 | CFLAGS+= ${WARNS} -fPIC 14 | 15 | all: ${SONAME} ${ANAME} 16 | 17 | ${SONAME}: ${OBJS} 18 | ${CC} ${OBJS} -shared ${LDFLAGS} -o ${SONAME} 19 | ln -sf ${SONAME} ${SOLINK} 20 | 21 | ${ANAME}: ${OBJS} 22 | ${AR} rc ${ANAME} ${OBJS} 23 | ${RANLIB} ${ANAME} 24 | 25 | strip: 26 | strip ${SONAME} 27 | 28 | clean: 29 | rm -rf *.o *.so *.so.? *.So *.a 30 | 31 | install: strip 32 | #mkdir -p ${DESTDIR}/lib 33 | #cp ${SONAME} ${DESTDIR}/lib/ 34 | #ln -sf ${SONAME} ${DESTDIR}/lib/${SOLINK} 35 | #cp ${ANAME} ${DESTDIR}/lib/ 36 | -------------------------------------------------------------------------------- /lib/libaura/README: -------------------------------------------------------------------------------- 1 | libaura v3.1 README 2 | =================== 3 | 4 | $Id: README,v 1.4 2005/12/22 03:40:36 cpressey Exp $ 5 | 6 | What is libaura? 7 | ---------------- 8 | 9 | libaura is a LIBrary of Assorted Useful Reusable Abstractions. Notably, 10 | it provides dictionary and extensible buffer data types, memory management 11 | functions (wrappers to malloc() and free()), and filesystem predicates 12 | (is_file(), is_dir(), etc.) 13 | 14 | What is the current state of the project? 15 | ----------------------------------------- 16 | 17 | EXPERIMENTAL. libaura's application programming interface may change at 18 | any time. libaura 3.1 is not intended to be backwards-compatible with 19 | any previous versions. If you use libaura in a project, be prepared to 20 | chase API changes. 21 | 22 | How do I build and install libaura? 23 | ----------------------------------- 24 | 25 | On a BSD-based system, go into the libaura source directory and type: 26 | 27 | make 28 | 29 | Once built, it can be installed by typing (as root): 30 | 31 | make install 32 | 33 | Directions may differ for other systems. 34 | 35 | An alternative method is to build libaura using the ports system and 36 | install it using the package system. 37 | 38 | How do I use libaura from a program? 39 | ------------------------------------ 40 | 41 | You can give gcc the following sort of command line flags to tell it to 42 | link your program with libaura: 43 | 44 | gcc foo.c -o foo -L/usr/local/lib -laura 45 | 46 | See the libaura source code for the list of available functions and what 47 | they do. 48 | -------------------------------------------------------------------------------- /lib/libaura/buffer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2004 The DragonFly Project. All rights reserved. 3 | * 4 | * This code is derived from software contributed to The DragonFly Project 5 | * by Chris Pressey . 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions 9 | * are met: 10 | * 11 | * 1. Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 3. Neither the name of The DragonFly Project nor the names of its 18 | * contributors may be used to endorse or promote products derived 19 | * from this software without specific, prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 24 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 25 | * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 26 | * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, 27 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 29 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 30 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 31 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 | * SUCH DAMAGE. 33 | */ 34 | 35 | /* 36 | * buffer.h 37 | * $Id: buffer.h,v 1.3 2005/09/01 19:23:14 cpressey Exp $ 38 | */ 39 | 40 | #ifndef __AURA_BUFFER_H_ 41 | #define __AURA_BUFFER_H_ 42 | 43 | #include 44 | 45 | #ifdef __cplusplus 46 | extern "C" { 47 | #endif 48 | 49 | struct aura_buffer { 50 | char *buf; 51 | size_t len; 52 | size_t size; 53 | size_t pos; 54 | }; 55 | 56 | struct aura_buffer *aura_buffer_new(size_t); 57 | void aura_buffer_free(struct aura_buffer *); 58 | char *aura_buffer_buf(struct aura_buffer *); 59 | size_t aura_buffer_len(struct aura_buffer *); 60 | size_t aura_buffer_size(struct aura_buffer *); 61 | 62 | void aura_buffer_ensure_size(struct aura_buffer *, size_t); 63 | void aura_buffer_set(struct aura_buffer *, const char *, size_t); 64 | void aura_buffer_append(struct aura_buffer *, const char *, size_t); 65 | 66 | void aura_buffer_cpy(struct aura_buffer *, const char *); 67 | void aura_buffer_cat(struct aura_buffer *, const char *); 68 | int aura_buffer_cat_file(struct aura_buffer *, const char *, ...); 69 | int aura_buffer_cat_pipe(struct aura_buffer *, const char *, ...); 70 | 71 | int aura_buffer_seek(struct aura_buffer *, size_t); 72 | size_t aura_buffer_tell(struct aura_buffer *); 73 | int aura_buffer_eof(struct aura_buffer *); 74 | char aura_buffer_peek_char(struct aura_buffer *); 75 | char aura_buffer_scan_char(struct aura_buffer *); 76 | int aura_buffer_compare(struct aura_buffer *, const char *); 77 | int aura_buffer_expect(struct aura_buffer *, const char *); 78 | 79 | void aura_buffer_push(struct aura_buffer *, const void *, size_t); 80 | int aura_buffer_pop(struct aura_buffer *, void *, size_t); 81 | 82 | #ifdef __cplusplus 83 | } 84 | #endif 85 | 86 | #endif /* !__AURA_BUFFER_H_ */ 87 | -------------------------------------------------------------------------------- /lib/libaura/dict.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2004 The DragonFly Project. All rights reserved. 3 | * 4 | * This code is derived from software contributed to The DragonFly Project 5 | * by Chris Pressey . 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions 9 | * are met: 10 | * 11 | * 1. Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 3. Neither the name of The DragonFly Project nor the names of its 18 | * contributors may be used to endorse or promote products derived 19 | * from this software without specific, prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 24 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 25 | * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 26 | * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, 27 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 29 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 30 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 31 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 | * SUCH DAMAGE. 33 | */ 34 | 35 | /* 36 | * dict.c 37 | * $Id: dict.h,v 1.4 2005/09/01 19:23:14 cpressey Exp $ 38 | * Routines to manipulate dictionaries. 39 | */ 40 | 41 | #ifndef __AURA_DICT_H_ 42 | #define __AURA_DICT_H_ 43 | 44 | #include 45 | 46 | #ifdef __cplusplus 47 | extern "C" { 48 | #endif 49 | 50 | #define AURA_DICT_HASH 1 51 | #define AURA_DICT_LIST 2 52 | #define AURA_DICT_SORTED_LIST 3 53 | 54 | struct aura_dict { 55 | struct aura_bucket **b; 56 | size_t num_buckets; 57 | void (*fetch)(struct aura_dict *, const void *, size_t, void **, size_t *); 58 | void (*store)(struct aura_dict *, const void *, size_t, const void *, size_t); 59 | struct aura_bucket *cursor; 60 | size_t cur_bucket; 61 | }; 62 | 63 | struct aura_bucket { 64 | struct aura_bucket *next; 65 | void *key; 66 | size_t key_size; 67 | void *data; 68 | size_t data_size; 69 | }; 70 | 71 | struct aura_dict *aura_dict_new(size_t, int); 72 | void aura_dict_free(struct aura_dict *); 73 | 74 | void aura_dict_fetch(struct aura_dict *, const void *, size_t, 75 | void **, size_t *); 76 | int aura_dict_exists(struct aura_dict *, const void *, size_t); 77 | void aura_dict_store(struct aura_dict *, const void *, size_t, 78 | const void *, size_t); 79 | 80 | void aura_dict_rewind(struct aura_dict *); 81 | int aura_dict_eof(struct aura_dict *); 82 | void aura_dict_get_current_key(struct aura_dict *, 83 | void **, size_t *); 84 | void aura_dict_next(struct aura_dict *); 85 | size_t aura_dict_size(struct aura_dict *); 86 | 87 | #ifdef __cplusplus 88 | } 89 | #endif 90 | 91 | #endif /* !__AURA_DICT_H_ */ 92 | -------------------------------------------------------------------------------- /lib/libaura/fspred.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2004 The DragonFly Project. All rights reserved. 3 | * 4 | * This code is derived from software contributed to The DragonFly Project 5 | * by Chris Pressey . 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions 9 | * are met: 10 | * 11 | * 1. Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 3. Neither the name of The DragonFly Project nor the names of its 18 | * contributors may be used to endorse or promote products derived 19 | * from this software without specific, prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 24 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 25 | * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 26 | * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, 27 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 29 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 30 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 31 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 | * SUCH DAMAGE. 33 | */ 34 | 35 | /* 36 | * $Id: fspred.h,v 1.3 2005/09/01 19:23:14 cpressey Exp $ 37 | */ 38 | 39 | #ifndef __FSPRED_H_ 40 | #define __FSPRED_H_ 41 | 42 | #ifdef __cplusplus 43 | extern "C" { 44 | #endif 45 | 46 | /*** PROTOTYPES ***/ 47 | 48 | int is_dir(const char *, ...); 49 | int is_file(const char *, ...); 50 | int is_program(const char *, ...); 51 | int is_device(const char *, ...); 52 | int is_named_pipe(const char *, ...); 53 | int is_mountpoint_mounted(const char *); 54 | int is_device_mounted(const char *); 55 | int is_any_slice_mounted(const char *); 56 | 57 | #ifdef __cplusplus 58 | } 59 | #endif 60 | 61 | #endif /* !__FSPRED_H_ */ 62 | -------------------------------------------------------------------------------- /lib/libaura/mem.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2004 The DragonFly Project. All rights reserved. 3 | * 4 | * This code is derived from software contributed to The DragonFly Project 5 | * by Chris Pressey . 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions 9 | * are met: 10 | * 11 | * 1. Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 3. Neither the name of The DragonFly Project nor the names of its 18 | * contributors may be used to endorse or promote products derived 19 | * from this software without specific, prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 24 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 25 | * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 26 | * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, 27 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 29 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 30 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 31 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 | * SUCH DAMAGE. 33 | */ 34 | 35 | /* 36 | * mem.c 37 | * $Id: mem.c,v 1.2 2005/02/06 06:57:30 cpressey Exp $ 38 | * Aura memory management functions. 39 | */ 40 | 41 | #include 42 | #include 43 | #include 44 | #include 45 | 46 | #ifdef TRACK_ALLOCATION 47 | #include 48 | #endif 49 | 50 | #include "mem.h" 51 | 52 | void * 53 | aura_malloc(size_t size, const char *what) 54 | { 55 | void *ptr; 56 | 57 | if ((ptr = malloc(size)) == NULL) { 58 | errx(EX_UNAVAILABLE, "malloc(%s) failed", what); 59 | } 60 | #ifdef TRACK_ALLOCATION 61 | fprintf(stderr, "***** malloc(%s) = %08lx\n", what, ptr); 62 | #endif 63 | bzero(ptr, size); 64 | 65 | return(ptr); 66 | } 67 | 68 | char * 69 | aura_strdup(const char *string) 70 | { 71 | char *ptr; 72 | 73 | if ((ptr = strdup(string)) == NULL) { 74 | errx(EX_UNAVAILABLE, "strdup(\"%s\") failed", string); 75 | } 76 | #ifdef TRACK_ALLOCATION 77 | fprintf(stderr, "***** strdup(\"%s\") = %08lx\n", string, ptr); 78 | #endif 79 | 80 | return(ptr); 81 | } 82 | 83 | void 84 | #ifdef TRACK_ALLOCATION 85 | aura_free(void *ptr, const char *what) 86 | #else 87 | aura_free(void *ptr, const char *what __unused) 88 | #endif 89 | { 90 | #ifdef TRACK_ALLOCATION 91 | fprintf(stderr, "***** free(%s) = %08lx\n", what, ptr); 92 | #endif 93 | free(ptr); 94 | } 95 | -------------------------------------------------------------------------------- /lib/libaura/mem.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2004 The DragonFly Project. All rights reserved. 3 | * 4 | * This code is derived from software contributed to The DragonFly Project 5 | * by Chris Pressey . 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions 9 | * are met: 10 | * 11 | * 1. Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 3. Neither the name of The DragonFly Project nor the names of its 18 | * contributors may be used to endorse or promote products derived 19 | * from this software without specific, prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 24 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 25 | * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 26 | * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, 27 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 29 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 30 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 31 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 | * SUCH DAMAGE. 33 | */ 34 | 35 | /* 36 | * mem.h 37 | * $Id: mem.h,v 1.3 2005/09/01 19:23:14 cpressey Exp $ 38 | * Aura memory management functions and macros. 39 | */ 40 | 41 | #define AURA_MALLOC(ptr, what) \ 42 | do { \ 43 | ptr = (struct what *)aura_malloc(sizeof(struct what), \ 44 | "struct " #what); \ 45 | } while(0) 46 | 47 | #define AURA_FREE(ptr, what) \ 48 | do { \ 49 | aura_free(ptr, "struct " #what); \ 50 | } while(0) 51 | 52 | #ifdef __cplusplus 53 | extern "C" { 54 | #endif 55 | 56 | void *aura_malloc(size_t, const char *); 57 | char *aura_strdup(const char *); 58 | void aura_free(void *, const char *); 59 | 60 | #ifdef __cplusplus 61 | } 62 | #endif 63 | -------------------------------------------------------------------------------- /lib/libaura/popen.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2004 The DragonFly Project. All rights reserved. 3 | * 4 | * This code is derived from software contributed to The DragonFly Project 5 | * by Chris Pressey . 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions 9 | * are met: 10 | * 11 | * 1. Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 3. Neither the name of The DragonFly Project nor the names of its 18 | * contributors may be used to endorse or promote products derived 19 | * from this software without specific, prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 24 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 25 | * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 26 | * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, 27 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 29 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 30 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 31 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 | * SUCH DAMAGE. 33 | */ 34 | 35 | /* 36 | * popen.h 37 | * $Id: popen.h,v 1.6 2005/09/01 19:23:14 cpressey Exp $ 38 | * A modified version of the standard popen()/pclose() functions 39 | * which adds a third function, pgetpid(), which allows the program 40 | * which used popen() to obtain the pid of the process on the other 41 | * end of the pipe. 42 | */ 43 | 44 | #ifndef __AURA_POPEN_H_ 45 | #define __AURA_POPEN_H_ 46 | 47 | #include 48 | 49 | #include 50 | 51 | #ifdef __cplusplus 52 | extern "C" { 53 | #endif 54 | 55 | #define AURA_PGETS_TIMEOUT 1 56 | #define AURA_PGETS_SELECT_ERR 2 57 | #define AURA_PGETS_EOF 3 58 | #define AURA_PGETS_FGETS_ERR 4 59 | 60 | FILE *aura_popen(const char *, const char *, ...); 61 | int aura_pclose(FILE *); 62 | pid_t aura_pgetpid(FILE *); 63 | int aura_pgets(FILE *, char *, size_t, long, int *); 64 | 65 | #ifdef __cplusplus 66 | } 67 | #endif 68 | 69 | #endif /* !__AURA_POPEN_H_ */ 70 | -------------------------------------------------------------------------------- /lib/libaura/test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2004 The DragonFly Project. All rights reserved. 3 | * 4 | * This code is derived from software contributed to The DragonFly Project 5 | * by Chris Pressey . 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions 9 | * are met: 10 | * 11 | * 1. Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 3. Neither the name of The DragonFly Project nor the names of its 18 | * contributors may be used to endorse or promote products derived 19 | * from this software without specific, prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 24 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 25 | * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 26 | * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, 27 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 29 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 30 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 31 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 | * SUCH DAMAGE. 33 | */ 34 | 35 | /* 36 | * test.c 37 | * Test some libaura functions. 38 | * $Id: test.c,v 1.4 2005/01/06 23:50:17 cpressey Exp $ 39 | */ 40 | 41 | #include 42 | 43 | #include "dict.h" 44 | #include "fspred.h" 45 | 46 | int main(int argc, char **argv) 47 | { 48 | struct aura_dict *d; 49 | char k[256], v[256]; 50 | void *rv, *rk; 51 | size_t rv_len, rk_len; 52 | 53 | d = aura_dict_new(1, AURA_DICT_SORTED_LIST); 54 | /* d = aura_dict_new(23, AURA_DICT_HASH); */ 55 | 56 | while (!feof(stdin)) { 57 | printf("key> "); 58 | fgets(k, 255, stdin); 59 | if (strlen(k) > 0) 60 | k[strlen(k) - 1] = '\0'; 61 | if (k[0] == '?') { 62 | printf("%s %s a file\n", &k[1], 63 | is_file("%s", &k[1]) ? "IS" : "IS NOT"); 64 | } else if (strcmp(k, "@list") == 0) { 65 | /* List all values in dictionary. */ 66 | aura_dict_rewind(d); 67 | while (!aura_dict_eof(d)) { 68 | aura_dict_get_current_key(d, &rk, &rk_len), 69 | aura_dict_fetch(d, rk, rk_len, &rv, &rv_len); 70 | printf("+ %s -> %s\n", (char *)rk, (char *)rv); 71 | aura_dict_next(d); 72 | } 73 | } else { 74 | printf("value> "); 75 | fgets(v, 255, stdin); 76 | if (strlen(v) > 0) 77 | v[strlen(v) - 1] = '\0'; 78 | aura_dict_fetch(d, k, strlen(k) + 1, &rv, &rv_len); 79 | if (rv == NULL) { 80 | printf("*NOT FOUND*\n"); 81 | } else { 82 | printf("%s -> %s\n", k, (char *)rv); 83 | } 84 | aura_dict_store(d, k, strlen(k) + 1, v, strlen(v) + 1); 85 | } 86 | } 87 | 88 | aura_dict_free(d); 89 | 90 | return(0); 91 | } 92 | -------------------------------------------------------------------------------- /lib/libdfui/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for libdfui. 2 | # $Id: Makefile,v 1.28 2005/08/26 22:44:37 cpressey Exp $ 3 | 4 | BASE?=../.. 5 | include ${BASE}/Config 6 | 7 | LIB= dfui 8 | LIB_VER=4 9 | 10 | OBJS= encode.o decode.o conn_tcp.o \ 11 | connection.o conn_caps.o conn_npipe.o \ 12 | form.o dump.o system.o lang.o 13 | 14 | CFLAGS+= ${WARNS} -fPIC -I../libaura 15 | LDFLAGS+= ../libaura/libaura.a -Wl,-soname,${SONAME} 16 | 17 | # Default target: 18 | 19 | all: ${SONAME} ${ANAME} 20 | 21 | # Main targets, shared and static: 22 | 23 | ${SONAME}: ${OBJS} 24 | ${CC} ${OBJS} -shared ${LDFLAGS} -o ${SONAME} 25 | ${LN} -sf ${SONAME} ${SOLINK} 26 | 27 | ${ANAME}: ${OBJS} 28 | ${AR} rc ${ANAME} ${OBJS} 29 | ${RANLIB} ${ANAME} 30 | 31 | strip: 32 | ${STRIP} ${SONAME} 33 | 34 | clean: 35 | rm -rf *.o *.so *.so.* *.So *.a 36 | 37 | install: strip 38 | mkdir -p ${DESTDIR}${PREFIX}/lib 39 | cp ${SONAME} ${DESTDIR}${PREFIX}/lib 40 | ln -sf ${SONAME} ${DESTDIR}${PREFIX}/lib/${SOLINK} 41 | #cp ${ANAME} ${DESTDIR}${PREFIX}/lib 42 | -------------------------------------------------------------------------------- /lib/libdfui/README: -------------------------------------------------------------------------------- 1 | libdfui v4.1 README 2 | =================== 3 | 4 | $Id: README,v 1.4 2005/12/22 03:40:36 cpressey Exp $ 5 | 6 | What is libdfui? 7 | ---------------- 8 | 9 | libdfui is a LIBrary for DragonFly User Interfaces. It provides a highly 10 | abstract user interaction interface with which an application program 11 | (termed the backend) can communicate with a user via a concreate user 12 | interface terminal program (termed the frontend.) The frontend and the 13 | backend can communicate over several kinds of transport layers (TCP, 14 | CAPS, and Named Pipes.) The protocol is abstract enough so that the 15 | frontend can occupy nearly any medium (GUI, addressable text console, 16 | teletype, voice synthesis/recognition, etc) with little to no `fudging' 17 | of the semantics (i.e. the structure and nature of the information that 18 | the backend wishes to present and/or acquire.) 19 | 20 | What is the current state of the project? 21 | ----------------------------------------- 22 | 23 | EXPERIMENTAL. libdfui's application programming interface may change at 24 | any time. If you use libdfui in a project, be prepared to chase API changes. 25 | libdfui 4.1 is not expected to be backwards-compatible with previous 26 | versions. While many functions may be the same, some have changed. 27 | 28 | How do I build and install libdfui? 29 | ----------------------------------- 30 | 31 | On a BSD-based system, go into the libdfui source directory and type: 32 | 33 | make 34 | 35 | Once built, it can be installed by typing (as root): 36 | 37 | make install 38 | 39 | Directions may differ for other systems. 40 | 41 | An alternative method is to build libdfui using the ports system and 42 | install it using the package system. 43 | 44 | How do I use libdfui from a program? 45 | ------------------------------------ 46 | 47 | libdfui requires libaura, but is not statically linked with it, so any 48 | consumers of libdfui will also need to link to libaura. 49 | 50 | You can give gcc the following sort of command line flags to tell it to 51 | link your program with libdfui: 52 | 53 | gcc foo.c -o foo -L/usr/local/lib -laura -ldfui 54 | 55 | See the libdfui source code for the list of available functions and what 56 | they do. 57 | -------------------------------------------------------------------------------- /lib/libdfui/conn_caps.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c)2004 Cat's Eye Technologies. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 11 | * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in 13 | * the documentation and/or other materials provided with the 14 | * distribution. 15 | * 16 | * Neither the name of Cat's Eye Technologies nor the names of its 17 | * contributors may be used to endorse or promote products derived 18 | * from this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 | * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 25 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 26 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 29 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 31 | * OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | /* 35 | * conn_caps.h 36 | * $Id: conn_caps.h,v 1.8 2005/09/01 19:23:14 cpressey Exp $ 37 | */ 38 | 39 | #ifndef __CONN_CAPS_H_ 40 | #define __CONN_CAPS_H_ 41 | 42 | #include "system.h" 43 | #ifdef HAS_CAPS 44 | 45 | #include 46 | 47 | #include "dfui.h" 48 | 49 | #ifdef __cplusplus 50 | extern "C" { 51 | #endif 52 | 53 | struct dfui_conn_caps { 54 | int cid; /* the caps id for the connection */ 55 | int wresult; /* result of last caps_sys_wait/get */ 56 | struct caps_msgid msgid; /* msgid of the last msg recvd */ 57 | char *buf; /* XXX last message recvd */ 58 | size_t size; /* XXX size of msg recv buffer */ 59 | }; 60 | 61 | #define T_CAPS(c) ((struct dfui_conn_caps *)c->t_data) 62 | 63 | dfui_err_t dfui_caps_be_start(struct dfui_connection *); 64 | dfui_err_t dfui_caps_be_stop(struct dfui_connection *); 65 | 66 | dfui_err_t dfui_caps_be_ll_exchange(struct dfui_connection *, 67 | char, const char *); 68 | dfui_err_t dfui_caps_be_ll_receive(struct dfui_connection *); 69 | dfui_err_t dfui_caps_be_ll_reply(struct dfui_connection *, const char *); 70 | 71 | dfui_err_t dfui_caps_fe_connect(struct dfui_connection *); 72 | dfui_err_t dfui_caps_fe_disconnect(struct dfui_connection *); 73 | 74 | dfui_err_t dfui_caps_fe_ll_request(struct dfui_connection *, char, const char *); 75 | 76 | #ifdef __cplusplus 77 | } 78 | #endif 79 | 80 | #endif /* HAS_CAPS */ 81 | #endif /* !__CONN_CAPS_H_ */ 82 | -------------------------------------------------------------------------------- /lib/libdfui/conn_npipe.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c)2004 Cat's Eye Technologies. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 11 | * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in 13 | * the documentation and/or other materials provided with the 14 | * distribution. 15 | * 16 | * Neither the name of Cat's Eye Technologies nor the names of its 17 | * contributors may be used to endorse or promote products derived 18 | * from this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 | * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 25 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 26 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 29 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 31 | * OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | /* 35 | * conn_npipe.h 36 | * $Id: conn_npipe.h,v 1.8 2005/09/01 19:23:14 cpressey Exp $ 37 | */ 38 | 39 | #ifndef __CONN_NPIPE_H_ 40 | #define __CONN_NPIPE_H_ 41 | 42 | #include "system.h" 43 | #ifdef HAS_NPIPE 44 | 45 | #ifdef __cplusplus 46 | extern "C" { 47 | #endif 48 | 49 | #include 50 | 51 | #include "dfui.h" 52 | 53 | struct dfui_conn_npipe { 54 | char *in_pipename; 55 | char *out_pipename; 56 | FILE *in; /* pipe we read from */ 57 | FILE *out; /* pipe we write to */ 58 | }; 59 | 60 | #define T_NPIPE(c) ((struct dfui_conn_npipe *)c->t_data) 61 | 62 | dfui_err_t dfui_npipe_be_start(struct dfui_connection *); 63 | dfui_err_t dfui_npipe_be_stop(struct dfui_connection *); 64 | 65 | dfui_err_t dfui_npipe_be_ll_exchange(struct dfui_connection *, 66 | char, const char *); 67 | dfui_err_t dfui_npipe_be_ll_receive(struct dfui_connection *); 68 | dfui_err_t dfui_npipe_be_ll_reply(struct dfui_connection *, const char *); 69 | 70 | dfui_err_t dfui_npipe_fe_connect(struct dfui_connection *); 71 | dfui_err_t dfui_npipe_fe_disconnect(struct dfui_connection *); 72 | 73 | dfui_err_t dfui_npipe_fe_ll_request(struct dfui_connection *, char, const char *); 74 | 75 | #ifdef __cplusplus 76 | } 77 | #endif 78 | 79 | #endif /* HAS_NPIPE */ 80 | #endif /* !__CONN_NPIPE_H_ */ 81 | -------------------------------------------------------------------------------- /lib/libdfui/conn_tcp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c)2004 Cat's Eye Technologies. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 11 | * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in 13 | * the documentation and/or other materials provided with the 14 | * distribution. 15 | * 16 | * Neither the name of Cat's Eye Technologies nor the names of its 17 | * contributors may be used to endorse or promote products derived 18 | * from this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 | * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 25 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 26 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 29 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 31 | * OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | /* 35 | * conn_tcp.h 36 | * $Id: conn_tcp.h,v 1.8 2005/09/01 19:23:14 cpressey Exp $ 37 | */ 38 | 39 | #ifndef __CONN_TCP_H_ 40 | #define __CONN_TCP_H_ 41 | 42 | #include "system.h" 43 | #ifdef HAS_TCP 44 | 45 | #ifdef __cplusplus 46 | extern "C" { 47 | #endif 48 | 49 | #include 50 | 51 | #include "dfui.h" 52 | 53 | struct dfui_conn_tcp { 54 | int listen_sd; /* listen socket descriptor (b/e) */ 55 | int connected_sd; /* connected socket descriptor */ 56 | int is_connected; /* is socket connected 0 = no */ 57 | FILE *stream; /* stream that wraps connected_sd */ 58 | }; 59 | 60 | #define T_TCP(c) ((struct dfui_conn_tcp *)c->t_data) 61 | 62 | dfui_err_t dfui_tcp_be_start(struct dfui_connection *); 63 | dfui_err_t dfui_tcp_be_stop(struct dfui_connection *); 64 | 65 | dfui_err_t dfui_tcp_be_ll_exchange(struct dfui_connection *, 66 | char msgtype, const char *); 67 | dfui_err_t dfui_tcp_be_ll_receive(struct dfui_connection *); 68 | dfui_err_t dfui_tcp_be_ll_reply(struct dfui_connection *, const char *); 69 | 70 | dfui_err_t dfui_tcp_fe_connect(struct dfui_connection *); 71 | dfui_err_t dfui_tcp_fe_disconnect(struct dfui_connection *); 72 | 73 | dfui_err_t dfui_tcp_fe_ll_request(struct dfui_connection *, char, const char *); 74 | 75 | int read_data(FILE *, char *, int); 76 | int write_data(FILE *, const char *, int); 77 | 78 | #endif /* HAS_TCP */ 79 | 80 | #ifdef __cplusplus 81 | } 82 | #endif 83 | 84 | #endif /* !__CONN_TCP_H_ */ 85 | -------------------------------------------------------------------------------- /lib/libdfui/dump.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c)2004 Cat's Eye Technologies. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 11 | * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in 13 | * the documentation and/or other materials provided with the 14 | * distribution. 15 | * 16 | * Neither the name of Cat's Eye Technologies nor the names of its 17 | * contributors may be used to endorse or promote products derived 18 | * from this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 | * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 25 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 26 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 29 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 31 | * OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | /* 35 | * dump.h 36 | * $Id: dump.h,v 1.4 2005/09/01 19:23:14 cpressey Exp $ 37 | */ 38 | 39 | #ifndef __DUMP_H_ 40 | #define __DUMP_H_ 41 | 42 | #include 43 | 44 | #include "dfui.h" 45 | 46 | #ifdef __cplusplus 47 | extern "C" { 48 | #endif 49 | 50 | extern FILE *dfui_debug_file; 51 | 52 | void dfui_info_dump(const struct dfui_info *); 53 | void dfui_option_dump(const struct dfui_option *); 54 | void dfui_form_dump(const struct dfui_form *); 55 | void dfui_response_dump(const struct dfui_response *); 56 | void dfui_dataset_dump(const struct dfui_dataset *); 57 | void dfui_celldata_dump(const struct dfui_celldata *); 58 | void dfui_action_dump(const struct dfui_action *); 59 | void dfui_field_dump(const struct dfui_field *); 60 | void dfui_progress_dump(const struct dfui_progress *); 61 | 62 | void dfui_debug(const char *, ...); 63 | 64 | #ifdef __cplusplus 65 | } 66 | #endif 67 | 68 | #endif /* !__DUMP_H_ */ 69 | -------------------------------------------------------------------------------- /lib/libdfui/lang.c: -------------------------------------------------------------------------------- 1 | /* 2 | * $Id: lang.c,v 1.5 2005/02/12 00:31:46 cpressey Exp $ 3 | */ 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #include "lang.h" 13 | 14 | struct _langset { 15 | const char *name; 16 | const char *font8x8; 17 | const char *font8x14; 18 | const char *font8x16; 19 | const char *keymap; 20 | const char *scrnmap; 21 | const char *language; 22 | const char *charset; 23 | const char *term; 24 | } langset[] = { 25 | { "ru", "cp866-8x8", "cp866-8x14", "cp866-8x16", "ru.koi8-r", "koi8-r2cp866", "ru_RU.KOI8-R", "KOI8-R", "cons25r" } 26 | }; 27 | 28 | #define langcount (sizeof(langset) / sizeof(struct _langset)) 29 | 30 | static int get_lang_num(const char *langname); 31 | static int system_fmt(const char *fmt, ...); 32 | 33 | 34 | static int 35 | get_lang_num(const char *langname) 36 | { 37 | size_t i; 38 | 39 | for(i =0; i < langcount; i++) 40 | if(strcmp(langset[i].name, langname) == 0) 41 | return i; 42 | 43 | return -1; 44 | } 45 | 46 | static int 47 | system_fmt(const char *fmt, ...) 48 | { 49 | char *command; 50 | va_list args; 51 | 52 | va_start(args, fmt); 53 | vasprintf(&command, fmt, args); 54 | va_end(args); 55 | 56 | #ifdef DEBUG 57 | fprintf(stderr, "%s\n", command); 58 | #endif 59 | 60 | return(system(command)); 61 | } 62 | 63 | /* do this once */ 64 | int 65 | set_lang_syscons(const char *id) 66 | { 67 | int lang_num; 68 | 69 | lang_num = get_lang_num(id); 70 | 71 | if(lang_num < 0) 72 | return(0); 73 | 74 | #define kbddev "/dev/ttyv0" 75 | #define viddev "/dev/ttyv0" 76 | #define kbdcontrol "/usr/sbin/kbdcontrol" 77 | #define vidcontrol "/usr/sbin/vidcontrol" 78 | 79 | if ( 80 | system_fmt("%s < %s -l %s", kbdcontrol, kbddev, langset[lang_num].keymap) != 0 || 81 | system_fmt("%s < %s -l %s", vidcontrol, viddev, langset[lang_num].scrnmap) != 0 || 82 | system_fmt("%s < %s -f 8x8 %s", vidcontrol, viddev, langset[lang_num].font8x8) != 0 || 83 | system_fmt("%s < %s -f 8x14 %s", vidcontrol, viddev, langset[lang_num].font8x14) != 0 || 84 | system_fmt("%s < %s -f 8x16 %s", vidcontrol, viddev, langset[lang_num].font8x16) != 0) 85 | return(0); 86 | 87 | return(1); 88 | } 89 | 90 | /* do this for each side (backend, frontend) */ 91 | int 92 | set_lang_envars(const char *id) 93 | { 94 | char *term; 95 | 96 | int lang_num; 97 | 98 | lang_num = get_lang_num(id); 99 | 100 | if(lang_num < 0) 101 | return(0); 102 | 103 | /* gettext recommended setting */ 104 | setenv("LANGUAGE", langset[lang_num].name, 1); 105 | 106 | /* also should be set */ 107 | setenv("LANG", langset[lang_num].language, 1); 108 | 109 | /* set this too for completeness */ 110 | setenv("MM_CHARSET", langset[lang_num].charset, 1); 111 | 112 | /* TERM must be set for some encodings */ 113 | term = getenv("TERM"); 114 | if((strcmp(term,"cons25") == 0) && 115 | langset[lang_num].term != NULL) 116 | setenv("TERM", langset[lang_num].term, 1); 117 | 118 | return(1); 119 | } 120 | -------------------------------------------------------------------------------- /lib/libdfui/lang.h: -------------------------------------------------------------------------------- 1 | /* 2 | * $Id: lang.h,v 1.3 2005/09/01 19:23:14 cpressey Exp $ 3 | */ 4 | #ifndef __LANG_H_ 5 | #define __LANG_H_ 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | 11 | int set_lang_syscons(const char *); 12 | int set_lang_envars(const char *); 13 | 14 | #ifdef __cplusplus 15 | } 16 | #endif 17 | 18 | #endif /* !__LANG_H_ */ 19 | -------------------------------------------------------------------------------- /lib/libdfui/system.c: -------------------------------------------------------------------------------- 1 | /* 2 | * system.c 3 | * System definitions and capabilities. 4 | * $Id: system.c,v 1.7 2005/08/27 06:55:15 cpressey Exp $ 5 | */ 6 | 7 | #include 8 | #undef __unused /* occurs in following header on some systems */ 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #include "dfui.h" 18 | #include "system.h" 19 | 20 | char * 21 | ostype() 22 | { 23 | int mib[2]; 24 | size_t len; 25 | char *p; 26 | 27 | mib[0] = CTL_KERN; 28 | mib[1] = KERN_OSTYPE; 29 | sysctl(mib, 2, NULL, &len, NULL, 0); 30 | p = malloc(len); 31 | sysctl(mib, 2, p, &len, NULL, 0); 32 | return p; 33 | } 34 | 35 | int 36 | has_caps() 37 | { 38 | #ifdef HAS_CAPS 39 | return 1; 40 | #endif 41 | return 0; 42 | } 43 | 44 | int 45 | has_npipe() 46 | { 47 | #ifdef HAS_NPIPE 48 | return 1; 49 | #else 50 | return 0; 51 | #endif 52 | } 53 | 54 | int 55 | has_tcp() 56 | { 57 | #ifdef HAS_TCP 58 | return 1; 59 | #else 60 | return 0; 61 | #endif 62 | } 63 | 64 | /* 65 | * Get transport from transport name. 66 | * 67 | * return(0) if transport is not supported. 68 | * retirn(-1) if transport unknown. 69 | */ 70 | int 71 | get_transport(const char *transport_name) 72 | { 73 | if (strcmp(transport_name, "caps") == 0) { 74 | if (has_caps()) 75 | return DFUI_TRANSPORT_CAPS; 76 | return(0); 77 | } else if (strcmp(transport_name, "npipe") == 0) { 78 | if (has_npipe()) 79 | return DFUI_TRANSPORT_NPIPE; 80 | return(0); 81 | } else if (strcmp(transport_name, "tcp") == 0) { 82 | if (has_tcp()) 83 | return DFUI_TRANSPORT_TCP; 84 | return(0); 85 | } 86 | return(-1); 87 | } 88 | 89 | /* 90 | * Get transport upon user request 91 | * 92 | * Print appropriate error message to stderr 93 | * and exit if transport not supported or unknown. 94 | */ 95 | int 96 | user_get_transport(const char *transport_name) 97 | { 98 | int transport; 99 | 100 | transport = get_transport(transport_name); 101 | 102 | if (transport == 0) { 103 | errx(EX_UNAVAILABLE, "Transport is not supported: ``%s''.\n", 104 | transport_name); 105 | } else if (transport < 0) { 106 | errx(EX_CONFIG, "Wrong transport name: ``%s''.\n", 107 | transport_name); 108 | } 109 | 110 | return(transport); 111 | } 112 | -------------------------------------------------------------------------------- /lib/libdfui/system.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c)2004 Cat's Eye Technologies. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 11 | * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in 13 | * the documentation and/or other materials provided with the 14 | * distribution. 15 | * 16 | * Neither the name of Cat's Eye Technologies nor the names of its 17 | * contributors may be used to endorse or promote products derived 18 | * from this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 | * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 25 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 26 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 29 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 31 | * OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | /* 35 | * system.h 36 | * $Id: system.h,v 1.11 2005/09/01 19:23:14 cpressey Exp $ 37 | */ 38 | 39 | #ifndef __SYSTEM_H_ 40 | #define __SYSTEM_H_ 41 | 42 | #if (__FreeBSD__ || __DragonFly__ || __OpenBSD__ || __NetBSD__ || __linux__) 43 | # define HAS_TCP 44 | # define HAS_NPIPE 45 | #endif 46 | 47 | #if (__DragonFly__) 48 | # define HAS_CAPS 49 | #endif 50 | 51 | #ifndef HAS_TCP 52 | #ifndef HAS_NPIPE 53 | #ifndef HAS_CAPS 54 | #error "Your OS must support at least one IPC mechanism: TCP/IP sockets, named pipes, or CAPS." 55 | #endif 56 | #endif 57 | #endif 58 | 59 | #if defined(__DragonFly__) 60 | #define OPERATING_SYSTEM_NAME "DragonFly BSD" 61 | #define OPERATING_SYSTEM_URL "http://www.dragonflybsd.org" 62 | 63 | #elif defined(__FreeBSD__) 64 | #define OPERATING_SYSTEM_NAME "FreeBSD" 65 | #define OPERATING_SYSTEM_URL "http://www.freebsd.org" 66 | 67 | #elif defined(__OpenBSD__) 68 | #define OPERATING_SYSTEM_NAME "OpenBSD" 69 | #define OPERATING_SYSTEM_URL "http://www.openbsd.org" 70 | 71 | #elif defined(__NetBSD__) 72 | #define OPERATING_SYSTEM_NAME "NetBSD" 73 | #define OPERATING_SYSTEM_URL "http://www.netbsd.org" 74 | 75 | #endif 76 | 77 | #ifdef __cplusplus 78 | extern "C" { 79 | #endif 80 | 81 | char *ostype(void); 82 | int has_tcp(void); 83 | int has_npipe(void); 84 | int has_caps(void); 85 | int get_transport(const char *); 86 | int user_get_transport(const char *); 87 | 88 | #ifdef __cplusplus 89 | } 90 | #endif 91 | 92 | #endif /* !__SYSTEM_H_ */ 93 | -------------------------------------------------------------------------------- /lib/lua/Makefile: -------------------------------------------------------------------------------- 1 | SUBDIR= app filename transceiver compat-5.1 posix luasocket dfui pty lcurses 2 | 3 | .include 4 | -------------------------------------------------------------------------------- /lib/lua/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/opnsense/bsdinstaller/a7dc8378301c0360a8184f8b29e96b80892b1698/lib/lua/README -------------------------------------------------------------------------------- /lib/lua/app/Makefile: -------------------------------------------------------------------------------- 1 | # $Id: Makefile,v 1.6 2005/08/27 02:11:33 cpressey Exp $ 2 | 3 | BASE?=../../.. 4 | include ${BASE}/Config 5 | 6 | all: 7 | @echo "Nothing to build." 8 | 9 | clean: 10 | @echo "No cleaning required." 11 | 12 | install: 13 | mkdir -p ${DESTDIR}${PREFIX}/share/lua/5.0 14 | cp app.lua ${DESTDIR}${PREFIX}/share/lua/5.0 15 | -------------------------------------------------------------------------------- /lib/lua/compat-5.1/Makefile: -------------------------------------------------------------------------------- 1 | # $Id: Makefile,v 1.5.2.1 2009/01/03 19:49:46 sullrich Exp $ 2 | 3 | CFLAGS+= -fPIC 4 | 5 | BASE?=../../.. 6 | include ${BASE}/Config 7 | 8 | LUA=../../../lua 9 | 10 | CFLAGS+= -Wall 11 | 12 | all: compat-5.1.o 13 | 14 | compat-5.1.o: compat-5.1.c compat-5.1.h 15 | $(CC) $(CFLAGS) -I$(LUA)/include -c compat-5.1.c -o compat-5.1.o 16 | 17 | strip: 18 | strip compat-5.1.o 19 | 20 | clean: 21 | rm -f *.o 22 | 23 | install: strip 24 | mkdir -p $(DESTDIR)${PREFIX}/bin 25 | cp lua50c51.sh $(DESTDIR)${PREFIX}/bin/lua50c51 26 | mkdir -p ${DESTDIR}${PREFIX}/share/lua/5.0 27 | cp compat-5.1.lua ${DESTDIR}${PREFIX}/share/lua/5.0 28 | -------------------------------------------------------------------------------- /lib/lua/compat-5.1/compat-5.1.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** Compat-5.1 3 | ** Copyright Kepler Project 2004-2005 (http://www.keplerproject.org/compat) 4 | ** $Id: compat-5.1.c,v 1.2 2005/07/30 02:21:34 cpressey Exp $ 5 | */ 6 | 7 | #include 8 | #include 9 | #include "lua.h" 10 | #include "lauxlib.h" 11 | #include "compat-5.1.h" 12 | 13 | static void getfield(lua_State *L, int idx, const char *name) { 14 | const char *end = strchr(name, '.'); 15 | lua_pushvalue(L, idx); 16 | while (end) { 17 | lua_pushlstring(L, name, end - name); 18 | lua_gettable(L, -2); 19 | lua_remove(L, -2); 20 | if (lua_isnil(L, -1)) return; 21 | name = end+1; 22 | end = strchr(name, '.'); 23 | } 24 | lua_pushstring(L, name); 25 | lua_gettable(L, -2); 26 | lua_remove(L, -2); 27 | } 28 | 29 | static void setfield(lua_State *L, int idx, const char *name) { 30 | const char *end = strchr(name, '.'); 31 | lua_pushvalue(L, idx); 32 | while (end) { 33 | lua_pushlstring(L, name, end - name); 34 | lua_gettable(L, -2); 35 | /* create table if not found */ 36 | if (lua_isnil(L, -1)) { 37 | lua_pop(L, 1); 38 | lua_newtable(L); 39 | lua_pushlstring(L, name, end - name); 40 | lua_pushvalue(L, -2); 41 | lua_settable(L, -4); 42 | } 43 | lua_remove(L, -2); 44 | name = end+1; 45 | end = strchr(name, '.'); 46 | } 47 | lua_pushstring(L, name); 48 | lua_pushvalue(L, -3); 49 | lua_settable(L, -3); 50 | lua_pop(L, 2); 51 | } 52 | 53 | LUALIB_API void luaL_module(lua_State *L, const char *libname, 54 | const luaL_reg *l, int nup) { 55 | if (libname) { 56 | getfield(L, LUA_GLOBALSINDEX, libname); /* check whether lib already exists */ 57 | if (lua_isnil(L, -1)) { 58 | int env, ns; 59 | lua_pop(L, 1); /* get rid of nil */ 60 | lua_pushliteral(L, "require"); 61 | lua_gettable(L, LUA_GLOBALSINDEX); /* look for require */ 62 | lua_getfenv(L, -1); /* getfenv(require) */ 63 | lua_remove(L, -2); /* remove function require */ 64 | env = lua_gettop(L); 65 | 66 | lua_newtable(L); /* create namespace for lib */ 67 | ns = lua_gettop(L); 68 | getfield(L, env, "package.loaded"); /* get package.loaded table */ 69 | if (lua_isnil(L, -1)) { /* create package.loaded table */ 70 | lua_pop(L, 1); /* remove previous result */ 71 | lua_newtable(L); 72 | lua_pushvalue(L, -1); 73 | setfield(L, env, "package.loaded"); 74 | } 75 | else if (!lua_istable(L, -1)) 76 | luaL_error(L, "name conflict for library `%s'", libname); 77 | lua_pushstring(L, libname); 78 | lua_pushvalue(L, ns); 79 | lua_settable(L, -3); /* package.loaded[libname] = ns */ 80 | lua_pop(L, 1); /* get rid of package.loaded table */ 81 | lua_pushvalue(L, ns); /* copy namespace */ 82 | setfield(L, LUA_GLOBALSINDEX, libname); 83 | lua_remove (L, env); /* remove env */ 84 | } 85 | lua_insert(L, -(nup+1)); /* move library table to below upvalues */ 86 | } 87 | for (; l->name; l++) { 88 | int i; 89 | lua_pushstring(L, l->name); 90 | for (i=0; ifunc, nup); 93 | lua_settable(L, -(nup+3)); 94 | } 95 | lua_pop(L, nup); /* remove upvalues */ 96 | } 97 | 98 | -------------------------------------------------------------------------------- /lib/lua/compat-5.1/compat-5.1.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Compat-5.1 3 | ** Copyright Kepler Project 2004-2005 (http://www.keplerproject.org/compat/) 4 | ** $Id: compat-5.1.h,v 1.2 2005/07/30 02:21:34 cpressey Exp $ 5 | */ 6 | 7 | #ifndef COMPAT_H 8 | 9 | LUALIB_API void luaL_module(lua_State *L, const char *libname, 10 | const luaL_reg *l, int nup); 11 | #define luaL_openlib luaL_module 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /lib/lua/compat-5.1/lua50c51.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | LUA_CPATH='/usr/local/lib/lua/5.0/?.so' exec /usr/local/bin/lua50 -l/usr/local/share/lua/5.0/compat-5.1.lua $* 4 | -------------------------------------------------------------------------------- /lib/lua/dfui/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for luadfui. 2 | # $Id: Makefile,v 1.13 2005/08/26 22:44:37 cpressey Exp $ 3 | 4 | BASE?=../../.. 5 | include ${BASE}/Config 6 | 7 | LUA=../../../lua 8 | 9 | COMPAT?=../compat-5.1 10 | 11 | LIB= ldfui.so 12 | OBJS= common.o dfui.o progress.o 13 | 14 | CFLAGS+= ${WARNS} -fPIC -I/usr/local/include 15 | CFLAGS+= -I${LUA}/include -I${COMPAT} -I../../libdfui 16 | LDFLAGS+= -L../../libdfui -L${LUA}/lib/ 17 | LDFLAGS+= -ldfui -lm -llua50 -llualib50 18 | 19 | all: ${LIB} 20 | 21 | ${LIB}: ${OBJS} 22 | ${CC} ${OBJS} ${COMPAT}/compat-5.1.o -shared ${LDFLAGS} -o ${LIB} 23 | 24 | strip: 25 | ${STRIP} ${LIB} 26 | 27 | clean: 28 | rm -f *.o *.so 29 | 30 | install: strip 31 | mkdir -p ${DESTDIR}${PREFIX}/lib/lua/5.0 32 | cp ${LIB} ${DESTDIR}${PREFIX}/lib/lua/5.0 33 | mkdir -p ${DESTDIR}${PREFIX}/share/lua/5.0 34 | cp dfui.lua ${DESTDIR}${PREFIX}/share/lua/5.0 35 | -------------------------------------------------------------------------------- /lib/lua/dfui/dfui.lua: -------------------------------------------------------------------------------- 1 | -- $Id: dfui.lua,v 1.46 2005/08/01 22:05:45 cpressey Exp $ 2 | -- Wrapper/helper/extra abstractions for DFUI. 3 | 4 | --[[------]]-- 5 | --[[ DFUI ]]-- 6 | --[[------]]-- 7 | 8 | -- 9 | -- This is a wrapper object around DFUI.Connection and DFUI.Progress, 10 | -- intended to be used as a client of the the App.UIBridge object. 11 | -- 12 | 13 | module("dfui") 14 | 15 | DFUI = require "ldfui" 16 | local POSIX = require "posix" 17 | 18 | DFUI.new = function(tab) 19 | local dfui = {} 20 | local transport = tab.transport or "tcp" 21 | local rendezvous = tab.rendezvous or "9999" 22 | local connection 23 | local log = tab.log or function(fmt, ...) 24 | print(string.format(fmt, unpack(arg))) 25 | end 26 | 27 | dfui.start = function(dfui) 28 | connection = DFUI.Connection.new(transport, rendezvous) 29 | if connection:start() == 0 then 30 | connection:stop() 31 | log("Could not establish DFUI connection " .. 32 | " on %s:%s", transport, rendezvous) 33 | return false 34 | end 35 | log("DFUI connection on %s:%s successfully established", 36 | transport, rendezvous) 37 | return true 38 | end 39 | 40 | dfui.stop = function(dfui) 41 | return connection:stop() 42 | end 43 | 44 | dfui.present = function(dfui, tab) 45 | local response = connection:present(tab) 46 | local i, action 47 | 48 | -- Handle the 'effect' field which may be given in 49 | -- any action table within a form table. When it 50 | -- is given, it should be a function which the 51 | -- user wishes to be executed automatically when 52 | -- the response is caused by that action. This lets 53 | -- the user write simpler Lua code (c:present(f) can 54 | -- execute things directly, instead of returning an 55 | -- id code which the user must look up in a table etc.) 56 | 57 | for i, action in ipairs(tab.actions or {}) do 58 | if action.id == response.action_id and 59 | type(action.effect) == "function" then 60 | response.result = action.effect(response) 61 | end 62 | end 63 | 64 | return response 65 | end 66 | 67 | dfui.set = function(dfui, key, value) 68 | if key == "lang_envars" then 69 | return connection:set_lang_envars(id) ~= 0 70 | elseif key == "lang_syscons" then 71 | return connection:set_lang_syscons(id) ~= 0 72 | end 73 | if connection:set_global_setting(key, value) ~= 0 then 74 | return nil, "Cancelled" 75 | else 76 | return true 77 | end 78 | end 79 | 80 | -- 81 | -- Constructor within a constructor, here... 82 | -- 83 | dfui.new_progress_bar = function(dfui, tab) 84 | local method = {} 85 | local pr 86 | local title = tab.title or "Working..." 87 | local short_desc = tab.short_desc or title 88 | local long_desc = tab.long_desc or "" 89 | local amount = 0 90 | 91 | pr = DFUI.Progress.new(connection, 92 | title, short_desc, long_desc, amount) 93 | 94 | method.start = function(method) 95 | return pr:start() 96 | end 97 | 98 | method.set_amount = function(method, new_amount) 99 | return pr:set_amount(new_amount) 100 | end 101 | 102 | method.set_short_desc = function(method, new_short_desc) 103 | return pr:set_short_desc(new_short_desc) 104 | end 105 | 106 | method.update = function(method) 107 | return pr:update() 108 | end 109 | 110 | method.stop = function(method) 111 | return pr:stop() 112 | end 113 | 114 | return method 115 | end 116 | 117 | return dfui 118 | end 119 | 120 | return DFUI 121 | -------------------------------------------------------------------------------- /lib/lua/filename/Makefile: -------------------------------------------------------------------------------- 1 | # $Id: Makefile,v 1.5 2005/08/27 02:11:33 cpressey Exp $ 2 | 3 | BASE?=../../.. 4 | include ${BASE}/Config 5 | 6 | all: 7 | @echo "Nothing to build." 8 | 9 | clean: 10 | @echo "No cleaning required." 11 | 12 | install: 13 | mkdir -p ${DESTDIR}${PREFIX}/share/lua/5.0 14 | cp filename.lua ${DESTDIR}${PREFIX}/share/lua/5.0 15 | -------------------------------------------------------------------------------- /lib/lua/lcurses/Makefile: -------------------------------------------------------------------------------- 1 | # makefile for lcurses library for Lua 2 | # $Id: Makefile,v 1.9 2005/08/26 22:44:38 cpressey Exp $ 3 | 4 | BASE?=../../.. 5 | include ${BASE}/Config 6 | 7 | # change these to reflect your Lua installation 8 | LUA=../../../lua 9 | LUAINC= $(LUA)/include 10 | LUALIB= $(LUA)/lib 11 | 12 | COMPAT=../compat-5.1 13 | 14 | # no need to change anything below here 15 | CFLAGS+= -fPIC -O2 -I$(LUAINC) -Wall -ansi 16 | LDFLAGS+=-L$(LUALIB) -L/usr/local/lib -lpanel -lcurses -llualib50 -llua50 17 | 18 | MYNAME= curses 19 | MYLIB= l$(MYNAME) 20 | 21 | OBJS= $(MYLIB).o 22 | 23 | T= $(MYLIB).so 24 | 25 | VER=0.1-devel 26 | 27 | all: $T 28 | 29 | lua: lcurses.c lua.c 30 | $(CC) -I. -DDEBUG -g -o lua lua.c lcurses.c -L. -llualib -llua -lpanel -lcurses -lm -ldl 31 | 32 | $T: $(OBJS) 33 | $(CC) -fPIC -o $@ -shared $(OBJS) $(COMPAT)/compat-5.1.o $(LDFLAGS) 34 | 35 | lcurses.o: lcurses.c lpanel.c 36 | 37 | clean: 38 | rm -f $(OBJS) $T core core.* *.core a.out 39 | 40 | strip: 41 | ${STRIP} $T 42 | 43 | install: strip 44 | mkdir -p $(DESTDIR)${PREFIX}/lib/lua/5.0 45 | cp $T $(DESTDIR)${PREFIX}/lib/lua/5.0 46 | mkdir -p ${DESTDIR}${PREFIX}/share/lua/5.0 47 | cp curses.lua ${DESTDIR}${PREFIX}/share/lua/5.0 48 | -------------------------------------------------------------------------------- /lib/lua/lcurses/curses.lua: -------------------------------------------------------------------------------- 1 | --[[------------------------------------------------------------------------ 2 | curses.lua 3 | support code for curses library 4 | usage lua -lcurses ... 5 | 6 | Author: Tiago Dionizio (tngd@mega.ist.utl.pt) 7 | $Id: curses.lua,v 1.2 2005/07/31 02:46:32 cpressey Exp $ 8 | --]]------------------------------------------------------------------------ 9 | 10 | --[[ Documentation --------------------------------------------------------- 11 | 12 | 13 | 14 | --]]------------------------------------------------------------------------ 15 | 16 | module "curses" 17 | 18 | curses = require("lcurses") 19 | 20 | return curses 21 | -------------------------------------------------------------------------------- /lib/lua/luasocket/INSTALL: -------------------------------------------------------------------------------- 1 | It should be easy to build LuaSocket. Just as an example, I am providing my 2 | makefiles for Linux, Mac OS X and Visual C.NET. The Linux makefile can be 3 | used for AIX, SunOS, and IRIX too, with little modification. These build 4 | two shared libraries: one for luasocket and one for mime. 5 | 6 | LuaSocket 2.0 uses the new package proposal for Lua 5.1. All Lua library 7 | developers are encouraged to update their libraries so that all libraries 8 | can coexist peacefully and users can benefit from the standardization and 9 | flexibility of the standard. 10 | 11 | Please check the installation instructions in the manual for details. 12 | Have fun! 13 | Diego. 14 | -------------------------------------------------------------------------------- /lib/lua/luasocket/LICENSE: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/opnsense/bsdinstaller/a7dc8378301c0360a8184f8b29e96b80892b1698/lib/lua/luasocket/LICENSE -------------------------------------------------------------------------------- /lib/lua/luasocket/Makefile: -------------------------------------------------------------------------------- 1 | # $Id: Makefile,v 1.8 2005/08/27 07:20:39 cpressey Exp $ 2 | # BSD Installer Makefile for luasocket, adapted from makefile.Linux. 3 | 4 | BASE?=../../.. 5 | include ${BASE}/Config 6 | 7 | LV=2.0 8 | MV=1.0 9 | 10 | LUA?=../../../lua 11 | 12 | COMPAT?=../compat-5.1 13 | 14 | LOBJS= luasocket.o timeout.o buffer.o io.o auxiliar.o except.o \ 15 | select.o options.o inet.o tcp.o udp.o usocket.o 16 | 17 | MOBJS= mime.o 18 | 19 | CFLAGS+= -I$(LUA)/include -I$(COMPAT) \ 20 | $(PROF) $(DBG) -pedantic -W -Wall -fPIC 21 | LDFLAGS+= -L$(LUA)/lib -llua -llualib 22 | 23 | LDYN=lsocket.so 24 | 25 | MDYN=lmime.so 26 | 27 | all: $(LDYN) $(MDYN) 28 | 29 | $(LDYN): $(LOBJS) 30 | $(CC) $(LOBJS) $(COMPAT)/compat-5.1.o -shared $(LDFLAGS) -o $(LDYN) 31 | 32 | $(MDYN): $(MOBJS) 33 | $(CC) ${MOBJS} $(COMPAT)/compat-5.1.o -shared ${LDFLAGS} -o $(MDYN) 34 | 35 | strip: 36 | strip $(LDYN) $(MDYN) 37 | 38 | clean: 39 | rm -f $(LOBJS) $(MOBJS) $(SOBJS) 40 | rm -f $(MDYN) $(LDYN) $(SDYN) 41 | 42 | install: strip 43 | mkdir -p $(DESTDIR)${PREFIX}/lib/lua/5.0 44 | cp $(LDYN) $(MDYN) $(DESTDIR)${PREFIX}/lib/lua/5.0 45 | mkdir -p $(DESTDIR)${PREFIX}/share/lua/5.0 46 | cp lua/*.lua $(DESTDIR)${PREFIX}/share/lua/5.0 47 | -------------------------------------------------------------------------------- /lib/lua/luasocket/NEW: -------------------------------------------------------------------------------- 1 | What's New 2 | 3 | The big change for the 2.0 (beta3) release was the adoption of the Lua 4 | 5.1 package proposal. There were several bug fixes too (a beta is a 5 | beta, is a beta). 6 | 7 | * New compat-5.1 distribution: 8 | - Instalation uses new directory structure; 9 | - Namespace hierarchy is in now back in use (ex. socket.url instead of url); 10 | - All modules call require even for standard libraries; 11 | * LTN12 avoids coroutines (so you can go wild on the C side); 12 | * socket.select wasn't calling tm_markstart; 13 | * Kludge on wsocket.c:sock_send for Windows timeout issue moved to 14 | buffer.c:sendraw so it's not a kludge anymore; 15 | * socket.protect only catches errors thrown by socket.try; 16 | * Fixed udp:sendto to call sock_sendto instead of sock_send; 17 | * close wasn't returning 1! 18 | * socket.gettime returns time since Unix Epoch 1/1/1970 (UTC) 19 | * socket.sleep is robust to interrupts; 20 | * http.PROXY wasn't working. 21 | * fixed some of the examples 22 | -------------------------------------------------------------------------------- /lib/lua/luasocket/README: -------------------------------------------------------------------------------- 1 | This release is a "beta" version. It has been tested on WinXP, Mac OS X, 2 | and Linux. Although no major API changes should happen before the 3 | final version is released, please look for and report any bugs (or 4 | "features") you encounter. 5 | 6 | Have fun, 7 | Diego Nehab. 8 | -------------------------------------------------------------------------------- /lib/lua/luasocket/auxiliar.h: -------------------------------------------------------------------------------- 1 | #ifndef AUX_H 2 | #define AUX_H 3 | /*=========================================================================*\ 4 | * Auxiliar routines for class hierarchy manipulation 5 | * LuaSocket toolkit (but completely independent of other LuaSocket modules) 6 | * 7 | * A LuaSocket class is a name associated with Lua metatables. A LuaSocket 8 | * group is a name associated with a class. A class can belong to any number 9 | * of groups. This module provides the functionality to: 10 | * 11 | * - create new classes 12 | * - add classes to groups 13 | * - set the class of objects 14 | * - check if an object belongs to a given class or group 15 | * - get the userdata associated to objects 16 | * - print objects in a pretty way 17 | * 18 | * LuaSocket class names follow the convention {}. Modules 19 | * can define any number of classes and groups. The module tcp.c, for 20 | * example, defines the classes tcp{master}, tcp{client} and tcp{server} and 21 | * the groups tcp{client,server} and tcp{any}. Module functions can then 22 | * perform type-checking on their arguments by either class or group. 23 | * 24 | * LuaSocket metatables define the __index metamethod as being a table. This 25 | * table has one field for each method supported by the class, and a field 26 | * "class" with the class name. 27 | * 28 | * The mapping from class name to the corresponding metatable and the 29 | * reverse mapping are done using lauxlib. 30 | * 31 | * RCS ID: $Id: auxiliar.h,v 1.1 2005/07/26 21:06:14 cpressey Exp $ 32 | \*=========================================================================*/ 33 | 34 | #include 35 | #include 36 | 37 | int aux_open(lua_State *L); 38 | void aux_newclass(lua_State *L, const char *classname, luaL_reg *func); 39 | void aux_add2group(lua_State *L, const char *classname, const char *group); 40 | void aux_setclass(lua_State *L, const char *classname, int objidx); 41 | void *aux_checkclass(lua_State *L, const char *classname, int objidx); 42 | void *aux_checkgroup(lua_State *L, const char *groupname, int objidx); 43 | void *aux_getclassudata(lua_State *L, const char *groupname, int objidx); 44 | void *aux_getgroupudata(lua_State *L, const char *groupname, int objidx); 45 | int aux_checkboolean(lua_State *L, int objidx); 46 | int aux_tostring(lua_State *L); 47 | 48 | #endif /* AUX_H */ 49 | -------------------------------------------------------------------------------- /lib/lua/luasocket/buffer.h: -------------------------------------------------------------------------------- 1 | #ifndef BUF_H 2 | #define BUF_H 3 | /*=========================================================================*\ 4 | * Input/Output interface for Lua programs 5 | * LuaSocket toolkit 6 | * 7 | * Line patterns require buffering. Reading one character at a time involves 8 | * too many system calls and is very slow. This module implements the 9 | * LuaSocket interface for input/output on connected objects, as seen by 10 | * Lua programs. 11 | * 12 | * Input is buffered. Output is *not* buffered because there was no simple 13 | * way of making sure the buffered output data would ever be sent. 14 | * 15 | * The module is built on top of the I/O abstraction defined in io.h and the 16 | * timeout management is done with the timeout.h interface. 17 | * 18 | * RCS ID: $Id: buffer.h,v 1.1 2005/07/26 21:06:14 cpressey Exp $ 19 | \*=========================================================================*/ 20 | #include 21 | 22 | #include "io.h" 23 | #include "timeout.h" 24 | 25 | /* buffer size in bytes */ 26 | #define BUF_SIZE 8192 27 | 28 | /* buffer control structure */ 29 | typedef struct t_buf_ { 30 | double birthday; /* throttle support info: creation time, */ 31 | size_t sent, received; /* bytes sent, and bytes received */ 32 | p_io io; /* IO driver used for this buffer */ 33 | p_tm tm; /* timeout management for this buffer */ 34 | size_t first, last; /* index of first and last bytes of stored data */ 35 | char data[BUF_SIZE]; /* storage space for buffer data */ 36 | } t_buf; 37 | typedef t_buf *p_buf; 38 | 39 | int buf_open(lua_State *L); 40 | void buf_init(p_buf buf, p_io io, p_tm tm); 41 | int buf_meth_send(lua_State *L, p_buf buf); 42 | int buf_meth_receive(lua_State *L, p_buf buf); 43 | int buf_meth_getstats(lua_State *L, p_buf buf); 44 | int buf_meth_setstats(lua_State *L, p_buf buf); 45 | int buf_isempty(p_buf buf); 46 | 47 | #endif /* BUF_H */ 48 | -------------------------------------------------------------------------------- /lib/lua/luasocket/except.c: -------------------------------------------------------------------------------- 1 | /*=========================================================================*\ 2 | * Simple exception support 3 | * LuaSocket toolkit 4 | * 5 | * RCS ID: $Id: except.c,v 1.1 2005/07/26 21:06:14 cpressey Exp $ 6 | \*=========================================================================*/ 7 | #include 8 | #include 9 | #include 10 | 11 | #include "except.h" 12 | 13 | /*=========================================================================*\ 14 | * Internal function prototypes. 15 | \*=========================================================================*/ 16 | static int global_protect(lua_State *L); 17 | static int global_newtry(lua_State *L); 18 | static int protected_(lua_State *L); 19 | static int finalize(lua_State *L); 20 | static int do_nothing(lua_State *L); 21 | 22 | /* except functions */ 23 | static luaL_reg func[] = { 24 | {"newtry", global_newtry}, 25 | {"protect", global_protect}, 26 | {NULL, NULL} 27 | }; 28 | 29 | /*-------------------------------------------------------------------------*\ 30 | * Try factory 31 | \*-------------------------------------------------------------------------*/ 32 | static void wrap(lua_State *L) { 33 | lua_newtable(L); 34 | lua_pushnumber(L, 1); 35 | lua_pushvalue(L, -3); 36 | lua_settable(L, -3); 37 | lua_insert(L, -2); 38 | lua_pop(L, 1); 39 | } 40 | 41 | static int finalize(lua_State *L) { 42 | if (!lua_toboolean(L, 1)) { 43 | lua_pushvalue(L, lua_upvalueindex(1)); 44 | lua_pcall(L, 0, 0, 0); 45 | lua_settop(L, 2); 46 | wrap(L); 47 | lua_error(L); 48 | return 0; 49 | } else return lua_gettop(L); 50 | } 51 | 52 | static int do_nothing(lua_State *L) { 53 | (void) L; 54 | return 0; 55 | } 56 | 57 | static int global_newtry(lua_State *L) { 58 | lua_settop(L, 1); 59 | if (lua_isnil(L, 1)) lua_pushcfunction(L, do_nothing); 60 | lua_pushcclosure(L, finalize, 1); 61 | return 1; 62 | } 63 | 64 | /*-------------------------------------------------------------------------*\ 65 | * Protect factory 66 | \*-------------------------------------------------------------------------*/ 67 | static int unwrap(lua_State *L) { 68 | if (lua_istable(L, -1)) { 69 | lua_pushnumber(L, 1); 70 | lua_gettable(L, -2); 71 | lua_pushnil(L); 72 | lua_insert(L, -2); 73 | return 1; 74 | } else return 0; 75 | } 76 | 77 | static int protected_(lua_State *L) { 78 | lua_pushvalue(L, lua_upvalueindex(1)); 79 | lua_insert(L, 1); 80 | if (lua_pcall(L, lua_gettop(L) - 1, LUA_MULTRET, 0) != 0) { 81 | if (unwrap(L)) return 2; 82 | else lua_error(L); 83 | return 0; 84 | } else return lua_gettop(L); 85 | } 86 | 87 | static int global_protect(lua_State *L) { 88 | lua_pushcclosure(L, protected_, 1); 89 | return 1; 90 | } 91 | 92 | /*-------------------------------------------------------------------------*\ 93 | * Init module 94 | \*-------------------------------------------------------------------------*/ 95 | int except_open(lua_State *L) { 96 | luaL_openlib(L, NULL, func, 0); 97 | return 0; 98 | } 99 | -------------------------------------------------------------------------------- /lib/lua/luasocket/except.h: -------------------------------------------------------------------------------- 1 | #ifndef EXCEPT_H 2 | #define EXCEPT_H 3 | /*=========================================================================*\ 4 | * Exception control 5 | * LuaSocket toolkit (but completely independent from other modules) 6 | * 7 | * This provides support for simple exceptions in Lua. During the 8 | * development of the HTTP/FTP/SMTP support, it became aparent that 9 | * error checking was taking a substantial amount of the coding. These 10 | * function greatly simplify the task of checking errors. 11 | * 12 | * The main idea is that functions should return nil as its first return 13 | * value when it finds an error, and return an error message (or value) 14 | * following nil. In case of success, as long as the first value is not nil, 15 | * the other values don't matter. 16 | * 17 | * The idea is to nest function calls with the "try" function. This function 18 | * checks the first value, and calls "error" on the second if the first is 19 | * nil. Otherwise, it returns all values it received. 20 | * 21 | * The protect function returns a new function that behaves exactly like the 22 | * function it receives, but the new function doesn't throw exceptions: it 23 | * returns nil followed by the error message instead. 24 | * 25 | * With these two function, it's easy to write functions that throw 26 | * exceptions on error, but that don't interrupt the user script. 27 | * 28 | * RCS ID: $Id: except.h,v 1.1 2005/07/26 21:06:14 cpressey Exp $ 29 | \*=========================================================================*/ 30 | 31 | #include 32 | 33 | int except_open(lua_State *L); 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /lib/lua/luasocket/inet.h: -------------------------------------------------------------------------------- 1 | #ifndef INET_H 2 | #define INET_H 3 | /*=========================================================================*\ 4 | * Internet domain functions 5 | * LuaSocket toolkit 6 | * 7 | * This module implements the creation and connection of internet domain 8 | * sockets, on top of the socket.h interface, and the interface of with the 9 | * resolver. 10 | * 11 | * The function inet_aton is provided for the platforms where it is not 12 | * available. The module also implements the interface of the internet 13 | * getpeername and getsockname functions as seen by Lua programs. 14 | * 15 | * The Lua functions toip and tohostname are also implemented here. 16 | * 17 | * RCS ID: $Id: inet.h,v 1.1 2005/07/26 21:06:14 cpressey Exp $ 18 | \*=========================================================================*/ 19 | #include 20 | #include "socket.h" 21 | #include "timeout.h" 22 | 23 | #ifdef _WIN32 24 | #define INET_ATON 25 | #endif 26 | 27 | int inet_open(lua_State *L); 28 | 29 | const char *inet_trycreate(p_sock ps, int type); 30 | const char *inet_tryconnect(p_sock ps, const char *address, 31 | unsigned short port, p_tm tm); 32 | const char *inet_trybind(p_sock ps, const char *address, 33 | unsigned short port); 34 | 35 | int inet_meth_getpeername(lua_State *L, p_sock ps); 36 | int inet_meth_getsockname(lua_State *L, p_sock ps); 37 | 38 | #ifdef INET_ATON 39 | int inet_aton(const char *cp, struct in_addr *inp); 40 | #endif 41 | 42 | #endif /* INET_H */ 43 | -------------------------------------------------------------------------------- /lib/lua/luasocket/io.c: -------------------------------------------------------------------------------- 1 | /*=========================================================================*\ 2 | * Input/Output abstraction 3 | * LuaSocket toolkit 4 | * 5 | * RCS ID: $Id: io.c,v 1.1 2005/07/26 21:06:14 cpressey Exp $ 6 | \*=========================================================================*/ 7 | #include "io.h" 8 | 9 | /*=========================================================================*\ 10 | * Exported functions 11 | \*=========================================================================*/ 12 | /*-------------------------------------------------------------------------*\ 13 | * Initializes C structure 14 | \*-------------------------------------------------------------------------*/ 15 | void io_init(p_io io, p_send send, p_recv recv, p_error error, void *ctx) { 16 | io->send = send; 17 | io->recv = recv; 18 | io->error = error; 19 | io->ctx = ctx; 20 | } 21 | 22 | /*-------------------------------------------------------------------------*\ 23 | * I/O error strings 24 | \*-------------------------------------------------------------------------*/ 25 | const char *io_strerror(int err) { 26 | switch (err) { 27 | case IO_DONE: return NULL; 28 | case IO_CLOSED: return "closed"; 29 | case IO_TIMEOUT: return "timeout"; 30 | case IO_CLIPPED: return "clipped"; 31 | default: return "unknown error"; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /lib/lua/luasocket/io.h: -------------------------------------------------------------------------------- 1 | #ifndef IO_H 2 | #define IO_H 3 | /*=========================================================================*\ 4 | * Input/Output abstraction 5 | * LuaSocket toolkit 6 | * 7 | * This module defines the interface that LuaSocket expects from the 8 | * transport layer for streamed input/output. The idea is that if any 9 | * transport implements this interface, then the buffer.c functions 10 | * automatically work on it. 11 | * 12 | * The module socket.h implements this interface, and thus the module tcp.h 13 | * is very simple. 14 | * 15 | * RCS ID: $Id: io.h,v 1.1 2005/07/26 21:06:14 cpressey Exp $ 16 | \*=========================================================================*/ 17 | #include 18 | #include 19 | 20 | #include "timeout.h" 21 | 22 | /* IO error codes */ 23 | enum { 24 | IO_DONE = 0, /* operation completed successfully */ 25 | IO_TIMEOUT = -1, /* operation timed out */ 26 | IO_CLOSED = -2, /* the connection has been closed */ 27 | IO_CLIPPED = -3, /* maxium bytes count reached */ 28 | IO_UNKNOWN = -4 29 | }; 30 | 31 | /* interface to error message function */ 32 | typedef const char *(*p_error) ( 33 | void *ctx, /* context needed by send */ 34 | int err /* error code */ 35 | ); 36 | 37 | /* interface to send function */ 38 | typedef int (*p_send) ( 39 | void *ctx, /* context needed by send */ 40 | const char *data, /* pointer to buffer with data to send */ 41 | size_t count, /* number of bytes to send from buffer */ 42 | size_t *sent, /* number of bytes sent uppon return */ 43 | p_tm tm /* timeout control */ 44 | ); 45 | 46 | /* interface to recv function */ 47 | typedef int (*p_recv) ( 48 | void *ctx, /* context needed by recv */ 49 | char *data, /* pointer to buffer where data will be writen */ 50 | size_t count, /* number of bytes to receive into buffer */ 51 | size_t *got, /* number of bytes received uppon return */ 52 | p_tm tm /* timeout control */ 53 | ); 54 | 55 | /* IO driver definition */ 56 | typedef struct t_io_ { 57 | void *ctx; /* context needed by send/recv */ 58 | p_send send; /* send function pointer */ 59 | p_recv recv; /* receive function pointer */ 60 | p_error error; /* strerror function */ 61 | } t_io; 62 | typedef t_io *p_io; 63 | 64 | void io_init(p_io io, p_send send, p_recv recv, p_error error, void *ctx); 65 | const char *io_strerror(int err); 66 | 67 | #endif /* IO_H */ 68 | 69 | -------------------------------------------------------------------------------- /lib/lua/luasocket/lua/README: -------------------------------------------------------------------------------- 1 | This directory contains the implementation of the protocols FTP, HTTP 2 | and SMTP, the URL parsing and composition module, MIME and LTN12 modules. 3 | The files provided are: 4 | 5 | socket.lua -- Core library loader 6 | 7 | The module socket.lua is the loader for the C core of LuaSocket. 8 | It also provides some shortcut routines. 9 | 10 | ltn12.lua -- LTN12 implementation 11 | 12 | The module ltn12.lua provides routines that implement the concepts 13 | introduced by LTN012. 14 | 15 | mime.lua -- part of the MIME standard 16 | 17 | The module mime.lua provides routines that implement common operations 18 | defined in the MIME standard. 19 | 20 | http.lua -- HTTP protocol implementation 21 | 22 | The module http.lua provides general HTTP client support. 23 | 24 | smtp.lua -- SMTP protocol implementation 25 | 26 | The module smtp.lua provides functionality to send e-mail messages to a 27 | SMTP mail server. Support is also provided to send multipart messages. 28 | 29 | ftp.lua -- FTP protocol implementation 30 | 31 | The module ftp.lua provides functions to download and upload files from 32 | and to FTP servers. 33 | 34 | tp.lua -- FTP/SMTP/DICT subsystem 35 | 36 | The module tp.lua provides a common subsystem over which the FTP/SMTP/DICT 37 | support is built. 38 | 39 | url.lua -- URL parsing and composition 40 | 41 | The module url.lua provides routines to split a URL into its components 42 | and to compose a base URL and relative URL into an absolute URL. 43 | 44 | These modules are part of the LuaSocket library and are supported. 45 | Please send any comments to the Lua List and I will hear. 46 | 47 | Good luck, 48 | Diego. 49 | -------------------------------------------------------------------------------- /lib/lua/luasocket/lua/mime.lua: -------------------------------------------------------------------------------- 1 | ----------------------------------------------------------------------------- 2 | -- MIME support for the Lua language. 3 | -- Author: Diego Nehab 4 | -- Conforming to RFCs 2045-2049 5 | -- RCS ID: $Id: mime.lua,v 1.1 2005/07/26 21:06:14 cpressey Exp $ 6 | ----------------------------------------------------------------------------- 7 | 8 | ----------------------------------------------------------------------------- 9 | -- Declare module and import dependencies 10 | ----------------------------------------------------------------------------- 11 | local base = require("base") 12 | local ltn12 = require("ltn12") 13 | local mime = require("lmime") 14 | module("mime") 15 | 16 | -- encode, decode and wrap algorithm tables 17 | mime.encodet = {} 18 | mime.decodet = {} 19 | mime.wrapt = {} 20 | 21 | -- creates a function that chooses a filter by name from a given table 22 | local function choose(table) 23 | return function(name, opt1, opt2) 24 | if base.type(name) ~= "string" then 25 | name, opt1, opt2 = "default", name, opt1 26 | end 27 | local f = table[name or "nil"] 28 | if not f then error("unknown key (" .. base.tostring(name) .. ")", 3) 29 | else return f(opt1, opt2) end 30 | end 31 | end 32 | 33 | -- define the encoding filters 34 | mime.encodet['base64'] = function() 35 | return ltn12.filter.cycle(b64, "") 36 | end 37 | 38 | mime.encodet['quoted-printable'] = function(mode) 39 | return ltn12.filter.cycle(qp, "", 40 | (mode == "binary") and "=0D=0A" or "\r\n") 41 | end 42 | 43 | -- define the decoding filters 44 | mime.decodet['base64'] = function() 45 | return ltn12.filter.cycle(unb64, "") 46 | end 47 | 48 | mime.decodet['quoted-printable'] = function() 49 | return ltn12.filter.cycle(unqp, "") 50 | end 51 | 52 | local io, string = io, string 53 | 54 | local function format(chunk) 55 | if chunk then 56 | if chunk == "" then return "''" 57 | else return string.len(chunk) end 58 | else return "nil" end 59 | end 60 | 61 | -- define the line-wrap filters 62 | mime.wrapt['text'] = function(length) 63 | length = length or 76 64 | return ltn12.filter.cycle(wrp, length, length) 65 | end 66 | mime.wrapt['base64'] = wrapt['text'] 67 | mime.wrapt['default'] = wrapt['text'] 68 | 69 | mime.wrapt['quoted-printable'] = function() 70 | return ltn12.filter.cycle(qpwrp, 76, 76) 71 | end 72 | 73 | -- function that choose the encoding, decoding or wrap algorithm 74 | mime.encode = choose(encodet) 75 | mime.decode = choose(decodet) 76 | mime.wrap = choose(wrapt) 77 | 78 | -- define the end-of-line normalization filter 79 | function mime.normalize(marker) 80 | return ltn12.filter.cycle(eol, 0, marker) 81 | end 82 | 83 | -- high level stuffing filter 84 | function mime.stuff() 85 | return ltn12.filter.cycle(dot, 2) 86 | end 87 | 88 | --getmetatable(_M).__index = nil 89 | -------------------------------------------------------------------------------- /lib/lua/luasocket/luasocket.h: -------------------------------------------------------------------------------- 1 | #ifndef LUASOCKET_H 2 | #define LUASOCKET_H 3 | /*=========================================================================*\ 4 | * LuaSocket toolkit 5 | * Networking support for the Lua language 6 | * Diego Nehab 7 | * 9/11/1999 8 | * 9 | * RCS ID: $Id: luasocket.h,v 1.1 2005/07/26 21:06:14 cpressey Exp $ 10 | \*=========================================================================*/ 11 | #include 12 | 13 | /*-------------------------------------------------------------------------*\ 14 | * Current luasocket version 15 | \*-------------------------------------------------------------------------*/ 16 | #define LUASOCKET_VERSION "LuaSocket 2.0 (beta3)" 17 | #define LUASOCKET_COPYRIGHT "Copyright (C) 2004-2005 Diego Nehab" 18 | #define LUASOCKET_AUTHORS "Diego Nehab" 19 | 20 | /*-------------------------------------------------------------------------*\ 21 | * This macro prefixes all exported API functions 22 | \*-------------------------------------------------------------------------*/ 23 | #ifndef LUASOCKET_API 24 | #define LUASOCKET_API extern 25 | #endif 26 | 27 | /*-------------------------------------------------------------------------*\ 28 | * Initializes the library. 29 | \*-------------------------------------------------------------------------*/ 30 | LUASOCKET_API int luaopen_socket(lua_State *L); 31 | 32 | #endif /* LUASOCKET_H */ 33 | -------------------------------------------------------------------------------- /lib/lua/luasocket/mime.h: -------------------------------------------------------------------------------- 1 | #ifndef MIME_H 2 | #define MIME_H 3 | /*=========================================================================*\ 4 | * MIME support functions 5 | * LuaSocket toolkit 6 | * 7 | * This module provides functions to implement transfer content encodings 8 | * and formatting conforming to RFC 2045. It is used by mime.lua, which 9 | * provide a higher level interface to this functionality. 10 | * 11 | * RCS ID: $Id: mime.h,v 1.1 2005/07/26 21:06:14 cpressey Exp $ 12 | \*=========================================================================*/ 13 | #include 14 | 15 | /*-------------------------------------------------------------------------*\ 16 | * This macro prefixes all exported API functions 17 | \*-------------------------------------------------------------------------*/ 18 | #ifndef MIME_API 19 | #define MIME_API extern 20 | #endif 21 | 22 | MIME_API int luaopen_mime(lua_State *L); 23 | 24 | #endif /* MIME_H */ 25 | -------------------------------------------------------------------------------- /lib/lua/luasocket/options.h: -------------------------------------------------------------------------------- 1 | #ifndef OPTIONS_H 2 | #define OPTIONS_H 3 | /*=========================================================================*\ 4 | * Common option interface 5 | * LuaSocket toolkit 6 | * 7 | * This module provides a common interface to socket options, used mainly by 8 | * modules UDP and TCP. 9 | * 10 | * RCS ID: $Id: options.h,v 1.1 2005/07/26 21:06:14 cpressey Exp $ 11 | \*=========================================================================*/ 12 | 13 | #include 14 | #include "socket.h" 15 | 16 | /* option registry */ 17 | typedef struct t_opt { 18 | const char *name; 19 | int (*func)(lua_State *L, p_sock ps); 20 | } t_opt; 21 | typedef t_opt *p_opt; 22 | 23 | /* supported options */ 24 | int opt_dontroute(lua_State *L, p_sock ps); 25 | int opt_broadcast(lua_State *L, p_sock ps); 26 | int opt_reuseaddr(lua_State *L, p_sock ps); 27 | int opt_tcp_nodelay(lua_State *L, p_sock ps); 28 | int opt_keepalive(lua_State *L, p_sock ps); 29 | int opt_linger(lua_State *L, p_sock ps); 30 | int opt_reuseaddr(lua_State *L, p_sock ps); 31 | int opt_ip_multicast_ttl(lua_State *L, p_sock ps); 32 | int opt_ip_multicast_loop(lua_State *L, p_sock ps); 33 | int opt_ip_add_membership(lua_State *L, p_sock ps); 34 | int opt_ip_drop_membersip(lua_State *L, p_sock ps); 35 | 36 | /* invokes the appropriate option handler */ 37 | int opt_meth_setoption(lua_State *L, p_opt opt, p_sock ps); 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /lib/lua/luasocket/select.h: -------------------------------------------------------------------------------- 1 | #ifndef SELECT_H 2 | #define SELECT_H 3 | /*=========================================================================*\ 4 | * Select implementation 5 | * LuaSocket toolkit 6 | * 7 | * Each object that can be passed to the select function has to export 8 | * method getfd() which returns the descriptor to be passed to the 9 | * underlying select function. Another method, dirty(), should return 10 | * true if there is data ready for reading (required for buffered input). 11 | * 12 | * RCS ID: $Id: select.h,v 1.1 2005/07/26 21:06:14 cpressey Exp $ 13 | \*=========================================================================*/ 14 | 15 | int select_open(lua_State *L); 16 | 17 | #endif /* SELECT_H */ 18 | -------------------------------------------------------------------------------- /lib/lua/luasocket/socket.h: -------------------------------------------------------------------------------- 1 | #ifndef SOCK_H 2 | #define SOCK_H 3 | /*=========================================================================*\ 4 | * Socket compatibilization module 5 | * LuaSocket toolkit 6 | * 7 | * BSD Sockets and WinSock are similar, but there are a few irritating 8 | * differences. Also, not all *nix platforms behave the same. This module 9 | * (and the associated usocket.h and wsocket.h) factor these differences and 10 | * creates a interface compatible with the io.h module. 11 | * 12 | * RCS ID: $Id: socket.h,v 1.1 2005/07/26 21:06:14 cpressey Exp $ 13 | \*=========================================================================*/ 14 | #include "io.h" 15 | 16 | /*=========================================================================*\ 17 | * Platform specific compatibilization 18 | \*=========================================================================*/ 19 | #ifdef _WIN32 20 | #include "wsocket.h" 21 | #else 22 | #include "usocket.h" 23 | #endif 24 | 25 | /*=========================================================================*\ 26 | * The connect and accept functions accept a timeout and their 27 | * implementations are somewhat complicated. We chose to move 28 | * the timeout control into this module for these functions in 29 | * order to simplify the modules that use them. 30 | \*=========================================================================*/ 31 | #include "timeout.h" 32 | 33 | /* we are lazy... */ 34 | typedef struct sockaddr SA; 35 | 36 | /*=========================================================================*\ 37 | * Functions bellow implement a comfortable platform independent 38 | * interface to sockets 39 | \*=========================================================================*/ 40 | int sock_open(void); 41 | int sock_close(void); 42 | void sock_destroy(p_sock ps); 43 | void sock_shutdown(p_sock ps, int how); 44 | int sock_sendto(p_sock ps, const char *data, size_t count, 45 | size_t *sent, SA *addr, socklen_t addr_len, p_tm tm); 46 | int sock_recvfrom(p_sock ps, char *data, size_t count, 47 | size_t *got, SA *addr, socklen_t *addr_len, p_tm tm); 48 | void sock_setnonblocking(p_sock ps); 49 | void sock_setblocking(p_sock ps); 50 | int sock_select(int n, fd_set *rfds, fd_set *wfds, fd_set *efds, p_tm tm); 51 | 52 | int sock_connect(p_sock ps, SA *addr, socklen_t addr_len, p_tm tm); 53 | int sock_create(p_sock ps, int domain, int type, int protocol); 54 | int sock_bind(p_sock ps, SA *addr, socklen_t addr_len); 55 | int sock_listen(p_sock ps, int backlog); 56 | int sock_accept(p_sock ps, p_sock pa, SA *addr, socklen_t *addr_len, p_tm tm); 57 | 58 | const char *sock_hoststrerror(int err); 59 | const char *sock_strerror(int err); 60 | 61 | /* these are perfect to use with the io abstraction module 62 | and the buffered input module */ 63 | int sock_send(p_sock ps, const char *data, size_t count, size_t *sent, p_tm tm); 64 | int sock_recv(p_sock ps, char *data, size_t count, size_t *got, p_tm tm); 65 | const char *sock_ioerror(p_sock ps, int err); 66 | 67 | int sock_gethostbyaddr(const char *addr, socklen_t len, struct hostent **hp); 68 | int sock_gethostbyname(const char *addr, struct hostent **hp); 69 | 70 | #endif /* SOCK_H */ 71 | -------------------------------------------------------------------------------- /lib/lua/luasocket/tcp.h: -------------------------------------------------------------------------------- 1 | #ifndef TCP_H 2 | #define TCP_H 3 | /*=========================================================================*\ 4 | * TCP object 5 | * LuaSocket toolkit 6 | * 7 | * The tcp.h module is basicly a glue that puts together modules buffer.h, 8 | * timeout.h socket.h and inet.h to provide the LuaSocket TCP (AF_INET, 9 | * SOCK_STREAM) support. 10 | * 11 | * Three classes are defined: master, client and server. The master class is 12 | * a newly created tcp object, that has not been bound or connected. Server 13 | * objects are tcp objects bound to some local address. Client objects are 14 | * tcp objects either connected to some address or returned by the accept 15 | * method of a server object. 16 | * 17 | * RCS ID: $Id: tcp.h,v 1.1 2005/07/26 21:06:14 cpressey Exp $ 18 | \*=========================================================================*/ 19 | #include 20 | 21 | #include "buffer.h" 22 | #include "timeout.h" 23 | #include "socket.h" 24 | 25 | typedef struct t_tcp_ { 26 | t_sock sock; 27 | t_io io; 28 | t_buf buf; 29 | t_tm tm; 30 | } t_tcp; 31 | 32 | typedef t_tcp *p_tcp; 33 | 34 | int tcp_open(lua_State *L); 35 | 36 | #endif /* TCP_H */ 37 | -------------------------------------------------------------------------------- /lib/lua/luasocket/timeout.h: -------------------------------------------------------------------------------- 1 | #ifndef TM_H 2 | #define TM_H 3 | /*=========================================================================*\ 4 | * Timeout management functions 5 | * LuaSocket toolkit 6 | * 7 | * RCS ID: $Id: timeout.h,v 1.1 2005/07/26 21:06:14 cpressey Exp $ 8 | \*=========================================================================*/ 9 | #include 10 | 11 | /* timeout control structure */ 12 | typedef struct t_tm_ { 13 | double total; /* total number of miliseconds for operation */ 14 | double block; /* maximum time for blocking calls */ 15 | double start; /* time of start of operation */ 16 | } t_tm; 17 | typedef t_tm *p_tm; 18 | 19 | int tm_open(lua_State *L); 20 | void tm_init(p_tm tm, double block, double total); 21 | double tm_get(p_tm tm); 22 | double tm_getretry(p_tm tm); 23 | p_tm tm_markstart(p_tm tm); 24 | double tm_getstart(p_tm tm); 25 | double tm_gettime(void); 26 | int tm_meth_settimeout(lua_State *L, p_tm tm); 27 | 28 | #define tm_iszero(tm) ((tm)->block == 0.0) 29 | 30 | #endif /* TM_H */ 31 | -------------------------------------------------------------------------------- /lib/lua/luasocket/udp.h: -------------------------------------------------------------------------------- 1 | #ifndef UDP_H 2 | #define UDP_H 3 | /*=========================================================================*\ 4 | * UDP object 5 | * LuaSocket toolkit 6 | * 7 | * The udp.h module provides LuaSocket with support for UDP protocol 8 | * (AF_INET, SOCK_DGRAM). 9 | * 10 | * Two classes are defined: connected and unconnected. UDP objects are 11 | * originally unconnected. They can be "connected" to a given address 12 | * with a call to the setpeername function. The same function can be used to 13 | * break the connection. 14 | * 15 | * RCS ID: $Id: udp.h,v 1.1 2005/07/26 21:06:14 cpressey Exp $ 16 | \*=========================================================================*/ 17 | #include 18 | 19 | #include "timeout.h" 20 | #include "socket.h" 21 | 22 | /* can't be larger than wsocket.c MAXCHUNK!!! */ 23 | #define UDP_DATAGRAMSIZE 8192 24 | 25 | typedef struct t_udp_ { 26 | t_sock sock; 27 | t_tm tm; 28 | } t_udp; 29 | typedef t_udp *p_udp; 30 | 31 | int udp_open(lua_State *L); 32 | 33 | #endif /* UDP_H */ 34 | -------------------------------------------------------------------------------- /lib/lua/luasocket/usocket.h: -------------------------------------------------------------------------------- 1 | #ifndef USOCKET_H 2 | #define USOCKET_H 3 | /*=========================================================================*\ 4 | * Socket compatibilization module for Unix 5 | * LuaSocket toolkit 6 | * 7 | * RCS ID: $Id: usocket.h,v 1.1 2005/07/26 21:06:14 cpressey Exp $ 8 | \*=========================================================================*/ 9 | 10 | /*=========================================================================*\ 11 | * BSD include files 12 | \*=========================================================================*/ 13 | /* error codes */ 14 | #include 15 | /* close function */ 16 | #include 17 | /* fnctnl function and associated constants */ 18 | #include 19 | /* struct sockaddr */ 20 | #include 21 | /* socket function */ 22 | #include 23 | /* struct timeval */ 24 | #include 25 | /* gethostbyname and gethostbyaddr functions */ 26 | #include 27 | /* sigpipe handling */ 28 | #include 29 | /* IP stuff*/ 30 | #include 31 | #include 32 | /* TCP options (nagle algorithm disable) */ 33 | #include 34 | 35 | typedef int t_sock; 36 | typedef t_sock *p_sock; 37 | 38 | #define SOCK_INVALID (-1) 39 | 40 | #endif /* USOCKET_H */ 41 | -------------------------------------------------------------------------------- /lib/lua/luasocket/wsocket.h: -------------------------------------------------------------------------------- 1 | #ifndef WSOCKET_H 2 | #define WSOCKET_H 3 | /*=========================================================================*\ 4 | * Socket compatibilization module for Win32 5 | * LuaSocket toolkit 6 | * 7 | * RCS ID: $Id: wsocket.h,v 1.1 2005/07/26 21:06:14 cpressey Exp $ 8 | \*=========================================================================*/ 9 | 10 | /*=========================================================================*\ 11 | * WinSock include files 12 | \*=========================================================================*/ 13 | #include 14 | 15 | typedef int socklen_t; 16 | typedef SOCKET t_sock; 17 | typedef t_sock *p_sock; 18 | 19 | #define SOCK_INVALID (INVALID_SOCKET) 20 | 21 | #endif /* WSOCKET_H */ 22 | -------------------------------------------------------------------------------- /lib/lua/posix/Makefile: -------------------------------------------------------------------------------- 1 | # makefile for POSIX library for Lua 2 | 3 | BASE?=../../.. 4 | include ${BASE}/Config 5 | 6 | # change these to reflect your Lua installation 7 | LUA= ../../../lua 8 | LUAINC= $(LUA)/include 9 | LUALIB= $(LUA)/lib 10 | LUABIN= $(LUA)/bin 11 | 12 | COMPAT=../compat-5.1 13 | 14 | MYNAME= posix 15 | MYLIB= l$(MYNAME) 16 | 17 | # no need to change anything below here 18 | CFLAGS+= -fPIC -O2 -pedantic -Wall -I$(LUAINC) 19 | LDFLAGS+=-L$(LUALIB) -L/usr/local/lib -llua50 -llualib50 20 | 21 | OBJS= $(MYLIB).o 22 | 23 | T= $(MYLIB).so 24 | 25 | all: $T 26 | 27 | strip: 28 | strip $T 29 | 30 | $T: $(OBJS) 31 | $(CC) -fPIC $(OBJS) $(COMPAT)/compat-5.1.o -shared $(LDFLAGS) -o $@ 32 | 33 | $(OBJS): modemuncher.c 34 | 35 | clean: 36 | rm -f $(OBJS) $T core core.* a.out 37 | 38 | x: 39 | @echo "$(MYNAME) library:" 40 | @grep '},' $(MYLIB).c | cut -f2 | tr -d '{",' | sort | column 41 | 42 | xx: 43 | @echo "$(MYNAME) library:" 44 | @fgrep '/**' $(MYLIB).c | cut -f2 -d/ | tr -d '*' | sort | column 45 | 46 | # distribution 47 | 48 | install: strip 49 | mkdir -p $(DESTDIR)${PREFIX}/lib/lua/5.0 50 | cp $T $(DESTDIR)${PREFIX}/lib/lua/5.0 51 | mkdir -p ${DESTDIR}${PREFIX}/share/lua/5.0 52 | cp posix.lua ${DESTDIR}${PREFIX}/share/lua/5.0 53 | 54 | # eof 55 | -------------------------------------------------------------------------------- /lib/lua/posix/README: -------------------------------------------------------------------------------- 1 | This is a POSIX library for Lua 5.0. 2 | 3 | To try this Lua library, edit Makefile to reflect your installation of Lua. 4 | Then run make. This will build lposix.so and run a simple test. If everything 5 | is ok, install lposix.so and posix.lua in some official place. You may want 6 | to edit posix.lua to change the default value of SOPATH (you can also set the 7 | environment variable LUA_SOPATH at run time). 8 | 9 | Here is a brief explanation of the files in this package: 10 | lposix.c posix library 11 | posix.lua support code 12 | test.lua test code 13 | tree.lua tree view of the file system 14 | 15 | The only documentation is the reference manual written by Claudio Terra for 16 | the original release of poslib. See 17 | http://www.soho-one.com/software/poslib/ 18 | This text is now outdated, because new functions have been added and some of 19 | the semantics have changed. For updated documentation, read the code :-) and 20 | a POSIX manual. I used this online reference for POSIX: 21 | http://www.opengroup.org/onlinepubs/007904875/toc.htm 22 | To see a summary of what is exported to Lua, do "make xx". The examples in 23 | test.lua and tree.lua show the library in action. 24 | 25 | This code is hereby placed in the public domain. 26 | Please send comments, suggestions, and bug reports to lhf@tecgraf.puc-rio.br . 27 | -------------------------------------------------------------------------------- /lib/lua/posix/posix.lua: -------------------------------------------------------------------------------- 1 | -- posix.lua 2 | -- support code for posix library 3 | -- usage lua -lposix ... 4 | 5 | module("posix") 6 | 7 | require "lposix" 8 | 9 | return posix 10 | -------------------------------------------------------------------------------- /lib/lua/pty/Makefile: -------------------------------------------------------------------------------- 1 | # $Id: Makefile,v 1.11 2005/08/26 22:44:38 cpressey Exp $ 2 | 3 | BASE?=../../.. 4 | include ${BASE}/Config 5 | 6 | LUA?=../../../lua 7 | 8 | COMPAT?=../compat-5.1 9 | 10 | CFLAGS+= ${WARNS} -fPIC -I../ -I${LUA}/include -I/usr/local/include 11 | LDFLAGS+= -L${LUA}/lib -L/usr/local/lib -lutil -lm -llua50 -llualib50 12 | 13 | LIB= lpty.so 14 | OBJS= pty.o 15 | 16 | all: ${LIB} 17 | 18 | strip: 19 | strip ${LIB} 20 | 21 | ${LIB}: ${OBJS} 22 | ${CC} ${OBJS} ${COMPAT}/compat-5.1.o -shared ${LDFLAGS} -o ${LIB} 23 | 24 | pty.o: pty.c 25 | ${CC} ${CFLAGS} -c pty.c -o pty.o 26 | 27 | clean: 28 | rm -rf *.so *.o 29 | 30 | install: strip 31 | mkdir -p ${DESTDIR}${PREFIX}/lib/lua/5.0 32 | cp ${LIB} ${DESTDIR}${PREFIX}/lib/lua/5.0 33 | mkdir -p ${DESTDIR}${PREFIX}/share/lua/5.0 34 | cp pty.lua ${DESTDIR}${PREFIX}/share/lua/5.0 35 | -------------------------------------------------------------------------------- /lib/lua/pty/pty.lua: -------------------------------------------------------------------------------- 1 | -- $Id: pty.lua,v 1.2 2005/08/13 20:00:40 cpressey Exp $ 2 | -- Lua wrapper functions for Lua 5.0.x Pty (pseudo-terminal) binding. 3 | 4 | module("pty") 5 | 6 | Pty = require("lpty") 7 | 8 | --[[------------]]-- 9 | --[[ Pty.Logged ]]-- 10 | --[[------------]]-- 11 | 12 | -- 13 | -- Wraps a plain Pty by adding a logging function callback. 14 | -- 15 | 16 | Pty.Logged = {} 17 | Pty.Logged.open = function(command, log_fn) 18 | local method = {} -- instance 19 | local pty = Pty.open(command) 20 | 21 | if not pty then 22 | log_fn("WARNING: could not open pty to '" .. command .. "'") 23 | return nil 24 | end 25 | 26 | log_fn(",- opened pty to '" .. command .. "'") 27 | 28 | method.readline = function(self) 29 | local line = pty:readline() 30 | if line then 31 | log_fn("< " .. line) 32 | else 33 | log_fn("( EOF )") 34 | end 35 | return line 36 | end 37 | 38 | method.write = function(self, str) 39 | log_fn("> " .. str) 40 | return pty:write(str) 41 | end 42 | 43 | method.flush = function(self) 44 | return pty:flush() 45 | end 46 | 47 | method.signal = function(self, sig) 48 | return pty:signal(sig) 49 | end 50 | 51 | method.close = function(self) 52 | log_fn("`- closed pty to '" .. command .. "'") 53 | return pty:close() 54 | end 55 | 56 | return method 57 | end 58 | 59 | return Pty 60 | -------------------------------------------------------------------------------- /lib/lua/transceiver/Makefile: -------------------------------------------------------------------------------- 1 | # $Id: Makefile,v 1.11 2005/08/26 22:44:38 cpressey Exp $ 2 | 3 | BASE?=../../.. 4 | include ${BASE}/Config 5 | 6 | all: 7 | clean: 8 | 9 | install: 10 | mkdir -p ${DESTDIR}${PREFIX}/share/lua/5.0 11 | cp transceiver.lua ${DESTDIR}${PREFIX}/share/lua/5.0 12 | -------------------------------------------------------------------------------- /lua/COPYRIGHT: -------------------------------------------------------------------------------- 1 | Lua License 2 | ----------- 3 | 4 | Lua is licensed under the terms of the MIT license reproduced below. 5 | This means that Lua is free software and can be used for both academic 6 | and commercial purposes at absolutely no cost. 7 | 8 | For details and rationale, see http://www.lua.org/license.html . 9 | 10 | =============================================================================== 11 | 12 | Copyright (C) 2003-2004 Tecgraf, PUC-Rio. 13 | 14 | Permission is hereby granted, free of charge, to any person obtaining a copy 15 | of this software and associated documentation files (the "Software"), to deal 16 | in the Software without restriction, including without limitation the rights 17 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 18 | copies of the Software, and to permit persons to whom the Software is 19 | furnished to do so, subject to the following conditions: 20 | 21 | The above copyright notice and this permission notice shall be included in 22 | all copies or substantial portions of the Software. 23 | 24 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 25 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 26 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 27 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 28 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 29 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 30 | THE SOFTWARE. 31 | 32 | =============================================================================== 33 | 34 | (end of COPYRIGHT) 35 | -------------------------------------------------------------------------------- /lua/INSTALL: -------------------------------------------------------------------------------- 1 | This is Lua 5.0. 2 | 3 | * Installation 4 | ------------ 5 | Building Lua on a Unix system should be very easy: 6 | 7 | 1. Read "config" and edit it to suit your platform and needs. 8 | We strongly recommend that you enable support for dynamic loading, 9 | if your platform allows it. 10 | 2. Do "make". 11 | 3. If you want to install Lua in an "official" place in your system, 12 | then do "make install". The official place and the way to install 13 | files are defined in "config". You may have to be root to do this. 14 | 15 | See below for instructions for Windows and other systems. 16 | 17 | * What you get 18 | ------------ 19 | If "make" succeeds, you get: 20 | * an interpreter in ./bin/lua and a compiler in ./bin/luac; 21 | * libraries in ./lib; 22 | * include files in ./include. 23 | These are the only directories you need for development. 24 | 25 | There are man pages for lua and luac, in both nroff and html; a reference 26 | manual in html in ./doc, some sample code in ./test, and some useful stuff 27 | in ./etc. You don't need these directories for development. 28 | 29 | See also the README files in the various subdirectories. 30 | A convenient starting point is ./doc/readme.html. 31 | 32 | * If you have problems (and solutions!) 33 | ------------------------------------- 34 | If "make" fails, please let us know (lua@tecgraf.puc-rio.br). 35 | If you make changes to "config" or to the Makefiles, please send them to us. 36 | 37 | * Shared libraries 38 | ---------------- 39 | If you are running Linux, do "make so" after "make" succeeds. 40 | This will create shared libraries in ./lib. 41 | To install those shared libraries in an official place, do "make soinstall". 42 | 43 | If you want the interpreter and the compiler to use shared libraries, 44 | then do "make sobin" too. You may want to do this before "make install". 45 | 46 | If you only want the shared libraries, you may want to add -fPIC to MYCFLAGS 47 | in "config". Also, you may need to run "ldconfig" as root. 48 | 49 | You may need to include ./lib in the LD_LIBRARY_PATH environment variable 50 | to link programs that use the shared libraries if you don't put them in the 51 | official places with "make install". (You may need to use the full path.) 52 | 53 | Building shared libraries in other systems is similar but details differ; 54 | you may need to fix a few details in the top-level Makefile. 55 | 56 | * Installation on Windows and other systems 57 | ----------------------------------------------------- 58 | The instructions for building Lua on other systems machine depend on the 59 | particular compiler you are using. The simplest way is to create a folder 60 | with all .c and .h files, and then create projects for the core library, 61 | the standard library, the interpreter, and the compiler, as follows: 62 | 63 | core lib: lapi.c lcode.c ldebug.c ldo.c ldump.c lfunc.c lgc.c llex.c 64 | lmem.c lobject.c lopcodes.c lparser.c lstate.c lstring.c 65 | ltable.c ltests.c ltm.c lundump.c lvm.c lzio.c 66 | 67 | standard lib: lauxlib.c lbaselib.c ldblib.c liolib.c lmathlib.c ltablib.c 68 | lstrlib.c loadlib.c 69 | 70 | interpreter: core lib, standard lib, lua.c 71 | 72 | compiler: core lib, standard lib, luac.c print.c 73 | and also lopcodes.c (with LUA_OPNAMES defined) from core. 74 | 75 | Of course, to use Lua as a library, you'll have to know how to create 76 | and use libraries with your compiler. 77 | 78 | Also, read "config" to see what can be customized at compilation time. 79 | 80 | (end of INSTALL) 81 | -------------------------------------------------------------------------------- /lua/Makefile: -------------------------------------------------------------------------------- 1 | # makefile for Lua hierarchy 2 | # see INSTALL for installation instructions 3 | # see config for customization instructions 4 | 5 | BASE=.. 6 | include $(BASE)/Config 7 | 8 | LUA= . 9 | 10 | all: dirs 11 | $(MAKE) -C src all 12 | $(MAKE) -C src/lib all 13 | ld -o lib/liblua50.so -shared -soname liblua50.so src/*.o 14 | ld -o lib/liblualib50.so -shared -soname liblualib50.so src/lib/*.o 15 | $(MAKE) -C src/luac all 16 | $(MAKE) -C src/lua all 17 | 18 | clean: 19 | cd src; $(MAKE) clean 20 | cd src/lib; $(MAKE) clean 21 | cd src/luac; $(MAKE) clean 22 | cd src/lua; $(MAKE) clean 23 | rm -f lib/*.so* bin/* 24 | 25 | # in case they were not created during unpacking 26 | dirs: bin lib 27 | 28 | bin lib: 29 | mkdir -p $@ 30 | 31 | # remove debug information from binaries 32 | strip: 33 | $(STRIP) bin/* lib/*.so* 34 | 35 | # official installation 36 | install: strip 37 | $(INSTALL_EXEC) bin/* $(INSTALL_BIN) 38 | mv $(INSTALL_BIN)/lua $(INSTALL_BIN)/lua50 39 | mv $(INSTALL_BIN)/luac $(INSTALL_BIN)/lua50c 40 | #$(INSTALL_DATA) lib/*.a $(INSTALL_LIB) 41 | $(INSTALL_EXEC) lib/*.so* $(INSTALL_LIB) 42 | 43 | # echo config parameters 44 | echo: 45 | @echo "" 46 | @echo "These are the parameters currently set in $(LUA)/config to build Lua $V:" 47 | @echo "" 48 | @echo "LOADLIB = $(LOADLIB)" 49 | @echo "DLLIB = $(DLLIB)" 50 | @echo "NUMBER = $(NUMBER)" 51 | @echo "POPEN = $(POPEN)" 52 | @echo "TMPNAM = $(TMPNAM)" 53 | @echo "DEGREES = $(DEGREES)" 54 | @echo "USERCONF = $(USERCONF)" 55 | @echo "CC = $(CC)" 56 | @echo "WARN = $(WARN)" 57 | @echo "MYCFLAGS = $(MYCFLAGS)" 58 | @echo "MYLDFLAGS = $(MYLDFLAGS)" 59 | @echo "EXTRA_LIBS = $(EXTRA_LIBS)" 60 | @echo "AR = $(AR)" 61 | @echo "RANLIB = $(RANLIB)" 62 | @echo "STRIP = $(STRIP)" 63 | @echo "INSTALL_ROOT = $(INSTALL_ROOT)" 64 | @echo "INSTALL_BIN = $(INSTALL_BIN)" 65 | @echo "INSTALL_INC = $(INSTALL_INC)" 66 | @echo "INSTALL_LIB = $(INSTALL_LIB)" 67 | @echo "INSTALL_MAN = $(INSTALL_MAN)" 68 | @echo "INSTALL_EXEC = $(INSTALL_EXEC)" 69 | @echo "INSTALL_DATA = $(INSTALL_DATA)" 70 | @echo "" 71 | @echo "Edit $(LUA)/config if needed to suit your platform and then run make." 72 | @echo "" 73 | 74 | # turn config into Lua code 75 | # uncomment the last sed expression if you want nil instead of empty strings 76 | lecho: 77 | @echo "-- $(LUA)/config for Lua $V" 78 | @echo "VERSION = '$(V)'" 79 | @make echo | grep = | sed -e 's/= /= "/' -e 's/$$/"/' #-e 's/""/nil/' 80 | @echo "-- EOF" 81 | 82 | newer: 83 | @find . -newer MANIFEST -type f 84 | -------------------------------------------------------------------------------- /lua/README: -------------------------------------------------------------------------------- 1 | This is Lua 5.0. 2 | See HISTORY for a summary of changes since the last released version. 3 | 4 | * What is Lua? 5 | ------------ 6 | Lua is a powerful, light-weight programming language designed for extending 7 | applications. Lua is also frequently used as a general-purpose, stand-alone 8 | language. Lua is free software. 9 | 10 | For complete information, visit Lua's web site at http://www.lua.org/ . 11 | For an executive summary, see http://www.lua.org/about.html . 12 | 13 | Lua has been used in many different projects around the world. 14 | For a short list, see http://www.lua.org/uses.html . 15 | 16 | * Availability 17 | ------------ 18 | Lua is freely available for both academic and commercial purposes. 19 | See COPYRIGHT and http://www.lua.org/license.html for details. 20 | Lua can be downloaded from its official site http://www.lua.org/ and 21 | several other sites aroung the world. For a complete list of mirror sites, 22 | see http://www.lua.org/mirrors.html . 23 | 24 | * Installation 25 | ------------ 26 | Lua is implemented in pure ANSI C, and compiles unmodified in all known 27 | platforms that have an ANSI C compiler. Under Unix, simply typing "make" 28 | should work. See INSTALL for detailed instructions. 29 | 30 | * Contacting the authors 31 | ---------------------- 32 | Send your comments, questions, and bug reports to lua@tecgraf.puc-rio.br. 33 | For more information about the authors, see http://www.lua.org/authors.html . 34 | For reporting bugs, try also the mailing list: lua-l@tecgraf.puc-rio.br. 35 | For more information about this list, including instructions on how to 36 | subscribe and access the archives, see http://www.lua.org/lua-l.html . 37 | 38 | * Origin 39 | ------ 40 | Lua is developed at Tecgraf, the Computer Graphics Technology Group 41 | of PUC-Rio (the Pontifical Catholic University of Rio de Janeiro in Brazil). 42 | Tecgraf is a laboratory of the Department of Computer Science. 43 | 44 | (end of README) 45 | -------------------------------------------------------------------------------- /lua/UPDATE: -------------------------------------------------------------------------------- 1 | This is Lua 5.0.2, an update of Lua 5.0 that includes the following changes, 2 | which fix all known bugs in Lua 5.0. For the exact differences, see DIFFS. 3 | 4 | src/ldo.c 5 | Attempt to resume running coroutine crashed Lua 6 | src/lgc.c 7 | C functions also may have stacks larger than current top 8 | Userdata to be collected still counted into new GC threshold 9 | src/lgc.h 10 | Userdata to be collected still counted into new GC threshold 11 | src/lparser.c 12 | Syntax `local function' did not increment stack size 13 | src/lvm.c 14 | `pc' address was invalidated when a coroutine was suspended 15 | Count hook might be called without being set 16 | src/lib/lbaselib.c 17 | Buffer overflow for unusual %p representation 18 | Wrong number of returns from chunks loaded from stdin 19 | src/lib/liolib.c 20 | `file.close()' could not be called without arguments 21 | Buffer overflow for unusual %p representation 22 | src/luac/luac.c 23 | Missing lock/unlock 24 | -------------------------------------------------------------------------------- /lua/build: -------------------------------------------------------------------------------- 1 | # If you don't want to use make, run this script. 2 | # But make sure you read config to see what can be customized. 3 | 4 | 5 | # Easiest way to build bin/lua: 6 | # cc -O2 -o bin/lua -Iinclude -Isrc src/*.c src/lib/*.c src/lua/*.c -lm -ldl 7 | 8 | 9 | # Easiest way to build Lua libraries and executables: 10 | echo -n 'building core library... ' 11 | cd src 12 | cc -O2 -c -I../include *.c 13 | ar rc ../lib/liblua.a *.o 14 | rm -f *.o 15 | 16 | echo -n 'standard library... ' 17 | cd lib 18 | cc -O2 -c -I../../include *.c 19 | ar rc ../../lib/liblualib.a *.o 20 | rm -f *.o 21 | 22 | echo -n 'lua... ' 23 | cd ../lua 24 | cc -O2 -o ../../bin/lua -I../../include *.c ../../lib/*.a -lm -ldl 25 | 26 | echo -n 'luac... ' 27 | cd ../luac 28 | cc -O2 -o ../../bin/luac -I../../include -I.. *.c -DLUA_OPNAMES ../lopcodes.c ../../lib/*.a 29 | 30 | echo 'done' 31 | 32 | cd ../.. 33 | bin/lua test/hello.lua 34 | -------------------------------------------------------------------------------- /lua/configure: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Lua does not use GNU autoconf; just edit ./config if needed to suit your 4 | # platform and then run make. 5 | 6 | # This shows the parameters currently set in ./config: 7 | make echo 8 | 9 | # If you want config as a Lua program, run "make lecho". 10 | -------------------------------------------------------------------------------- /lua/include/lualib.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lualib.h,v 1.1 2005/07/25 21:23:32 cpressey Exp $ 3 | ** Lua standard libraries 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #ifndef lualib_h 9 | #define lualib_h 10 | 11 | #include "lua.h" 12 | 13 | 14 | #ifndef LUALIB_API 15 | #define LUALIB_API LUA_API 16 | #endif 17 | 18 | 19 | #define LUA_COLIBNAME "coroutine" 20 | LUALIB_API int luaopen_base (lua_State *L); 21 | 22 | #define LUA_TABLIBNAME "table" 23 | LUALIB_API int luaopen_table (lua_State *L); 24 | 25 | #define LUA_IOLIBNAME "io" 26 | #define LUA_OSLIBNAME "os" 27 | LUALIB_API int luaopen_io (lua_State *L); 28 | 29 | #define LUA_STRLIBNAME "string" 30 | LUALIB_API int luaopen_string (lua_State *L); 31 | 32 | #define LUA_MATHLIBNAME "math" 33 | LUALIB_API int luaopen_math (lua_State *L); 34 | 35 | #define LUA_DBLIBNAME "debug" 36 | LUALIB_API int luaopen_debug (lua_State *L); 37 | 38 | 39 | LUALIB_API int luaopen_loadlib (lua_State *L); 40 | 41 | 42 | /* to help testing the libraries */ 43 | #ifndef lua_assert 44 | #define lua_assert(c) /* empty */ 45 | #endif 46 | 47 | 48 | /* compatibility code */ 49 | #define lua_baselibopen luaopen_base 50 | #define lua_tablibopen luaopen_table 51 | #define lua_iolibopen luaopen_io 52 | #define lua_strlibopen luaopen_string 53 | #define lua_mathlibopen luaopen_math 54 | #define lua_dblibopen luaopen_debug 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /lua/src/Makefile: -------------------------------------------------------------------------------- 1 | # makefile for Lua core library 2 | 3 | CFLAGS += -fPIC 4 | 5 | BASE=../.. 6 | include $(BASE)/Config 7 | 8 | LUA= .. 9 | 10 | OBJS= \ 11 | lapi.o \ 12 | lcode.o \ 13 | ldebug.o \ 14 | ldo.o \ 15 | ldump.o \ 16 | lfunc.o \ 17 | lgc.o \ 18 | llex.o \ 19 | lmem.o \ 20 | lobject.o \ 21 | lopcodes.o \ 22 | lparser.o \ 23 | lstate.o \ 24 | lstring.o \ 25 | ltable.o \ 26 | ltests.o \ 27 | ltm.o \ 28 | lundump.o \ 29 | lvm.o \ 30 | lzio.o 31 | 32 | SRCS= \ 33 | lapi.c \ 34 | lcode.c \ 35 | ldebug.c \ 36 | ldo.c \ 37 | ldump.c \ 38 | lfunc.c \ 39 | lgc.c \ 40 | llex.c \ 41 | lmem.c \ 42 | lobject.c \ 43 | lopcodes.c \ 44 | lparser.c \ 45 | lstate.c \ 46 | lstring.c \ 47 | ltable.c \ 48 | ltests.c \ 49 | ltm.c \ 50 | lundump.c \ 51 | lvm.c \ 52 | lzio.c \ 53 | lapi.h \ 54 | lcode.h \ 55 | ldebug.h \ 56 | ldo.h \ 57 | lfunc.h \ 58 | lgc.h \ 59 | llex.h \ 60 | llimits.h \ 61 | lmem.h \ 62 | lobject.h \ 63 | lopcodes.h \ 64 | lparser.h \ 65 | lstate.h \ 66 | lstring.h \ 67 | ltable.h \ 68 | ltm.h \ 69 | lundump.h \ 70 | lvm.h \ 71 | lzio.h 72 | 73 | T= $(LIB)/liblua.a 74 | 75 | all: $T 76 | 77 | $T: $(OBJS) 78 | $(AR) rcu $@ $(OBJS) 79 | $(RANLIB) $@ 80 | 81 | clean: 82 | rm -f $(OBJS) $T 83 | 84 | co: 85 | co -q -f -M $(SRCS) 86 | 87 | klean: clean 88 | rm -f $(SRCS) 89 | -------------------------------------------------------------------------------- /lua/src/README: -------------------------------------------------------------------------------- 1 | This is the Lua core. 2 | 3 | The standard Lua library are in lib/. 4 | A sample interpreter is in lua/. 5 | A standalone compiler is in luac/. 6 | -------------------------------------------------------------------------------- /lua/src/lapi.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lapi.h,v 1.1 2005/07/25 21:23:32 cpressey Exp $ 3 | ** Auxiliary functions from Lua API 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lapi_h 8 | #define lapi_h 9 | 10 | 11 | #include "lobject.h" 12 | 13 | 14 | void luaA_pushobject (lua_State *L, const TObject *o); 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /lua/src/lcode.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lcode.h,v 1.1 2005/07/25 21:23:32 cpressey Exp $ 3 | ** Code generator for Lua 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lcode_h 8 | #define lcode_h 9 | 10 | #include "llex.h" 11 | #include "lobject.h" 12 | #include "lopcodes.h" 13 | #include "lparser.h" 14 | 15 | 16 | /* 17 | ** Marks the end of a patch list. It is an invalid value both as an absolute 18 | ** address, and as a list link (would link an element to itself). 19 | */ 20 | #define NO_JUMP (-1) 21 | 22 | 23 | /* 24 | ** grep "ORDER OPR" if you change these enums 25 | */ 26 | typedef enum BinOpr { 27 | OPR_ADD, OPR_SUB, OPR_MULT, OPR_DIV, OPR_POW, 28 | OPR_CONCAT, 29 | OPR_NE, OPR_EQ, 30 | OPR_LT, OPR_LE, OPR_GT, OPR_GE, 31 | OPR_AND, OPR_OR, 32 | OPR_NOBINOPR 33 | } BinOpr; 34 | 35 | #define binopistest(op) ((op) >= OPR_NE) 36 | 37 | typedef enum UnOpr { OPR_MINUS, OPR_NOT, OPR_NOUNOPR } UnOpr; 38 | 39 | 40 | #define getcode(fs,e) ((fs)->f->code[(e)->info]) 41 | 42 | #define luaK_codeAsBx(fs,o,A,sBx) luaK_codeABx(fs,o,A,(sBx)+MAXARG_sBx) 43 | 44 | int luaK_code (FuncState *fs, Instruction i, int line); 45 | int luaK_codeABx (FuncState *fs, OpCode o, int A, unsigned int Bx); 46 | int luaK_codeABC (FuncState *fs, OpCode o, int A, int B, int C); 47 | void luaK_fixline (FuncState *fs, int line); 48 | void luaK_nil (FuncState *fs, int from, int n); 49 | void luaK_reserveregs (FuncState *fs, int n); 50 | void luaK_checkstack (FuncState *fs, int n); 51 | int luaK_stringK (FuncState *fs, TString *s); 52 | int luaK_numberK (FuncState *fs, lua_Number r); 53 | void luaK_dischargevars (FuncState *fs, expdesc *e); 54 | int luaK_exp2anyreg (FuncState *fs, expdesc *e); 55 | void luaK_exp2nextreg (FuncState *fs, expdesc *e); 56 | void luaK_exp2val (FuncState *fs, expdesc *e); 57 | int luaK_exp2RK (FuncState *fs, expdesc *e); 58 | void luaK_self (FuncState *fs, expdesc *e, expdesc *key); 59 | void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k); 60 | void luaK_goiftrue (FuncState *fs, expdesc *e); 61 | void luaK_goiffalse (FuncState *fs, expdesc *e); 62 | void luaK_storevar (FuncState *fs, expdesc *var, expdesc *e); 63 | void luaK_setcallreturns (FuncState *fs, expdesc *var, int nresults); 64 | int luaK_jump (FuncState *fs); 65 | void luaK_patchlist (FuncState *fs, int list, int target); 66 | void luaK_patchtohere (FuncState *fs, int list); 67 | void luaK_concat (FuncState *fs, int *l1, int l2); 68 | int luaK_getlabel (FuncState *fs); 69 | void luaK_prefix (FuncState *fs, UnOpr op, expdesc *v); 70 | void luaK_infix (FuncState *fs, BinOpr op, expdesc *v); 71 | void luaK_posfix (FuncState *fs, BinOpr op, expdesc *v1, expdesc *v2); 72 | 73 | 74 | #endif 75 | -------------------------------------------------------------------------------- /lua/src/ldebug.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ldebug.h,v 1.1 2005/07/25 21:23:32 cpressey Exp $ 3 | ** Auxiliary functions from Debug Interface module 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ldebug_h 8 | #define ldebug_h 9 | 10 | 11 | #include "lstate.h" 12 | 13 | 14 | #define pcRel(pc, p) (cast(int, (pc) - (p)->code) - 1) 15 | 16 | #define getline(f,pc) (((f)->lineinfo) ? (f)->lineinfo[pc] : 0) 17 | 18 | #define resethookcount(L) (L->hookcount = L->basehookcount) 19 | 20 | 21 | void luaG_inithooks (lua_State *L); 22 | void luaG_typeerror (lua_State *L, const TObject *o, const char *opname); 23 | void luaG_concaterror (lua_State *L, StkId p1, StkId p2); 24 | void luaG_aritherror (lua_State *L, const TObject *p1, const TObject *p2); 25 | int luaG_ordererror (lua_State *L, const TObject *p1, const TObject *p2); 26 | void luaG_runerror (lua_State *L, const char *fmt, ...); 27 | void luaG_errormsg (lua_State *L); 28 | int luaG_checkcode (const Proto *pt); 29 | 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /lua/src/ldo.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ldo.h,v 1.1 2005/07/25 21:23:32 cpressey Exp $ 3 | ** Stack and Call structure of Lua 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ldo_h 8 | #define ldo_h 9 | 10 | 11 | #include "lobject.h" 12 | #include "lstate.h" 13 | #include "lzio.h" 14 | 15 | 16 | /* 17 | ** macro to control inclusion of some hard tests on stack reallocation 18 | */ 19 | #ifndef HARDSTACKTESTS 20 | #define condhardstacktests(x) { /* empty */ } 21 | #else 22 | #define condhardstacktests(x) x 23 | #endif 24 | 25 | 26 | #define luaD_checkstack(L,n) \ 27 | if ((char *)L->stack_last - (char *)L->top <= (n)*(int)sizeof(TObject)) \ 28 | luaD_growstack(L, n); \ 29 | else condhardstacktests(luaD_reallocstack(L, L->stacksize)); 30 | 31 | 32 | #define incr_top(L) {luaD_checkstack(L,1); L->top++;} 33 | 34 | #define savestack(L,p) ((char *)(p) - (char *)L->stack) 35 | #define restorestack(L,n) ((TObject *)((char *)L->stack + (n))) 36 | 37 | #define saveci(L,p) ((char *)(p) - (char *)L->base_ci) 38 | #define restoreci(L,n) ((CallInfo *)((char *)L->base_ci + (n))) 39 | 40 | 41 | /* type of protected functions, to be ran by `runprotected' */ 42 | typedef void (*Pfunc) (lua_State *L, void *ud); 43 | 44 | void luaD_resetprotection (lua_State *L); 45 | int luaD_protectedparser (lua_State *L, ZIO *z, int bin); 46 | void luaD_callhook (lua_State *L, int event, int line); 47 | StkId luaD_precall (lua_State *L, StkId func); 48 | void luaD_call (lua_State *L, StkId func, int nResults); 49 | int luaD_pcall (lua_State *L, Pfunc func, void *u, 50 | ptrdiff_t oldtop, ptrdiff_t ef); 51 | void luaD_poscall (lua_State *L, int wanted, StkId firstResult); 52 | void luaD_reallocCI (lua_State *L, int newsize); 53 | void luaD_reallocstack (lua_State *L, int newsize); 54 | void luaD_growstack (lua_State *L, int n); 55 | 56 | void luaD_throw (lua_State *L, int errcode); 57 | int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud); 58 | 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /lua/src/lfunc.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lfunc.h,v 1.1 2005/07/25 21:23:32 cpressey Exp $ 3 | ** Auxiliary functions to manipulate prototypes and closures 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lfunc_h 8 | #define lfunc_h 9 | 10 | 11 | #include "lobject.h" 12 | 13 | 14 | Proto *luaF_newproto (lua_State *L); 15 | Closure *luaF_newCclosure (lua_State *L, int nelems); 16 | Closure *luaF_newLclosure (lua_State *L, int nelems, TObject *e); 17 | UpVal *luaF_findupval (lua_State *L, StkId level); 18 | void luaF_close (lua_State *L, StkId level); 19 | void luaF_freeproto (lua_State *L, Proto *f); 20 | void luaF_freeclosure (lua_State *L, Closure *c); 21 | 22 | const char *luaF_getlocalname (const Proto *func, int local_number, int pc); 23 | 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /lua/src/lgc.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lgc.h,v 1.1 2005/07/25 21:23:33 cpressey Exp $ 3 | ** Garbage Collector 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lgc_h 8 | #define lgc_h 9 | 10 | 11 | #include "lobject.h" 12 | 13 | 14 | #define luaC_checkGC(L) { lua_assert(!(L->ci->state & CI_CALLING)); \ 15 | if (G(L)->nblocks >= G(L)->GCthreshold) luaC_collectgarbage(L); } 16 | 17 | 18 | size_t luaC_separateudata (lua_State *L); 19 | void luaC_callGCTM (lua_State *L); 20 | void luaC_sweep (lua_State *L, int all); 21 | void luaC_collectgarbage (lua_State *L); 22 | void luaC_link (lua_State *L, GCObject *o, lu_byte tt); 23 | 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /lua/src/lib/Makefile: -------------------------------------------------------------------------------- 1 | # makefile for Lua standard library 2 | 3 | CFLAGS += -fPIC 4 | 5 | BASE=../../.. 6 | include $(BASE)/Config 7 | 8 | LUA= ../.. 9 | 10 | EXTRA_DEFS= $(POPEN) $(TMPNAM) $(DEGREES) $(LOADLIB) 11 | 12 | OBJS= lauxlib.o lbaselib.o ldblib.o liolib.o lmathlib.o ltablib.o lstrlib.o loadlib.o 13 | SRCS= lauxlib.c lbaselib.c ldblib.c liolib.c lmathlib.c ltablib.c lstrlib.c loadlib.c 14 | 15 | T= $(LIB)/liblualib.a 16 | 17 | all: $T 18 | 19 | $T: $(OBJS) 20 | $(AR) rcu $@ $(OBJS) 21 | $(RANLIB) $@ 22 | 23 | clean: 24 | rm -f $(OBJS) $T 25 | 26 | co: 27 | co -q -f -M $(SRCS) 28 | 29 | klean: clean 30 | rm -f $(SRCS) 31 | -------------------------------------------------------------------------------- /lua/src/lib/README: -------------------------------------------------------------------------------- 1 | This is the standard Lua library. 2 | 3 | The code of the standard library can be read as an example of how to export 4 | C functions to Lua. The easiest library to read is lmathlib.c. 5 | 6 | The library is implemented entirely on top of the official Lua API as declared 7 | in lua.h, using lauxlib.c, which contains several useful functions for writing 8 | libraries. We encourage developers to use lauxlib.c in their own libraries. 9 | -------------------------------------------------------------------------------- /lua/src/llex.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: llex.h,v 1.1 2005/07/25 21:23:33 cpressey Exp $ 3 | ** Lexical Analyzer 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef llex_h 8 | #define llex_h 9 | 10 | #include "lobject.h" 11 | #include "lzio.h" 12 | 13 | 14 | #define FIRST_RESERVED 257 15 | 16 | /* maximum length of a reserved word */ 17 | #define TOKEN_LEN (sizeof("function")/sizeof(char)) 18 | 19 | 20 | /* 21 | * WARNING: if you change the order of this enumeration, 22 | * grep "ORDER RESERVED" 23 | */ 24 | enum RESERVED { 25 | /* terminal symbols denoted by reserved words */ 26 | TK_AND = FIRST_RESERVED, TK_BREAK, 27 | TK_DO, TK_ELSE, TK_ELSEIF, TK_END, TK_FALSE, TK_FOR, TK_FUNCTION, 28 | TK_IF, TK_IN, TK_LOCAL, TK_NIL, TK_NOT, TK_OR, TK_REPEAT, 29 | TK_RETURN, TK_THEN, TK_TRUE, TK_UNTIL, TK_WHILE, 30 | /* other terminal symbols */ 31 | TK_NAME, TK_CONCAT, TK_DOTS, TK_EQ, TK_GE, TK_LE, TK_NE, TK_NUMBER, 32 | TK_STRING, TK_EOS 33 | }; 34 | 35 | /* number of reserved words */ 36 | #define NUM_RESERVED (cast(int, TK_WHILE-FIRST_RESERVED+1)) 37 | 38 | 39 | typedef union { 40 | lua_Number r; 41 | TString *ts; 42 | } SemInfo; /* semantics information */ 43 | 44 | 45 | typedef struct Token { 46 | int token; 47 | SemInfo seminfo; 48 | } Token; 49 | 50 | 51 | typedef struct LexState { 52 | int current; /* current character (charint) */ 53 | int linenumber; /* input line counter */ 54 | int lastline; /* line of last token `consumed' */ 55 | Token t; /* current token */ 56 | Token lookahead; /* look ahead token */ 57 | struct FuncState *fs; /* `FuncState' is private to the parser */ 58 | struct lua_State *L; 59 | ZIO *z; /* input stream */ 60 | Mbuffer *buff; /* buffer for tokens */ 61 | TString *source; /* current source name */ 62 | int nestlevel; /* level of nested non-terminals */ 63 | } LexState; 64 | 65 | 66 | void luaX_init (lua_State *L); 67 | void luaX_setinput (lua_State *L, LexState *LS, ZIO *z, TString *source); 68 | int luaX_lex (LexState *LS, SemInfo *seminfo); 69 | void luaX_checklimit (LexState *ls, int val, int limit, const char *msg); 70 | void luaX_syntaxerror (LexState *ls, const char *s); 71 | void luaX_errorline (LexState *ls, const char *s, const char *token, int line); 72 | const char *luaX_token2str (LexState *ls, int token); 73 | 74 | 75 | #endif 76 | -------------------------------------------------------------------------------- /lua/src/lmem.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lmem.c,v 1.1 2005/07/25 21:23:33 cpressey Exp $ 3 | ** Interface to Memory Manager 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #include 9 | 10 | #define lmem_c 11 | 12 | #include "lua.h" 13 | 14 | #include "ldebug.h" 15 | #include "ldo.h" 16 | #include "lmem.h" 17 | #include "lobject.h" 18 | #include "lstate.h" 19 | 20 | 21 | 22 | /* 23 | ** definition for realloc function. It must assure that l_realloc(NULL, 24 | ** 0, x) allocates a new block (ANSI C assures that). (`os' is the old 25 | ** block size; some allocators may use that.) 26 | */ 27 | #ifndef l_realloc 28 | #define l_realloc(b,os,s) realloc(b,s) 29 | #endif 30 | 31 | /* 32 | ** definition for free function. (`os' is the old block size; some 33 | ** allocators may use that.) 34 | */ 35 | #ifndef l_free 36 | #define l_free(b,os) free(b) 37 | #endif 38 | 39 | 40 | #define MINSIZEARRAY 4 41 | 42 | 43 | void *luaM_growaux (lua_State *L, void *block, int *size, int size_elems, 44 | int limit, const char *errormsg) { 45 | void *newblock; 46 | int newsize = (*size)*2; 47 | if (newsize < MINSIZEARRAY) 48 | newsize = MINSIZEARRAY; /* minimum size */ 49 | else if (*size >= limit/2) { /* cannot double it? */ 50 | if (*size < limit - MINSIZEARRAY) /* try something smaller... */ 51 | newsize = limit; /* still have at least MINSIZEARRAY free places */ 52 | else luaG_runerror(L, errormsg); 53 | } 54 | newblock = luaM_realloc(L, block, 55 | cast(lu_mem, *size)*cast(lu_mem, size_elems), 56 | cast(lu_mem, newsize)*cast(lu_mem, size_elems)); 57 | *size = newsize; /* update only when everything else is OK */ 58 | return newblock; 59 | } 60 | 61 | 62 | /* 63 | ** generic allocation routine. 64 | */ 65 | void *luaM_realloc (lua_State *L, void *block, lu_mem oldsize, lu_mem size) { 66 | lua_assert((oldsize == 0) == (block == NULL)); 67 | if (size == 0) { 68 | if (block != NULL) { 69 | l_free(block, oldsize); 70 | block = NULL; 71 | } 72 | else return NULL; /* avoid `nblocks' computations when oldsize==size==0 */ 73 | } 74 | else if (size >= MAX_SIZET) 75 | luaG_runerror(L, "memory allocation error: block too big"); 76 | else { 77 | block = l_realloc(block, oldsize, size); 78 | if (block == NULL) { 79 | if (L) 80 | luaD_throw(L, LUA_ERRMEM); 81 | else return NULL; /* error before creating state! */ 82 | } 83 | } 84 | if (L) { 85 | lua_assert(G(L) != NULL && G(L)->nblocks > 0); 86 | G(L)->nblocks -= oldsize; 87 | G(L)->nblocks += size; 88 | } 89 | return block; 90 | } 91 | 92 | -------------------------------------------------------------------------------- /lua/src/lmem.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lmem.h,v 1.1 2005/07/25 21:23:33 cpressey Exp $ 3 | ** Interface to Memory Manager 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lmem_h 8 | #define lmem_h 9 | 10 | 11 | #include 12 | 13 | #include "llimits.h" 14 | #include "lua.h" 15 | 16 | #define MEMERRMSG "not enough memory" 17 | 18 | 19 | void *luaM_realloc (lua_State *L, void *oldblock, lu_mem oldsize, lu_mem size); 20 | 21 | void *luaM_growaux (lua_State *L, void *block, int *size, int size_elem, 22 | int limit, const char *errormsg); 23 | 24 | #define luaM_free(L, b, s) luaM_realloc(L, (b), (s), 0) 25 | #define luaM_freelem(L, b) luaM_realloc(L, (b), sizeof(*(b)), 0) 26 | #define luaM_freearray(L, b, n, t) luaM_realloc(L, (b), \ 27 | cast(lu_mem, n)*cast(lu_mem, sizeof(t)), 0) 28 | 29 | #define luaM_malloc(L, t) luaM_realloc(L, NULL, 0, (t)) 30 | #define luaM_new(L, t) cast(t *, luaM_malloc(L, sizeof(t))) 31 | #define luaM_newvector(L, n,t) cast(t *, luaM_malloc(L, \ 32 | cast(lu_mem, n)*cast(lu_mem, sizeof(t)))) 33 | 34 | #define luaM_growvector(L,v,nelems,size,t,limit,e) \ 35 | if (((nelems)+1) > (size)) \ 36 | ((v)=cast(t *, luaM_growaux(L,v,&(size),sizeof(t),limit,e))) 37 | 38 | #define luaM_reallocvector(L, v,oldn,n,t) \ 39 | ((v)=cast(t *, luaM_realloc(L, v,cast(lu_mem, oldn)*cast(lu_mem, sizeof(t)), \ 40 | cast(lu_mem, n)*cast(lu_mem, sizeof(t))))) 41 | 42 | 43 | #endif 44 | 45 | -------------------------------------------------------------------------------- /lua/src/lopcodes.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lopcodes.c,v 1.1 2005/07/25 21:23:33 cpressey Exp $ 3 | ** extracted automatically from lopcodes.h by mkprint.lua 4 | ** DO NOT EDIT 5 | ** See Copyright Notice in lua.h 6 | */ 7 | 8 | 9 | #define lopcodes_c 10 | 11 | #include "lua.h" 12 | 13 | #include "lobject.h" 14 | #include "lopcodes.h" 15 | 16 | 17 | #ifdef LUA_OPNAMES 18 | 19 | const char *const luaP_opnames[] = { 20 | "MOVE", 21 | "LOADK", 22 | "LOADBOOL", 23 | "LOADNIL", 24 | "GETUPVAL", 25 | "GETGLOBAL", 26 | "GETTABLE", 27 | "SETGLOBAL", 28 | "SETUPVAL", 29 | "SETTABLE", 30 | "NEWTABLE", 31 | "SELF", 32 | "ADD", 33 | "SUB", 34 | "MUL", 35 | "DIV", 36 | "POW", 37 | "UNM", 38 | "NOT", 39 | "CONCAT", 40 | "JMP", 41 | "EQ", 42 | "LT", 43 | "LE", 44 | "TEST", 45 | "CALL", 46 | "TAILCALL", 47 | "RETURN", 48 | "FORLOOP", 49 | "TFORLOOP", 50 | "TFORPREP", 51 | "SETLIST", 52 | "SETLISTO", 53 | "CLOSE", 54 | "CLOSURE" 55 | }; 56 | 57 | #endif 58 | 59 | #define opmode(t,b,bk,ck,sa,k,m) (((t)< 9 | 10 | #define lstring_c 11 | 12 | #include "lua.h" 13 | 14 | #include "lmem.h" 15 | #include "lobject.h" 16 | #include "lstate.h" 17 | #include "lstring.h" 18 | 19 | 20 | 21 | void luaS_freeall (lua_State *L) { 22 | lua_assert(G(L)->strt.nuse==0); 23 | luaM_freearray(L, G(L)->strt.hash, G(L)->strt.size, TString *); 24 | } 25 | 26 | 27 | void luaS_resize (lua_State *L, int newsize) { 28 | GCObject **newhash = luaM_newvector(L, newsize, GCObject *); 29 | stringtable *tb = &G(L)->strt; 30 | int i; 31 | for (i=0; isize; i++) { 34 | GCObject *p = tb->hash[i]; 35 | while (p) { /* for each node in the list */ 36 | GCObject *next = p->gch.next; /* save next */ 37 | lu_hash h = gcotots(p)->tsv.hash; 38 | int h1 = lmod(h, newsize); /* new position */ 39 | lua_assert(cast(int, h%newsize) == lmod(h, newsize)); 40 | p->gch.next = newhash[h1]; /* chain it */ 41 | newhash[h1] = p; 42 | p = next; 43 | } 44 | } 45 | luaM_freearray(L, tb->hash, tb->size, TString *); 46 | tb->size = newsize; 47 | tb->hash = newhash; 48 | } 49 | 50 | 51 | static TString *newlstr (lua_State *L, const char *str, size_t l, lu_hash h) { 52 | TString *ts = cast(TString *, luaM_malloc(L, sizestring(l))); 53 | stringtable *tb; 54 | ts->tsv.len = l; 55 | ts->tsv.hash = h; 56 | ts->tsv.marked = 0; 57 | ts->tsv.tt = LUA_TSTRING; 58 | ts->tsv.reserved = 0; 59 | memcpy(ts+1, str, l*sizeof(char)); 60 | ((char *)(ts+1))[l] = '\0'; /* ending 0 */ 61 | tb = &G(L)->strt; 62 | h = lmod(h, tb->size); 63 | ts->tsv.next = tb->hash[h]; /* chain new entry */ 64 | tb->hash[h] = valtogco(ts); 65 | tb->nuse++; 66 | if (tb->nuse > cast(ls_nstr, tb->size) && tb->size <= MAX_INT/2) 67 | luaS_resize(L, tb->size*2); /* too crowded */ 68 | return ts; 69 | } 70 | 71 | 72 | TString *luaS_newlstr (lua_State *L, const char *str, size_t l) { 73 | GCObject *o; 74 | lu_hash h = (lu_hash)l; /* seed */ 75 | size_t step = (l>>5)+1; /* if string is too long, don't hash all its chars */ 76 | size_t l1; 77 | for (l1=l; l1>=step; l1-=step) /* compute hash */ 78 | h = h ^ ((h<<5)+(h>>2)+(unsigned char)(str[l1-1])); 79 | for (o = G(L)->strt.hash[lmod(h, G(L)->strt.size)]; 80 | o != NULL; 81 | o = o->gch.next) { 82 | TString *ts = gcotots(o); 83 | if (ts->tsv.len == l && (memcmp(str, getstr(ts), l) == 0)) 84 | return ts; 85 | } 86 | return newlstr(L, str, l, h); /* not found */ 87 | } 88 | 89 | 90 | Udata *luaS_newudata (lua_State *L, size_t s) { 91 | Udata *u; 92 | u = cast(Udata *, luaM_malloc(L, sizeudata(s))); 93 | u->uv.marked = (1<<1); /* is not finalized */ 94 | u->uv.tt = LUA_TUSERDATA; 95 | u->uv.len = s; 96 | u->uv.metatable = hvalue(defaultmeta(L)); 97 | /* chain it on udata list */ 98 | u->uv.next = G(L)->rootudata; 99 | G(L)->rootudata = valtogco(u); 100 | return u; 101 | } 102 | 103 | -------------------------------------------------------------------------------- /lua/src/lstring.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lstring.h,v 1.1 2005/07/25 21:23:33 cpressey Exp $ 3 | ** String table (keep all strings handled by Lua) 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lstring_h 8 | #define lstring_h 9 | 10 | 11 | #include "lobject.h" 12 | #include "lstate.h" 13 | 14 | 15 | 16 | #define sizestring(l) (cast(lu_mem, sizeof(union TString))+ \ 17 | (cast(lu_mem, l)+1)*sizeof(char)) 18 | 19 | #define sizeudata(l) (cast(lu_mem, sizeof(union Udata))+(l)) 20 | 21 | #define luaS_new(L, s) (luaS_newlstr(L, s, strlen(s))) 22 | #define luaS_newliteral(L, s) (luaS_newlstr(L, "" s, \ 23 | (sizeof(s)/sizeof(char))-1)) 24 | 25 | #define luaS_fix(s) ((s)->tsv.marked |= (1<<4)) 26 | 27 | void luaS_resize (lua_State *L, int newsize); 28 | Udata *luaS_newudata (lua_State *L, size_t s); 29 | void luaS_freeall (lua_State *L); 30 | TString *luaS_newlstr (lua_State *L, const char *str, size_t l); 31 | 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /lua/src/ltable.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ltable.h,v 1.1 2005/07/25 21:23:33 cpressey Exp $ 3 | ** Lua tables (hash) 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ltable_h 8 | #define ltable_h 9 | 10 | #include "lobject.h" 11 | 12 | 13 | #define gnode(t,i) (&(t)->node[i]) 14 | #define gkey(n) (&(n)->i_key) 15 | #define gval(n) (&(n)->i_val) 16 | 17 | 18 | const TObject *luaH_getnum (Table *t, int key); 19 | TObject *luaH_setnum (lua_State *L, Table *t, int key); 20 | const TObject *luaH_getstr (Table *t, TString *key); 21 | const TObject *luaH_get (Table *t, const TObject *key); 22 | TObject *luaH_set (lua_State *L, Table *t, const TObject *key); 23 | Table *luaH_new (lua_State *L, int narray, int lnhash); 24 | void luaH_free (lua_State *L, Table *t); 25 | int luaH_next (lua_State *L, Table *t, StkId key); 26 | 27 | /* exported only for debugging */ 28 | Node *luaH_mainposition (const Table *t, const TObject *key); 29 | 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /lua/src/ltm.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ltm.c,v 1.1 2005/07/25 21:23:33 cpressey Exp $ 3 | ** Tag methods 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #include 9 | 10 | #define ltm_c 11 | 12 | #include "lua.h" 13 | 14 | #include "lobject.h" 15 | #include "lstate.h" 16 | #include "lstring.h" 17 | #include "ltable.h" 18 | #include "ltm.h" 19 | 20 | 21 | 22 | const char *const luaT_typenames[] = { 23 | "nil", "boolean", "userdata", "number", 24 | "string", "table", "function", "userdata", "thread" 25 | }; 26 | 27 | 28 | void luaT_init (lua_State *L) { 29 | static const char *const luaT_eventname[] = { /* ORDER TM */ 30 | "__index", "__newindex", 31 | "__gc", "__mode", "__eq", 32 | "__add", "__sub", "__mul", "__div", 33 | "__pow", "__unm", "__lt", "__le", 34 | "__concat", "__call" 35 | }; 36 | int i; 37 | for (i=0; itmname[i] = luaS_new(L, luaT_eventname[i]); 39 | luaS_fix(G(L)->tmname[i]); /* never collect these names */ 40 | } 41 | } 42 | 43 | 44 | /* 45 | ** function to be used with macro "fasttm": optimized for absence of 46 | ** tag methods 47 | */ 48 | const TObject *luaT_gettm (Table *events, TMS event, TString *ename) { 49 | const TObject *tm = luaH_getstr(events, ename); 50 | lua_assert(event <= TM_EQ); 51 | if (ttisnil(tm)) { /* no tag method? */ 52 | events->flags |= cast(lu_byte, 1u<tmname[event]; 61 | switch (ttype(o)) { 62 | case LUA_TTABLE: 63 | return luaH_getstr(hvalue(o)->metatable, ename); 64 | case LUA_TUSERDATA: 65 | return luaH_getstr(uvalue(o)->uv.metatable, ename); 66 | default: 67 | return &luaO_nilobject; 68 | } 69 | } 70 | 71 | -------------------------------------------------------------------------------- /lua/src/ltm.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ltm.h,v 1.1 2005/07/25 21:23:33 cpressey Exp $ 3 | ** Tag methods 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ltm_h 8 | #define ltm_h 9 | 10 | 11 | #include "lobject.h" 12 | 13 | 14 | /* 15 | * WARNING: if you change the order of this enumeration, 16 | * grep "ORDER TM" 17 | */ 18 | typedef enum { 19 | TM_INDEX, 20 | TM_NEWINDEX, 21 | TM_GC, 22 | TM_MODE, 23 | TM_EQ, /* last tag method with `fast' access */ 24 | TM_ADD, 25 | TM_SUB, 26 | TM_MUL, 27 | TM_DIV, 28 | TM_POW, 29 | TM_UNM, 30 | TM_LT, 31 | TM_LE, 32 | TM_CONCAT, 33 | TM_CALL, 34 | TM_N /* number of elements in the enum */ 35 | } TMS; 36 | 37 | 38 | 39 | #define gfasttm(g,et,e) \ 40 | (((et)->flags & (1u<<(e))) ? NULL : luaT_gettm(et, e, (g)->tmname[e])) 41 | 42 | #define fasttm(l,et,e) gfasttm(G(l), et, e) 43 | 44 | 45 | const TObject *luaT_gettm (Table *events, TMS event, TString *ename); 46 | const TObject *luaT_gettmbyobj (lua_State *L, const TObject *o, TMS event); 47 | void luaT_init (lua_State *L); 48 | 49 | extern const char *const luaT_typenames[]; 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /lua/src/lua/Makefile: -------------------------------------------------------------------------------- 1 | # makefile for Lua interpreter 2 | 3 | CFLAGS += -fPIC 4 | 5 | BASE=../../.. 6 | include $(BASE)/Config 7 | 8 | LUA= ../.. 9 | 10 | EXTRA_DEFS= $(USERCONF) 11 | OBJS= lua.o 12 | SRCS= lua.c 13 | 14 | T= $(BIN)/lua 15 | 16 | all: $T 17 | 18 | $T: $(OBJS) $(LIB)/liblua.a $(LIB)/liblualib.a 19 | $(CC) -o $@ $(MYLDFLAGS) $(OBJS) -L$(LIB) -llua -llualib $(EXTRA_LIBS) $(DLLIB) 20 | 21 | $(LIB)/liblua.a: 22 | cd ..; $(MAKE) 23 | 24 | $(LIB)/liblualib.a: 25 | cd ../lib; $(MAKE) 26 | 27 | clean: 28 | rm -f $(OBJS) $T 29 | 30 | co: 31 | co -q -f -M $(SRCS) 32 | 33 | klean: clean 34 | rm -f $(SRCS) 35 | -------------------------------------------------------------------------------- /lua/src/lua/README: -------------------------------------------------------------------------------- 1 | This is lua, a sample Lua interpreter. 2 | It can be used as a batch interpreter and also interactively. 3 | There are man pages for it in both nroff and html in ../../doc. 4 | 5 | Usage: ./lua [options] [script [args]]. Available options are: 6 | - execute stdin as a file 7 | -e stat execute string `stat' 8 | -i enter interactive mode after executing `script' 9 | -l name load and run library `name' 10 | -v show version information 11 | -- stop handling options 12 | 13 | This interpreter is suitable for using Lua as a standalone language; it loads 14 | all standard libraries. For a minimal interpreter, see ../../etc/min.c. 15 | 16 | If your application simply exports new functions to Lua (which is common), 17 | then you can use this interpreter (almost) unmodified, as follows: 18 | 19 | * First, define a function 20 | void myinit (lua_State *L) 21 | in your own code. In this function, you should do whatever initializations 22 | are needed by your application, typically exporting your functions to Lua. 23 | (Of course, you can use any name instead of "myinit".) 24 | 25 | * Then, #define lua_userinit(L) to be "openstdlibs(L)+myinit(L)". 26 | Here, openstdlibs is a function in lua.c that opens all standard libraries. 27 | If you don't need them, just don't call openstdlibs and open any standard 28 | libraries that you do need in myinit. 29 | 30 | * Finally, remember to link your C code when building lua. 31 | 32 | For other customizations, see ../../etc/config.c. 33 | -------------------------------------------------------------------------------- /lua/src/luac/Makefile: -------------------------------------------------------------------------------- 1 | # makefile for Lua compiler 2 | 3 | BASE=../../.. 4 | include $(BASE)/Config 5 | 6 | LUA= ../.. 7 | 8 | INCS= -I$(INC) -I.. $(EXTRA_INCS) 9 | OBJS= luac.o print.o lopcodes.o 10 | SRCS= luac.c print.c 11 | 12 | T= $(BIN)/luac 13 | 14 | all: $T 15 | 16 | $T: $(OBJS) $(LIB)/liblua.a $(LIB)/liblualib.a 17 | $(CC) -o $@ $(MYLDFLAGS) $(OBJS) -L$(LIB) -llua -llualib $(EXTRA_LIBS) $(DLLIB) 18 | 19 | # print.c needs opcode names from lopcodes.c 20 | lopcodes.o: ../lopcodes.c ../lopcodes.h 21 | $(CC) -o $@ -c $(CFLAGS) -DLUA_OPNAMES ../lopcodes.c 22 | 23 | $(LIB)/liblua.a: 24 | cd ..; $(MAKE) 25 | 26 | $(LIB)/liblualib.a: 27 | cd ../lib; $(MAKE) 28 | 29 | clean: 30 | rm -f $(OBJS) $T 31 | 32 | co: 33 | co -q -f -M $(SRCS) 34 | 35 | klean: clean 36 | rm -f $(SRCS) 37 | -------------------------------------------------------------------------------- /lua/src/luac/README: -------------------------------------------------------------------------------- 1 | This is luac, the Lua compiler. 2 | There are man pages for it in both nroff and html in ../../doc. 3 | 4 | luac translates Lua programs into binary files that can be loaded latter. 5 | The main advantages of pre-compiling chunks are: faster loading, protecting 6 | source code from user changes, and off-line syntax error detection. 7 | luac can also be used to learn about the Lua virtual machine. 8 | 9 | Usage: /l/luac/luac [options] [filenames]. Available options are: 10 | - process stdin 11 | -l list 12 | -o name output to file `name' (default is "luac.out") 13 | -p parse only 14 | -s strip debug information 15 | -v show version information 16 | -- stop handling options 17 | 18 | luac is also an example of how to use the internals of Lua (politely). 19 | -------------------------------------------------------------------------------- /lua/src/lundump.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lundump.h,v 1.1 2005/07/25 21:23:33 cpressey Exp $ 3 | ** load pre-compiled Lua chunks 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lundump_h 8 | #define lundump_h 9 | 10 | #include "lobject.h" 11 | #include "lzio.h" 12 | 13 | /* load one chunk; from lundump.c */ 14 | Proto* luaU_undump (lua_State* L, ZIO* Z, Mbuffer* buff); 15 | 16 | /* find byte order; from lundump.c */ 17 | int luaU_endianness (void); 18 | 19 | /* dump one chunk; from ldump.c */ 20 | void luaU_dump (lua_State* L, const Proto* Main, lua_Chunkwriter w, void* data); 21 | 22 | /* print one chunk; from print.c */ 23 | void luaU_print (const Proto* Main); 24 | 25 | /* definitions for headers of binary files */ 26 | #define LUA_SIGNATURE "\033Lua" /* binary files start with "Lua" */ 27 | #define VERSION 0x50 /* last format change was in 5.0 */ 28 | #define VERSION0 0x50 /* last major change was in 5.0 */ 29 | 30 | /* a multiple of PI for testing native format */ 31 | /* multiplying by 1E7 gives non-trivial integer values */ 32 | #define TEST_NUMBER ((lua_Number)3.14159265358979323846E7) 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /lua/src/lvm.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lvm.h,v 1.1 2005/07/25 21:23:33 cpressey Exp $ 3 | ** Lua virtual machine 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lvm_h 8 | #define lvm_h 9 | 10 | 11 | #include "ldo.h" 12 | #include "lobject.h" 13 | #include "ltm.h" 14 | 15 | 16 | #define tostring(L,o) ((ttype(o) == LUA_TSTRING) || (luaV_tostring(L, o))) 17 | 18 | #define tonumber(o,n) (ttype(o) == LUA_TNUMBER || \ 19 | (((o) = luaV_tonumber(o,n)) != NULL)) 20 | 21 | #define equalobj(L,o1,o2) \ 22 | (ttype(o1) == ttype(o2) && luaV_equalval(L, o1, o2)) 23 | 24 | 25 | int luaV_lessthan (lua_State *L, const TObject *l, const TObject *r); 26 | int luaV_equalval (lua_State *L, const TObject *t1, const TObject *t2); 27 | const TObject *luaV_tonumber (const TObject *obj, TObject *n); 28 | int luaV_tostring (lua_State *L, StkId obj); 29 | const TObject *luaV_gettable (lua_State *L, const TObject *t, TObject *key, 30 | int loop); 31 | void luaV_settable (lua_State *L, const TObject *t, TObject *key, StkId val); 32 | StkId luaV_execute (lua_State *L); 33 | void luaV_concat (lua_State *L, int total, int last); 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /lua/src/lzio.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lzio.c,v 1.1 2005/07/25 21:23:33 cpressey Exp $ 3 | ** a generic input stream interface 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #include 9 | 10 | #define lzio_c 11 | 12 | #include "lua.h" 13 | 14 | #include "llimits.h" 15 | #include "lmem.h" 16 | #include "lzio.h" 17 | 18 | 19 | int luaZ_fill (ZIO *z) { 20 | size_t size; 21 | const char *buff = z->reader(NULL, z->data, &size); 22 | if (buff == NULL || size == 0) return EOZ; 23 | z->n = size - 1; 24 | z->p = buff; 25 | return char2int(*(z->p++)); 26 | } 27 | 28 | 29 | int luaZ_lookahead (ZIO *z) { 30 | if (z->n == 0) { 31 | int c = luaZ_fill(z); 32 | if (c == EOZ) return c; 33 | z->n++; 34 | z->p--; 35 | } 36 | return char2int(*z->p); 37 | } 38 | 39 | 40 | void luaZ_init (ZIO *z, lua_Chunkreader reader, void *data, const char *name) { 41 | z->reader = reader; 42 | z->data = data; 43 | z->name = name; 44 | z->n = 0; 45 | z->p = NULL; 46 | } 47 | 48 | 49 | /* --------------------------------------------------------------- read --- */ 50 | size_t luaZ_read (ZIO *z, void *b, size_t n) { 51 | while (n) { 52 | size_t m; 53 | if (z->n == 0) { 54 | if (luaZ_fill(z) == EOZ) 55 | return n; /* return number of missing bytes */ 56 | else { 57 | ++z->n; /* filbuf removed first byte; put back it */ 58 | --z->p; 59 | } 60 | } 61 | m = (n <= z->n) ? n : z->n; /* min. between n and z->n */ 62 | memcpy(b, z->p, m); 63 | z->n -= m; 64 | z->p += m; 65 | b = (char *)b + m; 66 | n -= m; 67 | } 68 | return 0; 69 | } 70 | 71 | /* ------------------------------------------------------------------------ */ 72 | char *luaZ_openspace (lua_State *L, Mbuffer *buff, size_t n) { 73 | if (n > buff->buffsize) { 74 | if (n < LUA_MINBUFFER) n = LUA_MINBUFFER; 75 | luaM_reallocvector(L, buff->buffer, buff->buffsize, n, char); 76 | buff->buffsize = n; 77 | } 78 | return buff->buffer; 79 | } 80 | 81 | 82 | -------------------------------------------------------------------------------- /lua/src/lzio.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lzio.h,v 1.1 2005/07/25 21:23:33 cpressey Exp $ 3 | ** Buffered streams 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #ifndef lzio_h 9 | #define lzio_h 10 | 11 | #include "lua.h" 12 | 13 | 14 | #define EOZ (-1) /* end of stream */ 15 | 16 | typedef struct Zio ZIO; 17 | 18 | 19 | #define char2int(c) cast(int, cast(unsigned char, (c))) 20 | 21 | #define zgetc(z) (((z)->n--)>0 ? char2int(*(z)->p++) : luaZ_fill(z)) 22 | 23 | #define zname(z) ((z)->name) 24 | 25 | void luaZ_init (ZIO *z, lua_Chunkreader reader, void *data, const char *name); 26 | size_t luaZ_read (ZIO* z, void* b, size_t n); /* read next n bytes */ 27 | int luaZ_lookahead (ZIO *z); 28 | 29 | 30 | 31 | typedef struct Mbuffer { 32 | char *buffer; 33 | size_t buffsize; 34 | } Mbuffer; 35 | 36 | 37 | char *luaZ_openspace (lua_State *L, Mbuffer *buff, size_t n); 38 | 39 | #define luaZ_initbuffer(L, buff) ((buff)->buffer = NULL, (buff)->buffsize = 0) 40 | 41 | #define luaZ_sizebuffer(buff) ((buff)->buffsize) 42 | #define luaZ_buffer(buff) ((buff)->buffer) 43 | 44 | #define luaZ_resizebuffer(L, buff, size) \ 45 | (luaM_reallocvector(L, (buff)->buffer, (buff)->buffsize, size, char), \ 46 | (buff)->buffsize = size) 47 | 48 | #define luaZ_freebuffer(L, buff) luaZ_resizebuffer(L, buff, 0) 49 | 50 | 51 | /* --------- Private Part ------------------ */ 52 | 53 | struct Zio { 54 | size_t n; /* bytes still unread */ 55 | const char *p; /* current position in buffer */ 56 | lua_Chunkreader reader; 57 | void* data; /* additional data */ 58 | const char *name; 59 | }; 60 | 61 | 62 | int luaZ_fill (ZIO *z); 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /ncurses/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for dfuife_curses. 2 | # $Id: Makefile,v 1.28 2005/08/29 19:19:13 cpressey Exp $ 3 | 4 | BASE?=.. 5 | .include "${BASE}/Config" 6 | 7 | PACKAGE=dfuife_curses 8 | 9 | OBJS= curses_util.o \ 10 | curses_form.o curses_widget.o curses_bar.o \ 11 | curses_xlat.o \ 12 | main.o 13 | 14 | CFLAGS+= ${WARNS} 15 | CFLAGS+= -I${BASE}/lib/libaura -I${BASE}/lib/libdfui 16 | CFLAGS+= -I/usr/local/include 17 | 18 | LDFLAGS+= -L${BASE}/lib/libdfui -ldfui -lpanel -lncurses 19 | 20 | # Default target. 21 | 22 | PROG= dfuife_curses 23 | 24 | all: ${PROG} 25 | 26 | # Main target. 27 | 28 | ${PROG}: ${OBJS} 29 | ${CC} ${CFLAGS} ${OBJS} ${LDFLAGS} -o ${PROG} 30 | 31 | strip: 32 | strip ${PROG} 33 | 34 | clean: 35 | rm -f aura dfui 36 | rm -rf ${PROG} *.o *.core 37 | 38 | install: strip 39 | mkdir -p ${DESTDIR}${PREFIX}/sbin 40 | cp dfuife_curses ${DESTDIR}${PREFIX}/sbin 41 | mkdir -p ${DESTDIR}${PREFIX}/share/dfuife_curses 42 | cp *.txt ${DESTDIR}${PREFIX}/share/dfuife_curses 43 | -------------------------------------------------------------------------------- /ncurses/curses_bar.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c)2004 Cat's Eye Technologies. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 11 | * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in 13 | * the documentation and/or other materials provided with the 14 | * distribution. 15 | * 16 | * Neither the name of Cat's Eye Technologies nor the names of its 17 | * contributors may be used to endorse or promote products derived 18 | * from this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 | * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 25 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 26 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 29 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 31 | * OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | /* 35 | * curses_bar.h 36 | * $Id: curses_bar.h,v 1.5 2005/04/12 06:09:03 cpressey Exp $ 37 | */ 38 | 39 | #ifndef __CURSES_BAR_H 40 | #define __CURSES_BAR_H 41 | 42 | #include 43 | #include 44 | 45 | struct curses_bar { 46 | WINDOW *win; 47 | PANEL *pan; 48 | unsigned int x; 49 | unsigned int y; 50 | unsigned int width; 51 | unsigned int height; 52 | int colors; 53 | }; 54 | 55 | #define CURSES_BAR_WIDEN 1 56 | #define CURSES_BAR_BOTTOM 2 57 | 58 | struct curses_bar *curses_bar_new(unsigned int, unsigned int, 59 | unsigned int, unsigned int, int, int); 60 | void curses_bar_free(struct curses_bar *); 61 | void curses_bar_set_text(struct curses_bar *, 62 | const char *, ...); 63 | 64 | #endif /* !__CURSES_BAR_H */ 65 | -------------------------------------------------------------------------------- /ncurses/curses_xlat.h: -------------------------------------------------------------------------------- 1 | /* 2 | * curses_xlat.h 3 | * $Id: curses_xlat.h,v 1.3 2005/02/08 05:54:44 cpressey Exp $ 4 | */ 5 | 6 | #ifndef __CURSES_XLAT_H 7 | #define __CURSES_XLAT_H 8 | 9 | /* 10 | * Info structure attached to each curses form's userdata pointer. 11 | * Lets us get back to the underlying dfui form and track columns widths. 12 | */ 13 | struct curses_form_userdata { 14 | const struct dfui_form *f; 15 | int widths[256]; 16 | }; 17 | 18 | int curses_form_create_widget_row(struct curses_form *, 19 | struct curses_widget *, const struct dfui_dataset *, 20 | int, int, int); 21 | struct curses_form *curses_form_construct_from_dfui_form(const struct dfui_form *); 22 | struct curses_form *curses_form_construct_from_dfui_progress(const struct dfui_progress *, 23 | struct curses_widget **, 24 | struct curses_widget **, 25 | struct curses_widget **); 26 | void curses_widgets_update_from_dfui_progress(const struct dfui_progress *, 27 | struct curses_widget *, 28 | struct curses_widget *, 29 | struct curses_widget *); 30 | struct dfui_response *response_construct_from_curses_form(const struct dfui_form *, 31 | const struct curses_form *, 32 | const struct curses_widget *); 33 | 34 | #endif /* !__CURSES_XLAT_H */ 35 | -------------------------------------------------------------------------------- /ncurses/fred.txt: -------------------------------------------------------------------------------- 1 | 2 | ,--, | ,--, 3 | | `-, ,^, ,-' | 4 | `, `-, (/ \) ,-` ,-' 5 | `-, `-,/ \,-` ,-` 6 | `------( )------' 7 | ,----------( )-----------, 8 | | _,-( )-,_ | 9 | `-,__,-` \ / `-,__,-' 10 | | | 11 | | | 12 | | | 13 | | | 14 | | | 15 | | | 16 | `|' 17 | -------------------------------------------------------------------------------- /ncurses/hourglass.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@ 4 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 5 | @@@@@ @@@@@ 6 | @@@@@ @@@@@ 7 | @@@@@@@@@@@ @@@@@@@@@@@ 8 | \\\\\ ///// 9 | )))))))))))) ((((((((((( 10 | ///// \\\\\ 11 | @@@@@@@@@@@ @@@@@@@@@@@ 12 | @@@@@ @@@@@ 13 | @@@@@ @@@@@ 14 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 15 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@ 16 | -------------------------------------------------------------------------------- /ncurses/puffy.txt: -------------------------------------------------------------------------------- 1 | | . 2 | . |L /| . 3 | _ . |\ _| \--+._/| . 4 | / ||\| Y J ) / |/| ./ 5 | J |)'( | ` F`.'/ 6 | -<| F __ .-< 7 | | / .-'. `. /-. L___ 8 | J \ < \ | | O\|.-' 9 | _J \ .- \/ O | | \ |F 10 | '-F -<_. \ .-' `-' L__ 11 | __J _ _. >-' )._. |-' 12 | `-|.' /_. \_| F 13 | /.- . _.< 14 | /' /.' .' `\ 15 | /L /' |/ _.-'-\ 16 | /'J ___.---'\| 17 | |\ .--' V | `. ` 18 | |/`. `-. `._) 19 | / .-.\ 20 | VK \ ( `\ 21 | `.\ 22 | --------------------------------------------------------------------------------