Fossil SCM

Further refinements and more tests.

mistachkin 2014-06-20 18:31 experimental
Commit 70ba07c368a139b13a2b3b4e2c2cac8e9cd370cb
+8 -6
--- src/comformat.c
+++ src/comformat.c
@@ -139,10 +139,14 @@
139139
}
140140
if( c=='\n' ){
141141
charCnt = 0;
142142
lineCnt++;
143143
}else if( c=='\t' ){
144
+ int nextIndex = comment_next_space(zLine, index);
145
+ if( nextIndex<=0 || (nextIndex-index)>maxChars ){
146
+ break;
147
+ }
144148
charCnt++;
145149
if( maxChars<COMMENT_TAB_WIDTH ){
146150
fossil_print(" ");
147151
break;
148152
}
@@ -160,11 +164,11 @@
160164
}
161165
fossil_print("%c", c);
162166
if( maxChars==0 ) break;
163167
if( c=='\n' ) break;
164168
}
165
- if( charCnt>0 || lineCnt==0 ){
169
+ if( charCnt>0 ){
166170
fossil_print("\n");
167171
lineCnt++;
168172
}
169173
if( pLineCnt ){
170174
*pLineCnt += lineCnt;
@@ -194,23 +198,21 @@
194198
}
195199
196200
/*
197201
** This function scans the specified comment line starting just after the
198202
** initial index and returns the index of the next spacing character -OR-
199
-** zero if such a character cannot be found.
203
+** zero if such a character cannot be found. For the purposes of this
204
+** algorithm, the NUL character is treated the same as a spacing character.
200205
*/
201206
int comment_next_space(
202207
const char *zLine, /* [in] The comment line being printed. */
203208
int index /* [in] The current character index being handled. */
204209
){
205210
int nextIndex = index + 1;
206211
for(;;){
207212
char c = zLine[nextIndex];
208
- if( c==0 ){
209
- return 0;
210
- }
211
- if( fossil_isspace(c) ){
213
+ if( c==0 || fossil_isspace(c) ){
212214
return nextIndex;
213215
}
214216
nextIndex++;
215217
}
216218
return 0; /* NOT REACHED */
217219
--- src/comformat.c
+++ src/comformat.c
@@ -139,10 +139,14 @@
139 }
140 if( c=='\n' ){
141 charCnt = 0;
142 lineCnt++;
143 }else if( c=='\t' ){
 
 
 
 
144 charCnt++;
145 if( maxChars<COMMENT_TAB_WIDTH ){
146 fossil_print(" ");
147 break;
148 }
@@ -160,11 +164,11 @@
160 }
161 fossil_print("%c", c);
162 if( maxChars==0 ) break;
163 if( c=='\n' ) break;
164 }
165 if( charCnt>0 || lineCnt==0 ){
166 fossil_print("\n");
167 lineCnt++;
168 }
169 if( pLineCnt ){
170 *pLineCnt += lineCnt;
@@ -194,23 +198,21 @@
194 }
195
196 /*
197 ** This function scans the specified comment line starting just after the
198 ** initial index and returns the index of the next spacing character -OR-
199 ** zero if such a character cannot be found.
 
200 */
201 int comment_next_space(
202 const char *zLine, /* [in] The comment line being printed. */
203 int index /* [in] The current character index being handled. */
204 ){
205 int nextIndex = index + 1;
206 for(;;){
207 char c = zLine[nextIndex];
208 if( c==0 ){
209 return 0;
210 }
211 if( fossil_isspace(c) ){
212 return nextIndex;
213 }
214 nextIndex++;
215 }
216 return 0; /* NOT REACHED */
217
--- src/comformat.c
+++ src/comformat.c
@@ -139,10 +139,14 @@
139 }
140 if( c=='\n' ){
141 charCnt = 0;
142 lineCnt++;
143 }else if( c=='\t' ){
144 int nextIndex = comment_next_space(zLine, index);
145 if( nextIndex<=0 || (nextIndex-index)>maxChars ){
146 break;
147 }
148 charCnt++;
149 if( maxChars<COMMENT_TAB_WIDTH ){
150 fossil_print(" ");
151 break;
152 }
@@ -160,11 +164,11 @@
164 }
165 fossil_print("%c", c);
166 if( maxChars==0 ) break;
167 if( c=='\n' ) break;
168 }
169 if( charCnt>0 ){
170 fossil_print("\n");
171 lineCnt++;
172 }
173 if( pLineCnt ){
174 *pLineCnt += lineCnt;
@@ -194,23 +198,21 @@
198 }
199
200 /*
201 ** This function scans the specified comment line starting just after the
202 ** initial index and returns the index of the next spacing character -OR-
203 ** zero if such a character cannot be found. For the purposes of this
204 ** algorithm, the NUL character is treated the same as a spacing character.
205 */
206 int comment_next_space(
207 const char *zLine, /* [in] The comment line being printed. */
208 int index /* [in] The current character index being handled. */
209 ){
210 int nextIndex = index + 1;
211 for(;;){
212 char c = zLine[nextIndex];
213 if( c==0 || fossil_isspace(c) ){
 
 
 
214 return nextIndex;
215 }
216 nextIndex++;
217 }
218 return 0; /* NOT REACHED */
219
--- test/comment.test
+++ test/comment.test
@@ -88,5 +88,35 @@
8888
8989
###############################################################################
9090
9191
fossil test-comment-format --wordbreak "*TEST* " "this is a test......................................................................................................................." 60
9292
test comment-15 {$RESULT eq "*TEST* this is a\n test.................................................\n .....................................................\n .................\n(4 lines output)"}
93
+
94
+###############################################################################
95
+
96
+fossil test-comment-format "*TEST* " "this is a test......................................................................................................................." 60
97
+test comment-16 {$RESULT eq "*TEST* this is a\n test.................................................\n .....................................................\n .................\n(4 lines output)"}
98
+
99
+###############################################################################
100
+
101
+fossil test-comment-format --wordbreak "*TEST* " "this is a test......................................................................................................................." 60
102
+test comment-17 {$RESULT eq "*TEST* this is a\n test.................................................\n .....................................................\n .................\n(4 lines output)"}
103
+
104
+###############################################################################
105
+
106
+fossil test-comment-format "*TEST* " "one two three four five six seven eight nine ten eleven twelve" 60
107
+test comment-18 {$RESULT eq "*TEST* one two three four five six seven eight nine ten elev\n en twelve\n(2 lines output)"}
108
+
109
+###############################################################################
110
+
111
+fossil test-comment-format --wordbreak "*TEST* " "one two three four five six seven eight nine ten eleven twelve" 60
112
+test comment-19 {$RESULT eq "*TEST* one two three four five six seven eight nine ten\n eleven twelve\n(2 lines output)"}
113
+
114
+###############################################################################
115
+
116
+fossil test-comment-format "*TEST* " "one two three four five six seven eight nine ten eleven twelve" 60
117
+test comment-20 {$RESULT eq "*TEST* one two three four five\n six seven eight nine ten\n eleven twelve\n(3 lines output)"}
118
+
119
+###############################################################################
120
+
121
+fossil test-comment-format --wordbreak "*TEST* " "one two three four five six seven eight nine ten eleven twelve" 60
122
+test comment-21 {$RESULT eq "*TEST* one two three four five\n six seven eight nine ten\n eleven twelve\n(3 lines output)"}
93123
--- test/comment.test
+++ test/comment.test
@@ -88,5 +88,35 @@
88
89 ###############################################################################
90
91 fossil test-comment-format --wordbreak "*TEST* " "this is a test......................................................................................................................." 60
92 test comment-15 {$RESULT eq "*TEST* this is a\n test.................................................\n .....................................................\n .................\n(4 lines output)"}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
93
--- test/comment.test
+++ test/comment.test
@@ -88,5 +88,35 @@
88
89 ###############################################################################
90
91 fossil test-comment-format --wordbreak "*TEST* " "this is a test......................................................................................................................." 60
92 test comment-15 {$RESULT eq "*TEST* this is a\n test.................................................\n .....................................................\n .................\n(4 lines output)"}
93
94 ###############################################################################
95
96 fossil test-comment-format "*TEST* " "this is a test......................................................................................................................." 60
97 test comment-16 {$RESULT eq "*TEST* this is a\n test.................................................\n .....................................................\n .................\n(4 lines output)"}
98
99 ###############################################################################
100
101 fossil test-comment-format --wordbreak "*TEST* " "this is a test......................................................................................................................." 60
102 test comment-17 {$RESULT eq "*TEST* this is a\n test.................................................\n .....................................................\n .................\n(4 lines output)"}
103
104 ###############################################################################
105
106 fossil test-comment-format "*TEST* " "one two three four five six seven eight nine ten eleven twelve" 60
107 test comment-18 {$RESULT eq "*TEST* one two three four five six seven eight nine ten elev\n en twelve\n(2 lines output)"}
108
109 ###############################################################################
110
111 fossil test-comment-format --wordbreak "*TEST* " "one two three four five six seven eight nine ten eleven twelve" 60
112 test comment-19 {$RESULT eq "*TEST* one two three four five six seven eight nine ten\n eleven twelve\n(2 lines output)"}
113
114 ###############################################################################
115
116 fossil test-comment-format "*TEST* " "one two three four five six seven eight nine ten eleven twelve" 60
117 test comment-20 {$RESULT eq "*TEST* one two three four five\n six seven eight nine ten\n eleven twelve\n(3 lines output)"}
118
119 ###############################################################################
120
121 fossil test-comment-format --wordbreak "*TEST* " "one two three four five six seven eight nine ten eleven twelve" 60
122 test comment-21 {$RESULT eq "*TEST* one two three four five\n six seven eight nine ten\n eleven twelve\n(3 lines output)"}
123

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button