libexplain
1.4.D001
|
00001 /* 00002 * libexplain - Explain errno values returned by libc functions 00003 * Copyright (C) 2009, 2013 Peter Miller 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU Lesser General Public License as 00007 * published by the Free Software Foundation; either version 3 of the 00008 * License, or (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 * Lesser General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU Lesser General Public License 00016 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00017 */ 00018 00019 #include <libexplain/ac/linux/termios.h> 00020 #ifndef HAVE_LINUX_TERMIOS_H 00021 #include <libexplain/ac/termios.h> 00022 #endif 00023 00024 #include <libexplain/buffer/termio_baud.h> 00025 #include <libexplain/buffer/termio_cflag.h> 00026 #include <libexplain/parse_bits.h> 00027 #include <libexplain/sizeof.h> 00028 00029 00030 void 00031 explain_buffer_termio_cflag(explain_string_buffer_t *sb, int value) 00032 { 00033 static const explain_parse_bits_table_t table[] = 00034 { 00035 { "CSTOPB", CSTOPB }, 00036 { "CREAD", CREAD }, 00037 { "PARENB", PARENB }, 00038 { "PARODD", PARODD }, 00039 { "HUPCL", HUPCL }, 00040 { "CLOCAL", CLOCAL }, 00041 #ifdef CMSPAR 00042 { "CMSPAR", CMSPAR }, 00043 #endif 00044 { "CRTSCTS", CRTSCTS }, 00045 }; 00046 00047 int first = 1; 00048 int n; 00049 00050 #ifdef CBAUD 00051 n = value & CBAUD; 00052 if (n) 00053 { 00054 explain_buffer_termio_baud(sb, n); 00055 first = 0; 00056 value &= ~CBAUD; 00057 } 00058 #endif 00059 00060 #ifdef IBSHIFT 00061 n = (value & CIBAUD) >> IBSHIFT; 00062 if (n) 00063 { 00064 if (!first) 00065 explain_string_buffer_puts(sb, " | "); 00066 explain_string_buffer_putc(sb, '('); 00067 explain_buffer_termio_baud(sb, n); 00068 explain_string_buffer_puts(sb, " << IBSHIFT)"); 00069 first = 0; 00070 value &= ~CIBAUD; 00071 } 00072 #endif 00073 00074 n = value & CSIZE; 00075 if (!first) 00076 explain_string_buffer_puts(sb, " | "); 00077 switch (n) 00078 { 00079 case CS5: 00080 explain_string_buffer_puts(sb, "CS5"); 00081 break; 00082 00083 case CS6: 00084 explain_string_buffer_puts(sb, "CS6"); 00085 break; 00086 00087 case CS7: 00088 explain_string_buffer_puts(sb, "CS7"); 00089 break; 00090 00091 case CS8: 00092 default: 00093 explain_string_buffer_puts(sb, "CS8"); 00094 break; 00095 } 00096 value &= ~CSIZE; 00097 first = 0; 00098 00099 if (!value) 00100 return; 00101 explain_string_buffer_puts(sb, " | "); 00102 explain_parse_bits_print(sb, value, table, SIZEOF(table)); 00103 } 00104 00105 00106 /* vim: set ts=8 sw=4 et : */