static gboolean is_whitespace(gchar character)
{
/*
  Determines whether a character is a control character or a white-space character
*/
  return (g_ascii_iscntrl(character) || g_ascii_isspace(character));
}
Beispiel #2
0
/* query user for a string and jump to the entry
 * which begins with this string while the users types */
void
screen_jump(struct list_window *lw,
		list_window_callback_fn_t callback_fn,
	    list_window_paint_callback_t paint_callback,
		void *callback_data)
{
	char *search_str, *iter, *temp;
	const int WRLN_MAX_LINE_SIZE = 1024;
	int key = 65;
	command_t cmd;

	if (screen.findbuf) {
		g_free(screen.findbuf);
		screen.findbuf = NULL;
	}
	screen.findbuf = g_malloc0(WRLN_MAX_LINE_SIZE);
	/* In screen.findbuf is the whole string which is displayed in the status_window
	 * and search_str is the string the user entered (without the prompt) */
	search_str = screen.findbuf + g_snprintf(screen.findbuf, WRLN_MAX_LINE_SIZE, "%s: ", JUMP_PROMPT);
	iter = search_str;

	while(1) {
		key = screen_getch(screen.findbuf);
		/* if backspace or delete was pressed, process instead of ending loop */
		if (key == KEY_BACKSPACE || key == KEY_DC) {
			int i;
			if (search_str <= g_utf8_find_prev_char(screen.findbuf, iter))
				iter = g_utf8_find_prev_char(screen.findbuf, iter);
			for (i = 0; *(iter + i) != '\0'; i++)
				*(iter + i) = '\0';
			continue;
		}
		/* if a control key was pressed, end loop */
		else if (g_ascii_iscntrl(key) || key == KEY_NPAGE || key == KEY_PPAGE) {
			break;
		}
		else {
			*iter = key;
			if (iter < screen.findbuf + WRLN_MAX_LINE_SIZE - 3)
				++iter;
		}
		list_window_jump(lw, callback_fn, callback_data, search_str);

		/* repaint the list_window */
		if (paint_callback != NULL)
			list_window_paint2(lw, paint_callback, callback_data);
		else
			list_window_paint(lw, callback_fn, callback_data);
		wrefresh(lw->w);
	}

	/* ncmpc should get the command */
	ungetch(key);
	if ((cmd=get_keyboard_command()) != CMD_NONE)
		do_input_event(cmd);

	temp = g_strdup(search_str);
	g_free(screen.findbuf);
	screen.findbuf = temp;
}
Beispiel #3
0
static gboolean
parse_domain (const gchar *argument, gint index, gint *parsed_position,
              GError **error)
{
    gint i;
    const gchar *domain;

    domain = argument + index;
    if (domain[0] == '[') {
        i = 1;
        while (TRUE) {
            if (domain[i] == '[' || domain[i] == ']') {
                break;
            } else if (domain[i] == '\\') {
                i++;
                if (IS_TEXT(domain[i])) {
                    i++;
                } else {
                    RETURN_ERROR_WITH_POSITION("invalid quoted character "
                                               "in domain",
                                               argument, index + i);
                }
            } else if (g_ascii_isspace(domain[i])) {
                break;
            } else if (g_ascii_iscntrl(domain[i]) ||
                       g_ascii_isgraph(domain[i])) {
                i++;
            } else {
                break;
            }
        }
        if (domain[i] != ']')
            RETURN_ERROR_WITH_POSITION("terminate ']' is missing in domain",
                                       argument, index + i);
        i++;
    } else {
        i = 0;
        if (!g_ascii_isalnum(domain[i]))
            RETURN_ERROR_WITH_POSITION("domain should start with "
                                       "alphabet or digit",
                                       argument, index + i);
        do {
            i++;
            while (g_ascii_isalnum(domain[i]) || domain[i] == '-') {
                i++;
            }
        } while (domain[i] == '.');
    }

    *parsed_position = i;
    return TRUE;
}
Beispiel #4
0
static gboolean
parse_local_part (const gchar *argument, gint index, gint *parsed_position,
                  GError **error)
{
    gint i;
    const gchar *local_part;

    local_part = argument + index;
    if (local_part[0] == '"') {
        i = 1;
        while (TRUE) {
            if (local_part[i] == '\\') {
                i++;
                if (IS_TEXT(local_part[i])) {
                    i++;
                } else {
                    RETURN_ERROR_WITH_POSITION("invalid quoted character "
                                               "in local part",
                                               argument, index + i);
                }
            } else if (local_part[i] == '"') {
                break;
            } else if (g_ascii_isspace(local_part[i])) {
                break;
            } else if (g_ascii_iscntrl(local_part[i]) ||
                       g_ascii_isgraph(local_part[i])) {
                i++;
            } else {
                break;
            }
        }
        if (local_part[i] != '"')
            RETURN_ERROR_WITH_POSITION("end quote for local part is missing",
                                       argument, index + i);
        i++;
    } else {
        i = -1;
        do {
            i++;
            while (IS_ATOM_TEXT(local_part[i])) {
                i++;
            }
        } while (local_part[i] == '.');
    }

    *parsed_position = i;
    return TRUE;
}
static gboolean
looks_like_text (const guchar *data, gsize data_size)
{
  gsize i;
  char c;

  for (i = 0; i < data_size; i++)
    {
      c = data[i];

      if (g_ascii_iscntrl (c) &&
          !g_ascii_isspace (c) &&
          c != '\b')
        return FALSE;
    }
  return TRUE;
}
Beispiel #6
0
static void
_client_socket_handler(gpointer data, gint socket, PurpleInputCondition condition)
{
	BonjourJabberConversation *bconv = data;
	gint len, message_length;
	static char message[4096];

	/* Read the data from the socket */
	if ((len = recv(socket, message, sizeof(message) - 1, 0)) == -1) {
		/* There have been an error reading from the socket */
		if (errno != EAGAIN) {
			const char *err = g_strerror(errno);

			purple_debug_warning("bonjour", "receive error: %s\n", err ? err : "(null)");

			bonjour_jabber_close_conversation(bconv);
			if (bconv->pb != NULL) {
				BonjourBuddy *bb = purple_buddy_get_protocol_data(bconv->pb);

				if(bb != NULL)
					bb->conversation = NULL;
			}

			/* I guess we really don't need to notify the user.
			 * If they try to send another message it'll reconnect */
		}
		return;
	} else if (len == 0) { /* The other end has closed the socket */
		const gchar *name = purple_buddy_get_name(bconv->pb);
		purple_debug_warning("bonjour", "Connection closed (without stream end) by %s.\n", (name) ? name : "(unknown)");
		bonjour_jabber_stream_ended(bconv);
		return;
	} else {
		message_length = len;
		message[message_length] = '\0';

		while (message_length > 0 && g_ascii_iscntrl(message[message_length - 1])) {
			message[message_length - 1] = '\0';
			message_length--;
		}
	}

	purple_debug_info("bonjour", "Receive: -%s- %d bytes\n", message, len);

	bonjour_parser_process(bconv, message, message_length);
}
Beispiel #7
0
/*
  Translate SPACE to "\\040", etc.
  Taken from gflare plugin
 */
void
gfig_name_encode (gchar *dest,
                  gchar *src)
{
  gint cnt = MAX_LOAD_LINE - 1;

  while (*src && cnt--)
    {
      if (g_ascii_iscntrl (*src) || g_ascii_isspace (*src) || *src == '\\')
        {
          sprintf (dest, "\\%03o", *src++);
          dest += 4;
        }
      else
        *dest++ = *src++;
    }
  *dest = '\0';
}
Beispiel #8
0
static void autoindent_brace_code (GtkScintilla *sci, PreferencesManager *pref)
{
    gint current_pos;
    gint current_line;
    gint previous_line;
    gint previous_line_indentation;
    gint previous_line_start;
    gint previous_line_end;
    gchar *previous_char_buffer;
    gint previous_char_buffer_length;
    gchar *previous_line_buffer;
    gint previous_line_buffer_length;

    current_pos = gtk_scintilla_get_current_pos(sci);
    current_line = gtk_scintilla_line_from_position(sci, current_pos);

    gphpedit_debug (DEBUG_DOCUMENT);

    if (current_line>0) {
        gtk_scintilla_begin_undo_action(sci);
        previous_line = current_line-1;
        previous_line_indentation = gtk_scintilla_get_line_indentation(sci, previous_line);

        previous_line_end = gtk_scintilla_get_line_end_position(sci, previous_line);
        previous_char_buffer = gtk_scintilla_get_text_range (sci, previous_line_end-1, previous_line_end, &previous_char_buffer_length);
        if (is_css_char_autoindent(*previous_char_buffer)) {
            gint indentation_size;
            g_object_get(pref, "indentation_size", &indentation_size, NULL);
            previous_line_indentation+=indentation_size;
        } else if (is_css_char_autounindent(*previous_char_buffer)) {
            gint indentation_size;
            g_object_get(pref, "indentation_size", &indentation_size, NULL);
            previous_line_indentation-=indentation_size;
            if (previous_line_indentation < 0) previous_line_indentation = 0;
            previous_line_start = gtk_scintilla_position_from_line(sci, previous_line);
            previous_line_buffer = gtk_scintilla_get_text_range (sci, previous_line_start, previous_line_end, &previous_line_buffer_length);
            gboolean unindent = TRUE;
            gint char_act = 0;
            while (char_act <= previous_line_buffer_length)
            {
                char c = previous_line_buffer[char_act];
                if (!(g_ascii_iscntrl(c) || g_ascii_isspace(c) || is_css_char_autounindent(c))) {
                    unindent = FALSE;
                    break;
                }
                char_act++;
            }
            if (unindent) gtk_scintilla_set_line_indentation(sci, previous_line, previous_line_indentation);
            g_free(previous_line_buffer);
        }
        g_free(previous_char_buffer);
        indent_line(sci, current_line, previous_line_indentation);
        gphpedit_debug_message (DEBUG_DOCUMENT, "previous_line=%d, previous_indent=%d\n", previous_line, previous_line_indentation);
        gint pos;
        gboolean tabs_instead_spaces;
        g_object_get(pref,"tabs_instead_spaces", &tabs_instead_spaces, NULL);
        if(tabs_instead_spaces) {
            pos = gtk_scintilla_position_from_line(sci, current_line)+(previous_line_indentation/gtk_scintilla_get_tab_width(sci));
        } else {
            pos = gtk_scintilla_position_from_line(sci, current_line)+(previous_line_indentation);
        }
        gtk_scintilla_goto_pos(sci, pos);
        gtk_scintilla_end_undo_action(sci);
    }
}
Beispiel #9
0
static char *
COM_Parse (char *data)
{
	int	c;
	int	len;

	len = 0;
	com_token[0] = '\0';
	com_token_start = 0;
	com_token_length = 0;

	if (data == NULL)
		return NULL;

	/* skip whitespace */
skipwhite:
	while (TRUE) {
		c = *data;
		if (c == '\0')
			return NULL;	/* end of file; */
		if ((c != ' ') && (!g_ascii_iscntrl(c)))
		    break;
		data++;
		com_token_start++;
	}

	/* skip // comments */
	if ((c=='/') && (data[1]=='/')) {
		while (*data && *data != '\n')
			data++;
			com_token_start++;
		goto skipwhite;
	}

	/* handle quoted strings specially */
	if (c == '\"') {
		data++;
		com_token_start++;
		while (TRUE) {
			c = *data++;
			if ((c=='\"') || (c=='\0')) {
				com_token[len] = '\0';
				return data;
			}
			com_token[len] = c;
			len++;
			com_token_length++;
		}
	}

	/* parse a regular word */
	do {
		com_token[len] = c;
		data++;
		len++;
		com_token_length++;
		c = *data;
	} while (( c != ' ') && (!g_ascii_iscntrl(c)));

	com_token[len] = '\0';
	return data;
}
static const char *
COM_Parse (const char *data, int data_len, int* token_start, int* token_len)
{
	int c;
	char* com_token = (char*)wmem_alloc(wmem_packet_scope(), data_len+1);

	com_token[0] = '\0';
	*token_start = 0;
	*token_len = 0;

	if (data == NULL)
		return NULL;

	/* skip whitespace */
skipwhite:
	while (TRUE) {
		c = *data;
		if (c == '\0')
			return NULL;	/* end of file; */
		if ((c != ' ') && (!g_ascii_iscntrl(c)))
		    break;
		data++;
		(*token_start)++;
	}

	/* skip // comments */
	if ((c=='/') && (data[1]=='/')) {
		while (*data && *data != '\n'){
			data++;
			(*token_start)++;
		}
		goto skipwhite;
	}

	/* handle quoted strings specially */
	if (c == '\"') {
		data++;
		(*token_start)++;
		while (*token_len < data_len) {
			c = *data++;
			if ((c=='\"') || (c=='\0')) {
				com_token[*token_len] = '\0';
				return data;
			}
			com_token[*token_len] = c;
			(*token_len)++;
		}
	}

	if (*token_len == data_len) {
		com_token[*token_len] = '\0';
		return data;
	}

	/* parse a regular word */
	do {
		com_token[*token_len] = c;
		data++;
		(*token_len)++;
		c = *data;
	} while (( c != ' ') && (!g_ascii_iscntrl(c)) && (*token_len < data_len));

	com_token[*token_len] = '\0';
	return data;
}
static gchar *
mh_profile_readline( XfceMailwatchMHMailbox *mh, const gchar *mh_profile, GIOChannel *ioc )
{
    gchar           *line = NULL, *curline;
    gsize           nread, newline;
    GIOStatus       status;
    GError          *error = NULL;

    g_return_val_if_fail( ioc != NULL, NULL );

    status = g_io_channel_read_line( ioc, &curline,
                                     &nread, &newline,
                                     &error );
    while ( status == G_IO_STATUS_NORMAL ) {
        gchar       c;

        curline[newline] = 0;

        if ( !*curline ) {
            /* An mh profile shouldn't contain blank lines. Ignore 'em */
            g_free( curline );
        }
        else {
            if ( !line ) {
                if ( g_ascii_isspace( *curline ) ) {
                    /* The profile isn't right, ignore */
                    curline = g_strstrip( curline );
                }

                line = curline;
            }
            else {
                gchar       *p;

                curline = g_strstrip( curline );

                p = g_strconcat( line, curline, NULL );

                g_free( line );
                g_free( curline );

                line = p;
            }

            if ( g_io_channel_read_chars( ioc, &c, 1, &nread, NULL ) == G_IO_STATUS_NORMAL ) {
                if ( !g_ascii_isspace( c ) || g_ascii_iscntrl( c ) ) {
                    /* g_ascii_iscntrl() is supposed to catch newlines */
                    g_io_channel_seek_position( ioc, -1, G_SEEK_CUR, NULL );
                    break;
                }
            }
        }

        status = g_io_channel_read_line( ioc, &curline,
                                         &nread, &newline,
                                         &error );
    }

    if ( status == G_IO_STATUS_ERROR ) {
        xfce_mailwatch_log_message( mh->mailwatch, XFCE_MAILWATCH_MAILBOX( mh ),
                                    XFCE_MAILWATCH_LOG_WARNING,
                                    "Error reading file %s: %s",
                                    mh_profile, error->message );

        g_error_free( error );
    }

    return ( line );
}
Beispiel #12
0
// handle a keypress in edit mode
// 2 = nav
// 0 = unhandled
// 1 = handled
// -1 = handled and return pressed (finished)
int textbox_keypress ( textbox *tb, XEvent *ev, char *pad, KeySym key, Status stat )
{
    if ( !( tb->flags & TB_EDITABLE ) ) {
        return 0;
    }
    if ( stat == XLookupKeySym || stat == XLookupBoth ) {
        // Left or Ctrl-b
        if ( abe_test_action ( MOVE_CHAR_BACK, ev->xkey.state, key ) ) {
            textbox_cursor_dec ( tb );
            return 2;
        }
        // Right or Ctrl-F
        else if ( abe_test_action ( MOVE_CHAR_FORWARD, ev->xkey.state, key ) ) {
            textbox_cursor_inc ( tb );
            return 2;
        }

        // Ctrl-U: Kill from the beginning to the end of the line.
        else if ( abe_test_action ( CLEAR_LINE, ev->xkey.state, key ) ) {
            textbox_text ( tb, "" );
            return 1;
        }
        // Ctrl-A
        else if ( abe_test_action ( MOVE_FRONT, ev->xkey.state, key ) ) {
            textbox_cursor ( tb, 0 );
            return 2;
        }
        // Ctrl-E
        else if ( abe_test_action ( MOVE_END, ev->xkey.state, key ) ) {
            textbox_cursor_end ( tb );
            return 2;
        }
        // Ctrl-Alt-h
        else if ( abe_test_action ( REMOVE_WORD_BACK, ev->xkey.state, key ) ) {
            textbox_cursor_bkspc_word ( tb );
            return 1;
        }
        // Ctrl-Alt-d
        else if ( abe_test_action ( REMOVE_WORD_FORWARD, ev->xkey.state, key ) ) {
            textbox_cursor_del_word ( tb );
            return 1;
        }    // Delete or Ctrl-D
        else if ( abe_test_action ( REMOVE_CHAR_FORWARD, ev->xkey.state, key ) ) {
            textbox_cursor_del ( tb );
            return 1;
        }
        // Alt-B
        else if ( abe_test_action ( MOVE_WORD_BACK, ev->xkey.state, key ) ) {
            textbox_cursor_dec_word ( tb );
            return 2;
        }
        // Alt-F
        else if ( abe_test_action ( MOVE_WORD_FORWARD, ev->xkey.state, key ) ) {
            textbox_cursor_inc_word ( tb );
            return 2;
        }
        // BackSpace, Ctrl-h
        else if ( abe_test_action ( REMOVE_CHAR_BACK, ev->xkey.state, key ) ) {
            textbox_cursor_bkspc ( tb );
            return 1;
        }
        else if ( abe_test_action ( ACCEPT_CUSTOM, ev->xkey.state, key ) ) {
            return -2;
        }
        else if  ( abe_test_action ( ACCEPT_ENTRY_CONTINUE, ev->xkey.state, key ) ) {
            return -3;
        }
        else if ( abe_test_action ( ACCEPT_ENTRY, ev->xkey.state, key ) ) {
            return -1;
        }
    }
    if ( *pad != 0 && ( stat == XLookupBoth || stat == XLookupChars ) ) {
        // Filter When alt/ctrl is pressed do not accept the character.
        if (  !g_ascii_iscntrl ( *pad ) ) {
            textbox_insert ( tb, tb->cursor, pad );
            textbox_cursor_inc ( tb );
            return 1;
        }
    }

    return 0;
}