Use stderr for message output.

This commit is contained in:
Hidetoshi Shimokawa 2003-01-24 03:40:36 +00:00
parent ff301db64c
commit 8604e72a9f
2 changed files with 37 additions and 31 deletions

View File

@ -56,17 +56,19 @@ extern int dvsend(int, char *, char, int);
static void
usage(void)
{
printf("fwcontrol [-g gap_count] [-b pri_req] [-c node]"
fprintf(stderr, "fwcontrol [-g gap_count] [-b pri_req] [-c node]"
" [-r] [-t] [-d node] [-l file] [-R file] [-S file]\n");
printf("\t-g: broadcast gap_count by phy_config packet\n");
printf("\t-b: set PRIORITY_BUDGET register on all supported nodes\n");
printf("\t-c: read configuration ROM\n");
printf("\t-r: bus reset\n");
printf("\t-t: read topology map\n");
printf("\t-d: hex dump of configuration ROM\n");
printf("\t-l: load and parse hex dump file of configuration ROM\n");
printf("\t-R: Receive DV stream\n");
printf("\t-S: Send DV stream\n");
fprintf(stderr, "\t-g: broadcast gap_count by phy_config packet\n");
fprintf(stderr,
"\t-b: set PRIORITY_BUDGET register on all supported nodes\n");
fprintf(stderr, "\t-c: read configuration ROM\n");
fprintf(stderr, "\t-r: bus reset\n");
fprintf(stderr, "\t-t: read topology map\n");
fprintf(stderr, "\t-d: hex dump of configuration ROM\n");
fprintf(stderr,
"\t-l: load and parse hex dump file of configuration ROM\n");
fprintf(stderr, "\t-R: Receive DV stream\n");
fprintf(stderr, "\t-S: Send DV stream\n");
exit(0);
}

View File

@ -122,8 +122,11 @@ int dvrecv(int d, char *filename, char ich, int count)
wbuf[0].iov_len = 0;
len = read(d, buf, BUFSIZE);
if (len < 0) {
if (errno == EAGAIN)
if (errno == EAGAIN) {
fprintf(stderr, "(EAGAIN)\n");
fflush(stderr);
continue;
}
err(1, "read failed");
}
ptr = (u_int32_t *) buf;
@ -135,7 +138,7 @@ int dvrecv(int d, char *filename, char ich, int count)
goto next;
}
#if 0
printf("%08x %08x %08x %08x\n",
fprintf(stderr, "%08x %08x %08x %08x\n",
htonl(ptr[0]), htonl(ptr[1]),
htonl(ptr[2]), htonl(ptr[3]));
#endif
@ -153,13 +156,13 @@ int dvrecv(int d, char *filename, char ich, int count)
dv++) {
#if 0
printf("(%d,%d) ", dv->sct, dv->dseq);
fprintf(stderr, "(%d,%d) ", dv->sct, dv->dseq);
#endif
if (dv->sct == DV_SCT_HEADER && dv->dseq == 0) {
#if 0
printf("%d(%d) ", k, m);
fprintf(stderr, "%d(%d) ", k, m);
#else
printf("%d", k%10);
fprintf(stderr, "%d", k%10);
#endif
pal = ((dv->payload[0] & DV_DSF_12) != 0);
nb = nblocks[pal];
@ -169,16 +172,17 @@ int dvrecv(int d, char *filename, char ich, int count)
npad = ((nb - m) % nb);
if (npad < 0)
npad += nb;
printf("(%d blocks padded)", npad);
fprintf(stderr, "(%d blocks padded)",
npad);
npad *= BLOCKSIZE;
npad = write(fd, pad, npad);
}
#endif
k++;
if (k % 30 == 0) { /* every second */
printf("\n");
fprintf(stderr, "\n");
}
fflush(stdout);
fflush(stderr);
m = 0;
}
if (k == 0 || (count > 0 && k > count))
@ -209,7 +213,7 @@ int dvrecv(int d, char *filename, char ich, int count)
}
}
close(fd);
printf("\n");
fprintf(stderr, "\n");
return 0;
}
@ -264,7 +268,8 @@ int dvsend(int d, char *filename, char ich, int count)
gettimeofday(&start, NULL);
#if 0
printf("%08x %08x %08x\n", htonl(hdr[0]), htonl(hdr[1]), htonl(hdr[2]));
fprintf(stderr, "%08x %08x %08x\n",
htonl(hdr[0]), htonl(hdr[1]), htonl(hdr[2]));
#endif
frames = 0;
packets = 0;
@ -278,7 +283,7 @@ int dvsend(int d, char *filename, char ich, int count)
while (dlen < DSIZE) {
len = read(fd, pbuf + dlen, DSIZE - dlen);
if (len <= 0) {
printf("\nend of file(len=%d)\n", len);
fprintf(stderr, "\nend of file(len=%d)\n", len);
goto send_end;
}
dlen += len;
@ -291,13 +296,13 @@ int dvsend(int d, char *filename, char ich, int count)
#endif
if (header) {
printf("%d", frames % 10);
fprintf(stderr, "%d", frames % 10);
frames ++;
if (count > 0 && frames > count)
break;
if (frames % 30 == 0)
printf("\n");
fflush(stdout);
fprintf(stderr, "\n");
fflush(stderr);
system = ((dv->payload[0] & DV_DSF_12) != 0);
f_cycle = (cycle_acc / frame_cycle[system].d) & 0xf;
f_frac = (cycle_acc % frame_cycle[system].d
@ -328,7 +333,8 @@ int dvsend(int d, char *filename, char ich, int count)
len = writev(d, wbuf, 1);
if (len < 0) {
if (errno == EAGAIN) {
printf("again"); fflush(stdout);
fprintf(stderr, "(EAGAIN)\n");
fflush(stderr);
goto again1;
}
err(1, "write failed");
@ -341,22 +347,20 @@ int dvsend(int d, char *filename, char ich, int count)
len = writev(d, wbuf, 2);
if (len < 0) {
if (errno == EAGAIN) {
printf("again"); fflush(stdout);
fprintf(stderr, "(EAGAIN)\n");
fflush(stderr);
goto again2;
}
err(1, "write failed");
}
#if 0
printf("."); fflush(stdout);
#endif
}
close(fd);
printf("\n");
fprintf(stderr, "\n");
send_end:
gettimeofday(&end, NULL);
rtime = end.tv_sec - start.tv_sec
+ (end.tv_usec - start.tv_usec) * 1e-6;
printf("%d frames, %.2f secs, %.2f frames/sec\n",
fprintf(stderr, "%d frames, %.2f secs, %.2f frames/sec\n",
frames, rtime, frames/rtime);
return 0;
}