mirror of
https://github.com/Llewellynvdm/conky.git
synced 2024-11-05 21:07:52 +00:00
fixed $tail, many thanks to MrGreen for pointing this out
git-svn-id: https://conky.svn.sourceforge.net/svnroot/conky/trunk/conky@38 7f574dfc-610e-0410-a909-a81674777703
This commit is contained in:
parent
023ed2200e
commit
2b3b776843
117
conky.c
117
conky.c
@ -628,7 +628,7 @@ struct text_object {
|
|||||||
char *logfile;
|
char *logfile;
|
||||||
double last_update;
|
double last_update;
|
||||||
float interval;
|
float interval;
|
||||||
char buffer[TEXT_BUFFER_SIZE];
|
char buffer[TEXT_BUFFER_SIZE*4];
|
||||||
} tail;
|
} tail;
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
@ -2152,105 +2152,54 @@ static void generate_text()
|
|||||||
|
|
||||||
|
|
||||||
OBJ(tail) {
|
OBJ(tail) {
|
||||||
if (current_update_time -
|
if (current_update_time -obj->data.tail.last_update < obj->data.tail.interval) {
|
||||||
obj->data.tail.last_update <
|
snprintf(p, n, "%s", obj->data.tail.buffer);
|
||||||
obj->data.tail.interval) {
|
|
||||||
snprintf(p, n, "%s",
|
|
||||||
obj->data.tail.buffer);
|
|
||||||
} else {
|
} else {
|
||||||
|
obj->data.tail.last_update = current_update_time;
|
||||||
obj->data.tail.last_update =
|
|
||||||
current_update_time;
|
|
||||||
|
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
int i;
|
int i;
|
||||||
tailstring *head = NULL;
|
tailstring *head = NULL;
|
||||||
tailstring *headtmp1 = NULL;
|
tailstring *headtmp = NULL;
|
||||||
tailstring *headtmp2 = NULL;
|
fp = fopen(obj->data.tail.logfile, "rt");
|
||||||
tailstring *headtmp2tmp = NULL;
|
|
||||||
fp = fopen(obj->data.tail.logfile,
|
|
||||||
"rt");
|
|
||||||
if (fp == NULL)
|
if (fp == NULL)
|
||||||
ERR("tail logfile failed to open");
|
ERR("tail logfile failed to open");
|
||||||
else {
|
else {
|
||||||
obj->data.tail.readlines =
|
obj->data.tail.readlines = 0;
|
||||||
0;
|
|
||||||
|
|
||||||
while (fgets
|
while (fgets(obj->data.tail.buffer, TEXT_BUFFER_SIZE*4, fp) != NULL) {
|
||||||
(obj->data.tail.
|
addtail(&head, obj->data.tail.buffer);
|
||||||
buffer,
|
obj->data.tail.readlines++;
|
||||||
TEXT_BUFFER_SIZE *
|
|
||||||
4, fp) != NULL) {
|
|
||||||
addtail(&head,
|
|
||||||
obj->data.
|
|
||||||
tail.
|
|
||||||
buffer);
|
|
||||||
obj->data.tail.
|
|
||||||
readlines++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
|
||||||
headtmp1 = head;
|
if (obj->data.tail.readlines > 0) {
|
||||||
if (obj->data.tail.
|
for (i = 0;i < obj->data.tail.wantedlines + 1 && i < obj->data.tail.readlines; i++) {
|
||||||
readlines > 0) {
|
addtail(&headtmp, head->data);
|
||||||
for (i = 0;
|
|
||||||
i <
|
|
||||||
obj->data.
|
|
||||||
tail.
|
|
||||||
wantedlines;
|
|
||||||
i++) {
|
|
||||||
if (head) {
|
|
||||||
addtail
|
|
||||||
(&headtmp2,
|
|
||||||
head->
|
|
||||||
data);
|
|
||||||
head = head->next;
|
head = head->next;
|
||||||
} else
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
headtmp2tmp =
|
strcpy(obj->data.tail.buffer, headtmp->data);
|
||||||
headtmp2;
|
headtmp = headtmp->next;
|
||||||
for (i = 0;
|
for (i = 1;i < obj->data.tail.wantedlines + 1 && i < obj->data.tail.readlines; i++) {
|
||||||
i <
|
if (headtmp) {
|
||||||
obj->data.
|
strncat(obj->data.tail.buffer, headtmp->data, TEXT_BUFFER_SIZE * 4 / obj->data.tail.wantedlines);
|
||||||
tail.
|
headtmp = headtmp->next;
|
||||||
wantedlines;
|
|
||||||
i++) {
|
|
||||||
if (headtmp2) {
|
|
||||||
strncat
|
|
||||||
(obj->
|
|
||||||
data.
|
|
||||||
tail.
|
|
||||||
buffer,
|
|
||||||
headtmp2->
|
|
||||||
data,
|
|
||||||
TEXT_BUFFER_SIZE
|
|
||||||
*
|
|
||||||
4
|
|
||||||
/
|
|
||||||
obj->
|
|
||||||
data.
|
|
||||||
tail.
|
|
||||||
wantedlines);
|
|
||||||
headtmp2
|
|
||||||
=
|
|
||||||
headtmp2->
|
|
||||||
next;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* this is good enough for now. */
|
/* get rid of any ugly newlines at the end */
|
||||||
snprintf(p, n,
|
if (obj->data.tail.buffer[strlen(obj->data.tail.buffer)-1] == '\n') {
|
||||||
"%s",
|
obj->data.tail.buffer[strlen(obj->data.tail.buffer)-1] = '\0';
|
||||||
obj->data.
|
|
||||||
tail.
|
|
||||||
buffer);
|
|
||||||
|
|
||||||
freetail
|
|
||||||
(headtmp2tmp);
|
|
||||||
}
|
}
|
||||||
freetail(headtmp1);
|
snprintf(p, n, "%s", obj->data.tail.buffer);
|
||||||
|
|
||||||
|
freetail(headtmp);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
strcpy(obj->data.tail.buffer, "Logfile Empty");
|
||||||
|
snprintf(p, n, "Logfile Empty");
|
||||||
|
}
|
||||||
|
freetail(head);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3898,9 +3847,9 @@ int main(int argc, char **argv)
|
|||||||
init_X11();
|
init_X11();
|
||||||
|
|
||||||
tmpstring1 = (char *)
|
tmpstring1 = (char *)
|
||||||
malloc(2 * TEXT_BUFFER_SIZE);
|
malloc(TEXT_BUFFER_SIZE);
|
||||||
tmpstring2 = (char *)
|
tmpstring2 = (char *)
|
||||||
malloc(2 * TEXT_BUFFER_SIZE);
|
malloc(TEXT_BUFFER_SIZE);
|
||||||
|
|
||||||
/* load current_config or CONFIG_FILE */
|
/* load current_config or CONFIG_FILE */
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user