Changeset 247

Show
Ignore:
Timestamp:
04/04/07 21:35:56 (1 year ago)
Author:
ug
Message:

Implemented rectangle notation for AB/AW/AE tags in process. Some small fixes for empty db's.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • 06/libkombilo/search.cpp

    r245 r247  
    10361036  int rc = sqlite3_exec(db, sql, 0, 0, 0); 
    10371037  if (rc != SQLITE_OK) { 
    1038     printf("error %d\n", rc); 
    10391038    throw DBError(); 
    10401039  } 
     
    21742173 
    21752174HashhitF::HashhitF() { 
    2176   printf("oops\n"); 
    21772175  cont = 0; 
    21782176  emn = 0; 
     
    37943792  rc = sqlite3_exec(db, sql.c_str(), insertEntry, this, 0); 
    37953793  if (rc != SQLITE_OK && rc != SQLITE_ERROR) { 
    3796     printf("sql error %d\n", rc); 
    37973794    throw DBError();  
    37983795  } 
     
    39783975void GameList::tagsearch(int tag) throw(DBError) { 
    39793976  char sql[200]; 
    3980    
     3977 
    39813978  if (!tag) return; 
    39823979  if (tag > 0) { 
     
    40604057 
    40614058int GameList::find_duplicates(int bs, bool strict) throw(DBError) { 
     4059  if (!currentList->size()) return 0; // this also deals with the case of an empty db 
    40624060  int bs_index = 0; 
    40634061  if (duplicates) delete duplicates; 
     
    43154313    oldList = 0; 
    43164314    if (currentList) delete currentList; 
    4317     currentList = 0
     4315    currentList = new vector<pair<int,int> >
    43184316    return; 
    43194317  } 
     
    46654663    int rc = sqlite3_prepare(db, sql_ins_rnp.c_str(), -1, &ppStmt, 0); 
    46664664    if (rc != SQLITE_OK || ppStmt==0) { 
    4667       printf("db error %d\n", rc); 
    46684665      throw DBError(); // FIXME: catch busy error, (and/or throw DBError?) 
    46694666    } 
     
    47184715      // printf("nn\n"); 
    47194716      bool caughtSGFError = false; 
     4717      char* propValue = 0; 
     4718 
    47204719      try { 
    47214720 
    47224721        // parse current node, watch out for B, W, AB, AW, AE properties 
    4723  
    47244722        const char* s = currentN->SGFstring.c_str(); 
    47254723        int lSGFstring = strlen(s); 
     
    47564754          ID[IDindex] = 0; // found next property ID 
    47574755          bool IDrelevant= (!strcmp(ID,"B") || !strcmp(ID,"W") || !strcmp(ID,"AB") || !strcmp(ID,"AW") || !strcmp(ID,"AE")); 
    4758           char* propValue = new char[lSGFstring+1]; 
     4756          propValue = new char[100000]; 
    47594757          int propValueIndex = 0; 
    47604758          int oldPropValueIndex = 0; 
     
    47694767              if (97 <= s[i] && s[i] <= 96+bs) { // valid board coordinate? 
    47704768                propValue[propValueIndex++] = s[i]; 
     4769                if (propValueIndex > 99990) throw SGFError(); 
    47714770              } else if (s[i] == 't') { ; // allow passes, but do not record them (we handle them a little sloppily here) 
     4771              } else if (s[i] == ':') { 
     4772                if (propValueIndex - oldPropValueIndex != 2) 
     4773                  throw SGFError(); 
     4774                char rect1 = 'a'; 
     4775                char rect2 = 'a'; 
     4776                i++; 
     4777                while (i<lSGFstring && (s[i] == '\t' || s[i] == ' ' || s[i] == '\r' || s[i] == '\n')) i++; 
     4778                if (i >= lSGFstring) throw SGFError(); 
     4779                if (97 <= s[i] && s[i] <= 96+bs) // valid board coordinate? 
     4780                  rect1 = s[i]; 
     4781                else throw SGFError(); 
     4782                i++; 
     4783                while (i<lSGFstring && (s[i] == '\t' || s[i] == ' ' || s[i] == '\r' || s[i] == '\n')) i++; 
     4784                if (i >= lSGFstring) throw SGFError(); 
     4785                if (97 <= s[i] && s[i] <= 96+bs) // valid board coordinate? 
     4786                  rect2 = s[i]; 
     4787                else throw SGFError(); 
     4788                i++; 
     4789                while (i<lSGFstring && (s[i] == '\t' || s[i] == ' ' || s[i] == '\r' || s[i] == '\n')) i++; 
     4790                if (i >= lSGFstring) throw SGFError(); 
     4791                if (s[i] == ']') { 
     4792                  char st1 = propValue[propValueIndex-2]; 
     4793                  char st2 = propValue[propValueIndex-1]; 
     4794                  propValueIndex -= 2; // do not want to have the first entry twice! 
     4795                  for(char x1 = st1; x1 <= rect1; x1++) { 
     4796                    for(char x2 = st2; x2 <= rect2; x2++) { 
     4797                      propValue[propValueIndex++] = x1; 
     4798                      propValue[propValueIndex++] = x2; 
     4799                      if (propValueIndex > 99990) throw SGFError(); 
     4800                    } 
     4801                  } 
     4802                  oldPropValueIndex = propValueIndex; 
     4803                  break; 
     4804                } else throw SGFError(); 
    47724805              } else { 
    47734806                throw SGFError(); 
     
    47764809            } 
    47774810            if (i >= lSGFstring) throw SGFError(); 
    4778             if (propValueIndex - oldPropValueIndex != 0 && propValueIndex - oldPropValueIndex != 2) 
     4811 
     4812            if (propValueIndex - oldPropValueIndex != 0 && propValueIndex - oldPropValueIndex != 2) { 
    47794813              throw SGFError(); 
     4814            } 
    47804815            oldPropValueIndex = propValueIndex; 
    47814816 
     
    47944829            } 
    47954830            delete [] propValue; 
     4831            propValue = 0; 
    47964832            continue; 
    47974833          } 
     
    48384874              } 
    48394875              delete [] propValue; 
     4876              propValue = 0; 
    48404877        }  
    48414878      } catch (SGFError) { 
     4879        if (propValue) { 
     4880          delete [] propValue; 
     4881          propValue = 0; 
     4882        } 
    48424883        return_val |= SGF_ERROR; 
    48434884        caughtSGFError = true;