reapack

Package manager for REAPER
Log | Files | Refs | Submodules | README | LICENSE

prepare.rb (1253B)


      1 #!/usr/bin/env ruby
      2 
      3 Signal.trap('INT') { abort }
      4 
      5 REGEX = /\A\/\*.+?\*\/\n/m.freeze
      6 PREAMBLE = DATA.read.freeze
      7 
      8 def process(input)
      9   if input.start_with? '/'
     10     before = input.hash
     11     input.sub! REGEX, PREAMBLE
     12     input if input.hash != before
     13   else
     14     input.prepend "#{PREAMBLE}\n"
     15   end
     16 end
     17 
     18 ARGV.each do |path|
     19   File.open path, 'r+t' do |file|
     20     output = process file.read
     21     next unless output
     22 
     23     file.rewind
     24     file.write output
     25     file.truncate file.pos
     26   end
     27 end
     28 
     29 __END__
     30 /* ReaPack: Package manager for REAPER
     31  * Copyright (C) 2015-2025  Christian Fillion
     32  *
     33  * This program is free software: you can redistribute it and/or modify
     34  * it under the terms of the GNU Lesser General Public License as published by
     35  * the Free Software Foundation, either version 3 of the License, or
     36  * (at your option) any later version.
     37  *
     38  * This program is distributed in the hope that it will be useful,
     39  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     40  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     41  * GNU Lesser General Public License for more details.
     42  *
     43  * You should have received a copy of the GNU Lesser General Public License
     44  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
     45  */