aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2003-12-16 22:18:34 +0000
committerDimitri Sokolyuk <demon@dim13.org>2003-12-16 22:18:34 +0000
commit604fb0829aa2bac9626cc4c03369355fc833faf6 (patch)
tree5e284c8e8d41b44ee141d22fcf92fd9a86aca76c
parent7526b9fe61aefb7d1631915362524390c174fdbb (diff)
fix output
-rw-r--r--watch.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/watch.c b/watch.c
index 0538e70..090e5d7 100644
--- a/watch.c
+++ b/watch.c
@@ -100,10 +100,10 @@ int main (int argc, char **argv) {
void loop(char *cmd) {
char buf;
FILE *pipe;
- int i;
+ int i,j;
while(!die_flag) {
- i = 0;
+ i = 0; j = 0;
clear();
if(!n_flag) {
title(cmd);
@@ -111,11 +111,16 @@ void loop(char *cmd) {
}
pipe = popen(cmd, "r");
while((buf = fgetc(pipe)) != EOF) {
- if((buf == '\0') || (buf == '\n'))
- i++;
+ if((buf == '\0') || (buf == '\n')) {
+ i++;
+ j = 0;
+ }
if(i >= LINES)
break;
- printw("%c",buf);
+ if(j < COLS) {
+ printw("%c",buf);
+ j++;
+ }
}
pclose(pipe);
refresh();
@@ -131,12 +136,12 @@ void title(char *cmd) {
struct tm *tm = localtime(&tval);
title = (char *)malloc(COLS + 1);
- sprintf(title, " Every %ds %s", period, cmd);
+ snprintf(title, COLS," Every %ds %s", period, cmd);
len = strlen(title);
if((COLS - len) > 0)
memset(title + len, ' ', COLS - len);
len = strlen(title);
- sprintf(title + len - 9, "%.2d:%.2d:%.2d ",
+ snprintf(title + len - 9, 10, "%.2d:%.2d:%.2d ",
tm->tm_hour, tm->tm_min, tm->tm_sec);
title[COLS] = '\0';