2009-05-24
* Added fancy new 'temperature gradients' feature for graphs, via the -t
switch at the end of graph arguments.
+ * Allow ~/... and $HOME/... paths for more stuff.
2009-05-19
* Added inotify support to reload the config when modified automatically
return tv.tv_sec + (tv.tv_usec / 1000000.0);
}
+/* Converts '~/...' paths to '/home/blah/...' assumes that 'dest' is at least
+ * DEFAULT_TEXT_BUFFER_SIZE. It's similar to variable_substitute, except only
+ * cheques for $HOME and ~/ in path */
+void to_real_path(char *dest, const char *source)
+{
+ char tmp[DEFAULT_TEXT_BUFFER_SIZE];
+ if (sscanf(source, "~/%s", tmp) || sscanf(source, "$HOME/%s", tmp)) {
+ char *homedir = getenv("HOME");
+ if (homedir) {
+ snprintf(dest, DEFAULT_TEXT_BUFFER_SIZE, "%s/%s", homedir, tmp);
+ } else {
+ ERR("$HOME environment variable doesn't exist");
+ strncpy(dest, source, DEFAULT_TEXT_BUFFER_SIZE);
+ }
+ } else {
+ strncpy(dest, source, DEFAULT_TEXT_BUFFER_SIZE);
+ }
+}
+
FILE *open_file(const char *file, int *reported)
{
- FILE *fp = fopen(file, "r");
+ char path[DEFAULT_TEXT_BUFFER_SIZE];
+ FILE *fp = 0;
+
+ to_real_path(path, file);
+ fp = fopen(file, "r");
if (!fp) {
if (!reported || *reported == 0) {
void get_cpu_count(void);
double get_time(void);
+/* Converts '~/...' paths to '/home/blah/...' assumes that 'dest' is at least
+ * DEFAULT_TEXT_BUFFER_SIZE. It's similar to variable_substitute, except only
+ * cheques for $HOME and ~/ in path */
+void to_real_path(char *dest, const char *source);
FILE *open_file(const char *, int *);
void variable_substitute(const char *s, char *dest, unsigned int n);
int check_contains(char *f, char *s)
{
int ret = 0;
- FILE *where = fopen(f, "r");
+ FILE *where = open_file(f, 0);
if (where) {
char buf1[256], buf2[256];
OBJ(head)
print_head_object(obj, p, p_max_size);
OBJ(lines) {
- FILE *fp = fopen(obj->data.s,"r");
+ FILE *fp = open_file(obj->data.s, &obj->a);
if(fp != NULL) {
/* FIXME: use something more general (see also tail.c, head.c */
}
OBJ(words) {
- FILE *fp = fopen(obj->data.s,"r");
+ FILE *fp = open_file(obj->data.s, &obj->a);
if(fp != NULL) {
char buf[BUFSZ];
static void draw_stuff(void)
{
- if(overwrite_file) {
+ if (overwrite_file) {
overwrite_fpointer = fopen(overwrite_file, "w");
if(!overwrite_fpointer)
ERR("Can't overwrite '%s' anymore", overwrite_file);
}
- if(append_file) {
+ if (append_file) {
append_fpointer = fopen(append_file, "a");
if(!append_fpointer)
ERR("Can't append '%s' anymore", append_file);
if (!current_config) {
/* load default config file */
- char buf[256];
+ char buf[DEFAULT_TEXT_BUFFER_SIZE];
FILE *fp;
/* Try to use personal config file first */
- variable_substitute(CONFIG_FILE, buf, sizeof(buf));
+ to_real_path(buf, CONFIG_FILE);
if (buf[0] && (fp = fopen(buf, "r"))) {
current_config = strndup(buf, max_user_text);
fclose(fp);
extern int output_methods;
extern enum x_initialiser_state x_initialised;
+#define DEFAULT_TEXT_BUFFER_SIZE_S "##DEFAULT_TEXT_BUFFER_SIZE"
+
#endif /* _conky_h_ */
#include "imlib2.h"
#include "config.h"
#include "logging.h"
+#include "common.h"
#include <Imlib2.h>
#include <stdio.h>
if (!sscanf(args, "%1024s", cur->name)) {
ERR("Invalid args for $image. Format is: '<path to image> (-p x,y) (-s WxH)' (got '%s')", args);
}
+ to_real_path(cur->name, cur->name);
// now we check for optional args
tmp = strstr(args, "-p ");
if (tmp) {
void llua_load(const char *script)
{
int error;
+ char path[DEFAULT_TEXT_BUFFER_SIZE];
+
if(!lua_L) return;
- error = luaL_dofile(lua_L, script);
+
+ to_real_path(path, script);
+ error = luaL_dofile(lua_L, path);
if (error) {
ERR("llua_load: %s", lua_tostring(lua_L, -1));
lua_pop(lua_L, 1);
int init_tailhead_object(enum tailhead_type type,
struct text_object *obj, const char *arg)
{
- char buf[64];
+ char buf[128];
int n1, n2;
struct stat st;
FILE *fp = NULL;
return 1;
}
- numargs = sscanf(arg, "%63s %i %i", buf, &n1, &n2);
+ numargs = sscanf(arg, "%127s %i %i", buf, &n1, &n2);
if (numargs < 2 || numargs > 3) {
ERR("incorrect number of arguments given to %s object", me);
if (type == HEAD) {
goto NO_FIFO;
}
+ to_real_path(buf, buf);
if (stat(buf, &st) == 0) {
if (S_ISFIFO(st.st_mode)) {
fd = open(buf, O_RDONLY | O_NONBLOCK);