From a412f6583a70a4e8cd8c0cf9221a2778dfbf6ce4 Mon Sep 17 00:00:00 2001 From: Nick Patavalis Date: Sat, 10 Feb 2018 10:04:14 +0200 Subject: [PATCH] Type consistency tweaks Better type consistency when returning enums flowcntrl_e and parity_e. See also PR #92. --- picocom.c | 10 +++++++--- term.c | 4 ++-- term.h | 14 ++++++++------ 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/picocom.c b/picocom.c index 7053d71..e512eb4 100644 --- a/picocom.c +++ b/picocom.c @@ -66,6 +66,7 @@ const char *parity_str[] = { [P_ODD] = "odd", [P_MARK] = "mark", [P_SPACE] = "space", + [P_ERROR] = "invalid parity mode", }; /* flow control modes names */ @@ -74,6 +75,7 @@ const char *flow_str[] = { [FC_RTSCTS] = "RTS/CTS", [FC_XONXOFF] = "xon/xoff", [FC_OTHER] = "other", + [FC_ERROR] = "invalid flow control mode", }; /**********************************************************************/ @@ -850,7 +852,7 @@ baud_down (int baud) return nb; } -int +enum flowcntrl_e flow_next (int flow) { switch(flow) { @@ -871,7 +873,7 @@ flow_next (int flow) return flow; } -int +enum parity_e parity_next (int parity) { switch(parity) { @@ -1212,7 +1214,9 @@ int tty_q_push(const char *s, int len) { int do_command (unsigned char c) { - int newbaud, newflow, newparity, newbits, newstopbits; + int newbaud, newbits, newstopbits; + enum flowcntrl_e newflow; + enum parity_e newparity; const char *xfr_cmd; char *fname; unsigned char hexbuf[HEXBUF_SZ]; diff --git a/term.c b/term.c index 610725f..f333642 100644 --- a/term.c +++ b/term.c @@ -942,7 +942,7 @@ term_get_parity (int fd) i = term_find(fd); if ( i < 0 ) { - parity = -1; + parity = P_ERROR; break; } @@ -1155,7 +1155,7 @@ term_get_flowcntrl (int fd) i = term_find(fd); if ( i < 0 ) { - flow = -1; + flow = FC_ERROR; break; } diff --git a/term.h b/term.h index 4175144..09acfe2 100644 --- a/term.h +++ b/term.h @@ -161,6 +161,7 @@ enum term_errno_e { * P_ODD - odd parity * P_MARK - mark parity (parity bit always 1) * P_SPACE - space parity (parity bit always 0) + * P_ERROR - marker to indicate error for functions returning parity_e */ enum parity_e { P_NONE = 0, @@ -168,7 +169,7 @@ enum parity_e { P_ODD, P_MARK, P_SPACE, - P_ERROR = -1 + P_ERROR }; /* @@ -180,13 +181,14 @@ enum parity_e { * FC_RTSCTS - RTS/CTS handshaking, also known as hardware * flow-control. * FC_XONXOFF - xon/xoff flow control. + * FC_ERROR - marker to indicate error for functions returning flowcntrl_e */ enum flowcntrl_e { FC_NONE = 0, FC_RTSCTS, FC_XONXOFF, FC_OTHER, - FC_ERROR = -1 + FC_ERROR }; /* @@ -551,8 +553,8 @@ int term_get_baudrate (int fd, int *ispeed); * Reads and decodes the current parity settings in the * "currtermios" structure of the managed filedes "fd". * - * Returns one of the "enum parity_e" members, or -1 if "fd" does not - * correspond to a managed filedes. + * Returns one of the "enum parity_e" members. Returns P_ERROR if "fd" + * does not correspond to a managed filedes. */ enum parity_e term_get_parity (int fd); @@ -581,8 +583,8 @@ int term_get_stopbits (int fd); * Reads and decodes the current flow-control settings in the * "currtermios" structure of the managed filedes "fd". * - * Returns one of the "enum flowcntrl_e" members, or -1 if "fd" does - * not correspond to a managed filedes. + * Returns one of the "enum flowcntrl_e" members. Returns FC_ERROR if + * "fd" does not correspond to a managed filedes. */ enum flowcntrl_e term_get_flowcntrl (int fd);