File: gtdoc.lua

package info (click to toggle)
genometools 1.6.2%2Bds-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 50,504 kB
  • sloc: ansic: 271,868; ruby: 30,327; python: 4,942; sh: 3,230; makefile: 1,214; perl: 219; pascal: 159; haskell: 37; sed: 5
file content (200 lines) | stat: -rw-r--r-- 5,291 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
--[[
  Copyright (c) 2008-2011 Gordon Gremme <gordon@gremme.org>
  Copyright (c) 2008      Center for Bioinformatics, University of Hamburg

  Permission to use, copy, modify, and distribute this software for any
  purpose with or without fee is hereby granted, provided that the above
  copyright notice and this permission notice appear in all copies.

  THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
]]

require 'gtdoclib'

function usage()
  io.stderr:write(string.format("Usage: [-html] [-lua] [-tex] [-v] %s " ..
                                "gt_home\n", arg[0]))
  io.stderr:write("Generate documentation for the GenomeTools home " ..
                  "directory gt_home.\n")
  os.exit(1)
end

local be_verbose    = false
local in_mode       = "C"
local out_mode      = "txt"
local file_mode     = false
local file_list     = {}

if #arg >= 1 then
  while #arg >= 1 and string.match(arg[1], "^-") do
    if string.match(arg[1], "^-f") then
      file_mode = true
      table.remove(arg, 1)
      while #arg > 1 and not string.match(arg[1], "^-") do
        file_list[#file_list+1] = arg[1]
        table.remove(arg, 1)
      end
    elseif string.match(arg[1], "^-h") then
      out_mode = "html"
      table.remove(arg, 1)
    elseif string.match(arg[1], "^-t") then
      out_mode = "latex"
      table.remove(arg, 1)
    elseif string.match(arg[1], "^-l") then
      in_mode = "Lua"
      table.remove(arg, 1)
    elseif string.match(arg[1], "^-v") then
      be_verbose = true
      table.remove(arg, 1)
    end
  end
  if #arg == 1 then
    gt_home = arg[1]
  else
    usage()
  end
else
  usage()
end

local template_path = gt_home .. "/gtdata/modules/gtdoclib/"

local export_C   = { "src/core",
                     "src/extended",
                     "src/annotationsketch" }

local export_Lua = { "src/gtlua",
                     "gtdata/modules/gtlua.lua",
                     "gtdata/modules/gtlua" }

local doc_parser      = DocParser:new()
local doc_base        = DocBase:new()

local function show_rec_array(array, depth)
  assert(array)
  for _, v in ipairs(array) do
    if type(v) == "table" then
      print("<edge>")
      show_rec_array(v, depth + 2)
    else
      local indent = string.rep(".", depth)
      print(string.format("%s%s", indent, v))
    end
  end
end

local function process_file(filename, be_verbose, is_lua)
  assert(filename)
  if (is_lua and (is_header(filename) or is_lua_file(filename))) or
     (not is_lua and is_api_header(filename)) then
    local ast = doc_parser:parse(filename, be_verbose, is_lua)
    if ast and be_verbose then
      print("showing ast:")
      show_rec_array(ast, 0)
    end
    if ast then
      doc_base:process_ast(ast, be_verbose)
    end
  end
end

local function process_single_file(filename, be_verbose, is_lua)
  assert(filename)
  if (is_header(filename) or is_lua_file(filename)) then
    local ast = doc_parser:parse(filename, be_verbose, is_lua)
    if ast and be_verbose then
      print("showing ast:")
      show_rec_array(ast, 0)
    end
    if ast then
      doc_base:process_ast(ast, be_verbose)
    end
  end
end

local function iter (a, i) -- taken from PiL, page 59
  i = i + 1
  local v = a[i]
  if v then
    return i, v
  end
end

function sorted_dir(dir)
  local entries = {}
  local i = 0
  for name in lfs.dir(dir) do
    i = i + 1
    entries[i] = name
  end
  table.sort(entries)
  return iter, entries, 0
end

local export = nil
local is_lua = nil

if in_mode == "C" then
  export = export_C
  is_lua = false
else
  assert(in_mode == "Lua")
  export = export_Lua
  is_lua = true
end

assert(export)

if file_mode then
  for _, f in ipairs(file_list) do
    local filename = gt_home .. "/" .. f
    process_single_file(filename, be_verbose, is_lua)
  end
else
  for _, v in ipairs(export) do
    local filename = gt_home .. "/" .. v
    if is_dir(filename) then
      for _, f in sorted_dir(filename) do
        local filename = filename .. "/" .. f
        process_file(filename, be_verbose, is_lua)
      end
    else
      process_file(filename, be_verbose, is_lua)
    end
  end
end

local doc_visitor
if out_mode == "txt" then
  doc_visitor = DocVisitorTxt:new()
  doc_base:accept(doc_visitor)
elseif out_mode == "latex" then
  local header
  if in_mode == "C" then
    header = "libgenometools_header_latex.lp"
  else
    header = "gtscript_header_latex.lp"
  end
  doc_visitor = DocVisitorLaTeX:new(template_path, header)
  doc_visitor:show_header()
  doc_base:accept(doc_visitor)
  doc_visitor:show_footer()
else
  assert(out_mode == "html")
  local header
  if in_mode == "C" then
    header = "libgenometools_header.lp"
  else
    header = "gtscript_header.lp"
  end
  doc_visitor = DocVisitorHTML:new(template_path, header)
  doc_visitor:show_header()
  doc_base:accept(doc_visitor)
  doc_visitor:show_footer()
end