sloccount (2.26-4) 70_bts508556_xml_support

Summary

 break_filelist    |    1 
 makefile          |    9 +++++
 testcode/test.xml |   11 +++++++
 xml_count.l       |   83 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 103 insertions(+), 1 deletion(-)

    
download this patch

Patch contents

#! /bin/sh /usr/share/dpatch/dpatch-run
## 70_bts508556_xml_support.dpatch by Elie De Brauwer <edb@newtec.eu>
##
## All lines beginning with `## DP:' are a description of the patch.
## DP: Enable XML support

@DPATCH@
diff -urNad sloccount~/break_filelist sloccount/break_filelist
--- sloccount~/break_filelist	2009-01-23 23:59:58.843753006 +0100
+++ sloccount/break_filelist	2009-01-24 00:01:05.027752302 +0100
@@ -210,6 +210,7 @@
    # ???: .pco is Oracle Cobol
   "jsp" => "jsp",  # Java server pages
   "vhd" => "vhdl", # VHDL code
+  "xml" => "xml",  # XML files
 );
 
 
diff -urNad sloccount~/makefile sloccount/makefile
--- sloccount~/makefile	2009-01-23 23:59:58.843753006 +0100
+++ sloccount/makefile	2009-01-23 23:59:58.919752430 +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) 
 
 FLEX_GENERATED= \
    pascal_count \
@@ -154,6 +155,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~/testcode/test.xml sloccount/testcode/test.xml
--- sloccount~/testcode/test.xml	1970-01-01 01:00:00.000000000 +0100
+++ sloccount/testcode/test.xml	2009-01-23 23:59:58.919752430 +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~/xml_count.l sloccount/xml_count.l
--- sloccount~/xml_count.l	1970-01-01 01:00:00.000000000 +0100
+++ sloccount/xml_count.l	2009-01-23 23:59:58.923752935 +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++;
+}