Fossil SCM
Improve clarity of the new comment printing algorithm.
Commit
8e7d2a6586b2214b8a9c30ffeb101a02bd91c87f
Parent
351de029f3b5a00…
1 file changed
+8
-5
+8
-5
| --- src/comformat.c | ||
| +++ src/comformat.c | ||
| @@ -179,10 +179,11 @@ | ||
| 179 | 179 | if( !zLine ) return; |
| 180 | 180 | if( lineChars<=0 ) return; |
| 181 | 181 | comment_print_indent(zLine, indent, trimSpace, &index); |
| 182 | 182 | maxChars = lineChars; |
| 183 | 183 | for(;;){ |
| 184 | + int useChars = 1; | |
| 184 | 185 | char c = zLine[index]; |
| 185 | 186 | if( c==0 ){ |
| 186 | 187 | break; |
| 187 | 188 | }else{ |
| 188 | 189 | if( origBreak && index>0 ){ |
| @@ -193,36 +194,38 @@ | ||
| 193 | 194 | } |
| 194 | 195 | } |
| 195 | 196 | index++; |
| 196 | 197 | } |
| 197 | 198 | if( c=='\n' ){ |
| 198 | - charCnt = 0; | |
| 199 | 199 | lineCnt++; |
| 200 | + charCnt = 0; | |
| 201 | + useChars = 0; | |
| 200 | 202 | }else if( c=='\t' ){ |
| 201 | 203 | int nextIndex = comment_next_space(zLine, index); |
| 202 | 204 | if( nextIndex<=0 || (nextIndex-index)>maxChars ){ |
| 203 | 205 | break; |
| 204 | 206 | } |
| 205 | 207 | charCnt++; |
| 206 | - if( maxChars<COMMENT_TAB_WIDTH ){ | |
| 208 | + useChars = COMMENT_TAB_WIDTH; | |
| 209 | + if( maxChars<useChars ){ | |
| 207 | 210 | fossil_print(" "); |
| 208 | 211 | break; |
| 209 | 212 | } |
| 210 | - maxChars -= COMMENT_TAB_WIDTH; | |
| 211 | 213 | }else if( wordBreak && fossil_isspace(c) ){ |
| 212 | 214 | int nextIndex = comment_next_space(zLine, index); |
| 213 | 215 | if( nextIndex<=0 || (nextIndex-index)>maxChars ){ |
| 214 | 216 | break; |
| 215 | 217 | } |
| 216 | 218 | charCnt++; |
| 217 | - maxChars--; | |
| 218 | 219 | }else{ |
| 219 | 220 | charCnt++; |
| 220 | - maxChars--; | |
| 221 | 221 | } |
| 222 | + assert( c!='\n' || charCnt==0 ); | |
| 222 | 223 | fossil_print("%c", c); |
| 224 | + maxChars -= useChars; | |
| 223 | 225 | if( maxChars==0 ) break; |
| 226 | + assert( maxChars>0 ); | |
| 224 | 227 | if( c=='\n' ) break; |
| 225 | 228 | } |
| 226 | 229 | if( charCnt>0 ){ |
| 227 | 230 | fossil_print("\n"); |
| 228 | 231 | lineCnt++; |
| 229 | 232 |
| --- src/comformat.c | |
| +++ src/comformat.c | |
| @@ -179,10 +179,11 @@ | |
| 179 | if( !zLine ) return; |
| 180 | if( lineChars<=0 ) return; |
| 181 | comment_print_indent(zLine, indent, trimSpace, &index); |
| 182 | maxChars = lineChars; |
| 183 | for(;;){ |
| 184 | char c = zLine[index]; |
| 185 | if( c==0 ){ |
| 186 | break; |
| 187 | }else{ |
| 188 | if( origBreak && index>0 ){ |
| @@ -193,36 +194,38 @@ | |
| 193 | } |
| 194 | } |
| 195 | index++; |
| 196 | } |
| 197 | if( c=='\n' ){ |
| 198 | charCnt = 0; |
| 199 | lineCnt++; |
| 200 | }else if( c=='\t' ){ |
| 201 | int nextIndex = comment_next_space(zLine, index); |
| 202 | if( nextIndex<=0 || (nextIndex-index)>maxChars ){ |
| 203 | break; |
| 204 | } |
| 205 | charCnt++; |
| 206 | if( maxChars<COMMENT_TAB_WIDTH ){ |
| 207 | fossil_print(" "); |
| 208 | break; |
| 209 | } |
| 210 | maxChars -= COMMENT_TAB_WIDTH; |
| 211 | }else if( wordBreak && fossil_isspace(c) ){ |
| 212 | int nextIndex = comment_next_space(zLine, index); |
| 213 | if( nextIndex<=0 || (nextIndex-index)>maxChars ){ |
| 214 | break; |
| 215 | } |
| 216 | charCnt++; |
| 217 | maxChars--; |
| 218 | }else{ |
| 219 | charCnt++; |
| 220 | maxChars--; |
| 221 | } |
| 222 | fossil_print("%c", c); |
| 223 | if( maxChars==0 ) break; |
| 224 | if( c=='\n' ) break; |
| 225 | } |
| 226 | if( charCnt>0 ){ |
| 227 | fossil_print("\n"); |
| 228 | lineCnt++; |
| 229 |
| --- src/comformat.c | |
| +++ src/comformat.c | |
| @@ -179,10 +179,11 @@ | |
| 179 | if( !zLine ) return; |
| 180 | if( lineChars<=0 ) return; |
| 181 | comment_print_indent(zLine, indent, trimSpace, &index); |
| 182 | maxChars = lineChars; |
| 183 | for(;;){ |
| 184 | int useChars = 1; |
| 185 | char c = zLine[index]; |
| 186 | if( c==0 ){ |
| 187 | break; |
| 188 | }else{ |
| 189 | if( origBreak && index>0 ){ |
| @@ -193,36 +194,38 @@ | |
| 194 | } |
| 195 | } |
| 196 | index++; |
| 197 | } |
| 198 | if( c=='\n' ){ |
| 199 | lineCnt++; |
| 200 | charCnt = 0; |
| 201 | useChars = 0; |
| 202 | }else if( c=='\t' ){ |
| 203 | int nextIndex = comment_next_space(zLine, index); |
| 204 | if( nextIndex<=0 || (nextIndex-index)>maxChars ){ |
| 205 | break; |
| 206 | } |
| 207 | charCnt++; |
| 208 | useChars = COMMENT_TAB_WIDTH; |
| 209 | if( maxChars<useChars ){ |
| 210 | fossil_print(" "); |
| 211 | break; |
| 212 | } |
| 213 | }else if( wordBreak && fossil_isspace(c) ){ |
| 214 | int nextIndex = comment_next_space(zLine, index); |
| 215 | if( nextIndex<=0 || (nextIndex-index)>maxChars ){ |
| 216 | break; |
| 217 | } |
| 218 | charCnt++; |
| 219 | }else{ |
| 220 | charCnt++; |
| 221 | } |
| 222 | assert( c!='\n' || charCnt==0 ); |
| 223 | fossil_print("%c", c); |
| 224 | maxChars -= useChars; |
| 225 | if( maxChars==0 ) break; |
| 226 | assert( maxChars>0 ); |
| 227 | if( c=='\n' ) break; |
| 228 | } |
| 229 | if( charCnt>0 ){ |
| 230 | fossil_print("\n"); |
| 231 | lineCnt++; |
| 232 |