Made -pkt_output combinable with message output lists

This commit is contained in:
2012-09-16 14:19:28 +00:00
parent 634b20ec05
commit c0b7304b61
3 changed files with 129 additions and 57 deletions

View File

@ -627,8 +627,8 @@ int Xorriso_write_to_channel(struct XorrisO *xorriso,
bit15= with bit1 to bit3: close depicted log file
*/
{
char *rpt, *npt, *text= NULL;
int ret= 1, info_redirected= 0, result_redirected= 0;
char *rpt, *npt, *text= NULL, *line= NULL;
int ret= 1, info_redirected= 0, result_redirected= 0, l;
char prefix[16];
FILE *logfile_fp, *pktlog_fp;
static int num_channels= 4;
@ -723,41 +723,35 @@ bit15= with bit1 to bit3: close depicted log file
if(xorriso->msglist_flags[xorriso->msglist_stackfill - 1] & 2)
info_redirected= 1;
}
if(result_redirected) {
if(channel_no==1 || channel_no==3) {
ret= Xorriso_write_to_msglist(xorriso,
&(xorriso->result_msglists[xorriso->msglist_stackfill - 1]),
text, 0);
if(ret <= 0)
{ ret= -1; goto ex; }
}
}
if(info_redirected) {
if(channel_no==2 || channel_no==3) {
ret= Xorriso_write_to_msglist(xorriso,
&(xorriso->info_msglists[xorriso->msglist_stackfill - 1]),
text, 0);
if(ret <= 0)
{ ret= -1; goto ex; }
}
}
if((channel_no == 1 && result_redirected) ||
(channel_no == 2 && info_redirected) ||
(result_redirected && info_redirected))
{ret= 1; goto ex;}
/* Non-redirected output */
if(!xorriso->packet_output) {
if(channel_no==1 || channel_no==3) {
printf("%s",text);
fflush(stdout);
if(result_redirected) {
ret= Xorriso_write_to_msglist(xorriso,
&(xorriso->result_msglists[xorriso->msglist_stackfill - 1]),
text, 0);
if(ret <= 0)
{ ret= -1; goto ex; }
} else {
printf("%s",text);
fflush(stdout);
}
}
if(channel_no==2 || channel_no==3) {
if(xorriso->stderr_fp != NULL) {
fprintf(xorriso->stderr_fp, "%s", text);
fflush(xorriso->stderr_fp);
} else
fprintf(stderr, "%s", text);
if(info_redirected) {
ret= Xorriso_write_to_msglist(xorriso,
&(xorriso->info_msglists[xorriso->msglist_stackfill - 1]),
text, 0);
if(ret <= 0)
{ ret= -1; goto ex; }
} else {
if(xorriso->stderr_fp != NULL) {
fprintf(xorriso->stderr_fp, "%s", text);
fflush(xorriso->stderr_fp);
} else
fprintf(stderr, "%s", text);
}
}
if(logfile_fp!=NULL) {
fprintf(logfile_fp,"%s",text);
@ -774,10 +768,12 @@ bit15= with bit1 to bit3: close depicted log file
prefix[2]= '0';
else
prefix[2]= '1';
if(xorriso->packet_output) {
ret= fwrite(prefix,5,1,stdout);
if(ret<=0)
{ret= 0; goto ex;}
if(!result_redirected) {
if(xorriso->packet_output) {
ret= fwrite(prefix,5,1,stdout);
if(ret<=0)
{ret= 0; goto ex;}
}
}
if(pktlog_fp!=NULL) {
ret= fwrite(prefix,5,1,pktlog_fp);
@ -786,12 +782,28 @@ bit15= with bit1 to bit3: close depicted log file
}
if(npt==NULL) {
if(xorriso->packet_output) {
ret= fwrite(rpt,strlen(rpt),1,stdout);
if(ret<=0)
{ret= 0; goto ex;}
ret= fwrite("\n",1,1,stdout);
if(ret<=0)
{ret= 0; goto ex;}
if(result_redirected) {
l= strlen(rpt);
Xorriso_alloc_meM(line, char, 5 + l + 1 + 1);
memcpy(line, prefix, 5);
memcpy(line + 5, rpt, l);
line[5 + l] = '\n';
line[5 + l + 1] = 0;
ret= Xorriso_write_to_msglist(xorriso,
&(xorriso->result_msglists[xorriso->msglist_stackfill - 1]),
line, 0);
Xorriso_free_meM(line);
line= NULL;
if(ret <= 0)
{ ret= -1; goto ex; }
} else {
ret= fwrite(rpt,strlen(rpt),1,stdout);
if(ret<=0)
{ret= 0; goto ex;}
ret= fwrite("\n",1,1,stdout);
if(ret<=0)
{ret= 0; goto ex;}
}
}
if(pktlog_fp!=NULL) {
ret= fwrite(rpt,strlen(rpt),1,pktlog_fp);
@ -804,9 +816,24 @@ bit15= with bit1 to bit3: close depicted log file
break;
} else {
if(xorriso->packet_output) {
ret= fwrite(rpt,npt+1-rpt,1,stdout);
if(ret<=0)
{ret= 0; goto ex;}
if(result_redirected) {
l= npt + 1 - rpt;
Xorriso_alloc_meM(line, char, 5 + l + 1);
memcpy(line, prefix, 5);
memcpy(line + 5, rpt, l);
line[5 + l] = 0;
ret= Xorriso_write_to_msglist(xorriso,
&(xorriso->result_msglists[xorriso->msglist_stackfill - 1]),
line, 0);
Xorriso_free_meM(line);
line= NULL;
if(ret <= 0)
{ ret= -1; goto ex; }
} else {
ret= fwrite(rpt,npt+1-rpt,1,stdout);
if(ret<=0)
{ret= 0; goto ex;}
}
}
if(pktlog_fp!=NULL) {
ret= fwrite(rpt,npt+1-rpt,1,pktlog_fp);
@ -824,6 +851,7 @@ bit15= with bit1 to bit3: close depicted log file
ex:
if(text != in_text && text != NULL)
free(text);
Xorriso_free_meM(line);
#ifdef Xorriso_fetch_with_msg_queueS
@ -1016,14 +1044,6 @@ ex:;
}
int Xorriso_result_handler_stdout(void *handle, char *text)
{
printf("%s", text);
fflush(stdout);
return(1);
}
int Xorriso_info_handler_stderr(void *handle, char *text)
{
struct XorrisO *xorriso;
@ -1040,6 +1060,52 @@ int Xorriso_info_handler_stderr(void *handle, char *text)
}
int Xorriso_result_handler_stdout(void *handle, char *text)
{
printf("%s", text);
fflush(stdout);
return(1);
}
int Xorriso_result_handler_pkt(void *handle, char *text)
{
int nl= -1, ret, l;
struct XorrisO *xorriso;
xorriso= (struct XorrisO *) handle;
if(!xorriso->packet_output)
return Xorriso_result_handler_stdout(handle, text);
/* Interpret pkt_output */
l= strlen(text);
if(l >= 5) {
if(strchr("RIM", text[0]) != NULL && text[1] == ':' &&
strchr("01", text[2]) != NULL && text[3] == ':' && text[4] == ' ')
nl= (text[2] == '1');
}
if(nl < 0) /* Not pkt_output format */
return Xorriso_result_handler_stdout(handle, text);
if(nl == 0) {
/* Suppress newline */
if(text[l - 1] == '\n')
l--;
}
if(text[0] == 'R') {
ret= fwrite(text + 5, l - 5, 1, stdout);
} else {
ret= fwrite(text + 5, l - 5, 1,
xorriso->stderr_fp != NULL ? xorriso->stderr_fp : stderr);
}
if(ret <= 0)
return(0);
return(1);
}
int Xorriso_process_msg_lists(struct XorrisO *xorriso,
struct Xorriso_lsT *result_list,
struct Xorriso_lsT *info_list,
@ -1053,7 +1119,7 @@ int Xorriso_process_msg_lists(struct XorrisO *xorriso,
handler= xorriso->msgw_result_handler;
handle= xorriso->msgw_result_handle;
if(handler == NULL) {
handler= Xorriso_result_handler_stdout;
handler= Xorriso_result_handler_pkt;
handle= xorriso;
}
for(lpt= result_list; lpt != NULL; lpt= lpt->next) {