<?xml version="1.0" encoding="iso-8859-1" ?>
<!DOCTYPE mfile SYSTEM "matlab.dtd">
<mfile name="highlight.m">
<line nb="0001 "><keyword>function</keyword> highlight(mfile,options,outfile)</line>
<line nb="0002 "><comment>%HIGHLIGHT - Syntax Highlighting of Matlab M-files in HTML, LaTeX, RTF and XML.</comment></line>
<line nb="0003 "><comment>%  HIGHLIGHT(MFILE) takes an M-file MFILE in input and writes on disk an HTML</comment></line>
<line nb="0004 "><comment>%  file with the same basename ('foo.m' =&gt; 'foo.html') adding colored syntax </comment></line>
<line nb="0005 "><comment>%  highlighting on comment, string and Matlab keyword elements.</comment></line>
<line nb="0006 "><comment>%  HIGHLIGHT(MFILE,OPTIONS) with OPTIONS being string 'html', 'xhtml', 'tex', </comment></line>
<line nb="0007 "><comment>%  'rtf' or 'xml', allows to choose the output format between HTML, XHTML, LaTeX</comment></line>
<line nb="0008 "><comment>%  RTF or XML. The same rule is used to determine the name of the output file.</comment></line>
<line nb="0009 "><comment>%  HIGHLIGHT(MFILE,OPTIONS) allows to specify some options in a structure:</comment></line>
<line nb="0010 "><comment>%     options.type - Output file type </comment></line>
<line nb="0011 "><comment>%             [ {'html'} | 'tex' | 'rtf' | 'xml' | 'xhtml']</comment></line>
<line nb="0012 "><comment>%     options.tabs - Replace '\t' in source code by n white space</comment></line>
<line nb="0013 "><comment>%                           [ 0 ... {4}  ... n]</comment></line>
<line nb="0014 "><comment>%     options.linenb - Display line number in front of each line [ 0 | {1} ]</comment></line>
<line nb="0015 "><comment>%  HIGHLIGHT(MFILE,OPTIONS,OUTFILE) allows to specify the name of the output </comment></line>
<line nb="0016 "><comment>%  file. OUTFILE can also be a file handle. In that case, no header will be </comment></line>
<line nb="0017 "><comment>%  written, only the highlighted Matlab code will be sent to the OUTFILE stream.</comment></line>
<line nb="0018 "></line>
<line nb="0019 "><comment>%  Output file can be customized (font style, font color, font size, ...):</comment></line>
<line nb="0020 "><comment>%     o HTML: use CSS (Cascading Style Sheets) to define 'comment', 'string', </comment></line>
<line nb="0021 "><comment>%       'keyword', 'cont' and 'code' SPAN elements and 'mcode' PRE tag.</comment></line>
<line nb="0022 "><comment>%     o LaTeX: packages 'alltt' and 'color' are required, you can modify colors</comment></line>
<line nb="0023 "><comment>%       in defining colors 'string', 'comment' and 'keyword' using command</comment></line>
<line nb="0024 "><comment>%                      \definecolor{mycolor}{rgb}{a,b,c}</comment></line>
<line nb="0025 "><comment>%     o RTF: Colors are defined in the Color Table at the beginning of the</comment></line>
<line nb="0026 "><comment>%       document. See Rich Text Format Specifications for more details:</comment></line>
<line nb="0027 "><comment>%       &lt;http://msdn.microsoft.com/library/en-us/dnrtfspec/html/rtfspec.asp&gt;</comment></line>
<line nb="0028 "><comment>%     o XML: you will find the DTD of the resulting XML file in matlab.dtd</comment></line>
<line nb="0029 "><comment>%       You can then use XSL to transform your XML file in what you want.</comment></line>
<line nb="0030 "><comment>%       For example, mat2html.xsl transforms your XML file in HTML as it would</comment></line>
<line nb="0031 "><comment>%       be if you would have used highlight.m to to so.</comment></line>
<line nb="0032 "><comment>%       On Matlab 6.5, the command is:</comment></line>
<line nb="0033 "><comment>%               xslt highlight.xml mat2html.xsl highlight.html</comment></line>
<line nb="0034 "><comment>%       On Linux, using libxslt &lt;http://xmlsoft.org/XSLT/&gt;, the command is: </comment></line>
<line nb="0035 "><comment>%               xsltproc -o highlight.html mat2html.xsl highlight.xml</comment></line>
<line nb="0036 "></line>
<line nb="0037 "><comment>%  Copyright (C) 2003 Guillaume Flandin &lt;Guillaume [at] artefact.tk&gt;</comment></line>
<line nb="0038 "><comment>%  $Revision: 1.1 $Date: 2003/09/07 15:39:33 $</comment></line>
<line nb="0039 "></line>
<line nb="0040 "><comment>%  This program is free software; you can redistribute it and/or</comment></line>
<line nb="0041 "><comment>%  modify it under the terms of the GNU General Public License</comment></line>
<line nb="0042 "><comment>%  as published by the Free Software Foundation; either version 2</comment></line>
<line nb="0043 "><comment>%  of the License, or any later version.</comment></line>
<line nb="0044 "><comment>% </comment></line>
<line nb="0045 "><comment>%  This program is distributed in the hope that it will be useful,</comment></line>
<line nb="0046 "><comment>%  but WITHOUT ANY WARRANTY; without even the implied warranty of</comment></line>
<line nb="0047 "><comment>%  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</comment></line>
<line nb="0048 "><comment>%  GNU General Public License for more details.</comment></line>
<line nb="0049 "><comment>% </comment></line>
<line nb="0050 "><comment>%  You should have received a copy of the GNU General Public License</comment></line>
<line nb="0051 "><comment>%  along with this program; if not, write to the Free Software</comment></line>
<line nb="0052 "><comment>%  Foundation Inc, 59 Temple Pl. - Suite 330, Boston, MA 02111-1307, USA.</comment></line>
<line nb="0053 "></line>
<line nb="0054 "><comment>% Suggestions for improvement and fixes are always welcome, although no</comment></line>
<line nb="0055 "><comment>% guarantee is made whether and when they will be implemented.</comment></line>
<line nb="0056 "><comment>% Send requests to Guillaume [at] artefact.tk</comment></line>
<line nb="0057 "></line>
<line nb="0058 "><comment>%- Set up options</comment></line>
<line nb="0059 ">error(nargchk(1,3,nargin));</line>
<line nb="0060 "></line>
<line nb="0061 ">opt = struct(<string>'type'</string>,   <string>'html'</string>, <cont>...</cont></line>
<line nb="0062 ">             <string>'tabs'</string>,   4, <cont>...</cont></line>
<line nb="0063 ">             <string>'linenb'</string>, 1, <cont>...</cont></line>
<line nb="0064 ">             <string>'indent'</string>, 0);</line>
<line nb="0065 "><keyword>if</keyword> nargin &gt;= 2</line>
<line nb="0066 ">    <keyword>if</keyword> isstruct(options)</line>
<line nb="0067 ">        names = fieldnames(options);</line>
<line nb="0068 ">        <keyword>for</keyword> i=1:length(names)</line>
<line nb="0069 ">            opt = setfield(opt,names{i},getfield(options,names{i}));</line>
<line nb="0070 ">        <keyword>end</keyword></line>
<line nb="0071 ">    <keyword>elseif</keyword> ischar(options)</line>
<line nb="0072 ">        opt.type = options;</line>
<line nb="0073 ">    <keyword>else</keyword></line>
<line nb="0074 ">        error(<string>'Bad input argument.'</string>);</line>
<line nb="0075 ">    <keyword>end</keyword></line>
<line nb="0076 "><keyword>end</keyword></line>
<line nb="0077 "><keyword>if</keyword> strcmp(lower(opt.type),<string>'latex'</string>), opt.type = <string>'tex'</string>; <keyword>end</keyword></line>
<line nb="0078 "><keyword>if</keyword> strcmp(lower(opt.type),<string>'xml'</string>), opt.linenb = 1; <keyword>end</keyword></line>
<line nb="0079 "></line>
<line nb="0080 "><comment>%- If no output filename is provided, one is chosen according to mfile</comment></line>
<line nb="0081 "><keyword>if</keyword> nargin &lt; 3</line>
<line nb="0082 ">    [pathstr, name, ext] = fileparts(mfile);</line>
<line nb="0083 ">    outfile = fullfile(pathstr, [name, <string>'.'</string> lower(opt.type)]);</line>
<line nb="0084 "><keyword>end</keyword></line>
<line nb="0085 "></line>
<line nb="0086 "><comment>%- If an output filename is provided, a standard header is created</comment></line>
<line nb="0087 "><keyword>if</keyword> ischar(outfile)</line>
<line nb="0088 ">    outfid = fopen(outfile,<string>'wt'</string>);</line>
<line nb="0089 ">    <keyword>if</keyword> outfid == -1</line>
<line nb="0090 ">        error(sprintf(<string>'Cannot open '</string>,outfile));</line>
<line nb="0091 ">    <keyword>end</keyword></line>
<line nb="0092 ">    feval([lower(opt.type) <string>'_file_start'</string>],outfid,mfile);</line>
<line nb="0093 "><comment>%- Otherwise a file handle is provided</comment></line>
<line nb="0094 "><keyword>else</keyword></line>
<line nb="0095 ">    outfid = outfile;</line>
<line nb="0096 "><keyword>end</keyword></line>
<line nb="0097 "></line>
<line nb="0098 "><comment>%- Open the Matlab mfile to be highlighted</comment></line>
<line nb="0099 ">mfid = fopen(mfile,<string>'rt'</string>);</line>
<line nb="0100 "><keyword>if</keyword> mfid == -1</line>
<line nb="0101 ">    error(sprintf(<string>'Cannot open '</string>,mfile));</line>
<line nb="0102 "><keyword>end</keyword></line>
<line nb="0103 "></line>
<line nb="0104 "><comment>%- Write the syntax highlighted mfile code in the output file</comment></line>
<line nb="0105 ">write_highlighted_code(mfid,outfid,opt)</line>
<line nb="0106 "></line>
<line nb="0107 "><comment>%- Close the Matlab mfile and potentially the output file</comment></line>
<line nb="0108 ">fclose(mfid);</line>
<line nb="0109 "><keyword>if</keyword> ischar(outfile), </line>
<line nb="0110 ">    feval([lower(opt.type) <string>'_file_end'</string>],outfid);</line>
<line nb="0111 ">    fclose(outfid); </line>
<line nb="0112 "><keyword>end</keyword></line>
<line nb="0113 "></line>
<line nb="0114 "><comment>%===============================================================================</comment></line>
<line nb="0115 "><keyword>function</keyword> write_highlighted_code(mfid,outfid,opt)</line>
<line nb="0116 ">    matlabKeywords = getMatlabKeywords;</line>
<line nb="0117 ">    mKeySort       = getMatlabKeywordsSorted;</line>
<line nb="0118 ">    out_format     = feval([lower(opt.type) <string>'_format'</string>]);</line>
<line nb="0119 ">    strtok_delim   = sprintf(<string>' \t\n\r(){}[]&lt;&gt;+-*~!|\\@&amp;/.,:;=&quot;''%'</string>);</line>
<line nb="0120 ">    </line>
<line nb="0121 ">    fprintf(outfid,out_format.pre_start);</line>
<line nb="0122 ">    nbline = 1;</line>
<line nb="0123 ">    nbblanks = 0;</line>
<line nb="0124 ">    flagnextline = 0;</line>
<line nb="0125 ">    <keyword>while</keyword> 1</line>
<line nb="0126 ">        tline = fgetl(mfid);</line>
<line nb="0127 ">        <keyword>if</keyword> ~ischar(tline), <keyword>break</keyword>, <keyword>end</keyword></line>
<line nb="0128 ">        tline = feval([lower(opt.type) <string>'_special_char'</string>],horztab(tline,opt.tabs));</line>
<line nb="0129 ">        <comment>%- Display the line number at each line</comment></line>
<line nb="0130 ">        <keyword>if</keyword> opt.linenb</line>
<line nb="0131 ">            fprintf(outfid,out_format.nb_line,nbline);</line>
<line nb="0132 ">            nbline = nbline + 1;</line>
<line nb="0133 ">        <keyword>end</keyword></line>
<line nb="0134 ">        <comment>%- Remove blanks at the beginning of the line</comment></line>
<line nb="0135 ">        <keyword>if</keyword> opt.indent</line>
<line nb="0136 ">            tline = fliplr(deblank(fliplr(tline)));</line>
<line nb="0137 ">        <keyword>end</keyword></line>
<line nb="0138 ">        nbblanks = nbblanks + flagnextline;</line>
<line nb="0139 ">        flagnextline = 0;</line>
<line nb="0140 ">        <comment>%- Split code into meaningful chunks</comment></line>
<line nb="0141 ">        splitc = splitcode(tline);</line>
<line nb="0142 ">        newline = <string>''</string>;</line>
<line nb="0143 ">        <keyword>for</keyword> i=1:length(splitc)</line>
<line nb="0144 ">            <keyword>if</keyword> isempty(splitc{i})</line>
<line nb="0145 ">            <keyword>elseif</keyword> splitc{i}(1) == <string>''''</string></line>
<line nb="0146 ">                newline = [newline sprintf(out_format.string,splitc{i})];</line>
<line nb="0147 ">            <keyword>elseif</keyword> splitc{i}(1) == <string>'%'</string></line>
<line nb="0148 ">                newline = [newline sprintf(out_format.comment,splitc{i})];</line>
<line nb="0149 ">            <keyword>elseif</keyword> ~isempty(strmatch(<string>'...'</string>,splitc{i}))</line>
<line nb="0150 ">                newline = [newline sprintf(out_format.cont,<string>'...'</string>)];</line>
<line nb="0151 ">                <keyword>if</keyword> ~isempty(splitc{i}(4:end))</line>
<line nb="0152 ">                    newline = [newline sprintf(out_format.comment,splitc{i}(4:end))];</line>
<line nb="0153 ">                <keyword>end</keyword></line>
<line nb="0154 ">            <keyword>else</keyword></line>
<line nb="0155 ">                <comment>%- Look for Matlab keywords</comment></line>
<line nb="0156 ">                r = splitc{i};</line>
<line nb="0157 ">                stringcode = <string>''</string>;</line>
<line nb="0158 ">                <keyword>while</keyword> 1</line>
<line nb="0159 ">                    [t,r,q] = strtok(r,strtok_delim);</line>
<line nb="0160 ">                    stringcode = [stringcode q];</line>
<line nb="0161 ">                    <keyword>if</keyword> isempty(t), <keyword>break</keyword>, <keyword>end</keyword>;</line>
<line nb="0162 ">                    isNextIncr  = any(strcmp(t,mKeySort.nextincr));</line>
<line nb="0163 ">                    isNextIncr2 = any(strcmp(t,mKeySort.nextincr2));</line>
<line nb="0164 ">                    isCurrDecr  = any(strcmp(t,mKeySort.currdecr));</line>
<line nb="0165 ">                    isNextDecr  = any(strcmp(t,mKeySort.nextdecr));</line>
<line nb="0166 ">                    isOther     = any(strcmp(t,mKeySort.other));</line>
<line nb="0167 ">                    <keyword>if</keyword> isNextDecr <comment>% if strcmp(t,'end')</comment></line>
<line nb="0168 ">                        <comment>% 'end' is keyword or array subscript ?</comment></line>
<line nb="0169 ">                        rr = fliplr(deblank(fliplr(r)));</line>
<line nb="0170 ">                        icomma = strmatch(<string>','</string>,rr);</line>
<line nb="0171 ">                        isemicolon = strmatch(<string>';'</string>,rr);</line>
<line nb="0172 ">                        <keyword>if</keyword> ~(isempty(rr) | ~isempty([icomma isemicolon]))</line>
<line nb="0173 ">                            isNextDecr = 0;</line>
<line nb="0174 ">                        <keyword>else</keyword></line>
<line nb="0175 ">                            nbblanks = nbblanks - 1;</line>
<line nb="0176 ">                            flagnextline = flagnextline + 1;</line>
<line nb="0177 ">                        <keyword>end</keyword></line>
<line nb="0178 ">                        <comment>% TODO % false detection of a([end,1])</comment></line>
<line nb="0179 ">                    <keyword>end</keyword></line>
<line nb="0180 ">                    <keyword>if</keyword> isNextIncr, flagnextline = flagnextline + 1; <keyword>end</keyword></line>
<line nb="0181 ">                    <keyword>if</keyword> isNextIncr2, flagnextline = flagnextline + 2; <keyword>end</keyword></line>
<line nb="0182 ">                    <keyword>if</keyword> isNextDecr, flagnextline = flagnextline - 1; <keyword>end</keyword></line>
<line nb="0183 ">                    <keyword>if</keyword> isCurrDecr, nbblanks = nbblanks - 1; <keyword>end</keyword></line>
<line nb="0184 ">                    <comment>% if any(strcmp(t,matlabKeywords))</comment></line>
<line nb="0185 ">                    <keyword>if</keyword> isNextIncr | isNextIncr2 |isCurrDecr | isNextDecr | isOther</line>
<line nb="0186 ">                        <keyword>if</keyword> ~isempty(stringcode)</line>
<line nb="0187 ">                            newline = [newline sprintf(out_format.code,stringcode)];</line>
<line nb="0188 ">                            stringcode = <string>''</string>;</line>
<line nb="0189 ">                        <keyword>end</keyword></line>
<line nb="0190 ">                        newline = [newline sprintf(out_format.keyword,t)];</line>
<line nb="0191 ">                    <keyword>else</keyword></line>
<line nb="0192 ">                        stringcode = [stringcode t];</line>
<line nb="0193 ">                    <keyword>end</keyword></line>
<line nb="0194 ">                <keyword>end</keyword></line>
<line nb="0195 ">                <keyword>if</keyword> ~isempty(stringcode)</line>
<line nb="0196 ">                    newline = [newline sprintf(out_format.code,stringcode)];</line>
<line nb="0197 ">                <keyword>end</keyword></line>
<line nb="0198 ">            <keyword>end</keyword></line>
<line nb="0199 ">        <keyword>end</keyword></line>
<line nb="0200 ">        <keyword>if</keyword> ~opt.indent, nbblanks = 0; <keyword>end</keyword></line>
<line nb="0201 ">        <comment>%- Print the syntax highlighted line</comment></line>
<line nb="0202 ">        fprintf(outfid,out_format.line,[blanks(nbblanks*opt.tabs) newline]);</line>
<line nb="0203 ">    <keyword>end</keyword></line>
<line nb="0204 ">    fprintf(outfid,out_format.pre_end);</line>
<line nb="0205 "></line>
<line nb="0206 "><comment>%===============================================================================</comment></line>
<line nb="0207 "><comment>%                                  HTML FORMAT                                 %</comment></line>
<line nb="0208 "><comment>%===============================================================================</comment></line>
<line nb="0209 "><keyword>function</keyword> html_file_start(fid,mfile)</line>
<line nb="0210 ">    fprintf(fid,[ <cont>...</cont></line>
<line nb="0211 ">    <string>'&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;\n'</string> <cont>...</cont></line>
<line nb="0212 ">    <string>'\t&quot;http://www.w3.org/TR/REC-html40/loose.dtd&quot;&gt;\n'</string> <cont>...</cont></line>
<line nb="0213 ">    <string>'&lt;html&gt;\n&lt;head&gt;\n&lt;title&gt;%s&lt;/title&gt;\n'</string> <cont>...</cont></line>
<line nb="0214 ">    <string>'&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot;&gt;\n'</string> <cont>...</cont></line>
<line nb="0215 ">    <string>'&lt;meta name=&quot;generator&quot; content=&quot;highlight.m &amp;copy; 2003 Guillaume Flandin&quot;&gt;\n'</string> <cont>...</cont></line>
<line nb="0216 ">    <string>'&lt;style type=&quot;text/css&quot;&gt;\n'</string> <cont>...</cont></line>
<line nb="0217 ">    <string>'  .comment {color: #228B22;}\n'</string> <cont>...</cont></line>
<line nb="0218 ">    <string>'  .string {color: #B20000;}\n'</string> <cont>...</cont></line>
<line nb="0219 ">    <string>'  .keyword, .cont {color: #0000FF;}\n'</string> <cont>...</cont></line>
<line nb="0220 ">    <string>'  .cont {text-decoration: underline;}\n'</string> <cont>...</cont></line>
<line nb="0221 ">    <string>'  .code {color: #000000;}\n'</string> <cont>...</cont></line>
<line nb="0222 ">    <string>'&lt;/style&gt;\n'</string> <cont>...</cont></line>
<line nb="0223 ">    <string>'&lt;/head&gt;\n&lt;body&gt;\n'</string>],mfile);</line>
<line nb="0224 "></line>
<line nb="0225 "><comment>%-------------------------------------------------------------------------------</comment></line>
<line nb="0226 "><keyword>function</keyword> html_file_end(fid)</line>
<line nb="0227 ">    fprintf(fid,<string>'\n&lt;/body&gt;\n&lt;/html&gt;'</string>);</line>
<line nb="0228 "></line>
<line nb="0229 "><comment>%-------------------------------------------------------------------------------</comment></line>
<line nb="0230 "><keyword>function</keyword> format = html_format</line>
<line nb="0231 ">    format.string    = <string>'&lt;span class=&quot;string&quot;&gt;%s&lt;/span&gt;'</string>;</line>
<line nb="0232 ">    format.comment   = <string>'&lt;span class=&quot;comment&quot;&gt;%s&lt;/span&gt;'</string>;</line>
<line nb="0233 ">    format.code      = <string>'%s'</string>; <comment>%'&lt;span class=&quot;code&quot;&gt;%s&lt;/span&gt;';</comment></line>
<line nb="0234 ">    format.keyword   = <string>'&lt;span class=&quot;keyword&quot;&gt;%s&lt;/span&gt;'</string>;</line>
<line nb="0235 ">    format.cont      = <string>'&lt;span class=&quot;cont&quot;&gt;%s&lt;/span&gt;'</string>;</line>
<line nb="0236 ">    format.pre_start = <string>'&lt;pre class=&quot;mcode&quot;&gt;'</string>;</line>
<line nb="0237 ">    format.pre_end   = <string>'&lt;/pre&gt;\n'</string>;</line>
<line nb="0238 ">    format.nb_line   = <string>'%04d '</string>;</line>
<line nb="0239 ">    format.line      = <string>'%s\n'</string>;</line>
<line nb="0240 "></line>
<line nb="0241 "><comment>%-------------------------------------------------------------------------------</comment></line>
<line nb="0242 "><keyword>function</keyword> str = html_special_char(str)</line>
<line nb="0243 ">    <comment>%- See http://www.w3.org/TR/html4/charset.html#h-5.3.2</comment></line>
<line nb="0244 ">    str = strrep(str,<string>'&amp;'</string>,<string>'&amp;amp;'</string>);</line>
<line nb="0245 ">    str = strrep(str,<string>'&lt;'</string>,<string>'&amp;lt;'</string>);</line>
<line nb="0246 ">    str = strrep(str,<string>'&gt;'</string>,<string>'&amp;gt;'</string>);</line>
<line nb="0247 ">    str = strrep(str,<string>'&quot;'</string>,<string>'&amp;quot;'</string>);</line>
<line nb="0248 "></line>
<line nb="0249 "><comment>%===============================================================================</comment></line>
<line nb="0250 "><comment>%                                  XHTML FORMAT                                %</comment></line>
<line nb="0251 "><comment>%===============================================================================</comment></line>
<line nb="0252 "><keyword>function</keyword> xhtml_file_start(fid,mfile)</line>
<line nb="0253 ">    fprintf(fid,[ <cont>...</cont></line>
<line nb="0254 ">    <string>'&lt;?xml version=&quot;1.0&quot;?&gt;\n'</string> <cont>...</cont></line>
<line nb="0255 ">    <string>'&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot; '</string> <cont>...</cont></line>
<line nb="0256 ">    <string>'&quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot;&gt;\n'</string> <cont>...</cont></line>
<line nb="0257 ">    <string>'&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot; lang=&quot;en&quot; xml:lang=&quot;en&quot;&gt;\n'</string> <cont>...</cont></line>
<line nb="0258 ">    <string>'&lt;head&gt;\n&lt;title&gt;%s&lt;/title&gt;\n'</string> <cont>...</cont></line>
<line nb="0259 ">    <string>'&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot; /&gt;\n'</string> <cont>...</cont></line>
<line nb="0260 ">    <string>'&lt;meta name=&quot;generator&quot; content=&quot;highlight.m &amp;copy; 2003 Guillaume Flandin&quot; /&gt;\n'</string> <cont>...</cont></line>
<line nb="0261 ">    <string>'&lt;style type=&quot;text/css&quot;&gt;\n'</string> <cont>...</cont></line>
<line nb="0262 ">    <string>'  .comment {color: #228B22;}\n'</string> <cont>...</cont></line>
<line nb="0263 ">    <string>'  .string {color: #B20000;}\n'</string> <cont>...</cont></line>
<line nb="0264 ">    <string>'  .keyword, .cont {color: #0000FF;}\n'</string> <cont>...</cont></line>
<line nb="0265 ">    <string>'  .cont {text-decoration: underline;}\n'</string> <cont>...</cont></line>
<line nb="0266 ">    <string>'  .code {color: #000000;}\n'</string> <cont>...</cont></line>
<line nb="0267 ">    <string>'&lt;/style&gt;\n'</string> <cont>...</cont></line>
<line nb="0268 ">    <string>'&lt;/head&gt;\n&lt;body&gt;\n'</string>],mfile);</line>
<line nb="0269 "></line>
<line nb="0270 "><comment>%-------------------------------------------------------------------------------</comment></line>
<line nb="0271 "><keyword>function</keyword> xhtml_file_end(fid)</line>
<line nb="0272 ">    fprintf(fid,<string>'\n&lt;/body&gt;\n&lt;/html&gt;'</string>);</line>
<line nb="0273 "></line>
<line nb="0274 "><comment>%-------------------------------------------------------------------------------</comment></line>
<line nb="0275 "><keyword>function</keyword> format = xhtml_format</line>
<line nb="0276 ">    format.string    = <string>'&lt;span class=&quot;string&quot;&gt;%s&lt;/span&gt;'</string>;</line>
<line nb="0277 ">    format.comment   = <string>'&lt;span class=&quot;comment&quot;&gt;%s&lt;/span&gt;'</string>;</line>
<line nb="0278 ">    format.code      = <string>'%s'</string>; <comment>%'&lt;span class=&quot;code&quot;&gt;%s&lt;/span&gt;';</comment></line>
<line nb="0279 ">    format.keyword   = <string>'&lt;span class=&quot;keyword&quot;&gt;%s&lt;/span&gt;'</string>;</line>
<line nb="0280 ">    format.cont      = <string>'&lt;span class=&quot;cont&quot;&gt;%s&lt;/span&gt;'</string>;</line>
<line nb="0281 ">    format.pre_start = <string>'&lt;pre class=&quot;mcode&quot;&gt;'</string>;</line>
<line nb="0282 ">    format.pre_end   = <string>'&lt;/pre&gt;\n'</string>;</line>
<line nb="0283 ">    format.nb_line   = <string>'%04d '</string>;</line>
<line nb="0284 ">    format.line      = <string>'%s\n'</string>;</line>
<line nb="0285 "></line>
<line nb="0286 "><comment>%-------------------------------------------------------------------------------</comment></line>
<line nb="0287 "><keyword>function</keyword> str = xhtml_special_char(str)</line>
<line nb="0288 ">    <comment>%- See http://www.w3.org/TR/html4/charset.html#h-5.3.2</comment></line>
<line nb="0289 ">    str = strrep(str,<string>'&amp;'</string>,<string>'&amp;amp;'</string>);</line>
<line nb="0290 ">    str = strrep(str,<string>'&lt;'</string>,<string>'&amp;lt;'</string>);</line>
<line nb="0291 ">    str = strrep(str,<string>'&gt;'</string>,<string>'&amp;gt;'</string>);</line>
<line nb="0292 ">    str = strrep(str,<string>'&quot;'</string>,<string>'&amp;quot;'</string>);</line>
<line nb="0293 "></line>
<line nb="0294 "></line>
<line nb="0295 "><comment>%===============================================================================</comment></line>
<line nb="0296 "><comment>%                                   XML FORMAT                                 %</comment></line>
<line nb="0297 "><comment>%===============================================================================</comment></line>
<line nb="0298 "><keyword>function</keyword> xml_file_start(fid,mfile)</line>
<line nb="0299 ">    fprintf(fid,[ <cont>...</cont></line>
<line nb="0300 ">    <string>'&lt;?xml version=&quot;1.0&quot; encoding=&quot;iso-8859-1&quot; ?&gt;\n'</string> <cont>...</cont></line>
<line nb="0301 ">    <string>'&lt;!DOCTYPE mfile SYSTEM &quot;matlab.dtd&quot;&gt;\n'</string> <cont>...</cont></line>
<line nb="0302 ">    <string>'&lt;mfile name=&quot;%s&quot;&gt;\n'</string>],mfile);</line>
<line nb="0303 "></line>
<line nb="0304 "><comment>%-------------------------------------------------------------------------------</comment></line>
<line nb="0305 "><keyword>function</keyword> xml_file_end(fid)</line>
<line nb="0306 ">    fprintf(fid,<string>'&lt;/mfile&gt;'</string>);</line>
<line nb="0307 "></line>
<line nb="0308 "><comment>%-------------------------------------------------------------------------------</comment></line>
<line nb="0309 "><keyword>function</keyword> format = xml_format</line>
<line nb="0310 ">    format.string    = <string>'&lt;string&gt;%s&lt;/string&gt;'</string>;</line>
<line nb="0311 ">    format.comment   = <string>'&lt;comment&gt;%s&lt;/comment&gt;'</string>;</line>
<line nb="0312 ">    format.code      = <string>'%s'</string>; <comment>%'&lt;code&gt;%s&lt;/code&gt;';</comment></line>
<line nb="0313 ">    format.keyword   = <string>'&lt;keyword&gt;%s&lt;/keyword&gt;'</string>;</line>
<line nb="0314 ">    format.cont      = <string>'&lt;cont&gt;%s&lt;/cont&gt;'</string>;</line>
<line nb="0315 ">    format.pre_start = <string>''</string>;</line>
<line nb="0316 ">    format.pre_end   = <string>''</string>;</line>
<line nb="0317 ">    format.nb_line   = <string>'&lt;line nb=&quot;%04d &quot;&gt;'</string>;</line>
<line nb="0318 ">    format.line      = <string>'%s&lt;/line&gt;\n'</string>;</line>
<line nb="0319 "></line>
<line nb="0320 "><comment>%-------------------------------------------------------------------------------</comment></line>
<line nb="0321 "><keyword>function</keyword> str = xml_special_char(str)</line>
<line nb="0322 ">    <comment>%- See http://www.w3.org/TR/REC-xml#sec-predefined-ent</comment></line>
<line nb="0323 ">    str = strrep(str,<string>'&amp;'</string>,<string>'&amp;amp;'</string>);</line>
<line nb="0324 ">    str = strrep(str,<string>'&lt;'</string>,<string>'&amp;lt;'</string>);</line>
<line nb="0325 ">    str = strrep(str,<string>'&gt;'</string>,<string>'&amp;gt;'</string>);</line>
<line nb="0326 ">    str = strrep(str,<string>'&quot;'</string>,<string>'&amp;quot;'</string>);</line>
<line nb="0327 ">    <comment>%str = strrep(str,'''','&amp;apos;');</comment></line>
<line nb="0328 ">    </line>
<line nb="0329 "><comment>%===============================================================================</comment></line>
<line nb="0330 "><comment>%                                  LaTeX FORMAT                                %</comment></line>
<line nb="0331 "><comment>%===============================================================================</comment></line>
<line nb="0332 "><keyword>function</keyword> tex_file_start(fid,mfile)</line>
<line nb="0333 ">    fprintf(fid,[<string>'\\documentclass[a4paper,10pt]{article}\n'</string> <cont>...</cont></line>
<line nb="0334 ">                 <string>'    \\usepackage{alltt}\n'</string> <cont>...</cont></line>
<line nb="0335 ">                 <string>'    \\usepackage{color}\n'</string> <cont>...</cont></line>
<line nb="0336 ">                 <string>'    \\usepackage{fullpage}\n'</string> <cont>...</cont></line>
<line nb="0337 ">                 <string>'    \\definecolor{string}{rgb}{0.7,0.0,0.0}\n'</string> <cont>...</cont></line>
<line nb="0338 ">                 <string>'    \\definecolor{comment}{rgb}{0.13,0.54,0.13}\n'</string> <cont>...</cont></line>
<line nb="0339 ">                 <string>'    \\definecolor{keyword}{rgb}{0.0,0.0,1.0}\n'</string> <cont>...</cont></line>
<line nb="0340 ">                 <string>'    \\title{%s}\n'</string> <cont>...</cont></line>
<line nb="0341 ">                 <string>'    \\author{\\textsc{Matlab}, The Mathworks, Inc.}\n'</string> <cont>...</cont></line>
<line nb="0342 ">                 <string>'\\begin{document}\n'</string> <cont>...</cont></line>
<line nb="0343 ">                 <string>'\\maketitle\n'</string>],mfile);</line>
<line nb="0344 "></line>
<line nb="0345 "><comment>%-------------------------------------------------------------------------------</comment></line>
<line nb="0346 "><keyword>function</keyword> tex_file_end(fid)</line>
<line nb="0347 ">    fprintf(fid,<string>'\\end{document}'</string>);</line>
<line nb="0348 "></line>
<line nb="0349 "><comment>%-------------------------------------------------------------------------------</comment></line>
<line nb="0350 "><keyword>function</keyword> format = tex_format</line>
<line nb="0351 ">    format.string    = <string>'\\textcolor{string}{%s}'</string>;</line>
<line nb="0352 ">    format.comment   = <string>'textcolor{comment}{%s}'</string>; <comment>% '%' has been replaced by '\%'</comment></line>
<line nb="0353 ">    format.code      = <string>'%s'</string>;</line>
<line nb="0354 ">    format.keyword   = <string>'\\textcolor{keyword}{%s}'</string>;</line>
<line nb="0355 ">    format.cont      = <string>'\\textcolor{keyword}{\\underline{%s}}'</string>;</line>
<line nb="0356 ">    format.pre_start = <string>'\\begin{alltt}\n'</string>;</line>
<line nb="0357 ">    format.pre_end   = <string>'\\end{alltt}\n'</string>;</line>
<line nb="0358 ">    format.nb_line   = <string>'%04d '</string>;</line>
<line nb="0359 ">    format.line      = <string>'%s\n'</string>;</line>
<line nb="0360 "></line>
<line nb="0361 "><comment>%-------------------------------------------------------------------------------</comment></line>
<line nb="0362 "><keyword>function</keyword> str = tex_special_char(str)</line>
<line nb="0363 ">    <comment>% Special characters: # $ % &amp; ~ _ ^ \ { }</comment></line>
<line nb="0364 ">    str = strrep(str,<string>'\'</string>,<string>'\(\backslash\)'</string>); <comment>% $\backslash$ or \textbackslash or \verb+\+</comment></line>
<line nb="0365 ">    str = strrep(str,<string>'#'</string>,<string>'\#'</string>);</line>
<line nb="0366 ">    str = strrep(str,<string>'$'</string>,<string>'\$'</string>);</line>
<line nb="0367 ">    str = strrep(str,<string>'%'</string>,<string>'\%'</string>);</line>
<line nb="0368 ">    str = strrep(str,<string>'&amp;'</string>,<string>'\&amp;'</string>);</line>
<line nb="0369 ">    str = strrep(str,<string>'_'</string>,<string>'\_'</string>);</line>
<line nb="0370 ">    str = strrep(str,<string>'{'</string>,<string>'\{'</string>);</line>
<line nb="0371 ">    str = strrep(str,<string>'}'</string>,<string>'\}'</string>);</line>
<line nb="0372 ">    str = strrep(str,<string>'^'</string>,<string>'\^{}'</string>);</line>
<line nb="0373 ">    str = strrep(str,<string>'~'</string>,<string>'\~{}'</string>); <comment>% or \textasciitilde</comment></line>
<line nb="0374 "></line>
<line nb="0375 "><comment>%===============================================================================</comment></line>
<line nb="0376 "><comment>%                                   RTF FORMAT                                 %</comment></line>
<line nb="0377 "><comment>%===============================================================================</comment></line>
<line nb="0378 "><keyword>function</keyword> rtf_file_start(fid,mfile)</line>
<line nb="0379 ">    fprintf(fid,[<string>'{\\rtf1\\ansi\n\n'</string> <cont>...</cont></line>
<line nb="0380 ">                 <string>'{\\fonttbl{\\f0\\fmodern\\fcharset0\\fprq1 Courier New;}}\n\n'</string> <cont>...</cont></line>
<line nb="0381 ">                 <string>'{\\colortbl;\n'</string> <cont>...</cont></line>
<line nb="0382 ">                 <string>'\\red0\\green0\\blue0;\n'</string> <cont>...</cont></line>
<line nb="0383 ">                 <string>'\\red0\\green0\\blue255;\n'</string> <cont>...</cont></line>
<line nb="0384 ">                 <string>'\\red0\\green255\\blue255;\n'</string> <cont>...</cont></line>
<line nb="0385 ">                 <string>'\\red0\\green255\\blue0;\n'</string> <cont>...</cont></line>
<line nb="0386 ">                 <string>'\\red255\\green0\\blue255;\n'</string> <cont>...</cont></line>
<line nb="0387 ">                 <string>'\\red255\\green0\\blue0;}\n\n'</string> <cont>...</cont></line>
<line nb="0388 ">                 <string>'{\\info{\\title %s}\n'</string> <cont>...</cont></line>
<line nb="0389 ">                 <string>'{\\author HighLight.m Copyright 2003}\n'</string> <cont>...</cont></line>
<line nb="0390 ">                 <string>'{\\creatim\\yr%s\\mo%s\\dy%s}'</string> <cont>...</cont></line>
<line nb="0391 ">                 <string>'{\\*\\manager Guillaume Flandin}\n'</string> <cont>...</cont></line>
<line nb="0392 ">                 <string>'{\\*\\company Artefact.tk}\n'</string> <cont>...</cont></line>
<line nb="0393 ">                 <string>'{\\*\\hlinkbase http://www.artefact.tk/software/'</string> <cont>...</cont><comment> </comment></line>
<line nb="0394 ">                 <string>'matlab/highlight/}}\n\n'</string>],mfile,<cont>...</cont></line>
<line nb="0395 ">                 datestr(date,<string>'yyyy'</string>),datestr(date,<string>'mm'</string>),datestr(date,<string>'dd'</string>));</line>
<line nb="0396 "></line>
<line nb="0397 "><comment>%-------------------------------------------------------------------------------</comment></line>
<line nb="0398 "><keyword>function</keyword> rtf_file_end(fid)</line>
<line nb="0399 ">    fprintf(fid,<string>'}'</string>);</line>
<line nb="0400 "></line>
<line nb="0401 "><comment>%-------------------------------------------------------------------------------</comment></line>
<line nb="0402 "><keyword>function</keyword> format = rtf_format</line>
<line nb="0403 ">    format.string    = <string>'{\\cf6 %s}'</string>;</line>
<line nb="0404 ">    format.comment   = <string>'{\\cf4 %s}'</string>;</line>
<line nb="0405 ">    format.code      = <string>'{%s}'</string>;</line>
<line nb="0406 ">    format.keyword   = <string>'{\\cf2 %s}'</string>;</line>
<line nb="0407 ">    format.cont      = <string>'{\\cf2 %s}'</string>;</line>
<line nb="0408 ">    format.pre_start = <string>'{\\f0\\fs16{'</string>;</line>
<line nb="0409 ">    format.pre_end   = <string>'}}'</string>;</line>
<line nb="0410 ">    format.nb_line   = <string>'{%04d }'</string>;</line>
<line nb="0411 ">    format.line      = <string>'%s\n\\par '</string>;</line>
<line nb="0412 "></line>
<line nb="0413 "><comment>%-------------------------------------------------------------------------------</comment></line>
<line nb="0414 "><keyword>function</keyword> str = rtf_special_char(str)</line>
<line nb="0415 ">    str = strrep(str,<string>'\'</string>,<string>'\\'</string>);</line>
<line nb="0416 ">    str = strrep(str,<string>'{'</string>,<string>'\{'</string>);</line>
<line nb="0417 ">    str = strrep(str,<string>'}'</string>,<string>'\}'</string>);</line>
<line nb="0418 "></line>
<line nb="0419 "><comment>%===============================================================================</comment></line>
<line nb="0420 "><comment>%                                 MATLAB KEYWORDS                              %</comment></line>
<line nb="0421 "><comment>%===============================================================================</comment></line>
<line nb="0422 "><keyword>function</keyword> matlabKeywords = getMatlabKeywords</line>
<line nb="0423 ">    <comment>%matlabKeywords = iskeyword; % Matlab R13</comment></line>
<line nb="0424 ">    matlabKeywords = {<string>'break'</string>, <string>'case'</string>, <string>'catch'</string>, <string>'continue'</string>, <string>'elseif'</string>, <string>'else'</string>,<cont>...</cont></line>
<line nb="0425 ">                      <string>'end'</string>, <string>'for'</string>, <string>'function'</string>, <string>'global'</string>, <string>'if'</string>, <string>'otherwise'</string>, <cont>...</cont></line>
<line nb="0426 ">                      <string>'persistent'</string>, <string>'return'</string>, <string>'switch'</string>, <string>'try'</string>, <string>'while'</string>};</line>
<line nb="0427 ">                      </line>
<line nb="0428 "><comment>%-------------------------------------------------------------------------------</comment></line>
<line nb="0429 "><keyword>function</keyword> mKeySort = getMatlabKeywordsSorted</line>
<line nb="0430 ">    mKeySort.nextincr = {<string>'for'</string>, <string>'while'</string>, <string>'if'</string>, <string>'else'</string>, <string>'elseif'</string>, <cont>...</cont></line>
<line nb="0431 ">                         <string>'case'</string>, <string>'otherwise'</string>, <string>'try'</string>, <string>'catch'</string>};</line>
<line nb="0432 ">    mKeySort.nextincr2 = {<string>'switch'</string>};</line>
<line nb="0433 ">    mKeySort.currdecr = {<string>'else'</string>, <string>'elseif'</string>, <string>'case'</string>, <string>'otherwise'</string>, <string>'catch'</string>};</line>
<line nb="0434 ">    mKeySort.nextdecr = {<string>'end'</string>};</line>
<line nb="0435 ">    mKeySort.other    = {<string>'break'</string>, <string>'continue'</string>, <string>'function'</string>, <string>'global'</string>, <cont>...</cont></line>
<line nb="0436 ">                         <string>'persistent'</string>, <string>'return'</string>};</line>
<line nb="0437 "></line>
<line nb="0438 "><comment>%===============================================================================</comment></line>
<line nb="0439 "><comment>%                               HANDLE TAB CHARACTER                           %</comment></line>
<line nb="0440 "><comment>%===============================================================================</comment></line>
<line nb="0441 "><keyword>function</keyword> str = horztab(str,n)</line>
<line nb="0442 ">    <comment>%- For browsers, the horizontal tab character is the smallest non-zero </comment></line>
<line nb="0443 ">    <comment>%- number of spaces necessary to line characters up along tab stops that are</comment></line>
<line nb="0444 ">    <comment>%- every 8 characters: behaviour obtained when n = 0.</comment></line>
<line nb="0445 ">    <keyword>if</keyword> n &gt; 0</line>
<line nb="0446 ">        str = strrep(str,sprintf(<string>'\t'</string>),blanks(n));</line>
<line nb="0447 ">    <keyword>end</keyword></line>
<line nb="0448 "></line>
<line nb="0449 "><comment>%===============================================================================</comment></line>
<line nb="0450 "><comment>%                                MATLAB CODE PARSER                            %</comment></line>
<line nb="0451 "><comment>%===============================================================================</comment></line>
<line nb="0452 "><keyword>function</keyword> splitc = splitcode(code)</line>
<line nb="0453 ">    <comment>%Split a line of  Matlab code in string, comment and other</comment></line>
<line nb="0454 "></line>
<line nb="0455 ">    <comment>%- Label quotes in {'transpose', 'beginstring', 'midstring', 'endstring'}</comment></line>
<line nb="0456 ">    iquote = findstr(code,<string>''''</string>);</line>
<line nb="0457 ">    quotetransp = [double(<string>'_''.)}]'</string>) <cont>...</cont></line>
<line nb="0458 ">                   double(<string>'A'</string>):double(<string>'Z'</string>) <cont>...</cont></line>
<line nb="0459 ">                   double(<string>'0'</string>):double(<string>'9'</string>) <cont>...</cont></line>
<line nb="0460 ">                   double(<string>'a'</string>):double(<string>'z'</string>)];</line>
<line nb="0461 ">    flagstring = 0;</line>
<line nb="0462 ">    flagdoublequote = 0;</line>
<line nb="0463 ">    jquote = [];</line>
<line nb="0464 ">    <keyword>for</keyword> i=1:length(iquote)</line>
<line nb="0465 ">        <keyword>if</keyword> ~flagstring</line>
<line nb="0466 ">            <keyword>if</keyword> iquote(i) &gt; 1 &amp; any(quotetransp == double(code(iquote(i)-1)))</line>
<line nb="0467 ">                <comment>% =&gt; 'transpose';</comment></line>
<line nb="0468 ">            <keyword>else</keyword></line>
<line nb="0469 ">                <comment>% =&gt; 'beginstring';</comment></line>
<line nb="0470 ">                jquote(size(jquote,1)+1,:) = [iquote(i) length(code)];</line>
<line nb="0471 ">                flagstring = 1;</line>
<line nb="0472 ">            <keyword>end</keyword></line>
<line nb="0473 ">        <keyword>else</keyword> <comment>% if flagstring</comment></line>
<line nb="0474 ">            <keyword>if</keyword> flagdoublequote | <cont>...</cont></line>
<line nb="0475 ">               (iquote(i) &lt; length(code) &amp; strcmp(code(iquote(i)+1),<string>''''</string>))</line>
<line nb="0476 ">                <comment>% =&gt; 'midstring';</comment></line>
<line nb="0477 ">                flagdoublequote = ~flagdoublequote;</line>
<line nb="0478 ">            <keyword>else</keyword></line>
<line nb="0479 ">                <comment>% =&gt; 'endstring';</comment></line>
<line nb="0480 ">                jquote(size(jquote,1),2) = iquote(i);</line>
<line nb="0481 ">                flagstring = 0;</line>
<line nb="0482 ">            <keyword>end</keyword></line>
<line nb="0483 ">        <keyword>end</keyword></line>
<line nb="0484 ">    <keyword>end</keyword></line>
<line nb="0485 "></line>
<line nb="0486 ">    <comment>%- Find if a portion of code is a comment</comment></line>
<line nb="0487 ">    ipercent = findstr(code,<string>'%'</string>);</line>
<line nb="0488 ">    jpercent = [];</line>
<line nb="0489 ">    <keyword>for</keyword> i=1:length(ipercent)</line>
<line nb="0490 ">        <keyword>if</keyword> isempty(jquote) | <cont>...</cont></line>
<line nb="0491 ">           ~any((ipercent(i) &gt; jquote(:,1)) &amp; (ipercent(i) &lt; jquote(:,2)))</line>
<line nb="0492 ">            jpercent = [ipercent(i) length(code)];</line>
<line nb="0493 ">            <keyword>break</keyword>;</line>
<line nb="0494 ">        <keyword>end</keyword></line>
<line nb="0495 ">    <keyword>end</keyword></line>
<line nb="0496 "></line>
<line nb="0497 ">    <comment>%- Find continuation punctuation '...'</comment></line>
<line nb="0498 ">    icont = findstr(code,<string>'...'</string>);</line>
<line nb="0499 ">    <keyword>for</keyword> i=1:length(icont)</line>
<line nb="0500 ">        <keyword>if</keyword> (isempty(jquote) | <cont>...</cont></line>
<line nb="0501 ">            ~any((icont(i) &gt; jquote(:,1)) &amp; (icont(i) &lt; jquote(:,2)))) &amp; <cont>...</cont></line>
<line nb="0502 ">            (isempty(jpercent) | <cont>...</cont></line>
<line nb="0503 ">            icont(i) &lt; jpercent(1))</line>
<line nb="0504 ">            jpercent = [icont(i) length(code)];</line>
<line nb="0505 ">            <keyword>break</keyword>;</line>
<line nb="0506 ">        <keyword>end</keyword></line>
<line nb="0507 ">    <keyword>end</keyword></line>
<line nb="0508 "></line>
<line nb="0509 ">    <comment>%- Remove strings inside comments</comment></line>
<line nb="0510 ">    <keyword>if</keyword> ~isempty(jpercent) &amp; ~isempty(jquote)</line>
<line nb="0511 ">        jquote(find(jquote(:,1) &gt; jpercent(1)),:) = [];</line>
<line nb="0512 ">    <keyword>end</keyword></line>
<line nb="0513 "></line>
<line nb="0514 ">    <comment>%- Split code in a cell array of strings</comment></line>
<line nb="0515 ">    icode = [jquote ; jpercent];</line>
<line nb="0516 ">    splitc = {};</line>
<line nb="0517 ">    <keyword>if</keyword> isempty(icode)</line>
<line nb="0518 ">        splitc{1} = code;</line>
<line nb="0519 ">    <keyword>elseif</keyword> icode(1,1) &gt; 1</line>
<line nb="0520 ">        splitc{1} = code(1:icode(1,1)-1);</line>
<line nb="0521 ">    <keyword>end</keyword></line>
<line nb="0522 ">    <keyword>for</keyword> i=1:size(icode,1)</line>
<line nb="0523 ">        splitc{end+1} = code(icode(i,1):icode(i,2));</line>
<line nb="0524 ">        <keyword>if</keyword> i &lt; size(icode,1) &amp; icode(i+1,1) &gt; icode(i,2) + 1</line>
<line nb="0525 ">            splitc{end+1} = code((icode(i,2)+1):(icode(i+1,1)-1));</line>
<line nb="0526 ">        <keyword>elseif</keyword> i == size(icode,1) &amp; icode(i,2) &lt; length(code)</line>
<line nb="0527 ">            splitc{end+1} = code(icode(i,2)+1:end);</line>
<line nb="0528 ">        <keyword>end</keyword></line>
<line nb="0529 ">    <keyword>end</keyword></line>
<line nb="0530 ">      </line>
<line nb="0531 "><comment>%===============================================================================</comment></line>
<line nb="0532 "><comment>%                           MODIFIED VERSION OF STRTOK                         %</comment></line>
<line nb="0533 "><comment>%===============================================================================</comment></line>
<line nb="0534 "><keyword>function</keyword> [token, remainder, quotient] = strtok(string, delimiters)</line>
<line nb="0535 "><comment>% Modified version of STRTOK to also return the quotient</comment></line>
<line nb="0536 "><comment>% string = [quotient token remainder]</comment></line>
<line nb="0537 "><comment>%STRTOK Find token in string.</comment></line>
<line nb="0538 "><comment>%   STRTOK(S) returns the first token in the string S delimited</comment></line>
<line nb="0539 "><comment>%   by &quot;white space&quot;.   Any leading white space characters are ignored.</comment></line>
<line nb="0540 "><comment>%</comment></line>
<line nb="0541 "><comment>%   STRTOK(S,D) returns the first token delimited by one of the </comment></line>
<line nb="0542 "><comment>%   characters in D.  Any leading delimiter characters are ignored.</comment></line>
<line nb="0543 "><comment>%</comment></line>
<line nb="0544 "><comment>%   [T,R] = STRTOK(...) also returns the remainder of the original</comment></line>
<line nb="0545 "><comment>%   string.</comment></line>
<line nb="0546 "><comment>%   If the token is not found in S then R is an empty string and T</comment></line>
<line nb="0547 "><comment>%   is same as S. </comment></line>
<line nb="0548 "><comment>%</comment></line>
<line nb="0549 "><comment>%   Copyright 1984-2002 The MathWorks, Inc. </comment></line>
<line nb="0550 "><comment>%   $Revision: 5.14 $  $Date: 2002/04/09 00:33:38 $</comment></line>
<line nb="0551 "></line>
<line nb="0552 ">token = []; remainder = []; quotient = string;</line>
<line nb="0553 "></line>
<line nb="0554 ">len = length(string);</line>
<line nb="0555 "><keyword>if</keyword> len == 0</line>
<line nb="0556 ">    <keyword>return</keyword></line>
<line nb="0557 "><keyword>end</keyword></line>
<line nb="0558 "></line>
<line nb="0559 "><keyword>if</keyword> (nargin == 1)</line>
<line nb="0560 ">    delimiters = [9:13 32]; <comment>% White space characters</comment></line>
<line nb="0561 "><keyword>end</keyword></line>
<line nb="0562 "></line>
<line nb="0563 ">i = 1;</line>
<line nb="0564 "><keyword>while</keyword> (any(string(i) == delimiters))</line>
<line nb="0565 ">    i = i + 1;</line>
<line nb="0566 ">    <keyword>if</keyword> (i &gt; len), <keyword>return</keyword>, <keyword>end</keyword></line>
<line nb="0567 "><keyword>end</keyword></line>
<line nb="0568 ">start = i;</line>
<line nb="0569 "><keyword>while</keyword> (~any(string(i) == delimiters))</line>
<line nb="0570 ">    i = i + 1;</line>
<line nb="0571 ">    <keyword>if</keyword> (i &gt; len), <keyword>break</keyword>, <keyword>end</keyword></line>
<line nb="0572 "><keyword>end</keyword></line>
<line nb="0573 ">finish = i - 1;</line>
<line nb="0574 "></line>
<line nb="0575 ">token = string(start:finish);</line>
<line nb="0576 "></line>
<line nb="0577 "><keyword>if</keyword> (nargout &gt;= 2)</line>
<line nb="0578 ">    remainder = string(finish + 1:length(string));</line>
<line nb="0579 "><keyword>end</keyword></line>
<line nb="0580 "></line>
<line nb="0581 "><keyword>if</keyword> (nargout == 3 &amp; start &gt; 1)</line>
<line nb="0582 ">    quotient = string(1:start-1);</line>
<line nb="0583 "><keyword>else</keyword></line>
<line nb="0584 ">    quotient = [];</line>
<line nb="0585 "><keyword>end</keyword></line>
</mfile>
