00001
00007
00008
00009 #include <kernel.h>
00010 #include <device.h>
00011 #include <tty.h>
00012
00020 devcall ttyWrite(device *pdev, uchar *buf, ushort len)
00021 {
00022 struct tty *ptty;
00023 device *phw = NULL;
00024 ushort i = 0;
00025 uchar last = 0;
00026
00027
00028 ptty = (struct tty *)pdev->controlblk;
00029 ASSERT((NULL != ptty) && (TTY_STATE_ALLOC == ptty->state));
00030
00031 phw = ptty->tty_phw;
00032 ASSERT(NULL != phw);
00033
00034 for (i = 0; i < len; i++)
00035 {
00036
00037 if (!(ptty->oflags & TTY_OFLAG_RAW))
00038 {
00039
00040 if ( ('\r' == buf[i])
00041 || (('\n' == buf[i])
00042 && ('\r' != last) ))
00043 {
00044
00045
00046
00047
00048
00049 if (SYSERR == (*phw->putc)(phw, '\r')) break;
00050 if (SYSERR == (*phw->putc)(phw, '\n')) break;
00051 last = buf[i];
00052 continue;
00053 }
00054
00055
00056 if (('\0' == buf[i]) || ('\n' == buf[i]))
00057 {
00058 last = buf[i];
00059 continue;
00060 }
00061
00062
00063 if (('\b' == buf[i]) || (0x7F == buf[i]))
00064 {
00065
00066 if (SYSERR == (*phw->putc)(phw, '\b')) break;
00067 if (SYSERR == (*phw->putc)(phw, ' ')) break;
00068 if (SYSERR == (*phw->putc)(phw, '\b')) break;
00069 last = buf[i];
00070 continue;
00071 }
00072 }
00073
00074
00075 if (SYSERR == (*phw->putc)(phw, buf[i])) break;
00076
00077
00078 last = buf[i];
00079 }
00080
00081 return i;
00082 }