Code covered by the BSD License  

Highlights from
publish_plus

image thumbnail
from publish_plus by Michael Wild
Extends the PUBLISH function provided by MATLAB to pdf, ps and dvi and all

includefuns(dom)
function dom = includefuns(dom)
% INCLUDEFUNS Process INCLUDE statements in code

%--------------------------------------------------------------------------
% Author    : Michael Wild
% Email     : themiwi@student.ethz.ch
% Copyright 2005-2005
%
% Created   : 2005.05.10, 08:58
% Version   : 0.1
%
% DISCLAIMER
% ==========
%
% The software provided by me with this Matlab function and the altered
% version of the original PUBLISH function by The Mathworks are purely
% experimental. You use it at your own risk. I am not responible for any
% harm or damage caused by it.

inc = {};
inccode = [];
cellList = dom.getElementsByTagName('cell');
for n = 1:cellList.getLength
    mcodeList = cellList.item(n-1).getElementsByTagName('mcode');
    if (mcodeList.getLength > 0) && (mcodeList.item(0).getLength > 0)
        mcode = char(mcodeList.item(0).getFirstChild.getData);
    else
        mcode = '';
    end
    % Get the include names
    [inc,mcode] = getincludes(mcode);
%     inc = [inc, i1];
    % Read the files
    if ~isempty(inccode)
        inccode = [];
    end
    for i = 1:length(inc)
       inccode = [inccode,file2char(locateFile(inc{i}))];
    end
    if ~isempty(inccode)
        mcode = [cell2str(mcode),inccode];
        mcodeList.item(0).getFirstChild.setData(mcode);
    end
end


function [inc,mcode] = getincludes(mcode)
% find lines beginning with %#INCLUDE and return the following word
inc = {};
mcode = str2cell(mcode);
tok = strmatch('%#INCLUDE',mcode);
for i=tok'
    j = [strfind(mcode{i},' '),length(mcode{i})];
    inc = [inc,{mcode{i}(j(1)+1:j(2))}];
end
mcode(tok) = [];

function c = str2cell( str )
% break str into a cell string. use \n as deliminiter
i = [0,strfind(str,char(10)),length(str)+1];
c = {};
for j=2:length(i)
    c{end+1} = str(i(j-1)+1:i(j)-1);
end

function str = cell2str( c )
% concat a string from a cell string, use \n as delimiter
str = [];
for i=1:length(c)
    str = sprintf('%s\n%s',str,c{i});
end

Contact us at files@mathworks.com