The patch I attached in my previous mail was faulty, here is the correct
version.
--
Elie De Brauwer
diff -urNad sloccount-2.26.org/break_filelist sloccount-2.26.new/break_filelist
--- sloccount-2.26.org/break_filelist 2008-12-12 13:23:55.000000000 +0100
+++ sloccount-2.26.new/break_filelist 2008-12-12 13:27:56.000000000 +0100
@@ -205,6 +205,7 @@
"hs" => "haskell", "lhs" => "haskell",
# ???: .pco is Oracle Cobol
"jsp" => "jsp", # Java server pages
+ "xml" => "xml", # XML files
);
diff -urNad sloccount-2.26.org/debian/rules sloccount-2.26.new/debian/rules
--- sloccount-2.26.org/debian/rules 2008-12-12 13:23:55.000000000 +0100
+++ sloccount-2.26.new/debian/rules 2008-12-12 13:26:01.000000000 +0100
@@ -15,6 +15,7 @@
get_sloc \
get_sloc_details \
jsp_count \
+ xml_count \
lexcount1 \
make_filelists \
pascal_count \
diff -urNad sloccount-2.26.org/makefile sloccount-2.26.new/makefile
--- sloccount-2.26.org/makefile 2008-12-12 13:23:55.000000000 +0100
+++ sloccount-2.26.new/makefile 2008-12-12 13:25:39.000000000 +0100
@@ -82,7 +82,8 @@
pascal_count$(EXE_SUFFIX) \
php_count$(EXE_SUFFIX) \
jsp_count$(EXE_SUFFIX) \
- ml_count$(EXE_SUFFIX)
+ ml_count$(EXE_SUFFIX) \
+ xml_count$(EXE_SUFFIX)
EXECUTABLES= \
ada_count \
@@ -148,6 +149,12 @@
jsp_count$(EXE_SUFFIX): jsp_count.c
$(CC) jsp_count.c -o jsp_count$(EXE_SUFFIX)
+xml_count.c: xml_count.l driver.c driver.h
+ flex -Cfe -t xml_count.l > xml_count.c
+
+xml_count$(EXE_SUFFIX): xml_count.c
+ $(CC) xml_count.c -o xml_count$(EXE_SUFFIX)
+
ml_count$(EXE_SUFFIX): ml_count.c
$(CC) ml_count.c -o ml_count$(EXE_SUFFIX)
diff -urNad sloccount-2.26.org/testcode/test.xml sloccount-2.26.new/testcode/test.xml
--- sloccount-2.26.org/testcode/test.xml 1970-01-01 01:00:00.000000000 +0100
+++ sloccount-2.26.new/testcode/test.xml 2008-12-12 13:26:09.000000000 +0100
@@ -0,0 +1,11 @@
+<?xml version="1.0"?>
+
+<!-- This is an xml file -->
+<tag>
+ <tag2 number="3">
+ Just some stuff
+ </tag2>
+ <blah />
+</tag>
+<!-- It should have 7 useful lines -->
+
diff -urNad sloccount-2.26.org/xml_count.l sloccount-2.26.new/xml_count.l
--- sloccount-2.26.org/xml_count.l 1970-01-01 01:00:00.000000000 +0100
+++ sloccount-2.26.new/xml_count.l 2008-12-12 13:25:50.000000000 +0100
@@ -0,0 +1,83 @@
+%{
+
+/*
+This is part of SLOCCount, a toolsuite that counts source lines of code (SLOC).
+Copyright (C) 2001-2004 David A. Wheeler, Bob Brown and Elie De Brauwer
+This is based on Bob Browns jsp_count.l, which was based on David A. Wheeler's
+pascal_count.l.
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+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
+
+To contact David A. Wheeler, see his website at:
+ http://www.dwheeler.com.
+*/
+
+#include "driver.h"
+
+#define YY_NO_UNPUT
+
+/* 1 if we saw a non-comment, non-whitespace char on this line */
+int saw_char = 0;
+static void count(void);
+
+%}
+
+%option noyywrap
+
+SPACE [ \t\n\r\f]
+
+%x chtml
+%x string
+
+%%
+ line_number = 1;
+ saw_char = 0;
+ BEGIN(INITIAL);
+
+[ \t\r\f] /* Do nothing */
+"<!--" { BEGIN(chtml); }
+\n { count(); }
+
+\" {saw_char = 1; BEGIN(string);}
+
+[^ \t\r\f(\n<"][^<\n"]* {saw_char = 1;}
+. {saw_char = 1;}
+
+
+<chtml>"-->" { BEGIN(INITIAL); }
+<chtml>\n { count(); }
+<chtml>. /* no-op */
+
+<string>[^\"\n]+ {saw_char = 1;}
+<string>\n {
+ fprintf(stderr, "Warning: newline in string - file %s, line %ld\n",
+ filename, line_number);
+ count();
+ BEGIN(INITIAL); /* Switch back; this at least limits damage */
+ }
+<string>\" { BEGIN(INITIAL);}
+
+%%
+
+#include "driver.c"
+
+static void count(void)
+{
+ if ( saw_char ) {
+ sloc++;
+ saw_char = 0;
+ }
+ line_number++;
+}