libexplain  1.4.D001
libexplain/buffer/termio_oflag.c
Go to the documentation of this file.
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 
00021 #include <libexplain/buffer/termio_oflag.h>
00022 #include <libexplain/parse_bits.h>
00023 #include <libexplain/sizeof.h>
00024 
00025 
00026 void
00027 explain_buffer_termio_oflag(explain_string_buffer_t *sb, int value)
00028 {
00029     static const explain_parse_bits_table_t table[] =
00030     {
00031         { "OPOST", OPOST },
00032 #ifdef OLCUC
00033         { "OLCUC", OLCUC },
00034 #endif
00035         { "ONLCR", ONLCR },
00036         { "OCRNL", OCRNL },
00037         { "ONOCR", ONOCR },
00038         { "ONLRET", ONLRET },
00039 #ifdef OFILL
00040         { "OFILL", OFILL },
00041 #endif
00042 #ifdef OFDEL
00043         { "OFDEL", OFDEL },
00044 #endif
00045 #ifdef NL1
00046         { "NL1", NL1 },
00047 #endif
00048 #ifdef BS1
00049         { "BS1", BS1 },
00050 #endif
00051 #ifdef VT1
00052         { "VT1", VT1 },
00053 #endif
00054 #ifdef FF1
00055         { "FF1", FF1 },
00056 #endif
00057     };
00058 
00059     int first = 1;
00060 
00061 #ifdef CRDLY
00062     switch (value & CRDLY)
00063     {
00064     default:
00065     case CR0:
00066         break;
00067 
00068     case CR1:
00069         explain_string_buffer_puts(sb, "CR1");
00070         first = 0;
00071         break;
00072 
00073     case CR2:
00074         explain_string_buffer_puts(sb, "CR2");
00075         first = 0;
00076         break;
00077 
00078     case CR3:
00079         explain_string_buffer_puts(sb, "CR3");
00080         first = 0;
00081         break;
00082     }
00083     value &= ~CRDLY;
00084 #endif
00085 
00086 #ifdef TABDLY
00087     switch (value & TABDLY)
00088     {
00089     case TAB0:
00090         value &= ~TABDLY;
00091         break;
00092 
00093 #ifdef TAB1
00094     case TAB1:
00095         if (!first)
00096             explain_string_buffer_puts(sb, " | ");
00097         explain_string_buffer_puts(sb, "TAB1");
00098         first = 0;
00099         value &= ~TABDLY;
00100         break;
00101 #endif
00102 
00103 #ifdef TAB2
00104     case TAB2:
00105         if (!first)
00106             explain_string_buffer_puts(sb, " | ");
00107         explain_string_buffer_puts(sb, "TAB2");
00108         first = 0;
00109         value &= ~TABDLY;
00110         break;
00111 #endif
00112 
00113     case TAB3:
00114         if (!first)
00115             explain_string_buffer_puts(sb, " | ");
00116         explain_string_buffer_puts(sb, "TAB3");
00117         first = 0;
00118         value &= ~TABDLY;
00119         break;
00120 
00121     default:
00122         break;
00123     }
00124 #endif
00125 
00126     if (!value && !first)
00127         return;
00128     if (!first)
00129         explain_string_buffer_puts(sb, " | ");
00130     explain_parse_bits_print(sb, value, table, SIZEOF(table));
00131 }
00132 
00133 
00134 /* vim: set ts=8 sw=4 et : */