"Fossies" - the Fresh Open Source Software Archive

Member "xorriso-1.5.4/xorriso/xorriso_main.c" (30 Jan 2021, 10523 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 "xorriso_main.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 - Command line oriented batch and dialog tool which creates, loads,
    3    manipulates and burns ISO 9660 filesystem images.
    4 
    5    Copyright 2007-2021 Thomas Schmitt, <scdbackup@gmx.net>
    6 
    7    Initial code of this program was derived from program src/askme.c out
    8    of scdbackup-0.8.8, Copyright 2007 Thomas Schmitt, BSD-License.
    9 
   10    Provided under GPL version 2 or later, with the announcement that this
   11    might get changed in future. I would prefer BSD or LGPL as soon as the
   12    license situation of the library code allows that.
   13    (This announcement affects only future releases of xorriso and it will
   14     always be possible to derive a GPLv2+ from the future license.)
   15 
   16    There is a derived package "GNU xorriso" under GPLv3+ which combines the
   17    libburnia libraries and program xorriso to a statically linked binary.
   18 
   19 
   20    Overview of xorriso architecture:
   21 
   22    libburn provides the ability to read and write data. 
   23 
   24    libisofs interprets and manipulates ISO 9660 directory trees. It generates
   25    the output stream which is handed over to libburn.
   26 
   27    libisoburn by its lower level API encapsulates the connectivity issues
   28    between libburn and libisofs. This API also enables multi-session emulation
   29    on overwritable media and random access file objects.
   30 
   31    xorriso is the higher level API of libisoburn which allows to operate all
   32    three libraries by a unified set of commands. 
   33    <libisoburn/xorriso.h> exposes the public functions.
   34    Among these functions are direct equivalents of the xorriso interpreter
   35    commands. There are also functions for fundamental management and for
   36    handling event messages.
   37 
   38    This file  xorriso_main.c  runs the xorriso API as batch and dialog program.
   39 
   40    One should not mix the use of the xorriso API with the use of the lower
   41    level APIs of libburn, libisofs, libisoburn.
   42    
   43    --------------------------------------------------------------------------
   44    The following overview is relevant for development but not for usage of
   45    xorriso. An application programmer should read xorriso.h and man xorriso
   46    (or info xorriso), rather than diving into its source code.
   47    For examples see the functions main() and check_compatibility() below.
   48    --------------------------------------------------------------------------
   49 
   50    The xorriso source is divided in two groups:
   51 
   52    A set of source modules interacts with the lower level library APIs:
   53 
   54    base_obj.[ch]    fundamental operations of the XorrisO object
   55    lib_mgt.[ch]     manages the relation between xorriso and the libraries
   56    drive_mgt.[ch]   operates on drives and media
   57    iso_img.[ch]     operates on ISO images and their global properties
   58    iso_tree.[ch]    access nodes of the libisofs tree model
   59    iso_manip.[ch]   manipulates the libisofs tree model
   60    sort_cmp.[ch]    sorts and compare tree nodes
   61    write_run.[ch]   functions to write sessions
   62    read_run.[ch]    functions to read data from ISO image
   63    filters.[ch]     operates on data filter objects
   64    xorrisoburn.h    declarations needed by the non-library modules
   65 
   66    Another set is independent of the lower level APIs:
   67 
   68    parse_exec.c     deals with parsing and interpretation of command input
   69    sfile.c          functions around files and strings
   70    aux_objects.c    various helper classes
   71    misc_funct.c     miscellaneous helper functions
   72    findjob.c        performs tree searches in libisofs or in POSIX filesystem
   73    check_media.c    perform verifying runs on media or images
   74    text_io.c        text i/o functions
   75    match.c          functions for pattern matching
   76    emulators.c      emulators for mkisofs and cdrecord
   77    disk_ops.c       actions on onjects of disk filesystems
   78    cmp_update.c     compare or update files between disk filesystem and
   79                     ISO filesystem
   80    opts_a_c.c       commands -a* to -c*
   81    opts_d_h.c       commands -d* to -h*
   82    opts_i_o.c       commands -i* to -o*
   83    opts_p_z.c       commands -p* to -z*
   84 
   85    xorriso_private.h contains the definition of struct Xorriso and for
   86    convenience includes the .h files of the non-library group.
   87 
   88 */
   89 
   90 #ifdef HAVE_CONFIG_H
   91 #include "../config.h"
   92 #endif
   93 
   94 #include <ctype.h>
   95 #include <sys/types.h>
   96 #include <unistd.h>
   97 #include <stdlib.h>
   98 #include <stdio.h>
   99 #include <string.h>
  100 
  101 #include <locale.h>
  102 
  103 
  104 /* xorriso_main.c includes the internal copy of the API definition */
  105 /* The official xorriso options API is defined in <libisoburn/xorriso.h> */
  106 #include "xorriso.h"
  107 
  108 
  109 /* The minimum version of libisoburn xorriso API to be used with this
  110    version of xorriso.
  111 */
  112 #define Xorriso_req_majoR  1
  113 #define Xorriso_req_minoR  5
  114 #define Xorriso_req_micrO  4
  115 
  116 
  117 static void yell_xorriso()
  118 {
  119  fprintf(stderr,
  120          "%sxorriso %d.%d.%d%s : RockRidge filesystem manipulator, libburnia project.\n\n",
  121 #ifdef Xorriso_GNU_xorrisO
  122         "GNU ",
  123 #else
  124         "",
  125 #endif
  126         Xorriso_header_version_majoR, Xorriso_header_version_minoR,
  127         Xorriso_header_version_micrO, Xorriso_program_patch_leveL);
  128 }
  129 
  130 
  131 /* Check whether build configuration and runtime linking are consistent.
  132 */
  133 static void check_compatibility()
  134 {
  135  int lib_major, lib_minor, lib_micro;
  136 
  137 /* First an ugly compile time check for header version compatibility.
  138    If everything matches, then no C code is produced. In case of mismatch,
  139    intentionally faulty C code will be inserted.
  140 */
  141 /* The minimum requirement of xorriso towards the libisoburn header
  142    at compile time is defined above 
  143      Xorriso_req_majoR
  144      Xorriso_req_minoR
  145      Xorriso_req_micrO
  146    It gets compared against the version macros in xorriso.h :
  147      Xorriso_header_version_majoR
  148      Xorriso_header_version_minoR
  149      Xorriso_header_version_micrO
  150    If the header is too old then the following code shall cause failure of
  151    cdrskin compilation rather than to allow production of a program with
  152    unpredictable bugs or memory corruption.
  153    The compiler messages supposed to appear in this case are:
  154       error: 'XORRISO_MISCONFIGURATION' undeclared (first use in this function)
  155       error: 'INTENTIONAL_ABORT_OF_COMPILATION__HEADERFILE_xorriso_dot_h_TOO_OLD__SEE_xorriso_main_dot_c' undeclared (first use in this function)
  156       error: 'XORRISO_MISCONFIGURATION_' undeclared (first use in this function)
  157 */
  158 /* The indentation is an advise of man gcc to help old compilers ignoring */
  159  #if Xorriso_req_majoR > Xorriso_header_version_majoR
  160  #define Xorriso_dot_h_too_olD 1
  161  #endif
  162  #if Xorriso_req_majoR == Xorriso_header_version_majoR && Xorriso_req_minoR > Xorriso_header_version_minoR
  163  #define Xorriso_dot_h_too_olD 1
  164  #endif
  165  #if Xorriso_req_minoR == Xorriso_header_version_minoR && Xorriso_req_micrO > Xorriso_header_version_micrO
  166  #define Xorriso_dot_h_too_olD 1
  167  #endif
  168 
  169 #ifdef Xorriso_dot_h_too_olD
  170 XORRISO_MISCONFIGURATION = 0;
  171 INTENTIONAL_ABORT_OF_COMPILATION__HEADERFILE_xorriso_dot_h_TOO_OLD__SEE_xorriso_main_dot_c = 0;
  172 XORRISO_MISCONFIGURATION_ = 0;
  173 #endif
  174 
  175 /* End of ugly compile time test (scroll up for explanation) */
  176 
  177 
  178  /* Needed are at least 44 bits in signed type off_t .
  179     This is a popular mistake in configuration or compilation.
  180  */
  181  if(sizeof(off_t) < 6) {
  182    yell_xorriso();
  183    fprintf(stderr,
  184     "xorriso : FATAL : Compile time misconfiguration. sizeof(off_t) too small.\n\n");
  185    exit(4);
  186  }
  187 
  188  /* Check whether the linked xorriso code is young enough.
  189  */
  190  if(! Xorriso__is_compatible(Xorriso_header_version_majoR,
  191                              Xorriso_header_version_minoR,
  192                              Xorriso_header_version_micrO, 0)) {
  193    yell_xorriso();
  194    Xorriso__version(&lib_major, &lib_minor, &lib_micro);
  195    fprintf(stderr,
  196            "xorriso : FATAL : libisoburn/xorriso runtime version mismatch. Found %d.%d.%d, need %d.%d.%d\n\n",
  197            lib_major, lib_minor, lib_micro,
  198            Xorriso_header_version_majoR, Xorriso_header_version_minoR,
  199            Xorriso_header_version_micrO);
  200    exit(4);
  201  }
  202 
  203 }
  204 
  205 
  206 int main(int argc, char **argv)
  207 {
  208  int ret, i;
  209  struct XorrisO *xorriso= NULL;
  210  char **orig_argv= NULL;
  211 
  212  check_compatibility(); /* might exit() */
  213 
  214  if(argc < 2) {
  215    yell_xorriso();
  216    fprintf(stderr,"usage : %s [commands]\n", argv[0]);
  217    fprintf(stderr, "        More is told by command -help\n");
  218    exit(2);
  219  }
  220  setlocale(LC_CTYPE, "");
  221  ret= Xorriso_new(&xorriso, argv[0], 0);
  222  if(ret <= 0) {
  223    fprintf(stderr,"Creation of XorrisO object failed. (not enough memory ?)\n");
  224    exit(3);
  225  }
  226 
  227  /* The prescan of arguments performs actions which have to happen before
  228     the normal processing of startup files and arguments.
  229     Among them are -help and -prog_help which end the program without
  230     yelling its name and version.
  231  */
  232  ret= Xorriso_prescan_args(xorriso,argc,argv,0);
  233  if(ret == 0)
  234    goto end_successfully;
  235  /* Put out program name and version to stderr only if not done already now */
  236  yell_xorriso();
  237  if(ret < 0)
  238    exit(5);
  239  /* After having yelled xorriso, prescan again for unknown arguments */
  240  ret= Xorriso_prescan_args(xorriso, argc, argv, 2);
  241  if(ret < 0)
  242    exit(5);
  243 
  244  /* The following command interpreters are allowed only after this
  245     initialization.
  246  */
  247  ret= Xorriso_startup_libraries(xorriso, 0);
  248  if(ret <= 0)
  249    {ret= 4; goto emergency_exit;}
  250  Xorriso_process_msg_queues(xorriso, 0);
  251 
  252  /* Interpret startup files */
  253  ret= Xorriso_read_rc(xorriso, 0);
  254  if(ret == 3)
  255    goto end_successfully;
  256  if(ret <= 0)
  257    {ret= 5; goto emergency_exit;}
  258 
  259  /* Interpret program arguments */
  260  orig_argv= argv;
  261  ret= Xorriso_program_arg_bsl(xorriso, argc, &argv, 0); 
  262  if(ret <= 0)
  263    {ret= 5; goto emergency_exit;}
  264  i= 1;
  265  ret= Xorriso_interpreter(xorriso, argc, argv, &i, 2);
  266  if(ret == 3)
  267    goto end_successfully;
  268  if(ret <= 0)
  269    {ret= 5; goto emergency_exit;}
  270 
  271  /* Enter dialog mode if it has been activated meanwhile */
  272  ret= Xorriso_dialog(xorriso, 0);
  273  if(ret <= 0)
  274    {ret= 6; goto emergency_exit;}
  275 
  276 end_successfully:; /* normal shutdown, including eventual -commit */
  277  Xorriso_stop_msg_watcher(xorriso, 1);
  278  Xorriso_process_msg_queues(xorriso, 0);
  279  if(Xorriso_change_is_pending(xorriso, 1))
  280    Xorriso_option_end(xorriso, 2);
  281  Xorriso_process_msg_queues(xorriso, 0);
  282  ret= Xorriso_make_return_value(xorriso, 0);
  283  Xorriso_process_errfile(xorriso, 0, "xorriso end", 0, 1);
  284  Xorriso_destroy(&xorriso, 1);
  285  if(orig_argv != argv && orig_argv != NULL) {
  286    for(i= 0; i < argc; i++)
  287      if(argv[i] != NULL)
  288        free(argv[i]);
  289    free(argv);
  290  }
  291  exit(ret);
  292 
  293 emergency_exit:;
  294  if(xorriso != NULL) { /* minimal shutdown */
  295    Xorriso_process_msg_queues(xorriso, 0);
  296    Xorriso_destroy(&xorriso, 1);
  297  }
  298  exit(ret);
  299 }
  300 
  301