source: prextra/prhelp2html.m @ 39

Last change on this file since 39 was 29, checked in by bduin, 13 years ago
File size: 21.7 KB
Line 
1%PRHELP2HTML Construct HTML file from help part of PRTools routine
2%
3%               S = PRHELP2HTML(COMMAND,RECREATE,HTMLDIR)
4%               S = PRHELP2HTML(TOOLBOX,RECREATE,HTMLDIR)
5%
6% INPUT
7%   COMMAND    String with PRTools command, default: all prtools m-files
8%   TOOLBOX    Name of the toolbox to be handled, default PRTOOLS.
9%              Toolbox should be in the bath in in this call the last
10%              character should be a '/'.
11%   RECREATE   0/1 flag indicating whether non-existing references
12%              in the SEE ALSO section should be created as well
13%   HTMLDIR     String with desired directory in which the HTML
14%              file should be stored
15%
16% OUTPUT
17%   S          HTML code written to file, empty in case of error
18%
19% DESCRIPTION
20% This command takes the help part of a PRTools command and creates a HTML
21% file in the desired sub-directory. In case it is not given, a
22% sub-directory is used with the same name as the (sub-)directory of
23% COMMAND.
24%
25% In creating HTML code the following formatting rules apply:
26% - NAME is used for the title and the first heading
27% - There are (slightly) different rules for standard sections of the
28%   PRTools help:
29%   INPUT, OUTPUT, DESCRIPTION, REFERENCES, EXAMPLES, SEE ALSO
30% - New sections are detected by their name in capitals starting at
31%   position 1 or 2 of the line.
32% - The first word of the first line is skipped (assuming it is identical
33%   to NAME).  The remaining part of the line is used as heading.
34% - The next block of lines is assumed to be ways to call the command and
35%   is printed as code (Courier size 3) on separate lines.
36% - The INPUT and OUTPUT sections are printed as two-column tables. The
37%   first column is printed as code.
38% - Multiple spaces in the source are used to define column separators.
39%   ACCIDENTAL MULTIPLE SPACES CAUSE ERRORS!!!!
40% - Blocks of lines in the following DESCRIPTION section are formatted as
41%   separate paragraphs.
42% - Lines starting with ' - ' will start a dotted list.
43% - Lines following an empty line and starting with multiple spaces are
44%   assumed to be code and printed as Courier_3.
45% - Lines containing sets of multiple spaces after the first words start a
46%   two-column table. Consecutive lines starting with multiple spaces are
47%   placed in the second column.
48% - Lines ending with a ':' force a break (<br>) in the paragraph.
49% - An attempt is made to detect code in text (using the Matlab convention
50%   of upper case characters only). This is printed as Courier 2.
51% - Literature references in the REFERENCE section generater a break if the
52%   line starts with a number.
53% - Code in the EXAMPLE section is printed as it is using Courier_2.
54% - Users are advised to neglect here the Matlab convention of capitals in
55%   order to facilitate direct copying and execution.
56% - References are created for command names in the EXAMPLE section that
57%   are preceded by 'See', e.g. 'See PREX_PLOTC'.
58% - References are created for all PRTools commands in the SEE ALSO
59%   section.
60
61
62% BEFORE YOU START TO DEBUG, READ THIS
63% This routine was original intended to work on the prtools dir only.
64% Later it was somewhat changed in order to handle files in prdatasets,
65% prdatafiles and possibly distools and dd_tools as well. Only for
66% prtools the subdir structure (with the @dataset, @datafile, @mapping
67% sub dirs) is recognized, and only if the first parameter, COMMAND, is
68% empty.
69%
70% The Contents files have a special layout. It is handled by prcontent2html
71% in case of PRTools, but for other toolboxes it most likely doesn't work.
72%
73% The formatting rules of the PRTools help are strict. Don't try to relax
74% them in the below code, but change the help-text if you are not satisfied
75% with the result. Especially avoid '  ' (double spaces) where they are not
76% needed as the conversion jumps into a table-mode as soon as they are
77% encountered.
78%
79% Bob Duin, April 2011
80
81function out = prhelp2html(name,recreate,htmldir)
82
83if nargin < 3, htmldir = cd; end
84if nargin < 2 | isempty(recreate), recreate = 0; end
85if nargin < 1 | isempty(name) % default is prtools
86        dirs = {'ldc','dataset','datafile','mapping'};
87        run_all_files(mfilename,dirs,htmldir);
88        s = prcontent2html('prtools',[],htmldir);
89        if nargout > 0
90                out = s;
91        end
92        return;
93else
94        if strcmp(name(end),'/') & exist(name(1:end-1),'dir') == 7
95                name = name(1:end-1);
96                dirs = {fullfile(name,'Contents.m')};
97                run_all_files(mfilename,dirs,htmldir);
98                s = prcontent2html(name,[],htmldir); % does not work usually
99                if nargout > 0
100                        out = s;
101                end
102                return
103        end
104end
105
106file = which(name);
107if isempty(file)
108        disp(['  ----->  ' name ' not found']);
109        out = [];
110        return
111end
112%[pp,name] = fileparts(file);
113if isempty(htmldir)
114        [xx,htmldir] = fileparts(fileparts(file));
115end
116% if isempty(strmatch(subdir,char('prtools','@dataset','@datafile','@mapping'),'exact'))
117% %     disp([name ' Not PRTools'])
118%       out = [];
119%       return
120% end
121
122disp(file)
123t = gethf(file); % help part
124
125t = strrep(t,char([10 13]),char(10));
126t = strrep(t,char([13 10]),char(10));
127t = strrep(t,char(13),char(10));
128t = strrep(t,char(9),char([32 32]));
129n = length(strfind(t,10));
130       
131s = ['<html>' content_manual '<head><title>' name '</title></head>' newline];
132
133s = [s '<body bgcolor="#ffffff"><p align="center"><font face="Courier" ' ...
134   'size=5><strong>' upper(name) '</strong></font></p>' newline];
135
136title = listn(t,1);
137[qq,title] = strtok(title); % get rid of first word, probably name
138s = [s '<h3>' title '</h3>' newline];
139s = [s '<p>' newline];
140liston = false;
141previous_empty = false;
142coding = false;
143cellopen = false;
144tabstate = false;
145
146if strfind(lower(title),'info')
147        state = 'text';
148else
149        state = 'start';
150end
151nextlinespace = htmlspace;
152for j=2:n                             % do for all lines
153        newlinespace = nextlinespace;
154        nextlinespace = htmlspace;
155        r = listn(t,j);
156        u = cleanstr(r);
157%     if strfind(r,'supplied')
158%        disp(r)
159%     end
160        [tok,posttok] = strtok(u);
161        single = isempty(strtok(posttok));
162        emptyline = isempty(tok);
163        if length(r) < 2,
164                startspace = false;
165                tabstartspace = false;
166        else
167                startspace = strcmp(r(1:2),'  ');
168                if length(r) < 4 || ~tabstate
169                        tabstartspace = false;
170                else
171                        tabstartspace = strcmp(r(1:4),'    ');
172                        colpos1 = find(r ~= ' ',1,'first');
173                end
174                if tabstartspace
175                        startspace = false;
176                end
177        end
178        uppertoken = isupper(tok);
179        upperline = isupper(u);
180        functioncall = ~isempty(strfind(lower(r),name));
181        input = strcmp(tok,'INPUT');
182        output = strcmp(tok,'OUTPUT');
183        listline = strcmp(tok,'-');
184        description = strcmp(tok,'DESCRIPTION');
185        example = strcmp(tok,'EXAMPLE') | strcmp(tok,'EXAMPLES');
186        reference = strcmp(tok,'REFERENCE') | strcmp(tok,'REFERENCES');
187        seealso = strcmpi(tok,'SEE') & strcmpi(strtok(posttok),'ALSO');
188        inputstate = strcmp(state,'input');
189        outputstate = strcmp(state,'output');
190        tabstate = strcmp(state,'tab');
191        startstate = strcmp(state,'start');
192        commandstate = strcmp(state,'command');
193        textstate = strcmp(state,'text');
194        examplestate = strcmp(state,'examp');
195        seealsostate = strcmp(state,'seealso');
196        refstate = strcmp(state,'reference');
197        iotabstate = inputstate | outputstate;
198  ntabs = regexp(strtrim(r),'   *','start');
199        tab = length(ntabs>1) | (length(ntabs)==1 && ntabs(1)>1);
200       
201        if seealso % get rid of also
202                [qq,posttok] = strtok(posttok);
203                single = isempty(strtok(posttok));
204        end
205               
206        if previous_empty && ~startspace && ~tabstartspace && ~tab && tabstate
207                if cellopen
208                        s = closecell(s);
209                        cellopen = false;
210                end
211                s = endtable(s);
212    s = [s '</p>' newline '<p>'];
213                state = oldstate;
214        end
215       
216        if emptyline                          % start new paragraph
217                if liston, s = [s '</ul>']; liston = false; end
218                if iotabstate
219      s = endtable(s);
220      state = 'text';
221    else
222                        s = [s '</p>' newline '<p>']; %#ok<AGROW>
223                end
224                if ~examplestate
225                        coding = false;
226                end
227               
228        elseif (startspace && ((functioncall && upperline) || commandstate)) || startstate
229                                                    % command
230                %n = findstr(u,'=');  % align =
231                %n = min(n,17);       % but dont exeggarate
232                n = find(r~=' ',1,'first');
233                s  = [s code(u,n,3) '<br>' newline];
234                state = 'command';
235               
236        elseif input && single                 % input
237                if commandstate || textstate         % start table
238                        s = [s '</p><p>' newline];        % new paragraph
239                        s = [s '<table cellspacing="0" cellpadding="3" width="100%"'...
240                                        ' align="center" border="0"']; % start table
241                        s = [s '<tr> <td width="100"><font size="4"><strong>Input</strong></font></td>'];
242                  state = 'input';
243                end
244        elseif output && single
245                if inputstate
246                        s = endtable(s); % end inputtable
247                end
248                if inputstate || commandstate || textstate  % start table
249                        s = [s '</p><p>'];                      % new paragraph
250                        s = [s '<table cellspacing="0" cellpadding="3" width="100%"'...
251                                        ' align="center" border="0"']; % start table
252                        s = [s '<tr> <td width="120"><font size="4"><strong>Output</strong></font></td>'];
253                end
254                state = 'output';
255        elseif iotabstate % input/output table
256               
257               
258    if uppertoken  % next input/output parameter
259      s = [s '<tr> <td width="120" valign="baseline">' makecode(tok,1) '</td>'];
260                        [f0,f1] = regexp(posttok,'^ *[:-] *');
261                        if ~isempty(f0)
262                                posttok = posttok(f1+1:end);
263                        end
264      s = [s '<td valign="baseline">' findmakecode(posttok)];
265    else % continuation of description
266      s = [s htmlspace findmakecode(u)];
267    end
268               
269        elseif (tab || tabstate) ...
270                        && ~examplestate && ~startspace && ~tabstartspace % arbitrary table
271                if ~tabstate     % start table
272                        if liston, s = [s '</ul>']; liston = false; end
273                s = [s '</p><p>'];                % new paragraph
274                        s = [s '<table cellspacing="0" cellpadding="3" width="100%"'...
275                                ' align="center" border="0"']; % start table
276                        oldstate = state;
277                        state = 'tab';
278                        tabstate = true;
279                        cellopen = false;
280                end
281                if cellopen
282                        s = closecell(s);
283                        cellopen = false;
284                end
285                % first cell
286                s = [s '<tr> <td width="120" valign="baseline">' makecode(tok,1) '</td>'];
287                % get rid of :
288                [f0,f1] = regexp(posttok,'^ *: *');
289                if ~isempty(f0)
290                        posttok = posttok(f1+1:end);
291                end
292                colpos0 = findstr(cleanstr(posttok),r); % store starting pos 2nd cell
293                % second cell
294                s = [s '<td valign="baseline">'];
295                [tok2,posttok2] = strtok(posttok);
296                if strcmp(tok2,'-') % possible start of list
297                        s = [s '<ul><li>' findmakecode(posttok2)];
298                        liston = true;
299                else
300                        s = [s  findmakecode(posttok)];
301                        liston = false;
302                end
303                cellopen = true;
304               
305        elseif startspace && tab && ~textstate
306                if liston, s = [s '</ul>']; liston = 0; end
307                s = [s htmlspace findmakecode(u)];
308        elseif description && single
309                s = endtable(s,tab);
310                s = [s '</p><h3> Description</h3><p>' newline];
311                state = 'text';
312        elseif reference && single
313                s = endtable(s,tab);
314                s = [s '</p><h3> Reference(s)</h3><p>' newline];
315                nref = 0;
316                state = 'reference';
317        elseif example && single
318                s = endtable(s,tab);
319                s = [s '</p><h3> Example(s)</h3><p>' newline];
320                state = 'examp';
321%       elseif seealso && single
322%               s = endtable(s,tab);
323%               s = [s '</p><h3> See also</h3><p>' newline];
324%               state = 'seealso';
325        elseif seealso
326                s = endtable(s,tab);
327                s = [s '</p><h3> See also</h3><p>' newline];
328                state = 'seealso';
329                if ~single
330                        s = [s commandrefs(posttok,recreate,htmldir)];
331                end
332        else % undefined lines
333                if examplestate
334                        if length(u) > 3 && strcmpi(u(1:4),'see ')
335                                s = [s '</p>' commandrefs(u(5:end),recreate,fileparts(htmldir)) '<p>'];
336                        else
337                                s = [s strrep(code(strrep(r,' ','#$!'),0,3),'#$!','&nbsp;') '<br>'];
338        %                       s = [s code(r) '<br>'];
339                        end
340                elseif refstate
341                        if abs(u(1)>=48) && abs(u(1)<=57) && nref > 0
342                                s = [s '<br>' u];
343                        else
344                                s = [s htmlspace u];
345                                nref = 1;
346                        end
347                elseif seealsostate
348                        if listline
349                                s = [s '<strong><font size="4">' findmakecode(u(3:end)) '</font></strong><br>'];
350                        else
351                                s = [s commandrefs(u,recreate,htmldir)];               
352                        end
353                elseif tabstartspace && tabstate && (colpos1 > colpos0) ...
354                                && (previous_empty || coding) % start code in table
355                        s = [s  strrep(code(strrep(r(colpos0:end),' ','#$!'),0,3),'#$!','&nbsp;') '<br>'];
356                        coding = true;
357                elseif startspace && ~tabstate && ~liston ...
358                                && (previous_empty || coding) % code line
359                        s = [s strrep(code(strrep(r,' ','#$!'),2,3),'#$!','&nbsp;') '<br>'];
360                        nextlinespace = '';
361      coding = true;
362                elseif listline
363                        if ~liston
364                                s = [s '<ul>'];
365                                liston = true;
366                        end
367                        if u(end) == ':'
368                                s = [s '<li>' findmakecode(u(3:end-1)) '<br>'];
369                                nextlinespace = '';
370                        else
371                                s = [s '<li>' findmakecode(u(3:end))];
372                        end
373%               elseif tabstate && ~startspace && ~tabstartspace % end of table
374%                       s = endtable(s);
375%                       state = oldstate;
376%                       s = [s findmakecode(u)];
377                elseif tabstate % next line in table, store starting position
378                        colpos0 = colpos1;
379                        s = [s newlinespace findmakecode(cleanstr(u))];
380                else % just a line
381                        if u(end) == ':'
382                                s = [s newlinespace findmakecode(cleanstr(u(1:end-1))) '<br>'];
383                                nextlinespace = '';
384                        else
385                                s = [s newlinespace findmakecode(cleanstr(u))];
386                        end
387                %       s = [s newlinespace findmakecode(cleanstr(u))];
388                end
389        end
390       
391        if emptyline
392                previous_empty = true;
393        else
394                previous_empty = false;
395        end
396       
397end
398
399if cellopen
400        s = closecell(s);
401end
402if tabstate
403        s = endtable(s);
404end
405
406
407s = strrep(s,'<p>&nbsp;','<p>');
408s = strrep(s,' </font>&nbsp;',' </font>');
409s = strrep(s,['<p>' newline '&nbsp;'],'<p>');
410s = [s '</p>' content_manual '</body></html>'];
411[qq,name] = fileparts(name); % allows for names like dataset/show
412% if exist(fullfile(htmldir,name),'file') == 2
413%       htmlname = fullfile(htmldir,name);
414% else
415%       %htmlname = [tok '.html'];
416%       file = which(name);
417%       pp = fileparts(file);
418%       [qq,subdir] = fileparts(pp);
419%       htmldir = fullfile(fileparts(htmldir),subdir);
420%       htmlname = fullfile(htmldir,name);
421% end
422       
423if exist([htmldir],'file') ~= 7
424        mkdir(htmldir);
425end
426writf([fullfile(htmldir,name) '.html'],s);
427disp([int2str(recreate) ' ' name ' html created'])
428if nargout > 0
429        out = s;
430end
431       
432return
433
434function i = isupper(s)
435% true if s doesnot change by upper
436i = strcmp(s,upper(s));
437return
438
439function out = code(s,n,fsize)
440        %convert s to Courier, add n spaces in front, fontsize fsize
441        if nargin < 3, fsize = 2; end
442        if nargin < 2, n = 0; end
443        out = ['<font face="Courier" size="' int2str(fsize) '">' htmlspace(n) s '</font>'];
444return
445
446function out = makecode(s,n,fsize)
447        %convert any consequetive set of uppers and make them Courier size fsize,
448        % add n spaces in front
449        if strmatch(s(end),char(',','.'))
450                send = s(end); s(end) = [];
451        elseif length(s) > 1 && ~isempty(strmatch(s(end-1:end),char(', ','. ')))
452                send = s(end-1:end); s(end-1:end) = [];
453        else
454                send = [];
455        end
456        if nargin < 3, fsize = 2; end
457        if nargin < 2, n = 0; end
458        out = [];
459        if isupper(s)
460                %out = code(lower(s),n);
461                out = code(s,n,fsize);
462        else
463                while ~isempty(s)
464                        [t,s] = strtok(s);
465                        if isupper(t)
466                                %t = code(lower(t));
467                                t = code(t,n,fsize);
468                        end
469                        out = [out ' ' t];
470                end
471        end
472        out = [out send];
473return
474       
475function s = cleanstr(s)
476        V = char([9 10 11 12 13 32]);
477        for n=1:length(s)
478                if all(V~=s(n))
479                        break;
480                end
481        end
482        s = s(n:end);
483        for n=length(s):-1:1
484                if all(V~=s(n))
485                        break
486                end
487        end
488        s = s(1:n);
489return
490
491function s = endtable(s,tab)
492if strcmp(s(end-7:end),char([60 47 112 62 10 60 112  62]))
493        s(end-7:end) = [];
494end
495if strcmp(s(end-6:end),char([60 47 112 62 60 112  62]))
496        s(end-7:end) = [];
497end
498if nargin < 2 || tab % don't do this for tab = 0
499        s = [s '</td></tr></table>' newline]; % end table
500end
501
502function s = commandrefs(r,recreate,htmldir)
503        if nargin < 3, htmldir = cd; end
504        if nargin < 2 | isempty(recreate), recreate = 0; end
505        s = [];
506        r_debug = r;
507        while ~isempty(r) && isempty(regexp(r,'^[ .,]*$', 'once' ))
508                [tok,r] = strtok(r,' .,');
509                tok = lower(tok);
510                htmlname = [tok '.html'];
511                file = which(tok);
512                pp = fileparts(file);
513                [qq,subdir] = fileparts(pp);
514%               htmlname = fullfile(subdir,htmlname);
515                htmlfullname1 = fullfile(htmldir,htmlname);
516                htmlfullname2 = fullfile(fullfile(fileparts(htmldir),subdir),htmlname);
517                if exist(htmlfullname1,'file') == 2  % check whether command is in htmldir
518                        s = [s '<a href="./' htmlname '">' tok '</a>, '];
519                elseif exist(htmlfullname2,'file') == 2 % exists elsewhere?
520                        s = [s '<a href="../' fullfile(subdir,htmlname) '">' tok '</a>, '];
521                elseif isempty(tok) || ~isempty(regexp(tok,'^ *', 'once' ))
522                        ;
523                elseif recreate
524                        tt = prhelp2html(tok); % don't iterate further!
525                        if ~isempty(tt)
526                                s = [s '<a href="../' htmlname '">' tok '</a>, '];
527                        else
528                                % disp([r_debug ' --> ' tok ])
529                                s = [s tok ', '];
530                        end
531                else
532                        s = [s tok ', '];
533                end
534        end
535        if ~isempty(s)
536%               s(end-1:end) = [];
537                s = code(s,0,3);
538        end
539        s = strrep(s,'\','/'); % avoid  \ in html addresses
540return
541
542function s = htmlspace(n)
543        if nargin < 1, n=1; end
544        if n > 0
545                s = repmat('&nbsp;',1,n);
546        else
547                s = [];
548        end
549return
550
551function s = findmakecode(r)
552% find pieces of code (capitals only) and convert them to lower Courier
553r = strrep(r,'. A ','. aA ');  % prevent conversion of A at the start of a sentence
554r = [' ' r ' ']; % ending space may be helpful
555r = strrep(r,'NaN',code('NaN'));
556
557[f0,f1] = regexp(r,'[ ,(\[]+[A-Z0123456789=<>(){},.''''*+\\/;:\[\]_ ]+[ .,-]');
558
559%[f0,f1,toks] = regexp(r,'[ ,(]+[A-Z0123456789=<>(){},*+\\/;:\[\]_ ]+[ .,-]');
560if ~isempty(f0)
561        if f0(1) > 1 % first part no code
562                s = r(1:f0(1)-1);
563        else
564                s = [];
565        end
566        for j=1:length(f0)  % all code parts
567                s = [s makecode(r(f0(j):f1(j)))];
568                if j < length(f0) % between code parts
569                        s = [s r(f1(j)+1:f0(j+1)-1)];
570                end
571        end
572        if f1(end) < length(r) % last part no code
573                s = [s r(f1(end)+1:end)];
574        end
575else
576        s = r;
577end
578
579if s(end) == ' ', s(end) = []; end % remove ending space
580s = strrep(s,'. aA ','. A ');  % convert prevention back
581
582function s = closecell(s)
583if strcmp(s(end-7:end),char([60 47 112 62 10 60 112  62]))
584        s(end-7:end) = [];
585elseif strcmp(s(end-6:end),char([60 47 112 62 60 112  62]))
586        s(end-7:end) = [];
587end
588s = [s '</td></tr>'];
589
590
591%LISTN List lines specified by their line number
592%
593% t = listn(r,n)
594% Get the lines in r given by the line numbers in n.
595function t = listn(r,n)
596k = [0,find(r==newline)];
597t = [];
598for j = n
599        if j < length(k)
600    t = [t,r(k(j)+1:k(j+1))];
601        end
602end
603return
604
605function run_all_files(command,dirs,subdir)
606
607%dirs = {'ldc','dataset','datafile','mapping'};
608for n=1:length(dirs)
609        prtools_dir = fileparts(which(dirs{n}));
610        [qq,prtools_dirname] = fileparts(prtools_dir); % get rid of root
611        ff = dirnames(prtools_dir);
612        for j=1:length(ff)
613                [qq,name] = fileparts(ff{j});
614                if n==1
615                        feval(command,name,[],fullfile(subdir,prtools_dirname)); % prtools main commands
616                else
617                        feval(command,fullfile(prtools_dirname,name),[],fullfile(subdir,prtools_dirname)); % subdir commands
618                end
619        end
620end
621
622function files = dirnames(direct)
623% get all m-files in dir
624
625allnames = dir(fullfile(direct,'*.m'));
626files = char(allnames(:).name);
627files(strmatch('Contents.m',files),:) = [];
628files(strmatch('Readme.m',files),:) = [];
629files = cellstr(files);
630
631
632function s = gethf(file)
633%GETHF Create heading file from m-file
634%
635%       s = gethf(file)
636%
637% The heading of the given m-file consisting of all starting % lines
638% is isolated and returned in s.
639%
640%       gethf(dir)
641%
642% All headings of the files in dir are merged into a file named headings.doc.
643% Default dir is cd.
644%
645% Use mergeprt for restoring
646if nargin == 0
647        gethf(cd);
648end
649if isdir(file)
650        files = dir(file);
651        docfile = ['headings.doc'];
652        m = size(files,1);
653        for i = 1:m
654                if (~files(i,:).isdir) & (files(i,:).name(end-1:end) == '.m')
655                        name = files(i,:).name;
656                        s = gethf(name);
657                        s = ['##1' name(1:end-2) newline s newline '##2' newline];
658                        %disp(s)
659                        appendf(docfile,s);
660                end
661        end
662else
663        %disp(file)
664        [s,ns] = readf(file);
665        p = grep(s,'%');
666        if isempty(p) % no comments found
667                s = [];
668                return
669        end
670        p = [p p(end)+10];  % trick
671        I = find(p - [0,p(1:length(p)-1)] ~= 1);
672        if p(1) == 1 & isempty(I), I = length(p) + 1; end
673%       if length(I) > 0 & I(1) > 1
674        if length(I) > 0
675                if I(1) == 1
676                        I(1) = [];
677                end
678                n = I(1) - 1;
679                s = listn(s,p(1):n+p(1)-1);
680                s = strrep(s,[newline '%'],newline);
681                %s = strrep(s,[newline ' '],newline);
682                %s = strrep(s,[newline newline],'&*&');
683                %s = strrep(s,[newline '        '],'*&* ');
684                %s = strrep(s,newline,' ');
685                %s = strrep(s,'&*&',[newline newline]);
686                %s = strrep(s,'*&*',newline);
687                s = s(2:end);
688        else
689                s = '';
690        end
691end
692
693function [r,n] = readf(file,newline)
694%READF Readfile
695%
696% [r,n] = readf(file,newline)
697% Reads file into string r. The number of lines
698% is returned in n.
699if nargin < 2, newline = 13; end
700fid = fopen(deblank(file),'r');
701if fid < 0
702   error(['Cann''t open ' file])
703end
704r = fscanf(fid,'%c');
705fclose(fid);
706n = length(find(r==newline));
707if r(length(r)) ~= newline, n = n + 1; end
708return
709
710
711
712function writf(file,r)
713%WRITF Write file
714%
715% writf(file,r)
716% Write file from string r
717fid = fopen(file,'w');
718if fid < 0
719   error(['Cannot open file ' file])
720end
721fprintf(fid,'%c',r);
722fclose(fid);
723return
724
725
726function [k,z] = grep(r,s)
727%GREP Get line specific lines
728%
729% [k,n] = grep(r,s)
730% Get the numbers of all lines in the set of lines r
731% that contain s.
732% n is the total number of lines.
733n = [0,find(r==newline)];
734m = findstr(r,s);
735[i,j] = sort([n,m]);;
736q = [0,j(1:length(j)-1)]-j;
737k = j(find(q>0))-1;
738z = length(n)-1; % # of lines
739return
740
741
742function t = content_manual
743t = ['<table border="0" cellspacing="0" cellpadding="3" width="100%" '...
744           'align="center"><tr><td><a href="../prtools.html">contents</a>' ...
745                 '</td><td><p align="right"><a '...
746     'href="http://prtools.org/manual" target="_top">manual</a></p></td>'...
747                 '</tr></table></p>'];
748return
749
Note: See TracBrowser for help on using the repository browser.