Discussions of the Parallel Programming book
 help / color / mirror / Atom feed
* [RFC PATCH 0/3] Trial of replacing hyphens with en-dashes
@ 2016-08-13  3:38 Akira Yokosawa
  2016-08-13  3:39 ` [RFC PATCH 1/3] Trial of replacing hyphens with en-dashes for number Akira Yokosawa
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Akira Yokosawa @ 2016-08-13  3:38 UTC (permalink / raw)
  To: Paul E. McKenney; +Cc: perfbook, Akira Yokosawa

From a63dd50b648013af5780341f9c740bf9d9f6b65d Mon Sep 17 00:00:00 2001
From: Akira Yokosawa <akiyks@gmail.com>
Date: Sat, 13 Aug 2016 11:17:19 +0900
Subject: [RFC PATCH 0/3] Trial of replacing hyphens with en-dashes

Hi Paul,

This is an RFC patch series of my attempt to replace hyphens used for
ranges of numbers with en-dashes.
Instead of sending modifications in LaTeX sources as patches, I'm
submitting scripts which do the replacements on the fly.
The "sed" script is fairly stable now, and there is no false positives
AFAIK.
There might still be false negatives I'm not aware of. Any false positive
would be addressed by adding a sed pattern.
As a bonus, the sed pattern also contains fixes of typos such as "line~mm-nn".

To try the replacement, at the top directory of perfbook, invoke the
script by "sh utilities/dohyphen2endash.sh".
You need to be in a clean git repository. This check is to ensure
that you can revert the changes made by the script by "git reset --hard".
So you might want to try this series on a test branch.
Or the check of git status can be overridden by a "-f" or "--force" option.

The modification by the scripts can be reviewed by "git diff" afterwards.

It is up to the editor's choice whether or not to commit the result.

Just adding the scripts to the repository is fine with me.

                                                Thanks, Akira 
------

Akira Yokosawa (3):
  Trial of replacing hyphens with en-dashes for number ranges
  dohyphen2endash.sh: Add check of git status
  dohyphen2endash.sh: Use mktemp to create temp file

 utilities/dohyphen2endash.sh | 74 ++++++++++++++++++++++++++++++++++++++++++++
 utilities/hyphen2endash.sh   | 50 ++++++++++++++++++++++++++++++
 2 files changed, 124 insertions(+)
 create mode 100644 utilities/dohyphen2endash.sh
 create mode 100644 utilities/hyphen2endash.sh

-- 
1.9.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [RFC PATCH 1/3] Trial of replacing hyphens with en-dashes for number
  2016-08-13  3:38 [RFC PATCH 0/3] Trial of replacing hyphens with en-dashes Akira Yokosawa
@ 2016-08-13  3:39 ` Akira Yokosawa
  2016-08-13  3:40 ` [RFC PATCH 2/3] dohyphen2endash.sh: Add check of git status Akira Yokosawa
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Akira Yokosawa @ 2016-08-13  3:39 UTC (permalink / raw)
  To: Paul E. McKenney; +Cc: perfbook, Akira Yokosawa

From 449dc8ab744b917a66ea1a38b7f5d7af09ba8025 Mon Sep 17 00:00:00 2001
From: Akira Yokosawa <akiyks@gmail.com>
Date: Wed, 10 Aug 2016 06:59:07 +0900
Subject: [RFC PATCH 1/3] Trial of replacing hyphens with en-dashes for number
 ranges

This commit adds scripts to do replacing.
By doing "sh utilities/dohyphen2endash.sh" in the top directory,
hyphens used in number ranges such as "Lines~m-n" will be replaced
with en-dashes such as "Lines~m--n" in LaTeX sources.
For patterns used to find replacement candidates, see
"utilities/hyphen2endash.sh".

Signed-off-by: Akira Yokosawa <akiyks@gmail.com>
---
 utilities/dohyphen2endash.sh | 36 +++++++++++++++++++++++++++++++
 utilities/hyphen2endash.sh   | 50 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 86 insertions(+)
 create mode 100644 utilities/dohyphen2endash.sh
 create mode 100644 utilities/hyphen2endash.sh

diff --git a/utilities/dohyphen2endash.sh b/utilities/dohyphen2endash.sh
new file mode 100644
index 0000000..3270983
--- /dev/null
+++ b/utilities/dohyphen2endash.sh
@@ -0,0 +1,36 @@
+#!/bin/sh
+#
+# Apply hypen2endash.sh for all .tex files
+#
+# 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, you can access it online at
+# http://www.gnu.org/licenses/gpl-2.0.html.
+#
+# Copyright (C) Akira Yokosawa, 2016
+#
+# Authors: Akira Yokosawa <akiyks@gmain.com>
+
+texfiles=`find . -name '*.tex' -print`
+for i in $texfiles
+do
+	basename="${i%.tex}"
+#	echo $basename
+	sh ./utilities/hyphen2endash.sh $basename.tex > $basename.tmp
+	if diff -q $basename.tex $basename.tmp >/dev/null
+	then
+		rm $basename.tmp
+	else
+		echo "$basename.tex modified"
+		mv -f $basename.tmp $basename.tex
+	fi
+done
diff --git a/utilities/hyphen2endash.sh b/utilities/hyphen2endash.sh
new file mode 100644
index 0000000..2b37696
--- /dev/null
+++ b/utilities/hyphen2endash.sh
@@ -0,0 +1,50 @@
+#!/bin/sh
+#
+# Find hyphens used for number range and replace them with en dashes.
+#
+# Replacement candidates are
+# Lines~nn-mm -> Lines~nn--mm
+# Lines nn-mm -> Lines~nn--mm
+# lines~nn-mm -> lines~nn--mm
+# lines nn-mm -> lines~nn--mm
+# line nn-mm -> lines~nn--mm  -- includes typo fix
+# Line nn-mm -> Lines~nn--mm  -- includes typo fix
+# line~nn-mm -> lines~nn--mm  -- includes typo fix
+# Line~nn-mm -> Lines~nn--mm  -- includes typo fix
+# Lines~nn--mm and oo-pp -> Lines~nn--mm and oo--pp
+# Slides nn-mm -> Slides~nn--mm
+# Figures~\ref{foo}-\ref{bar} -> Figures~\ref{foo}--\ref{bar}
+#
+# 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, you can access it online at
+# http://www.gnu.org/licenses/gpl-2.0.html.
+#
+# Copyright (C) Akira Yokosawa, 2016
+#
+# Authors: Akira Yokosawa <akiyks@gmain.com>
+
+cat $1 |
+	sed -e 's/Lines~\([0-9]\+\)-\([0-9]\+\)/Lines~\1--\2/g' \
+	    -e 's/Lines \([0-9]\+\)-\([0-9]\+\)/Lines~\1--\2/g' \
+	    -e 's/lines~\([0-9]\+\)-\([0-9]\+\)/lines~\1--\2/g' \
+	    -e 's/lines \([0-9]\+\)-\([0-9]\+\)/lines~\1--\2/g' \
+	    -e 's/Line~\([0-9]\+\)-\([0-9]\+\)/Lines~\1--\2/g' \
+	    -e 's/Line \([0-9]\+\)-\([0-9]\+\)/Lines~\1--\2/g' \
+	    -e 's/line~\([0-9]\+\)-\([0-9]\+\)/lines~\1--\2/g' \
+	    -e 's/line \([0-9]\+\)-\([0-9]\+\)/lines~\1--\2/g' \
+	    -e 's/Lines~\([0-9]\+\)--\([0-9]\+\) and \([0-9]\+\)-\([0-9]\+\)/Lines~\1--\2 and \3--\4/g' \
+	    -e 's/Slides \([0-9]\+\)-\([0-9]\+\)/Slides~\1--\2/g' \
+	    -e 's/Figures~\(\\ref{.*}\)-\(\\ref{.*}\)/Figures~\1--\2/g' \
+	    -e 's/\/\* Lines~\([0-9]\+\)--\([0-9]\+\) \*\//\/\* Lines \1-\2 \*\//g'
+
+# Last pattern is to preserve "Lines n-m" in comments within code snippet
-- 
1.9.1



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [RFC PATCH 2/3] dohyphen2endash.sh: Add check of git status
  2016-08-13  3:38 [RFC PATCH 0/3] Trial of replacing hyphens with en-dashes Akira Yokosawa
  2016-08-13  3:39 ` [RFC PATCH 1/3] Trial of replacing hyphens with en-dashes for number Akira Yokosawa
@ 2016-08-13  3:40 ` Akira Yokosawa
  2016-08-13  3:41 ` [RFC PATCH 3/3] dohyphen2endash.sh: Use mktemp to create temp file Akira Yokosawa
  2016-08-14  2:36 ` [RFC PATCH 0/3] Trial of replacing hyphens with en-dashes Paul E. McKenney
  3 siblings, 0 replies; 5+ messages in thread
From: Akira Yokosawa @ 2016-08-13  3:40 UTC (permalink / raw)
  To: Paul E. McKenney; +Cc: perfbook, Akira Yokosawa

From 1fc4b3e11e22f12c0ca347cbbcae6dae329cdcf0 Mon Sep 17 00:00:00 2001
From: Akira Yokosawa <akiyks@gmail.com>
Date: Fri, 12 Aug 2016 23:58:46 +0900
Subject: [RFC PATCH 2/3] dohyphen2endash.sh: Add check of git status

This commit also adds option "-f" and "--force" to override the
check.

Signed-off-by: Akira Yokosawa <akiyks@gmail.com>
---
 utilities/dohyphen2endash.sh | 38 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)

diff --git a/utilities/dohyphen2endash.sh b/utilities/dohyphen2endash.sh
index 3270983..05557f0 100644
--- a/utilities/dohyphen2endash.sh
+++ b/utilities/dohyphen2endash.sh
@@ -1,6 +1,9 @@
 #!/bin/sh
 #
 # Apply hypen2endash.sh for all .tex files
+# If invoked in non-clean git status, this script will abort.
+# If invoked with the "--force" option, this script will continue
+# regardless of git status.
 #
 # 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
@@ -20,6 +23,41 @@
 #
 # Authors: Akira Yokosawa <akiyks@gmain.com>

+# parse option
+TEMP=`getopt -o f --long force -- "$@"`
+
+if [ $? != 0 ] ; then echo "Error in parse option..." >&2 ; exit 1 ; fi
+
+eval set -- "$TEMP"
+
+forced=0
+
+while true ; do
+	case "$1" in
+		-f|--force) forced=1 ; shift ;;
+		--) shift ; break ;;
+		*) echo "Unknown option!" ; exit 1 ;;
+	esac
+done
+# check if we are in git repository
+if ! test -e .git
+then
+	echo "not in a git repository"
+	exit 1
+fi
+# check if companion script exists
+if ! test -e utilities/hyphen2endash.sh
+then
+	echo "utilities/hyphen2endash.sh not found."
+	exit 1
+fi
+# check if git status is clean
+gitstatus=`git status --porcelain | wc -l`
+if [ $forced -eq 0 -a $gitstatus != "0" ]
+then
+	echo "git status not clean --- aborting."
+	exit 1
+fi
 texfiles=`find . -name '*.tex' -print`
 for i in $texfiles
 do
-- 
1.9.1



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [RFC PATCH 3/3] dohyphen2endash.sh: Use mktemp to create temp file
  2016-08-13  3:38 [RFC PATCH 0/3] Trial of replacing hyphens with en-dashes Akira Yokosawa
  2016-08-13  3:39 ` [RFC PATCH 1/3] Trial of replacing hyphens with en-dashes for number Akira Yokosawa
  2016-08-13  3:40 ` [RFC PATCH 2/3] dohyphen2endash.sh: Add check of git status Akira Yokosawa
@ 2016-08-13  3:41 ` Akira Yokosawa
  2016-08-14  2:36 ` [RFC PATCH 0/3] Trial of replacing hyphens with en-dashes Paul E. McKenney
  3 siblings, 0 replies; 5+ messages in thread
From: Akira Yokosawa @ 2016-08-13  3:41 UTC (permalink / raw)
  To: Paul E. McKenney; +Cc: perfbook, Akira Yokosawa

From a63dd50b648013af5780341f9c740bf9d9f6b65d Mon Sep 17 00:00:00 2001
From: Akira Yokosawa <akiyks@gmail.com>
Date: Sat, 13 Aug 2016 11:02:39 +0900
Subject: [RFC PATCH 3/3] dohyphen2endash.sh: Use mktemp to create temp file

Signed-off-by: Akira Yokosawa <akiyks@gmail.com>
---
 utilities/dohyphen2endash.sh | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/utilities/dohyphen2endash.sh b/utilities/dohyphen2endash.sh
index 05557f0..2a0fdc7 100644
--- a/utilities/dohyphen2endash.sh
+++ b/utilities/dohyphen2endash.sh
@@ -59,16 +59,16 @@ then
 	exit 1
 fi
 texfiles=`find . -name '*.tex' -print`
+tmpf=`mktemp`
 for i in $texfiles
 do
 	basename="${i%.tex}"
 #	echo $basename
-	sh ./utilities/hyphen2endash.sh $basename.tex > $basename.tmp
-	if diff -q $basename.tex $basename.tmp >/dev/null
+	sh ./utilities/hyphen2endash.sh $basename.tex > $tmpf
+	if ! diff -q $basename.tex $tmpf >/dev/null
 	then
-		rm $basename.tmp
-	else
 		echo "$basename.tex modified"
-		mv -f $basename.tmp $basename.tex
+		cp -f $tmpf $basename.tex
 	fi
 done
+rm -f $tmpf
-- 
1.9.1



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [RFC PATCH 0/3] Trial of replacing hyphens with en-dashes
  2016-08-13  3:38 [RFC PATCH 0/3] Trial of replacing hyphens with en-dashes Akira Yokosawa
                   ` (2 preceding siblings ...)
  2016-08-13  3:41 ` [RFC PATCH 3/3] dohyphen2endash.sh: Use mktemp to create temp file Akira Yokosawa
@ 2016-08-14  2:36 ` Paul E. McKenney
  3 siblings, 0 replies; 5+ messages in thread
From: Paul E. McKenney @ 2016-08-14  2:36 UTC (permalink / raw)
  To: Akira Yokosawa; +Cc: perfbook

On Sat, Aug 13, 2016 at 12:38:11PM +0900, Akira Yokosawa wrote:
> >From a63dd50b648013af5780341f9c740bf9d9f6b65d Mon Sep 17 00:00:00 2001
> From: Akira Yokosawa <akiyks@gmail.com>
> Date: Sat, 13 Aug 2016 11:17:19 +0900
> Subject: [RFC PATCH 0/3] Trial of replacing hyphens with en-dashes
> 
> Hi Paul,
> 
> This is an RFC patch series of my attempt to replace hyphens used for
> ranges of numbers with en-dashes.
> Instead of sending modifications in LaTeX sources as patches, I'm
> submitting scripts which do the replacements on the fly.
> The "sed" script is fairly stable now, and there is no false positives
> AFAIK.
> There might still be false negatives I'm not aware of. Any false positive
> would be addressed by adding a sed pattern.
> As a bonus, the sed pattern also contains fixes of typos such as "line~mm-nn".
> 
> To try the replacement, at the top directory of perfbook, invoke the
> script by "sh utilities/dohyphen2endash.sh".
> You need to be in a clean git repository. This check is to ensure
> that you can revert the changes made by the script by "git reset --hard".
> So you might want to try this series on a test branch.
> Or the check of git status can be overridden by a "-f" or "--force" option.
> 
> The modification by the scripts can be reviewed by "git diff" afterwards.
> 
> It is up to the editor's choice whether or not to commit the result.
> 
> Just adding the scripts to the repository is fine with me.

And, after inspecting the scripts, I took this approach.

Thank you!

							Thanx, Paul

>                                                 Thanks, Akira 
> ------
> 
> Akira Yokosawa (3):
>   Trial of replacing hyphens with en-dashes for number ranges
>   dohyphen2endash.sh: Add check of git status
>   dohyphen2endash.sh: Use mktemp to create temp file
> 
>  utilities/dohyphen2endash.sh | 74 ++++++++++++++++++++++++++++++++++++++++++++
>  utilities/hyphen2endash.sh   | 50 ++++++++++++++++++++++++++++++
>  2 files changed, 124 insertions(+)
>  create mode 100644 utilities/dohyphen2endash.sh
>  create mode 100644 utilities/hyphen2endash.sh
> 
> -- 
> 1.9.1
> 


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2016-08-14  8:29 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-08-13  3:38 [RFC PATCH 0/3] Trial of replacing hyphens with en-dashes Akira Yokosawa
2016-08-13  3:39 ` [RFC PATCH 1/3] Trial of replacing hyphens with en-dashes for number Akira Yokosawa
2016-08-13  3:40 ` [RFC PATCH 2/3] dohyphen2endash.sh: Add check of git status Akira Yokosawa
2016-08-13  3:41 ` [RFC PATCH 3/3] dohyphen2endash.sh: Use mktemp to create temp file Akira Yokosawa
2016-08-14  2:36 ` [RFC PATCH 0/3] Trial of replacing hyphens with en-dashes Paul E. McKenney

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox