#!/usr/bin/env ruby

$LOAD_PATH << "../../../lib" unless $LOAD_PATH.include?("../../../lib")
require "qwik/util-path"

def read_file(file)
  s = ""
  file.open {|f|
    while line = f.gets
      line.sub!(/\/\/.+$/, "")
      case line
      when /\A\/\//, /\A\s*$/
	# do nothing
      else
	s << line
      end
    end
    f.read
  }
  s
end

def add_all_js(src)
  path = ".".path
  path.each_entry {|file|
    f = file.to_s
    next unless /\.js\z/ =~ f
    s = read_file(file)
    src << s
  }
end

def add_some_js(src)
  path = ".".path
 #ar = %w(base history monitor niftypp wysiwyg)
  ar = %w(base niftypp)
  ar.each {|f|
    pa = path+(f+".js")
    #p pa
    s = read_file(pa)
    src << s
  }
end

def generate_src
  src = <<"EOT"
// Copyright (C) 2003-2005 Kouichirou Eto, All rights reserved.
// This is free software with ABSOLUTELY NO WARRANTY.
// You can redistribute it and/or modify it under the terms of the GNU GPL2.

// This file is automatically generated.
// PLEASE DO NOT EDIT THIS FILE.

EOT
  #add_all_js(src)
  add_some_js(src)
  "../all.js".path.open("wb") {|f|
    f.puts src
  }
end
generate_src
