Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions toolbox/RWTHMindstormsNXT/readFromIniFile.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function ret = readFromIniFile(AppName, KeyName, filename)
function ret = readFromIniFile(AppName, KeyName, filename) %#codegen
% Reads parameters from a configuration file (usually *.ini)
%
% Syntax
Expand Down Expand Up @@ -86,8 +86,8 @@
%% Try to read in inifile
fid = fopen(filename, 'r');
if fid < 0
warning('MATLAB:RWTHMindstormsNXT:couldNotOpenInifile', 'Ini-file "%s" was not found or could not be read.', filename);
return
error('MATLAB:RWTHMindstormsNXT:couldNotOpenInifile', ...
'Ini-file "%s" was not found or could not be read.', filename);
end%if

% input to a string
Expand All @@ -98,13 +98,14 @@
%% Separate lines and parse away
curSection = '';
curKey = '';
curVal = '';
while(~isempty(data))

% get next line by LFs
[curLine, data] = strtok(data, char(10)); %#ok<STTOK>
[curLine, data] = strtok(data, newline); %#ok<STTOK>

% remove whitespace (includes removing CRs if present)
curLine = strtrim(curLine);
% remove whitespace & comments (includes removing CRs if present)
curLine = strtrim(strtok(curLine, ';'));

% if line's empty or too short
if length(curLine) < 2
Expand All @@ -123,8 +124,8 @@
% ignore this line, it's a comment

% or if we have a key
elseif ~isempty(strfind(curLine, '=')) % found a =, it's a key
[curKey remainder] = strtok(curLine, '=');
elseif contains(curLine, '=') % found a =, it's a key
[curKey, remainder] = strtok(curLine, '=');
curVal = strtok(remainder, '=');
% remove whitespaces from tokens
curKey = strtrim(curKey);
Expand All @@ -144,4 +145,3 @@


end%function