Source

Coin / scripts / replace-headers.sh

Diff from to

File scripts/replace-headers.sh

-#!/bin/sh
+#!/bin/bash
 #
 # ./replace-headers.sh
 #
 #
 # Note: This script does not take backup of changed files. Use with caution!
 #
-
-DEBUG=true
+DEBUG=false
 HEADER="/**************************************************************************\\
- *
- *  This file is part of the Coin 3D visualization library.
- *  Copyright (C) by Kongsberg Oil & Gas Technologies.
- *
- *  This library is free software; you can redistribute it and/or
- *  modify it under the terms of the GNU General Public License
- *  (\"GPL\") version 2 as published by the Free Software Foundation.
- *  See the file LICENSE.GPL at the root directory of this source
- *  distribution for additional information about the GNU GPL.
- *
- *  For using Coin with software that can not be combined with the GNU
- *  GPL, and for taking advantage of the additional benefits of our
- *  support services, please contact Kongsberg Oil & Gas Technologies
- *  about acquiring a Coin Professional Edition License.
- *
- *  See http://www.coin3d.org/ for more information.
- *
- *  Kongsberg Oil & Gas Technologies, Bygdoy Alle 5, 0257 Oslo, NORWAY.
- *  http://www.sim.no/  sales@sim.no  coin-support@coin3d.org
- *
-\**************************************************************************/"
+ * Copyright (c) Kongsberg Oil & Gas Technologies AS
+ * All rights reserved.
+ * 
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ * 
+ * Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 
+ * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 
+ * Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ * 
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+\\**************************************************************************/"
 STARTSWITH="^/\*\*\*"
 ENDSWITH="^\\\*\*\*"
 IGNORE="(/boost/|/\.hg/)"
 echo "Updating headers... (This may take several minutes)"
 
 for file in $(find . -type f)
+#for file in $@
 do
   # indicate work in progress...
   echo -n .
   # skip hidden and binary files
   [[ "$file" =~ "/\." ]] && continue
   [[ "$file" =~ "$IGNORE" ]] && continue
-  [[ "$(file $file)" =~ ": .*text" ]] || continue
+  [[ "$(file $file)" =~ .*:*text ]] || continue
 
   # fetch the header line numbers
-  LINES=$(wc -l $file | sed 's/ .*//')
+  LINES=$(wc -l $file | sed -e 's/[^0-9]*\([0-9]*\) .*/\1/')
   FROM=$(grep -n "$STARTSWITH" $file | head -n 1 | sed 's/:.*//')
   [ "$FROM" = "" ] && continue
   LENGTH=$(cat $file | tail -n $(($LINES-$FROM)) | grep -n "$ENDSWITH" | head -n 1 | sed 's/:.*//')
     #read
   else
     # update file
-    cat $file | head -n $(($FROM-1)) > $TEMP
+    if [[ $(($FROM-1)) -gt 0 ]]; then cat $file | head -n $(($FROM-1)) > $TEMP; fi
     echo "$HEADER" >> $TEMP
     cat $file | tail -n $(($LINES-$FROM-$LENGTH)) >> $TEMP
     mv $TEMP $file