4 function shift
( array
, \
8 for ( l =
0; l
< asorti
( array
, junk
) - 1; l
++ )
15 function init_cpp_src_line
()
22 function shift_valid_bp
( array
, \
27 if ( 0 < asorti
( array
, junk
) )
36 function check_cpp_src_line_break_pos
( \
39 printf( "break_pos:" )
40 for ( i =
0; i
< asorti
( break_pos
, junk
); i
++ )
41 printf( " %d", break_pos
[i
] );
46 function check_cpp_src_line
()
48 printf( "logical_line[%s]\n", logical_line
)
49 check_cpp_src_line_break_pos
()
53 function append_line
( phys_line
, \
57 sub( /\\$
/, " ", filt_line
)
58 logical_line = logical_line filt_line
59 bp_len = asorti
( break_pos
, junk
)
60 break_pos
[bp_len
] =
length( logical_line
) - 1
64 function print_line
( \
65 c0
, c1
, i
, junk
, part_str
)
69 while( asorti
( break_pos
, junk
) > 1 )
71 if ( ( c1 = shift_valid_bp
( break_pos
) ) < 1 )
73 part_str =
substr( logical_line
, c0
+ 1 )
74 printf( "%s\n", part_str
)
78 part_str =
substr( logical_line
, c0
+ 1, c1
- c0
+ 1 )
79 gsub( / $
/, "\\", part_str
)
80 printf( "%s\n", part_str
)
84 part_str =
substr( logical_line
, c0
+ 1 )
85 printf( "%s\n", part_str
)
89 function shrink_spaces
( pos
, \
90 tail
, removed_length
, k
)
92 tail =
substr( logical_line
, pos
)
93 sub( /^
[ \t]+/, " ", tail
)
94 removed_length =
length( logical_line
) - pos
- length( tail
) + 1
95 logical_line =
substr( logical_line
, 0, pos
- 1 ) tail
98 for ( k =
0; k
< asorti
( break_pos
, junk
); k
++ )
99 if ( ( pos
+ removed_length
) <= break_pos
[k
] )
100 break_pos
[k
] = break_pos
[k
] - removed_length
;
101 else if ( pos
<= break_pos
[k
] )
104 return removed_length
108 function shrink_spaces_to_linebreak
( pos
, \
109 junk
, part_str
, removed_length
, i
)
111 for ( i =
0; i
< asorti
( break_pos
, junk
) && break_pos
[i
] < pos
; i
++ )
114 if ( break_pos
[i
] < 1 )
117 part_str =
substr( logical_line
, pos
, break_pos
[i
] - pos
+ 1 )
118 sub( /^
[ \t]+/, " ", part_str
)
119 removed_length =
( break_pos
[i
] - pos
+ 1 ) - length( part_str
)
121 tail =
substr( logical_line
, pos
+ removed_length
)
122 logical_line =
substr( logical_line
, 0, pos
- 1 ) tail
124 for ( ; i
< asorti
( break_pos
, junk
); i
++ )
125 break_pos
[i
] -= removed_length
;
127 return removed_length
131 function delete_linebreaks_in_2nd_token
( \
132 tail
, paren_depth
, junk
, i
, j
, k
, l
)
134 if ( logical_line ~
/^
[ \t]*#[ \t]*define[ \t]+[0-9A-Za-z_]+\(/ )
137 sub( /^
[ \t]*#[ \t]*define[ \t]+[0-9A-Za-z_]+/, "", tail )
141 i =
length( logical_line
) - length( tail
) + 1 # seek to the 1st op paren
144 if ( substr( logical_line
, j
, 2 ) ~
/[ \t][ \t]/ )
145 l = shrink_spaces
( j
);
146 else if ( substr( logical_line
, j
, 1 ) ==
"(" )
148 else if ( substr( logical_line
, j
, 1 ) ==
")" )
151 } while ( j
< length( logical_line
) && paren_depth
!= 0 )
153 for ( k =
0; k
< asorti
( break_pos
, junk
); k
++ )
154 if ( i
<= break_pos
[k
] && break_pos
[k
] < j
)
158 shrink_spaces_to_linebreak
( j
);
170 delete_linebreaks_in_2nd_token
()
176 if ( 0 < length( logical_line
) )
178 delete_linebreaks_in_2nd_token
()