Skip to content
Snippets Groups Projects
Commit 6e0d8d26 authored by Mark Winter's avatar Mark Winter
Browse files

Modified matlab BuildMex script to handle new 'Info' command output format

parent 5ef8ea51
No related branches found
No related tags found
No related merge requests found
......@@ -9,6 +9,12 @@ function BuildMexObject(mexFile, objectName, parentPackage)
commandList = mexFunc('Info');
cd(oldPath);
% Delete old function definitions
if ( exist(['@' objectName], 'dir') )
delete(fullfile(['@' objectName], '*.m'));
end
makeClassdef(objectName, mexName, commandList);
for i=1:length(commandList)
makeStaticMethod(objectName, mexName, commandList(i), parentPackage);
......@@ -44,25 +50,37 @@ end
function makeStaticMethod(objectName, mexName, commandInfo, parentPackage)
methodFile = fopen(fullfile(['@' objectName],[commandInfo.command '.m']), 'wt');
helpLines = strsplit(commandInfo.help, '\n', 'CollapseDelimiters',false);
validIdx = find(cellfun(@(x)(~isempty(x)), helpLines));
validLines = helpLines(validIdx);
% Autogenerated help has is organized so that the first two nonempy lines are:
% 1. Internal command usage
% 2. Command Summary
% 3. ... Additional help lines
% Ignore first helpline (internal usage string) which is replaced by prototypeString()
summaryString = '';
if ( length(commandInfo.helpLines) < 2 )
summaryString = [makePrototypeString(commandInfo) ' '];
end
if ( ~isempty(commandInfo.helpLines) )
summaryString = [summaryString commandInfo.helpLines{1}];
if ( length(validLines) >= 2 )
% Second line is the 'command summary'
summaryString = validLines{2};
end
% Write top line as <Command> - <Summary>, Summary may be empty
fprintf(methodFile, '%% %s - %s\n', commandInfo.command, summaryString);
if ( length(commandInfo.helpLines) > 1 )
fprintf(methodFile, '%% %s\n', makePrototypeString(commandInfo,objectName,parentPackage,true));
end
% Write call protoype string
fprintf(methodFile, '%% %s\n', makePrototypeString(commandInfo,objectName,parentPackage,true));
for i=2:length(commandInfo.helpLines)
fprintf(methodFile, '%% %s\n', commandInfo.helpLines{i});
% Write remaining help lines directly
if ( length(validIdx) > 2 )
for i=validIdx(3):length(helpLines)
fprintf(methodFile, '%% %s\n', helpLines{i});
end
end
% Output function body
fprintf(methodFile, 'function %s\n', makePrototypeString(commandInfo));
fprintf(methodFile, ' %s;\n', makeCommandString(objectName, mexName,commandInfo,parentPackage));
fprintf(methodFile, 'end\n');
......@@ -75,6 +93,7 @@ function commandString = makeCommandString(objectName, mexName, commandInfo, par
if ( ~isempty(commandInfo.outArgs) )
commandString = ['[' makeCommaList(commandInfo.outArgs) '] = '];
end
if ( ~exist('parentPackage','var') )
parentPackage = [];
else
......@@ -123,26 +142,15 @@ function protoString = makePrototypeString(commandInfo, objectName, parentPackag
protoString = [protoString ')'];
end
function commaStr = makeCommaList(inList, leaveOptBrackets)
function commaStr = makeCommaList(inStr, leaveOptBrackets)
if (~exist('leaveOptBrackets','var') || isempty(leaveOptBrackets))
leaveOptBrackets = false;
end
commaStr = '';
if ( isempty(inList) )
return;
end
for i=1:length(inList)-1
commaStr = [commaStr removeOptBrackets(inList{i}, leaveOptBrackets) ','];
end
commaStr = [commaStr removeOptBrackets(inList{end}, leaveOptBrackets)];
end
function argName = removeOptBrackets(argName, leaveOptBrackets)
if ( ~leaveOptBrackets )
argName = regexprep(argName, '\[(\w+)\]', '$1');
if ( leaveOptBrackets )
commaStr = inStr;
else
commaStr = regexprep(inStr, '\[(\w+)\]', '$1');
end
end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment