From 884f34af66fb3fb67030d82d39b11443afabeff1 Mon Sep 17 00:00:00 2001
From: glenux <glenux@eaee96b3-f302-0410-b096-c6cfd47f7835>
Date: Sun, 24 Jan 2010 18:31:02 +0000
Subject: [PATCH] sshfs-mapper: Finish & fix map parsing.

git-svn-id: https://websvn.glenux.net/svn/Upoc/sshfs-mapper/trunk@1518 eaee96b3-f302-0410-b096-c6cfd47f7835
---
 map.rb | 34 +++++++++++++++++++++++++---------
 1 file changed, 25 insertions(+), 9 deletions(-)

diff --git a/map.rb b/map.rb
index a1c4b56..333087a 100644
--- a/map.rb
+++ b/map.rb
@@ -1,6 +1,11 @@
 module SshfsMapper
+
 	class Map 
 		attr_reader :path, :host, :port, :user, :map
+		@@debug = false
+
+		class MapParseError < RuntimeError
+		end
 
 		def initialize( map_path )
 			@path = map_path
@@ -11,26 +16,37 @@ module SshfsMapper
 			@maps = {}
 		end
 
-		def parse()
+		def parse
 			puts "Parsing map #{@path}"
 			f = File.open( @path )
+			linect = 0
 			f.each do |line|
+				line = line.strip
+				linect += 1
+
+				#puts "  [#{line}]"
 				case line
-				when /^\s*REMOTE_USER\s*=\s*(.*)\s*$/
+				when /^\s*REMOTE_USER\s*=\s*(.*)\s*$/ then
 					@user = $1
-				when /^\s*REMOTE_PORT\s*=\s*(.*)\s*$/
+					puts "d: remote_user => #{$1}" if @@debug
+				when /^\s*REMOTE_PORT\s*=\s*(.*)\s*$/ then
 					@port = $1.to_i
-				when /^\s*REMOTE_HOST\s*=\s*(.*)\s*$/
+					puts "d: remote_port => #{$1}" if @@debug
+				when /^\s*REMOTE_HOST\s*=\s*(.*)\s*$/ then
 					@host = $1
-				when /^\s*REMOTE_CYPHER\s*=\s*(.*)\s*$/
-					idx = ["arcfour", "aes-256-cbc"].index( $1 )
-					if not idx.nil? then
+					puts "d: remote_host => #{$1}" if @@debug
+				when /^\s*REMOTE_CYPHER\s*=\s*(.*)\s*$/ then
+					cyphers = ["arcfour", "aes-256-cbc"]
+					if cyphers.include? $1 then
 						@host = $1
 					end
-				when /^\s*MAP\s*=\s*(.*)\s+(.*)\s*$/
+				when /^\s*MAP\s*=\s*(.*)\s+(.*)\s*$/ then
 					@maps[$1] = $2
+					puts "d: map #{$1} => #{$2}" if @@debug
+				when /^\s*$/ then
+					puts "d: dropping empty line" if @@debug
 				else
-					puts "dropping #{line}"
+					raise MapParseError, "parse error at #{@path}:#{linect}"
 				end
 			end
 			f.close