Eventual backslash output conversion outside quotes for more terminal-safety
This commit is contained in:
@ -513,7 +513,7 @@ int Sfile_off_t_text(char text[80], off_t num, int flag)
|
||||
*/
|
||||
int Sfile_bsl_interpreter(char *text, int upto, int *eaten, int flag)
|
||||
{
|
||||
char *rpt, *wpt, num_text[4], wdummy[8];
|
||||
char *rpt, *wpt, num_text[8], wdummy[8];
|
||||
unsigned int num= 0;
|
||||
|
||||
*eaten= 0;
|
||||
@ -542,13 +542,14 @@ int Sfile_bsl_interpreter(char *text, int upto, int *eaten, int flag)
|
||||
*(wpt++)= 11;
|
||||
} else if(*rpt == '\\') {
|
||||
*(wpt++)= '\\';
|
||||
} else if(rpt[0] >= '0' && rpt[0] <= '9' &&
|
||||
rpt[1] >= '0' && rpt[1] <= '9' &&
|
||||
rpt[2] >= '0' && rpt[2] <= '9') {
|
||||
num_text[0]= *(rpt + 0);
|
||||
num_text[1]= *(rpt + 1);
|
||||
num_text[2]= *(rpt + 2);
|
||||
num_text[3]= 0;
|
||||
} else if(rpt[0] >= '0' && rpt[0] <= '7' &&
|
||||
rpt[1] >= '0' && rpt[1] <= '7' &&
|
||||
rpt[2] >= '0' && rpt[2] <= '7') {
|
||||
num_text[0]= '0';
|
||||
num_text[1]= *(rpt + 0);
|
||||
num_text[2]= *(rpt + 1);
|
||||
num_text[3]= *(rpt + 2);
|
||||
num_text[4]= 0;
|
||||
sscanf(num_text, "%o", &num);
|
||||
if(num > 0 && num <= 255) {
|
||||
rpt+= 2;
|
||||
@ -626,6 +627,8 @@ ex:;
|
||||
|
||||
|
||||
/* @param flag bit0= only encode inside quotes
|
||||
bit1= encode < 32 outside quotes except 7, 8, 9, 10, 12, 13
|
||||
bit2= encode in any case above 126
|
||||
*/
|
||||
int Sfile_bsl_encoder(char **result, char *text, int flag)
|
||||
{
|
||||
@ -650,8 +653,16 @@ int Sfile_bsl_encoder(char **result, char *text, int flag)
|
||||
sq_open= !(sq_open || dq_open);
|
||||
if(*rpt == '"')
|
||||
dq_open= !(sq_open || dq_open);
|
||||
if((*rpt >= 32 && *rpt <= 126 && *rpt != '\\') ||
|
||||
((flag & 1) && !(sq_open || dq_open))) {
|
||||
if(*rpt >= 32 && *rpt <= 126 && *rpt != '\\') {
|
||||
*(wpt++)= *rpt;
|
||||
continue;
|
||||
}
|
||||
if( ((flag & 1) && !(sq_open || dq_open)) &&
|
||||
!((flag & 2) && (*rpt >= 1 && * rpt <= 31 &&
|
||||
!(*rpt == 7 || *rpt == 8 || *rpt == 9 || *rpt == 10 ||
|
||||
*rpt == 12 || *rpt == 13))) &&
|
||||
!((flag & 4) && (*rpt > 126 || *rpt < 0)) &&
|
||||
!((flag & 6) && *rpt == '\\')) {
|
||||
*(wpt++)= *rpt;
|
||||
continue;
|
||||
}
|
||||
@ -4360,7 +4371,7 @@ bit15= with bit1 or bit2: close depicted log file
|
||||
/* Eventually perform backslash encoding of non-printable characters */
|
||||
if(((xorriso->bsl_interpretation & 32) && channel_no == 1) ||
|
||||
((xorriso->bsl_interpretation & 64) && channel_no == 2)) {
|
||||
ret= Sfile_bsl_encoder(&text, text, 1);
|
||||
ret= Sfile_bsl_encoder(&text, text, 1 | 2 | 4);
|
||||
if(ret <= 0)
|
||||
{ret= -1; goto ex;}
|
||||
}
|
||||
|
Reference in New Issue
Block a user