Exemple #1
0
Autocorrect::Autocorrect(){
    
    // get dictionary: fills global dictionary list
    get_dictionary();
    get_numbers();
    
    
}
Exemple #2
0
gboolean get_dictionary_value(const FieldType* ftype,
                              FieldData* fdata, address src, address dest)
{
  gboolean found = FALSE;
  GHashTable* dictionary = 0;
  const TypedValue* prev = 0;
  
  dictionary = get_dictionary(ftype, src, dest);
  if (!ftype->key) {
    BAILOUT(FALSE, "No key on field.");
  }
  prev = g_hash_table_lookup(dictionary,ftype->key);
  if (prev) {
    /* Determine if the types match */
    if (prev->type == ftype->type) {
      /* Copy the previous value for use */
      found = TRUE;
      fdata->status = prev->empty ? FieldEmpty : FieldExists;
      if (fdata->status == FieldExists) {
        copy_field_value(ftype->type, &prev->value, &fdata->value);
      }
    }
    else {
      /* An the types differ which is a dynamic error
       * The cast is to change the gchar* to guint8* so that our types will work with it
       */
      err_d(4, fdata);
    }
  }
  else if(ftype->hasDefault){
    /* TODO FIX THIS remove the || TRUE once the other todo has been handled*/
    if(ftype->mandatory || TRUE){
      fdata->status = FieldExists;
      copy_field_value(ftype->type, &ftype->value, &fdata->value);
    }
    else {
      /* TODO Determine if the default value is empty
       * if so set status accordingly and return the value
       * otherwise do the same as above but handle for optional (-1 for ints and such)
       */
      
    }
  }
  else {
    fdata->status = FieldUndefined;
  }
  
  return found;
}
Dictionary&
DictionaryManager::get_dictionary()
{
  if (current_dict)
  {
    return *current_dict; 
  }
  else
  {
    if (current_language)
    {
      current_dict = &get_dictionary(current_language);
      return *current_dict;
    }
    else
    {
      return empty_dict;
    }
  }
}
Exemple #4
0
void set_dictionary_value(const FieldType* ftype,
                          const FieldData* fdata, address src, address dest)
{
  GHashTable* dictionary = 0;
  TypedValue* prev_value = 0;
  TypedValue* new_value = 0;
  
  dictionary = get_dictionary(ftype, src, dest);
  
  if(!ftype->key) {
    return;
  }

  prev_value = g_hash_table_lookup(dictionary, ftype->key);
  /* Recycle the previous value */
  if (prev_value) {
    if (!prev_value->empty) {
      cleanup_field_value(ftype->type, &prev_value->value);
    }
    new_value = prev_value;
  }
  else {
    new_value = g_malloc(sizeof(TypedValue));
  }
  /* Copy in the values */
  new_value->type = ftype->type;
  new_value->empty = fdata->status == FieldEmpty;
  if (!new_value->empty) {
    copy_field_value(ftype->type, &fdata->value, &new_value->value);
  }
  if (new_value) {
    /* Only have to insert if we created a new value. */
    if (!prev_value) {
      g_hash_table_insert(dictionary, g_strdup(ftype->key), new_value);
    }
  } else {
    DBG1("Failed to set value for field type: %s", ftype->name);
  }
}
Dictionary&
DictionaryManager::get_dictionary(const Language& language)
{
  //log_debug << "Dictionary for language \"" << spec << "\" requested" << std::endl;
  //log_debug << "...normalized as \"" << lang << "\"" << std::endl;
  assert(language);

  Dictionaries::iterator i = dictionaries.find(language); 
  if (i != dictionaries.end())
  {
    return *i->second;
  }
  else // Dictionary for languages lang isn't loaded, so we load it
  {
    //log_debug << "get_dictionary: " << lang << std::endl;
    Dictionary* dict = new Dictionary(charset);

    dictionaries[language] = dict;

    for (SearchPath::reverse_iterator p = search_path.rbegin(); p != search_path.rend(); ++p)
    {
      std::vector<std::string> files = filesystem->open_directory(*p);

      std::string best_filename;
      int best_score = 0;

      for(std::vector<std::string>::iterator filename = files.begin(); filename != files.end(); filename++)
      {
        // check if filename matches requested language
        if (has_suffix(*filename, ".po"))
        { // ignore anything that isn't a .po file

            Language po_language = Language::from_env(convertFilename2Language(*filename));

          if (!po_language)
          {
            log_warning << *filename << ": warning: ignoring, unknown language" << std::endl;
          }
          else
          {
            int score = Language::match(language, po_language);
                          
            if (score > best_score)
            {
              best_score = score;
              best_filename = *filename;
            }
          }
        }
      }
              
      if (!best_filename.empty())
      {
        std::string pofile = *p + "/" + best_filename;
        try 
        {
          std::auto_ptr<std::istream> in = filesystem->open_file(pofile);
          if (!in.get())
          {
            log_error << "error: failure opening: " << pofile << std::endl;
          }
          else
          {
            POParser::parse(pofile, *in, *dict);
          }
        }
        catch(std::exception& e) 
        {
          log_error << "error: failure parsing: " << pofile << std::endl;
          log_error << e.what() << "" << std::endl;
        }
      }
    }

    if (language.get_country().size() > 0)
    {
        printf("Adding language fallback %s\n", language.get_language().c_str());
        dict->addFallback( &get_dictionary(Language::from_spec(language.get_language())) );
    }
    return *dict;
  }
}
Exemple #6
0
	  void SPELLEROBJ::work(void) 
	  {
	    int i;


		if (mode==0)
		{
  		  enter=0;
		  if (((input!=63) && (oldinput==63)) || (input!=INVALID_VALUE) && (oldinput==INVALID_VALUE))
		  {
			enter=1;
			switchtime=0;
		  }
		  oldinput=input;

		  if (switchtime++> speed)
		  {

			switchtime=0;
			select++; 
			if (select>=selections) 
			{
			   select=0; 
			   selstart=0; selbegin=0; 
			   selections=entries; selend=selections; 
			   delchars=0; 

			   //selstart+=selections; 
			   //if (selstart>selend) selstart=0;
			}
			if (displayWnd) InvalidateRect(displayWnd,NULL,FALSE);

		  }
		}

		if (mode==1)
		{
			enter=0;
			
			if (waitres) 
			{
				if (input!=(int)oldinput)  waitres=0;
			}
			else
			{


				oldpaddle=paddle;
				paddle = ((int) size_value(in_ports[1].in_min,in_ports[1].in_max,input2, 16.0f ,0.0f,0));

				
				if (paddle!= oldpaddle)
				{ 
					select = paddle  % (selections+1) -1 ; 
					presstime=0;
				}
		
				if (select==-1) idletime++;
				else { idletime=0; presstime++;}
				

				if (idletime>idle)
				{
					idletime=0; select=-1; 
					oldpaddle=paddle+1;
					if (selstart+selections<selend) selstart+=selections;
					
					// if (selstart>selend)
					else                      
					{ selstart=0; selbegin=0; selections=entries; selend=selections; 
					  delchars=0; }
					InvalidateRect(displayWnd,NULL,FALSE);
				}

				if (input!=15)  { get_suggestions(); waitres=1; oldinput=input; idletime=0; presstime=0; select=-1; }

				if (presstime>press) {presstime=0; enter=1; idletime=0; }

				if (displayWnd && (select!=os)) InvalidateRect(displayWnd,NULL,FALSE);
				os=select;
			
			}

		}

		if (mode==2)
		{
			if (waitres) 
			{
				if (input==15)  waitres=0;
			}
			else
			{
				if (input==15) idletime++; else idletime=0;

				if (idletime>idle)
				{
					idletime=0; select=-1; 
					if (selstart+selections<selend) selstart+=selections;
					
					// if (selstart>selend)
					else                      
					{ selstart=0; selbegin=0; selections=entries; selend=selections; 
					  delchars=0; }
					InvalidateRect(displayWnd,NULL,FALSE);
				}

				if ((input!=oldinput) || (input==15)) presstime=0;
				else
				{ 
					if (++presstime>press)
					{

						if (input==14) 	{ selstart=0; selbegin=0; selections=entries; selend=selections; }

						if (input==13)  get_suggestions();

						if (input==7) {  select--; if (select<0) select=selections-1; enter=2; }
						if (input==11)  {  select++; if (select==selections) select=-1; enter=2; }
			
						presstime=1;
					}
				}

				if ((enter==2) && (idletime>180) && (select>=0)) {enter=1; waitres=1;}

				if (displayWnd && (select!=os)) InvalidateRect(displayWnd,NULL,FALSE);
				os=select;
			}
		    oldinput=input;

		}



		if (enter==1)
		{
			enter=0;

			switch( dict[selstart+select].type)
			{
			  
			  case FINAL_CHARACTERS:
				{
				 
 				  char c;
				  int u,keep=0;

				  c=dict[selstart+select].data[0];
				
				  switch (c)
				  {

					case '<': if (strlen(word)>0) word[strlen(word)-1]=0; 
							  if (directsend)  send_key(8);
								break;
					case 1:   if (!directsend)  send_word(word);
							  if (autolearn) learn_words();
							  strcpy(word,"");
							break;

					case 2:   for (u=0;u<entries;u++) 
							  {
								  if (dict[u].data[0]>20)   // not a command 
								  {
									up_chars(dict[u].data,dict[u].data);
									up_chars(dict[u].tag,dict[u].tag);
								  }
							  }
							  upchar=1; break;

					case 3:  get_suggestions(); 
							 InvalidateRect(displayWnd,NULL,FALSE);
							 keep=1;
							 //waitres=1; oldinput=input; 
							 idletime=0; presstime=0; switchtime=0;
							 //select=-1; 
							 break;
					
					case 4:  get_dictionary(); 
							 InvalidateRect(displayWnd,NULL,FALSE);
							 keep=1;
							 idletime=0; presstime=0; switchtime=0;
							 break;

					default:  
						if (delchars)
						{ 
						  word[strlen(word)-delchars]=0;
						  strcat(word,dict[selstart+select].data);
						  strcat(word," ");
						  if (directsend)
						  {
							send_word(dict[selstart+select].data);
							send_key(' ');
						  }
						  delchars=0;
						}
						else 
						{
							strcat(word,dict[selstart+select].data);
							if (directsend) send_word(dict[selstart+select].data);
							if (strlen(dict[selstart+select].data)>1)
							{
								strcat(word," ");
								if (directsend)  send_key(' ');
							}

							if ((dict[selstart+select].data[0]>20)&&(upchar))
							{
								upchar=0;
								for (u=0;u<entries;u++) 
								{
									if (dict[u].data[0]>20)
									{
									  low_chars(dict[u].data,dict[u].data);
									  low_chars(dict[u].tag,dict[u].tag);
									}
								}

							}
						}
				  }
				
				  if (!keep)
				  {
				    select=-1;
				    selstart=0;selbegin=0;selections=entries;selend=selections;

					make_suggestions();
				    
				  }
				}
			    break;

			case EXTEND_CHARACTERS:
				i=0;
				while (dict[selstart+select].data[i])
				{
					dict[START_DYNAMIC+i].data[0]=dict[selstart+select].data[i];
					dict[START_DYNAMIC+i].data[1]=0;

					dict[START_DYNAMIC+i].tag[0]=dict[selstart+select].tag[i];
					dict[START_DYNAMIC+i].tag[1]=0;

					dict[START_DYNAMIC+i].type=FINAL_CHARACTERS;
					i++;
				}
				selstart=START_DYNAMIC;selbegin=START_DYNAMIC;
				selend=START_DYNAMIC+i-1;
				selections=i;
				select=-1;
				break;


			case DICTIONARY:
					strcpy(fn,GLOBAL.resourcepath);
 					strcat(fn,"dictionary\\");
					strcat(fn,dict[selstart+select].data);
					load_dictionary(fn);
					make_suggestions();
					select=-1;
				    selstart=0;selbegin=0;selections=entries;selend=selections;
				    
				break;

			}

			if (displayWnd) InvalidateRect(displayWnd,NULL,FALSE);
		}
		
		

	  }