pwritespecconstructioncmd.m

来自「利用Stateflow 进行嵌入式代码开发很好用」· M 代码 · 共 66 行

M
66
字号
function txtBuffer = pWriteSpecConstructionCmd(iStruct, type)
%PWRITESPECCONSTRUCTIONCMD Writes the ML construction commands needed to
%   fill the specification structure, generate the c-mex, build the c-mex 
%   and generate tlc block file according to the ISTRUCT content.
%

%   Copyright 2005 The MathWorks, Inc.
%   $File: $
%   $Revision: $
%   $Date:  $

error(nargchk(1, 2, nargin));

% for TLC or C ?
if nargin < 2
    type = 'c';
else
    type = lower(type);
end

% get input struture fieldnames
fieldNames = fieldnames(iStruct);

% initialize output buffer
txtBuffer = [];

% first initialize the structure defintion
txtBuffer = [txtBuffer, sprintf('     def = legacy_code_initialize;\n')];

% walk through the structure fields
for ii = 1:length(fieldNames)
    
    switch class(iStruct.(fieldNames{ii}))
        case 'char'
            if ~isempty(iStruct.(fieldNames{ii}))
                txtBuffer = [txtBuffer, ...
                    sprintf('     def.%s = ''%s'';\n', fieldNames{ii}, iStruct.(fieldNames{ii}))];
            end

        case 'cell'

            if ~cellfun('isempty', iStruct.(fieldNames{ii}))
                txtBuffer = [txtBuffer, ...
                    sprintf('     def.%s = {', fieldNames{ii})];
                sep = '';
                c = char(iStruct.(fieldNames{ii}));
                for jj = 1:size(c, 1)
                    txtBuffer = [txtBuffer, ...
                        sprintf('%s''%s''', sep, deblank(c(jj, :)))];
                    sep = ', ';
                end
                txtBuffer = [txtBuffer, sprintf('};\n')];
            end

        otherwise

    end
end

if strcmp(type, 'c')
    txtBuffer = [txtBuffer, sprintf('     legacy_code_sfcn_cmex_generate(def);\n')];
    txtBuffer = [txtBuffer, sprintf('     legacy_code_compile(def);\n')];
else
    txtBuffer = [txtBuffer, sprintf('     legacy_code_sfcn_tlc_generate(def);\n')];
end

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?