summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rw-r--r--scripts/OK.cocci13
-rwxr-xr-xscripts/clean-all6
-rwxr-xr-xscripts/cleanfile176
-rw-r--r--scripts/detector.cocci14
-rw-r--r--scripts/diag.cocci13
-rw-r--r--scripts/enginelist.cocci6
-rwxr-xr-xscripts/indent13
-rwxr-xr-xscripts/indent-c++13
-rw-r--r--scripts/is_matrix.spatch14
-rwxr-xr-xscripts/refactoring9
-rwxr-xr-xscripts/update_copyright_year8
11 files changed, 285 insertions, 0 deletions
diff --git a/scripts/OK.cocci b/scripts/OK.cocci
new file mode 100644
index 0000000..8c09d8c
--- /dev/null
+++ b/scripts/OK.cocci
@@ -0,0 +1,13 @@
+// use is_matrix when possible
+
+@@
+identifier res, f;
+expression E;
+@@
+
+(
+res &= DIAG(E);
+|
+-res &= E;
++res &= DIAG(E);
+)
diff --git a/scripts/clean-all b/scripts/clean-all
new file mode 100755
index 0000000..34071de
--- /dev/null
+++ b/scripts/clean-all
@@ -0,0 +1,6 @@
+#!/bin/bash
+find .. -name "*flymake*" -exec rm -f {} \;
+./cleanfile ../hkl.h ../hkl/*.[ch] ../tests/*.[ch] ../tests/tap/*.[ch] ../gui/*.[ch]
+./indent ../hkl.h ../hkl/*.[ch] ../tests/*.[ch] ../tests/tap/*.[ch] ../gui/*.[ch]
+./indent-c++ ../hkl3d/*.cpp ../hkl3d/*.h
+find .. -name "*flymake*" -exec rm -f {} \;
diff --git a/scripts/cleanfile b/scripts/cleanfile
new file mode 100755
index 0000000..cefd29e
--- /dev/null
+++ b/scripts/cleanfile
@@ -0,0 +1,176 @@
+#!/usr/bin/perl -w
+#
+# Clean a text file -- or directory of text files -- of stealth whitespace.
+# WARNING: this can be a highly destructive operation. Use with caution.
+#
+
+use bytes;
+use File::Basename;
+
+# Default options
+$max_width = 79;
+
+# Clean up space-tab sequences, either by removing spaces or
+# replacing them with tabs.
+sub clean_space_tabs($)
+{
+ no bytes; # Tab alignment depends on characters
+
+ my($li) = @_;
+ my($lo) = '';
+ my $pos = 0;
+ my $nsp = 0;
+ my($i, $c);
+
+ for ($i = 0; $i < length($li); $i++) {
+ $c = substr($li, $i, 1);
+ if ($c eq "\t") {
+ my $npos = ($pos+$nsp+8) & ~7;
+ my $ntab = ($npos >> 3) - ($pos >> 3);
+ $lo .= "\t" x $ntab;
+ $pos = $npos;
+ $nsp = 0;
+ } elsif ($c eq "\n" || $c eq "\r") {
+ $lo .= " " x $nsp;
+ $pos += $nsp;
+ $nsp = 0;
+ $lo .= $c;
+ $pos = 0;
+ } elsif ($c eq " ") {
+ $nsp++;
+ } else {
+ $lo .= " " x $nsp;
+ $pos += $nsp;
+ $nsp = 0;
+ $lo .= $c;
+ $pos++;
+ }
+ }
+ $lo .= " " x $nsp;
+ return $lo;
+}
+
+# Compute the visual width of a string
+sub strwidth($) {
+ no bytes; # Tab alignment depends on characters
+
+ my($li) = @_;
+ my($c, $i);
+ my $pos = 0;
+ my $mlen = 0;
+
+ for ($i = 0; $i < length($li); $i++) {
+ $c = substr($li,$i,1);
+ if ($c eq "\t") {
+ $pos = ($pos+8) & ~7;
+ } elsif ($c eq "\n") {
+ $mlen = $pos if ($pos > $mlen);
+ $pos = 0;
+ } else {
+ $pos++;
+ }
+ }
+
+ $mlen = $pos if ($pos > $mlen);
+ return $mlen;
+}
+
+$name = basename($0);
+
+@files = ();
+
+while (defined($a = shift(@ARGV))) {
+ if ($a =~ /^-/) {
+ if ($a eq '-width' || $a eq '-w') {
+ $max_width = shift(@ARGV)+0;
+ } else {
+ print STDERR "Usage: $name [-width #] files...\n";
+ exit 1;
+ }
+ } else {
+ push(@files, $a);
+ }
+}
+
+foreach $f ( @files ) {
+ print STDERR "$name: $f\n";
+
+ if (! -f $f) {
+ print STDERR "$f: not a file\n";
+ next;
+ }
+
+ if (!open(FILE, '+<', $f)) {
+ print STDERR "$name: Cannot open file: $f: $!\n";
+ next;
+ }
+
+ binmode FILE;
+
+ # First, verify that it is not a binary file; consider any file
+ # with a zero byte to be a binary file. Is there any better, or
+ # additional, heuristic that should be applied?
+ $is_binary = 0;
+
+ while (read(FILE, $data, 65536) > 0) {
+ if ($data =~ /\0/) {
+ $is_binary = 1;
+ last;
+ }
+ }
+
+ if ($is_binary) {
+ print STDERR "$name: $f: binary file\n";
+ next;
+ }
+
+ seek(FILE, 0, 0);
+
+ $in_bytes = 0;
+ $out_bytes = 0;
+ $blank_bytes = 0;
+
+ @blanks = ();
+ @lines = ();
+ $lineno = 0;
+
+ while ( defined($line = <FILE>) ) {
+ $lineno++;
+ $in_bytes += length($line);
+ $line =~ s/[ \t\r]*$//; # Remove trailing spaces
+ $line = clean_space_tabs($line);
+
+ if ( $line eq "\n" ) {
+ push(@blanks, $line);
+ $blank_bytes += length($line);
+ } else {
+ push(@lines, @blanks);
+ $out_bytes += $blank_bytes;
+ push(@lines, $line);
+ $out_bytes += length($line);
+ @blanks = ();
+ $blank_bytes = 0;
+ }
+
+ $l_width = strwidth($line);
+ if ($max_width && $l_width > $max_width) {
+ print STDERR
+ "$f:$lineno: line exceeds $max_width characters ($l_width)\n";
+ }
+ }
+
+ # Any blanks at the end of the file are discarded
+
+ if ($in_bytes != $out_bytes) {
+ # Only write to the file if changed
+ seek(FILE, 0, 0);
+ print FILE @lines;
+
+ if ( !defined($where = tell(FILE)) ||
+ !truncate(FILE, $where) ) {
+ die "$name: Failed to truncate modified file: $f: $!\n";
+ }
+ }
+
+ close(FILE);
+}
diff --git a/scripts/detector.cocci b/scripts/detector.cocci
new file mode 100644
index 0000000..fe739c8
--- /dev/null
+++ b/scripts/detector.cocci
@@ -0,0 +1,14 @@
+@@
+@@
+
+
+-hkl_detector_idx_set(...);
+
+@@
+identifier detector;
+@@
+
+HklDetector *detector;
+...
+- 0 == detector->idx
++ 1 == detector->idx \ No newline at end of file
diff --git a/scripts/diag.cocci b/scripts/diag.cocci
new file mode 100644
index 0000000..d3ca089
--- /dev/null
+++ b/scripts/diag.cocci
@@ -0,0 +1,13 @@
+// use is_matrix when possible
+
+@@
+identifier res;
+expression E;
+@@
+
+(
+res &= DIAG(E);
+|
+-res &= E;
++res &= DIAG(E);
+)
diff --git a/scripts/enginelist.cocci b/scripts/enginelist.cocci
new file mode 100644
index 0000000..ea19ffd
--- /dev/null
+++ b/scripts/enginelist.cocci
@@ -0,0 +1,6 @@
+@@
+expression f;
+@@
+
+- hkl_engine_list_add(self, f(self));
++ f(self);
diff --git a/scripts/indent b/scripts/indent
new file mode 100755
index 0000000..a763dd6
--- /dev/null
+++ b/scripts/indent
@@ -0,0 +1,13 @@
+#!/bin/bash
+# PUBLIC DOMAIN
+if [ -z "$1" ]; then
+ echo usage: $0 file-to-indent file2 file3 ...
+ exit 1
+fi
+
+for i in $@; do
+ echo Loading $i
+ emacs --batch --load ../Documentation/hkl-default.el --file $i \
+ -f c-mode --eval "(indent-region (point-min) (point-max) nil)" -f save-buffer
+done
+
diff --git a/scripts/indent-c++ b/scripts/indent-c++
new file mode 100755
index 0000000..5a4d8ef
--- /dev/null
+++ b/scripts/indent-c++
@@ -0,0 +1,13 @@
+#!/bin/bash
+# PUBLIC DOMAIN
+if [ -z "$1" ]; then
+ echo usage: $0 file-to-indent file2 file3 ...
+ exit 1
+fi
+
+for i in $@; do
+ echo Loading $i
+ emacs --batch --load ../Documentation/hkl-default.el --file $i \
+ -f c++-mode --eval "(indent-region (point-min) (point-max) nil)" -f save-buffer
+done
+
diff --git a/scripts/is_matrix.spatch b/scripts/is_matrix.spatch
new file mode 100644
index 0000000..928b13d
--- /dev/null
+++ b/scripts/is_matrix.spatch
@@ -0,0 +1,14 @@
+// use is_matrix when possible
+
+@i@
+@@
+
+#include <tap/hkl-tap.h>
+
+@depends on i@
+identifier M, __func__;
+expression E;
+@@
+
+-ok(TRUE == hkl_matrix_cmp(M, E), __func__);
++is_matrix(M, E, __func__);
diff --git a/scripts/refactoring b/scripts/refactoring
new file mode 100755
index 0000000..5e7e8ee
--- /dev/null
+++ b/scripts/refactoring
@@ -0,0 +1,9 @@
+# use a cocci spatch for the refactoring
+
+SP_FILE=$1
+shift
+spatch -in-place -sp_file $SP_FILE -I .. $*
+echo $1, $2
+echo "refactor using $SP_FILE" > ../.git/GITGUI_BCK
+git add $SP_FILE
+cat $SP_FILE >> ../.git/GITGUI_BCK
diff --git a/scripts/update_copyright_year b/scripts/update_copyright_year
new file mode 100755
index 0000000..0f8789f
--- /dev/null
+++ b/scripts/update_copyright_year
@@ -0,0 +1,8 @@
+#!/bin/bash
+
+CURRENT_YEAR=`date +%Y`
+let LAST_YEAR=CURRENT_YEAR-1
+MSG="upgrading copyright year from $LAST_YEAR to $CURRENT_YEAR"
+echo $MSG
+rgrep -w -l -I "Copyright .*-$LAST_YEAR" .. | xargs sed -i "s,-$LAST_YEAR,-$CURRENT_YEAR,g"
+echo $MSG > ../.git/GITGUI_BCK