void Revert(const Kmer &kmer) {
   Kmer old_value = Substitute(kmer);
   if (old_value != kmer) {
     mapping_.erase(kmer);
     mapping_[old_value] = kmer;
   }
 }
 bool CheckCanRemap(const Sequence& old_s, const Sequence& new_s) const {
   if(!CheckAllDifferent(old_s, new_s))
     return false;
   size_t old_length = old_s.size() - k_ + 1;
   size_t new_length = new_s.size() - k_ + 1;
   UniformPositionAligner aligner(old_s.size() - k_ + 1,
                                  new_s.size() - k_ + 1);
   Kmer old_kmer = old_s.start<Kmer>(k_);
   old_kmer >>= 0;
   for (size_t i = k_ - 1; i < old_s.size(); ++i) {
     old_kmer <<= old_s[i];
     size_t old_kmer_offset = i - k_ + 1;
     size_t new_kmer_offest = aligner.GetPosition(old_kmer_offset);
     if(old_kmer_offset * 2 + 1 == old_length && new_length % 2 == 0) {
       Kmer middle(k_ - 1, new_s, new_length / 2);
       if (typename Kmer::less2()(middle, !middle)) {
         new_kmer_offest = new_length - 1 - new_kmer_offest;
       }
     }
     Kmer new_kmer(k_, new_s, new_kmer_offest);
     auto it = mapping_.find(new_kmer);
     if (it != mapping_.end()) {
       if (Substitute(new_kmer) != old_kmer) {
         return false;
       }
     }
   }
   return true;
 }
  void RemapKmers(const Sequence& old_s, const Sequence& new_s) {
    VERIFY(this->IsAttached());
    size_t old_length = old_s.size() - k_ + 1;
    size_t new_length = new_s.size() - k_ + 1;
    UniformPositionAligner aligner(old_s.size() - k_ + 1,
                                   new_s.size() - k_ + 1);
    Kmer old_kmer = old_s.start<Kmer>(k_);

    for (size_t i = k_ - 1; i < old_s.size(); ++i) {
      // Instead of shifting right
      if (i != k_ - 1) {
        old_kmer <<= old_s[i];
      }

      size_t old_kmer_offset = i - k_ + 1;
      size_t new_kmer_offest = aligner.GetPosition(old_kmer_offset);
      if(old_kmer_offset * 2 + 1 == old_length && new_length % 2 == 0) {
        Kmer middle(unsigned(k_ - 1), new_s, new_length / 2);
        if(typename Kmer::less2()(middle, !middle)) {
          new_kmer_offest = new_length - 1 - new_kmer_offest;
        }
      }
      Kmer new_kmer(unsigned(k_), new_s, new_kmer_offest);
      auto it = mapping_.find(new_kmer);
      if (it != mapping_.end()) {
    	if(verification_on_)
    		VERIFY(Substitute(new_kmer) == old_kmer);
        mapping_.erase(it);
      }
      if(old_kmer != new_kmer)
            mapping_[old_kmer] = new_kmer;
    }
  }
示例#4
0
void    MsgFormat( char *msg, char *buff, ... ) {
// Format a message.
    va_list     args;

    va_start( args, buff );
    Substitute( msg, buff, args );
    va_end( args );
}
示例#5
0
static  void    BldErrMsg( unsigned int err, char *buffer, va_list args ) {
// Build error message.
    *buffer = NULLCHAR;
    if( LoadMsg( err, &buffer[1], ERR_BUFF_SIZE-1 ) ) {
        buffer[0] = ' ';
        Substitute( buffer, buffer, args );
    }
}
示例#6
0
bool TParserBase::Consume(const char* text)
{
    if (TryConsume(text))
        return true;
    else {
        AddError(Substitute("Expected \"$0\".", text));
        return false;
    }
}
示例#7
0
size_t String::Substitute(const unsigned char ucChar, const String strSubstitute)
{
	// Construct the string to substitute
	char szString[2];
	szString[0] = ucChar;
	szString[1] = '\0';

	return Substitute(szString, strSubstitute);
}
bool TSimpleTextMiner::DoInput(Wtroka& text, SDocumentAttribtes& docAttr, ETypeOfDocument& docType)
{
    try {
        return Input->NextDocument(text, docAttr, docType);

    } catch (...) {
        (*ErrorStream) << Substitute("Error on document input:\n$0", CurrentExceptionMessage()) << Endl;
        return false;
    }
}
示例#9
0
void CHomonym::Print(TOutputStream& stream, const Stroka& strKwType, ECharset encoding) const
{
    Stroka s;
    if (strKwType.size())
        s = Substitute(" (<b>$0</b>) ", strKwType);

    stream << "  " << NStr::Encode(GetShortLemma(), encoding) << " ";
    PrintFormGrammems(stream, encoding);
    stream << s << GetLabelsString(encoding) << Endl;
}
bool TSimpleTextMiner::DoProcess(Wtroka& text, SDocumentAttribtes& docAttr, ETypeOfDocument& docType)
{
    try {
        return ProcessString(text, docAttr, docType);

    } catch (...) {
        (*ErrorStream) << Substitute("Error on document \"$0\" (processing):\n$1",
            docAttr.m_strUrl, CurrentExceptionMessage()) << Endl;
        return false;
    }
}
示例#11
0
bool    CWorkGrammar::IsValid() const
{
    for (CWRI it = m_EncodedRules.begin(); it!= m_EncodedRules.end(); it++) {
        const CWorkRightRulePart& R = it->m_RightPart;
        if (R.m_SynMainItemNo >= R.m_Items.size()) {
            Cerr << Substitute("$0 has no syntax root", GetRuleStr(it)) << Endl;
            return false;
        };
    };

    return true;
};
示例#12
0
void Process_Args (args *arguments, int argv, char *argc []) {
   int i = 0;
   
   arguments->newsgroup = NULL;
   arguments->toc = UNDEFINED;
   arguments->sort = UNDEFINED;
   arguments->article = UNDEFINED;
   arguments->thread = UNDEFINED;

      
   /* find "-g", and make sure there is a valid newsgroup following */
   if (i + 1 < argv) { /* make sure there is 'another' argument */
      i++; /* worry about next argument */

      /* !!!!! NEW LAST MINUTE STUFF */
      if (argc[i][0] != '.' && argc[i][0] != '/') {
         char *full_path;
         full_path = (char *) malloc (1024);
         getcwd (full_path, 1024);
         strcat (full_path, "/");
         strcat (full_path, argc[i]);
         Substitute (&full_path, ".", "/", 0, 1);
         arguments->newsgroup = full_path;
      } /* LAST MINUTE STUFF ENDS HERE (END THE ELSE IS "NULLIFIED") */

      else {
         char *temp; 
         temp = (char *) malloc (strlen (argc[i]) + 1);
         strcpy (temp, argc[i]);
         Substitute (&temp, ".", "/", 0, 1);
         arguments->newsgroup = temp;
      }
      /* ---- old ---- arguments->newsgroup = argc[i]; */
   } 

   else {
      printf ("You must specify the newsgroup name.\n");
      exit (-1);
   }
}
示例#13
0
bool TGztParser::ParseChainedFieldValues(TFieldValueDescriptorProto* value)
{
    DO(ParseSingleFieldValue(value));

    // try read several more values, interleaved with "+" or "|"
    if (!LookingAtListDelimiter())
        return true;

    // What was previously read into @value was actually a first item of chained list,
    // not a single value. So transform @value to a list and place its current content
    // as first sub-value of this list.


    // Re-use previuosly allocated items
    THolder<TFieldValueDescriptorProto> sub_value;
    if (value->mutable_list()->mutable_value()->ClearedCount() > 0) {
        sub_value.Reset(value->mutable_list()->mutable_value()->ReleaseCleared());
        sub_value->CopyFrom(*value);
        //sub_value->Swap(value);    -- Swap is unsafe here because it creates cycles for some reason!
    }
    else
        sub_value.Reset(new TFieldValueDescriptorProto(*value));

    value->Clear();

    value->set_type(TFieldValueDescriptorProto::TYPE_LIST);
    value->mutable_list()->mutable_value()->AddAllocated(sub_value.Release());

    // only single kind of separating token is allowed at single chained list.
    // so next we only accept a delimiters of same level which are equal to the first one.
    Stroka delimiter = CurrentToken().text;
    if (delimiter == "|")
        value->mutable_list()->set_type(TValuesListDescriptorProto::PIPE_DELIMITED);
    else if (delimiter == "+")
        value->mutable_list()->set_type(TValuesListDescriptorProto::PLUS_DELIMITED);
    else
        YASSERT(false);

    const char* delim_text = delimiter.c_str();
    while (TryConsume(delim_text))
        DO(ParseSingleFieldValue(value->mutable_list()->add_value()));

    // it is an error to meet any list delimiter here (as it will be mixed with previuos delimiters).
    if (!LookingAtListDelimiter())
        return true;
    else {
        AddError(Substitute("Distinct kinds of delimiters (\"$0\" and \"$1\") "
                            "should not be mixed in a single chained list at same level.",
                            delimiter, CurrentToken().text));
        return false;
    }
}
示例#14
0
void CHomonym::Print(TOutputStream& stream, ECharset encoding) const
{
    Stroka s;
    s = GetStrKWType(encoding);
    if (s.size())
        s = Substitute(" (<b>$0</b>) ", s);

    if (IsDeleted())
        s += "[deleted]";
    stream << NStr::Encode(GetShortLemma(), encoding) << " ";
    PrintGrammems(Grammems.All(), stream, encoding);
    stream << s << GetLabelsString(encoding);
}
示例#15
0
bool TGztParser::ParseGztFileOption(TGztFileDescriptorProto* file) {
  DO(Consume("option"));
  Stroka option_name;
  DO(ConsumeString(&option_name, "Expected an option name."));
  if (option_name == "strip-names" || option_name == "strip_names" || option_name == "strip names")
      file->set_strip_names(true);
  //else if <other option here>
  else {
      AddError(Substitute("Unrecognized option \"$0\".", option_name));
      return false;
  }
  DO(Consume(";"));
  return true;
}
示例#16
0
bool TGztParser::ParseEncoding(Stroka* encoding_name) {
  DO(Consume("encoding"));
  DO(ConsumeString(encoding_name, "Expected a string naming the encoding to use."));
  ECharset enc = CharsetByName(encoding_name->c_str());
  if (enc == CODES_UNKNOWN) {
      AddError(Substitute("Unrecognized encoding \"$0\".", *encoding_name));
      return false;
  }
  DO(Consume(";"));

  SetEncoding(enc);

  return true;
}
bool TSimpleTextMiner::DoOutput(SDocumentAttribtes& docAttr)
{
    CTextProcessor* pText = GetTextProcessor();
    YASSERT(pText != NULL);

    try {
        return Output->OutputFacts(*pText);

    } catch (...) {
        (*ErrorStream) << Substitute("Error on document \"$0\" (output):\n$1",
            docAttr.m_strUrl, CurrentExceptionMessage()) << Endl;
        return false;
    }
}
void CSitFactInterpretation::FillFioFactField(const fact_field_reference_t& fact_field, const CWordSequence* pWS,
                                              yvector<CFactFields>& newFacts, const SWordHomonymNum& val)
{
    const CFioWordSequence* pFioWS = dynamic_cast<const CFioWordSequence*>(pWS);
    if (pFioWS == NULL) {
        Stroka s = Substitute("Can't get fio value for $0.$1 in sentence \"$2\"", fact_field.m_strFactTypeName,
                              fact_field.m_strFieldName, NStr::DebugEncode(this->ToString()));
        Cerr << s << Endl;
        return;
    }
    CFioWS newFioWS(*pFioWS);
    newFioWS.SetMainWord(val);
    FillWSFactField(fact_field, newFioWS, newFacts);
}
示例#19
0
Stroka CSentence::ToHTMLColorString(const yvector<CWordsPair>& wp, const Stroka& sColor, ECharset encoding) const
{
    Stroka str;
    for (size_t i = 0; i + 1 <= m_words.size(); ++i) {
        CWord* pW = m_words[i].Get();
        for (size_t j = 0; j < wp.size(); ++j)
            if (wp[j].FirstWord() == (int)i)
                str += Substitute("<font color=\"$0\">", sColor);
        if (i > 0 && (!pW->IsPunct() || pW->IsOpenBracket() || pW->IsCloseBracket()))
            str += " ";
        str += NStr::Encode(pW->GetOriginalText(), encoding);
        for (size_t j = 0; j < wp.size(); ++j)
            if (wp[j].LastWord() == (int)i)
                str += "</font>";
    }
    return StripString(str);
}
示例#20
0
static  void    BldErrMsg( unsigned int err, char *buffer, va_list args ) {
// Build error message.
    const char          __FAR *char_ptr;
    const unsigned char __FAR *phrase_ptr;
    char                *buff_start;
    unsigned int        word_count;
    unsigned int        index;
    char                chr;
    int                 len;

    phrase_ptr = GetMsg( err );
    word_count = *phrase_ptr & LENGTH_MASK;
    phrase_ptr++;
    buff_start = buffer;
    *buffer = ' ';
    buffer++;
    for( ;; ) {
        index = 0;
        do {
            len = *phrase_ptr;
            index += len;
            ++phrase_ptr;
            --word_count;
        } while( len == 255 );
        char_ptr = GetWord( index );
        len = *(const char __FAR *)char_ptr;
        char_ptr++;
        for( ;; ) {
            chr = *char_ptr;
            char_ptr++;
            if( --len < 0 ) break;
            *buffer = chr;
            buffer++;
        }
        if( word_count == 0 ) break;
#if _CSET != _KANJI
        *buffer = ' ';
        buffer++;
#endif
    }
    *buffer = '\0';
    Substitute( buff_start, buff_start, args );
}
示例#21
0
bool CProcessor::Run()
{
    try {
        StartTime = time(&StartTime);
        WriteInformation("Start.");

        TextMiner->Run();

        WriteInformation("End.");

        if (PrettyXMLWriter.Get() != NULL)
            PrettyXMLWriter->SaveToFile(m_Parm.GetPrettyOutputFileName());

        m_Parm.WriteToLog("\n");
        return true;

    } catch (...) {
        WriteInformation(Substitute("Fatal error: $0", CurrentExceptionMessage()));
        return false;
    }
}
示例#22
0
char *BuildInsertQuery (art *articles, int i, char *database_name) {
   char *query;
   char threadposition[8] = "";
   char lines[8] = "";
   char *subject;

   query = (char *) malloc (512);
   query[0] = '\0';

   sprintf (threadposition, "%d", articles[i].references + 1);
   sprintf (lines, "%d", articles[i].lines);   

   subject = (char *) malloc (strlen (articles[i].subject) + 1);
   strcpy (subject, articles[i].subject);
   if (strstr (articles[i].subject, "'") != NULL) {
      Substitute (&subject, "'", "\\'", 1, 1);
   }

   strcat (query, "insert into ");
   strcat (query, database_name);
   strcat (query, " values ('" );
   strcat (query, articles[i].filename);
   strcat (query, "', ");
   strcat (query, threadposition);
   strcat (query, ", '");
   strcat (query, articles[i].message_id);
   strcat (query, "', '");
   strcat (query, articles[i].reference_field);
   strcat (query, "', '");
   strcat (query, articles[i].date_string);
   strcat (query, "', '");
   strcat (query, subject);
   strcat (query, "', '");
   strcat (query, articles[i].from);
   strcat (query, "', ");
   strcat (query, lines);
   strcat (query, ")");

   return query;
}
示例#23
0
void CProcessor::PrintSpeed(Stroka strUrl)
{
    if (DocCount % 50 == 0) {
        time_t curTime = time(&curTime);
        CTimeSpan cts(curTime - StartTime);
        double vm, tm;  //  Объем и время
        vm = (double) TotalVolume / 1048576.0;
        tm = (double) cts.GetTotalSeconds();
        double speed = (vm * 3600) / tm;
        Stroka intervalTime;
        intervalTime = Substitute("$0:$1:$2", cts.GetHours(), cts.GetMinutes(), cts.GetSeconds());

        double iTouchedSents = 0;
        if (SentenceCount != 0)
            iTouchedSents = 100 * TouchedSentenceCount / SentenceCount;

        Stroka suTime;
        suTime = Sprintf("Time:%s Doc:%lu Vol:%.2fMb Speed:%.0fMb/h (%s), Used sentences:%.2f%%",
            intervalTime.c_str(), DocCount, vm, speed, strUrl.c_str(), iTouchedSents);
        Clog << suTime << '\r';
    }
}
示例#24
0
bool TParserBase::ConsumeExtendedIdentifier(Stroka* output, const char* error)
{
    // Always return UTF8

    // First piece should be an identifier, non-ASCII alpha character or underscore
    if (!LookingAtType(Tokenizer::TYPE_IDENTIFIER) && !LookingAt('_') &&
        !LookingAtNonAsciiAlpha()) {
        AddError(error);
        return false;
    }

    output->clear();
    do {
        if (LookingAtNonAscii()) {
            if (CodePage_ == NULL) {
                AddError(Substitute("Unquoted non-ASCII characters allowed only for single-byte encodings (e.g. cp1251).\n"
                                    "Current encoding: $0.", NameByCharset(Encoding)));
                return false;
            } else if (!CodePage_->IsAlpha(CurrentToken().text[0]))
                break;
        } else if (LookingAtType(Tokenizer::TYPE_FLOAT)) {
            // We don't accept syntax like "blah.123".
            AddError("Need space between unquoted identifier and decimal point.");
            return false;
        } else if (!LookingAtType(Tokenizer::TYPE_IDENTIFIER) &&
                   !(LookingAtType(Tokenizer::TYPE_INTEGER) && ::IsAlnum(CurrentToken().text[0])) &&
                   !LookingAt('_'))
            break;

        *output += CurrentToken().text;
        NextToken();

    } while (AdjacentToPrevious());

    YASSERT(!output->empty());
    return RecodeToUtf8(*output);
}
bool CParseGrammar::CheckCoherence() const
{
    yset<CGrammarItem> AllLeftParts;
    size_t i =0;

    for (; i<m_Rules.size(); i++)
        AllLeftParts.insert(m_Rules[i].m_LeftPart);

    for (i =0; i<m_Rules.size(); i++)
        for (size_t k =0; k<m_Rules[i].m_RightParts.size(); k++)
            for (size_t j =0; j<m_Rules[i].m_RightParts[k].size(); j++) {
                const CGrammarItem& I = m_Rules[i].m_RightParts[k][j];
                if (I.m_Type == siMeta) {
                    if    (AllLeftParts.find(I) == AllLeftParts.end()) {
                        Cerr << Substitute("\"$0\" is used, but not defined (line $1; file $2)\n",
                                           I.m_ItemStrId, m_Rules[i].m_RightParts[k].m_SourceLineNo,
                                           m_Rules[i].m_RightParts[k].m_SourceLine) << Endl;
                        return  false;
                    };
                };
            };

    return true;
};
bool KnowLedgeBasedAgent::askAnd(vector<string> conjuncts, vector<string> substitution)
{
    if (conjuncts.size() == 0) return true;
    string first = conjuncts[0];
    string newFirst = first;
    vector<string> rest = *new vector<string>(conjuncts.begin()+1, conjuncts.end());
    for(long i=0; i<substitution.size(); i++)
    {
        if (substitution[i].compare(""))
        {
            newFirst = Substitute(first, substitution[i]);
        }
        else substitution.erase(substitution.begin()+i);
        if (askOr(newFirst, substitution))
        {
            bool validity = askAnd(rest, substitution);
            if (!validity) continue;
            else return true;
        }
        else continue;
        //return true;
    }
    return false;
}
示例#27
0
// add substitute
void Keyboard::addSubstitute(const ModifiedKey &i_mkeyFrom,
							 const ModifiedKey &i_mkeyTo)
{
	m_substitutes.push_front(Substitute(i_mkeyFrom, i_mkeyTo));
}
示例#28
0
BOOL CLegend::OnInitDialog() 
{
	CPropertyPage::OnInitDialog();

	// TODO: Add extra initialization here

	m_cRichEditIcons.SetWindowText(
	"Instrument Button Colors...\n"
	"GREEN_ICON Normal state.\n"
	"YELLOW_ICON A command has been sent from MIC to the instrument and MIC is waiting for a response.\n"
	"RED_ICON Communications Failure! A command has been sent and resent but no acceptable response has been received back from the instrument.\n"
	"WHITE_ICON FLASHING to previous color. The disk is full or the instrument has a failure which is causing data loss\n"
	"CYAN_ICON Some instruments cannot respond to MIC during initialization. This is a wait state that MIC may enter for a short period to allow the instrument to finish initializing.\n"
	"GRAY_ICON MIC has been instructed not to talk to the instrument.  In all cases this state will eventually revert to a normal operational state.\n"
	"\n"
	"Instrument Button ICONs...\n"
	"SQUARE_ICON Square: One or more of the tabbed pages have a data item out of tolerance or a configuration mismatch\n"
	"CLOCK_ICON Clock: The difference between MIC's time and the instrument's time is greater than the user set tolerance\n"
	"FLAG_ICON Flag:  MIC has sent and resent a command with no acceptable response and consequently commanded a long break reset in an attempt to reinitialize the instrument or a Hard Checksum Error occurred.\n"
	"BELL_ICON Bell: The instrument is currently reporting a \"Measurement Interval of Interest\" or equivalent.\n"	
	"FACE_ICON Face: The instrument has reported either a power problem or a battery backed up memory problem.\n"	
	"FLOPPY_ICON Floppy Disk & Flashing: MIC has stopped writing to disk and talking to the instrument.  This can be caused by the hard drive being too full, the maximum use of the hard drive set too low, or disk write failure.\n"
	"SKULL_ICON Skull and Cross Bones: The instrument has repeatedly failed to respond to commands and long break resets.  MIC will attempt to reset it every 15 minutes or instrument is in a state which is causing DATA LOSS.\n"
	"BOMB_ICON Bomb: Configuration Error.  Instrument support object could not connect to communications object.  Edit the MIC.INI file or delete the instrument object and recreate it to correct this problem.\n"
	"==========================================\n"
	"NOTE: This information may be modified by editing \"default.rtf\" in the MIC install directory.  An instrument\n"
	"specific display may be created by saving the modified \"default.rtf\" with the instrument's name.  For example, \"GRAND 3.rtf\" or  \"Room 257.rtf\".  Be sure to save the edited file as type Rich Text Format (*.rtf).  The Button\n"
	"ICONS are from the WINGDINGS font and may need to be changed for non-US fonts.\n");  

	Substitute("GREEN_ICON", "GREEN",COLOR_GREEN,false);
	Substitute("YELLOW_ICON","YELLOW",COLOR_YELLOW,false);
	Substitute("RED_ICON",   "RED",COLOR_RED,false);
	Substitute("WHITE_ICON","WHITE",COLOR_BLACK,false);
	Substitute("CYAN_ICON", "CYAN",COLOR_CYAN,false);
	Substitute("GRAY_ICON", "GRAY",COLOR_GRAY,false);

	Substitute("RED_ICON","RED",COLOR_RED,false);
	Substitute("SQUARE_ICON","r",COLOR_RED,true);
	Substitute("CLOCK_ICON", "»",COLOR_RED,true);
	Substitute("FLAG_ICON",  "O",COLOR_RED,true);
	Substitute("BELL_ICON",  "%",COLOR_RED,true);
	Substitute("FACE_ICON",  "L",COLOR_RED,true);
	Substitute("FLOPPY_ICON","<",COLOR_RED,true);
	Substitute("SKULL_ICON", "N",COLOR_RED,true);
	Substitute("BOMB_ICON",  "M",COLOR_RED,true);
	m_cRichEditIcons.SetSel(0,10);
	
	return FALSE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE

}
示例#29
0
void CLegend::SetText(char *text)
{
//	TRACE("CLegend::SetText(%s)\n", text);

//CString	m_csText = text;

	if (_access(text,4)==0)
	{
		CFile fIn(text, CFile::typeBinary | CFile::modeRead);
		EDITSTREAM es;
		es.dwCookie = (DWORD) &fIn;
		es.dwError = NULL;
		es.pfnCallback = ReadEditData;
		while(m_cRichEditIcons.StreamIn(SF_RTF | SFF_SELECTION,es)!=0);
		fIn.Close();
	}
	else
	{
		m_cRichEditIcons.SetWindowText(text);
		Substitute("GREEN_ICON", "GREEN",COLOR_GREEN,false);
		Substitute("YELLOW_ICON","YELLOW",COLOR_YELLOW,false);
		Substitute("RED_ICON",   "RED",COLOR_RED,false);
		Substitute("WHITE_ICON","WHITE",COLOR_BLACK,false);
		Substitute("CYAN_ICON", "CYAN",COLOR_CYAN,false);
		Substitute("GRAY_ICON", "GRAY",COLOR_GRAY,false);

		Substitute("SQUARE_ICON","r",COLOR_RED,true);
		Substitute("CLOCK_ICON", "»",COLOR_RED,true);
		Substitute("FLAG_ICON",  "O",COLOR_RED,true);
		Substitute("BELL_ICON",  "%",COLOR_RED,true);
		Substitute("FACE_ICON",  "L",COLOR_RED,true);
		Substitute("FLOPPY_ICON","<",COLOR_RED,true);
		Substitute("SKULL_ICON", "N",COLOR_RED,true);
		Substitute("BOMB_ICON",  "M",COLOR_RED,true);
		m_cRichEditIcons.SetSel(0,0);
	}
}
示例#30
0
void BuildDataBase (art *articles, int num_of_articles, char *newsgroup) {
   MYSQL mysql, *con;
   MYSQL_RES *res;
   MYSQL_ROW row;
   char query[MAX_QUERY];
   int x;
   char *table_name;

   table_name = (char *) malloc (1024);
   strcpy (table_name, newsgroup);
   Substitute (&table_name, ".", "", 1, 1);
   Substitute (&table_name, "/", "", 1, 1);

   /* printf ("(((%s))))", table_name); */

   /* ---- Connect to database server. ---- */
   if( !(con = mysql_connect(&mysql, HOSTNAME, USERNAME,PASSWORD)) ) {
      error("Could not connect.");
   }
	
   /* ---- Select DataBase. ---- */
   if (mysql_select_db(con, DATABASE)){
      error("Could not select DataBase.");
   }

   /* ---- Drop the students table ----<<<<<<<<<<<<<<<<<< DELETE */
   strcpy (query, "drop table ");
   strcat (query, table_name);
	
   if(mysql_query(con,query)) {
   }

   /* ----- Form Query for creating table --- */
   clrstr (query);
   strcat (query, "create table ");
   strcat (query, table_name);
   strcat (query, " (");
   strcat (query, "filename char(10),");
   strcat (query, "threadposn int,");
   strcat (query, "messageid char(100) not null,");
   strcat (query, "reference char(100),");
   strcat (query, "date char(40),");
   strcat (query, "subject char(100),");
   strcat (query, "msg_from char(100),");
   strcat (query, "nlines int,");
   strcat (query, "primary key(messageid) )");
	
   /* ----- Create table. ----- */
   if(mysql_query(con, query)){
      error("could not create table");
   }
	
   /* ----- insert records into the table --- */
   for (x = 0; x < num_of_articles; x++) {
      clrstr(query);
      if (articles[x].reference_field == NULL) {
         strcat (query, BuildInsertQuerySpecial (articles, x, table_name));
      } else {
         strcat (query, BuildInsertQuery (articles, x, table_name));
      }

      if (mysql_query (con, query)) {
         printf ("Could not insert record!!!! ");
         printf ("Failure to insert: %s\n", query);
      }
   }
	
   /* ---- Let us look at what we inserted ---- */
   clrstr(query);
   strcpy(query, "select * from ");
   strcat(query, table_name);
   strcat(query, " where threadposn = 1 order by messageid");
	
   if(mysql_query(con, query)) {
      error("! select 1");
   }	

   /* ---- Store results from query into res structure. ---- */
   if (!(res = mysql_store_result(con))){
      error("! store 1");
   }
   while ((row = mysql_fetch_row(res))) {
      printf("%s %s %s %s\n", row[2], row[4], row[5], row[6]);
   }

   /* ---- Drop the students table ---- */
   strcpy (query, "drop table ");
   strcat (query, table_name);

   /* ================== dropping table ===================== 	
   if(mysql_query(con,query)) {
      error("! drop 1");
   }
   =================== dropping table ===================== */
	
   /* ---- Finally close connection to server ---- */
   mysql_close(con);
}