Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Re-add the legacy comment printing algorithm. Currently, it is being retained primarily for testing and comparison purposes. |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | experimental |
Files: | files | file ages | folders |
SHA1: |
0463c7bfb1a9980bb08681b9fef37a7d |
User & Date: | mistachkin 2014-06-21 01:32:58.828 |
Context
2014-06-21
| ||
01:38 | Add --trimspace option to the 'test-comment-format' test command. ... (check-in: 4e3f915c user: mistachkin tags: experimental) | |
01:32 | Re-add the legacy comment printing algorithm. Currently, it is being retained primarily for testing and comparison purposes. ... (check-in: 0463c7bf user: mistachkin tags: experimental) | |
2014-06-20
| ||
20:56 | Merge updates from trunk. ... (check-in: 265a48d3 user: mistachkin tags: experimental) | |
Changes
Changes to src/comformat.c.
︙ | ︙ | |||
24 25 26 27 28 29 30 | #ifdef _WIN32 # include <windows.h> #else # include <termios.h> #endif #if INTERFACE | | > | | | 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | #ifdef _WIN32 # include <windows.h> #else # include <termios.h> #endif #if INTERFACE #define COMMENT_PRINT_NONE ((u32)0x00000000) /* No flags. */ #define COMMENT_PRINT_LEGACY ((u32)0x00000001) /* Use legacy algorithm. */ #define COMMENT_PRINT_TRIM_SPACE ((u32)0x00000002) /* Trim leading/trailing. */ #define COMMENT_PRINT_WORD_BREAK ((u32)0x00000004) /* Break lines on words. */ #define COMMENT_PRINT_DEFAULT (COMMENT_PRINT_TRIM_SPACE) /* Defaults. */ #endif /* ** This is the previous value used by most external callers when they ** needed to specify a default maximum line length to be used with the ** comment_print() function. |
︙ | ︙ | |||
154 155 156 157 158 159 160 | } if( pzLine ){ *pzLine = zLine + index; } } /* | > > > | | | | | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 | } if( pzLine ){ *pzLine = zLine + index; } } /* ** This is the legacy comment printing algorithm. Currently, it is being ** retained primarily for testing and comparison purposes. ** ** Given a comment string, format that string for printing on a TTY. ** Assume that the output cursors is indent spaces from the left margin ** and that a single line can contain no more than width characters. ** Indent all subsequent lines by indent. ** ** Returns the number of new lines emitted. */ static int comment_print_legacy( const char *zText, /* The comment text to be printed. */ int indent, /* Number of spaces to indent each non-initial line. */ int width /* Maximum number of characters per line. */ ){ int tlen = width - indent; int si, sk, i, k; int doIndent = 0; char *zBuf; char zBuffer[400]; int lineCnt = 0; #if defined(_WIN32) if( width<0 ){ CONSOLE_SCREEN_BUFFER_INFO csbi; memset(&csbi, 0, sizeof(CONSOLE_SCREEN_BUFFER_INFO)); if( GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi) ){ tlen = csbi.srWindow.Right - csbi.srWindow.Left - indent; } } #elif defined(TIOCGWINSZ) if( width<0 ){ struct winsize w; memset(&w, 0, sizeof(struct winsize)); if( ioctl(0, TIOCGWINSZ, &w)!=-1 ){ tlen = w.ws_col - indent; } } #else if( width<0 ){ /* ** Fallback to using more-or-less the "legacy semantics" of hard-coding ** the maximum line length to a value reasonable for the vast majority ** of supported systems. */ tlen = COMMENT_LEGACY_LINE_LENGTH - indent; } #endif if( zText==0 ) zText = "(NULL)"; if( tlen<=0 ){ tlen = strlen(zText); } if( tlen >= (sizeof(zBuffer)) ){ zBuf = fossil_malloc(tlen+1); }else{ zBuf = zBuffer; } for(;;){ while( fossil_isspace(zText[0]) ){ zText++; } if( zText[0]==0 ){ if( doIndent==0 ){ fossil_print("\n"); lineCnt = 1; } if( zBuf!=zBuffer) fossil_free(zBuf); return lineCnt; } for(sk=si=i=k=0; zText[i] && k<tlen; i++){ char c = zText[i]; if( fossil_isspace(c) ){ si = i; sk = k; if( k==0 || zBuf[k-1]!=' ' ){ zBuf[k++] = ' '; } }else{ zBuf[k] = c; if( c=='-' && k>0 && fossil_isalpha(zBuf[k-1]) ){ si = i+1; sk = k+1; } k++; } } if( doIndent ){ fossil_print("%*s", indent, ""); } doIndent = 1; if( sk>0 && zText[i] ){ zText += si; zBuf[sk] = 0; }else{ zText += i; zBuf[k] = 0; } fossil_print("%s\n", zBuf); lineCnt++; } } /* ** Given a comment string, format that string for printing on a TTY. ** Assume that the output cursors is indent spaces from the left margin ** and that a single line can contain no more than width characters. ** Indent all subsequent lines by indent. ** ** Returns the number of new lines emitted. */ int comment_print( const char *zText, /* The comment text to be printed. */ int indent, /* Number of spaces to indent each non-initial line. */ int width, /* Maximum number of characters per line. */ int flags /* Zero or more "COMMENT_PRINT_*" flags, see above. */ ){ int maxChars = width - indent; int legacy = flags & COMMENT_PRINT_LEGACY; int trimSpace = flags & COMMENT_PRINT_TRIM_SPACE; int wordBreak = flags & COMMENT_PRINT_WORD_BREAK; int lineCnt = 0; const char *zLine; if( legacy ){ return comment_print_legacy(zText, indent, width); } #if defined(_WIN32) if( width<0 ){ CONSOLE_SCREEN_BUFFER_INFO csbi; memset(&csbi, 0, sizeof(CONSOLE_SCREEN_BUFFER_INFO)); if( GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi) ){ maxChars = csbi.srWindow.Right - csbi.srWindow.Left - indent; } |
︙ | ︙ | |||
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 | ** Usage: %fossil test-comment-format ?OPTIONS? PREFIX TEXT ?WIDTH? ** ** Test comment formatting and printing. Use for testing only. ** ** Options: ** --decode Decode the text using the same method used when ** handling the value of a C-card from a manifest. ** --wordbreak Attempt to break lines on word boundaries. */ void test_comment_format(void){ const char *zPrefix; char *zText; int indent, width; int decode = find_option("decode", 0, 0)!=0; int flags = COMMENT_PRINT_DEFAULT; if( find_option("wordbreak", 0, 0) ){ flags |= COMMENT_PRINT_WORD_BREAK; } if( g.argc!=4 && g.argc!=5 ){ usage("PREFIX TEXT ?WIDTH?"); } zPrefix = g.argv[2]; | > > > > | 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 | ** Usage: %fossil test-comment-format ?OPTIONS? PREFIX TEXT ?WIDTH? ** ** Test comment formatting and printing. Use for testing only. ** ** Options: ** --decode Decode the text using the same method used when ** handling the value of a C-card from a manifest. ** --legacy Use the legacy comment printing algorithm. ** --wordbreak Attempt to break lines on word boundaries. */ void test_comment_format(void){ const char *zPrefix; char *zText; int indent, width; int decode = find_option("decode", 0, 0)!=0; int flags = COMMENT_PRINT_DEFAULT; if( find_option("legacy", 0, 0) ){ flags |= COMMENT_PRINT_LEGACY; } if( find_option("wordbreak", 0, 0) ){ flags |= COMMENT_PRINT_WORD_BREAK; } if( g.argc!=4 && g.argc!=5 ){ usage("PREFIX TEXT ?WIDTH?"); } zPrefix = g.argv[2]; |
︙ | ︙ |