summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElie De Brauwer <edb@newtec.eu>2012-04-11 12:21:24 +0200
committerJari Aalto <jari.aalto@cante.net>2012-04-11 12:21:24 +0200
commit9f8db739af3c1dfce92f77fdf544c752c717b716 (patch)
treef57fae99251b3805fb5a43bc8bb0f3c9fc02325c
parent3877c0480634e43ea7fbf0a87675d21d093eed93 (diff)
Enable XML support
Gbp-Pq: Name 70_bts508556_xml_support.patch
-rwxr-xr-xbreak_filelist1
-rw-r--r--makefile9
-rw-r--r--testcode/test.xml11
-rw-r--r--xml_count.l83
4 files changed, 103 insertions, 1 deletions
diff --git a/break_filelist b/break_filelist
index 6fe3270..f52d3d8 100755
--- a/break_filelist
+++ b/break_filelist
@@ -210,6 +210,7 @@ $noisy = 0; # Set to 1 if you want noisy reports.
# ???: .pco is Oracle Cobol
"jsp" => "jsp", # Java server pages
"vhd" => "vhdl", # VHDL code
+ "xml" => "xml", # XML files
);
diff --git a/makefile b/makefile
index 60d55b1..322fba8 100644
--- a/makefile
+++ b/makefile
@@ -82,7 +82,8 @@ COMPILED_EXECUTABLES= \
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.c: jsp_count.l driver.c driver.h
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 --git a/testcode/test.xml b/testcode/test.xml
new file mode 100644
index 0000000..4d10dce
--- /dev/null
+++ b/testcode/test.xml
@@ -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 --git a/xml_count.l b/xml_count.l
new file mode 100644
index 0000000..d167af3
--- /dev/null
+++ b/xml_count.l
@@ -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++;
+}