⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 patchfns.in

📁 linux下各种patch的管理工具
💻 IN
📖 第 1 页 / 共 2 页
字号:
#! @BASH@# This file contains the common functions used in all quilt script# It is meant to be sourced by bash scripts.#  This script is free software; you can redistribute it and/or modify#  it under the terms of the GNU General Public License version 2 as#  published by the Free Software Foundation.##  See the COPYING and AUTHORS files for more details.export TEXTDOMAIN=quiltexport TEXTDOMAINDIR=@LOCALEDIR@: ${LC_CTYPE:=$LANG}: ${LC_MESSAGES:=$LANG}ORIGINAL_LANG=$LANGexport LANG=POSIXexport QUILT_PATCHES QUILT_PC SUBDIR SERIES DBDB_VERSION=2: ${QUILT_PATCHES:=patches}: ${QUILT_PC:=.pc}# Support compatibility layerif [ -d $QUILT_DIR/compat ]then	export PATH="$QUILT_DIR/compat:$PATH"fiunset CDPATHshopt -s dotglobif [ -e "$QUILTRC" ]then	source "$QUILTRC"fi# Add default arguments for this commandif [ -n "$QUILT_COMMAND" ]; then	args="QUILT_$(echo $QUILT_COMMAND | tr a-z A-Z)_ARGS"	eval set -- ${!args} \"\$@\"	unset argsfi# ========================================================#declare -a exit_handlers##add_exit_handler() {#	exit_handlers[${#exit_handlers[@]}]=$1#}##remove_exit_handler() {#	declare -a handlers#	local h#	for h in "${exit_handlers[@]}"; do#		[ "$h" = "$1" ] && continue#		handlers[${#handlers[@]}]=$h#	done#	exit_handlers=( "${handlers[@]}" )#}##run_exit_handlers() {#	local h#	for h in "${exit_handlers[@]}"; do#		eval $h#	done#}##trap run_exit_handlers EXIT# ========================================================# Quote a string for use in a basic regular expression.quote_bre(){	echo "$1" | sed -e 's:\([][^$/.*\\]\):\\\1:g'}# Quote a string for use in an extended regular expression.quote_re(){	echo "$1" | sed -e 's:\([][?{(|)}^$/.+*\\]\):\\\1:g'}basename(){	local path=$1	while [ "${path:(-1)}" = "/" ]	do		path=${path%/}	done	echo "${path##*/}"}dirname(){	local path=$1	while [ "${path:(-1)}" = "/" ]	do		path=${path%/}	done	local basename="${path##*/}"	path="${path:0:${#path}-${#basename}}"	while [ "${path:(-1)}" = "/" ]	do		path=${path%/}	done	if [ -n "$path" ]	then		echo "$path"	else		if [ ${1:0:1} = "/" ]		then			echo "/"		else			echo "."		fi	fi}patch_file_name(){	echo "$QUILT_PATCHES/$1"}# The -pN option and possibly others that should be passed to patch.patch_args(){	local patch=$1	if [ -e $SERIES ]	then		awk '			{sub(/(^|[ \t]+)#.*/, "") }		$1 == "'"$patch"'" \			{ if (NF >= 2)				for (i=2; i <= NF; i++)					print $i			  else				print "-p1" ;			  exit			}		' $SERIES	fi}patch_strip_level(){	local patch=$1 i	for i in $(patch_args $patch)	do		case $i in		-p)			echo $2			return ;;		-p*)			echo ${i:2}			return ;;		esac	done	echo "1"}change_db_strip_level(){	local level=$1 patch=$2	if [ x$level != x-p1 ]	then		level="$level"	else		level=""	fi	if [ -e $SERIES ]	then		local tmpfile=$(gen_tempfile)		awk '		/^'"$(quote_re $patch)"'([ \t]|$)/ \			{ for(i=2; i<=NF; i++)				if ($i ~ /^-p/) {					$i="'"$level"'"					break				}			  if (i > NF && "'"$level"'" != "")				 $i="'"$level"'"			}			{ print }		' $SERIES > $tmpfile		if ! cmp $SERIES $tmpfile >/dev/null 2>/dev/null		then			cat $tmpfile > $SERIES		fi		rm -f $tmpfile	else		return 1	fi}patch_in_series(){	local patch=$1	if ! [ -e $SERIES ]	then		return 1	else		grep -q "^$(quote_bre $patch)\([ \t]\|$\)" $SERIES	fi}# Insert new patch after topmost patchinsert_in_series(){	local patch=$1 patch_args=$2	local next=$(patch_after "$(top_patch)") tmpfile	if [ -n "$patch_args" ]	then		patch_args=" $patch_args"	fi	tmpfile=$(gen_tempfile) || return 1	mkdir -p $(dirname $SERIES)	if [ -n "$next" ]	then		awk '		/^'"$(quote_re $next)"'([ \t]|$)/ \				{ print "'"$patch$patch_args"'" }				{ print }		' $SERIES > $tmpfile		status=$?		if [ $status -ne 0 ]		then			rm -f $tmpfile			return 1		fi	else		if [ -e $SERIES ]		then			cat $SERIES > $tmpfile		fi		echo "$patch$patch_args" >> $tmpfile	fi	cat $tmpfile > $SERIES	rm -f $tmpfile}remove_from_series(){	local patch=$1	tmpfile=$(gen_tempfile) || return 1	awk '	! /^'"$(quote_re $patch)"'([ \t]|$)/ \				{ print }	' $SERIES > $tmpfile	if [ $? -ne 0 ]	then		rm -f $tmpfile	   	return 1	fi	cat $tmpfile > $SERIES	rm -f $tmpfile}rename_in_series(){	local from=$1 to=$2	tmpfile=$(gen_tempfile) || return 1	awk '	/^'"$(quote_re $from)"'([ \t]|$)/ \		{ sub(/'"$(quote_re $from)"'/, "'"${to//\"/\\\"}"'")		  good=1 }		{ print }	END	{ exit(! good) }	' $SERIES > $tmpfile	if [ $? -ne 0 ]	then		rm -f $tmpfile		return 1	fi	cat $tmpfile > $SERIES	rm -f $tmpfile}rename_in_db(){	local from=$1 to=$2	local tmpfile	tmpfile=$(gen_tempfile) || return 1	awk '	/^'"$(quote_re $from)"'$/ \		{ sub(/'"$(quote_re $from)"'/, "'"${to//\"/\\\"}"'")		  good=1 }		{ print }	END	{ exit(! good) }	' $DB > $tmpfile	if [ $? -eq 0 ]	then		cat $tmpfile > $DB		rm -f $tmpfile	else		rm -f $tmpfile		return 1	fi}backup_file_name(){	local patch=$1	while [ $# -gt 1 ]	do		echo "$QUILT_PC/$patch/$2"		shift	done}cat_series(){	if [ -e $SERIES ]	then		sed -e '/^$/d' -e '/^#/d' -e 's/^[ '$'\t'']*//' \		    -e 's/[ '$'\t''].*//' $SERIES	else		return 1	fi}top_patch(){	local patch=$(tail -n 1 $DB 2>/dev/null)	[ -n "$patch" ] && echo "$patch"}is_numeric(){	echo $1 | grep -q '^[0-9]*$'}is_applied(){	local patch=$1	[ -e $DB ] || return 1	grep -q "^$(quote_bre $patch)\$" $DB}applied_patches(){	[ -e $DB ] || return 1	cat $DB}applied_before(){	local patch=$1	if [ -n "$patch" ]	then		awk '		$0 == "'"$patch"'"	{ exit }					{ print }		' $DB	fi}		patches_before(){	local patch=$1	if [ -n "$patch" ]	then		cat_series \		| awk '		$0 == "'"$patch"'"	{ exit }					{ print }		'	fi}patches_after(){	local patch=$1	if [ -n "$patch" ]	then		cat_series \		| awk '		seen == 1		{ print }		$0 == "'"$patch"'"	{ seen=1 }		'	else		cat_series	fi}patch_after(){	local patch="$1"	patch=$(patches_after "$patch" | head -n 1)	[ -n "$patch" ] && echo "$patch"}# List all patches that have been applied on top of patch $1patches_on_top_of(){	local patch=$1	[ -e $DB ] || return	awk '	$0 == "'"$patch"'"	{ seen=1 ; next }	seen == 1		{ print }	' $DB}# Print the name of the patch that modified the file $2 next after# patch $1, or print nothing if patch $1 is on top.next_patch_for_file(){	local patch=$1 file=$2	local patches_on_top=$(patches_on_top_of $patch)	if [ -n "$patches_on_top" ]	then		for patch in $patches_on_top		do			if [ -f $(backup_file_name $patch $file) ]			then				echo $patch				break			fi		done	fi}add_to_db(){	echo $1 >> $DB}remove_from_db(){	local patch=$1	local tmpfile	if tmpfile=$(gen_tempfile)	then		grep -v "^$(quote_bre $patch)\$" $DB > $tmpfile		cat $tmpfile > $DB		rm -f $tmpfile		[ -s $DB ] || rm -f $DB	fi}find_first_patch(){	local patch=$(cat_series | head -n 1)	if [ -z "$patch" ]	then		printf $"No patches in series\n" >&2		return 1	fi	echo "$patch"}find_top_patch(){	if ! top_patch	then		if find_first_patch > /dev/null		then			printf $"No patches applied\n" >&2		fi

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -