class SiSU_Markup::MarkupIdentify

Public Class Methods

new(opt) click to toggle source
# File lib/sisu/sst_identify_markup.rb, line 80
def initialize(opt)
  @opt=opt
  @description='This is a script attempts to identify the version of markup used in SiSU (and provides information on changes in markup)'
end

Public Instance Methods

determine_markup_version() click to toggle source
# File lib/sisu/sst_identify_markup.rb, line 213
def determine_markup_version
  if @opt.fns.nil? \
  or @opt.fns.empty?
    MarkupHistory.new(@opt).help_identify
  end
  if File.exist?(@opt.fns)
    if @opt.fns =~/\.(?:sst|ssm|ssi|s[123i]|r[123])/
      markup=identify #(@opt.fns)
      if defined? markup.version
        unless @opt.act[:quiet][:set]==:on
          message=unless markup.declared_version.empty?
            "#{@opt.fns}\n  markup Type Declared as SiSU #{markup.declared_version} #{markup.declared_type}\n  appears to be SiSU #{markup.version}"
          else
            "Markup Type Appears to be SiSU #{markup.version}\n  in file #{@opt.fns}"
          end
          puts message
          puts %{"sisu --query-#{markup.version}" for a brief description of markup type}
        end
      end
    else puts 'file-type not recognised: ' + @opt.fns
    end
  else puts 'file not found: ' + @opt.fns
  end
  (defined? markup.version) \
  ? markup.version
  : 'markup type/version not determined'
end
help() click to toggle source
# File lib/sisu/sst_identify_markup.rb, line 84
    def help
    print <<WOK

#{@description}

WOK
      exit
    end
identify() click to toggle source
# File lib/sisu/sst_identify_markup.rb, line 92
def identify
  f=@opt.fns
  if f =~/(?:\.sst|\.ssm|\.ssi|\.s[123])$/ \
  and File.exist?(f)
    file=File.open(f,'r')
    cont=file.readlines
    file.close
    links,oldlinks='',''
    markup=nil
    @declared_type,@declared_markup='[text?]',''
    if cont[0] =~ /^(?:%\s+)?SiSU\s+(text|master|insert)\s+([0-9](?:\.[0-9]+){1,2})/ \
    or cont[0] =~ /^(?:%\s+)?sisu-([0-9](?:\.[0-9]+){1,2})/
      @declared_type,@declared_markup=$1,$2
    elsif cont[0] =~ /^(?:%\s+)?SiSU\s+([0-9](?:\.[0-9]+){1,2})/ \
    or cont[0] =~ /^(?:%\s+)?sisu-([0-9](?:\.[0-9]+){1,2})/
      @declared_markup=$1
    end
    @flag_2_0,@flag_1_0,@flag_69,@flag_66,@flag_57,@flag_38=false,false,false,false,false,false
    cont.each_with_index do |y,i|
      if y =~/^(?:0\{?~links?|@links?:)\s/ \
      and f =~/(?:\.sst|\.ssm|\.ssi|\.s[123])/
        links=unless y =~/\{.+?\}\S+/; oldlinks=' (pre 0.20.4 header links)'
        else ' (post 0.20.4 header links)'
        end
      end
      if @flag_2_0 \
      or y =~/^@make:|^@classify|^\s\s?:[a-z_-]+?:\s+\S/
        version=2.0.to_f
        markup=MarkupInform.new(version,'2.0' + oldlinks,@declared_markup,@declared_type)
        @flag_2_0=true
        break
      end
      unless @flag_38
        if (y =~/^:?A~/ and f =~/(?:\.sst|\.ssm|\.ssi)/)
          version='0.38'
          markup=MarkupInform.new(version,'0.38' + oldlinks,@declared_markup,@declared_type)
          @flag_38=true
        end
      end
      if @flag_38
        if @flag_1_0 \
        or y =~/^=\{.+?\}\s*$/
          version='0.69'
          markup=MarkupInform.new(version,'0.69' + oldlinks,@declared_markup,@declared_type)
          @flag_1_0=true
          break
        end
        if @flag_66 \
        or y =~/[a-z+][:;]\{.+?\}[:;][a-z+]/
          version='0.66'
          markup=MarkupInform.new(version,'0.66' + oldlinks,@declared_markup,@declared_type)
          @flag_66=true
          break
        end
      end
    end
    unless @flag_2_0 \
    or @flag_1_0 \
    or @flag_66
      cont.each_with_index do |y,i|
        if y =~/^(?:0\{?~links?|@links?:)\s/ \
        and f =~/(?:\.sst|\.ssm|\.ssi|\.s[123])/
          links=unless y =~/\{.+?\}\S+/; oldlinks=' (pre 0.20.4 header links)'
          else ' (post 0.20.4 header links)'
          end
        end
        if @flag_57 \
        or (y =~/^:?A~\?? @title/ and f =~/(?:\.sst|\.ssm|\.ssi)/)
          version='0.57'
          markup=MarkupInform.new(version,'0.57' + oldlinks,@declared_markup,@declared_type)
          @flag_57=true
          break
        end
        if @flag_38 \
        or (y =~/^:?A~/ and f =~/(?:\.sst|\.ssm|\.ssi)/)
          version='0.38'
          markup=MarkupInform.new(version,'0.38' + oldlinks,@declared_markup,@declared_type)
          @flag_38=true
          break if i >= 200
          if y =~ /(?:~{\*+|~\[\*|~\[\+)\s/
            version='0.42'
            markup=MarkupInform.new(version,'0.42' + oldlinks,@declared_markup,@declared_type)
            break
          end
        end
        if (y =~/^1~/ and f =~/(?:\.sst|\.ssm|\.ssi)/) \
        and not @flag_38
          version='0.37'
          markup=MarkupInform.new(version,'0.37 is substantially 0.16 - 0.36 markup with new file-extension' + oldlinks,@declared_markup,@declared_type)
          break
        end
        if y =~/^1~/ \
        and f =~/\.([rs])([123])/ \
        and not @flag_38
          t,n=$1,$2
          version='0.16'
          instruct=if t =~/r/
            " (change file extension from .#{t}#{n} to .ssm)"
          else " (change file extension from .#{t}#{n} to .sst)"
          end
          markup=MarkupInform.new(version,'0.16 - 0.36' + instruct + links,@declared_markup,@declared_type)
          break
        end
        if y =~/^0\{~/ \
        and not @flag_38
          version='0.1'
          markup=MarkupInform.new(version,'0.1 - 0.15',@declared_markup,@declared_type)
          break
        end
        if y =~/^0\{{3}/ \
        and not @flag_38
          markup=MarkupInform.new('circa. 1997','old, check date',@declared_markup,@declared_type)
          break
        end
        markup='Not a recognised file type '
      end
    end
    markup
  else MarkupHistory.new(@opt).help_query
  end
end
markup_version?() click to toggle source
# File lib/sisu/sst_identify_markup.rb, line 240
def markup_version?
  if @opt.fns.empty?
    @opt.files.each do |fns|
      @opt.fns=fns
      determine_markup_version
    end
  else determine_markup_version
  end
end