Changeset 24659


Ignore:
Timestamp:
2011-09-27T12:09:55+13:00 (13 years ago)
Author:
jmt12
Message:

Several small changes to CLI such as new commands

File:
1 edited

Legend:

Unmodified
Added
Removed
  • gs2-extensions/parallel-building/trunk/src/src/gdbmcli-src/gdbmcli.cpp

    r24639 r24659  
    7373
    7474void
    75 printUsage (char *program_name)
     75printUsage ()
    7676{
    7777  cerr << "===== GDBM Command Line Interface v1.0 =====" << endl << endl;
    78   cerr << "usage: " << program_name << " [-removeold] database-name" << endl << endl;
    79   cerr << " -removeold   delete the contents of any existing database with the same name" << endl << endl;
    80   cerr << "Once the program is running enter empty key (\"[]\") to exit." << endl << endl;
    81   cerr << "examples:" << endl;
     78  cerr << "usage: gdbmcli <db path>" << endl << endl;
     79  cerr << "Once the program is running, the first thing it expects is the" << endl;
     80  cerr << "path to the GDBM database to open, after which you can use the" << endl;
     81  cerr << "commands below:" << endl;
    8282  cerr << "  [key]+<newline>value <= adds the pair key:value" << endl;
    8383  cerr << "  [key]<newline>value  <= also adds the pair" << endl;
    8484  cerr << "  [key]-               <= deleted the pair identified by key" << endl;
    8585  cerr << "  [key]?               <= lookup the value for key" << endl;
    86   cerr << "  [*]                  <= retrieve a list of keys" << endl << endl;
     86  cerr << "  [*]                  <= retrieve a list of keys" << endl;
     87  cerr << "  []                   <= exit " << endl << endl;
    8788}
    8889
     
    9091main (int argc, char *argv[])
    9192{
    92   // sanity check
    93   if (argc != 2 && argc != 3)
     93  if (argc != 2)
    9494  {
    95     printUsage(argv[0]);
     95    printUsage();
    9696    exit(0);
    9797  }
    9898
    99   char *dbname;
    100   bool removeold = false;
    101   if (argc == 3)
    102   {
    103     if (strcmp (argv[1], "-removeold") == 0)
    104     {
    105       removeold = true;
    106       dbname = argv[2];
    107     }
    108     else
    109     {
    110       cerr << argv[1] << " is not a valid option." << endl << endl;
    111       printUsage (argv[0]);
    112       exit(0);
    113     }
    114   }
    115   else
    116   {
    117     dbname = argv[1];
    118   }
     99  char *dbname = argv[1];
    119100
    120101  // open the database
    121102  // note that GDBM_FAST is obsolete on newer versions of gdbm
    122103  int read_write = GDBM_WRCREAT | GDBM_FAST;
    123   if (removeold)
    124   {
    125     read_write = GDBM_NEWDB | GDBM_FAST;
    126   }
    127104  int block_size = 0;
    128105#ifdef __WIN32__
     
    181158      }
    182159
     160      if (key == "?")
     161      {
     162        cout << "0.1" << endl;
     163        gdbm_close (dbf);
     164        return 0;
     165      }
     166
    183167      // retrieve the command token
    184168      if (!cin.eof())
Note: See TracChangeset for help on using the changeset viewer.