Made -pkt_output combinable with message output lists

This commit is contained in:
Thomas Schmitt 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) {

View File

@ -580,8 +580,9 @@ struct Xorriso_lsT;
output and eventual older redirections will not see new messages until
the redirection is ended by a call to Xorriso_pull_outlists() with the
stack_handle value returned by this call.
Redirected output is not written to the files of Xorriso_option_logfile()
and the Xorriso_option_pkt_output() protocol will not be applied.
If Xorriso_option_pkt_output() is set to "on", then it will consolidate
output in the result_list of Xorriso_fetch_outlists() resp.
Xorriso_pull_outlists().
@param xorriso The environment handle
@param stack_handle returns an id number which is unique as long as
its redirection is stacked. Do not interpret it and
@ -685,7 +686,9 @@ int Xorriso_pull_outlists(struct XorrisO *xorriso, int stack_handle,
@param xorriso The environment handle
@param result_handler Pointer to the function which shall be called with
each result message. A NULL pointer causes output
to be directed to stdout.
to be directed to stdout resp. to be interpreted
as -pkt_output format if this is enabled by
Xorriso_option_pkt_output().
@param result_handle The first argument of (*result_handler)(). It shall
point to a memory object that knows all necessary
external parameters for running (*result_handler)().
@ -1294,6 +1297,9 @@ int Xorriso_option_path_list(struct XorrisO *xorriso, char *adr, int flag);
int Xorriso_option_pathspecs(struct XorrisO *xorriso, char *mode, int flag);
/* Command -pkt_output */
/* Note: If output is redirected by Xorriso_push_outlists() then mode "on"
consolidates output in the result output list, not on stdout.
*/
int Xorriso_option_pkt_output(struct XorrisO *xorriso, char *mode, int flag);
/* Command -preparer_id */

View File

@ -1 +1 @@
#define Xorriso_timestamP "2012.09.15.170346"
#define Xorriso_timestamP "2012.09.16.141845"