Permalink
Browse files

Add make-bootstrap-jim script

Allows a single source file version of jimsh to be created
for bootstrap purposes.

Signed-off-by: Steve Bennett <steveb@workware.net.au>
  • Loading branch information...
1 parent 7eea351 commit 50842214af3fb8d82d6097faba975de0c27b4ff8 @msteveb committed Dec 9, 2010
Showing with 91 additions and 11 deletions.
  1. +3 −0 bootstrap.tcl
  2. +11 −11 jimregexp.c
  3. +77 −0 make-bootstrap-jim
View
@@ -0,0 +1,3 @@
+# No need for package support in the bootstrap jimsh, but
+# Tcl extensions call package require
+proc package {args} {}
View
@@ -643,7 +643,7 @@ static void reg_addrange_str(regex_t *preg, const char *str)
*
* If 'upper' is set, converts the char to uppercase.
*/
-static int utf8_tounicode_case(const char *s, int *uc, int upper)
+static int reg_utf8_tounicode_case(const char *s, int *uc, int upper)
{
int l = utf8_tounicode(s, uc);
if (upper) {
@@ -657,7 +657,7 @@ static int utf8_tounicode_case(const char *s, int *uc, int upper)
*
* Returns -1 for an invalid hex digit.
*/
-static int xdigitval(int c)
+static int hexdigitval(int c)
{
if (c >= '0' && c <= '9')
return c - '0';
@@ -680,7 +680,7 @@ static int parse_hex(const char *s, int n, int *uc)
int k;
for (k = 0; k < n; k++) {
- int c = xdigitval(*s++);
+ int c = hexdigitval(*s++);
if (c == -1) {
break;
}
@@ -747,7 +747,7 @@ static int *regatom(regex_t *preg, int *flagp)
int nocase = (preg->cflags & REG_ICASE);
int ch;
- int n = utf8_tounicode_case(preg->regparse, &ch, nocase);
+ int n = reg_utf8_tounicode_case(preg->regparse, &ch, nocase);
*flagp = WORST; /* Tentatively. */
@@ -784,7 +784,7 @@ static int *regatom(regex_t *preg, int *flagp)
int start;
int end;
- pattern += utf8_tounicode_case(pattern, &start, nocase);
+ pattern += reg_utf8_tounicode_case(pattern, &start, nocase);
if (start == '\\') {
pattern += reg_decode_escape(pattern, &start);
if (start == 0) {
@@ -795,7 +795,7 @@ static int *regatom(regex_t *preg, int *flagp)
if (pattern[0] == '-' && pattern[1]) {
/* skip '-' */
pattern += utf8_tounicode(pattern, &end);
- pattern += utf8_tounicode_case(pattern, &end, nocase);
+ pattern += reg_utf8_tounicode_case(pattern, &end, nocase);
if (end == '\\') {
pattern += reg_decode_escape(pattern, &end);
if (end == 0) {
@@ -926,7 +926,7 @@ static int *regatom(regex_t *preg, int *flagp)
/* Until end of string or a META char is reached */
while (*preg->regparse && strchr(META, *preg->regparse) == NULL) {
- n = utf8_tounicode_case(preg->regparse, &ch, (preg->cflags & REG_ICASE));
+ n = reg_utf8_tounicode_case(preg->regparse, &ch, (preg->cflags & REG_ICASE));
if (ch == '\\' && preg->regparse[n]) {
/* Non-trailing backslash.
* Is this a special escape, or a regular escape?
@@ -1220,7 +1220,7 @@ static int prefix_cmp(const int *prog, int proglen, const char *string, int noca
const char *s = string;
while (proglen && *s) {
int ch;
- int n = utf8_tounicode_case(s, &ch, nocase);
+ int n = reg_utf8_tounicode_case(s, &ch, nocase);
if (ch != *prog) {
return -1;
}
@@ -1274,7 +1274,7 @@ static const char *str_find(const char *string, int c, int nocase)
}
while (*string) {
int ch;
- int n = utf8_tounicode_case(string, &ch, nocase);
+ int n = reg_utf8_tounicode_case(string, &ch, nocase);
if (c == ch) {
return string;
}
@@ -1427,7 +1427,7 @@ static int regmatch(regex_t *preg, const int *prog)
no = regrepeat(preg, OPERAND(scan));
while (no >= min) {
int ch;
- utf8_tounicode_case(preg->reginput, &ch, (preg->cflags & REG_ICASE));
+ reg_utf8_tounicode_case(preg->reginput, &ch, (preg->cflags & REG_ICASE));
/* If it could work, try it. */
if (reg_iseol(preg, nextch) || ch == nextch)
if (regmatch(preg, next))
@@ -1506,7 +1506,7 @@ static int regrepeat(regex_t *preg, const int *p )
if (preg->cflags & REG_ICASE) {
while (1) {
int ch;
- int n = utf8_tounicode_case(scan, &ch, 1);
+ int n = reg_utf8_tounicode_case(scan, &ch, 1);
if (*opnd != ch) {
break;
}
View
@@ -0,0 +1,77 @@
+#!/bin/sh
+
+# This script writes to stdout, a single source file (e.g. jimsh0.c)
+# which can be compiled to provide a bootstrap version of jimsh.
+# e.g. cc -o jimsh0 jimsh0.c
+
+makeext()
+{
+ source="$1"
+ basename=`basename "$source" .tcl`
+cat <<EOF
+int Jim_${basename}Init(Jim_Interp *interp)
+{
+ if (Jim_PackageProvide(interp, "$basename", "1.0", JIM_ERRMSG))
+ return JIM_ERR;
+
+ return Jim_Eval_Named(interp,
+EOF
+
+# Note: Keep newlines so that line numbers match in error messages
+sed -e 's/^[ ]*#.*//' -e 's@\\@\\\\@g' -e 's@"@\\"@g' -e 's@^\(.*\)$@"\1\\n"@' $source
+#sed -e 's@^\(.*\)$@"\1\\n"@' $source
+
+echo ",\"$source\", 1);"
+echo "}"
+}
+
+makeloadexts()
+{
+cat <<EOF
+int Jim_InitStaticExtensions(Jim_Interp *interp)
+EOF
+ echo "{"
+ for ext in $*; do
+ echo "extern int Jim_${ext}Init(Jim_Interp *);"
+ echo "Jim_${ext}Init(interp);"
+ done
+ echo "return JIM_OK;"
+ echo "}"
+}
+
+cexts="aio readdir regexp file exec clock array"
+tclexts="bootstrap glob stdlib tclcompat"
+
+# Note ordering
+allexts="bootstrap aio readdir glob regexp file exec clock array stdlib tclcompat"
+
+echo "/* This is single source file, bootstrap version of Jim Tcl. See http://jim.berlios.de/ */"
+
+# define some core features
+for i in _GNU_SOURCE JIM_TCL_COMPAT JIM_REFERENCES JIM_ANSIC HAVE_VFORK JIM_REGEXP HAVE_NO_AUTOCONF _JIMAUTOCONF_H; do
+ echo "#define $i"
+done
+echo '#define TCL_LIBRARY "."'
+# and extensions
+for i in $allexts; do
+ echo "#define jim_ext_$i"
+done
+
+# Now output header files, removing references to jim header files
+for i in utf8.h jim.h jim-subcmd.h jimregexp.h ; do
+ sed -e '/#include.*jim/d' -e '/#include.*utf8/d' $i
+done
+
+# Now extension source code
+for i in $tclexts; do
+ makeext $i.tcl
+done
+for i in $cexts; do
+ sed -e '/#include.*jim/d' jim-$i.c
+done
+makeloadexts $allexts
+
+# And finally the core source code
+for i in jim.c jim-subcmd.c utf8.c jim-interactive.c jim-format.c jimregexp.c jimsh.c; do
+ sed -e '/#include.*jim/d' -e '/#include.*utf8/d' $i
+done

0 comments on commit 5084221

Please sign in to comment.