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/space/automap/functor/afpvol_generator.h> 00020 #include <lib/output/file.h> 00021 #include <lib/rcstring/accumulator.h> 00022 00023 00024 space_automap_functor_afpvol_generator:: 00025 ~space_automap_functor_afpvol_generator() 00026 { 00027 } 00028 00029 00030 space_automap_functor_afpvol_generator::space_automap_functor_afpvol_generator( 00031 const rcstring &filename 00032 ) : 00033 op(output_file::create(filename)) 00034 { 00035 } 00036 00037 00038 static rcstring 00039 mangle(const rcstring &text) 00040 { 00041 rcstring_accumulator acc; 00042 const char *cp = text.c_str(); 00043 bool minus = false; 00044 for (;;) 00045 { 00046 unsigned char c = *cp++; 00047 if (!c) 00048 { 00049 if (acc.empty()) 00050 return "root"; 00051 return acc.mkstr(); 00052 } 00053 if (isalnum(c)) 00054 { 00055 if (minus && !acc.empty()) 00056 acc.push_back('-'); 00057 acc.push_back(c); 00058 minus = false; 00059 } 00060 else 00061 { 00062 minus = true; 00063 } 00064 } 00065 } 00066 00067 00068 void 00069 space_automap_functor_afpvol_generator::walk( 00070 const space_automap_row::pointer &rp) 00071 { 00072 rcstring path = rp->get_mount_point().get_mount_point(); 00073 op->put(path); 00074 op->put(':'); 00075 op->put(mangle(path)); 00076 op->put('\n'); 00077 } 00078 00079 00080 // vim: set ts=8 sw=4 et :