├── .gitignore ├── .gitmodules ├── AUTHORS ├── Makefile.am ├── NEWS ├── README ├── bootstrap ├── bootstrap.conf ├── configure.ac ├── curses.lua ├── lcurses.c ├── m4 ├── .gitignore ├── ax_lua.m4 ├── ax_with_curses.m4 └── ax_with_prog.m4 ├── make_lcurses_doc.pl ├── strlcpy.c └── tests.lua /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | *.html 3 | .deps 4 | .libs 5 | /curses_c.la 6 | /lcurses.lo 7 | /lcurses.o 8 | /lcurses-*.tar.gz 9 | /release-notes-* 10 | /lib 11 | /INSTALL 12 | /ChangeLog 13 | /COPYING 14 | /aclocal.m4 15 | /autom4te.cache 16 | /build-aux 17 | /config.h 18 | /config.h.in 19 | /config.log 20 | /config.lt 21 | /config.guess 22 | /config.log 23 | /config.status 24 | /config.sub 25 | /config.lineno 26 | /configure 27 | /depcomp 28 | /gnulib 29 | /install-sh 30 | /libtool 31 | /ltmain.sh 32 | /missing 33 | /Makefile 34 | /Makefile.in 35 | /stamp-h1 36 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "gnulib"] 2 | path = gnulib 3 | url = git://git.sv.gnu.org/gnulib 4 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | See README for the authors. 2 | -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | ## Process this file with automake to produce Makefile.in 2 | 3 | ACLOCAL_AMFLAGS = -I m4 4 | 5 | AM_CPPFLAGS = $(LUA_INCLUDE) 6 | AM_CFLAGS = $(WERROR_CFLAGS) $(WARN_CFLAGS) 7 | 8 | lualib_LTLIBRARIES = curses_c.la 9 | dist_luadata_DATA = curses.lua 10 | 11 | curses_c_la_SOURCES = lcurses.c 12 | curses_c_la_LDFLAGS = -module $(CURSES_LIB) 13 | 14 | ChangeLog: 15 | git2cl > ChangeLog 16 | 17 | LUA_ENV = LUA_INIT= LUA_PATH="$(abs_srcdir)/?.lua;;" LUA_CPATH="$(abs_srcdir)/$(objdir)/?$(shrext);;" 18 | 19 | EXTRA_DIST = lcurses.html lcurses_c.html 20 | 21 | lcurses_c.html: lcurses.c make_lcurses_doc.pl 22 | $(PERL) make_lcurses_doc.pl 23 | 24 | check-local: 25 | $(LUA_ENV) $(LUA) tests.lua 26 | 27 | release: distcheck 28 | git diff --exit-code && \ 29 | git push && \ 30 | woger lua-l package=$(PACKAGE) package_name=$(PACKAGE_NAME) version="release $(VERSION)" description="Lua bindings for curses" notes=release-notes-$(VERSION) 31 | git tag -a -m "Release tag" rel-`echo $(VERSION) | sed -e 's/\./-/g'` && \ 32 | git push --tags 33 | @cat release-notes-$(VERSION) && echo "\n\nDon't forget to release on LuaForge!" 34 | -------------------------------------------------------------------------------- /NEWS: -------------------------------------------------------------------------------- 1 | See the web site (listed in README) for news. 2 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | LCURSES IS NOW MERGED INTO luaposix: http://luaforge.net/projects/luaposix 2 | 3 | lcurses 4 | ------- 5 | 6 | Reuben Thomas 7 | http://luaforge.net/projects/lcurses 8 | 9 | 10 | lcurses is a C library for Lua 5.1 that wraps the curses API. It is 11 | copyright Tiago Dionizio 2004-2007 and 12 | copyright Reuben Thomas 2009-2011, and is released under the MIT 13 | license, like Lua (see http://www.lua.org/copyright.html; it's 14 | basically the same as the BSD license). There is no warranty. 15 | 16 | Please report bugs and make suggestions to the email address above, or 17 | use the LuaForge trackers. 18 | 19 | 20 | Installation 21 | ------------ 22 | 23 | As normal: 24 | 25 | [If using git sources: 26 | 27 | ./autogen.sh 28 | ] 29 | 30 | ./configure && make [&& make install] 31 | 32 | The following options may be of interest if you have Lua installed on 33 | non-default paths (as you are likely to on any system supporting more 34 | than one version of Lua): 35 | 36 | --libdir=DIR Install shared library in this directory 37 | --with-lua-prefix=DIR Lua files are in DIR 38 | --with-lua-suffix=ARG Lua binary and library files are suffixed with ARG 39 | 40 | For example, on Debian or Ubuntu: 41 | 42 | CPPFLAGS='-I /usr/include/lua5.1' ./configure --libdir=/usr/local/lib/lua/5.1 --with-lua-suffix=5.1 43 | 44 | 45 | Use 46 | --- 47 | 48 | Unfortunately, there's currently no documentation other than 49 | lcurses.c. It's fairly straightforward, though. 50 | 51 | GNU Zile 2.5.0 and later is written in Lua, using lcurses, so it 52 | contains plenty of example code. See the lua branch of its git 53 | repository at: http://git.savannah.gnu.org/cgit/zile.git 54 | -------------------------------------------------------------------------------- /bootstrap: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # Print a version string. 3 | scriptversion=2011-08-19.18; # UTC 4 | 5 | # Bootstrap this package from checked-out sources. 6 | # Written by Gary V. Vaughan, 2010 7 | 8 | # Copyright (C) 2010 Free Software Foundation, Inc. 9 | # This is free software; see the source for copying conditions. There is NO 10 | # warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 11 | 12 | # This program is free software: you can redistribute it and/or modify 13 | # it under the terms of the GNU General Public License as published by 14 | # the Free Software Foundation, either version 3 of the License, or 15 | # (at your option) any later version. 16 | 17 | # This program is distributed in the hope that it will be useful, 18 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 | # GNU General Public License for more details. 21 | 22 | # You should have received a copy of the GNU General Public License 23 | # along with this program. If not, see . 24 | 25 | # Originally written by Paul Eggert. The canonical version of this 26 | # script is maintained as build-aux/bootstrap in gnulib, however, to 27 | # be useful to your project, you should place a copy of it under 28 | # version control in the top-level directory of your project. The 29 | # intent is that all customization can be done with a bootstrap.conf 30 | # file also maintained in your version control; gnulib comes with a 31 | # template build-aux/bootstrap.conf to get you started. 32 | 33 | # Please report bugs or propose patches to bug-gnulib@gnu.org. 34 | 35 | 36 | ## ================================================================== ## 37 | ## ## 38 | ## DO NOT EDIT THIS FILE, CUSTOMIZE IT USING A BOOTSTRAP.CONF ## 39 | ## ## 40 | ## ================================================================== ## 41 | 42 | ## ------------------------------- ## 43 | ## User overridable command paths. ## 44 | ## ------------------------------- ## 45 | 46 | # All uppercase denotes values stored in the environment. These 47 | # variables should generally be overridden by the user - however, we do 48 | # set them to `true' in some parts of this script to prevent them being 49 | # called at the wrong time by other tools that we call (`autoreconf', 50 | # for example). 51 | # 52 | # We also allow `LIBTOOLIZE' and `M4' to be overridden, and export the 53 | # result for child processes, but they are handled by the function 54 | # `func_find_tool' and not defaulted in this section. 55 | 56 | : "${ACLOCAL=aclocal}" 57 | : "${AUTOCONF=autoconf}" 58 | : "${AUTOHEADER=autoheader}" 59 | : "${AUTOM4TE=autom4te}" 60 | : "${AUTOHEADER=autoheader}" 61 | : "${AUTOMAKE=automake}" 62 | : "${AUTOPOINT=autopoint}" 63 | : "${AUTORECONF=autoreconf}" 64 | : "${CMP=cmp}" 65 | : "${CONFIG_SHELL=/bin/sh}" 66 | : "${DIFF=diff}" 67 | : "${EGREP=egrep}" 68 | : "${FGREP=fgrep}" 69 | : "${GIT=git}" 70 | : "${GREP=grep}" 71 | : "${LN_S=ln -s}" 72 | : "${RM=rm}" 73 | : "${SED=sed}" 74 | 75 | export ACLOCAL 76 | export AUTOCONF 77 | export AUTOHEADER 78 | export AUTOM4TE 79 | export AUTOHEADER 80 | export AUTOMAKE 81 | export AUTOPOINT 82 | export AUTORECONF 83 | 84 | 85 | ## -------------- ## 86 | ## Configuration. ## 87 | ## -------------- ## 88 | 89 | # Short help message in response to `-h'. Add to this in `bootstrap.conf' 90 | # if you accept any additional options. 91 | usage_message="Bootstrap this package from the checked-out sources. 92 | 93 | Common Bootstrap Options: 94 | -c, --copy copy files instead of creating symbolic links. 95 | --debug enable verbose shell tracing 96 | -n, --dry-run print commands rather than running them 97 | -f, --force attempt to bootstrap even if the sources seem not to have 98 | been checked out. 99 | --gnulib-srcdir=DIRNAME 100 | specify a local directory where gnulib sources reside. 101 | Use this if you already have the gnulib sources on your 102 | machine, and don't want to waste your bandwidth 103 | downloading them again. Defaults to \$GNULIB_SRCDIR. 104 | --skip-git do not fetch files from remote repositories 105 | --skip-po do not download po files. 106 | -v, --verbose verbosely report processing 107 | --version print version information and exit 108 | -W, --warnings=CATEGORY 109 | report the warnings falling in CATEGORY [all] 110 | -h, --help print short or long help message and exit 111 | " 112 | 113 | # Warning categories used by `bootstrap', append others if you use them 114 | # in your `bootstrap.conf'. 115 | warning_categories="recommend settings upgrade" 116 | 117 | # Additional text appended to `usage_message' in response to `--help'. 118 | long_help_message=" 119 | Warning categories include: 120 | \`all' show all warnings 121 | \`none' turn off all the warnings 122 | \`error' warnings are treated as fatal errors 123 | \`recommend' show warnings about missing recommended packages 124 | \`settings' show warnings about missing \`bootstrap.conf' settings 125 | \`upgrade' show warnings about out-dated files 126 | 127 | If the file $progpath.conf exists in the same directory as this script, its 128 | contents are read as shell variables to configure the bootstrap. 129 | 130 | For build prerequisites, environment variables like \$AUTOCONF and \$AMTAR 131 | are honored. 132 | 133 | Running without arguments will suffice in most cases. 134 | " 135 | 136 | # A newline delimited list of triples of programs (that respond to 137 | # --version), the minimum version numbers required (or just `-' in the 138 | # version field if any version will be sufficient) and homepage URLs 139 | # to help locate missing packages. 140 | buildreq= 141 | 142 | # Name of a file containing instructions on installing missing packages 143 | # required in `buildreq'. 144 | buildreq_readme=README-hacking 145 | 146 | # These are extracted from AC_INIT in configure.ac, though you can 147 | # override those values in `bootstrap.conf' if you prefer. 148 | build_aux= 149 | macro_dir= 150 | package= 151 | package_name= 152 | package_version= 153 | package_bugreport= 154 | 155 | # These are extracted from `gnulib-cache.m4', or else fall-back 156 | # automatically on the gnulib defaults; unless you set the values 157 | # manually in `bootstrap.conf'. 158 | doc_base= 159 | gnulib_mk= 160 | gnulib_name= 161 | local_gl_dir= 162 | source_base= 163 | tests_base= 164 | 165 | # The list of gnulib modules required at `gnulib-tool' time. If you 166 | # check `gnulib-cache.m4' into your repository, then this list will be 167 | # extracted automatically. 168 | gnulib_modules= 169 | 170 | # Extra gnulib files that are not in modules, which override files of 171 | # the same name installed by other bootstrap tools. 172 | gnulib_non_module_files=" 173 | build-aux/compile 174 | build-aux/install-sh 175 | build-aux/missing 176 | build-aux/mdate-sh 177 | build-aux/texinfo.tex 178 | build-aux/depcomp 179 | build-aux/config.guess 180 | build-aux/config.sub 181 | doc/INSTALL 182 | " 183 | 184 | # Relative path to the local gnulib submodule, and url to the upstream 185 | # git repository. If you have a gnulib entry in your .gitmodules file, 186 | # these values are ignored. 187 | gnulib_path= 188 | gnulib_url= 189 | 190 | # Additional gnulib-tool options to use. 191 | gnulib_tool_options=" 192 | --no-changelog 193 | " 194 | 195 | # bootstrap removes any macro-files that are not included by aclocal.m4, 196 | # except for files listed in this variable which are always kept. 197 | gnulib_precious=" 198 | gnulib-tool.m4 199 | " 200 | 201 | # When truncating long commands for display, always allow at least this 202 | # many characters before truncating. 203 | min_cmd_len=160 204 | 205 | # The command to download all .po files for a specified domain into 206 | # a specified directory. Fill in the first %s is the domain name, and 207 | # the second with the destination directory. Use rsync's -L and -r 208 | # options because the latest/%s directory and the .po files within are 209 | # all symlinks. 210 | po_download_command_format=\ 211 | "rsync --delete --exclude '*.s1' -Lrtvz \ 212 | 'translationproject.org::tp/latest/%s/' '%s'" 213 | 214 | # Other locale categories that need message catalogs. 215 | extra_locale_categories= 216 | 217 | # Additional xgettext options to use. Gnulib might provide you with an 218 | # extensive list of additional options to append to this, but gettext 219 | # 0.16.1 and newer appends them automaticaly, so you can safely ignore 220 | # the complaints from `gnulib-tool' if your $configure_ac states: 221 | # 222 | # AM_GNU_GETTEXT_VERSION([0.16.1]) 223 | xgettext_options=" 224 | --flag=_:1:pass-c-format 225 | --flag=N_:1:pass-c-format 226 | " 227 | 228 | # Package copyright holder for gettext files. Defaults to FSF if unset. 229 | copyright_holder= 230 | 231 | # File that should exist in the top directory of a checked out hierarchy, 232 | # but not in a distribution tarball. 233 | checkout_only_file= 234 | 235 | # Whether to use copies instead of symlinks by default (if set to true, 236 | # the --copy option has no effect). 237 | copy=false 238 | 239 | # Set this to ".cvsignore .gitignore" in `bootstrap.conf' if you want 240 | # those files to be generated in directories like `lib/', `m4/', and `po/', 241 | # or set it to "auto" to make this script select which to use based 242 | # on which version control system (if any) is used in the source directory. 243 | # Or set it to "none" to ignore VCS ignore files entirely. Default is 244 | # "auto". 245 | vc_ignore= 246 | 247 | 248 | ## -------------------- ## 249 | ## Shell normalisation. ## 250 | ## -------------------- ## 251 | 252 | # NLS nuisances. 253 | LANGUAGE=C 254 | export LANGUAGE 255 | 256 | # Ensure file names are sorted consistently across platforms. 257 | LC_ALL=C 258 | export LC_ALL 259 | 260 | # CDPATH. 261 | (unset CDPATH) >/dev/null 2>&1 && unset CDPATH 262 | 263 | 264 | ## ------------------------- ## 265 | ## Hook function management. ## 266 | ## ------------------------- ## 267 | 268 | # This section contains functions for adding, removing, and running hooks 269 | # to the main code. A hook is just a named list of of function, that can 270 | # be run in order later on. 271 | 272 | 273 | # func_append VAR VALUE 274 | # --------------------- 275 | # Append VALUE onto the existing contents of VAR. 276 | if (eval 'x=a; x+=" b"; test "x$x" = "xa b"') 2>/dev/null 277 | then 278 | # This is an XSI compatible shell, allowing a faster implementation... 279 | eval 'func_append () 280 | { 281 | $debug_cmd 282 | 283 | eval "$1+=\$2" 284 | }' 285 | else 286 | # ...otherwise fall back to using expr, which is often a shell builtin. 287 | func_append () 288 | { 289 | $debug_cmd 290 | 291 | eval "$1=\$$1\$2" 292 | } 293 | fi 294 | 295 | 296 | # func_hookable FUNC_NAME 297 | # ----------------------- 298 | # Declare that FUNC_NAME will run hooks added with 299 | # `func_add_hook FUNC_NAME ...'. 300 | func_hookable () 301 | { 302 | $debug_cmd 303 | 304 | func_append hookable_funcs " $1" 305 | } 306 | 307 | 308 | # func_add_hook FUNC_NAME HOOK_FUNC 309 | # --------------------------------- 310 | # Request that FUNC_NAME call HOOK_FUNC before it returns. FUNC_NAME must 311 | # first have been declared "hookable" by a coll to `func_hookable'. 312 | func_add_hook () 313 | { 314 | $debug_cmd 315 | 316 | case " $hookable_funcs " in 317 | *" $1 "*) ;; 318 | *) func_fatal_error "Error: \`$1' does not accept hook functions." ;; 319 | esac 320 | 321 | eval func_append ${1}_hooks '" $2"' 322 | } 323 | 324 | 325 | # func_remove_hook FUNC_NAME HOOK_FUNC 326 | # ------------------------------------ 327 | # Remove HOOK_FUNC from the list of functions called by FUNC_NAME. 328 | func_remove_hook () 329 | { 330 | $debug_cmd 331 | 332 | eval ${1}_hooks='`echo "\$'$1'_hooks" |$SED "s| '$2'||"`' 333 | } 334 | 335 | 336 | # func_run_hooks FUNC_NAME [ARG]... 337 | # --------------------------------- 338 | # Run all hook functions registered to FUNC_NAME. 339 | func_run_hooks () 340 | { 341 | $debug_cmd 342 | 343 | case " $hookable_funcs " in 344 | *" $1 "*) ;; 345 | *) func_fatal_error "Error: \`$1' does not support hook funcions.n" ;; 346 | esac 347 | 348 | eval hook_funcs="\$$1_hooks" 349 | 350 | # shift away the first argument (FUNC_NAME) 351 | shift 352 | func_run_hooks_result=${1+"$@"} 353 | 354 | for hook_func in $hook_funcs; do 355 | eval $hook_func '"$@"' 356 | 357 | # store returned options list back into positional 358 | # parameters for next `cmd' execution. 359 | eval set dummy "$func_run_hooks_result"; shift 360 | done 361 | } 362 | 363 | 364 | ## ------------------- ## 365 | ## Hookable functions. ## 366 | ## ------------------- ## 367 | 368 | # After `bootstrap.conf' has been sourced, execution proceeds by calling 369 | # `func_bootstrap'. Where a function is decorated with `func_hookable 370 | # func_name', you will find a matching `func_run_hooks func_name' which 371 | # executes all functions added with `func_add_hook func_name my_func'. 372 | # 373 | # You might notice that many of these functions begin with a series of 374 | # `$require_foo' lines. See the docu-comments at the start of the 375 | # `Resource management' section for a description of what these are. 376 | 377 | 378 | # func_bootstrap [ARG]... 379 | # ----------------------- 380 | # All the functions called inside func_bootstrap are hookable. See the 381 | # the individual implementations for details. 382 | func_bootstrap () 383 | { 384 | $debug_cmd 385 | 386 | # Save the current positional parameters to prevent them being 387 | # corrupted by calls to `set' in `func_init'. 388 | func_quote_for_eval ${1+"$@"} 389 | my_saved_positional_parameters="$func_quote_for_eval_result" 390 | 391 | # initialisation 392 | func_init 393 | 394 | # option processing 395 | eval func_options "$my_saved_positional_parameters" 396 | 397 | # post-option preparation 398 | func_prep 399 | 400 | # reconfigure the package 401 | func_reconfigure 402 | 403 | # finalisation 404 | func_fini 405 | } 406 | 407 | 408 | # func_init 409 | # --------- 410 | # Any early initialisations can be hooked to this function. Consider 411 | # whether you can hook onto `func_prep' instead, because if you hook 412 | # any slow to execute code in here, it will also add to the time before 413 | # `./bootstrap --version' can respond. 414 | func_hookable func_init 415 | func_init () 416 | { 417 | $debug_cmd 418 | 419 | func_run_hooks func_init 420 | } 421 | 422 | 423 | # func_options [ARG]... 424 | # --------------------- 425 | # All the functions called inside func_options are hookable. See the 426 | # individual implementations for details. 427 | func_hookable func_options 428 | func_options () 429 | { 430 | $debug_cmd 431 | 432 | func_options_prep ${1+"$@"} 433 | eval func_parse_options \ 434 | ${func_options_prep_result+"$func_options_prep_result"} 435 | eval func_validate_options \ 436 | ${func_parse_options+"$func_parse_options_result"} 437 | 438 | eval func_run_hooks func_options \ 439 | ${func_validate_options_result+"$func_validate_options_result"} 440 | 441 | # save modified positional parameters for caller 442 | func_options_result="$func_run_hooks_result" 443 | } 444 | 445 | 446 | # func_options_prep [ARG]... 447 | # -------------------------- 448 | # All initialisations required before starting the option parse loop. 449 | # Note that when calling hook functions, we pass through the list of 450 | # positional parameters. If a hook function modifies that list, and 451 | # needs to propogate that back to rest of this script, then the complete 452 | # modified list must be put in `func_run_hooks_result' before 453 | # returning. 454 | func_hookable func_options_prep 455 | func_options_prep () 456 | { 457 | $debug_cmd 458 | 459 | warning_func=func_error 460 | 461 | # Option defaults: 462 | opt_copy=${copy-false} 463 | opt_dry_run=false 464 | opt_force=false 465 | opt_gnulib_srcdir="$GNULIB_SRCDIR" 466 | opt_skip_git=false 467 | opt_skip_po=false 468 | opt_warning= 469 | opt_verbose=false 470 | 471 | func_run_hooks func_options_prep ${1+"$@"} 472 | 473 | # save modified positional parameters for caller 474 | func_options_prep_result="$func_run_hooks_result" 475 | } 476 | 477 | 478 | # func_parse_options [ARG]... 479 | # --------------------------- 480 | # The main option parsing loop. 481 | # 482 | # In order to add your own option parsing hooks, you must accept the 483 | # full positional parameter list in your hook function, remove any 484 | # options that you action, and then pass back the remaining unprocessed 485 | # options in `func_run_hooks_result', escaped suitably for `eval'. Like 486 | # this: 487 | # 488 | # my_silent_option () 489 | # { 490 | # $debug_cmd 491 | # 492 | # case $1 in 493 | # --silent|-s) opt_silent=:; shift ;; 494 | # esac 495 | # 496 | # func_quote_for_eval ${1+"$@"} 497 | # func_run_hooks_result="$func_quote_for_eval_result" 498 | # } 499 | # func_add_hook func_parse_options my_silent_option 500 | # 501 | func_hookable func_parse_options 502 | func_parse_options () 503 | { 504 | $debug_cmd 505 | 506 | func_parse_options_result= 507 | 508 | # this just eases exit handling 509 | while test $# -gt 0; do 510 | 511 | # Defer to hook functions for initial option parsing, so they 512 | # get priority in the event of reusing an option name. 513 | func_run_hooks func_parse_options ${1+"$@"} 514 | 515 | # Adjust func_parse_options positional parameters to match 516 | eval set dummy "$func_run_hooks_result"; shift 517 | 518 | opt="$1" 519 | shift 520 | case $opt in 521 | --debug|-x) debug_cmd='set -x' 522 | func_echo "enabling shell trace mode" 523 | $debug_cmd 524 | ;; 525 | --dry-run|--dryrun|-n) 526 | opt_dry_run=: ;; 527 | --copy|-c) opt_copy=: ;; 528 | --force|-f) opt_force=: ;; 529 | 530 | --gnulib-srcdir) 531 | test $# = 0 && func_missing_arg $opt && break 532 | opt_gnulib_srcdir="$1" 533 | shift 534 | ;; 535 | 536 | --skip-git) opt_skip_git=: ;; 537 | --skip-po) opt_skip_po=: ;; 538 | --verbose|-v) opt_verbose=: ;; 539 | 540 | --warnings|--warning|-W) 541 | test $# = 0 && func_missing_arg $opt && break 542 | case " $1 " in 543 | " all ") 544 | opt_warning=" $warning_categories" 545 | ;; 546 | " none ") 547 | opt_warning=" none" 548 | warning_func=: 549 | ;; 550 | " error ") 551 | warning_func=func_fatal_error 552 | ;; 553 | *" $warning_categories "*) 554 | func_append_u opt_warning " $1" 555 | ;; 556 | *) 557 | func_fatal_error \ 558 | "Error: unsupported warning category: \`$1'" 559 | ;; 560 | esac 561 | shift 562 | ;; 563 | 564 | --version) func_version ;; 565 | -\?|-h) func_usage ;; 566 | --help) func_help ;; 567 | 568 | # Separate optargs to long options: 569 | --*=*) 570 | func_split_equals "$opt" 571 | set dummy "$func_split_equals_lhs" \ 572 | "$func_split_equals_rhs" ${1+"$@"} 573 | shift 574 | ;; 575 | 576 | # Separate optargs to short options: 577 | -W*) 578 | func_split_short_opt "$opt" 579 | set dummy "$func_split_short_opt_name" \ 580 | "$func_split_short_opt_arg" ${1+"$@"} 581 | shift 582 | ;; 583 | 584 | # Separate non-argument short options: 585 | -\?*|-h*|-c*|-f*|-n*|-v*|-x*) 586 | func_split_short_opt "$opt" 587 | set dummy "$func_split_short_opt_name" \ 588 | "-$func_split_short_opt_arg" ${1+"$@"} 589 | shift 590 | ;; 591 | 592 | --) set dummy "$opt"; shift; break ;; 593 | -*) func_fatal_help "unrecognised option: \`$opt'" ;; 594 | *) set dummy "$opt"; shift; break ;; 595 | esac 596 | done 597 | 598 | # save modified positional parameters for caller 599 | func_quote_for_eval ${1+"$@"} 600 | func_parse_options_result="$func_quote_for_eval_result" 601 | } 602 | 603 | 604 | # func_validate_options [ARG]... 605 | # ------------------------------ 606 | # Perform any sanity checks on option settings and/or unconsumed 607 | # arguments. 608 | func_hookable func_validate_options 609 | func_validate_options () 610 | { 611 | $debug_cmd 612 | 613 | # display all warnings if -W was not given 614 | test -n "$opt_warning" || opt_warning="$warning_categories" 615 | 616 | func_run_hooks func_validate_options ${1+"$@"} 617 | 618 | # Validate options. 619 | test $# -gt 0 \ 620 | && func_fatal_help "too many arguments" 621 | 622 | # Bail if the options were screwed! 623 | $exit_cmd $EXIT_FAILURE 624 | 625 | # save modified positional parameters for caller 626 | func_quote_for_eval ${1+"$@"} 627 | func_validate_options_result="$func_quote_for_eval_result" 628 | } 629 | 630 | 631 | # func_prep 632 | # --------- 633 | # Function to perform preparation for remaining bootstrap process. If 634 | # your hooked code relies on the outcome of `func_options' hook it here 635 | # rather than to `func_init'. 636 | # 637 | # All the functions called inside func_prep are hookable. See the 638 | # individual implementations for details. 639 | func_hookable func_prep 640 | func_prep () 641 | { 642 | $debug_cmd 643 | 644 | $require_bootstrap_uptodate 645 | $require_buildtools_uptodate 646 | $require_checkout_only_file 647 | 648 | $require_gnulib_merge_changelog 649 | 650 | # fetch update files from the translation project 651 | func_update_translations 652 | 653 | func_run_hooks func_prep 654 | } 655 | 656 | 657 | # func_update_translations 658 | # ------------------------ 659 | # Update package po files and translations. 660 | func_hookable func_update_translations 661 | func_update_translations () 662 | { 663 | $debug_cmd 664 | 665 | $opt_skip_po || { 666 | test -d po && { 667 | $require_package 668 | 669 | func_update_po_files po $package || exit $? 670 | } 671 | 672 | func_run_hooks func_update_translations 673 | } 674 | } 675 | 676 | 677 | # func_reconfigure 678 | # ---------------- 679 | # Reconfigure the current package by running the appropriate autotools in a 680 | # suitable order. 681 | func_hookable func_reconfigure 682 | func_reconfigure () 683 | { 684 | $debug_cmd 685 | 686 | # Released `autopoint' has the tendency to install macros that have 687 | # been obsoleted in current `gnulib., so run this before `gnulib-tool'. 688 | func_autopoint 689 | 690 | # Autoreconf runs `aclocal' before `libtoolize', which causes spurious 691 | # warnings if the initial `aclocal' is confused by the libtoolized 692 | # (or worse: out-of-date) macro directory. 693 | func_libtoolize 694 | 695 | # If you need to do anything after `gnulib-tool' is done, but before 696 | # `autoreconf' runs, you don't need to override this whole function, 697 | # because `func_gnulib_tool' is hookable. 698 | func_gnulib_tool 699 | 700 | func_autoreconf 701 | 702 | func_run_hooks func_reconfigure 703 | } 704 | 705 | 706 | # func_gnulib_tool 707 | # ---------------- 708 | # Run `gnulib-tool' to fetch gnulib modules into the current package. 709 | # 710 | # It's assumed that since you are using gnulib's `bootstrap' script, 711 | # you're also using gnulib elsewhere in your package. If not, then 712 | # you can replace this function in `bootstrap.conf' with: 713 | # 714 | # func_gnulib_tool () { :; } 715 | # 716 | # (although the function returns immediately if $gnulib_tool is set to 717 | # true in any case). 718 | func_hookable func_gnulib_tool 719 | func_gnulib_tool () 720 | { 721 | $debug_cmd 722 | 723 | $require_gnulib_tool 724 | $require_libtoolize 725 | 726 | test true = "$gnulib_tool" || { 727 | if test -n "$gnulib_modules"; then 728 | $require_gnulib_cache 729 | $require_build_aux 730 | $require_macro_dir 731 | 732 | # Try not to pick up any stale values from `gnulib-cache.m4'. 733 | rm -f "$gnulib_cache" 734 | 735 | gnulib_mode="--import" 736 | 737 | # `gnulib_modules' and others are maintained in `bootstrap.conf`: 738 | # Use `gnulib --import` to fetch gnulib modules. 739 | test -n "$build_aux" \ 740 | && func_append_u gnulib_tool_options " --aux-dir=$build_aux" 741 | test -n "$macro_dir" \ 742 | && func_append_u gnulib_tool_options " --m4-base=$macro_dir" 743 | test -n "$doc_base" \ 744 | && func_append_u gnulib_tool_options " --doc-base=$doc_base" 745 | test -n "$gnulib_name" \ 746 | && func_append_u gnulib_tool_options " --lib=$gnulib_name" 747 | test -n "$local_gl_dir" \ 748 | && func_append_u gnulib_tool_options " --local-dir=$local_gl_dir" 749 | test -n "$source_base" \ 750 | && func_append_u gnulib_tool_options " --source-base=$source_base" 751 | test -n "$gnulib_mk" \ 752 | && func_append_u gnulib_tool_options " --makefile-name=$gnulib_mk" 753 | test -n "$tests_base" && { 754 | func_append_u gnulib_tool_options " --tests-base=$tests_base" 755 | func_append_u gnulib_tool_options " --with-tests" 756 | } 757 | else 758 | 759 | # `gnulib_modules' and others are cached in `gnulib-cache.m4': 760 | # Use `gnulib --update' to fetch gnulib modules. 761 | gnulib_mode="--update" 762 | fi 763 | 764 | # Add a sensible default libtool option to gnulib_tool_options. 765 | case " $gnulib_tool_options " in 766 | *" --no-libtool "*|*" --libtool "*) ;; 767 | *) if test true = "$LIBTOOLIZE"; then 768 | func_append_u gnulib_tool_options " --no-libtool" 769 | else 770 | func_append_u gnulib_tool_options " --libtool" 771 | fi 772 | ;; 773 | esac 774 | 775 | $opt_copy || func_append_u gnulib_tool_options " --symbolic" 776 | 777 | func_append_u gnulib_tool_options " $gnulib_mode" 778 | func_append gnulib_tool_options " $gnulib_modules" 779 | 780 | # The embedded echo is to squash whitespace before display. 781 | gnulib_cmd=`echo $gnulib_tool $gnulib_tool_options` 782 | 783 | func_show_eval "$gnulib_cmd" 'exit $?' 784 | } 785 | 786 | func_run_hooks func_gnulib_tool 787 | } 788 | 789 | 790 | # func_fini 791 | # --------- 792 | # Function to perform all finalisation for the bootstrap process. 793 | func_hookable func_fini 794 | func_fini () 795 | { 796 | $debug_cmd 797 | 798 | func_install_gnulib_non_module_files 799 | func_gettext_configuration 800 | func_clean_dangling_symlinks 801 | func_clean_unused_macros 802 | func_skip_po_recommendation 803 | 804 | func_run_hooks func_fini 805 | 806 | func_echo "Done. Now you can run './configure'." 807 | } 808 | 809 | 810 | # func_gettext_configuration 811 | # -------------------------- 812 | # Edit configuration values into po/Makevars. 813 | func_hookable func_gettext_configuration 814 | func_gettext_configuration () 815 | { 816 | $debug_cmd 817 | 818 | $require_autopoint 819 | 820 | test true = "$AUTOPOINT" || { 821 | $require_copyright_holder 822 | $require_extra_locale_categories 823 | $require_package_bugreport 824 | 825 | # Escape xgettext options for sed Makevars generation below. 826 | # We have to delete blank lines in a separate script so that we don't 827 | # append \\\ to the penultimate line, and then delete the last empty 828 | # line, which messes up the variable substitution later in this 829 | # function. Note that adding a literal \\\ requires double escaping 830 | # here, once for the execution subshell, and again for the assignment, 831 | # which is why there are actually 12 (!!) backslashes in the script. 832 | my_xgettext_options=`echo "$xgettext_options$nl" |$SED '/^$/d' |$SED ' 833 | $b 834 | s|$| \\\\\\\\\\\\|'` 835 | 836 | # Create gettext configuration. 837 | func_echo "Creating po/Makevars from po/Makevars.template ..." 838 | $RM -f po/Makevars 839 | $SED ' 840 | /^EXTRA_LOCALE_CATEGORIES *=/s|=.*|= '"$extra_locale_categories"'| 841 | /^COPYRIGHT_HOLDER *=/s|=.*|= '"$copyright_holder"'| 842 | /^MSGID_BUGS_ADDRESS *=/s|=.*|= '"$package_bugreport"'| 843 | /^XGETTEXT_OPTIONS *=/{ 844 | s|$| \\| 845 | a\ 846 | '"$my_xgettext_options"' \\\ 847 | $${end_of_xgettext_options+} 848 | } 849 | ' po/Makevars.template >po/Makevars || exit 1 850 | } 851 | 852 | func_run_hooks func_gettext_configuration 853 | } 854 | 855 | 856 | 857 | ## --------------- ## 858 | ## Core functions. ## 859 | ## --------------- ## 860 | 861 | # This section contains the main functions called from the `Hookable 862 | # functions' (shown above), and are the ones you're most likely 863 | # to want to replace with your own implementations in `bootstrap.conf'. 864 | 865 | 866 | # func_autopoint 867 | # -------------- 868 | # If this package uses gettext, then run `autopoint'. 869 | func_autopoint () 870 | { 871 | $debug_cmd 872 | 873 | $require_autopoint 874 | 875 | test true = "$AUTOPOINT" \ 876 | || func_show_eval "$AUTOPOINT --force" 'exit $?' 877 | } 878 | 879 | 880 | # func_libtoolize 881 | # --------------- 882 | # If this package uses libtool, then run `libtoolize'. 883 | func_libtoolize () 884 | { 885 | $debug_cmd 886 | 887 | $require_libtoolize 888 | 889 | test true = "$LIBTOOLIZE" || { 890 | my_libtoolize_options= 891 | $opt_copy && func_append my_libtoolize_options " --copy" 892 | $opt_force && func_append my_libtoolize_options " --force" 893 | $opt_verbose || func_append my_libtoolize_options " --quiet" 894 | func_show_eval "$LIBTOOLIZE$my_libtoolize_options" 'exit $?' 895 | } 896 | } 897 | 898 | 899 | # func_autoreconf 900 | # --------------- 901 | # Being careful not to re-run `autopoint' or `libtoolize', and not to 902 | # try to run `autopoint', `libtoolize' or `autoheader' on packages that 903 | # don't use them, defer to `autoreconf' for execution of the remaining 904 | # autotools to bootstrap this package. 905 | func_autoreconf () 906 | { 907 | $debug_cmd 908 | 909 | $require_autoheader 910 | $require_build_aux # automake and others put files in here 911 | $require_macro_dir # aclocal and others put files in here 912 | 913 | # We ran these manually already, and autoreconf won't exec `:' 914 | save_AUTOPOINT="$AUTOPOINT"; AUTOPOINT=true 915 | save_LIBTOOLIZE="$LIBTOOLIZE"; LIBTOOLIZE=true 916 | 917 | my_autoreconf_options= 918 | $opt_copy || func_append my_autoreconf_options " --symlink" 919 | $opt_force && func_append my_autoreconf_options " --force" 920 | $opt_verbose && func_append my_autoreconf_options " --verbose" 921 | func_show_eval "$AUTORECONF$my_autoreconf_options --install" 'exit $?' 922 | 923 | AUTOPOINT="$save_AUTOPOINT" 924 | LIBTOOLIZE="$save_LIBTOOLIZE" 925 | } 926 | 927 | 928 | # func_install_gnulib_non_module_files 929 | # ------------------------------------ 930 | # Get additional non-module files from gnulib, overriding existing files. 931 | func_install_gnulib_non_module_files () 932 | { 933 | $debug_cmd 934 | 935 | $require_build_aux 936 | $require_gnulib_path 937 | 938 | test -n "$gnulib_non_module_files" && { 939 | if test -n "$gnulib_path"; then 940 | maybe_exit_cmd=: 941 | 942 | for file in $gnulib_non_module_files; do 943 | case $file in 944 | */COPYING*) dest=COPYING;; 945 | */INSTALL) dest=INSTALL;; 946 | build-aux/*) dest=$build_aux/`expr "$file" : 'build-aux/\(.*\)'`;; 947 | *) dest=$file;; 948 | esac 949 | 950 | # Be sure to show all copying errors before bailing out 951 | if test -f "$gnulib_path/$file"; then 952 | func_symlink_to_dir "$gnulib_path" $file $dest 953 | else 954 | func_error "Error: \`$gnulib_path/$file' does not exist" 955 | maybe_exit_cmd="exit $EXIT_FAILURE" 956 | fi 957 | done 958 | 959 | $maybe_exit_cmd 960 | else 961 | func_warning recommend "\ 962 | Unable to link \`\$gnulib_non_module_files', please provide the 963 | location of a complete \`gnulib' tree by setting \`gnulib_path' in 964 | your \`bootstrap.conf' or with the \`--gnulib-srcdir' option - or 965 | else specify the location of your \`git' binary by setting \`GIT' 966 | in the environment so that a fresh \`gnulib' submodule can be cloned." 967 | fi 968 | } 969 | } 970 | 971 | 972 | # func_check_configuration VARNAME [CONFIGURE_MACRO] 973 | # -------------------------------------------------- 974 | func_check_configuration () 975 | { 976 | $debug_cmd 977 | 978 | $require_configure_ac 979 | 980 | eval 'test -n "$'$1'"' || { 981 | my_error_msg="Error: please set \`$1' in \`bootstrap.conf'" 982 | test -n "$2" \ 983 | && func_append my_error_msg " 984 | or add the following (or similar) to your \`$configure_ac': 985 | $2" 986 | 987 | func_fatal_error "$my_error_msg" 988 | } 989 | } 990 | 991 | 992 | # func_clean_dangling_symlinks 993 | # ---------------------------- 994 | # Remove any dangling symlink matching "*.m4" or "*.[ch]" in some 995 | # gnulib-populated directories. Such .m4 files would cause aclocal to 996 | # fail. The following requires GNU find 4.2.3 or newer. Considering 997 | # the usual portability constraints of this script, that may seem a very 998 | # demanding requirement, but it should be ok. Ignore any failure, 999 | # which is fine, since this is only a convenience to help developers 1000 | # avoid the relatively unusual case in which a symlinked-to .m4 file is 1001 | # git-removed from gnulib between successive runs of this script. 1002 | func_clean_dangling_symlinks () 1003 | { 1004 | $debug_cmd 1005 | 1006 | $require_macro_dir 1007 | $require_source_base 1008 | 1009 | func_verbose "cleaning dangling symlinks" 1010 | 1011 | find "$macro_dir" "$source_base" \ 1012 | -depth \( -name '*.m4' -o -name '*.[ch]' \) \ 1013 | -type l -xtype l -delete > /dev/null 2>&1 1014 | } 1015 | 1016 | 1017 | # func_clean_unused_macros 1018 | # ------------------------ 1019 | # Autopoint can result in over-zealously adding macros into $macro_dir 1020 | # even though they are not actually used, for example tests to help 1021 | # build the `intl' directory even though you have specified 1022 | # `AM_GNU_GETTEXT([external])' in your configure.ac. This function 1023 | # looks removes any macro files that can be found in gnulib, but 1024 | # are not `m4_include'd by `aclocal.m4'. 1025 | func_clean_unused_macros () 1026 | { 1027 | $debug_cmd 1028 | 1029 | $require_gnulib_path 1030 | $require_macro_dir 1031 | 1032 | test -n "$gnulib_path" && test -f aclocal.m4 && { 1033 | aclocal_m4s=`find . -name aclocal.m4 -print` 1034 | 1035 | # We use `ls|grep' instead of `ls *.m4' to avoid exceeding 1036 | # command line length limits in some shells. 1037 | for file in `cd $macro_dir && ls -1 |grep '\.m4$'`; do 1038 | 1039 | # Remove a macro file when aclocal.m4 does not m4_include it... 1040 | func_grep_q 'm4_include([[]'$macro_dir/$file'])' $aclocal_m4s \ 1041 | || test ! -f $gnulib_path/m4/$file || { 1042 | 1043 | # ...and there is an identical file in gnulib... 1044 | if func_cmp_s $gnulib_path/m4/$file $macro_dir/$file; then 1045 | 1046 | # ...and it's not in the precious list (`echo' is needed 1047 | # here to squash whitespace for the match expression). 1048 | case " "`echo $gnulib_precious`" " in 1049 | *" $file "*) ;; 1050 | *) rm -f $macro_dir/$file 1051 | func_verbose \ 1052 | "removing unused gnulib file \`$macro_dir/$file'" 1053 | esac 1054 | fi 1055 | } 1056 | done 1057 | } 1058 | } 1059 | 1060 | 1061 | # func_skip_po_recommendation 1062 | # --------------------------- 1063 | # If there is a po directory, and `--skip-po' wasn't passed, let the 1064 | # user know that they can use `--skip-po' on subsequent invocations. 1065 | func_skip_po_recommendation () 1066 | { 1067 | test ! -d po \ 1068 | || $opt_skip_po \ 1069 | || func_warning recommend "\ 1070 | If your pofiles are up-to-date, you can rerun bootstrap 1071 | as \`$progname --skip-po' to avoid redownloading." 1072 | } 1073 | 1074 | 1075 | ## -------------------- ## 1076 | ## Resource management. ## 1077 | ## -------------------- ## 1078 | 1079 | # This section contains definitions for functions that each ensure a 1080 | # particular resource (a file, or a non-empty configuration variable for 1081 | # example) is available, and if appropriate to extract default values 1082 | # from pertinent package files. Where a variable already has a non- 1083 | # empty value (as set by the package's `bootstrap.conf'), that value is 1084 | # used in preference to deriving the default. Call them using their 1085 | # associated `require_*' variable to ensure that they are executed, at 1086 | # most, once. 1087 | 1088 | 1089 | # require_checkout_only_file 1090 | # -------------------------- 1091 | # Bail out if this package only bootstraps properly from a repository 1092 | # checkout. 1093 | require_checkout_only_file=func_require_checkout_only_file 1094 | func_require_checkout_only_file () 1095 | { 1096 | $debug_cmd 1097 | 1098 | test -n "$checkout_only_file" && test ! -f "$checkout_only_file" \ 1099 | && func_fatal_error "\ 1100 | Error: Bootstrapping from a non-checked-out distribution is risky." 1101 | 1102 | require_checkout_only_file=: 1103 | } 1104 | 1105 | 1106 | # require_aclocal_amflags 1107 | # ----------------------- 1108 | # Ensure `$aclocal_amflags' has a sensible default, extracted from 1109 | # `Makefile.am' if necessary. 1110 | require_aclocal_amflags=func_require_aclocal_amflags 1111 | func_require_aclocal_amflags () 1112 | { 1113 | $debug_cmd 1114 | 1115 | $require_makefile_am 1116 | 1117 | my_sed_extract_aclocal_amflags='s|#.*$|| 1118 | /^[ ]*ACLOCAL_AMFLAGS[ ]*=/ { 1119 | s|^.*=[ ]*\(.*\)|aclocal_amflags="\1"| 1120 | p 1121 | }' 1122 | 1123 | my_aclocal_flags_cmd=`$SED -n "$my_sed_extract_aclocal_amflags" \ 1124 | "$makefile_am"` 1125 | eval "$my_aclocal_flags_cmd" 1126 | 1127 | func_verbose "ACLOCAL_AMFLAGS='$aclocal_amflags'" 1128 | 1129 | require_aclocal_amflags=: 1130 | } 1131 | 1132 | 1133 | # require_autobuild_buildreq 1134 | # -------------------------- 1135 | # Try to find whether the bootstrap requires autobuild. 1136 | require_autobuild_buildreq=func_require_autobuild_buildreq 1137 | func_require_autobuild_buildreq () 1138 | { 1139 | $debug_cmd 1140 | 1141 | printf "$buildreq"| func_grep_q '^[ ]*autobuild' || { 1142 | $require_configure_ac 1143 | 1144 | func_extract_trace AB_INIT 1145 | test -n "$func_extract_trace_result" && { 1146 | func_append buildreq 'autobuild - http://josefsson.org/autobuild/ 1147 | ' 1148 | func_verbose "auto-adding \`autobuild' to build requirements" 1149 | } 1150 | } 1151 | 1152 | require_autobuild_buildreq=: 1153 | } 1154 | 1155 | 1156 | # require_autoconf_buildreq 1157 | # require_gettext_buildreq 1158 | # require_libtoolize_buildreq 1159 | # --------------------------- 1160 | # Try to find the minimum compatible version of autoconf/libtool 1161 | # required to bootstrap successfully, and add it to `$buildreq'. 1162 | for tool in autoconf libtoolize gettext; do 1163 | b=$tool 1164 | v=require_${tool}_buildreq 1165 | f=func_$v 1166 | case $tool in 1167 | autoconf) m=AC_PREREQ ;; 1168 | libtoolize) m=LT_PREREQ; b=libtool ;; 1169 | gettext) m=AM_GNU_GETTEXT_VERSION ;; 1170 | esac 1171 | 1172 | eval $v'='$f' 1173 | '$f' () 1174 | { 1175 | $debug_cmd 1176 | 1177 | # The following is ignored if undefined, but might be necessary 1178 | # in order for `func_find_tool` to run. 1179 | ${require_'$tool'-:} 1180 | 1181 | printf "$buildreq" | func_grep_q '\''^[ ]*'$tool\'' || { 1182 | $require_configure_ac 1183 | 1184 | func_extract_trace '$m' 1185 | my_version="$func_extract_trace_result" 1186 | test -n "$my_version" && { 1187 | func_append buildreq "\ 1188 | '$tool' $my_version http://www.gnu.org/s/'$b' 1189 | " 1190 | func_verbose \ 1191 | "auto-adding \`'$tool'-$my_version'\'' to build requirements" 1192 | } 1193 | } 1194 | 1195 | '$v'=: 1196 | } 1197 | ' 1198 | done 1199 | 1200 | 1201 | # require_autoheader 1202 | # ------------------ 1203 | # Skip autoheader if it's not needed. 1204 | require_autoheader=func_require_autoheader 1205 | func_require_autoheader () 1206 | { 1207 | $debug_cmd 1208 | 1209 | test true = "$AUTOHEADER" || { 1210 | func_extract_trace AC_CONFIG_HEADERS 1211 | test -n "$func_extract_trace_result" \ 1212 | || func_extract_trace AC_CONFIG_HEADER 1213 | 1214 | test -n "$func_extract_trace_result" || { 1215 | AUTOHEADER=true 1216 | 1217 | func_verbose "export AUTOHEADER='$AUTOHEADER'" 1218 | 1219 | # Make sure the search result is visible to subshells 1220 | export AUTOHEADER 1221 | } 1222 | } 1223 | 1224 | require_autoheader=: 1225 | } 1226 | 1227 | 1228 | # require_automake_buildreq 1229 | # ------------------------- 1230 | # Try to find the minimum compatible version of automake required to 1231 | # bootstrap successfully, and add it to `$buildreq'. 1232 | require_automake_buildreq=func_require_automake_buildreq 1233 | func_require_automake_buildreq () 1234 | { 1235 | $debug_cmd 1236 | 1237 | # if automake is not already listed in $buildreq... 1238 | printf "$buildreq"| func_grep_q automake || { 1239 | func_extract_trace AM_INIT_AUTOMAKE 1240 | 1241 | # ...and AM_INIT_AUTOMAKE is declared... 1242 | test -n "$func_extract_trace_result" && { 1243 | automake_version=`echo "$func_extract_trace_result" \ 1244 | |$SED 's|[^0-9]*||; s| .*$||'` 1245 | test -n "$automake_version" || automake_version="-" 1246 | 1247 | func_append buildreq "\ 1248 | automake $automake_version http://www.gnu.org/s/automake 1249 | " 1250 | func_verbose \ 1251 | "auto-adding \`automake-$automake_version' to build requirements" 1252 | } 1253 | } 1254 | 1255 | require_automake_buildreq=: 1256 | } 1257 | 1258 | 1259 | # require_autopoint 1260 | # ----------------- 1261 | # Skip autopoint if it's not needed. 1262 | require_autopoint=func_require_autopoint 1263 | func_require_autopoint () 1264 | { 1265 | $debug_cmd 1266 | 1267 | test true = "$AUTOPOINT" || { 1268 | func_extract_trace AM_GNU_GETTEXT_VERSION 1269 | 1270 | test -n "$func_extract_trace_result" || { 1271 | AUTOPOINT=true 1272 | 1273 | func_verbose "export AUTOPOINT='$AUTOPOINT'" 1274 | 1275 | # Make sure the search result is visible to subshells 1276 | export AUTOPOINT 1277 | } 1278 | } 1279 | 1280 | require_autopoint=: 1281 | } 1282 | 1283 | 1284 | # func_require_bootstrap_uptodate 1285 | # ------------------------------- 1286 | # Complain if the version of bootstrap in the gnulib directory differs 1287 | # from the one we are running. 1288 | require_bootstrap_uptodate=func_require_bootstrap_uptodate 1289 | func_require_bootstrap_uptodate () 1290 | { 1291 | $debug_cmd 1292 | 1293 | $require_gnulib_path 1294 | 1295 | test x = x"$gnulib_path" \ 1296 | || func_cmp_s $progpath $gnulib_path/build-aux/bootstrap \ 1297 | || func_warning upgrade "\ 1298 | \`$progpath' differs from \`./$gnulib_path/build-aux/bootstrap', 1299 | please consider adopting the canonical version from gnulib." 1300 | 1301 | require_bootstrap_uptodate=: 1302 | } 1303 | 1304 | 1305 | # require_build_aux 1306 | # ----------------- 1307 | # Ensure that `$build_aux' is set, and if it doesn't already point to an 1308 | # existing directory, create one. 1309 | require_build_aux=func_require_build_aux 1310 | func_require_build_aux () 1311 | { 1312 | $debug_cmd 1313 | 1314 | test -n "$build_aux" || { 1315 | $require_configure_ac 1316 | 1317 | func_extract_trace AC_CONFIG_AUX_DIR 1318 | build_aux="$func_extract_trace_result" 1319 | func_check_configuration build_aux \ 1320 | "AC_CONFIG_AUX_DIR([name of a directory for build scripts])" 1321 | 1322 | func_verbose "build_aux='$build_aux'" 1323 | } 1324 | 1325 | $require_vc_ignore_files 1326 | 1327 | # If the build_aux directory doesn't exist, create it now, and mark it 1328 | # as ignored for the VCS. 1329 | if test ! -d "$build_aux"; then 1330 | func_show_eval "mkdir '$build_aux'" 1331 | 1332 | test -n "$vc_ignore_files" \ 1333 | || func_insert_sorted_if_absent "$build_aux" $vc_ignore_files 1334 | fi 1335 | 1336 | require_build_aux=: 1337 | } 1338 | 1339 | 1340 | # func_require_buildtools_uptodate 1341 | # -------------------------------- 1342 | # Ensure all the packages listed in BUILDREQS are available on the build 1343 | # machine at the minimum versions or better. 1344 | require_buildtools_uptodate=func_require_buildtools_uptodate 1345 | func_require_buildtools_uptodate () 1346 | { 1347 | $debug_cmd 1348 | 1349 | $require_autobuild_buildreq 1350 | $require_autoconf_buildreq 1351 | $require_automake_buildreq 1352 | $require_libtoolize_buildreq 1353 | $require_gettext_buildreq 1354 | 1355 | test -n "$buildreq" && { 1356 | func_check_versions $buildreq 1357 | $func_check_versions_result || { 1358 | test -n "$buildreq_readme" \ 1359 | && test -f "$buildreq_readme" \ 1360 | && func_error "\ 1361 | Error: $buildreq_readme explains how to obtain these prerequisite programs: 1362 | " 1363 | func_strtable 7 11 12 36 \ 1364 | "Program" "Min_version" "Homepage" $buildreq 1365 | func_fatal_error "$func_strtable_result" 1366 | } 1367 | } 1368 | 1369 | require_buildtools_uptodate=: 1370 | } 1371 | 1372 | 1373 | # require_configure_ac 1374 | # -------------------- 1375 | # Ensure that there is a `configure.ac' or `configure.in' file in the 1376 | # current directory, and that `$configure_ac' contains its name. 1377 | require_configure_ac=func_require_configure_ac 1378 | func_require_configure_ac () 1379 | { 1380 | $debug_cmd 1381 | 1382 | test -n "$configure_ac" || { 1383 | for configure_ac in configure.ac configure.in; do 1384 | test -f $configure_ac && break 1385 | done 1386 | 1387 | <$configure_ac 1388 | } 1389 | 1390 | func_verbose "found \`$configure_ac'" 1391 | 1392 | require_configure_ac=: 1393 | } 1394 | 1395 | 1396 | # require_copyright_holder 1397 | # ------------------------ 1398 | # Ensure there is a sensible non-empty default value in `$copyright_holder'. 1399 | require_copyright_holder=func_require_copyright_holder 1400 | func_require_copyright_holder () 1401 | { 1402 | $debug_cmd 1403 | 1404 | test -n "$copyright_holder" || { 1405 | copyright_holder='Free Software Foundation, Inc.' 1406 | func_warning settings "\ 1407 | Please set copyright_holder explicitly in \`bootstrap.conf'; 1408 | defaulting to \`$copyright_holder'." 1409 | } 1410 | 1411 | require_copyright_holder=: 1412 | } 1413 | 1414 | 1415 | # require_dotgitmodules 1416 | # --------------------- 1417 | # Ensure we have a `.gitmodules' file, with appropriate `gnulib' settings. 1418 | require_dotgitmodules=func_require_dotgitmodules 1419 | func_require_dotgitmodules () 1420 | { 1421 | $debug_cmd 1422 | 1423 | $require_git 1424 | 1425 | test true = "$GIT" || { 1426 | # A gnulib entry in .gitmodules always takes precedence. 1427 | my_path="`$GIT config --file .gitmodules submodule.gnulib.path 2>/dev/null`" 1428 | 1429 | test -n "$my_path" || { 1430 | $require_vc_ignore_files 1431 | 1432 | func_verbose "creating \`.gitmodules'" 1433 | 1434 | # If the .gitmodules file doesn't exist, create it now, and mark 1435 | # it as ignored for the VCS. 1436 | test -n "$gnulib_path" || gnulib_path=gnulib 1437 | test -n "$gnulib_url" || gnulib_url=git://git.sv.gnu.org/gnulib 1438 | 1439 | { 1440 | echo '[submodule "gnulib"]' 1441 | echo " path = $gnulib_path" 1442 | echo " url = $gnulib_url" 1443 | } >> .gitmodules 1444 | 1445 | test -n "$vc_ignore_files" \ 1446 | || func_insert_sorted_if_absent ".gitmodules" $vc_ignore_files 1447 | } 1448 | } 1449 | 1450 | require_dotgitmodules=: 1451 | } 1452 | 1453 | 1454 | # require_extra_locale_categories 1455 | # ------------------------------- 1456 | # Ensure there is a default value in `$extra_locale_categories' 1457 | require_extra_locale_categories=func_require_extra_locale_categories 1458 | func_require_extra_locale_categories () 1459 | { 1460 | $debug_cmd 1461 | 1462 | # Defaults to empty, so run with whatever value may have been set in 1463 | # `bootstrap.conf'. 1464 | require_extra_locale_categories=: 1465 | } 1466 | 1467 | 1468 | # require_git 1469 | # ----------- 1470 | # Ignore git if it's not available, or we're not in a git checkout tree. 1471 | require_git=func_require_git 1472 | func_require_git () 1473 | { 1474 | $debug_cmd 1475 | 1476 | $opt_skip_git && GIT=true 1477 | 1478 | test true = "$GIT" || { 1479 | if test -f .gitignore && ($GIT --version) >/dev/null 2>&1; then :; else 1480 | GIT=true 1481 | fi 1482 | } 1483 | 1484 | func_verbose "GIT='$GIT'" 1485 | 1486 | require_git=: 1487 | } 1488 | 1489 | 1490 | # require_gnu_m4 1491 | # -------------- 1492 | # Search for GNU M4, and export it in $M4. 1493 | require_gnu_m4=func_require_gnu_m4 1494 | func_require_gnu_m4 () 1495 | { 1496 | $debug_cmd 1497 | 1498 | test -n "$M4" || { 1499 | # Find the first m4 binary that responds to --version. 1500 | func_find_tool M4 gm4 gnum4 m4 1501 | } 1502 | 1503 | test -n "$M4" || func_fatal_error "\ 1504 | Error: Please install GNU M4, or \`export M4=/path/to/gnu/m4'." 1505 | 1506 | func_verbose "export M4='$M4'" 1507 | 1508 | # Make sure the search result is visible to subshells 1509 | export M4 1510 | 1511 | require_gnu_m4=: 1512 | } 1513 | 1514 | 1515 | # require_gnulib_cache 1516 | # -------------------- 1517 | # Ensure there is a non-empty default for `$gnulib_cache', and that it 1518 | # names an existing file. 1519 | require_gnulib_cache=func_require_gnulib_cache 1520 | func_require_gnulib_cache () 1521 | { 1522 | $debug_cmd 1523 | 1524 | $require_macro_dir 1525 | 1526 | test -n "$gnulib_cache" \ 1527 | || gnulib_cache="$macro_dir/gnulib-cache.m4" 1528 | 1529 | func_verbose "found \`$gnulib_cache'" 1530 | 1531 | require_gnulib_cache=: 1532 | } 1533 | 1534 | 1535 | # require_gnulib_files_already_present 1536 | # ------------------------------------ 1537 | # If we have no means to update imported gnulib files, then try to 1538 | # ensure at least that this tree already has files from a previous 1539 | # `gnulib-tool' run. 1540 | require_gnulib_files_already_present=func_require_gnulib_files_already_present 1541 | func_require_gnulib_files_already_present () 1542 | { 1543 | $debug_cmd 1544 | 1545 | $require_build_aux 1546 | $require_macro_dir 1547 | $require_gnulib_mk 1548 | $require_source_base 1549 | 1550 | # As a heuristic, only bail out if any of the following 1551 | # are missing. 1552 | my_gnulib_files_already_present=" 1553 | $build_aux/install-sh 1554 | $macro_dir/00gnulib.m4 1555 | $source_base/${gnulib_mk:-Makefile.am} 1556 | " 1557 | 1558 | $opt_dry_run || { 1559 | for my_file in $my_gnulib_files_already_present; do 1560 | test -f "$my_file" || func_fatal_error "\ 1561 | Error: Can't find, copy or download required gnulib files, 1562 | please provide the location of a complete \`gnulib' tree 1563 | by setting \`gnulib_path' in your \`bootstrap.conf' or 1564 | with the \`--gnulib-srcdir' option - or else specify the 1565 | location of your \`git' binary by setting \`GIT' in the 1566 | environment so that a fresh \`gnulib' submodule can be 1567 | cloned." 1568 | done 1569 | } 1570 | 1571 | require_gnulib_files_already_present=: 1572 | } 1573 | 1574 | 1575 | # require_gnulib_merge_changelog 1576 | # ------------------------------ 1577 | # See if we can use gnulib's git-merge-changelog merge driver. 1578 | require_gnulib_merge_changelog=func_require_gnulib_merge_changelog 1579 | func_require_gnulib_merge_changelog () 1580 | { 1581 | $debug_cmd 1582 | 1583 | test -f ChangeLog && { 1584 | $require_git 1585 | 1586 | test true = "$GIT" || { 1587 | if $GIT config merge.merge-changelog.driver >/dev/null ; then 1588 | : 1589 | elif (git-merge-changelog --version) >/dev/null 2>&1 ; then 1590 | func_echo "initializing git-merge-changelog driver" 1591 | $GIT config merge.merge-changelog.name 'GNU-style ChangeLog merge driver' 1592 | $GIT config merge.merge-changelog.driver 'git-merge-changelog %O %A %B' 1593 | else 1594 | func_warning recommend \ 1595 | "Consider installing git-merge-changelog from gnulib." 1596 | fi 1597 | } 1598 | } 1599 | 1600 | require_gnulib_merge_changelog=: 1601 | } 1602 | 1603 | 1604 | # require_gnulib_mk 1605 | # ----------------- 1606 | # Ensure gnulib_mk has a sensible value, extracted from `gnulib-cache.m4' 1607 | # if possible, otherwise letting `gnulib-tool' pick a default. 1608 | require_gnulib_mk=func_require_gnulib_mk 1609 | func_require_gnulib_mk () 1610 | { 1611 | $debug_cmd 1612 | 1613 | test -n "$gnulib_mk" || { 1614 | $require_gnulib_cache 1615 | $require_macro_dir 1616 | 1617 | func_extract_trace "gl_MAKEFILE_NAME" "$gnulib_cache" 1618 | gnulib_mk="$func_extract_trace_result" 1619 | 1620 | test -n "$gnulib_mk" && func_verbose "gnulib_mk='$gnulib_mk'" 1621 | } 1622 | 1623 | require_gnulib_mk=: 1624 | } 1625 | 1626 | 1627 | # require_gnulib_path 1628 | # require_gnulib_url 1629 | # ------------------- 1630 | # Ensure `gnulib_path' and `gnulib_url' are set. 1631 | require_gnulib_path=func_require_dotgitmodules_parameters 1632 | require_gnulib_url=func_require_dotgitmodules_parameters 1633 | func_require_dotgitmodules_parameters () 1634 | { 1635 | $debug_cmd 1636 | 1637 | $require_git 1638 | 1639 | if test true = "$GIT"; then 1640 | # If we can't find git (or if the user specified `--skip-git'), 1641 | # then use an existing gnulib directory specified with 1642 | # `--gnulib-srcdir' if possible. 1643 | test -n "$gnulib_path" \ 1644 | || test ! -x "$opt_gnulib_srcdir/gnulib-tool" \ 1645 | || gnulib_path="$opt_gnulib_srcdir" 1646 | fi 1647 | 1648 | $require_dotgitmodules 1649 | 1650 | # Extract the parameters with sed, since git may be missing 1651 | test -n "$gnulib_path" \ 1652 | || gnulib_path=`sed -e '/^.submodule "gnulib".$/,${ 1653 | /[ ]*path *= */{ 1654 | s,[ ]*,,g;s,^[^=]*=,,;p 1655 | } 1656 | };d' .gitmodules | sed 1q` 1657 | test -n "$gnulib_url" \ 1658 | || gnulib_url=`sed -e '/^.submodule "gnulib".$/,${ 1659 | /[ ]*url *= */{ 1660 | s,[ ]*,,g;s,^[^=]*=,,;p 1661 | } 1662 | };d' .gitmodules | sed 1q` 1663 | 1664 | func_verbose "gnulib_path='$gnulib_path'" 1665 | func_verbose "gnulib_url='$gnulib_url'" 1666 | 1667 | require_gnulib_path=: 1668 | require_gnulib_url=: 1669 | } 1670 | 1671 | 1672 | # require_gnulib_submodule 1673 | # ------------------------ 1674 | # Ensure that there is a current gnulib submodule at `$gnulib_path'. 1675 | require_gnulib_submodule=func_require_gnulib_submodule 1676 | func_require_gnulib_submodule () 1677 | { 1678 | $debug_cmd 1679 | 1680 | $require_git 1681 | 1682 | if test true = "$GIT"; then 1683 | func_warning recommend \ 1684 | "No \`git' found; imported gnulib modules may be outdated." 1685 | else 1686 | $require_gnulib_path 1687 | $require_gnulib_url 1688 | 1689 | if test -f .gitmodules && test -f "$gnulib_path/gnulib-tool"; then 1690 | func_show_eval "$GIT submodule update" \ 1691 | 'func_fatal_error "Error: Unable to update gnulib submodule."' 1692 | 1693 | elif test -n "$opt_gnulib_srcdir"; then 1694 | # Older git can't clone into an empty directory. 1695 | rmdir "$gnulib_path" 2>/dev/null 1696 | func_show_eval "$GIT clone --reference '$opt_gnulib_srcdir' \ 1697 | '$gnulib_url' '$gnulib_path'" \ 1698 | && func_show_eval "$GIT submodule init" \ 1699 | && func_show_eval "$GIT submodule update" \ 1700 | || func_fatal_error "Error: Unable to fetch gnulib submodule." 1701 | 1702 | # Without --gnulib-srcdir, and no existing checked out submodule, we 1703 | # create a new shallow clone of the remote gnulib repository. 1704 | else 1705 | trap func_cleanup_gnulib 1 2 13 15 1706 | 1707 | shallow= 1708 | $GIT clone -h 2>&1 |func_grep_q -- --depth \ 1709 | && shallow='--depth 2' 1710 | 1711 | func_show_eval "$GIT clone $shallow '$gnulib_url' '$gnulib_path'" \ 1712 | func_cleanup_gnulib 1713 | 1714 | trap - 1 2 13 15 1715 | fi 1716 | fi 1717 | 1718 | require_gnulib_submodule=: 1719 | } 1720 | 1721 | 1722 | # require_gnulib_tool 1723 | # ------------------- 1724 | # Ensure that `$gnulib_tool' is set, and points to an executable file, 1725 | # or else fall back to using the binary `true' if the main gnulib 1726 | # files appear to have been imported already. 1727 | require_gnulib_tool=func_require_gnulib_tool 1728 | func_require_gnulib_tool () 1729 | { 1730 | $debug_cmd 1731 | 1732 | $require_gnulib_submodule 1733 | 1734 | test true = "$gnulib_tool" || { 1735 | $require_gnulib_path 1736 | 1737 | test -n "$gnulib_tool" \ 1738 | || gnulib_tool="$gnulib_path/gnulib-tool" 1739 | 1740 | test -x "$gnulib_tool" || { 1741 | $require_gnulib_files_already_present 1742 | 1743 | gnulib_tool=true 1744 | func_warning recommend \ 1745 | "No \`gnulib-tool' found; gnulib modules may be missing." 1746 | } 1747 | 1748 | test true = "$gnulib_tool" \ 1749 | || func_verbose "found \`$gnulib_tool'" 1750 | } 1751 | 1752 | require_gnulib_tool=: 1753 | } 1754 | 1755 | 1756 | # require_libtoolize 1757 | # ------------------ 1758 | # Skip libtoolize if it's not needed. 1759 | require_libtoolize=func_require_libtoolize 1760 | func_require_libtoolize () 1761 | { 1762 | $debug_cmd 1763 | 1764 | # Unless we're not searching for libtool use by this package, set 1765 | # LIBTOOLIZE to true if none of `LT_INIT', `AC_PROG_LIBTOOL' and 1766 | # `AM_PROG_LIBTOOL' are used in configure. 1767 | test true = "$LIBTOOLIZE" || { 1768 | func_extract_trace LT_INIT 1769 | test -n "$func_extract_trace_result"||func_extract_trace AC_PROG_LIBTOOL 1770 | test -n "$func_extract_trace_result"||func_extract_trace AM_PROG_LIBTOOL 1771 | test -n "$func_extract_trace_result"||LIBTOOLIZE=true 1772 | } 1773 | 1774 | test -n "$LIBTOOLIZE" || { 1775 | # Find libtoolize, named glibtoolize in Mac Ports, but prefer 1776 | # user-installed libtoolize to ancient glibtoolize shipped by 1777 | # Apple with Mac OS X when Mac Ports is not installed. 1778 | func_find_tool LIBTOOLIZE libtoolize glibtoolize 1779 | } 1780 | 1781 | func_verbose "export LIBTOOLIZE='$LIBTOOLIZE'" 1782 | 1783 | # Make sure the search result is visible to subshells 1784 | export LIBTOOLIZE 1785 | 1786 | require_libtoolize=: 1787 | } 1788 | 1789 | 1790 | # require_macro_dir 1791 | # ----------------- 1792 | # Ensure that `$macro_dir' is set, and if it doesn't already point to an 1793 | # existing directory, create one. 1794 | require_macro_dir=func_require_macro_dir 1795 | func_require_macro_dir () 1796 | { 1797 | $debug_cmd 1798 | 1799 | # Sometimes this is stored in `configure.ac'. 1800 | test -n "$macro_dir" || { 1801 | func_extract_trace AC_CONFIG_MACRO_DIR 1802 | macro_dir="$func_extract_trace_result" 1803 | } 1804 | 1805 | # Otherwise we might find it in `Makefile.am'. 1806 | test -n "$macro_dir" || { 1807 | $require_aclocal_amflags 1808 | 1809 | my_sed_scan='s|^.*-I[ ]*\([^ ]*\) .*|\1|' 1810 | 1811 | # Trailing space in echo is required by the sed script. 1812 | macro_dir=`echo "$aclocal_amflags " |$SED "$my_sed_scan"` 1813 | } 1814 | 1815 | func_verbose "macro_dir='$macro_dir'" 1816 | 1817 | func_check_configuration macro_dir \ 1818 | "AC_CONFIG_MACRO_DIR([name of a directory for configure m4 files])" 1819 | 1820 | $require_vc_ignore_files 1821 | 1822 | # If the macro_dir directory doesn't exist, create it now, and mark it 1823 | # as ignored for the VCS. 1824 | if test ! -d "$macro_dir"; then 1825 | mkdir "$macro_dir" || func_permissions_error "$macro_dir" 1826 | 1827 | test -n "$vc_ignore_files" \ 1828 | || func_insert_sorted_if_absent "$macro_dir" $vc_ignore_files 1829 | fi 1830 | 1831 | require_macro_dir=: 1832 | } 1833 | 1834 | 1835 | # require_makefile_am 1836 | # ------------------- 1837 | # Ensure there is a `Makefile.am' in the current directory. 1838 | # names an existing file. 1839 | require_makefile_am=func_require_makefile_am 1840 | func_require_makefile_am () 1841 | { 1842 | $debug_cmd 1843 | 1844 | test -n "$makefile_am" \ 1845 | || makefile_am="Makefile.am" 1846 | 1847 | <"$makefile_am" 1848 | 1849 | func_verbose "found \`$makefile_am'" 1850 | 1851 | require_makefile_am=: 1852 | } 1853 | 1854 | 1855 | # require_package 1856 | # --------------- 1857 | # Ensure that `$package' contains a sensible default value. 1858 | require_package=func_require_package 1859 | func_require_package () 1860 | { 1861 | $debug_cmd 1862 | 1863 | test -n "$package" || { 1864 | $require_package_name 1865 | 1866 | package=`echo "$package_name" \ 1867 | |$SED 's/GNU //;y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'` 1868 | } 1869 | 1870 | func_verbose "package='$package'" 1871 | 1872 | require_package=: 1873 | } 1874 | 1875 | 1876 | # require_package_bugreport 1877 | # ------------------------- 1878 | # Ensure that this has a sensible value, extracted from `configure.ac' 1879 | # if appropriate (and possible!). 1880 | require_package_bugreport=func_require_package_bugreport 1881 | func_require_package_bugreport () 1882 | { 1883 | $debug_cmd 1884 | 1885 | func_extract_trace AC_INIT 1886 | 1887 | save_ifs="$IFS" 1888 | IFS=: 1889 | set dummy $func_extract_trace_result 1890 | IFS="$save_ifs" 1891 | shift 1892 | 1893 | test -n "$package_bugreport" || package_bugreport="$3" 1894 | func_check_configuration package_bugreport \ 1895 | "AC_INIT([$package_name], [$package_version], [bug-$package@gnu.org])" 1896 | func_verbose "package_bugreport='$package_bugreport'" 1897 | 1898 | require_package_bugreport=: 1899 | } 1900 | 1901 | 1902 | # require_package_name 1903 | # -------------------- 1904 | # Ensure that this has a sensible value, extracted from `configure.ac' 1905 | # if appropriate (and possible!). 1906 | require_package_name=func_require_package_name 1907 | func_require_package_name () 1908 | { 1909 | $debug_cmd 1910 | 1911 | func_extract_trace AC_INIT 1912 | 1913 | save_ifs="$IFS" 1914 | IFS=: 1915 | set dummy $func_extract_trace_result 1916 | IFS="$save_ifs" 1917 | shift 1918 | 1919 | test -n "$package_name" || package_name="$1" 1920 | func_check_configuration package_name \ 1921 | "AC_INIT([name of your package], [package version number])" 1922 | func_verbose "package_name='$package_name'" 1923 | 1924 | require_package_name=: 1925 | } 1926 | 1927 | 1928 | # require_package_version 1929 | # ----------------------- 1930 | # Ensure that this has a sensible value, extracted from `configure.ac' 1931 | # if appropriate (and possible!). While we might have set all the 1932 | # parameters extracted from AC_INIT at once, `package_version' in 1933 | # particular is not necessarily available as early as the others, since 1934 | # `git-version-gen' is often involved, and until then we can't rely on 1935 | # getting a correct version number from an AC_INIT extraction. 1936 | require_package_version=func_require_package_version 1937 | func_require_package_version () 1938 | { 1939 | $debug_cmd 1940 | 1941 | func_extract_trace AC_INIT 1942 | 1943 | save_ifs="$IFS" 1944 | IFS=: 1945 | set dummy $func_extract_trace_result 1946 | IFS="$save_ifs" 1947 | shift 1948 | 1949 | test -n "$package_version" || package_version="$2" 1950 | func_check_configuration package_version \ 1951 | "AC_INIT([$package_name], [package version number])" 1952 | func_verbose "package_version='$package_version'" 1953 | 1954 | require_package_version=: 1955 | } 1956 | 1957 | 1958 | # require_source_base 1959 | # ------------------- 1960 | # Ensure that source_base has a sensible value, extracted from 1961 | # `gnulib-cache.m4' if possible. 1962 | require_source_base=func_require_source_base 1963 | func_require_source_base () 1964 | { 1965 | $debug_cmd 1966 | 1967 | $require_gnulib_cache 1968 | 1969 | test -f "$gnulib_cache" && test x = "x$source_base" && { 1970 | $require_macro_dir 1971 | 1972 | func_extract_trace "gl_SOURCE_BASE" "$gnulib_cache" 1973 | 1974 | source_base="$func_extract_trace_result" 1975 | 1976 | func_verbose "source_base='$source_base'" 1977 | } 1978 | 1979 | # Only prevent repeated calls if we found something... 1980 | # gnulib-cache.m4 might arrive before the next call. 1981 | test -n "$source_base" && require_source_base=: 1982 | } 1983 | 1984 | 1985 | # require_vc_ignore_files 1986 | # ----------------------- 1987 | # Ensure that `$vc_ignore' has been processed to list VCS ignore files 1988 | # in `$vc_ignore_files' 1989 | require_vc_ignore_files=func_require_vc_ignore_files 1990 | func_require_vc_ignore_files () 1991 | { 1992 | $debug_cmd 1993 | 1994 | test -n "$vc_ignore" || vc_ignore=auto 1995 | 1996 | if test auto = "$vc_ignore" && test x = x"$vc_ignore_files"; then 1997 | vc_ignore_files= 1998 | test -d .git && vc_ignore_files=.gitignore 1999 | test -d CVS && vc_ignore_files="$vc_ignore_files .cvsignore" 2000 | else 2001 | vc_ignore_files="$vc_ignore" 2002 | fi 2003 | 2004 | func_verbose "vc_ignore_files='$vc_ignore_files'" 2005 | 2006 | require_vc_ignore_files=: 2007 | } 2008 | 2009 | 2010 | ## ------------------## 2011 | ## Helper functions. ## 2012 | ## ------------------## 2013 | 2014 | # This section contains the helper functions used by the rest of `bootstrap'. 2015 | 2016 | # func_len STRING 2017 | # --------------- 2018 | # STRING may not start with a hyphen. 2019 | if (eval 'x=123; test x${#x} = "x3"') 2>/dev/null 2020 | then 2021 | # This is an XSI compatible shell, allowing a faster implementation... 2022 | eval 'func_len () 2023 | { 2024 | $debug_cmd 2025 | 2026 | func_len_result=${#1} 2027 | }' 2028 | else 2029 | # ...otherwise fall back to using expr, which is often a shell builtin. 2030 | func_len () 2031 | { 2032 | $debug_cmd 2033 | 2034 | func_len_result=`expr "$1" : ".*" 2>/dev/null || echo 0` 2035 | } 2036 | fi 2037 | 2038 | 2039 | # func_unset VAR 2040 | # -------------- 2041 | # Portably unset VAR. 2042 | func_unset () 2043 | { 2044 | { eval $1=; unset $1; } 2045 | } 2046 | unset=func_unset 2047 | 2048 | 2049 | # func_cmp_s FILE1 FILE2 2050 | # ---------------------- 2051 | # Return non-zero exit status unless FILE1 and FILE2 are identical, without 2052 | # output. 2053 | func_cmp_s () 2054 | { 2055 | $debug_cmd 2056 | 2057 | # This function relies on non-zero exit status, which will cause the 2058 | # program to exit when running in `set -e' mode. 2059 | $CMP "$@" >/dev/null 2>&1 2060 | } 2061 | 2062 | 2063 | # func_grep_q EXPRESSION [FILENAME..]. 2064 | # ------------------------------------ 2065 | # Check whether EXPRESSION matches any line of any listed FILENAME, 2066 | # without output. 2067 | func_grep_q () 2068 | { 2069 | $debug_cmd 2070 | 2071 | # This function relies on non-zero exit status, which will cause the 2072 | # program to exit when running in `set -e' mode. 2073 | $GREP "$@" >/dev/null 2>&1 2074 | } 2075 | 2076 | 2077 | # func_append_u VAR VALUE 2078 | # ----------------------- 2079 | # Append unique VALUE onto the existing contents of VAR, assuming 2080 | # entries are delimited by the first character of VALUE. For example: 2081 | # 2082 | # func_append_u options " --another-option option-argument" 2083 | # 2084 | # will only append to $options if " --another-option option-argument " 2085 | # is not already present somewhere in $options already (note spaces at 2086 | # each end implied by leading space in second argument). 2087 | func_append_u () 2088 | { 2089 | $debug_cmd 2090 | 2091 | eval my_current_value='`echo $'$1'`' 2092 | my_delim=`expr "$2" : '\(.\)'` 2093 | 2094 | case $my_delim$my_current_value$my_delim in 2095 | *"$2$my_delim"*) ;; 2096 | *) func_append "$@" ;; 2097 | esac 2098 | } 2099 | 2100 | 2101 | # func_strpad STR WIDTH CHAR 2102 | # -------------------------- 2103 | # Trim STR, or pad with CHAR to force a total length of WIDTH. 2104 | func_strpad () 2105 | { 2106 | $debug_cmd 2107 | 2108 | my_width=`expr "$2" - 1` 2109 | func_strpad_result=`echo "$1" |$SED ' 2110 | :a 2111 | s|^.\{0,'"$my_width"'\}$|&'"$3"'| 2112 | ta 2113 | '` 2114 | } 2115 | 2116 | 2117 | # func_strrpad STR WIDTH CHAR 2118 | # --------------------------- 2119 | # Trim STR, or right-justify-pad with CHAR to force a total length of 2120 | # WIDTH. 2121 | func_strrpad () 2122 | { 2123 | $debug_cmd 2124 | 2125 | my_width=`expr "$2" - 1` 2126 | func_strrpad_result=`echo "$1" |$SED ' 2127 | :a 2128 | s|^.\{0,'"$my_width"'\}$|'"$3"'&| 2129 | ta 2130 | '` 2131 | } 2132 | 2133 | 2134 | # func_strrow INDENT FIELD WIDTH [FIELDn WIDTHn]... 2135 | # ------------------------------------------------- 2136 | # Return a string containing each FIELD left justified to WIDTH, with 2137 | # the whole thing indented by INDENT spaces. This function is used to 2138 | # render one row of aligned columns for a table by func_strtable(). 2139 | func_strrow () 2140 | { 2141 | $debug_cmd 2142 | 2143 | func_strrow_linelen="$1"; shift 2144 | 2145 | my_row= 2146 | while test $# -gt 0; do 2147 | func_strrow_linelen=`expr $func_strrow_linelen + $2` 2148 | func_strpad "$1" $2 " " 2149 | func_append my_row "$func_strpad_result" 2150 | shift; shift 2151 | done 2152 | 2153 | func_strrpad "$my_row" $func_strrow_linelen " " 2154 | func_strrow_result="$func_strrpad_result" 2155 | } 2156 | 2157 | 2158 | # func_strtable INDENT WIDTH1...WIDTHn HEADER1...HEADERn FIELD1...FIELDn 2159 | # ---------------------------------------------------------------------- 2160 | # Generate a string of newline-separated rows arranged in lined-up 2161 | # columns of the given WIDTHs, with the entire table indented by INDENT 2162 | # spaces. The number of columns is determined by the number of integer 2163 | # valued WIDTH arguments following INDENT. The next set (i.e. a number 2164 | # of arguments equal to the number of WIDTH arguments) of fields are 2165 | # treated as the table's column HEADERs, and are separated from the 2166 | # remainder of the table by an indented row of `-' characters. Remaining 2167 | # arguments are each aligned below the next available header, wrapping 2168 | # to a new row as necessary. Finally another row of `-' characters is 2169 | # added to mark the end of the table. 2170 | # 2171 | # For example an unindented 3 column table with 2 rows of data would be 2172 | # generated by this call: 2173 | # 2174 | # func_strtable 3 20 10 25 \ 2175 | # Header1 Header2 Header3 \ 2176 | # Row1Col1 Row1Col2 Row1Col3 \ 2177 | # Row2Col1 Row2Col2 Row2Col3 2178 | # 2179 | # returning the following string: 2180 | # 2181 | # " Header1 Header2 Header3 2182 | # ------------------------------------------------------- 2183 | # Row1Col1 Row1Col2 Row1Col3 2184 | # Row2Col1 Row2Col2 Row2Col3 2185 | # -------------------------------------------------------" 2186 | func_strtable () 2187 | { 2188 | $debug_cmd 2189 | 2190 | # Save the indent value, we'll need it for each row we render. 2191 | my_indent="$1"; shift 2192 | 2193 | # Collect remaining numeric args into a list for reuse between 2194 | # members of each row when we call func_strrow later. 2195 | my_widths="$1"; shift 2196 | while test 0 -lt `expr "$1" : '[1-9][0-9]*$'`; do 2197 | func_append my_widths " $1"; shift 2198 | done 2199 | 2200 | # Extract the same number of positional parameters as there are 2201 | # width elements - we'll do the header rows separately so that 2202 | # we can insert a divider line. 2203 | my_header="$my_indent" 2204 | for my_width in $my_widths; do 2205 | func_append my_header " $1 $my_width"; shift 2206 | done 2207 | func_strrow $my_header 2208 | 2209 | # Strip off the indent, and make a divider with `-' chars, then 2210 | # reindent. 2211 | my_divider=`echo "$func_strrow_result" \ 2212 | |$SED 's|[^ ]|-|g 2213 | :a 2214 | s|- |--|g 2215 | ta 2216 | '` 2217 | 2218 | # Append the header and divider to the running result. 2219 | func_append func_strtable_result "\ 2220 | $func_strrow_result 2221 | $my_divider 2222 | " 2223 | 2224 | # The remaining rows are zipped between the width values we 2225 | # unwound earlier just like the header row above. 2226 | while test $# -gt 0; do 2227 | my_row="$my_indent" 2228 | for my_width in $my_widths; do 2229 | func_append my_row " $1 $my_width"; shift 2230 | done 2231 | func_strrow $my_row 2232 | func_append func_strtable_result "\ 2233 | $func_strrow_result 2234 | " 2235 | done 2236 | 2237 | # Mark the end of the table with a final divider line. 2238 | func_append func_strtable_result "$my_divider" 2239 | } 2240 | 2241 | 2242 | # func_echo ARG... 2243 | # ---------------- 2244 | # Echo program name prefixed message, taking newlines into account. 2245 | func_echo () 2246 | { 2247 | my_message="$*" 2248 | 2249 | save_IFS="$IFS" 2250 | IFS="$nl" 2251 | for my_line in $my_message; do 2252 | IFS="$save_IFS" 2253 | echo "$progname: $my_line" 2254 | done 2255 | IFS="$save_IFS" 2256 | } 2257 | 2258 | 2259 | # func_verbose ARG... 2260 | # ------------------- 2261 | # Echo program name prefixed message in verbose mode only. 2262 | func_verbose () 2263 | { 2264 | $opt_verbose && func_echo ${1+"$@"} 2265 | } 2266 | 2267 | 2268 | # func_error ARG... 2269 | # ----------------- 2270 | # Echo program name prefixed message to standard error. 2271 | func_error () 2272 | { 2273 | my_message="$*" 2274 | 2275 | save_IFS="$IFS" 2276 | IFS="$nl" 2277 | for my_line in $my_message; do 2278 | IFS="$save_IFS" 2279 | echo "$progname: $bold_on$my_line$bold_off" 1>&2 2280 | done 2281 | IFS="$save_IFS" 2282 | } 2283 | 2284 | # Allow display of bold text on terminals that support it 2285 | bold_on= 2286 | bold_off= 2287 | if test -t 1; then 2288 | if test -n "`tput bold 2>/dev/null`" \ 2289 | && test -n "`tput sgr0 2>/dev/null`" 2290 | then 2291 | bold_on=`tput bold` 2292 | bold_off=`tput sgr0` 2293 | fi 2294 | fi 2295 | 2296 | 2297 | # func_fatal_error ARG... 2298 | # ----------------------- 2299 | # Echo program name prefixed message to standard error, and exit. 2300 | func_fatal_error () 2301 | { 2302 | func_error ${1+"$@"} 2303 | exit $EXIT_FAILURE 2304 | } 2305 | 2306 | 2307 | # func_internal_error ARG... 2308 | # -------------------------- 2309 | # Echo program name prefixed message to standard error, and exit. 2310 | func_internal_error () 2311 | { 2312 | func_fatal_error "INTERNAL ERROR: " ${1+"$@"} " 2313 | Please report this bug to \`bug-gnulib@gnu.org' 2314 | in as much detail as possible." 2315 | } 2316 | 2317 | 2318 | # func_permissions_error FILE-OR-DIRECTORY 2319 | # ---------------------------------------- 2320 | # Echo program name prefixed permissions error message to standard 2321 | # error, and exit. 2322 | func_permissions_error () 2323 | { 2324 | $debug_cmd 2325 | 2326 | func_fatal_error "Error: Failed to create \`$1', check permissions." 2327 | } 2328 | 2329 | 2330 | # func_warning CATEGORY ARG... 2331 | # ---------------------------- 2332 | # Echo program name prefixed warning message to standard error. Warning 2333 | # messages can be filtered according to CATEGORY. 2334 | func_warning () 2335 | { 2336 | $debug_cmd 2337 | 2338 | case " $warning_categories " in 2339 | *" $1 "*) ;; 2340 | *) func_internal_error "invalid warning category \`$1'" ;; 2341 | esac 2342 | 2343 | my_category="$1" 2344 | shift 2345 | 2346 | case " $opt_warning " in 2347 | *" $my_category "*) $warning_func ${1+"$@"} ;; 2348 | esac 2349 | } 2350 | 2351 | 2352 | # func_fatal_help ARG... 2353 | # ---------------------- 2354 | # Echo program name prefixed message to standard error, followed by 2355 | # a help hint, and exit. 2356 | func_fatal_help () 2357 | { 2358 | $debug_cmd 2359 | 2360 | func_error ${1+"$@"} 2361 | func_fatal_error "$fatal_help" 2362 | } 2363 | fatal_help="Try \`$progname --help' for more information." ## default 2364 | 2365 | 2366 | # func_version 2367 | # ------------ 2368 | # Echo version message to standard output and exit. 2369 | func_version () 2370 | { 2371 | $debug_cmd 2372 | 2373 | cat </dev/null 2452 | then 2453 | # This is an XSI compatible shell, allowing a faster implementation... 2454 | eval 'func_split_short_opt () 2455 | { 2456 | $debug_cmd 2457 | 2458 | func_split_short_opt_arg=${1#??} 2459 | func_split_short_opt_name=${1%"$func_split_short_opt_arg"} 2460 | }' 2461 | else 2462 | # ...otherwise fall back to using expr, which is often a shell builtin. 2463 | func_split_short_opt () 2464 | { 2465 | $debug_cmd 2466 | 2467 | func_split_short_opt_name=`expr "x$1" : 'x-\(.\)'` 2468 | func_split_short_opt_arg=`expr "x$1" : 'x-.\(.*\)$'` 2469 | } 2470 | fi #func_split_short_opt 2471 | 2472 | 2473 | # func_split_equals STRING 2474 | # ------------------------ 2475 | # Set func_split_equals_lhs and func_split_equals_rhs shell variables after 2476 | # splitting STRING at the `=' sign. 2477 | if (eval 'x='--ab=cd'; y=${x#*=}; z=${x%%=*}; test x$y$z = xcd--ab') 2>/dev/null 2478 | then 2479 | # This is an XSI compatible shell, allowing a faster implementation... 2480 | eval 'func_split_equals () 2481 | { 2482 | $debug_cmd 2483 | 2484 | func_split_equals_lhs=${1%%=*} 2485 | func_split_equals_rhs=${1#*=} 2486 | test "x$func_split_equals_lhs" = "x$1" \ 2487 | && func_split_equals_rhs="" 2488 | }' 2489 | else 2490 | # ...otherwise fall back to using expr, which is often a shell builtin. 2491 | func_split_equals () 2492 | { 2493 | $debug_cmd 2494 | 2495 | func_split_equals_lhs=`expr "x$1" : 'x\([^=]*)'` 2496 | func_split_equals_rhs="" 2497 | test "x$func_split_equals_lhs" = "x$1" \ 2498 | || func_split_equals_rhs=`expr "x$1" : 'x[^=]*=\(.*\)$'` 2499 | } 2500 | fi #func_split_equals 2501 | 2502 | 2503 | # func_quote_for_eval ARG... 2504 | # -------------------------- 2505 | # Aesthetically quote ARGs to be evaled later. 2506 | # This function returns two values: FUNC_QUOTE_FOR_EVAL_RESULT 2507 | # is double-quoted, suitable for a subsequent eval, whereas 2508 | # FUNC_QUOTE_FOR_EVAL_UNQUOTED_RESULT has merely all characters 2509 | # which are still active within double quotes backslashified. 2510 | sed_quote_subst='s|\([`"$\\]\)|\\\1|g' 2511 | func_quote_for_eval () 2512 | { 2513 | $debug_cmd 2514 | 2515 | func_quote_for_eval_result= 2516 | 2517 | while test $# -gt 0; do 2518 | case $1 in 2519 | *[\\\`\"\$]*) 2520 | my_unquoted_arg=`printf "$1" | $SED "$sed_quote_subst"` ;; 2521 | *) 2522 | my_unquoted_arg="$1" ;; 2523 | esac 2524 | 2525 | case $my_unquoted_arg in 2526 | # Double-quote args containing shell metacharacters to delay 2527 | # word splitting, command substitution and variable expansion 2528 | # for a subsequent eval. 2529 | # Many Bourne shells cannot handle close brackets correctly 2530 | # in scan sets, so we specify it separately. 2531 | *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") 2532 | my_quoted_arg="\"$my_unquoted_arg\"" 2533 | ;; 2534 | *) 2535 | my_quoted_arg="$my_unquoted_arg" ;; 2536 | esac 2537 | test -n "$func_quote_for_eval_result" \ 2538 | && func_append func_quote_for_eval_result " " 2539 | func_append func_quote_for_eval_result "$my_quoted_arg" 2540 | shift 2541 | done 2542 | } 2543 | 2544 | 2545 | # func_show_eval CMD [FAIL_EXP] 2546 | # ----------------------------- 2547 | # Unless opt_silent is true, then output CMD. Then, if opt_dryrun is 2548 | # not true, evaluate CMD. If the evaluation of CMD fails, and FAIL_EXP 2549 | # is given, then evaluate it. 2550 | func_show_eval () 2551 | { 2552 | $debug_cmd 2553 | 2554 | my_cmd="$1" 2555 | my_fail_exp="${2-:}" 2556 | 2557 | ${opt_silent-false} || { 2558 | func_quote_for_eval $my_cmd 2559 | eval func_truncate_cmd $func_quote_for_eval_result 2560 | func_echo "running: $func_truncate_cmd_result" 2561 | } 2562 | 2563 | if ${opt_dry_run-false}; then :; else 2564 | eval "$my_cmd" 2565 | my_status=$? 2566 | if test "$my_status" -eq 0; then :; else 2567 | eval "(exit $my_status); $my_fail_exp" 2568 | fi 2569 | fi 2570 | } 2571 | 2572 | 2573 | # func_truncate_cmd CMD [ARG]... 2574 | # ------------------------------ 2575 | # For unreasonably long commands (such as a gnulib-tool invocation with 2576 | # the full module list for import), truncate CMD after the second non- 2577 | # option ARG. 2578 | func_truncate_cmd () 2579 | { 2580 | $debug_cmd 2581 | 2582 | my_last_arg_opt_p=false 2583 | func_truncate_cmd_result= 2584 | 2585 | set dummy "$@"; shift 2586 | 2587 | while test $# -gt 0; do 2588 | my_opt="$1"; shift 2589 | 2590 | test -n "$func_truncate_cmd_result" \ 2591 | && func_append func_truncate_cmd_result ' ' 2592 | func_append func_truncate_cmd_result "$my_opt" 2593 | 2594 | func_len "x$func_truncate_cmd_result" 2595 | 2596 | case $my_opt in 2597 | -*) my_last_arg_opt_p=: ;; 2598 | *) $my_last_arg_opt_p \ 2599 | || test $min_cmd_len -gt $func_len_result \ 2600 | || break 2601 | my_last_arg_opt_p=false 2602 | ;; 2603 | esac 2604 | done 2605 | 2606 | test $# -gt 0 && func_append func_truncate_cmd_result "..." 2607 | } 2608 | 2609 | 2610 | # func_extract_trace MACRO_NAME [FILENAME]... 2611 | # ------------------------------------------- 2612 | # set `$func_extract_trace_result' to a colon delimited list of 2613 | # arguments to MACRO_NAME in FILENAME. If no FILENAME is not given, 2614 | # then `configure.ac' is assumed. 2615 | func_extract_trace () 2616 | { 2617 | $debug_cmd 2618 | 2619 | $require_configure_ac 2620 | $require_gnu_m4 2621 | 2622 | my_macro="$1"; shift 2623 | test $# -gt 0 || { 2624 | set dummy $configure_ac 2625 | shift 2626 | } 2627 | 2628 | # Generate an error if the first file is missing 2629 | <"$1" 2630 | 2631 | # Sadly, we can't use `autom4te' tracing to extract macro 2632 | # arguments, because it complains about things we want to 2633 | # ignore at bootstrap time - like missing m4_include files; 2634 | # AC_PREREQ being newer than the installed autoconf; and 2635 | # returns nothing when tracing `AM_INIT_AUTOMAKE' when 2636 | # aclocal hasn't been generated yet. 2637 | # 2638 | # The following tries to emulate a less persnickety version 2639 | # of (and due to not having to wait for Perl startup on 2640 | # every invocation, it's probably faster too): 2641 | # 2642 | # autom4te --language=Autoconf --trace=$my_macro:\$% "$@" 2643 | # 2644 | # First we give a minimal set of macro declarations to M4 2645 | # to prime it for reading Autoconf macros, while still 2646 | # providing some of the functionality generally used at 2647 | # m4-time to supply dynamic arguments to Autocof functions, 2648 | # but without following `m4_s?include' files. 2649 | # 2650 | # We discard M4's stdout, but the M4 trace output from reading 2651 | # our "autoconf.mini" followed by any other files passed to 2652 | # this function is then scanned by sed to transform it into 2653 | # a colon delimited argument list assigned to a shell variable. 2654 | # 2655 | # Finally, we `eval' the sed generated assignment to get 2656 | # the result back into this script for further use by callers 2657 | # of this function. 2658 | 2659 | func_extract_trace_result= 2660 | eval `echo ' 2661 | # Initialisation. 2662 | m4_changequote([,]) 2663 | m4_define([m4_copy], [m4_define([$2], m4_defn([$1]))]) 2664 | m4_define([m4_rename], [m4_copy([$1], [$2])m4_undefine([$1])]) 2665 | 2666 | # Disable these macros. 2667 | m4_undefine([m4_dnl]) 2668 | m4_undefine([m4_include]) 2669 | m4_undefine([m4_m4exit]) 2670 | m4_undefine([m4_m4wrap]) 2671 | m4_undefine([m4_maketemp]) 2672 | 2673 | # Copy and rename macros not handled by "m4 --prefix". 2674 | m4_define([dnl], [m4_builtin([dnl])]) 2675 | m4_copy([m4_define], [m4_defun]) 2676 | m4_rename([m4_ifelse], [m4_if]) 2677 | m4_ifdef([m4_mkstemp], [m4_undefine([m4_mkstemp])]) 2678 | m4_rename([m4_patsubst], [m4_bpatsubst]) 2679 | m4_rename([m4_regexp], [m4_bregexp]) 2680 | 2681 | # "m4sugar.mini" - useful m4-time macros for dynamic arguments. 2682 | # If we discover packages that need more m4 macros defined in 2683 | # order to bootstrap correctly, add them here: 2684 | m4_define([m4_bmatch], 2685 | [m4_if([$#], 0, [], [$#], 1, [], [$#], 2, [$2], 2686 | [m4_if(m4_bregexp([$1], [$2]), -1, 2687 | [$0([$1], m4_shift3($@))], [$3])])]) 2688 | m4_define([m4_ifndef], [m4_ifdef([$1], [$3], [$2])]) 2689 | m4_define([m4_ifset], 2690 | [m4_ifdef([$1], [m4_ifval(m4_defn([$1]), [$2], [$3])], [$3])]) 2691 | m4_define([m4_require], [$1]) 2692 | m4_define([m4_shift3], [m4_shift(m4shift(m4shift($@)))]) 2693 | 2694 | # "autoconf.mini" - things from autoconf macros we care about. 2695 | m4_copy([m4_defun], [AC_DEFUN]) 2696 | 2697 | # Dummy definition for the macro we want to trace. 2698 | # AM_INIT_AUTOMAKE at least produces no trace without this. 2699 | AC_DEFUN(['"$my_macro"'])' \ 2700 | |$M4 -daq --prefix --trace="$my_macro" - "$@" 2>&1 1>/dev/null \ 2701 | |$SED -n 's|#.*$|| 2702 | /^m4trace: -1- '"$my_macro"'/ { 2703 | s|^m4trace: -1- '"$my_macro"'[([]*|func_extract_trace_result='\''| 2704 | s|], [[]|:|g 2705 | s|[])]*$|:'\''| 2706 | s|[^'\'']$|\&'\''| 2707 | p 2708 | }'` 2709 | 2710 | # Leave the ':' sentinel in place for successfully traced macros 2711 | # without arguments, otherwise remove it so that the results of 2712 | # single-argument macros can be used without additional parsing. 2713 | test : = "$func_extract_trace_result" \ 2714 | || func_extract_trace_result=`echo "$func_extract_trace_result" |$SED 's|:$||'` 2715 | } 2716 | 2717 | 2718 | # func_insert_sorted_if_absent STR FILE... 2719 | # ---------------------------------------- 2720 | # If $STR is not already on a line by itself in $FILE, insert it, 2721 | # sorting the new contents of the file and replacing $FILE with the result. 2722 | func_insert_sorted_if_absent () 2723 | { 2724 | $debug_cmd 2725 | 2726 | str=$1 2727 | shift 2728 | 2729 | for file 2730 | do 2731 | test -f $file || touch $file 2732 | 2733 | func_grep_q "$str" "$file" \ 2734 | && func_verbose "inserting \`$str' into \`$file'" 2735 | 2736 | echo "$str" | sort -u - $file | func_cmp_s - $file \ 2737 | || echo "$str" | sort -u - $file -o $file \ 2738 | || func_permissions_error "$file" 2739 | done 2740 | } 2741 | 2742 | 2743 | # func_sort_ver VER1 VER2 2744 | # ----------------------- 2745 | # Note this deviates from the version comparison in automake 2746 | # in that it treats 1.5 < 1.5.0, and treats 1.4.4a < 1.4-p3a 2747 | # but this should suffice as we won't be specifying old 2748 | # version formats or redundant trailing .0 in bootstrap.conf. 2749 | # If we did want full compatibility then we should probably 2750 | # use m4_version_compare from autoconf. 2751 | func_sort_ver () # sort -V is not generally available 2752 | { 2753 | $debug_cmd 2754 | 2755 | ver1="$1" 2756 | ver2="$2" 2757 | 2758 | # split on '.' and compare each component 2759 | i=1 2760 | while : ; do 2761 | p1=`echo "$ver1" | cut -d. -f$i` 2762 | p2=`echo "$ver2" | cut -d. -f$i` 2763 | if test ! "$p1"; then 2764 | echo "$1 $2" 2765 | break 2766 | elif test ! "$p2"; then 2767 | echo "$2 $1" 2768 | break 2769 | elif test ! "$p1" = "$p2"; then 2770 | if test "$p1" -gt "$p2" 2>/dev/null; then # numeric comparison 2771 | echo "$2 $1" 2772 | elif test "$p2" -gt "$p1" 2>/dev/null; then # numeric comparison 2773 | echo "$1 $2" 2774 | else # numeric, then lexicographic comparison 2775 | lp=`printf "$p1\n$p2\n" | sort -n | tail -n1` 2776 | if test "$lp" = "$p2"; then 2777 | echo "$1 $2" 2778 | else 2779 | echo "$2 $1" 2780 | fi 2781 | fi 2782 | break 2783 | fi 2784 | i=`expr $i + 1` 2785 | done 2786 | } 2787 | 2788 | 2789 | # func_get_version APP 2790 | # -------------------- 2791 | # echo the version number (if any) of APP, which is looked up along your 2792 | # PATH. 2793 | func_get_version () 2794 | { 2795 | $debug_cmd 2796 | 2797 | app=$1 2798 | 2799 | { $app --version || $app --version /dev/null 2>&1 \ 2800 | || return 1 2801 | 2802 | $app --version 2>&1 | 2803 | $SED -n '# extract version within line 2804 | s|.*[v ]\{1,\}\([0-9]\{1,\}\.[.a-z0-9-]*\).*|\1| 2805 | t done 2806 | 2807 | # extract version at start of line 2808 | s|^\([0-9]\{1,\}\.[.a-z0-9-]*\).*|\1| 2809 | t done 2810 | 2811 | d 2812 | 2813 | :done 2814 | #the following essentially does s|5.005|5.5| 2815 | s|\.0*\([1-9]\)|.\1|g 2816 | p 2817 | q' 2818 | } 2819 | 2820 | 2821 | # func_check_versions APP1 VER1 URL1 ...[APPN VERN URLN] 2822 | # ------------------------------------------------------ 2823 | func_check_versions () 2824 | { 2825 | $debug_cmd 2826 | 2827 | func_check_versions_result=: 2828 | 2829 | while test $# -gt 0; do 2830 | my_app="$1"; shift 2831 | my_reqver="$1"; shift 2832 | my_url="$1"; shift 2833 | 2834 | # Honor $APP variables ($TAR, $AUTOCONF, etc.) 2835 | my_appvar=`echo $my_app | tr '[a-z]' '[A-Z]'` 2836 | test "$my_appvar" = TAR && my_appvar=AMTAR 2837 | eval "my_app=\${$my_appvar-$my_app}" 2838 | my_instver=`func_get_version $my_app` 2839 | 2840 | test ! "$my_instver" \ 2841 | || func_verbose "found \`$my_app' version $my_instver" 2842 | 2843 | # Fail if --version didn't work. 2844 | if test ! "$my_instver"; then 2845 | func_error "Error: \`$my_app' not found" 2846 | func_check_versions_result=false 2847 | 2848 | # Fail if a new version than what we have is required. 2849 | elif test ! "$my_reqver" = "-"; then 2850 | my_newer=`func_sort_ver $my_reqver $my_instver | cut -d' ' -f2` 2851 | test ! "$my_newer" = "$my_instver" && { 2852 | func_error "\ 2853 | Error: \`$my_app' version == $my_instver is too old 2854 | \`$my_app' version >= $my_reqver is required" 2855 | func_check_versions_result=false 2856 | } 2857 | fi 2858 | done 2859 | } 2860 | 2861 | 2862 | # func_cleanup_gnulib 2863 | # ------------------- 2864 | # Recursively delete everything below the path in the global variable 2865 | # GNULIB_PATH. 2866 | func_cleanup_gnulib () 2867 | { 2868 | $debug_cmd 2869 | 2870 | status=$? 2871 | $RM -fr "$gnulib_path" 2872 | exit $status 2873 | } 2874 | 2875 | 2876 | # func_symlink_to_dir SRCDIR FILENAME [DEST_FILENAME] 2877 | # --------------------------------------------------- 2878 | # Make a symlink from FILENAME in SRCDIR to the current directory, 2879 | # optionally calling the symlink DEST_FILENAME. 2880 | func_symlink_to_dir () 2881 | { 2882 | $debug_cmd 2883 | 2884 | $require_vc_ignore_files 2885 | 2886 | src=$1/$2 2887 | dst=${3-$2} 2888 | 2889 | test -f "$src" && { 2890 | 2891 | # If the destination directory doesn't exist, create it. 2892 | # This is required at least for "lib/uniwidth/cjk.h". 2893 | dst_dir=`dirname "$dst"` 2894 | if ! test -d "$dst_dir"; then 2895 | mkdir -p "$dst_dir" 2896 | 2897 | # If we've just created a directory like lib/uniwidth, 2898 | # tell version control system(s) it's ignorable. 2899 | # FIXME: for now, this does only one level 2900 | parent=`dirname "$dst_dir"` 2901 | for dot_ig in x $vc_ignore_files; do 2902 | test $dot_ig = x && continue 2903 | ig=$parent/$dot_ig 2904 | func_insert_sorted_if_absent `echo "$dst_dir" |$SED 's|.*/||'` $ig 2905 | done 2906 | fi 2907 | 2908 | if $opt_copy; then 2909 | { 2910 | test ! -h "$dst" \ 2911 | || func_show_eval "$RM -f '$dst'" 2912 | } \ 2913 | && test -f "$dst" \ 2914 | && func_cmp_s "$src" "$dst" \ 2915 | && func_echo "copying file \`$src'" \ 2916 | && cp -fp "$src" "$dst" 2917 | else 2918 | test -h "$dst" \ 2919 | && src_ls=`ls -diL "$src" 2>/dev/null` \ 2920 | && set $src_ls && src_i=$1 \ 2921 | && dst_ls=`ls -diL "$dst" 2>/dev/null` \ 2922 | && set $dst_ls && dst_i=$1 \ 2923 | && test "$src_i" = "$dst_i" \ 2924 | || { 2925 | dot_dots= 2926 | case $src in 2927 | /*) ;; 2928 | *) 2929 | case /$dst/ in 2930 | *//* | */../* | */./* | /*/*/*/*/*/) 2931 | func_fatal_error "\ 2932 | Error: Invalid symlink calculation: $src -> $dst" 2933 | ;; 2934 | /*/*/*/*/) dot_dots=../../../;; 2935 | /*/*/*/) dot_dots=../../;; 2936 | /*/*/) dot_dots=../;; 2937 | esac 2938 | ;; 2939 | esac 2940 | 2941 | func_echo "linking file \`$src'" 2942 | ln -fs "$dot_dots$src" "$dst" 2943 | } 2944 | fi 2945 | } 2946 | } 2947 | 2948 | 2949 | # func_download_po_files SUBDIR DOMAIN 2950 | # ------------------------------------ 2951 | func_download_po_files () 2952 | { 2953 | $debug_cmd 2954 | 2955 | func_echo "getting translations into $1 for $2..." 2956 | cmd=`printf "$po_download_command_format" "$2" "$1"` 2957 | eval "$cmd" 2958 | } 2959 | 2960 | 2961 | # func_find_tool ENVVAR NAMES... 2962 | # ------------------------------ 2963 | # Search for a required program. Use the value of ENVVAR, if set, 2964 | # otherwise find the first of the NAMES that can be run (i.e., 2965 | # supports --version). If found, set ENVVAR to the program name, 2966 | # die otherwise. 2967 | func_find_tool () 2968 | { 2969 | $debug_cmd 2970 | 2971 | find_tool_envvar=$1 2972 | shift 2973 | find_tool_names=$@ 2974 | eval "find_tool_res=\$$find_tool_envvar" 2975 | if test x"$find_tool_res" = x; then 2976 | for i 2977 | do 2978 | if ($i --version /dev/null 2>&1; then 2979 | find_tool_res=$i 2980 | break 2981 | fi 2982 | done 2983 | else 2984 | find_tool_error_prefix="\$$find_tool_envvar: " 2985 | fi 2986 | test x"$find_tool_res" = x && func_fatal_error "\ 2987 | Error: One of these is required: 2988 | $find_tool_names" 2989 | 2990 | ($find_tool_res --version /dev/null 2>&1 \ 2991 | || func_fatal_error "\ 2992 | Error: ${find_tool_error_prefix}Cannot run \`$find_tool_res --version'" 2993 | 2994 | eval "$find_tool_envvar=\$find_tool_res" 2995 | eval "export $find_tool_envvar" 2996 | } 2997 | 2998 | 2999 | # func_update_po_files PO_DIR DOMAIN 3000 | # ---------------------------------- 3001 | # Mirror .po files to $po_dir/.reference and copy only the new 3002 | # or modified ones into $po_dir. Also update $po_dir/LINGUAS. 3003 | # Note po files that exist locally only are left in $po_dir but will 3004 | # not be included in LINGUAS and hence will not be distributed. 3005 | func_update_po_files () 3006 | { 3007 | $debug_cmd 3008 | 3009 | # Directory containing primary .po files. 3010 | # Overwrite them only when we're sure a .po file is new. 3011 | po_dir=$1 3012 | domain=$2 3013 | 3014 | # Mirror *.po files into this dir. 3015 | # Usually contains *.s1 checksum files. 3016 | ref_po_dir="$po_dir/.reference" 3017 | 3018 | test -d $ref_po_dir || mkdir $ref_po_dir || return 3019 | func_download_po_files $ref_po_dir $domain \ 3020 | && ls "$ref_po_dir"/*.po 2>/dev/null | 3021 | $SED 's|.*/||; s|\.po$||' > "$po_dir/LINGUAS" || return 3022 | 3023 | # Find sha1sum, named gsha1sum on MacPorts, and shasum on MacOS 10.6. 3024 | func_find_tool SHA1SUM sha1sum gsha1sum shasum 3025 | 3026 | langs=`cd $ref_po_dir && echo *.po|$SED 's|\.po||g'` 3027 | test "$langs" = '*' && langs=x 3028 | for po in $langs; do 3029 | case $po in x) continue;; esac 3030 | new_po="$ref_po_dir/$po.po" 3031 | cksum_file="$ref_po_dir/$po.s1" 3032 | if ! test -f "$cksum_file" || 3033 | ! test -f "$po_dir/$po.po" || 3034 | ! $SHA1SUM -c --status "$cksum_file" \ 3035 | < "$new_po" > /dev/null; then 3036 | echo "updated $po_dir/$po.po..." 3037 | cp "$new_po" "$po_dir/$po.po" \ 3038 | && $SHA1SUM < "$new_po" > "$cksum_file" 3039 | fi 3040 | done 3041 | } 3042 | 3043 | 3044 | 3045 | ## ----------------- ## 3046 | ## Global variables. ## 3047 | ## ----------------- ## 3048 | 3049 | EXIT_SUCCESS=0 3050 | EXIT_FAILURE=1 3051 | EXIT_MISMATCH=63 # $? = 63 is used to indicate version mismatch to missing. 3052 | EXIT_SKIP=77 # $? = 77 is used to indicate a skipped test to automake. 3053 | 3054 | exit_status=$EXIT_SUCCESS 3055 | 3056 | # Allow overriding, eg to get a function call trace: 3057 | # debug_cmd='eval echo "${FUNCNAME[0]} $*" >&2' bash bootstrap 3058 | debug_cmd="${debug_cmd-:}" 3059 | exit_cmd=: 3060 | 3061 | dirname='s|/[^/]*$||' 3062 | basename='s|^.*/||' 3063 | 3064 | nl=' 3065 | ' 3066 | 3067 | # Work around backward compatibility issue on IRIX 6.5. On IRIX 6.4+, sh 3068 | # is ksh but when the shell is invoked as "sh" and the current value of 3069 | # the _XPG environment variable is not equal to 1 (one), the special 3070 | # positional parameter $0, within a function call, is the name of the 3071 | # function. 3072 | progpath="$0" 3073 | 3074 | # The name of this program: 3075 | progname=`echo "$progpath" |$SED "$basename"` 3076 | 3077 | ## -------------------------------------------------- ## 3078 | ## Source package customisations in `bootstrap.conf'. ## 3079 | ## -------------------------------------------------- ## 3080 | 3081 | # Override the default configuration, if necessary. 3082 | # Make sure that bootstrap.conf is sourced from the current directory 3083 | # if we were invoked as "sh bootstrap". 3084 | case "$0" in 3085 | */*) test -r "$0.conf" && . "$0.conf" ;; 3086 | *) test -r "$0.conf" && . ./"$0.conf" ;; 3087 | esac 3088 | 3089 | 3090 | ## ------------------------------- ## 3091 | ## Actually perform the bootstrap. ## 3092 | ## ------------------------------- ## 3093 | 3094 | func_bootstrap ${1+"$@"} 3095 | 3096 | # The End. 3097 | exit $exit_status 3098 | 3099 | # Local variables: 3100 | # mode: shell-script 3101 | # sh-indentation: 2 3102 | # eval: (add-hook 'write-file-hooks 'time-stamp) 3103 | # time-stamp-start: "scriptversion=" 3104 | # time-stamp-format: "%:y-%02m-%02d.%02H" 3105 | # time-stamp-time-zone: "UTC" 3106 | # time-stamp-end: "; # UTC" 3107 | # End: 3108 | -------------------------------------------------------------------------------- /bootstrap.conf: -------------------------------------------------------------------------------- 1 | # bootstrap.conf (lcurses) version 2011-09-07 2 | # Written by Gary V. Vaughan, 2010 3 | 4 | # Copyright (C) 2010 Free Software Foundation, Inc. 5 | 6 | # This file is part of lcurses. 7 | # 8 | # Permission is hereby granted, free of charge, to any person obtaining 9 | # a copy of this software and associated documentation files (the 10 | # "Software"), to deal in the Software without restriction, including 11 | # without limitation the rights to use, copy, modify, merge, publish, 12 | # distribute, sublicense, and/or sell copies of the Software, and to 13 | # permit persons to whom the Software is furnished to do so, subject to 14 | # the following conditions: 15 | # 16 | # The above copyright notice and this permission notice shall be 17 | # included in all copies or substantial portions of the Software. 18 | # 19 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 20 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 21 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 22 | # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 23 | # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 24 | # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 25 | # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 26 | 27 | ## -------------- ## 28 | ## Configuration. ## 29 | ## -------------- ## 30 | 31 | # Additional gnulib-tool options to use. 32 | gnulib_tool_options=' 33 | --no-changelog 34 | --avoid=dummy 35 | ' 36 | 37 | # gnulib modules used by this package. 38 | gnulib_modules=' 39 | warnings 40 | manywarnings 41 | ' 42 | 43 | # Extra gnulib files that are not in modules, which override files of 44 | # the same name installed by other bootstrap tools. 45 | gnulib_non_module_files=' 46 | build-aux/config.guess 47 | build-aux/config.sub 48 | build-aux/install-sh 49 | build-aux/missing 50 | doc/COPYINGv3 51 | ' 52 | 53 | # The not-synced with gnulib warning is bogus until upstream adopts 54 | # the saner bootstrap script. 55 | require_bootstrap_uptodate=: 56 | 57 | ## --------------- ## 58 | ## Hook functions. ## 59 | ## --------------- ## 60 | 61 | # lcurses_ignore_gnulib_ignore 62 | # ---------------------------- 63 | # gnulib-tool updates m4/.gitignore and lib/.gitignore, and keeping 64 | # generated files under version control does not make sense. Since 65 | # lib is entirely ignored, we only need to prepopulate the m4 ignore 66 | # files with generated files not tracked by gnulib-tool. 67 | lcurses_ignore_gnulib_ignore () 68 | { 69 | $debug_cmd 70 | 71 | $require_macro_dir 72 | 73 | if test -f "$macro_dir/.gitignore" ; then 74 | : 75 | else 76 | func_verbose "creating initial \`$macro_dir/.gitignore'" 77 | cat > $macro_dir/.gitignore <<\EOF 78 | # files created by gnulib, but that gnulib doesn't track 79 | *~ 80 | .gitignore 81 | gnulib-comp.m4 82 | EOF 83 | fi 84 | } 85 | func_add_hook func_prep lcurses_ignore_gnulib_ignore 86 | 87 | 88 | # lcurses_force_changelog 89 | # ----------------------- 90 | # Automake requires that ChangeLog exist. 91 | lcurses_force_changelog () 92 | { 93 | $debug_cmd 94 | 95 | touch ChangeLog || exit 1 96 | } 97 | func_add_hook func_gnulib_tool lcurses_force_changelog 98 | 99 | 100 | # lcurses_cleanup_changelog 101 | # ---------------------- 102 | # Configure script does not require ChangeLog. 103 | lcurses_cleanup_changelog () 104 | { 105 | $debug_cmd 106 | 107 | rm ChangeLog || exit 1 108 | } 109 | func_add_hook func_fini lcurses_cleanup_changelog 110 | 111 | 112 | 113 | # lcurses_cleanup_empty_dirs 114 | # ----------------------- 115 | # Gnulib leaves behind a few files we don't need. 116 | lcurses_cleanup_empty_dirs () 117 | { 118 | $debug_cmd 119 | 120 | rm lib/.gitignore lib/Makefile.am || exit 1 121 | rmdir lib || exit 1 122 | } 123 | func_add_hook func_fini lcurses_cleanup_empty_dirs 124 | 125 | 126 | # Local variables: 127 | # mode: shell-script 128 | # sh-indentation: 2 129 | # eval: (add-hook 'write-file-hooks 'time-stamp) 130 | # time-stamp-start: "# bootstrap.conf (lcurses) version " 131 | # time-stamp-format: "%:y-%02m-%02d" 132 | # time-stamp-end: "$" 133 | # End: 134 | -------------------------------------------------------------------------------- /configure.ac: -------------------------------------------------------------------------------- 1 | dnl Process this file with autoconf to produce a configure script 2 | 3 | AC_INIT(lcurses, 8, rrt@sc3d.org) 4 | AC_CONFIG_AUX_DIR([build-aux]) 5 | 6 | AM_INIT_AUTOMAKE([-Wall -Werror std-options]) 7 | 8 | m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])]) 9 | 10 | dnl Check for programs 11 | AC_PROG_CC 12 | gl_EARLY 13 | 14 | AC_ARG_ENABLE([gcc-warnings], 15 | [AS_HELP_STRING([--enable-gcc-warnings], 16 | [turn on lots of GCC warnings (for developers)])], 17 | [case $enableval in 18 | yes|no) ;; 19 | *) AC_MSG_ERROR([bad value $enableval for gcc-warnings option]) ;; 20 | esac 21 | gl_gcc_warnings=$enableval], 22 | [gl_gcc_warnings=no] 23 | ) 24 | 25 | if test "$gl_gcc_warnings" = yes; then 26 | gl_WARN_ADD([-Werror], [WERROR_CFLAGS]) 27 | 28 | # Set up the list of undesired warnings. 29 | nw= 30 | nw="$nw -Wsystem-headers" # Don’t let system headers trigger warnings 31 | nw="$nw -Wundef" # All compiler preprocessors support #if UNDEF 32 | nw="$nw -Wtraditional" # All compilers nowadays support ANSI C 33 | nw="$nw -Wstrict-overflow" # Use a lower level (see below). 34 | nw="$nw -Wconversion" # These warnings usually don’t point to mistakes. 35 | nw="$nw -Wsign-conversion" # Likewise. 36 | nw="$nw -Waggregate-return" # We do this on purpose. 37 | nw="$nw -Wbad-function-cast" # FIXME: We do this on purpose (non-pointer list elements). 38 | nw="$nw -Wtraditional-conversion" # Don't care. 39 | nw="$nw -Wpadded" # Don't care. 40 | nw="$nw -Wc++-compat" # Don't care. 41 | nw="$nw -Woverlength-strings" # Don't care. 42 | nw="$nw -Wmissing-format-attribute" # Don't care. 43 | nw="$nw -Wunreachable-code" # Seems buggy. 44 | nw="$nw -Wunused-macros" # those macros might come in handy later 45 | 46 | gl_MANYWARN_ALL_GCC([warnings]) 47 | 48 | # Enable all GCC warnings not in this list. 49 | gl_MANYWARN_COMPLEMENT([warnings], [$warnings], [$nw]) 50 | for w in $warnings; do 51 | gl_WARN_ADD([$w]) 52 | done 53 | 54 | # Add an extra warning 55 | gl_WARN_ADD([-Wstrict-overflow=1]) 56 | # Add some more safety measures 57 | gl_WARN_ADD([-D_FORTIFY_SOURCE=2]) 58 | gl_WARN_ADD([-fmudflap]) 59 | fi 60 | 61 | LT_PREREQ([2.2.6]) 62 | LT_INIT 63 | LT_OUTPUT 64 | 65 | eval `./libtool --config |grep '^objdir='` 66 | eval `./libtool --config |grep '^shrext_cmds='` 67 | module=yes eval shrext=$shrext_cmds 68 | 69 | AC_SUBST([objdir]) 70 | AC_SUBST([shrext]) 71 | AC_SUBST(LIBTOOL_DEPS) 72 | 73 | gl_INIT 74 | 75 | dnl Check for header files 76 | AC_HEADER_STDC 77 | 78 | AC_CHECK_FUNCS([strlcpy]) 79 | 80 | dnl Curses 81 | AX_WITH_CURSES 82 | if test "$ax_cv_curses" != "yes"; then 83 | AC_MSG_ERROR([cannot find curses]) 84 | fi 85 | AC_ARG_VAR(CURSES_LIB, [linker flags for curses library]) 86 | 87 | dnl Lua 5.1 88 | AX_PROG_LUA(501) 89 | AX_LUA_HEADERS 90 | AX_LUA_HEADERS_VERSION(501) 91 | AC_SUBST(LUA) 92 | AC_SUBST(LUA_INCLUDE) 93 | 94 | dnl Lua libraries 95 | dnl FIXME: Parametrize on version 96 | lualibdir='${libdir}/lua/5.1' 97 | AC_SUBST(lualibdir) 98 | luadatadir='${datadir}/lua/5.1' 99 | AC_SUBST(luadatadir) 100 | 101 | dnl Perl 102 | AX_WITH_PROG([PERL], [perl]) 103 | if test -z "$PERL"; then 104 | AC_MSG_FAILURE([cannot find perl]) 105 | fi 106 | 107 | dnl Generate output files 108 | AC_CONFIG_MACRO_DIR(m4) 109 | AC_CONFIG_HEADER(config.h) 110 | AC_CONFIG_FILES(Makefile) 111 | AC_OUTPUT 112 | -------------------------------------------------------------------------------- /curses.lua: -------------------------------------------------------------------------------- 1 | --- Lua bindings for curses 2 | module ("curses", package.seeall) 3 | 4 | require "curses_c" 5 | 6 | -- These Lua functions detect number of args, like Unified Funcs in Perl Curses 7 | -- see http://pjb.com.au/comp/lua/lcurses.html 8 | -- see http://search.cpan.org/perldoc?Curses 9 | 10 | function addch (...) 11 | if #{...} == 3 then 12 | return curses.stdscr():mvaddch(...) 13 | else 14 | return curses.stdscr():addch(...) 15 | end 16 | end 17 | 18 | function addstr(...) -- detect number of args, like Unified Funcs in Perl Curses 19 | if #{...} == 3 then 20 | return curses.stdscr():mvaddstr(...) 21 | else 22 | return curses.stdscr():addstr(...) 23 | end 24 | end 25 | 26 | function attrset (a) return curses.stdscr():attrset(a) end 27 | function clear () return curses.stdscr():clear() end 28 | function clrtobot () return curses.stdscr():clrtobot() end 29 | function clrtoeol () return curses.stdscr():clrtoeol() end 30 | 31 | function getch (...) 32 | local c 33 | if #{...} == 2 then 34 | c = curses.stdscr():mvgetch(...) 35 | else 36 | c = curses.stdscr():getch() 37 | end 38 | if c < 256 then 39 | return string.char(c) 40 | end 41 | -- could kludge-test for utf8, e.g. c3 a9 20 c3 aa 20 c3 ab 20 e2 82 ac 0a 42 | return c 43 | end 44 | 45 | function getstr (...) 46 | if #{...} > 1 then 47 | return curses.stdscr():mvgetstr(...) 48 | else 49 | return curses.stdscr():getstr(...) 50 | end 51 | end 52 | getnstr = getstr 53 | 54 | function getyx () return curses.stdscr():getyx() end 55 | function keypad (b) return curses.stdscr():keypad(b) end 56 | function move (y,x) return curses.stdscr():move(y,x) end 57 | function refresh () return curses.stdscr():refresh() end 58 | function timeout (t) return curses.stdscr():timeout(t) end 59 | -------------------------------------------------------------------------------- /lcurses.c: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * Library: lcurses - Lua 5.1 interface to the curses library * 3 | * * 4 | * (c) Reuben Thomas 2009-2010 * 5 | * (c) Tiago Dionizio 2004-2007 * 6 | * * 7 | * Permission is hereby granted, free of charge, to any person obtaining * 8 | * a copy of this software and associated documentation files (the * 9 | * "Software"), to deal in the Software without restriction, including * 10 | * without limitation the rights to use, copy, modify, merge, publish, * 11 | * distribute, sublicense, and/or sell copies of the Software, and to * 12 | * permit persons to whom the Software is furnished to do so, subject to * 13 | * the following conditions: * 14 | * * 15 | * The above copyright notice and this permission notice shall be * 16 | * included in all copies or substantial portions of the Software. * 17 | * * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * 19 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * 20 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.* 21 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY * 22 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, * 23 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE * 24 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * 25 | ************************************************************************/ 26 | 27 | #include "config.h" 28 | 29 | #include 30 | #include 31 | #include 32 | #include 33 | #ifdef HAVE_NCURSES_H 34 | #include 35 | #else 36 | #include 37 | #endif 38 | #include 39 | 40 | /* strlcpy() implementation for non-BSD based Unices. 41 | strlcpy() is a safer less error-prone replacement for strncpy(). */ 42 | #include "strlcpy.c" 43 | 44 | 45 | /* 46 | ** ======================================================= 47 | ** defines 48 | ** ======================================================= 49 | */ 50 | static const char *STDSCR_REGISTRY = "curses:stdscr"; 51 | static const char *WINDOWMETA = "curses:window"; 52 | static const char *CHSTRMETA = "curses:chstr"; 53 | static const char *RIPOFF_TABLE = "curses:ripoffline"; 54 | 55 | #define B(v) ((((int) (v)) == ERR)) 56 | 57 | /* ======================================================= */ 58 | 59 | #define LC_NUMBER(v) \ 60 | static int lc_ ## v(lua_State *L) \ 61 | { \ 62 | lua_pushnumber(L, v()); \ 63 | return 1; \ 64 | } 65 | 66 | #define LC_NUMBER2(n,v) \ 67 | static int lc_ ## n(lua_State *L) \ 68 | { \ 69 | lua_pushnumber(L, v); \ 70 | return 1; \ 71 | } 72 | 73 | /* ======================================================= */ 74 | 75 | #define LC_STRING(v) \ 76 | static int lc_ ## v(lua_State *L) \ 77 | { \ 78 | lua_pushstring(L, v()); \ 79 | return 1; \ 80 | } 81 | 82 | #define LC_STRING2(n,v) \ 83 | static int lc_ ## n(lua_State *L) \ 84 | { \ 85 | lua_pushstring(L, v); \ 86 | return 1; \ 87 | } 88 | 89 | /* ======================================================= */ 90 | 91 | #define LC_BOOL(v) \ 92 | static int lc_ ## v(lua_State *L) \ 93 | { \ 94 | lua_pushboolean(L, v()); \ 95 | return 1; \ 96 | } 97 | 98 | #define LC_BOOL2(n,v) \ 99 | static int lc_ ## n(lua_State *L) \ 100 | { \ 101 | lua_pushboolean(L, v); \ 102 | return 1; \ 103 | } 104 | 105 | /* ======================================================= */ 106 | 107 | #define LC_BOOLOK(v) \ 108 | static int lc_ ## v(lua_State *L) \ 109 | { \ 110 | lua_pushboolean(L, B(v())); \ 111 | return 1; \ 112 | } 113 | 114 | #define LC_BOOLOK2(n,v) \ 115 | static int lc_ ## n(lua_State *L) \ 116 | { \ 117 | lua_pushboolean(L, B(v)); \ 118 | return 1; \ 119 | } 120 | 121 | /* ======================================================= */ 122 | 123 | #define LCW_BOOLOK(n) \ 124 | static int lcw_ ## n(lua_State *L) \ 125 | { \ 126 | WINDOW *w = lcw_check(L, 1); \ 127 | lua_pushboolean(L, B(n(w))); \ 128 | return 1; \ 129 | } 130 | 131 | 132 | /* 133 | ** ======================================================= 134 | ** privates 135 | ** ======================================================= 136 | */ 137 | static void lcw_new(lua_State *L, WINDOW *nw) 138 | { 139 | if (nw) 140 | { 141 | WINDOW **w = lua_newuserdata(L, sizeof(WINDOW*)); 142 | luaL_getmetatable(L, WINDOWMETA); 143 | lua_setmetatable(L, -2); 144 | *w = nw; 145 | } 146 | else 147 | { 148 | lua_pushliteral(L, "failed to create window"); 149 | lua_error(L); 150 | } 151 | } 152 | 153 | static WINDOW **lcw_get(lua_State *L, int offset) 154 | { 155 | WINDOW **w = (WINDOW**)luaL_checkudata(L, offset, WINDOWMETA); 156 | if (w == NULL) luaL_argerror(L, offset, "bad curses window"); 157 | return w; 158 | } 159 | 160 | static WINDOW *lcw_check(lua_State *L, int offset) 161 | { 162 | WINDOW **w = lcw_get(L, offset); 163 | if (*w == NULL) luaL_argerror(L, offset, "attempt to use closed curses window"); 164 | return *w; 165 | } 166 | 167 | static int lcw_tostring(lua_State *L) 168 | { 169 | WINDOW **w = lcw_get(L, 1); 170 | char buff[34]; 171 | if (*w == NULL) 172 | strcpy(buff, "closed"); 173 | else 174 | sprintf(buff, "%p", lua_touserdata(L, 1)); 175 | lua_pushfstring(L, "curses window (%s)", buff); 176 | return 1; 177 | } 178 | 179 | /* 180 | ** ======================================================= 181 | ** chtype handling 182 | ** ======================================================= 183 | */ 184 | static chtype lc_checkch(lua_State *L, int offset) 185 | { 186 | if (lua_type(L, offset) == LUA_TNUMBER) 187 | return (chtype)luaL_checknumber(L, offset); 188 | if (lua_type(L, offset) == LUA_TSTRING) 189 | return *lua_tostring(L, offset); 190 | 191 | luaL_typerror(L, offset, "chtype"); 192 | /* never executes */ 193 | return (chtype)0; 194 | } 195 | 196 | static chtype lc_optch(lua_State *L, int offset, chtype def) 197 | { 198 | if (lua_isnoneornil(L, offset)) 199 | return def; 200 | return lc_checkch(L, offset); 201 | } 202 | 203 | /****c* classes/chstr 204 | * FUNCTION 205 | * Line drawing buffer. 206 | * 207 | * SEE ALSO 208 | * curses.new_chstr 209 | ****/ 210 | 211 | typedef struct 212 | { 213 | unsigned int len; 214 | chtype str[1]; 215 | } chstr; 216 | #define CHSTR_SIZE(len) (sizeof(chstr) + len * sizeof(chtype)) 217 | 218 | 219 | /* create new chstr object and leave it in the lua stack */ 220 | static chstr* chstr_new(lua_State *L, int len) 221 | { 222 | if (len < 1) 223 | { 224 | lua_pushliteral(L, "invalid chstr length"); 225 | lua_error(L); 226 | } 227 | { 228 | chstr *cs = lua_newuserdata(L, CHSTR_SIZE(len)); 229 | luaL_getmetatable(L, CHSTRMETA); 230 | lua_setmetatable(L, -2); 231 | cs->len = len; 232 | return cs; 233 | } 234 | } 235 | 236 | /* get chstr from lua (convert if needed) */ 237 | static chstr* lc_checkchstr(lua_State *L, int offset) 238 | { 239 | chstr *cs = (chstr*)luaL_checkudata(L, offset, CHSTRMETA); 240 | if (cs) return cs; 241 | 242 | luaL_argerror(L, offset, "bad curses chstr"); 243 | return NULL; 244 | } 245 | 246 | /****f* curses/curses.new_chstr 247 | * FUNCTION 248 | * Create a new line drawing buffer instance. 249 | * 250 | * SEE ALSO 251 | * chstr 252 | ****/ 253 | static int lc_new_chstr(lua_State *L) 254 | { 255 | int len = luaL_checkint(L, 1); 256 | chstr* ncs = chstr_new(L, len); 257 | memset(ncs->str, ' ', len*sizeof(chtype)); 258 | return 1; 259 | } 260 | 261 | /* change the contents of the chstr */ 262 | static int chstr_set_str(lua_State *L) 263 | { 264 | chstr *cs = lc_checkchstr(L, 1); 265 | int offset = luaL_checkint(L, 2); 266 | const char *str = luaL_checkstring(L, 3); 267 | int len = lua_strlen(L, 3); 268 | int attr = (chtype)luaL_optnumber(L, 4, A_NORMAL); 269 | int rep = luaL_optint(L, 5, 1); 270 | int i; 271 | 272 | if (offset < 0) 273 | return 0; 274 | 275 | while (rep-- > 0 && offset <= (int)cs->len) 276 | { 277 | if (offset + len - 1 > (int)cs->len) 278 | len = cs->len - offset + 1; 279 | 280 | for (i = 0; i < len; ++i) 281 | cs->str[offset + i] = str[i] | attr; 282 | offset += len; 283 | } 284 | 285 | return 0; 286 | } 287 | 288 | 289 | /****m* chstr/set_ch 290 | * FUNCTION 291 | * Set a character in the buffer. 292 | * 293 | * SYNOPSIS 294 | * chstr:set_ch(offset, char, attribute [, repeat]) 295 | * 296 | * EXAMPLE 297 | * Set the buffer with 'a's where the first one is capitalized 298 | * and has bold. 299 | * size = 10 300 | * str = curses.new_chstr(10) 301 | * str:set_ch(0, 'A', curses.A_BOLD) 302 | * str:set_ch(1, 'a', curses.A_NORMAL, size - 1) 303 | ****/ 304 | static int chstr_set_ch(lua_State *L) 305 | { 306 | chstr* cs = lc_checkchstr(L, 1); 307 | int offset = luaL_checkint(L, 2); 308 | chtype ch = lc_checkch(L, 3); 309 | int attr = (chtype)luaL_optnumber(L, 4, A_NORMAL); 310 | int rep = luaL_optint(L, 5, 1); 311 | 312 | while (rep-- > 0) 313 | { 314 | if (offset < 0 || offset >= (int) cs->len) 315 | return 0; 316 | 317 | cs->str[offset] = ch | attr; 318 | 319 | ++offset; 320 | } 321 | return 0; 322 | } 323 | 324 | /* get information from the chstr */ 325 | static int chstr_get(lua_State *L) 326 | { 327 | chstr* cs = lc_checkchstr(L, 1); 328 | int offset = luaL_checkint(L, 2); 329 | chtype ch; 330 | 331 | if (offset < 0 || offset >= (int) cs->len) 332 | return 0; 333 | 334 | ch = cs->str[offset]; 335 | 336 | lua_pushnumber(L, ch & A_CHARTEXT); 337 | lua_pushnumber(L, ch & A_ATTRIBUTES); 338 | lua_pushnumber(L, ch & A_COLOR); 339 | return 3; 340 | } 341 | 342 | /* retrieve chstr length */ 343 | static int chstr_len(lua_State *L) 344 | { 345 | chstr *cs = lc_checkchstr(L, 1); 346 | lua_pushnumber(L, cs->len); 347 | return 1; 348 | } 349 | 350 | /* duplicate chstr */ 351 | static int chstr_dup(lua_State *L) 352 | { 353 | chstr *cs = lc_checkchstr(L, 1); 354 | chstr *ncs = chstr_new(L, cs->len); 355 | 356 | memcpy(ncs->str, cs->str, CHSTR_SIZE(cs->len)); 357 | return 1; 358 | } 359 | 360 | /* 361 | ** ======================================================= 362 | ** initscr 363 | ** ======================================================= 364 | */ 365 | 366 | #define CCR(n, v) \ 367 | lua_pushstring(L, n); \ 368 | lua_pushnumber(L, v); \ 369 | lua_settable(L, lua_upvalueindex(1)); 370 | 371 | #define CC(s) CCR(#s, s) 372 | #define CC2(s, v) CCR(#s, v) 373 | 374 | /* 375 | ** these values may be fixed only after initialization, so this is 376 | ** called from lc_initscr, after the curses driver is initialized 377 | ** 378 | ** curses table is kept at upvalue position 1, in case the global 379 | ** name is changed by the user or even in the registration phase by 380 | ** the developer 381 | ** 382 | ** some of these values are not constant so need to register 383 | ** them directly instead of using a table 384 | */ 385 | static void register_curses_constants(lua_State *L) 386 | { 387 | /* colors */ 388 | CC(COLOR_BLACK) CC(COLOR_RED) CC(COLOR_GREEN) 389 | CC(COLOR_YELLOW) CC(COLOR_BLUE) CC(COLOR_MAGENTA) 390 | CC(COLOR_CYAN) CC(COLOR_WHITE) 391 | 392 | /* alternate character set */ 393 | CC(ACS_BLOCK) CC(ACS_BOARD) 394 | 395 | CC(ACS_BTEE) CC(ACS_TTEE) 396 | CC(ACS_LTEE) CC(ACS_RTEE) 397 | CC(ACS_LLCORNER) CC(ACS_LRCORNER) 398 | CC(ACS_URCORNER) CC(ACS_ULCORNER) 399 | 400 | CC(ACS_LARROW) CC(ACS_RARROW) 401 | CC(ACS_UARROW) CC(ACS_DARROW) 402 | 403 | CC(ACS_HLINE) CC(ACS_VLINE) 404 | 405 | CC(ACS_BULLET) CC(ACS_CKBOARD) CC(ACS_LANTERN) 406 | CC(ACS_DEGREE) CC(ACS_DIAMOND) 407 | 408 | CC(ACS_PLMINUS) CC(ACS_PLUS) 409 | CC(ACS_S1) CC(ACS_S9) 410 | 411 | /* attributes */ 412 | CC(A_NORMAL) CC(A_STANDOUT) CC(A_UNDERLINE) 413 | CC(A_REVERSE) CC(A_BLINK) CC(A_DIM) 414 | CC(A_BOLD) CC(A_PROTECT) CC(A_INVIS) 415 | CC(A_ALTCHARSET) CC(A_CHARTEXT) 416 | CC(A_ATTRIBUTES) 417 | 418 | /* key functions */ 419 | CC(KEY_BREAK) CC(KEY_DOWN) CC(KEY_UP) 420 | CC(KEY_LEFT) CC(KEY_RIGHT) CC(KEY_HOME) 421 | CC(KEY_BACKSPACE) 422 | 423 | CC(KEY_DL) CC(KEY_IL) CC(KEY_DC) 424 | CC(KEY_IC) CC(KEY_EIC) CC(KEY_CLEAR) 425 | CC(KEY_EOS) CC(KEY_EOL) CC(KEY_SF) 426 | CC(KEY_SR) CC(KEY_NPAGE) CC(KEY_PPAGE) 427 | CC(KEY_STAB) CC(KEY_CTAB) CC(KEY_CATAB) 428 | CC(KEY_ENTER) CC(KEY_SRESET) CC(KEY_RESET) 429 | CC(KEY_PRINT) CC(KEY_LL) CC(KEY_A1) 430 | CC(KEY_A3) CC(KEY_B2) CC(KEY_C1) 431 | CC(KEY_C3) CC(KEY_BTAB) CC(KEY_BEG) 432 | CC(KEY_CANCEL) CC(KEY_CLOSE) CC(KEY_COMMAND) 433 | CC(KEY_COPY) CC(KEY_CREATE) CC(KEY_END) 434 | CC(KEY_EXIT) CC(KEY_FIND) CC(KEY_HELP) 435 | CC(KEY_MARK) CC(KEY_MESSAGE) CC(KEY_MOUSE) 436 | CC(KEY_MOVE) CC(KEY_NEXT) CC(KEY_OPEN) 437 | CC(KEY_OPTIONS) CC(KEY_PREVIOUS) CC(KEY_REDO) 438 | CC(KEY_REFERENCE) CC(KEY_REFRESH) CC(KEY_REPLACE) 439 | CC(KEY_RESIZE) CC(KEY_RESTART) CC(KEY_RESUME) 440 | CC(KEY_SAVE) CC(KEY_SBEG) CC(KEY_SCANCEL) 441 | CC(KEY_SCOMMAND) CC(KEY_SCOPY) CC(KEY_SCREATE) 442 | CC(KEY_SDC) CC(KEY_SDL) CC(KEY_SELECT) 443 | CC(KEY_SEND) CC(KEY_SEOL) CC(KEY_SEXIT) 444 | CC(KEY_SFIND) CC(KEY_SHELP) CC(KEY_SHOME) 445 | CC(KEY_SIC) CC(KEY_SLEFT) CC(KEY_SMESSAGE) 446 | CC(KEY_SMOVE) CC(KEY_SNEXT) CC(KEY_SOPTIONS) 447 | CC(KEY_SPREVIOUS) CC(KEY_SPRINT) CC(KEY_SREDO) 448 | CC(KEY_SREPLACE) CC(KEY_SRIGHT) CC(KEY_SRSUME) 449 | CC(KEY_SSAVE) CC(KEY_SSUSPEND) CC(KEY_SUNDO) 450 | CC(KEY_SUSPEND) CC(KEY_UNDO) 451 | 452 | /* KEY_Fx 0 <= x <= 63 */ 453 | CC(KEY_F0) CC2(KEY_F1, KEY_F(1)) CC2(KEY_F2, KEY_F(2)) 454 | CC2(KEY_F3, KEY_F(3)) CC2(KEY_F4, KEY_F(4)) CC2(KEY_F5, KEY_F(5)) 455 | CC2(KEY_F6, KEY_F(6)) CC2(KEY_F7, KEY_F(7)) CC2(KEY_F8, KEY_F(8)) 456 | CC2(KEY_F9, KEY_F(9)) CC2(KEY_F10, KEY_F(10)) CC2(KEY_F11, KEY_F(11)) 457 | CC2(KEY_F12, KEY_F(12)) 458 | } 459 | 460 | /* 461 | ** make sure screen is restored (and cleared) at exit 462 | ** (for the situations where program is aborted without a 463 | ** proper cleanup) 464 | */ 465 | static void cleanup(void) 466 | { 467 | if (!isendwin()) 468 | { 469 | wclear(stdscr); 470 | wrefresh(stdscr); 471 | endwin(); 472 | } 473 | } 474 | 475 | static int lc_initscr(lua_State *L) 476 | { 477 | WINDOW *w; 478 | 479 | /* initialize curses */ 480 | w = initscr(); 481 | 482 | /* no longer used, so clean it up */ 483 | lua_pushstring(L, RIPOFF_TABLE); 484 | lua_pushnil(L); 485 | lua_settable(L, LUA_REGISTRYINDEX); 486 | 487 | /* failed to initialize */ 488 | if (w == NULL) 489 | return 0; 490 | 491 | /* return stdscr - main window */ 492 | lcw_new(L, w); 493 | 494 | /* save main window on registry */ 495 | lua_pushstring(L, STDSCR_REGISTRY); 496 | lua_pushvalue(L, -2); 497 | lua_rawset(L, LUA_REGISTRYINDEX); 498 | 499 | /* setup curses constants - curses.xxx numbers */ 500 | register_curses_constants(L); 501 | 502 | /* install cleanup handler to help in debugging and screen trashing */ 503 | atexit(cleanup); 504 | 505 | return 1; 506 | } 507 | 508 | /* FIXME: Avoid cast to void. */ 509 | static int lc_endwin(lua_State *L) 510 | { 511 | (void) L; 512 | endwin(); 513 | return 0; 514 | } 515 | 516 | LC_BOOL(isendwin) 517 | 518 | static int lc_stdscr(lua_State *L) 519 | { 520 | lua_pushstring(L, STDSCR_REGISTRY); 521 | lua_rawget(L, LUA_REGISTRYINDEX); 522 | return 1; 523 | } 524 | 525 | LC_NUMBER2(COLS, COLS) 526 | LC_NUMBER2(LINES, LINES) 527 | 528 | /* 529 | ** ======================================================= 530 | ** color 531 | ** ======================================================= 532 | */ 533 | 534 | LC_BOOLOK(start_color) 535 | LC_BOOL(has_colors) 536 | 537 | static int lc_init_pair(lua_State *L) 538 | { 539 | short pair = luaL_checkint(L, 1); 540 | short f = luaL_checkint(L, 2); 541 | short b = luaL_checkint(L, 3); 542 | 543 | lua_pushboolean(L, B(init_pair(pair, f, b))); 544 | return 1; 545 | } 546 | 547 | static int lc_pair_content(lua_State *L) 548 | { 549 | short pair = luaL_checkint(L, 1); 550 | short f; 551 | short b; 552 | int ret = pair_content(pair, &f, &b); 553 | 554 | if (ret == ERR) 555 | return 0; 556 | 557 | lua_pushnumber(L, f); 558 | lua_pushnumber(L, b); 559 | return 2; 560 | } 561 | 562 | LC_NUMBER2(COLORS, COLORS) 563 | LC_NUMBER2(COLOR_PAIRS, COLOR_PAIRS) 564 | 565 | static int lc_COLOR_PAIR(lua_State *L) 566 | { 567 | int n = luaL_checkint(L, 1); 568 | lua_pushnumber(L, COLOR_PAIR(n)); 569 | return 1; 570 | } 571 | 572 | /* 573 | ** ======================================================= 574 | ** termattrs 575 | ** ======================================================= 576 | */ 577 | 578 | LC_NUMBER(baudrate) 579 | LC_NUMBER(erasechar) 580 | LC_BOOL(has_ic) 581 | LC_BOOL(has_il) 582 | LC_NUMBER(killchar) 583 | 584 | static int lc_termattrs(lua_State *L) 585 | { 586 | if (lua_gettop(L) < 1) 587 | { 588 | lua_pushnumber(L, termattrs()); 589 | } 590 | else 591 | { 592 | int a = luaL_checkint(L, 1); 593 | lua_pushboolean(L, termattrs() & a); 594 | } 595 | return 1; 596 | } 597 | 598 | LC_STRING(termname) 599 | LC_STRING(longname) 600 | 601 | /* 602 | ** ======================================================= 603 | ** kernel 604 | ** ======================================================= 605 | */ 606 | 607 | /* there is no easy way to implement this... */ 608 | static lua_State *rip_L = NULL; 609 | static int ripoffline_cb(WINDOW* w, int cols) 610 | { 611 | static int line = 0; 612 | int top = lua_gettop(rip_L); 613 | 614 | /* better be safe */ 615 | if (!lua_checkstack(rip_L, 5)) 616 | return 0; 617 | 618 | /* get the table from the registry */ 619 | lua_pushstring(rip_L, RIPOFF_TABLE); 620 | lua_gettable(rip_L, LUA_REGISTRYINDEX); 621 | 622 | /* get user callback function */ 623 | if (lua_isnil(rip_L, -1)) { 624 | lua_pop(rip_L, 1); 625 | return 0; 626 | } 627 | 628 | lua_rawgeti(rip_L, -1, ++line); /* function to be called */ 629 | lcw_new(rip_L, w); /* create window object */ 630 | lua_pushnumber(rip_L, cols); /* push number of columns */ 631 | 632 | lua_pcall(rip_L, 2, 0, 0); /* call the lua function */ 633 | 634 | lua_settop(rip_L, top); 635 | return 1; 636 | } 637 | 638 | static int lc_ripoffline(lua_State *L) 639 | { 640 | static int rip = 0; 641 | int top_line = lua_toboolean(L, 1); 642 | 643 | if (!lua_isfunction(L, 2)) 644 | { 645 | lua_pushliteral(L, "invalid callback passed as second parameter"); 646 | lua_error(L); 647 | } 648 | 649 | /* need to save the lua state somewhere... */ 650 | rip_L = L; 651 | 652 | /* get the table where we are going to save the callbacks */ 653 | lua_pushstring(L, RIPOFF_TABLE); 654 | lua_gettable(L, LUA_REGISTRYINDEX); 655 | 656 | if (lua_isnil(L, -1)) 657 | { 658 | lua_pop(L, 1); 659 | lua_newtable(L); 660 | 661 | lua_pushstring(L, RIPOFF_TABLE); 662 | lua_pushvalue(L, -2); 663 | lua_settable(L, LUA_REGISTRYINDEX); 664 | } 665 | 666 | /* save function callback in registry table */ 667 | lua_pushvalue(L, 2); 668 | lua_rawseti(L, -2, ++rip); 669 | 670 | /* and tell curses we are going to take the line */ 671 | lua_pushboolean(L, B(ripoffline(top_line ? 1 : -1, ripoffline_cb))); 672 | return 1; 673 | } 674 | 675 | static int lc_curs_set(lua_State *L) 676 | { 677 | int vis = luaL_checkint(L, 1); 678 | int state = curs_set(vis); 679 | if (state == ERR) 680 | return 0; 681 | 682 | lua_pushnumber(L, state); 683 | return 1; 684 | } 685 | 686 | static int lc_napms(lua_State *L) 687 | { 688 | int ms = luaL_checkint(L, 1); 689 | lua_pushboolean(L, B(napms(ms))); 690 | return 1; 691 | } 692 | 693 | /* 694 | ** ======================================================= 695 | ** beep 696 | ** ======================================================= 697 | */ 698 | LC_BOOLOK(beep) 699 | LC_BOOLOK(flash) 700 | 701 | 702 | /* 703 | ** ======================================================= 704 | ** window 705 | ** ======================================================= 706 | */ 707 | 708 | static int lc_newwin(lua_State *L) 709 | { 710 | int nlines = luaL_checkint(L, 1); 711 | int ncols = luaL_checkint(L, 2); 712 | int begin_y = luaL_checkint(L, 3); 713 | int begin_x = luaL_checkint(L, 4); 714 | 715 | lcw_new(L, newwin(nlines, ncols, begin_y, begin_x)); 716 | return 1; 717 | } 718 | 719 | static int lcw_delwin(lua_State *L) 720 | { 721 | WINDOW **w = lcw_get(L, 1); 722 | if (*w != NULL && *w != stdscr) 723 | { 724 | delwin(*w); 725 | *w = NULL; 726 | } 727 | return 0; 728 | } 729 | 730 | static int lcw_mvwin(lua_State *L) 731 | { 732 | WINDOW *w = lcw_check(L, 1); 733 | int y = luaL_checkint(L, 2); 734 | int x = luaL_checkint(L, 3); 735 | lua_pushboolean(L, B(mvwin(w, y, x))); 736 | return 1; 737 | } 738 | 739 | static int lcw_subwin(lua_State *L) 740 | { 741 | WINDOW *orig = lcw_check(L, 1); 742 | int nlines = luaL_checkint(L, 2); 743 | int ncols = luaL_checkint(L, 3); 744 | int begin_y = luaL_checkint(L, 4); 745 | int begin_x = luaL_checkint(L, 5); 746 | 747 | lcw_new(L, subwin(orig, nlines, ncols, begin_y, begin_x)); 748 | return 1; 749 | } 750 | 751 | static int lcw_derwin(lua_State *L) 752 | { 753 | WINDOW *orig = lcw_check(L, 1); 754 | int nlines = luaL_checkint(L, 2); 755 | int ncols = luaL_checkint(L, 3); 756 | int begin_y = luaL_checkint(L, 4); 757 | int begin_x = luaL_checkint(L, 5); 758 | 759 | lcw_new(L, derwin(orig, nlines, ncols, begin_y, begin_x)); 760 | return 1; 761 | } 762 | 763 | static int lcw_mvderwin(lua_State *L) 764 | { 765 | WINDOW *w = lcw_check(L, 1); 766 | int par_y = luaL_checkint(L, 2); 767 | int par_x = luaL_checkint(L, 3); 768 | lua_pushboolean(L, B(mvderwin(w, par_y, par_x))); 769 | return 1; 770 | } 771 | 772 | static int lcw_dupwin(lua_State *L) 773 | { 774 | WINDOW *w = lcw_check(L, 1); 775 | lcw_new(L, dupwin(w)); 776 | return 1; 777 | } 778 | 779 | static int lcw_wsyncup(lua_State *L) 780 | { 781 | WINDOW *w = lcw_check(L, 1); 782 | wsyncup(w); 783 | return 0; 784 | } 785 | 786 | static int lcw_syncok(lua_State *L) 787 | { 788 | WINDOW *w = lcw_check(L, 1); 789 | int bf = lua_toboolean(L, 2); 790 | lua_pushboolean(L, B(syncok(w, bf))); 791 | return 1; 792 | } 793 | 794 | static int lcw_wcursyncup(lua_State *L) 795 | { 796 | WINDOW *w = lcw_check(L, 1); 797 | wcursyncup(w); 798 | return 0; 799 | } 800 | 801 | static int lcw_wsyncdown(lua_State *L) 802 | { 803 | WINDOW *w = lcw_check(L, 1); 804 | wsyncdown(w); 805 | return 0; 806 | } 807 | 808 | /* 809 | ** ======================================================= 810 | ** refresh 811 | ** ======================================================= 812 | */ 813 | LCW_BOOLOK(wrefresh) 814 | LCW_BOOLOK(wnoutrefresh) 815 | LCW_BOOLOK(redrawwin) 816 | 817 | static int lcw_wredrawln(lua_State *L) 818 | { 819 | WINDOW *w = lcw_check(L, 1); 820 | int beg_line = luaL_checkint(L, 2); 821 | int num_lines = luaL_checkint(L, 3); 822 | lua_pushboolean(L, B(wredrawln(w, beg_line, num_lines))); 823 | return 1; 824 | } 825 | 826 | LC_BOOLOK(doupdate) 827 | 828 | /* 829 | ** ======================================================= 830 | ** move 831 | ** ======================================================= 832 | */ 833 | 834 | static int lcw_wmove(lua_State *L) 835 | { 836 | WINDOW *w = lcw_check(L, 1); 837 | int y = luaL_checkint(L, 2); 838 | int x = luaL_checkint(L, 3); 839 | lua_pushboolean(L, B(wmove(w, y, x))); 840 | return 1; 841 | } 842 | 843 | /* 844 | ** ======================================================= 845 | ** scroll 846 | ** ======================================================= 847 | */ 848 | 849 | static int lcw_wscrl(lua_State *L) 850 | { 851 | WINDOW *w = lcw_check(L, 1); 852 | int n = luaL_checkint(L, 2); 853 | lua_pushboolean(L, B(wscrl(w, n))); 854 | return 1; 855 | } 856 | 857 | /* 858 | ** ======================================================= 859 | ** touch 860 | ** ======================================================= 861 | */ 862 | 863 | static int lcw_touch(lua_State *L) 864 | { 865 | WINDOW *w = lcw_check(L, 1); 866 | int changed; 867 | if (lua_isnoneornil(L, 2)) 868 | changed = TRUE; 869 | else 870 | changed = lua_toboolean(L, 2); 871 | 872 | if (changed) 873 | lua_pushboolean(L, B(touchwin(w))); 874 | else 875 | lua_pushboolean(L, B(untouchwin(w))); 876 | return 1; 877 | } 878 | 879 | static int lcw_touchline(lua_State *L) 880 | { 881 | WINDOW *w = lcw_check(L, 1); 882 | int y = luaL_checkint(L, 2); 883 | int n = luaL_checkint(L, 3); 884 | int changed; 885 | if (lua_isnoneornil(L, 4)) 886 | changed = TRUE; 887 | else 888 | changed = lua_toboolean(L, 4); 889 | lua_pushboolean(L, B(wtouchln(w, y, n, changed))); 890 | return 1; 891 | } 892 | 893 | static int lcw_is_linetouched(lua_State *L) 894 | { 895 | WINDOW *w = lcw_check(L, 1); 896 | int line = luaL_checkint(L, 2); 897 | lua_pushboolean(L, is_linetouched(w, line)); 898 | return 1; 899 | } 900 | 901 | static int lcw_is_wintouched(lua_State *L) 902 | { 903 | WINDOW *w = lcw_check(L, 1); 904 | lua_pushboolean(L, is_wintouched(w)); 905 | return 1; 906 | } 907 | 908 | /* 909 | ** ======================================================= 910 | ** getyx 911 | ** ======================================================= 912 | */ 913 | 914 | static int lcw_getyx(lua_State *L) 915 | { 916 | WINDOW *w = lcw_check(L, 1); 917 | int y, x; 918 | getyx(w, y, x); 919 | lua_pushnumber(L, y); 920 | lua_pushnumber(L, x); 921 | return 2; 922 | } 923 | 924 | static int lcw_getparyx(lua_State *L) 925 | { 926 | WINDOW *w = lcw_check(L, 1); 927 | int y, x; 928 | getparyx(w, y, x); 929 | lua_pushnumber(L, y); 930 | lua_pushnumber(L, x); 931 | return 2; 932 | } 933 | 934 | static int lcw_getbegyx(lua_State *L) 935 | { 936 | WINDOW *w = lcw_check(L, 1); 937 | int y, x; 938 | getbegyx(w, y, x); 939 | lua_pushnumber(L, y); 940 | lua_pushnumber(L, x); 941 | return 2; 942 | } 943 | 944 | static int lcw_getmaxyx(lua_State *L) 945 | { 946 | WINDOW *w = lcw_check(L, 1); 947 | int y, x; 948 | getmaxyx(w, y, x); 949 | lua_pushnumber(L, y); 950 | lua_pushnumber(L, x); 951 | return 2; 952 | } 953 | 954 | /* 955 | ** ======================================================= 956 | ** border 957 | ** ======================================================= 958 | */ 959 | 960 | static int lcw_wborder(lua_State *L) 961 | { 962 | WINDOW *w = lcw_check(L, 1); 963 | chtype ls = lc_optch(L, 2, 0); 964 | chtype rs = lc_optch(L, 3, 0); 965 | chtype ts = lc_optch(L, 4, 0); 966 | chtype bs = lc_optch(L, 5, 0); 967 | chtype tl = lc_optch(L, 6, 0); 968 | chtype tr = lc_optch(L, 7, 0); 969 | chtype bl = lc_optch(L, 8, 0); 970 | chtype br = lc_optch(L, 9, 0); 971 | 972 | lua_pushnumber(L, B(wborder(w, ls, rs, ts, bs, tl, tr, bl, br))); 973 | return 1; 974 | } 975 | 976 | static int lcw_box(lua_State *L) 977 | { 978 | WINDOW *w = lcw_check(L, 1); 979 | chtype verch = lc_checkch(L, 2); 980 | chtype horch = lc_checkch(L, 3); 981 | 982 | lua_pushnumber(L, B(box(w, verch, horch))); 983 | return 1; 984 | } 985 | 986 | static int lcw_whline(lua_State *L) 987 | { 988 | WINDOW *w = lcw_check(L, 1); 989 | chtype ch = lc_checkch(L, 2); 990 | int n = luaL_checkint(L, 3); 991 | 992 | lua_pushnumber(L, B(whline(w, ch, n))); 993 | return 1; 994 | } 995 | 996 | static int lcw_wvline(lua_State *L) 997 | { 998 | WINDOW *w = lcw_check(L, 1); 999 | chtype ch = lc_checkch(L, 2); 1000 | int n = luaL_checkint(L, 3); 1001 | 1002 | lua_pushnumber(L, B(wvline(w, ch, n))); 1003 | return 1; 1004 | } 1005 | 1006 | 1007 | static int lcw_mvwhline(lua_State *L) 1008 | { 1009 | WINDOW *w = lcw_check(L, 1); 1010 | int y = luaL_checkint(L, 2); 1011 | int x = luaL_checkint(L, 3); 1012 | chtype ch = lc_checkch(L, 4); 1013 | int n = luaL_checkint(L, 5); 1014 | 1015 | lua_pushnumber(L, B(mvwhline(w, y, x, ch, n))); 1016 | return 1; 1017 | } 1018 | 1019 | static int lcw_mvwvline(lua_State *L) 1020 | { 1021 | WINDOW *w = lcw_check(L, 1); 1022 | int y = luaL_checkint(L, 2); 1023 | int x = luaL_checkint(L, 3); 1024 | chtype ch = lc_checkch(L, 4); 1025 | int n = luaL_checkint(L, 5); 1026 | 1027 | lua_pushnumber(L, B(mvwvline(w, y, x, ch, n))); 1028 | return 1; 1029 | } 1030 | 1031 | /* 1032 | ** ======================================================= 1033 | ** clear 1034 | ** ======================================================= 1035 | */ 1036 | 1037 | LCW_BOOLOK(werase) 1038 | LCW_BOOLOK(wclear) 1039 | LCW_BOOLOK(wclrtobot) 1040 | LCW_BOOLOK(wclrtoeol) 1041 | 1042 | /* 1043 | ** ======================================================= 1044 | ** slk 1045 | ** ======================================================= 1046 | */ 1047 | static int lc_slk_init(lua_State *L) 1048 | { 1049 | int fmt = luaL_checkint(L, 1); 1050 | lua_pushboolean(L, B(slk_init(fmt))); 1051 | return 1; 1052 | } 1053 | 1054 | static int lc_slk_set(lua_State *L) 1055 | { 1056 | int labnum = luaL_checkint(L, 1); 1057 | const char* label = luaL_checkstring(L, 2); 1058 | int fmt = luaL_checkint(L, 3); 1059 | 1060 | lua_pushboolean(L, B(slk_set(labnum, label, fmt))); 1061 | return 1; 1062 | } 1063 | 1064 | LC_BOOLOK(slk_refresh) 1065 | LC_BOOLOK(slk_noutrefresh) 1066 | 1067 | static int lc_slk_label(lua_State *L) 1068 | { 1069 | int labnum = luaL_checkint(L, 1); 1070 | lua_pushstring(L, slk_label(labnum)); 1071 | return 1; 1072 | } 1073 | 1074 | LC_BOOLOK(slk_clear) 1075 | LC_BOOLOK(slk_restore) 1076 | LC_BOOLOK(slk_touch) 1077 | 1078 | static int lc_slk_attron(lua_State *L) 1079 | { 1080 | chtype attrs = lc_checkch(L, 1); 1081 | lua_pushboolean(L, B(slk_attron(attrs))); 1082 | return 1; 1083 | } 1084 | 1085 | static int lc_slk_attroff(lua_State *L) 1086 | { 1087 | chtype attrs = lc_checkch(L, 1); 1088 | lua_pushboolean(L, B(slk_attroff(attrs))); 1089 | return 1; 1090 | } 1091 | 1092 | static int lc_slk_attrset(lua_State *L) 1093 | { 1094 | chtype attrs = lc_checkch(L, 1); 1095 | lua_pushboolean(L, B(slk_attrset(attrs))); 1096 | return 1; 1097 | } 1098 | 1099 | /* 1100 | ** ======================================================= 1101 | ** addch 1102 | ** ======================================================= 1103 | */ 1104 | 1105 | static int lcw_waddch(lua_State *L) 1106 | { 1107 | WINDOW *w = lcw_check(L, 1); 1108 | chtype ch = lc_checkch(L, 2); 1109 | lua_pushboolean(L, B(waddch(w, ch))); 1110 | return 1; 1111 | } 1112 | 1113 | static int lcw_mvwaddch(lua_State *L) 1114 | { 1115 | WINDOW *w = lcw_check(L, 1); 1116 | int y = luaL_checkint(L, 2); 1117 | int x = luaL_checkint(L, 3); 1118 | chtype ch = lc_checkch(L, 4); 1119 | 1120 | lua_pushboolean(L, B(mvwaddch(w, y, x, ch))); 1121 | return 1; 1122 | } 1123 | 1124 | static int lcw_wechochar(lua_State *L) 1125 | { 1126 | WINDOW *w = lcw_check(L, 1); 1127 | chtype ch = lc_checkch(L, 2); 1128 | 1129 | lua_pushboolean(L, B(wechochar(w, ch))); 1130 | return 1; 1131 | } 1132 | 1133 | /* 1134 | ** ======================================================= 1135 | ** addchstr 1136 | ** ======================================================= 1137 | */ 1138 | 1139 | static int lcw_waddchnstr(lua_State *L) 1140 | { 1141 | WINDOW *w = lcw_check(L, 1); 1142 | int n = luaL_optint(L, 3, -1); 1143 | chstr *cs = lc_checkchstr(L, 2); 1144 | 1145 | if (n < 0 || n > (int) cs->len) 1146 | n = cs->len; 1147 | 1148 | lua_pushboolean(L, B(waddchnstr(w, cs->str, n))); 1149 | return 1; 1150 | } 1151 | 1152 | static int lcw_mvwaddchnstr(lua_State *L) 1153 | { 1154 | WINDOW *w = lcw_check(L, 1); 1155 | int y = luaL_checkint(L, 2); 1156 | int x = luaL_checkint(L, 3); 1157 | int n = luaL_optint(L, 5, -1); 1158 | chstr *cs = lc_checkchstr(L, 4); 1159 | 1160 | if (n < 0 || n > (int) cs->len) 1161 | n = cs->len; 1162 | 1163 | lua_pushboolean(L, B(mvwaddchnstr(w, y, x, cs->str, n))); 1164 | return 1; 1165 | } 1166 | 1167 | /* 1168 | ** ======================================================= 1169 | ** addstr 1170 | ** ======================================================= 1171 | */ 1172 | 1173 | static int lcw_waddnstr(lua_State *L) 1174 | { 1175 | WINDOW *w = lcw_check(L, 1); 1176 | const char *str = luaL_checkstring(L, 2); 1177 | int n = luaL_optint(L, 3, -1); 1178 | 1179 | if (n < 0) n = lua_strlen(L, 2); 1180 | 1181 | lua_pushboolean(L, B(waddnstr(w, str, n))); 1182 | return 1; 1183 | } 1184 | 1185 | static int lcw_mvwaddnstr(lua_State *L) 1186 | { 1187 | WINDOW *w = lcw_check(L, 1); 1188 | int y = luaL_checkint(L, 2); 1189 | int x = luaL_checkint(L, 3); 1190 | const char *str = luaL_checkstring(L, 4); 1191 | int n = luaL_optint(L, 5, -1); 1192 | 1193 | if (n < 0) n = lua_strlen(L, 4); 1194 | 1195 | lua_pushboolean(L, B(mvwaddnstr(w, y, x, str, n))); 1196 | return 1; 1197 | } 1198 | 1199 | /* 1200 | ** ======================================================= 1201 | ** bkgd 1202 | ** ======================================================= 1203 | */ 1204 | 1205 | static int lcw_wbkgdset(lua_State *L) 1206 | { 1207 | WINDOW *w = lcw_check(L, 1); 1208 | chtype ch = lc_checkch(L, 2); 1209 | wbkgdset(w, ch); 1210 | return 0; 1211 | } 1212 | 1213 | static int lcw_wbkgd(lua_State *L) 1214 | { 1215 | WINDOW *w = lcw_check(L, 1); 1216 | chtype ch = lc_checkch(L, 2); 1217 | lua_pushboolean(L, B(wbkgd(w, ch))); 1218 | return 1; 1219 | } 1220 | 1221 | static int lcw_getbkgd(lua_State *L) 1222 | { 1223 | WINDOW *w = lcw_check(L, 1); 1224 | lua_pushnumber(L, B(getbkgd(w))); 1225 | return 1; 1226 | } 1227 | 1228 | /* 1229 | ** ======================================================= 1230 | ** inopts 1231 | ** ======================================================= 1232 | */ 1233 | 1234 | static int lc_cbreak(lua_State *L) 1235 | { 1236 | if (lua_isnoneornil(L, 1) || lua_toboolean(L, 1)) 1237 | lua_pushboolean(L, B(cbreak())); 1238 | else 1239 | lua_pushboolean(L, B(nocbreak())); 1240 | return 1; 1241 | } 1242 | 1243 | static int lc_echo(lua_State *L) 1244 | { 1245 | if (lua_isnoneornil(L, 1) || lua_toboolean(L, 1)) 1246 | lua_pushboolean(L, B(echo())); 1247 | else 1248 | lua_pushboolean(L, B(noecho())); 1249 | return 1; 1250 | } 1251 | 1252 | static int lc_raw(lua_State *L) 1253 | { 1254 | if (lua_isnoneornil(L, 1) || lua_toboolean(L, 1)) 1255 | lua_pushboolean(L, B(raw())); 1256 | else 1257 | lua_pushboolean(L, B(noraw())); 1258 | return 1; 1259 | } 1260 | 1261 | static int lc_halfdelay(lua_State *L) 1262 | { 1263 | int tenths = luaL_checkint(L, 1); 1264 | lua_pushboolean(L, B(halfdelay(tenths))); 1265 | return 1; 1266 | } 1267 | 1268 | static int lcw_intrflush(lua_State *L) 1269 | { 1270 | WINDOW *w = lcw_check(L, 1); 1271 | int bf = lua_toboolean(L, 2); 1272 | lua_pushboolean(L, B(intrflush(w, bf))); 1273 | return 1; 1274 | } 1275 | 1276 | static int lcw_keypad(lua_State *L) 1277 | { 1278 | WINDOW *w = lcw_check(L, 1); 1279 | int bf = lua_isnoneornil(L, 2) ? 1 : lua_toboolean(L, 2); 1280 | lua_pushboolean(L, B(keypad(w, bf))); 1281 | return 1; 1282 | } 1283 | 1284 | static int lcw_meta(lua_State *L) 1285 | { 1286 | WINDOW *w = lcw_check(L, 1); 1287 | int bf = lua_toboolean(L, 2); 1288 | lua_pushboolean(L, B(meta(w, bf))); 1289 | return 1; 1290 | } 1291 | 1292 | static int lcw_nodelay(lua_State *L) 1293 | { 1294 | WINDOW *w = lcw_check(L, 1); 1295 | int bf = lua_toboolean(L, 2); 1296 | lua_pushboolean(L, B(nodelay(w, bf))); 1297 | return 1; 1298 | } 1299 | 1300 | static int lcw_timeout(lua_State *L) 1301 | { 1302 | WINDOW *w = lcw_check(L, 1); 1303 | int delay = luaL_checkint(L, 2); 1304 | wtimeout(w, delay); 1305 | return 0; 1306 | } 1307 | 1308 | static int lcw_notimeout(lua_State *L) 1309 | { 1310 | WINDOW *w = lcw_check(L, 1); 1311 | int bf = lua_toboolean(L, 2); 1312 | lua_pushboolean(L, B(notimeout(w, bf))); 1313 | return 1; 1314 | } 1315 | 1316 | /* 1317 | ** ======================================================= 1318 | ** outopts 1319 | ** ======================================================= 1320 | */ 1321 | 1322 | static int lc_nl(lua_State *L) 1323 | { 1324 | if (lua_isnoneornil(L, 1) || lua_toboolean(L, 1)) 1325 | lua_pushboolean(L, B(nl())); 1326 | else 1327 | lua_pushboolean(L, B(nonl())); 1328 | return 1; 1329 | } 1330 | 1331 | static int lcw_clearok(lua_State *L) 1332 | { 1333 | WINDOW *w = lcw_check(L, 1); 1334 | int bf = lua_toboolean(L, 2); 1335 | lua_pushboolean(L, B(clearok(w, bf))); 1336 | return 1; 1337 | } 1338 | 1339 | static int lcw_idlok(lua_State *L) 1340 | { 1341 | WINDOW *w = lcw_check(L, 1); 1342 | int bf = lua_toboolean(L, 2); 1343 | lua_pushboolean(L, B(idlok(w, bf))); 1344 | return 1; 1345 | } 1346 | 1347 | static int lcw_leaveok(lua_State *L) 1348 | { 1349 | WINDOW *w = lcw_check(L, 1); 1350 | int bf = lua_toboolean(L, 2); 1351 | lua_pushboolean(L, B(leaveok(w, bf))); 1352 | return 1; 1353 | } 1354 | 1355 | static int lcw_scrollok(lua_State *L) 1356 | { 1357 | WINDOW *w = lcw_check(L, 1); 1358 | int bf = lua_toboolean(L, 2); 1359 | lua_pushboolean(L, B(scrollok(w, bf))); 1360 | return 1; 1361 | } 1362 | 1363 | static int lcw_idcok(lua_State *L) 1364 | { 1365 | WINDOW *w = lcw_check(L, 1); 1366 | int bf = lua_toboolean(L, 2); 1367 | idcok(w, bf); 1368 | return 0; 1369 | } 1370 | 1371 | static int lcw_immedok(lua_State *L) 1372 | { 1373 | WINDOW *w = lcw_check(L, 1); 1374 | int bf = lua_toboolean(L, 2); 1375 | immedok(w, bf); 1376 | return 0; 1377 | } 1378 | 1379 | static int lcw_wsetscrreg(lua_State *L) 1380 | { 1381 | WINDOW *w = lcw_check(L, 1); 1382 | int top = luaL_checkint(L, 2); 1383 | int bot = luaL_checkint(L, 3); 1384 | lua_pushboolean(L, B(wsetscrreg(w, top, bot))); 1385 | return 1; 1386 | } 1387 | 1388 | /* 1389 | ** ======================================================= 1390 | ** overlay 1391 | ** ======================================================= 1392 | */ 1393 | 1394 | static int lcw_overlay(lua_State *L) 1395 | { 1396 | WINDOW *srcwin = lcw_check(L, 1); 1397 | WINDOW *dstwin = lcw_check(L, 2); 1398 | 1399 | lua_pushboolean(L, B(overlay(srcwin, dstwin))); 1400 | return 1; 1401 | } 1402 | 1403 | static int lcw_overwrite(lua_State *L) 1404 | { 1405 | WINDOW *srcwin = lcw_check(L, 1); 1406 | WINDOW *dstwin = lcw_check(L, 2); 1407 | 1408 | lua_pushboolean(L, B(overwrite(srcwin, dstwin))); 1409 | return 1; 1410 | } 1411 | 1412 | static int lcw_copywin(lua_State *L) 1413 | { 1414 | WINDOW *srcwin = lcw_check(L, 1); 1415 | WINDOW *dstwin = lcw_check(L, 2); 1416 | int sminrow = luaL_checkint(L, 3); 1417 | int smincol = luaL_checkint(L, 4); 1418 | int dminrow = luaL_checkint(L, 5); 1419 | int dmincol = luaL_checkint(L, 6); 1420 | int dmaxrow = luaL_checkint(L, 7); 1421 | int dmaxcol = luaL_checkint(L, 8); 1422 | int woverlay = lua_toboolean(L, 9); 1423 | 1424 | lua_pushboolean(L, B(copywin(srcwin, dstwin, sminrow, 1425 | smincol, dminrow, dmincol, dmaxrow, dmaxcol, woverlay))); 1426 | 1427 | return 1; 1428 | } 1429 | 1430 | /* 1431 | ** ======================================================= 1432 | ** util 1433 | ** ======================================================= 1434 | */ 1435 | 1436 | static int lc_unctrl(lua_State *L) 1437 | { 1438 | chtype c = (chtype)luaL_checknumber(L, 1); 1439 | lua_pushstring(L, unctrl(c)); 1440 | return 1; 1441 | } 1442 | 1443 | static int lc_keyname(lua_State *L) 1444 | { 1445 | int c = luaL_checkint(L, 1); 1446 | lua_pushstring(L, keyname(c)); 1447 | return 1; 1448 | } 1449 | 1450 | static int lc_delay_output(lua_State *L) 1451 | { 1452 | int ms = luaL_checkint(L, 1); 1453 | lua_pushboolean(L, B(delay_output(ms))); 1454 | return 1; 1455 | } 1456 | 1457 | static int lc_flushinp(lua_State *L) 1458 | { 1459 | lua_pushboolean(L, B(flushinp())); 1460 | return 1; 1461 | } 1462 | 1463 | /* 1464 | ** ======================================================= 1465 | ** delch 1466 | ** ======================================================= 1467 | */ 1468 | 1469 | LCW_BOOLOK(wdelch) 1470 | 1471 | static int lcw_mvwdelch(lua_State *L) 1472 | { 1473 | WINDOW *w = lcw_check(L, 1); 1474 | int y = luaL_checkint(L, 2); 1475 | int x = luaL_checkint(L, 3); 1476 | 1477 | lua_pushboolean(L, B(mvwdelch(w, y, x))); 1478 | return 1; 1479 | } 1480 | 1481 | /* 1482 | ** ======================================================= 1483 | ** deleteln 1484 | ** ======================================================= 1485 | */ 1486 | 1487 | LCW_BOOLOK(wdeleteln) 1488 | LCW_BOOLOK(winsertln) 1489 | 1490 | static int lcw_winsdelln(lua_State *L) 1491 | { 1492 | WINDOW *w = lcw_check(L, 1); 1493 | int n = luaL_checkint(L, 2); 1494 | lua_pushboolean(L, B(winsdelln(w, n))); 1495 | return 1; 1496 | } 1497 | 1498 | /* 1499 | ** ======================================================= 1500 | ** getch 1501 | ** ======================================================= 1502 | */ 1503 | 1504 | static int lcw_wgetch(lua_State *L) 1505 | { 1506 | WINDOW *w = lcw_check(L, 1); 1507 | int c = wgetch(w); 1508 | 1509 | if (c == ERR) return 0; 1510 | 1511 | lua_pushnumber(L, c); 1512 | return 1; 1513 | } 1514 | 1515 | static int lcw_mvwgetch(lua_State *L) 1516 | { 1517 | WINDOW *w = lcw_check(L, 1); 1518 | int y = luaL_checkint(L, 2); 1519 | int x = luaL_checkint(L, 3); 1520 | int c; 1521 | 1522 | if (wmove(w, y, x) == ERR) return 0; 1523 | 1524 | c = wgetch(w); 1525 | 1526 | if (c == ERR) return 0; 1527 | 1528 | lua_pushnumber(L, c); 1529 | return 1; 1530 | } 1531 | 1532 | static int lc_ungetch(lua_State *L) 1533 | { 1534 | int c = luaL_checkint(L, 1); 1535 | lua_pushboolean(L, B(ungetch(c))); 1536 | return 1; 1537 | } 1538 | 1539 | /* 1540 | ** ======================================================= 1541 | ** getstr 1542 | ** ======================================================= 1543 | */ 1544 | 1545 | static int lcw_wgetnstr(lua_State *L) 1546 | { 1547 | WINDOW *w = lcw_check(L, 1); 1548 | int n = luaL_optint(L, 2, 0); 1549 | char buf[LUAL_BUFFERSIZE]; 1550 | 1551 | if (n == 0 || n >= LUAL_BUFFERSIZE) n = LUAL_BUFFERSIZE - 1; 1552 | if (wgetnstr(w, buf, n) == ERR) 1553 | return 0; 1554 | 1555 | lua_pushstring(L, buf); 1556 | return 1; 1557 | } 1558 | 1559 | static int lcw_mvwgetnstr(lua_State *L) 1560 | { 1561 | WINDOW *w = lcw_check(L, 1); 1562 | int y = luaL_checkint(L, 2); 1563 | int x = luaL_checkint(L, 3); 1564 | int n = luaL_optint(L, 4, -1); 1565 | char buf[LUAL_BUFFERSIZE]; 1566 | 1567 | if (n == 0 || n >= LUAL_BUFFERSIZE) n = LUAL_BUFFERSIZE - 1; 1568 | if (mvwgetnstr(w, y, x, buf, n) == ERR) 1569 | return 0; 1570 | 1571 | lua_pushstring(L, buf); 1572 | return 1; 1573 | } 1574 | 1575 | /* 1576 | ** ======================================================= 1577 | ** inch 1578 | ** ======================================================= 1579 | */ 1580 | 1581 | static int lcw_winch(lua_State *L) 1582 | { 1583 | WINDOW *w = lcw_check(L, 1); 1584 | lua_pushnumber(L, winch(w)); 1585 | return 1; 1586 | } 1587 | 1588 | static int lcw_mvwinch(lua_State *L) 1589 | { 1590 | WINDOW *w = lcw_check(L, 1); 1591 | int y = luaL_checkint(L, 2); 1592 | int x = luaL_checkint(L, 3); 1593 | lua_pushnumber(L, mvwinch(w, y, x)); 1594 | return 1; 1595 | } 1596 | 1597 | /* 1598 | ** ======================================================= 1599 | ** inchstr 1600 | ** ======================================================= 1601 | */ 1602 | 1603 | static int lcw_winchnstr(lua_State *L) 1604 | { 1605 | WINDOW *w = lcw_check(L, 1); 1606 | int n = luaL_checkint(L, 2); 1607 | chstr *cs = chstr_new(L, n); 1608 | 1609 | if (winchnstr(w, cs->str, n) == ERR) 1610 | return 0; 1611 | 1612 | return 1; 1613 | } 1614 | 1615 | static int lcw_mvwinchnstr(lua_State *L) 1616 | { 1617 | WINDOW *w = lcw_check(L, 1); 1618 | int y = luaL_checkint(L, 2); 1619 | int x = luaL_checkint(L, 3); 1620 | int n = luaL_checkint(L, 4); 1621 | chstr *cs = chstr_new(L, n); 1622 | 1623 | if (mvwinchnstr(w, y, x, cs->str, n) == ERR) 1624 | return 0; 1625 | 1626 | return 1; 1627 | } 1628 | 1629 | /* 1630 | ** ======================================================= 1631 | ** instr 1632 | ** ======================================================= 1633 | */ 1634 | 1635 | static int lcw_winnstr(lua_State *L) 1636 | { 1637 | WINDOW *w = lcw_check(L, 1); 1638 | int n = luaL_checkint(L, 2); 1639 | char buf[LUAL_BUFFERSIZE]; 1640 | 1641 | if (n >= LUAL_BUFFERSIZE) n = LUAL_BUFFERSIZE - 1; 1642 | if (winnstr(w, buf, n) == ERR) 1643 | return 0; 1644 | 1645 | lua_pushlstring(L, buf, n); 1646 | return 1; 1647 | } 1648 | 1649 | static int lcw_mvwinnstr(lua_State *L) 1650 | { 1651 | WINDOW *w = lcw_check(L, 1); 1652 | int y = luaL_checkint(L, 2); 1653 | int x = luaL_checkint(L, 3); 1654 | int n = luaL_checkint(L, 4); 1655 | char buf[LUAL_BUFFERSIZE]; 1656 | 1657 | if (n >= LUAL_BUFFERSIZE) n = LUAL_BUFFERSIZE - 1; 1658 | if (mvwinnstr(w, y, x, buf, n) == ERR) 1659 | return 0; 1660 | 1661 | lua_pushlstring(L, buf, n); 1662 | return 1; 1663 | } 1664 | 1665 | /* 1666 | ** ======================================================= 1667 | ** insch 1668 | ** ======================================================= 1669 | */ 1670 | 1671 | static int lcw_winsch(lua_State *L) 1672 | { 1673 | WINDOW *w = lcw_check(L, 1); 1674 | chtype ch = lc_checkch(L, 2); 1675 | lua_pushboolean(L, B(winsch(w, ch))); 1676 | return 1; 1677 | } 1678 | 1679 | static int lcw_mvwinsch(lua_State *L) 1680 | { 1681 | WINDOW *w = lcw_check(L, 1); 1682 | int y = luaL_checkint(L, 2); 1683 | int x = luaL_checkint(L, 3); 1684 | chtype ch = lc_checkch(L, 4); 1685 | lua_pushboolean(L, B(mvwinsch(w, y, x, ch))); 1686 | return 1; 1687 | } 1688 | 1689 | /* 1690 | ** ======================================================= 1691 | ** insstr 1692 | ** ======================================================= 1693 | */ 1694 | 1695 | static int lcw_winsstr(lua_State *L) 1696 | { 1697 | WINDOW *w = lcw_check(L, 1); 1698 | const char *str = luaL_checkstring(L, 2); 1699 | lua_pushboolean(L, B(winsnstr(w, str, lua_strlen(L, 2)))); 1700 | return 1; 1701 | } 1702 | 1703 | static int lcw_mvwinsstr(lua_State *L) 1704 | { 1705 | WINDOW *w = lcw_check(L, 1); 1706 | int y = luaL_checkint(L, 2); 1707 | int x = luaL_checkint(L, 3); 1708 | const char *str = luaL_checkstring(L, 4); 1709 | lua_pushboolean(L, B(mvwinsnstr(w, y, x, str, lua_strlen(L, 2)))); 1710 | return 1; 1711 | } 1712 | 1713 | static int lcw_winsnstr(lua_State *L) 1714 | { 1715 | WINDOW *w = lcw_check(L, 1); 1716 | const char *str = luaL_checkstring(L, 2); 1717 | int n = luaL_checkint(L, 3); 1718 | lua_pushboolean(L, B(winsnstr(w, str, n))); 1719 | return 1; 1720 | } 1721 | 1722 | static int lcw_mvwinsnstr(lua_State *L) 1723 | { 1724 | WINDOW *w = lcw_check(L, 1); 1725 | int y = luaL_checkint(L, 2); 1726 | int x = luaL_checkint(L, 3); 1727 | const char *str = luaL_checkstring(L, 4); 1728 | int n = luaL_checkint(L, 5); 1729 | lua_pushboolean(L, B(mvwinsnstr(w, y, x, str, n))); 1730 | return 1; 1731 | } 1732 | 1733 | /* 1734 | ** ======================================================= 1735 | ** pad 1736 | ** ======================================================= 1737 | */ 1738 | 1739 | static int lc_newpad(lua_State *L) 1740 | { 1741 | int nlines = luaL_checkint(L, 1); 1742 | int ncols = luaL_checkint(L, 2); 1743 | lcw_new(L, newpad(nlines, ncols)); 1744 | return 1; 1745 | } 1746 | 1747 | static int lcw_subpad(lua_State *L) 1748 | { 1749 | WINDOW *orig = lcw_check(L, 1); 1750 | int nlines = luaL_checkint(L, 2); 1751 | int ncols = luaL_checkint(L, 3); 1752 | int begin_y = luaL_checkint(L, 4); 1753 | int begin_x = luaL_checkint(L, 5); 1754 | 1755 | lcw_new(L, subpad(orig, nlines, ncols, begin_y, begin_x)); 1756 | return 1; 1757 | } 1758 | 1759 | static int lcw_prefresh(lua_State *L) 1760 | { 1761 | WINDOW *p = lcw_check(L, 1); 1762 | int pminrow = luaL_checkint(L, 2); 1763 | int pmincol = luaL_checkint(L, 3); 1764 | int sminrow = luaL_checkint(L, 4); 1765 | int smincol = luaL_checkint(L, 5); 1766 | int smaxrow = luaL_checkint(L, 6); 1767 | int smaxcol = luaL_checkint(L, 7); 1768 | 1769 | lua_pushboolean(L, B(prefresh(p, pminrow, pmincol, 1770 | sminrow, smincol, smaxrow, smaxcol))); 1771 | return 1; 1772 | } 1773 | 1774 | static int lcw_pnoutrefresh(lua_State *L) 1775 | { 1776 | WINDOW *p = lcw_check(L, 1); 1777 | int pminrow = luaL_checkint(L, 2); 1778 | int pmincol = luaL_checkint(L, 3); 1779 | int sminrow = luaL_checkint(L, 4); 1780 | int smincol = luaL_checkint(L, 5); 1781 | int smaxrow = luaL_checkint(L, 6); 1782 | int smaxcol = luaL_checkint(L, 7); 1783 | 1784 | lua_pushboolean(L, B(pnoutrefresh(p, pminrow, pmincol, 1785 | sminrow, smincol, smaxrow, smaxcol))); 1786 | return 1; 1787 | } 1788 | 1789 | 1790 | static int lcw_pechochar(lua_State *L) 1791 | { 1792 | WINDOW *p = lcw_check(L, 1); 1793 | chtype ch = lc_checkch(L, 2); 1794 | 1795 | lua_pushboolean(L, B(pechochar(p, ch))); 1796 | return 1; 1797 | } 1798 | 1799 | /* 1800 | ** ======================================================= 1801 | ** attr 1802 | ** ======================================================= 1803 | */ 1804 | 1805 | static int lcw_wattroff(lua_State *L) 1806 | { 1807 | WINDOW *w = lcw_check(L, 1); 1808 | int attrs = luaL_checkint(L, 2); 1809 | lua_pushboolean(L, B(wattroff(w, attrs))); 1810 | return 1; 1811 | } 1812 | 1813 | static int lcw_wattron(lua_State *L) 1814 | { 1815 | WINDOW *w = lcw_check(L, 1); 1816 | int attrs = luaL_checkint(L, 2); 1817 | lua_pushboolean(L, B(wattron(w, attrs))); 1818 | return 1; 1819 | } 1820 | 1821 | static int lcw_wattrset(lua_State *L) 1822 | { 1823 | WINDOW *w = lcw_check(L, 1); 1824 | int attrs = luaL_checkint(L, 2); 1825 | lua_pushboolean(L, B(wattrset(w, attrs))); 1826 | return 1; 1827 | } 1828 | 1829 | LCW_BOOLOK(wstandend) 1830 | LCW_BOOLOK(wstandout) 1831 | 1832 | 1833 | /* 1834 | ** ======================================================= 1835 | ** query terminfo database 1836 | ** ======================================================= 1837 | */ 1838 | 1839 | static char ti_capname[32]; 1840 | 1841 | static int ti_getflag (lua_State *L) 1842 | { 1843 | int res; 1844 | 1845 | strlcpy (ti_capname, luaL_checkstring (L, 1), sizeof (ti_capname)); 1846 | res = tigetflag (ti_capname); 1847 | if (-1 == res) 1848 | return luaL_error (L, "`%s' is not a boolean capability", ti_capname); 1849 | else 1850 | lua_pushboolean (L, res); 1851 | return 1; 1852 | } 1853 | 1854 | static int ti_getnum (lua_State *L) 1855 | { 1856 | int res; 1857 | 1858 | strlcpy (ti_capname, luaL_checkstring (L, 1), sizeof (ti_capname)); 1859 | res = tigetnum (ti_capname); 1860 | if (-2 == res) 1861 | return luaL_error (L, "`%s' is not a numeric capability", ti_capname); 1862 | else if (-1 == res) 1863 | lua_pushnil (L); 1864 | else 1865 | lua_pushnumber(L, res); 1866 | return 1; 1867 | } 1868 | 1869 | static int ti_getstr (lua_State *L) 1870 | { 1871 | const char *res; 1872 | 1873 | strlcpy (ti_capname, luaL_checkstring (L, 1), sizeof (ti_capname)); 1874 | res = tigetstr (ti_capname); 1875 | if ((char *) -1 == res) 1876 | return luaL_error (L, "`%s' is not a string capability", ti_capname); 1877 | else if (NULL == res) 1878 | lua_pushnil (L); 1879 | else 1880 | lua_pushstring(L, res); 1881 | return 1; 1882 | } 1883 | 1884 | 1885 | /* 1886 | ** ======================================================= 1887 | ** register functions 1888 | ** ======================================================= 1889 | */ 1890 | /* chstr members */ 1891 | static const luaL_reg chstrlib[] = 1892 | { 1893 | { "len", chstr_len }, 1894 | { "set_ch", chstr_set_ch }, 1895 | { "set_str", chstr_set_str }, 1896 | { "get", chstr_get }, 1897 | { "dup", chstr_dup }, 1898 | 1899 | { NULL, NULL } 1900 | }; 1901 | 1902 | #define EWF(name) { #name, lcw_ ## name }, 1903 | static const luaL_reg windowlib[] = 1904 | { 1905 | /* window */ 1906 | { "close", lcw_delwin }, 1907 | { "sub", lcw_subwin }, 1908 | { "derive", lcw_derwin }, 1909 | { "move_window", lcw_mvwin }, 1910 | { "move_derived", lcw_mvderwin }, 1911 | { "clone", lcw_dupwin }, 1912 | { "syncup", lcw_wsyncup }, 1913 | { "syncdown", lcw_wsyncdown }, 1914 | { "syncok", lcw_syncok }, 1915 | { "cursyncup", lcw_wcursyncup }, 1916 | 1917 | /* inopts */ 1918 | EWF(intrflush) 1919 | EWF(keypad) 1920 | EWF(meta) 1921 | EWF(nodelay) 1922 | EWF(timeout) 1923 | EWF(notimeout) 1924 | 1925 | /* outopts */ 1926 | EWF(clearok) 1927 | EWF(idlok) 1928 | EWF(leaveok) 1929 | EWF(scrollok) 1930 | EWF(idcok) 1931 | EWF(immedok) 1932 | EWF(wsetscrreg) 1933 | 1934 | /* pad */ 1935 | EWF(subpad) 1936 | EWF(prefresh) 1937 | EWF(pnoutrefresh) 1938 | EWF(pechochar) 1939 | 1940 | /* move */ 1941 | { "move", lcw_wmove }, 1942 | 1943 | /* scroll */ 1944 | { "scrl", lcw_wscrl }, 1945 | 1946 | /* refresh */ 1947 | { "refresh", lcw_wrefresh }, 1948 | { "noutrefresh", lcw_wnoutrefresh }, 1949 | { "redrawwin", lcw_redrawwin }, 1950 | { "redrawln", lcw_wredrawln }, 1951 | 1952 | /* clear */ 1953 | { "erase", lcw_werase }, 1954 | { "clear", lcw_wclear }, 1955 | { "clrtobot", lcw_wclrtobot }, 1956 | { "clrtoeol", lcw_wclrtoeol }, 1957 | 1958 | /* touch */ 1959 | { "touch", lcw_touch }, 1960 | { "touchline", lcw_touchline }, 1961 | { "is_linetouched", lcw_is_linetouched }, 1962 | { "is_wintouched", lcw_is_wintouched }, 1963 | 1964 | /* attrs */ 1965 | { "attroff", lcw_wattroff }, 1966 | { "attron", lcw_wattron }, 1967 | { "attrset", lcw_wattrset }, 1968 | { "standout", lcw_wstandout }, 1969 | { "standend", lcw_wstandend }, 1970 | 1971 | /* getch */ 1972 | { "getch", lcw_wgetch }, 1973 | { "mvgetch", lcw_mvwgetch }, 1974 | 1975 | /* getyx */ 1976 | EWF(getyx) 1977 | EWF(getparyx) 1978 | EWF(getbegyx) 1979 | EWF(getmaxyx) 1980 | 1981 | /* border */ 1982 | { "border", lcw_wborder }, 1983 | { "box", lcw_box }, 1984 | { "hline", lcw_whline }, 1985 | { "vline", lcw_wvline }, 1986 | { "mvhline", lcw_mvwhline }, 1987 | { "mvvline", lcw_mvwvline }, 1988 | 1989 | /* addch */ 1990 | { "addch", lcw_waddch }, 1991 | { "mvaddch", lcw_mvwaddch }, 1992 | { "echoch", lcw_wechochar }, 1993 | 1994 | /* addchstr */ 1995 | { "addchstr", lcw_waddchnstr }, 1996 | { "mvaddchstr", lcw_mvwaddchnstr }, 1997 | 1998 | /* addstr */ 1999 | { "addstr", lcw_waddnstr }, 2000 | { "mvaddstr", lcw_mvwaddnstr }, 2001 | 2002 | /* bkgd */ 2003 | EWF(wbkgdset) 2004 | EWF(wbkgd) 2005 | EWF(getbkgd) 2006 | 2007 | /* overlay */ 2008 | { "overlay", lcw_overlay }, 2009 | { "overwrite", lcw_overwrite }, 2010 | { "copywin", lcw_copywin }, 2011 | 2012 | /* delch */ 2013 | { "delch", lcw_wdelch }, 2014 | { "mvdelch", lcw_mvwdelch }, 2015 | 2016 | /* deleteln */ 2017 | { "deleteln", lcw_wdeleteln }, 2018 | { "insertln", lcw_winsertln }, 2019 | EWF(winsdelln) 2020 | 2021 | /* getstr */ 2022 | { "getstr", lcw_wgetnstr }, 2023 | { "mvgetstr", lcw_mvwgetnstr }, 2024 | 2025 | /* inch */ 2026 | EWF(winch) 2027 | EWF(mvwinch) 2028 | EWF(winchnstr) 2029 | EWF(mvwinchnstr) 2030 | 2031 | /* instr */ 2032 | EWF(winnstr) 2033 | EWF(mvwinnstr) 2034 | 2035 | /* insch */ 2036 | EWF(winsch) 2037 | EWF(mvwinsch) 2038 | 2039 | /* insstr */ 2040 | EWF(winsstr) 2041 | EWF(winsnstr) 2042 | EWF(mvwinsstr) 2043 | EWF(mvwinsnstr) 2044 | 2045 | /* misc */ 2046 | {"__gc", lcw_delwin }, /* rough safety net */ 2047 | {"__tostring", lcw_tostring}, 2048 | {NULL, NULL} 2049 | }; 2050 | 2051 | #define ECF(name) { #name, lc_ ## name }, 2052 | static const luaL_reg curseslib[] = 2053 | { 2054 | /* chstr helper function */ 2055 | { "new_chstr", lc_new_chstr }, 2056 | 2057 | /* initscr */ 2058 | { "endwin", lc_endwin }, 2059 | { "isendwin", lc_isendwin }, 2060 | { "stdscr", lc_stdscr }, 2061 | { "cols", lc_COLS }, 2062 | { "lines", lc_LINES }, 2063 | 2064 | /* color */ 2065 | { "start_color", lc_start_color }, 2066 | { "has_colors", lc_has_colors }, 2067 | { "init_pair", lc_init_pair }, 2068 | { "pair_content", lc_pair_content }, 2069 | { "colors", lc_COLORS }, 2070 | { "color_pairs", lc_COLOR_PAIRS }, 2071 | { "color_pair", lc_COLOR_PAIR }, 2072 | 2073 | /* termattrs */ 2074 | { "baudrate", lc_baudrate }, 2075 | { "erasechar", lc_erasechar }, 2076 | { "killchar", lc_killchar }, 2077 | { "has_ic", lc_has_ic }, 2078 | { "has_il", lc_has_il }, 2079 | { "termattrs", lc_termattrs }, 2080 | { "termname", lc_termname }, 2081 | { "longname", lc_longname }, 2082 | 2083 | /* kernel */ 2084 | { "ripoffline", lc_ripoffline }, 2085 | { "napms", lc_napms }, 2086 | { "curs_set", lc_curs_set }, 2087 | 2088 | /* beep */ 2089 | { "beep", lc_beep }, 2090 | { "flash", lc_flash }, 2091 | 2092 | /* window */ 2093 | { "newwin", lc_newwin }, 2094 | 2095 | /* pad */ 2096 | { "newpad", lc_newpad }, 2097 | 2098 | /* refresh */ 2099 | { "doupdate", lc_doupdate }, 2100 | 2101 | /* inopts */ 2102 | { "cbreak", lc_cbreak }, 2103 | { "echo", lc_echo }, 2104 | { "raw", lc_raw }, 2105 | { "halfdelay", lc_halfdelay }, 2106 | 2107 | /* util */ 2108 | { "unctrl", lc_unctrl }, 2109 | { "keyname", lc_keyname }, 2110 | { "delay_output", lc_delay_output }, 2111 | { "flushinp", lc_flushinp }, 2112 | 2113 | /* getch */ 2114 | { "ungetch", lc_ungetch }, 2115 | 2116 | /* outopts */ 2117 | { "nl", lc_nl }, 2118 | 2119 | /* query terminfo database */ 2120 | { "tigetflag", ti_getflag }, 2121 | { "tigetnum", ti_getnum }, 2122 | { "tigetstr", ti_getstr }, 2123 | 2124 | /* slk */ 2125 | ECF(slk_init) 2126 | ECF(slk_set) 2127 | ECF(slk_refresh) 2128 | ECF(slk_noutrefresh) 2129 | ECF(slk_label) 2130 | ECF(slk_clear) 2131 | ECF(slk_restore) 2132 | ECF(slk_touch) 2133 | ECF(slk_attron) 2134 | ECF(slk_attroff) 2135 | ECF(slk_attrset) 2136 | 2137 | /* terminator */ 2138 | {NULL, NULL} 2139 | }; 2140 | 2141 | 2142 | /* Prototype to keep compiler happy. */ 2143 | int luaopen_curses_c (lua_State *L); 2144 | 2145 | int luaopen_curses_c (lua_State *L) 2146 | { 2147 | /* 2148 | ** create new metatable for window objects 2149 | */ 2150 | luaL_newmetatable(L, WINDOWMETA); 2151 | lua_pushliteral(L, "__index"); 2152 | lua_pushvalue(L, -2); /* push metatable */ 2153 | lua_rawset(L, -3); /* metatable.__index = metatable */ 2154 | luaL_openlib(L, NULL, windowlib, 0); 2155 | 2156 | lua_pop(L, 1); /* remove metatable from stack */ 2157 | 2158 | /* 2159 | ** create new metatable for chstr objects 2160 | */ 2161 | luaL_newmetatable(L, CHSTRMETA); 2162 | lua_pushliteral(L, "__index"); 2163 | lua_pushvalue(L, -2); /* push metatable */ 2164 | lua_rawset(L, -3); /* metatable.__index = metatable */ 2165 | luaL_openlib(L, NULL, chstrlib, 0); 2166 | 2167 | lua_pop(L, 1); /* remove metatable from stack */ 2168 | 2169 | /* 2170 | ** create global table with curses methods/variables/constants 2171 | */ 2172 | luaL_register(L, "curses", curseslib); 2173 | 2174 | lua_pushstring(L, "initscr"); 2175 | lua_pushvalue(L, -2); 2176 | lua_pushcclosure(L, lc_initscr, 1); 2177 | lua_settable(L, -3); 2178 | 2179 | return 1; 2180 | } 2181 | 2182 | /* Local Variables: */ 2183 | /* c-basic-offset: 4 */ 2184 | /* End: */ 2185 | -------------------------------------------------------------------------------- /m4/.gitignore: -------------------------------------------------------------------------------- 1 | /libtool.m4 2 | /ltoptions.m4 3 | /ltsugar.m4 4 | /ltversion.m4 5 | /lt~obsolete.m4 6 | /00gnulib.m4 7 | /gnulib-cache.m4 8 | /gnulib-common.m4 9 | /gnulib-comp.m4 10 | /gnulib-tool.m4 11 | /manywarnings.m4 12 | /onceonly.m4 13 | /warnings.m4 14 | -------------------------------------------------------------------------------- /m4/ax_lua.m4: -------------------------------------------------------------------------------- 1 | # =========================================================================== 2 | # http://www.gnu.org/software/autoconf-archive/ax_lua.html 3 | # =========================================================================== 4 | # 5 | # SYNOPSIS 6 | # 7 | # AX_WITH_LUA 8 | # AX_PROG_LUA [(MIN-VERSION, [TOO-BIG-VERSION])] 9 | # AX_LUA_VERSION (MIN-VERSION, [TOO-BIG-VERSION]) 10 | # AX_LUA_HEADERS 11 | # AX_LUA_HEADERS_VERSION (MIN-VERSION, [TOO-BIG-VERSION]) 12 | # AX_LUA_LIBS 13 | # AX_LUA_READLINE 14 | # 15 | # DESCRIPTION 16 | # 17 | # Detect Lua interpreter, headers and libraries, optionally enforcing a 18 | # particular range of versions. If only one version is given, then exactly 19 | # this version is required. 20 | # 21 | # AX_WITH_LUA searches for a Lua interpreter and defines LUA if found. 22 | # 23 | # AX_PROG_LUA searches for a Lua interpreter in the given version range, 24 | # if any, and defines LUA if found, or stops with an error if not. 25 | # 26 | # AX_LUA_VERSION checks that the version of Lua is at least MIN-VERSION 27 | # and less than TOO-BIG-VERSION, if given. 28 | # 29 | # AX_LUA_HEADERS searches for Lua headers and defines HAVE_LUA_H and 30 | # HAVE_LUALIB_H if found, and defines LUA_INCLUDE to the preprocessor 31 | # flags needed, if any. 32 | # 33 | # AX_LUA_HEADERS_VERSION checks that the Lua headers' version is at least 34 | # MIN-VERSION, and less than TOO-BIG-VERSION, if given. 35 | # 36 | # AX_LUA_LIBS searches for Lua libraries and defines LUA_LIB if found. 37 | # 38 | # AX_LUA_READLINE configures Lua to be built with readline support, if 39 | # available. This macro requires AX_LIB_READLINE. 40 | # 41 | # Versions are specified as three-digit integers whose first digit is the 42 | # major version and last two are the minor version (the same format as 43 | # LUA_VERSION_NUM in lua.h); e.g. 501 for Lua 5.1. The revision (e.g. the 44 | # "3" in "5.1.3") is ignored. 45 | # 46 | # The following options are added by these macros: 47 | # 48 | # --with-lua-suffix=ARG Lua binaries and library files are 49 | # suffixed with ARG. 50 | # 51 | # LICENSE 52 | # 53 | # Copyright (c) 2011 Reuben Thomas 54 | # Copyright (c) 2009 Matthieu Moy 55 | # Copyright (c) 2009 Tom Payne 56 | # 57 | # This program is free software: you can redistribute it and/or modify it 58 | # under the terms of the GNU General Public License as published by the 59 | # Free Software Foundation, either version 3 of the License, or (at your 60 | # option) any later version. 61 | # 62 | # This program is distributed in the hope that it will be useful, but 63 | # WITHOUT ANY WARRANTY; without even the implied warranty of 64 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General 65 | # Public License for more details. 66 | # 67 | # You should have received a copy of the GNU General Public License along 68 | # with this program. If not, see . 69 | # 70 | # As a special exception, the respective Autoconf Macro's copyright owner 71 | # gives unlimited permission to copy, distribute and modify the configure 72 | # scripts that are the output of Autoconf when processing the Macro. You 73 | # need not follow the terms of the GNU General Public License when using 74 | # or distributing such scripts, even though portions of the text of the 75 | # Macro appear in them. The GNU General Public License (GPL) does govern 76 | # all other use of the material that constitutes the Autoconf Macro. 77 | # 78 | # This special exception to the GPL applies to versions of the Autoconf 79 | # Macro released by the Autoconf Archive. When you make and distribute a 80 | # modified version of the Autoconf Macro, you may extend this special 81 | # exception to the GPL to apply to your modified version as well. 82 | 83 | #serial 15 84 | 85 | dnl Helper function to declare extra options 86 | AC_DEFUN([_AX_LUA_OPTS], 87 | [AC_ARG_WITH([lua-suffix], 88 | [AS_HELP_STRING([--with-lua-suffix=ARG], 89 | [Lua binary and library files are suffixed with ARG])])])dnl 90 | 91 | AC_DEFUN([AX_WITH_LUA], 92 | [_AX_LUA_OPTS 93 | if test "x$LUA" = x; then 94 | AC_PATH_PROG(LUA, lua$with_lua_suffix) 95 | fi])dnl 96 | 97 | AC_DEFUN([AX_PROG_LUA], 98 | [AX_WITH_LUA 99 | if test -z "$LUA"; then 100 | AC_MSG_FAILURE([Lua not found]) 101 | fi 102 | if test -n "$1"; then 103 | AX_LUA_VERSION($1, $2) 104 | fi 105 | AC_SUBST(LUA)])dnl 106 | 107 | dnl Helper function to parse minimum & maximum versions 108 | AC_DEFUN([_AX_LUA_VERSIONS], 109 | [lua_min_version=$1 110 | lua_max_version=$2 111 | if test "x$lua_min_version" = x; then 112 | lua_min_version=0 113 | fi 114 | if test "x$lua_max_version" = x; then 115 | lua_max_version=$(($lua_min_version + 1)) 116 | fi]) 117 | 118 | AC_DEFUN([AX_LUA_VERSION], 119 | [_AX_LUA_OPTS 120 | _AX_LUA_VERSIONS($1, $2) 121 | AC_MSG_CHECKING([Lua version is in range $lua_min_version <= v < $lua_max_version]) 122 | if test "x$LUA" != x; then 123 | lua_text_version=$(LUA_INIT= $LUA -e 'print(_VERSION)' 2>&1 | cut -d' ' -f2) 124 | case $lua_text_version in 125 | 5.2*) 126 | lua_version=502 127 | ;; 128 | 5.1*) 129 | lua_version=501 130 | ;; 131 | 5.0*) 132 | lua_version=500 133 | ;; 134 | 4.0*) 135 | lua_version=400 136 | ;; 137 | *) 138 | lua_version=-1 139 | ;; 140 | esac 141 | if test $lua_version -ge "$lua_min_version" && test $lua_version -lt "$lua_max_version"; then 142 | AC_MSG_RESULT([yes]) 143 | else 144 | AC_MSG_RESULT([no]) 145 | AC_MSG_FAILURE([Lua version not in desired range.]) 146 | fi 147 | else 148 | AC_MSG_RESULT([no]) 149 | AC_MSG_FAILURE([Lua version not in desired range.]) 150 | fi])dnl 151 | 152 | AC_DEFUN([AX_LUA_HEADERS], 153 | [_AX_LUA_OPTS 154 | LUA_OLD_CPPFLAGS="$CPPFLAGS" 155 | CPPFLAGS="$CPPFLAGS $LUA_INCLUDE" 156 | AC_CHECK_HEADERS([lua.h lualib.h]) 157 | CPPFLAGS="$LUA_OLD_CPPFLAGS"])dnl 158 | 159 | AC_DEFUN([AX_LUA_LIBS], 160 | [_AX_LUA_OPTS 161 | AC_CHECK_LIB([m], [exp], [lua_extra_libs="$lua_extra_libs -lm"], []) 162 | AC_CHECK_LIB([dl], [dlopen], [lua_extra_libs="$lua_extra_libs -ldl"], []) 163 | AC_CHECK_LIB([lua$with_lua_suffix], 164 | [lua_call], 165 | [LUA_LIB="$LUA_LIB -llua$with_lua_suffix $lua_extra_libs"], 166 | [], 167 | [$LUA_LIB $lua_extra_libs])])dnl 168 | 169 | AC_DEFUN([AX_LUA_HEADERS_VERSION], 170 | [_AX_LUA_OPTS 171 | _AX_LUA_VERSIONS($1, $2) 172 | AC_MSG_CHECKING([lua.h version is in range $lua_min_version <= v < $lua_max_version]) 173 | LUA_OLD_LIBS="$LIBS" 174 | LIBS="$LIBS $LUA_LIB" 175 | LUA_OLD_CPPFLAGS="$CPPFLAGS" 176 | CPPFLAGS="$CPPFLAGS $LUA_INCLUDE" 177 | AC_RUN_IFELSE([AC_LANG_SOURCE([[ 178 | #include 179 | #include 180 | #include 181 | int main() 182 | { 183 | printf("(found %s, %d)... ", LUA_VERSION, LUA_VERSION_NUM); 184 | if (LUA_VERSION_NUM >= $lua_min_version && LUA_VERSION_NUM < $lua_max_version) 185 | exit(EXIT_SUCCESS); 186 | exit(EXIT_FAILURE); 187 | } 188 | ]])], 189 | [AC_MSG_RESULT([yes])], 190 | [AC_MSG_RESULT([no]) 191 | AC_MSG_FAILURE([lua.h version not in desired range])]) 192 | LIBS="$LUA_OLD_LIBS" 193 | CPPFLAGS="$LUA_OLD_CPPFLAGS"])dnl 194 | 195 | AC_DEFUN([AX_LUA_READLINE], 196 | [AX_LIB_READLINE 197 | if test -n "$ac_cv_header_readline_readline_h" && test -n "$ac_cv_header_readline_history_h"; then 198 | LUA_LIBS_CFLAGS="-DLUA_USE_READLINE $LUA_LIBS_CFLAGS" 199 | fi])dnl 200 | -------------------------------------------------------------------------------- /m4/ax_with_curses.m4: -------------------------------------------------------------------------------- 1 | # =========================================================================== 2 | # http://www.gnu.org/software/autoconf-archive/ax_with_curses.html 3 | # =========================================================================== 4 | # 5 | # SYNOPSIS 6 | # 7 | # AX_WITH_CURSES 8 | # 9 | # DESCRIPTION 10 | # 11 | # Detect SysV compatible curses, such as ncurses. 12 | # 13 | # Defines HAVE_CURSES_H or HAVE_NCURSES_H if curses is found. CURSES_LIB 14 | # is also set with the required library, but is not appended to LIBS 15 | # automatically. If no working curses library is found CURSES_LIB will be 16 | # left blank. If CURSES_LIB is set in the environment, the supplied value 17 | # will be used. 18 | # 19 | # There are two options: --with-ncurses forces the use of ncurses, and 20 | # --with-ncursesw forces the use of ncursesw (wide character ncurses). The 21 | # corresponding options --without-ncurses and --without-ncursesw force 22 | # those libraries not to be used. By default, ncursesw is preferred to 23 | # ncurses, which is preferred to plain curses. 24 | # 25 | # ax_cv_curses is set to "yes" if any curses is found (including 26 | # ncurses!); ax_cv_ncurses is set to "yes" if any ncurses is found, and 27 | # ax_cv_ncursesw is set to "yes" if ncursesw is found. 28 | # 29 | # LICENSE 30 | # 31 | # Copyright (c) 2009 Mark Pulford 32 | # Copyright (c) 2009 Damian Pietras 33 | # Copyright (c) 2011 Reuben Thomas 34 | # 35 | # This program is free software: you can redistribute it and/or modify it 36 | # under the terms of the GNU General Public License as published by the 37 | # Free Software Foundation, either version 3 of the License, or (at your 38 | # option) any later version. 39 | # 40 | # This program is distributed in the hope that it will be useful, but 41 | # WITHOUT ANY WARRANTY; without even the implied warranty of 42 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General 43 | # Public License for more details. 44 | # 45 | # You should have received a copy of the GNU General Public License along 46 | # with this program. If not, see . 47 | # 48 | # As a special exception, the respective Autoconf Macro's copyright owner 49 | # gives unlimited permission to copy, distribute and modify the configure 50 | # scripts that are the output of Autoconf when processing the Macro. You 51 | # need not follow the terms of the GNU General Public License when using 52 | # or distributing such scripts, even though portions of the text of the 53 | # Macro appear in them. The GNU General Public License (GPL) does govern 54 | # all other use of the material that constitutes the Autoconf Macro. 55 | # 56 | # This special exception to the GPL applies to versions of the Autoconf 57 | # Macro released by the Autoconf Archive. When you make and distribute a 58 | # modified version of the Autoconf Macro, you may extend this special 59 | # exception to the GPL to apply to your modified version as well. 60 | 61 | #serial 10 62 | 63 | AU_ALIAS([MP_WITH_CURSES], [AX_WITH_CURSES]) 64 | AC_DEFUN([AX_WITH_CURSES], 65 | [AC_ARG_WITH(ncurses, [AS_HELP_STRING([--with-ncurses], 66 | [Force the use of ncurses over curses])],,) 67 | ax_save_LIBS="$LIBS" 68 | AC_ARG_WITH(ncursesw, [AS_HELP_STRING([--without-ncursesw], 69 | [Don't use ncursesw (wide character support)])],,) 70 | if test ! "$CURSES_LIB" && test "$with_ncurses" != no && test "$with_ncursesw" != "no" 71 | then 72 | AC_CACHE_CHECK([for working ncursesw], ax_cv_ncursesw, 73 | [LIBS="$ax_save_LIBS -lncursesw" 74 | AC_TRY_LINK( 75 | [#include ], 76 | [chtype a; int b=A_STANDOUT, c=KEY_LEFT; initscr(); ], 77 | ax_cv_ncursesw=yes, ax_cv_ncursesw=no)]) 78 | if test "$ax_cv_ncursesw" = yes 79 | then 80 | AC_CHECK_HEADER([ncursesw/curses.h], AC_DEFINE([HAVE_NCURSESW_H], 1, 81 | [Define if you have ncursesw.h])) 82 | AC_DEFINE([HAVE_NCURSES_H], 1, [Define if you have ncursesw/curses.h]) 83 | AC_DEFINE([HAVE_NCURSESW], 1, [Define if you have libncursesw]) 84 | CURSES_LIB="-lncursesw" 85 | ax_cv_ncurses=yes 86 | ax_cv_curses=yes 87 | fi 88 | fi 89 | if test ! "$CURSES_LIB" && test "$with_ncurses" != no && test "$with_ncursesw" != yes 90 | then 91 | AC_CACHE_CHECK([for working ncurses], ax_cv_ncurses, 92 | [LIBS="$ax_save_LIBS -lncurses" 93 | AC_TRY_LINK( 94 | [#include ], 95 | [chtype a; int b=A_STANDOUT, c=KEY_LEFT; initscr(); ], 96 | ax_cv_ncurses=yes, ax_cv_ncurses=no)]) 97 | if test "$ax_cv_ncurses" = yes 98 | then 99 | AC_DEFINE([HAVE_NCURSES_H],[1],[Define if you have ncurses.h]) 100 | CURSES_LIB="-lncurses" 101 | ax_cv_curses=yes 102 | fi 103 | fi 104 | if test "$ax_cv_curses" != yes && test "$with_ncurses" != yes && test "$with_ncursesw" != yes 105 | then 106 | if test ! "$CURSES_LIB" 107 | then 108 | CURSES_LIB="-lcurses" 109 | fi 110 | AC_CACHE_CHECK([for working curses], ax_cv_curses, 111 | [LIBS="$ax_save_LIBS $CURSES_LIB" 112 | AC_TRY_LINK( 113 | [#include ], 114 | [chtype a; int b=A_STANDOUT, c=KEY_LEFT; initscr(); ], 115 | ax_cv_curses=yes, ax_cv_curses=no)]) 116 | if test "$ax_cv_curses" = yes 117 | then 118 | AC_DEFINE([HAVE_CURSES_H],[1],[Define if you have curses.h]) 119 | fi 120 | fi 121 | LIBS="$ax_save_LIBS" 122 | ])dnl 123 | -------------------------------------------------------------------------------- /m4/ax_with_prog.m4: -------------------------------------------------------------------------------- 1 | # =========================================================================== 2 | # http://www.gnu.org/software/autoconf-archive/ax_with_prog.html 3 | # =========================================================================== 4 | # 5 | # SYNOPSIS 6 | # 7 | # AX_WITH_PROG([VARIABLE],[program],[VALUE-IF-NOT-FOUND],[PATH]) 8 | # 9 | # DESCRIPTION 10 | # 11 | # Locates an installed program binary, placing the result in the precious 12 | # variable VARIABLE. Accepts a present VARIABLE, then --with-program, and 13 | # failing that searches for program in the given path (which defaults to 14 | # the system path). If program is found, VARIABLE is set to the full path 15 | # of the binary; if it is not found VARIABLE is set to VALUE-IF-NOT-FOUND 16 | # if provided, unchanged otherwise. 17 | # 18 | # A typical example could be the following one: 19 | # 20 | # AX_WITH_PROG(PERL,perl) 21 | # 22 | # NOTE: This macro is based upon the original AX_WITH_PYTHON macro from 23 | # Dustin J. Mitchell . 24 | # 25 | # LICENSE 26 | # 27 | # Copyright (c) 2008 Francesco Salvestrini 28 | # Copyright (c) 2008 Dustin J. Mitchell 29 | # 30 | # Copying and distribution of this file, with or without modification, are 31 | # permitted in any medium without royalty provided the copyright notice 32 | # and this notice are preserved. This file is offered as-is, without any 33 | # warranty. 34 | 35 | #serial 16 36 | 37 | AC_DEFUN([AX_WITH_PROG],[ 38 | AC_PREREQ([2.61]) 39 | 40 | pushdef([VARIABLE],$1) 41 | pushdef([EXECUTABLE],$2) 42 | pushdef([VALUE_IF_NOT_FOUND],$3) 43 | pushdef([PATH_PROG],$4) 44 | 45 | AC_ARG_VAR(VARIABLE,Absolute path to EXECUTABLE executable) 46 | 47 | AS_IF(test -z "$VARIABLE",[ 48 | AC_MSG_CHECKING(whether EXECUTABLE executable path has been provided) 49 | AC_ARG_WITH(EXECUTABLE,AS_HELP_STRING([--with-EXECUTABLE=[[[PATH]]]],absolute path to EXECUTABLE executable), [ 50 | AS_IF([test "$withval" != yes && test "$withval" != no],[ 51 | VARIABLE="$withval" 52 | AC_MSG_RESULT($VARIABLE) 53 | ],[ 54 | VARIABLE="" 55 | AC_MSG_RESULT([no]) 56 | AS_IF([test "$withval" != no], [ 57 | AC_PATH_PROG([]VARIABLE[],[]EXECUTABLE[],[]VALUE_IF_NOT_FOUND[],[]PATH_PROG[]) 58 | ]) 59 | ]) 60 | ],[ 61 | AC_MSG_RESULT([no]) 62 | AC_PATH_PROG([]VARIABLE[],[]EXECUTABLE[],[]VALUE_IF_NOT_FOUND[],[]PATH_PROG[]) 63 | ]) 64 | ]) 65 | 66 | popdef([PATH_PROG]) 67 | popdef([VALUE_IF_NOT_FOUND]) 68 | popdef([EXECUTABLE]) 69 | popdef([VARIABLE]) 70 | ]) 71 | -------------------------------------------------------------------------------- /make_lcurses_doc.pl: -------------------------------------------------------------------------------- 1 | # Build lcurses documentation 2 | # (c) Peter Billam 2011 3 | 4 | # Permission is hereby granted, free of charge, to any person obtaining 5 | # a copy of this software and associated documentation files (the 6 | # "Software"), to deal in the Software without restriction, including 7 | # without limitation the rights to use, copy, modify, merge, publish, 8 | # distribute, sublicense, and/or sell copies of the Software, and to 9 | # permit persons to whom the Software is furnished to do so, subject to 10 | # the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be 13 | # included in all copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | 23 | 24 | open(I, 'lcurses.c') or die; my @I = (); close I; 25 | 26 | # make list of the lc_ and lcw_ routines 27 | my %lc_routine = (); 28 | my %lcw_routine = (); 29 | foreach (@I) { 30 | s/&/&/g; s/>/>/g; s/$_"; 33 | $lc_routine{$1} = 1; 34 | } elsif ($_ =~ /^static\s.+\s(lcw_\w+)/) { 35 | $_ = "$_"; 36 | $lcw_routine{$1} = 1; 37 | } 38 | } 39 | 40 | open(O, '>', 'lcurses_c.html') or die; 41 | print O <lcurses.c 43 |

lcurses.c

 44 | EOT
 45 | foreach my $line (@I) {
 46 |         if ($line =~ /^#define CC\(/) {
 47 |                 print O '',$line;
 48 |         } elsif ($line =~ /^#define EWF\(/) {
 49 |                 print O '',$line;
 50 |         } elsif ($line =~ /^#define ECF\(/) {
 51 |                 print O '',$line;
 52 |         } else {
 53 |                 print O $line;
 54 |         }
 55 | }
 56 | print O <
 58 | EOT
 59 | close O;
 60 | 
 61 | my @P = ();  close P;
 62 | open(O, '>', 'lcurses.html') or die;
 63 | foreach my $line (@P) {
 64 |         if ($line =~ /^(\w+)\(/) {
 65 |                 my $s = $1;
 66 |                 if ($lc_routine{"lc_$s"}) {
 67 |                         print O $line,
 68 |                           "  see lcurses.c
\n"; 69 | } elsif ($lcw_routine{"lcw_$s"}) { 70 | print O $line, 71 | "(see lcurses.c)
\n"; 72 | } else { 73 | print O $line,'
'; 74 | } 75 | } elsif ($line =~ /XXWINDOWLIBXX/) { 76 | my %wl = (); 77 | my $i = $[; while ($i <= $#I) { 78 | if ($I[$i] =~ /static const luaL_reg windowlib/) { last; } 79 | $i += 1; 80 | } 81 | while ($i <= $#I) { 82 | if ($I[$i] =~ / misc /) { last; } 83 | if ($I[$i] =~ /EWF\((\w+)\)/) { $wl{$1} = "lcw_$1"; 84 | } elsif ($I[$i] =~ /"(\w+)", (lcw_\w+)/) { $wl{$1} = $2; 85 | } 86 | $i += 1; 87 | } 88 | foreach my $k (sort keys %wl) { 89 | my $v = $wl{$k}; 90 | if ($lcw_routine{$v}) { 91 | print O "$k()   see " 92 | . "lcurses.c
\n"; 93 | } else { 94 | print O "$k()
\n"; 95 | } 96 | } 97 | } else { 98 | my $url = 'http://search.cpan.org/perldoc?Curses'; 99 | $line =~ s#Perl Curses#Perl Curses#; 100 | print O $line; 101 | } 102 | } 103 | close O; 104 | __END__ 105 | 106 | 107 | 108 | 109 | lcurses documentation 110 | 111 | 112 | 115 | 116 | 117 | 118 | 119 |

120 | lcurses documentation 121 |

122 | 123 | 124 |
125 |

126 | 127 | 128 |
129 | 136 | 137 | 144 |
145 | 146 |
147 | 148 | 149 | 150 |

151 |

152 |

NAME

153 |

lcurses   -   154 | a C library for Lua 5.1 that wraps the curses API. 155 |

156 |

SYNOPSIS

157 |
require 'curses'
158 | curses.initscr()
159 | curses.cbreak()
160 | curses.echo(0)  -- not noecho !
161 | curses.nl(0)    -- not nonl !
162 | local stdscr = curses.stdscr()  -- it's a userdatum
163 | stdscr:clear()
164 | local a = {};  for k in pairs(curses) do a[#a+1]=k end
165 | stdscr:mvaddstr(15,20,'print out curses table (y/n) ? ')
166 | stdscr:refresh()
167 | local c = stdscr:getch()
168 | if c < 256 then c = string.char(c) end
169 | curses.endwin()
170 | if c == 'y' then
171 |     table.sort(a)
172 |     for i,k in ipairs(a) do print(type(curses[k])..'  '..k) end
173 | end
174 |

175 |

176 |

DESCRIPTION

177 |

lcurses is the interface between Lua and your system's ncurses 178 | or curses library. For descriptions on the usage of a given function 179 | or constant, consult your system's documentation, starting with 180 | man ncurses or man curses

181 |

182 |

183 |

CURSES FUNCTIONS

184 |

This list of functions can be seen by

185 |
186 |   require 'curses' ; local a = {};
187 |   for k in pairs(curses) do
188 |     if type(curses[k]) == 'function' then a[#a+1]=k end
189 |   end
190 |   table.sort(a) ; for i,k in ipairs(a) do print(k) end
191 |

and are defined in the 192 | 193 | static const luaL_reg curseslib 194 | section of lcurses.c 195 |

196 | baudrate() 197 | beep() 198 | cbreak() 199 | color_pair() 200 | color_pairs() 201 | colors() 202 | cols() 203 | curs_set() 204 | delay_output() 205 | doupdate() 206 | echo() 207 | endwin() 208 | erasechar() 209 | flash() 210 | flushinp() 211 | halfdelay() 212 | has_colors() 213 | has_ic() 214 | has_il() 215 | init_pair() 216 | initscr() 217 | isendwin() 218 | keyname() 219 | killchar() 220 | lines() 221 | longname() 222 | napms() 223 | new_chstr() 224 | newpad() 225 | newwin() 226 | nl() 227 | pair_content() 228 | raw() 229 | ripoffline() 230 | slk_attroff() 231 | slk_attron() 232 | slk_attrset() 233 | slk_clear() 234 | slk_init() 235 | slk_label() 236 | slk_noutrefresh() 237 | slk_refresh() 238 | slk_restore() 239 | slk_set() 240 | slk_touch() 241 | start_color() 242 | stdscr() 243 | termattrs() 244 | termname() 245 | unctrl() 246 | ungetch() 247 |

248 |

249 |

WINDOW METHODS

250 |

These are defined in the 251 | 252 | static const luaL_reg windowlib 253 | section of lcurses.c 254 |

255 | XXWINDOWLIBXX 256 |

257 |

CONSTANTS

258 |

These constants only appear after curses.initscr() is called; 259 | they can be seen by:

260 |
261 |   require 'curses' ; curses.initscr() ; local a = {};
262 |   for k in pairs(curses) do
263 |     if type(curses[k]) == 'number' then a[#a+1]=k end
264 |   end
265 |   curses.endwin()
266 |   table.sort(a) ; for i,k in ipairs(a) do print(k) end
267 |

and are defined in the 268 | 269 | static void register_curses_constants 270 | section of lcurses.c

271 |

ACS_BLOCK 272 | ACS_BOARD 273 | ACS_BTEE 274 | ACS_BULLET 275 | ACS_CKBOARD 276 | ACS_DARROW 277 | ACS_DEGREE 278 | ACS_DIAMOND 279 | ACS_HLINE 280 | ACS_LANTERN 281 | ACS_LARROW 282 | ACS_LLCORNER 283 | ACS_LRCORNER 284 | ACS_LTEE 285 | ACS_PLMINUS 286 | ACS_PLUS 287 | ACS_RARROW 288 | ACS_RTEE 289 | ACS_S1 290 | ACS_S9 291 | ACS_TTEE 292 | ACS_UARROW 293 | ACS_ULCORNER 294 | ACS_URCORNER 295 | ACS_VLINE

296 |

A_ALTCHARSET 297 | A_ATTRIBUTES 298 | A_BLINK 299 | A_BOLD 300 | A_CHARTEXT 301 | A_DIM 302 | A_INVIS 303 | A_NORMAL 304 | A_PROTECT 305 | A_REVERSE 306 | A_STANDOUT 307 | A_UNDERLINE

308 |

COLOR_BLACK 309 | COLOR_BLUE 310 | COLOR_CYAN 311 | COLOR_GREEN 312 | COLOR_MAGENTA 313 | COLOR_RED 314 | COLOR_WHITE 315 | COLOR_YELLOW

316 |

KEY_A1 317 | KEY_A3 318 | KEY_B2 319 | KEY_BACKSPACE 320 | KEY_BEG 321 | KEY_BREAK 322 | KEY_BTAB 323 | KEY_C1 324 | KEY_C3 325 | KEY_CANCEL 326 | KEY_CATAB 327 | KEY_CLEAR 328 | KEY_CLOSE 329 | KEY_COMMAND 330 | KEY_COPY 331 | KEY_CREATE 332 | KEY_CTAB 333 | KEY_DC 334 | KEY_DL 335 | KEY_DOWN 336 | KEY_EIC 337 | KEY_END 338 | KEY_ENTER 339 | KEY_EOL 340 | KEY_EOS 341 | KEY_EXIT 342 | KEY_F0 343 | KEY_F1 344 | KEY_F10 345 | KEY_F11 346 | KEY_F12 347 | KEY_F2 348 | KEY_F3 349 | KEY_F4 350 | KEY_F5 351 | KEY_F6 352 | KEY_F7 353 | KEY_F8 354 | KEY_F9 355 | KEY_FIND 356 | KEY_HELP 357 | KEY_HOME 358 | KEY_IC 359 | KEY_IL 360 | KEY_LEFT 361 | KEY_LL 362 | KEY_MARK 363 | KEY_MESSAGE 364 | KEY_MOUSE 365 | KEY_MOVE 366 | KEY_NEXT 367 | KEY_NPAGE 368 | KEY_OPEN 369 | KEY_OPTIONS 370 | KEY_PPAGE 371 | KEY_PREVIOUS 372 | KEY_PRINT 373 | KEY_REDO 374 | KEY_REFERENCE 375 | KEY_REFRESH 376 | KEY_REPLACE 377 | KEY_RESET 378 | KEY_RESIZE 379 | KEY_RESTART 380 | KEY_RESUME 381 | KEY_RIGHT 382 | KEY_SAVE 383 | KEY_SBEG 384 | KEY_SCANCEL 385 | KEY_SCOMMAND 386 | KEY_SCOPY 387 | KEY_SCREATE 388 | KEY_SDC 389 | KEY_SDL 390 | KEY_SELECT 391 | KEY_SEND 392 | KEY_SEOL 393 | KEY_SEXIT 394 | KEY_SF 395 | KEY_SFIND 396 | KEY_SHELP 397 | KEY_SHOME 398 | KEY_SIC 399 | KEY_SLEFT 400 | KEY_SMESSAGE 401 | KEY_SMOVE 402 | KEY_SNEXT 403 | KEY_SOPTIONS 404 | KEY_SPREVIOUS 405 | KEY_SPRINT 406 | KEY_SR 407 | KEY_SREDO 408 | KEY_SREPLACE 409 | KEY_SRESET 410 | KEY_SRIGHT 411 | KEY_SRSUME 412 | KEY_SSAVE 413 | KEY_SSUSPEND 414 | KEY_STAB 415 | KEY_SUNDO 416 | KEY_SUSPEND 417 | KEY_UNDO 418 | KEY_UP

419 |

420 |

421 |

COMPATIBILITY

422 |

In the C library, the following functions:

423 |
424 |     getstr()   (and wgetstr(), mvgetstr(), and mvwgetstr())
425 |     inchstr()  (and winchstr(), mvinchstr(), and mvwinchstr())
426 |     instr()    (and winstr(), mvinstr(), and mvwinstr())
427 |

are subject to buffer overflow attack. This is because you pass 428 | in the buffer to be filled in, which has to be of finite length. 429 | But in this Lua module, a buffer is assigned automatically 430 | and the function returns the string, so there is no security issue. 431 | You may still use the alternate functions:

432 |
   s = stdscr:getnstr()
433 |    s = stdscr:inchnstr()
434 |    s = stdscr:innstr()
435 |

which take an extra "size of buffer" argument, 436 | in order to impose a maximum length on the string the user may type in.

437 |

Some of the C functions beginning with "no" do not exist in Lua. 438 | You should use curses.nl(0) and curses.nl(1) 439 | instead of nonl() and nl(), 440 | and likewise curses.echo(0) and curses.echo(1) 441 | instead of noecho() and echo() . 442 |

443 | In this Lua module the stdscr:getch() function always returns an 444 | integer. In C, a single character is an integer, but in Lua 445 | (and Perl) a single character is a short string. 446 | The Perl Curses 447 | function getch() returns a char if it was a char, 448 | and a number if it was a constant; to get this behaviour in Lua 449 | you have to convert explicitly, e.g.:
450 |   if c < 256 then c = string.char(c) end 451 |

452 | Some Lua functions take a different set of parameters 453 | than their C counterparts; for example, you should 454 | use str = stdscr.getstr() and y, x = stdscr.getyx() instead 455 | of getstr(str) and getyx(y, x), 456 | and likewise 457 | for getbegyx 458 | and getmaxyx 459 | and getparyx 460 | and pair_content. 461 | The Perl Curses module now uses the C-compatible parameters, 462 | so be aware of this difference when translating code from Perl into Lua, 463 | as well as from C into Lua. 464 |

465 | Many curses functions have variants starting with the prefixes 466 | w-, mv-, and/or wmv-. 467 | These variants differ only in the explicit addition of a window, 468 | or by the addition of two coordinates 469 | that are used to move the cursor first. 470 | For example, addch() has three other 471 | variants: waddch(), mvaddch(), 472 | and mvwaddch(). 473 | The Perl Curses module combines these variants into one 474 | "Unified Function" 475 | which detects how many arguments it has and behaves accordingly. 476 | But with this Lua module you must always specify the window 477 | (because it is the Object) 478 | e.g.: stdscr:addch(), 479 | and so the mv- variant is retained. 480 | If you are translating Perl code into Lua you may wish to use 481 | some wrapper functions. 482 |

483 |

INSTALLATION

484 |
485 |   luarocks install lcurses
486 |

487 |

AUTHOR

488 |

lcurses was written by   Reuben Thomas   489 | 490 | http://github.com/rrthomas/lcurses
491 | This documentation was created by 492 | a script 493 | written by 494 | Peter Billam. 495 |

496 |

SEE ALSO

497 |
http://github.com/rrthomas/lcurses
498 | http://luaforge.net/projects/lcurses/
499 | http://luarocks.org/repositories/rocks/index.html#lcurses
500 | http://luaforge.net/frs/download.php/4823/lcurses-6.tar.gz
501 | http://git.savannah.gnu.org/cgit/zile.git/tree/src/term_curses.lua?h=lua
502 | http://search.cpan.org/perldoc?Curses
503 | man ncurses
504 | man curses
505 | 506 | 507 | 508 | 509 | -------------------------------------------------------------------------------- /strlcpy.c: -------------------------------------------------------------------------------- 1 | /* strlcpy.c -- size-bounded string copying and concatenation 2 | 3 | Copyright (C) 2004 Free Software Foundation, Inc. 4 | Written by Bob Friesenhahn, 2004 5 | 6 | NOTE: The canonical source of this file is maintained with the 7 | GNU Libtool package. Report bugs to bug-libtool@gnu.org. 8 | 9 | GNU Libltdl is free software; you can redistribute it and/or 10 | modify it under the terms of the GNU Lesser General Public 11 | License as published by the Free Software Foundation; either 12 | version 2 of the License, or (at your option) any later version. 13 | 14 | As a special exception to the GNU Lesser General Public License, 15 | if you distribute this file as part of a program or library that 16 | is built using GNU Libtool, you may include this file under the 17 | same distribution terms that you use for the rest of that program. 18 | 19 | GNU Libltdl is distributed in the hope that it will be useful, 20 | but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22 | GNU Lesser General Public License for more details. 23 | 24 | You should have received a copy of the GNU Lesser General Public 25 | License along with GNU Libltdl; see the file COPYING.LIB. If not, a 26 | copy can be downloaded from http://www.gnu.org/licenses/lgpl.html, 27 | or obtained by writing to the Free Software Foundation, Inc., 28 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 29 | */ 30 | 31 | #include 32 | #include 33 | 34 | /* 35 | lt_strlcpy copies up to dstsize - 1 characters from the NULL-terminated 36 | string src to dst, NULL-terminating the result. The total length of 37 | the string which would have been created given sufficient buffer 38 | size (may be longer than dstsize) is returned. This function 39 | substitutes for strlcpy() which is available under OpenBSD, FreeBSD 40 | and Solaris 9. 41 | 42 | Buffer overflow can be checked as follows: 43 | 44 | if (lt_strlcpy(dst, src, dstsize) >= dstsize) 45 | return -1; 46 | */ 47 | #if !defined(HAVE_STRLCPY) 48 | # define strlcpy rpl_strlcpy 49 | static size_t strlcpy(char *dst, const char *src, const size_t dstsize); 50 | 51 | static size_t 52 | strlcpy(char *dst, const char *src, const size_t dstsize) 53 | { 54 | size_t length=0; 55 | char *p; 56 | const char *q; 57 | 58 | assert(dst != NULL); 59 | assert(src != (const char *) NULL); 60 | assert(dstsize >= 1); 61 | 62 | /* 63 | Copy src to dst within bounds of size-1. 64 | */ 65 | for ( p=dst, q=src, length=0 ; 66 | (*q != 0) && (length < dstsize-1) ; 67 | length++, p++, q++ ) 68 | *p = *q; 69 | 70 | dst[length]='\0'; 71 | 72 | /* 73 | Add remaining length of src to length. 74 | */ 75 | while (*q++) 76 | length++; 77 | 78 | return length; 79 | } 80 | #endif /* !defined(HAVE_STRLCPY) */ 81 | -------------------------------------------------------------------------------- /tests.lua: -------------------------------------------------------------------------------- 1 | -- Trivial test that we can load the module 2 | require "curses" 3 | --------------------------------------------------------------------------------