summaryrefslogtreecommitdiff
path: root/libc/termios
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2000-10-09 20:06:30 +0000
committerEric Andersen <andersen@codepoet.org>2000-10-09 20:06:30 +0000
commitc1fe19d4c1db610692365472a90f4661e48449c1 (patch)
treed0b0219ffca3c4c4256f55c4aea4513e43d6aecd /libc/termios
parent9efafb8bbc7408b04643dcd53825d971577b4d9d (diff)
Bug ugly formatting update
Diffstat (limited to 'libc/termios')
-rw-r--r--libc/termios/.indent.pro33
-rw-r--r--libc/termios/Makefile11
-rw-r--r--libc/termios/termios.c294
-rw-r--r--libc/termios/ttyname.c66
4 files changed, 230 insertions, 174 deletions
diff --git a/libc/termios/.indent.pro b/libc/termios/.indent.pro
new file mode 100644
index 000000000..492ecf1c7
--- /dev/null
+++ b/libc/termios/.indent.pro
@@ -0,0 +1,33 @@
+--blank-lines-after-declarations
+--blank-lines-after-procedures
+--break-before-boolean-operator
+--no-blank-lines-after-commas
+--braces-on-if-line
+--braces-on-struct-decl-line
+--comment-indentation25
+--declaration-comment-column25
+--no-comment-delimiters-on-blank-lines
+--cuddle-else
+--continuation-indentation4
+--case-indentation0
+--else-endif-column33
+--space-after-cast
+--line-comments-indentation0
+--declaration-indentation1
+--dont-format-first-column-comments
+--dont-format-comments
+--honour-newlines
+--indent-level4
+/* changed from 0 to 4 */
+--parameter-indentation4
+--line-length78 /* changed from 75 */
+--continue-at-parentheses
+--no-space-after-function-call-names
+--dont-break-procedure-type
+--dont-star-comments
+--leave-optional-blank-lines
+--dont-space-special-semicolon
+--tab-size4
+/* additions by Mark */
+--case-brace-indentation0
+--leave-preprocessor-space
diff --git a/libc/termios/Makefile b/libc/termios/Makefile
index 3a9ee7a13..7bcb35407 100644
--- a/libc/termios/Makefile
+++ b/libc/termios/Makefile
@@ -31,16 +31,21 @@ MOBJ=tcsetattr.o tcgetattr.o tcdrain.o tcflow.o tcflush.o tcsendbreak.o \
CSRC=ttyname.c
COBJS=$(patsubst %.c,%.o, $(CSRC))
+OBJS=$(MOBJ) $(COBJS)
-all: $(MOBJ) $(COBJS) $(LIBC)
+all: $(OBJS) $(LIBC)
-$(LIBC): $(MOBJ) $(COBJS)
- $(AR) $(ARFLAGS) $(LIBC) $(MOBJ) $(COBJS)
+$(LIBC): ar-target
+
+ar-target: $(OBJS)
+ $(AR) $(ARFLAGS) $(LIBC) $(OBJS)
$(MOBJ): $(MSRC)
$(CC) $(CFLAGS) -DL_$* $< -c -o $*.o
+$(OBJS): Makefile
+
clean:
rm -f *.[oa] *~ core
diff --git a/libc/termios/termios.c b/libc/termios/termios.c
index 7532259d4..6781f32fd 100644
--- a/libc/termios/termios.c
+++ b/libc/termios/termios.c
@@ -16,126 +16,119 @@
#ifdef L_isatty
int isatty(int fd)
{
- struct termios term;
- int rv, err = errno;
- rv= (ioctl(fd, TCGETS, &term)==0);
- if( rv==0 && errno == ENOSYS )
- rv = (fd<3);
- errno = err;
- return rv;
+ struct termios term;
+ int rv, err = errno;
+
+ rv = (ioctl(fd, TCGETS, &term) == 0);
+ if (rv == 0 && errno == ENOSYS)
+ rv = (fd < 3);
+ errno = err;
+ return rv;
}
-#endif
+#endif
#ifdef L_tcgetattr
-int
-tcgetattr(fd, term)
-int fd;
+int tcgetattr(fd, term)
+int fd;
struct termios *term;
{
- return ioctl(fd, TCGETS, term);
+ return ioctl(fd, TCGETS, term);
}
#endif
#ifdef L_tcsetattr
-int
-tcsetattr(fildes, optional_actions, termios_p)
+int tcsetattr(fildes, optional_actions, termios_p)
int fildes;
int optional_actions;
struct termios *termios_p;
{
- switch (optional_actions)
- {
- case TCSANOW:
- return ioctl(fildes, TCSETS, termios_p);
- case TCSADRAIN:
- return ioctl(fildes, TCSETSW, termios_p);
- case TCSAFLUSH:
- return ioctl(fildes, TCSETSF, termios_p);
- default:
- errno = EINVAL;
- return -1;
- }
+ switch (optional_actions) {
+ case TCSANOW:
+ return ioctl(fildes, TCSETS, termios_p);
+ case TCSADRAIN:
+ return ioctl(fildes, TCSETSW, termios_p);
+ case TCSAFLUSH:
+ return ioctl(fildes, TCSETSF, termios_p);
+ default:
+ errno = EINVAL;
+ return -1;
+ }
}
#endif
#ifdef L_tcdrain
/* Wait for pending output to be written on FD. */
-int
-tcdrain(fd)
-int fd;
+int tcdrain(fd)
+int fd;
{
- /* With an argument of 1, TCSBRK just waits for output to drain. */
- return ioctl(fd, TCSBRK, 1);
+ /* With an argument of 1, TCSBRK just waits for output to drain. */
+ return ioctl(fd, TCSBRK, 1);
}
#endif
#ifdef L_tcflow
-int
-tcflow(fd, action)
+int tcflow(fd, action)
int fd;
int action;
{
- return ioctl(fd, TCXONC, action);
+ return ioctl(fd, TCXONC, action);
}
#endif
#ifdef L_tcflush
/* Flush pending data on FD. */
-int
-tcflush(fd, queue_selector)
-int fd;
-int queue_selector;
+int tcflush(fd, queue_selector)
+int fd;
+int queue_selector;
{
- return ioctl(fd, TCFLSH, queue_selector);
+ return ioctl(fd, TCFLSH, queue_selector);
}
#endif
#ifdef L_tcsendbreak
/* Send zero bits on FD. */
-int
-tcsendbreak(fd, duration)
-int fd;
-int duration;
+int tcsendbreak(fd, duration)
+int fd;
+int duration;
{
- /*
- * The break lasts 0.25 to 0.5 seconds if DURATION is zero, and an
- * implementation-defined period if DURATION is nonzero. We define a
- * positive DURATION to be number of milliseconds to break.
- */
- if (duration <= 0)
- return ioctl(fd, TCSBRK, 0);
-
- /*
- * ioctl can't send a break of any other duration for us. This could be
- * changed to use trickery (e.g. lower speed and send a '\0') to send
- * the break, but for now just return an error.
- */
- errno = EINVAL;
- return -1;
+ /*
+ * The break lasts 0.25 to 0.5 seconds if DURATION is zero, and an
+ * implementation-defined period if DURATION is nonzero. We define a
+ * positive DURATION to be number of milliseconds to break.
+ */
+ if (duration <= 0)
+ return ioctl(fd, TCSBRK, 0);
+
+ /*
+ * ioctl can't send a break of any other duration for us. This could be
+ * changed to use trickery (e.g. lower speed and send a '\0') to send
+ * the break, but for now just return an error.
+ */
+ errno = EINVAL;
+ return -1;
}
#endif
#ifdef L_tcsetpgrp
/* Set the foreground process group ID of FD set PGRP_ID. */
-int
-tcsetpgrp(fd, pgrp_id)
-int fd;
+int tcsetpgrp(fd, pgrp_id)
+int fd;
pid_t pgrp_id;
{
- return ioctl(fd, TIOCSPGRP, &pgrp_id);
+ return ioctl(fd, TIOCSPGRP, &pgrp_id);
}
#endif
#ifdef L_tcgetpgrp
/* Return the foreground process group ID of FD. */
-pid_t
-tcgetpgrp(fd)
-int fd;
+pid_t tcgetpgrp(fd)
+int fd;
{
- int pgrp;
- if (ioctl(fd, TIOCGPGRP, &pgrp) < 0)
- return (pid_t) - 1;
- return (pid_t) pgrp;
+ int pgrp;
+
+ if (ioctl(fd, TIOCGPGRP, &pgrp) < 0)
+ return (pid_t) - 1;
+ return (pid_t) pgrp;
}
#endif
@@ -143,7 +136,7 @@ int fd;
speed_t cfgetospeed(tp)
struct termios *tp;
{
- return (tp->c_cflag & CBAUD);
+ return (tp->c_cflag & CBAUD);
}
#endif
@@ -151,34 +144,36 @@ struct termios *tp;
speed_t cfgetispeed(tp)
struct termios *tp;
{
- return (tp->c_cflag & CBAUD);
+ return (tp->c_cflag & CBAUD);
}
#endif
#ifdef L_cfsetospeed
int cfsetospeed(tp, speed)
-struct termios *tp; speed_t speed;
+struct termios *tp;
+speed_t speed;
{
#ifdef CBAUDEX
- if ((speed & ~CBAUD) ||
- ((speed & CBAUDEX) && (speed < B57600 || speed > B115200)))
- return 0;
+ if ((speed & ~CBAUD) ||
+ ((speed & CBAUDEX) && (speed < B57600 || speed > B115200)))
+ return 0;
#else
- if (speed & ~CBAUD)
- return 0;
+ if (speed & ~CBAUD)
+ return 0;
#endif
- tp->c_cflag &= ~CBAUD;
- tp->c_cflag |= speed;
+ tp->c_cflag &= ~CBAUD;
+ tp->c_cflag |= speed;
- return 0;
+ return 0;
}
#endif
#ifdef L_cfsetispeed
int cfsetispeed(tp, speed)
-struct termios *tp; speed_t speed;
+struct termios *tp;
+speed_t speed;
{
- return cfsetospeed(tp, speed);
+ return cfsetospeed(tp, speed);
}
#endif
@@ -192,87 +187,110 @@ static struct {
speed_t code;
} tcspeeds[] = {
#ifdef B50
- {50, B50},
+ {
+ 50, B50},
#endif
#ifdef B75
- {75, B75},
+ {
+ 75, B75},
#endif
#ifdef B110
- {110, B110},
+ {
+ 110, B110},
#endif
#ifdef B134
- {134, B134},
+ {
+ 134, B134},
#endif
#ifdef B150
- {150, B150},
+ {
+ 150, B150},
#endif
#ifdef B200
- {200, B200},
+ {
+ 200, B200},
#endif
#ifdef B300
- {300, B300},
+ {
+ 300, B300},
#endif
#ifdef B600
- {600, B600},
+ {
+ 600, B600},
#endif
#ifdef B1200
- {1200, B1200},
+ {
+ 1200, B1200},
#endif
#ifdef B1800
- {1800, B1800},
+ {
+ 1800, B1800},
#endif
#ifdef B2400
- {2400, B2400},
+ {
+ 2400, B2400},
#endif
#ifdef B4800
- {4800, B4800},
+ {
+ 4800, B4800},
#endif
#ifdef B9600
- {9600, B9600},
+ {
+ 9600, B9600},
#endif
#ifdef B19200
- {19200, B19200},
+ {
+ 19200, B19200},
#endif
#ifdef B38400
- {38400, B38400},
+ {
+ 38400, B38400},
#endif
#ifdef B57600
- {57600, B57600},
+ {
+ 57600, B57600},
#endif
#ifdef B115200
- {115200, B115200},
+ {
+ 115200, B115200},
#endif
#ifdef B230400
- {230400, B230400},
+ {
+ 230400, B230400},
#endif
#ifdef B460800
- {460800, B460800},
+ {
+ 460800, B460800},
#endif
#ifdef B0
- {0, B0},
+ {
+ 0, B0},
#endif
- {0, 0}
+ {
+ 0, 0}
};
int tcspeed_to_number(code)
speed_t code;
{
- int i;
- code &= CBAUD;
- for(i=0;tcspeeds[i].code;i++)
- if (tcspeeds[i].code == code)
- return tcspeeds[i].number;
- return 0;
+ int i;
+
+ code &= CBAUD;
+ for (i = 0; tcspeeds[i].code; i++)
+ if (tcspeeds[i].code == code)
+ return tcspeeds[i].number;
+ return 0;
}
speed_t tcspeed_from_number(number)
int number;
{
- int i;
- for(i=0;tcspeeds[i].code;i++)
- if (tcspeeds[i].number == number)
- return tcspeeds[i].code;
- return B0;
+ int i;
+
+ for (i = 0; tcspeeds[i].code; i++)
+ if (tcspeeds[i].number == number)
+ return tcspeeds[i].code;
+ return B0;
}
#endif
@@ -280,7 +298,7 @@ int number;
int cfgetospeedn(tp)
struct termios *tp;
{
- return tcspeed_to_number(cfgetospeed(tp));
+ return tcspeed_to_number(cfgetospeed(tp));
}
#endif
@@ -288,23 +306,25 @@ struct termios *tp;
int cfgetispeedn(tp)
struct termios *tp;
{
- return tcspeed_to_number(cfgetispeed(tp));
+ return tcspeed_to_number(cfgetispeed(tp));
}
#endif
#ifdef L_cfsetospeedn
int cfsetospeedn(tp, speed)
-struct termios *tp; int speed;
+struct termios *tp;
+int speed;
{
- return cfsetospeed(tp, tcspeed_from_number(speed));
+ return cfsetospeed(tp, tcspeed_from_number(speed));
}
#endif
#ifdef L_cfsetispeedn
int cfsetispeedn(tp, speed)
-struct termios *tp; int speed;
+struct termios *tp;
+int speed;
{
- return cfsetispeedn(tp, tcspeed_from_number(speed));
+ return cfsetispeedn(tp, tcspeed_from_number(speed));
}
#endif
@@ -315,8 +335,7 @@ struct termios *tp; int speed;
/* Copyright (C) 1992 Free Software Foundation, Inc.
This file is part of the GNU C Library.*/
-void
-cfmakeraw(t)
+void cfmakeraw(t)
struct termios *t;
{
/* I changed it to the current form according to the suggestions
@@ -328,20 +347,23 @@ struct termios *t;
* I took out the bits commented out by #if 1...#else - RHP
*/
- /* VMIN = 0 means non-blocking for Linux */
- t->c_cc[VMIN] = 1; t->c_cc[VTIME] = 1;
- /* clear some bits with &= ~(bits), set others with |= */
- t->c_cflag &= ~(CSIZE|PARENB|CSTOPB);
- t->c_cflag |= (CS8|HUPCL|CREAD);
- t->c_iflag &= ~(IGNBRK|BRKINT|PARMRK|INPCK|ISTRIP);
- t->c_iflag &= ~(INLCR|IGNCR|ICRNL|IXON|IXOFF);
- t->c_iflag |= (BRKINT|IGNPAR);
- t->c_oflag &= ~(OPOST|OLCUC|OCRNL|ONOCR|ONLRET|OFILL|OFDEL);
- t->c_oflag &= ~(NLDLY|CRDLY|TABDLY|BSDLY|VTDLY|FFDLY);
- t->c_oflag |= (ONLCR|NL0|CR0|TAB3|BS0|VT0|FF0);
- t->c_lflag &= ~(ISIG|ICANON|IEXTEN|ECHO|ECHOE|ECHOK|ECHONL);
- t->c_lflag &= ~(NOFLSH|XCASE);
- t->c_lflag &= ~(ECHOPRT|ECHOCTL|ECHOKE);
+ /* VMIN = 0 means non-blocking for Linux */
+ t->c_cc[VMIN] = 1;
+ t->c_cc[VTIME] = 1;
+ /* clear some bits with &= ~(bits), set others with |= */
+ t->c_cflag &= ~(CSIZE | PARENB | CSTOPB);
+ t->c_cflag |= (CS8 | HUPCL | CREAD);
+ t->c_iflag &= ~(IGNBRK | BRKINT | PARMRK | INPCK | ISTRIP);
+ t->c_iflag &= ~(INLCR | IGNCR | ICRNL | IXON | IXOFF);
+ t->c_iflag |= (BRKINT | IGNPAR);
+ t->c_oflag &=
+ ~(OPOST | OLCUC | OCRNL | ONOCR | ONLRET | OFILL | OFDEL);
+ t->c_oflag &= ~(NLDLY | CRDLY | TABDLY | BSDLY | VTDLY | FFDLY);
+ t->c_oflag |= (ONLCR | NL0 | CR0 | TAB3 | BS0 | VT0 | FF0);
+ t->c_lflag &=
+ ~(ISIG | ICANON | IEXTEN | ECHO | ECHOE | ECHOK | ECHONL);
+ t->c_lflag &= ~(NOFLSH | XCASE);
+ t->c_lflag &= ~(ECHOPRT | ECHOCTL | ECHOKE);
}
#endif
diff --git a/libc/termios/ttyname.c b/libc/termios/ttyname.c
index 9fc4f950c..ee78137c0 100644
--- a/libc/termios/ttyname.c
+++ b/libc/termios/ttyname.c
@@ -4,43 +4,39 @@
#include <sys/stat.h>
#include <dirent.h>
-char *
-ttyname(fd)
-int fd;
+char *ttyname(fd)
+int fd;
{
- static char dev[] = "/dev";
- struct stat st, dst;
- DIR *fp;
- struct dirent *d;
- static char name[NAME_MAX];
- int noerr = errno;
+ static char dev[] = "/dev";
+ struct stat st, dst;
+ DIR *fp;
+ struct dirent *d;
+ static char name[NAME_MAX];
+ int noerr = errno;
- if (fstat(fd, &st) < 0)
- return 0;
- if (!isatty(fd))
- {
- errno = ENOTTY;
- return 0;
- }
+ if (fstat(fd, &st) < 0)
+ return 0;
+ if (!isatty(fd)) {
+ errno = ENOTTY;
+ return 0;
+ }
- fp = opendir(dev);
- if (fp == 0)
- return 0;
- strcpy(name, dev);
- strcat(name, "/");
+ fp = opendir(dev);
+ if (fp == 0)
+ return 0;
+ strcpy(name, dev);
+ strcat(name, "/");
- while ((d = readdir(fp)) != 0)
- {
- strcpy(name + sizeof(dev), d->d_name);
- if (stat(name, &dst) == 0
- && st.st_dev == dst.st_dev && st.st_ino == dst.st_ino)
- {
- closedir(fp);
- errno = noerr;
- return name;
- }
- }
- closedir(fp);
- errno = noerr;
- return 0;
+ while ((d = readdir(fp)) != 0) {
+ strcpy(name + sizeof(dev), d->d_name);
+ if (stat(name, &dst) == 0
+ && st.st_dev == dst.st_dev && st.st_ino == dst.st_ino) {
+ closedir(fp);
+ errno = noerr;
+ return name;
+ }
+ }
+ closedir(fp);
+ errno = noerr;
+ return 0;
}