Changeset 810
- Timestamp:
- 06/09/09 10:06:05 (10 months ago)
- Location:
- trunk/src
- Files:
-
- 1 added
- 1 removed
- 2 modified
-
lspkg (modified) (1 diff)
-
mkpatch (modified) (3 diffs)
-
mkpatch.new (added)
-
mkpatch.old (deleted)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lspkg
r659 r810 37 37 options are: 38 38 39 -v, --view: view installed package contents 40 -p, --print: print the contents of a package file 41 -r, --remove: remove matching packages 42 -s, --search: search a file under installed packages 43 -d, --description: show matching packages' descriptions 39 -v, --view <package_name> 40 view installed package contents 41 -p, --print <package_name> 42 print the contents of a package file 43 -r, --remove <package_name> 44 remove matching packages 45 -s, --search <file_name> 46 search a file under installed packages 47 -d, --description <package_name> 48 show matching packages' descriptions 44 49 " 45 50 } -
trunk/src/mkpatch
r809 r810 1 1 #!/bin/bash 2 2 # 3 # MKPatch 2.0.0: Simple patch program to .mkbuild models3 # mkpatch: Simple patch program to .mkbuild models 4 4 # feedback: rudsonaalves at yahoo.com.br | gpl 5 5 # … … 21 21 # 22 22 # Version: 23 PROG_VERSION= 2.023 PROG_VERSION=1.1 24 24 BASENAME=`basename $0` 25 26 function get_line { 27 28 # get a line $1 from file $2 29 [ $# -ne 2 ] && exit $ERROR_PAR_NUMBER 30 ! is_number $1 && exit $ERROR_NOT_NUMBER 31 [ ! -e $2 ] && exit $ERROR_FILE_NOTFOUND 32 33 sed "$1 q;d" $2 34 } 35 36 function get_diff_line { 37 38 # get diff line e return: 39 # - Action in Diff_Action 40 # - Diff Line in Diff_Str_Line 41 if [ $1 -gt $Diff_N_Lines ]; then 42 Diff_Action=" " 43 Diff_Str_Line="" 44 return 0 45 fi 46 Line=`get_line $1 $2` 47 Diff_Action=`echo "$Line" | cut -c1` 48 Diff_Str_Line=`echo "$Line" | cut -c2-` 49 } 50 51 52 # ---------------------------------------------------------------- 53 # ------------------- mkpatch program ---------------------------- 54 # common.sh library start 55 COMMON_SH="/usr/libexec/simplepkg/common.sh" 56 if [ -f "$COMMON_SH" ]; then 57 source $COMMON_SH 58 else 59 echo "$BASENAME: file $COMMON_SH not found. Check your $BASENAME installation" 60 fi 61 62 # Load error codes 63 error_codes 64 # ---------------- 25 65 26 66 if [ "$1" = "--help" -o "$1" = "-h" ]; then … … 29 69 fi 30 70 31 # check number of parameters 32 [ $# -ne 2 ] && exit 102 71 # Check input parameters 72 [ $# -ne 2 ] && exit $ERROR_PAR_NUMBER 73 [ ! -e $1 ] && exit $ERROR_FILE_NOTFOUND 74 [ ! -e $2 ] && exit $ERROR_FILE_NOTFOUND 33 75 34 # check diff_file exit 35 [ ! -e $1 ] && exit 100 76 # Start variables 77 Diff_File=$1 78 Source_File=$2 79 Diff_N_Lines=`wc -l $1 | cut -f1 -d" "` 80 Source_N_Lines=`wc -l $2 | cut -f1 -d" "` 36 81 37 # check source_file exit 38 [ ! -e $2 ] && exit 100 82 # Start vars 83 Diff_Line=1 84 Diff_Pointer=1 85 Status_Diff=0 39 86 40 # Change IFS to <ENTER> only 41 OLD_IFS=$IFS 42 IFS=' 43 ' 87 # Get frist Diff_File line 88 get_diff_line $Diff_Line $Diff_File || exit $? 44 89 45 # Read file patch 46 index=0 47 while read line; do 48 Diff_lines[index]="`echo $line | cut -c2-`" 49 Diff_action[index]="`echo $line | cut -c1`" 50 let index++ 51 done < $1 52 let Diff_n_lines=index-1 53 54 #for index in `seq 1 $Diff_n_lines`; do 55 # echo "Action:"${Diff_action[index]}"< Line:"${Diff_lines[index]}"<" 56 #done 57 58 # Read source file 59 index=0 60 while read line; do 61 Source_lines[index]="$line" 62 let index++ 63 done < $2 64 let Source_n_lines=index-1 65 66 #for index in `seq 1 $Source_n_lines`; do 67 # echo "${Source_lines[index]}" 68 #done 69 70 IFS=$OLD_IFS 71 72 Source_index=0 73 Diff_index=0 74 Diff_pointer=0 75 Status_diff=0 76 77 Output="" 78 Output_index=0 79 80 #echo -e "\n\nStart Patch...\n\n" 81 #set -x 82 while [ $Source_index -le $Source_n_lines -a $Diff_index -le $Diff_n_lines ]; do 90 Source_Line=1 91 # Get frist Source_File line 92 Source_Str_Line=`get_line $Source_Line $Source_File` || exit $? 93 while [ $Source_Line -le $Source_N_Lines ]; do 83 94 # make Actions 84 #echo ">${Diff_action[Diff_index]}<" 85 case "${Diff_action[Diff_index]}" in 95 case $Diff_Action in 86 96 '-') 87 if [ "$ {Source_lines[Source_index]}" == "${Diff_lines[Diff_index]}" ]; then88 Status_ diff=189 let Diff_ index++97 if [ "$Source_Str_Line" = "$Diff_Str_Line" ]; then 98 Status_Diff=1 99 let Diff_Line++ 90 100 else 91 Diff_index=$Diff_pointer 92 Status_diff=0 93 Output[Output_index]="${Source_lines[Souce_index]}" 94 let Output_index++ 101 Diff_Line=$Diff_Pointer 102 Status_Diff=0 103 echo "$Source_Str_Line" 95 104 fi 96 let Source_index++ 97 ;; 105 get_diff_line $Diff_Line $Diff_File || exit $? 106 let Source_Line++ 107 Source_Str_Line=`get_line $Source_Line $Source_File` || exit $? 108 ;; 98 109 '+') 99 Output[Output_index]="${Diff_lines[Diff_index]}"100 let Diff_ index++101 let Output_index++102 ;;110 echo "$Diff_Str_Line" 111 let Diff_Line++ 112 get_diff_line $Diff_Line $Diff_File || exit $? 113 ;; 103 114 ' ') 104 if [ "$ {Source_lines[Source_index]}" == "${Diff_lines[Diff_index]}" ]; then105 Status_ diff=1106 let Diff_ index++115 if [ "$Source_Str_Line" = "$Diff_Str_Line" ]; then 116 Status_Diff=1 117 let Diff_Line++ 107 118 else 108 Status_ diff=0109 Diff_ index=$Diff_pointer119 Status_Diff=0 120 Diff_Line=$Diff_Pointer 110 121 fi 111 Output[Output_index]="${Source_lines[Source_index]}" 112 let Output_index++ 113 let Source_index++ 114 ;; 122 echo "$Source_Str_Line" 123 get_diff_line $Diff_Line $Diff_File || exit $? 124 let Source_Line++ 125 Source_Str_Line=`get_line $Source_Line $Source_File` || exit $? 126 ;; 115 127 '=') 116 let Diff_index++ 117 Status_diff=0 118 Diff_pointer=$Diff_index 119 ;; 120 '*') 128 let Diff_Line++ 129 Status_Diff=0 130 Diff_Pointer=$Diff_Line 131 get_diff_line $Diff_Line $Diff_File || exit $? 132 ;; 133 *) 121 134 echo "Invalid diff action." 122 exit 600123 ;;135 exit $ERROR_MKPATCH 136 ;; 124 137 esac 125 #read ANS; clear126 done127 #set -x128 if [ $Diff_index -gt $Diff_n_lines -a $Source_index -le $Source_n_lines ]; then129 for index in `seq $Source_index $Source_n_lines`; do130 Output[Output_index]="${Source_lines[index]}"131 let Output_index++132 done133 elif [ $Diff_index -le $Diff_n_lines ]; then134 # Make others addline "+" in the end file135 while [ "${Diff_Action[Diff_index]}" == "+" ]; do136 Output[Output_index]="${Diff_lines[Diff_index]}"137 let Diff_index++138 let Output_index++139 done140 fi141 #exit 1142 # Print Output file143 for index in `seq 1 $Output_index`; do144 echo "${Output[$index-1]}"145 138 done 146 139 140 # Make others addline "+" in the end file 141 while [ "$Diff_Action" = "+" -a $Diff_Line -le $Diff_N_Lines ]; do 142 echo "$Diff_Str_Line" 143 let Diff_Line++ 144 get_diff_line $Diff_Line $Diff_File || exit $? 145 done
