Changeset 4259 for zzuf/trunk/src
- Timestamp:
- Jan 13, 2010, 12:54:38 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
zzuf/trunk/src/zzcat.c
r4255 r4259 56 56 57 57 static int run(char const *sequence, char const *file); 58 static void output(char const *buf, size_t len); 58 59 59 60 static void syntax(void); … … 165 166 166 167 /* 168 * File output method. 169 */ 170 171 static void output(char const *buf, size_t len) 172 { 173 size_t i; 174 175 if (!(escape_tabs || escape_ends || escape_other 176 || number_lines || number_nonblank)) 177 { 178 fwrite(buf, len, 1, stdout); 179 return; 180 } 181 182 for (i = 0; i < len; i++) 183 { 184 int ch = (unsigned int)(unsigned char)buf[i]; 185 186 if (escape_other && ch >= 0x80) 187 { 188 if (ch - 0x80 < 0x20 || ch - 0x80 == 0x7f) 189 fprintf(stdout, "M-^%c", (ch - 0x80) ^ 0x40); 190 else 191 fprintf(stdout, "M-%c", ch - 0x80); 192 } 193 else if (escape_tabs && ch == '\t') 194 fprintf(stdout, "^I"); 195 else if (escape_ends && ch == '\n') 196 puts("$"); 197 else if (escape_other && (ch < 0x20 || ch == 0x7f)) 198 fprintf(stdout, "^%c", ch ^ 0x40); 199 else 200 putchar(ch); 201 } 202 } 203 204 /* 167 205 * Command intepreter 168 206 */ … … 187 225 } while(0) 188 226 227 #define ROUNDUP(size) (((size) + 0xfff) & ~0xfff) 228 189 229 #define MERGE(address, cnt, off) \ 190 230 do { \ … … 193 233 { \ 194 234 retlen = retoff + _cnt; \ 195 retbuf = realloc(retbuf, retlen); \ 235 if (ROUNDUP(retlen) != ROUNDUP(retlen - _cnt)) \ 236 retbuf = realloc(retbuf, ROUNDUP(retlen)); \ 196 237 } \ 197 238 if (_cnt > 0) \ … … 488 529 close(fd); 489 530 490 if (escape_tabs || escape_ends || escape_other || number_lines) 491 { 492 size_t i; 493 494 for (i = 0; i < retlen; i++) 495 { 496 int ch = (unsigned int)(unsigned char)retbuf[i]; 497 498 if (escape_other && ch >= 0x80) 499 { 500 if (ch - 0x80 < 0x20 || ch - 0x80 == 0x7f) 501 fprintf(stdout, "M-^%c", (ch - 0x80) ^ 0x40); 502 else 503 fprintf(stdout, "M-%c", ch - 0x80); 504 } 505 else if (escape_tabs && ch == '\t') 506 fprintf(stdout, "^I"); 507 else if (escape_ends && ch == '\n') 508 puts("$"); 509 else if (escape_other && (ch < 0x20 || ch == 0x7f)) 510 fprintf(stdout, "^%c", ch ^ 0x40); 511 else 512 putchar(ch); 513 } 514 } 515 else 516 { 517 fwrite(retbuf, retlen, 1, stdout); 518 } 519 531 output(retbuf, retlen); 520 532 free(retbuf); 521 533 free(tmp);
Note: See TracChangeset
for help on using the changeset viewer.