JSDOC/Packer.vala
[gnome.introspection-doc-generator] / JSDOC / Packer.vala
index 867cff7..16bd4af 100644 (file)
@@ -64,11 +64,14 @@ namespace JSDOC
                * @cfg {String} target to write files to - must be full path.
                */
                string target;
+               FileOutputStream targetStream = null;
                /**
                 * @cfg {String} debugTarget target to write files debug version to (uncompacted)- must be full path.
                 */
                string targetDebug;
-       
+               
+
+               FileOutputStream targetDebugStream  = null;
                /**
                 * @cfg {String} tmpDir  (optional) where to put the temporary files. 
                 *      if you set this, then files will not be cleaned up
@@ -117,8 +120,7 @@ namespace JSDOC
                                this.files.add(f); //?? easier way?
                        }
                }
-               FileOutputStream targetStream = null;
-               FileOutputStream targetDebugStream  = null;
+       
                
                public void pack()
                {
@@ -207,10 +209,10 @@ namespace JSDOC
                                string file_contents;
                        // debug Target
                        
-                       if (this.debugTargetStream !=null) {
+                       if (this.targetDebugStream !=null) {
                                
                                FileUtils.get_contents(file,out file_contents);
-                           this.debugTarget.write(file_contents);
+                           this.targetDebugStream.write(file_contents);
                            loaded_string = false;
                        }
                        // it's a good idea to check with 0 compression to see if the code can parse!!
@@ -262,7 +264,7 @@ namespace JSDOC
                    
                    // if we are translating, write the translations strings at the top
                    // of the file..
-                   
+                   /*
                    if (this.translateJSON) {
                        
                           
@@ -306,12 +308,12 @@ namespace JSDOC
                           
                        }
                    }
-                   
+                   */
                    print("MERGING SOURCE");
                    
                    for(var i=0; i < this.files.length; i++)  {
                        var file = this.files[i];
-                       var minfile = this.tmpDir + '/' + file.replace(/\//g, '.');
+                       var minfile = this.tmpDir + '/' + file.replace('/', '.');
                        
                        
                        if (!File.exists(minfile)) {
@@ -320,17 +322,18 @@ namespace JSDOC
                        var str = File.read(minfile);
                        print("using MIN FILE  "+ minfile);
                        if (str.length) {
-                           if (this.target) {
-                               File.append(this.target, '//' + file + "\n");   
-                               File.append(this.target, str + "\n");   
+                           if (this.targetStream != null) {
+                                       this.targetStream.write("//" + file + "\n"); 
+                                       this.targetStream.write(str + "\n"); 
+
                            } else {
-                               this.out += '//' + file + "\n";
+                               this.out += "//" + file + "\n";
                                this.out += str + "\n";
                            }
                            
                        }
                        if (this.cleanup) {
-                           File.remove(minfile);
+                           FileUtils.remove(minfile);
                        }
                        
                    }
@@ -340,7 +343,7 @@ namespace JSDOC
                     
                
                
-               },
+               }
     /**
      * Core packing routine  for a file
      * 
@@ -408,172 +411,16 @@ namespace JSDOC
         
          
     },
+     
     
-    timerPrint: function (str) {
-        var ntime = new Date() * 1;
-        var tdif =  ntime -this.timer;
-        this.timer = ntime;
-        print('['+tdif+']'+str);
-    },
-    
-    /**
-     * 
-     * Translation concept...
-     * -> replace text strings with _T....
-     * -> this file will need inserting at the start of the application....
-     * -> we need to generate 2 files, 
-     * -> a reference used to do the translation, and the _T file..
-     *
-     *
-     * We store the trsum on the token...
-     * 
-     */
-    
-    writeTranslateFile : function(fn, minfile, toks) 
-    {
-        
-        var map = {};  // 'string=> md5sum'
-        var _this = this;
-        var t, last, next;
-        
-        
-        var tokfind =  function (j,dir) {
-            while (1) {
-                if ((dir < 0) && (j < 0)) {
-                    return false;
-                }
-                if ((dir > 0) && (j >= toks.length)) {
-                    return false;
-                }
-                j += dir;
-                if (toks[j].type != 'WHIT') {
-                    return toks[j];
-                }
-            }
-            return false;
-            
-        }
-        
-        
-        for (var i=0;i<toks.length;i++) {
-            
-            t = toks[i];
-            if (t.type != 'STRN') {
-                continue;
-            }
-            if (t.name != 'DOUBLE_QUOTE') {
-                continue;
-            }
-            
-            last = tokfind(i,-1);
-            next = tokfind(i,+1);
-            
-            // we have to ignore key values on objects
-            
-            // defined by
-            // last == '{' or ',' and
-            // next == ':'
-            
-            if (next &&
-                next.type == 'PUNC' &&
-                next.data == ':' && 
-                last && 
-                last.type == 'PUNC' &&
-                (last.data == ',' || last.data == '{')
-            ){
-                continue; // found object key... - we can not translate these
-            }
-                
-            var sval = t.data.substring(1,t.data.length-1);
-            var ffn = fn.substring(_this.prefix.length);
-            
-            t.trsum = _this.md5(ffn + '-' + sval);
-            map[sval] = t.trsum;
-            
-            
-            
-        }
-        
-        
-        var transfile = minfile + '.lang.trans';
-        var transmd5 = minfile + '.lang';
-        print("writeTranslateFile "  + transfile);
-        var i = 0;
-        var v = '';
-        if (File.exists(transfile)) {
-            File.remove(transfile);
-        }
-        if (File.exists(transmd5)) {
-            File.remove(transmd5);
-        }
-        for(v in map) { i++; break };
-        if (!i ) {
-            return; // no strings in file...
-        }
-        var ffn = fn.substring(this.prefix.length);
-         
-         
-        File.write(transfile, "\n'" + ffn  + "' : {");
-        var l = '';
-        var _tout = {}
-         
-        File.write(transmd5, '');
-        for(v in map) {
-            if (!v.length) {
-                continue;
-            }
-            File.append(transfile, l + "\n\t\"" + v  + "\" : \"" + v +"\"");
-            l = ',';
-            // strings are raw... - as the where encoded to start with!!!
-            // so we should not need to encode them again.. - just wrap with "
-            File.append(transmd5, '_T["' + this.md5(ffn + '-' + v) + '"]="'+v+"\";\n");
-        }
-        File.append(transfile, "\n},"); // always one trailing..
-        
-         
-    },
     md5 : function (string)
     {
         
         return GLib.compute_checksum_for_string(GLib.ChecksumType.MD5, string, string.length);
         
     },
-    stringHandler : function(tok)
-    {
-        //print("STRING HANDLER");
-       // callback when outputing compressed file, 
-       var data = tok.data;
-        if (!this.translateJSON) {
-         //   print("TURNED OFF");
-            return data;
-        }
-        if (tok.name == 'SINGLE_QUOTE') {
-            return data;
-        }
-        
-        if (typeof(tok.trsum) == 'undefined') {
-            return data;
-        }
-        
-        return '_T["' + tok.trsum + '"]';
-        
-        var sval = data.substring(1,data.length-1);
-        // we do not clean up... quoting here!??!!?!?!?!?
-        
-        
-        // blank with tabs or spaces..
-        //if (!sval.replace(new RegExp("(\\\\n|\\\\t| )+",'g'), '').length) {
-       //     return tok.outData;
-       // }
-        
-        var sval = tok.data.substring(1,data.length-1);
-        var fn = this.activeFile.substring(this.prefix.length);
-        
-        
-        return '_T["' + this.md5(fn + '-' + sval) + '"]';
-        
-        
-    }
+    
+    //stringHandler : function(tok) -- not used...
     
     
 };