|
From: <ai...@us...> - 2010-10-11 22:56:10
|
Revision: 11259
http://plplot.svn.sourceforge.net/plplot/?rev=11259&view=rev
Author: airwin
Date: 2010-10-11 22:56:04 +0000 (Mon, 11 Oct 2010)
Log Message:
-----------
Version of scripts used for first round of commentary style changes
(temporarily limited to config.h.cmake + source code in src).
Modified Paths:
--------------
trunk/scripts/convert_comment.py
trunk/scripts/style_source.sh
Modified: trunk/scripts/convert_comment.py
===================================================================
--- trunk/scripts/convert_comment.py 2010-10-11 22:53:05 UTC (rev 11258)
+++ trunk/scripts/convert_comment.py 2010-10-11 22:56:04 UTC (rev 11259)
@@ -5,40 +5,117 @@
# stdin, output file is stdout.
import sys
import re
+# Restore default signal handling for SIGPIPE as suggested by
+# http://www.velocityreviews.com/forums/t332662-ioerror-errno-32-broken-pipe.html
+# so that stdout can be sent (unix-only) to a pipelined process that terminates
+# early such as cmp.
+import signal
+signal.signal(signal.SIGPIPE, signal.SIG_DFL)
+
ifsingleline = True
for line in sys.stdin.readlines():
+ start_comment = line.find("/*")
+ start_special = line.find("//*")
+ # if start_special corresponds to start_comment, then ignore start_comment
+ # to deal with issue of recursive changes to an original line of the
+ # form "/******..."
+ if start_special >= 0 and start_special == start_comment -1:
+ start_comment = -1
+
end_comment = line.find("*/")
- # len(line) includes new line character at end.
+ # Note trailing "\n" has not (yet) been removed from line so that the next
+ # to last character is at position len(line) - 3.
if end_comment >=0 and end_comment != len(line) - 3:
sys.stderr.write(line)
- raise RuntimeError, "Trailing garbage after */"
+ raise RuntimeError, "Cannot handle embedded comment with trailing character(s) after */"
- if ifsingleline :
- start_comment = line.find("/*")
+ if ifsingleline and (start_comment >=0 or end_comment >=0):
+ # strip trailing "\n" (Unix line endings, only) since that might
+ # cause trouble with stripping trailing white space below.
+ # This trailing "\n" will be added back at the end.
+ line = re.sub(r'^(.*)\n$', "\\1", line)
if start_comment <0 and end_comment >=0:
sys.stderr.write(line)
raise RuntimeError, "Trailing */ for a line which is not a comment"
- # convert single-line comment.
- line = re.sub(r'^(.*)(/\*)(.*) *\*/$', "\\1//\\3", line)
+ # Convert single-line comment (if it exists).
+ # \1 corresponds to zero or more leading characters before "/*".
+ # \3 corresponds to zero or more characters between "/*" and
+ # "*/".
+ # N.B. preserves indentation.
+ line = re.sub(r'^(.*)(/\*)(.*)\*/$', "\\1//\\3", line)
+ # strip trailing white space (if any).
+ line = line.rstrip()
+ # Deal with "/**" case which would be changed to "//*" above.
+ start_special = line.find("//*")
start_comment = line.find("/*")
- if start_comment >= 0:
+ if start_special < 0 and start_comment >= 0:
# Convert first line of multiline comment.
- line = line.replace("/*", "//")
+ # N.B. preserves indentation.
+ line = line.replace("/*", "//", 1)
ifsingleline = False
- else:
- end_comment = line.find("*/")
+
+ # Add back (Unix-only) line ending.
+ line = line + "\n"
+
+ elif not ifsingleline:
+ if start_comment >=0:
+ sys.stderr.write(line)
+ raise RuntimeError, "*/ in the middle of a comment block"
+
+ # strip trailing "\n" (Unix line endings, only) since that might
+ # cause trouble with stripping trailing white space below.
+ # This trailing "\n" will be added back at the end.
+ line = re.sub(r'^(.*)\n$', "\\1", line)
if end_comment < 0:
# Convert multiline comment line that is not start line
- # or end line of that comment. Look for leading blank asterisk
- # standard form of multiline commend line and get rid of it.
- line = "//" + re.sub(r'^ \*', "", line)
+ # or end line of that comment.
+ # Replace " *" after zero or more blanks (the standard form
+ # produced by uncrustify) if it is there by "//".
+ # N.B. preserves indentation.
+ line = re.sub(r'^( *) \*', "\\1//", line)
+ start_newcomment = line.find("//")
+ if start_newcomment < 0:
+ # If all previous conversion attempts failed....
+ line = "//" + line
else:
# Convert last line of multiline comment.
- line = "//" + re.sub(r'^ *(.*)\*/', "\\1", line)
+ # Try converting vacuous form (initial blanks + " */")
+ # to initial blanks (if any) + "//".
+ # This consumes the blank in " */" that is customary as
+ # the last line of a multi-line block.
+ # N.B. preserves indentation.
+ # \1 contains the initial blanks
+ line = re.sub(r'^( *) \*/$', "\\1//", line)
+
+ # Try converting non-vacuous standard form produced by
+ # uncrustify (initial blanks + " *" + any string + "*/")
+ # to initial blanks + "//" + any string.
+ # N.B. preserves indentation.
+ # \1 contains the initial blanks
+ # \2 contains the "any" string preceding "*/".
+ line = re.sub(r'^( *) \*(.*)\*/$', "\\1//\\2", line)
+
+ # If all previous conversion attempts failed....
+ # N.B. Does not preserve indentation.
+ line = re.sub(r'^(.*)\*/$', "//\\1", line)
+
+ # strip trailing white space (if any).
+ line = line.rstrip()
ifsingleline = True
+ # Add back (Unix-only) line ending.
+ line = line + "\n"
+
+ # Special transforms to get rid of left-over "\*" and "*\" forms which
+ # have historically been used to frame multi-block comments by some
+ # PLplot developers.
+ # Replace leading "// \*" ==> "//"
+ line = re.sub(r'^// \\\*(.*)$', "//\\1", line)
+ # Remove "*\" from end of comment lines
+ line = re.sub(r'^//(.*)\*\\$', "//\\1", line)
+
sys.stdout.write(line)
sys.exit()
Modified: trunk/scripts/style_source.sh
===================================================================
--- trunk/scripts/style_source.sh 2010-10-11 22:53:05 UTC (rev 11258)
+++ trunk/scripts/style_source.sh 2010-10-11 22:56:04 UTC (rev 11259)
@@ -3,12 +3,16 @@
# $Id$
# This script will run uncrustify on all source files registered in
-# the lists below and summarize which uncrustified files are
-# different. Also there are options to view the differences in detail
+# the lists below (and scripts/convert_comment.py on all C source
+# files registerd below) and summarize which uncrustified or
+# comment-converted files would be different. (convert_comment.py
+# converts /* ... */ style comments to the c99-acceptable // form of
+# comments because uncrustify does not (yet) have that configuration
+# choice.) Also there are options to view the differences in detail
# and/or apply them. This script must be run from the top-level
# directory of the PLplot source tree.
-# Copyright (C) 2009 Alan W. Irwin
+# Copyright (C) 2009-2010 Alan W. Irwin
#
# This file is part of PLplot.
#
@@ -110,7 +114,6 @@
echo "Immediate exit specified!"
exit
fi
-
fi
export csource_LIST
@@ -120,6 +123,9 @@
# src directory
csource_LIST="$csource_LIST src/*.[ch]"
+# temporary
+exclude_c=ON
+if [ -z "$exclude_c" ] ; then
# All C source (i.e., exclude qt.h) in include directory.
csource_LIST="$csource_LIST `ls include/*.h include/*.h.in include/*.h.cmake |grep -v qt.h`"
@@ -182,29 +188,47 @@
fi
done
-uncrustify_source()
+# temporary
+fi
+transform_source()
{
-# $1 is a list of source files of a particular language.
-# $2 is the language identification string for those source files in
-# the form needed by uncrustify. From the uncrustify man page those
-# language id forms are C, CPP, D, CS, JAVA, PAWN, VALA, OC, OC+
+ # $1 is a list of source files of a particular language.
+ # $2 is the language identification string for those source files in
+ # the form needed by uncrustify. From the uncrustify man page those
+ # language id forms are C, CPP, D, CS, JAVA, PAWN, VALA, OC, OC+
+ u_command="uncrustify -c uncrustify.cfg -q -l $2"
+ # $3 is either "comments" to indicate comments will be transformed
+ # using scripts/convert_comment.py or any other string (or
+ # nothing) to indicate uncrustify will be used.
+ if [ "$3" = "comments" ] ; then
+ c_command="scripts/convert_comment.py"
+ else
+ c_command="cat -"
+ fi
+ # Process $c_command after $u_command so that comments will be rendered
+ # in standard form by uncrustify before scripts/convert_comment.py
+ # is run.
+
for language_source in $1 ; do
- uncrustify -c uncrustify.cfg -q -l $2 < $language_source | cmp --quiet $language_source -
+ $u_command < $language_source | $c_command | \
+ cmp --quiet $language_source -
if [ "$?" -ne 0 ] ; then
ls $language_source
if [ "$diff" = "ON" ] ; then
- uncrustify -c uncrustify.cfg -q -l $2 < $language_source | diff $diff_options $language_source -
+ $u_command < $language_source | $c_command | \
+ diff $diff_options $language_source -
fi
if [ "$apply" = "ON" ] ; then
- uncrustify -c uncrustify.cfg -q -l $2 --no-backup $language_source
+ $u_command < $language_source | $c_command >| /tmp/temporary.file
+ mv -f /tmp/temporary.file $language_source
fi
fi
done
}
-uncrustify_source "$csource_LIST" C
-uncrustify_source "$cppsource_LIST" CPP
-uncrustify_source "$javasource_LIST" JAVA
-uncrustify_source "$dsource_LIST" D
+transform_source "$csource_LIST" C "comments"
+#transform_source "$cppsource_LIST" CPP
+#transform_source "$javasource_LIST" JAVA
+#transform_source "$dsource_LIST" D
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|