summaryrefslogtreecommitdiff
path: root/src/index.rb
diff options
context:
space:
mode:
Diffstat (limited to 'src/index.rb')
-rwxr-xr-xsrc/index.rb27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/index.rb b/src/index.rb
new file mode 100755
index 0000000..c719fcc
--- /dev/null
+++ b/src/index.rb
@@ -0,0 +1,27 @@
+require 'pathname'
+
+puts %Q[
+ CREATE TABLE searchIndex(id INTEGER PRIMARY KEY, name TEXT, type TEXT, path TEXT);
+ CREATE UNIQUE INDEX anchor ON searchIndex (name, type, path);
+]
+
+INSERT_SQL = %Q[
+ INSERT INTO searchIndex(name, type, path) VALUES ('%s','%s','%s');
+]
+
+PATTERN = %r[<title>GNU make: (.+)</title>]
+
+def quote(s)
+ s.gsub(/&amp;/, '&').gsub(/'/, "\\'")
+end
+
+ARGV.each do |arg|
+ Pathname.glob(arg) do |path|
+ match = path.each_line.lazy.map { |line| PATTERN.match(line) }.find { |m| m }
+ if match
+ printf INSERT_SQL, quote(match[1]), 'Guide', path.basename
+ else
+ $stderr.puts "%{path.basename}: no title found"
+ end
+ end
+end