Du bist hier: Snippet-Verzeichnis » UNIX Admin (199)
Sprache:

addCopyright

Sprache: English
Programmiersprache: Unix Shell
Veröffentlicht von: alferca [nicht registriert]
Letzte Änderung: 15.05.2006
Aufrufe: 957


Beschreibung

adds a copyright to a set of files.It is smart enough to detect what changes (diff) has to apply (patch) to the destination file to match the new copyright.(example of copyright)#addCopyrightScript : adds a Copyright to a set of files # # Copyright (C) 2002 Alvaro Fernandez # #

Code

1 #!/bin/sh 2 3 # addCopyrightScript : adds a Copyright to a set of files 4 # 5 # Copyright (C) 2002 Alvaro Fernandez <cafernan@bbcr.uwaterloo.ca> 6 # <alferca@inf.upv.es> 7 8 #check copyright file 9 if [ $# -ne 1 ]; then 10 echo "usage $0 <copyrightFile>" 11 exit 1 12 fi 13 14 if [ ! -r $1 ] ; then 15 echo "copyright file $1 is not valid" 16 exit 1 17 else 18 COPYRIGHT_FILE=$1 19 echo "using copyrightfile: $COPYRIGHT_FILE" 20 fi 21 22 # select files to add copyright 23 MODIFY_FILES=*.java 24 25 # temporal name for the local files 26 DIFF_FILE="./local_diff" 27 28 29 # Count lines of the copyright 30 number_of_lines=`wc -l < $COPYRIGHT_FILE` 31 32 # function to get number of files of destination to compare/merge 33 getComentaryLines(){ 34 35 linesComentary=`awk 'BEGIN {i=0;lines=0} /([[:alpha:]]*)/ && lines == 0 {exit} index($1,"/*")>0 {lines=1} index($1,"*/")>0 {i=NR;lines=0} END {print i}' $file ` 36 echo $linesComentary 37 38 } 39 40 # function to analyze recursively 41 analyze_dir() 42 { 43 44 for file in $MODIFY_FILES 45 do 46 if [ -r $file ] ; then 47 48 echo $file 49 getComentaryLines 50 51 if [ $linesComentary -eq 0 ] ; then 52 filehead=`echo ""` 53 ` cat /dev/null | diff - $COPYRIGHT_FILE > ${DIFF_FILE}_${file}.diff` 54 result=$? 55 else 56 filehead=`head -n $linesComentary $file` 57 `head -n $linesComentary $file | diff - $COPYRIGHT_FILE > ${DIFF_FILE}_${file}.diff` 58 result=$? 59 fi 60 61 62 if [ $result -eq 0 ]; then 63 #equal files 64 echo "Copyright already added" 65 else 66 # slightly differences 67 echo "aplying patch" 68 patch $file < ${DIFF_FILE}_${file}.diff 69 rm -f ${file}.orig 70 rm -f ${file}.rej 71 72 73 fi 74 75 rm -f ${DIFF_FILE}_${file}.diff 76 echo 77 78 fi 79 done 80 81 82 # Analize recursively 83 84 for file in `ls` 85 do 86 if test -d $file ; then 87 cd `pwd`/$file 88 #echo `pwd` 89 analyze_dir; 90 cd .. 91 #else 92 #echo $file 93 fi 94 done 95 96 97 98 99 100 } 101 102 103 # main 104 analyze_dir 105 echo "Processing finished." 106

Noch kein Kommentar vorhanden

Dieses Snippet kommentieren

Name *  

E-Mail (wird nicht angezeigt) *    

Website  

Kommentar *  

Sicherheitscode Sicherheitscode *    

RSS