Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Clean up the indentation mess

Use 'indent'. Not perfect, but at least consistent.

Signed-off-by: Steve Bennett <steveb@workware.net.au>
  • Loading branch information...
commit cbc635e8f4de48408768053a976dc7bd7177ba7a 1 parent 75af5a8
@msteveb authored
Showing with 5,124 additions and 4,754 deletions.
  1. +34 −0 .indent.pro
  2. +9 −16 Makefile.in
  3. +2 −22 README
  4. 0  doc/Sqlite-Extension.txt → README.sqlite
  5. +0 −1  STYLE
  6. +3 −13 config.h.in → autoconf.h.in
  7. +45 −167 configure
  8. +8 −35 configure.ac
  9. 0  doc/AIO-Extension.txt
  10. 0  doc/Embedder-HOWTO.txt
  11. +0 −9 doc/Makefile
  12. 0  doc/Tcl.html.supplied
  13. +0 −98 doc/jim_man.txt
  14. +0 −55 doc/make-index
  15. +213 −195 jim-aio.c
  16. +5 −6 jim-array.c
  17. +8 −7 jim-bio.c
  18. +4 −6 jim-clock.c
  19. +90 −85 jim-eventloop.c
  20. +114 −105 jim-exec.c
  21. +65 −46 jim-file.c
  22. +13 −11 jim-interactive.c
  23. +61 −0 jim-load-static-exts.c
  24. +18 −16 jim-load.c
  25. +247 −293 jim-nvp.c
  26. +42 −44 jim-package.c
  27. +9 −12 jim-posix.c
  28. +13 −16 jim-readdir.c
  29. +8 −10 jim-readline.c
  30. +40 −26 jim-regexp.c
  31. +58 −61 jim-sdl.c
  32. +10 −9 jim-signal.c
  33. +64 −61 jim-sqlite.c
  34. +82 −78 jim-sqlite3.c
  35. +43 −26 jim-subcmd.c
  36. +40 −36 jim-syslog.c
  37. +15 −13 jim-win32compat.c
  38. +3,444 −2,919 jim.c
  39. +3 −5 jim.h.in → jim.h
  40. +166 −41 {doc → }/jim_tcl.txt
  41. +23 −15 jimsh.c
  42. +1 −10 make-c-ext.sh
  43. +0 −18 make-jim-load-extensions.sh
  44. +0 −18 make-load-extensions.sh
  45. +25 −8 rlprompt.tcl
  46. BIN  tcltests/test.bin
  47. +40 −0 tcltests/test_signal2.tcl
  48. +16 −0 tcltests/test_trysignal.tcl
  49. +2 −14 tests/expr-old.test
  50. +0 −124 tests/filecopy.test
  51. +37 −0 tests/infoframe.test
  52. +4 −4 tree.tcl
View
34 .indent.pro
@@ -0,0 +1,34 @@
+-ncs
+-npcs
+-nut
+-bad
+-bap
+-bbb
+-nbc
+-nlp
+-ci4
+-br
+-ncdb
+-nce
+-cli4
+-d0
+-di1
+-nfc1
+-i4
+-l100
+-npsl
+-TJim_Stack
+-TJim_HashEntry
+-TJim_HashTableType
+-TJim_HashTable
+-TJim_HashTableIterator
+-TJim_Obj
+-TJim_ObjType
+-TJim_CallFrame
+-TJim_Var
+-TJim_Cmd
+-TJim_PrngState
+-TJim_Interp
+-TJim_Reference
+-TParseToken
+-TParseTokenList
View
25 Makefile.in
@@ -1,5 +1,4 @@
RANLIB ?= ranlib
-SIZE ?= size
# Configuration
@@ -15,16 +14,14 @@ CFLAGS += -DTCL_LIBRARY=\"/lib/tcl6\"
CFLAGS += -DJIM_TCL_COMPAT -DJIM_REFERENCES
-CFLAGS += -DHAVE_CONFIG_H -Wall -g $(OPTIM) -I@SRCDIR@ -I. @EXTRA_CFLAGS@
+CFLAGS += -Wall -g $(OPTIM) -I@SRCDIR@ -I. @EXTRA_CFLAGS@
VPATH := @SRCDIR@
ifeq ($(jim_libtype),static)
# Emulate tinytcl
LIBJIM := libtcl6.a
else
- #LIBJIM := libjim_shared.so
LIBJIM := libtcl6.so
- #CFLAGS += -fPIC
CFLAGS += $(SH_CFLAGS)
endif
@@ -41,18 +38,16 @@ EXTENSIONS_OBJS := $(patsubst %,jim-%.o,$(EXTENSIONS))
# Create C extensions from pure Tcl extensions
jim-%.c: %.tcl
echo $@ >>.clean
- sh @SRCDIR@/make-c-ext.sh $@ $<
+ sh @SRCDIR@/make-c-ext.sh $< >$@
-OBJS += load_extensions.o
+OBJS += jim-load-static-exts.o
-TARGETS += $(LIBJIM) jimsh
+all: jimsh
-all: $(TARGETS)
- if [ -d doc ]; then $(MAKE) -C doc all; fi
+docs: Tcl.html
jimsh: $(LIBJIM) jimsh.o
$(CC) $(LDFLAGS) -o $@ jimsh.o $(LIBJIM) $(LDLIBS) @LIBDL@ -lm
- $(SIZE) $@
ifeq ($(jim_libtype),static)
$(LIBJIM): $(OBJS) $(EXTENSIONS_OBJS)
@@ -63,15 +58,13 @@ $(LIBJIM): $(OBJS) $(EXTENSIONS_OBJS)
$(CC) $(LDFLAGS) $(SH_LDFLAGS) -o $@ $^
endif
-load_extensions.c: @SRCDIR@/make-jim-load-extensions.sh
- sh @SRCDIR@/make-jim-load-extensions.sh $@ $(EXTENSIONS)
-
-install:
+Tcl.html: jim_tcl.txt
+ asciidoc -o $@ -d manpage $^
clean:
- rm -f *.o lib*.a $(TARGETS) load_extensions.c doc/Tcl.html
+ rm -f *.o lib*.a jimsh Tcl.html
if [ -f .clean ]; then rm -f `cat .clean` .clean; fi
distclean: clean
- rm -f jim.h Makefile config.status config.log
+ rm -f autoconf.h Makefile config.status config.log
rm -rf autom4te.cache
View
24 README
@@ -116,28 +116,8 @@ Jim was tested under Linux, FreeBSD, MacosX, Windows XP (mingw, MVC).
To compile jim itself try:
- make jim
-
-On systems other than GNU/Linux, you may have to compile without "-ldl"
-because it's not needed, but will cause a compilation error (no configure for
-now... applications embedding Jim will probably have one already).
-
-In order to avoid to link against 'dl' just use:
-
- make LIBS="" jim
-
-For instructions about how to compile extensions just try 'make'
-and see the available options. Check also the next section of this file.
-
---------------------------------------------------------------------------------
-HOW TO COMPILE IN SYSTEMS WITH JUST ANSI-C SUPPORT
---------------------------------------------------------------------------------
-
-Try:
-
- make LIBS="" DEFS="-DJIM_ANSIC" jim
-
-This should compile Jim almost everywhere there is a decent ANSI-C compiler.
+ ./configure
+ make
--------------------------------------------------------------------------------
EXTENSIONS
View
0  doc/Sqlite-Extension.txt → README.sqlite
File renamed without changes
View
1  STYLE
@@ -62,4 +62,3 @@ C FEATURES
Only C89 ANSI C is allowed. C99 features can't be used currently.
GCC extensions are not allowed.
-
View
16 config.h.in → autoconf.h.in
@@ -1,12 +1,8 @@
-/* config.h.in. Generated from configure.ac by autoheader. */
+/* autoconf.h.in. Generated from configure.ac by autoheader. */
/* Define to 1 if you have the `backtrace' function. */
#undef HAVE_BACKTRACE
-/* Define to 1 if you have the declaration of `mkdir', and to 0 if you don't.
- */
-#undef HAVE_DECL_MKDIR
-
/* Define to 1 if you have the `fork' function. */
#undef HAVE_FORK
@@ -28,8 +24,8 @@
/* Define to 1 if you have the `mkstemp' function. */
#undef HAVE_MKSTEMP
-/* Define to 1 if you have the `regcomp' function. */
-#undef HAVE_REGCOMP
+/* Define to 1 if you have the `realpath' function. */
+#undef HAVE_REALPATH
/* Define to 1 if you have the <stdint.h> header file. */
#undef HAVE_STDINT_H
@@ -49,9 +45,6 @@
/* Define to 1 if you have the `sysinfo' function. */
#undef HAVE_SYSINFO
-/* Define to 1 if you have the `syslog' function. */
-#undef HAVE_SYSLOG
-
/* Define to 1 if you have the <sys/stat.h> header file. */
#undef HAVE_SYS_STAT_H
@@ -67,9 +60,6 @@
/* Define to 1 if you have the `vfork' function. */
#undef HAVE_VFORK
-/* Define if mkdir(2) takes a single argument (no mode) */
-#undef MKDIR_ONE_ARG
-
/* Define to the address where bug reports for this package should be sent. */
#undef PACKAGE_BUGREPORT
View
212 configure
@@ -1,6 +1,6 @@
#! /bin/sh
# Guess values for system-dependent variables and create Makefiles.
-# Generated by GNU Autoconf 2.65 for jim 0.62.
+# Generated by GNU Autoconf 2.65 for jim 0.63.
#
# Report bugs to <steveb@workware.net.au>.
#
@@ -552,8 +552,8 @@ MAKEFLAGS=
# Identity of this package.
PACKAGE_NAME='jim'
PACKAGE_TARNAME='jim'
-PACKAGE_VERSION='0.62'
-PACKAGE_STRING='jim 0.62'
+PACKAGE_VERSION='0.63'
+PACKAGE_STRING='jim 0.63'
PACKAGE_BUGREPORT='steveb@workware.net.au'
PACKAGE_URL=''
@@ -595,11 +595,11 @@ ac_includes_default="\
ac_subst_vars='LTLIBOBJS
LIBOBJS
+LIBDL
SRCDIR
EXTRA_CFLAGS
JIM_LIBTYPE
JIM_EXTENSIONS
-LIBDL
SH_LDFLAGS
SH_CFLAGS
host_os
@@ -1218,7 +1218,7 @@ if test "$ac_init_help" = "long"; then
# Omit some internal or obsolete options to make the list less imposing.
# This message is too long to be a string in the A/UX 3.1 sh.
cat <<_ACEOF
-\`configure' configures jim 0.62 to adapt to many kinds of systems.
+\`configure' configures jim 0.63 to adapt to many kinds of systems.
Usage: $0 [OPTION]... [VAR=VALUE]...
@@ -1283,7 +1283,7 @@ fi
if test -n "$ac_init_help"; then
case $ac_init_help in
- short | recursive ) echo "Configuration of jim 0.62:";;
+ short | recursive ) echo "Configuration of jim 0.63:";;
esac
cat <<\_ACEOF
@@ -1291,7 +1291,7 @@ Optional Features:
--disable-option-checking ignore unrecognized --enable/--with options
--disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no)
--enable-FEATURE[=ARG] include FEATURE [ARG=yes]
- --disable-fork do not use fork
+ --disable-fork do not use fork (no exec, etc.)
--enable-math include support for math functions
Optional Packages:
@@ -1376,7 +1376,7 @@ fi
test -n "$ac_init_help" && exit $ac_status
if $ac_init_version; then
cat <<\_ACEOF
-jim configure 0.62
+jim configure 0.63
generated by GNU Autoconf 2.65
Copyright (C) 2009 Free Software Foundation, Inc.
@@ -1704,50 +1704,11 @@ $as_echo "$ac_res" >&6; }
eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;}
} # ac_fn_c_check_func
-
-# ac_fn_c_check_decl LINENO SYMBOL VAR
-# ------------------------------------
-# Tests whether SYMBOL is declared, setting cache variable VAR accordingly.
-ac_fn_c_check_decl ()
-{
- as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
- { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $2 is declared" >&5
-$as_echo_n "checking whether $2 is declared... " >&6; }
-if { as_var=$3; eval "test \"\${$as_var+set}\" = set"; }; then :
- $as_echo_n "(cached) " >&6
-else
- cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h. */
-$4
-int
-main ()
-{
-#ifndef $2
- (void) $2;
-#endif
-
- ;
- return 0;
-}
-_ACEOF
-if ac_fn_c_try_compile "$LINENO"; then :
- eval "$3=yes"
-else
- eval "$3=no"
-fi
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-fi
-eval ac_res=\$$3
- { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
-$as_echo "$ac_res" >&6; }
- eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;}
-
-} # ac_fn_c_check_decl
cat >config.log <<_ACEOF
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.
-It was created by jim $as_me 0.62, which was
+It was created by jim $as_me 0.63, which was
generated by GNU Autoconf 2.65. Invocation command line was
$ $0 $@
@@ -2094,7 +2055,7 @@ ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $
ac_compiler_gnu=$ac_cv_c_compiler_gnu
-ac_config_headers="$ac_config_headers config.h"
+ac_config_headers="$ac_config_headers autoconf.h"
# Checks for programs.
@@ -3333,7 +3294,6 @@ HAVE_LONG_LONG="#define HAVE_LONG_LONG"
fi
-
# Shared library support. Because we don't believe in automake!
ac_aux_dir=
for ac_dir in "$srcdir" "$srcdir/.." "$srcdir/../.."; do
@@ -3448,7 +3408,7 @@ if test "${enable_fork+set}" = set; then :
if test "x$enableval" = "xno" ; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: * disabling fork" >&5
$as_echo "* disabling fork" >&6; }
- EXTRA_CFLAGS="-DHAVE_NO_FORK"
+ EXTRA_CFLAGS="-DJIM_NOFORK"
fi
fi
@@ -3478,8 +3438,30 @@ if test "${with_jim_ext+set}" = set; then :
fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: enabling jim extensions: $jim_extensions" >&5
+$as_echo "enabling jim extensions: $jim_extensions" >&6; }
+JIM_EXTENSIONS=$jim_extensions
+
+for i in $jim_extensions; do
+ EXTRA_CFLAGS="$EXTRA_CFLAGS -Djim_ext_$i"
+done
+
+JIM_LIBTYPE=static
+
+# Check whether --with-jim-shared was given.
+if test "${with_jim_shared+set}" = set; then :
+ withval=$with_jim_shared;
+ if test "x$withval" = "xyes" ; then
+ JIM_LIBTYPE=shared
+ fi
+
+
+fi
+
+JIM_LIBTYPE=$JIM_LIBTYPE
+
-for ac_func in backtrace geteuid lstat mkstemp fork strptime sysinfo ualarm
+for ac_func in ualarm sysinfo lstat fork vfork
do :
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
@@ -3492,45 +3474,24 @@ _ACEOF
fi
done
-
-for ac_func in vfork
+for ac_func in backtrace geteuid mkstemp realpath strptime
do :
- ac_fn_c_check_func "$LINENO" "vfork" "ac_cv_func_vfork"
-if test "x$ac_cv_func_vfork" = x""yes; then :
+ as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
+ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
+eval as_val=\$$as_ac_var
+ if test "x$as_val" = x""yes; then :
cat >>confdefs.h <<_ACEOF
-#define HAVE_VFORK 1
+#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1
_ACEOF
-else
- IGNORE="$IGNORE exec posix signal eventloop"
fi
done
-for ac_func in syslog
-do :
- ac_fn_c_check_func "$LINENO" "syslog" "ac_cv_func_syslog"
-if test "x$ac_cv_func_syslog" = x""yes; then :
- cat >>confdefs.h <<_ACEOF
-#define HAVE_SYSLOG 1
-_ACEOF
-else
- IGNORE="$IGNORE syslog"
-fi
-done
+EXTRA_CFLAGS=$EXTRA_CFLAGS
-for ac_func in regcomp
-do :
- ac_fn_c_check_func "$LINENO" "regcomp" "ac_cv_func_regcomp"
-if test "x$ac_cv_func_regcomp" = x""yes; then :
- cat >>confdefs.h <<_ACEOF
-#define HAVE_REGCOMP 1
-_ACEOF
+SRCDIR=`dirname $0`
-else
- IGNORE="$IGNORE regexp"
-fi
-done
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for dlopen in -ldl" >&5
$as_echo_n "checking for dlopen in -ldl... " >&6; }
@@ -3571,93 +3532,11 @@ $as_echo "$ac_cv_lib_dl_dlopen" >&6; }
if test "x$ac_cv_lib_dl_dlopen" = x""yes; then :
LIBDL=-ldl
-else
- IGNORE="$IGNORE load"
-fi
-
-
-# Does mkdir() include a mode_t argument?
-ac_fn_c_check_decl "$LINENO" "mkdir" "ac_cv_have_decl_mkdir" "$ac_includes_default"
-if test "x$ac_cv_have_decl_mkdir" = x""yes; then :
- ac_have_decl=1
-else
- ac_have_decl=0
-fi
-
-cat >>confdefs.h <<_ACEOF
-#define HAVE_DECL_MKDIR $ac_have_decl
-_ACEOF
-if test $ac_have_decl = 1; then :
- { $as_echo "$as_me:${as_lineno-$LINENO}: checking if mkdir takes 2 arguments" >&5
-$as_echo_n "checking if mkdir takes 2 arguments... " >&6; }
- cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h. */
-#include <sys/stat.h>
- #include <sys/types.h>
-
-int
-main ()
-{
-(void)mkdir("dummy");
- ;
- return 0;
-}
-_ACEOF
-if ac_fn_c_try_compile "$LINENO"; then :
- { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
-$as_echo "no" >&6; }
-
-$as_echo "#define MKDIR_ONE_ARG /**/" >>confdefs.h
-
-
-else
- { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
-$as_echo "yes" >&6; }
-fi
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-
fi
-# Remove extensions in $IGNORE from $jim_extensions
-
-for i in $IGNORE; do
- jim_extensions=`echo "$jim_extensions" | sed -e "s/$i//"`
-done
-
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: enabling jim extensions: $jim_extensions" >&5
-$as_echo "enabling jim extensions: $jim_extensions" >&6; }
-JIM_EXTENSIONS=$jim_extensions
-
-for i in $jim_extensions; do
- EXTRA_CFLAGS="$EXTRA_CFLAGS -Djim_ext_$i"
-done
-
-JIM_LIBTYPE=static
-
-# Check whether --with-jim-shared was given.
-if test "${with_jim_shared+set}" = set; then :
- withval=$with_jim_shared;
- if test "x$withval" = "xyes" ; then
- JIM_LIBTYPE=shared
- fi
-
-
-fi
-
-JIM_LIBTYPE=$JIM_LIBTYPE
-
-
-
-EXTRA_CFLAGS=$EXTRA_CFLAGS
-
-SRCDIR=`dirname $0`
-
-
ac_config_files="$ac_config_files Makefile"
-ac_config_files="$ac_config_files jim.h"
-
cat >confcache <<\_ACEOF
# This file is a shell script that caches the results of configure
# tests run on this system so they can be shared between configure
@@ -4163,7 +4042,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
# report actual input values of CONFIG_FILES etc. instead of their
# values after options handling.
ac_log="
-This file was extended by jim $as_me 0.62, which was
+This file was extended by jim $as_me 0.63, which was
generated by GNU Autoconf 2.65. Invocation command line was
CONFIG_FILES = $CONFIG_FILES
@@ -4225,7 +4104,7 @@ _ACEOF
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
ac_cs_version="\\
-jim config.status 0.62
+jim config.status 0.63
configured by $0, generated by GNU Autoconf 2.65,
with options \\"\$ac_cs_config\\"
@@ -4340,9 +4219,8 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
for ac_config_target in $ac_config_targets
do
case $ac_config_target in
- "config.h") CONFIG_HEADERS="$CONFIG_HEADERS config.h" ;;
+ "autoconf.h") CONFIG_HEADERS="$CONFIG_HEADERS autoconf.h" ;;
"Makefile") CONFIG_FILES="$CONFIG_FILES Makefile" ;;
- "jim.h") CONFIG_FILES="$CONFIG_FILES jim.h" ;;
*) as_fn_error "invalid argument: \`$ac_config_target'" "$LINENO" 5;;
esac
View
43 configure.ac 100644 → 100755
@@ -2,8 +2,8 @@
# Process this file with autoconf to produce a configure script.
AC_PREREQ(2.57)
-AC_INIT([jim], [0.62], [steveb@workware.net.au])
-AC_CONFIG_HEADERS([config.h])
+AC_INIT([jim], [0.63], [steveb@workware.net.au])
+AC_CONFIG_HEADER(autoconf.h)
# Checks for programs.
AC_PROG_CC
@@ -12,7 +12,6 @@ AC_PROG_MAKE_SET
# Checks for types
AC_CHECK_TYPES(long long,AC_SUBST(HAVE_LONG_LONG,["#define HAVE_LONG_LONG"]))
-
# Shared library support. Because we don't believe in automake!
AC_CANONICAL_HOST
case $host in
@@ -25,11 +24,11 @@ case $host in
esac
AC_ARG_ENABLE(fork,
- [ --disable-fork do not use fork],
+ [ --disable-fork do not use fork (no exec, etc.)],
[
if test "x$enableval" = "xno" ; then
AC_MSG_RESULT(* disabling fork)
- EXTRA_CFLAGS="-DHAVE_NO_FORK"
+ EXTRA_CFLAGS="-DJIM_NOFORK"
fi
],
)
@@ -53,35 +52,6 @@ AC_ARG_WITH(jim-ext,
fi
]
)
-
-AC_CHECK_FUNCS([backtrace geteuid lstat mkstemp fork strptime sysinfo ualarm])
-
-AC_CHECK_FUNCS(vfork,,IGNORE="$IGNORE exec posix signal eventloop")
-AC_CHECK_FUNCS(syslog,,IGNORE="$IGNORE syslog")
-AC_CHECK_FUNCS(regcomp,,IGNORE="$IGNORE regexp")
-AC_CHECK_LIB(dl, dlopen, AC_SUBST(LIBDL,-ldl), IGNORE="$IGNORE load")
-
-# Does mkdir() include a mode_t argument?
-AC_CHECK_DECLS(mkdir,
- [AC_MSG_CHECKING(if mkdir takes 2 arguments)
- AC_TRY_COMPILE(
- [#include <sys/stat.h>
- #include <sys/types.h>
- ],
- [(void)mkdir("dummy");],
- [AC_MSG_RESULT(no)
- AC_DEFINE(MKDIR_ONE_ARG,[],[Define if mkdir(2) takes a single argument (no mode)])
- ],
- [AC_MSG_RESULT(yes)],
- )]
-)
-
-# Remove extensions in $IGNORE from $jim_extensions
-
-for i in $IGNORE; do
- jim_extensions=`echo "$jim_extensions" | sed -e "s/$i//"`
-done
-
AC_MSG_RESULT(enabling jim extensions: $jim_extensions)
AC_SUBST(JIM_EXTENSIONS,$jim_extensions)
for i in $jim_extensions; do
@@ -99,10 +69,13 @@ AC_ARG_WITH(jim-shared,
)
AC_SUBST(JIM_LIBTYPE,$JIM_LIBTYPE)
+AC_CHECK_FUNCS([ualarm sysinfo lstat fork vfork])
+AC_CHECK_FUNCS([backtrace geteuid mkstemp realpath strptime])
AC_SUBST(EXTRA_CFLAGS,$EXTRA_CFLAGS)
AC_SUBST(SRCDIR,`dirname $0`)
+AC_CHECK_LIB(dl, dlopen,AC_SUBST(LIBDL,-ldl))
+
AC_CONFIG_FILES([Makefile])
-AC_CONFIG_FILES([jim.h])
AC_OUTPUT
View
0  doc/AIO-Extension.txt
No changes.
View
0  doc/Embedder-HOWTO.txt
No changes.
View
9 doc/Makefile
@@ -1,9 +0,0 @@
-TCLSH := $(shell which jimsh)
-ifeq ($(TCLSH),)
-TCLSH := $(shell which tclsh)
-endif
-
-all: Tcl.html
-
-Tcl.html: jim_tcl.txt make-index
- $(TCLSH) make-index < jim_tcl.txt | asciidoc -o $@ -d manpage -
View
0  doc/Tcl.html.supplied
No changes.
View
98 doc/jim_man.txt
@@ -1,98 +0,0 @@
-Jim(n)
-======
-
-NAME
-----
-Jim - a better Tcl
-
-SYNOPSIS
---------
-
- cc <source> -ltcl6
-
-or
-
- jimsh <script>
-
-INTRODUCTION
-------------
-# what: jim commands, description, points to ponder
-
-jim
- set var [value]
-
- dict
-
- array [get | set ]
- set $array($elem) $val
- the array command and array syntax $array($elem) is
- an wrapper around dict!
-
-
-package eventloop
- after time/ms script
- the script is mandatory! a blocking wait is not implemented ( good!? )
- returns event_handle
- open: after cancel and remaining time query. ( stubs in C exist UK)
-
- vwait variable
- work the eventloop until variable is accessed.
- currently works only on change of variable content!!
- returns ?variable value?
-
-package aio
- aio.open
- returns handle ?aio.file<nnn>?
-
- aio.socket <socketspec> <serverspec>|<remotehostspec>
- socketspec may be stream, stream.server ( TODO : dgram , domain, ..... )
- serverspec may be [ANY|<InterfaceIPorName>]:<port|servicename>
- remotehostspec may be <hostIPorName>:<port|servicename>
- returns handle ?aio.socket<nnn>? | aio.
-
- $aio.handle
- close
- tell
- seek
- gets
- read
- write
- ndelay [1|0]
- readable [ {} | <readable event script> [ <eof event script> ] ]
- noargs: return the scripts for readable event, optional eof event script.
- returns {} on not setup
- [ list <readable script> <eof script> ]
- arg {} : remove event
- arg <readable script> : setup script or read event, fold eof into this script
- arg <readable script> <eof script> same as above, eof is handled separately.
-
- writable
- same for writable, no eof though
- onexception
- same for out-of-band data
-
- accept
- applys only to server sockets and should be used in a fileevent.
- returns a new socket handle for the accepted connection.
-
-
-package posix
- signal <signame> [ <sigaction> ]
- tell signal action for signal $signame or if given set action to $sigaction
- $sigaction can be either default, ignore , debug or ( TODO: an action script
- that works like a fileevent )
- in all cases the previous action is returned.
-
- sleep <seconds>
- sleep number of seconds
-
- usleep <delay> [ <units> ]
- call usleep/nanosleep with given value
- bare or time as float plus unit ( one of s ms us ns )
-
- pit
- return unix second ( since epoch ) as a float(double)
- Jpit
- return Julian Date in days as a float(double)!
- see http://en.wikipedia.org/wiki/Julian_Date
-
View
55 doc/make-index
@@ -1,55 +0,0 @@
-# vim:se syn=tcl:
-
-while {[gets stdin buf] >= 0} {
- if {$buf eq "@INSERTINDEX@"} {
- break
- }
- puts $buf
-}
-
-# Collect lines and commands
-set lines {}
-set commands {}
-set c 0
-
-while {[gets stdin buf] >= 0} {
- if {[string match "~~*" $buf]} {
- if {[string match "*:*" $prev]} {
- incr c
- set target cmd_$c
- set lines [linsert $lines end-1 "\[\[$target\]\]"]
- } else {
- set target _$prev
- }
- foreach cmd [split $prev ":,"] {
- set cmd [string trim $cmd]
- if {$cmd ne ""} {
- lappend commands [list $cmd $target]
- }
- }
- }
- lappend lines $buf
- set prev $buf
-}
-
-# Output the index
-puts {[frame="none",grid="none"]}
-puts {|=========================}
-set i 0
-foreach command [lsort $commands] {
- foreach {cmd target} $command break
-
- puts -nonewline "|<<$target,$cmd>> "
- incr i
- if {$i % 8 == 0} {
- puts ""
- }
-}
-while {$i % 8 != 0} {
- incr i
- puts -nonewline "| "
-}
-puts ""
-puts {|=========================}
-
-puts [join $lines \n]
View
408 jim-aio.c
@@ -1,3 +1,4 @@
+
/* Jim - A small embeddable Tcl interpreter
*
* Copyright 2005 Salvatore Sanfilippo <antirez@invece.org>
@@ -65,11 +66,12 @@
#define AIO_KEEPOPEN 1
-typedef struct AioFile {
+typedef struct AioFile
+{
FILE *fp;
Jim_Obj *filename;
int type;
- int OpenFlags; /* AIO_KEEPOPEN? keep FILE* */
+ int OpenFlags; /* AIO_KEEPOPEN? keep FILE* */
int fd;
#ifdef O_NDELAY
int flags;
@@ -90,30 +92,36 @@ static int JimParseIpAddress(Jim_Interp *interp, const char *hostport, struct so
{
char a[0x20];
char b[0x20];
- const char* sthost;
- const char* stport;
+ const char *sthost;
+ const char *stport;
unsigned port;
struct hostent *he;
- switch (sscanf(hostport,"%[^:]:%[^:]",a,b)) {
- case 2: sthost = a; stport = b; break;
- case 1: sthost = "0.0.0.0"; stport = a; break;
+ switch (sscanf(hostport, "%[^:]:%[^:]", a, b)) {
+ case 2:
+ sthost = a;
+ stport = b;
+ break;
+ case 1:
+ sthost = "0.0.0.0";
+ stport = a;
+ break;
default:
return JIM_ERR;
}
- if (0 == strncmp(sthost,"ANY",3)) {
+ if (0 == strncmp(sthost, "ANY", 3)) {
sthost = "0.0.0.0";
}
port = atol(stport);
he = gethostbyname(sthost);
if (!he) {
- Jim_SetResultString(interp,hstrerror(h_errno),-1);
+ Jim_SetResultString(interp, hstrerror(h_errno), -1);
return JIM_ERR;
}
- sa->sin_family= he->h_addrtype;
- memcpy(&sa->sin_addr, he->h_addr, he->h_length); /* set address */
+ sa->sin_family = he->h_addrtype;
+ memcpy(&sa->sin_addr, he->h_addr, he->h_length); /* set address */
sa->sin_port = htons(port);
return JIM_OK;
@@ -141,6 +149,7 @@ static void JimAioSetError(Jim_Interp *interp, Jim_Obj *name)
static void JimAioDelProc(Jim_Interp *interp, void *privData)
{
AioFile *af = privData;
+
JIM_NOTUSED(interp);
Jim_DecrRefCount(interp, af->filename);
@@ -151,13 +160,13 @@ static void JimAioDelProc(Jim_Interp *interp, void *privData)
#ifdef jim_ext_eventloop
/* remove existing EventHandlers */
if (af->rEvent) {
- Jim_DeleteFileHandler(interp,af->fp);
+ Jim_DeleteFileHandler(interp, af->fp);
}
if (af->wEvent) {
- Jim_DeleteFileHandler(interp,af->fp);
+ Jim_DeleteFileHandler(interp, af->fp);
}
if (af->eEvent) {
- Jim_DeleteFileHandler(interp,af->fp);
+ Jim_DeleteFileHandler(interp, af->fp);
}
#endif
Jim_Free(af);
@@ -169,24 +178,23 @@ static int aio_cmd_read(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
char buf[AIO_BUF_LEN];
Jim_Obj *objPtr;
int nonewline = 0;
- int neededLen = -1; /* -1 is "read as much as possible" */
+ int neededLen = -1; /* -1 is "read as much as possible" */
- if (argc && Jim_CompareStringImmediate(interp, argv[0], "-nonewline"))
- {
+ if (argc && Jim_CompareStringImmediate(interp, argv[0], "-nonewline")) {
nonewline = 1;
argv++;
argc--;
}
if (argc == 1) {
jim_wide wideValue;
+
if (Jim_GetWide(interp, argv[0], &wideValue) != JIM_OK)
return JIM_ERR;
if (wideValue < 0) {
- Jim_SetResultString(interp, "invalid parameter: negative len",
- -1);
+ Jim_SetResultString(interp, "invalid parameter: negative len", -1);
return JIM_ERR;
}
- neededLen = (int) wideValue;
+ neededLen = (int)wideValue;
}
else if (argc) {
return -1;
@@ -195,10 +203,11 @@ static int aio_cmd_read(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
while (neededLen != 0) {
int retval;
int readlen;
-
+
if (neededLen == -1) {
readlen = AIO_BUF_LEN;
- } else {
+ }
+ else {
readlen = (neededLen > AIO_BUF_LEN ? AIO_BUF_LEN : neededLen);
}
retval = fread(buf, 1, readlen, af->fp);
@@ -208,7 +217,8 @@ static int aio_cmd_read(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
neededLen -= retval;
}
}
- if (retval != readlen) break;
+ if (retval != readlen)
+ break;
}
/* Check for error conditions */
if (ferror(af->fp)) {
@@ -221,7 +231,7 @@ static int aio_cmd_read(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
int len;
const char *s = Jim_GetString(objPtr, &len);
- if (len > 0 && s[len-1] == '\n') {
+ if (len > 0 && s[len - 1] == '\n') {
objPtr->length--;
objPtr->bytes[objPtr->length] = '\0';
}
@@ -239,17 +249,21 @@ static int aio_cmd_gets(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
objPtr = Jim_NewStringObj(interp, NULL, 0);
while (1) {
int more = 0;
- buf[AIO_BUF_LEN-1] = '_';
+
+ buf[AIO_BUF_LEN - 1] = '_';
if (fgets(buf, AIO_BUF_LEN, af->fp) == NULL)
break;
- if (buf[AIO_BUF_LEN-1] == '\0' && buf[AIO_BUF_LEN-2] != '\n')
+ if (buf[AIO_BUF_LEN - 1] == '\0' && buf[AIO_BUF_LEN - 2] != '\n')
more = 1;
if (more) {
- Jim_AppendString(interp, objPtr, buf, AIO_BUF_LEN-1);
- } else {
+ Jim_AppendString(interp, objPtr, buf, AIO_BUF_LEN - 1);
+ }
+ else {
int len = strlen(buf);
+
if (len) {
int hasnl = (buf[len - 1] == '\n');
+
/* strip "\n" */
Jim_AppendString(interp, objPtr, buf, strlen(buf) - hasnl);
}
@@ -367,7 +381,7 @@ static int aio_cmd_sendto(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
wdata = Jim_GetString(argv[0], &wlen);
/* Note that we don't validate the socket type. Rely on sendto() failing if appropriate */
- len = sendto(fileno(af->fp), wdata, wlen, 0, (struct sockaddr*)&sa, sizeof(sa));
+ len = sendto(fileno(af->fp), wdata, wlen, 0, (struct sockaddr *)&sa, sizeof(sa));
if (len < 0) {
JimAioSetError(interp, NULL);
return JIM_ERR;
@@ -384,7 +398,8 @@ static int aio_cmd_accept(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
AioFile *af;
char buf[AIO_CMD_LEN];
long fileId;
- sock = accept(serv_af->fd,(struct sockaddr*)&serv_af->sa,&addrlen);
+
+ sock = accept(serv_af->fd, (struct sockaddr *)&serv_af->sa, &addrlen);
if (sock < 0)
return JIM_ERR;
@@ -396,10 +411,10 @@ static int aio_cmd_accept(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
af->fd = sock;
af->filename = Jim_NewStringObj(interp, "accept", -1);
Jim_IncrRefCount(af->filename);
- af->fp = fdopen(sock,"r+");
+ af->fp = fdopen(sock, "r+");
af->OpenFlags = 0;
#ifdef O_NDELAY
- af->flags = fcntl(af->fd,F_GETFL);
+ af->flags = fcntl(af->fd, F_GETFL);
#endif
af->rEvent = NULL;
af->wEvent = NULL;
@@ -415,6 +430,7 @@ static int aio_cmd_accept(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
static int aio_cmd_flush(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
AioFile *af = Jim_CmdPrivData(interp);
+
if (fflush(af->fp) == EOF) {
JimAioSetError(interp, af->filename);
return JIM_ERR;
@@ -425,6 +441,7 @@ static int aio_cmd_flush(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
static int aio_cmd_eof(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
AioFile *af = Jim_CmdPrivData(interp);
+
Jim_SetResultInt(interp, feof(af->fp));
return JIM_OK;
}
@@ -484,7 +501,7 @@ static int aio_cmd_ndelay(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
return JIM_ERR;
}
if (nb) {
- fmode |= O_NDELAY;
+ fmode |= O_NDELAY;
}
else {
fmode &= ~O_NDELAY;
@@ -508,7 +525,8 @@ static void JimAioFileEventFinalizer(Jim_Interp *interp, void *clientData)
static int JimAioFileEventHandler(Jim_Interp *interp, void *clientData, int mask)
{
Jim_Obj *objPtr = clientData;
- Jim_Obj *scrPtr = NULL ;
+ Jim_Obj *scrPtr = NULL;
+
if (mask == (JIM_EVENT_READABLE | JIM_EVENT_FEOF)) {
Jim_ListIndex(interp, objPtr, 1, &scrPtr, 0);
}
@@ -519,7 +537,8 @@ static int JimAioFileEventHandler(Jim_Interp *interp, void *clientData, int mask
return 0;
}
-static int aio_eventinfo(Jim_Interp *interp, AioFile *af, unsigned mask, Jim_Obj **scriptListObj, Jim_Obj *script1, Jim_Obj *script2)
+static int aio_eventinfo(Jim_Interp *interp, AioFile * af, unsigned mask, Jim_Obj **scriptListObj,
+ Jim_Obj *script1, Jim_Obj *script2)
{
int scriptlen = 0;
@@ -560,10 +579,8 @@ static int aio_eventinfo(Jim_Interp *interp, AioFile *af, unsigned mask, Jim_Obj
Jim_ListAppendElement(interp, *scriptListObj, script2);
}
- Jim_CreateFileHandler(interp, af->fp, mask,
- JimAioFileEventHandler,
- *scriptListObj,
- JimAioFileEventFinalizer);
+ Jim_CreateFileHandler(interp, af->fp, mask,
+ JimAioFileEventHandler, *scriptListObj, JimAioFileEventFinalizer);
return JIM_OK;
}
@@ -600,7 +617,7 @@ static int aio_cmd_onexception(Jim_Interp *interp, int argc, Jim_Obj *const *arg
}
#endif
-static const jim_subcmd_type command_table[] = {
+static const jim_subcmd_type aio_command_table[] = {
{ .cmd = "read",
.args = "?-nonewline? ?len?",
.function = aio_cmd_read,
@@ -703,7 +720,7 @@ static const jim_subcmd_type command_table[] = {
static int JimAioSubCmdProc(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
- return Jim_CallSubCmd(interp, Jim_ParseSubCmd(interp, command_table, argc, argv), argc, argv);
+ return Jim_CallSubCmd(interp, Jim_ParseSubCmd(interp, aio_command_table, argc, argv), argc, argv);
}
static int JimAioOpenCommand(Jim_Interp *interp, int argc,
@@ -732,8 +749,10 @@ static int JimAioOpenCommand(Jim_Interp *interp, int argc,
else if (Jim_CompareStringImmediate(interp, argv[1], "stderr")) {
OpenFlags |= AIO_KEEPOPEN;
fp = stderr;
- } else {
+ }
+ else {
const char *mode = "r";
+
if (argc == 3) {
mode = Jim_GetString(argv[2], NULL);
}
@@ -753,7 +772,7 @@ static int JimAioOpenCommand(Jim_Interp *interp, int argc,
af->fp = fp;
af->fd = fileno(fp);
#ifdef O_NDELAY
- af->flags = fcntl(af->fd,F_GETFL);
+ af->flags = fcntl(af->fd, F_GETFL);
#endif
af->filename = argv[1];
Jim_IncrRefCount(af->filename);
@@ -767,6 +786,7 @@ static int JimAioOpenCommand(Jim_Interp *interp, int argc,
}
#ifndef JIM_ANSIC
+
/**
* Creates a channel for fd.
*
@@ -776,13 +796,15 @@ static int JimAioOpenCommand(Jim_Interp *interp, int argc,
* Creates the command and lappends the name of the command to the current result.
*
*/
-static int JimMakeChannel(Jim_Interp *interp, Jim_Obj *filename, const char *hdlfmt, int fd, const char *mode)
+static int JimMakeChannel(Jim_Interp *interp, Jim_Obj *filename, const char *hdlfmt, int fd,
+ const char *mode)
{
long fileId;
AioFile *af;
char buf[AIO_CMD_LEN];
FILE *fp = fdopen(fd, mode);
+
if (fp == NULL) {
close(fd);
JimAioSetError(interp, NULL);
@@ -813,26 +835,26 @@ static int JimMakeChannel(Jim_Interp *interp, Jim_Obj *filename, const char *hdl
return JIM_OK;
}
-static int JimAioSockCommand(Jim_Interp *interp, int argc,
- Jim_Obj *const *argv)
+static int JimAioSockCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
const char *hdlfmt = "aio.unknown%ld";
const char *socktypes[] = {
- "unix",
- "unix.server",
- "dgram",
- "dgram.server",
- "stream",
+ "unix",
+ "unix.server",
+ "dgram",
+ "dgram.server",
+ "stream",
"stream.server",
"pipe",
NULL
};
- enum {
- SOCK_UNIX,
- SOCK_UNIX_SERV,
- SOCK_DGRAM_CL,
- SOCK_DGRAM_SERV,
- SOCK_STREAM_CL,
+ enum
+ {
+ SOCK_UNIX,
+ SOCK_UNIX_SERV,
+ SOCK_DGRAM_CL,
+ SOCK_DGRAM_SERV,
+ SOCK_STREAM_CL,
SOCK_STREAM_SERV,
SOCK_STREAM_PIPE,
};
@@ -843,15 +865,14 @@ static int JimAioSockCommand(Jim_Interp *interp, int argc,
int on = 1;
const char *mode = "r+";
- if (argc < 2 ) {
-wrongargs:
+ if (argc < 2) {
+ wrongargs:
Jim_WrongNumArgs(interp, 1, argv, "type ?address?");
return JIM_ERR;
}
- if (Jim_GetEnum(interp, argv[1], socktypes, &socktype, "socket type",
- JIM_ERRMSG) != JIM_OK)
- return JIM_ERR;
+ if (Jim_GetEnum(interp, argv[1], socktypes, &socktype, "socket type", JIM_ERRMSG) != JIM_OK)
+ return JIM_ERR;
if (argc == 3) {
hostportarg = Jim_GetString(argv[2], NULL);
@@ -862,157 +883,157 @@ static int JimAioSockCommand(Jim_Interp *interp, int argc,
Jim_SetResultString(interp, "", 0);
- hdlfmt = "aio.sock%ld" ;
+ hdlfmt = "aio.sock%ld";
switch (socktype) {
- case SOCK_DGRAM_CL:
- if (argc == 2) {
- /* No address, so an unconnected dgram socket */
- sock = socket(PF_INET,SOCK_DGRAM,0);
- if (sock < 0) {
- JimAioSetError(interp, NULL);
- return JIM_ERR;
+ case SOCK_DGRAM_CL:
+ if (argc == 2) {
+ /* No address, so an unconnected dgram socket */
+ sock = socket(PF_INET, SOCK_DGRAM, 0);
+ if (sock < 0) {
+ JimAioSetError(interp, NULL);
+ return JIM_ERR;
+ }
+ break;
}
- break;
- }
- /* fall through */
- case SOCK_STREAM_CL:
- {
- struct sockaddr_in sa;
+ /* fall through */
+ case SOCK_STREAM_CL:
+ {
+ struct sockaddr_in sa;
- if (JimParseIpAddress(interp, hostportarg, &sa) != JIM_OK) {
- return JIM_ERR;
- }
- sock = socket(PF_INET,socktype == SOCK_DGRAM_CL ? SOCK_DGRAM : SOCK_STREAM,0);
- if (sock < 0) {
- JimAioSetError(interp, NULL);
- return JIM_ERR;
- }
- res = connect(sock,(struct sockaddr*)&sa,sizeof(sa));
- if (res) {
- JimAioSetError(interp, argv[2]);
- close(sock);
- return JIM_ERR;
+ if (JimParseIpAddress(interp, hostportarg, &sa) != JIM_OK) {
+ return JIM_ERR;
+ }
+ sock = socket(PF_INET, socktype == SOCK_DGRAM_CL ? SOCK_DGRAM : SOCK_STREAM, 0);
+ if (sock < 0) {
+ JimAioSetError(interp, NULL);
+ return JIM_ERR;
+ }
+ res = connect(sock, (struct sockaddr *)&sa, sizeof(sa));
+ if (res) {
+ JimAioSetError(interp, argv[2]);
+ close(sock);
+ return JIM_ERR;
+ }
}
- }
- break;
+ break;
- case SOCK_STREAM_SERV:
- case SOCK_DGRAM_SERV:
- {
- struct sockaddr_in sa;
+ case SOCK_STREAM_SERV:
+ case SOCK_DGRAM_SERV:
+ {
+ struct sockaddr_in sa;
- if (JimParseIpAddress(interp, hostportarg, &sa) != JIM_OK) {
- JimAioSetError(interp, argv[2]);
- return JIM_ERR;
- }
- sock = socket(PF_INET,socktype == SOCK_DGRAM_SERV ? SOCK_DGRAM : SOCK_STREAM,0);
- if (sock < 0) {
- JimAioSetError(interp, NULL);
- return JIM_ERR;
- }
+ if (JimParseIpAddress(interp, hostportarg, &sa) != JIM_OK) {
+ JimAioSetError(interp, argv[2]);
+ return JIM_ERR;
+ }
+ sock = socket(PF_INET, socktype == SOCK_DGRAM_SERV ? SOCK_DGRAM : SOCK_STREAM, 0);
+ if (sock < 0) {
+ JimAioSetError(interp, NULL);
+ return JIM_ERR;
+ }
- /* Enable address reuse */
- setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
+ /* Enable address reuse */
+ setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
- res = bind(sock,(struct sockaddr*)&sa,sizeof(sa));
- if (res) {
- JimAioSetError(interp, argv[2]);
- close(sock);
- return JIM_ERR;
- }
- if (socktype != SOCK_DGRAM_SERV) {
- res = listen(sock,5);
+ res = bind(sock, (struct sockaddr *)&sa, sizeof(sa));
if (res) {
- JimAioSetError(interp, NULL);
+ JimAioSetError(interp, argv[2]);
close(sock);
return JIM_ERR;
}
+ if (socktype != SOCK_DGRAM_SERV) {
+ res = listen(sock, 5);
+ if (res) {
+ JimAioSetError(interp, NULL);
+ close(sock);
+ return JIM_ERR;
+ }
+ }
+ hdlfmt = "aio.socksrv%ld";
}
- hdlfmt = "aio.socksrv%ld" ;
- }
- break;
+ break;
- case SOCK_UNIX:
- {
- struct sockaddr_un sa;
- socklen_t len;
+ case SOCK_UNIX:
+ {
+ struct sockaddr_un sa;
+ socklen_t len;
- if (JimParseDomainAddress(interp, hostportarg, &sa) != JIM_OK) {
- JimAioSetError(interp, argv[2]);
- return JIM_ERR;
- }
- sock = socket(PF_UNIX, SOCK_STREAM,0);
- if (sock < 0) {
- JimAioSetError(interp, NULL);
- return JIM_ERR;
- }
- len = strlen(sa.sun_path) + 1 + sizeof(sa.sun_family);
- res = connect(sock,(struct sockaddr*)&sa,len);
- if (res) {
- JimAioSetError(interp, argv[2]);
- close(sock);
- return JIM_ERR;
+ if (JimParseDomainAddress(interp, hostportarg, &sa) != JIM_OK) {
+ JimAioSetError(interp, argv[2]);
+ return JIM_ERR;
+ }
+ sock = socket(PF_UNIX, SOCK_STREAM, 0);
+ if (sock < 0) {
+ JimAioSetError(interp, NULL);
+ return JIM_ERR;
+ }
+ len = strlen(sa.sun_path) + 1 + sizeof(sa.sun_family);
+ res = connect(sock, (struct sockaddr *)&sa, len);
+ if (res) {
+ JimAioSetError(interp, argv[2]);
+ close(sock);
+ return JIM_ERR;
+ }
+ hdlfmt = "aio.sockunix%ld";
+ break;
}
- hdlfmt = "aio.sockunix%ld" ;
- break;
- }
- case SOCK_UNIX_SERV:
- {
- struct sockaddr_un sa;
- socklen_t len;
+ case SOCK_UNIX_SERV:
+ {
+ struct sockaddr_un sa;
+ socklen_t len;
- if (JimParseDomainAddress(interp, hostportarg, &sa) != JIM_OK) {
- JimAioSetError(interp, argv[2]);
- return JIM_ERR;
- }
- sock = socket(PF_UNIX, SOCK_STREAM,0);
- if (sock < 0) {
- JimAioSetError(interp, NULL);
- return JIM_ERR;
- }
- len = strlen(sa.sun_path) + 1 + sizeof(sa.sun_family);
- res = bind(sock,(struct sockaddr*)&sa,len);
- if (res) {
- JimAioSetError(interp, argv[2]);
- close(sock);
- return JIM_ERR;
- }
- res = listen(sock,5);
- if (res) {
- JimAioSetError(interp, NULL);
- close(sock);
- return JIM_ERR;
+ if (JimParseDomainAddress(interp, hostportarg, &sa) != JIM_OK) {
+ JimAioSetError(interp, argv[2]);
+ return JIM_ERR;
+ }
+ sock = socket(PF_UNIX, SOCK_STREAM, 0);
+ if (sock < 0) {
+ JimAioSetError(interp, NULL);
+ return JIM_ERR;
+ }
+ len = strlen(sa.sun_path) + 1 + sizeof(sa.sun_family);
+ res = bind(sock, (struct sockaddr *)&sa, len);
+ if (res) {
+ JimAioSetError(interp, argv[2]);
+ close(sock);
+ return JIM_ERR;
+ }
+ res = listen(sock, 5);
+ if (res) {
+ JimAioSetError(interp, NULL);
+ close(sock);
+ return JIM_ERR;
+ }
+ hdlfmt = "aio.sockunixsrv%ld";
+ break;
}
- hdlfmt = "aio.sockunixsrv%ld" ;
- break;
- }
- case SOCK_STREAM_PIPE:
- {
- int p[2];
+ case SOCK_STREAM_PIPE:
+ {
+ int p[2];
- if (pipe(p) < 0) {
- JimAioSetError(interp, NULL);
- return JIM_ERR;
- }
+ if (pipe(p) < 0) {
+ JimAioSetError(interp, NULL);
+ return JIM_ERR;
+ }
- hdlfmt = "aio.pipe%ld" ;
- if (JimMakeChannel(interp, argv[1], hdlfmt, p[0], "r") != JIM_OK) {
- close(p[0]);
- close(p[1]);
- JimAioSetError(interp, NULL);
- return JIM_ERR;
+ hdlfmt = "aio.pipe%ld";
+ if (JimMakeChannel(interp, argv[1], hdlfmt, p[0], "r") != JIM_OK) {
+ close(p[0]);
+ close(p[1]);
+ JimAioSetError(interp, NULL);
+ return JIM_ERR;
+ }
+ /* Note, if this fails it will leave p[0] open, but this should never happen */
+ mode = "w";
+ sock = p[1];
}
- /* Note, if this fails it will leave p[0] open, but this should never happen */
- mode = "w";
- sock = p[1];
- }
- break;
+ break;
- default:
- Jim_SetResultString(interp, "Unsupported socket type", -1);
- return JIM_ERR;
+ default:
+ Jim_SetResultString(interp, "Unsupported socket type", -1);
+ return JIM_ERR;
}
return JimMakeChannel(interp, argv[1], hdlfmt, sock, mode);
@@ -1024,7 +1045,7 @@ FILE *Jim_AioFilehandle(Jim_Interp *interp, Jim_Obj *command)
Jim_Cmd *cmdPtr = Jim_GetCommand(interp, command, JIM_ERRMSG);
if (cmdPtr && cmdPtr->cmdProc == JimAioSubCmdProc) {
- return ((AioFile *)cmdPtr->privData)->fp;
+ return ((AioFile *) cmdPtr->privData)->fp;
}
return NULL;
}
@@ -1106,7 +1127,7 @@ static int JimAioPutsCmd(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
static void JimAioTclCompat(Jim_Interp *interp)
{
- static const char *tclcmds[] = { "read", "gets", "flush", "close", "eof", "seek", "tell", 0};
+ static const char *tclcmds[] = { "read", "gets", "flush", "close", "eof", "seek", "tell", 0 };
int i;
for (i = 0; tclcmds[i]; i++) {
@@ -1116,11 +1137,8 @@ static void JimAioTclCompat(Jim_Interp *interp)
}
#endif
-int
-Jim_aioInit(Jim_Interp *interp)
+int Jim_aioInit(Jim_Interp *interp)
{
- if (Jim_PackageProvide(interp, "aio", "1.0", JIM_ERRMSG) != JIM_OK)
- return JIM_ERR;
Jim_CreateCommand(interp, "open", JimAioOpenCommand, NULL, NULL);
#ifndef JIM_ANSIC
Jim_CreateCommand(interp, "socket", JimAioSockCommand, NULL, NULL);
View
11 jim-array.c
@@ -1,3 +1,4 @@
+
/*
* (c) 2008 Steve Bennett <steveb@workware.net.au>
*
@@ -100,7 +101,7 @@ static int array_cmd_get(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
Jim_SetResult(interp, dictObj);
}
else {
- /* REVISIT: We could create a dictionary rather than a list ...*/
+ /* REVISIT: We could create a dictionary rather than a list ... */
/* Only return the matching values */
resultObj = Jim_NewListObj(interp, NULL, 0);
@@ -228,6 +229,7 @@ static int array_cmd_set(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
for (i = 0; i < len && rc == JIM_OK; i += 2) {
Jim_Obj *nameObj;
Jim_Obj *valueObj;
+
Jim_ListIndex(interp, listObj, i, &nameObj, JIM_NONE);
Jim_ListIndex(interp, listObj, i + 1, &valueObj, JIM_NONE);
@@ -237,7 +239,7 @@ static int array_cmd_set(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
return rc;
}
-static const jim_subcmd_type command_table[] = {
+static const jim_subcmd_type array_command_table[] = {
{ .cmd = "exists",
.args = "arrayName",
.function = array_cmd_exists,
@@ -286,9 +288,6 @@ static const jim_subcmd_type command_table[] = {
int Jim_arrayInit(Jim_Interp *interp)
{
- if (Jim_PackageProvide(interp, "array", "1.0", JIM_ERRMSG) != JIM_OK) {
- return JIM_ERR;
- }
- Jim_CreateCommand(interp, "array", Jim_SubCmdProc, (void *)command_table, NULL);
+ Jim_CreateCommand(interp, "array", Jim_SubCmdProc, (void *)array_command_table, NULL);
return JIM_OK;
}
View
15 jim-bio.c
@@ -1,3 +1,4 @@
+
/*
* jim-bio.c
*
@@ -33,6 +34,7 @@
static int hex2char(const char *hex)
{
int value;
+
value = (hex[0] >= 'A' ? ((hex[0] & 0xdf) - 'A') + 10 : (hex[0] - '0'));
value *= 16;
value += (hex[1] >= 'A' ? ((hex[1] & 0xdf) - 'A') + 10 : (hex[1] - '0'));
@@ -70,7 +72,7 @@ static int bio_cmd_read(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
}
fh = Jim_AioFilehandle(interp, argv[0]);
-
+
if (!fh) {
return JIM_ERR;
}
@@ -84,6 +86,7 @@ static int bio_cmd_read(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
/* Read one char at a time */
while (len > 0) {
int ch = fgetc(fh);
+
if (ch == EOF) {
break;
}
@@ -130,7 +133,7 @@ static int bio_cmd_copy(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
FILE *infh = Jim_AioFilehandle(interp, argv[0]);
FILE *outfh = Jim_AioFilehandle(interp, argv[1]);
-
+
if (infh == NULL || outfh == NULL) {
return JIM_ERR;
}
@@ -143,6 +146,7 @@ static int bio_cmd_copy(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
while (count < maxlen) {
int ch = fgetc(infh);
+
if (ch == EOF || fputc(ch, outfh) == EOF) {
break;
}
@@ -218,7 +222,7 @@ static int bio_cmd_write(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
return JIM_OK;
}
-static const jim_subcmd_type command_table[] = {
+static const jim_subcmd_type bio_command_table[] = {
{ .cmd = "read",
.function = bio_cmd_read,
.args = "?-hex? fd var numbytes",
@@ -246,9 +250,6 @@ static const jim_subcmd_type command_table[] = {
int
Jim_bioInit(Jim_Interp *interp)
{
- if (Jim_PackageProvide(interp, "bio", "1.0", JIM_ERRMSG) != JIM_OK) {
- return JIM_ERR;
- }
- Jim_CreateCommand(interp, "bio", Jim_SubCmdProc, (void *)command_table, NULL);
+ Jim_CreateCommand(interp, "bio", Jim_SubCmdProc, (void *)bio_command_table, NULL);
return JIM_OK;
}
View
10 jim-clock.c
@@ -1,3 +1,4 @@
+
/*
* tcl_clock.c
*
@@ -50,7 +51,7 @@ static int clock_cmd_scan(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
char *pt;
struct tm tm;
time_t now = time(0);
-
+
if (!Jim_CompareStringImmediate(interp, argv[1], "-format")) {
return -1;
}
@@ -78,7 +79,7 @@ static int clock_cmd_seconds(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
return JIM_OK;
}
-static const jim_subcmd_type command_table[] = {
+static const jim_subcmd_type clock_command_table[] = {
{ .cmd = "seconds",
.function = clock_cmd_seconds,
.minargs = 0,
@@ -106,9 +107,6 @@ static const jim_subcmd_type command_table[] = {
int Jim_clockInit(Jim_Interp *interp)
{
- if (Jim_PackageProvide(interp, "clock", "1.0", JIM_ERRMSG) != JIM_OK) {
- return JIM_ERR;
- }
- Jim_CreateCommand(interp, "clock", Jim_SubCmdProc, (void *)command_table, NULL);
+ Jim_CreateCommand(interp, "clock", Jim_SubCmdProc, (void *)clock_command_table, NULL);
return JIM_OK;
}
View
175 jim-eventloop.c
@@ -1,3 +1,4 @@
+
/* Jim - A small embeddable Tcl interpreter
*
* Copyright 2005 Salvatore Sanfilippo <antirez@invece.org>
@@ -38,6 +39,7 @@
* are those of the authors and should not be interpreted as representing
* official policies, either expressed or implied, of the Jim Tcl Project.
**/
+
/* TODO:
*
* - to really use flags in Jim_ProcessEvents()
@@ -55,12 +57,14 @@
#include <unistd.h>
#include <sys/select.h>
#include <errno.h>
+
/* --- */
/* File event structure */
-typedef struct Jim_FileEvent {
+typedef struct Jim_FileEvent
+{
FILE *handle;
- int mask; /* one of JIM_EVENT_(READABLE|WRITABLE|EXCEPTION) */
+ int mask; /* one of JIM_EVENT_(READABLE|WRITABLE|EXCEPTION) */
Jim_FileProc *fileProc;
Jim_EventFinalizerProc *finalizerProc;
void *clientData;
@@ -68,12 +72,13 @@ typedef struct Jim_FileEvent {
} Jim_FileEvent;
/* Time event structure */
-typedef struct Jim_TimeEvent {
- jim_wide id; /* time event identifier. */
- int mode; /* restart, repetitive .. UK */
- long initialms; /* initial relativ timer value UK */
- long when_sec; /* seconds */
- long when_ms; /* milliseconds */
+typedef struct Jim_TimeEvent
+{
+ jim_wide id; /* time event identifier. */
+ int mode; /* restart, repetitive .. UK */
+ long initialms; /* initial relativ timer value UK */
+ long when_sec; /* seconds */
+ long when_ms; /* milliseconds */
Jim_TimeProc *timeProc;
Jim_EventFinalizerProc *finalizerProc;
void *clientData;
@@ -81,15 +86,15 @@ typedef struct Jim_TimeEvent {
} Jim_TimeEvent;
/* Per-interp stucture containing the state of the event loop */
-typedef struct Jim_EventLoop {
+typedef struct Jim_EventLoop
+{
jim_wide timeEventNextId;
Jim_FileEvent *fileEventHead;
Jim_TimeEvent *timeEventHead;
} Jim_EventLoop;
-void Jim_CreateFileHandler(Jim_Interp *interp, FILE *handle, int mask,
- Jim_FileProc *proc, void *clientData,
- Jim_EventFinalizerProc *finalizerProc)
+void Jim_CreateFileHandler(Jim_Interp *interp, FILE * handle, int mask,
+ Jim_FileProc * proc, void *clientData, Jim_EventFinalizerProc * finalizerProc)
{
Jim_FileEvent *fe;
Jim_EventLoop *eventLoop = Jim_GetAssocData(interp, "eventloop");
@@ -104,13 +109,13 @@ void Jim_CreateFileHandler(Jim_Interp *interp, FILE *handle, int mask,
eventLoop->fileEventHead = fe;
}
-void Jim_DeleteFileHandler(Jim_Interp *interp, FILE *handle)
+void Jim_DeleteFileHandler(Jim_Interp *interp, FILE * handle)
{
Jim_FileEvent *fe, *prev = NULL;
Jim_EventLoop *eventLoop = Jim_GetAssocData(interp, "eventloop");
fe = eventLoop->fileEventHead;
- while(fe) {
+ while (fe) {
if (fe->handle == handle) {
if (prev == NULL)
eventLoop->fileEventHead = fe->next;
@@ -134,12 +139,11 @@ static void JimGetTime(long *seconds, long *milliseconds)
gettimeofday(&tv, NULL);
*seconds = tv.tv_sec;
- *milliseconds = tv.tv_usec/1000;
+ *milliseconds = tv.tv_usec / 1000;
}
jim_wide Jim_CreateTimeHandler(Jim_Interp *interp, jim_wide milliseconds,
- Jim_TimeProc *proc, void *clientData,
- Jim_EventFinalizerProc *finalizerProc)
+ Jim_TimeProc * proc, void *clientData, Jim_EventFinalizerProc * finalizerProc)
{
Jim_EventLoop *eventLoop = Jim_GetAssocData(interp, "eventloop");
jim_wide id = eventLoop->timeEventNextId++;
@@ -152,10 +156,10 @@ jim_wide Jim_CreateTimeHandler(Jim_Interp *interp, jim_wide milliseconds,
te->id = id;
te->mode = 0;
te->initialms = milliseconds;
- te->when_sec = cur_sec + milliseconds/1000;
- te->when_ms = cur_ms + milliseconds%1000;
+ te->when_sec = cur_sec + milliseconds / 1000;
+ te->when_ms = cur_ms + milliseconds % 1000;
if (te->when_ms >= 1000) {
- te->when_sec ++;
+ te->when_sec++;
te->when_ms -= 1000;
}
te->timeProc = proc;
@@ -171,19 +175,19 @@ jim_wide Jim_DeleteTimeHandler(Jim_Interp *interp, jim_wide id)
Jim_TimeEvent *te, *prev = NULL;
Jim_EventLoop *eventLoop = Jim_GetAssocData(interp, "eventloop");
long cur_sec, cur_ms;
- jim_wide remain ;
+ jim_wide remain;
JimGetTime(&cur_sec, &cur_ms);
te = eventLoop->timeEventHead;
if (id >= eventLoop->timeEventNextId) {
- return -2; /* wrong event ID */
+ return -2; /* wrong event ID */
}
- while(te) {
+ while (te) {
if (te->id == id) {
- remain = (te->when_sec - cur_sec) * 1000;
- remain += (te->when_ms - cur_ms) ;
- remain = (remain < 0) ? 0 : remain ;
+ remain = (te->when_sec - cur_sec) * 1000;
+ remain += (te->when_ms - cur_ms);
+ remain = (remain < 0) ? 0 : remain;
if (prev == NULL)
eventLoop->timeEventHead = te->next;
@@ -197,22 +201,21 @@ jim_wide Jim_DeleteTimeHandler(Jim_Interp *interp, jim_wide id)
prev = te;
te = te->next;
}
- return -1; /* NO event with the specified ID found */
+ return -1; /* NO event with the specified ID found */
}
/* Search the first timer to fire.
* This operation is useful to know how many time the select can be
* put in sleep without to delay any event.
* If there are no timers NULL is returned. */
-static Jim_TimeEvent *JimSearchNearestTimer(Jim_EventLoop *eventLoop)
+static Jim_TimeEvent *JimSearchNearestTimer(Jim_EventLoop * eventLoop)
{
Jim_TimeEvent *te = eventLoop->timeEventHead;
Jim_TimeEvent *nearest = NULL;
while (te) {
if (!nearest || te->when_sec < nearest->when_sec ||
- (te->when_sec == nearest->when_sec &&
- te->when_ms < nearest->when_ms))
+ (te->when_sec == nearest->when_sec && te->when_ms < nearest->when_ms))
nearest = te;
te = te->next;
}
@@ -242,6 +245,7 @@ int Jim_ProcessEvents(Jim_Interp *interp, int flags)
Jim_FileEvent *fe = eventLoop->fileEventHead;
Jim_TimeEvent *te;
jim_wide maxId;
+
JIM_NOTUSED(flags);
FD_ZERO(&rfds);
@@ -252,11 +256,14 @@ int Jim_ProcessEvents(Jim_Interp *interp, int flags)
while (fe != NULL) {
int fd = fileno(fe->handle);
- if (fe->mask & JIM_EVENT_READABLE)
- FD_SET(fd, &rfds);
- if (fe->mask & JIM_EVENT_WRITABLE) FD_SET(fd, &wfds);
- if (fe->mask & JIM_EVENT_EXCEPTION) FD_SET(fd, &efds);
- if (maxfd < fd) maxfd = fd;
+ if (fe->mask & JIM_EVENT_READABLE)
+ FD_SET(fd, &rfds);
+ if (fe->mask & JIM_EVENT_WRITABLE)
+ FD_SET(fd, &wfds);
+ if (fe->mask & JIM_EVENT_EXCEPTION)
+ FD_SET(fd, &efds);
+ if (maxfd < fd)
+ maxfd = fd;
numfd++;
fe = fe->next;
}
@@ -280,35 +287,36 @@ int Jim_ProcessEvents(Jim_Interp *interp, int flags)
JimGetTime(&now_sec, &now_ms);
tvp = &tv;
dt = 1000 * (shortest->when_sec - now_sec);
- dt += ( shortest->when_ms - now_ms);
+ dt += (shortest->when_ms - now_ms);
if (dt < 0) {
dt = 1;
}
- tvp->tv_sec = dt / 1000;
+ tvp->tv_sec = dt / 1000;
tvp->tv_usec = dt % 1000;
- } else {
- tvp = NULL; /* wait forever */
+ }
+ else {
+ tvp = NULL; /* wait forever */
}
- retval = select(maxfd+1, &rfds, &wfds, &efds, tvp);
+ retval = select(maxfd + 1, &rfds, &wfds, &efds, tvp);
if (retval < 0) {
/* XXX: Consider errno? EINTR? */
- } else if (retval > 0) {
+ }
+ else if (retval > 0) {
fe = eventLoop->fileEventHead;
- while(fe != NULL) {
+ while (fe != NULL) {
int fd = fileno(fe->handle);
if ((fe->mask & JIM_EVENT_READABLE && FD_ISSET(fd, &rfds)) ||
(fe->mask & JIM_EVENT_WRITABLE && FD_ISSET(fd, &wfds)) ||
- (fe->mask & JIM_EVENT_EXCEPTION && FD_ISSET(fd, &efds)))
- {
+ (fe->mask & JIM_EVENT_EXCEPTION && FD_ISSET(fd, &efds))) {
int mask = 0;
if ((fe->mask & JIM_EVENT_READABLE) && FD_ISSET(fd, &rfds)) {
mask |= JIM_EVENT_READABLE;
- if ((fe->mask & JIM_EVENT_FEOF) && feof(fe->handle))
- mask |= JIM_EVENT_FEOF;
- }
+ if ((fe->mask & JIM_EVENT_FEOF) && feof(fe->handle))
+ mask |= JIM_EVENT_FEOF;
+ }
if (fe->mask & JIM_EVENT_WRITABLE && FD_ISSET(fd, &wfds))
mask |= JIM_EVENT_WRITABLE;
if (fe->mask & JIM_EVENT_EXCEPTION && FD_ISSET(fd, &efds))
@@ -326,7 +334,8 @@ int Jim_ProcessEvents(Jim_Interp *interp, int flags)
FD_CLR(fd, &rfds);
FD_CLR(fd, &wfds);
FD_CLR(fd, &efds);
- } else {
+ }
+ else {
fe = fe->next;
}
}
@@ -335,8 +344,8 @@ int Jim_ProcessEvents(Jim_Interp *interp, int flags)
/* Check time events */
te = eventLoop->timeEventHead;
- maxId = eventLoop->timeEventNextId-1;
- while(te) {
+ maxId = eventLoop->timeEventNextId - 1;
+ while (te) {
long now_sec, now_ms;
jim_wide id;
@@ -345,9 +354,7 @@ int Jim_ProcessEvents(Jim_Interp *interp, int flags)
continue;
}
JimGetTime(&now_sec, &now_ms);
- if (now_sec > te->when_sec ||
- (now_sec == te->when_sec && now_ms >= te->when_ms))
- {
+ if (now_sec > te->when_sec || (now_sec == te->when_sec && now_ms >= te->when_ms)) {
id = te->id;
te->timeProc(interp, te->clientData);
/* After an event is processed our time event list may
@@ -358,7 +365,8 @@ int Jim_ProcessEvents(Jim_Interp *interp, int flags)
* itself. To do so we saved the max ID we want to handle. */
Jim_DeleteTimeHandler(interp, id);
te = eventLoop->timeEventHead;
- } else {
+ }
+ else {
te = te->next;
}
}
@@ -376,7 +384,7 @@ void JimELAssocDataDeleProc(Jim_Interp *interp, void *data)
Jim_EventLoop *eventLoop = data;
fe = eventLoop->fileEventHead;
- while(fe) {
+ while (fe) {
next = fe->next;
if (fe->finalizerProc)
fe->finalizerProc(interp, fe->clientData);
@@ -385,7 +393,7 @@ void JimELAssocDataDeleProc(Jim_Interp *interp, void *data)
}
te = eventLoop->timeEventHead;
- while(te) {
+ while (te) {
next = te->next;
if (te->finalizerProc)
te->finalizerProc(interp, te->clientData);
@@ -395,8 +403,7 @@ void JimELAssocDataDeleProc(Jim_Interp *interp, void *data)
Jim_Free(data);
}
-static int JimELVwaitCommand(Jim_Interp *interp, int argc,
- Jim_Obj *const *argv)
+static int JimELVwaitCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
Jim_Obj *oldValue;
@@ -405,7 +412,8 @@ static int JimELVwaitCommand(Jim_Interp *interp, int argc,
return JIM_ERR;
}
oldValue = Jim_GetGlobalVariable(interp, argv[1], JIM_NONE);
- if (oldValue) Jim_IncrRefCount(oldValue);
+ if (oldValue)
+ Jim_IncrRefCount(oldValue);
while (1) {
Jim_Obj *currValue;
@@ -415,11 +423,11 @@ static int JimELVwaitCommand(Jim_Interp *interp, int argc,
* or if was unset and now is set (or the contrary). */
if ((oldValue && !currValue) ||
(!oldValue && currValue) ||
- (oldValue && currValue &&
- !Jim_StringEqObj(oldValue, currValue, JIM_CASESENS)))
+ (oldValue && currValue && !Jim_StringEqObj(oldValue, currValue, JIM_CASESENS)))
break;
}
- if (oldValue) Jim_DecrRefCount(interp, oldValue);
+ if (oldValue)
+ Jim_DecrRefCount(interp, oldValue);
return JIM_OK;
}
@@ -437,24 +445,23 @@ void JimAfterTimeEventFinalizer(Jim_Interp *interp, void *clientData)
Jim_DecrRefCount(interp, objPtr);
}
-static int JimELAfterCommand(Jim_Interp *interp, int argc,
- Jim_Obj *const *argv)
+static int JimELAfterCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
jim_wide ms, id;
Jim_Obj *objPtr, *idObjPtr;
const char *options[] = {
"info", "cancel", NULL
};
- enum {INFO, CANCEL, RESTART, EXPIRE, CREATE };
- int option = CREATE ;
+ enum
+ { INFO, CANCEL, RESTART, EXPIRE, CREATE };
+ int option = CREATE;
if (argc < 3) {
Jim_WrongNumArgs(interp, 1, argv, "<after milliseconds> script|cancel <id>");
return JIM_ERR;
}
if (Jim_GetWide(interp, argv[1], &ms) != JIM_OK) {
- if (Jim_GetEnum(interp, argv[1], options, &option, "after options",
- JIM_ERRMSG) != JIM_OK) {
+ if (Jim_GetEnum(interp, argv[1], options, &option, "after options", JIM_ERRMSG) != JIM_OK) {
return JIM_ERR;
}
}
@@ -462,7 +469,7 @@ static int JimELAfterCommand(Jim_Interp *interp, int argc,
case CREATE:
Jim_IncrRefCount(argv[2]);
id = Jim_CreateTimeHandler(interp, ms, JimAfterTimeHandler, argv[2],
- JimAfterTimeEventFinalizer);
+ JimAfterTimeEventFinalizer);
objPtr = Jim_NewStringObj(interp, NULL, 0);
Jim_AppendString(interp, objPtr, "after#", -1);
idObjPtr = Jim_NewIntObj(interp, id);
@@ -471,22 +478,23 @@ static int JimELAfterCommand(Jim_Interp *interp, int argc,
Jim_DecrRefCount(interp, idObjPtr);
Jim_SetResult(interp, objPtr);
return JIM_OK;
- case CANCEL: {
- int tlen ;
- jim_wide remain = 0;
- const char *tok = Jim_GetString(argv[2], &tlen);
- if (strncmp(tok, "after#", 6) == 0 && Jim_StringToWide(tok + 6, &id, 10) == JIM_OK) {
- remain = Jim_DeleteTimeHandler(interp, id);
- if (remain > -2) {
- Jim_SetResult(interp, Jim_NewIntObj(interp, remain));
- return JIM_OK;
+ case CANCEL:{
+ int tlen;
+ jim_wide remain = 0;
+ const char *tok = Jim_GetString(argv[2], &tlen);
+
+ if (strncmp(tok, "after#", 6) == 0 && Jim_StringToWide(tok + 6, &id, 10) == JIM_OK) {
+ remain = Jim_DeleteTimeHandler(interp, id);
+ if (remain > -2) {
+ Jim_SetResult(interp, Jim_NewIntObj(interp, remain));
+ return JIM_OK;
+ }
}
+ Jim_SetResultString(interp, "invalid event", -1);
+ return JIM_ERR;
}
- Jim_SetResultString(interp, "invalid event" , -1);
- return JIM_ERR;
- }
default:
- fprintf(stderr,"unserviced option to after %d\n",option);
+ fprintf(stderr, "unserviced option to after %d\n", option);
}
return JIM_OK;
}
@@ -495,9 +503,6 @@ int Jim_eventloopInit(Jim_Interp *interp)
{
Jim_EventLoop *eventLoop;
- if (Jim_PackageProvide(interp, "eventloop", "1.0", JIM_ERRMSG) != JIM_OK)
- return JIM_ERR;
-
eventLoop = Jim_Alloc(sizeof(*eventLoop));
eventLoop->fileEventHead = NULL;
eventLoop->timeEventHead = NULL;
View
219 jim-exec.c
@@ -1,3 +1,4 @@
+
/*
* (c) 2008 Steve Bennett <steveb@workware.net.au>
*
@@ -38,7 +39,7 @@ static void Jim_RemoveTrailingNewline(Jim_Obj *objPtr)
int len;
const char *s = Jim_GetString(objPtr, &len);
- if (len > 0 && s[len-1] == '\n') {
+ if (len > 0 && s[len - 1] == '\n') {
objPtr->length--;
objPtr->bytes[objPtr->length] = '\0';
}
@@ -78,6 +79,7 @@ static void JimTrimTrailingNewline(Jim_Interp *interp)
{
int len;
const char *p = Jim_GetString(Jim_GetResult(interp), &len);
+
if (len > 0 && p[len - 1] == '\n') {
Jim_SetResultString(interp, p, len - 1);
}
@@ -97,9 +99,10 @@ static int JimCheckWaitStatus(Jim_Interp *interp, int pid, int waitStatus)
}
else if (WIFSIGNALED(waitStatus)) {
#ifdef jim_ext_signal
- Jim_SetResultFormatted(interp, "child killed by signal %s", Jim_SignalId(WTERMSIG(waitStatus)));
+ Jim_SetResultFormatted(interp, "child killed by signal %s",
+ Jim_SignalId(WTERMSIG(waitStatus)));
#else
- Jim_SetResultFormatted(interp, "child killed by signal %d", WTERMSIG(waitStatus));
+ Jim_SetResultFormatted(interp, "child killed by signal %d", WTERMSIG(waitStatus));
#endif
}
else if (WIFSTOPPED(waitStatus)) {
@@ -112,16 +115,14 @@ static int JimCheckWaitStatus(Jim_Interp *interp, int pid, int waitStatus)
static int Jim_CreatePipeline(Jim_Interp *interp, int argc, Jim_Obj *const *argv,
int **pidArrayPtr, int *inPipePtr, int *outPipePtr, int *errFilePtr);
static void JimDetachPids(Jim_Interp *interp, int numPids, int *pidPtr);
-static int
-Jim_CleanupChildren(Jim_Interp *interp, int numPids, int *pidPtr, int errorId);