From 0cc9b20c15460213e488bf5e70963b941482f628 Mon Sep 17 00:00:00 2001 From: William Harrington Date: Tue, 14 Jan 2025 16:06:02 -0600 Subject: Add source. --- sdk/dev/format.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 sdk/dev/format.c (limited to 'sdk/dev/format.c') diff --git a/sdk/dev/format.c b/sdk/dev/format.c new file mode 100644 index 0000000..508ec6c --- /dev/null +++ b/sdk/dev/format.c @@ -0,0 +1,64 @@ +/* + * Specify serial port data line format. + * $Id$ + * Copyright (c) 1997 by Tycho Softworks. + * For conditions of distribution and reuse see product license. + */ + +#include +#ifndef TERMIOS_H_MISSING +#include +#endif + +int setformat(stty_t stty, char *format) +{ +#ifndef TERMIOS_H_MISSING + struct termios *tios = stty; + + tios->c_cflag &= ~CSIZE; + if(format[2] == '1') + tios->c_cflag &= ~CSTOPB; + else + tios->c_cflag |= CSTOPB; + + switch(format[0]) + { + case '5': + tios->c_cflag |= CS5; + break; + case '6': + tios->c_cflag |= CS6; + break; + case '7': + tios->c_cflag |= CS7; + break; + case '8': + tios->c_cflag |= CS8; + break; + } + + switch(format[1]) + { + case 'n': + case 'N': + tios->c_cflag &= ~(PARODD | PARENB); + break; + case 'e': + case 'E': + tios->c_cflag |= PARENB; + tios->c_cflag &= ~PARODD; + break; + case 'o': + case 'O': + tios->c_cflag |= (PARENB | PARODD); + break; + } + +#endif + return 0; +} + + + + + -- cgit v1.2.3-54-g00ecf