Changeset 527 for CMT/HEAD


Ignore:
Timestamp:
Nov 20, 2009, 10:45:54 AM (15 years ago)
Author:
rybkin
Message:

See C.L. 414

Location:
CMT/HEAD
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • CMT/HEAD/ChangeLog

    r526 r527  
     12009-11-20    <rybkin@lal.in2p3.fr> 414
     2
     3        * source/cmt_system.h: In class CmtSystem, introduce functions
     4        close_ostream, close_stdout in order check whether there are file write
     5        errors, and exit with an error if that is the case
     6        * source/cmt_system.cxx: Implement introduced functions, in function
     7        CmtSystem::compare_and_update_files, check file stream status
     8        * source/cmt_generators.cxx: Set file_access_error error if file cannot be
     9        opened for writing, close file streams on writing making use of
     10        close_ostream
     11        * source/cmt_generator.cxx: idem
     12        * source/cmt_parser.cxx: idem, in setup.[c]sh, cleanup.[c]sh scripts, check
     13        CMT command exit status, on failure, print the command and exit,
     14        for "cmt filter" command, set path_not_found error, when appropriate
     15        * source/cmt.cxx: Close stdout with CmtSystem::close_stdout before exiting
     16        the program
     17        * source/cmt_string.cxx: In function cmt_string::write, check file stream
     18        status
     19        * src/Makefile.header: Improve a diagnostic message by using the standard
     20        macros
     21        * mgr/cmt_dependencies.make: Update
     22       
    1232009-11-13    <rybkin@lal.in2p3.fr> 413
    224
  • CMT/HEAD/mgr/cmt_dependencies.make

    r496 r527  
    2929cmt_cmtpath_pattern_cxx_dependencies =  ../source/cmt_cmtpath_pattern.cxx   ../source/cmt_vector.h   ../source/cmt_std.h   ../source/cmt_string.h   ../source/cmt_regexp.h   ../source/cmt_system.h   ../source/cmt.h   ../source/cmt_parser.h   ../source/cmt_branch.h   ../source/cmt_fragment.h   ../source/cmt_group.h   ../source/cmt_constituent.h   ../source/cmt_language.h   ../source/cmt_map.h   ../source/cmt_pattern.h   ../source/cmt_include.h   ../source/cmt_script.h   ../source/cmt_scope_section.h   ../source/cmt_use.h   ../source/cmt_tag.h   ../source/cmt_symbol.h   ../source/cmt_awk.h   ../source/cmt_project.h   ../source/cmt_cmtpath_pattern.h   ../source/cmt_database.h   ../source/cmt_syntax.h
    3030cmt_sequence_cxx_dependencies =  ../source/cmt_sequence.cxx   ../source/cmt_std.h   ../source/cmt_string.h   ../source/cmt_regexp.h   ../source/cmt_awk.h   ../source/cmt_sequence.h   ../source/cmt_vector.h   ../source/cmt_system.h
    31 cmt_generators_cxx_dependencies =  ../source/cmt_generators.cxx   ../source/cmt_std.h   ../source/cmt_string.h   ../source/cmt_vector.h   ../source/cmt_regexp.h   ../source/cmt_system.h   ../source/cmt.h   ../source/cmt_parser.h   ../source/cmt_fragment.h   ../source/cmt_group.h   ../source/cmt_constituent.h   ../source/cmt_language.h   ../source/cmt_awk.h   ../source/cmt_map.h   ../source/cmt_include.h   ../source/cmt_script.h   ../source/cmt_pattern.h   ../source/cmt_scope_section.h   ../source/cmt_use.h   ../source/cmt_deps_builder.h   ../source/cmt_generator.h   ../source/cmt_generators.h   ../source/cmt_tag.h   ../source/cmt_symbol.h   ../source/cmt_log.h
     31cmt_generators_cxx_dependencies =  ../source/cmt_generators.cxx   ../source/cmt_std.h   ../source/cmt_string.h   ../source/cmt_vector.h   ../source/cmt_regexp.h   ../source/cmt_system.h   ../source/cmt.h   ../source/cmt_parser.h   ../source/cmt_fragment.h   ../source/cmt_group.h   ../source/cmt_constituent.h   ../source/cmt_language.h   ../source/cmt_awk.h   ../source/cmt_map.h   ../source/cmt_include.h   ../source/cmt_script.h   ../source/cmt_pattern.h   ../source/cmt_scope_section.h   ../source/cmt_use.h   ../source/cmt_deps_builder.h   ../source/cmt_generator.h   ../source/cmt_generators.h   ../source/cmt_tag.h   ../source/cmt_symbol.h   ../source/cmt_log.h   ../source/cmt_error.h
    3232cmt_scope_section_cxx_dependencies =  ../source/cmt_scope_section.cxx   ../source/cmt_std.h   ../source/cmt_string.h   ../source/cmt_vector.h   ../source/cmt_regexp.h   ../source/cmt_system.h   ../source/cmt.h   ../source/cmt_parser.h   ../source/cmt_scope_section.h
    3333cmt_log_cxx_dependencies =  ../source/cmt_log.cxx   ../source/cmt_std.h   ../source/cmt_string.h   ../source/cmt_log.h   ../source/cmt_vector.h   ../source/cmt_parser.h   ../source/cmt_regexp.h   ../source/cmt_system.h   ../source/cmt.h
  • CMT/HEAD/source/cmt.cxx

    r400 r527  
    2222    }
    2323
     24  CmtSystem::close_stdout ();
     25
    2426  return (status);
    2527}
  • CMT/HEAD/source/cmt_generator.cxx

    r488 r527  
    312312void CmtGenerator::terminate ()
    313313{
    314   fclose (m_output_file);
     314  CmtSystem::close_ostream (m_output_file, m_output_file_name);
     315  //  fclose (m_output_file);
    315316
    316317  //--- Complete the operation --------------
  • CMT/HEAD/source/cmt_generators.cxx

    r488 r527  
    1010#include "cmt_symbol.h"
    1111#include "cmt_log.h"
     12#include "cmt_error.h"
    1213#include <assert.h>
    1314
     
    13241325      terminate ();
    13251326    }
     1327  else
     1328    {
     1329      CmtError::set (CmtError::file_access_error, m_output_file_name);
     1330    }
    13261331}
    13271332
     
    15571562                  */
    15581563                  s.write (file);
    1559                   fclose (file);
     1564                  CmtSystem::close_ostream (file, backup);
     1565                  //  fclose (file);
    15601566
    15611567                  need_makefile = true;
    15621568                }
     1569              else
     1570                {
     1571                  CmtError::set (CmtError::file_access_error, backup);
     1572                }
    15631573            }
    15641574        }
     
    15701580      if (file != NULL)
    15711581        {
    1572           fprintf (file, "include $(CMTROOT)/src/Makefile.header\n");
    1573           fprintf (file, "\n");
    1574           fprintf (file, "include $(CMTROOT)/src/constituents.make\n");
    1575           fprintf (file, "\n");
    1576           fclose (file);
    1577         }
     1582          fprintf (file,
     1583                   "include $(CMTROOT)/src/Makefile.header\n"
     1584                   "\n"
     1585                   "include $(CMTROOT)/src/constituents.make\n"
     1586                   "\n");
     1587          CmtSystem::close_ostream (file, makefile);
     1588          //          fclose (file);
     1589        }
     1590      else
     1591        {
     1592          CmtError::set (CmtError::file_access_error, makefile);
     1593        }
    15781594    }
    15791595
     
    15941610      if (file != NULL)
    15951611        {
    1596           fprintf (file, "!include $(CMTROOT)\\src\\NMakefile.header\n");
    1597           fprintf (file, "\n");
    1598           fprintf (file, "!include $(CMTROOT)\\src\\constituents.nmake\n");
    1599           fprintf (file, "\n");
    1600           fclose (file);
    1601         }
     1612          fprintf (file,
     1613                   "!include $(CMTROOT)\\src\\NMakefile.header\n"
     1614                   "\n"
     1615                   "!include $(CMTROOT)\\src\\constituents.nmake\n"
     1616                   "\n");
     1617          CmtSystem::close_ostream (file, makefile);
     1618          //          fclose (file);
     1619        }
     1620      else
     1621        {
     1622          CmtError::set (CmtError::file_access_error, makefile);
     1623        }
    16021624    }
    16031625
     
    17471769      terminate ();
    17481770    }
     1771  else
     1772    {
     1773      CmtError::set (CmtError::file_access_error, m_output_file_name);
     1774    }
    17491775
    17501776  m_output_file_name = msdevdir + "all.dspnew";
     
    17551781      dsp_all_fragment.wincopy (m_output_file, 1, &m_PACKAGE);
    17561782      terminate ();
     1783    }
     1784  else
     1785    {
     1786      CmtError::set (CmtError::file_access_error, m_output_file_name);
    17571787    }
    17581788
     
    24292459      make_setup_fragment.copy (m_output_file, 1, &m_PACKAGE);
    24302460
    2431       fclose (m_output_file);
     2461      CmtSystem::close_ostream (m_output_file, new_file_name);
     2462      //  fclose (m_output_file);
    24322463
    24332464      //--- Complete the operation --------------
    24342465
    24352466      commit (new_file_name);
     2467    }
     2468  else
     2469    {
     2470      CmtError::set (CmtError::file_access_error, new_file_name);
    24362471    }
    24372472
     
    26372672      constituents_trailer_fragment.copy (m_output_file, 0);
    26382673
    2639       fclose (m_output_file);
     2674      CmtSystem::close_ostream (m_output_file, new_file_name);
     2675      //  fclose (m_output_file);
    26402676
    26412677      commit (new_file_name);
     2678    }
     2679  else
     2680    {
     2681      CmtError::set (CmtError::file_access_error, new_file_name);
    26422682    }
    26432683}
     
    29673007  FILE* f = fopen (m_output_file_name.c_str (), "wb");
    29683008
    2969   if (f == 0)
    2970     {
    2971       CmtMessage::error ("Cannot open " + m_output_file_name + " for write");
    2972       //      cerr << "Cannot open " << m_output_file_name << " for write" << endl;
     3009  if (f != 0)
     3010    {
     3011      dependencies.write (f);
     3012      CmtSystem::close_ostream (f, m_output_file_name);
     3013      //          fclose (f);
    29733014    }
    29743015  else
    29753016    {
    2976       dependencies.write (f);
    2977       fclose (f);
     3017      CmtError::set (CmtError::file_access_error, m_output_file_name);
     3018      //      CmtMessage::error ("Cannot open " + m_output_file_name + " for write");
    29783019    }
    29793020
  • CMT/HEAD/source/cmt_parser.cxx

    r525 r527  
    25052505  //  configure_current_package ();
    25062506
    2507   Generator::build_default_makefile ();
     2507  //  Generator::build_default_makefile ();
    25082508
    25092509  CmtSystem::cmt_string_vector makes;
     
    25812581  install_cleanup_scripts ();
    25822582  install_native_version_file ();
     2583
     2584  Generator::build_default_makefile ();
    25832585
    25842586  CmtSystem::cd ("..");
     
    31993201  if (!CmtSystem::test_file (input))
    32003202    {
    3201       CmtMessage::error ("File " + input + " not found");
    3202       //      cerr << "#CMT> File " << input << " not found" << endl;
     3203      CmtError::set (CmtError::path_not_found, input);
     3204      //      CmtMessage::error ("File " + input + " not found");
    32033205      return;
    32043206    }
     
    32133215
    32143216  FILE* file = fopen (output, "wb");
    3215   if (file == NULL)
    3216     {
    3217       CmtMessage::error ("Cannot write filtered file " + output);
    3218       //      cerr << "#CMT> Cannot write filtered file " << output << endl;
     3217  if (file != NULL)
     3218    {
     3219      text.write (file);
     3220      CmtSystem::close_ostream (file, output);
     3221      //      fclose (file);
    32193222    }
    32203223  else
    32213224    {
    3222       text.write (file);
    3223       fclose (file);
     3225      CmtError::set (CmtError::file_access_error, output);
     3226      //      CmtMessage::error ("Cannot write filtered file " + output);
    32243227    }
    32253228}
     
    48124815              fprintf (f, "if $status != 0 then\n  set tempfile=/tmp/cmt.$$\nendif\n");
    48134816              fprintf (f, "${CMTROOT}/mgr/cmt cleanup -%s "
    4814                        "-pack=%s -version=%s -path=%s $* >${tempfile}; "
    4815                        "source ${tempfile}\n",
     4817                       "-pack=%s -version=%s -path=%s $* >${tempfile}\n",
    48164818                       suffix[i].c_str (),
    48174819                       Me.m_current_package.c_str (),
    48184820                       version.c_str (),
    48194821                       Me.m_current_path.c_str ());
    4820               fprintf (f, "/bin/rm -f ${tempfile}\n");
     4822              fprintf (f,
     4823                       "if ( $status == 0 ) then\n"
     4824                       "  source ${tempfile}\n"
     4825                       "  /bin/rm -f ${tempfile}\n"
     4826                       "else\n"
     4827                       "  echo \"${CMTROOT}/mgr/cmt cleanup -%s "
     4828                       "-pack=%s -version=%s -path=%s $* >${tempfile}\"\n"
     4829                       "  /bin/rm -f ${tempfile}\n"
     4830                       "  false\n"
     4831                       "endif\n",
     4832                       suffix[i].c_str (),
     4833                       Me.m_current_package.c_str (),
     4834                       version.c_str (),
     4835                       Me.m_current_path.c_str ());
    48214836            }
    48224837          else if (mode[i] == Sh)
     
    48294844              fprintf (f, "if test ! $? = 0 ; then tempfile=/tmp/cmt.$$; fi\n");
    48304845              fprintf (f, "${CMTROOT}/mgr/cmt cleanup -%s "
    4831                        "-pack=%s -version=%s -path=%s $* >${tempfile}; "
    4832                        ". ${tempfile}\n",
     4846                       "-pack=%s -version=%s -path=%s $* >${tempfile}\n",
    48334847                       suffix[i].c_str (),
    48344848                       Me.m_current_package.c_str (),
    48354849                       version.c_str (),
    48364850                       Me.m_current_path.c_str ());
    4837               fprintf (f, "/bin/rm -f ${tempfile}\n");
     4851              fprintf (f,
     4852                       "if test $? = 0 ; then\n"
     4853                       "  . ${tempfile}\n"
     4854                       "  /bin/rm -f ${tempfile}\n"
     4855                       "else\n"
     4856                       "  echo >&2 \"${CMTROOT}/mgr/cmt cleanup -%s "
     4857                       "-pack=%s -version=%s -path=%s $* >${tempfile}\"\n"
     4858                       "  /bin/rm -f ${tempfile}\n"
     4859                       "  false\n"
     4860                       "fi\n",
     4861                       suffix[i].c_str (),
     4862                       Me.m_current_package.c_str (),
     4863                       version.c_str (),
     4864                       Me.m_current_path.c_str ());
    48384865            }
    48394866          else if (mode[i] == Bat)
     
    48464873          fprintf (f, "\n");
    48474874
    4848           fclose (f);
     4875          CmtSystem::close_ostream (f, file_name);
     4876          //          fclose (f);
    48494877
    48504878          cmt_string old_file_name = "cleanup";
     
    48544882          CmtSystem::compare_and_update_files (file_name, old_file_name);
    48554883        }
     4884      else
     4885        {
     4886          CmtError::set (CmtError::file_access_error, file_name);
     4887        }
    48564888    }
    48574889}
     
    49324964              fprintf (f, "if $status != 0 then\n  set tempfile=/tmp/cmt.$$\nendif\n");
    49334965              fprintf (f, "${CMTROOT}/mgr/cmt setup -%s "
    4934                        "-pack=%s -version=%s -path=%s %s $* >${tempfile}; "
    4935                        "source ${tempfile}\n",
     4966                       "-pack=%s -version=%s -path=%s %s $* >${tempfile}\n",
    49364967                       suffix[i].c_str (),
    49374968                       Me.m_current_package.c_str (),
     
    49394970                       Me.m_current_path.c_str (),
    49404971                       no_cleanup_opt.c_str ());
    4941               fprintf (f, "/bin/rm -f ${tempfile}\n");
     4972              fprintf (f,
     4973                       "if ( $status == 0 ) then\n"
     4974                       "  source ${tempfile}\n"
     4975                       "  /bin/rm -f ${tempfile}\n"
     4976                       "else\n"
     4977                       "  echo \"${CMTROOT}/mgr/cmt setup -%s "
     4978                       "-pack=%s -version=%s -path=%s %s $* >${tempfile}\"\n"
     4979                       "  /bin/rm -f ${tempfile}\n"
     4980                       "  false\n"
     4981                       "endif\n",
     4982                       suffix[i].c_str (),
     4983                       Me.m_current_package.c_str (),
     4984                       version.c_str (),
     4985                       Me.m_current_path.c_str (),
     4986                       no_cleanup_opt.c_str ());
    49424987            }
    49434988          else if (mode[i] == Sh)
     
    49575002              fprintf (f, "if test ! $? = 0 ; then tempfile=/tmp/cmt.$$; fi\n");
    49585003              fprintf (f, "${CMTROOT}/mgr/cmt setup -%s "
    4959                        "-pack=%s -version=%s -path=%s %s $* >${tempfile}; "
    4960                        ". ${tempfile}\n",
     5004                       "-pack=%s -version=%s -path=%s %s $* >${tempfile}\n",
    49615005                       suffix[i].c_str (),
    49625006                       Me.m_current_package.c_str (),
     
    49645008                       Me.m_current_path.c_str (),
    49655009                       no_cleanup_opt.c_str ());
    4966               fprintf (f, "/bin/rm -f ${tempfile}\n");
     5010              fprintf (f,
     5011                       "if test $? = 0 ; then\n"
     5012                       "  . ${tempfile}\n"
     5013                       "  /bin/rm -f ${tempfile}\n"
     5014                       "else\n"
     5015                       "  echo >&2 \"${CMTROOT}/mgr/cmt setup -%s "
     5016                       "-pack=%s -version=%s -path=%s %s $* >${tempfile}\"\n"
     5017                       "  /bin/rm -f ${tempfile}\n"
     5018                       "  false\n"
     5019                       "fi\n",
     5020                       suffix[i].c_str (),
     5021                       Me.m_current_package.c_str (),
     5022                       version.c_str (),
     5023                       Me.m_current_path.c_str (),
     5024                       no_cleanup_opt.c_str ());
    49675025            }
    49685026          else if (mode[i] == Bat)
     
    49785036          fprintf (f, "\n");
    49795037
    4980           fclose (f);
     5038          CmtSystem::close_ostream (f, file_name);
     5039          //          fclose (f);
    49815040
    49825041          cmt_string old_file_name = "setup";
     
    49865045          CmtSystem::compare_and_update_files (file_name, old_file_name);
    49875046        }
     5047      else
     5048        {
     5049          CmtError::set (CmtError::file_access_error, file_name);
     5050        }
    49885051    }
    49895052}
     
    50495112              fprintf (f, "set tempfile=`${CMTROOT}/mgr/cmt -quiet build temporary_name`\n");
    50505113              fprintf (f, "if $status != 0 then\n  set tempfile=/tmp/cmt.$$\nendif\n");
    5051               fprintf (f, "${CMTROOT}/mgr/cmt cleanup -%s -pack=cmt_standalone -path=%s $* >${tempfile}; "
    5052                        "source ${tempfile}\n",
     5114              fprintf (f, "${CMTROOT}/mgr/cmt cleanup -%s -pack=cmt_standalone -path=%s $* >${tempfile}\n",
    50535115                       suffix[i].c_str (),
    50545116                       Me.m_current_path.c_str ());
    5055               fprintf (f, "/bin/rm -f ${tempfile}\n");
     5117              fprintf (f,
     5118                       "if ( $status == 0 ) then\n"
     5119                       "  source ${tempfile}\n"
     5120                       "  /bin/rm -f ${tempfile}\n"
     5121                       "else\n"
     5122                       "  echo \"${CMTROOT}/mgr/cmt cleanup -%s -pack=cmt_standalone -path=%s $* >${tempfile}\"\n"
     5123                       "  /bin/rm -f ${tempfile}\n"
     5124                       "  false\n"
     5125                       "endif\n",
     5126                       suffix[i].c_str (),
     5127                       Me.m_current_path.c_str ());
    50565128            }
    50575129          else if (mode[i] == Sh)
     
    50635135              fprintf (f, "tempfile=`${CMTROOT}/mgr/cmt -quiet build temporary_name`\n");
    50645136              fprintf (f, "if test ! $? = 0 ; then tempfile=/tmp/cmt.$$; fi\n");
    5065               fprintf (f, "${CMTROOT}/mgr/cmt cleanup -%s -pack=cmt_standalone -path=%s $* >${tempfile}; "
    5066                        ". ${tempfile}\n",
     5137              fprintf (f, "${CMTROOT}/mgr/cmt cleanup -%s -pack=cmt_standalone -path=%s $* >${tempfile}\n",
    50675138                       suffix[i].c_str (),
    50685139                       Me.m_current_path.c_str ());
    5069               fprintf (f, "/bin/rm -f ${tempfile}\n");
     5140              fprintf (f,
     5141                       "if test $? = 0 ; then\n"
     5142                       "  . ${tempfile}\n"
     5143                       "  /bin/rm -f ${tempfile}\n"
     5144                       "else\n"
     5145                       "  echo >&2 \"${CMTROOT}/mgr/cmt cleanup -%s -pack=cmt_standalone -path=%s $* >${tempfile}\"\n"
     5146                       "  /bin/rm -f ${tempfile}\n"
     5147                       "  false\n"
     5148                       "fi\n",
     5149                       suffix[i].c_str (),
     5150                       Me.m_current_path.c_str ());
    50705151            }
    50715152          else
     
    50785159          fprintf (f, "\n");
    50795160
    5080           fclose (f);
     5161          CmtSystem::close_ostream (f, file_name);
     5162          //          fclose (f);
    50815163
    50825164          cmt_string old_file_name = "cleanup";
     
    50865168          CmtSystem::compare_and_update_files (file_name, old_file_name);
    50875169        }
     5170      else
     5171        {
     5172          CmtError::set (CmtError::file_access_error, file_name);
     5173        }
    50885174    }
    50895175}
     
    51045190            cerr << "Creating native_version file." << endl;   
    51055191
    5106           FILE* f = fopen ("new.native_version.cmt", "wb");
    5107 
     5192          cmt_string file_name ("new.native_version.cmt");
     5193          FILE* f = fopen (file_name.c_str (), "wb");
    51085194          if (f != NULL)
    51095195            {
    51105196              fprintf (f, "%s\n", value.c_str ());
     5197              CmtSystem::close_ostream (f, file_name);
     5198              //          fclose (f);
     5199             
     5200              CmtSystem::compare_and_update_files ("new.native_version.cmt", "native_version.cmt");
    51115201            }     
    5112 
    5113           fclose (f);
    5114 
    5115           CmtSystem::compare_and_update_files ("new.native_version.cmt", "native_version.cmt");
     5202          else
     5203            {
     5204              CmtError::set (CmtError::file_access_error, file_name);
     5205            }
    51165206        }
    51175207    }   
     
    51845274              fprintf (f, "set tempfile=`${CMTROOT}/mgr/cmt -quiet build temporary_name`\n");
    51855275              fprintf (f, "if $status != 0 then\n  set tempfile=/tmp/cmt.$$\nendif\n");
    5186               fprintf (f, "${CMTROOT}/mgr/cmt setup -%s -pack=cmt_standalone -path=%s %s $* >${tempfile}; "
    5187                        "source ${tempfile}\n",
     5276              fprintf (f, "${CMTROOT}/mgr/cmt setup -%s -pack=cmt_standalone -path=%s %s $* >${tempfile}\n",
    51885277                       suffix[i].c_str (),
    51895278                       Me.m_current_path.c_str (),
    51905279                       no_cleanup_opt.c_str ());
    5191               fprintf (f, "/bin/rm -f ${tempfile}\n");
     5280              fprintf (f,
     5281                       "if ( $status == 0 ) then\n"
     5282                       "  source ${tempfile}\n"
     5283                       "  /bin/rm -f ${tempfile}\n"
     5284                       "else\n"
     5285                       "  echo \"${CMTROOT}/mgr/cmt setup -%s -pack=cmt_standalone -path=%s %s $* >${tempfile}\"\n"
     5286                       "  /bin/rm -f ${tempfile}\n"
     5287                       "  false\n"
     5288                       "endif\n",
     5289                       suffix[i].c_str (),
     5290                       Me.m_current_path.c_str (),
     5291                       no_cleanup_opt.c_str ());
    51925292            }
    51935293          else if (mode[i] == Sh)
     
    52035303              fprintf (f, "tempfile=`${CMTROOT}/mgr/cmt -quiet build temporary_name`\n");
    52045304              fprintf (f, "if test ! $? = 0 ; then tempfile=/tmp/cmt.$$; fi\n");
    5205               fprintf (f, "${CMTROOT}/mgr/cmt setup -%s -pack=cmt_standalone -path=%s %s $* >${tempfile}; "
    5206                        ". ${tempfile}\n",
     5305              fprintf (f, "${CMTROOT}/mgr/cmt setup -%s -pack=cmt_standalone -path=%s %s $* >${tempfile}\n",
    52075306                       suffix[i].c_str (),
    52085307                       Me.m_current_path.c_str (),
    52095308                       no_cleanup_opt.c_str ());
    5210               fprintf (f, "/bin/rm -f ${tempfile}\n");
     5309              fprintf (f,
     5310                       "if test $? = 0 ; then\n"
     5311                       "  . ${tempfile}\n"
     5312                       "  /bin/rm -f ${tempfile}\n"
     5313                       "else\n"
     5314                       "  echo >&2 \"${CMTROOT}/mgr/cmt setup -%s -pack=cmt_standalone -path=%s %s $* >${tempfile}\"\n"
     5315                       "  /bin/rm -f ${tempfile}\n"
     5316                       "  false\n"
     5317                       "fi\n",
     5318                       suffix[i].c_str (),
     5319                       Me.m_current_path.c_str (),
     5320                       no_cleanup_opt.c_str ());
    52115321            }
    52125322          else
     
    52205330          fprintf (f, "\n");
    52215331
    5222           fclose (f);
     5332          CmtSystem::close_ostream (f, file_name);
     5333          //          fclose (f);
    52235334
    52245335          cmt_string old_file_name = "setup";
     
    52285339          CmtSystem::compare_and_update_files (file_name, old_file_name);
    52295340        }
     5341      else
     5342        {
     5343          CmtError::set (CmtError::file_access_error, file_name);
     5344        }
    52305345    }
    52315346}
     
    56235738    {
    56245739      int code = CmtError::get_last_error_code ();
    5625       if (!Me.m_quiet) CmtError::print ();
     5740      CmtError::print ();
     5741      //      if (!Me.m_quiet) CmtError::print ();
    56265742      clear ();
    56275743
     
    63966512        }   
    63976513     
    6398       if (!Me.m_quiet) CmtError::print ();
     6514      CmtError::print ();
     6515      //      if (!Me.m_quiet) CmtError::print ();
    63996516      clear ();
    64006517      return (code);
  • CMT/HEAD/source/cmt_string.cxx

    r11 r527  
    759759    {
    760760      write (f);
    761       fclose (f);
     761      if (ferror (f))
     762        return (false);
     763      if (fclose (f))
     764        return (false);
    762765      return (true);
    763766    }
  • CMT/HEAD/source/cmt_system.cxx

    r515 r527  
    528528    {
    529529      s1.write (f);
    530       fclose (f);
     530      if (ferror (f))
     531        return (false);
     532      if (fclose (f))
     533        return (false);
    531534
    532535      unlink (name1);
     
    24192422}
    24202423
    2421 
    2422 
    2423 
     2424//----------------------------------------------------------
     2425void CmtSystem::close_ostream (FILE *stream, const cmt_string& name)
     2426{
     2427  cmt_string msg ("Cannot write");
     2428  cmt_string n = (name != "") ? " " + name : "";
     2429  if (stream == NULL)
     2430    {
     2431      CmtMessage::error (msg + n);
     2432      exit (EXIT_FAILURE);
     2433    }
     2434
     2435  bool prev_fail = ferror (stream);
     2436  bool fclose_fail = fclose (stream);
     2437
     2438  if (prev_fail || fclose_fail)
     2439    {
     2440      int err = fclose_fail ? errno : 0;
     2441      cmt_string e = err ? ": " + cmt_string (strerror (err)) : "";
     2442      CmtMessage::error (msg + n + e);
     2443      exit (EXIT_FAILURE);
     2444    }
     2445}
     2446
     2447//----------------------------------------------------------
     2448void CmtSystem::close_stdout (void)
     2449{
     2450  /*
     2451   * The idea and, to some extent, implementation of this function
     2452   * was borrowed from the GNU core utilities of the Free Software Foundation
     2453   * http://www.gnu.org/software/coreutils/
     2454   */
     2455  close_ostream (stdout, "stdout");
     2456}
    24242457
    24252458//----------------------------------------------------------
  • CMT/HEAD/source/cmt_system.h

    r435 r527  
    145145  static cmt_string get_makefile_suffix ();
    146146
     147  static void close_ostream (FILE *stream, const cmt_string& name = "" );
     148  static void close_stdout (void);
     149
    147150};
    148151
  • CMT/HEAD/src/Makefile.header

    r487 r527  
    7979          retval=$$?; \
    8080          if test $${retval} != 0; then \
    81           echo "#CMT> Error: $@: Cannot generate" >&2; \
    82           /bin/rm -f $@; fi; \
     81            test -z "$(cmtmsg)" || \
     82            echo "$(CMTMSGPREFIX)" "(Makefile.header) Cannot generate $@" >&2; \
     83            \rm -f $@; \
     84          fi; \
    8385          exit $${retval}
    8486
Note: See TracChangeset for help on using the changeset viewer.