greenstone.org greenstone wiki greenstone trac planet greenstone

Changeset 17783

Show
Ignore:
Timestamp:
2008-11-07 13:41:18 (2 months ago)
Author:
ak19
Message:

1. When a collection's txt.gz version of its database produced on a Windows machine is brought over to a Linux machine, the library server used to break when trying to serve the collection, because the txt2db program would preserve the Windows-specific carriage-return character. Now this is discarded to make the database file generated from the txt.gz db files uniform between operating systems. 2. (Minor changes, defensive programming.) Dr Bainbridge corrected all newlines chars printed out to stderr and stdout to endl as this may produce more consistent results across operating systems.

Files:

Legend:

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

    r15230 r17783  
    4949 
    5050void print_usage (char *program_name) { 
    51   cerr << "usage: " << program_name << " [options] database-name\n\n"
    52   cerr << "options:\n"
    53   cerr << " -append        append to existing database\n\n"
     51  cerr << "usage: " << program_name << " [options] database-name" << endl << endl
     52  cerr << "options:" << endl
     53  cerr << " -append        append to existing database" << endl << endl
    5454} 
    5555 
     
    7777      dbname = argv[2]; 
    7878    } else { 
    79       cerr << argv[1] << " is not a valid option.\n\n"
     79      cerr << argv[1] << " is not a valid option." << endl << endl
    8080      print_usage (argv[0]); 
    8181      exit (0); 
     
    9595#endif 
    9696  if (dbf == NULL) { 
    97     cerr << "couldn't create " << dbname << "\n"
     97    cerr << "couldn't create " << dbname << endl
    9898    exit (0); 
    9999  } 
     
    113113    } 
    114114    if (!cin.eof()) cin.get(c); // skip ] 
    115     while (!cin.eof() && (c == '\n' || c == 'r')) cin.get(c); 
     115    while (!cin.eof() && (c == '\n' || c == '\r')) cin.get(c); 
    116116     
    117117    // look for 70 dashes 
    118118    tmp = ""; 
    119119    while (!cin.eof() && (num_dashes < 70)) { 
    120       if (c == '\n' || c == '\r') { 
     120      if (c == '\n') { 
    121121        tmp.push_back ((unsigned char)c); 
     122        num_dashes = 0;  
     123         
     124      } else if (c == '\r') {  
     125        // Here we are able to process both Windows-specific text files  
     126        // (containing carriage-return, newline) and Linux text files  
     127        // (containing only newline characters) by ignoring the Windows'  
     128        // carriage-return altogether so that we produce a uniform database 
     129        // file from either system's type of text file.  
     130        // If we don't ignore the carriage return here, txt.gz files 
     131        // produced on Windows cause a GS library running on Linux to break. 
    122132        num_dashes = 0; 
    123          
     133 
    124134      } else if (c == '-') { 
    125135        tmp.push_back ((unsigned char)c); 
     
    141151      key_data.dptr = key.getcstr(); 
    142152      if (key_data.dptr == NULL) { 
    143         cerr << "NULL key_data.dptr\n"
     153        cerr << "NULL key_data.dptr" << endl
    144154        exit (0); 
    145155      } 
     
    150160      value_data.dptr = value.getcstr(); 
    151161      if (value_data.dptr == NULL) { 
    152         cerr << "NULL value_data.dptr\n"
     162        cerr << "NULL value_data.dptr" << endl
    153163        exit (0); 
    154164      } 
     
    157167      // store the value 
    158168      if (gdbm_store (dbf, key_data, value_data, GDBM_REPLACE) < 0) { 
    159         cerr << "gdbm_store returned an error\n"
     169        cerr << "gdbm_store returned an error" << endl
    160170        exit (0); 
    161171      }