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
This commit is contained in:
Bart Oldeman 2004-01-27 20:07:28 +00:00
parent b7491eba32
commit d4f6a7104b
3 changed files with 22 additions and 41 deletions

View File

@ -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 {

View File

@ -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;
}

View File

@ -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);