#define LENGTH(x) (sizeof x / sizeof x[0])
-#define MAX_BINDINGS 256
#define _POSIX_SOURCE
#include <gtk/gtk.h>
#include <errno.h>
#include <fcntl.h>
#include <signal.h>
+#include <assert.h>
#include "uzbl.h"
#include "config.h"
{ NULL, 0, 0, 0, NULL, NULL, NULL }
};
+enum ptr_type {TYPE_INT, TYPE_STR, TYPE_FLOAT};
+
/* associate command names to their properties */
typedef const struct {
/* TODO: Make this ambiguous void **ptr into a union { char *char_p; int *int_p; float *float_p; } val;
the PTR() macro is kind of preventing this change at the moment. */
void **ptr;
- int type;
+ enum ptr_type type;
int dump;
int writeable;
- void (*func)(void);
+ /*@null@*/ void (*func)(void);
} uzbl_cmdprop;
-enum {TYPE_INT, TYPE_STR, TYPE_FLOAT};
-
/* abbreviations to help keep the table's width humane */
#define PTR_V(var, t, d, fun) { .ptr = (void*)&(var), .type = TYPE_##t, .dump = d, .writeable = 1, .func = fun }
#define PTR_C(var, t, fun) { .ptr = (void*)&(var), .type = TYPE_##t, .dump = 0, .writeable = 0, .func = fun }
const struct {
- char *name;
+ const char *name;
uzbl_cmdprop cp;
} var_name_to_ptr[] = {
/* variable name pointer to variable in code type dump callback function */
const struct {
- char *key;
+ /*@null@*/ char *key;
guint mask;
} modkeys[] = {
{ "SHIFT", GDK_SHIFT_MASK }, // shift
/* --- UTILITY FUNCTIONS --- */
enum {EXP_ERR, EXP_SIMPLE_VAR, EXP_BRACED_VAR, EXP_EXPR, EXP_JS, EXP_ESCAPE};
guint
-get_exp_type(gchar *s) {
+get_exp_type(const gchar *s) {
/* variables */
if(*(s+1) == '(')
return EXP_EXPR;
else
return EXP_SIMPLE_VAR;
+ /*@notreached@*/
return EXP_ERR;
}
* recurse == 2: don't expand '@<java script>@'
*/
gchar *
-expand(char *s, guint recurse) {
+expand(const char *s, guint recurse) {
uzbl_cmdprop *c;
guint etype;
- char upto = ' ';
char *end_simple_var = "^°!\"§$%&/()=?'`'+~*'#-.:,;@<>| \\{}[]¹²³¼½";
- char str_end[2];
- char ret[4096];
+ char *ret = NULL;
char *vend = NULL;
GError *err = NULL;
gchar *cmd_stdout = NULL;
if(!vend) vend = strchr(s, '\0');
break;
case EXP_BRACED_VAR:
- s++; upto = '}';
- vend = strchr(s, upto);
+ s++;
+ vend = strchr(s, '}');
if(!vend) vend = strchr(s, '\0');
break;
case EXP_EXPR:
s++;
- strcpy(str_end, ")@");
- str_end[2] = '\0';
- vend = strstr(s, str_end);
+ vend = strstr(s, ")@");
if(!vend) vend = strchr(s, '\0');
break;
case EXP_JS:
s++;
- strcpy(str_end, ">@");
- str_end[2] = '\0';
- vend = strstr(s, str_end);
+ vend = strstr(s, ">@");
if(!vend) vend = strchr(s, '\0');
break;
case EXP_ESCAPE:
s++;
- strcpy(str_end, "]@");
- str_end[2] = '\0';
- vend = strstr(s, str_end);
+ vend = strstr(s, "]@");
if(!vend) vend = strchr(s, '\0');
break;
}
+ assert(vend);
- if(vend) {
- strncpy(ret, s, vend-s);
- ret[vend-s] = '\0';
- }
+ ret = g_strndup(s, vend-s);
if(etype == EXP_SIMPLE_VAR ||
etype == EXP_BRACED_VAR) {
g_error_free (err);
}
else if (*cmd_stdout) {
- int len = strlen(cmd_stdout);
+ size_t len = strlen(cmd_stdout);
- if(cmd_stdout[len-1] == '\n')
- cmd_stdout[--len] = 0; /* strip trailing newline */
+ if(len > 0 && cmd_stdout[len-1] == '\n')
+ cmd_stdout[--len] = '\0'; /* strip trailing newline */
g_string_append(buf, cmd_stdout);
g_free(cmd_stdout);
g_free(mycmd);
s = vend+2;
}
+
+ free(ret);
+ ret = NULL;
break;
default:
if (uzbl.behave.print_version) {
printf("Commit: %s\n", COMMIT);
- exit(0);
+ exit(EXIT_SUCCESS);
}
/* initialize hash table */
set_var_value("uri", uri_override);
g_free(uri_override);
} else if (uzbl.state.uri)
- cmd_load_uri(uzbl.gui.web_view, NULL);
+ cmd_load_uri();
gtk_main ();
clean_up();