| | @@ -44,14 +44,13 @@ |
| 44 | 44 | ** |
| 45 | 45 | ** Return the number of newlines that are output. |
| 46 | 46 | */ |
| 47 | 47 | int comment_print(const char *zText, int indent, int lineLength){ |
| 48 | 48 | int tlen = lineLength - indent; |
| 49 | | - int si, sk, i, k; |
| 49 | + int len = 0; |
| 50 | 50 | int doIndent = 0; |
| 51 | | - char *zBuf; |
| 52 | | - char zBuffer[400]; |
| 51 | + const char *zBuf; |
| 53 | 52 | int lineCnt = 0; |
| 54 | 53 | |
| 55 | 54 | #if defined(_WIN32) |
| 56 | 55 | if( lineLength<0 ){ |
| 57 | 56 | CONSOLE_SCREEN_BUFFER_INFO csbi; |
| | @@ -80,56 +79,50 @@ |
| 80 | 79 | #endif |
| 81 | 80 | if( zText==0 ) zText = "(NULL)"; |
| 82 | 81 | if( tlen<=0 ){ |
| 83 | 82 | tlen = strlen(zText); |
| 84 | 83 | } |
| 85 | | - if( tlen >= (sizeof(zBuffer)) ){ |
| 86 | | - zBuf = fossil_malloc(tlen+1); |
| 87 | | - }else{ |
| 88 | | - zBuf = zBuffer; |
| 89 | | - } |
| 90 | | - for(;;){ |
| 91 | | - while( fossil_isspace(zText[0]) ){ zText++; } |
| 92 | | - if( zText[0]==0 ){ |
| 93 | | - if( doIndent==0 ){ |
| 94 | | - fossil_print("\n"); |
| 95 | | - lineCnt = 1; |
| 96 | | - } |
| 97 | | - if( zBuf!=zBuffer) fossil_free(zBuf); |
| 98 | | - return lineCnt; |
| 99 | | - } |
| 100 | | - for(sk=si=i=k=0; zText[i] && k<tlen; i++){ |
| 101 | | - char c = zText[i]; |
| 102 | | - if( fossil_isspace(c) ){ |
| 103 | | - si = i; |
| 104 | | - sk = k; |
| 105 | | - if( k==0 || zBuf[k-1]!=' ' ){ |
| 106 | | - zBuf[k++] = ' '; |
| 107 | | - } |
| 108 | | - }else{ |
| 109 | | - zBuf[k] = c; |
| 110 | | - if( c=='-' && k>0 && fossil_isalpha(zBuf[k-1]) ){ |
| 111 | | - si = i+1; |
| 112 | | - sk = k+1; |
| 113 | | - } |
| 114 | | - k++; |
| 115 | | - } |
| 116 | | - } |
| 117 | | - if( doIndent ){ |
| 118 | | - fossil_print("%*s", indent, ""); |
| 119 | | - } |
| 120 | | - doIndent = 1; |
| 121 | | - if( sk>0 && zText[i] ){ |
| 122 | | - zText += si; |
| 123 | | - zBuf[sk] = 0; |
| 124 | | - }else{ |
| 125 | | - zText += i; |
| 126 | | - zBuf[k] = 0; |
| 127 | | - } |
| 128 | | - fossil_print("%s\n", zBuf); |
| 129 | | - lineCnt++; |
| 130 | | - } |
| 84 | + while( fossil_isspace(zText[0]) ){ zText++; } |
| 85 | + if( zText[0]==0 ){ |
| 86 | + if( doIndent==0 ){ |
| 87 | + fossil_print("\n"); |
| 88 | + lineCnt = 1; |
| 89 | + } |
| 90 | + return lineCnt; |
| 91 | + } |
| 92 | + |
| 93 | + zBuf = zText; |
| 94 | + for(;;){ |
| 95 | + if( zText[0]==0 ){ |
| 96 | + if( doIndent ){ |
| 97 | + fossil_print("%*s", indent, ""); |
| 98 | + } |
| 99 | + fossil_print("%.*s\n", zText -zBuf, zBuf); |
| 100 | + lineCnt++; |
| 101 | + break; |
| 102 | + } |
| 103 | + |
| 104 | + if( zText[0]=='\t' ){ |
| 105 | + len += 8; |
| 106 | + }else{ |
| 107 | + len++; |
| 108 | + } |
| 109 | + if( (zText[0]=='\n') || len >= tlen ){ |
| 110 | + while( !fossil_isspace(zText[0]) ){ zText--; } |
| 111 | + if( doIndent ){ |
| 112 | + fossil_print("%*s", indent, ""); |
| 113 | + } |
| 114 | + doIndent = 1; |
| 115 | + fossil_print("%.*s\n", zText -zBuf, zBuf); |
| 116 | + zBuf = zText; |
| 117 | + len=0; |
| 118 | + lineCnt++; |
| 119 | + if( !zBuf++ ) break; |
| 120 | + } |
| 121 | + zText++; |
| 122 | + } |
| 123 | + return lineCnt; |
| 131 | 124 | } |
| 132 | 125 | |
| 133 | 126 | /* |
| 134 | 127 | ** Test the comment printing |
| 135 | 128 | ** |
| 136 | 129 | |