update sendfile

This commit is contained in:
Andrew Pamment 2019-12-02 09:57:38 +10:00
parent 600bcdefcf
commit a15f663547

View File

@ -4,19 +4,25 @@
void md_sendfile(const char *filename, int pause) { void md_sendfile(const char *filename, int pause) {
FILE *fptr; FILE *fptr;
char c; char c, d;
int lines = 0; int lines = 0;
char lastch = 'x';
fptr = fopen(filename, "r"); fptr = fopen(filename, "r");
if (fptr != NULL) { if (fptr != NULL) {
c = fgetc(fptr); c = fgetc(fptr);
while (!feof(fptr) && c != 0x1a) { while (!feof(fptr) && c != 0x1a) {
if (c == '\n') { if (c == '\n') {
lines++; lines++;
if (lastch != '\r') {
md_printf("\r\n"); md_printf("\r\n");
} else {
md_printf("\n");
}
if (lines == 22 && pause == TRUE) { if (lines == 22 && pause == TRUE) {
md_printf("More (Y/N)"); md_printf("More (Y/N)");
c = md_getc(); d = md_getc();
if (tolower(c) == 'n') { if (tolower(d) == 'n') {
fclose(fptr); fclose(fptr);
return; return;
} }
@ -27,6 +33,7 @@ void md_sendfile(const char *filename, int pause) {
} else { } else {
md_putchar(c); md_putchar(c);
} }
lastch = c;
c = fgetc(fptr); c = fgetc(fptr);
} }
fclose(fptr); fclose(fptr);