"Fossies" - the Fresh Open Source Software Archive

Member "dbtool-1.9.1/dbtool.cc" (15 May 2015, 3209 Bytes) of package /linux/privat/dbtool-1.9.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "dbtool.cc" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 1.9_vs_1.9.1.

    1 /*
    2  * 'dbtool' is a simple but powerful  commandline interface to the
    3  * GNU gdbm system (or, alternatively the Berkeley DB), useful for
    4  * shellscripts which needs a database for data storage.
    5  */
    6 
    7 /*
    8  *
    9  *  This file  is part of the DBTOOL program.
   10  *
   11  *  By  accessing  this software,  DBTOOL, you  are  duly informed
   12  *  of and agree to be  bound  by the  conditions  described below
   13  *  in this notice:
   14  *
   15  *  This software product,  DBTOOL,  is developed by T.v. Dein
   16  *  and  copyrighted  (C)  2001-2015  by  T.v. Dein,  with all
   17  *  rights reserved.
   18  *
   19  *  There  is no charge for DBTOOL software.  You can redistribute
   20  *  it and/or modify it under the terms of the GNU  General Public
   21  *  License, which is incorporated by reference herein.
   22  *
   23  *  DBTOOL is distributed WITHOUT ANY WARRANTY, IMPLIED OR EXPRESS,
   24  *  OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE or that
   25  *  the use of it will not infringe on any third party's intellec-
   26  *  tual property rights.
   27  *
   28  *  You  should  have received a copy of the  GNU  General  Public
   29  *  License  along with DBTOOL.  Copies can also be obtained from:
   30  *
   31  *    http://www.gnu.org/licenses/gpl.txt
   32  *
   33  *  or by writing to:
   34  *
   35  *  Free Software Foundation, Inc.
   36  *  59 Temple Place, Suite 330
   37  *  Boston, MA 02111-1307
   38  *  USA
   39  *
   40  *  Or contact:
   41  *
   42  *   "T.v. Dein" <tlinden@cpan.org>
   43  *
   44  *
   45  */
   46 
   47 #include "platform.h"
   48 #include "dbtool.h"
   49 #include "config.h"
   50 #include "engine.h"
   51 #include "cipher.h"
   52 
   53 Config config;
   54 cipher rijn;
   55 
   56 int main(int argc, char *argv[]) {
   57   config.args(argc, argv);
   58   Engine engine;
   59   string pkg = PACKAGE;
   60 
   61   if(config.parse() != 0) {
   62     cerr << config.usage;
   63     exit(1);
   64   }
   65   else {
   66     switch(config.command) {
   67     case 'i':
   68       /* insert */
   69       if(config.key == "") {
   70     cerr << pkg << ": key required\n";
   71     exit(1);
   72       }
   73       engine.insert();
   74       break;
   75     case 'd':
   76       /* dump */
   77       engine.dump();
   78       break;
   79     case 'I':
   80       engine.from_input();
   81       break;
   82     case 's':
   83       /* select */
   84       if(config.key == "") {
   85     cerr << pkg << ": key required\n";
   86     exit(1);
   87       }
   88       engine.select();
   89       break;
   90     case 'S':
   91       /* regexp select */
   92       if(config.key == "") {
   93     cerr << pkg << ": key (regexp) required\n";
   94     exit(1);
   95       }
   96       engine.regexp();
   97       break;
   98     case 'r':
   99       /* remove */
  100       if(config.key == "") {
  101     cerr << pkg << ": key required\n";
  102     exit(1);
  103       }
  104       engine.remove();
  105       break;
  106     case 'u':
  107       /* update */
  108       if(config.key == "") {
  109     cerr << pkg << ": key required\n";
  110     exit(1);
  111       }
  112       engine.update();
  113       break;
  114     case 'v':
  115       /* version */
  116       cerr << "This is " << pkg << " version " << VERSION << " by T.v. Dein.\n";
  117       exit(1);
  118     case 'h':
  119       /* usage/help */
  120       cerr << config.usage;
  121       exit(1);
  122     }
  123   }
  124   exit(0);
  125 }
  126 
  127 
  128 
  129 string readpass() {
  130   char *pass;
  131   char *envpass;
  132   envpass = getenv(PW_VARNAME);
  133   if(envpass != NULL) {
  134     string pw = envpass;
  135     return pw;
  136   }
  137   else {
  138 #ifdef HAVE_GETPASS
  139     pass = getpass("passphrase: ");
  140     string password = pass;
  141     free(pass);
  142 #else
  143     cout << "passphrase: ";
  144     string password;
  145     cin >> password;
  146 #endif
  147     return password;
  148   }
  149 }
  150 
  151