| 1 |
|
| #ifdef __cplusplus |
| 2 |
|
| extern "C" { |
| 3 |
|
| #endif |
| 4 |
|
| #include "EXTERN.h" |
| 5 |
|
| #include "perl.h" |
| 6 |
|
| #include "XSUB.h" |
| 7 |
|
| #ifdef __cplusplus |
| 8 |
|
| } |
| 9 |
|
| #endif |
| 10 |
|
| |
| 11 |
|
| |
| 12 |
|
| MODULE = String::DiffLine PACKAGE = String::DiffLine |
| 13 |
|
| |
| 14 |
|
| PROTOTYPES: ENABLE |
| 15 |
|
| |
| 16 |
|
| void |
| 17 |
|
| diffline(s1,s2) |
| 18 |
|
| char *s1; |
| 19 |
|
| char *s2; |
| 20 |
|
| PREINIT: |
| 21 |
|
| STRLEN l,l1,l2,nll,i,lpos,lines; |
| 22 |
|
| char *nl,lnl; |
| 23 |
|
| PPCODE: |
| 24 |
11 |
| l1=SvCUR(ST(0)); |
| 25 |
11 |
| l2=SvCUR(ST(1)); |
| 26 |
11 |
| nl=SvPV(perl_get_sv("/",FALSE),nll); |
| 27 |
11 |
▶ | if(nll==0) nl="\n"; |
Branch: 1 branch
| Branch | True | False | Total |
| if(nll==0) nl="\n"; |
1 |
10 |
11 |
|
| 28 |
11 |
▶ | lnl=nl[nll?nll-1:0]; |
Branch: 1 branch
| Branch | True | False | Total |
| lnl=nl[nll?nll-1:0]; |
10 |
1 |
11 |
|
| 29 |
11 |
| lpos=0;lines=1; |
| 30 |
11 |
▶ | EXTEND(sp,3); |
Branch: 1 branch
| Branch | True | False | Total |
| EXTEND(sp,3); |
0 |
11 |
11 |
|
| 31 |
|
| /*printf("s1=%s l1=%d s2=%s l2=%d nl=%s nll=%d\n",s1,l1,s2,l2,nl,nll);*/ |
| 32 |
11 |
| l=l1<l2?l1:l2; |
| 33 |
76 |
▶ | for(i=0;i<l;i++) |
Branch: 1 branch
| Branch | True | False | Total |
| for(i=0;i<l;i++) |
73 |
3 |
76 |
|
| 34 |
|
| { |
| 35 |
73 |
▶ | if(s1[i]!=s2[i]) |
Branch: 1 branch
| Branch | True | False | Total |
| if(s1[i]!=s2[i]) |
8 |
65 |
73 |
|
| 36 |
|
| { |
| 37 |
8 |
| PUSHs(sv_2mortal(newSViv(i))); |
| 38 |
8 |
| PUSHs(sv_2mortal(newSViv(lines))); |
| 39 |
8 |
| PUSHs(sv_2mortal(newSViv(i-lpos))); |
| 40 |
8 |
| XSRETURN(3); |
| 41 |
|
| } |
| 42 |
|
| /* check if we're at last character of end-of-line 'nl' */ |
| 43 |
65 |
▶ | if(s1[i]==lnl && |
Branch: 1 branch
| Branch | True | False | Total |
| if(s1[i]==lnl && |
17 |
48 |
65 |
|
| 44 |
28 |
▶ | (nll==1 || |
Branch: 3 branches
| Branch | True | False | Total |
| (nll==1 || |
11 |
6 |
17 |
| (nll==1 || |
6 |
2 |
8 |
| (nll==1 || |
1 |
2 |
3 |
|
| 45 |
11 |
▶ | (nll?i-lpos+1>=nll && memcmp(s1+i-nll+1,nl,nll)==0: |
Branch: 3 branches
| Branch | True | False | Total |
| (nll?i-lpos+1>=nll && memcmp(s1+i-nll+1,nl,nll)==0: |
8 |
3 |
11 |
| (nll?i-lpos+1>=nll && memcmp(s1+i-nll+1,nl,nll)==0: |
6 |
2 |
8 |
| (nll?i-lpos+1>=nll && memcmp(s1+i-nll+1,nl,nll)==0: |
6 |
0 |
6 |
|
| 46 |
3 |
▶ | i==l-1 || s1[i+1]!=lnl))) |
Branch: 2 branches
| Branch | True | False | Total |
| i==l-1 || s1[i+1]!=lnl))) |
3 |
0 |
3 |
| i==l-1 || s1[i+1]!=lnl))) |
1 |
2 |
3 |
|
| 47 |
13 |
| lines++,lpos=i+1; |
| 48 |
|
| } |
| 49 |
3 |
▶ | if(l1==l2) |
Branch: 1 branch
| Branch | True | False | Total |
| if(l1==l2) |
2 |
1 |
3 |
|
| 50 |
2 |
| PUSHs(&PL_sv_undef); |
| 51 |
|
| else |
| 52 |
1 |
| PUSHs(sv_2mortal(newSViv(l))); |
| 53 |
3 |
| PUSHs(sv_2mortal(newSViv(lines))); |
| 54 |
3 |
| PUSHs(sv_2mortal(newSViv(i-lpos))); |
| 55 |
|
| |
| 56 |
|
| |