lib/config/showvconfig.cc.in
changeset 0 6f7a81934006
equal deleted inserted replaced
-1:000000000000 0:6f7a81934006
       
     1 #include <config.h>
       
     2 #include <limits.h>
       
     3 #include <unistd.h>
       
     4 #include "misc/pwentry.h"
       
     5 #include "vdomain/vdomain.h"
       
     6 #include "configrc.h"
       
     7 #include "fdbuf/fdbuf.h"
       
     8 
       
     9 template<class T>
       
    10 void show_val(const char* name, T value)
       
    11 {
       
    12   fout << name << ": " << value << "\n\n";
       
    13 }
       
    14 
       
    15 void show_uns(const char* name, unsigned value)
       
    16 {
       
    17   fout << name << ": ";
       
    18   if(value == UINT_MAX)
       
    19     fout << "-1\n\n";
       
    20   else
       
    21     fout << value << "\n\n";
       
    22 }
       
    23 
       
    24 void show_list(const char* name, const strlist& value)
       
    25 {
       
    26   if(!value)
       
    27     fout << name << " is empty.\n";
       
    28   else
       
    29     for(mystring_iter iter(value.str()); iter; ++iter)
       
    30       fout << name << ": " << *iter << "\n";
       
    31   fout << "\n";
       
    32 }
       
    33 
       
    34 #define show_dir show_val
       
    35 #define show_str show_val
       
    36 
       
    37 pwentry user;
       
    38 vdomain domain(user);
       
    39 
       
    40 bool go_home()
       
    41 {
       
    42   if(!user.home) {
       
    43     ferr << "showvconfig: Can't determine home directory" << endl;
       
    44     return false;
       
    45   }
       
    46   if(chdir(user.home.c_str()) == -1) {
       
    47     ferr << "showvconfig: Can't change to home directory" << endl;
       
    48     return false;
       
    49   }
       
    50   config = &domain.config;
       
    51   return true;
       
    52 }
       
    53 
       
    54 int main()
       
    55 {
       
    56   if(!go_home())
       
    57     return 1;
       
    58 %%LIST%%
       
    59   return 0;
       
    60 }