예제 #1
0
파일: jutil.c 프로젝트: Lilitana/Pidgin
gboolean jabber_resourceprep_validate(const char *str)
{
#ifdef USE_IDN
	gboolean result;
#else
	const char *c;
#endif

	if(!str)
		return TRUE;

	if(strlen(str) > 1023)
		return FALSE;

#ifdef USE_IDN
	strncpy(idn_buffer, str, sizeof(idn_buffer) - 1);
	idn_buffer[sizeof(idn_buffer) - 1] = '\0';
	result = jabber_resourceprep(idn_buffer, sizeof(idn_buffer));
	return result;
#else /* USE_IDN */
	c = str;
	while(c && *c) {
		gunichar ch = g_utf8_get_char(c);
		if(!g_unichar_isgraph(ch) && ch != ' ')
			return FALSE;

		c = g_utf8_next_char(c);
	}

	return TRUE;
#endif /* USE_IDN */
}
예제 #2
0
파일: jutil.c 프로젝트: Lilitana/Pidgin
gboolean jabber_nodeprep_validate(const char *str)
{
#ifdef USE_IDN
	gboolean result;
#else
	const char *c;
#endif

	if(!str)
		return TRUE;

	if(strlen(str) > 1023)
		return FALSE;

#ifdef USE_IDN
	strncpy(idn_buffer, str, sizeof(idn_buffer) - 1);
	idn_buffer[sizeof(idn_buffer) - 1] = '\0';
	result = jabber_nodeprep(idn_buffer, sizeof(idn_buffer));
	return result;
#else /* USE_IDN */
	c = str;
	while(c && *c) {
		gunichar ch = g_utf8_get_char(c);
		if(ch == '\"' || ch == '&' || ch == '\'' || ch == '/' || ch == ':' ||
				ch == '<' || ch == '>' || ch == '@' || !g_unichar_isgraph(ch)) {
			return FALSE;
		}
		c = g_utf8_next_char(c);
	}

	return TRUE;
#endif /* USE_IDN */
}
예제 #3
0
파일: luah.c 프로젝트: pawelz/luakit
void
luaH_keystr_push(lua_State *L, guint keyval)
{
    gchar ucs[7];
    guint ulen;
    guint32 ukval = gdk_keyval_to_unicode(keyval);

    /* check for printable unicode character */
    if (g_unichar_isgraph(ukval)) {
        ulen = g_unichar_to_utf8(ukval, ucs);
        ucs[ulen] = 0;
        lua_pushstring(L, ucs);
    }
    /* sent keysym for non-printable characters */
    else
        lua_pushstring(L, gdk_keyval_name(keyval));
}
static gdouble
quality_func (MatePasswordDialog *dialog, const char *text, gpointer ptr)
{
	const char *p;
	gsize length;
	int uppercase = 0, symbols = 0, numbers = 0, strength;
	gunichar uc;

	if (text == NULL) return 0.0;

	/* Get the length */
	length = g_utf8_strlen (text, -1);

	/* Count the number of number, symbols and uppercase chars */
	for (p = text; *p; p = g_utf8_find_next_char (p, NULL))
	{
		uc = g_utf8_get_char (p);

		if (g_unichar_isdigit (uc))
		{
			numbers++;
		}
		else if (g_unichar_isupper (uc))
		{
			uppercase++;
		}
		else if (g_unichar_islower (uc))
		{
			/* Not counted */
		}
		else if (g_unichar_isgraph (uc))
		{
			symbols++;
		}
	}

	if (length    > 5) length = 5;
	if (numbers   > 3) numbers = 3;
	if (symbols   > 3) symbols = 3;
	if (uppercase > 3) uppercase = 3;

	strength = (length * 10 - 20) + (numbers * 10) + (symbols * 15) + (uppercase * 10);
	strength = CLAMP (strength, 0, 100);

	return (double) strength / 100.0;
}
예제 #5
0
파일: jutil.c 프로젝트: Lilitana/Pidgin
gboolean jabber_domain_validate(const char *str)
{
	const char *c;
	size_t len;

	if(!str)
		return TRUE;

	len = strlen(str);
	if (len > 1023)
		return FALSE;

	c = str;

	if (*c == '[') {
		/* Check if str is a valid IPv6 identifier */
		gboolean valid = FALSE;

		if (*(c + len - 1) != ']')
			return FALSE;

		/* Ugly, but in-place */
		*(gchar *)(c + len - 1) = '\0';
		valid = purple_ipv6_address_is_valid(c + 1);
		*(gchar *)(c + len - 1) = ']';

		return valid;
	}

	while(c && *c) {
		gunichar ch = g_utf8_get_char(c);
		/* The list of characters allowed in domain names is pretty small */
		if ((ch <= 0x7F && !( (ch >= 'a' && ch <= 'z')
				|| (ch >= '0' && ch <= '9')
				|| (ch >= 'A' && ch <= 'Z')
				|| ch == '.'
				|| ch == '-' )) || (ch >= 0x80 && !g_unichar_isgraph(ch)))
			return FALSE;

		c = g_utf8_next_char(c);
	}

	return TRUE;
}
예제 #6
0
static gboolean
imapx_acl_entry_validate_access_id (const gchar *access_id,
                                    GError **err)
{
	const gchar *id_ptr = NULL;
	gunichar uc;
	gboolean ok = TRUE;

	g_return_val_if_fail (access_id != NULL, FALSE);
	g_return_val_if_fail (err == NULL || *err == NULL, FALSE);

	/* access_id is required to be valid UTF-8 */
	ok = g_utf8_validate (access_id, -1, NULL);
	if (! ok)
		goto exit;

	/* access_id may not contain whitespace
	 * and non-printables
	 */
	id_ptr = access_id;
	while (id_ptr != NULL) {
		uc = g_utf8_get_char (id_ptr);
		if (! g_unichar_isgraph (uc)) {
			ok = FALSE;
			goto exit;
		}
		id_ptr = g_utf8_next_char (id_ptr);
		if (g_strcmp0 (id_ptr, "") == 0)
			break;
	}

	/* add more checks here */

 exit:

	if (! ok) {
		g_set_error (err,
		             CAMEL_ERROR,
		             CAMEL_ERROR_GENERIC,
		             _("Invalid IMAP ACL AccessID"));
	}

	return ok;
}
예제 #7
0
/**
 * wordcount:
 * @text: A #gchar* to examine.
 * @chars: #guint*, will contain no. chars in text.
 * @lines: #guint*, will contain no. lines in text.
 * @words: #guint*, will contain no. words in text.
 *
 * Returns number of characters, lines and words in the supplied #gchar*.
 * Handles UTF-8 correctly. Input must be properly encoded UTF-8.
 * Words are defined as any characters grouped, separated with spaces.
 * I.e., this is a word: "12a42a,.". This is two words: ". ."
 *
 * This function contains a switch() with inspiration from the GNU wc utility.
 * Rewritten for glib UTF-8 handling by Christian Tellefsen, [email protected].
 *
 * Note that gchar == char, so that gives us no problems here.
 *
 * Return value: void
 **/
void wordcount(gchar *text, guint *chars, guint *lines, guint *words)
{
	guint in_word = 0;
	gunichar utext;
	
	if(!text) return; /* politely refuse to operate on NULL .. */
		
	*chars = *words = *lines = 0;
	while (*text != '\0') {
		(*chars)++;
		
		switch (*text) {
			case '\n':
				(*lines)++;
				/* Fall through. */
			case '\r':
			case '\f':
			case '\t':
			case ' ':
			case '\v':
				mb_word_separator:
				if (in_word) {
					in_word = 0;
					(*words)++;
				}
				break;
			default:
				utext = g_utf8_get_char_validated(text, 2); /* This might be an utf-8 char..*/
				if (g_unichar_isspace (utext)) /* Unicode encoded space? */
					goto mb_word_separator;
				if (g_unichar_isgraph (utext)) /* Is this something printable? */
					in_word = 1;
				break;
		} /* switch */
		
		text = g_utf8_next_char(text); /* Even if the current char is 2 bytes, this will iterate correctly. */
	}
	
	/* Capture last word, if there's no whitespace at the end of the file. */
	if(in_word) (*words)++;
	/* We start counting line numbers from 1 */
	if(*chars > 0) (*lines)++;
}
예제 #8
0
파일: util.c 프로젝트: vifino/dwb
/* util_keyval_to_char (guint keyval)      return: char * (alloc) {{{*/
char *
util_keyval_to_char(guint keyval, gboolean ignore_whitespace) 
{
    char *key = NULL;
    guint32 unichar;
    int length;
    if ( (unichar = gdk_keyval_to_unicode(keyval)) ) 
    {
        if (ignore_whitespace && !g_unichar_isgraph(unichar))
            return NULL;
        key = g_malloc0_n(6, sizeof(char));
        if ( key && (length = g_unichar_to_utf8(unichar, key))) 
        {
            memset(&key[length], '\0', 6-length); 
            return key;
        }
        else 
            g_free(key);
    }
    return NULL;
}/*}}}*/
예제 #9
0
파일: jutil.c 프로젝트: VoxOx/VoxOx
gboolean jabber_resourceprep_validate(const char *str)
{
    const char *c;

    if(!str)
        return TRUE;

    if(strlen(str) > 1023)
        return FALSE;

    c = str;
    while(c && *c) {
        gunichar ch = g_utf8_get_char(c);
        if(!g_unichar_isgraph(ch) && ch != ' ')
            return FALSE;

        c = g_utf8_next_char(c);
    }

    return TRUE;
}
예제 #10
0
파일: jutil.c 프로젝트: VoxOx/VoxOx
gboolean jabber_nodeprep_validate(const char *str)
{
    const char *c;

    if(!str)
        return TRUE;

    if(strlen(str) > 1023)
        return FALSE;

    c = str;
    while(c && *c) {
        gunichar ch = g_utf8_get_char(c);
        if(ch == '\"' || ch == '&' || ch == '\'' || ch == '/' || ch == ':' ||
                ch == '<' || ch == '>' || ch == '@' || !g_unichar_isgraph(ch)) {
            return FALSE;
        }
        c = g_utf8_next_char(c);
    }

    return TRUE;
}
예제 #11
0
static sb4
ora_def_callback (GdaOracleValue *ora_value,
		  OCIDefine *def,
		  ub4 iter,
		  dvoid **bufpp,
		  ub4 **alenpp,
		  ub1 *piecep,
		  dvoid **indpp,
		  ub2 **rcodep)
{
	*piecep = OCI_ONE_PIECE;

	if (!ora_value->value) {
		/* 1st chunk */
		ora_value->defined_size = 0;
		ora_value->value = g_new0 (guchar, BUFFER_SIZE + 1);
		*bufpp = ora_value->value;
	}
	else {
		/* other chunks */
		ora_value->defined_size += ora_value->xlen; /* previous's chunk's real size */
#ifdef GDA_DEBUG_NO
		gint i;
		g_print ("XLEN= %d\n", ora_value->xlen);
		for (i = 0 ; i < ora_value->defined_size; i++)
			g_print ("SO FAR[%d]=[%d]%c\n", i, ((gchar*) ora_value->value)[i],
				 g_unichar_isgraph (((gchar*) ora_value->value)[i]) ? ((gchar*) ora_value->value)[i] : '-');
#endif
		ora_value->value = g_renew (guchar, ora_value->value, ora_value->defined_size + BUFFER_SIZE);
		*bufpp = ora_value->value + ora_value->defined_size;
	}

	ora_value->xlen = BUFFER_SIZE;
	*alenpp = &(ora_value->xlen);
	*indpp = (dvoid *) &(ora_value->indicator);
	*rcodep = (ub2 *) &(ora_value->rcode);

	return OCI_CONTINUE;
}
예제 #12
0
static void
atk_key_event_from_gdk_event_key (GdkEventKey       *key,
                                  AtkKeyEventStruct *event)
{
  if (key->type == GDK_KEY_PRESS)
    event->type = ATK_KEY_EVENT_PRESS;
  else if (key->type == GDK_KEY_RELEASE)
    event->type = ATK_KEY_EVENT_RELEASE;
  else
    g_assert_not_reached ();

  event->state = key->state;
  event->keyval = key->keyval;
  event->length = key->length;
  if (key->string && key->string[0] &&
      g_unichar_isgraph (g_utf8_get_char (key->string)))
    event->string = key->string;
  else
    event->string = gdk_keyval_name (key->keyval);

  event->keycode = key->hardware_keycode;
  event->timestamp = key->time;
}
static AtkKeyEventStruct *
atk_key_event_from_gdk_event_key (GdkEventKey *key)
{
    AtkKeyEventStruct *event = g_new0(AtkKeyEventStruct, 1);
    switch (key->type) {
    case GDK_KEY_PRESS:
        event->type = ATK_KEY_EVENT_PRESS;
        break;
    case GDK_KEY_RELEASE:
        event->type = ATK_KEY_EVENT_RELEASE;
        break;
    default:
        g_assert_not_reached ();
        return NULL;
    }
    event->state = key->state;
    event->keyval = key->keyval;
    event->length = key->length;
    if (key->string && key->string [0] && 
        (key->state & GDK_CONTROL_MASK ||
         g_unichar_isgraph (g_utf8_get_char (key->string)))) {
        event->string = key->string;
    }
    else if (key->type == GDK_KEY_PRESS ||
             key->type == GDK_KEY_RELEASE) {
        event->string = gdk_keyval_name (key->keyval);	    
    }
    event->keycode = key->hardware_keycode;
    event->timestamp = key->time;

    MAI_LOG_DEBUG(("MaiKey:\tsym %u\n\tmods %x\n\tcode %u\n\ttime %lx\n",
                   (unsigned int) event->keyval,
                   (unsigned int) event->state,
                   (unsigned int) event->keycode,
                   (unsigned long int) event->timestamp));
    return event;
}
예제 #14
0
파일: events.c 프로젝트: jackMort/uzbl
/* Transform gdk key events to our own events */
void
key_to_event(guint keyval, gint mode) {
    gchar ucs[7];
    gint ulen;
    guint32 ukval = gdk_keyval_to_unicode(keyval);

    /* check for printable unicode char */
    /* TODO: Pass the keyvals through a GtkIMContext so that
     *       we also get combining chars right
    */
    if(g_unichar_isgraph(ukval)) {
        ulen = g_unichar_to_utf8(ukval, ucs);
        ucs[ulen] = 0;

        send_event(mode == GDK_KEY_PRESS ? KEY_PRESS : KEY_RELEASE,
                ucs, NULL);
    }
    /* send keysym for non-printable chars */
    else {
        send_event(mode == GDK_KEY_PRESS ? KEY_PRESS : KEY_RELEASE,
                gdk_keyval_name(keyval), NULL);
    }

}
예제 #15
0
파일: msg.c 프로젝트: spk121/jozabad
// Addresses are 1 to 16 codepoints, and must start and end
// with a non-space codepoint
gboolean address_validate (gchar *str)
{
  glong len;
  gchar *p;

  if (str == NULL)
    return FALSE;
  if (!g_utf8_validate (str, -1, NULL))
    return FALSE;
  len = g_utf8_strlen (str, -1);
  if (len == 0 || len > JZ_MSG_MAX_ADDRESS_LENGTH)
  return FALSE;
  
p = str;
for (glong i = 0; i < len; i ++)
  {
    if ((i == 0 || i == len - 1) && (!g_unichar_isgraph (g_utf8_get_char (p))))
      return FALSE;
    else if (!g_unichar_isprint (g_utf8_get_char (p)))
      return FALSE;
    p = g_utf8_next_char (p);
  }
return TRUE;
}
예제 #16
0
static gboolean
rspamd_tokenizer_get_word (rspamd_ftok_t * buf,
		gchar const **cur, rspamd_ftok_t * token,
		GList **exceptions, gboolean is_utf, gsize *rl,
		gboolean check_signature)
{
	gsize remain, pos, siglen = 0;
	const gchar *p, *next_p, *sig = NULL;
	gunichar uc;
	guint processed = 0;
	struct process_exception *ex = NULL;
	enum {
		skip_delimiters = 0,
		feed_token,
		skip_exception,
		process_signature
	} state = skip_delimiters;

	if (buf == NULL) {
		return FALSE;
	}

	if (exceptions != NULL && *exceptions != NULL) {
		ex = (*exceptions)->data;
	}

	g_assert (is_utf);
	g_assert (cur != NULL);

	if (*cur == NULL) {
		*cur = buf->begin;
	}

	token->len = 0;

	pos = *cur - buf->begin;
	if (pos >= buf->len) {
		return FALSE;
	}

	remain = buf->len - pos;
	p = *cur;
	token->begin = p;

	while (remain > 0) {
		uc = g_utf8_get_char (p);
		next_p = g_utf8_next_char (p);

		if (next_p - p > (gint)remain) {
			return FALSE;
		}

		switch (state) {
		case skip_delimiters:
			if (ex != NULL && p - buf->begin == (gint)ex->pos) {
				token->begin = "!!EX!!";
				token->len = sizeof ("!!EX!!") - 1;
				processed = token->len;
				state = skip_exception;
				continue;
			}
			else if (g_unichar_isgraph (uc)) {
				if (!g_unichar_ispunct (uc)) {
					state = feed_token;
					token->begin = p;
					continue;
				}
				else if (check_signature && pos != 0 && (*p == '_' || *p == '-')) {
					sig = p;
					siglen = remain;
					state = process_signature;
					continue;
				}
			}
			break;
		case feed_token:
			if (ex != NULL && p - buf->begin == (gint)ex->pos) {
				goto set_token;
			}
			else if (!g_unichar_isgraph (uc) || g_unichar_ispunct (uc)) {
				goto set_token;
			}
			processed ++;
			break;
		case skip_exception:
			*cur = p + ex->len;
			*exceptions = g_list_next (*exceptions);
			goto set_token;
			break;
		case process_signature:
			if (*p == '\r' || *p == '\n') {
				msg_debug ("signature found: %*s", (gint)siglen, sig);
				return FALSE;
			}
			else if (*p != ' ' && *p != '-' && *p != '_') {
				state = skip_delimiters;
				continue;
			}
			break;
		}

		remain -= next_p - p;
		p = next_p;
	}

set_token:
	if (rl) {
		*rl = processed;
	}

	if (token->len == 0) {
		token->len = p - token->begin;
		g_assert (token->len > 0);
		*cur = p;
	}

	return TRUE;
}
예제 #17
0
void CheckCapitalization::check_capitalization(vector < int >&chapters, vector < ustring > &verses, ustring & text, vector < size_t > &pointers, bool end_check)
/*
Check capitalization in text.
If "end_check" is true, it also check for final sentence closing.
*/
{
  /*
     Note that this at first used gtk_text_iter_starts_sentence (&iter) and
     gtk_text_iter_ends_sentence (&iter), but these functions are not good enough,
     because do not work in several cases, like e.g. in the following line, it does
     not indicate the end of the sentence:
     As soon as the leaders of the tribes of Israel took their places, the 
     Israelites said, “How could such a horrible thing happen?"
     Therefore we use other means to check sentences.
   */

  // No check if there's no text.
  if (trim(text).empty())
    return;
  // Some variables needed.
  bool expect_capital_now = false;
  bool expect_capital_caused_by_reference = false;
  gunichar previous_char = 0;
  int localchapter = 0;
  ustring localverse = "0";
  GtkTextBuffer *textbuffer;
  textbuffer = gtk_text_buffer_new(NULL);
  gtk_text_buffer_set_text(textbuffer, text.c_str(), -1);
  GtkTextIter iter;
  gtk_text_buffer_get_start_iter(textbuffer, &iter);
  bool going = true;
  while (going) {
    // Get the unicode character.
    gunichar unichar = gtk_text_iter_get_char(&iter);
    // See whether to expect a capital now.
    if (punctuation_followed_by_capitals_set.find(unichar) != punctuation_followed_by_capitals_set.end()) {
      // Ok, expect capital.
      expect_capital_now = true;
      expect_capital_caused_by_reference = false;
      // Was this expectation caused by a reference?
      if (is_reference(iter))
        expect_capital_caused_by_reference = true;
    }
    // If we expect a capital, and we find one, no longer look for one.
    if (expect_capital_now) {
      if (g_unichar_isupper(unichar)) {
        expect_capital_now = false;
      }
    }
    // If we expect a capital, and we get lower case, that might be trouble.
    if (expect_capital_now) {
      if (g_unichar_islower(unichar)) {
        // There is no trouble if it follows a character after which to ignore lower case.
        if (ignore_lower_case_following_set.find(previous_char) != ignore_lower_case_following_set.end()) {
          expect_capital_now = false;
        }
        // If the lowercase character follows an abbreviation, there is no trouble either.
        GtkTextIter iter2 = iter;
        gtk_text_iter_backward_word_start(&iter2);
        GtkTextIter iter3 = iter2;
        gtk_text_iter_forward_word_end(&iter3);
        gtk_text_iter_forward_char(&iter3);
        ustring abbreviation = gtk_text_iter_get_text(&iter2, &iter3);
        if (abbreviations.find(abbreviation) != abbreviations.end()) {
          expect_capital_now = false;
        }
        // If it follows a reference, there is no trouble.
        if (expect_capital_caused_by_reference)
          expect_capital_now = false;
        // Ok, give message.
        if (expect_capital_now) {
          // Determine chapter and verse.
          get_chapter_and_verse(chapters, verses, pointers, iter, localchapter, localverse);
          message(book, localchapter, localverse, _("Capital expected: ") + get_context(iter));
        }
        // Only give one message about missing capitals in this context.
        expect_capital_now = false;
      }
    }
    // Store this characters as the previous characters for the next round.
    if (g_unichar_isgraph(unichar))
      previous_char = unichar;
    // Next round.
    going = gtk_text_iter_forward_char(&iter);
  }
  // The sentence should be ended with proper punctuation.
  if (end_check) {
    if (expect_capital_now)
      if (g_unichar_isdigit(previous_char))
        expect_capital_now = false;
    if (!expect_capital_now) {
      message(book, chapter, verse, _("Unended sentence: ") + get_context(iter));
    }
  }
  // Free memory
  g_object_unref(textbuffer);
}
예제 #18
0
/*based on code form libgnomekbd*/
static PyObject *
get_label (KeySym keyval)
{
    gchar buf[5];
    gunichar uc;

    PyObject * label;

    switch (keyval) {
    case GDK_Scroll_Lock:
        label = PyString_FromString("Scroll\nLock");
        break;

    case GDK_space:
        label = PyString_FromString(" ");
        break;

    case GDK_Sys_Req:
        label = PyString_FromString("Sys Rq");
        break;

    case GDK_Page_Up:
        label = PyString_FromString("Page\nUp");
        break;

    case GDK_Page_Down:
        label = PyString_FromString("Page\nDown");
        break;

    case GDK_Num_Lock:
        label = PyString_FromString("Num\nLock");
        break;

    case GDK_KP_Page_Up:
        label = PyString_FromString("Pg Up");
        break;

    case GDK_KP_Page_Down:
        label = PyString_FromString("Pg Dn");
        break;

    case GDK_KP_Home:
        label = PyString_FromString("Home");
        break;

    case GDK_KP_Left:
        label = PyString_FromString("Left");
        break;

    case GDK_KP_End:
        label = PyString_FromString("End");
        break;

    case GDK_KP_Up:
        label = PyString_FromString("Up");
        break;

    case GDK_KP_Begin:
        label = PyString_FromString("Begin");
        break;

    case GDK_KP_Right:
        label = PyString_FromString("Right");
        break;

    case GDK_KP_Enter:
        label = PyString_FromString("Enter");
        break;

    case GDK_KP_Down:
        label = PyString_FromString("Down");
        break;

    case GDK_KP_Insert:
        label = PyString_FromString("Ins");
        break;

    case GDK_KP_Delete:
        label = PyString_FromString("Del");
        break;

    case GDK_dead_grave:
        label = PyString_FromString("ˋ");
        break;

    case GDK_dead_acute:
        label = PyString_FromString("ˊ");
        break;

    case GDK_dead_circumflex:
        label = PyString_FromString("ˆ");
        break;

    case GDK_dead_tilde:
        label = PyString_FromString("~");
        break;

    case GDK_dead_macron:
        label = PyString_FromString("ˉ");
        break;

    case GDK_dead_breve:
        label = PyString_FromString("˘");
        break;

    case GDK_dead_abovedot:
        label = PyString_FromString("˙");
        break;

    case GDK_dead_diaeresis:
        label = PyString_FromString("¨");
        break;

    case GDK_dead_abovering:
        label = PyString_FromString("˚");
        break;

    case GDK_dead_doubleacute:
        label = PyString_FromString("˝");
        break;

    case GDK_dead_caron:
        label = PyString_FromString("ˇ");
        break;

    case GDK_dead_cedilla:
        label = PyString_FromString("¸");
        break;

    case GDK_dead_ogonek:
        label = PyString_FromString("˛");
        break;

        /* case GDK_dead_iota:
         * case GDK_dead_voiced_sound:
         * case GDK_dead_semivoiced_sound: */

    case GDK_dead_belowdot:
        label = PyString_FromString(".");
        break;

    case GDK_horizconnector:
        label = PyString_FromString("horiz\nconn");
        break;

    case GDK_Mode_switch:
        label = PyString_FromString("AltGr");
        break;

    case GDK_Multi_key:
        label = PyString_FromString("Compose");
        break;

    default:
        uc = gdk_keyval_to_unicode (keyval);
        if (uc != 0 && g_unichar_isgraph (uc)) {
            buf[g_unichar_to_utf8 (uc, buf)] = '\0';
            label = PyString_FromString(buf);
        }
        else
        {

            gchar *name = gdk_keyval_name (keyval);

            if (name)
                label = PyString_FromStringAndSize(name,2);
            else
                label = PyString_FromString(" ");

        }
    }
    return label;
}
예제 #19
0
파일: gdkkeys-win32.c 프로젝트: Aridna/gtk2
static void
update_keymap (void)
{
  static guint current_serial = 0;
  guchar key_state[256];
  guint scancode;
  guint vk;
  gboolean capslock_tested = FALSE;

  if (keysym_tab != NULL && current_serial == _gdk_keymap_serial)
    return;

  current_serial = _gdk_keymap_serial;

  if (keysym_tab == NULL)
    keysym_tab = g_new (guint, 4*256);

  memset (key_state, 0, sizeof (key_state));

  _gdk_keyboard_has_altgr = FALSE;
  gdk_shift_modifiers = GDK_SHIFT_MASK;

  for (vk = 0; vk < 256; vk++)
    {
      if ((scancode = MapVirtualKey (vk, 0)) == 0 &&
	  vk != VK_DIVIDE)
	keysym_tab[vk*4+0] =
	  keysym_tab[vk*4+1] =
	  keysym_tab[vk*4+2] =
	  keysym_tab[vk*4+3] = GDK_VoidSymbol;
      else
	{
	  gint shift;

	  if (vk == VK_RSHIFT)
	    _scancode_rshift = scancode;

	  key_state[vk] = 0x80;
	  for (shift = 0; shift < 4; shift++)
	    {
	      guint *ksymp = keysym_tab + vk*4 + shift;
	      
	      set_shift_vks (key_state, shift);

	      *ksymp = 0;

	      /* First, handle those virtual keys that we always want
	       * as special GDK_* keysyms, even if ToAsciiEx might
	       * turn some them into a ASCII character (like TAB and
	       * ESC).
	       */
	      handle_special (vk, ksymp, shift);

	      if (*ksymp == 0)
		{
		  wchar_t wcs[10];
		  gint k;

		  wcs[0] = wcs[1] = 0;
		  k = ToUnicodeEx (vk, scancode, key_state,
				   wcs, G_N_ELEMENTS (wcs),
				   0, _gdk_input_locale);
#if 0
		  g_print ("ToUnicodeEx(%#02x, %d: %d): %d, %04x %04x\n",
			   vk, scancode, shift, k,
			   wcs[0], wcs[1]);
#endif
		  if (k == 1)
		    *ksymp = gdk_unicode_to_keyval (wcs[0]);
		  else if (k == -1)
		    {
		      guint keysym = gdk_unicode_to_keyval (wcs[0]);

		      /* It is a dead key, and it's has been stored in
		       * the keyboard layout's state by
		       * ToAsciiEx()/ToUnicodeEx(). Yes, this is an
		       * incredibly silly API! Make the keyboard
		       * layout forget it by calling
		       * ToAsciiEx()/ToUnicodeEx() once more, with the
		       * virtual key code and scancode for the
		       * spacebar, without shift or AltGr. Otherwise
		       * the next call to ToAsciiEx() with a different
		       * key would try to combine with the dead key.
		       */
		      reset_after_dead (key_state);

		      /* Use dead keysyms instead of "undead" ones */
		      handle_dead (keysym, ksymp);
		    }
		  else if (k == 0)
		    {
		      /* Seems to be necessary to "reset" the keyboard layout
		       * in this case, too. Otherwise problems on NT4.
		       */
		      reset_after_dead (key_state);
		    }
		  else
		    {
#if 0
		      GDK_NOTE (EVENTS,
				g_print ("ToUnicodeEx returns %d "
					 "for vk:%02x, sc:%02x%s%s\n",
					 k, vk, scancode,
					 (shift&0x1 ? " shift" : ""),
					 (shift&0x2 ? " altgr" : "")));
#endif
		    }
		}
	      if (*ksymp == 0)
		*ksymp = GDK_VoidSymbol;
	    }
	  key_state[vk] = 0;

	  /* Check if keyboard has an AltGr key by checking if
	   * the mapping with Control+Alt is different.
	   */
	  if (!_gdk_keyboard_has_altgr)
	    if ((keysym_tab[vk*4 + 2] != GDK_VoidSymbol &&
		 keysym_tab[vk*4] != keysym_tab[vk*4 + 2]) ||
		(keysym_tab[vk*4 + 3] != GDK_VoidSymbol &&
		 keysym_tab[vk*4 + 1] != keysym_tab[vk*4 + 3]))
	      _gdk_keyboard_has_altgr = TRUE;
	  
	  if (!capslock_tested)
	    {
	      /* Can we use this virtual key to determine the CapsLock
	       * key behaviour: CapsLock or ShiftLock? If it generates
	       * keysyms for printable characters and has a shifted
	       * keysym that isn't just the upperacase of the
	       * unshifted keysym, check the behaviour of VK_CAPITAL.
	       */
	      if (g_unichar_isgraph (gdk_keyval_to_unicode (keysym_tab[vk*4 + 0])) &&
		  keysym_tab[vk*4 + 1] != keysym_tab[vk*4 + 0] &&
		  g_unichar_isgraph (gdk_keyval_to_unicode (keysym_tab[vk*4 + 1])) &&
		  keysym_tab[vk*4 + 1] != gdk_keyval_to_upper (keysym_tab[vk*4 + 0]))
		{
		  guchar chars[2];
		  
		  capslock_tested = TRUE;
		  
		  key_state[VK_SHIFT] = 0;
		  key_state[VK_CONTROL] = key_state[VK_MENU] = 0;
		  key_state[VK_CAPITAL] = 1;

		  if (ToAsciiEx (vk, scancode, key_state,
				 (LPWORD) chars, 0, _gdk_input_locale) == 1)
		    {
		      if (chars[0] >= GDK_space &&
			  chars[0] <= GDK_asciitilde &&
			  chars[0] == keysym_tab[vk*4 + 1])
			{
			  /* CapsLock acts as ShiftLock */
			  gdk_shift_modifiers |= GDK_LOCK_MASK;
			}
		    }
		  key_state[VK_CAPITAL] = 0;
		}    
	    }
	}
    }
  GDK_NOTE (EVENTS, print_keysym_tab ());
} 
예제 #20
0
파일: html.c 프로젝트: moisseev/rspamd
/* Decode HTML entitles in text */
guint
rspamd_html_decode_entitles_inplace (gchar *s, guint len)
{
	guint l, rep_len;
	gchar *t = s, *h = s, *e = s, *end_ptr;
	gint state = 0, val, base;
	entity *found, key;

	if (len == 0) {
		l = strlen (s);
	}
	else {
		l = len;
	}

	while (h - s < (gint)l) {
		switch (state) {
		/* Out of entitle */
		case 0:
			if (*h == '&') {
				state = 1;
				e = h;
				h++;
				continue;
			}
			else {
				*t = *h;
				h++;
				t++;
			}
			break;
		case 1:
			if (*h == ';' && h > e) {
				/* Determine base */
				/* First find in entities table */

				key.name = e + 1;
				*h = '\0';
				if (*(e + 1) != '#' &&
					(found =
					bsearch (&key, entities_defs, G_N_ELEMENTS (entities_defs),
							sizeof (entity), entity_cmp)) != NULL) {
					if (found->replacement) {
						rep_len = strlen (found->replacement);
						memcpy (t, found->replacement, rep_len);
						t += rep_len;
					}
					else {
						memmove (t, e, h - e);
						t += h - e;
					}
				}
				else if (e + 2 < h) {
					if (*(e + 2) == 'x' || *(e + 2) == 'X') {
						base = 16;
					}
					else if (*(e + 2) == 'o' || *(e + 2) == 'O') {
						base = 8;
					}
					else {
						base = 10;
					}
					if (base == 10) {
						val = strtoul ((e + 2), &end_ptr, base);
					}
					else {
						val = strtoul ((e + 3), &end_ptr, base);
					}
					if (end_ptr != NULL && *end_ptr != '\0') {
						/* Skip undecoded */
						memmove (t, e, h - e);
						t += h - e;
					}
					else {
						/* Search for a replacement */
						key.code = val;
						found =
							bsearch (&key, entities_defs_num, G_N_ELEMENTS (
									entities_defs), sizeof (entity),
								entity_cmp_num);
						if (found) {
							if (found->replacement) {
								rep_len = strlen (found->replacement);
								memcpy (t, found->replacement, rep_len);
								t += rep_len;
							}
						}
						else {
							/* Unicode point */
							if (g_unichar_isgraph (val)) {
								t += g_unichar_to_utf8 (val, t);
							}
							else {
								memmove (t, e, h - e);
								t += h - e;
							}
						}
					}
				}

				*h = ';';
				state = 0;
			}
			h++;

			break;
		}
	}

	return (t - s);
}