nis-util
1.0.D108
|
00001 // 00002 // nis-util - NIS Administration Utilities 00003 // Copyright (C) 2012 Peter Miller 00004 // 00005 // This program is free software; you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License as published by 00007 // the Free Software Foundation; either version 2 of the License, or (at 00008 // 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 // General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License along 00016 // with this program. If not, see <http://www.gnu.org/licenses/>. 00017 // 00018 00019 #include <lib/ac/assert.h> 00020 00021 #include <lib/output/prefix.h> 00022 00023 00024 output_prefix::~output_prefix() 00025 { 00026 } 00027 00028 00029 output_prefix::output_prefix( 00030 const output::pointer &a_deeper, 00031 const rcstring &a_prefix 00032 ) : 00033 deeper(a_deeper), 00034 prefix(a_prefix), 00035 prefix0(a_prefix.trim_right()) 00036 { 00037 assert(prefix.is_printable()); 00038 } 00039 00040 00041 output_prefix::pointer 00042 output_prefix::create(const output::pointer &a_deeper, const rcstring &a_prefix) 00043 { 00044 return pointer(new output_prefix(a_deeper, a_prefix)); 00045 } 00046 00047 00048 output_prefix::output_prefix( 00049 const output::pointer &a_deeper, 00050 int indent 00051 ) : 00052 deeper(a_deeper), 00053 prefix(rcstring::spaces(indent > 0 ? indent : 0)), 00054 prefix0() 00055 { 00056 } 00057 00058 00059 output_prefix::pointer 00060 output_prefix::create(const output::pointer &a_deeper, int a_indent) 00061 { 00062 return pointer(new output_prefix(a_deeper, a_indent)); 00063 } 00064 00065 00066 void 00067 output_prefix::put(char c) 00068 { 00069 if (get_column() == 0) 00070 { 00071 if (c == '\n') 00072 deeper->put(prefix0); 00073 else 00074 deeper->put(prefix); 00075 } 00076 deeper->put(c); 00077 } 00078 00079 00080 int 00081 output_prefix::get_column(void) 00082 const 00083 { 00084 int n = deeper->get_column(); 00085 n -= prefix.size(); 00086 return (n < 0 ? 0 : n); 00087 } 00088 00089 00090 int 00091 output_prefix::get_line_width(void) 00092 const 00093 { 00094 int n = deeper->get_line_width(); 00095 n -= prefix.size(); 00096 return (n < 10 ? 10 : n); 00097 } 00098 00099 00100 // vim: set ts=8 sw=4 et :