"Fossies" - the Fresh Open Source Software Archive

Member "xorriso-1.5.4/xorriso/text_io.c" (30 Jan 2021, 149826 Bytes) of package /linux/misc/xorriso-1.5.4.pl02.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "text_io.c" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 1.5.2_vs_1.5.4.

    1 
    2 /* xorriso - creates, loads, manipulates and burns ISO 9660 filesystem images.
    3 
    4    Copyright 2007-2020 Thomas Schmitt, <scdbackup@gmx.net>
    5 
    6    Provided under GPL version 2 or later.
    7 
    8    This file contains the implementation of text i/o functions.
    9 */
   10 
   11 #ifdef HAVE_CONFIG_H
   12 #include "../config.h"
   13 #endif
   14 
   15 #include <ctype.h>
   16 #include <sys/types.h>
   17 #include <unistd.h>
   18 #include <stdlib.h>
   19 #include <stdio.h>
   20 #include <string.h>
   21 #include <sys/stat.h>
   22 #include <sys/time.h>
   23 #include <time.h>
   24 #include <errno.h>
   25 #include <signal.h>
   26 #include <pthread.h>
   27 #include <fcntl.h>
   28 
   29 /* O_BINARY is needed for Cygwin but undefined elsewhere */
   30 #ifndef O_BINARY
   31 #define O_BINARY 0
   32 #endif
   33 
   34 
   35 /* for -charset */
   36 #include <iconv.h>
   37 #include <langinfo.h>
   38 #include <locale.h>
   39 
   40 
   41 #ifdef Xorriso_with_readlinE
   42 #ifdef Xorriso_with_old_readlinE
   43 #include <readline.h>
   44 #include <history.h>
   45 #else /* Xorriso_with_old_readlinE */
   46 #include <readline/readline.h>
   47 #include <readline/history.h>
   48 #endif /* ! Xorriso_with_old_readlinE */
   49 #define Xorriso_with_line_editoR yes
   50 #endif /* Xorriso_with_readlinE */
   51 
   52 #ifdef Xorriso_with_editlinE
   53 #include <histedit.h>
   54 #define Xorriso_with_line_editoR yes
   55 #endif /* Xorriso_with_editlinE */
   56 
   57 
   58 #include "xorriso.h"
   59 #include "xorriso_private.h"
   60 #include "xorrisoburn.h"
   61 
   62 
   63 int Xorriso_protect_stdout(struct XorrisO *xorriso, int flag)
   64 {
   65  if(xorriso->dev_fd_1>=0)
   66    return(2);
   67  xorriso->dev_fd_1= dup(1);
   68  close(1);
   69  dup2(2,1);
   70  return(1);
   71 }
   72 
   73 #ifdef Xorriso_with_editlinE
   74 
   75 /* These have to be global and shared by all XorrisOs which might be active.
   76 */
   77 static EditLine *editline_handle= NULL;
   78 static History *editline_history= NULL;
   79 static int editline_is_initialized= 0;
   80 
   81 
   82 char *Xorriso__editline_prompt(EditLine *el_handle)
   83 {
   84   return "";
   85 }
   86 
   87 
   88 void Xorriso_init_editline(struct XorrisO *xorriso, int flag)
   89 {
   90  HistEvent ev;
   91 
   92  /* >>> Need mutex */
   93 
   94  if(editline_is_initialized != 0)
   95    return;
   96  editline_is_initialized= -1; /* Invalid */
   97 
   98  editline_handle= el_init(xorriso->progname, stdin, stdout, stderr);
   99  if(editline_handle == NULL)
  100    return;
  101  el_set(editline_handle, EL_EDITOR, "emacs");
  102  el_set(editline_handle, EL_PROMPT, &Xorriso__editline_prompt);
  103 
  104  editline_history= history_init();
  105  if(editline_history == NULL)
  106    return;
  107  history(editline_history, &ev, H_SETSIZE, 1000);
  108  el_set(editline_handle, EL_HIST, history, editline_history);
  109 
  110  editline_is_initialized= 1; /* Valid now */
  111  return;
  112 }
  113 
  114 
  115 int Xorriso__shutdown_editline(int flag)
  116 {
  117  if(editline_history != NULL)
  118    history_end(editline_history);
  119  editline_history= NULL;
  120  if(editline_handle != NULL)
  121    el_end(editline_handle);
  122  editline_handle= NULL;
  123  editline_is_initialized= 0;
  124  return(1);
  125 }
  126 
  127 #endif /* Xorriso_with_editlinE */
  128 
  129 #ifdef Xorriso_with_readlinE
  130 
  131 /* http://lists.gnu.org/archive/html/bug-readline/2014-06/msg00005.html */
  132 const char *Xorriso__readline_license(int flag)
  133 {
  134 #ifdef RL_VERSION_MAJOR
  135 #if RL_VERSION_MAJOR > 5
  136 
  137  return("GPLv3+");
  138 
  139 #endif
  140 #endif
  141 
  142  return("GPLv2+");
  143 }
  144 
  145 #endif /* Xorriso_with_readlinE */
  146 
  147 #ifdef Xorriso_with_line_editoR
  148 
  149 char *Xorriso_emul_readline(struct XorrisO *xorriso, int flag)
  150 {
  151 
  152 #ifdef Xorriso_with_editlinE
  153 
  154  const char *cpt;
  155  int count= 0;
  156  char *retpt;
  157 
  158  /* >>> Need mutex */
  159 
  160  Xorriso_init_editline(xorriso, 0);
  161  if(editline_is_initialized < 0) {
  162 
  163    /* >>> fallback */;
  164 
  165  }
  166 
  167  cpt= el_gets(editline_handle, &count);
  168  if(count == -1 || cpt == NULL)
  169    return(NULL);
  170  retpt= calloc(1, count + 1);
  171  if(retpt == NULL)
  172    return(NULL);
  173  memcpy(retpt, cpt, count);
  174  retpt[count]= 0;
  175  return(retpt);
  176 
  177 #else
  178 
  179 #ifdef Xorriso_with_readlinE
  180 
  181  char *cpt;
  182 
  183  cpt= readline("");
  184  return(cpt);
  185 
  186 #else
  187 
  188  return(NULL);
  189 
  190 #endif /* ! Xorriso_with_readlinE */
  191 #endif /* ! Xorriso_with_editlinE */
  192 }
  193 
  194 
  195 void Xorriso_emul_add_history(struct XorrisO *xorriso, char *line, int flag)
  196 {
  197 #ifdef Xorriso_with_editlinE
  198 
  199  HistEvent ev;
  200 
  201  /* >>> Need mutex */
  202 
  203  Xorriso_init_editline(xorriso, 0);
  204  if(editline_is_initialized < 0)
  205    return;
  206 
  207  history(editline_history, &ev, H_ENTER, line);
  208 
  209 #else
  210 
  211 #ifdef Xorriso_with_readlinE
  212 
  213  add_history(line);
  214 
  215 #else
  216 
  217  /* ??? How to raise protest ? */;
  218 
  219 #endif /* ! Xorriso_with_readlinE */
  220 #endif /* ! Xorriso_with_editlinE */
  221 }
  222 
  223 
  224 /* @param flag  bit1= do only report to fp
  225 */
  226 int Xorriso_status_history(struct XorrisO *xorriso, char *filter, FILE *fp,
  227                            int flag)
  228 {
  229 
  230 #ifdef Xorriso_with_editlinE
  231 
  232  int ret, l;
  233  HistEvent ev;
  234  int hc, i, was_end= 0;
  235  char *str= NULL;
  236 
  237 
  238  /* >>> Need mutex */
  239 
  240  Xorriso_init_editline(xorriso, 0);
  241  if(editline_is_initialized < 0)
  242    {ret= 0; goto ex;}
  243 
  244  Xorriso_alloc_meM(str, char, SfileadrL);
  245 
  246  ret= history(editline_history, &ev, H_LAST);
  247  for(hc= 0; ret != -1; hc++) {
  248    ret= history(editline_history, &ev, H_PREV);
  249    was_end = (strcmp(ev.str, "-end") == 0);
  250  }
  251  if(was_end)
  252    hc--;
  253  if(hc >= xorriso->status_history_max)
  254    i= hc - xorriso->status_history_max;
  255  else
  256    i= 0;
  257  
  258  ret= history(editline_history, &ev, H_LAST);
  259  for(; i < hc && ret != -1; i++) {
  260    /* Eat newline at line end */
  261    strncpy(str, ev.str, SfileadrL - 1);
  262    str[SfileadrL - 1]= 0;
  263    l= strlen(str);
  264    if(l > 0)
  265      if(str[l - 1] == '\n')
  266        str[l - 1]= 0;
  267 
  268    sprintf(xorriso->result_line, "-history ");
  269    Text_shellsafe(str, xorriso->result_line, 1);
  270    strcat(xorriso->result_line, "\n");
  271    Xorriso_status_result(xorriso, filter, fp, flag & 2);
  272    ret= history(editline_history, &ev, H_PREV);
  273  }
  274  ret= 1;
  275 ex:;
  276  Xorriso_free_meM(str);
  277  return(ret);
  278 
  279 #else
  280 #ifdef Xorriso_with_readlinE
  281 
  282  HIST_ENTRY **hl;
  283  int hc, i;
  284 
  285  hl= history_list();
  286  if(hl != NULL) {
  287    for(hc= 0; hl[hc] != NULL; hc++);
  288    if(hc > 0)
  289      if(strcmp(hl[hc-1]->line, "-end") == 0)
  290        hc--;
  291    if(hc >= xorriso->status_history_max)
  292      i= hc - xorriso->status_history_max;
  293    else
  294      i= 0;
  295    for(; i < hc; i++) {
  296      sprintf(xorriso->result_line, "-history ");
  297      Text_shellsafe(hl[i]->line, xorriso->result_line, 1);
  298      strcat(xorriso->result_line, "\n");
  299      Xorriso_status_result(xorriso, filter, fp, flag & 2);
  300    }
  301  }
  302  return(1);
  303 
  304 #else /* Xorriso_with_readlinE */
  305 
  306  return(0);
  307 
  308 #endif /* ! Xorriso_with_readlinE */
  309 #endif /* ! Xorriso_with_editlinE */
  310 
  311 }
  312 
  313 #endif /* Xorriso_with_line_editoR */
  314 
  315 
  316 int Xorriso_dialog_input(struct XorrisO *xorriso, char line[], int linesize,
  317                          int flag)
  318 /*
  319  bit0= do not write to history
  320  bit1= do not read input (but eventually write to history)
  321  bit2= do not write to history line which begin with "-history:" or "-history "
  322  bit3= enforce single line dialog mode
  323  bit4= do not read from xorriso->buffered_dialog
  324  bit5= write to history in any case (if it is enabled at compile time)
  325 */
  326 {
  327  char **argv= NULL, *linept, *why_append= "";
  328  int ret, argc= 0, base_length= 0, l, append_line;
  329 #ifdef Xorriso_with_line_editoR
  330  static char last_input[SfileadrL]= {""};
  331  int no_history= 0;
  332  char *cpt= NULL;
  333 #endif /* Xorriso_with_line_editoR */
  334  double tdiff;
  335  struct timeval tv;
  336  struct Xorriso_lsT *next_lst;
  337 
  338  gettimeofday(&tv, NULL);
  339  tdiff= tv.tv_sec+(1.e-6*(double) tv.tv_usec);
  340 
  341  fflush(stdout);
  342  linept= line;
  343 
  344 #ifdef Xorriso_with_line_editoR
  345  no_history= (flag & 1) || xorriso->use_stdin;
  346 #endif
  347 
  348 get_single:;
  349 
  350  if(xorriso->buffered_dialog != NULL && !(flag & (16 | 2))) {
  351    /* Consume next buffered line */
  352    next_lst= Xorriso_lst_get_next(xorriso->buffered_dialog, 0);
  353    strcpy(line, Xorriso_lst_get_text(xorriso->buffered_dialog, 0));
  354    Xorriso_lst_destroy(&(xorriso->buffered_dialog), 0);
  355    xorriso->buffered_dialog= next_lst;
  356    goto process_single;
  357  }
  358 
  359 #ifdef Xorriso_with_line_editoR
  360 
  361  if(xorriso->use_stdin || xorriso->dev_fd_1>=0 ||
  362     xorriso->tolerate_stdin_eof) {
  363    if(flag&2) {
  364      if(flag & 32)
  365        goto put_into_history;
  366      {ret= 1; goto ex;}
  367    }
  368    if(Sfile_fgets_n(linept,linesize - base_length - 1, stdin,
  369                       (xorriso->dialog == 2)) == NULL) {
  370      if(xorriso->tolerate_stdin_eof)
  371        {ret= -2; goto ex;}
  372      /* need a very dramatic end */
  373      kill(getpid(),SIGHUP);
  374      {ret= -1; goto ex;}
  375    }
  376    goto process_single;
  377  }
  378  if(flag&2) {
  379    cpt= NULL;
  380  } else {
  381    cpt= Xorriso_emul_readline(xorriso, 0);
  382    if(cpt==NULL) {
  383      /* need a very dramatic end */
  384      kill(getpid(),SIGHUP);
  385      {ret= -1; goto ex;}
  386    }
  387    l= strlen(cpt);
  388    if(l >= linesize - base_length - 1) {
  389      strncpy(linept, cpt, linesize - 1);
  390      line[linesize - 1]= 0;
  391      sprintf(xorriso->info_text,"Input line too long !");
  392      Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
  393      goto new_empty;
  394    } else 
  395      strcpy(linept, cpt);
  396  }
  397 
  398 #else /* Xorriso_with_line_editoR */
  399 
  400  if(flag&2)
  401    {ret= 1; goto ex;}
  402  if(Sfile_fgets_n(linept, linesize - base_length - 1, stdin,
  403                   (xorriso->dialog == 2)) == NULL) {
  404    if(xorriso->tolerate_stdin_eof)
  405      {ret= -2; goto ex;}
  406    /* need a very dramatic end */
  407    kill(getpid(),SIGHUP);
  408    {ret= -1; goto ex;}
  409  }
  410 
  411 #endif /* ! Xorriso_with_line_editoR */
  412 
  413 process_single:;
  414 
  415  if(xorriso->dialog == 2 && !(flag & 8)) {
  416    append_line= 0;
  417    if(linept != line && strcmp(linept, "@@@") == 0) {
  418      sprintf(xorriso->info_text, "Incomplete input line cleared by %s",
  419              linept);
  420      Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "NOTE",0);
  421 new_empty:;
  422      line[0]= 0;
  423      linept= line;
  424      sprintf(xorriso->info_text, "-------------------------------------\n");
  425      Xorriso_info(xorriso,0);
  426      sprintf(xorriso->info_text, "Enter new text for empty input line :\n");
  427      Xorriso_info(xorriso,0);
  428      goto get_single;
  429    }
  430    l= strlen(line);
  431    ret= Sfile_make_argv("", line, &argc, &argv, 16);
  432    if(ret < 0)
  433      goto ex;
  434    if(ret == 0 && !append_line) {
  435      /* append a newline character */
  436      if(l >= linesize - 1) {
  437        sprintf(xorriso->info_text,"Input line too long !");
  438        Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
  439        goto new_empty;
  440      }
  441      line[l]= '\n';
  442      line[l + 1]= 0;
  443      append_line= 1;
  444      why_append= "Quoted newline char";
  445    }
  446    if(l > 0 && !append_line)
  447      if(line[l - 1] == '\\') {
  448        line[l - 1]= 0;
  449        append_line= 1;
  450        why_append= "Trailing backslash ";
  451      }
  452    if(append_line) {
  453      base_length= strlen(line);
  454      linept= line + base_length;
  455      sprintf(xorriso->info_text,
  456           "---------------------------------------------------------------\n");
  457      Xorriso_info(xorriso,0);
  458      sprintf(xorriso->info_text,
  459              "%s : Enter rest of line (or @@@ to clear it) :\n", why_append);
  460      Xorriso_info(xorriso,0);
  461      goto get_single;
  462    }
  463  }
  464 
  465 #ifdef Xorriso_with_line_editoR
  466 
  467 put_into_history:;
  468  if((flag & 32) || (line[0]!=0 && strcmp(last_input,line)!=0 && !no_history)) {
  469    if(!((flag&4) && 
  470       (strncmp(line,"-history:",9)==0 || strncmp(line,"-history ",9)==0))) {
  471      Xorriso_emul_add_history(xorriso, line, 0);
  472      strncpy(last_input,line,sizeof(last_input)-1);
  473      last_input[sizeof(last_input)-1]= 0;
  474    }
  475  }
  476 
  477 #endif /* Xorriso_with_line_editoR */
  478 
  479  ret= 1;
  480 ex:;
  481 
  482 #ifdef Xorriso_with_line_editoR
  483  if(cpt!=NULL)
  484    free(cpt);
  485 #endif
  486 
  487  gettimeofday(&tv, NULL);
  488  xorriso->idle_time+= tv.tv_sec+(1.e-6*(double) tv.tv_usec)-tdiff;
  489  return(ret);
  490 }
  491 
  492 
  493 int Xorriso_request_confirmation(struct XorrisO *xorriso, int flag)
  494 /*
  495  bit0= important operation going on: 
  496        demand confirmation of abort, only abort on @@@
  497  bit1= mark '@' and '@@' by return 4
  498  bit2= accept: i|n= ignore | do not remove , r|y= retry | remove , q|x= abort
  499  bit3= @@@ = 'done reading' rather than 'abort'
  500  bit4= in non-dialog mode return 6 rather than 1
  501 */
  502 /* return: <=0 error
  503            1= go on | do not remove existing file
  504            2= abort
  505            3= redo request for confirmation
  506            4= see flag bit1
  507           (5= skip volume)
  508            6= retry failed operation | remove existing file
  509  */
  510 {
  511  int ret;
  512  char *line= NULL, *cpt, *previous_line= NULL;
  513  char *abort_req_text,*abort_really_text;
  514 
  515  Xorriso_alloc_meM(line, char, SfileadrL);
  516  Xorriso_alloc_meM(previous_line, char, SfileadrL);
  517 
  518  if(!xorriso->dialog) {
  519    if(flag&16)
  520      {ret= 6; goto ex;}
  521    {ret= 1; goto ex;}
  522  }
  523  if(flag&8) {
  524    abort_req_text= "request to end";
  525    abort_really_text= "done reading";
  526  } else {
  527    abort_req_text= "request to abort";
  528    abort_really_text= "abort this command";
  529  }
  530  ret= Xorriso_dialog_input(xorriso,line, SfileadrL, 1);
  531  xorriso->result_line_counter= 0;
  532  xorriso->result_page_counter++;
  533  if(ret<=0)
  534    if(xorriso->result_page_length>0)
  535      xorriso->result_page_length= -xorriso->result_page_length;
  536 
  537  cpt= line;
  538  if(strcmp(cpt,"@@@")==0 ||
  539     strcmp(cpt,"x")==0 || strcmp(cpt,"X")==0 ||
  540     strcmp(cpt,"q")==0 || strcmp(cpt,"Q")==0) {
  541    if(flag&1) {
  542      strcpy(previous_line,cpt);
  543      sprintf(xorriso->info_text,
  544              "... [%s = %s registered. Really %s ? (y/n) ] ...\n",
  545              cpt,abort_req_text,abort_really_text);
  546      Xorriso_info(xorriso,0);
  547      ret= Xorriso_dialog_input(xorriso,line, SfileadrL, 1);
  548      if(ret<=0)
  549        goto ex;
  550      cpt= line;
  551      if(strcmp(cpt,previous_line)==0 || 
  552         ((*cpt=='Y' || *cpt=='y' || *cpt=='j' || *cpt=='J' || *cpt=='1') &&
  553            *(cpt+1)==0)) {
  554        xorriso->request_to_abort= 1;
  555        sprintf(xorriso->info_text,
  556                "------- ( %s confirmed )\n",abort_req_text);
  557        Xorriso_info(xorriso,0);
  558        {ret= 2; goto ex;}
  559      }
  560      sprintf(xorriso->info_text, "....... ( %s revoked )\n",abort_req_text);
  561      Xorriso_info(xorriso,0);
  562      {ret= 3; goto ex;}
  563    }
  564    xorriso->request_to_abort= 1;
  565    sprintf(xorriso->info_text,
  566 "----------- [%s = request to abort registered. Operation ends ] ------------\n",
  567            cpt);
  568    Xorriso_info(xorriso,0);
  569    {ret= 2; goto ex;}
  570  } else if(*cpt=='@') {
  571    if(strcmp(cpt,"@@")==0) {
  572      goto klammer_affe;
  573      
  574    } else if(strcmp(cpt,"@")==0) {
  575 klammer_affe:;
  576      if(xorriso->result_page_length>0)
  577        xorriso->result_page_length= -xorriso->result_page_length;
  578      if(flag&1) {
  579        sprintf(xorriso->info_text,
  580 "... [@ = prompt suppression registered. Prompting disabled temporarily ] ...\n");
  581        Xorriso_info(xorriso,0);
  582      }
  583 
  584    } else {
  585      Xorriso_dialog_input(xorriso,cpt,strlen(line)+1,2); /* write to history */
  586      sprintf(xorriso->info_text,
  587  "--- Unrecognized input beginning with @. Please enter something else.\n");
  588      Xorriso_info(xorriso,0);
  589      {ret= 3; goto ex;}
  590    }
  591    if(flag&2)
  592      {ret= 4; goto ex;}
  593    if(flag&1)
  594      {ret= 3; goto ex;}
  595    {ret= 1; goto ex;}
  596  } else if(flag&4) {
  597 
  598    if(strcmp(cpt,"i")==0 || strcmp(cpt,"I")==0 ||
  599       strcmp(cpt,"n")==0 || strcmp(cpt,"N")==0 ||
  600       *cpt==0) { 
  601      {ret= 1; goto ex;}
  602    } else if(strcmp(cpt,"r")==0 || strcmp(cpt,"R")==0 ||
  603              strcmp(cpt,"y")==0 || strcmp(cpt,"Y")==0) {
  604      {ret= 6; goto ex;}
  605    } else {
  606      /* >>> unknown input */
  607      sprintf(xorriso->info_text,
  608           "--- Please enter one of : empty line, i,n, r,y, q,x, @, @@@\n");
  609      Xorriso_info(xorriso,0);
  610      {ret= 3; goto ex;}
  611    }
  612 
  613  } else if(*cpt!=0 && !(flag&1)) {
  614    Xorriso_dialog_input(xorriso,cpt,strlen(line)+1,2); /* write to history */
  615    strcpy(xorriso->pending_option,cpt);
  616    xorriso->request_to_abort= 1;
  617    sprintf(xorriso->info_text,
  618 "-------------- [ Input of option registered. Operation ends ] ---------------\n");
  619    Xorriso_info(xorriso,0);
  620    {ret= 2; goto ex;}
  621 
  622  } else if(*cpt!=0) {
  623    Xorriso_dialog_input(xorriso,cpt,strlen(line)+1,2); /* write to history */
  624    sprintf(xorriso->info_text,
  625            "--- Please enter one of : empty line, @, @@@\n");
  626    Xorriso_info(xorriso,0);
  627    {ret= 3; goto ex;}
  628  }
  629  ret= 1;
  630 ex:;
  631  Xorriso_free_meM(line);
  632  Xorriso_free_meM(previous_line);
  633  return(ret);
  634 }
  635 
  636 
  637 /* @param flag bit0= quoted multiline mode
  638                bit1= release allocated memory and return 1
  639                bit2= with bit0: warn of empty text arguments
  640                bit3= deliver as single quoted text including all whitespace
  641                      and without any backslash interpretation
  642    @return -1=out of memory , 0=line format error , 1=ok, go on , 2=done
  643 */
  644 int Xorriso_read_lines(struct XorrisO *xorriso, FILE *fp, int *linecount,
  645                        int *argc, char ***argv, int flag)
  646 {
  647  char *line= NULL, *linept, *fgot;
  648  int l, base_length, append_line, ret, mem_linecount, i;
  649 
  650  Sfile_make_argv("", line, argc, argv, 2);
  651  if(flag & 2)
  652    {ret= 1; goto ex;}
  653 
  654  Xorriso_alloc_meM(line, char, 5 * SfileadrL + 2);
  655 
  656  mem_linecount= *linecount;
  657  linept= line;
  658  base_length= 0;
  659  while(1) {
  660    fgot= Sfile_fgets_n(linept, SfileadrL - base_length - 1, fp,
  661                        !!(flag & (1 | 8)));
  662    if(fgot == NULL) {
  663      if(ferror(fp))
  664        {ret= 0; goto ex;}
  665      if(linept != line) {
  666        sprintf(xorriso->info_text,"Open quotation mark at end of input");
  667        Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
  668        {ret= 0; goto ex;}
  669      }
  670      {ret= 2; goto ex;}
  671    }
  672    l= strlen(line);
  673    (*linecount)++;
  674    append_line= 0;
  675    if(flag & 1) { /* check whether the line is incomplete yet */
  676      ret= Sfile_make_argv("", line, argc, argv, 16);
  677      if(ret < 0)
  678        goto ex;
  679      if(ret == 0 && !append_line) {
  680        line[l]= '\n';
  681        line[l + 1]= 0;
  682        append_line= 1;
  683      }
  684      if(l > 0 && !append_line)
  685        if(line[l - 1] == '\\') {
  686          line[l - 1]= 0;
  687          append_line= 1;
  688        }
  689    }
  690    if(l >= SfileadrL) {
  691      sprintf(xorriso->info_text,"Input line too long !");
  692      Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
  693      {ret= 0; goto ex;}
  694    }
  695    if(!append_line)
  696  break;
  697    base_length= strlen(line);
  698    linept= line + base_length;
  699  }
  700  if((flag & 1) && !(flag & 8)) {
  701    ret= Sfile_make_argv("", line, argc, argv,
  702                         1 | ((xorriso->bsl_interpretation & 3) << 5));
  703    if(ret < 0)
  704      goto ex;
  705    if(flag & 4)
  706      for(i= 0; i < *argc; i++) {
  707        if((*argv)[i][0] == 0) {
  708          sprintf(xorriso->info_text, "Empty text as quoted argument in ");
  709        } else if(strlen((*argv)[i]) >= SfileadrL) {
  710          (*argv)[i][SfileadrL - 1]= 0;
  711          sprintf(xorriso->info_text,
  712                  "Input text too long and now truncated in");
  713        } else
  714      continue;
  715        if(mem_linecount + 1 < *linecount)
  716          sprintf(xorriso->info_text + strlen(xorriso->info_text),
  717                  "lines %d to %d", mem_linecount + 1, *linecount);
  718        else
  719          sprintf(xorriso->info_text + strlen(xorriso->info_text),
  720                  "line %d", mem_linecount + 1);
  721        Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "WARNING", 0);
  722      }
  723  } else {
  724    (*argv)= Smem_malloC(sizeof(char *));
  725    if(*argv == NULL)
  726      {ret= -1; goto ex;}
  727    (*argv)[0]= strdup(line);
  728    if((*argv)[0] == NULL) {
  729      free(*argv);
  730      (*argv)= NULL;
  731      {ret= -1; goto ex;}
  732    }
  733    *argc= 1;
  734  }
  735  ret= 1;
  736 ex:;
  737  Xorriso_free_meM(line);
  738  return(ret);
  739 }
  740 
  741 
  742 int Xorriso_predict_linecount(struct XorrisO *xorriso, char *line,
  743                               int *linecount, int flag)
  744 {
  745  int width,l;
  746  char *spt,*ept;
  747 
  748  *linecount= 0;
  749  spt= line;
  750  width= xorriso->result_page_width;
  751  while(1) {
  752    ept= strchr(spt,'\n');
  753    if(ept==NULL)
  754      l= strlen(spt);
  755    else
  756      l= ept-spt;
  757    l+= xorriso->result_open_line_len;
  758    if(ept!=NULL && l==0)
  759      (*linecount)++;
  760    else {
  761      (*linecount)+= l/width;
  762      if(ept==NULL) {
  763        xorriso->result_open_line_len= l%width;
  764  break;
  765      }
  766      (*linecount)+= !!(l%width);
  767    }
  768    xorriso->result_open_line_len= 0;
  769    spt= ept+1;
  770  }
  771  return(1);
  772 }
  773 
  774 
  775 int Xorriso_pager(struct XorrisO *xorriso, char *line, int flag)
  776 /*
  777  bit1= mark '@' by return 4
  778 */
  779 /* return: <=0 error , 1=go on , 2=abort , 4=see flag bit1*/
  780 {
  781  int ret,linecount;
  782  char *info_text= NULL;
  783 
  784  if(xorriso->result_page_length<=0 || xorriso->request_not_to_ask ||
  785     xorriso->dialog == 0)
  786    {ret= 1; goto ex;}
  787  Xorriso_predict_linecount(xorriso,line,&linecount,0);
  788  if(xorriso->result_line_counter+linecount>xorriso->result_page_length) {
  789 ask_for_page:;
  790    if(info_text == NULL)
  791      Xorriso_alloc_meM(info_text, char, 10*SfileadrL);
  792    strcpy(info_text,xorriso->info_text);
  793    sprintf(xorriso->info_text,"\n");
  794    Xorriso_info(xorriso,0);
  795    sprintf(xorriso->info_text,
  796 ".... [Press Enter to continue. @,Enter avoids further stops. @@@ aborts] ....\n");
  797    Xorriso_info(xorriso,0);
  798    ret= Xorriso_request_confirmation(xorriso,flag&2);
  799    strcpy(xorriso->info_text,info_text);
  800    if(ret<=0)
  801      goto ex;
  802    if(ret==2)
  803      {ret= 2; goto ex;}
  804    if(ret==3)
  805      goto ask_for_page;
  806  }
  807  xorriso->result_line_counter+= linecount;
  808  ret= 1;
  809 ex:;
  810  Xorriso_free_meM(info_text);
  811  return(ret);
  812 }
  813 
  814 
  815 /* @param flag bit0= no error message in case of failure
  816 */
  817 static int Xorriso_obtain_lock(struct XorrisO *xorriso,
  818                                pthread_mutex_t *lock_handle,
  819                                char *purpose, int flag)
  820 {
  821  int ret;
  822  static int complaints= 0, complaint_limit= 5; 
  823 
  824  ret= pthread_mutex_lock(lock_handle);
  825  if(ret != 0) {
  826    if(flag & 1)
  827      return(-1);
  828    /* Cannot report failure through the failing message output system */
  829    complaints++;
  830    if(complaints <= complaint_limit)
  831      fprintf(stderr,
  832              "xorriso : pthread_mutex_lock() for %s returns %d\n",
  833              purpose, ret);
  834    return(-1);
  835  }
  836  return(1);
  837 }
  838 
  839 
  840 /* @param flag bit0= no error message in case of failure
  841 */
  842 static int Xorriso_release_lock(struct XorrisO *xorriso,
  843                                pthread_mutex_t *lock_handle,
  844                                char *purpose, int flag)
  845 {
  846  int ret;
  847  static int complaints= 0, complaint_limit= 5; 
  848 
  849  ret= pthread_mutex_unlock(lock_handle);
  850  if(ret != 0) {
  851    if(flag & 1)
  852      return(0);
  853    /* Cannot report failure through the failing message output system */
  854    complaints++;
  855    if(complaints <= complaint_limit)
  856      fprintf(stderr,
  857              "xorriso : pthread_mutex_unlock() for %s returns %d\n",
  858              purpose, ret);
  859    return(0);
  860  }
  861  return(1);
  862 }
  863 
  864 
  865 static int Xorriso_lock_outlists(struct XorrisO *xorriso, int flag)
  866 {
  867  int ret;
  868 
  869  ret= Xorriso_obtain_lock(xorriso, &(xorriso->result_msglists_lock),
  870                           "outlists", 0);
  871  return(ret);
  872 }
  873 
  874 
  875 static int Xorriso_unlock_outlists(struct XorrisO *xorriso, int flag)
  876 {
  877  int ret;
  878 
  879  ret= Xorriso_release_lock(xorriso, &(xorriso->result_msglists_lock),
  880                            "outlists", 0);
  881  return(ret);
  882 }
  883 
  884 
  885 static int Xorriso_write_to_msglist(struct XorrisO *xorriso,
  886                                     struct Xorriso_lsT **xorriso_msglist,
  887                                     char *text, int flag)
  888 {
  889  int ret, locked= 0;
  890  struct Xorriso_lsT *msglist;
  891 
  892  ret= Xorriso_lock_outlists(xorriso, 0);
  893  if(ret <= 0)
  894    goto ex;
  895  locked= 1;
  896  msglist= *xorriso_msglist;
  897  ret= Xorriso_lst_append_binary(&msglist, text, strlen(text) + 1, 0);
  898  if(ret <= 0) {
  899    ret= -1; goto ex;
  900  }
  901  if(*xorriso_msglist == NULL)
  902    *xorriso_msglist= msglist;
  903  ret= 1;
  904 ex:;
  905  if(locked)
  906    Xorriso_unlock_outlists(xorriso, 0);
  907  return(ret);
  908 }
  909 
  910 
  911 int Xorriso_write_to_channel(struct XorrisO *xorriso,
  912                              char *in_text, int channel_no, int flag)
  913 /*
  914  bit0= eventually backslash encode linefeeds
  915  bit1= text is the name of the log file for the given channel 
  916  bit2= text is the name of the consolidated packet log file for all channels 
  917  bit3= text is the name of the stderr redirection file
  918 bit15= with bit1 to bit3: close depicted log file
  919 */
  920 {
  921  char *rpt, *npt, *text= NULL, *line= NULL;
  922  int ret= 1, info_redirected= 0, result_redirected= 0, l;
  923  char prefix[16];
  924  FILE *logfile_fp, *pktlog_fp;
  925  static int num_channels= 4;
  926  static char channel_prefixes[4][4]= {".","R","I","M"};
  927  int Xorriso_sieve_filter_msg(struct XorrisO *xorriso, char *msg, int flag);
  928 
  929 #ifdef Xorriso_fetch_with_msg_queueS
  930  static int complaints= 0, complaint_limit= 5;
  931  int locked= 0, uret;
  932 #endif
  933 
  934  text= in_text; /* might change due to backslash encoding */
  935 
  936  if(channel_no<0 || channel_no>=num_channels)
  937    {ret= -1; goto ex;}
  938 
  939 #ifdef Xorriso_fetch_with_msg_queueS
  940  ret= pthread_mutex_lock(&(xorriso->write_to_channel_lock));
  941  if(ret != 0) {
  942    /* Cannot report failure through the failing message output system */
  943    complaints++;
  944    if(complaints <= complaint_limit)
  945      fprintf(stderr,
  946            "xorriso : pthread_mutex_lock() for write_to_channel returns %d\n",
  947            ret);
  948    /* Intentionally not aborting here */;
  949  } else
  950    locked= 1;
  951 #endif /* Xorriso_fetch_with_msg_queueS */
  952 
  953  /* Logfiles */
  954  logfile_fp= xorriso->logfile_fp[channel_no];
  955  pktlog_fp= xorriso->pktlog_fp;
  956  if((flag&2) && logfile_fp!=NULL) {
  957    fprintf(logfile_fp,
  958      "! end ! end ! end ! end ! end ! end ! end ! end xorriso log : %s : %s\n",
  959            channel_prefixes[channel_no],Sfile_datestr(time(0),1|2|256));
  960    fclose(logfile_fp);
  961    xorriso->logfile_fp[channel_no]= logfile_fp= NULL;
  962  }
  963  if((flag&4) && pktlog_fp!=NULL) {
  964    fprintf(pktlog_fp,
  965  "I:1:! end ! end ! end ! end ! end ! end ! end ! end xorriso log : %s : %s\n",
  966            channel_prefixes[channel_no],Sfile_datestr(time(0),1|2|256));
  967    fclose(pktlog_fp);
  968    xorriso->pktlog_fp= pktlog_fp= NULL;
  969  }
  970  if((flag & 8) && xorriso->stderr_fp != NULL) {
  971    fclose(xorriso->stderr_fp);
  972    xorriso->stderr_fp= NULL;
  973  }
  974  if(flag&(1<<15))
  975    {ret= 1; goto ex;}
  976  if((flag&2)) {
  977    xorriso->logfile_fp[channel_no]= logfile_fp= fopen(text,"a");
  978    if(logfile_fp==NULL)
  979      {ret= 0; goto ex;}
  980    fprintf(logfile_fp,
  981   "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! xorriso log : %s : %s\n",
  982            channel_prefixes[channel_no],Sfile_datestr(time(0),1|2|256));
  983    fflush(logfile_fp);
  984  }
  985  if((flag&4)) {
  986    xorriso->pktlog_fp= pktlog_fp= fopen(text,"a");
  987    if(pktlog_fp==NULL)
  988      {ret= 0; goto ex;}
  989    fprintf(pktlog_fp,
  990   "I:1:!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! xorriso log : . : %s\n",
  991            Sfile_datestr(time(0),1|2|256));
  992    fflush(pktlog_fp);
  993  }
  994  if(flag & 8) {
  995    ret= truncate(text, (off_t) 0);
  996    if(ret == -1 && errno != ENOENT)
  997      {ret= 0; goto ex;}
  998    xorriso->stderr_fp= fopen(text, "a");
  999    if(xorriso->stderr_fp == NULL)
 1000      {ret= 0; goto ex;}
 1001  }
 1002  if(flag & (2 | 4 | 8))
 1003    {ret= 1; goto ex;}
 1004 
 1005  /* Eventually perform backslash encoding of non-printable characters */
 1006  if(((xorriso->bsl_interpretation & 32) && channel_no == 1) ||
 1007     ((xorriso->bsl_interpretation & 64) && channel_no == 2)) {
 1008    ret= Sfile_bsl_encoder(&text, text, strlen(text), 1 | 2 | 4);
 1009    if(ret <= 0)
 1010      {ret= -1; goto ex;}
 1011  }
 1012 
 1013  /* Pick interesting words for the Xorriso_sieve API */
 1014  Xorriso_sieve_filter_msg(xorriso, text,
 1015                           (channel_no > 0 ? channel_no - 1 : 0));
 1016 
 1017  /* Eventually perform message redirection */
 1018  if(xorriso->msglist_stackfill > 0) {
 1019    if(xorriso->msglist_flags[xorriso->msglist_stackfill - 1] & 1)
 1020      result_redirected= 1;
 1021    if(xorriso->msglist_flags[xorriso->msglist_stackfill - 1] & 2)
 1022      info_redirected= 1;
 1023  }
 1024 
 1025  /* Non-redirected output */
 1026  if(!xorriso->packet_output) {
 1027    if(channel_no==1 || channel_no==3) {
 1028      if(result_redirected) {
 1029        ret= Xorriso_write_to_msglist(xorriso,
 1030                  &(xorriso->result_msglists[xorriso->msglist_stackfill - 1]),
 1031                  text, 0);
 1032        if(ret <= 0)
 1033          { ret= -1; goto ex; }
 1034      } else {
 1035        printf("%s",text);
 1036        fflush(stdout);
 1037      }
 1038    }
 1039    if(channel_no==2 || channel_no==3) {
 1040      if(info_redirected) {
 1041        ret= Xorriso_write_to_msglist(xorriso,
 1042                  &(xorriso->info_msglists[xorriso->msglist_stackfill - 1]),
 1043                  text, 0);
 1044        if(ret <= 0)
 1045          { ret= -1; goto ex; }
 1046      } else {
 1047        if(xorriso->stderr_fp != NULL) {
 1048          fprintf(xorriso->stderr_fp, "%s", text);
 1049          fflush(xorriso->stderr_fp);
 1050        } else
 1051          fprintf(stderr, "%s", text);
 1052      }
 1053    }
 1054    if(logfile_fp!=NULL) {
 1055      fprintf(logfile_fp,"%s",text);
 1056      fflush(logfile_fp);
 1057    }
 1058    if(pktlog_fp==NULL)
 1059      {ret= 1; goto ex;}
 1060  }
 1061  rpt= text;
 1062  sprintf(prefix,"%s:x: ",channel_prefixes[channel_no]);
 1063  while(*rpt!=0) {
 1064    npt= strchr(rpt,'\n');
 1065    if(npt==NULL)
 1066      prefix[2]= '0';
 1067    else
 1068      prefix[2]= '1';
 1069    if(!result_redirected) {
 1070      if(xorriso->packet_output) {
 1071        ret= fwrite(prefix,5,1,stdout);
 1072        if(ret<=0)
 1073          {ret= 0; goto ex;}
 1074      }
 1075    }
 1076    if(pktlog_fp!=NULL) {
 1077      ret= fwrite(prefix,5,1,pktlog_fp);
 1078      if(ret<=0)
 1079        {ret= 0; goto ex;}
 1080    }
 1081    if(npt==NULL) {
 1082      if(xorriso->packet_output) {
 1083        if(result_redirected) {
 1084          l= strlen(rpt);
 1085          Xorriso_alloc_meM(line, char, 5 + l + 1 + 1);
 1086          memcpy(line, prefix, 5);
 1087          memcpy(line + 5, rpt, l);
 1088          line[5 + l] = '\n';
 1089          line[5 + l + 1] = 0;
 1090          ret= Xorriso_write_to_msglist(xorriso,
 1091                    &(xorriso->result_msglists[xorriso->msglist_stackfill - 1]),
 1092                    line, 0);
 1093          Xorriso_free_meM(line);
 1094          line= NULL;
 1095          if(ret <= 0)
 1096            { ret= -1; goto ex; }
 1097        } else {
 1098          ret= fwrite(rpt,strlen(rpt),1,stdout);
 1099          if(ret<=0)
 1100            {ret= 0; goto ex;}
 1101          ret= fwrite("\n",1,1,stdout);
 1102          if(ret<=0)
 1103            {ret= 0; goto ex;}
 1104        }
 1105      }
 1106      if(pktlog_fp!=NULL) {
 1107        ret= fwrite(rpt,strlen(rpt),1,pktlog_fp);
 1108        if(ret<=0)
 1109          {ret= 0; goto ex;}
 1110        ret= fwrite("\n",1,1,pktlog_fp);
 1111        if(ret<=0)
 1112          {ret= 0; goto ex;}
 1113      }
 1114  break;
 1115    } else {
 1116      if(xorriso->packet_output) {
 1117        if(result_redirected) {
 1118          l= npt + 1 - rpt;
 1119          Xorriso_alloc_meM(line, char, 5 + l + 1);
 1120          memcpy(line, prefix, 5);
 1121          memcpy(line + 5, rpt, l);
 1122          line[5 + l] = 0;
 1123          ret= Xorriso_write_to_msglist(xorriso,
 1124                    &(xorriso->result_msglists[xorriso->msglist_stackfill - 1]),
 1125                    line, 0);
 1126          Xorriso_free_meM(line);
 1127          line= NULL;
 1128          if(ret <= 0)
 1129            { ret= -1; goto ex; }
 1130        } else {
 1131          ret= fwrite(rpt,npt+1-rpt,1,stdout);
 1132          if(ret<=0)
 1133            {ret= 0; goto ex;}
 1134        }
 1135      }
 1136      if(pktlog_fp!=NULL) {
 1137        ret= fwrite(rpt,npt+1-rpt,1,pktlog_fp);
 1138        if(ret<=0)
 1139          {ret= 0; goto ex;}
 1140      }
 1141    }
 1142    rpt= npt+1;
 1143  }
 1144  if(xorriso->packet_output)
 1145    fflush(stdout);
 1146  if(pktlog_fp!=NULL)
 1147    fflush(pktlog_fp);
 1148  ret= 1;
 1149 ex:
 1150  if(text != in_text && text != NULL)
 1151    free(text);
 1152  Xorriso_free_meM(line);
 1153 
 1154 #ifdef Xorriso_fetch_with_msg_queueS
 1155 
 1156  if(locked) {
 1157    uret= pthread_mutex_unlock(&(xorriso->write_to_channel_lock));
 1158    if(uret != 0) {
 1159      /* Cannot report failure through the failing message output system */
 1160      complaints++;
 1161      if(complaints <= complaint_limit)
 1162        fprintf(stderr,
 1163           "xorriso : pthread_mutex_unlock() for write_to_channel returns %d\n",
 1164           uret);
 1165    }
 1166  }
 1167 
 1168 #endif /* Xorriso_fetch_with_msg_queueS */
 1169 
 1170  return(ret);
 1171 }
 1172 
 1173 
 1174 int Xorriso_push_outlists(struct XorrisO *xorriso, int *stack_handle,
 1175                           int flag)
 1176 {
 1177  int ret, locked= 0;
 1178 
 1179  ret= Xorriso_lock_outlists(xorriso, 0);
 1180  if(ret <= 0)
 1181    goto ex;
 1182  locked= 1;
 1183  if(xorriso->msglist_stackfill + 1 >= Xorriso_max_outlist_stacK) {
 1184    Xorriso_unlock_outlists(xorriso, 0);
 1185    locked= 0;
 1186    Xorriso_msgs_submit(xorriso, 0,
 1187                 "Overflow of message output redirection stack", 0, "FATAL", 0);
 1188    ret= -1; goto ex;
 1189  }
 1190  if((flag & 3) == 0)
 1191    flag|= 3;
 1192  xorriso->msglist_stackfill++;
 1193  xorriso->result_msglists[xorriso->msglist_stackfill - 1]= NULL;
 1194  xorriso->info_msglists[xorriso->msglist_stackfill - 1]= NULL;
 1195  xorriso->msglist_flags[xorriso->msglist_stackfill - 1]= flag & 3;
 1196  *stack_handle= xorriso->msglist_stackfill - 1;
 1197  ret= 1;
 1198 ex:;
 1199  if(locked)
 1200    Xorriso_unlock_outlists(xorriso, 0);
 1201  return(ret);
 1202  return(1);
 1203 }
 1204 
 1205 
 1206 int Xorriso_fetch_outlists(struct XorrisO *xorriso, int stack_handle,
 1207                            struct Xorriso_lsT **result_list,
 1208                            struct Xorriso_lsT **info_list, int flag)
 1209 {
 1210  int ret, locked= 0;
 1211 
 1212 #ifdef Xorriso_fetch_with_msg_queueS
 1213 
 1214  ret= Xorriso_process_msg_queues(xorriso, 0);
 1215  if(ret <= 0)
 1216    goto ex;
 1217 
 1218 #endif /* Xorriso_fetch_with_msg_queueS */
 1219 
 1220  if((flag & 3) == 0)
 1221    flag|= 3;
 1222 
 1223  ret= Xorriso_lock_outlists(xorriso, 0);
 1224  if(ret <= 0)
 1225    goto ex;
 1226  locked= 1;
 1227 
 1228  if(stack_handle == -1)
 1229    stack_handle= xorriso->msglist_stackfill - 1;
 1230  if(stack_handle < 0 || stack_handle >= xorriso->msglist_stackfill) {
 1231    Xorriso_unlock_outlists(xorriso, 0);
 1232    locked= 0;
 1233    Xorriso_msgs_submit(xorriso, 0,
 1234                 "Program error: Wrong message output redirection stack handle",
 1235                 0, "FATAL", 0);
 1236    ret= -1; goto ex;
 1237  }
 1238 
 1239  if(flag & 1) {
 1240    *result_list= xorriso->result_msglists[stack_handle];
 1241    xorriso->result_msglists[stack_handle]= NULL;
 1242  }
 1243  if(flag & 2) {
 1244    *info_list= xorriso->info_msglists[stack_handle];
 1245    xorriso->info_msglists[stack_handle]= NULL;
 1246  }
 1247 
 1248  ret= 1;
 1249 ex:;
 1250  if(locked)
 1251    Xorriso_unlock_outlists(xorriso, 0);
 1252  return(ret);
 1253 }
 1254 
 1255 
 1256 int Xorriso_peek_outlists(struct XorrisO *xorriso, int stack_handle,
 1257                           int timeout, int flag)
 1258 {
 1259  int ret, locked= 0, yes= 0;
 1260  static int u_wait= 19000;
 1261  time_t start_time;
 1262 
 1263  if((flag & 3) == 0)
 1264    flag|= 3;
 1265  if(stack_handle == -1)
 1266    stack_handle= xorriso->msglist_stackfill - 1;
 1267  start_time= time(NULL);
 1268 
 1269 try_again:;
 1270  ret= Xorriso_obtain_lock(xorriso, &(xorriso->msgw_fetch_lock),
 1271                           "message watcher fetch operation", 0);
 1272  if(ret <= 0)
 1273    {yes= -2; goto ex;}
 1274  locked= 1;
 1275 
 1276  yes= 0;
 1277  if(stack_handle < 0 || stack_handle >= xorriso->msglist_stackfill)
 1278    {yes= -1; goto ex;}
 1279  if(flag & 1)
 1280    yes|= (xorriso->result_msglists[stack_handle] != NULL);
 1281  if(flag & 2)
 1282    yes|= (xorriso->info_msglists[stack_handle] != NULL);
 1283  if(xorriso->msg_watcher_state == 2 && xorriso->msgw_msg_pending)
 1284    yes|= 2;
 1285 
 1286  ret= Xorriso_release_lock(xorriso, &(xorriso->msgw_fetch_lock),
 1287                            "message watcher fetch operation", 0);
 1288  if(ret <= 0)
 1289    {yes= -2; goto ex;}
 1290  locked= 0;
 1291 
 1292  if(yes && (flag & 4)) {
 1293    usleep(u_wait);
 1294    if(time(NULL) <= start_time + timeout)
 1295      goto try_again;
 1296  }
 1297 
 1298 ex:;
 1299  if(locked) {
 1300    ret= Xorriso_release_lock(xorriso, &(xorriso->msgw_fetch_lock),
 1301                              "message watcher fetch operation", 0);
 1302    if(ret <= 0 && yes >= 0)
 1303      yes= -2;
 1304  }
 1305  return(yes);
 1306 }
 1307 
 1308 
 1309 int Xorriso_pull_outlists(struct XorrisO *xorriso, int stack_handle,
 1310                           struct Xorriso_lsT **result_list,
 1311                           struct Xorriso_lsT **info_list, int flag)
 1312 {
 1313  int i, ret, locked= 0;
 1314 
 1315  ret= Xorriso_lock_outlists(xorriso, 0);
 1316  if(ret <= 0)
 1317    goto ex;
 1318  locked= 1;
 1319 
 1320  if(stack_handle == -1)
 1321    stack_handle= xorriso->msglist_stackfill - 1;
 1322  if(stack_handle < 0 || stack_handle >= xorriso->msglist_stackfill) {
 1323    Xorriso_unlock_outlists(xorriso, 0);
 1324    locked= 0;
 1325    Xorriso_msgs_submit(xorriso, 0,
 1326                 "Program error: Wrong message output redirection stack handle",
 1327                 0, "FATAL", 0);
 1328    ret= -1; goto ex;
 1329  }
 1330 
 1331  /* Concatenate all redirections above stack_handle */
 1332  *result_list= NULL;
 1333  *info_list= NULL;
 1334  for(i = stack_handle; i < xorriso->msglist_stackfill; i++) {
 1335    if(*result_list == NULL)
 1336      *result_list= xorriso->result_msglists[i];
 1337    else
 1338      Xorriso_lst_concat(*result_list, xorriso->result_msglists[i], 0);
 1339    if(*info_list == NULL)
 1340      *info_list= xorriso->info_msglists[i];
 1341    else
 1342      Xorriso_lst_concat(*info_list, xorriso->info_msglists[i], 0);
 1343  }
 1344  xorriso->msglist_stackfill= stack_handle;
 1345 
 1346  ret= 1;
 1347 ex:;
 1348  if(locked)
 1349    Xorriso_unlock_outlists(xorriso, 0);
 1350  return(ret);
 1351 }
 1352 
 1353 
 1354 int Xorriso_info_handler_stderr(void *handle, char *text)
 1355 {
 1356  struct XorrisO *xorriso;
 1357 
 1358  xorriso= (struct XorrisO *) handle;
 1359  if(xorriso->stderr_fp != NULL) {
 1360    fprintf(xorriso->stderr_fp, "%s", text);
 1361    fflush(xorriso->stderr_fp);
 1362  } else {
 1363    fprintf(stderr, "%s", text);
 1364    fflush(stderr);
 1365  }
 1366  return(1);
 1367 }
 1368 
 1369 
 1370 int Xorriso_result_handler_stdout(void *handle, char *text)
 1371 {
 1372  printf("%s", text);
 1373  fflush(stdout);
 1374  return(1);
 1375 }
 1376 
 1377 
 1378 int Xorriso_result_handler_pkt(void *handle, char *text)
 1379 {
 1380  int nl= -1, ret, l;
 1381  struct XorrisO *xorriso;
 1382 
 1383  xorriso= (struct XorrisO *) handle;
 1384 
 1385  if(!xorriso->packet_output)
 1386    return Xorriso_result_handler_stdout(handle, text);
 1387 
 1388  /* Interpret pkt_output */
 1389  l= strlen(text);
 1390  if(l >= 5) {
 1391    if(strchr("RIM", text[0]) != NULL && text[1] == ':' &&
 1392       strchr("01", text[2]) != NULL && text[3] == ':' && text[4] == ' ')
 1393      nl= (text[2] == '1');
 1394  }
 1395  if(nl < 0) /* Not pkt_output format */
 1396    return Xorriso_result_handler_stdout(handle, text);
 1397 
 1398  if(nl == 0) {
 1399    /* Suppress newline */
 1400    if(text[l - 1] == '\n')
 1401      l--;
 1402  }
 1403 
 1404  if(text[0] == 'R') {
 1405    ret= fwrite(text + 5, l - 5, 1, stdout);
 1406  } else {
 1407    ret= fwrite(text + 5, l - 5, 1,
 1408                xorriso->stderr_fp != NULL ? xorriso->stderr_fp : stderr);
 1409  }
 1410  if(ret <= 0)
 1411    return(0);
 1412  return(1);
 1413 }
 1414 
 1415 
 1416 int Xorriso_process_msg_lists(struct XorrisO *xorriso,
 1417                                      struct Xorriso_lsT *result_list,
 1418                                      struct Xorriso_lsT *info_list,
 1419                                      int *line_count, int flag)
 1420 {
 1421  struct Xorriso_lsT *lpt;
 1422  int ret;
 1423  int (*handler)(void *handle, char *text);
 1424  void *handle;
 1425 
 1426  handler= xorriso->msgw_result_handler;
 1427  handle= xorriso->msgw_result_handle;
 1428  if(handler == NULL) {
 1429    handler= Xorriso_result_handler_pkt;
 1430    handle= xorriso;
 1431  }
 1432  for(lpt= result_list; lpt != NULL; lpt= lpt->next) {
 1433    (*line_count)++;
 1434    ret= (*handler)(handle, Xorriso_lst_get_text(lpt, 0));
 1435    if(ret < 0)
 1436      return(-1);
 1437  }
 1438  handler= xorriso->msgw_info_handler;
 1439  handle= xorriso->msgw_info_handle;
 1440  if(handler == NULL) {
 1441    handler= Xorriso_info_handler_stderr;
 1442    handle= xorriso;
 1443  }
 1444  for(lpt= info_list; lpt != NULL; lpt= lpt->next) {
 1445    (*line_count)++;
 1446    ret= (*handler)(handle, Xorriso_lst_get_text(lpt, 0));
 1447    if(ret < 0)
 1448      return(-1);
 1449  }
 1450  return(1);
 1451 }
 1452 
 1453 
 1454 static void *Xorriso_msg_watcher(void *state_pt)
 1455 {
 1456  struct XorrisO *xorriso;
 1457  int ret, u_wait= 25000, line_count, sleep_thresh= 20, lock_failure= 0;
 1458  struct Xorriso_lsT *result_list= NULL, *info_list= NULL;
 1459  static int debug_sev= 0;
 1460 
 1461  xorriso= (struct XorrisO *) state_pt;
 1462 
 1463  if(debug_sev == 0)
 1464    Xorriso__text_to_sev("DEBUG", &debug_sev, 0);
 1465 
 1466  xorriso->msg_watcher_state= 2;
 1467  if(xorriso->msgw_info_handler != NULL &&
 1468     debug_sev < xorriso->report_about_severity &&
 1469     debug_sev < xorriso->abort_on_severity)
 1470    (*xorriso->msgw_info_handler)(xorriso,
 1471                      "xorriso : DEBUG : Concurrent message watcher started\n");
 1472  while(1) {
 1473    line_count= 0;
 1474 
 1475    /* Watch out for end request in xorriso */
 1476    if(xorriso->msg_watcher_state == 3)
 1477  break;
 1478 
 1479    ret= Xorriso_obtain_lock(xorriso, &(xorriso->msgw_fetch_lock),
 1480                             "message watcher fetch operation", 1);
 1481    if(ret <= 0) {
 1482      lock_failure= 1;
 1483  break;
 1484    }
 1485    xorriso->msgw_msg_pending= 1;
 1486    ret= Xorriso_fetch_outlists(xorriso, -1, &result_list, &info_list, 3);
 1487    if(ret > 0) {
 1488      /* Process fetched lines */
 1489      xorriso->msgw_msg_pending= 2;
 1490      Xorriso_release_lock(xorriso, &(xorriso->msgw_fetch_lock),
 1491                           "message watcher fetch operation", 1);
 1492      ret= Xorriso_process_msg_lists(xorriso, result_list, info_list,
 1493                                     &line_count, 0);
 1494      xorriso->msgw_msg_pending= 0;
 1495      Xorriso_lst_destroy_all(&result_list, 0);
 1496      Xorriso_lst_destroy_all(&info_list, 0);
 1497      if(ret < 0)
 1498  break;
 1499    } else {
 1500      xorriso->msgw_msg_pending= 0;
 1501      Xorriso_release_lock(xorriso, &(xorriso->msgw_fetch_lock),
 1502                           "message watcher fetch operation", 1);
 1503    }
 1504    xorriso->msgw_msg_pending= 0;
 1505 
 1506    if(ret < 0)
 1507  break;
 1508 
 1509    if(line_count < sleep_thresh)
 1510      usleep(u_wait);
 1511  }
 1512  if(xorriso->msgw_info_handler != NULL &&
 1513     debug_sev < xorriso->report_about_severity &&
 1514     debug_sev < xorriso->abort_on_severity &&
 1515     !lock_failure)
 1516    (*xorriso->msgw_info_handler)(xorriso,
 1517                      "xorriso : DEBUG : Concurrent message watcher ended\n");
 1518  xorriso->msg_watcher_state= 0;
 1519  return(NULL);
 1520 }
 1521 
 1522 
 1523 int Xorriso_start_msg_watcher(struct XorrisO *xorriso,
 1524                     int (*result_handler)(void *handle, char *text),
 1525                     void *result_handle,
 1526                     int (*info_handler)(void *handle, char *text),
 1527                     void *info_handle,
 1528                     int flag)
 1529 {
 1530  int ret, u_wait= 1000, locked= 0, pushed= 0, uret, line_count= 0;
 1531  struct Xorriso_lsT *result_list= NULL, *info_list= NULL;
 1532  pthread_attr_t attr;
 1533  pthread_attr_t *attr_pt = NULL;
 1534  pthread_t thread;
 1535 
 1536  ret= pthread_mutex_lock(&(xorriso->msg_watcher_lock));
 1537  if(ret != 0) {
 1538    Xorriso_msgs_submit(xorriso, 0,
 1539            "Cannot acquire mutex lock for managing concurrent message watcher",
 1540             ret, "FATAL", 0);
 1541    ret= -1; goto ex;
 1542  }
 1543  locked= 1;
 1544 
 1545  /* Check for running watcher */
 1546  if(xorriso->msg_watcher_state > 0) {
 1547    sprintf(xorriso->info_text,
 1548           "There is already a concurrent message watcher running");
 1549    Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, errno, "FAILURE", 0);
 1550    ret= 0; goto ex;
 1551  }
 1552 
 1553  ret= Xorriso_push_outlists(xorriso, &(xorriso->msgw_stack_handle), 3);
 1554  if(ret <= 0)
 1555    goto ex;
 1556  pushed= 1;
 1557 
 1558  /* Register watcher */
 1559  xorriso->msgw_result_handler= result_handler;
 1560  xorriso->msgw_result_handle= result_handle;
 1561  xorriso->msgw_info_handler= info_handler;
 1562  xorriso->msgw_info_handle= info_handle;
 1563  xorriso->msg_watcher_state= 1;
 1564 
 1565  /* Start thread */
 1566  pthread_attr_init(&attr);
 1567  pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
 1568  attr_pt= &attr;
 1569  ret= pthread_create(&thread, attr_pt, Xorriso_msg_watcher, xorriso);
 1570  if(ret != 0) {
 1571    sprintf(xorriso->info_text,
 1572           "Cannot create thread for concurrent message watcher");
 1573    Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, errno, "FAILURE", 0);
 1574    ret= 0; goto ex;
 1575  }
 1576 
 1577  /* Wait until watcher has indicated start */
 1578  while(xorriso->msg_watcher_state == 1) {
 1579 
 1580    /* >>> have a timeout ? */;
 1581 
 1582    usleep(u_wait);
 1583  }
 1584 
 1585  ret= 1;
 1586 ex:;
 1587  if(ret <= 0 && pushed) {
 1588    uret= Xorriso_pull_outlists(xorriso, xorriso->msgw_stack_handle,
 1589                               &result_list, &info_list, 0);
 1590    if(uret > 0) {
 1591      xorriso->msgw_result_handler= NULL;
 1592      xorriso->msgw_info_handler= NULL;
 1593      Xorriso_process_msg_lists(xorriso, result_list, info_list,
 1594                                &line_count, 0);
 1595      Xorriso_lst_destroy_all(&result_list, 0);
 1596      Xorriso_lst_destroy_all(&info_list, 0);
 1597    }
 1598  }
 1599  if(locked) {
 1600    uret= pthread_mutex_unlock(&(xorriso->msg_watcher_lock));
 1601    if(uret != 0) {
 1602      Xorriso_msgs_submit(xorriso, 0,
 1603            "Cannot release mutex lock for managing concurrent message watcher",
 1604            uret, "FATAL", 0);
 1605      ret= -1;
 1606    }
 1607  }
 1608  return(ret);
 1609 }
 1610 
 1611 
 1612 /* @param flag bit0= do not complain loudly if no wather is active
 1613 */
 1614 int Xorriso_stop_msg_watcher(struct XorrisO *xorriso, int flag)
 1615 {
 1616  int ret, u_wait= 1000, locked= 0, uret, line_count= 0;
 1617  struct Xorriso_lsT *result_list= NULL, *info_list= NULL;
 1618 
 1619  if((flag & 1) && xorriso->msg_watcher_state != 2)
 1620    /* Roughly tolerate non-running watcher */
 1621    {ret= 0; goto ex;}
 1622 
 1623  ret= pthread_mutex_lock(&(xorriso->msg_watcher_lock));
 1624  if(ret != 0) {
 1625    Xorriso_msgs_submit(xorriso, 0,
 1626            "Cannot acquire mutex lock for managing concurrent message watcher",
 1627             ret, "FATAL", 0);
 1628    ret= -1; goto ex;
 1629  }
 1630  locked= 1;
 1631 
 1632  /* Check for running watcher */
 1633  if(xorriso->msg_watcher_state != 2) {
 1634    sprintf(xorriso->info_text,
 1635           "There is no concurrent message watcher running");
 1636    Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, errno, "SORRY", 0);
 1637    ret= 0; goto ex;
 1638  }
 1639 
 1640  /* Inform watcher of desire to stop it */
 1641  xorriso->msg_watcher_state= 3;
 1642 
 1643  /* Wait until watcher has indicated its end */
 1644  while(xorriso->msg_watcher_state != 0) {
 1645 
 1646    /* >>> have a timeout ? */;
 1647 
 1648    usleep(u_wait);
 1649  }
 1650 
 1651  ret= Xorriso_obtain_lock(xorriso, &(xorriso->msgw_fetch_lock),
 1652                           "message watcher fetch operation", 1);
 1653  if(ret <= 0) {
 1654    Xorriso_msgs_submit(xorriso, 0,
 1655            "Cannot obtain mutex lock for managing concurrent message watcher",
 1656            ret, "FATAL", 0);
 1657    ret= -1;
 1658    goto ex;
 1659  }
 1660  xorriso->msgw_msg_pending= 1;
 1661  ret= Xorriso_pull_outlists(xorriso, xorriso->msgw_stack_handle,
 1662                             &result_list, &info_list, 0);
 1663  if(ret > 0) {
 1664    xorriso->msgw_msg_pending= 2;
 1665    Xorriso_release_lock(xorriso, &(xorriso->msgw_fetch_lock),
 1666                         "message watcher fetch operation", 1);
 1667    Xorriso_process_msg_lists(xorriso, result_list, info_list,
 1668                              &line_count, 0);
 1669    xorriso->msgw_msg_pending= 0;
 1670    Xorriso_lst_destroy_all(&result_list, 0);
 1671    Xorriso_lst_destroy_all(&info_list, 0);
 1672  } else {
 1673    xorriso->msgw_msg_pending= 0;
 1674    Xorriso_release_lock(xorriso, &(xorriso->msgw_fetch_lock),
 1675                         "message watcher fetch operation", 1);
 1676  }
 1677 
 1678  xorriso->msgw_result_handler= NULL;
 1679  xorriso->msgw_info_handler= NULL;
 1680 
 1681  ret= 1;
 1682 ex:;
 1683  if(locked) {
 1684    uret= pthread_mutex_unlock(&(xorriso->msg_watcher_lock));
 1685    if(uret != 0) {
 1686      Xorriso_msgs_submit(xorriso, 0,
 1687            "Cannot release mutex lock for managing concurrent message watcher",
 1688            uret, "FATAL", 0);
 1689      ret= -1;
 1690    }
 1691  }
 1692  return(ret);
 1693 }
 1694 
 1695 
 1696 /* -------------------------- Xorriso_msg_sievE -------------------------- */
 1697 
 1698 struct Xorriso_msg_filteR {
 1699  char *name;
 1700  char *prefix;
 1701  char *separators;
 1702  int channels;         /* What to watch: bit0=result , bit1=info , bit2=mark */
 1703 
 1704  int num_words;
 1705  int *word_idx;
 1706  int last_word_line_end;
 1707 
 1708                 /* Oldest result gets discarded when new surpassed threshold */
 1709  int max_results;
 1710 
 1711  struct Xorriso_lsT *results; /* Serialized tuples of num_words */
 1712  int num_results;
 1713  int num_delivered;
 1714  struct Xorriso_lsT *next_to_deliver;
 1715 
 1716  struct Xorriso_msg_filteR *prev;
 1717  struct Xorriso_msg_filteR *next;
 1718 };
 1719 int Xorriso_msg_filter_destroy(struct Xorriso_msg_filteR **o, int flag);
 1720 
 1721 
 1722 int Xorriso_msg_filter_new(struct Xorriso_msg_filteR **o, char *name,
 1723                            struct Xorriso_msg_filteR *prev,
 1724                            struct Xorriso_msg_filteR *next,
 1725                            int flag)
 1726 {
 1727  struct Xorriso_msg_filteR *m;
 1728 
 1729  m= (*o)= TSOB_FELD(struct Xorriso_msg_filteR, 1);
 1730  if((*o) == NULL)
 1731    return(-1);
 1732  m->name= NULL;
 1733  m->prefix= NULL;
 1734  m->separators= NULL;
 1735  m->channels= 7;
 1736  m->num_words= 0;
 1737  m->word_idx= NULL;
 1738  m->last_word_line_end= flag & 1;
 1739  m->max_results= 1;
 1740  m->results= NULL;
 1741  m->num_results= 0;
 1742  m->num_delivered= 0;
 1743  m->next_to_deliver= NULL;
 1744 
 1745  m->name= strdup(name);
 1746  if(m->name == NULL)
 1747    goto failure;
 1748 
 1749  m->prev= prev;
 1750  if(prev != NULL)
 1751    prev->next= m;
 1752  m->next= next;
 1753  if(next != NULL)
 1754    next->prev= m;
 1755  return(1);
 1756 failure:
 1757  Xorriso_msg_filter_destroy(o, 0);
 1758  return(-1);
 1759 }
 1760 
 1761 
 1762 int Xorriso_msg_filter_destroy(struct Xorriso_msg_filteR **o, int flag)
 1763 {
 1764  struct Xorriso_msg_filteR *m;
 1765 
 1766  if((*o)==NULL)
 1767    return(0);
 1768  m= *o;
 1769  if(m->name != NULL)
 1770    free(m->name);
 1771  if(m->prefix != NULL)
 1772    free(m->prefix);
 1773  if(m->separators != NULL)
 1774    free(m->separators);
 1775  if(m->word_idx != NULL)
 1776    free((char *) m->word_idx);
 1777  if(m->results != NULL)
 1778    Xorriso_lst_destroy_all(&(m->results), 0);
 1779  if(m->prev != NULL)
 1780    m->prev->next= m->next;
 1781  if(m->next != NULL)
 1782    m->next->prev= m->prev;
 1783 
 1784  free(*o);
 1785  *o= NULL;
 1786  return(1);
 1787 }
 1788 
 1789 
 1790 int Xorriso_msg_filter_set_words(struct Xorriso_msg_filteR *m,
 1791                                  int num_words, int *word_idx, int flag)
 1792 {
 1793  int i;
 1794 
 1795  if(m->word_idx != NULL)
 1796    free(m->word_idx);
 1797  m->num_words= 0;
 1798  if(num_words <= 0)
 1799    return(1);
 1800  m->word_idx= TSOB_FELD(int, num_words);
 1801  if(m->word_idx == NULL)
 1802    return(-1);
 1803  for(i= 0; i < num_words; i++)
 1804    m->word_idx[i]= word_idx[i];
 1805  m->num_words= num_words;
 1806  return(1);
 1807 }
 1808 
 1809 
 1810 struct Xorriso_msg_sievE {
 1811 
 1812  int num_filters;
 1813 
 1814  struct Xorriso_msg_filteR *first_filter;
 1815 
 1816 };
 1817 
 1818 
 1819 int Xorriso_msg_sieve_new(struct Xorriso_msg_sievE **o, int flag)
 1820 {
 1821  struct Xorriso_msg_sievE *m;
 1822 
 1823  m= (*o)= TSOB_FELD(struct Xorriso_msg_sievE, 1);
 1824  if((*o) == NULL)
 1825    return(-1);
 1826  m->num_filters= 0;
 1827  m->first_filter= NULL;
 1828  return(1);
 1829 }
 1830 
 1831 
 1832 int Xorriso_msg_sieve_destroy(struct Xorriso_msg_sievE **o, int flag)
 1833 {
 1834  struct Xorriso_msg_sievE *m;
 1835  struct Xorriso_msg_filteR *f, *next_f= NULL;
 1836 
 1837  if((*o) == NULL)
 1838    return(0);
 1839  m= *o;
 1840  for(f= m->first_filter; f != NULL; f= next_f) {
 1841    next_f= f->next;
 1842    Xorriso_msg_filter_destroy(&f, 0);
 1843  }
 1844  free(*o);
 1845  *o= NULL;
 1846  return(1);
 1847 }
 1848 
 1849 
 1850 /* API */
 1851 int Xorriso_sieve_add_filter(struct XorrisO *xorriso, char *name,
 1852                              int channels, char *prefix, char *separators,
 1853                              int num_words, int *word_idx, int max_results,
 1854                              int flag)
 1855 {
 1856  int ret;
 1857  struct Xorriso_msg_sievE *sieve= NULL;
 1858  struct Xorriso_msg_filteR *filter;
 1859 
 1860  if(xorriso->msg_sieve == NULL) {
 1861    ret= Xorriso_msg_sieve_new(&sieve, 0);
 1862    if(ret <= 0)
 1863      goto no_mem;
 1864    xorriso->msg_sieve= sieve;
 1865  } else
 1866    sieve= xorriso->msg_sieve;
 1867  ret= Xorriso_msg_filter_new(&filter, name, NULL, sieve->first_filter,
 1868                              flag & 1);
 1869  if(ret <= 0)
 1870    goto no_mem;
 1871  sieve->first_filter= filter;
 1872  ret= Xorriso_msg_filter_set_words(filter, num_words, word_idx, 0);
 1873  if(ret <= 0)
 1874    goto no_mem;
 1875  if(prefix != NULL)
 1876    filter->prefix= strdup(prefix);
 1877  if(separators != NULL)
 1878    filter->separators= strdup(separators);
 1879  filter->channels= channels;
 1880  filter->max_results= max_results;
 1881  (sieve->num_filters)++;
 1882  return(1);
 1883 
 1884 no_mem:;
 1885  Xorriso_msg_sieve_destroy(&sieve, 0);
 1886  Xorriso_no_malloc_memory(xorriso, NULL, 0);
 1887  return(-1);
 1888 }
 1889 
 1890 
 1891 /* API */
 1892 int Xorriso_sieve_dispose(struct XorrisO *xorriso, int flag)
 1893 {
 1894  Xorriso_msg_sieve_destroy(&(xorriso->msg_sieve), 0);
 1895  return(1);
 1896 }
 1897 
 1898 
 1899 /* API */
 1900 int Xorriso_sieve_clear_results(struct XorrisO *xorriso, int flag)
 1901 {
 1902  struct Xorriso_msg_filteR *f;
 1903 
 1904  if(xorriso->msg_sieve == NULL)
 1905    return(1);
 1906  for(f= xorriso->msg_sieve->first_filter; f != NULL; f= f->next) {
 1907    f->num_results= 0;
 1908    f->num_delivered= 0;
 1909    if(f->results != NULL)
 1910      Xorriso_lst_destroy_all(&(f->results), 0);
 1911    f->next_to_deliver= NULL;
 1912  }
 1913  return(1);
 1914 }
 1915 
 1916 
 1917 /* API */
 1918 /* @param flag bit0= Reset reading to first matching result
 1919                bit1= Only inquire number of available results.
 1920                      Do not allocate memory.
 1921                bit2= If *argv is not NULL, then free it before attaching
 1922                      new memory.
 1923                bit3= Do not read recorded data but rather list all filter names
 1924 */
 1925 int Xorriso_sieve_get_result(struct XorrisO *xorriso, char *name,
 1926                              int *argc, char ***argv, int *available, int flag)
 1927 {
 1928  struct Xorriso_msg_filteR *f;
 1929  struct Xorriso_lsT *lst;
 1930  int i;
 1931 
 1932  if(flag & 4)
 1933    Xorriso__dispose_words(argc, argv);
 1934  *argc= 0;
 1935  *argv= NULL;
 1936 
 1937  if(xorriso->msg_sieve == NULL)
 1938    return(0); 
 1939 
 1940  if(flag & 8) {
 1941    if(xorriso->msg_sieve->num_filters <= 0)
 1942      return(0);
 1943    *argv= calloc(xorriso->msg_sieve->num_filters, sizeof(char *));
 1944    if(*argv == NULL)
 1945      goto no_mem;
 1946    *argc= xorriso->msg_sieve->num_filters;
 1947    for(i= 0; i < *argc; i++)
 1948      (*argv)[i]= NULL;
 1949    i= 0;
 1950    for(f= xorriso->msg_sieve->first_filter; f != NULL; f= f->next) {
 1951      (*argv)[*argc - i - 1]= strdup(f->name);
 1952      if((*argv)[*argc - i - 1] == NULL)
 1953        goto no_mem;
 1954      i++;
 1955    }
 1956    *argc= i;
 1957    return(1);
 1958  }
 1959 
 1960  for(f= xorriso->msg_sieve->first_filter; f != NULL; f= f->next) {
 1961    if(strcmp(f->name, name) != 0)
 1962  continue;
 1963    *available= f->num_results - f->num_delivered;
 1964    if(*available <= 0)
 1965      return(0);
 1966    if(flag & 2)
 1967      return(1);
 1968 
 1969    if(flag & 1) {
 1970      f->num_delivered= 0;
 1971      f->next_to_deliver= NULL;
 1972    }
 1973    if(f->next_to_deliver == NULL) {
 1974      f->next_to_deliver= f->results;
 1975      for(i= 0; i < f->num_words * f->num_delivered; i++)
 1976        if(f->next_to_deliver != NULL)
 1977          f->next_to_deliver= Xorriso_lst_get_next(f->next_to_deliver, 0);
 1978    }
 1979    if(f->next_to_deliver == NULL) {
 1980      /* Should not happen */
 1981      goto unexpected_null;
 1982    }
 1983    if(f->num_words <= 0)
 1984      return(1);
 1985 
 1986    *argv= calloc(f->num_words, sizeof(char *));
 1987    if(*argv == NULL)
 1988      goto no_mem;
 1989    *argc= f->num_words;
 1990    for(i= 0; i < *argc; i++)
 1991      (*argv)[i]= NULL;
 1992 
 1993    lst= f->next_to_deliver;
 1994    for(i= 0; i < *argc; i++) {
 1995      if(lst != NULL) {
 1996        (*argv)[i]= strdup(Xorriso_lst_get_text(lst, 0));
 1997        if((*argv)[i] == NULL)
 1998          goto no_mem;
 1999      } else {
 2000        /* should not happen */
 2001 unexpected_null:;
 2002        Xorriso_msgs_submit(xorriso, 0,
 2003                     "Program error: Unexpected NULL pointer in message sieve.",
 2004                     0, "WARNING", 0);
 2005        if(*argv != NULL)
 2006          Xorriso__dispose_words(argc, argv);
 2007        *available= 0;
 2008        return(-2);
 2009      }
 2010      lst= Xorriso_lst_get_next(lst, 0);
 2011    }
 2012    f->next_to_deliver= lst;
 2013    (f->num_delivered)++;
 2014    (*available)--;
 2015    return(1);
 2016  }
 2017  return(-2);
 2018 no_mem:
 2019  if(*argv != NULL)
 2020    Xorriso__dispose_words(argc, argv);
 2021  Xorriso_no_malloc_memory(xorriso, NULL, 0);
 2022  return(-1);
 2023 }
 2024 
 2025 
 2026 int Xorriso_sieve_big(struct XorrisO *xorriso, int flag)
 2027 {
 2028  struct Xorriso_sieve_big_filteR {
 2029    char *name;
 2030    int channels;
 2031    char *prefix;
 2032    char *separators;
 2033    int num_words;
 2034    int word_idx[6];
 2035    int max_results;
 2036    int flag;
 2037  };
 2038  static struct Xorriso_sieve_big_filteR filters[] = {
 2039    {"-changes_pending", 3, "-changes_pending", "", 1,
 2040                                                { 0, -1, -1, -1, -1, -1}, 1, 0},
 2041    {"?  -dev", 3, "?  -dev", "", 4, { 0,  1,  3,  4, -1, -1},
 2042                                                                         10, 0},
 2043    {"??  -dev", 3, "??  -dev", "", 4, { 0,  1,  3,  4, -1, -1},
 2044                                                                         90, 0},
 2045    {"Abstract File:", 3, "Abstract File: ", "", 1, { 0, -1, -1, -1, -1, -1},
 2046                                                                          1, 1},
 2047    {"After commit :", 3, "After commit :", "", 1, { 0, -1, -1, -1, -1, -1},
 2048                                                                          1, 0},
 2049    {"App Id       :", 3, "App Id       : ", "", 1, { 0, -1, -1, -1, -1, -1},
 2050                                                                          1, 1},
 2051    {"Biblio File  :", 3, "Biblio File  : ", "", 1, { 0, -1, -1, -1, -1, -1},
 2052                                                                          1, 1},
 2053    {"Build timestamp   :", 3, "Build timestamp   :  ", "", 1,
 2054                                                { 0, -1, -1, -1, -1, -1}, 1, 1},
 2055    {"CopyrightFile:", 3, "CopyrightFile: ", "", 1, { 0, -1, -1, -1, -1, -1},
 2056                                                                          1, 1},
 2057    {"Creation Time:", 3, "Creation Time: ", "", 1, { 0, -1, -1, -1, -1, -1},
 2058                                                                          1, 1},
 2059    {"DVD obs 64 kB:", 3, "DVD obs 64 kB:", "", 1, { 0, -1, -1, -1, -1, -1},
 2060                                                                          1, 0},
 2061    {"Drive access :", 3, "Drive access : ", ": ", 2, { 0,  1,  -1, -1, -1, -1},
 2062                                                                          2, 0},
 2063    {"Drive current:", 3, "Drive current:", "", 2, { 0,  1, -1, -1, -1, -1},
 2064                                                                          2, 0},
 2065    {"Drive id     :", 3, "Drive id     :", "", 1, { 0, -1, -1, -1, -1, -1},
 2066                                                                          2, 0},
 2067    {"Drive type   :", 3, "Drive type   :", "", 3, { 1,  3,  5, -1, -1, -1},
 2068                                                                          2, 0},
 2069    {"Eff. Time    :", 3, "Eff. Time    : ", "", 1, { 0, -1, -1, -1, -1, -1},
 2070                                                                          1, 1},
 2071    {"Expir. Time  :", 3, "Expir. Time  : ", "", 1, { 0, -1, -1, -1, -1, -1},
 2072                                                                          1, 1},
 2073    {"Ext. filters :", 3, "Ext. filters : ", "", 1, { 0, -1, -1, -1, -1, -1},
 2074                                                                          1, 1},
 2075    {"File damaged :", 3, "File damaged :", "", 4, { 0,  2,  4,  6, -1, -1},
 2076                                                                      10000, 0},
 2077    {"File data lba:", 3, "File data lba:", "", 5, { 0,  2,  4,  6,  8, -1},
 2078                                                                      10000, 0},
 2079    {"Format idx   :", 3, "Format idx ", ",: ", 4, { 0,  1,  2,  3, -1, -1},
 2080                                                                        100, 1},
 2081    {"Format status:", 3, "Format status:", ", ", 2, { 0,  1, -1, -1, -1, -1},
 2082                                                                          1, 1},
 2083    {"ISO session  :", 3, "ISO session  :", "", 4, { 0,  2,  4,  6, -1, -1},
 2084                                                                      10000, 1},
 2085    {"Image size   :", 3, "Image size   :", "", 1, { 0, -1, -1, -1, -1, -1},
 2086                                                                          1, 0},
 2087    {"Jigdo files  :", 3, "Jigdo files  :", "", 1, { 0, -1, -1, -1, -1, -1},
 2088                                                                          1, 0},
 2089    {"Local ACL    :", 3, "Local ACL    :", "", 1, { 0, -1, -1, -1, -1, -1},
 2090                                                                          1, 0},
 2091    {"Local xattr  :", 3, "Local xattr  :", "", 1, { 0, -1, -1, -1, -1, -1},
 2092                                                                          1, 0},
 2093    {"MD5 MISMATCH:", 3, "MD5 MISMATCH:", "", 1, { 0, -1, -1, -1, -1, -1},
 2094                                                                      10000, 0},
 2095    {"MD5 tag range:", 3, "MD5 tag range:", "", 3, { 0,  2,  4, -1, -1, -1},
 2096                                                                      10000, 1},
 2097    {"Media blocks :", 3, "Media blocks :", "", 3, { 0,  3,  6, -1, -1, -1},
 2098                                                                          2, 0},
 2099    {"Media current:", 3, "Media current: ", "", 1, { 0, -1, -1, -1, -1, -1},
 2100                                                                          2, 1},
 2101    {"Media id     :", 3, "Media id     :", "", 1, { 0, -1, -1, -1, -1, -1},
 2102                                                                          2, 0},
 2103    {"Media nwa    :", 3, "Media nwa    :", "", 1, { 0, -1, -1, -1, -1, -1},
 2104                                                                          1, 0},
 2105    {"Media product:", 3, "Media product:", "", 2, { 0,  2, -1, -1, -1, -1},
 2106                                                                          2, 1},
 2107    {"Media region :", 3, "Media region :", "", 3, { 0,  2,  4, -1, -1, -1},
 2108                                                                      10000, 1},
 2109    {"Media space  :", 3, "Media space  :", "", 1, { 0, -1, -1, -1, -1, -1},
 2110                                                                          1, 0},
 2111    {"Media status :", 3, "Media status : ", "", 1, { 0, -1, -1, -1, -1, -1},
 2112                                                                          2, 1},
 2113    {"Media summary:", 3, "Media summary:", "", 4, { 0,  2,  5,  7, -1, -1},
 2114                                                                          2, 0},
 2115    {"Modif. Time  :", 3, "Modif. Time  : ", "", 1, { 0, -1, -1, -1, -1, -1},
 2116                                                                          1, 1},
 2117    {"PVD address  :", 3, "PVD address  :", "", 1, { 0, -1, -1, -1, -1, -1},
 2118                                                                          1, 0},
 2119    {"Preparer Id  :", 3, "Preparer Id  : ", "", 1, { 0, -1, -1, -1, -1, -1},
 2120                                                                          1, 1},
 2121    {"Profile      :", 3, "Profile      :", "", 2, { 0,  1, -1, -1, -1, -1},
 2122                                                                        256, 1},
 2123    {"Publisher Id :", 3, "Publisher Id : ", "", 1, { 0, -1, -1, -1, -1, -1},
 2124                                                                          1, 1},
 2125    {"Readline     :", 3, "Readline     :", "", 1, { 0, -1, -1, -1, -1, -1},
 2126                                                                          1, 0},
 2127    {"Size lower   :", 3, "Size lower   :", "", 1, { 0, -1, -1, -1, -1, -1},
 2128                                                                          1, 0},
 2129    {"Size upper   :", 3, "Size upper   :", "", 1, { 0, -1, -1, -1, -1, -1},
 2130                                                                          1, 0},
 2131    {"System Id    :", 3, "System Id    : ", "", 1, { 0, -1, -1, -1, -1, -1},
 2132                                                                          1, 1},
 2133    {"Version timestamp :", 3, "Version timestamp :", "", 1,
 2134                                                { 0, -1, -1, -1, -1, -1}, 1, 0},
 2135    {"Volume Id    :", 3, "Volume Id    : ", "", 1, { 0, -1, -1, -1, -1, -1},
 2136                                                                          1, 1},
 2137    {"Volume Set Id:", 3, "Volume Set Id: ", "", 1, { 0, -1, -1, -1, -1, -1},
 2138                                                                          1, 1},
 2139    {"Volume id    :", 3, "Volume id    :", "", 1, { 0, -1, -1, -1, -1, -1},
 2140                                                                          2, 0},
 2141    {"Write speed  :", 3, "Write speed  :", "", 2, { 0,  2, -1, -1, -1, -1},
 2142                                                                        100, 0},
 2143    {"Write speed H:", 3, "Write speed H:", "", 2, { 0,  2, -1, -1, -1, -1},
 2144                                                                          1, 0},
 2145    {"Write speed L:", 3, "Write speed L:", "", 2, { 0,  2, -1, -1, -1, -1},
 2146                                                                          1, 0},
 2147    {"Write speed h:", 3, "Write speed h:", "", 2, { 0,  2, -1, -1, -1, -1},
 2148                                                                          1, 0},
 2149    {"Write speed l:", 3, "Write speed l:", "", 2, { 0,  2, -1, -1, -1, -1},
 2150                                                                          1, 0},
 2151    {"libburn    in use :", 3, "libburn    in use :", "", 2,
 2152                                                { 0,  1, -1, -1, -1, -1}, 1, 1},
 2153    {"libburn OS adapter:", 3, "libburn OS adapter:  ", "", 1,
 2154                                                { 0, -1, -1, -1, -1, -1}, 1, 1},
 2155    {"libisoburn in use :", 3, "libisoburn in use :", "", 2,
 2156                                                { 0,  1, -1, -1, -1, -1}, 1, 1},
 2157    {"libisofs   in use :", 3, "libisofs   in use :", "", 2,
 2158                                                { 0,  1, -1, -1, -1, -1}, 1, 1},
 2159    {"libjte     in use :", 3, "libjte     in use :", "", 2,
 2160                                                { 0,  1, -1, -1, -1, -1}, 1, 1},
 2161    {"xorriso version   :", 3, "xorriso version   :", "", 1,
 2162                                                { 0, -1, -1, -1, -1, -1}, 1, 0},
 2163    {"zisofs       :", 3, "zisofs       :", "", 1, { 0, -1, -1, -1, -1, -1},
 2164                                                                          1, 0},
 2165    {"@", 0, "@", "", 0, {-1, -1, -1, -1, -1, -1}, 0, 0}
 2166  };
 2167 
 2168  struct Xorriso_sieve_big_filteR *f;
 2169  int ret, i;
 2170 
 2171  for(i= 0; ; i++) {
 2172    f= &(filters[i]);
 2173    if(strcmp(f->name, "@") == 0)
 2174  break;
 2175    ret= Xorriso_sieve_add_filter(xorriso, f->name, f->channels, f->prefix,
 2176                                  f->separators, f->num_words, f->word_idx,
 2177                                  f->max_results, f->flag);
 2178    if(ret <= 0)
 2179      goto failure;
 2180  }
 2181  return(1);
 2182 failure:
 2183  Xorriso_sieve_dispose(xorriso, 0);
 2184  return(-1);
 2185 }
 2186 
 2187 
 2188 /* Check for matching filter and eventually extract words.
 2189    To be called by Xorriso_result, Xorriso_info, Xorriso_mark,
 2190    and alike.
 2191    Thus no own message output is allowed here !
 2192    @param flag bit0-1= channel:
 2193                        0= result channel
 2194                        1= info channel
 2195                        2= mark channel
 2196 */
 2197 int Xorriso_sieve_filter_msg(struct XorrisO *xorriso, char *msg, int flag)
 2198 {
 2199  int channel, ret, argc= 0, i, max_words, l, widx, skip;
 2200  char **argv= NULL, *prefix_storage= NULL, *prefix, *cpt, *to_parse= NULL;
 2201  struct Xorriso_msg_filteR *f;
 2202  struct Xorriso_lsT *lst, *prev_lst, *next_lst;
 2203 
 2204  if(xorriso->msg_sieve == NULL || xorriso->msg_sieve_disabled)
 2205    return(1);
 2206 
 2207  channel= flag & 3;
 2208 
 2209  for(f= xorriso->msg_sieve->first_filter; f != NULL; f= f->next) {
 2210    if(!(f->channels & (1 << channel)))
 2211  continue;
 2212    prefix= f->prefix;
 2213 
 2214    if(prefix[0] == '?') {
 2215      skip= 0;
 2216      for(cpt= prefix; *cpt; cpt++)
 2217        if(*cpt == '?')
 2218          skip++;
 2219        else
 2220      break;
 2221      l= strlen(prefix);
 2222      if(strlen(msg) >= (unsigned int) l) {
 2223        if(l - skip == 0 || strncmp(prefix + skip, msg + skip, l - skip) == 0) {
 2224          Xorriso_free_meM(prefix_storage);
 2225          prefix_storage= NULL;
 2226          Xorriso_alloc_meM(prefix_storage, char, l + 1);
 2227          strncpy(prefix_storage, msg, l);
 2228          prefix_storage[l]= 0;
 2229          prefix= prefix_storage;
 2230        }
 2231      }
 2232    }
 2233    if(prefix[0])
 2234      if(strncmp(prefix, msg, strlen(prefix)) != 0)
 2235  continue;
 2236 
 2237    if (to_parse != NULL)
 2238      free(to_parse);
 2239    to_parse= strdup(msg);
 2240    if(to_parse == NULL)
 2241      goto no_mem;
 2242    l= strlen(to_parse);
 2243    if(l > 0)
 2244      if(to_parse[l - 1] == '\n')
 2245        to_parse[l - 1]= 0;
 2246 
 2247    max_words= 0;
 2248    if(f->last_word_line_end)
 2249      if(f->num_words > 0)                /* Let last word take rest of line */
 2250        max_words= f->word_idx[f->num_words - 1];
 2251    if(max_words <= 0 && f->last_word_line_end) {
 2252      /* Copy rest of line as single word because Xorriso_parse_line understands
 2253         max_words == 0 as unlimited number of words. But here it is desired
 2254         to get the rest of line already in argv[0].
 2255      */
 2256      max_words= 0;
 2257      argv= calloc(1, sizeof(char *));
 2258      if(argv == NULL)
 2259        goto no_mem;
 2260      argc= 1;
 2261      argv[0]= strdup(to_parse + strlen(prefix));
 2262      if(argv[0] == NULL)
 2263        goto no_mem;
 2264      ret= 1;
 2265    } else {
 2266      ret= Xorriso_parse_line(xorriso, to_parse, prefix, f->separators,
 2267                              max_words, &argc, &argv, 0);
 2268    }
 2269    if(ret < 0)
 2270      goto ex;
 2271    if(ret == 0)
 2272  continue;
 2273 
 2274    if(f->last_word_line_end && argc > max_words) {
 2275      l= strlen(argv[max_words]);
 2276      if(l > 0)
 2277        if(argv[max_words][l - 1] == '\n')
 2278          argv[max_words][l - 1]= 0;
 2279    }
 2280 
 2281    if(f->max_results > 0 && f->num_results >= f->max_results) {
 2282      /* Dispose surplus results */
 2283      for(i= 0; i < f->num_words; i++) {
 2284        if(f->results != NULL) {
 2285          next_lst= f->results->next;
 2286          Xorriso_lst_destroy(&(f->results), 0);
 2287          f->results= next_lst;
 2288        }
 2289      }
 2290      if(f->num_delivered > 0)
 2291        (f->num_delivered)--;
 2292      if(f->num_delivered == 0)
 2293        f->next_to_deliver= NULL;
 2294      f->num_results--;
 2295    }
 2296 
 2297    if(f->results == NULL) {
 2298      prev_lst= NULL;
 2299    } else {
 2300      for(prev_lst= f->results; prev_lst->next != NULL;
 2301          prev_lst= prev_lst->next);
 2302    }
 2303    for(i= 0; i < f->num_words; i++) {
 2304      widx= f->word_idx[i];
 2305      if(widx >= argc || widx < 0)
 2306        ret= Xorriso_lst_new(&lst, "", prev_lst, 0);
 2307      else if(argv[widx] == NULL)
 2308        ret= Xorriso_lst_new(&lst, "", prev_lst, 0);
 2309      else
 2310        ret= Xorriso_lst_new(&lst, argv[widx], prev_lst, 0);
 2311      if(ret <= 0)
 2312        goto no_mem;
 2313      if(prev_lst == NULL)
 2314        f->results= lst;
 2315      prev_lst= lst;
 2316    }
 2317    (f->num_results)++;
 2318    Xorriso__dispose_words(&argc, &argv);
 2319  }
 2320  ret= 1;
 2321 ex:
 2322  if(to_parse != NULL)
 2323    free(to_parse);
 2324  Xorriso_free_meM(prefix_storage);
 2325  Xorriso__dispose_words(&argc, &argv);
 2326  return(ret);
 2327 no_mem:;
 2328  Xorriso_no_malloc_memory(xorriso, NULL, 1); /* reports to stderr */
 2329  ret= -1;
 2330  goto ex;
 2331 }
 2332 
 2333 
 2334 /* ^^^^^^^^^^^^^^^^^^^^^^^^^^ Xorriso_msg_sievE ^^^^^^^^^^^^^^^^^^^^^^^^^^ */
 2335 
 2336 
 2337 int Xorriso_result(struct XorrisO *xorriso, int flag)
 2338 /*
 2339  bit0= no considerations or computations or dialog. Just put out.
 2340 */
 2341 {
 2342  int ret, redirected= 0;
 2343 
 2344  if(flag&1)
 2345    goto put_it_out;
 2346  if(xorriso->request_to_abort)
 2347    return(1);
 2348  if(xorriso->msglist_stackfill > 0)
 2349    if(xorriso->msglist_flags[xorriso->msglist_stackfill - 1] & 1)
 2350      redirected= 1;
 2351  if(xorriso->result_page_length>0 && !redirected) {
 2352    ret= Xorriso_pager(xorriso,xorriso->result_line,2);
 2353    if(ret<=0)
 2354      return(ret);
 2355    if(ret==2)
 2356      return(1);
 2357    if(xorriso->request_to_abort)
 2358      return(1);
 2359  }
 2360 put_it_out:;
 2361  xorriso->bar_is_fresh= 0;
 2362  ret= Xorriso_write_to_channel(xorriso, xorriso->result_line, 1,0);
 2363  return(ret);
 2364 }
 2365 
 2366 
 2367 int Xorriso_info(struct XorrisO *xorriso, int flag)
 2368 /*
 2369  bit0= use pager (as with result)
 2370  bit1= permission to suppress output
 2371  bit2= insist in showing output
 2372 */
 2373 {
 2374  int ret;
 2375  static int note_sev= 0;
 2376 
 2377  if(flag&2)
 2378    if(xorriso->request_to_abort)
 2379      return(1);
 2380 
 2381  if(note_sev==0)
 2382    Xorriso__text_to_sev("NOTE", &note_sev, 0);
 2383  if(note_sev<xorriso->report_about_severity &&
 2384     note_sev<xorriso->abort_on_severity && !(flag&4))
 2385    return(1);
 2386 
 2387  if(flag&1) {
 2388    ret= Xorriso_pager(xorriso,xorriso->info_text,2);
 2389    if(ret<=0)
 2390      return(ret);
 2391    if(ret==2)
 2392      return(1);
 2393    if(flag&2)
 2394      if(xorriso->request_to_abort)
 2395        return(1);
 2396  }
 2397  xorriso->bar_is_fresh= 0;
 2398  ret=Xorriso_write_to_channel(xorriso, xorriso->info_text, 2, 0);
 2399  return(ret);
 2400 }
 2401 
 2402 
 2403 int Xorriso_mark(struct XorrisO *xorriso, int flag)
 2404 {
 2405  int ret= 1,r_ret,i_ret;
 2406 
 2407  if(xorriso->mark_text[0]==0)
 2408    return(1);
 2409  if(xorriso->packet_output) 
 2410    ret=Xorriso_write_to_channel(xorriso, xorriso->mark_text, 3, 0);
 2411  else {
 2412    sprintf(xorriso->result_line,"%s\n",xorriso->mark_text);
 2413    r_ret= Xorriso_result(xorriso,1);
 2414    strcpy(xorriso->info_text,xorriso->result_line);
 2415    i_ret= Xorriso_info(xorriso,0);
 2416    if(r_ret==0 || i_ret==0)
 2417      ret= 0;
 2418  }
 2419  return(ret);
 2420 }
 2421 
 2422 
 2423 int Xorriso_restxt(struct XorrisO *xorriso, char *text)
 2424 {
 2425  int ret;
 2426 
 2427  strncpy(xorriso->result_line,text,sizeof(xorriso->result_line)-1);
 2428  xorriso->result_line[sizeof(xorriso->result_line)-1]= 0;
 2429  ret= Xorriso_result(xorriso,0);
 2430  return(ret);
 2431 }
 2432 
 2433 
 2434 /* @param flag bit0-7= purpose
 2435                        0= ERRFILE
 2436                        1= mark line (only to be put out if enabled)
 2437 */
 2438 int Xorriso_process_errfile(struct XorrisO *xorriso,
 2439                             int error_code, char msg_text[], int os_errno,
 2440                             int flag)
 2441 {
 2442  char ttx[41];
 2443  int purpose;
 2444 
 2445  if(strlen(msg_text)>SfileadrL)
 2446    return(-1);
 2447 
 2448  purpose= flag&255;
 2449  if(purpose==1 && !(xorriso->errfile_mode&1))
 2450    return(2);
 2451  if(xorriso->errfile_fp!=NULL) {
 2452    if(purpose==1)
 2453      fprintf(xorriso->errfile_fp, "----------------- %s  %s\n",
 2454              msg_text, Ftimetxt(time(0), ttx, 1));
 2455    else
 2456      fprintf(xorriso->errfile_fp, "%s\n", msg_text);
 2457    fflush(xorriso->errfile_fp);
 2458    return(1);
 2459  }
 2460  if(xorriso->errfile_log[0]==0)
 2461    return(1);
 2462  if(strcmp(xorriso->errfile_log, "-")==0 ||
 2463     strcmp(xorriso->errfile_log, "-R")==0) {
 2464    if(purpose==1)
 2465      sprintf(xorriso->result_line, "----------------- %s  %s\n",
 2466              msg_text, Ftimetxt(time(0), ttx, 1));
 2467    else
 2468      sprintf(xorriso->result_line, "%s\n", msg_text);
 2469    Xorriso_result(xorriso, 1);
 2470    return(1);
 2471  }
 2472  if(strcmp(xorriso->errfile_log, "-I") == 0 &&
 2473     xorriso->info_text != msg_text) { /* (Beware of stepping on own foot) */
 2474    if(purpose==1)
 2475      sprintf(xorriso->info_text, "ERRFILE_MARK=%s  %s\n",
 2476              msg_text, Ftimetxt(time(0), ttx, 1));
 2477    else
 2478      sprintf(xorriso->info_text, "ERRFILE=%s\n", msg_text);
 2479    Xorriso_info(xorriso, 0);
 2480    return(1);
 2481  }
 2482  return(2);
 2483 }
 2484 
 2485 
 2486 #ifdef Xorriso_fetch_with_msg_queueS
 2487 /* Important: This function must stay thread-safe with all use of xorriso. */
 2488 #else
 2489 /* Note: It is ok to submit xorriso->info_text as msg_text here. */
 2490 #endif
 2491 /* flag: 
 2492      bit0= for Xorriso_info() : use pager (as with result)
 2493      bit1= for Xorriso_info() : permission to suppress output
 2494      bit2..5= name prefix
 2495        0="xorriso"
 2496        1="libisofs"
 2497        2="libburn"
 2498        3="libisoburn"
 2499        else: ""
 2500      bit6= append carriage return rather than line feed (if not os_errno)
 2501      bit7= perform Xorriso_process_msg_queues() first
 2502      bit8= do not prepend name prefix and severity
 2503 */
 2504 int Xorriso_msgs_submit(struct XorrisO *xorriso, 
 2505                         int error_code, char msg_text[], int os_errno,
 2506                         char severity[], int flag)
 2507 {
 2508  int ret, lt, li, sev, i;
 2509  char *sev_text= "FATAL", prefix[80], *text= NULL;
 2510  static char pfx_list[20][16]= {
 2511                    "xorriso : ", "libisofs: ", "libburn : ", "libisoburn: ",
 2512                     "", "", "", "", "", "", "", "", "", "", "", "" };
 2513 
 2514  if(flag&128)
 2515    Xorriso_process_msg_queues(xorriso, 0);
 2516 
 2517  if(strcmp(severity, "ERRFILE")==0)
 2518    Xorriso_process_errfile(xorriso, error_code, msg_text, os_errno, 0);
 2519 
 2520  /* Set problem status */
 2521  ret= Xorriso__text_to_sev(severity, &sev, 0);
 2522  if(ret<=0)
 2523    Xorriso__text_to_sev(sev_text, &sev, 0);
 2524  else
 2525    sev_text= severity;
 2526  if(xorriso->problem_status<sev)
 2527    Xorriso_set_problem_status(xorriso, sev_text, 0);
 2528 
 2529  /* Report problem event */
 2530  if(sev<xorriso->report_about_severity && sev<xorriso->abort_on_severity)
 2531    {ret= 2; goto ex;}
 2532  lt= strlen(msg_text);
 2533  if(!(flag & 256)) {
 2534    sprintf(prefix,"%s%s : ", pfx_list[(flag>>2)&15], sev_text);
 2535    li= strlen(prefix);
 2536  } else {
 2537    prefix[0]= 0;
 2538    li= 0;
 2539  }
 2540  if(lt > ((int) sizeof(xorriso->info_text)) - li - 2)
 2541    lt= sizeof(xorriso->info_text)-li-2;
 2542 
 2543 #ifdef Xorriso_fetch_with_msg_queueS
 2544 
 2545  Xorriso_alloc_meM(text, char, sizeof(xorriso->info_text));
 2546 
 2547 #else /* Xorriso_fetch_with_msg_queueS */
 2548 
 2549  text= xorriso->info_text;
 2550 
 2551 #endif /* ! Xorriso_fetch_with_msg_queueS */
 2552 
 2553  if(msg_text == text) {
 2554    if(li > 0) {
 2555      for(i= lt; i>=0; i--)
 2556        msg_text[i+li]= msg_text[i];
 2557      for(i=0; i<li; i++)
 2558        msg_text[i]= prefix[i];
 2559    }
 2560  } else {
 2561    if(li > 0)
 2562      strcpy(text, prefix);
 2563    strncpy(text + li, msg_text, lt);
 2564  }
 2565  if((flag&64) && os_errno<=0)
 2566    text[li+lt]= '\r';
 2567  else
 2568    text[li+lt]= '\n';
 2569  text[li+lt+1]= 0;
 2570  if(os_errno>0)
 2571    sprintf(text + strlen(text) - 1, " : %s\n", strerror(os_errno));
 2572 
 2573 #ifdef Xorriso_fetch_with_msg_queueS
 2574 
 2575  Xorriso_write_to_channel(xorriso, text, 2, 0);
 2576 
 2577 #else /* Xorriso_fetch_with_msg_queueS */
 2578 
 2579  Xorriso_info(xorriso,4|(flag&3));
 2580 
 2581 #endif /* ! Xorriso_fetch_with_msg_queueS */
 2582 
 2583 ex:;
 2584 
 2585 #ifdef Xorriso_fetch_with_msg_queueS
 2586  Xorriso_free_meM(text);
 2587 #endif /* ! Xorriso_fetch_with_msg_queueS */
 2588 
 2589  return(ret);
 2590 }
 2591 
 2592 
 2593 /* To be used with isoburn_set_msgs_submit()
 2594 */
 2595 int Xorriso_msgs_submit_void(void *xorriso,
 2596                         int error_code, char msg_text[], int os_errno,
 2597                         char severity[], int flag)
 2598 {
 2599  int ret;
 2600 
 2601  ret= Xorriso_msgs_submit((struct XorrisO *) xorriso, error_code, msg_text,
 2602                           os_errno, severity, flag);
 2603  return(ret);
 2604 }
 2605 
 2606 
 2607 /** @return -1= abort , 0= no , 1= yes
 2608 */
 2609 int Xorriso_reassure(struct XorrisO *xorriso, char *cmd, char *which_will,
 2610                      int flag)
 2611 {
 2612  int ret;
 2613 
 2614  if(!xorriso->do_reassure)
 2615    return(1);
 2616  sprintf(xorriso->info_text, "Really perform %s which will %s ? (y/n)\n",
 2617          cmd, which_will);
 2618  Xorriso_info(xorriso, 4);
 2619  do {
 2620    ret= Xorriso_request_confirmation(xorriso, 2|4|16);
 2621  } while(ret==3);
 2622  if(ret==6 || ret==4) {
 2623    sprintf(xorriso->info_text, "%s confirmed", cmd);
 2624    Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "NOTE", 0);
 2625    return(1);
 2626  }
 2627  if(ret==2) {
 2628    sprintf(xorriso->info_text, "%s aborted", cmd);
 2629    Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "NOTE", 0);
 2630    return(-1);
 2631  }
 2632  sprintf(xorriso->info_text, "%s revoked", cmd);
 2633  Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "NOTE", 0);
 2634  return(0);
 2635 }
 2636 
 2637 
 2638 int Xorriso_write_session_log(struct XorrisO *xorriso, int flag)
 2639 {
 2640  FILE *fp= NULL;
 2641  char *sfe= NULL, timetext[40], *rpt, *wpt;
 2642  int ret;
 2643 
 2644  if(xorriso->session_logfile[0]==0)
 2645    {ret= 2; goto ex;}
 2646 
 2647  Xorriso_alloc_meM(sfe, char, 5 * SfileadrL);
 2648 
 2649  fp= fopen(xorriso->session_logfile, "a");
 2650  if(fp==0) {
 2651    sprintf(xorriso->info_text, "-session_log: Cannot open file %s",
 2652            Text_shellsafe(xorriso->session_logfile, sfe, 0));
 2653    Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
 2654    {ret= 0; goto ex;}
 2655  }
 2656  wpt= sfe;
 2657  for(rpt= xorriso->volid; *rpt!=0; rpt++) {
 2658    if(*rpt=='\n') {
 2659      *(wpt++)= '\\';
 2660      *(wpt++)= 'n';
 2661    } else
 2662      *(wpt++)= *rpt;
 2663  }
 2664  *wpt= 0;
 2665  fprintf(fp, "%s %d %d %s\n",
 2666          Ftimetxt(time(0), timetext, 2), xorriso->session_lba,
 2667          xorriso->session_blocks, sfe);
 2668  fclose(fp);
 2669  ret= 1;
 2670 ex:;
 2671  Xorriso_free_meM(sfe);
 2672  return(ret);
 2673 }
 2674 
 2675 
 2676 int Xorriso_status_filter(struct XorrisO *xorriso, char *filter, char *line,
 2677                           int flag)
 2678 {
 2679  if(filter!=NULL)
 2680    if(filter[0]=='-')
 2681      if(strncmp(filter, line, strlen(filter))!=0)
 2682        return(0);
 2683  return(1);
 2684 }
 2685 
 2686 
 2687 int Xorriso_status_result(struct XorrisO *xorriso, char *filter, FILE *fp,
 2688                           int flag)
 2689 /* 
 2690 bit1= do only report to fp
 2691 */
 2692 {
 2693  int ret;
 2694 
 2695  ret= Xorriso_status_filter(xorriso, filter, xorriso->result_line, 0);
 2696  if(ret <= 0)
 2697    return(2);
 2698  if(!(flag&2))
 2699    Xorriso_result(xorriso,0);
 2700  if(fp!=NULL) {
 2701    ret= fwrite(xorriso->result_line,strlen(xorriso->result_line),1,fp);
 2702    if(ret<=0)
 2703      return(ret);
 2704  }   
 2705  return(1);
 2706 }
 2707 
 2708 
 2709 /*
 2710  bit0= do only report non-default settings
 2711  bit1= do only report to fp
 2712 */
 2713 int Xorriso_boot_status_sysarea(struct XorrisO *xorriso, char *filter,
 2714                                 FILE *fp, int flag)
 2715 {
 2716  char *line, *form= "any", *spec= "system_area=";
 2717  int sa_type;
 2718  
 2719  line= xorriso->result_line;
 2720  
 2721  sa_type= (xorriso->system_area_options & 0xfc) >> 2;
 2722  if(sa_type != 0) 
 2723    return(2);
 2724  if (xorriso->system_area_disk_path[0] == 0 && (flag & 1))
 2725    return(2);
 2726    
 2727  if(xorriso->system_area_options & 1) {
 2728    form= "grub";
 2729    if(xorriso->system_area_options & (1 << 14))
 2730      spec= "grub2_mbr=";
 2731  } else if(xorriso->system_area_options & 2) {
 2732    form= "isolinux";
 2733  } if(xorriso->system_area_options & (1 << 14)) {
 2734    form= "grub";
 2735    spec= "grub2_mbr=";
 2736  }
 2737  sprintf(line, "-boot_image %s %s", form, spec);
 2738  Text_shellsafe(xorriso->system_area_disk_path, line, 1);
 2739  strcat(line, "\n");
 2740  Xorriso_status_result(xorriso, filter, fp, flag & 2);
 2741  return(1);
 2742 }
 2743 
 2744 
 2745 static char *Xorriso__speedname(int speed)
 2746 {
 2747  static char name[64];
 2748 
 2749  if(speed > 0) {
 2750    sprintf(name, "%dkB/s", speed);
 2751    return(name);
 2752  } else if(speed == 0) {
 2753    return("max");
 2754  } else if(speed == -1) {
 2755    return("min");
 2756  } else if(speed == -2) {
 2757    return("none");
 2758  }
 2759  sprintf(name, "%d", speed);
 2760  return(name);
 2761 }
 2762 
 2763 
 2764 int Xorriso_status(struct XorrisO *xorriso, char *filter, FILE *fp, int flag)
 2765 /*
 2766  bit0= do only report non-default settings
 2767  bit1= do only report to fp
 2768  bit2= report current -resume status even if bit0 is set, but only if valid
 2769  bit3= report readline history
 2770  bit4= report -resume options indirectly as 
 2771               -options_from_file:${resume_state_file}_pos
 2772 */
 2773 {
 2774  int is_default, no_defaults, i, ret, adr_mode, do_single, behavior;
 2775  int show_indev= 1, show_outdev= 1, show_dev= 0;
 2776  int do_drive_access, did_drive_access;
 2777  int part_table_implicit= 0;
 2778  char *line, *sfe= NULL, mode[80], *form, *treatment;
 2779  char *in_pt, *out_pt, *nl_charset, *local_charset, *mode_pt;
 2780  char *dev_filter= NULL, *xorriso_id= NULL;
 2781  static char channel_prefixes[4][4]= {".","R","I","M"};
 2782  static char load_names[][20]= {"auto", "session", "track", "lba", "volid"};
 2783  static int max_load_mode= 4;
 2784  static char scsi_family[8][8]=
 2785                               {"default", "sr", "scd", "st", "sg", "", "", ""};
 2786  struct Xorriso_lsT *paths, *leafs, *s, *plst, *vlst;
 2787 
 2788  Xorriso_alloc_meM(sfe, char, 5 * SfileadrL + 80);
 2789  Xorriso_alloc_meM(xorriso_id, char, 129);
 2790 
 2791  no_defaults= flag&1;
 2792  line= xorriso->result_line;
 2793 
 2794  if(xorriso->no_rc) {
 2795    sprintf(line,"-no_rc\n");
 2796    Xorriso_status_result(xorriso,filter,fp,flag&2);
 2797  }
 2798 
 2799  is_default= strcmp(xorriso->list_delimiter, "--") == 0;
 2800  sprintf(line,"-list_delimiter %s\n", xorriso->list_delimiter);
 2801  if(!(is_default && no_defaults))
 2802    Xorriso_status_result(xorriso,filter,fp,flag&2);
 2803 
 2804  is_default= 0;
 2805  if(xorriso->dialog == 2)
 2806    sprintf(line,"-dialog on\n");
 2807  else if(xorriso->dialog == 1)
 2808    sprintf(line,"-dialog single_line\n");
 2809  else {
 2810    sprintf(line,"-dialog off\n");
 2811    is_default= 1;
 2812  }
 2813  if(!(is_default && no_defaults))
 2814    Xorriso_status_result(xorriso,filter,fp,flag&2);
 2815 
 2816  is_default= (xorriso->result_page_length==0 && xorriso->result_page_width==80);
 2817  sprintf(line,"-page %d %d\n",
 2818               (xorriso->result_page_length>=0?xorriso->result_page_length
 2819                                            :-xorriso->result_page_length),
 2820               xorriso->result_page_width);
 2821  if(!(is_default && no_defaults))
 2822    Xorriso_status_result(xorriso,filter,fp,flag&2);
 2823 
 2824  is_default= (xorriso->use_stdin==0);
 2825  sprintf(line,"-use_readline %s\n", (xorriso->use_stdin?"off":"on"));
 2826  if(!(is_default && no_defaults))
 2827    Xorriso_status_result(xorriso,filter,fp,flag&2);
 2828 
 2829  is_default= (xorriso->sh_style_result == 0);
 2830  sprintf(line, "-sh_style_result %s\n",
 2831          xorriso->sh_style_result ? "on" : "off");
 2832  if(!(is_default && no_defaults))
 2833    Xorriso_status_result(xorriso,filter,fp,flag&2);
 2834 
 2835  is_default= (xorriso->bsl_interpretation == 0);
 2836  strcpy(line, "-backslash_codes ");
 2837  if(xorriso->bsl_interpretation == 0)
 2838    strcat(line, "off");
 2839  else if(xorriso->bsl_interpretation == (3 | 16 | 32 | 64))
 2840    strcat(line, "on");
 2841  else {
 2842    if((xorriso->bsl_interpretation & 3) == 1)
 2843      strcat(line, "in_double_quotes");
 2844    else if((xorriso->bsl_interpretation & 3) == 2)
 2845      strcat(line, "in_quotes");
 2846    else if((xorriso->bsl_interpretation & 3) == 3)
 2847      strcat(line, "with_quoted_input");
 2848    if(xorriso->bsl_interpretation & 16) {
 2849      if(strlen(line) > 17)
 2850        strcat(line, ":"); 
 2851      strcat(line, "with_program_arguments");
 2852    }
 2853    if((xorriso->bsl_interpretation & (32 | 64)) == (32 | 64)) {
 2854      if(strlen(line) > 17)
 2855        strcat(line, ":"); 
 2856      strcat(line, "encode_output");
 2857    } else {
 2858      if(xorriso->bsl_interpretation & 32) {
 2859        if(strlen(line) > 17)
 2860          strcat(line, ":"); 
 2861        strcat(line, "encode_results");
 2862      }
 2863      if(xorriso->bsl_interpretation & 64) {
 2864        if(strlen(line) > 17)
 2865          strcat(line, ":"); 
 2866        strcat(line, "encode_infos");
 2867      }
 2868    }
 2869  }
 2870  strcat(line, "\n");
 2871  if(!(is_default && no_defaults))
 2872    Xorriso_status_result(xorriso,filter,fp,flag&2);
 2873 
 2874  is_default= !xorriso->packet_output;
 2875  sprintf(line,"-pkt_output %s\n",(xorriso->packet_output?"on":"off"));
 2876  if(!(is_default && no_defaults))
 2877    Xorriso_status_result(xorriso,filter,fp,flag&2);
 2878 
 2879  for(i=0;i<4;i++) {
 2880    is_default= (xorriso->logfile[i][0] == 0);
 2881    sprintf(line,"-logfile %s %s\n",
 2882            channel_prefixes[i],Text_shellsafe(xorriso->logfile[i],sfe,0));
 2883    if(!(is_default && no_defaults))
 2884      Xorriso_status_result(xorriso,filter,fp,flag&2);
 2885  }
 2886 
 2887  is_default= (xorriso->errfile_log[0]==0);
 2888  sprintf(line,"-errfile_log %s\n",Text_shellsafe(xorriso->errfile_log,sfe,0));
 2889  if(!(is_default && no_defaults))
 2890    Xorriso_status_result(xorriso,filter,fp,flag&2);
 2891 
 2892  if(xorriso->check_media_default == NULL) {
 2893    is_default= 1;
 2894    sprintf(line, "-check_media_defaults reset=now %s\n",
 2895            xorriso->list_delimiter);
 2896  } else {
 2897    ret= Xorriso_check_media_list_job(xorriso, xorriso->check_media_default,
 2898                                      line, no_defaults);
 2899    is_default= (ret == 2);
 2900    strcat(line, "\n");
 2901  }
 2902  if(!(is_default && no_defaults))
 2903    Xorriso_status_result(xorriso,filter,fp,flag&2);
 2904 
 2905  behavior= Xorriso__get_signal_behavior(0);
 2906  is_default= (behavior == 1);
 2907  treatment= "on";
 2908  if(behavior == 0)
 2909    treatment= "off";
 2910  else if(behavior == 2)
 2911    treatment= "sig_dfl";
 2912  else if(behavior == 3)
 2913    treatment= "sig_ign";
 2914  sprintf(line,"-signal_handling %s\n", treatment);
 2915  if(!(is_default && no_defaults))
 2916    Xorriso_status_result(xorriso,filter,fp,flag&2);
 2917 
 2918  is_default= (xorriso->img_read_error_mode==2);
 2919  treatment= "best_effort";
 2920  if(xorriso->img_read_error_mode==1)
 2921    treatment= "failure";
 2922  else if(xorriso->img_read_error_mode==2)
 2923    treatment= "fatal";
 2924  sprintf(line,"-error_behavior image_loading %s\n", treatment);
 2925  if(!(is_default && no_defaults))
 2926    Xorriso_status_result(xorriso,filter,fp,flag&2);
 2927  is_default= (xorriso->extract_error_mode == 1);
 2928  treatment= "keep";
 2929  if(xorriso->extract_error_mode == 0)
 2930    treatment= "best_effort";
 2931  else if(xorriso->extract_error_mode == 2)
 2932    treatment= "delete";
 2933  sprintf(line,"-error_behavior file_extraction %s\n", treatment);
 2934  if(!(is_default && no_defaults))
 2935    Xorriso_status_result(xorriso,filter,fp,flag&2);
 2936 
 2937  is_default= (xorriso->mark_text[0]==0);
 2938  sprintf(line,"-mark %s\n",Text_shellsafe(xorriso->mark_text,sfe,0));
 2939  if(!(is_default && no_defaults))
 2940    Xorriso_status_result(xorriso,filter,fp,flag&2);
 2941 
 2942  is_default= (xorriso->temp_mem_limit==16*1024*1024);
 2943  if((xorriso->temp_mem_limit/1024/1024)*1024*1024==xorriso->temp_mem_limit)
 2944    sprintf(line,"-temp_mem_limit %dm\n", xorriso->temp_mem_limit/1024/1024);
 2945  else
 2946    sprintf(line,"-temp_mem_limit %dk\n", xorriso->temp_mem_limit/1024);
 2947  if(!(is_default && no_defaults))
 2948    Xorriso_status_result(xorriso,filter,fp,flag&2);
 2949 
 2950 
 2951  sprintf(line,"-prog %s\n",Text_shellsafe(xorriso->progname,sfe,0));
 2952  Xorriso_status_result(xorriso,filter,fp,flag&2);
 2953 
 2954  if(xorriso->ban_stdio_write) {
 2955    sprintf(line,"-ban_stdio_write\n");
 2956    Xorriso_status_result(xorriso,filter,fp,flag&2);
 2957  }
 2958 
 2959  is_default= ((xorriso->early_stdio_test & 14) == 0);
 2960  sprintf(line, "-early_stdio_test %s\n",
 2961                xorriso->early_stdio_test & 6 ? xorriso->early_stdio_test & 8 ?
 2962                "appendable_wo" : "on" : "off");
 2963  if(!(is_default && no_defaults))
 2964    Xorriso_status_result(xorriso,filter,fp,flag&2);
 2965 
 2966  is_default= ((xorriso->cache_default & 3) == 3);
 2967  sprintf(line, "-data_cache_size ");
 2968  if(xorriso->cache_default & 1)
 2969    sprintf(line + strlen(line), "default ");
 2970  else
 2971    sprintf(line + strlen(line), "%d ", xorriso->cache_num_tiles);
 2972  if(xorriso->cache_default & 2)
 2973    sprintf(line + strlen(line), "default\n");
 2974  else
 2975    sprintf(line + strlen(line), "%d\n", xorriso->cache_tile_blocks);
 2976  if(!(is_default && no_defaults))
 2977    Xorriso_status_result(xorriso,filter,fp,flag&2);
 2978 
 2979  is_default= (xorriso->allow_restore==0 && xorriso->do_concat_split==1 &&
 2980               xorriso->do_auto_chmod==0 && xorriso->drives_exclusive == 1);
 2981  mode_pt= "off"; 
 2982  if(xorriso->allow_restore == -2)
 2983    mode_pt= "blocked";
 2984  else if(xorriso->allow_restore == -1)
 2985    mode_pt= "banned";
 2986  else if(xorriso->allow_restore == 1)
 2987    mode_pt= "on";
 2988  else if(xorriso->allow_restore == 2)
 2989    mode_pt= "device_files";
 2990  if(xorriso->allow_restore == -1)
 2991    sprintf(line,"-osirrox %s\n", mode_pt);
 2992  else
 2993    sprintf(line,"-osirrox %s:%s:%s:%s:%s\n", mode_pt,
 2994          xorriso->do_concat_split ? "concat_split_on" : "concat_split_off",
 2995          xorriso->do_auto_chmod ? "auto_chmod_on" : "auto_chmod_off",
 2996          xorriso->do_restore_sort_lba ? "sort_lba_on" : "sort_lba_off",
 2997          xorriso->drives_exclusive ? "o_excl_on" : "o_excl_off");
 2998  if(!(is_default && no_defaults))
 2999    Xorriso_status_result(xorriso,filter,fp,flag&2);
 3000 
 3001  is_default = ((xorriso->do_strict_acl & 1) == 0 &&
 3002                (xorriso->do_md5 & (64 | 128)) == 0 &&
 3003                xorriso->sparse_min_gap == 0);
 3004  sprintf(line,"-osirrox %s:%s:sparse=",
 3005          (xorriso->do_strict_acl & 1) ? "strict_acl_on" : "strict_acl_off",
 3006          (xorriso->do_md5 & 64) ? 
 3007                    (xorriso->do_md5 & 128) ? "check_md5_force" : "check_md5_on"
 3008                                 : "check_md5_off");
 3009  if(xorriso->sparse_min_gap <= 0)
 3010    strcat(line, "off");
 3011  else
 3012    Sfile_off_t_text(line  + strlen(line), xorriso->sparse_min_gap, 0);
 3013  strcat(line, "\n");
 3014  if(!(is_default && no_defaults))
 3015    Xorriso_status_result(xorriso, filter, fp, flag & 2);
 3016 
 3017  is_default= (xorriso->mount_opts_flag == 0);
 3018   sprintf(line,"-mount_opts %s\n",
 3019           xorriso->mount_opts_flag & 1 ? "shared" : "exclusive");
 3020  if(!(is_default && no_defaults))
 3021    Xorriso_status_result(xorriso,filter,fp,flag&2);
 3022 
 3023  Xorriso_boot_image_status(xorriso, filter, fp, flag & 3);
 3024 
 3025  Xorriso_boot_status_sysarea(xorriso, filter, fp, flag & 3);
 3026 
 3027  is_default= (xorriso->partition_offset == 0);
 3028  sprintf(line,"-boot_image any partition_offset=%lu\n",
 3029               (unsigned long int) xorriso->partition_offset);
 3030  if(!(is_default && no_defaults))
 3031    Xorriso_status_result(xorriso,filter,fp,flag&2);
 3032  is_default= (xorriso->partition_secs_per_head == 0);
 3033  sprintf(line,"-boot_image any partition_sec_hd=%lu\n",
 3034               (unsigned long int) xorriso->partition_secs_per_head);
 3035  if(!(is_default && no_defaults))
 3036    Xorriso_status_result(xorriso,filter,fp,flag&2);
 3037  is_default= (xorriso->partition_heads_per_cyl == 0);
 3038  sprintf(line,"-boot_image any partition_hd_cyl=%lu\n",
 3039               (unsigned long int) xorriso->partition_heads_per_cyl);
 3040  if(!(is_default && no_defaults))
 3041    Xorriso_status_result(xorriso,filter,fp,flag&2);
 3042 
 3043  ret= (xorriso->system_area_options & 0x300) >> 8;
 3044  is_default= (ret == 0);
 3045  sprintf(line,"-boot_image any partition_cyl_align=%s\n",
 3046          ret == 0 ? "auto" : ret == 1 ? "on" : ret == 3 ? "all" : "off");
 3047  if(!(is_default && no_defaults))
 3048    Xorriso_status_result(xorriso,filter,fp,flag&2);
 3049 
 3050  if((xorriso->system_area_disk_path[0] || !part_table_implicit) &&
 3051     (xorriso->partition_offset == 0 || (xorriso->system_area_options & 2))) {
 3052    is_default= ((xorriso->system_area_options & 3) == 0);
 3053    sprintf(line,"-boot_image %s partition_table=%s\n",
 3054            xorriso->system_area_options & 2 ? "isolinux" : "grub",
 3055            xorriso->system_area_options & 3 ? "on" : "off");
 3056    if(!(is_default && no_defaults))
 3057      Xorriso_status_result(xorriso,filter,fp,flag&2);
 3058  }
 3059 
 3060  is_default= ((xorriso->system_area_options & (1 << 15)) == 0);
 3061  sprintf(line, "-boot_image any mbr_force_bootable=%s\n",
 3062          (xorriso->system_area_options & (1 << 15)) ? "on" : "off");
 3063  if(!(is_default && no_defaults))
 3064    Xorriso_status_result(xorriso,filter,fp,flag&2);
 3065 
 3066  is_default= (xorriso->appended_as_gpt == 0 && xorriso->appended_as_apm == 0);
 3067  if(is_default) {
 3068    sprintf(line, "-boot_image any appended_part_as=mbr\n");
 3069    if(!no_defaults)
 3070      Xorriso_status_result(xorriso,filter,fp,flag&2);
 3071  } else {
 3072    if(xorriso->appended_as_gpt) {
 3073      sprintf(line, "-boot_image any appended_part_as=gpt\n");
 3074      Xorriso_status_result(xorriso,filter,fp,flag&2);
 3075    }
 3076    if(xorriso->appended_as_apm) {
 3077      sprintf(line, "-boot_image any appended_part_as=apm\n");
 3078      Xorriso_status_result(xorriso,filter,fp,flag&2);
 3079    }
 3080  }
 3081 
 3082  is_default= (xorriso->part_like_isohybrid == 0);
 3083  sprintf(line, "-boot_image any part_like_isohybrid=%s\n",
 3084          xorriso->part_like_isohybrid ? "on" : "off");
 3085  if(!(is_default && no_defaults))
 3086    Xorriso_status_result(xorriso,filter,fp,flag&2);
 3087 
 3088  is_default= (xorriso->iso_mbr_part_type == -1);
 3089  sprintf(line, "-boot_image any iso_mbr_part_type=");
 3090  if(xorriso->iso_mbr_part_flag & 1) {
 3091    Xorriso__format_guid(xorriso->iso_gpt_type_guid, line + strlen(line), 0);
 3092    strcat(line, "\n");
 3093  } else if(xorriso->iso_mbr_part_type == -1) {
 3094    sprintf(line + strlen(line), "default\n");
 3095  } else {
 3096    sprintf(line + strlen(line), "0x%-2.2x\n",
 3097            (unsigned int) xorriso->iso_mbr_part_type);
 3098  }
 3099  if(!(is_default && no_defaults))
 3100    Xorriso_status_result(xorriso,filter,fp,flag&2);
 3101 
 3102  is_default= (xorriso->gpt_guid_mode == 0);
 3103  sprintf(line, "-boot_image any gpt_disk_guid=%s",
 3104          xorriso->gpt_guid_mode == 0 ? "random" :
 3105          xorriso->gpt_guid_mode == 2 ? "volume_date_uuid" : "");
 3106  if(xorriso->gpt_guid_mode == 1)
 3107    for(i= 0; i < 16; i++)
 3108      sprintf(line + strlen(line), "%-2.2x",
 3109              (unsigned int) xorriso->gpt_guid[i]);
 3110  strcat(line, "\n");
 3111  if(!(is_default && no_defaults))
 3112    Xorriso_status_result(xorriso,filter,fp,flag&2);
 3113 
 3114  ret= ((xorriso->system_area_options & 0x3cfc) == 0x400);
 3115  is_default= (ret == 0);
 3116  sprintf(line, "-boot_image any chrp_boot_part=%s\n",
 3117          ret == 1 ? "on" : "off");
 3118  if(!(is_default && no_defaults))
 3119    Xorriso_status_result(xorriso, filter, fp, flag & 2);
 3120 
 3121  is_default= (xorriso->prep_partition[0] == 0);
 3122  sprintf(line,"-boot_image any prep_boot_part=%s\n", 
 3123               Text_shellsafe(xorriso->prep_partition, sfe, 0));
 3124  if(!(is_default && no_defaults))
 3125    Xorriso_status_result(xorriso, filter, fp, flag & 2);
 3126  
 3127  is_default= (xorriso->efi_boot_partition[0] == 0);
 3128  sprintf(line,"-boot_image any efi_boot_part=%s\n",
 3129               Text_shellsafe(xorriso->efi_boot_partition, sfe, 0));
 3130  if(!(is_default && no_defaults))
 3131    Xorriso_status_result(xorriso, filter, fp, flag & 2);
 3132 
 3133 #ifdef Xorriso_with_isohybriD
 3134  if(strcmp(form, "isolinux") == 0) {
 3135    static char modes[4][6]= {"off", "auto", "on", "force"};
 3136    is_default= (xorriso->boot_image_isohybrid == 1);
 3137    sprintf(line,"-boot_image isolinux isohybrid=%s\n",
 3138            modes[xorriso->boot_image_isohybrid & 3]);
 3139    if(!(is_default && no_defaults))
 3140      Xorriso_status_result(xorriso,filter,fp,flag&2);
 3141  }
 3142 #endif /* Xorriso_with_isohybriD */
 3143 
 3144  is_default= 1;
 3145  for(i= 0; i < 8; i++)
 3146    if(xorriso->hfsp_serial_number[i])
 3147      is_default= 0;
 3148  sprintf(line, "-boot_image any hfsplus_serial=");
 3149  for(i= 0; i < 8; i++)
 3150    sprintf(line + strlen(line), "%-2.2X",
 3151            (unsigned int) xorriso->hfsp_serial_number[i]);
 3152  strcat(line, "\n");
 3153  if(!(is_default && no_defaults))
 3154    Xorriso_status_result(xorriso, filter, fp, flag & 2);
 3155 
 3156  is_default= (xorriso->hfsp_block_size == 0);
 3157  sprintf(line, "-boot_image any hfsplus_block_size=%d\n",
 3158                xorriso->hfsp_block_size);
 3159  if(!(is_default && no_defaults))
 3160    Xorriso_status_result(xorriso, filter, fp, flag & 2);
 3161 
 3162  is_default= (xorriso->apm_block_size == 0);
 3163  sprintf(line, "-boot_image any apm_block_size=%d\n",
 3164                xorriso->apm_block_size);
 3165  if(!(is_default && no_defaults))
 3166    Xorriso_status_result(xorriso, filter, fp, flag & 2);
 3167 
 3168  sprintf(line,"-cd ");
 3169  if(filter != NULL)
 3170    if(strncmp(filter, "-cdi", 4) == 0)
 3171      sprintf(line,"-cdi ");
 3172  sprintf(line + strlen(line),"%s\n",
 3173          (xorriso->wdi[0] ? Text_shellsafe(xorriso->wdi,sfe,0) : "'/'"));
 3174  Xorriso_status_result(xorriso,filter,fp,flag&2);
 3175  sprintf(line,"-cdx %s\n",
 3176          (xorriso->wdx[0] ? Text_shellsafe(xorriso->wdx,sfe,0) : "'/'"));
 3177  Xorriso_status_result(xorriso,filter,fp,flag&2);
 3178 
 3179  is_default= (xorriso->split_size==0);
 3180  strcpy(line,"-split_size ");
 3181  if(xorriso->split_size % (1024*1024) || xorriso->split_size==0) {
 3182    Sfile_off_t_text(line+strlen(line), xorriso->split_size, 0);
 3183  } else {
 3184    Sfile_off_t_text(line+strlen(line), xorriso->split_size / (1024*1024), 0);
 3185    strcat(line, "m");
 3186  }
 3187  strcat(line, "\n");
 3188  if(!(is_default && no_defaults))
 3189    Xorriso_status_result(xorriso,filter,fp,flag&2);
 3190 
 3191  is_default= (xorriso->add_plainly==0);
 3192  sprintf(line,"-add_plainly %s\n",
 3193          (xorriso->add_plainly == 1 ? "unknown" : 
 3194           xorriso->add_plainly == 2 ? "dashed" :
 3195           xorriso->add_plainly == 3 ? "any" : "none"));
 3196  if(!(is_default && no_defaults))
 3197    Xorriso_status_result(xorriso,filter,fp,flag&2);
 3198 
 3199  ret= Exclusions_get_descrs(xorriso->disk_exclusions, &paths, &leafs, 0);
 3200  if(ret>0) {
 3201    for(; paths!=NULL; paths= paths->next) {
 3202      sprintf(line, "-not_paths %s %s\n",
 3203              Text_shellsafe(paths->text, sfe, 0), xorriso->list_delimiter);
 3204      Xorriso_status_result(xorriso,filter,fp,flag&2);
 3205    } 
 3206    for(; leafs!=NULL; leafs= leafs->next) {
 3207      sprintf(line,"-not_leaf %s\n", Text_shellsafe(leafs->text, sfe, 0));
 3208      Xorriso_status_result(xorriso,filter,fp,flag&2);
 3209    } 
 3210  }
 3211 
 3212  is_default= (xorriso->file_name_limit == 255);
 3213  sprintf(line, "-file_name_limit %d\n", xorriso->file_name_limit);
 3214  if(!(is_default && no_defaults))
 3215    Xorriso_status_result(xorriso,filter,fp,flag&2);
 3216 
 3217  is_default= (xorriso->file_size_limit ==
 3218               Xorriso_default_file_size_limiT);
 3219  if(xorriso->file_size_limit <= 0)
 3220    sprintf(line, "-file_size_limit off %s\n", xorriso->list_delimiter);
 3221  else
 3222    sprintf(line, "-file_size_limit %.f %s\n",
 3223            (double) xorriso->file_size_limit, xorriso->list_delimiter);
 3224  if(!(is_default && no_defaults))
 3225    Xorriso_status_result(xorriso,filter,fp,flag&2);
 3226 
 3227  is_default= (xorriso->disk_excl_mode==1);
 3228  sprintf(line, "-not_mgt %s:%s:%s:%s\n",
 3229          (xorriso->disk_excl_mode&1 ? "on" : "off"),
 3230          (xorriso->disk_excl_mode&2 ? "param_on" : "param_off"),
 3231          (xorriso->disk_excl_mode&4 ? "subtree_on" : "subtree_off"),
 3232          (xorriso->disk_excl_mode&8 ? "ignore_on" : "ignore_off"));
 3233  if(!(is_default && no_defaults))
 3234    Xorriso_status_result(xorriso,filter,fp,flag&2);
 3235 
 3236  is_default= (xorriso->do_override_now_time == 0);
 3237  if(xorriso->do_override_now_time)
 3238    sprintf(line, "-iso_nowtime =%.f\n", (double) xorriso->now_time_override);
 3239  else
 3240    sprintf(line, "-iso_nowtime dynamic\n");
 3241  if(!(is_default && no_defaults))
 3242    Xorriso_status_result(xorriso, filter, fp, flag & 2);
 3243 
 3244  is_default= (xorriso->do_iso_rr_pattern==1);
 3245  sprintf(line,"-iso_rr_pattern %s\n",
 3246          (xorriso->do_iso_rr_pattern == 1 ? "on" :
 3247          (xorriso->do_iso_rr_pattern == 2 ? "ls" : "off")));
 3248  if(!(is_default && no_defaults))
 3249    Xorriso_status_result(xorriso,filter,fp,flag&2);
 3250 
 3251  is_default= (xorriso->do_disk_pattern==2);
 3252  sprintf(line,"-disk_pattern %s\n",
 3253          (xorriso->do_disk_pattern == 1 ? "on" :
 3254          (xorriso->do_disk_pattern == 2 ? "ls" : "off")));
 3255  if(!(is_default && no_defaults))
 3256    Xorriso_status_result(xorriso,filter,fp,flag&2);
 3257 
 3258  is_default= xorriso->volid_default;
 3259  sprintf(line,"-volid %s\n",Text_shellsafe(xorriso->volid,sfe,0));
 3260  if(!(is_default && no_defaults))
 3261    Xorriso_status_result(xorriso,filter,fp,flag&2);
 3262  if(is_default && xorriso->loaded_volid[0] &&
 3263     strcmp(xorriso->loaded_volid, xorriso->volid)!=0 && !no_defaults) {
 3264    sprintf(line,"# loaded image effective -volid %s\n",
 3265            Text_shellsafe(xorriso->loaded_volid,sfe,0));
 3266    Xorriso_status_result(xorriso,filter,fp,flag&2);
 3267  }
 3268 
 3269  Xorriso_preparer_string(xorriso, xorriso_id, 0);
 3270  is_default= (strcmp(xorriso->preparer_id, xorriso_id) == 0);
 3271  sprintf(line,"-preparer_id %s\n",Text_shellsafe(xorriso->preparer_id,sfe,0));
 3272  if(!(is_default && no_defaults))
 3273    Xorriso_status_result(xorriso,filter,fp,flag&2);
 3274 
 3275  is_default= (xorriso->publisher[0]==0);
 3276  sprintf(line,"-publisher %s\n",Text_shellsafe(xorriso->publisher,sfe,0));
 3277  if(!(is_default && no_defaults))
 3278    Xorriso_status_result(xorriso,filter,fp,flag&2);
 3279 
 3280  is_default= (xorriso->application_id[0]==0);
 3281  sprintf(line,"-application_id %s\n",
 3282          Text_shellsafe(xorriso->application_id,sfe,0));
 3283  if(!(is_default && no_defaults))
 3284    Xorriso_status_result(xorriso,filter,fp,flag&2);
 3285 
 3286  is_default= (xorriso->system_id[0]==0);
 3287  sprintf(line,"-system_id %s\n", Text_shellsafe(xorriso->system_id,sfe,0));
 3288  if(!(is_default && no_defaults))
 3289    Xorriso_status_result(xorriso,filter,fp,flag&2);
 3290 
 3291  is_default= (xorriso->volset_id[0]==0);
 3292  sprintf(line,"-volset_id %s\n", Text_shellsafe(xorriso->volset_id,sfe,0));
 3293  if(!(is_default && no_defaults))
 3294    Xorriso_status_result(xorriso,filter,fp,flag&2);
 3295 
 3296  is_default= (xorriso->vol_creation_time == 0);
 3297  sprintf(line,"-volume_date c %s\n",
 3298          is_default ? "default" :
 3299          Ftimetxt(xorriso->vol_creation_time, sfe, 2));
 3300  if(!(is_default && no_defaults))
 3301    Xorriso_status_result(xorriso,filter,fp,flag&2);
 3302 
 3303  is_default= (xorriso->vol_modification_time == 0);
 3304  sprintf(line,"-volume_date m %s\n",
 3305          xorriso->vol_uuid[0] ? "overridden" :
 3306          is_default ? "default" :
 3307          Ftimetxt(xorriso->vol_modification_time, sfe, 2));
 3308  if(!(is_default && no_defaults))
 3309    Xorriso_status_result(xorriso,filter,fp,flag&2);
 3310 
 3311  is_default= (xorriso->vol_expiration_time == 0);
 3312  sprintf(line,"-volume_date x %s\n",
 3313          is_default ? "default" :
 3314          Ftimetxt(xorriso->vol_expiration_time, sfe, 2));
 3315  if(!(is_default && no_defaults))
 3316    Xorriso_status_result(xorriso,filter,fp,flag&2);
 3317 
 3318  is_default= (xorriso->vol_effective_time == 0);
 3319  sprintf(line,"-volume_date f %s\n",
 3320          is_default ? "default" :
 3321          Ftimetxt(xorriso->vol_effective_time, sfe, 2));
 3322  if(!(is_default && no_defaults))
 3323    Xorriso_status_result(xorriso,filter,fp,flag&2);
 3324 
 3325  is_default= (xorriso->vol_uuid[0] == 0);
 3326  sprintf(line,"-volume_date uuid %s\n",
 3327          Text_shellsafe(xorriso->vol_uuid,sfe,0));
 3328  if(!(is_default && no_defaults))
 3329    Xorriso_status_result(xorriso,filter,fp,flag&2);
 3330 
 3331  is_default= (xorriso->all_file_dates[0] == 0);
 3332  sprintf(line,"-volume_date all_file_dates %s\n",
 3333          Text_shellsafe(xorriso->all_file_dates,sfe,0));
 3334  if(!(is_default && no_defaults))
 3335    Xorriso_status_result(xorriso,filter,fp,flag&2);
 3336 
 3337  is_default= (xorriso->copyright_file[0] == 0);
 3338  sprintf(line,"-copyright_file %s\n",
 3339         Text_shellsafe(xorriso->copyright_file,sfe,0));
 3340  if(!(is_default && no_defaults))
 3341    Xorriso_status_result(xorriso,filter,fp,flag&2);
 3342 
 3343  is_default= (xorriso->biblio_file[0]==0);
 3344  sprintf(line,"-biblio_file %s\n",Text_shellsafe(xorriso->biblio_file,sfe,0));
 3345  if(!(is_default && no_defaults))
 3346    Xorriso_status_result(xorriso,filter,fp,flag&2);
 3347 
 3348  is_default= (xorriso->abstract_file[0]==0);
 3349  sprintf(line,"-abstract_file %s\n",
 3350          Text_shellsafe(xorriso->abstract_file,sfe,0));
 3351  if(!(is_default && no_defaults))
 3352    Xorriso_status_result(xorriso,filter,fp,flag&2);
 3353 
 3354  is_default= (strcmp(xorriso->application_use, " ") == 0);
 3355  sprintf(line, "-application_use %s\n",
 3356          Text_shellsafe(xorriso->application_use, sfe, 0));
 3357  if(!(is_default && no_defaults))
 3358    Xorriso_status_result(xorriso,filter,fp,flag&2);
 3359 
 3360  is_default= (xorriso->do_joliet==0);
 3361  sprintf(line,"-joliet %s\n", (xorriso->do_joliet == 1 ? "on" : "off"));
 3362  if(!(is_default && no_defaults))
 3363    Xorriso_status_result(xorriso,filter,fp,flag&2);
 3364 
 3365  is_default= (xorriso->do_rockridge == 1);
 3366  sprintf(line, "-rockridge %s\n", (xorriso->do_rockridge == 1 ? "on" : "off"));
 3367  if(!(is_default && no_defaults))
 3368    Xorriso_status_result(xorriso,filter,fp,flag&2);
 3369 
 3370  is_default= (xorriso->do_hfsplus == 0);
 3371  sprintf(line,"-hfsplus %s\n", (xorriso->do_hfsplus == 1 ? "on" : "off"));
 3372  if(!(is_default && no_defaults))
 3373    Xorriso_status_result(xorriso,filter,fp,flag&2);
 3374 
 3375  Xorriso_lst_get_last(xorriso->jigdo_params, &plst, 0);
 3376  Xorriso_lst_get_last(xorriso->jigdo_values, &vlst, 0);
 3377  if(plst == NULL || vlst == NULL) {
 3378    is_default= 1;
 3379    sprintf(line,"-jigdo clear 'all'\n");
 3380    if(!(is_default && no_defaults))
 3381      Xorriso_status_result(xorriso, filter, fp, flag & 2);
 3382  }
 3383  while(plst != NULL && vlst != NULL) {
 3384    sprintf(line,"-jigdo %s %s\n", Xorriso_lst_get_text(plst, 0), 
 3385            Text_shellsafe(Xorriso_lst_get_text(vlst, 0), sfe, 0));
 3386    Xorriso_status_result(xorriso, filter, fp, flag & 2);
 3387    plst= Xorriso_lst_get_prev(plst, 0);
 3388    vlst= Xorriso_lst_get_prev(vlst, 0);
 3389  }
 3390 
 3391  if(xorriso->do_global_uid) {
 3392    sprintf(line,"-uid %lu\n", (unsigned long) xorriso->global_uid);
 3393    Xorriso_status_result(xorriso,filter,fp,flag&2);
 3394  }
 3395 
 3396  if(xorriso->do_global_gid) {
 3397    sprintf(line,"-gid %lu\n", (unsigned long) xorriso->global_gid);
 3398    Xorriso_status_result(xorriso,filter,fp,flag&2);
 3399  }
 3400 
 3401  Xorriso_status_extf(xorriso, filter, fp, flag & 2);
 3402  Xorriso_status_zisofs(xorriso, filter, fp, flag & 3);
 3403 
 3404  is_default= !xorriso->allow_graft_points;
 3405  sprintf(line,"-pathspecs %s\n",
 3406          (xorriso->allow_graft_points & 2) ? "as_mkisofs" :
 3407            xorriso->allow_graft_points ? "on" : "off");
 3408  if(!(is_default && no_defaults))
 3409    Xorriso_status_result(xorriso,filter,fp,flag&2);
 3410 
 3411  is_default= (xorriso->do_follow_pattern && (!xorriso->do_follow_param)
 3412               && xorriso->do_follow_mount && (!xorriso->do_follow_links)
 3413               && xorriso->follow_link_limit==100
 3414               && (!xorriso->do_follow_concat));
 3415  mode[0]= 0;
 3416  if(xorriso->do_follow_pattern &&
 3417     !(xorriso->do_follow_links && xorriso->do_follow_mount))
 3418    strcat(mode,":pattern");
 3419  if(xorriso->do_follow_param && !(xorriso->do_follow_links))
 3420    strcat(mode,":param");
 3421  if(xorriso->do_follow_links)
 3422    strcat(mode,":link");
 3423  if(xorriso->do_follow_concat)
 3424    strcat(mode,":concat");
 3425  if(xorriso->do_follow_mount)
 3426    strcat(mode,":mount");
 3427  if(mode[0]==0)
 3428    strcpy(mode, ":off");
 3429  sprintf(mode+strlen(mode), ":limit=%d", xorriso->follow_link_limit);
 3430  sprintf(line,"-follow %s\n", mode+1);
 3431  if(!(is_default && no_defaults))
 3432    Xorriso_status_result(xorriso,filter,fp,flag&2);
 3433 
 3434  is_default= (xorriso->do_overwrite==2);
 3435  sprintf(line,"-overwrite %s\n",(xorriso->do_overwrite == 1 ? "on" :
 3436                              (xorriso->do_overwrite == 2 ? "nondir" : "off")));
 3437  if(!(is_default && no_defaults))
 3438    Xorriso_status_result(xorriso,filter,fp,flag&2);
 3439 
 3440  is_default= !xorriso->do_reassure;
 3441  sprintf(line,"-reassure %s\n",(xorriso->do_reassure == 1 ? "on" :
 3442                              (xorriso->do_reassure == 2 ? "tree" : "off")));
 3443  if(!(is_default && no_defaults))
 3444    Xorriso_status_result(xorriso,filter,fp,flag&2);
 3445 
 3446  is_default= (xorriso->read_speed == -2);
 3447  sprintf(line,"-read_speed %s\n", Xorriso__speedname(xorriso->read_speed));
 3448  if(!(is_default && no_defaults))
 3449    Xorriso_status_result(xorriso,filter,fp,flag&2);
 3450  is_default= (xorriso->read_speed_force <= 0);
 3451  sprintf(line,"-read_speed soft_force:%s\n",
 3452               xorriso->read_speed_force <= 0 ?
 3453                           "0" : Xorriso__speedname(xorriso->read_speed_force));
 3454  if(!(is_default && no_defaults))
 3455    Xorriso_status_result(xorriso,filter,fp,flag&2);
 3456  is_default= (xorriso->read_speed_corr == 250000);
 3457  sprintf(line,"-read_speed soft_corr:%d\n", xorriso->read_speed_corr);
 3458  if(!(is_default && no_defaults))
 3459    Xorriso_status_result(xorriso,filter,fp,flag&2);
 3460 
 3461  is_default= !(xorriso->auto_close || xorriso->do_close);
 3462  sprintf(line,"-close %s\n",xorriso->auto_close ? "as_needed" :
 3463                             xorriso->do_close ? "on" : "off");
 3464  if(!(is_default && no_defaults))
 3465    Xorriso_status_result(xorriso,filter,fp,flag&2);
 3466 
 3467  is_default= (xorriso->do_tao == 0);
 3468  sprintf(line,"-write_type %s\n",
 3469       xorriso->do_tao == 0 ? "auto" : xorriso->do_tao > 0 ? "tao" : "sao/dao");
 3470  if(!(is_default && no_defaults))
 3471    Xorriso_status_result(xorriso,filter,fp,flag&2);
 3472 
 3473  is_default= !xorriso->do_dummy;
 3474  sprintf(line,"-dummy %s\n",(xorriso->do_dummy ? "on" : "off"));
 3475  if(!(is_default && no_defaults))
 3476    Xorriso_status_result(xorriso,filter,fp,flag&2);
 3477 
 3478  is_default= (xorriso->write_speed==0);
 3479  sprintf(line,"-speed %s\n", Xorriso__speedname(xorriso->write_speed));
 3480  if(!(is_default && no_defaults))
 3481    Xorriso_status_result(xorriso,filter,fp,flag&2);
 3482 
 3483  is_default= (xorriso->do_stream_recording==0);
 3484  strcpy(mode, "off");
 3485  if(xorriso->do_stream_recording == 1)
 3486    strcpy(mode, "full");
 3487  if(xorriso->do_stream_recording == 2)
 3488    strcpy(mode, "data");
 3489  else if(xorriso->do_stream_recording == 32)
 3490    strcpy(mode, "on");
 3491  else if(xorriso->do_stream_recording >= 16)
 3492    sprintf(mode, "%ds", xorriso->do_stream_recording);
 3493  sprintf(line,"-stream_recording %s\n", mode);
 3494  if(!(is_default && no_defaults))
 3495    Xorriso_status_result(xorriso,filter,fp,flag&2);
 3496 
 3497  is_default= (xorriso->modesty_on_drive == 0 &&
 3498               xorriso->min_buffer_usec == 5000 &&
 3499               xorriso->max_buffer_usec == 25000 &&
 3500               xorriso->buffer_timeout_sec == 120 &&
 3501               xorriso->min_buffer_percent == 90 &&
 3502               xorriso->max_buffer_percent == 95);
 3503  if(xorriso->modesty_on_drive == 0)
 3504    strcpy(mode, "off");
 3505  else if(xorriso->modesty_on_drive == 1)
 3506    strcpy(mode, "on");
 3507  else
 3508    sprintf(mode, "%d", xorriso->modesty_on_drive);
 3509  sprintf(mode + strlen(mode), ":min_percent=%d", xorriso->min_buffer_percent);
 3510  sprintf(mode + strlen(mode), ":max_percent=%d", xorriso->max_buffer_percent);
 3511  if(xorriso->buffer_timeout_sec >= 0)
 3512    sprintf(mode + strlen(mode), ":timeout_sec=%d", xorriso->buffer_timeout_sec);
 3513  if(xorriso->min_buffer_usec >= 0)
 3514    sprintf(mode + strlen(mode), ":min_usec=%d", xorriso->min_buffer_usec);
 3515  if(xorriso->max_buffer_usec >= 0)
 3516    sprintf(mode + strlen(mode), ":max_usec=%d", xorriso->max_buffer_usec);
 3517  sprintf(line,"-modesty_on_drive %s\n", mode);
 3518  if(!(is_default && no_defaults))
 3519    Xorriso_status_result(xorriso,filter,fp,flag&2);
 3520 
 3521  is_default= (xorriso->dvd_obs == 0);
 3522  strcpy(mode, "default");
 3523  if(xorriso->dvd_obs == 32768 || xorriso->dvd_obs == 65536)
 3524    sprintf(mode, "%dk", xorriso->dvd_obs / 1024);
 3525  sprintf(line,"-dvd_obs %s\n", mode);
 3526  if(!(is_default && no_defaults))
 3527    Xorriso_status_result(xorriso,filter,fp,flag&2);
 3528 
 3529  is_default= (xorriso->use_immed_bit == 0);
 3530  strcpy(line, "-use_immed_bit ");
 3531  if(xorriso->use_immed_bit == 0) {
 3532    strcat(line, "default");
 3533    if(xorriso->use_immed_bit_default > 0)
 3534      strcat(line, "/on");
 3535    else if(xorriso->use_immed_bit_default < 0)
 3536      strcat(line, "/off");
 3537    strcat(line, "\n");
 3538  } else if(xorriso->use_immed_bit > 0) {
 3539    strcat(line, "on\n");
 3540  } else if(xorriso->use_immed_bit < 0) {
 3541    strcat(line, "off\n");
 3542  }
 3543  if(!(is_default && no_defaults))
 3544    Xorriso_status_result(xorriso,filter,fp,flag&2);
 3545 
 3546  is_default= (xorriso->stdio_sync == 0);
 3547  strcpy(line, "-stdio_sync ");
 3548  if(xorriso->stdio_sync == -1)
 3549    strcat(line, "off");
 3550  else if(xorriso->stdio_sync == 0)
 3551    strcat(line, "on");
 3552  else if(xorriso->stdio_sync == 1)
 3553    strcat(line, "end");
 3554  else if(xorriso->stdio_sync % 512) {
 3555    Sfile_off_t_text(line+strlen(line), (off_t) (xorriso->stdio_sync * 2048),
 3556                     0);
 3557  } else {
 3558    Sfile_off_t_text(line+strlen(line), (off_t) (xorriso->stdio_sync / 512), 0);
 3559    strcat(line, "m"); 
 3560  }
 3561  strcat(line, "\n"); 
 3562  if(!(is_default && no_defaults))
 3563    Xorriso_status_result(xorriso,filter,fp,flag&2);
 3564 
 3565  is_default= (xorriso->fs==4*512);
 3566  if((xorriso->fs/512)*512==xorriso->fs)
 3567    sprintf(line,"-fs %dm\n", xorriso->fs/512);
 3568  else
 3569    sprintf(line,"-fs %dk\n", xorriso->fs*2);
 3570  if(!(is_default && no_defaults))
 3571    Xorriso_status_result(xorriso,filter,fp,flag&2);
 3572 
 3573  is_default= (xorriso->padding==300*1024);
 3574  sprintf(line,"-padding %dk\n", xorriso->padding/1024);
 3575  if(!(is_default && no_defaults))
 3576    Xorriso_status_result(xorriso,filter,fp,flag&2);
 3577  is_default= (xorriso->do_padding_by_libisofs == 0);
 3578  sprintf(line,"-padding %s\n",
 3579          xorriso->do_padding_by_libisofs ? "included" : "appended");
 3580  if(!(is_default && no_defaults))
 3581    Xorriso_status_result(xorriso,filter,fp,flag&2);
 3582 
 3583  is_default= (strcmp(xorriso->report_about_text,"UPDATE")==0);
 3584  sprintf(line,"-report_about %s\n",xorriso->report_about_text);
 3585  if(!(is_default && no_defaults))
 3586    Xorriso_status_result(xorriso,filter,fp,flag&2);
 3587 
 3588  is_default= (xorriso->scsi_log == 0);
 3589  sprintf(line,"-scsi_log %s\n", xorriso->scsi_log ? "on" : "off");
 3590  if(!(is_default && no_defaults))
 3591    Xorriso_status_result(xorriso,filter,fp,flag&2);
 3592 
 3593  is_default= (xorriso->session_logfile[0]==0);
 3594  sprintf(line,"-session_log %s\n",
 3595          Text_shellsafe(xorriso->session_logfile,sfe,0));
 3596  if(!(is_default && no_defaults))
 3597    Xorriso_status_result(xorriso,filter,fp,flag&2);
 3598 
 3599  is_default= (xorriso->pacifier_style==0);
 3600  sprintf(line,"-pacifier '%s'\n",
 3601          xorriso->pacifier_style==1 ? "mkisofs" : 
 3602          xorriso->pacifier_style==2 ? "cdrecord" : "xorriso");
 3603  if(!(is_default && no_defaults))
 3604    Xorriso_status_result(xorriso,filter,fp,flag&2);
 3605  is_default= (xorriso->pacifier_interval == 1.0);
 3606  sprintf(line,"-pacifier interval=%f\n", xorriso->pacifier_interval);
 3607  if(!(is_default && no_defaults))
 3608    Xorriso_status_result(xorriso,filter,fp,flag&2);
 3609 
 3610  is_default= (strcmp(xorriso->return_with_text,"SORRY")==0 &&
 3611               xorriso->return_with_value==32);
 3612  sprintf(line,"-return_with %s %d\n",
 3613          xorriso->return_with_text, xorriso->return_with_value);
 3614  if(!(is_default && no_defaults))
 3615    Xorriso_status_result(xorriso,filter,fp,flag&2);
 3616  
 3617  is_default= 0;
 3618  sprintf(line,"-abort_on %s\n",xorriso->abort_on_text);
 3619  if(!(is_default && no_defaults))
 3620    Xorriso_status_result(xorriso,filter,fp,flag&2);
 3621  
 3622  if(xorriso->status_history_max!=Xorriso_status_history_maX || !no_defaults) {
 3623    sprintf(line,"-status_history_max %d\n",xorriso->status_history_max);
 3624    Xorriso_status_result(xorriso,filter,fp,flag&2);
 3625  }
 3626 
 3627 #ifdef Xorriso_with_line_editoR
 3628 
 3629  if((flag & 8) && xorriso->status_history_max > 0 && !xorriso->use_stdin)
 3630    Xorriso_status_history(xorriso, filter, fp, flag & 2);
 3631 
 3632 #endif /* Xorriso_with_line_editoR */
 3633 
 3634  is_default= (xorriso->toc_emulation_flag == 0);
 3635  sprintf(line,"-rom_toc_scan %s:%s:%s\n",
 3636          xorriso->toc_emulation_flag & 4 ? "force" :
 3637                                 xorriso->toc_emulation_flag & 1 ? "on" : "off",
 3638          xorriso->toc_emulation_flag & 2 ? "emul_off" : "emul_on",
 3639          xorriso->toc_emulation_flag & 8 ? "emul_wide" : "emul_narrow");
 3640  if(!(is_default && no_defaults))
 3641    Xorriso_status_result(xorriso, filter, fp, flag & 2);
 3642 
 3643  is_default= (xorriso->displacement == 0);
 3644  sprintf(line, "-displacement %s%lu\n",
 3645                xorriso->displacement_sign < 0 ? "-" : "",
 3646                (unsigned long) xorriso->displacement);
 3647  if(!(is_default && no_defaults))
 3648    Xorriso_status_result(xorriso, filter, fp, flag & 2);
 3649 
 3650  adr_mode= xorriso->image_start_mode & 0xffff;
 3651  if(adr_mode>=0 && adr_mode<=max_load_mode) {
 3652    is_default= (adr_mode==0);
 3653    sprintf(line,"-load %s ", load_names[adr_mode]);
 3654    if(adr_mode==0)
 3655      sprintf(line+strlen(line),"''\n");
 3656    else if(adr_mode>=1 && adr_mode<=3)
 3657      sprintf(line+strlen(line),"%s\n", xorriso->image_start_value);
 3658    else
 3659      sprintf(line+strlen(line),"%s\n",
 3660               Text_shellsafe(xorriso->image_start_value, sfe, 0));
 3661    if(!(is_default && no_defaults))
 3662      Xorriso_status_result(xorriso,filter,fp,flag&2);
 3663  }
 3664 
 3665  is_default= (xorriso->read_fs == 0);
 3666  sprintf(line, "-read_fs %s\n",
 3667          xorriso->read_fs == 0 ? "any" :
 3668          xorriso->read_fs == 1 ? "norock" :
 3669          xorriso->read_fs == 2 ? "nojoliet" : "ecma119");
 3670  if(!(is_default && no_defaults))
 3671    Xorriso_status_result(xorriso, filter, fp, flag & 2);
 3672 
 3673  is_default= (xorriso->do_calm_drive & 1);
 3674  sprintf(line,"-calm_drive %s\n", xorriso->do_calm_drive & 1 ? "on" : "off");
 3675  if(!(is_default && no_defaults))
 3676    Xorriso_status_result(xorriso,filter,fp,flag&2);
 3677 
 3678  is_default= (xorriso->grow_blindly_msc2<0);
 3679  sprintf(sfe, "%d", xorriso->grow_blindly_msc2);
 3680  sprintf(line,"-grow_blindly %s\n",
 3681          xorriso->grow_blindly_msc2 < 0 ? "off" : sfe);
 3682  if(!(is_default && no_defaults))
 3683    Xorriso_status_result(xorriso,filter,fp,flag&2);
 3684 
 3685  Xorriso_get_local_charset(xorriso, &local_charset, 0);
 3686  nl_charset= nl_langinfo(CODESET);
 3687  is_default= (strcmp(local_charset, nl_charset) == 0);
 3688  sprintf(line, "-local_charset %s\n", Text_shellsafe(local_charset, sfe, 0));
 3689  if(!(is_default && no_defaults))
 3690    Xorriso_status_result(xorriso, filter, fp, flag & 2);
 3691 
 3692  is_default= (xorriso->out_charset == NULL && xorriso->in_charset == NULL);
 3693  in_pt= "";
 3694  if(xorriso->in_charset != NULL)
 3695    in_pt= xorriso->in_charset;
 3696  out_pt= "";
 3697  if(xorriso->out_charset != NULL)
 3698    out_pt= xorriso->out_charset;
 3699  do_single= 0;
 3700  ret= Xorriso_status_filter(xorriso, filter, "-in_charset", 0);
 3701  if(ret <= 0)
 3702    ret= Xorriso_status_filter(xorriso, filter, "-out_charset", 0);
 3703  if(ret > 0)
 3704    do_single= 1;
 3705  if(strcmp(in_pt, out_pt) == 0 && !do_single) {
 3706    sprintf(line, "-charset %s\n", Text_shellsafe(in_pt, sfe, 0));
 3707    if(!(is_default && no_defaults))
 3708      Xorriso_status_result(xorriso, filter, fp, flag & 2);
 3709  } else {
 3710    sprintf(line, "-in_charset %s\n", Text_shellsafe(in_pt, sfe, 0));
 3711    if(!(is_default && no_defaults))
 3712      Xorriso_status_result(xorriso, filter, fp, flag & 2);
 3713    sprintf(line, "-out_charset %s\n", Text_shellsafe(out_pt, sfe, 0));
 3714    if(!(is_default && no_defaults))
 3715      Xorriso_status_result(xorriso, filter, fp, flag & 2);
 3716  }
 3717  is_default= ((xorriso->do_aaip & (256 | 512)) == 0);
 3718  sprintf(line,"-auto_charset %s\n", (xorriso->do_aaip & 256 ? "on" : "off"));
 3719  if(!(is_default && no_defaults))
 3720    Xorriso_status_result(xorriso,filter,fp,flag&2);
 3721 
 3722  is_default= ((xorriso->ino_behavior & 31) == 7);
 3723  switch (xorriso->ino_behavior & 15) {
 3724  case 0: form= "on";
 3725  break; case 8: form= "without_update";
 3726  break; default: form= "off";
 3727  }
 3728  sprintf(line,"-hardlinks %s:%s:%s\n", form,
 3729          xorriso->ino_behavior & 32 ?
 3730          "no_lsl_count" : "lsl_count",
 3731          xorriso->ino_behavior & 16 ?
 3732          "cheap_sorted_extract" : "normal_extract"); 
 3733  if(!(is_default && no_defaults))
 3734    Xorriso_status_result(xorriso,filter,fp,flag&2);
 3735 
 3736  is_default= ((xorriso->do_aaip & (1 | 4)) == 0);
 3737  sprintf(line,"-acl %s\n", (xorriso->do_aaip & 1 ? "on" : "off"));
 3738  if(!(is_default && no_defaults))
 3739    Xorriso_status_result(xorriso,filter,fp,flag&2);
 3740  is_default= ((xorriso->do_aaip & (2 | 8)) == 0);
 3741  sprintf(line,"-xattr %s\n", (xorriso->do_aaip & 4 ?
 3742                                 xorriso->do_aaip & 1024 ? "any" : "user"
 3743                               : "off"));
 3744  if(!(is_default && no_defaults))
 3745    Xorriso_status_result(xorriso,filter,fp,flag&2);
 3746  is_default= ((xorriso->do_aaip & (16 | 32 | 64)) == 0);
 3747  sprintf(line,"-disk_dev_ino %s\n",
 3748          (xorriso->do_aaip & 16 ? (xorriso->do_aaip & 128 ? "ino_only" : "on" )
 3749                                 : "off"));
 3750  if(!(is_default && no_defaults))
 3751    Xorriso_status_result(xorriso,filter,fp,flag&2);
 3752 
 3753  is_default= ((xorriso->do_md5 & 31) == 0);
 3754  sprintf(line, "-md5 ");
 3755  if(xorriso->do_md5 & 1) {
 3756    if((xorriso->do_md5 & 8) == 8) {
 3757      strcat(line, "all");
 3758    } else {
 3759      strcat(line, "on");
 3760      if(xorriso->do_md5 & 8)
 3761        strcat(line, ":stability_check_on");
 3762    }
 3763    if(xorriso->do_md5 & 32) 
 3764      strcat(line, ":load_check_off");
 3765    strcat(line, "\n");
 3766  } else
 3767    strcat(line, "off\n");
 3768  if(!(is_default && no_defaults))
 3769    Xorriso_status_result(xorriso,filter,fp,flag&2);
 3770 
 3771  is_default= (xorriso->ecma119_map == 1);
 3772  sprintf(line, "-ecma119_map ");
 3773  if(xorriso->ecma119_map == 0)
 3774    strcat(line, "unmapped\n");
 3775  else if(xorriso->ecma119_map == 2)
 3776    strcat(line, "uppercase\n");
 3777  else if(xorriso->ecma119_map == 3)
 3778    strcat(line, "lowercase\n");
 3779  else
 3780    strcat(line, "stripped\n"); 
 3781  if(!(is_default && no_defaults))
 3782    Xorriso_status_result(xorriso,filter,fp,flag&2);
 3783 
 3784  is_default= (xorriso->joliet_map == 1);
 3785  sprintf(line, "-joliet_map ");
 3786  if(xorriso->joliet_map == 0)
 3787    strcat(line, "unmapped\n");
 3788  else
 3789    strcat(line, "stripped\n"); 
 3790  if(!(is_default && no_defaults))
 3791    Xorriso_status_result(xorriso,filter,fp,flag&2);
 3792 
 3793  is_default= (xorriso->scdbackup_tag_name[0] == 0 &&
 3794               xorriso->scdbackup_tag_listname[0] == 0);
 3795  sprintf(line, "-scdbackup_tag ");
 3796  Text_shellsafe(xorriso->scdbackup_tag_listname, line, 1);
 3797  strcat(line, " ");
 3798  Text_shellsafe(xorriso->scdbackup_tag_name, line, 1);
 3799  strcat(line, "\n");
 3800  if(!(is_default && no_defaults))
 3801    Xorriso_status_result(xorriso,filter,fp,flag&2);
 3802 
 3803  is_default= (Xorriso_get_relax_text(xorriso, sfe, 0) == 2);
 3804  sprintf(line,"-compliance %s\n", sfe);
 3805  if(!(is_default && no_defaults))
 3806    Xorriso_status_result(xorriso,filter,fp,flag&2);
 3807 
 3808  is_default= (xorriso->rr_reloc_dir[0] == 0);
 3809  sprintf(line, "-rr_reloc_dir ");
 3810  Text_shellsafe(xorriso->rr_reloc_dir, line, 1);
 3811  strcat(line, "\n");
 3812  if(!(is_default && no_defaults))
 3813    Xorriso_status_result(xorriso,filter,fp,flag&2);
 3814 
 3815  is_default= (xorriso->assert_volid[0] == 0);
 3816  sprintf(line, "-assert_volid ");
 3817  Text_shellsafe(xorriso->assert_volid, line, 1);
 3818  strcat(line, " ");
 3819  Text_shellsafe(xorriso->assert_volid_sev, line, 1);
 3820  strcat(line, "\n");
 3821  if(!(is_default && no_defaults))
 3822    Xorriso_status_result(xorriso,filter,fp,flag&2);
 3823  
 3824  is_default= 1;
 3825  if(xorriso->drive_blacklist != NULL || xorriso->drive_whitelist != NULL ||
 3826     xorriso->drive_greylist == NULL)
 3827    is_default= 0;
 3828  if(xorriso->drive_greylist != NULL) {
 3829    if(strcmp(Xorriso_get_pattern(xorriso, xorriso->drive_greylist, 0, 0),
 3830               "/dev") != 0)
 3831      is_default= 0;
 3832    if(Xorriso_get_pattern(xorriso, xorriso->drive_greylist, 1, 0) != NULL)
 3833      is_default= 0;
 3834  }
 3835  if(!(is_default && no_defaults)) {
 3836    for(s= xorriso->drive_blacklist; s != NULL; s= Xorriso_lst_get_next(s, 0)) {
 3837      sprintf(line, "-drive_class 'banned'   %s\n",
 3838              Text_shellsafe(Xorriso_lst_get_text(s, 0), sfe, 0));
 3839      Xorriso_status_result(xorriso,filter,fp,flag&2);
 3840    }
 3841    for(s= xorriso->drive_greylist; s != NULL; s= Xorriso_lst_get_next(s, 0)) {
 3842      sprintf(line, "-drive_class 'caution'  %s\n",
 3843              Text_shellsafe(Xorriso_lst_get_text(s, 0), sfe, 0));
 3844      Xorriso_status_result(xorriso,filter,fp,flag&2);
 3845    }
 3846    for(s= xorriso->drive_whitelist; s != NULL; s= Xorriso_lst_get_next(s, 0)) {
 3847      sprintf(line, "-drive_class 'harmless' %s\n",
 3848              Text_shellsafe(Xorriso_lst_get_text(s, 0), sfe, 0));
 3849      Xorriso_status_result(xorriso,filter,fp,flag&2);
 3850    }
 3851  }
 3852 
 3853  is_default= (xorriso->drives_exclusive == 1 && xorriso->drives_access == 1);
 3854  sprintf(line, "-drive_access %s:%s\n",
 3855          xorriso->drives_exclusive ? "exclusive" : "shared",
 3856          xorriso->drives_access == 0 ? "readonly" : "unrestricted");
 3857  if(!(is_default && no_defaults))
 3858    Xorriso_status_result(xorriso, filter, fp, flag & 2);
 3859 
 3860  is_default= (xorriso->linux_scsi_dev_family == 0);
 3861  sprintf(line, "-scsi_dev_family %s\n",
 3862                scsi_family[xorriso->linux_scsi_dev_family & 7]);
 3863  if(!(is_default && no_defaults))
 3864    Xorriso_status_result(xorriso,filter,fp,flag&2);
 3865 
 3866  do_single= do_drive_access= 0;
 3867  dev_filter= filter;
 3868  if(dev_filter != NULL) {
 3869    show_dev= Xorriso_status_filter(xorriso, filter, "-dev", 0);
 3870    if(show_dev > 0)
 3871      dev_filter= NULL; 
 3872  }
 3873  if(dev_filter != NULL) {
 3874    show_indev= Xorriso_status_filter(xorriso, filter, "-indev", 0);
 3875    show_outdev= Xorriso_status_filter(xorriso, filter, "-outdev", 0);
 3876    if(show_outdev > 0 || show_indev > 0)
 3877      do_single= 1;
 3878  }
 3879  if((xorriso->drives_exclusive != xorriso->indev_is_exclusive ||
 3880      xorriso->drives_access != xorriso->indev_access) && xorriso->indev[0]) {
 3881    do_single= 1;
 3882    do_drive_access|= 1;
 3883  }
 3884  if((xorriso->drives_exclusive != xorriso->outdev_is_exclusive ||
 3885             xorriso->drives_access != xorriso->outdev_access) &&
 3886             xorriso->outdev[0]) {
 3887    do_single= 1;
 3888    do_drive_access|= 2;
 3889  }
 3890  if(strcmp(xorriso->indev, xorriso->outdev) == 0 && !do_single) {
 3891    sprintf(line,"-dev %s\n", Text_shellsafe(xorriso->indev,sfe,0));
 3892    Xorriso_status_result(xorriso, dev_filter, fp, flag & 2);
 3893  } else {
 3894    did_drive_access= 0;
 3895    if((do_drive_access & 1) && xorriso->indev[0] && show_indev) {
 3896      sprintf(line,"-drive_access %s:%s\n",
 3897              xorriso->indev_is_exclusive ? "exclusive" : "shared",
 3898              xorriso->indev_access == 0 ? "readonly" : "unrestricted");
 3899      Xorriso_status_result(xorriso, NULL, fp, flag & 2);
 3900      did_drive_access= 1;
 3901    }
 3902    sprintf(line,"-indev %s\n", Text_shellsafe(xorriso->indev,sfe,0));
 3903    Xorriso_status_result(xorriso, dev_filter, fp, flag & 2);
 3904    if(did_drive_access) {
 3905      sprintf(line,"-drive_access %s:%s\n",
 3906              xorriso->drives_exclusive ? "exclusive" : "shared",
 3907              xorriso->drives_access == 0 ? "readonly" : "unrestricted");
 3908      Xorriso_status_result(xorriso, NULL, fp, flag & 2);
 3909    }
 3910 
 3911    did_drive_access= 0;
 3912    if((do_drive_access & 2) && xorriso->outdev[0] && show_outdev) {
 3913      sprintf(line,"-drive_access %s:%s\n",
 3914              xorriso->outdev_is_exclusive ? "exclusive" : "shared",
 3915              xorriso->outdev_access == 0 ? "readonly" : "unrestricted");
 3916      Xorriso_status_result(xorriso, NULL, fp, flag & 2);
 3917      did_drive_access= 1;
 3918    }
 3919    sprintf(line,"-outdev %s\n", Text_shellsafe(xorriso->outdev,sfe,0));
 3920    Xorriso_status_result(xorriso, dev_filter, fp, flag & 2);
 3921    if(did_drive_access) {
 3922      sprintf(line,"-drive_access %s:%s\n",
 3923              xorriso->drives_exclusive ? "exclusive" : "shared",
 3924              xorriso->drives_access == 0 ? "readonly" : "unrestricted");
 3925      Xorriso_status_result(xorriso, NULL, fp, flag & 2);
 3926    }
 3927  }
 3928 
 3929  ret= 1;
 3930 ex:;
 3931  Xorriso_free_meM(sfe);
 3932  Xorriso_free_meM(xorriso_id);
 3933  return(ret);
 3934 }
 3935 
 3936 
 3937 int Xorriso_pacifier_reset(struct XorrisO *xorriso, int flag)
 3938 {
 3939  xorriso->start_time= Sfile_microtime(0);
 3940  xorriso->last_update_time= xorriso->start_time;
 3941  xorriso->pacifier_count= 0;
 3942  xorriso->pacifier_prev_count= 0;
 3943  xorriso->pacifier_total= 0;
 3944  xorriso->pacifier_byte_count= 0;
 3945  return(1);
 3946 }
 3947 
 3948 
 3949 /* This call is to be issued by long running workers in short intervals.
 3950    It will check whether enough time has elapsed since the last pacifier
 3951    message and eventually issue an update message.
 3952    @param what_done  A sparse description of the action, preferably in past
 3953                      tense. E.g. "done" , "files added".
 3954    @param count The number of objects processed so far.
 3955                 Is ignored if <=0.
 3956    @param todo  The number of objects to be done in total.
 3957                 Is ignored if <=0.
 3958    @param current_object A string telling the object currently processed.
 3959                          Ignored if "".
 3960    @param flag  bit0= report unconditionally, no time check
 3961                 bit1= report count <=0 (no thank you for being patient then)
 3962                 bit2= report xorriso->pacifier_byte_count
 3963                 bit3= report speed
 3964                 bit4= with bit3: count is in blocks, else in bytes
 3965                 bit5= with bit3: report total speed
 3966                 bit6= report with carriage return rather than line feed
 3967                 bit7= with bit5: speed unit for outdev rather than indev
 3968 */
 3969 int Xorriso_pacifier_callback(struct XorrisO *xorriso, char *what_done,
 3970                               off_t count, off_t todo, char *current_object,
 3971                               int flag)
 3972 {
 3973  double current_time, since, interval_time, speed, speed_factor;
 3974  char count_text[80], byte_text[80], profile_name[80], *speed_unit;
 3975  int ret, profile_number, short_sec;
 3976  off_t amount;
 3977  
 3978  current_time= Sfile_microtime(0);
 3979  interval_time= current_time - xorriso->last_update_time;
 3980  if(interval_time < xorriso->pacifier_interval
 3981     && !(flag&1))
 3982    return(1);
 3983  xorriso->last_update_time= Sfile_microtime(0);
 3984  since= current_time - xorriso->start_time;
 3985  if((flag & 1) && since < 1.0 && xorriso->pacifier_interval >= 1.0)
 3986    since= 1.0;
 3987  if((flag & 1) && since < 0.1)
 3988    since= 0.1;
 3989  byte_text[0]= 0;
 3990  if(flag&4) {
 3991    strcat(byte_text, " (");
 3992    Sfile_scale((double) xorriso->pacifier_byte_count,
 3993                byte_text+strlen(byte_text), 7, 1e5, 0);
 3994    strcat(byte_text, ")");
 3995  }
 3996  short_sec= 0;
 3997  if(count<=0.0 && !(flag&2)) {
 3998    if(since < 2)
 3999      return(2);
 4000    sprintf(xorriso->info_text,
 4001            "Thank you for being patient for");
 4002  } else if(todo<=0.0) {
 4003    if(count<10000000)
 4004      sprintf(count_text, "%7.f", (double) count);
 4005    else
 4006      Sfile_scale((double) count, count_text, 7, 1e5, 1);
 4007    sprintf(xorriso->info_text, "%s %s%s in",
 4008            count_text, what_done, byte_text);
 4009    short_sec= (flag & 64);
 4010  } else {
 4011    sprintf(xorriso->info_text, "%.f of %.f %s%s in",
 4012            (double) count, (double) todo, what_done, byte_text);
 4013    short_sec= (flag & (8 | 64));
 4014  }
 4015  if(xorriso->pacifier_interval < 1.0) {
 4016    sprintf(xorriso->info_text + strlen(xorriso->info_text),
 4017            " %.1f", since);
 4018  } else {
 4019    sprintf(xorriso->info_text + strlen(xorriso->info_text),
 4020            " %.f", since);
 4021  }
 4022  sprintf(xorriso->info_text + strlen(xorriso->info_text),
 4023            " %s", short_sec ? "s" : "seconds");
 4024 
 4025  speed= -1.0;
 4026  if(flag & 4)
 4027    amount= xorriso->pacifier_byte_count;
 4028  else
 4029    amount= count;
 4030  if((flag & 8)) {
 4031    if(flag & 32) {
 4032      if(since > 0)
 4033        speed= amount / since;
 4034    } else if(amount >= xorriso->pacifier_prev_count) {
 4035      if(interval_time > 0)
 4036        speed= (amount - xorriso->pacifier_prev_count) / interval_time;
 4037    }
 4038  }
 4039  if(speed >= 0.0) {
 4040    if(flag & 16)
 4041      speed*= 2048.0;
 4042    ret= Xorriso_get_profile(xorriso, &profile_number, profile_name,
 4043                             (flag >> 6) & 2);
 4044    speed_factor= 1385000;
 4045    speed_unit= "D";
 4046    if(ret == 2) {
 4047      speed_factor= 150.0*1024;
 4048      speed_unit= "C";
 4049    } else if(ret == 3) {
 4050      speed_factor= 4495625;
 4051      speed_unit= "B";
 4052    }
 4053    sprintf(xorriso->info_text+strlen(xorriso->info_text), " %s %.1fx%s",
 4054            (flag & 32 ? "=" : ","), speed / speed_factor, speed_unit);
 4055  }
 4056  xorriso->pacifier_prev_count= amount;
 4057  if(current_object[0]!=0)
 4058    sprintf(xorriso->info_text+strlen(xorriso->info_text),
 4059            ", now at %s", current_object);
 4060  Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "UPDATE", (flag&64));
 4061  return(1);
 4062 }
 4063 
 4064 
 4065 int Xorriso_reset_counters(struct XorrisO *xorriso, int flag)
 4066 {
 4067  xorriso->error_count= 0;
 4068  xorriso->insert_count= 0;
 4069  xorriso->insert_bytes= 0;
 4070  Xorriso_pacifier_reset(xorriso, 0);
 4071  return(1);
 4072 }
 4073 
 4074 
 4075 /* @param flag bit0= to stderr rather than Xorriso_msgs_submit
 4076 */
 4077 int Xorriso_no_malloc_memory(struct XorrisO *xorriso, char **to_free, int flag)
 4078 {
 4079  if(to_free!=NULL)
 4080    if(*to_free!=NULL) {
 4081      /* Eventual memory sacrifice to get on going */
 4082      free(*to_free);
 4083      *to_free= NULL;
 4084    }
 4085  sprintf(xorriso->info_text, "Out of virtual memory");
 4086  if(flag & 1) {
 4087    fprintf(stderr, "%s", xorriso->info_text);
 4088    /* (No need to first check for problem status worse than ABORT) */
 4089    Xorriso_set_problem_status(xorriso, "ABORT", 0);
 4090  } else
 4091    Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "ABORT", 0);
 4092  return(1);
 4093 }
 4094 
 4095 
 4096 /* @param flag bit0=path is in source filesystem , bit1= unconditionally */
 4097 int Xorriso_much_too_long(struct XorrisO *xorriso, int len, int flag)
 4098 {
 4099  if(len>=SfileadrL || (flag&2)) {
 4100    sprintf(xorriso->info_text,
 4101            "Path given for file in %s is much too long (%d)",
 4102            ((flag&1) ? "local filesystem" : "ISO image"), len);
 4103    Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
 4104    return(0);
 4105  }
 4106  return(1);
 4107 }
 4108 
 4109 
 4110 int Xorriso_no_findjob(struct XorrisO *xorriso, char *cmd, int flag)
 4111 {
 4112  sprintf(xorriso->info_text, "%s: cannot create find job object", cmd);
 4113  Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FATAL", 0);
 4114  return(1);
 4115 }
 4116 
 4117 
 4118 int Xorriso_report_md5_outcome(struct XorrisO *xorriso, char *severity,
 4119                                int flag)
 4120 {
 4121  int has_md5;
 4122 
 4123  has_md5= Xorriso_image_has_md5(xorriso, 0);
 4124  if(xorriso->find_check_md5_result & 1) {
 4125    sprintf(xorriso->result_line,
 4126            "Mismatch detected between file contents and MD5 checksums.\n");
 4127  } else if(xorriso->find_check_md5_result & 8) {
 4128    sprintf(xorriso->result_line,
 4129            "File contents and their MD5 checksums match.\n");
 4130  } else {
 4131    sprintf(xorriso->result_line,
 4132            "Not a single file with MD5 checksum was found.");
 4133    if(has_md5 <= 0)
 4134      strcat(xorriso->result_line,
 4135             " (There is no MD5 checksum array loaded.)\n");
 4136    else
 4137      strcat(xorriso->result_line, "\n");
 4138  }
 4139  Xorriso_result(xorriso,0);
 4140  if(xorriso->find_check_md5_result & 2) {
 4141    sprintf(xorriso->result_line,
 4142            "Encountered errors other than non-match during MD5 checking.\n");
 4143    Xorriso_result(xorriso,0);
 4144  }
 4145  if((xorriso->find_check_md5_result & 4) && has_md5) {
 4146    sprintf(xorriso->result_line,
 4147    "There were data files which have no MD5 and thus could not be checked.\n");
 4148    Xorriso_result(xorriso,0);
 4149  }
 4150  if((xorriso->find_check_md5_result & 3) && strcmp(severity, "ALL") != 0) {
 4151    sprintf(xorriso->info_text, "Event triggered by MD5 comparison mismatch");
 4152    Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, severity, 0);
 4153  }
 4154  return(1);
 4155 }
 4156 
 4157 
 4158 /* @param flag bit0= do not issue prompt messages on info channel
 4159                bit1= use line rather than asking at dialog input
 4160 */
 4161 int Xorriso_msg_op_parse(struct XorrisO *xorriso, char *line,
 4162                          char *prefix, char *separators,
 4163                          int max_words, int pflag, int input_lines,
 4164                          int flag)
 4165 {
 4166  int ret, i, l, pargc= 0, bsl_mem;
 4167  char *pline= NULL, **pargv= NULL, *parse_line, *text= NULL, *text_pt;
 4168 
 4169  Xorriso_alloc_meM(pline, char, SfileadrL);
 4170 
 4171  if(!(flag & 1)) {
 4172    if(input_lines > 1)
 4173      sprintf(xorriso->info_text, "-msg_op parse: Enter %d lines of text\n",
 4174                                  input_lines);
 4175    else
 4176      sprintf(xorriso->info_text, "-msg_op parse: Enter text line\n");
 4177    Xorriso_info(xorriso, 0);
 4178  }
 4179 
 4180  if(flag & 2) {
 4181    parse_line= line;
 4182  } else {
 4183    pline[0]= 0;
 4184    for(i= 0; i < input_lines; i++) {
 4185      l= strlen(pline);
 4186      ret= Xorriso_dialog_input(xorriso, pline + l, SfileadrL - l - 1, 8 | 1);
 4187      if(ret <= 0)
 4188        goto ex;
 4189      if(i < input_lines - 1)
 4190        strcat(pline, "\n");
 4191    }
 4192    parse_line= pline;
 4193  }
 4194  ret= Xorriso_parse_line(xorriso, parse_line, prefix, separators, max_words,
 4195                          &pargc, &pargv, pflag);
 4196 
 4197  /* Temporarily disable backslash encoding of result channel */
 4198  bsl_mem= xorriso->bsl_interpretation;
 4199  xorriso->bsl_interpretation&= ~32;
 4200 
 4201  xorriso->msg_sieve_disabled= 1;
 4202  sprintf(xorriso->result_line, "%d\n", ret);
 4203  Xorriso_result(xorriso, 1);
 4204  if(ret == 1) {
 4205    sprintf(xorriso->result_line, "%d\n", pargc);
 4206    Xorriso_result(xorriso, 1);
 4207    for(i= 0; i < pargc; i++) {
 4208      text_pt= pargv[i];
 4209      if (bsl_mem & 32) {
 4210        ret= Sfile_bsl_encoder(&text, pargv[i], strlen(pargv[i]), 4);
 4211        if(ret >  0)
 4212          text_pt= text;
 4213      }
 4214      ret= Sfile_count_char(text_pt, '\n') + 1;
 4215      sprintf(xorriso->result_line, "%d\n", ret);
 4216      Xorriso_result(xorriso, 1);
 4217      Sfile_str(xorriso->result_line, text_pt, 0);
 4218      strcat(xorriso->result_line, "\n");
 4219      Xorriso_result(xorriso, 1);
 4220      Xorriso_free_meM(text);
 4221      text= NULL;
 4222    }
 4223  } else {
 4224    sprintf(xorriso->result_line, "0\n");
 4225    Xorriso_result(xorriso, 1);
 4226  }
 4227  xorriso->bsl_interpretation= bsl_mem;
 4228  ret= 1;
 4229 ex:;
 4230  Xorriso__dispose_words(&pargc, &pargv);
 4231  Xorriso_free_meM(text);
 4232  Xorriso_free_meM(pline);
 4233  return ret;
 4234 }
 4235 
 4236 
 4237 /* @param flag bit0= do not issue prompt messages on info channel
 4238 */
 4239 int Xorriso_msg_op_parse_bulk(struct XorrisO *xorriso,
 4240                               char *prefix, char *separators,
 4241                               int max_words, int pflag, int bulk_lines,
 4242                               int flag)
 4243 {
 4244  int ret, input_lines, i, j, l;
 4245  char line[80];
 4246  struct Xorriso_lsT *input_list= NULL, *input_end= NULL, *new_lst, *lst;
 4247  char *pline= NULL;
 4248 
 4249  if(!(flag & 1)) {
 4250    sprintf(xorriso->info_text,
 4251     "Enter %d groups of lines. Each group begins by a line which tells the\n",
 4252            bulk_lines);
 4253    Xorriso_info(xorriso, 0);
 4254    sprintf(xorriso->info_text,
 4255     "number of following lines in the group. Then come the announced lines\n");
 4256    Xorriso_info(xorriso, 0);
 4257    sprintf(xorriso->info_text,
 4258     "Do this blindly. No further prompt will appear. Best be a computer.\n");
 4259    Xorriso_info(xorriso, 0);
 4260  }
 4261 
 4262  Xorriso_alloc_meM(pline, char, SfileadrL);
 4263 
 4264  for(i= 0; i < bulk_lines; i++) {
 4265    ret= Xorriso_dialog_input(xorriso, line, sizeof(line), 8 | 1);
 4266    if(ret <= 0)
 4267      goto ex;
 4268    input_lines= -1;
 4269    sscanf(line, "%d", &input_lines);
 4270    pline[</