Changeset 810

Show
Ignore:
Timestamp:
06/09/09 10:06:05 (10 months ago)
Author:
rudson
Message:
 
Location:
trunk/src
Files:
1 added
1 removed
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/lspkg

    r659 r810  
    3737options are: 
    3838 
    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 
    4449" 
    4550} 
  • trunk/src/mkpatch

    r809 r810  
    11#!/bin/bash 
    22# 
    3 # MKPatch 2.0.0: Simple patch program to .mkbuild models 
     3# mkpatch: Simple patch program to .mkbuild models 
    44# feedback: rudsonaalves at yahoo.com.br | gpl 
    55# 
     
    2121# 
    2222# Version: 
    23 PROG_VERSION=2.0 
     23PROG_VERSION=1.1 
    2424BASENAME=`basename $0` 
     25 
     26function 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 
     36function 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 
     55COMMON_SH="/usr/libexec/simplepkg/common.sh" 
     56if [ -f "$COMMON_SH" ]; then 
     57  source $COMMON_SH 
     58else 
     59  echo "$BASENAME: file $COMMON_SH not found. Check your $BASENAME installation" 
     60fi 
     61 
     62# Load error codes 
     63error_codes 
     64# ---------------- 
    2565 
    2666if [ "$1" = "--help" -o "$1" = "-h" ]; then 
     
    2969fi 
    3070 
    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 
    3375 
    34 # check diff_file exit 
    35 [ ! -e $1 ] && exit 100 
     76# Start variables 
     77Diff_File=$1 
     78Source_File=$2 
     79Diff_N_Lines=`wc -l $1 | cut -f1 -d" "` 
     80Source_N_Lines=`wc -l $2 | cut -f1 -d" "` 
    3681 
    37 # check source_file exit 
    38 [ ! -e $2 ] && exit 100 
     82# Start vars 
     83Diff_Line=1 
     84Diff_Pointer=1 
     85Status_Diff=0 
    3986 
    40 # Change IFS to <ENTER> only 
    41 OLD_IFS=$IFS 
    42 IFS=' 
    43 ' 
     87# Get frist Diff_File line 
     88get_diff_line $Diff_Line $Diff_File || exit $? 
    4489 
    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 
     90Source_Line=1 
     91# Get frist Source_File line 
     92Source_Str_Line=`get_line $Source_Line $Source_File` || exit $? 
     93while [ $Source_Line -le $Source_N_Lines ];  do 
    8394    # make Actions 
    84     #echo ">${Diff_action[Diff_index]}<" 
    85     case "${Diff_action[Diff_index]}" in 
     95    case $Diff_Action in 
    8696        '-') 
    87             if [ "${Source_lines[Source_index]}" == "${Diff_lines[Diff_index]}" ]; then 
    88                 Status_diff=1 
    89                 let Diff_index++ 
     97            if [ "$Source_Str_Line" = "$Diff_Str_Line" ]; then 
     98                Status_Diff=1 
     99                let Diff_Line++ 
    90100            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" 
    95104            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        ;; 
    98109        '+') 
    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        ;; 
    103114        ' ') 
    104             if [ "${Source_lines[Source_index]}" == "${Diff_lines[Diff_index]}" ]; then 
    105                 Status_diff=1 
    106                 let Diff_index++ 
     115            if [ "$Source_Str_Line" = "$Diff_Str_Line" ]; then 
     116                Status_Diff=1 
     117                let Diff_Line++ 
    107118            else 
    108                 Status_diff=0 
    109                 Diff_index=$Diff_pointer 
     119                Status_Diff=0 
     120                Diff_Line=$Diff_Pointer 
    110121            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        ;; 
    115127        '=') 
    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        *) 
    121134            echo "Invalid diff action." 
    122             exit 600 
    123             ;; 
     135            exit $ERROR_MKPATCH 
     136        ;; 
    124137    esac 
    125     #read ANS; clear 
    126 done 
    127 #set -x 
    128 if [ $Diff_index -gt $Diff_n_lines -a $Source_index -le $Source_n_lines ]; then 
    129     for index in `seq $Source_index $Source_n_lines`; do 
    130         Output[Output_index]="${Source_lines[index]}" 
    131         let Output_index++ 
    132     done 
    133 elif [ $Diff_index -le $Diff_n_lines ]; then 
    134     # Make others addline "+" in the end file 
    135     while [ "${Diff_Action[Diff_index]}" == "+" ]; do 
    136         Output[Output_index]="${Diff_lines[Diff_index]}" 
    137         let Diff_index++ 
    138         let Output_index++ 
    139     done 
    140 fi 
    141 #exit 1 
    142 # Print Output file 
    143 for index in `seq 1 $Output_index`; do 
    144     echo "${Output[$index-1]}" 
    145138done 
    146139 
     140# Make others addline "+" in the end file 
     141while [ "$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 $? 
     145done