%% ================================================================================
%% $RCSfile: ecmodulepacklib.tlc,v $
%% $Revision: 1.1.6.4 $
%% $Date: 2004/07/01 04:41:33 $
%%
%% Copyright 1994-2004 The MathWorks, Inc.
%%
%%   This is the Model Packaging  Library of Functions.
%%
%% =================================================================================

%% ================== List of Function available in this libarry ===================
%%
%%  SLibMPRegSymbols() void
%%
%% =================================================================================

%% =================== SLibMPRegSymbols ============================================
%%

%function SLibMPRegSymbols() void
%assign modelName = LibGetModelName()
%assign enabled  = FEVAL("ec_mpt_enabled",modelName)
%if (enabled == 1 && !IsModelReferenceTarget())

  %% Get list of all files and file types
  %assign fileNameList = []
  %assign typeList = []
  %assign codeTemplate = []
  %foreach fileIdx = LibGetNumModelFiles()
     %assign opFile = LibGetSourceFileFromIdx(fileIdx)
     %assign fileNameList = fileNameList + opFile.Name
     %assign typeList = typeList + opFile.Type
     %assign codeTemplate = codeTemplate + opFile.CodeTemplate
  %endforeach


  %% Get all template symbol related information in a single call to m
  %% Symbol and associated parents are included
  %% Any special symbol contents are also provided

  %assign info = FEVAL("ec_get_mp_data",modelName,fileNameList,typeList,codeTemplate)
  %if info.state == 1

    %% For each file, register symbols. 
    %%
    %% for each file
    %%   get the file name and type
    %%   get file reference record to permit registration of symbols
    %%   for each symbol
    %%     register it with the file. Include parent relationship
    %%   end
    %% end


    %assign lSize = SIZE(info.fileBuf)
    %foreach fileIdx = lSize[1]
      %assign fileName  = info.fileBuf[fileIdx].fileName
   %assign fileType = info.fileBuf[fileIdx].fileType
   %assign cFile = SLibDoesModelFileExist(fileType, fileName)
   %if TYPE(cFile) != "Scope" %% file doesn't exist.
     %assign fileType  = fileType == "SystemBody" ? "Source" : "Header"
     %assign cFile = LibCreateSourceFile(fileType, "Simulink", fileName)
   %endif
      %assign lSize2 = SIZE(info.fileBuf[fileIdx].symreg)
      %foreach index =lSize2[1]
        %<LibAddSourceFileCustomSection(cFile,info.fileBuf[fileIdx].symreg[index].parent, info.fileBuf[fileIdx].symreg[index].symbolName)>
      %endforeach
    %endforeach

    %% Register any addition symbol buffer contents
    %% for each file with contents
    %%  Get file and type infomration
    %%  get file indentification record. Create file is necessary
    %%  for each buffer associated with the file
    %%    Register the contents into the associated symbol
    %%  end
    %% end
    %assign lSize = SIZE(info.fileBuf)
    %foreach index =lSize[1]
      %assign fileName = info.fileBuf[index].fileName
      %assign fileType = info.fileBuf[index].fileType
   %assign cFile = SLibDoesModelFileExist(fileType, fileName)
   %if TYPE(cFile) != "Scope" %% file doesn't exist.
     %assign fileType  = fileType == "SystemBody" ? "Source" : "Header"
     %assign cFile = LibCreateSourceFile(fileType, "Simulink", fileName)
   %endif
      %assign lSize2 = SIZE(info.fileBuf[index].buffer)
      %foreach index2 = lSize2[1]
        %assign bufferName = info.fileBuf[index].buffer[index2].bufferName
        %assign bufferContent = info.fileBuf[index].buffer[index2].bufferContent
        %<LibSetSourceFileCustomSection(cFile,bufferName,bufferContent)>
      %endforeach
    %endforeach
  %endif
%endif
%return
%endfunction
