From 5bcbd1d5d3e74f07220cbda4014d408f97447e63 Mon Sep 17 00:00:00 2001 From: guy Decoux Date: Sat, 28 Feb 2009 20:20:42 +0100 Subject: mmap-0.2.5 --- doc/b.rb | 109 +++++++++++++++++ doc/mmap.rb | 396 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 505 insertions(+) create mode 100755 doc/b.rb create mode 100644 doc/mmap.rb (limited to 'doc') diff --git a/doc/b.rb b/doc/b.rb new file mode 100755 index 0000000..0839bb3 --- /dev/null +++ b/doc/b.rb @@ -0,0 +1,109 @@ +#!/usr/bin/ruby + +def yield_or_not(primary) + text = primary.sub(/\{\s*\|([^|]+)\|[^}]*\}/, '') + if text != primary + "def #{text}yield #$1\nend" + else + "def #{text}end" + end +end + +def normalize(text) + norm = text.gsub(/\(\(\|([^|]+)\|\)\)/, '\\1') + norm.gsub!(/\(\(\{/, '') + norm.gsub!(/\}\)\)/, '') + norm.gsub!(/\(\(<([^|>]+)[^>]*>\)\)/, '\\1') + norm.gsub!(/^\s*:\s/, ' * ') + norm +end + +def intern_def(text, names, fout) + fout.puts "##{normalize(text.join('#'))}" + fout.puts yield_or_not(names[0]) + if names.size > 1 + n = names[0].chomp.sub(/\(.*/, '') + names[1 .. -1].each do |na| + nd = na.chomp.sub(/\(.*/, '') + if nd != n + fout.puts "#same than #{n}" + fout.puts yield_or_not(na) + end + end + end +end + +def output_def(text, names, keywords, fout) + if ! names.empty? + keywords.each do |k| + fout.puts k + intern_def(text, names, fout) + fout.puts "end" if k != "" + end + end +end + +def loop_file(file, fout) + text, keywords, names = [], [""], [] + comment = false + rep, indent, vide = '', -1, nil + IO.foreach(file) do |line| + if /^#\^/ =~ line + comment = ! comment + next + end + if comment + fout.puts "# #{normalize(line)}" + next + end + case line + when /^\s*$/ + vide = true + text.push line + when /^#\^/ + comment = ! comment + when /^##/ + line[0] = ?\s + fout.puts line + when /^#\s*(.+?)\s*$/ + keyword = $1 + output_def(text, names, keywords, fout) + text, names = [], [] + keywords = keyword.split(/\s*##\s*/) + if keywords.size == 1 + fout.puts keywords[0] + keywords = [""] + end + when /^#/ + when /^---/ + name = $' + if vide + output_def(text, names, keywords, fout) + text, names = [], [] + rep, indent, vide = '', -1, false + end + names.push name + else + vide = false + if line.sub!(/^(\s*): /, '* ') + indent += ($1 <=> rep) + rep = $1 + else + line.sub!(/^#{rep}/, '') + end + if indent >= 0 + line = (' ' * indent) + line + else + line.sub!(/\A\s*/, '') + end + text.push line + end + end +end + +File.open("#{ARGV[0]}.rb", "w") do |fout| + loop_file("../#{ARGV[0]}.rd", fout) + Dir['*.rd'].each do |file| + loop_file(file, fout) + end +end diff --git a/doc/mmap.rb b/doc/mmap.rb new file mode 100644 index 0000000..2c585a0 --- /dev/null +++ b/doc/mmap.rb @@ -0,0 +1,396 @@ +# The Mmap class implement memory-mapped file objects +# +# Most of these methods have the same syntax than the methods of String +# +# === WARNING +# === The variables $' and $` are not available with gsub! and sub! +class Mmap + include Comparable + include Enumerable + class << self + + #disable paging of all pages mapped. flag can be + #Mmap::MCL_CURRENT or Mmap::MCL_FUTURE + # + def lockall(flag) + end + + #create a new Mmap object + # + #* file + # + # Pathname of the file, if nil is given an anonymous map + # is created Mmanp::MAP_ANON + # + #* mode + # + # Mode to open the file, it can be "r", "w", "rw", "a" + # + #* protection + # + # specify the nature of the mapping + # + # * Mmap::MAP_SHARED + # + # Creates a mapping that's shared with all other processes + # mapping the same areas of the file. + # The default value is Mmap::MAP_SHARED + # + # * Mmap::MAP_PRIVATE + # + # Creates a private copy-on-write mapping, so changes to the + # contents of the mmap object will be private to this process + # + #* options + # + # Hash. If one of the options length or offset + # is specified it will not possible to modify the size of + # the mapped file. + # + # length:: maps length bytes from the file + # + # offset:: the mapping begin at offset + # + # advice:: the type of the access (see #madvise) + # + # + def new(file, mode = "r", protection = Mmap::MAP_SHARED, options = {}) + end + + #reenable paging + # + def unlockall + end + end + + #add count bytes to the file (i.e. pre-extend the file) + # + def extend(count) + end + + #advice can have the value Mmap::MADV_NORMAL, + #Mmap::MADV_RANDOM, Mmap::MADV_SEQUENTIAL, + #Mmap::MADV_WILLNEED, Mmap::MADV_DONTNEED + # + def madvise(advice) + end + + #change the mode, value must be "r", "w" or "rw" + # + def mprotect(mode) + end + + #disable paging + # + def mlock + end + + #flush the file + # + def msync + end + #same than msync + def flush + end + + #reenable paging + # + def munlock + end + + #terminate the association + def munmap + end + # + #=== Other methods with the same syntax than for the class String + # + # + + #comparison + # + def ==(other) + end + + #comparison + # + def >(other) + end + + #comparison + # + def >=(other) + end + + #comparison + # + def <(other) + end + + #comparison + # + def <=(other) + end + + #used for case comparison + # + def ===(other) + end + + #append other to self + # + def <<(other) + end + + #return an index of the match + # + def =~(other) + end + + #Element reference - with the following syntax + # + #self[nth] + # + #retrieve the nth character + # + #self[start..last] + # + #return a substring from start to last + # + #self[start, length] + # + #return a substring of lenght characters from start + # + def [](args) + end + + + # Element assignement - with the following syntax + # + # self[nth] = val + # + # change the nth character with val + # + # self[start..last] = val + # + # change substring from start to last with val + # + # self[start, len] = val + # + # replace length characters from start with val. + # + def []=(args) + end + + #comparison : return -1, 0, 1 + # + def self <=> other + end + + # only with ruby >= 1.7.1 + def casecmp(other) + end + + #append the contents of other + # + def concat(other) + end + + #change the first character to uppercase letter + # + def capitalize! + end + + #chop off the last character + # + def chop! + end + + #chop off the line ending character, specified by rs + # + def chomp!(rs = $/) + end + + #each parameter defines a set of character to count + # + def count(o1 [, o2, ...]) + end + + #crypt with salt + # + def crypt(salt) + end + + #delete every characters included in str + # + def delete!(str) + end + + #change all uppercase character to lowercase character + # + def downcase! + end + + #iterate on each byte + # + def each_byte + yield char + end + + #iterate on each line + # + def each(rs = $/) + yield line + end + #same than each + def each_line(rs = $/) + yield line + end + + #return true if the file is empty + # + def empty? + end + + #freeze the current file + # + def freeze + end + + #return true if the file is frozen + # + def frozen + end + + #global substitution + # + #str.gsub!(pattern, replacement) => str or nil + # + #str.gsub!(pattern) {|match| block } => str or nil + # + def gsub!(pattern, replacement = nil) + end + + #return true if other is found + # + def include?(other) + end + + #return the index of substr + # + def index(substr[, pos]) + end + + #insert str at index + # + def insert(index, str) >= 1.7.1 + end + + #return the size of the file + # + def length + end + + #convert pattern to a Regexp and then call + #match on self + def match(pattern) + end + + #reverse the content of the file + # + def reverse! + end + + #return the index of the last occurrence of substr + # + def rindex(substr[, pos]) + end + + #return an array of all occurence matched by pattern + # + def scan(pattern) + end + + #iterate through the file, matching the pattern + # + def scan(pattern) + yield str + end + + #return the size of the file + # + def size + end + + #same than [] + # + def slice + end + + #delete the specified portion of the file + # + def slice! + end + + #splits into a list of strings and return this array + # + def split([sep[, limit]]) + end + + #squeezes sequences of the same characters which is included in str + # + def squeeze!([str]) + end + + #removes leading and trailing whitespace + # + def strip! + end + + #removes leading whitespace + # + def lstrip! + end + + #removes trailing whitespace + # + def rstrip! + end + + #substitution + # + #str.sub!(pattern, replacement) => str or nil + # + #str.sub!(pattern) {|match| block } => str or nil + # + # + def sub!(pattern, replacement = nil) + end + + #return a checksum + # + def sum(bits = 16) + end + + #replaces all lowercase characters to uppercase characters, and vice-versa + # + def swapcase! + end + + #translate the character from search to replace + # + def tr!(search, replace) + end + + #translate the character from search to replace, then + #squeeze sequence of the same characters + # + def tr_s!(search, replace) + end + + #replaces all lowercase characters to downcase characters + # + def upcase! + end + + +end -- cgit v1.2.3