Changeset 91 for trunk/gsdl/src/library


Ignore:
Timestamp:
1998-12-30T16:50:37+13:00 (26 years ago)
Author:
rjmcnab
Message:

Changed the directory structure (collect.cfg and site.cfg now reside
in the collection/etc directory). Changed all input to the library
software to be converted from utf-8 to unicode (info database, mg,
and display). Got lib.init to read in collect.cfg and build.cfg and
used the information to read in the macrofiles. Made it check for each
macro file in both the collection directory and then the main directory.

Location:
trunk/gsdl/src/library
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl/src/library/Makefile

    r90 r91  
    2525AR = ar
    2626CC = gcc
    27 CCFLAGS = -O2
     27CCFLAGS = -O2 -g
    2828DEFS = -DNZDL -DQUIET -DSHORT_SUFFIX -DPARADOCNUM -DUSE_FASTCGI
    2929RANLIB = ranlib
  • trunk/gsdl/src/library/browse.cpp

    r61 r91  
    4444    else section = *thissection;
    4545
    46     gdbm.getinfo(section, collection, info);
    47     get_first_section(info.c, child);
    48    
    49     //    return_text += "<br>" + doclink + *thissection + "." + child + "\">" + info.t + "</a>\n";
    50     return_text += "<br>" + doclink + *thissection + "." + child + ".1\">" + info.t + "</a>\n";
     46    gdbm.getinfo(section, info);
     47    get_first_section(info.contents, child);
     48   
     49    //    return_text += "<br>" + doclink + *thissection + "." + child + "\">" + info.title + "</a>\n";
     50    return_text += "<br>" + doclink + *thissection + "." + child +
     51      ".1\">" + info.title + "</a>\n";
    5152    thissection ++;
    5253  }
     
    7677   
    7778    // get previous arrow
    78     if (gdbm.exists(previous, args["c"])) {
     79    if (gdbm.exists(previous)) {
    7980      return_text += "<td><a href=\"_httptext_&d=" + classification + "." + previous;
    8081      return_text += "\">_iconless_</a></td>\n";
     
    8384    // get page ? of ? text
    8485    return_text += "<td align=\"center\">\n";
    85     gdbm.getinfo(booksection, args["c"], info);
    86     if (is_number(info.t)) {
     86    gdbm.getinfo(booksection, info);
     87    if (is_number(info.title)) {
    8788      splitstring(class_string, contents);
    88       gdbm.getinfo(contents.back(), args["c"], topinfo);
    89       if (is_number(topinfo.t))
    90     return_text += "&nbsp;page " + info.t + " of " + topinfo.t + "&nbsp;";
     89      gdbm.getinfo(contents.back(), topinfo);
     90      if (is_number(topinfo.title))
     91    return_text += "&nbsp;page " + info.title + " of " + topinfo.title + "&nbsp;";
    9192      else
    92     return_text += "&nbsp;" + info.t + "&nbsp;";
     93    return_text += "&nbsp;" + info.title + "&nbsp;";
    9394    } else {
    94       return_text += " " + info.t + " ";
     95      return_text += " " + info.title + " ";
    9596    }
    9697    return_text += "</td>\n";
    9798
    9899    // get next arrow
    99     if (gdbm.exists(next, args["c"])) {
     100    if (gdbm.exists(next)) {
    100101      return_text += "<td><a href=\"_httptext_&d=" + classification + "." + next;
    101102      return_text += "\">_iconmore_</a></td>\n";
     
    182183  while (section != end) {
    183184    tab.clear();
    184     gdbm.getinfo(*section, args["c"], info);
     185    gdbm.getinfo(*section, info);
    185186    text_t icontabs;
    186187
     
    188189    icon = "_iconsmalltext_";
    189190    if (is_top_level(*section)) icon = "_iconopenbook_";
    190     else if (!info.c.empty()) icon = "_iconopenfolder_";
     191    else if (!info.contents.empty()) icon = "_iconopenfolder_";
    191192
    192193    // set up pointer
     
    217218      if (args["g"][1] == '0' || is_top_level(*section) ||
    218219      !are_same_chapter(booksection, *section) ||
    219       !info.c.empty()) {
     220      !info.contents.empty()) {
    220221    return_text += doclink + "d=" + classification;
    221222    return_text += "." + *section + "&a=" + pagetype;
     
    228229    return_text += "\">" + icon + "</a></td>";
    229230    return_text += "<td colspan=" + text_t(tabsleft);
    230     return_text += "><_font_>" + info.t + "</font>";
     231    return_text += "><_font_>" + info.title + "</font>";
    231232    return_text += "</td></tr>\n";
    232233   
     
    256257    if (is_book(*thisparent)) get_book(*thisparent, section);
    257258    else section = *thisparent;
    258     gdbm.getinfo(section, args["c"], info);
     259    gdbm.getinfo(section, info);
    259260   
    260261    // set up icon for this parent
     
    289290    return_text += "<td";
    290291    if (colnum > 1) return_text += " colspan=" + text_t(colnum);
    291     return_text += "><_font_>" + info.t;
    292     if (!info.a.empty()) return_text += " by " + info.a;
     292    return_text += "><_font_>" + info.title;
     293    if (!info.author.empty()) return_text += " by " + info.author;
    293294    return_text += "</font>";
    294295    return_text += "</td></tr>\n";
     
    320321    if (is_book(*thissibling)) get_book(*thissibling, section);
    321322    else section = *thissibling;
    322     gdbm.getinfo(section, args["c"], info);
     323    gdbm.getinfo(section, info);
    323324
    324325    // set up icon for this sibling
     
    342343    tab += ">" + thesetabs + pointer + "</td>";
    343344   
    344     if (info.c.empty()) {
     345    if (info.contents.empty()) {
    345346      // sibling is text document
    346347      icon = "_iconsmalltext_";
     
    362363      return_text += "\">" + icon + "</a></td><td";
    363364      if (colnum > 1) return_text += " colspan=" + text_t(colnum);
    364       return_text += "><_font_>" + info.t;
    365       if (!info.a.empty()) return_text += " by " + info.a;
     365      return_text += "><_font_>" + info.title;
     366      if (!info.author.empty()) return_text += " by " + info.author;
    366367      return_text += "</font></td></tr>\n";
    367368    } else {
    368369      // sibling is closed book or folder so clicking
    369370      // it should open contents
    370       get_first_section(info.c, child);
     371      get_first_section(info.contents, child);
    371372     
    372373      // get classification of child if it's a book
     
    393394      return_text += "\">" + icon + "</a></td><td";
    394395      if (colnum > 1) return_text += " colspan=" + text_t(colnum);
    395       return_text += "><_font_>" + info.t;
    396       if (!info.a.empty()) return_text += " by " + info.a;
     396      return_text += "><_font_>" + info.title;
     397      if (!info.author.empty()) return_text += " by " + info.author;
    397398      return_text += "</font></td></tr>\n";
    398399    }
     
    421422 
    422423  // get list of contents for this classification
    423   gdbm.getinfo(classt, collection, info);
    424   if (!info.c.empty()) {
    425     splitstring(info.c, classcontents);
     424  gdbm.getinfo(classt, info);
     425  if (!info.contents.empty()) {
     426    splitstring(info.contents, classcontents);
    426427    vector<text_t>::const_iterator here = classcontents.begin();
    427428    vector<text_t>::const_iterator end = classcontents.end();
    428429
    429430    while (here != end) {
    430       gdbm.getinfo(*here, collection, info);
     431      gdbm.getinfo(*here, info);
    431432     
    432433      if (*here == classification) {
    433     return_text += "<b>" + info.t + "</b>&nbsp;&nbsp;&nbsp;";
     434    return_text += "<b>" + info.title + "</b>&nbsp;&nbsp;&nbsp;";
    434435      } else {
    435     if (!info.c.empty()) {
    436       get_first_section(info.c, firstcontent);
     436    if (!info.contents.empty()) {
     437      get_first_section(info.contents, firstcontent);
    437438      return_text += link + *here + "." + firstcontent + "\">";
    438       return_text += info.t + "</a>&nbsp;&nbsp;&nbsp;";
     439      return_text += info.title + "</a>&nbsp;&nbsp;&nbsp;";
    439440    }
    440441      }
     
    462463
    463464  // get html for previous link if it exists
    464   gdbm.getinfo(previous, collection, info);
    465   if (!info.c.empty()) {
    466     get_first_section(info.c, firstcontent);
     465  gdbm.getinfo(previous, info);
     466  if (!info.contents.empty()) {
     467    get_first_section(info.contents, firstcontent);
    467468    arrows += "<a href=\"_httpbrowse_&d=";
    468469    arrows += previous + "." + firstcontent + "\">";
     
    475476
    476477  // get html for next link if it exists
    477   gdbm.getinfo(next, collection, info);
    478   if (!info.c.empty()) {
    479     get_first_section(info.c, firstcontent);
     478  gdbm.getinfo(next, info);
     479  if (!info.contents.empty()) {
     480    get_first_section(info.contents, firstcontent);
    480481    arrows += "<a href=\"_httpbrowse_&d=";
    481482    arrows += next + "." + firstcontent + "\">";
     
    539540    if (cols > totalcols) totalcols = cols;
    540541
    541     gdbm.getinfo(section, collection, info);
    542     if (!info.c.empty()) {
     542    gdbm.getinfo(section, info);
     543    if (!info.contents.empty()) {
    543544      vector<text_t> temp;
    544       splitstring(info.c, temp);
     545      splitstring(info.contents, temp);
    545546      while (!temp.empty()) {
    546547    sections.push_back(temp.back());
     
    601602  // don't want 'next' arrow pointing to next sibling if current section
    602603  // has children
    603   gdbm.getinfo(booksection, args["c"], info);
    604   if (!info.c.empty()) nextsibling = current_classification;
     604  gdbm.getinfo(booksection, info);
     605  if (!info.contents.empty()) nextsibling = current_classification;
    605606 
    606607  // set up the 'previous' arrow
     
    615616    while (previoussibling.empty()) {
    616617      vector<text_t> parentsiblings;
    617       gdbm.getinfo(sec, args["c"], info); // info on this section
    618       text_t last, parent = info.p;
    619       gdbm.getinfo(parent, args["c"], info); // info on parent
    620       gdbm.getinfo(info.p, args["c"], info); // info on grandparent
    621       splitstring(info.c, parentsiblings); // now have parents siblings
     618      gdbm.getinfo(sec, info); // info on this section
     619      text_t last, parent = info.parent;
     620      gdbm.getinfo(parent, info); // info on parent
     621      gdbm.getinfo(info.parent, info); // info on grandparent
     622      splitstring(info.contents, parentsiblings); // now have parents siblings
    622623     
    623624      vector<text_t>::const_iterator thisuncle = parentsiblings.begin();
     
    639640    text_t prev; // use this in case previoussibling contains classification
    640641    get_book(previoussibling, prev);
    641     gdbm.getinfo(prev, args["c"], info);
    642     while (!info.c.empty()) {
     642    gdbm.getinfo(prev, info);
     643    while (!info.contents.empty()) {
    643644      vector<text_t> contents;
    644       splitstring(info.c, contents);
     645      splitstring(info.contents, contents);
    645646      previoussibling = contents.back();
    646       gdbm.getinfo(previoussibling, args["c"], info);
     647      gdbm.getinfo(previoussibling, info);
    647648    }
    648649   
     
    655656  // if no younger siblings get parents younger siblings
    656657  while (nextsibling.empty()) {
    657     gdbm.getinfo(sec, args["c"], info);
    658     text_t parent = info.p;
    659     gdbm.getinfo(parent, args["c"], info); // parent info
    660     if (!info.p.empty()) {
     658    gdbm.getinfo(sec, info);
     659    text_t parent = info.parent;
     660    gdbm.getinfo(parent, info); // parent info
     661    if (!info.parent.empty()) {
    661662      vector<text_t> parentsiblings;
    662       gdbm.getinfo(info.p, args["c"], info); // grandparent info
    663       splitstring(info.c, parentsiblings); // got parents siblings
     663      gdbm.getinfo(info.parent, info); // grandparent info
     664      splitstring(info.contents, parentsiblings); // got parents siblings
    664665     
    665666      vector<text_t>::iterator thissibling = parentsiblings.begin();
     
    689690    text_t next;
    690691    get_book(nextsibling, next);
    691     gdbm.getinfo(next, args["c"], info);
    692     while (!info.c.empty()) {
    693       get_first_section(info.c, nextsibling);
    694       gdbm.getinfo(nextsibling, args["c"], info);
     692    gdbm.getinfo(next, info);
     693    while (!info.contents.empty()) {
     694      get_first_section(info.contents, nextsibling);
     695      gdbm.getinfo(nextsibling, info);
    695696    }
    696697    if (nextsibling[0] == 'B') nextsibling = classification + "." + nextsibling;
     
    755756    else key = *here;
    756757
    757     gdbm.getinfo(key, collection, info);
     758    gdbm.getinfo(key, info);
    758759    if (classification[0] == 'T') {
    759760     
    760       alphabetize_string_english(info.t);
    761       info.t += ":#:" + *here;
    762       tmparray = string_add(tmparray, &len, info.t.getcstr());
     761      alphabetize_string_english(info.title);
     762      info.title += ":#:" + *here;
     763      tmparray = string_add(tmparray, &len, info.title.getcstr());
    763764
    764765    } else if (classification[0] == 'A') {
    765       alphabetize_string_name(info.a);
    766       info.a += ":#:" + *here;
    767       tmparray = string_add(tmparray, &len, info.a.getcstr());
     766      alphabetize_string_name(info.author);
     767      info.author += ":#:" + *here;
     768      tmparray = string_add(tmparray, &len, info.author.getcstr());
    768769   
    769770    } else {
    770       info.i += ":#:" + *here;
    771       tmparray = string_add(tmparray, &len, info.i.getcstr());
     771      info.date += ":#:" + *here;
     772      tmparray = string_add(tmparray, &len, info.date.getcstr());
    772773    }
    773774    here ++;
  • trunk/gsdl/src/library/cgiwrap.cpp

    r90 r91  
    9090      if (cfgline.size () >= 2) {
    9191    if (cfgline[0] == "gsdlhome") lib->setgsdlhome(cfgline[1]);
    92     else if (cfgline[0] == "macroshome") lib->setmacroshome(cfgline[1]);
    93     else if (cfgline[0] == "gdbmhome") lib->setgdbmhome(cfgline[1]);
    94     else if (cfgline[0] == "indexhome") lib->setindexhome(cfgline[1]);
     92    else if (cfgline[0] == "gdbmdir") lib->setgdbmdir(cfgline[1]);
     93    else if (cfgline[0] == "collectdir") lib->setcollectdir(cfgline[1]);
    9594    else if (cfgline[0] == "httpprefix") lib->sethttpprefix(cfgline[1]);
    9695    else if (cfgline[0] == "gwcgi") lib->setgwcgi(cfgline[1]);
     
    123122
    124123  // read in the site configuration file
    125   // try in the collection directory, then GSDLHOME/etc,
    126   // then in GSDLHOME.
     124  // try in the collection/etc directory, and then GSDLHOME/etc.
    127125  text_t filename = filename_cat (GSDLHOME, "collect");
    128126  filename = filename_cat (filename, lib->get_collection_name());
     127  filename = filename_cat (filename, "etc");
    129128  filename = filename_cat (filename, "site.cfg");
    130129  if (!site_cfg_read (lib, filename, maxrequests)) {
    131     filename = filename_cat (GSDLHOME, "etc/site.cfg");
    132     if (!site_cfg_read (lib, filename, maxrequests)) {
    133       filename = filename_cat (GSDLHOME, "site.cfg");
    134       site_cfg_read (lib, filename, maxrequests);
    135     }
     130    filename = filename_cat (GSDLHOME, "etc");
     131    filename = filename_cat (GSDLHOME, "site.cfg");
     132    site_cfg_read (lib, filename, maxrequests);
    136133  }
    137134
    138135  // initialise the library software
    139   lib->init();
     136  ofstream initout (GSDLHOME "/etc/initout.txt");
     137  lib->init(initout);
     138  initout.close();
    140139 
    141140  // find out whether this is being run as a cgi-script
  • trunk/gsdl/src/library/gdbmclass.cpp

    r66 r91  
    11#include "text_t.h"
    22#include "gdbmclass.h"
     3#include "unitool.h"
     4#include "gsdlunicode.h"
     5#include "fileutil.h"
    36#include <ctype.h>
    47#include <string.h>
     
    3639
    3740void gdbm_info::clear () {
    38   d = 0;     // docnum
    39   t.clear(); // title
    40   p.clear(); // parent
    41   x.clear(); // classification
    42   c.clear(); // contents
    43   j.clear(); // jobnumber
    44   o.clear(); // OID
    45   a.clear(); // author
    46   s.clear(); // source
    47   i.clear(); // date
    48 }
    49 
    50 // checks if key is present in infodb.
    51 // returns 1 on success 0 on failure
    52 int gdbmclass::exists (text_t key, text_t collection) {
    53 
    54   datum key_data;
    55   datum return_data;
    56 
    57   // try to open the database if it's not already open
    58   if (!open_database(collection)) {
    59     if (logout != NULL) (*logout) << "gdbmclass: can't open database\n";
    60     return 0;
    61   }
    62  
    63   // sanity check
    64   if (gdbm_file == NULL) {
    65     if (logout != NULL) (*logout) << "gdbmclass: failed sanity check\n";   
    66     return 0;
    67   }
    68 
    69   char *db_key = key.getcstr();
    70 
    71   if (db_key == NULL) {
    72     if (logout != NULL) (*logout) << "gdbmclass: failed sanity check\n";
    73     return 0;
    74   }
    75 
    76   key_data.dptr = db_key;
    77   key_data.dsize = strlen (db_key);
    78   return_data = gdbm_fetch (gdbm_file, key_data);
    79   delete db_key;
    80   db_key = NULL;
    81 
    82   if (return_data.dptr == NULL) {
    83     if (logout != NULL) {
    84       (*logout) << "gdbmclass: null data pointer\n";
    85       outconvertclass text_t2ascii;
    86       (*logout) << text_t2ascii << "gdbmclass: key was \"" << key << "\"\n";
    87     }
    88     return 0;
    89   }
    90   free (return_data.dptr);
    91   return 1;
     41  docnum = 0;             // 'd'
     42  title.clear();          // 't'
     43  parent.clear();         // 'p'
     44  classification.clear(); // 'x'
     45  contents.clear();       // 'c'
     46  jobnum.clear();         // 'j'
     47  OID.clear();            // 'o'
     48  author.clear();         // 'a'
     49  source.clear();         // 's'
     50  date.clear();           // 'i'
     51}
     52
     53
     54
     55
     56
     57// returns 0 if failed, 1 if opened
     58int gdbmclass::opendatabase (const text_t &filename) {
     59  text_t data_location;
     60  int block_size = 0;
     61 
     62  if (gdbmfile != NULL) {
     63    if (openfile == filename) return 1;
     64    else closedatabase ();
     65  }
     66
     67  openfile = filename;
     68
     69  char *namebuffer = filename.getcstr();
     70  gdbmfile = gdbm_open (namebuffer, block_size, GDBM_READER, 00664, NULL);
     71  delete namebuffer;
     72
     73  if (gdbmfile == NULL && logout != NULL) {
     74    outconvertclass text_t2ascii;
     75    (*logout) << text_t2ascii << "database open failed on: " << filename << "\n";
     76  }
     77
     78  return (gdbmfile != NULL);
     79}
     80
     81
     82void gdbmclass::closedatabase () {
     83  if (gdbmfile == NULL) return;
     84 
     85  gdbm_close (gdbmfile);
     86  gdbmfile = NULL;
     87  openfile.clear();
    9288}
    9389
     
    9692// key and collection aren't references as they might be aliases to
    9793// something in info
    98 int gdbmclass::getinfo (text_t key, text_t collection, gdbm_info &info) {
    99 
     94int gdbmclass::getinfo (text_t key, gdbm_info &info) {
     95  text_t data;
     96
     97  if (!getkeydata (key, data)) return -1;
     98  text_t::iterator here = data.begin ();
     99  text_t::iterator end = data.end ();
     100
     101  text_t ikey, ivalue;
    100102  info.clear (); // reset info
    101  
     103
     104  while (getinfoline(here, end, ikey, ivalue)) {
     105    if (ikey == "d") { info.docnum = ivalue.getint(); }
     106    else if (ikey == "t") { info.title = ivalue; }
     107    else if (ikey == "p") { info.parent = ivalue; }
     108    else if (ikey == "x") { info.classification = ivalue; }
     109    else if (ikey == "c") { info.contents = ivalue; }
     110    else if (ikey == "j") { info.jobnum = ivalue; }
     111    else if (ikey == "o") { info.OID = ivalue; }
     112    else if (ikey == "a") { info.author = ivalue; }
     113    else if (ikey == "s") { info.source = ivalue; }
     114    else if (ikey == "i") { info.date = ivalue; }
     115  }
     116 
     117  return 0;
     118}
     119
     120
     121// returns 1 if the key exists
     122int gdbmclass::exists (text_t key) {
     123  text_t data;
     124  return getkeydata (key, data);
     125}
     126
     127
     128// returns 1 if successful
     129int gdbmclass::getkeydata (text_t key, text_t &data) {
    102130  datum key_data;
    103131  datum return_data;
    104   char ikey[256];
    105   char ivalue[16384];
    106   int pos = 0;
    107 
    108   // try to open the database if it's not already open
    109   if (!open_database(collection)) {
    110     if (logout != NULL) (*logout) << "gdbmclass: can't open database\n";
    111     return -1;
    112   }
    113  
    114   // sanity check
    115   if (gdbm_file == NULL) {
    116     if (logout != NULL) (*logout) << "gdbmclass: failed sanity check\n";   
    117     return -1;
    118   }
    119 
    120   char *db_key = key.getcstr();
    121 
    122   if (db_key == NULL) {
    123     if (logout != NULL) (*logout) << "gdbmclass: failed sanity check\n";
    124     return -1;
    125   }
    126 
    127   key_data.dptr = db_key;
    128   key_data.dsize = strlen (db_key);
    129   return_data = gdbm_fetch (gdbm_file, key_data);
    130   delete db_key;
    131   db_key = NULL;
    132 
    133   if (return_data.dptr == NULL) {
    134     if (logout != NULL) {
    135       (*logout) << "gdbmclass: null data pointer\n";
    136       outconvertclass text_t2ascii;
    137       (*logout) << text_t2ascii << "gdbmclass: key was \"" << key << "\"\n";
    138     }
    139     return -1;
    140   }
    141  
    142   while ((pos = get_infoline(return_data.dptr, return_data.dsize,
    143                  pos, ikey, ivalue)) >= 0) {
    144 
    145     if (strcmp (ikey, "d") == 0) {
    146       info.d = atoi(ivalue);
    147      
    148     } else if (strcmp (ikey, "p") == 0) {
    149       info.p = ivalue;
    150 
    151     } else if (strcmp (ikey, "t") == 0) {
    152       info.t = ivalue;
    153      
    154     } else if (strcmp (ikey, "x") == 0) {
    155       info.x = ivalue;
    156      
    157     } else if (strcmp (ikey, "c") == 0) {
    158       info.c = ivalue;
    159      
    160     } else if (strcmp (ikey, "j") == 0) {
    161       info.j = ivalue;
    162 
    163     } else if (strcmp (ikey, "o") == 0) {
    164       info.o = ivalue;
    165      
    166     } else if (strcmp (ikey, "a") == 0) {
    167       info.a = ivalue;
    168 
    169     } else if (strcmp (ikey, "s") == 0) {
    170       info.s = ivalue;
    171 
    172     } else if (strcmp (ikey, "i") == 0) {
    173       info.i = ivalue;
    174     }
    175   }
    176  
     132
     133  if (gdbmfile == NULL) return 0;
     134
     135  // get a utf-8 encoded c string of the unicode key
     136  key_data.dptr = (to_utf8(key)).getcstr();
     137  if (key_data.dptr == NULL) {
     138    if (logout != NULL) (*logout) << "gdbmclass: out of memory\n";
     139    return 0;
     140  }
     141  key_data.dsize = strlen (key_data.dptr);
     142
     143  // fetch the result
     144  return_data = gdbm_fetch (gdbmfile, key_data);
     145  delete key_data.dptr;
     146
     147  if (return_data.dptr == NULL) return 0;
     148
     149  data.setcarr (return_data.dptr, return_data.dsize);
    177150  free (return_data.dptr);
    178  
    179   return 0;
    180 }
    181 
    182 void gdbmclass::setgdbmhome (const text_t &thegdbmhome)
    183 {
    184   gdbmhome = thegdbmhome;
    185 }
     151  data = to_uni(data);  // convert to unicode
     152
     153  return 1;
     154}
     155
    186156
    187157// parses a line of the form <key>value\n
    188 // returns next position, -1 if there was nothing left to process
    189 // in the string, -2 if there was an error
    190 int gdbmclass::get_infoline (char *str, int len, int pos, char *key, char *value) {
    191   int keylen = 0;
    192   int valuelen = 0;
    193  
    194   key[0] = '\0';
    195   value[0] = '\0';
    196  
     158// returns 1 if successful
     159int gdbmclass::getinfoline (text_t::iterator &here, text_t::iterator end,
     160                text_t &key, text_t &value) {
     161  key.clear();
     162  value.clear();
     163
    197164  // ignore white space
    198   while (pos < len && isspace(str[pos])) pos++;
    199  
     165  while (here != end && is_unicode_space (*here)) here++;
     166
    200167  // get the '<'
    201   if (pos >= len) return -1;
    202   if (str[pos] != '<') return -2;
    203   pos++;
     168  if (here == end || *here != '<') return 0;
     169  here++;
    204170 
    205171  // get the key
    206   while (pos < len && str[pos] != '>')
    207     key[keylen++] = str[pos++];
    208  
    209   key[keylen] = '\0';
     172  while (here != end && *here != '>') {
     173    key.push_back(*here);
     174    here++;
     175  }
    210176 
    211177  // get the '>'
    212   if (pos >= len || str[pos] != '>') return -2;
    213   pos++;
     178  if (here == end || *here != '>') return 0;
     179  here++;
    214180 
    215181  // get the value
    216   while (pos < len && str[pos] != '\n')
    217     value[valuelen++] = str[pos++];
    218  
    219   value[valuelen] = '\0';
    220  
    221   return pos;
    222 }
    223 
    224 
    225 // returns 0 if failed, 1 if opened
    226 int gdbmclass::open_database (const text_t &collection) {
    227   text_t data_location, text_dir;
    228   int block_size = 0;
    229  
    230   if (gdbm_file != NULL) {
    231     if (collection != gdbm_open_name) {
    232       close_database();
    233     }
    234   }
    235   if (gdbm_file == NULL) {
    236     gdbm_open_name = collection;
    237     gettextsuffix (collection, text_dir);
    238 
    239 #ifdef __WIN32__
    240     data_location = gdbmhome + text_dir;
    241 #else
    242     data_location = gdbmhome + text_dir;
    243 #endif
    244        
    245 #ifdef _LITTLE_ENDIAN
    246     data_location += ".ldb"; // little endian version of the gdbm database
    247 #else
    248     data_location += ".bdb"; // big endian version on the gdbm database
    249 #endif
    250     char *namebuffer = data_location.getcstr();
    251     //    cerr << "database name: " << namebuffer << "\n";
    252 
    253     gdbm_file = gdbm_open (namebuffer, block_size, GDBM_READER, 00664, NULL);
    254     delete namebuffer;
    255   }
    256   return (gdbm_file != NULL);
    257 }
    258 
    259 
    260 void gdbmclass::close_database () {
    261  
    262   if (gdbm_file == NULL) return;
    263  
    264   gdbm_close (gdbm_file);
    265   gdbm_file = NULL;
    266 }
     182  while (here != end && *here != '\n') {
     183    value.push_back(*here);
     184    here++;
     185  }
     186
     187  return 1;
     188}
     189
     190
    267191
    268192
     
    420344    vector<text_t> classarray;
    421345    get_book_top (targetdoc, book_top);
    422     gdbm.getinfo(book_top, collection, info);
    423     splitstring (info.x, classarray);
     346    gdbm.getinfo(book_top, info);
     347    splitstring (info.classification, classarray);
    424348    if (!classarray.empty()) classification = classarray[0];
    425349    else classification = "C.1";
     
    513437  } else if (booksection.empty()) {
    514438    // get classification siblings
    515     gdbm.getinfo(classification, collection, info);
    516     gdbm.getinfo(info.p, collection, info); // info is now parent info
    517     splitstring(info.c, siblings);
     439    gdbm.getinfo(classification, info);
     440    gdbm.getinfo(info.parent, info); // info is now parent info
     441    splitstring(info.contents, siblings);
    518442    return;
    519443
     
    522446    if (is_top_level(booksection)) {
    523447      // top level of book so siblings are children of classification
    524       gdbm.getinfo(classification, collection, info);
    525       splitstring(info.c, siblings);
     448      gdbm.getinfo(classification, info);
     449      splitstring(info.contents, siblings);
    526450
    527451      // add classifications to book sections
     
    532456    } else {
    533457      // siblings come from immediate parent
    534       gdbm.getinfo(booksection, collection, info);
    535       gdbm.getinfo(info.p, collection, info); // info is now parent info
    536       splitstring(info.c, siblings);
     458      gdbm.getinfo(booksection, info);
     459      gdbm.getinfo(info.parent, info); // info is now parent info
     460      splitstring(info.contents, siblings);
    537461
    538462      // add classifications to book sections
  • trunk/gsdl/src/library/gdbmclass.h

    r43 r91  
    1212#endif
    1313
    14 #include "locateinfo.h"
    1514
    16 
    17 class gdbm_info
    18 {
     15class gdbm_info {
    1916public:
    20   int docnum;
    21   int d;
    22   text_t t;
    23   text_t p;
    24   text_t x;
    25   text_t c;
    26   text_t j;
    27   text_t o;
    28   text_t a;
    29   text_t s;
    30   text_t i;
     17  int docnum;            // 'd'
     18  text_t title;          // 't'
     19  text_t parent;         // 'p'
     20  text_t classification; // 'x'
     21  text_t contents;       // 'c'
     22  text_t jobnum;         // 'j'
     23  text_t OID;            // 'o'
     24  text_t author;         // 'a'
     25  text_t source;         // 's'
     26  text_t date;           // 'i'
    3127
    3228  void clear ();
     
    3430
    3531
    36 class gdbmclass
    37 {
     32class gdbmclass {
    3833public:
    39   gdbmclass() {gdbm_file = NULL; logout = &cerr;};
     34  gdbmclass() {gdbmfile = NULL; logout = &cerr;};
    4035  ~gdbmclass() {};
    4136 
     37  // returns 0 if failed, 1 if opened
     38  int opendatabase (const text_t &filename);
     39  void closedatabase ();
     40
    4241  // returns 0 on success, -1 on failure
    43   int getinfo (text_t key, text_t collection, gdbm_info &info);
    44   void setgdbmhome (const text_t &thegdbmhome);
     42  int getinfo (text_t key, gdbm_info &info);
    4543  void setlogout (ostream *thelogout) {logout = thelogout;}
    46   int exists (text_t key, text_t collection);
     44  int exists (text_t key);
    4745
    4846protected:
    49   text_t gdbmhome; // top level directory for gdbm files
    50   GDBM_FILE gdbm_file;
    51   text_t gdbm_open_name;
     47  text_t openfile;
     48  GDBM_FILE gdbmfile;
    5249  ostream *logout;
    5350 
    54   int open_database (const text_t &collection);
    55   void close_database ();
    56  
    57   int get_infoline (char *str, int len, int pos, char *key, char *value);
     51  int getkeydata (text_t key, text_t &data);
     52  int getinfoline (text_t::iterator &here, text_t::iterator end,
     53           text_t &key, text_t &value);
    5854};
    5955
  • trunk/gsdl/src/library/libinterface.cpp

    r67 r91  
    66#include "libinterface.h"
    77#include "cgiargs.h"
     8#include "fileutil.h"
     9#include "cfgread.h"
    810
    911#include <assert.h>
     
    142144// constructor
    143145
    144 libinterface::libinterface()
    145 {
     146libinterface::libinterface() {
    146147  browse = NULL;
    147148}
    148149
    149 void libinterface::setgsdlhome (const text_t &thegsdlhome)
    150 {
     150void libinterface::setgsdlhome (const text_t &thegsdlhome) {
     151  text_t thecollectdir, thegdbmdir, filename;
     152
    151153  gsdlhome = thegsdlhome;
    152   setmacroshome (thegsdlhome);
    153   setgdbmhome (thegsdlhome);
    154   setindexhome (thegsdlhome);
    155 }
    156 
    157 void libinterface::setmacroshome (const text_t &themacroshome)
    158 {
    159   macroshome = themacroshome;
    160 }
    161 
    162 void libinterface::setgdbmhome (const text_t &thegdbmhome)
    163 {
    164   gdbmhome = thegdbmhome;
    165   gdbm.setgdbmhome(gdbmhome);
    166 }
    167 
    168 void libinterface::setindexhome (const text_t &theindexhome)
    169 {
    170   indexhome = theindexhome;
    171   search.setindexhome(theindexhome);
    172 }
    173 
    174 void libinterface::sethttpprefix (const text_t &thehttpprefix)
    175 {
     154
     155  // search for etc/collect.cfg
     156  thecollectdir = filename_cat (gsdlhome, "collect");
     157  thecollectdir = filename_cat (thecollectdir, get_collection_name());
     158  filename = filename_cat (thecollectdir, "etc");
     159  filename = filename_cat (filename, "config.cfg");
     160  if (!file_exists(filename)) thecollectdir = gsdlhome;
     161
     162  thegdbmdir = filename_cat (thecollectdir, "index");
     163  thegdbmdir = filename_cat (thegdbmdir, "text");
     164
     165  setcollectdir (thecollectdir);
     166  setgdbmdir (thegdbmdir);
     167}
     168
     169void libinterface::setcollectdir (const text_t &thecollectdir) {
     170  collectdir = thecollectdir;
     171
     172  search.setcollectdir (collectdir);
     173}
     174
     175void libinterface::setgdbmdir (const text_t &thegdbmdir) {
     176  gdbmdir = thegdbmdir;
     177}
     178
     179void libinterface::sethttpprefix (const text_t &thehttpprefix) {
    176180  httpprefix = thehttpprefix;
    177181}
    178182
    179 void libinterface::setgwcgi (const text_t &thegwcgi)
    180 {
     183void libinterface::setgwcgi (const text_t &thegwcgi) {
    181184  gwcgi = thegwcgi;
    182185}
     186
     187
     188int libinterface::cfg_read (const text_t &filename) {
     189  text_t key;
     190  text_tarray cfgline;
     191  char *cstr = filename.getcstr();
     192  ifstream confin (cstr);
     193  delete cstr;
     194
     195  if (confin) {
     196    while (read_cfg_line(confin, cfgline) >= 0) {
     197      if (cfgline.size () >= 2) {
     198    key = cfgline[0];
     199    cfgline.erase(cfgline.begin());
     200    if (key == "maintainer")        cfg_info.maintainer = cfgline[0];
     201    else if (key == "indexes")      cfg_info.indexes = cfgline;
     202    else if (key == "defaultindex") cfg_info.defaultindex = cfgline[0];
     203    else if (key == "macrofiles")   cfg_info.macrofiles = cfgline;
     204    else if (key == "builddate")    cfg_info.builddate = cfgline[0];
     205    else if (key == "indexmap")     cfg_info.indexmap = cfgline;
     206    else if (key == "numbytes")     cfg_info.numbytes = (double)cfgline[0].getint();
     207    else if (key == "numdocs")      cfg_info.numdocs = (double)cfgline[0].getint();
     208      }
     209    }
     210    confin.close ();
     211    return 1;
     212  }
     213  return 0;
     214}
     215
    183216
    184217// init should be called after the various homes are set,
    185218// it returns 'false' on failure and 'true' on success
    186 bool libinterface::init ()
    187 {
     219bool libinterface::init (ostream &logout) {
     220  text_t collection = get_collection_name();
     221
     222  // redirect the error output to logout
     223  disp.setlogout (&logout);
     224  gdbm.setlogout (&logout);
     225
     226  // open the gdbm file
     227  text_t filename = filename_cat (gdbmdir, get_collection_name ());
     228#ifdef _LITTLE_ENDIAN
     229  filename += ".ldb"; // little endian version of the gdbm database
     230#else
     231  filename += ".bdb"; // big endian version on the gdbm database
     232#endif
     233  gdbm.opendatabase (filename);
     234
     235  // read in the configuration files etc/collect.cfg and index/build.cfg
     236  // entries in build.cfg should override those in collect.cfg
     237  filename = filename_cat (collectdir, "etc");
     238  filename = filename_cat (filename, "collect.cfg");
     239  cfg_read(filename);
     240  filename = filename_cat (collectdir, "index");
     241  filename = filename_cat (filename, "build.cfg");
     242  cfg_read(filename);
     243
     244  //  logout << text_t2ascii << "defaultindex: " << cfg_info.defaultindex << "\n";
     245
    188246  set_default_index();
    189   text_t collection = get_collection_name();
    190 
    191   // load up default macro files -- these shouldn't have absolute file names
    192 #ifdef __WIN32__
    193   disp.loaddefaultmacros(macroshome + "\\macros\\base.dm");
    194   disp.loaddefaultmacros(macroshome + "\\macros\\browse.dm");
    195   disp.loaddefaultmacros(macroshome + "\\macros\\text.dm");
    196   disp.loaddefaultmacros(macroshome + "\\macros\\query.dm");
    197   disp.loaddefaultmacros(macroshome + "\\macros\\help.dm");
    198   disp.loaddefaultmacros(macroshome + "\\macros\\gsdl.dm");
    199   disp.loaddefaultmacros(macroshome + "\\macros\\pref.dm");
    200 #else
    201   disp.loaddefaultmacros(macroshome + "/macros/base.dm");
    202   disp.loaddefaultmacros(macroshome + "/macros/browse.dm");
    203   disp.loaddefaultmacros(macroshome + "/macros/text.dm");
    204   disp.loaddefaultmacros(macroshome + "/macros/query.dm");
    205   disp.loaddefaultmacros(macroshome + "/macros/help.dm");
    206   disp.loaddefaultmacros(macroshome + "/macros/gsdl.dm");
    207   disp.loaddefaultmacros(macroshome + "/macros/pref.dm");
    208 #endif
     247
     248
     249  // load up the default macro files, the collection directory
     250  // is searched first for the file and then the main directory
     251  text_t colmacrodir = filename_cat (collectdir, "macros");
     252  text_t gsdlmacrodir = filename_cat (gsdlhome, "macros");
     253  text_tarray::iterator arrhere = cfg_info.macrofiles.begin();
     254  text_tarray::iterator arrend = cfg_info.macrofiles.end();
     255  while (arrhere != arrend) {
     256    filename = filename_cat (colmacrodir, *arrhere);
     257    if (!file_exists (filename)) {
     258      filename = filename_cat (gsdlmacrodir, *arrhere);
     259    }
     260    disp.loaddefaultmacros(filename);
     261    arrhere++;
     262  }
    209263
    210264  srand(time(NULL));
     
    222276  int err = LI_NOERROR;
    223277
    224   gdbm.setlogout (&logout); // make the output go where they want!
     278  // make the output go where they want!
     279  gdbm.setlogout (&logout);
     280  disp.setlogout (&logout);
    225281
    226282  cgiargsclass args;
     
    725781    if (args["d"][0] != 'B') get_book(args["d"], docref);
    726782    else docref = args["d"];
    727     if (gdbm.getinfo(docref, queryparams.collection, info) != 0) {
     783    if (gdbm.getinfo(docref, info) != 0) {
    728784      logout << text_t2ascii << "info_db wasn't opened - " << docref << "\n";
    729785      return;
     
    731787   
    732788    // get document text if there is any
    733     if (info.c.empty()) {
     789    if (info.contents.empty()) {
    734790        search.docTargetDocument(default_index, queryparams.collection,
    735                  info.d, content);
    736     if (info.t != "<i>(introductory text)</i>")
    737       content = "<h3>" + info.t + "</h3>\n" + content;
     791                 info.docnum, content);
     792    if (info.title != "<i>(introductory text)</i>")
     793      content = "<h3>" + info.title + "</h3>\n" + content;
    738794    }
    739795  }
     
    761817
    762818      // get docnum from gdbm
    763       if (gdbm.getinfo(*thiscontent, queryparams.collection, info) != 0) {
     819      if (gdbm.getinfo(*thiscontent, info) != 0) {
    764820    logout << text_t2ascii << "info_db wasn't opened - " << args["d"] << "\n";
    765821    return;
     
    767823
    768824      // if section has text get it, otherwise output section title
    769       if (info.c.empty()) {
     825      if (info.contents.empty()) {
    770826
    771827    // output <a name= > tags for all text sections currently displayed in toc (all text sections
     
    779835
    780836    search.docTargetDocument(default_index, queryparams.collection,
    781                  info.d, text);                 
    782     if (info.t != "<i>(introductory text)</i>")
    783       content += "<h3>" + info.t + "</h3>\n";
     837                 info.docnum, text);                   
     838    if (info.title != "<i>(introductory text)</i>")
     839      content += "<h3>" + info.title + "</h3>\n";
    784840    //  content += text + "<hr><br>\n";
    785841    content += text + "<p>\n"; // no longer want <hr> between sections
    786842      } else {
    787     content += "<h3>" + info.t + "</h3>\n";
     843    content += "<h3>" + info.title + "</h3>\n";
    788844      }
    789845
     
    820876      if (args["d"][0] != 'B') get_book(args["d"], docref);
    821877      else docref = args["d"];
    822       if (gdbm.getinfo(docref, queryparams.collection, info) != 0) {
     878      if (gdbm.getinfo(docref, info) != 0) {
    823879        logout << text_t2ascii << "info_db wasn't opened - " << docref << "\n";
    824880        return;
     
    826882   
    827883      // get document text if there is any
    828       if (info.c.empty()) {
     884      if (info.contents.empty()) {
    829885        search.docTargetDocument(default_index, queryparams.collection,
    830                                  info.d, content);
    831     if (info.t != "<i>(introductory text)</i>")
    832       content = "<h3>" + info.t + "</h3>\n" + content;
     886                                 info.docnum, content);
     887    if (info.title != "<i>(introductory text)</i>")
     888      content = "<h3>" + info.title + "</h3>\n" + content;
    833889      }
    834890    }
  • trunk/gsdl/src/library/libinterface.h

    r89 r91  
    3030
    3131
     32class cfg_info_t {
     33public:
     34  cfg_info_t () {numbytes=0.0; numdocs=0.0;};
    3235
    33 class libinterface
    34 {
     36  text_t      maintainer;
     37  text_tarray indexes;
     38  text_t      defaultindex;
     39  text_tarray macrofiles;
     40  text_t      builddate;
     41  text_tarray indexmap;
     42  double      numbytes;
     43  double      numdocs;
     44};
     45
     46
     47class libinterface {
    3548public:
    3649  libinterface ();
    3750  virtual ~libinterface() {}
    3851
    39   // setgsdlhome will set the macros, gdbm, index, and text homes
     52  // setgsdlhome will search for etc/collect.cfg and
     53  // set collectdir and gdbmdir
    4054  void setgsdlhome (const text_t &thegsdlhome);
    4155
    42   void setmacroshome (const text_t &themacroshome);
    43   void setgdbmhome (const text_t &thegdbmhome);
    44   void setindexhome (const text_t &theindexhome);
     56  // collectdir contains etc/collect.cfg, archives,
     57  // index, and maybe a macros directory
     58  void setcollectdir (const text_t &thecollectdir);
     59  void setgdbmdir (const text_t &thegdbmdir);
    4560
    4661  void sethttpprefix (const text_t &thehttpprefix);
     
    4964  // init should be called after the various homes are set,
    5065  // it returns 'false' on failure and 'true' on success
    51   bool init ();
     66  bool init (ostream &logout);
    5267 
    5368  // examine the cgi arguments and create the appropriate page,
     
    6580
    6681protected:
     82  cfg_info_t cfg_info;
     83
    6784  text_t gsdlhome;
    68   text_t macroshome;
    69   text_t gdbmhome;
    70   text_t indexhome;
     85  text_t gdbmdir;
     86  text_t collectdir;
    7187
    7288  text_t books;
     
    94110  mgsearchclass search;
    95111 
     112  int cfg_read (const text_t &filename);
     113
    96114  virtual void get_arg_config (text_t &argconfigstr);
    97115  text_t::iterator get_next_config_arg (text_t::iterator first, text_t::iterator last,
     
    129147  virtual void highlighttext(vector<text_t> &termvars, ostream &textout,
    130148                 ostream &logout, text_t &text);
    131   void libinterface::format_querystring (text_t &querystring);
     149  void format_querystring (text_t &querystring);
    132150
    133151
     
    139157  virtual void displaydocsummary (cgiargsclass &args, ostream &textout,
    140158                                  ostream &logout, queryresultsclass &queryresults,
    141                                   int resultnum) {}
     159                  int resultnum) {}
    142160
    143161
  • trunk/gsdl/src/library/locateinfo.cpp

    r32 r91  
    11#include "locateinfo.h"
     2#include "fileutil.h"
    23
    3 void getindexsuffix (const text_t &index,
    4              const text_t &collection,
    5              text_t &ttidxsuffix)
    6 {
    7 
    8   // new directory structure
    9   //  ttidxsuffix = "collect";
    10 
    11   //#ifdef __WIN32__
    12   //ttidxsuffix += "\\";
    13   //#else
    14   //ttidxsuffix += "/";
    15   //#endif
    16 
    17   //ttidxsuffix += collection;
    18 
    19 
    20 #ifdef __WIN32__
    21   ttidxsuffix += "\\index\\";
    22 #else
    23   ttidxsuffix += "/index/";
    24 #endif
    25 
    26 //           ttidxsuffix += collection; //this changed with new build software
    27   ttidxsuffix += index;
    28 #ifdef __WIN32__
    29   ttidxsuffix += "\\";
    30 #else
    31   ttidxsuffix += "/";
    32 #endif
    33   ttidxsuffix += collection;
     4text_t getindexsuffix (const text_t &collection,
     5               const text_t &index) {
     6  text_t indexsuffix = "index";
     7  indexsuffix = filename_cat (indexsuffix, index);
     8  indexsuffix = filename_cat (indexsuffix, collection);
     9  return indexsuffix;
    3410}
    3511
    36 void gettextsuffix (const text_t &collection,
    37             text_t &tttxtsuffix)
    38 {
    39   // new directory structure
    40   //  tttxtsuffix = "collect";
    41 
    42   //#ifdef __WIN32__
    43   //tttxtsuffix += "\\";
    44   //#else
    45   //tttxtsuffix += "/";
    46   //#endif
    47 
    48   //tttxtsuffix += collection;
    49 
    50 #ifdef __WIN32__
    51   tttxtsuffix += "\\index\\";
    52 #else
    53   tttxtsuffix += "/index/";
    54 #endif
    55 
    56 //                tttxtsuffix += collection; // path changed with new building software - Stefan.
    57   tttxtsuffix += "text";
    58 #ifdef __WIN32__
    59   tttxtsuffix += "\\";
    60 #else
    61   tttxtsuffix += "/";
    62 #endif
    63   tttxtsuffix += collection;
     12text_t gettextsuffix (const text_t &collection) {
     13  text_t textsuffix = "index";
     14  textsuffix = filename_cat (textsuffix, "text");
     15  textsuffix = filename_cat (textsuffix, collection);
     16  return textsuffix;
    6417}
  • trunk/gsdl/src/library/locateinfo.h

    r4 r91  
    44#include "text_t.h"
    55
    6 void getindexsuffix (const text_t &index,
    7              const text_t &collection,
    8              text_t &ttidxsuffix);
     6text_t getindexsuffix (const text_t &collection,
     7               const text_t &index);
    98
    10 void gettextsuffix (const text_t &collection,
    11             text_t &tttxtsuffix);
     9text_t gettextsuffix (const text_t &collection);
    1210
    1311#endif
  • trunk/gsdl/src/library/mgsearch.cpp

    r32 r91  
    2727#include "mgsearch.h"
    2828#include "locateinfo.h"
     29#include "gsdlunicode.h"
     30#include "unitool.h"
     31
    2932
    3033/////////////
     
    8285          float Weight, void *info) {
    8386
     87  // convert term from utf8 to unicode
     88  text_t term;
     89  utf8inconvertclass inconvert;
     90  convertclass::status_t status;
     91  inconvert.reset ();
     92  inconvert.setinput (Word, ULen);
     93  inconvert.convert (term, status);
     94
    8495  queryresultsclass *queryresults = (queryresultsclass *)info;
    85   queryresults->termvariants.push_back(Word);
     96  queryresults->termvariants.push_back(term);
    8697
    8798  return 0;
     
    93104  text_t *output = (text_t *)info;
    94105  if (output == NULL) return 0;
    95 
    96   output->setcarr(Word, ULen);
     106  output->clear();
     107
     108  utf8inconvertclass inconvert;
     109  convertclass::status_t status;
     110  inconvert.reset ();
     111  inconvert.setinput (Word, ULen);
     112  inconvert.convert (*output, status);
    97113 
    98114  // replace all control-Cs with spaces
    99115  text_t::iterator here = output->begin();
    100116  text_t::iterator end = output->end();
    101   while (here != end)
    102     {
    103       if (*here == '\x3') *here = ' ';
    104       here++;
    105     }
     117  while (here != end) {
     118    if (*here == '\x3') *here = ' ';
     119    here++;
     120  }
    106121 
    107122  return 0;
     
    129144
    130145
    131 void mgsearchclass::setindexhome (const text_t &theindexhome)
    132 {
    133   indexhome = theindexhome;
     146void mgsearchclass::setcollectdir (const text_t &thecollectdir)
     147{
     148  collectdir = thecollectdir;
    134149}
    135150
    136151
    137152bool mgsearchclass::search(const queryparamclass &queryparams,
    138               queryresultsclass &queryresults)
     153               queryresultsclass &queryresults)
    139154{
    140155  bool databaseloaded = true;
     
    146161  // first check the cache
    147162  if (cache->find(queryparams, queryresults))
    148     {
    149       return true;
    150     }
     163    return true;
    151164
    152165  // make sure there is a query to be processed
     
    154167  text_t::const_iterator queryend = queryparams.querystring.end();
    155168  while (queryhere != queryend) {
    156     if (((*queryhere >= 65) && (*queryhere <= 90)) ||
    157       ((*queryhere >= 97) && (*queryhere <= 122)) ||
    158       ((*queryhere >= 192) && (*queryhere <= 214)) ||
    159       ((*queryhere >= 216) && (*queryhere <= 246)) ||
    160       ((*queryhere >= 248) && (*queryhere <= 255)) ||
    161       ((*queryhere >= '0') && (*queryhere <= '9'))) break;
     169    if (is_unicode_letdig (*queryhere)) break;
    162170    queryhere++;
    163171  }
     
    169177
    170178
    171 
    172179  // get the names of the index and text suffixes
    173   text_t ttidxsuffix, tttxtsuffix;
    174   getindexsuffix (queryparams.search_index,
    175           queryparams.collection, ttidxsuffix);
    176   gettextsuffix (queryparams.collection, tttxtsuffix);
    177   char *idxsuffix = ttidxsuffix.getcstr(); assert (idxsuffix != NULL);
    178   char *txtsuffix = tttxtsuffix.getcstr(); assert (txtsuffix != NULL);
     180  char *idxsuffix = (getindexsuffix (queryparams.collection,
     181                     queryparams.search_index)).getcstr();
     182  assert (idxsuffix != NULL);
     183  char *txtsuffix = (gettextsuffix (queryparams.collection)).getcstr();
     184  assert (txtsuffix != NULL);
    179185
    180186#ifdef __WIN32__
    181   char *cindexhome = (indexhome+"\\").getcstr(); assert (cindexhome != NULL);
     187  char *ccollectdir = (collectdir+"\\").getcstr(); assert (ccollectdir != NULL);
    182188#else
    183   char *cindexhome = indexhome.getcstr(); assert (cindexhome != NULL);
     189  char *ccollectdir = collectdir.getcstr(); assert (ccollectdir != NULL);
    184190#endif
    185191
    186   if (load_database(cindexhome, idxsuffix, txtsuffix))
     192  if (load_database(ccollectdir, idxsuffix, txtsuffix))
    187193    {
    188194      setsearchmode (queryparams);
     
    195201  delete idxsuffix;
    196202  delete txtsuffix;
    197   delete cindexhome;
     203  delete ccollectdir;
    198204
    199205  return databaseloaded;
     
    348354// defaultindex is needed to load one
    349355bool mgsearchclass::docTargetDocument(const text_t &defaultindex,
    350                  const text_t &collection,
    351                  int docnum,
    352                  text_t &output)
     356                      const text_t &collection,
     357                      int docnum,
     358                      text_t &output)
    353359{
    354360  bool databaseloaded = true;
     
    423429    {
    424430      // get the names of the index and text suffixes
    425       text_t ttidxsuffix, tttxtsuffix;
    426       getindexsuffix (defaultindex, collection, ttidxsuffix);
    427       gettextsuffix (collection, tttxtsuffix);
    428       char *idxsuffix = ttidxsuffix.getcstr(); assert (idxsuffix != NULL);
    429       char *txtsuffix = tttxtsuffix.getcstr(); assert (txtsuffix != NULL);
     431      char *idxsuffix = (getindexsuffix (collection,
     432                     defaultindex)).getcstr();
     433      assert (idxsuffix != NULL);
     434      char *txtsuffix = (gettextsuffix (collection)).getcstr();
     435      assert (txtsuffix != NULL);
    430436
    431437#ifdef __WIN32__
    432       char *cindexhome = (indexhome+"\\").getcstr(); assert (cindexhome != NULL);
     438      char *ccollectdir = (collectdir+"\\").getcstr(); assert (ccollectdir != NULL);
    433439#else
    434       char *cindexhome = indexhome.getcstr(); assert (cindexhome != NULL);
     440      char *ccollectdir = collectdir.getcstr(); assert (ccollectdir != NULL);
    435441#endif
    436442     
    437 
    438       if (load_database(cindexhome, idxsuffix, txtsuffix))
    439     {
    440       databaseloaded = true;
    441     }
     443      if (load_database(ccollectdir, idxsuffix, txtsuffix))
     444    databaseloaded = true;
    442445      else
    443     {
    444       databaseloaded = false;
    445     }
    446      
     446    databaseloaded = false;
     447     
    447448      // free up the c strings
    448449      delete idxsuffix;
    449450      delete txtsuffix;
    450       delete cindexhome;
     451      delete ccollectdir;
    451452    }
    452453 
  • trunk/gsdl/src/library/mgsearch.h

    r4 r91  
    1818  // the index directory must be set before any searching
    1919  // is done
    20   void setindexhome (const text_t &theindexhome);
     20  void setcollectdir (const text_t &thecollectdir);
    2121 
    2222  // the search results are returned in queryresults
     
    3838protected:
    3939  querycache *cache;
    40   text_t indexhome; // top level directory for indexes
     40  text_t collectdir; // the collection directory
    4141
    4242  void setsearchmode (const queryparamclass &queryparams);
Note: See TracChangeset for help on using the changeset viewer.