Home > utility > findInc.m

findInc

PURPOSE ^

findInc: Find included files in a given C file

SYNOPSIS ^

function out = findInc(fileName)

DESCRIPTION ^

findInc: Find included files in a given C file
    Usage: out = findInc(fileName)
        fileName: file to be search
        out: Included files in a cell string

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function out = findInc(fileName)
0002 %findInc: Find included files in a given C file
0003 %    Usage: out = findInc(fileName)
0004 %        fileName: file to be search
0005 %        out: Included files in a cell string
0006 
0007 %    Roger Jang, 20020101
0008 
0009 fid = fopen(fileName);
0010 if fid<0,
0011     error(sprintf('Cannot open "%s"!', fileName));
0012 end
0013 
0014 lineNum = 1;
0015 while 1
0016     line = fgetl(fid);
0017     if ~isstr(line), break, end
0018     contents{lineNum} = xlate(line);
0019     lineNum = lineNum+1;
0020 end
0021 fclose(fid);
0022 
0023 out = {};
0024 for i=1:length(contents),
0025     line = contents{i};
0026     if ~isempty(line),
0027         pos = findstr(line, '#include "');
0028         if ~isempty(pos) & pos==1,
0029             temp = split(line, '"');
0030             out = {out{:}, temp{2}};
0031         end
0032     end
0033 end
0034 
0035 
0036 
0037 
0038 
0039 
0040 
0041 
0042 
0043 
0044 % Function for split
0045 function tokenList = split(str, delimiter)
0046 % SPLIT Split a string based on a given delimiter
0047 %    Usage:
0048 %    tokenList = split(str, delimiter)
0049 
0050 %    Roger Jang, 20010324
0051 
0052 tokenList = {};
0053 remain = str;
0054 i = 1;
0055 while ~isempty(remain),
0056     [token, remain] = strtok(remain, delimiter);
0057     tokenList{i} = token;
0058     i = i+1;
0059 end

Generated on Tue 01-Jun-2010 09:50:34 by m2html © 2003