diff options
author | Steve Bennett <steveb@workware.net.au> | 2009-07-29 14:12:41 +1000 |
---|---|---|
committer | Steve Bennett <steveb@workware.net.au> | 2010-10-15 10:11:03 +1000 |
commit | 4996f466d3bfb568b4798cbef03f059ae030be7f (patch) | |
tree | 05da6b67fd091ef2c081b951168abf78026582fa | |
parent | 1c0ce5bc7197de87f5820b1afc72304adef537b3 (diff) | |
download | jimtcl-4996f466d3bfb568b4798cbef03f059ae030be7f.zip jimtcl-4996f466d3bfb568b4798cbef03f059ae030be7f.tar.gz jimtcl-4996f466d3bfb568b4798cbef03f059ae030be7f.tar.bz2 |
Build fixes, better Jim_EvalFile()
*: make-c-ext is now make-c-ext.tcl
*: build doc/Tcl.html with asciidoc
*: Jim_SetIntResult -> Jim_SetResultInt
*: Jim_EvalFile() now reads the file contents in one go
-rw-r--r-- | Makefile.in | 2 | ||||
-rw-r--r-- | doc/jim_man.txt | 18 | ||||
-rw-r--r-- | jim-bio.c | 2 | ||||
-rw-r--r-- | jim-file.c | 17 | ||||
-rw-r--r-- | jim-regexp.c | 10 | ||||
-rw-r--r-- | jim.c | 40 | ||||
-rw-r--r-- | make-c-ext.tcl (renamed from make-c-ext) | 6 | ||||
-rw-r--r-- | make-load-extensions.sh | 8 |
8 files changed, 51 insertions, 52 deletions
diff --git a/Makefile.in b/Makefile.in index 2c7adde..4f54580 100644 --- a/Makefile.in +++ b/Makefile.in @@ -28,7 +28,7 @@ EXTENSIONS_OBJS := $(patsubst %,jim-%.o,$(EXTENSIONS)) # Create C extensions from pure Tcl extensions jim-%.c: %.tcl echo $@ >>.clean - tclsh make-c-ext $*.tcl + tclsh make-c-ext.tcl $@ $*.tcl # Emulate tinytcl LIBJIM := libtcl6.a diff --git a/doc/jim_man.txt b/doc/jim_man.txt index 88839ce..fca664c 100644 --- a/doc/jim_man.txt +++ b/doc/jim_man.txt @@ -1,3 +1,21 @@ +Jim(n) +====== + +NAME +---- +Jim - a better Tcl + +SYNOPSIS +-------- + + cc <source> -ltcl6 + +or + + jimsh <script> + +INTRODUCTION +------------ # what: jim commands, description, points to ponder jim @@ -179,7 +179,7 @@ static int bio_cmd_copy(Jim_Interp *interp, int argc, Jim_Obj *const *argv) return TCL_ERROR; } - Jim_SetIntResult(interp, count); + Jim_SetResultInt(interp, count); return JIM_OK; } @@ -94,11 +94,6 @@ static const char *GetFileType(int mode) return "unknown"; } -static void Jim_SetIntResult(Jim_Interp *interp, jim_wide wide) -{ - Jim_SetResult(interp, Jim_NewIntObj(interp, wide)); -} - /* *---------------------------------------------------------------------- * @@ -360,7 +355,7 @@ static int file_cmd_atime(Jim_Interp *interp, int argc, Jim_Obj *const *argv) if (file_stat(interp, argv[0], &sb) != JIM_OK) { return JIM_ERR; } - Jim_SetIntResult(interp, sb.st_atime); + Jim_SetResultInt(interp, sb.st_atime); return JIM_OK; } @@ -371,7 +366,7 @@ static int file_cmd_mtime(Jim_Interp *interp, int argc, Jim_Obj *const *argv) if (file_stat(interp, argv[0], &sb) != JIM_OK) { return JIM_ERR; } - Jim_SetIntResult(interp, sb.st_mtime); + Jim_SetResultInt(interp, sb.st_mtime); return JIM_OK; } @@ -382,7 +377,7 @@ static int file_cmd_size(Jim_Interp *interp, int argc, Jim_Obj *const *argv) if (file_stat(interp, argv[0], &sb) != JIM_OK) { return JIM_ERR; } - Jim_SetIntResult(interp, sb.st_size); + Jim_SetResultInt(interp, sb.st_size); return JIM_OK; } @@ -394,7 +389,7 @@ static int file_cmd_isdirectory(Jim_Interp *interp, int argc, Jim_Obj *const *ar if (file_stat(interp, argv[0], &sb) == JIM_OK) { ret = S_ISDIR(sb.st_mode); } - Jim_SetIntResult(interp, ret); + Jim_SetResultInt(interp, ret); return JIM_OK; } @@ -406,7 +401,7 @@ static int file_cmd_isfile(Jim_Interp *interp, int argc, Jim_Obj *const *argv) if (file_stat(interp, argv[0], &sb) == JIM_OK) { ret = S_ISREG(sb.st_mode); } - Jim_SetIntResult(interp, ret); + Jim_SetResultInt(interp, ret); return JIM_OK; } @@ -418,7 +413,7 @@ static int file_cmd_owned(Jim_Interp *interp, int argc, Jim_Obj *const *argv) if (file_stat(interp, argv[0], &sb) == JIM_OK) { ret = (geteuid() == sb.st_uid); } - Jim_SetIntResult(interp, ret); + Jim_SetResultInt(interp, ret); return JIM_OK; } diff --git a/jim-regexp.c b/jim-regexp.c index e3c194e..736813d 100644 --- a/jim-regexp.c +++ b/jim-regexp.c @@ -53,12 +53,6 @@ #define JIM_EXTENSION #include "jim.h" -/* REVISIT: Would be useful in jim.h */ -static void Jim_SetIntResult(Jim_Interp *interp, jim_wide wide) -{ - Jim_SetResult(interp, Jim_NewIntObj(interp, wide)); -} - /** * REVISIT: Should cache a number of compiled regexps for performance reasons. */ @@ -272,7 +266,7 @@ int Jim_RegexpCmd(Jim_Interp *interp, int argc, Jim_Obj *const *argv) Jim_SetResult(interp, resultListObj); } else { - Jim_SetIntResult(interp, num_matches); + Jim_SetResultInt(interp, num_matches); } } @@ -456,7 +450,7 @@ int Jim_RegsubCmd(Jim_Interp *interp, int argc, Jim_Obj *const *argv) result = Jim_SetVariable(interp, varname, resultObj); if (result == JIM_OK) { - Jim_SetIntResult(interp, num_matches); + Jim_SetResultInt(interp, num_matches); } else { Jim_SetResult(interp, Jim_NewEmptyStringObj(interp)); @@ -8461,43 +8461,31 @@ int Jim_EvalObjBackground(Jim_Interp *interp, Jim_Obj *scriptObjPtr) return retval; } -/* REVISIT: Just load the file with a single malloc/fread then Jim_EvalObj() */ +#include <sys/stat.h> + int Jim_EvalFile(Jim_Interp *interp, const char *filename) { - char *prg = NULL; FILE *fp; - int nread, totread, maxlen, buflen; - int retval; + char *buf; Jim_Obj *scriptObjPtr; - - if ((fp = fopen(filename, "r")) == NULL) { - const int cwd_len=2048; - char *cwd=malloc(cwd_len); - Jim_SetResult(interp, Jim_NewEmptyStringObj(interp)); - if (getcwd( cwd, cwd_len ) != 0) { - strcpy(cwd, "?"); - } + struct stat sb; + int retval; + + if (stat(filename, &sb) != 0 || (fp = fopen(filename, "r")) == NULL) { + Jim_SetResultString(interp, "", 0); Jim_AppendStrings(interp, Jim_GetResult(interp), "Error loading script \"", filename, "\"", - " cwd: ", cwd, " err: ", strerror(errno), NULL); - free(cwd); return JIM_ERR; } - buflen = 1024; - maxlen = totread = 0; - while (1) { - if (maxlen < totread+buflen+1) { - maxlen = totread+buflen+1; - prg = Jim_Realloc(prg, maxlen); - } - if ((nread = fread(prg+totread, 1, buflen, fp)) == 0) break; - totread += nread; + + buf = Jim_Alloc(sb.st_size + 1); + if (buf == 0 || fread(buf, sb.st_size, 1, fp) != 1) { + Jim_Free(buf); + return JIM_ERR; } - prg[totread] = '\0'; - fclose(fp); - scriptObjPtr = Jim_NewStringObjNoAlloc(interp, prg, totread); + scriptObjPtr = Jim_NewStringObjNoAlloc(interp, buf, sb.st_size); JimSetSourceInfo(interp, scriptObjPtr, filename, 1); Jim_IncrRefCount(scriptObjPtr); retval = Jim_EvalObj(interp, scriptObjPtr); diff --git a/make-c-ext b/make-c-ext.tcl index 4d3ae31..96f6355 100644 --- a/make-c-ext +++ b/make-c-ext.tcl @@ -14,14 +14,18 @@ proc tcl_to_string {str} { return $result } +set outfile [lindex $argv 0] +set argv [lrange $argv 1 end] + foreach file $argv { if {![string match *.tcl $file]} { error "Not a tcl file: $file" } set tmp [file tail $file] set rootname [file rootname $tmp] + if {0} { set outfile jim-$rootname.c - puts "$file -> $outfile" + } set f [open $file] set str [read $f] close $f diff --git a/make-load-extensions.sh b/make-load-extensions.sh index 334fbe1..c9b25cc 100644 --- a/make-load-extensions.sh +++ b/make-load-extensions.sh @@ -4,14 +4,14 @@ exec >$1 shift +exts=$(echo "$@" | sed -e 's@[^ ]*jim-@@g' -e 's@[.]c@@g') + echo '#include "jim.h"' -for i in "$@"; do - name=`echo $i | sed -e 's@.*/\(.*\).c@\1@'` +for name in $exts; do echo "extern int Jim_${name}Init(Jim_Interp *interp);" done echo "int Jim_InitStaticExtensions(Jim_Interp *interp) {" -for i in "$@"; do - name=`echo $i | sed -e 's@.*/\(.*\).c@\1@'` +for name in $exts; do echo "if (Jim_${name}Init(interp) != JIM_OK) return JIM_ERR;" done echo "return JIM_OK;" |