gusucode.com > private工具箱matlab源码程序 > private/code_sfun_customcode_source_file.m

    function code_sfun_customcode_source_file(fileNameInfo, customCodeSettings)
% CODE_SFUN_CUSTOMCODE_SOURCE_FILE(FILENAMEINFO)

%   Copyright 2015 The MathWorks, Inc.

   global gMachineInfo

   if nargin < 2
      customCodeSettings = get_custom_code_settings(gMachineInfo.target, gMachineInfo.parentTarget);
   end

   fileName = fullfile(fileNameInfo.targetDirName, fileNameInfo.customCodeSourceFile);
   sf_echo_generating('Coder', fileName);

   file = fopen(fileName,'Wt');
   if file<3
       construct_coder_error([],sprintf('Failed to create file: %s.',fileName),1);
       return
   end

   % Include the extra custom code header which includes global
   % declaration, header files,...
fprintf(file,'#include "%s"\n',fileNameInfo.customCodeHeaderFile);
fprintf(file,'\n');
   if gMachineInfo.ctxInfo.sfcnTgtCustomCodeInfo.hasSourceCode
fprintf(file,'/* Custom Source Code */\n');
fprintf(file,'%s\n',customCodeSettings.customSourceCode);
fprintf(file,'\n');
   end

fprintf(file,'/* Function Definition */\n');
   if gMachineInfo.ctxInfo.sfcnTgtCustomCodeInfo.hasInitCode
fprintf(file,'void %s_customcode_initializer(void)\n',gMachineInfo.machineName);
fprintf(file,'{\n');
fprintf(file,'   %s\n',customCodeSettings.customInitializer);
fprintf(file,'}\n');
   end
fprintf(file,'\n');
   if gMachineInfo.ctxInfo.sfcnTgtCustomCodeInfo.hasTermCode
fprintf(file,'void %s_customcode_terminator(void)\n',gMachineInfo.machineName);
fprintf(file,'{\n');
fprintf(file,'   %s\n',customCodeSettings.customTerminator);
fprintf(file,'}\n');
   end
fprintf(file,'\n');

   fclose(file);
   try_indenting_file(fileName);