From d4f6a7104bb294658311de22103e2bf13656126a Mon Sep 17 00:00:00 2001 From: Bart Oldeman Date: Tue, 27 Jan 2004 20:07:28 +0000 Subject: [PATCH] Clean up scr_pos updating routines: combine into update_scr_pos() function instead of 2 copies of the same thing. git-svn-id: https://svn.code.sf.net/p/freedos/svn/kernel/trunk@760 6ac86273-5f31-0410-b378-82cca8765d1b --- kernel/chario.c | 43 ++++++++++++++++++++----------------------- kernel/dosfns.c | 19 +------------------ kernel/proto.h | 1 + 3 files changed, 22 insertions(+), 41 deletions(-) diff --git a/kernel/chario.c b/kernel/chario.c index 9864058..93ea5f7 100644 --- a/kernel/chario.c +++ b/kernel/chario.c @@ -196,14 +196,9 @@ STATIC void fast_put_char(unsigned char chr) } #endif -/* writes a character in cooked mode; maybe with printer echo; - handles TAB expansion */ -STATIC int cooked_write_char(struct dhdr FAR **pdev, - unsigned char c, - unsigned char *fast_counter) +void update_scr_pos(unsigned char c, unsigned char count) { unsigned char scrpos = scr_pos; - unsigned char count = 1; if (c == CR) scrpos = 0; @@ -211,13 +206,24 @@ STATIC int cooked_write_char(struct dhdr FAR **pdev, if (scrpos > 0) scrpos--; } else if (c != LF && c != BELL) { - if (c == HT) { - count = 8 - (scrpos & 7); - c = ' '; - } scrpos += count; } scr_pos = scrpos; +} + +/* writes a character in cooked mode; maybe with printer echo; + handles TAB expansion */ +STATIC int cooked_write_char(struct dhdr FAR **pdev, + unsigned char c, + unsigned char *fast_counter) +{ + unsigned char count = 1; + + if (c == HT) { + count = 8 - (scr_pos & 7); + c = ' '; + } + update_scr_pos(c, count); do { @@ -277,28 +283,19 @@ void write_char(int c, int sft_idx) void write_char_stdout(int c) { - unsigned char scrpos = scr_pos; unsigned char count = 1; unsigned flags = get_sft(STDOUT)->sft_flags & (SFT_FDEVICE | SFT_FBINARY); /* ah=2, ah=9 should expand tabs even for raw devices and disk files */ if (flags != SFT_FDEVICE) { - if (c == CR) - scrpos = 0; - else if (c == BS) { - if (scrpos > 0) - scrpos--; - } else if (c != LF && c != BELL) { - if (c == HT) { - count = 8 - (scrpos & 7); - c = ' '; - } - scrpos += count; + if (c == HT) { + count = 8 - (scr_pos & 7); + c = ' '; } /* for raw devices already updated in dosfns.c */ if (!(flags & SFT_FDEVICE)) - scr_pos = scrpos; + update_scr_pos(c, count); } do { diff --git a/kernel/dosfns.c b/kernel/dosfns.c index 476dba2..ba9e787 100644 --- a/kernel/dosfns.c +++ b/kernel/dosfns.c @@ -247,25 +247,8 @@ long DosRWSft(int sft_idx, size_t n, void FAR * bp, int mode) { size_t cnt = (size_t)rc; const char FAR *p = bp; - unsigned char scrpos = scr_pos; while (cnt--) - { - switch (*p++) - { - case CR: - scrpos = 0; - break; - case LF: - case BELL: - break; - case BS: - --scrpos; - break; - default: - ++scrpos; - } - } - scr_pos = scrpos; + update_scr_pos(*p++, 1); } return rc; } diff --git a/kernel/proto.h b/kernel/proto.h index c2d67c2..4666207 100644 --- a/kernel/proto.h +++ b/kernel/proto.h @@ -69,6 +69,7 @@ void read_line(int sft_in, int sft_out, keyboard FAR * kp); size_t read_line_handle(int sft_idx, size_t n, char FAR * bp); void write_char(int c, int sft_idx); void write_char_stdout(int c); +void update_scr_pos(unsigned char c, unsigned char count); long cooked_write(struct dhdr FAR **pdev, size_t n, char FAR *bp); sft FAR *get_sft(UCOUNT);