--- multiplexer/en300468ts.c 2010/09/22 21:08:46 1.11 +++ multiplexer/en300468ts.c 2010/09/29 21:26:43 1.12 @@ -2028,6 +2028,7 @@ static unsigned int tab2ts(unsigned char static void argloop(int f0) { int i0 = 0; + int o0 = 0; char buf0[PATH_MAX]; do { int i, n, r, n0, n1, nst, tmo; @@ -2035,21 +2036,28 @@ static void argloop(int f0) struct sitab *st; struct sitab **pst; pollfd_init(); - if (f0 >= 0) { - n0 = pollfd_add(f0, POLLIN); - } else { - n0 = -1; - } + tmo = -1; + n0 = -1; + nst = -1; if (newtab != NULL) { - st = newtab; - nst = pollfd_add(st->u.a.fd, POLLIN); - while ((st = st->next) != NULL) { - pollfd_add(st->u.a.fd, POLLIN); - } + nst = pollfd_add(newtab->u.a.fd, POLLIN); + } else if ((r = tabline(&buf0[o0], i0))) { + o0 += r; + i0 -= r; + tmo = 0; } else { - nst = -1; + if ((i0 > 0) && (o0 > 0)) { + memmove(&buf0[0], &buf0[o0], i0); + o0 = 0; + } + if (i0 == sizeof(buf0)-1) { + buf0[sizeof(buf0)-1] = '\n'; + i0 += 1; + tmo = 0; + } else if (f0 >= 0) { + n0 = pollfd_add(f0, POLLIN); + } } - tmo = -1; if (outin == 0) { r = OUTBUF_SIZE; n1 = -1; @@ -2060,7 +2068,8 @@ static void argloop(int f0) } n1 = pollfd_add(STDOUT_FILENO, POLLOUT); } - for (i = 0; i <= TABLE_PID_LAST-TABLE_PID_FIRST; i++) { + i = 0; + while (tmo != 0 && i <= TABLE_PID_LAST-TABLE_PID_FIRST) { if ((tabin[i] > tabout[i]) && (r >= (((((tabbuf[i][tabout[i]+3] & 0x0F) << 8) + tabbuf[i][tabout[i]+4] + TS_HEADSLEN + TS_PFIELDLEN @@ -2077,8 +2086,8 @@ static void argloop(int f0) fprintf(stderr, "\n"); } #endif - break; } + i += 1; } gettimeofday(&tv, NULL); st = runtab; @@ -2269,18 +2278,6 @@ static void argloop(int f0) return; } i0 += r; - if (i0 == sizeof(buf0)-1) { - buf0[sizeof(buf0)-1] = '\n'; - i0 += 1; - } - i = 0; - while ((r = tabline(&buf0[i], i0))) { - i += r; - i0 -= r; - } - if (i0 > 0) { - memmove(&buf0[0], &buf0[i], i0); - } n -= 1; } } while (1);