Fossil SCM

Simplify the looks_like_binary() macro. Remove literal tab character, adjust styling and comments in looks_like_text().

mistachkin 2012-10-28 23:01 trunk
Commit c8e72df08eeaeac71f4c64c31af4294d2c8e9a67
1 file changed +6 -6
+6 -6
--- src/diff.c
+++ src/diff.c
@@ -48,11 +48,11 @@
4848
"cannot compute difference between binary files\n"
4949
5050
#define DIFF_CANNOT_COMPUTE_SYMLINK \
5151
"cannot compute difference between symlink and regular file\n"
5252
53
-#define looks_like_binary(blob) (!(looks_like_text(blob)&1))
53
+#define looks_like_binary(blob) (looks_like_text((blob)) == 0)
5454
#endif /* INTERFACE */
5555
5656
/*
5757
** Maximum length of a line in a text file. (8192)
5858
*/
@@ -179,35 +179,35 @@
179179
*/
180180
int looks_like_text(const Blob *pContent){
181181
const char *z = blob_buffer(pContent);
182182
unsigned int n = blob_size(pContent);
183183
int j, c;
184
- int result = 1;
184
+ int result = 1; /* Assume text with no CrLf */
185185
186186
/* Check individual lines.
187187
*/
188
- if( n==0 ) return 1; /* Empty file -> text */
188
+ if( n==0 ) return result; /* Empty file -> text */
189189
c = *z;
190190
if( c==0 ) return 0; /* \000 byte in a file -> binary */
191191
j = (c!='\n');
192192
while( --n>0 ){
193193
c = *++z; ++j;
194194
if( c==0 ) return 0; /* \000 byte in a file -> binary */
195195
if( c=='\n' ){
196196
if( z[-1]=='\r' ){
197
- result = -1; /* Contains CrLf, continue */
197
+ result = -1; /* Contains CrLf, continue */
198198
}
199199
if( j>LENGTH_MASK ){
200
- return 0; /* Very long line -> binary */
200
+ return 0; /* Very long line -> binary */
201201
}
202202
j = 0;
203203
}
204204
}
205205
if( j>LENGTH_MASK ){
206206
return 0; /* Very long line -> binary */
207207
}
208
- return result; /* No problems seen -> not binary */
208
+ return result; /* No problems seen -> not binary */
209209
}
210210
211211
/*
212212
** Return true if two DLine elements are identical.
213213
*/
214214
--- src/diff.c
+++ src/diff.c
@@ -48,11 +48,11 @@
48 "cannot compute difference between binary files\n"
49
50 #define DIFF_CANNOT_COMPUTE_SYMLINK \
51 "cannot compute difference between symlink and regular file\n"
52
53 #define looks_like_binary(blob) (!(looks_like_text(blob)&1))
54 #endif /* INTERFACE */
55
56 /*
57 ** Maximum length of a line in a text file. (8192)
58 */
@@ -179,35 +179,35 @@
179 */
180 int looks_like_text(const Blob *pContent){
181 const char *z = blob_buffer(pContent);
182 unsigned int n = blob_size(pContent);
183 int j, c;
184 int result = 1;
185
186 /* Check individual lines.
187 */
188 if( n==0 ) return 1; /* Empty file -> text */
189 c = *z;
190 if( c==0 ) return 0; /* \000 byte in a file -> binary */
191 j = (c!='\n');
192 while( --n>0 ){
193 c = *++z; ++j;
194 if( c==0 ) return 0; /* \000 byte in a file -> binary */
195 if( c=='\n' ){
196 if( z[-1]=='\r' ){
197 result = -1; /* Contains CrLf, continue */
198 }
199 if( j>LENGTH_MASK ){
200 return 0; /* Very long line -> binary */
201 }
202 j = 0;
203 }
204 }
205 if( j>LENGTH_MASK ){
206 return 0; /* Very long line -> binary */
207 }
208 return result; /* No problems seen -> not binary */
209 }
210
211 /*
212 ** Return true if two DLine elements are identical.
213 */
214
--- src/diff.c
+++ src/diff.c
@@ -48,11 +48,11 @@
48 "cannot compute difference between binary files\n"
49
50 #define DIFF_CANNOT_COMPUTE_SYMLINK \
51 "cannot compute difference between symlink and regular file\n"
52
53 #define looks_like_binary(blob) (looks_like_text((blob)) == 0)
54 #endif /* INTERFACE */
55
56 /*
57 ** Maximum length of a line in a text file. (8192)
58 */
@@ -179,35 +179,35 @@
179 */
180 int looks_like_text(const Blob *pContent){
181 const char *z = blob_buffer(pContent);
182 unsigned int n = blob_size(pContent);
183 int j, c;
184 int result = 1; /* Assume text with no CrLf */
185
186 /* Check individual lines.
187 */
188 if( n==0 ) return result; /* Empty file -> text */
189 c = *z;
190 if( c==0 ) return 0; /* \000 byte in a file -> binary */
191 j = (c!='\n');
192 while( --n>0 ){
193 c = *++z; ++j;
194 if( c==0 ) return 0; /* \000 byte in a file -> binary */
195 if( c=='\n' ){
196 if( z[-1]=='\r' ){
197 result = -1; /* Contains CrLf, continue */
198 }
199 if( j>LENGTH_MASK ){
200 return 0; /* Very long line -> binary */
201 }
202 j = 0;
203 }
204 }
205 if( j>LENGTH_MASK ){
206 return 0; /* Very long line -> binary */
207 }
208 return result; /* No problems seen -> not binary */
209 }
210
211 /*
212 ** Return true if two DLine elements are identical.
213 */
214

Keyboard Shortcuts

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