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/output.h> 00020 #include <lib/space/automap/row/simple.h> 00021 00022 00023 space_automap_row_simple::~space_automap_row_simple() 00024 { 00025 } 00026 00027 00028 space_automap_row_simple::space_automap_row_simple( 00029 const mount_point &a_mount_point, 00030 const rcstring &a_options, 00031 const locations_t &a_locations 00032 ) : 00033 space_automap_row(a_mount_point, a_options), 00034 locations(a_locations) 00035 { 00036 } 00037 00038 00039 space_automap_row_simple::pointer 00040 space_automap_row_simple::create(const mount_point &a_mount_point, 00041 const rcstring &a_options, const locations_t &a_locations) 00042 { 00043 return 00044 pointer 00045 ( 00046 new space_automap_row_simple 00047 ( 00048 a_mount_point, 00049 a_options, 00050 a_locations 00051 ) 00052 ); 00053 } 00054 00055 00056 void 00057 space_automap_row_simple::print(const output::pointer &op) 00058 const 00059 { 00060 op->put(get_mount_point().get_mount_point()); 00061 bool multi_line = false; 00062 if (!get_options().empty()) 00063 { 00064 int c = op->get_column(); 00065 c = (c < 8 ? 8 : c + 1); 00066 if (c + 1 + int(get_options().size()) > op->get_line_width()) 00067 { 00068 multi_line = true; 00069 op->put(" \\\n"); 00070 } 00071 op->indent_to(8); 00072 op->put(get_options()); 00073 } 00074 00075 // Will all the locations fit on the current line? 00076 if (!multi_line) 00077 { 00078 int w = 0; 00079 for 00080 ( 00081 locations_t::const_iterator it = locations.begin(); 00082 it != locations.end(); 00083 ++it 00084 ) 00085 { 00086 ++w; 00087 w += it->size(); 00088 } 00089 00090 int c = op->get_column(); 00091 c = (c < 16 ? 16 : c + 1); 00092 multi_line = (c + 1 + int(get_options().size()) > op->get_line_width()); 00093 } 00094 00095 if (!multi_line) 00096 { 00097 // print them all on the one line 00098 op->indent_to(15); 00099 for 00100 ( 00101 locations_t::const_iterator it = locations.begin(); 00102 it != locations.end(); 00103 ++it 00104 ) 00105 { 00106 op->put(' '); 00107 op->put(*it); 00108 } 00109 } 00110 else 00111 { 00112 // print each on a separate line 00113 for 00114 ( 00115 locations_t::const_iterator it = locations.begin(); 00116 it != locations.end(); 00117 ++it 00118 ) 00119 { 00120 op->put(" \\\n"); 00121 op->indent_to(16); 00122 op->put(*it); 00123 } 00124 } 00125 op->put('\n'); 00126 } 00127 00128 00129 space_automap_row::pointer 00130 space_automap_row_simple::repath(const mount_point &stem) 00131 const 00132 { 00133 return create(stem + get_mount_point(), get_options(), locations); 00134 } 00135 00136 00137 // vim: set ts=8 sw=4 et :