Exemple #1
0
SEXP ng_process(SEXP R_str, SEXP R_str_len, SEXP n_)
{
  char *str;
  const int n = INTEGER(n_)[0];
  wordlist_t *wl;
  ngramlist_t *ngl;
  const size_t len = INTEGER(R_str_len)[0] +1 ;
  
  SEXP RET, RET_NAMES, NGSIZE;
  SEXP str_ptr, wl_ptr, ngl_ptr;
  
  
  str = malloc(len * sizeof(str));
  strncpy(str, CHARPT(R_str, 0), len);
  
  wl = lex(str, len-1);
  ngl = process(wl, n);
  
  if (NULL == ngl)
  {
    PROTECT(RET = allocVector(INTSXP, 1));
    INTEGER(RET)[0] = -1;
    UNPROTECT(1);
    
    free(str);
    
    return RET;
  }
  
  newRptr(str, str_ptr, str_finalize);
  newRptr(wl, wl_ptr, wl_finalize);
  newRptr(ngl, ngl_ptr, ngl_finalize);
  
  // Wrangle the list
  PROTECT(NGSIZE = allocVector(INTSXP, 1));
  INTEGER(NGSIZE)[0] = ngl->ngsize;
  
  PROTECT(RET = allocVector(VECSXP, 4));
  PROTECT(RET_NAMES = allocVector(STRSXP, 4));
  
  SET_VECTOR_ELT(RET, 0, str_ptr);
  SET_VECTOR_ELT(RET, 1, wl_ptr);
  SET_VECTOR_ELT(RET, 2, ngl_ptr);
  SET_VECTOR_ELT(RET, 3, NGSIZE);
  
  SET_STRING_ELT(RET_NAMES, 0, mkChar("str_ptr"));
  SET_STRING_ELT(RET_NAMES, 1, mkChar("wl_ptr"));
  SET_STRING_ELT(RET_NAMES, 2, mkChar("ngl_ptr"));
  SET_STRING_ELT(RET_NAMES, 3, mkChar("ngsize"));
  
  setAttrib(RET, R_NamesSymbol, RET_NAMES);
  
  UNPROTECT(6);
  return RET;
}
void IRCDDBApp::doUpdate ( wxString& msg )
{
    int tableID = 0;

    wxStringTokenizer tkz(msg);

    if (!tkz.HasMoreTokens()) 
    {
      return;  // no text in message
    }

    wxString tk = tkz.GetNextToken();


    if (d->tablePattern.Matches(tk))
    {
      long i;

      if (tk.ToLong(&i))
      {
	tableID = i;
	if ((tableID < 0) || (tableID >= numberOfTables))
	{
	  wxLogVerbose(wxT("invalid table ID %d"), tableID);
	  return;
	}
      }
      else
      {
	return; // not a valid number
      }

      if (!tkz.HasMoreTokens()) 
      {
	return;  // received nothing but the tableID
      }

      tk = tkz.GetNextToken();
    }

    if (d->datePattern.Matches(tk))
    {
      if (!tkz.HasMoreTokens()) 
      {
	return;  // nothing after date string
      }

      wxString timeToken = tkz.GetNextToken();

      if (! d->timePattern.Matches(timeToken))
      {
	return; // no time string after date string
      }

      wxDateTime dt;

      if (dt.ParseFormat(tk + wxT(" ") + timeToken, wxT("%Y-%m-%d %H:%M:%S")) == NULL)
      {
	return; // date+time parsing failed
      }

      if ((tableID == 0) || (tableID == 1))
      {
	if (!tkz.HasMoreTokens())
	{
	  return;  // nothing after time string
	}

	wxString key = tkz.GetNextToken();

	if (! d->dbPattern.Matches(key))
	{
	  return; // no valid key
	}

	if (!tkz.HasMoreTokens())
	{
	  return;  // nothing after time string
	}

	wxString value = tkz.GetNextToken();

	if (! d->dbPattern.Matches(value))
	{
	  return; // no valid key
	}

	//wxLogVerbose(wxT("TABLE %d ") + key + wxT(" ") + value, tableID );


	if (tableID == 1)
	{
	  wxMutexLocker lock(d->rptrMapMutex);

	  IRCDDBAppRptrObject newRptr(dt, key, value);

	  d->rptrMap[key] = newRptr;

	  if (d->initReady)
	  {
	    wxString arearp_cs = key;
	    wxString zonerp_cs = value;

	    arearp_cs.Replace(wxT("_"), wxT(" "));
	    zonerp_cs.Replace(wxT("_"), wxT(" "));
	    zonerp_cs.SetChar(7, wxT('G'));

	    IRCMessage * m2 = new IRCMessage(wxT("IDRT_REPEATER"));
	    m2->addParam(arearp_cs);
	    m2->addParam(zonerp_cs);
	    m2->addParam(getIPAddress(value));
	    d->replyQ.putMessage(m2);
	  }
	}
	else if ((tableID == 0) && d->initReady)
	{
	  wxMutexLocker lock(d->rptrMapMutex);

	  wxString userCallsign = key;
	  wxString arearp_cs = value;
	  wxString zonerp_cs;
	  wxString ip_addr;

	  userCallsign.Replace(wxT("_"), wxT(" "));
	  arearp_cs.Replace(wxT("_"), wxT(" "));

	  if (d->rptrMap.count(value) == 1)
	  {
	    IRCDDBAppRptrObject o = d->rptrMap[value];
	    zonerp_cs = o.zonerp_cs;
	    zonerp_cs.Replace(wxT("_"), wxT(" "));
	    zonerp_cs.SetChar(7, wxT('G'));

	    ip_addr = getIPAddress(o.zonerp_cs);
	  }

	  IRCMessage * m2 = new IRCMessage(wxT("IDRT_USER"));
	  m2->addParam(userCallsign);
	  m2->addParam(arearp_cs);
	  m2->addParam(zonerp_cs);
	  m2->addParam(ip_addr); 
	  m2->addParam(tk + wxT(" ") + timeToken);
	  d->replyQ.putMessage(m2);

	}


      }
    }

}