Browse Source

Change cboard_pase() to use fread instead of fgetc

master
cancel 5 years ago
parent
commit
83ea4dfd30
  1. 30
      cboard.c

30
cboard.c

@ -24,22 +24,24 @@ Cboard_error cboard_paste(Glyph* gbuffer, Usz height, Usz width, Usz y, Usz x) {
Usz start_x = x; Usz start_x = x;
if (!fp) if (!fp)
return Cboard_error_popen_failed; return Cboard_error_popen_failed;
char inbuff[512];
for (;;) { for (;;) {
int c = fgetc(fp); size_t n = fread(inbuff, 1, sizeof inbuff, fp);
if (c == EOF) for (size_t i = 0; i < n; i++) {
break; char c = inbuff[i];
if (c == '\r' || c == '\n') { if (c == '\r' || c == '\n') {
y++; y++;
x = start_x; x = start_x;
continue; continue;
} }
if (c != ' ' && y < height && x < width) { if (c != ' ' && y < height && x < width) {
Glyph g = c <= CHAR_MAX && c >= CHAR_MIN && is_valid_glyph((Glyph)c) Glyph g = is_valid_glyph((Glyph)c) ? (Glyph)c : '.';
? (Glyph)c gbuffer_poke(gbuffer, height, width, y, x, g);
: '.'; }
gbuffer_poke(gbuffer, height, width, y, x, g); x++;
} }
x++; if (n < sizeof inbuff)
break;
} }
int status = pclose(fp); int status = pclose(fp);
return status ? Cboard_error_process_exit_error : Cboard_error_none; return status ? Cboard_error_process_exit_error : Cboard_error_none;

Loading…
Cancel
Save