"Fossies" - the Fresh Open Source Software Archive

Member "libisoburn-1.5.4/xorriso/opts_i_o.c" (4 Dec 2020, 56460 Bytes) of package /linux/misc/libisoburn-1.5.4.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 "opts_i_o.c" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 1.5.0_vs_1.5.2.

    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 options as mentioned in man page
    9    or info file derived from xorriso.texi.
   10 */
   11 
   12 #ifdef HAVE_CONFIG_H
   13 #include "../config.h"
   14 #endif
   15 
   16 #include <ctype.h>
   17 #include <sys/types.h>
   18 #include <unistd.h>
   19 #include <stdlib.h>
   20 #include <stdio.h>
   21 #include <string.h>
   22 #include <sys/stat.h>
   23 #include <sys/time.h>
   24 #include <time.h>
   25 #include <errno.h>
   26 
   27 #include "xorriso.h"
   28 #include "xorriso_private.h"
   29 #include "xorrisoburn.h"
   30 
   31 
   32 /* Command -iso_nowtime "dynamic"|timespec */
   33 int Xorriso_option_iso_nowtime(struct XorrisO *xorriso, char *text, int flag)
   34 {
   35  char *time_type = "m";
   36  int t_type= 0, ret;
   37  time_t t;
   38 
   39  if(strcmp(text, "dynamic") == 0) {
   40    xorriso->do_override_now_time= 0;
   41    Xorriso_set_libisofs_now(xorriso, 2);
   42    Xorriso_msgs_submit(xorriso, 0, "-iso_nowtime: Set to \"dynamic\"", 0,
   43                        "NOTE", 0);
   44    return(1);
   45  }
   46  ret= Xorriso_convert_datestring(xorriso, "-iso_nowtime", time_type, text,
   47                                  &t_type, &t, 0);
   48  if(ret<=0)
   49    goto ex;
   50  xorriso->do_override_now_time= 1;
   51  xorriso->now_time_override= t;
   52  Xorriso_set_libisofs_now(xorriso, 1);
   53  sprintf(xorriso->info_text, "-iso_nowtime: Set to =%.f", (double) t);
   54  Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "NOTE", 0);
   55  ret= 1;
   56 ex:;
   57  return(ret);
   58 }
   59 
   60 
   61 /* Option -iso_rr_pattern "on"|"ls"|"off" */
   62 int Xorriso_option_iso_rr_pattern(struct XorrisO *xorriso, char *mode,int flag)
   63 {
   64  if(strcmp(mode, "off")==0)
   65    xorriso->do_iso_rr_pattern= 0;
   66  else if(strcmp(mode, "on")==0)
   67    xorriso->do_iso_rr_pattern= 1;
   68  else if(strcmp(mode, "ls")==0)
   69    xorriso->do_iso_rr_pattern= 2;
   70  else {
   71    sprintf(xorriso->info_text, "-iso_rr_pattern: unknown mode '%s'", mode);
   72    Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
   73    return(0);
   74  }
   75  return(1);
   76 }
   77 
   78 
   79 /* Option -jigdo aspect argument */
   80 int Xorriso_option_jigdo(struct XorrisO *xorriso, char *aspect, char *arg,
   81                          int flag)
   82 {
   83  int ret;
   84 
   85  ret= Xorriso_jigdo_interpreter(xorriso, aspect, arg, 0);
   86  return(ret);
   87 }
   88 
   89 
   90 /* Option -joliet "on"|"off" */
   91 int Xorriso_option_joliet(struct XorrisO *xorriso, char *mode, int flag)
   92 {
   93  if(strcmp(mode, "off")==0)
   94    xorriso->do_joliet= 0;
   95  else if(strcmp(mode, "on")==0)
   96    xorriso->do_joliet= 1;
   97  else {
   98    sprintf(xorriso->info_text, "-joliet: unknown mode '%s'", mode);
   99    Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
  100    return(0);
  101  }
  102  return(1);
  103 }
  104 
  105 
  106 /* Command -joliet_map */
  107 int Xorriso_option_joliet_map(struct XorrisO *xorriso, char *mode, int flag)
  108 {
  109  if(strcmp(mode, "unmapped") == 0) {
  110    xorriso->joliet_map= 0;
  111  } else if(strcmp(mode, "stripped") == 0) {
  112    xorriso->joliet_map= 1;
  113  } else {
  114    sprintf(xorriso->info_text, "-joliet_map: unknown mode '%s'", mode);
  115    Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
  116    return(0);
  117  }
  118  return(1);
  119 }
  120 
  121 
  122 /* Command -launch_frontend */
  123 int Xorriso_option_launch_frontend(struct XorrisO *xorriso,
  124                                    int argc, char **argv, int *idx, int flag)
  125 {
  126  int ret, end_idx;
  127 
  128  end_idx= Xorriso_end_idx(xorriso, argc, argv, *idx, 1);
  129 
  130  if(xorriso->launch_frontend_banned) {
  131    sprintf(xorriso->info_text,
  132            "-launch_frontend was already executed in this xorriso run");
  133    Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
  134    ret= 0; goto ex;
  135  }
  136  xorriso->launch_frontend_banned= 1;
  137  if(end_idx <= *idx)
  138    {ret= 1; goto ex;}
  139  if(argv[*idx][0] == 0)
  140    {ret= 1; goto ex;}
  141  xorriso->dialog= 2;
  142  ret= Xorriso_launch_frontend(xorriso, end_idx - *idx, argv + *idx,
  143                               "", "", 0);
  144 ex:;
  145  (*idx)= end_idx;
  146  return(ret);
  147 }
  148 
  149 
  150 /* Option -list_arg_sorting */
  151 int Xorriso_option_list_arg_sorting(struct XorrisO *xorriso, int flag)
  152 {
  153  int ret;
  154 
  155  ret= Xorriso_cmd_sorting_rank(xorriso, 0, NULL, 0, 1);
  156  return(ret);
  157 }
  158 
  159 
  160 /* Option -list_delimiter */
  161 int Xorriso_option_list_delimiter(struct XorrisO *xorriso, char *text,
  162                                   int flag)
  163 {
  164  int ret, argc;
  165  char **argv= NULL;
  166 
  167  if(text[0] == 0) {
  168    sprintf(xorriso->info_text,
  169            "-list_delimiter: New delimiter text is empty");
  170    Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
  171    return(0);
  172  }
  173  if(strlen(text) > 80) {
  174    sprintf(xorriso->info_text,
  175            "-list_delimiter: New delimiter text is too long");
  176    Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
  177    return(0);
  178  }
  179  ret= Sfile_make_argv(xorriso->progname, text, &argc, &argv, 4);
  180  if(ret > 0) {
  181    if(argc > 2) {
  182      sprintf(xorriso->info_text,
  183             "-list_delimiter: New delimiter text contains more than one word");
  184      Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
  185    }
  186    Sfile_make_argv(xorriso->progname, text, &argc, &argv, 2);
  187    if(argc > 2)
  188      return(0);
  189  }
  190  if(strchr(text, '"') != NULL || strchr(text, '\'') != NULL) {
  191    sprintf(xorriso->info_text,
  192            "-list_delimiter: New delimiter text contains quotation marks");
  193    Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
  194    return(0);
  195  }
  196  strcpy(xorriso->list_delimiter, text);
  197  return(1);
  198 }
  199 
  200 
  201 /* Option -list_extras */
  202 int Xorriso_option_list_extras(struct XorrisO *xorriso, char *mode, int flag)
  203 {
  204  int ret;
  205 
  206  ret= Xorriso_list_extras(xorriso, mode, 0);
  207  return(ret);
  208 }
  209 
  210 
  211 /* Option -list_formats */
  212 int Xorriso_option_list_formats(struct XorrisO *xorriso, int flag)
  213 {
  214  int ret;
  215 
  216  ret= Xorriso_list_formats(xorriso, 0);
  217  return(ret);
  218 }
  219 
  220 
  221 /* Option -list_speeds */
  222 int Xorriso_option_list_speeds(struct XorrisO *xorriso, int flag)
  223 {
  224  int ret;
  225 
  226  ret= Xorriso_list_speeds(xorriso, 0);
  227  return(ret);
  228 }
  229 
  230 
  231 /* Option -list_profiles */
  232 int Xorriso_option_list_profiles(struct XorrisO *xorriso, char *which,
  233                                  int flag)
  234 {
  235  int ret;
  236  int mode= 0;
  237 
  238  if(strncmp(which,"in",2)==0)
  239    mode|= 1;
  240  else if(strncmp(which,"out",3)==0)
  241    mode|= 2;
  242  else
  243    mode|= 3;
  244  if(mode & 1) {
  245    ret= Xorriso_toc(xorriso, 1 | 16 | 32);
  246    if(ret > 0)
  247      Xorriso_list_profiles(xorriso, 0);
  248  }
  249  if((mode & 2) && xorriso->in_drive_handle != xorriso->out_drive_handle) {
  250    ret= Xorriso_toc(xorriso, 1 | 2 | 16 | 32);
  251    if(ret > 0)
  252      Xorriso_list_profiles(xorriso, 2);
  253  }
  254  return(1);
  255 }
  256 
  257 
  258 /* Command -lns alias -lnsi */
  259 int Xorriso_option_lnsi(struct XorrisO *xorriso, char *target, char *path,
  260                         int flag)
  261 {
  262  int ret;
  263  char *eff_path= NULL, *buffer= NULL, *namept;
  264 
  265  Xorriso_alloc_meM(eff_path, char, SfileadrL);
  266  Xorriso_alloc_meM(buffer, char, SfileadrL);
  267 
  268  ret= Xorriso_normalize_img_path(xorriso, xorriso->wdi, path, eff_path, 1);
  269  if(ret < 0)
  270    {ret= 0; goto ex;}
  271  if(ret > 0) { 
  272    sprintf(xorriso->info_text, "-lns: Address already existing: ");
  273    Text_shellsafe(eff_path, xorriso->info_text, 1);
  274    Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
  275    {ret= 0; goto ex;}
  276  } 
  277  ret= Xorriso_normalize_img_path(xorriso, xorriso->wdi, path, eff_path, 2);
  278  if(ret < 0)
  279    {ret= 0; goto ex;}
  280  ret= Xorriso_truncate_path_comps(xorriso, target, buffer, &namept, 0);
  281  if(ret < 0)
  282    {ret= 0; goto ex;}
  283  ret= Xorriso_graft_in(xorriso, NULL, namept, eff_path, (off_t) 0, (off_t) 0,
  284                        1024);
  285  if(ret <= 0)
  286    {ret= 0; goto ex;}
  287  ret= 1;
  288 ex:;
  289  Xorriso_free_meM(buffer);
  290  Xorriso_free_meM(eff_path);
  291  return(ret);
  292 }
  293 
  294 
  295 /* Option -load session|track|sbsector value */
  296 /* @param flag bit0= with adr_mode sbsector: adr_value is possibly 16 too high
  297    @return <=0 error , 1 success, 2 revoked by -reassure
  298 */
  299 int Xorriso_option_load(struct XorrisO *xorriso, char *adr_mode,
  300                           char *adr_value, int flag)
  301 {
  302  int ret;
  303 
  304  if(Xorriso_change_is_pending(xorriso, 0)) {
  305    sprintf(xorriso->info_text,
  306            "-load: Image changes pending. -commit or -rollback first");
  307    Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
  308    return(0);
  309  }
  310  ret= Xorriso_reassure(xorriso, "-load", "loads an alternative image", 0);
  311  if(ret<=0)
  312    return(2);
  313  ret= Xorriso_decode_load_adr(xorriso, "-load", adr_mode, adr_value,
  314                               &(xorriso->image_start_mode),
  315                               xorriso->image_start_value, flag & 1);
  316  if(ret <= 0)
  317    return(ret);
  318  xorriso->image_start_mode|= (1<<30); /* enable non-default msc1 processing */
  319  if(strlen(xorriso->indev)>0) {
  320    ret= Xorriso_option_rollback(xorriso, 1); /* Load image, no -reassure */
  321    if(ret<=0)
  322      return(ret);
  323  }
  324  return(1);
  325 }
  326 
  327 
  328 /* Option -logfile */
  329 int Xorriso_option_logfile(struct XorrisO *xorriso, char *channel,
  330                                                       char *fileadr, int flag)
  331 {
  332  int hflag,channel_no= 0, ret;
  333    
  334  if(channel[0]==0) {
  335 logfile_wrong_form:;
  336    sprintf(xorriso->info_text,"Wrong form. Correct would be: -logfile \".\"|\"R\"|\"I\"|\"M\" file_address");
  337    Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
  338    return(0);
  339  }
  340  hflag= 2;
  341  if(channel[0]=='R')
  342    channel_no= 1;
  343  else if(channel[0]=='I')
  344    channel_no= 2;
  345  else if(channel[0]=='M')
  346    channel_no= 3;
  347  else if(channel[0]=='.')
  348    hflag= 4;
  349  else
  350    goto logfile_wrong_form;
  351  if(strcmp(fileadr,"-")==0 || fileadr[0]==0)
  352      hflag|= (1<<15);
  353  xorriso->logfile[channel_no][0]= 0;
  354  ret= Xorriso_write_to_channel(xorriso, fileadr, channel_no, hflag);
  355  if(ret<=0) {
  356    sprintf(xorriso->info_text, "Cannot open logfile:  %s", fileadr);
  357    Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
  358  } else if(!(hflag&(1<<15)))
  359    if(Sfile_str(xorriso->logfile[channel_no], fileadr, 0)<=0)
  360      return(-1);
  361  return(ret>0);
  362 }
  363 
  364 
  365 /* Options -ls  alias -lsi   and -lsl  alias -lsli
  366        and -lsd alias -lsdi  and -lsdl alias -lsdli
  367        and -du  alias -dui   and -dus  alias -dusi
  368    @param flag bit0= long format (-lsl , -du, not -dus, not -ls)
  369                bit1= do not expand patterns but use literally
  370                bit2= -du rather than -ls
  371                bit3= list directories as themselves (-lsd) 
  372 */
  373 int Xorriso_option_lsi(struct XorrisO *xorriso, int argc, char **argv,
  374                       int *idx, int flag)
  375 {
  376  int ret, end_idx, filec= 0, nump, i, star= 1;
  377  char **filev= NULL, **patterns= NULL;
  378  off_t mem= 0;
  379  struct stat stbuf;
  380 
  381  if(flag & 4) {
  382    if(!(flag & 1))
  383      star= 0;
  384  } else {
  385    if(flag & 8)
  386      star= 0;
  387  }
  388 
  389  end_idx= Xorriso_end_idx(xorriso, argc, argv, *idx, 1);
  390  if(xorriso->do_iso_rr_pattern==0)
  391    flag|= 2;
  392 
  393  nump= end_idx - *idx;
  394  if((flag&2) && nump>0 ) {
  395    ;
  396  } else if(nump <= 0) {
  397    if(Xorriso_iso_lstat(xorriso, xorriso->wdi, &stbuf, 0)<0) {
  398      sprintf(xorriso->info_text,
  399              "Current -cd path does not yet exist in the ISO image");
  400      Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
  401      {ret= 0; goto ex;}
  402    }
  403    if(!S_ISDIR(stbuf.st_mode)) {
  404      sprintf(xorriso->info_text,
  405              "Current -cd meanwhile points to a non-directory in ISO image");
  406      Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
  407      {ret= 0; goto ex;}
  408    }
  409    patterns= calloc(1, sizeof(char *));
  410    if(patterns == NULL) {
  411 no_memory:;
  412      sprintf(xorriso->info_text,
  413              "Cannot allocate enough memory for pattern expansion");
  414      Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FATAL", 0);
  415      {ret= -1; goto ex;}
  416    }
  417    nump= 1;
  418    if(star)
  419      patterns[0]= "*";
  420    else 
  421      patterns[0]= ".";
  422    flag&= ~2;
  423  } else {
  424    patterns= calloc(nump, sizeof(char *));
  425    if(patterns==NULL)
  426      goto no_memory;
  427    for(i= 0; i<nump; i++) {
  428      if(argv[i + *idx][0]==0) {
  429        if(star)
  430          patterns[i]= "*";
  431        else
  432          patterns[i]= ".";
  433      } else
  434        patterns[i]= argv[i + *idx];
  435    }
  436  }
  437 
  438  if((flag & 1) && !(xorriso->ino_behavior & 32)) {
  439    ret= Xorriso_make_hln_array(xorriso, 0); /* for stbuf.st_nlink */
  440    if(ret < 0)
  441      goto ex;
  442  }
  443  if(flag&2) {
  444    ret= Xorriso_ls_filev(xorriso, xorriso->wdi, nump, argv + (*idx), mem,
  445                          flag&(1|4|8)); 
  446  } else if(nump==1 && strcmp(patterns[0],"*")==0 && !(flag&4)){
  447    /* save temporary memory by calling simpler function */
  448    ret= Xorriso_ls(xorriso, (flag&1)|4);
  449  } else {
  450    ret= Xorriso_expand_pattern(xorriso, nump, patterns, 0, &filec, &filev,
  451                                &mem, 0);
  452    if(ret<=0)
  453      {ret= 0; goto ex;}
  454    ret= Xorriso_ls_filev(xorriso, xorriso->wdi, filec, filev, mem,
  455                          flag&(1|4|8)); 
  456  }
  457  if(ret<=0)
  458    {ret= 0; goto ex;}
  459 
  460  ret= 1;
  461 ex:;
  462  if(patterns!=NULL)
  463    free((char *) patterns);
  464  Sfile_destroy_argv(&filec, &filev, 0);
  465  (*idx)= end_idx;
  466  return(ret);
  467 }
  468 
  469 
  470 /* Options -lsx, -lslx, -lsdx , -lsdlx , -dux , -dusx
  471    @param flag bit0= long format (-lslx , -dux)
  472                bit1= do not expand patterns but use literally
  473                bit2= du rather than ls
  474                bit3= list directories as themselves (ls -d) 
  475 */
  476 int Xorriso_option_lsx(struct XorrisO *xorriso, int argc, char **argv,
  477                       int *idx, int flag)
  478 {
  479  int ret, end_idx, filec= 0, nump, i;
  480  char **filev= NULL, **patterns= NULL;
  481  off_t mem= 0;
  482 
  483  end_idx= Xorriso_end_idx(xorriso, argc, argv, *idx, 1|2);
  484  if(xorriso->do_disk_pattern==0)
  485    flag|= 2;
  486 
  487  nump= end_idx - *idx;
  488  if((flag&2) && nump>0) {
  489    ;
  490  } else if(nump <= 0) {
  491    patterns= calloc(1, sizeof(char *));
  492    if(patterns == NULL) {
  493 no_memory:;
  494      sprintf(xorriso->info_text,
  495              "Cannot allocate enough memory for pattern expansion");
  496      Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FATAL", 0);
  497      {ret= -1; goto ex;}
  498    }
  499    nump= 1;
  500    if(flag&8)
  501      patterns[0]= ".";
  502    else
  503      patterns[0]= "*";
  504    flag&= ~2;
  505  } else {
  506    patterns= calloc(nump, sizeof(char *));
  507    if(patterns==NULL)
  508      goto no_memory;
  509    for(i= 0; i<nump; i++) {
  510      if(argv[i + *idx][0]==0)
  511        patterns[i]= "*";
  512      else
  513        patterns[i]= argv[i + *idx];
  514    }
  515  }
  516  if(flag&2) {
  517    ret= Xorriso_lsx_filev(xorriso, xorriso->wdx,
  518                           nump, argv + (*idx), mem, flag&(1|4|8)); 
  519 
  520 #ifdef Not_yeT
  521  } else if(nump==1 && strcmp(patterns[0],"*")==0 && !(flag&4)){
  522    /* save temporary memory by calling simpler function */
  523    ret= Xorriso_ls(xorriso, (flag&1)|4);
  524 #endif
  525 
  526  } else {
  527    ret= Xorriso_expand_disk_pattern(xorriso, nump, patterns, 0, &filec, &filev,
  528                                     &mem, 0);
  529    if(ret<=0)
  530      {ret= 0; goto ex;}
  531    ret= Xorriso_lsx_filev(xorriso, xorriso->wdx, filec, filev, mem,
  532                           flag&(1|4|8)); 
  533  }
  534  if(ret<=0)
  535    {ret= 0; goto ex;}
  536 
  537  ret= 1;
  538 ex:;
  539  if(patterns!=NULL)
  540    free((char *) patterns);
  541  Sfile_destroy_argv(&filec, &filev, 0);
  542  (*idx)= end_idx;
  543  return(ret);
  544 }
  545 
  546 
  547 /* Option -map , -map_single */
  548 /* @param flag bit0=do not report the added item
  549                bit1=do not reset pacifier, no final pacifier message
  550                bit5= -map_single: do not insert directory tree
  551 */
  552 int Xorriso_option_map(struct XorrisO *xorriso, char *disk_path,
  553                        char *iso_path, int flag)
  554 {
  555  int ret;
  556  char *eff_origin= NULL, *eff_dest= NULL, *ipth;
  557 
  558  Xorriso_alloc_meM(eff_origin, char, SfileadrL);
  559  Xorriso_alloc_meM(eff_dest, char, SfileadrL);
  560 
  561  if(!(flag&2))
  562    Xorriso_pacifier_reset(xorriso, 0);
  563 
  564  ipth= iso_path;
  565  if(ipth[0]==0)
  566    ipth= disk_path;
  567  if(disk_path[0]==0) {
  568    sprintf(xorriso->info_text, "-map: Empty disk_path given");
  569    Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 1);
  570    {ret= 0; goto ex;}
  571  }
  572  ret= Xorriso_normalize_img_path(xorriso, xorriso->wdx, disk_path, eff_origin,
  573                                  2|4);
  574  if(ret<=0)
  575    goto ex;
  576  ret= Xorriso_normalize_img_path(xorriso, xorriso->wdi, ipth, eff_dest, 2);
  577  if(ret<=0)
  578    goto ex;
  579  ret= Xorriso_graft_in(xorriso, NULL, eff_origin, eff_dest,
  580                        (off_t) 0, (off_t) 0, 2|(flag&32));
  581  if(!(flag&2))
  582    Xorriso_pacifier_callback(xorriso, "files added", xorriso->pacifier_count,
  583                              xorriso->pacifier_total, "", 1);
  584  if(ret<=0)
  585    goto ex;
  586 
  587  if(!(flag&1)) {
  588    sprintf(xorriso->info_text, "Added to ISO image: %s '%s'='%s'\n",
  589            (ret>1 ? "directory" : "file"), (eff_dest[0] ? eff_dest : "/"),
  590            eff_origin);
  591    Xorriso_info(xorriso,0);
  592  }
  593  ret= 1;
  594 ex:;
  595  Xorriso_free_meM(eff_origin);
  596  Xorriso_free_meM(eff_dest);
  597  return(ret);
  598 }
  599 
  600 
  601 /* Command -map_l , -compare_l , -update_l , -extract_l , -update_lxi ,
  602            -update_li
  603 */
  604 /* @param flag bit4= do not establish and dispose xorriso->di_array
  605                      for update_l
  606                bit8-11= mode 0= -map_l
  607                              1= -compare_l
  608                              2= -update_l
  609                              3= -extract_l
  610                              4= -update_lxi
  611                              5= -update_li
  612 */
  613 int Xorriso_option_map_l(struct XorrisO *xorriso, int argc, char **argv,
  614                          int *idx, int flag)
  615 {
  616  int ret, end_idx, optc= 0, was_failure= 1, i, j, fret, mode, problem_count;
  617  int ns_flag= 2|4, nt_flag= 2, opt_args_flag= 2, arg2c= 0, opt2c= 0;
  618  int new_opt2c;
  619  char *source_prefix= NULL, *target_prefix= NULL, *cmd, **optv= NULL;
  620  char *eff_source= NULL, *eff_target= NULL, *s_wd, *t_wd;
  621  char **eff_src_array= NULL, **eff_tgt_array= NULL, **opt2v= NULL;
  622  char **arg2v= NULL;
  623 
  624  cmd= "-map_l";
  625  s_wd= xorriso->wdx;
  626  t_wd= xorriso->wdi;
  627  Xorriso_pacifier_reset(xorriso, 0);
  628  mode= (flag>>8) & 15;
  629 
  630  if(mode==1)
  631    cmd= "-compare_l";
  632  else if(mode==2)
  633    cmd= "-update_l";
  634  else if(mode == 3 || mode == 5) {
  635    if(mode == 5)
  636      cmd= "-update_li";
  637    else
  638      cmd= "-extract_l";
  639    ns_flag= 2;
  640    s_wd= xorriso->wdi;
  641    nt_flag= 2|4;
  642    t_wd= xorriso->wdx;
  643    opt_args_flag= 0;
  644  } else if(mode == 4) {
  645    cmd= "-update_lxi";
  646  }
  647 
  648  end_idx= Xorriso_end_idx(xorriso, argc, argv, *idx, 1|2);
  649  if(end_idx - (*idx) < 3) {
  650    sprintf(xorriso->info_text, "%s: Not enough arguments given (%d < 3)", cmd,
  651            end_idx - (*idx));
  652    Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 1);
  653    ret= 0; goto ex;
  654  }
  655 
  656  Xorriso_alloc_meM(source_prefix, char, SfileadrL);
  657  Xorriso_alloc_meM(target_prefix, char, SfileadrL);
  658  Xorriso_alloc_meM(eff_source, char, SfileadrL);
  659  Xorriso_alloc_meM(eff_target, char, SfileadrL);
  660 
  661  ret= Xorriso_normalize_img_path(xorriso, s_wd, argv[*idx],
  662                                  source_prefix, ns_flag | 64);
  663  if(ret<=0)
  664    goto ex;
  665  ret= Xorriso_normalize_img_path(xorriso, t_wd, argv[(*idx)+1],
  666                                  target_prefix, nt_flag);
  667  if(ret<=0)
  668    goto ex;
  669  ret= Xorriso_opt_args(xorriso, cmd, argc, argv, (*idx)+2, &end_idx,
  670                        &optc, &optv, opt_args_flag);
  671  if(ret<=0)
  672    goto ex;
  673  if(mode == 4) {
  674    /* Convert pattern from disk to iso_rr */
  675    arg2c= end_idx - *idx - 2;
  676    Xorriso_alloc_meM(arg2v, char *, arg2c);
  677    for(i = 0; i < arg2c; i++)
  678      arg2v[i]= NULL;
  679    arg2c= 0;
  680    for(i = (*idx) + 2; i < end_idx; i++) {
  681      ret= Xorriso_normalize_img_path(xorriso, s_wd, argv[i],
  682                                      eff_source, ns_flag);
  683      if(ret<=0)
  684        goto ex;
  685      ret= Xorriso__exchange_prefix(source_prefix, target_prefix,
  686                                    eff_source, eff_target, 0);
  687      if(ret <= 0)
  688    continue;
  689      Xorriso_alloc_meM(arg2v[arg2c], char, strlen(eff_target) + 1);
  690      strcpy(arg2v[arg2c], eff_target);
  691      arg2c++;
  692    }
  693    /* Expand wildcards in iso_rr, do not include unmatched patterns */
  694    ret= Xorriso_opt_args(xorriso, cmd, arg2c, arg2v, 0, &i,
  695                           &opt2c, &opt2v, (1 << 10) | (1 << 7));
  696    if(ret<=0)
  697      goto ex;
  698    /* Convert from iso_rr path to disk path */
  699    new_opt2c= 0;
  700    for(i = 0; i < opt2c; i++) {
  701      ret= Xorriso__exchange_prefix(target_prefix, source_prefix,
  702                                    opt2v[i], eff_source, 0);
  703      free(opt2v[i]);
  704      opt2v[i]= NULL;
  705      if(ret <= 0)
  706    continue;
  707      Xorriso_alloc_meM(opt2v[new_opt2c], char, strlen(eff_source) + 1);
  708      strcpy(opt2v[new_opt2c], eff_source);
  709      new_opt2c++;
  710    }
  711    opt2c= new_opt2c;
  712    /* Merge both results */
  713    if(opt2c > 0) {
  714      Sfile_destroy_argv(&arg2c, &arg2v, 0);
  715      Xorriso_alloc_meM(arg2v, char *, optc + opt2c);
  716      for(i = 0; i < optc + opt2c; i++)
  717        arg2v[i]= NULL;
  718      arg2c= 0;
  719      for(i= 0; i < optc; i++) {
  720        ret= Xorriso_normalize_img_path(xorriso, s_wd, optv[i],
  721                                        eff_source, ns_flag);
  722        if(ret<=0)
  723          goto ex;
  724        Xorriso_alloc_meM(arg2v[arg2c], char, strlen(eff_source) + 1);
  725        strcpy(arg2v[arg2c], eff_source);
  726        arg2c++;
  727      }
  728      for(i= 0; i < opt2c; i++) {
  729        for(j= 0; j < optc; j++)
  730          if(strcmp(opt2v[i], arg2v[j]) == 0)
  731        break;
  732        if(j < optc)
  733      continue;
  734        arg2v[arg2c++]= opt2v[i];
  735        opt2v[i]= NULL;
  736      }
  737      Sfile_destroy_argv(&optc, &optv, 0);
  738      optv= arg2v;
  739      arg2v= NULL;
  740      optc= arg2c;
  741      arg2c= 0;
  742    }
  743  }
  744 
  745  if(mode == 3 &&
  746     (xorriso->do_restore_sort_lba || !(xorriso->ino_behavior & 4))) {
  747    eff_src_array= calloc(optc, sizeof(char *));
  748    eff_tgt_array= calloc(optc, sizeof(char *));
  749    if(eff_src_array == NULL || eff_tgt_array == NULL) {
  750      Xorriso_no_malloc_memory(xorriso, NULL, 0);
  751      ret= -1; goto ex;
  752    }
  753    for(i= 0; i < optc; i++)
  754      eff_src_array[i]= eff_tgt_array[i]= NULL;
  755  }
  756  if((mode == 2 || mode == 4) &&
  757      !((xorriso->ino_behavior & 2) || (flag & 16) ||
  758        xorriso->di_array != NULL)) {
  759    /* Create all-image node array sorted by isofs.di */
  760    ret= Xorriso_make_di_array(xorriso, 0);
  761    if(ret <= 0)
  762      goto ex;
  763  }
  764 
  765  for(i= 0; i<optc; i++) {
  766    ret= Xorriso_normalize_img_path(xorriso, s_wd, optv[i],
  767                                    eff_source, ns_flag);
  768    if(ret<=0)
  769      goto ex;
  770    ret= Xorriso__exchange_prefix(source_prefix, target_prefix,
  771                                  eff_source, eff_target, 0);
  772    if(ret == 0) {
  773      sprintf(xorriso->info_text, "%s: disk_path ", cmd);
  774      Text_shellsafe(eff_source, xorriso->info_text, 1);
  775      strcat(xorriso->info_text, " does not begin with disk_prefix ");
  776      Text_shellsafe(source_prefix, xorriso->info_text, 1);
  777      Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 1);
  778    }
  779    if(ret <= 0)
  780      goto ex;
  781 
  782    if(mode==0)
  783      ret= Xorriso_option_map(xorriso, eff_source, eff_target, 2);
  784    else if(mode==1)
  785      ret= Xorriso_option_compare(xorriso, eff_source, eff_target, 2|8);
  786    else if(mode == 2 || mode == 4)
  787      ret= Xorriso_option_update(xorriso, eff_source, eff_target, 2 | 8 | 16);
  788    else if(mode==3) {
  789      if(eff_src_array != NULL) {
  790        eff_src_array[i]= strdup(eff_source);
  791        eff_tgt_array[i]= strdup(eff_target);
  792        if(eff_src_array[i] == NULL || eff_tgt_array[i] == NULL) {
  793          Xorriso_no_malloc_memory(xorriso, &(eff_src_array[i]), 0);
  794          ret= -1; goto ex;
  795        }
  796      } else {
  797        ret= Xorriso_option_extract(xorriso, eff_source, eff_target, 2 | 4);
  798      }
  799    } else if(mode == 5) {
  800      ret= Xorriso_option_update(xorriso, eff_target, eff_source, 2 | 8 | 16);
  801    }
  802 
  803    if(ret>0 && !xorriso->request_to_abort)
  804  continue; /* regular bottom of loop */
  805    was_failure= 1;
  806    fret= Xorriso_eval_problem_status(xorriso, ret, 1 | 2);
  807    if(fret>=0)
  808  continue;
  809    goto ex;
  810  }
  811 
  812  ret= 1;
  813  if(mode == 3 && eff_src_array != NULL) {
  814    ret= Xorriso_lst_append_binary(&(xorriso->node_disk_prefixes),
  815                                   target_prefix, strlen(target_prefix) + 1, 0);
  816    if(ret <= 0)
  817      goto ex;
  818    ret= Xorriso_lst_append_binary(&(xorriso->node_img_prefixes),
  819                                   source_prefix, strlen(source_prefix) + 1, 0);
  820    if(ret <= 0)
  821      goto ex;
  822    ret= Xorriso_restore_sorted(xorriso, optc, eff_src_array, eff_tgt_array,
  823                                &problem_count, 0);
  824    if(ret <= 0 || problem_count > 0)
  825      was_failure= 1;
  826  }
  827  if(mode==0)
  828    Xorriso_pacifier_callback(xorriso, "files added", xorriso->pacifier_count,
  829                              xorriso->pacifier_total, "", 1);
  830  else if(mode==1 || mode==2 || mode == 4 || mode == 5)
  831    Xorriso_pacifier_callback(xorriso, "content bytes read",
  832                              xorriso->pacifier_count, 0, "", 1 | 8 | 32);
  833  else if(mode==3)
  834    Xorriso_pacifier_callback(xorriso, "files restored",xorriso->pacifier_count,
  835                              xorriso->pacifier_total, "", 1|4);
  836 ex:;
  837  Xorriso_destroy_node_array(xorriso, 0);
  838  i= optc;
  839  Sfile_destroy_argv(&i, &eff_src_array, 0);
  840  i= optc;
  841  Sfile_destroy_argv(&i, &eff_tgt_array, 0);
  842  Xorriso_free_meM(source_prefix);
  843  Xorriso_free_meM(target_prefix);
  844  Xorriso_free_meM(eff_source);
  845  Xorriso_free_meM(eff_target);
  846  (*idx)= end_idx;
  847  Xorriso_opt_args(xorriso, cmd, argc, argv, *idx, &end_idx, &optc, &optv, 256);
  848  Xorriso_opt_args(xorriso, cmd, argc, argv, *idx, &end_idx, &opt2c, &opt2v,
  849                   256);
  850  if(arg2c > 0)
  851    Sfile_destroy_argv(&arg2c, &arg2v, 0);
  852  else if(arg2v != NULL)
  853    Xorriso_free_meM(arg2v);
  854 
  855  if(ret<=0)
  856    return(ret);
  857  return(!was_failure);
  858 }
  859 
  860 
  861 /* Option -mark */
  862 int Xorriso_option_mark(struct XorrisO *xorriso, char *mark, int flag)
  863 {
  864  if(mark[0]==0)
  865    xorriso->mark_text[0]= 0;
  866  else
  867    strncpy(xorriso->mark_text,mark,sizeof(xorriso->mark_text)-1);
  868  xorriso->mark_text[sizeof(xorriso->mark_text)-1]= 0;
  869  return(1);
  870 }
  871 
  872 
  873 /* Option -md5 "on"|"all"|"off" */
  874 int Xorriso_option_md5(struct XorrisO *xorriso, char *mode, int flag)
  875 {
  876  char *npt, *cpt;
  877  int l;
  878 
  879  npt= cpt= mode;
  880  for(; npt!=NULL; cpt= npt+1) {
  881    npt= strchr(cpt,':');
  882    if(npt==NULL)
  883      l= strlen(cpt);
  884    else
  885      l= npt-cpt;
  886    if(l == 0)
  887  continue;
  888    if(l == 3 && strncmp(cpt, "off", l) == 0)
  889      xorriso->do_md5&= ~31;
  890    else if(l == 2 && strncmp(cpt, "on", l) == 0)
  891      xorriso->do_md5= (xorriso->do_md5 & ~31) | 7 | 16;
  892    else if(l == 3 && strncmp(cpt, "all", l) == 0)
  893      xorriso->do_md5|= 31;
  894    else if(l == 18 && strncmp(cpt, "stability_check_on", l) == 0)
  895      xorriso->do_md5|= 8;
  896    else if(l == 19 && strncmp(cpt, "stability_check_off", l) == 0)
  897      xorriso->do_md5&= ~8;
  898    else if(l == 13 && strncmp(cpt, "load_check_on", l) == 0)
  899      xorriso->do_md5&= ~32;
  900    else if(l == 14 && strncmp(cpt, "load_check_off", l) == 0)
  901      xorriso->do_md5|= 32;
  902    else {
  903      sprintf(xorriso->info_text, "-md5: unknown mode ");
  904      Text_shellsafe(cpt, xorriso->info_text, 1);
  905      Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
  906      return(0);
  907    }
  908  }
  909  return(1);
  910 }
  911 
  912 
  913 /* Option -mkdir alias -mkdiri */
  914 int Xorriso_option_mkdiri(struct XorrisO *xorriso, int argc, char **argv,
  915                           int *idx, int flag)
  916 {
  917  int i, end_idx, ret, was_failure= 0, fret;
  918 
  919  end_idx= Xorriso_end_idx(xorriso, argc, argv, *idx, 0);
  920 
  921  for(i= *idx; i<end_idx; i++) {
  922    ret= Xorriso_mkdir(xorriso, argv[i], 0);
  923    if(ret>0 && !xorriso->request_to_abort)
  924  continue; /* regular bottom of loop */
  925    was_failure= 1;
  926    fret= Xorriso_eval_problem_status(xorriso, ret, 1|2);
  927    if(fret>=0)
  928  continue;
  929    goto ex;
  930  }
  931  ret= 1; 
  932 ex:;
  933  (*idx)= end_idx;
  934  if(ret<=0)
  935    return(ret);
  936  return(!was_failure);
  937 }
  938 
  939 
  940 int Xorriso_option_modesty_on_drive(struct XorrisO *xorriso, char *mode,
  941                                     int flag)
  942 {
  943  char *npt, *cpt, *ppt;
  944  int l, num, set_min;
  945 
  946  npt= cpt= mode;
  947  for(; npt!=NULL; cpt= npt+1) {
  948    npt= strchr(cpt,':');
  949    if(npt==NULL)
  950      l= strlen(cpt);
  951    else
  952      l= npt-cpt;
  953    if(l == 0)
  954  continue;
  955    if(l == 3 && strncmp(cpt, "off", l) == 0) {
  956      xorriso->modesty_on_drive= 0;
  957    } else if(l == 1 && strncmp(cpt, "0", l) == 0) {
  958      xorriso->modesty_on_drive= 0;
  959    } else if(l == 2 && strncmp(cpt, "on", l) == 0) {
  960      xorriso->modesty_on_drive= 1;
  961    } else if(l == 1 && strncmp(cpt, "1", l) == 0) {
  962      xorriso->modesty_on_drive= 1;
  963    } else if(l == 2 && strncmp(cpt, "-1", l) == 0) {
  964      ;
  965    } else if(*cpt >= '1' && *cpt <= '9') {
  966      ppt= cpt;
  967      set_min= 2;
  968 set_size_percent:;
  969      sscanf(ppt, "%d", &num);
  970      if(num == -1) {
  971        ;
  972      } else if(num < 25) {
  973 bad_percent:;
  974        sprintf(xorriso->info_text, "-modesty_on_drive: percentage out of range [25 to 100]");
  975        Text_shellsafe(cpt, xorriso->info_text, 1);
  976        Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
  977        return(0);
  978      } else if(num > 100) {
  979        goto bad_percent;
  980      }
  981      if(set_min == 2) {
  982        xorriso->modesty_on_drive= 1;
  983      }
  984      if(set_min)
  985        xorriso->min_buffer_percent= num;
  986      else
  987        xorriso->max_buffer_percent= num;
  988    } else if(l >= 12 && strncmp(cpt, "min_percent=", 12) == 0) {
  989      ppt= cpt + 12;
  990      set_min= 1;
  991      goto set_size_percent;
  992    } else if(l >= 12 && strncmp(cpt, "max_percent=", 12) == 0) {
  993      ppt= cpt + 12;
  994      set_min= 0;
  995      goto set_size_percent;
  996    } else if(l >= 9 && strncmp(cpt, "min_usec=", 9) == 0) {
  997      ppt= cpt + 9;
  998      set_min= 1;
  999 set_sec:;
 1000      num= -1;
 1001      sscanf(ppt, "%d", &num);
 1002      if(num < 0)
 1003        num= 0;
 1004      if(set_min == 2)
 1005        xorriso->max_buffer_usec= num;
 1006      else if(set_min == 1)
 1007        xorriso->min_buffer_usec= num;
 1008      else if(set_min == 0)
 1009        xorriso->max_buffer_percent= num;
 1010      else
 1011        xorriso->buffer_timeout_sec= num;
 1012    } else if(l >= 9 && strncmp(cpt, "max_usec=", 9) == 0) {
 1013      ppt= cpt + 9;
 1014      set_min= 2;
 1015      goto set_sec;
 1016    } else if(l >= 12 && strncmp(cpt, "timeout_sec=", 12) == 0) {
 1017      ppt= cpt + 12;
 1018      set_min= -1;
 1019      goto set_sec;
 1020    } else {
 1021      sprintf(xorriso->info_text, "-modesty_on_drive: unknown mode ");
 1022      Text_shellsafe(cpt, xorriso->info_text, 1);
 1023      Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
 1024      return(0);
 1025    }
 1026  }
 1027  return(1);
 1028 }
 1029 
 1030 
 1031 /* Options -mount , -mount_cmd , -session_string */
 1032 /* @param bit0= -mount_cmd: print mount command to result channel rather
 1033                             than performing it
 1034           bit1= perform -session_string rather than -mount_cmd
 1035 */
 1036 int Xorriso_option_mount(struct XorrisO *xorriso, char *dev, char *adr_mode,
 1037                          char *adr, char *cmd, int flag)
 1038 {
 1039  int ret, entity_code= 0, m_flag;
 1040  char entity_id[81], *mnt;
 1041 
 1042  if(flag & 1)
 1043    mnt= "-mount_cmd";
 1044  else if(flag & 2)
 1045    mnt= "-session_string";
 1046  else {
 1047    mnt= "-mount";
 1048    if(xorriso->allow_restore <= 0) {
 1049      sprintf(xorriso->info_text,
 1050           "-mount: image-to-disk features are not enabled by option -osirrox");
 1051      Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
 1052      return(0);
 1053    }
 1054    if(Xorriso_change_is_pending(xorriso, 0)) {
 1055      sprintf(xorriso->info_text,
 1056              "%s: Image changes pending. -commit or -rollback first", mnt);
 1057      Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
 1058      return(0);
 1059    }
 1060  }
 1061  ret= Xorriso_decode_load_adr(xorriso, mnt, adr_mode, adr,
 1062                               &entity_code, entity_id, 0);
 1063  if(ret <= 0)
 1064    return(ret);
 1065  if(flag & 2)
 1066    m_flag= 1 | 4;
 1067  else
 1068    m_flag= (flag & 1) | 2;
 1069  ret= Xorriso_mount(xorriso, dev, entity_code, entity_id, cmd, m_flag);
 1070  return(ret);
 1071 }
 1072 
 1073 
 1074 /* Option -mount_opts option[:...] */
 1075 int Xorriso_option_mount_opts(struct XorrisO *xorriso, char *mode, int flag)
 1076 {
 1077  int was, l;
 1078  char *cpt, *npt;
 1079 
 1080  was= xorriso->mount_opts_flag;
 1081  npt= cpt= mode;
 1082  for(cpt= mode; npt!=NULL; cpt= npt+1) {
 1083    npt= strchr(cpt,':');
 1084    if(npt==NULL)
 1085      l= strlen(cpt);
 1086    else
 1087      l= npt-cpt;
 1088    if(l==0)
 1089      goto unknown_mode;
 1090    if(strncmp(cpt, "shared", l)==0) {
 1091      xorriso->mount_opts_flag|= 1;
 1092    } else if(strncmp(cpt, "exclusive", l)==0) {
 1093      xorriso->mount_opts_flag&= ~1;
 1094    } else {
 1095 unknown_mode:;
 1096      if(l<SfileadrL)
 1097        sprintf(xorriso->info_text, "-mount_opts: unknown option '%s'", cpt);
 1098      else
 1099        sprintf(xorriso->info_text, "-mount_opts: oversized parameter (%d)",l);
 1100      Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
 1101      xorriso->mount_opts_flag= was;
 1102      return(0);
 1103    }
 1104  }
 1105  return(1);
 1106 }
 1107 
 1108 
 1109 /* Command -move */
 1110 int Xorriso_option_move(struct XorrisO *xorriso, char *origin, char *dest,
 1111                         int flag)
 1112 {
 1113  int ret;
 1114  char *eff_origin= NULL, *eff_dest= NULL;
 1115 
 1116  Xorriso_alloc_meM(eff_origin, char, SfileadrL);
 1117  Xorriso_alloc_meM(eff_dest, char, SfileadrL);
 1118 
 1119  ret= Xorriso_normalize_img_path(xorriso, xorriso->wdi, origin, eff_origin, 0);
 1120  if(ret <= 0)
 1121    {ret= 0; goto ex;}
 1122  ret= Xorriso_normalize_img_path(xorriso, xorriso->wdi, dest, eff_dest, 2);
 1123  if(ret < 0)
 1124    {ret= 0; goto ex;}
 1125  ret= Xorriso_rename(xorriso, NULL, eff_origin, eff_dest, 0);
 1126  if(ret <= 0)
 1127    goto ex;
 1128  ret= 1;
 1129 ex:;
 1130  Xorriso_free_meM(eff_origin);
 1131  Xorriso_free_meM(eff_dest);
 1132  return(ret);
 1133 }
 1134 
 1135  
 1136 /* Command -msg_op */
 1137 int Xorriso_option_msg_op(struct XorrisO *xorriso, char *what, char *arg,
 1138                           int flag)
 1139 {
 1140  int ret, available, argc, pargc, i, pflag, max_words, input_lines, msd_mem;
 1141  char **argv= NULL, **pargv= NULL, *msg= "";
 1142  char *prefix, *separators;
 1143 
 1144  msd_mem= xorriso->msg_sieve_disabled;
 1145 
 1146  ret= 1;
 1147  if(strcmp(what, "parse") == 0 || strcmp(what, "parse_silently") == 0 ||
 1148     strcmp(what, "parse_bulk") == 0 ||
 1149     strcmp(what, "parse_bulk_silently") == 0) {
 1150    ret= Xorriso_parse_line(xorriso, arg, "", "", 5, &argc, &argv, 0);
 1151    prefix= "";
 1152    if(argc > 0) 
 1153      prefix= argv[0];
 1154    separators= "";
 1155    if(argc > 1)
 1156      separators= argv[1];
 1157    max_words= 0;
 1158    if(argc > 2)
 1159      sscanf(argv[2], "%d", &max_words);
 1160    pflag= 0;
 1161    if(argc > 3)
 1162      sscanf(argv[3], "%d", &pflag);
 1163    input_lines= 1;
 1164    if(argc > 4)
 1165      sscanf(argv[4], "%d", &input_lines);
 1166    if(strcmp(what, "parse") == 0 || strcmp(what, "parse_silently") == 0) {
 1167      ret= Xorriso_msg_op_parse(xorriso, "", prefix, separators,
 1168                                max_words, pflag, input_lines,
 1169                                (strcmp(what, "parse_silently") == 0));
 1170    } else {
 1171      ret= Xorriso_msg_op_parse_bulk(xorriso, prefix, separators,
 1172                                max_words, pflag, input_lines,
 1173                                (strcmp(what, "parse_bulk_silently") == 0));
 1174    }
 1175    if(ret <= 0)
 1176      goto ex;
 1177    xorriso->msg_sieve_disabled= msd_mem;
 1178    Xorriso__dispose_words(&argc, &argv);
 1179  } else if(strcmp(what, "start_sieve") == 0) {
 1180    Xorriso_sieve_dispose(xorriso, 0);
 1181    ret= Xorriso_sieve_big(xorriso, 0);
 1182    msg= "Message sieve enabled";
 1183 
 1184 /* >>> } else if(strcmp(what, "add_filter_rule") == 0) { */;
 1185 
 1186  } else if(strcmp(what, "clear_sieve") == 0) {
 1187    ret= Xorriso_sieve_clear_results(xorriso, 0);
 1188    msg= "Recorded message sieve results disposed";
 1189  } else if(strcmp(what, "end_sieve") == 0) {
 1190    ret= Xorriso_sieve_dispose(xorriso, 0);
 1191    msg= "Message sieve disabled";
 1192  } else if(strcmp(what, "read_sieve") == 0) {
 1193    ret= Xorriso_sieve_get_result(xorriso, arg, &pargc, &pargv, &available, 0);
 1194    xorriso->msg_sieve_disabled= 1;
 1195    sprintf(xorriso->result_line, "%d\n", ret);
 1196    Xorriso_result(xorriso, 1);
 1197    if(ret > 0) {
 1198      sprintf(xorriso->result_line, "%d\n", pargc);
 1199      Xorriso_result(xorriso, 1);
 1200      for(i= 0; i < pargc; i++) {
 1201        ret= Sfile_count_char(pargv[i], '\n') + 1;
 1202        sprintf(xorriso->result_line, "%d\n", ret);
 1203        Xorriso_result(xorriso, 1);
 1204        Sfile_str(xorriso->result_line, pargv[i], 0);
 1205        strcat(xorriso->result_line, "\n");
 1206        Xorriso_result(xorriso, 1);
 1207      }
 1208    } else {
 1209      strcpy(xorriso->result_line, "0\n");
 1210      Xorriso_result(xorriso, 1);
 1211      available= 0;
 1212    }
 1213    sprintf(xorriso->result_line, "%d\n", available);
 1214    Xorriso_result(xorriso, 1);
 1215    xorriso->msg_sieve_disabled= msd_mem;
 1216    Xorriso__dispose_words(&pargc, &pargv);
 1217    ret= 1;
 1218  } else if(strcmp(what, "show_sieve") == 0) {
 1219    ret= Xorriso_sieve_get_result(xorriso, "", &pargc, &pargv, &available, 8);
 1220    xorriso->msg_sieve_disabled= 1;
 1221    sprintf(xorriso->result_line, "%d\n", ret);
 1222    Xorriso_result(xorriso, 1);
 1223    if(ret > 0) {
 1224      sprintf(xorriso->result_line, "%d\n", pargc);
 1225      Xorriso_result(xorriso, 1);
 1226      for(i= 0; i < pargc; i++) {
 1227        sprintf(xorriso->result_line, "%s\n", pargv[i]);
 1228        Xorriso_result(xorriso, 1);
 1229      }
 1230    }
 1231    xorriso->msg_sieve_disabled= msd_mem;
 1232    Xorriso__dispose_words(&pargc, &pargv);
 1233  } else if(strcmp(what, "compare_sev") == 0) {
 1234    ret= Xorriso_parse_line(xorriso, arg, "", ",", 2, &argc, &argv, 0);
 1235    if(argc < 2) {
 1236      sprintf(xorriso->info_text,
 1237              "-msg_op cmp_sev: malformed severity pair '%s'", arg);
 1238      Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
 1239    } else {
 1240      ret= Xorriso__severity_cmp(argv[0], argv[1]);
 1241      sprintf(xorriso->result_line, "%d\n", ret);
 1242      Xorriso_result(xorriso, 1);
 1243    }
 1244    Xorriso__dispose_words(&argc, &argv);
 1245  } else if(strcmp(what, "list_sev") == 0) {
 1246    sprintf(xorriso->result_line, "%s\n", Xorriso__severity_list(0));
 1247    Xorriso_result(xorriso, 1);
 1248  } else {
 1249    sprintf(xorriso->info_text, "-msg_op: unknown operation '%s'", what);
 1250    Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
 1251    ret= 0;
 1252  }
 1253  if(ret > 0 && msg[0])
 1254    Xorriso_msgs_submit(xorriso, 0, msg, 0, "NOTE", 0);
 1255 
 1256 ex:;
 1257  xorriso->msg_sieve_disabled= msd_mem;
 1258  return(ret);
 1259 }
 1260 
 1261 
 1262 /* Option -mv alias -mvi */
 1263 int Xorriso_option_mvi(struct XorrisO *xorriso, int argc, char **argv,
 1264                       int *idx, int flag)
 1265 {
 1266  int i, end_idx_dummy, ret, is_dir= 0, was_failure= 0, fret;
 1267  char *eff_origin= NULL, *eff_dest= NULL, *dest_dir= NULL;
 1268  char *leafname= NULL;
 1269  int optc= 0;
 1270  char **optv= NULL;
 1271 
 1272  Xorriso_alloc_meM(eff_origin, char, SfileadrL);
 1273  Xorriso_alloc_meM(eff_dest, char, SfileadrL);
 1274  Xorriso_alloc_meM(dest_dir, char, SfileadrL);
 1275  Xorriso_alloc_meM(leafname, char, SfileadrL);
 1276 
 1277  ret= Xorriso_cpmv_args(xorriso, "-mvi", argc, argv, idx,
 1278                         &optc, &optv, eff_dest, 0);
 1279  if(ret<=0)
 1280    goto ex;
 1281  if(ret==2) {
 1282    is_dir= 1;
 1283    strcpy(dest_dir, eff_dest);
 1284  }
 1285  /* Perform movements */
 1286  for(i= 0; i<optc; i++) {
 1287    ret= Xorriso_normalize_img_path(xorriso, xorriso->wdi,optv[i],eff_origin,0);
 1288    if(ret<=0 || xorriso->request_to_abort)
 1289      goto problem_handler;
 1290    if(is_dir) {
 1291      ret= Sfile_leafname(eff_origin, leafname, 0);
 1292      if(ret<=0)
 1293        goto problem_handler;
 1294      strcpy(eff_dest, dest_dir);
 1295      ret= Sfile_add_to_path(eff_dest, leafname, 0);
 1296      if(ret<=0) {
 1297        sprintf(xorriso->info_text, "Effective path gets much too long (%d)",
 1298              (int) (strlen(eff_dest)+strlen(leafname)+1));
 1299        Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
 1300        goto problem_handler;
 1301      }
 1302    }
 1303    ret= Xorriso_rename(xorriso, NULL, eff_origin, eff_dest, 0);
 1304    if(ret<=0 || xorriso->request_to_abort)
 1305      goto problem_handler;
 1306    sprintf(xorriso->info_text, "Renamed in ISO image: ");
 1307    Text_shellsafe(eff_origin, xorriso->info_text, 1);
 1308    strcat(xorriso->info_text, " to ");
 1309    Text_shellsafe(eff_dest, xorriso->info_text, 1 | 2);
 1310    strcat(xorriso->info_text, "\n");
 1311    Xorriso_info(xorriso, 0);
 1312 
 1313  continue; /* regular bottom of loop */
 1314 problem_handler:;
 1315    was_failure= 1;
 1316    fret= Xorriso_eval_problem_status(xorriso, ret, 1|2);
 1317    if(fret>=0)
 1318  continue;
 1319    goto ex;
 1320  }
 1321  ret= !was_failure;
 1322 ex:;
 1323  Xorriso_free_meM(eff_origin);
 1324  Xorriso_free_meM(eff_dest);
 1325  Xorriso_free_meM(dest_dir);
 1326  Xorriso_free_meM(leafname);
 1327  Xorriso_opt_args(xorriso, "-mvi",
 1328                   argc, argv, *idx, &end_idx_dummy, &optc, &optv, 256);
 1329  return(ret);
 1330 }
 1331 
 1332 
 1333 /* Option -named_pipe_loop */
 1334 int Xorriso_option_named_pipe_loop(struct XorrisO *xorriso, char *mode,
 1335                                    char *stdin_pipe, char *stdout_pipe,
 1336                                    char *stderr_pipe, int flag)
 1337 {
 1338  char *pipe_paths[3], *cpt, *npt;
 1339  int ret, hflag= 0, l;
 1340 
 1341  npt= mode;
 1342  for(cpt= mode; npt != NULL; cpt= npt + 1) {
 1343    npt= strchr(cpt, ':');
 1344    if(npt==NULL)
 1345      l= strlen(cpt);
 1346    else
 1347      l= npt-cpt;
 1348    if(l==0) {
 1349      ;
 1350    } else if(strncmp(cpt, "-", l) == 0) {
 1351      ;
 1352    } else if(strncmp(cpt, "cleanup", l) == 0) {
 1353      hflag|= 1;
 1354    } else if(strncmp(cpt, "keep", l) == 0) {
 1355      hflag&= ~1;
 1356    } else if(strncmp(cpt, "buffered", l) == 0) {
 1357      hflag|= 2;
 1358    } else if(strncmp(cpt, "direct", l) == 0) {
 1359      hflag&= ~2;
 1360    } else { 
 1361      sprintf(xorriso->info_text, "-named_pipe_loop: unknown mode in '%s'",
 1362              mode);
 1363      Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
 1364      return(0);
 1365    }
 1366  }
 1367  pipe_paths[0]= stdin_pipe;
 1368  pipe_paths[1]= stdout_pipe;
 1369  pipe_paths[2]= stderr_pipe;
 1370  ret= Xorriso_named_pipe_loop(xorriso, pipe_paths, hflag);
 1371  return(ret);
 1372 }
 1373 
 1374 
 1375 /* Option -no_rc */
 1376 int Xorriso_option_no_rc(struct XorrisO *xorriso, int flag)
 1377 {
 1378  xorriso->no_rc= 1;
 1379  return(1);
 1380 }
 1381 
 1382 
 1383 /* Option -not_leaf , (-hide_disk_leaf , -as mkisofs -hide) */
 1384 /* @param flag  bit0-bit5= hide rather than adding to disk_exclusions
 1385                   bit0= add to iso_rr_hidings
 1386                   bit1= add to joliet_hidings
 1387                   bit2= add to hfsplus_hidings
 1388 */
 1389 int Xorriso_option_not_leaf(struct XorrisO *xorriso, char *pattern, int flag)
 1390 {
 1391  regex_t re;
 1392  char *regexpr= NULL;
 1393  int ret= 0;
 1394 
 1395  Xorriso_alloc_meM(regexpr, char, 2 * SfileadrL + 2);
 1396 
 1397  if(pattern[0]==0)
 1398    {ret= 0; goto cannot_add;}
 1399  Xorriso__bourne_to_reg(pattern, regexpr, 0);
 1400  if(regcomp(&re, regexpr, 0)!=0)
 1401    {ret= 0; goto cannot_add;}
 1402  if(flag & 63) {
 1403    if(flag & 1) {
 1404      ret= Exclusions_add_not_leafs(xorriso->iso_rr_hidings, pattern, &re, 0);
 1405      if(ret<=0)
 1406        goto cannot_add;
 1407    }
 1408    if(flag & 2) {
 1409      ret= Exclusions_add_not_leafs(xorriso->joliet_hidings, pattern, &re, 0);
 1410      if(ret<=0)
 1411        goto cannot_add;
 1412    }
 1413    if(flag & 4) {
 1414      ret= Exclusions_add_not_leafs(xorriso->hfsplus_hidings, pattern, &re, 0);
 1415      if(ret<=0)
 1416        goto cannot_add;
 1417    }
 1418  } else {
 1419    ret= Exclusions_add_not_leafs(xorriso->disk_exclusions, pattern, &re, 0);
 1420  }
 1421  if(ret<=0) {
 1422 cannot_add:;
 1423    sprintf(xorriso->info_text,"Cannot add pattern: %s ",
 1424            (flag & 3) ? "-hide_disk_leaf" : "-not_leaf");
 1425    Text_shellsafe(pattern, xorriso->info_text, 1);
 1426    Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
 1427    goto ex;
 1428  }
 1429  ret= 1;
 1430 ex:;
 1431  Xorriso_free_meM(regexpr);
 1432  return(ret);
 1433 }
 1434 
 1435 
 1436 /* Option -not_list , -quoted_not_list */
 1437 /* @param flag bit0= -quoted_not_list */
 1438 int Xorriso_option_not_list(struct XorrisO *xorriso, char *adr, int flag)
 1439 {
 1440  int ret, linecount= 0, insertcount= 0, null= 0, argc= 0, i;
 1441  FILE *fp= NULL;
 1442  char **argv= NULL;
 1443  
 1444  Xorriso_pacifier_reset(xorriso, 0);
 1445  if(adr[0]==0) {
 1446    sprintf(xorriso->info_text, "Empty file name given with %s",
 1447            (flag & 1) ? "-quoted_not_list" : "-not_list");
 1448    Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
 1449    return(0);
 1450  }
 1451  ret= Xorriso_afile_fopen(xorriso, adr, "rb", &fp, 0);
 1452  if(ret <= 0)
 1453    return(0);
 1454  while(1) {
 1455    ret= Xorriso_read_lines(xorriso, fp, &linecount, &argc, &argv,
 1456                            4 | (flag & 1) );
 1457    if(ret <= 0)
 1458      goto ex;
 1459    if(ret == 2)
 1460  break;
 1461    for(i= 0; i < argc; i++) {
 1462      if(argv[i][0] == 0)
 1463    continue;
 1464      if(strchr(argv[i], '/')!=NULL) {
 1465        null= 0;
 1466        ret= Xorriso_option_not_paths(xorriso, 1, argv + i, &null, 0);
 1467      } else
 1468        ret= Xorriso_option_not_leaf(xorriso, argv[i], 0);
 1469      if(ret<=0)
 1470        goto ex;
 1471      insertcount++;
 1472    }
 1473  }
 1474  ret= 1;
 1475 ex:;
 1476  Xorriso_read_lines(xorriso, fp, &linecount, &argc, &argv, 2);
 1477  if(fp != NULL && fp != stdin)
 1478    fclose(fp);
 1479  if(ret<=0) {
 1480    sprintf(xorriso->info_text, "Aborted reading of file ");
 1481    Text_shellsafe(adr, xorriso->info_text, 1);
 1482    sprintf(xorriso->info_text + strlen(xorriso->info_text),
 1483            " in line number %d", linecount);
 1484    Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
 1485  }
 1486  sprintf(xorriso->info_text, "Added %d exclusion list items from file ",
 1487          insertcount);
 1488  Text_shellsafe(adr, xorriso->info_text, 1);
 1489  strcat(xorriso->info_text, "\n");
 1490  Xorriso_info(xorriso,0);
 1491  return(ret);
 1492 }
 1493 
 1494 
 1495 /* Option -not_mgt */
 1496 int Xorriso_option_not_mgt(struct XorrisO *xorriso, char *setting, int flag)
 1497 {
 1498  int ret;
 1499  char *what_data= NULL, *what, *what_next;
 1500 
 1501  Xorriso_alloc_meM(what_data, char, SfileadrL);
 1502 
 1503  if(Sfile_str(what_data, setting, 0)<=0) {
 1504    sprintf(xorriso->info_text,
 1505            "-not_mgt: setting string is much too long (%d)",
 1506            (int) strlen(setting));
 1507    Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
 1508    {ret= 0; goto ex;}
 1509  } 
 1510  for(what= what_data; what!=NULL; what= what_next) {
 1511    what_next= strchr(what, ':');
 1512    if(what_next!=NULL) {
 1513      *what_next= 0;
 1514      what_next++;
 1515    }
 1516 
 1517    if(strcmp(what, "reset")==0 || strcmp(what, "erase")==0) {
 1518      if(strcmp(what, "reset")==0)
 1519        xorriso->disk_excl_mode= 1;
 1520      Exclusions_destroy(&(xorriso->disk_exclusions), 0);
 1521      ret= Exclusions_new(&(xorriso->disk_exclusions), 0);
 1522      if(ret<=0) {
 1523        Xorriso_no_malloc_memory(xorriso, NULL, 0);
 1524        goto ex;
 1525      }
 1526    } else if(strcmp(what, "on")==0) {
 1527      xorriso->disk_excl_mode|= 1;
 1528    } else if(strcmp(what, "off")==0) {
 1529      xorriso->disk_excl_mode&= ~1;
 1530    } else if(strcmp(what, "param_on")==0) {
 1531      xorriso->disk_excl_mode|= 2;
 1532    } else if(strcmp(what, "param_off")==0) {
 1533      xorriso->disk_excl_mode&= ~2;
 1534    } else if(strcmp(what, "subtree_on")==0) {
 1535      xorriso->disk_excl_mode|= 4;
 1536    } else if(strcmp(what, "subtree_off")==0) {
 1537      xorriso->disk_excl_mode&= ~4;
 1538    } else if(strcmp(what, "ignore_on")==0) {
 1539      xorriso->disk_excl_mode|= 8;
 1540    } else if(strcmp(what, "ignore_off")==0) {
 1541      xorriso->disk_excl_mode&= ~8;
 1542    } else {
 1543      sprintf(xorriso->info_text, "-not_mgt: unknown setting '%s'", what);
 1544      Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
 1545      {ret= 0; goto ex;}
 1546    }
 1547  }
 1548  ret= 1;
 1549 ex:;
 1550  Xorriso_free_meM(what_data);
 1551  return(ret);
 1552 }
 1553 
 1554 
 1555 /* Option -not_paths , (-hide_disk_paths , -as mkisofs -hide) */
 1556 /* @param flag  bit0= add to iso_rr_hidings rather than disk_exclusions
 1557                 bit1= add to joliet_hidings rather than disk_exclusions
 1558                 bit2= enable disk pattern expansion regardless of -disk_pattern
 1559                 bit8-13= consolidated hide state bits, duplicating bit0-1
 1560                    bit8= add to iso_rr_hidings
 1561                    bit9= add to joliet_hidings
 1562                   bit10= add to hfsplus_hidings
 1563 */
 1564 int Xorriso_option_not_paths(struct XorrisO *xorriso, int argc, char **argv,
 1565                              int *idx, int flag)
 1566 {
 1567  int ret, end_idx, num_descr= 0, dummy, optc= 0, i;
 1568  char **descr= NULL, **optv= NULL, *eff_path= NULL, *hpt= NULL;
 1569 
 1570  end_idx= Xorriso_end_idx(xorriso, argc, argv, *idx,
 1571                           (xorriso->do_disk_pattern == 1 || (flag & 4)) | 2);
 1572  if(end_idx<=0)
 1573    {ret= end_idx; goto ex;}
 1574 
 1575  num_descr= end_idx - *idx;
 1576  if(num_descr<=0)
 1577    {ret= 1; goto ex;}
 1578  
 1579  /* produce absolute patterns */
 1580  Xorriso_alloc_meM(eff_path, char, SfileadrL);
 1581  descr= TSOB_FELD(char *, num_descr);
 1582  if(descr==NULL) {
 1583 no_memory:;
 1584    Xorriso_no_pattern_memory(xorriso, sizeof(char *) * (off_t) num_descr, 0);
 1585    ret= -1; goto ex;
 1586  }
 1587  for(i= 0; i<num_descr; i++)
 1588    descr[i]= NULL;
 1589  for(i= 0; i<num_descr; i++) {
 1590    ret= Xorriso_normalize_img_path(xorriso, xorriso->wdx, argv[i+*idx],
 1591                                    eff_path, 2|4);
 1592    if(ret<=0)
 1593      goto ex;
 1594    descr[i]= strdup(eff_path); 
 1595    if(descr[i]==NULL)
 1596      goto no_memory;
 1597  }
 1598 
 1599  ret= Xorriso_opt_args(xorriso,
 1600                        (flag & 0x3f03) ? "-hide_disk_paths" : "-not_paths",
 1601                        num_descr, descr, 0, &dummy, &optc, &optv,
 1602                        2 | ((flag & 4) << 7));
 1603  if(ret<=0)
 1604    goto ex; 
 1605  if(flag & 0x3f03) {
 1606    if(flag & 0x0101) {
 1607      ret= Exclusions_add_not_paths(xorriso->iso_rr_hidings,
 1608                                    num_descr, descr, optc, optv, 0);
 1609      if(ret<=0) {
 1610 no_hide:;
 1611        sprintf(xorriso->info_text, "Cannot add path list: -hide_disk_paths ");
 1612        hpt= Xorriso__hide_mode_text(flag & 0x3f03, 0);
 1613        if(hpt != NULL)
 1614          sprintf(xorriso->info_text + strlen(xorriso->info_text), "%s ", hpt);
 1615        Xorriso_free_meM(hpt);
 1616        Text_shellsafe(argv[*idx], xorriso->info_text, 1);
 1617        strcat(xorriso->info_text, num_descr > 1 ? " ... " : " ");
 1618        strcat(xorriso->info_text, xorriso->list_delimiter);
 1619        Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
 1620        goto ex;
 1621      }
 1622    }
 1623    if(flag & 0x0202) {
 1624      ret= Exclusions_add_not_paths(xorriso->joliet_hidings,
 1625                                    num_descr, descr, optc, optv, 0);
 1626      if(ret<=0)
 1627        goto no_hide;
 1628    }
 1629    if(flag & 0x0400) {
 1630      ret= Exclusions_add_not_paths(xorriso->hfsplus_hidings,
 1631                                    num_descr, descr, optc, optv, 0);
 1632      if(ret<=0)
 1633        goto no_hide;
 1634    }
 1635  } else {
 1636    ret= Exclusions_add_not_paths(xorriso->disk_exclusions,
 1637                                  num_descr, descr, optc, optv, 0);
 1638    if(ret<=0) {
 1639      sprintf(xorriso->info_text,"Cannot add path list: -not_paths ");
 1640      Text_shellsafe(argv[*idx], xorriso->info_text, 1);
 1641      strcat(xorriso->info_text, num_descr > 1 ? " ... " : " ");
 1642      strcat(xorriso->info_text, xorriso->list_delimiter);
 1643      Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
 1644    }
 1645  }
 1646 ex:;
 1647  (*idx)= end_idx;
 1648  Xorriso_opt_args(xorriso, "-not_paths",
 1649                   num_descr, descr, 0, &dummy, &optc, &optv, 256);
 1650  if(descr!=NULL) {
 1651    for(i= 0; i<num_descr; i++)
 1652      if(descr[i]!=NULL)
 1653        free(descr[i]);
 1654    free((char *) descr);
 1655    descr= NULL;
 1656  }
 1657  Xorriso_free_meM(eff_path);
 1658  return(ret);
 1659 }
 1660 
 1661 
 1662 /* Option -options_from_file */
 1663 int Xorriso_option_options_from_file(struct XorrisO *xorriso, char *adr,
 1664                                      int flag)
 1665 /*
 1666  bit0= called from Xorriso_prescan_args,
 1667        therefore execute via that same function
 1668 */
 1669 /*
 1670 return:
 1671  <=0 error , 1 = success , 3 = end program run
 1672 */
 1673 {
 1674  int ret,linecount= 0, argc= 0, was_failure= 0, fret;
 1675  FILE *fp= NULL;
 1676  char **argv= NULL;
 1677  int linec= 0;
 1678  char *line= NULL, **linev= NULL;
 1679 
 1680  if(adr[0]==0) {
 1681    sprintf(xorriso->info_text,"Empty file name given with -options_from_file");
 1682    Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
 1683    return(0);
 1684  }
 1685  if(xorriso->is_dialog) {
 1686    sprintf(xorriso->info_text,"+ performing command lines from file ");
 1687    Text_shellsafe(adr, xorriso->info_text, 1);
 1688    strcat(xorriso->info_text, " :\n");
 1689    Xorriso_info(xorriso,1);
 1690  }
 1691  ret= Xorriso_afile_fopen(xorriso, adr, "rb", &fp, 0);
 1692  if(ret <= 0)
 1693    return(0);
 1694  sprintf(xorriso->info_text, "Command file:  ");
 1695  Text_shellsafe(adr, xorriso->info_text, 1);
 1696  Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "DEBUG", 0);
 1697  while(1) {
 1698    ret= Xorriso_read_lines(xorriso, fp, &linecount, &linec, &linev, 1 | 8);
 1699    if(ret <= 0)
 1700      goto ex; /* no problem_handler because there is no sense in going on */
 1701    if(ret == 2)
 1702  break;
 1703    line= linev[0];
 1704    if(line[0]==0 || line[0]=='#')
 1705  continue;
 1706 
 1707    if(flag&1) {
 1708      ret= Sfile_make_argv(xorriso->progname, line, &argc, &argv,
 1709                           4 | 8 | ((xorriso->bsl_interpretation & 3) << 5));
 1710      if(ret<=0)
 1711        goto problem_handler;
 1712      ret= Xorriso_prescan_args(xorriso,argc,argv,1);
 1713      if(ret==0)
 1714        {ret= 3; goto ex;}
 1715      if(ret<0)
 1716        goto problem_handler;
 1717    } else {
 1718      if(xorriso->is_dialog) {
 1719        sprintf(xorriso->info_text,"+ %d:  %s\n",linecount,line);
 1720        Xorriso_info(xorriso,1);
 1721      }
 1722      ret= Xorriso_execute_option(xorriso,line,1|(1<<16));
 1723      if(ret==3)
 1724        goto ex;
 1725      if(ret<=0)
 1726        goto problem_handler;
 1727    }
 1728 
 1729  continue; /* regular bottom of loop */
 1730 problem_handler:;
 1731    was_failure= 1;
 1732    fret= Xorriso_eval_problem_status(xorriso, ret, 1);
 1733    if(fret>=0)
 1734  continue;
 1735    goto ex;
 1736  }
 1737  ret= 1;
 1738 ex:;
 1739  Sfile_make_argv("", "", &argc, &argv, 2); /* release memory */
 1740  Xorriso_read_lines(xorriso, fp, &linecount, &linec, &linev, 2);
 1741  Xorriso_reset_counters(xorriso,0);
 1742  if(fp != NULL && fp != stdin)
 1743    fclose(fp);
 1744  if(ret<=0) {
 1745    sprintf(xorriso->info_text,
 1746            "error triggered by line %d of file:\n    ", linecount);
 1747    Text_shellsafe(adr, xorriso->info_text, 1);
 1748    strcat(xorriso->info_text, "\n");
 1749    Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "NOTE", 1);
 1750  }
 1751  sprintf(xorriso->info_text, "Command file end:  ");
 1752  Text_shellsafe(adr, xorriso->info_text, 1);
 1753  Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "DEBUG", 0);
 1754  if(ret!=1)
 1755    return(ret);
 1756  return(!was_failure);
 1757 }
 1758 
 1759 
 1760 /* Option -osirrox "on"|"off" */
 1761 int Xorriso_option_osirrox(struct XorrisO *xorriso, char *mode, int flag)
 1762 {
 1763  int l, allow_restore;
 1764  char *npt, *cpt;
 1765  double num= 0.0;
 1766 
 1767  allow_restore= xorriso->allow_restore;
 1768 
 1769  npt= cpt= mode;
 1770  for(cpt= mode; npt!=NULL; cpt= npt+1) {
 1771    npt= strchr(cpt,':');
 1772    if(npt==NULL)
 1773      l= strlen(cpt);
 1774    else
 1775      l= npt-cpt;
 1776    if(l==0 && mode[0]!=0)
 1777      goto unknown_mode;
 1778    if(strncmp(cpt, "off", l)==0 && l >= 3)
 1779      allow_restore= 0;
 1780    else if(strncmp(cpt, "banned", l)==0 && l >= 5)
 1781      allow_restore= -1;
 1782    else if(strncmp(cpt, "blocked", l)==0 && l >= 7)
 1783      allow_restore= -2;
 1784    else if(strncmp(cpt, "unblock", l)==0 && l >= 7) {
 1785      if(xorriso->allow_restore == -2)
 1786        xorriso->allow_restore= 0;
 1787      allow_restore= 1;
 1788    } else if(strncmp(cpt, "device_files", l)==0 && l >= 12)
 1789      allow_restore= 2;
 1790    else if((strncmp(cpt, "on", l)==0 && l >= 2) || mode[0]==0)
 1791      allow_restore= 1;
 1792    else if(strncmp(cpt, "concat_split_on", l)==0 && l >= 15)
 1793      xorriso->do_concat_split= 1;
 1794    else if(strncmp(cpt, "concat_split_off", l)==0 && l >= 16)
 1795      xorriso->do_concat_split= 0;
 1796    else if(strncmp(cpt, "auto_chmod_on", l)==0 && l >= 13)
 1797      xorriso->do_auto_chmod= 1;
 1798    else if(strncmp(cpt, "auto_chmod_off", l)==0 && l >= 14)
 1799      xorriso->do_auto_chmod= 0;
 1800    else if(strncmp(cpt, "sort_lba_on", l)==0 && l >= 11)
 1801      xorriso->do_restore_sort_lba= 1;
 1802    else if(strncmp(cpt, "sort_lba_off", l)==0 && l >= 12)
 1803      xorriso->do_restore_sort_lba= 0;
 1804    else if(strncmp(cpt, "o_excl_on", l)==0 && l >= 9)
 1805      xorriso->drives_exclusive= 1;
 1806    else if(strncmp(cpt, "o_excl_off", l)==0 && l >= 10)
 1807      xorriso->drives_exclusive= 0;
 1808    else if(strncmp(cpt, "strict_acl_on", l)==0 && l >= 13)
 1809      xorriso->do_strict_acl|= 1;
 1810    else if(strncmp(cpt, "strict_acl_off", l)==0 && l >= 14)
 1811      xorriso->do_strict_acl&= ~1;
 1812    else if(strncmp(cpt, "check_md5_on", l) == 0 && l >= 12) {
 1813      xorriso->do_md5|= 1 << 6;
 1814      xorriso->do_md5&= ~(2 << 6);
 1815    } else if(strncmp(cpt, "check_md5_force", l)==0 && l >= 15) {
 1816      xorriso->do_md5|= 3 << 6;
 1817    } else if(strncmp(cpt, "check_md5_off", l)==0 && l >= 13) {
 1818      xorriso->do_md5&= ~(3 << 6);
 1819    } else if(strncmp(cpt, "sparse=", 7) == 0 && l >= 7) {
 1820      if(strncmp(cpt + 7, "off", 3) == 0 && l == 10) {
 1821        num= 0.0;
 1822      } else {
 1823        Xorriso__parse_size_param(cpt, 7, l, &num);
 1824        if(num < 1.0)
 1825          num= 0.0;
 1826        if(num > 1.0 * 1024.0 * 1024.0 * 1024.0) {
 1827          strcpy(xorriso->info_text,
 1828                 "osirrox sparse= too large (allowed: off, 1 to 1g)");
 1829          Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
 1830          return(0);
 1831        }
 1832      }
 1833      xorriso->sparse_min_gap= num;
 1834    } else {
 1835 unknown_mode:;
 1836      sprintf(xorriso->info_text, "-osirrox: unknown mode '%s'", cpt);
 1837      Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
 1838      return(0);
 1839    }
 1840  }
 1841  if(allow_restore > 0 && xorriso->allow_restore == -1) {
 1842    sprintf(xorriso->info_text,
 1843      "-osirrox: was already permanently disabled by setting 'banned'");
 1844    Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
 1845    return(0);
 1846  }
 1847  if(allow_restore > 0 && xorriso->allow_restore == -2) {
 1848    sprintf(xorriso->info_text,
 1849            "-osirrox: is currently disabled by setting 'blocked'");
 1850    Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
 1851    return(0);
 1852  }
 1853  if(xorriso->allow_restore != -1)
 1854    xorriso->allow_restore= allow_restore;
 1855  sprintf(xorriso->info_text,
 1856          "Copying of file objects from ISO image to disk filesystem is: %s\n",
 1857          xorriso->allow_restore > 0 ? "Enabled" : "Disabled");
 1858  Xorriso_info(xorriso, 0);
 1859  return(1);
 1860 }
 1861 
 1862 
 1863 /* Option -overwrite "on"|"nondir"|"off" */
 1864 int Xorriso_option_overwrite(struct XorrisO *xorriso, char *mode, int flag)
 1865 {
 1866  if(strcmp(mode, "off")==0)
 1867    xorriso->do_overwrite= 0;
 1868  else if(strcmp(mode, "on")==0)
 1869    xorriso->do_overwrite= 1;
 1870  else if(strcmp(mode, "nondir")==0)
 1871    xorriso->do_overwrite= 2;
 1872  else {
 1873    sprintf(xorriso->info_text, "-overwrite: unknown mode '%s'", mode);
 1874    Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
 1875    return(0);
 1876  }
 1877  return(1);
 1878 }
 1879 
 1880