mirror of
https://github.com/Llewellynvdm/conky.git
synced 2024-11-16 01:57: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;
|
return fp;
|
||||||
}
|
}
|
||||||
|
|
||||||
void variable_substitute(const char *s, char *dest, unsigned int n)
|
std::string variable_substitute(std::string s)
|
||||||
{
|
{
|
||||||
while (*s && n > 1) {
|
std::string::size_type pos = 0;
|
||||||
if (*s == '$') {
|
while((pos = s.find('$', pos)) != std::string::npos) {
|
||||||
s++;
|
if(pos + 1 >= s.size())
|
||||||
if (*s != '$') {
|
break;
|
||||||
char buf[256];
|
|
||||||
const char *a, *var;
|
|
||||||
unsigned int len;
|
|
||||||
|
|
||||||
/* variable is either $foo or ${foo} */
|
if(s[pos+1] == '$') {
|
||||||
if (*s == '{') {
|
s.erase(pos, 1);
|
||||||
s++;
|
++pos;
|
||||||
a = s;
|
} else {
|
||||||
while (*s && *s != '}') {
|
std::string var;
|
||||||
s++;
|
std::string::size_type l = 0;
|
||||||
}
|
|
||||||
} else {
|
if(isalpha(s[pos+1])) {
|
||||||
a = s;
|
l = 1;
|
||||||
while (*s && (isalnum((int) *s) || *s == '_')) {
|
while(pos+l < s.size() && isalnum(s[pos+l]))
|
||||||
s++;
|
++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)
|
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);
|
std::string to_real_path(const std::string &source);
|
||||||
FILE *open_file(const char *file, int *reported);
|
FILE *open_file(const char *file, int *reported);
|
||||||
int open_fifo(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(char *buf, unsigned int n, long t);
|
||||||
void format_seconds_short(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);
|
free(current_mail_spool);
|
||||||
{
|
{
|
||||||
char buf[256];
|
std::string buf = variable_substitute(MAIL_FILE);
|
||||||
|
if (not buf.empty()) {
|
||||||
variable_substitute(MAIL_FILE, buf, 256);
|
current_mail_spool = strndup(buf.c_str(), text_buffer_size);
|
||||||
if (buf[0] != '\0') {
|
|
||||||
current_mail_spool = strndup(buf, text_buffer_size);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2847,13 +2845,11 @@ char load_config_file(const char *f)
|
|||||||
#endif /* BUILD_X11 */
|
#endif /* BUILD_X11 */
|
||||||
CONF("mail_spool") {
|
CONF("mail_spool") {
|
||||||
if (value) {
|
if (value) {
|
||||||
char buffer[256];
|
std::string buffer = variable_substitute(value);
|
||||||
|
|
||||||
variable_substitute(value, buffer, 256);
|
if (not buffer.empty()) {
|
||||||
|
|
||||||
if (buffer[0] != '\0') {
|
|
||||||
free_and_zero(current_mail_spool);
|
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 {
|
} else {
|
||||||
CONF_ERR;
|
CONF_ERR;
|
||||||
@ -3233,12 +3229,10 @@ void initialisation(int argc, char **argv) {
|
|||||||
|
|
||||||
#ifdef MAIL_FILE
|
#ifdef MAIL_FILE
|
||||||
if (current_mail_spool == NULL) {
|
if (current_mail_spool == NULL) {
|
||||||
char buf[256];
|
std::string buf = variable_substitute(MAIL_FILE);
|
||||||
|
|
||||||
variable_substitute(MAIL_FILE, buf, 256);
|
if (not buf.empty()) {
|
||||||
|
current_mail_spool = strndup(buf.c_str(), text_buffer_size);
|
||||||
if (buf[0] != '\0') {
|
|
||||||
current_mail_spool = strndup(buf, text_buffer_size);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
23
src/i8k.cc
23
src/i8k.cc
@ -78,6 +78,8 @@ int update_i8k(void)
|
|||||||
|
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
|
||||||
|
DBGP("read `%s' from /proc/i8k\n", i8k_procbuf);
|
||||||
|
|
||||||
i8k.version = strtok(&i8k_procbuf[0], I8K_DELIM);
|
i8k.version = strtok(&i8k_procbuf[0], I8K_DELIM);
|
||||||
i8k.bios = strtok(NULL, I8K_DELIM);
|
i8k.bios = strtok(NULL, I8K_DELIM);
|
||||||
i8k.serial = strtok(NULL, I8K_DELIM);
|
i8k.serial = strtok(NULL, I8K_DELIM);
|
||||||
@ -91,21 +93,21 @@ int update_i8k(void)
|
|||||||
return 0;
|
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) {
|
static const char *status_arr[] = { "off", "low", "high", "error" };
|
||||||
case 0: return "off";
|
|
||||||
case 1: return "low";
|
int i = status ? atoi(status) : 3;
|
||||||
case 2: return "high";
|
if(i < 0 || i > 3)
|
||||||
}
|
i = 3;
|
||||||
return "error";
|
|
||||||
|
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 print_i8k_left_fan_status(struct text_object *obj, char *p, int p_max_size)
|
||||||
{
|
{
|
||||||
(void)obj;
|
(void)obj;
|
||||||
snprintf(p, p_max_size, "%s",
|
print_i8k_fan_status(p, p_max_size, i8k.left_fan_status);
|
||||||
fan_status_to_string(atoi(i8k.left_fan_status)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_i8k_cpu_temp(struct text_object *obj, char *p, int p_max_size)
|
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 print_i8k_right_fan_status(struct text_object *obj, char *p, int p_max_size)
|
||||||
{
|
{
|
||||||
(void)obj;
|
(void)obj;
|
||||||
snprintf(p, p_max_size, "%s",
|
print_i8k_fan_status(p, p_max_size, i8k.right_fan_status);
|
||||||
fan_status_to_string(atoi(i8k.right_fan_status)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_i8k_ac_status(struct text_object *obj, char *p, int p_max_size)
|
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)
|
void parse_local_mail_args(struct text_object *obj, const char *arg)
|
||||||
{
|
{
|
||||||
float n1;
|
float n1;
|
||||||
char mbox[256], dst[256];
|
char mbox[256];
|
||||||
struct local_mail_s *locmail;
|
struct local_mail_s *locmail;
|
||||||
|
|
||||||
if (!arg) {
|
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));
|
locmail = (struct local_mail_s*)malloc(sizeof(struct local_mail_s));
|
||||||
memset(locmail, 0, 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;
|
locmail->interval = n1;
|
||||||
obj->data.opaque = locmail;
|
obj->data.opaque = locmail;
|
||||||
}
|
}
|
||||||
@ -663,7 +663,7 @@ static void imap_thread(thread_handle &handle, struct mail_s *mail)
|
|||||||
int threadfd = handle.readfd();
|
int threadfd = handle.readfd();
|
||||||
char resolved_host = 0;
|
char resolved_host = 0;
|
||||||
struct addrinfo hints;
|
struct addrinfo hints;
|
||||||
struct addrinfo *ai, *rp;
|
struct addrinfo *ai = 0, *rp;
|
||||||
char portbuf[8];
|
char portbuf[8];
|
||||||
|
|
||||||
while (fail < mail->retries) {
|
while (fail < mail->retries) {
|
||||||
@ -703,6 +703,7 @@ static void imap_thread(thread_handle &handle, struct mail_s *mail)
|
|||||||
close(sockfd);
|
close(sockfd);
|
||||||
}
|
}
|
||||||
freeaddrinfo(ai);
|
freeaddrinfo(ai);
|
||||||
|
ai = 0;
|
||||||
if (rp == NULL) {
|
if (rp == NULL) {
|
||||||
perror("connect");
|
perror("connect");
|
||||||
fail++;
|
fail++;
|
||||||
@ -1006,7 +1007,7 @@ static void pop3_thread(thread_handle &handle, struct mail_s *mail)
|
|||||||
struct stat stat_buf;
|
struct stat stat_buf;
|
||||||
char resolved_host = 0;
|
char resolved_host = 0;
|
||||||
struct addrinfo hints;
|
struct addrinfo hints;
|
||||||
struct addrinfo *ai, *rp;
|
struct addrinfo *ai = 0, *rp;
|
||||||
char portbuf[8];
|
char portbuf[8];
|
||||||
|
|
||||||
while (fail < mail->retries) {
|
while (fail < mail->retries) {
|
||||||
@ -1045,6 +1046,7 @@ static void pop3_thread(thread_handle &handle, struct mail_s *mail)
|
|||||||
close(sockfd);
|
close(sockfd);
|
||||||
}
|
}
|
||||||
freeaddrinfo(ai);
|
freeaddrinfo(ai);
|
||||||
|
ai = 0;
|
||||||
if (rp == NULL) {
|
if (rp == NULL) {
|
||||||
perror("connect");
|
perror("connect");
|
||||||
fail++;
|
fail++;
|
||||||
|
Loading…
Reference in New Issue
Block a user