Skip to content

Commit

Permalink
multilog: Read/write whole lines at a time
Browse files Browse the repository at this point in the history
  • Loading branch information
bruceg committed Mar 21, 2014
1 parent 86e3f20 commit 7921fe0
Showing 1 changed file with 15 additions and 23 deletions.
38 changes: 15 additions & 23 deletions multilog.c
Expand Up @@ -506,16 +506,15 @@ void doit(char **script)
const char *action;
int flagselected;
int flagtimestamp;
int linelen; /* 0 <= linelen <= MAXLINE */
int oldlinelen = sizeof line;
unsigned int linelen; /* 0 <= linelen <= MAXLINE */
unsigned int oldlinelen = sizeof line;

flagtimestamp = 0;
if (script[0])
if (script[0][0] == 't' || script[0][0] == 'T')
flagtimestamp = script[0][0];

for (i = 0;i <= MAXLINE;++i) line[i] = '\n';
linelen = 0;

flageof = 0;
for (;;) {
Expand All @@ -529,15 +528,8 @@ void doit(char **script)
: fmt_accustamp(line);
line[linelen++] = ' ';
}
while (linelen < MAXLINE) {
if (buffer_GETC(&ssin,&ch) <= 0) {
flageof = 1;
break;
}
if (ch == '\n')
break;
line[linelen++] = ch;
}
if (buffer_gets(&ssin,line+linelen,MAXLINE-linelen,'\n',&linelen) < 0)
flageof = 1;

for (i = linelen;i < oldlinelen;++i) line[i] = '\n';

Expand Down Expand Up @@ -595,18 +587,18 @@ void doit(char **script)
if (c[j].flagselected)
buffer_put(&c[j].ss,line,linelen);

if (linelen == MAXLINE)
for (;;) {
if (buffer_GETC(&ssin,&ch) <= 0) {
flageof = 1;
break;
}
if (ch == '\n')
break;
for (j = 0;j < cnum;++j)
if (c[j].flagselected)
buffer_PUTC(&c[j].ss,ch);
while (linelen == MAXLINE) {
linelen = 0;
if (buffer_gets(&ssin,line,MAXLINE,'\n',&linelen) < 0) {
flageof = 1;
break;
}
if (linelen == 0)
break;
for (j = 0;j < cnum;++j)
if (c[j].flagselected)
buffer_put(&c[j].ss,line,linelen);
}

for (j = 0;j < cnum;++j)
if (c[j].flagselected) {
Expand Down

0 comments on commit 7921fe0

Please sign in to comment.