Browse Source

Changed prefix to suffix in jtalkc. This can be used to produce different js files from the same st file.

Göran Krampe 13 years ago
parent
commit
411bd6e38c
2 changed files with 32 additions and 17 deletions
  1. 13 13
      bin/jtalkc
  2. 19 4
      nodejs/nodecompile.js

+ 13 - 13
bin/jtalkc

@@ -15,7 +15,7 @@ popd >/dev/null
 
 function usage {
 	cat <<ENDOFHELP
-Usage: $0 [-N|D|E] [-K|C|J] [-o] [-O|-A] [-g] [-p prefix] [-m class] [-M file]
+Usage: $0 [-N|D|E] [-K|C|J] [-o] [-O|-A] [-g] [-s suffix] [-m class] [-M file]
           [-i] [-I file] [file1 [file2 ...]] [Program]
 
    Will compile Jtalk files - either separately or into a runnable complete
@@ -64,9 +64,9 @@ Usage: $0 [-N|D|E] [-K|C|J] [-o] [-O|-A] [-g] [-p prefix] [-m class] [-M file]
   -g
      Compile Jtalk code in debug mode - include source and references etc.
 
-  -p prefix
-     Add <prefix> to compiled js files so that File.st is compiled into
-     <prefix>File.st.
+  -s suffix
+     Add <suffix> to compiled js files so that File.st is compiled into
+     File.<suffix>.st.
 
   -l library1,library2
      Load listed libraries (no spaces) into Compiler before compiling.
@@ -134,14 +134,14 @@ BASE=
 LOAD=
 LOADANDADD=
 CLOSUREOPTS=
-# Ok, bad coding practice but hey, who would use such a prefix?
-PREFIX=no-silly-prefix
-PREFIXUSED=
+# Ok, bad coding practice but hey, who would use such a suffix?
+SUFFIX=no-silly-suffix
+SUFFIXUSED=
 DEBUG=false
 NODECOMPILE=nodecompile.js
 
 # Read options and shift them away
-while getopts "NDEKCJoOAgp:l:L:i:IM:m:h?" o; do
+while getopts "NDEKCJoOAgs:l:L:i:IM:m:h?" o; do
 case "$o" in
    N) ENV=NODE
       BASE=$KERNEL
@@ -163,8 +163,8 @@ case "$o" in
       CLOSUREOPTS="$CLOSUREOPTS --compilation_level ADVANCED_OPTIMIZATIONS"
       CLOSUREFULL=true;;
    g) DEBUG=true;;
-   p) PREFIX=$OPTARG
-      PREFIXUSED=$PREFIX;;
+   s) SUFFIX=$OPTARG
+      SUFFIXUSED=$SUFFIX;;
    l) LOAD=$OPTARG;;
    L) LOADANDADD=$OPTARG;;
    I) INIT=$INITIALIZER;;
@@ -259,11 +259,11 @@ do
         CATEGORY=`basename $1 .st`
         if [ -f "$1" ]; then
            COMPILE="$COMPILE $1 $CATEGORY"
-           COMPILED="$COMPILED $PREFIXUSED$CATEGORY.js"
+           COMPILED="$COMPILED $CATEGORY$SUFFIXUSED.js"
         else
            if [ -f $JTALK/st/$1 ]; then
              COMPILE="$COMPILE $JTALK/st/$1 $CATEGORY"
-             COMPILED="$COMPILED $PREFIXUSED$CATEGORY.js"
+             COMPILED="$COMPILED $CATEGORY$SUFFIXUSED.js"
            else
              echo "JTalk file not found: $1"
              exit 1
@@ -292,7 +292,7 @@ cat $TOOURCOMPILER > $TMPDIR/compiler.js
  
 # Compile all collected .st files to .js
 echo "Loading libraries $TOOURCOMPILER and compiling ..."
-node $TMPDIR/compiler.js $DEBUG $PREFIX $COMPILE
+node $TMPDIR/compiler.js $DEBUG $SUFFIX $COMPILE
 
 # Verify all .js files corresponding to .st files were created, otherwise exit
 IFS=" "

+ 19 - 4
nodejs/nodecompile.js

@@ -4,8 +4,23 @@
 // as aCategoryName.js.
 var sys = require('sys'), fs = require('fs');
 
-// Only care about our arguments, strip away node and all.js
-var arguments = process.argv.splice(2);
+// Only care about our arguments, strip away node, all.js and debug flag.
+var arguments = process.argv.splice(4);
+
+// First argument is debugMode: "true" or "false"
+if (process.argv[2] == "true") {
+  smalltalk.debugMode = true;
+} else {
+  smalltalk.debugMode = false;
+}
+
+// Second argument is suffix: "no-silly-suffix" means none
+suffix = process.argv[3];
+if (suffix == "no-silly-suffix") {
+  suffix = "";
+}
+
+console.log("Compiling in debugMode: " + smalltalk.debugMode);
 
 // If it ends with .st, import it, otherwise export category as .js
 arguments.forEach(function(val, index, array) {
@@ -14,7 +29,7 @@ arguments.forEach(function(val, index, array) {
     code = fs.readFileSync(val, "utf8");
     smalltalk.Importer._new()._import_(code._stream());
   } else {
-    sys.puts("Exporting category " + val);
-    fs.writeFileSync(val + ".js", smalltalk.Exporter._new()._exportCategory_(val));
+    sys.puts("Exporting category " + val + " as " + val + suffix + ".js");
+    fs.writeFileSync(val + suffix + ".js", smalltalk.Exporter._new()._exportCategory_(val));
   }
 });