Top Level Namespace

Instance Method Summary collapse

Instance Method Details

#parseArgs(argc, nopt, single_opts, *opts) ⇒ Object

parseArgs is obsolete. Use OptionParser instead.


62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/parsearg.rb', line 62

def parseArgs(argc, nopt, single_opts, *opts)
  if (noOptions = getopts(single_opts, *opts)) == nil
    printUsageAndExit()
  end
  if nopt
    ex = nil
    pos = 0
    for o in nopt.split(/[()|&]/)
      pos += o.length
      ex = setExpression(ex, o, nopt[pos])
      pos += 1
    end
    begin
      if !eval(ex)
	printUsageAndExit()
      end
    rescue
      print "Format Error!! : \"" + nopt + "\"\t[parseArgs]\n"
      exit!(-1)
    end
  end
  if ARGV.length < argc
    printUsageAndExit()
  end
  return noOptions
end

#printUsageAndExitObject


19
20
21
22
23
24
# File 'lib/parsearg.rb', line 19

def printUsageAndExit()
  if $USAGE
    eval($USAGE)
  end
  exit()
end

#setExpression(ex, opt, op) ⇒ Object


44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/parsearg.rb', line 44

def setExpression(ex, opt, op)
  if !op
    ex = sprintf("%s$OPT_%s", ex, opt)
    return ex
  end
  case op.chr
  when "(", ")"
    ex = setParenthesis(ex, opt, op.chr)
  when "|", "&"
    ex = setOrAnd(ex, opt, op.chr)
  else
    return nil
  end
  return ex
end

#setOrAnd(ex, opt, c) ⇒ Object


35
36
37
38
39
40
41
42
# File 'lib/parsearg.rb', line 35

def setOrAnd(ex, opt, c)
  if opt != ""
    ex = sprintf("%s$OPT_%s %s%s ", ex, opt, c, c)
  else
    ex = sprintf("%s %s%s ", ex, c, c)
  end
  return ex
end

#setParenthesis(ex, opt, c) ⇒ Object


26
27
28
29
30
31
32
33
# File 'lib/parsearg.rb', line 26

def setParenthesis(ex, opt, c)
  if opt != ""
    ex = sprintf("%s$OPT_%s%s", ex, opt, c)
  else
    ex = sprintf("%s%s", ex, c)
  end
  return ex
end