diff_parser2.sh

#!/bin/bash


srcfile=new.c
diff=diff.txt


function parse_src_to_regions()
{
gawk '
{
judge = $0~/^[0-9a-zA-Z_]+(\[|\]|\*)*\s+(\[|\]|\*)*[0-9a-zA-Z_]+\s*\(.*$/
if (judge){
split($0, strs, "\\(")
split(strs[1], strs2, "\\s+")
func_name = strs2[length(strs2)]
func_to_start[func_name] = NR
print(func_name":"NR)
}
}
' $1
}


function get_regions_from_ranges()
{
gawk -F ":" '


BEGIN{
start = '$1'
end = '$2'
prevfunc = ""
prevline = -1
}


{
if ($2 > end){
exit;
}
if ($2 == end){
print($1":"$2)
exit;
}


if ($2 < start){
prevline = $2
prevfunc = $1
next
}


if ($2 == start){
print($1":"$2)
prevline = -1
next
}


if(prevline >= 0){
print("%#%"prevfunc":"prevline)
}


print($1":"$2)
}


END{


}


' $3
}


function get_start_to_end()
{
regions=`more $2`




for region in ${regions[*]}; do
OLD_IFS="$IFS"
IFS=":" 
strs=($region)
IFS="$OLD_IFS"
func_name=${strs[0]}
nr=$((${strs[1]}))
gawk '


BEGIN{
in_double_quote=0
in_quote=0
level=0
in_func=0
in_comment=0
}


{
if(NR < '$nr'){
next
}


if ($0~/^\s*\/\//){
next
}


if($0~/^\s*\/\*/){
in_comment = 1
}


split($0, char_array, "")
for(i=1; i<=length(char_array); ++i){
char = char_array[i]
if(char == "\\"){
i++
continue
}


if(in_comment == 1){
if(char != "*"){
continue
}
if(i==length(char_array) || char_array[i+1]!="/"){
continue
}
i++
in_comment = 0
continue
}


if(in_quote==0 && in_double_quote==0){
if(char=="/" && i<length(char_array)){
if(char_array[i+1]=="/"){
next
}else if(char_array[i+1]=="*"){
i++
in_comment=1
continue
}
}


if(char=="\x27"){
in_quote=1
continue
}


if(char=="\""){
in_double_quote=1
continue
}
}else{
if(in_quote==1){
if(match(char, /'\''/)){
in_quote=0
}
continue
}
if(in_double_quote==1){
if(match(char, /\"/)){
in_double_quote=0
}
continue
}
}


if(in_func==0){
if(!match(char, /\{/)){
continue
}
in_func = 1;
level = 1;
}else{


if(match(char, /\{/) || match(char, /\}/)){
if(match(char, /\{/)){
level=level+1
}else{
level=level-1
if(level==0){
print('$nr'":"NR)
exit
}
}
}


}
}


/* print(NR": "in_func" "level) */


if(in_func>0 && level==0){
print('$nr'":"NR)
exit
}
}s


END{


}


' $1
done
}


function print_by_ranges()
{
ranges=`more $5`
whole=""


for range in ${ranges[*]}; do
whole=$whole$range":"
done


gawk '


BEGIN{
cur=1
str="'$whole'"
split(str, strs, ":")
diff_start = '$2'
diff_end = '$3'
diff_started = 0
have_region=1  
}


{
if(cur+1<=length(strs)){
func_start = strs[cur]
func_end   = strs[cur+1]
have_region = 1
}else{
func_start = 8888888
func_end   = -1
have_region = 0
}


if(have_region==1){
if (func_end < diff_start){
cur+=2
next
}else if (func_start > diff_end){
exit
}
}


if(NR<=func_end && NR>=func_start){/*in-function modification*/
print($0)
diff_started = 1
}else if (NR < func_start && NR>=diff_start && NR<=diff_end){/* handle globals */
if((diff_started==0 && $0~/^\s+/) || (NR==diff_end && $0!~/;\s*$/)){
print("'$srcfile'"" line "NR": //error: parse_err=1, cannot handle partial global modification.")
exit
}


glo_judge  =          /^[0-9a-zA-Z_]+[\[\]\*]*\s+([0-9a-zA-Z_]+)/
glo_judge2 = /^extern\s+[0-9a-zA-Z_]+[\[\]\*]*\s+([0-9a-zA-Z_]+)/


if(match($0, glo_judge2, grp)){


while((getline gls < "'$4'""_new_globals.txt") > 0){
if(grp[1] == gls){
diff_started = 1
next
}
}
}


if($1!="extern"){
if(match($0, glo_judge, grp)){
print grp[1] >> "'$4'""_new_globals.txt"
}
print($0)
}
diff_started = 1
}




if(NR==func_end){
cur+=2
}
}


' $1
}




parse_src_to_regions $srcfile \
| get_regions_from_ranges $1 $2 \
| get_start_to_end $srcfile \
| print_by_ranges $srcfile $1 $2 src_output.c



基于MATLAB实现旅行推销员问题(TSP)的代码+项目说明(课程大作业)+测试数据.zip基于MATLAB实现旅行推销员问题(TSP)的代码+项目说明(课程大作业)+测试数据.zip基于MATLAB实现旅行推销员问题(TSP)的代码+项目说明(课程大作业)+测试数据.zip基于MATLAB实现旅行推销员问题(TSP)的代码+项目说明(课程大作业)+测试数据.zip基于MATLAB实现旅行推销员问题(TSP)的代码+项目说明(课程大作业)+测试数据.zip基于MATLAB实现旅行推销员问题(TSP)的代码+项目说明(课程大作业)+测试数据.zip基于MATLAB实现旅行推销员问题(TSP)的代码+项目说明(课程大作业)+测试数据.zip基于MATLAB实现旅行推销员问题(TSP)的代码+项目说明(课程大作业)+测试数据.zip基于MATLAB实现旅行推销员问题(TSP)的代码+项目说明(课程大作业)+测试数据.zip基于MATLAB实现旅行推销员问题(TSP)的代码+项目说明(课程大作业)+测试数据.zip基于MATLAB实现旅行推销员问题(TSP)的代码+项目说明(课程大作业)+测试数据.zip基于MATLAB实现旅行推销员问题(TSP)的代码+项目说明(课程大作业)+测试数据.zip基于MATLAB实现旅行推销员问题(TSP)的代码+项目说明(课程大作业)+测试数据.zip基于MATLAB实现旅行推销员问题(TSP)的代码+项目说明(课程大作业)+测试数据.zip基于MATLAB实现旅行推销员问题(TSP)的代码+项目说明(课程大作业)+测试数据.zip基于MATLAB实现旅行推销员问题(TSP)的代码+项目说明(课程大作业)+测试数据.zip基于MATLAB实现旅行推销员问题(TSP)的代码+项目说明(课程大作业)+测试数据.zip基于MATLAB实现旅行推销员问题(TSP)的代码+项目说明(课程大作业)+测试数据.zip基于MATLAB实现旅行推销员问题(TSP)的代码+项目说明(课程大作业)+测试数据.zip基于MATLAB实现旅行推销员问题(TSP)的代码+项目说明(课程大作业)+测试数据.zip 【备注】 1、该资源内项目代码百分百可运行,请放心下载使用!有问题请及时沟通交流。 2、适用人群:计算机相关专业(如计科、信息安全、数据科学与大数据技术、人工智能、通信、物联网、自动化、电子信息等)在校学生、专业老师或者企业员工下载使用。 3、用途:项目具有较高的学习借鉴价值,不仅适用于小白学习入门进阶。也可作为毕设项目、课程设计、大作业、初期项目立项演示等。 4、如果基础还行,或热爱钻研,亦可在此项目代码基础上进行修改添加,实现其他不同功能。 欢迎下载!欢迎交流学习!不清楚的可以私信问我!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值