Skip to content

Commit

Permalink
Quadruple the speed of 'make check_conformity'
Browse files Browse the repository at this point in the history
  • Loading branch information
Gregory W. Chicares committed Jan 18, 2006
1 parent c33816e commit 7afe844
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 12 deletions.
13 changes: 10 additions & 3 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
// email: <chicares@cox.net>
// snail: Chicares, 186 Belle Woods Drive, Glastonbury CT 06033, USA

// $Id: ChangeLog,v 1.302 2006-01-17 13:28:52 chicares Exp $
// $Id: ChangeLog,v 1.303 2006-01-18 12:16:41 chicares Exp $

MAINTENANCE

Expand Down Expand Up @@ -5513,7 +5513,14 @@ any carriage return.
multiple_cell_document.cpp
objects.make
single_cell_document.cpp
xmlwrapp_ex.cpp [expunged]
xmlwrapp_ex.hpp [expunged]
xmlwrapp_ex.cpp [expunged]
xmlwrapp_ex.hpp [expunged]
Refactor.

20060118T1216Z <chicares@cox.net> [1202]

GNUmakefile
objects.make
test_coding_rules.cpp [new file]
Quadruple the speed of 'make check_conformity'.

21 changes: 13 additions & 8 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# email: <chicares@cox.net>
# snail: Chicares, 186 Belle Woods Drive, Glastonbury CT 06033, USA

# $Id: GNUmakefile,v 1.53 2006-01-12 09:53:47 chicares Exp $
# $Id: GNUmakefile,v 1.54 2006-01-18 12:16:41 chicares Exp $

###############################################################################

Expand Down Expand Up @@ -401,6 +401,15 @@ clobber: source_clean

################################################################################

# Custom tools built from source.

.PHONY: custom_tools
custom_tools:
@$(MAKE) test_coding_rules$(EXEEXT)
@$(CP) --update $(build_directory)/test_coding_rules$(EXEEXT) /usr/local/bin

################################################################################

# Check conformity to certain formatting rules; count lines and defects.

# Arbitrarily but reasonably, files like scripts and makefiles aren't
Expand All @@ -426,7 +435,7 @@ supplemental_test_makefile = ../forbidden.make
# problem caused by MSYS.

.PHONY: check_conformity
check_conformity: source_clean
check_conformity: source_clean custom_tools
@-[ ! -e $(supplemental_test_makefile) ] \
|| $(MAKE) --no-print-directory -f $(supplemental_test_makefile)
@$(ECHO) " Unexpected or oddly-named source files:"
Expand Down Expand Up @@ -460,12 +469,6 @@ check_conformity: source_clean
@$(GREP) --line-number ' $$' $(licensed_files) || true
@$(ECHO) " Files that improperly contain physical tabs:"
@$(GREP) -l ' ' $(filter-out $(makefiles),$(licensed_files)) || true
@$(ECHO) " Files that contain carriage returns:"
@for z in $(licensed_files) $(xpm_files); \
do \
$(ECHO) -n $$z; \
<$$z $(TR) '\r' '\a' | $(SED) -e ';/\a/!d' | $(WC) -l; \
done | $(SED) -e ';/ 0$$/d';
@$(ECHO) " Headers that should include \"config.hpp\" first but don't:"
@for z in \
$(filter-out config.hpp $(wildcard config_*.hpp),$(wildcard *.hpp)); \
Expand Down Expand Up @@ -533,6 +536,8 @@ check_conformity: source_clean
$$z - \
|| $(ECHO) "... in file $$z"; \
done;
@$(ECHO) " Miscellaneous problems:"
@-test_coding_rules $(licensed_files) $(xpm_files)
@$(ECHO) "Total lines of code:"
@$(WC) -l $(prerequisite_files) | $(SED) -e ';/[Tt]otal/!d' -e 's/[^0-9]//'
@$(ECHO) "Number of source files:"
Expand Down
7 changes: 6 additions & 1 deletion objects.make
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# email: <chicares@cox.net>
# snail: Chicares, 186 Belle Woods Drive, Glastonbury CT 06033, USA

# $Id: objects.make,v 1.63 2006-01-17 13:28:52 chicares Exp $
# $Id: objects.make,v 1.64 2006-01-18 12:16:41 chicares Exp $

################################################################################

Expand Down Expand Up @@ -701,6 +701,11 @@ ihs_crc_comp$(EXEEXT): \
$(main_auxiliary_common_objects) \
ihs_crc_comp.o \

test_coding_rules$(EXEEXT): \
$(boost_filesystem_objects) \
$(main_auxiliary_common_objects) \
test_coding_rules.o \

################################################################################

# Product files.
Expand Down
92 changes: 92 additions & 0 deletions test_coding_rules.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
// Test files for consistency with various rules: for now, only "no CR".
//
// Copyright (C) 2006 Gregory W. Chicares.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2 as
// published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
// http://savannah.nongnu.org/projects/lmi
// email: <chicares@cox.net>
// snail: Chicares, 186 Belle Woods Drive, Glastonbury CT 06033, USA

// $Id: test_coding_rules.cpp,v 1.1 2006-01-18 12:16:41 chicares Exp $

#ifdef __BORLANDC__
# include "pchfile.hpp"
# pragma hdrstop
#endif // __BORLANDC__

#include "armor.hpp"
#include "istream_to_string.hpp"
#include "main_common.hpp"

#include <boost/filesystem/exception.hpp>
#include <boost/filesystem/fstream.hpp>
#include <boost/filesystem/operations.hpp>
#include <boost/filesystem/path.hpp>

#include <ios>
#include <iostream>
#include <ostream>
#include <string>

int process_file(char const* filename)
{
fs::path filepath(filename);

if(!fs::exists(filepath))
{
std::cerr << "File '" << filename << "' not found.\n";
return 1;
}

if(fs::is_directory(filepath))
{
return 0;
}

fs::ifstream ifs(filepath, std::ios_base::binary);
std::string s;
istream_to_string(ifs, s);

if(std::string::npos != s.find('\r'))
{
std::cout << "File '" << filename << "' contains CR.\n";
}

if(!ifs)
{
std::cerr << "Error processing file '" << filename << "'.\n";
return 1;
}

return 0;
}

int try_main(int argc, char* argv[])
{
int result = 0;
for(int j = 1; j < argc; ++j)
{
try
{
result = result || process_file(argv[j]);
}
catch(...)
{
report_exception();
}
}
return result ? EXIT_FAILURE : EXIT_SUCCESS;
}

0 comments on commit 7afe844

Please sign in to comment.