Develop and Download Open Source Software

Browse CVS Repository

Diff of /xoonips/AL/commonal.cc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.113 by orrisroot, Tue Oct 11 16:20:22 2005 UTC revision 1.113.2.1 by aga4096, Tue Oct 18 09:19:53 2005 UTC
# Line 22  Line 22 
22   *   *
23   * $Revision$   * $Revision$
24   * $Log$   * $Log$
25     * Revision 1.113.2.1  2005/10/18 09:19:53  aga4096
26     * ・PubMed補完が正しくないことがあるのを修正.
27     *
28   * Revision 1.113  2005/10/11 16:20:22  orrisroot   * Revision 1.113  2005/10/11 16:20:22  orrisroot
29   * SQLRowCount の戻り値チェックを元にもどした.   * SQLRowCount の戻り値チェックを元にもどした.
30   *   *
# Line 497  static SQLHANDLE henv = NULL; Line 500  static SQLHANDLE henv = NULL;
500  static SQLHANDLE hdbc = NULL;  static SQLHANDLE hdbc = NULL;
501    
502    
503  static bool processEsummary(xmlTextReaderPtr reader, pubmed_t* p);  static void processEsummary(xmlTextReaderPtr reader, string &title, string &title_abbr);
504  static bool processEsearch(xmlTextReaderPtr reader, pubmed_t* p, int* DocID );  static bool processEsearch(xmlTextReaderPtr reader, pubmed_t* p, int* DocID );
505  static void processEfetch(xmlTextReaderPtr reader, pubmed_t* p);  static void processEfetch(xmlTextReaderPtr reader, pubmed_t* p);
506  static int streamPubmedFile(const char *filename, pubmed_t* p);  static int streamPubmedFile(const char *filename, pubmed_t* p);
# Line 546  static string getCsvStr( const itemid_t Line 549  static string getCsvStr( const itemid_t
549      return iids_str;      return iids_str;
550  }  }
551    
552    string urlencode( string str ){
553        int len = str.length();
554        char *buf = new char[len*3+1];
555        char *p = buf;
556        for ( int i = 0; i < len; i++ ){
557            char c = str[i];
558            if ( isalnum(c) || c =='$' || c == '*' || c == '_' || c =='.' )
559                *p++ = c;
560            else {
561                sprintf( p, "%%%02X", c & 0x00ff );
562                p += 3;
563            }
564        }
565        *p = '\0';
566        string encoded(buf);
567        delete[] buf;
568        return encoded;
569    }
570    
571  /**  /**
572   *   *
573   * public_item_target_userの設定値が'all'ならtrueをかえす   * public_item_target_userの設定値が'all'ならtrueをかえす
# Line 6944  static int streamPubmedFile(const char * Line 6966  static int streamPubmedFile(const char *
6966          return ret;          return ret;
6967      }      }
6968            
6969        // processEfetchで得たjournalは省略形なので、それを非省略形に変換する
6970      string url = PUBMED_ESEARCH_URL_BASE;      string url = PUBMED_ESEARCH_URL_BASE;
6971      const char* ptr = p -> getJournal( );      string journal( p -> getJournal() );
6972      while( *ptr != '\0' ){      url += urlencode("\""+journal+"\"[TA]"); // [TA] = [Title Abbreviation]
6973          char buf[ 4 ];      url = urlencode(url);  // libxmlのバグ(?)のため、2回urlencodeする
         sprintf( buf, "%%%02X", ( unsigned char )*( ptr++ ) );  
         url +=  buf;  
     }  
       
6974      reader = xmlNewTextReaderFilename(url.c_str());      reader = xmlNewTextReaderFilename(url.c_str());
6975      if( reader != NULL ){      if( reader != NULL ){
6976          ret = xmlTextReaderRead(reader);          ret = xmlTextReaderRead(reader);
6977          while( ret == 1 ){          while( ret == 1 ){
6978              if( processEsearch(reader, p, &DocID ) ) break;              if( processEsearch(reader, p, &DocID ) ) {
6979                    
6980                    string title, title_abbr;
6981                    url = PUBMED_ESUMMARY_URL_BASE;
6982                    url += intToString( DocID );
6983                    xmlTextReaderPtr reader2 = xmlNewTextReaderFilename(url.c_str());
6984                    if( reader2 != NULL ){
6985                        ret = xmlTextReaderRead(reader2);
6986                        while( ret == 1 ){
6987                            processEsummary( reader2, title, title_abbr );
6988                            ret = xmlTextReaderRead( reader2 );
6989                        }
6990                        xmlFreeTextReader(reader2);
6991                    }
6992                    err = xmlGetLastError();
6993                    if( err != NULL ){
6994                        setLastErrorString( err -> message );
6995                        //return ret;
6996                    }
6997                    if ( title_abbr == journal )
6998                        p -> setJournal( title.c_str() );
6999                    
7000                }
7001              ret = xmlTextReaderRead(reader);              ret = xmlTextReaderRead(reader);
7002          }          }
7003          while( ret == 1 ){          while( ret == 1 ){
# Line 6970  static int streamPubmedFile(const char * Line 7011  static int streamPubmedFile(const char *
7011          return ret;          return ret;
7012      }      }
7013            
     url = PUBMED_ESUMMARY_URL_BASE;  
     url += intToString( DocID );  
     reader = xmlNewTextReaderFilename(url.c_str());  
     if( reader != NULL ){  
         ret = xmlTextReaderRead(reader);  
         while( ret == 1 ){  
             if( processEsummary( reader, p ) ) break;  
             ret = xmlTextReaderRead( reader );  
         }  
         while( ret == 1 ){  
             ret = xmlTextReaderRead(reader);  
         }  
         xmlFreeTextReader(reader);  
     }  
     err = xmlGetLastError();  
     if( err != NULL ){  
         setLastErrorString( err -> message );  
         return ret;  
     }  
       
7014      return ret;      return ret;
7015  }  }
7016    
# Line 7093  static bool processEsearch(xmlTextReader Line 7114  static bool processEsearch(xmlTextReader
7114                      xmlChar* value = xmlTextReaderValue( reader );                      xmlChar* value = xmlTextReaderValue( reader );
7115                      *DocID = atoi( ( char* )value );                      *DocID = atoi( ( char* )value );
7116                      xmlFree( value );                      xmlFree( value );
7117                                          value = NULL;                      value = NULL;
7118                      return true;                      return true;
7119                  }                  }
7120              }              }
# Line 7107  static bool processEsearch(xmlTextReader Line 7128  static bool processEsearch(xmlTextReader
7128    
7129  /**  /**
7130   *   *
7131   * @return true Journal Titleを取得した.   * Journal Title, Journal Title Abbreviation を取得する.
  * @return false Journal Titleを取得出来なかった.パースの継続を請う.  
7132   */   */
7133  static bool processEsummary(xmlTextReaderPtr reader, pubmed_t* p)  static void processEsummary(xmlTextReaderPtr reader, string &title, string &title_abbr )
7134  {  {
7135      xmlChar* name = NULL;      xmlChar* name = NULL;
7136      xmlChar* value = NULL;      xmlChar* value = NULL;
     bool ret = false;  
7137            
7138      name = xmlTextReaderName(reader);      name = xmlTextReaderName(reader);
7139      if( name == NULL)      if( name == NULL)
# Line 7129  static bool processEsummary(xmlTextReade Line 7148  static bool processEsummary(xmlTextReade
7148                      if( xmlTextReaderRead(reader) == 1 ){                      if( xmlTextReaderRead(reader) == 1 ){
7149                          if( xmlTextReaderNodeType( reader ) == XML_READER_TYPE_TEXT ){                          if( xmlTextReaderNodeType( reader ) == XML_READER_TYPE_TEXT ){
7150                              xmlChar* value = xmlTextReaderValue( reader );                              xmlChar* value = xmlTextReaderValue( reader );
7151                              p -> setJournal( ( char* )value );                              title = ( char* )value;
7152                                xmlFree( value );
7153                                value = NULL;
7154                            }
7155                        }
7156                    }
7157                    else if( strcmp( "MedAbbr", ( char* )attr_val ) == 0 ){
7158                        if( xmlTextReaderRead(reader) == 1 ){
7159                            if( xmlTextReaderNodeType( reader ) == XML_READER_TYPE_TEXT ){
7160                                xmlChar* value = xmlTextReaderValue( reader );
7161                                title_abbr = ( char* )value;
7162                              xmlFree( value );                              xmlFree( value );
7163                              value = NULL;                              value = NULL;
                             ret = true;  
7164                          }                          }
7165                      }                      }
7166                  }                  }
# Line 7143  static bool processEsummary(xmlTextReade Line 7171  static bool processEsummary(xmlTextReade
7171      xmlFree(name);      xmlFree(name);
7172            
7173      if( value != NULL) xmlFree(value);      if( value != NULL) xmlFree(value);
     return ret;  
7174  }  }
7175    
7176  static void processAsinSearch(xmlTextReaderPtr reader, amazonbook_t* p )  static void processAsinSearch(xmlTextReaderPtr reader, amazonbook_t* p )

Legend:
Removed from v.1.113  
changed lines
  Added in v.1.113.2.1

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26