@@ -131,6 +131,8 @@ ALNUM_LITERAL \"[^\"\n]*\"|\'[^\'\n]*\'
131
131
"SUPPRESS" { return SUPPRESS ; }
132
132
"PRINTING" { return PRINTING ; }
133
133
"REPLACING" { return REPLACING ; }
134
+ "LEADING" { return LEADING ; }
135
+ "TRAILING" { return TRAILING ; }
134
136
{WORD } {
135
137
#ifdef I18N_UTF8
136
138
convert_ucs_hyphen_minus (yytext );
@@ -790,43 +792,106 @@ ppecho (const char *text)
790
792
791
793
text_queue = cb_text_list_add (text_queue , text );
792
794
793
- for (r = current_replace_list ; r ; r = r -> next ) {
794
- queue = text_queue ;
795
- for (l = r -> old_text ; l ; l = l -> next ) {
795
+ while (text_queue ) {
796
+ for (r = current_replace_list ; r ; r = r -> next ) {
797
+ queue = text_queue ;
798
+ for (l = r -> old_text ; l ; l = l -> next ) {
799
+ while (l && (l -> text [0 ] == ' ' || l -> text [0 ] == '\n' )) {
800
+ l = l -> next ;
801
+ }
802
+ if (l == NULL ) {
803
+ break ;
804
+ }
805
+ while (queue && (queue -> text [0 ] == ' ' ||
806
+ queue -> text [0 ] == '\n' )) {
807
+ queue = queue -> next ;
808
+ }
809
+ if (queue == NULL ) {
810
+ return ; /* partial match */
811
+ }
812
+ if (r -> replace_type == CB_REPLACE_LEADING ) {
813
+ break ;
814
+ } else if (r -> replace_type == CB_REPLACE_TRAILING ) {
815
+ break ;
816
+ } else if (r -> replace_type == CB_REPLACE_OTHER ) {
817
+ if (strcasecmp (l -> text , queue -> text ) != 0 ) {
818
+ break ;
819
+ }
820
+ }
821
+ queue = queue -> next ;
822
+ }
823
+ if (r -> replace_type == CB_REPLACE_LEADING ) {
824
+ if (!l || !queue ) {
825
+ continue ;
826
+ }
827
+ if (strncasecmp (l -> text , queue -> text , strlen (l -> text )) == 0 ) {
828
+ break ;
829
+ }
830
+ } else if (r -> replace_type == CB_REPLACE_TRAILING ) {
831
+ if (!l || !queue || strlen (queue -> text ) < strlen (r -> old_text -> text )) {
832
+ continue ;
833
+ }
834
+ if (strcasecmp (queue -> text + strlen (queue -> text ) - strlen (r -> old_text -> text ), r -> old_text -> text ) == 0 ) {
835
+ break ;
836
+ }
837
+ } else if (l == NULL ) {
838
+ /* match */
839
+ break ;
840
+ }
841
+ }
842
+
843
+ /* match */
844
+ if (r && r -> replace_type == CB_REPLACE_LEADING ) {
845
+ int oldlen = strlen (l -> text );
846
+ for (l = text_queue ; l != queue ; l = l -> next ) {
847
+ fputs (l -> text , ppout );
848
+ }
849
+ l = r -> new_text ;
796
850
while (l && (l -> text [0 ] == ' ' || l -> text [0 ] == '\n' )) {
797
851
l = l -> next ;
798
852
}
799
- if (l == NULL ) {
800
- break ;
853
+ if (l ) {
854
+ fputs ( l -> text , ppout ) ;
801
855
}
802
- while (queue && (queue -> text [0 ] == ' ' ||
803
- queue -> text [0 ] == '\n' )) {
804
- queue = queue -> next ;
856
+ fputs (queue -> text + oldlen , ppout );
857
+ queue = queue -> next ;
858
+ } else if (r && r -> replace_type == CB_REPLACE_TRAILING ) {
859
+ int i ;
860
+ int oldlen = strlen (l -> text );
861
+ for (l = text_queue ; l != queue ; l = l -> next ) {
862
+ fputs (l -> text , ppout );
805
863
}
806
- if ( queue == NULL ) {
807
- return ; /* partial match */
864
+ for ( i = 0 ; i < strlen ( queue -> text ) - oldlen ; i ++ ) {
865
+ fputc ( queue -> text [ i ], ppout );
808
866
}
809
- if (strcasecmp (l -> text , queue -> text ) != 0 ) {
810
- break ;
867
+ l = r -> new_text ;
868
+ while (l && (l -> text [0 ] == ' ' || l -> text [0 ] == '\n' )) {
869
+ l = l -> next ;
870
+ }
871
+ if (l ) {
872
+ fputs (l -> text , ppout );
811
873
}
812
874
queue = queue -> next ;
813
- }
814
- if (l == NULL ) {
815
- /* match */
875
+ } else if (r && l == NULL ) {
816
876
for (l = r -> new_text ; l ; l = l -> next ) {
817
877
fputs (l -> text , ppout );
818
878
}
819
- /*
820
- text_queue = queue ? queue->next : NULL;
821
- */
822
- text_queue = queue ;
823
- continue ;
879
+ } else {
880
+ /* no match */
881
+ if (!text_queue ) {
882
+ break ;
883
+ }
884
+ fputs (text_queue -> text , ppout );
885
+ queue = text_queue -> next ;
824
886
}
825
- }
826
887
827
- /* no match */
828
- for (; text_queue ; text_queue = text_queue -> next ) {
829
- fputs (text_queue -> text , ppout );
888
+ while (text_queue != queue ) {
889
+ if (!text_queue ) break ;
890
+
891
+ l = text_queue -> next ;
892
+ free (text_queue );
893
+ text_queue = l ;
894
+ }
830
895
}
831
896
}
832
897
}
0 commit comments