mirror of
https://github.com/Llewellynvdm/conky.git
synced 2024-11-15 17:47:09 +00:00
Merge remote branch 'origin/master' into lua-config
Conflicts: src/conky.cc
This commit is contained in:
commit
976e0eddf5
@ -152,60 +152,47 @@ FILE *open_file(const char *file, int *reported)
|
||||
return fp;
|
||||
}
|
||||
|
||||
void variable_substitute(const char *s, char *dest, unsigned int n)
|
||||
std::string variable_substitute(std::string s)
|
||||
{
|
||||
while (*s && n > 1) {
|
||||
if (*s == '$') {
|
||||
s++;
|
||||
if (*s != '$') {
|
||||
char buf[256];
|
||||
const char *a, *var;
|
||||
unsigned int len;
|
||||
std::string::size_type pos = 0;
|
||||
while((pos = s.find('$', pos)) != std::string::npos) {
|
||||
if(pos + 1 >= s.size())
|
||||
break;
|
||||
|
||||
/* variable is either $foo or ${foo} */
|
||||
if (*s == '{') {
|
||||
s++;
|
||||
a = s;
|
||||
while (*s && *s != '}') {
|
||||
s++;
|
||||
}
|
||||
} else {
|
||||
a = s;
|
||||
while (*s && (isalnum((int) *s) || *s == '_')) {
|
||||
s++;
|
||||
}
|
||||
if(s[pos+1] == '$') {
|
||||
s.erase(pos, 1);
|
||||
++pos;
|
||||
} else {
|
||||
std::string var;
|
||||
std::string::size_type l = 0;
|
||||
|
||||
if(isalpha(s[pos+1])) {
|
||||
l = 1;
|
||||
while(pos+l < s.size() && isalnum(s[pos+l]))
|
||||
++l;
|
||||
var = s.substr(pos+1, l-1);
|
||||
} else if(s[pos+1] == '{') {
|
||||
l = s.find('}', pos);
|
||||
if(l == std::string::npos)
|
||||
break;
|
||||
l -= pos - 1;
|
||||
var = s.substr(pos+2, l-3);
|
||||
} else
|
||||
++pos;
|
||||
|
||||
if(l) {
|
||||
s.erase(pos, l);
|
||||
const char *val = getenv(var.c_str());
|
||||
if(val) {
|
||||
s.insert(pos, val);
|
||||
pos += strlen(val);
|
||||
}
|
||||
|
||||
/* copy variable to buffer and look it up */
|
||||
len = (s - a > 255) ? 255 : (s - a);
|
||||
strncpy(buf, a, len);
|
||||
buf[len] = '\0';
|
||||
|
||||
if (*s == '}') {
|
||||
s++;
|
||||
}
|
||||
|
||||
var = getenv(buf);
|
||||
|
||||
if (var) {
|
||||
/* add var to dest */
|
||||
len = strlen(var);
|
||||
if (len >= n) {
|
||||
len = n - 1;
|
||||
}
|
||||
strncpy(dest, var, len);
|
||||
dest += len;
|
||||
n -= len;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
*dest++ = *s++;
|
||||
n--;
|
||||
}
|
||||
|
||||
*dest = '\0';
|
||||
return s;
|
||||
}
|
||||
|
||||
void format_seconds(char *buf, unsigned int n, long seconds)
|
||||
|
@ -68,7 +68,7 @@ double get_time(void);
|
||||
std::string to_real_path(const std::string &source);
|
||||
FILE *open_file(const char *file, int *reported);
|
||||
int open_fifo(const char *file, int *reported);
|
||||
void variable_substitute(const char *s, char *dest, unsigned int n);
|
||||
std::string variable_substitute(std::string s);
|
||||
|
||||
void format_seconds(char *buf, unsigned int n, long t);
|
||||
void format_seconds_short(char *buf, unsigned int n, long t);
|
||||
|
24
src/conky.cc
24
src/conky.cc
@ -2632,11 +2632,9 @@ static void set_default_configurations(void)
|
||||
|
||||
free(current_mail_spool);
|
||||
{
|
||||
char buf[256];
|
||||
|
||||
variable_substitute(MAIL_FILE, buf, 256);
|
||||
if (buf[0] != '\0') {
|
||||
current_mail_spool = strndup(buf, text_buffer_size);
|
||||
std::string buf = variable_substitute(MAIL_FILE);
|
||||
if (not buf.empty()) {
|
||||
current_mail_spool = strndup(buf.c_str(), text_buffer_size);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2847,13 +2845,11 @@ char load_config_file(const char *f)
|
||||
#endif /* BUILD_X11 */
|
||||
CONF("mail_spool") {
|
||||
if (value) {
|
||||
char buffer[256];
|
||||
std::string buffer = variable_substitute(value);
|
||||
|
||||
variable_substitute(value, buffer, 256);
|
||||
|
||||
if (buffer[0] != '\0') {
|
||||
if (not buffer.empty()) {
|
||||
free_and_zero(current_mail_spool);
|
||||
current_mail_spool = strndup(buffer, text_buffer_size);
|
||||
current_mail_spool = strndup(buffer.c_str(), text_buffer_size);
|
||||
}
|
||||
} else {
|
||||
CONF_ERR;
|
||||
@ -3233,12 +3229,10 @@ void initialisation(int argc, char **argv) {
|
||||
|
||||
#ifdef MAIL_FILE
|
||||
if (current_mail_spool == NULL) {
|
||||
char buf[256];
|
||||
std::string buf = variable_substitute(MAIL_FILE);
|
||||
|
||||
variable_substitute(MAIL_FILE, buf, 256);
|
||||
|
||||
if (buf[0] != '\0') {
|
||||
current_mail_spool = strndup(buf, text_buffer_size);
|
||||
if (not buf.empty()) {
|
||||
current_mail_spool = strndup(buf.c_str(), text_buffer_size);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
23
src/i8k.cc
23
src/i8k.cc
@ -78,6 +78,8 @@ int update_i8k(void)
|
||||
|
||||
fclose(fp);
|
||||
|
||||
DBGP("read `%s' from /proc/i8k\n", i8k_procbuf);
|
||||
|
||||
i8k.version = strtok(&i8k_procbuf[0], I8K_DELIM);
|
||||
i8k.bios = strtok(NULL, I8K_DELIM);
|
||||
i8k.serial = strtok(NULL, I8K_DELIM);
|
||||
@ -91,21 +93,21 @@ int update_i8k(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const char *fan_status_to_string(int status)
|
||||
static void print_i8k_fan_status(char *p, int p_max_size, const char *status)
|
||||
{
|
||||
switch(status) {
|
||||
case 0: return "off";
|
||||
case 1: return "low";
|
||||
case 2: return "high";
|
||||
}
|
||||
return "error";
|
||||
static const char *status_arr[] = { "off", "low", "high", "error" };
|
||||
|
||||
int i = status ? atoi(status) : 3;
|
||||
if(i < 0 || i > 3)
|
||||
i = 3;
|
||||
|
||||
snprintf(p, p_max_size, "%s", status_arr[i]);
|
||||
}
|
||||
|
||||
void print_i8k_left_fan_status(struct text_object *obj, char *p, int p_max_size)
|
||||
{
|
||||
(void)obj;
|
||||
snprintf(p, p_max_size, "%s",
|
||||
fan_status_to_string(atoi(i8k.left_fan_status)));
|
||||
print_i8k_fan_status(p, p_max_size, i8k.left_fan_status);
|
||||
}
|
||||
|
||||
void print_i8k_cpu_temp(struct text_object *obj, char *p, int p_max_size)
|
||||
@ -121,8 +123,7 @@ void print_i8k_cpu_temp(struct text_object *obj, char *p, int p_max_size)
|
||||
void print_i8k_right_fan_status(struct text_object *obj, char *p, int p_max_size)
|
||||
{
|
||||
(void)obj;
|
||||
snprintf(p, p_max_size, "%s",
|
||||
fan_status_to_string(atoi(i8k.right_fan_status)));
|
||||
print_i8k_fan_status(p, p_max_size, i8k.right_fan_status);
|
||||
}
|
||||
|
||||
void print_i8k_ac_status(struct text_object *obj, char *p, int p_max_size)
|
||||
|
12
src/mail.cc
12
src/mail.cc
@ -352,7 +352,7 @@ static void update_mail_count(struct local_mail_s *mail)
|
||||
void parse_local_mail_args(struct text_object *obj, const char *arg)
|
||||
{
|
||||
float n1;
|
||||
char mbox[256], dst[256];
|
||||
char mbox[256];
|
||||
struct local_mail_s *locmail;
|
||||
|
||||
if (!arg) {
|
||||
@ -370,11 +370,11 @@ void parse_local_mail_args(struct text_object *obj, const char *arg)
|
||||
}
|
||||
}
|
||||
|
||||
variable_substitute(mbox, dst, sizeof(dst));
|
||||
std::string dst = variable_substitute(mbox);
|
||||
|
||||
locmail = (struct local_mail_s*)malloc(sizeof(struct local_mail_s));
|
||||
memset(locmail, 0, sizeof(struct local_mail_s));
|
||||
locmail->mbox = strndup(dst, text_buffer_size);
|
||||
locmail->mbox = strndup(dst.c_str(), text_buffer_size);
|
||||
locmail->interval = n1;
|
||||
obj->data.opaque = locmail;
|
||||
}
|
||||
@ -663,7 +663,7 @@ static void imap_thread(thread_handle &handle, struct mail_s *mail)
|
||||
int threadfd = handle.readfd();
|
||||
char resolved_host = 0;
|
||||
struct addrinfo hints;
|
||||
struct addrinfo *ai, *rp;
|
||||
struct addrinfo *ai = 0, *rp;
|
||||
char portbuf[8];
|
||||
|
||||
while (fail < mail->retries) {
|
||||
@ -703,6 +703,7 @@ static void imap_thread(thread_handle &handle, struct mail_s *mail)
|
||||
close(sockfd);
|
||||
}
|
||||
freeaddrinfo(ai);
|
||||
ai = 0;
|
||||
if (rp == NULL) {
|
||||
perror("connect");
|
||||
fail++;
|
||||
@ -1006,7 +1007,7 @@ static void pop3_thread(thread_handle &handle, struct mail_s *mail)
|
||||
struct stat stat_buf;
|
||||
char resolved_host = 0;
|
||||
struct addrinfo hints;
|
||||
struct addrinfo *ai, *rp;
|
||||
struct addrinfo *ai = 0, *rp;
|
||||
char portbuf[8];
|
||||
|
||||
while (fail < mail->retries) {
|
||||
@ -1045,6 +1046,7 @@ static void pop3_thread(thread_handle &handle, struct mail_s *mail)
|
||||
close(sockfd);
|
||||
}
|
||||
freeaddrinfo(ai);
|
||||
ai = 0;
|
||||
if (rp == NULL) {
|
||||
perror("connect");
|
||||
fail++;
|
||||
|
Loading…
Reference in New Issue
Block a user