Skip to content

Commit

Permalink
Merge pull request #205 from keis/formfiller
Browse files Browse the repository at this point in the history
Formfiller
  • Loading branch information
keis committed Feb 4, 2016
2 parents d224d59 + d673996 commit 14535ad
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 28 deletions.
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -248,7 +248,7 @@ install-uzbl-browser: uzbl-browser install-dirs install-uzbl-core install-event-
#$(INSTALL) -m644 README.browser.md $(DOCDIR)/README.browser.md
$(INSTALL) -m644 README.event-manager.md $(DOCDIR)/README.event-manager.md
$(INSTALL) -m644 README.scripts.md $(DOCDIR)/README.scripts.md
cp -rv examples $(SHAREDIR)/uzbl/examples
cp -rv examples $(SHAREDIR)/uzbl/
$(INSTALL) -d $(SHAREDIR)/icons/hicolor/32x32/apps/
$(INSTALL) -m644 icons/32x32.png $(SHAREDIR)/icons/hicolor/32x32/apps/uzbl.png
$(INSTALL) -d $(SHAREDIR)/icons/hicolor/48x48/apps/
Expand Down
7 changes: 4 additions & 3 deletions examples/data/scripts/formfiller.js
Expand Up @@ -40,11 +40,11 @@ return {
dump: function () {
var rv = '';
var frames = slice.apply(window.frames);
frames.push(window);

frames.forEach(function (frame) {
try {
var inputs = frame.document.getElementsByTagName('input');

var inputs = slice.apply(frame.document.getElementsByTagName('input'));
inputs.filter(hasName).forEach(function (input) {
if (inputTypeIsText(input.type)) {
rv += '%' + escape(input.name) + '(' + input.type + '):' + input.value + '\n';
Expand All @@ -53,7 +53,7 @@ return {
}
});

var textareas = frame.document.getElementsByTagName('textarea');
var textareas = slice.apply(frame.document.getElementsByTagName('textarea'));
textareas.filter(hasName).forEach(function (textarea) {
var escaped = textarea.value.replace(/(^|\n)\\/g, '$1\\\\').replace(/(^|\n)%/g, '$1\\%');
rv += '%' + escape(textarea.name) + '(textarea):\n' + escaped + '\n%\n';
Expand All @@ -69,6 +69,7 @@ return {
insert: function (fname, ftype, fvalue, fchecked) {
fname = unescape(fname);
var frames = slice.apply(window.frames);
frames.push(window);

frames.forEach(function (frame) {
try {
Expand Down
6 changes: 3 additions & 3 deletions examples/data/scripts/formfiller.sh
Expand Up @@ -66,7 +66,7 @@ get_option () {
ls "$basefile"* | sed -e 's!^'"$basefile"'\.!!' | $DMENU
;;
1)
echo "$basefile"*
ls "$basefile"* | sed -e 's!^'"$basefile"'\.!!'
;;
*)
;;
Expand Down Expand Up @@ -168,7 +168,7 @@ edit_profile () {
if [ -e "$file" ]; then
$UZBL_EDITOR "$file"
else
new_profile "$profile"
new_profile "$file"
fi
}

Expand All @@ -188,7 +188,7 @@ load_profile () {

one_time_profile ()
{
local tmpfile="$( tmpfile "$UZBL_SOCKET_DIR/formfiller-${0##*/}-$$-XXXXXX" )"
local tmpfile="$( mktemp "$UZBL_SOCKET_DIR/formfiller-${0##*/}-$$-XXXXXX" )"
readonly tmpfile
trap 'rm -f "$tmpfile"' EXIT

Expand Down
23 changes: 22 additions & 1 deletion src/commands.c
Expand Up @@ -332,6 +332,9 @@ init_js_commands_api ()
static GArray *
split_quoted (const gchar *src, const gboolean unquote);

static gchar *
unescape (gchar *src);

void
parse_command_arguments (const gchar *args, GArray *argv, gboolean split)
{
Expand All @@ -341,7 +344,7 @@ parse_command_arguments (const gchar *args, GArray *argv, gboolean split)

if (!split) {
/* Pass the parameters through in one chunk. */
uzbl_commands_args_append (argv, g_strdup (args));
uzbl_commands_args_append (argv, unescape (g_strdup (args)));
return;
}

Expand Down Expand Up @@ -511,6 +514,24 @@ split_quoted (const gchar *src, const gboolean unquote)
return argv;
}

static gchar *
unescape (gchar *src)
{
gchar *s = src;
gchar *p = src;

while(*s != '\0') {
if (*s == '\\') {
s++;
}
*(p++) = *(s++);
}

*p = '\0';

return src;
}

void
parse_command_from_file (const char *cmd)
{
Expand Down
38 changes: 18 additions & 20 deletions src/io.c
Expand Up @@ -685,37 +685,35 @@ send_buffered_event (gpointer event, gpointer data)
gboolean
line_buffer_io (GIOChannel *gio, GIOCondition condition, gpointer data)
{
UZBL_UNUSED (condition);

UzblIOBufferData *io_data = (UzblIOBufferData *)data;

static const gsize BUFSZ = 256;
gchar input[BUFSZ];
gsize read;
GError *error = NULL;
gboolean eof = FALSE;

do {
GIOStatus status = g_io_channel_read_chars (gio, input, BUFSZ, &read, &error);
if ((condition & G_IO_IN) == G_IO_IN) {
do {
GIOStatus status = g_io_channel_read_chars (gio, input, BUFSZ, &read, &error);

if (status == G_IO_STATUS_ERROR) {
g_warning ("Error buffering: %s", error->message);
g_clear_error (&error);
if (status == G_IO_STATUS_ERROR) {
g_warning ("Error buffering: %s", error->message);
g_clear_error (&error);

if (io_data->error_callback) {
io_data->error_callback(gio, io_data->data);
}
if (io_data->error_callback) {
io_data->error_callback(gio, io_data->data);
}

return G_SOURCE_REMOVE;
}
return G_SOURCE_REMOVE;
}

if (status == G_IO_STATUS_EOF) {
eof = TRUE;
break;
}
if (status == G_IO_STATUS_EOF) {
break;
}

g_string_append_len (io_data->buffer, input, read);
} while (read);
g_string_append_len (io_data->buffer, input, read);
} while (read);
}

gboolean contin = G_SOURCE_CONTINUE;

Expand All @@ -735,7 +733,7 @@ line_buffer_io (GIOChannel *gio, GIOCondition condition, gpointer data)
}
} while (end);

if (eof) {
if ((condition & G_IO_HUP) == G_IO_HUP) {
if (io_data->error_callback) {
io_data->error_callback(gio, io_data->data);
}
Expand Down
1 change: 1 addition & 0 deletions src/variables.c
Expand Up @@ -845,6 +845,7 @@ expand_impl (const gchar *str, UzblExpandStage stage)
break;
}
case '\\':
g_string_append_c (buf, *p);
++p;
if (!*p) {
break;
Expand Down

0 comments on commit 14535ad

Please sign in to comment.