Ignore:
Timestamp:
2009-02-06T18:19:44+13:00 (15 years ago)
Author:
davidb
Message:

Support for reindexing a document added

File:
1 edited

Legend:

Unmodified
Added
Removed
  • gsdl/trunk/common-src/src/gdbmedit/txt2db/txt2db.cpp

    r17783 r18469  
    7272  char *dbname;
    7373  int append = 0;
     74  int delkey = 0;
     75
    7476  if (argc == 3) {
    7577    if (strcmp (argv[1], "-append") == 0) {
     
    105107    value = "";
    106108   
    107     // look for [key]\n
     109    // Parse out 'key' from [key]\n
     110
     111    // scan for first occurrence of [
    108112    while (!cin.eof() && c != '[') cin.get(c);
     113
    109114    if (!cin.eof()) cin.get(c); // skip [
     115
     116    // now look for closing ], building up 'key' as we go
    110117    while (!cin.eof() && c != ']') {
    111118      key.push_back ((unsigned char)c);
    112119      cin.get(c);
    113120    }
    114     if (!cin.eof()) cin.get(c); // skip ]
     121
     122    if (!cin.eof()) {
     123      // most likely an eol char, but if '-', then signifies record
     124      // is to be deleted, not added
     125      cin.get(c);
     126      if (c == '-') {   
     127    delkey = 1;
     128      }
     129      else {
     130    delkey = 0;
     131      }
     132    }
    115133    while (!cin.eof() && (c == '\n' || c == '\r')) cin.get(c);
    116134   
     
    155173      }
    156174      key_data.dsize = strlen(key_data.dptr);
     175
     176      if (delkey) {
     177    // delete the given key
     178    if (gdbm_delete(dbf, key_data) < 0) {
     179      cerr << "gdbm_delete returned an error" << endl;
     180    }
     181      }
     182      else {
     183
     184    // add/append
     185
     186    // convert value to a datum datatype
     187    datum value_data;
     188    value_data.dptr = value.getcstr();
     189    if (value_data.dptr == NULL) {
     190      cerr << "NULL value_data.dptr" << endl;
     191      exit (0);
     192    }
     193    value_data.dsize = strlen(value_data.dptr);
    157194     
    158       // convert value to a datum datatype
    159       datum value_data;
    160       value_data.dptr = value.getcstr();
    161       if (value_data.dptr == NULL) {
    162     cerr << "NULL value_data.dptr" << endl;
    163     exit (0);
    164       }
    165       value_data.dsize = strlen(value_data.dptr);
    166      
    167       // store the value
    168       if (gdbm_store (dbf, key_data, value_data, GDBM_REPLACE) < 0) {
    169     cerr << "gdbm_store returned an error" << endl;
    170     exit (0);
    171       }
    172      
     195    // store the value
     196    if (gdbm_store (dbf, key_data, value_data, GDBM_REPLACE) < 0) {
     197      cerr << "gdbm_store returned an error" << endl;
     198      exit (0);
     199    }
     200
     201   
     202    free(value_data.dptr);
     203      }
     204
    173205      free(key_data.dptr);
    174       free(value_data.dptr);
    175206    }
    176207  }
Note: See TracChangeset for help on using the changeset viewer.