| matref_write(filename,mdir,newdir,refm,prefix,postfix)
|
function [] = matref_write(filename,mdir,newdir,refm,prefix,postfix)
% [] = matref_write(filename,mdir,newdir,refm,prefix,postfix)
% Reads the TOTAL MATLAB code in an m-file and
% replaces the call to other m-files in every location in the text to
% a m-file name with the new pre- and postfixes.
%
% INPUT PARAMETERS
%
% mdir = directory containing the
% m-files in the toolbox you want to crosslink
% newdir = directory name containing all the html
% files under mdir. Assumes it exists!!
% filename = name of file WITH extension!
% refm = string matrix of all functions in mdir
% prefix = a string which is used as a prefix to m-file name
% postfix = a string which is used as a postfix to m-file name
%
% Copyright (c) B.K. Alsberg, 1997
%
loc_nam = [mdir,'\',filename];
ext = '.m';
%%%% Here we remove the extension %%%%%%%%%
pos = findstr(filename,'.');
if length(pos) >0,
filename_new = filename(1:pos-1);
else
filename_new = filename;
end;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
filename_new2 = [prefix,filename_new,postfix,ext];
fid = fopen([newdir,'\', filename_new2],'w');
fid2 = fopen(loc_nam,'r');
%% Sets the upper limit of characters on a line in the
%% m-file:
n = 150;
U = blanks(n);
%cdstr = ['cd ',newdir];
%eval(cdstr);
%%% Start reading into a matrix ALL the comment AND command
%%% lines in the m-file
k=1;
while feof(fid2) ~= 1,
str = fgetl(fid2);
q = min(n,length(str));
if q>0 & isstr(str) ==1,
% U(k,1:q) = str;
% This is to ensure we have a comparable case for the
% characters by keeping all names in lower case:
U(k,1:q) = lower(str(1:q));
else
U(k,:) = blanks(n);
end;
k=k+1;
end;
fclose(fid2);
[n1,m1]=size(U);
[n2,m2]=size(refm);
% Here we include the filename itself in the list since we can have
% a recursive function.
if m2 > 0,
nl = length(filename);
vec = blanks(m2);
vec(1:nl) = filename;
refm = [refm;vec];
n2 = n2+1;
else
refm = filename;
n2=1;
end;
for i = 1:n1
tmpstr = deblank(U(i,:));
for j = 1:n2
strtmp = deblank(refm(j,:));
q = length(strtmp);
%%%% Here we remove the extension %%%%%%%%%
refstring = strrep(strtmp,'.m',[]);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
newname = [prefix,refstring,postfix];
posidx =[];
posidx = findstr(tmpstr,newname);
if length(posidx) < 1,
tmpstr = strrep(tmpstr,refstring,newname);
end;
end;
fprintf(fid,'%s \n',tmpstr);
clear tmpstr
end;
fclose(fid);
|
|