def export_cscope(file, _path_prefix)
      buf = ''
      files = []
      db_by_line.each do |filename, lines|
        next if lines.empty?

        buf << "\t@#{filename}\n\n"
        buf << "0 #{CSCOPE_GLOBAL_HACK_START}\n"
        files << filename
        func_count = 0

        lines.sort.each do |line_no, records|
          line = line_for_record(records.first)
          toks = tokenize_line(line, records)
          next if toks.empty?

          prev = 0
          buf << line_no.to_s << ' '
          toks.each do |offset, record|
            next if offset < prev # this probably indicates an extractor bug

            # Don't export nested functions, cscope barfs on them since C doesn't
            # have them at all. Skipping tokens is easy; since prev isn't updated
            # they get turned into plain text automatically.
            if record[:type] == :func
              case record[:tbl]
              when :defs
                func_count += 1
                next unless func_count == 1
              when :end
                func_count -= 1
                next unless func_count == 0
              end
            end

            buf << cscope_output(line, prev, offset, record)
            prev = offset + record[:key].length
          end
          buf << cscope_plaintext(line, prev, line.length) << "\n\n"
        end
      end

      buf << "\t@\n"

      header = "cscope 15 #{Dir.pwd} -c "
      offset = format("%010d\n", header.length + 11 + buf.bytes.count)

      file.print(header)
      file.print(offset)
      file.print(buf)

      file.print("#{@meta[:paths].length}\n")
      @meta[:paths].each { |p| file.print("#{p}\n") }
      file.print("0\n")
      file.print("#{files.length}\n")
      buf = ''
      files.each { |f| buf << f + "\n" }
      file.print("#{buf.length}\n#{buf}")
    end
def export_cscope(file, _path_prefix)
      buf = ''
      files = []
      db_by_line.each do |filename, lines|
        next if lines.empty?

        buf << "\t@#{filename}\n\n"
        buf << "0 #{CSCOPE_GLOBAL_HACK_START}\n"
        files << filename
        func_count = 0

        lines.sort.each do |line_no, records|
          line = line_for_record(records.first)
          toks = tokenize_line(line, records)
          next if toks.empty?

          prev = 0
          buf << line_no.to_s << ' '
          toks.each do |offset, record|
            next if offset < prev # this probably indicates an extractor bug

            # Don't export nested functions, cscope barfs on them since C doesn't
            # have them at all. Skipping tokens is easy; since prev isn't updated
            # they get turned into plain text automatically.
            if record[:type] == :func
              case record[:tbl]
              when :defs
                func_count += 1
                next unless func_count == 1
              when :end
                func_count -= 1
                next unless func_count == 0
              end
            end

            buf << cscope_output(line, prev, offset, record)
            prev = offset + record[:key].length
          end
          buf << cscope_plaintext(line, prev, line.length) << "\n\n"
        end
      end

      buf << "\t@\n"

      header = "cscope 15 #{Dir.pwd} -c "
      offset = format("%010d\n", header.length + 11 + buf.bytes.count)

      file.print(header)
      file.print(offset)
      file.print(buf)

      file.print("#{@meta[:paths].length}\n")
      @meta[:paths].each { |p| file.print("#{p}\n") }
      file.print("0\n")
      file.print("#{files.length}\n")
      buf = ''
      files.each { |f| buf << f + "\n" }
      file.print("#{buf.length}\n#{buf}")
    end
ftp://ftp.eeng.dcu.ie/pub/ee454/cygwin/usr/share/doc/mlcscope-14.1.8/html/cscope.html