diff options
author | Christopher Lenz <cmlenz@apache.org> | 2008-08-30 10:26:51 +0000 |
---|---|---|
committer | Christopher Lenz <cmlenz@apache.org> | 2008-08-30 10:26:51 +0000 |
commit | fae1935ffc8ee0c4096bbb327f69a24c7b58c2c1 (patch) | |
tree | 14d23f0de4a0868decd1b0055f44a1cd0e7f3e05 /src/couchdb/couch_config_writer.erl | |
parent | 39902f39104e3ba33b7fc8c825e7b49136bb104d (diff) |
Some cosmetic cleanup (removed trailing whitespace, fixed indentation, make the test runner script executable).
git-svn-id: https://svn.apache.org/repos/asf/incubator/couchdb/trunk@690487 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/couchdb/couch_config_writer.erl')
-rw-r--r-- | src/couchdb/couch_config_writer.erl | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/src/couchdb/couch_config_writer.erl b/src/couchdb/couch_config_writer.erl index 6e93c131..6a56c96e 100644 --- a/src/couchdb/couch_config_writer.erl +++ b/src/couchdb/couch_config_writer.erl @@ -24,24 +24,24 @@ -export([save_to_file/2]). %% @spec save_to_file( -%% Config::{{Module::string(), Variable::string()}, Value::string()}, +%% Config::{{Module::string(), Variable::string()}, Value::string()}, %% File::filename()) -> ok %% @doc Saves a Module/Key/Value triple to the ini file File::filename() save_to_file({{Module, Variable}, Value}, File) -> - + ?LOG_DEBUG("saving to file '~s', Congif: '~p'", [File, {{Module, Variable}, Value}]), - + % open file and create a list of lines {ok, Stream} = file:read_file(File), OldFileContents = binary_to_list(Stream), {ok, Lines} = regexp:split(OldFileContents, "\r\n|\n|\r|\032"), - + % prepare input variables ModuleName = "[" ++ Module ++ "]", VariableList = Variable, - + % produce the contents for the config file - NewFileContents = + NewFileContents = case NewFileContents2 = save_loop({{ModuleName, VariableList}, Value}, Lines, "", "", []) of % we didn't change anything, that means we couldn't find a matching % [ini section] in which case we just append a new one. @@ -50,7 +50,7 @@ save_to_file({{Module, Variable}, Value}, File) -> _ -> NewFileContents2 end, - + % do the save, close the config file and get out save_file(File, NewFileContents), file:close(Stream), @@ -102,7 +102,7 @@ save_loop({{Module, Variable}, Value}, [Line|Rest], OldCurrentModule, Contents, % go to next line save_loop({{Module, Variable}, Value}, Rest, NewCurrentModule, Contents2 ++ NewContents, DoneVariables2); - + save_loop(_Config, [], _OldModule, NewFileContents, _DoneVariable) -> % we're out of new lines, just return the new file's contents NewFileContents. @@ -111,7 +111,7 @@ append_new_ini_section({{ModuleName, Variable}, Value}, OldFileContents) -> OldFileContents ++ "\n\n" ++ ModuleName ++ "\n" ++ Variable ++ "=" ++ Value ++ "\n". %% @spec parse_module(Lins::string(), OldModule::string()) -> string() -%% @doc Tries to match a line against a pattern specifying a ini module or +%% @doc Tries to match a line against a pattern specifying a ini module or %% section ("[Module]"). Returns OldModule if no match is found. parse_module(Line, OldModule) -> case regexp:match(Line, "^\\[([a-zA-Z0-9_-]*)\\]$") of @@ -140,7 +140,7 @@ parse_variable(Line, Variable, Value) -> Variable ++ "=" ++ Value end. -%% @spec save_file(File::filename(), Contents::string()) -> +%% @spec save_file(File::filename(), Contents::string()) -> %% ok | {error, Reason::string()} %% @doc Writes Contents to File save_file(File, Contents) -> |