root/src/args.c

/* [previous][next][first][last][top][bottom][index][help]  */

DEFINITIONS

This source file includes following definitions.
  1. mc_args_clean_temp_help_strings
  2. mc_args_new_color_group
  3. mc_args_add_usage_info
  4. mc_args_add_extended_info_to_help
  5. mc_args__convert_help_to_syscharset
  6. parse_mc_e_argument
  7. parse_mc_v_argument
  8. mcedit_arg_vpath_new
  9. mcedit_arg_new
  10. parse_mcedit_arguments
  11. mc_setup_run_mode
  12. mc_args_parse
  13. mc_args_show_info
  14. mc_setup_by_args
  15. mcedit_arg_free

   1 /*
   2    Handle command line arguments.
   3 
   4    Copyright (C) 2009-2021
   5    Free Software Foundation, Inc.
   6 
   7    Written by:
   8    Slava Zanko <slavazanko@gmail.com>, 2009.
   9    Andrew Borodin <aborodin@vmail.ru>, 2011, 2012.
  10 
  11    This file is part of the Midnight Commander.
  12 
  13    The Midnight Commander is free software: you can redistribute it
  14    and/or modify it under the terms of the GNU General Public License as
  15    published by the Free Software Foundation, either version 3 of the License,
  16    or (at your option) any later version.
  17 
  18    The Midnight Commander is distributed in the hope that it will be useful,
  19    but WITHOUT ANY WARRANTY; without even the implied warranty of
  20    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  21    GNU General Public License for more details.
  22 
  23    You should have received a copy of the GNU General Public License
  24    along with this program.  If not, see <http://www.gnu.org/licenses/>.
  25  */
  26 
  27 #include <config.h>
  28 #include <stdlib.h>
  29 #include <stdio.h>
  30 
  31 #include "lib/global.h"
  32 #include "lib/tty/tty.h"
  33 #include "lib/strutil.h"
  34 #include "lib/vfs/vfs.h"
  35 #include "lib/util.h"           /* x_basename() */
  36 
  37 #include "src/textconf.h"
  38 
  39 #include "src/args.h"
  40 
  41 /*** external variables **************************************************************************/
  42 
  43 /*** global variables ****************************************************************************/
  44 
  45 /* If true, assume we are running on an xterm terminal */
  46 gboolean mc_args__force_xterm = FALSE;
  47 
  48 gboolean mc_args__nomouse = FALSE;
  49 
  50 /* Force colors, only used by Slang */
  51 gboolean mc_args__force_colors = FALSE;
  52 
  53 /* Don't load keymap from file and use default one */
  54 gboolean mc_args__nokeymap = FALSE;
  55 
  56 char *mc_args__last_wd_file = NULL;
  57 
  58 /* when enabled NETCODE, use folowing file as logfile */
  59 char *mc_args__netfs_logfile = NULL;
  60 
  61 /* keymap file */
  62 char *mc_args__keymap_file = NULL;
  63 
  64 void *mc_run_param0 = NULL;
  65 char *mc_run_param1 = NULL;
  66 
  67 /*** file scope macro definitions ****************************************************************/
  68 
  69 /*** file scope type declarations ****************************************************************/
  70 
  71 /*** file scope variables ************************************************************************/
  72 
  73 /* If true, show version info and exit */
  74 static gboolean mc_args__show_version = FALSE;
  75 
  76 /* forward declarations */
  77 static gboolean parse_mc_e_argument (const gchar * option_name, const gchar * value,
  78                                      gpointer data, GError ** mcerror);
  79 static gboolean parse_mc_v_argument (const gchar * option_name, const gchar * value,
  80                                      gpointer data, GError ** mcerror);
  81 
  82 static GOptionContext *context;
  83 
  84 #ifdef ENABLE_SUBSHELL
  85 static gboolean mc_args__nouse_subshell = FALSE;
  86 #endif /* ENABLE_SUBSHELL */
  87 static gboolean mc_args__show_datadirs = FALSE;
  88 static gboolean mc_args__show_datadirs_extended = FALSE;
  89 #ifdef ENABLE_CONFIGURE_ARGS
  90 static gboolean mc_args__show_configure_opts = FALSE;
  91 #endif
  92 
  93 static GOptionGroup *main_group;
  94 
  95 static const GOptionEntry argument_main_table[] = {
  96     /* *INDENT-OFF* */
  97     /* generic options */
  98     {
  99      "version", 'V', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE,
 100      &mc_args__show_version,
 101      N_("Displays the current version"),
 102      NULL
 103     },
 104 
 105     /* options for wrappers */
 106     {
 107      "datadir", 'f', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE,
 108      &mc_args__show_datadirs,
 109      N_("Print data directory"),
 110      NULL
 111     },
 112 
 113     /* show extended information about used data directories */
 114     {
 115      "datadir-info", 'F', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE,
 116      &mc_args__show_datadirs_extended,
 117      N_("Print extended info about used data directories"),
 118      NULL
 119     },
 120 
 121 #ifdef ENABLE_CONFIGURE_ARGS
 122     /* show configure options */
 123     {
 124      "configure-options", '\0', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE,
 125      &mc_args__show_configure_opts,
 126      N_("Print configure options"),
 127      NULL
 128     },
 129 #endif
 130 
 131     {
 132      "printwd", 'P', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_STRING,
 133      &mc_args__last_wd_file,
 134      N_("Print last working directory to specified file"),
 135      N_("<file>")
 136     },
 137 
 138 #ifdef ENABLE_SUBSHELL
 139     {
 140      "subshell", 'U', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE,
 141      &mc_global.tty.use_subshell,
 142      N_("Enables subshell support (default)"),
 143      NULL
 144     },
 145 
 146     {
 147      "nosubshell", 'u', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE,
 148      &mc_args__nouse_subshell,
 149      N_("Disables subshell support"),
 150      NULL
 151     },
 152 #endif
 153 
 154     /* debug options */
 155 #ifdef ENABLE_VFS_FTP
 156     {
 157      "ftplog", 'l', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_STRING,
 158      &mc_args__netfs_logfile,
 159      N_("Log ftp dialog to specified file"),
 160      N_("<file>")
 161     },
 162 #endif /* ENABLE_VFS_FTP */
 163 
 164     {
 165      /* handle arguments manually */
 166      "view", 'v', G_OPTION_FLAG_IN_MAIN | G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK,
 167      (gpointer) parse_mc_v_argument,
 168      N_("Launches the file viewer on a file"),
 169      N_("<file>")
 170     },
 171 
 172     {
 173      /* handle arguments manually */
 174      "edit", 'e', G_OPTION_FLAG_IN_MAIN | G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK,
 175      (gpointer) parse_mc_e_argument,
 176      N_("Edit files"),
 177      N_("<file> ...")
 178     },
 179 
 180     G_OPTION_ENTRY_NULL
 181     /* *INDENT-ON* */
 182 };
 183 
 184 static GOptionGroup *terminal_group;
 185 #define ARGS_TERM_OPTIONS 0
 186 static const GOptionEntry argument_terminal_table[] = {
 187     /* *INDENT-OFF* */
 188     /* terminal options */
 189     {
 190      "xterm", 'x', ARGS_TERM_OPTIONS, G_OPTION_ARG_NONE,
 191      &mc_args__force_xterm,
 192      N_("Forces xterm features"),
 193      NULL
 194     },
 195 
 196     {
 197      "no-x11", 'X', ARGS_TERM_OPTIONS, G_OPTION_ARG_NONE,
 198      &mc_global.tty.disable_x11,
 199      N_("Disable X11 support"),
 200      NULL
 201     },
 202 
 203     {
 204      "oldmouse", 'g', ARGS_TERM_OPTIONS, G_OPTION_ARG_NONE,
 205      &mc_global.tty.old_mouse,
 206      N_("Tries to use an old highlight mouse tracking"),
 207      NULL
 208     },
 209 
 210     {
 211      "nomouse", 'd', ARGS_TERM_OPTIONS, G_OPTION_ARG_NONE,
 212      &mc_args__nomouse,
 213      N_("Disable mouse support in text version"),
 214      NULL
 215     },
 216 
 217 #ifdef HAVE_SLANG
 218     {
 219      "termcap", 't', ARGS_TERM_OPTIONS, G_OPTION_ARG_NONE,
 220      &SLtt_Try_Termcap,
 221      N_("Tries to use termcap instead of terminfo"),
 222      NULL
 223     },
 224 #endif
 225 
 226     {
 227      "slow", 's', ARGS_TERM_OPTIONS, G_OPTION_ARG_NONE,
 228      &mc_global.tty.slow_terminal,
 229      N_("To run on slow terminals"),
 230      NULL
 231     },
 232 
 233     {
 234      "stickchars", 'a', ARGS_TERM_OPTIONS, G_OPTION_ARG_NONE,
 235      &mc_global.tty.ugly_line_drawing,
 236      N_("Use stickchars to draw"),
 237      NULL
 238     },
 239 
 240 #ifdef HAVE_SLANG
 241     {
 242      "resetsoft", 'k', ARGS_TERM_OPTIONS, G_OPTION_ARG_NONE,
 243      &reset_hp_softkeys,
 244      N_("Resets soft keys on HP terminals"),
 245      NULL
 246     },
 247 #endif
 248 
 249     {
 250      "keymap", 'K', ARGS_TERM_OPTIONS, G_OPTION_ARG_STRING,
 251      &mc_args__keymap_file,
 252      N_("Load definitions of key bindings from specified file"),
 253      N_("<file>")
 254     },
 255 
 256     {
 257      "nokeymap", '\0', ARGS_TERM_OPTIONS, G_OPTION_ARG_NONE,
 258      &mc_args__nokeymap,
 259      N_("Don't load definitions of key bindings from file, use defaults"),
 260      NULL
 261     },
 262 
 263     G_OPTION_ENTRY_NULL
 264     /* *INDENT-ON* */
 265 };
 266 
 267 #undef ARGS_TERM_OPTIONS
 268 
 269 static GOptionGroup *color_group;
 270 #define ARGS_COLOR_OPTIONS 0
 271 /* #define ARGS_COLOR_OPTIONS G_OPTION_FLAG_IN_MAIN */
 272 static const GOptionEntry argument_color_table[] = {
 273     /* *INDENT-OFF* */
 274     /* color options */
 275     {
 276      "nocolor", 'b', ARGS_COLOR_OPTIONS, G_OPTION_ARG_NONE,
 277      &mc_global.tty.disable_colors,
 278      N_("Requests to run in black and white"),
 279      NULL
 280     },
 281 
 282     {
 283      "color", 'c', ARGS_COLOR_OPTIONS, G_OPTION_ARG_NONE,
 284      &mc_args__force_colors,
 285      N_("Request to run in color mode"),
 286      NULL
 287     },
 288 
 289     {
 290      "colors", 'C', ARGS_COLOR_OPTIONS, G_OPTION_ARG_STRING,
 291      &mc_global.tty.command_line_colors,
 292      N_("Specifies a color configuration"),
 293      N_("<string>")
 294     },
 295 
 296     {
 297      "skin", 'S', ARGS_COLOR_OPTIONS, G_OPTION_ARG_STRING,
 298      &mc_global.tty.skin,
 299      N_("Show mc with specified skin"),
 300      N_("<string>")
 301     },
 302 
 303     G_OPTION_ENTRY_NULL
 304     /* *INDENT-ON* */
 305 };
 306 
 307 #undef ARGS_COLOR_OPTIONS
 308 
 309 static gchar *mc_args__loc__colors_string = NULL;
 310 static gchar *mc_args__loc__footer_string = NULL;
 311 static gchar *mc_args__loc__header_string = NULL;
 312 static gchar *mc_args__loc__usage_string = NULL;
 313 
 314 /* --------------------------------------------------------------------------------------------- */
 315 /*** file scope functions ************************************************************************/
 316 /* --------------------------------------------------------------------------------------------- */
 317 
 318 static void
 319 mc_args_clean_temp_help_strings (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 320 {
 321     MC_PTR_FREE (mc_args__loc__colors_string);
 322     MC_PTR_FREE (mc_args__loc__footer_string);
 323     MC_PTR_FREE (mc_args__loc__header_string);
 324     MC_PTR_FREE (mc_args__loc__usage_string);
 325 }
 326 
 327 /* --------------------------------------------------------------------------------------------- */
 328 
 329 static GOptionGroup *
 330 mc_args_new_color_group (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 331 {
 332     /* *INDENT-OFF* */
 333     /* FIXME: to preserve translations, lines should be split. */
 334     mc_args__loc__colors_string = g_strdup_printf ("%s\n%s",
 335                                                    /* TRANSLATORS: don't translate keywords */
 336                                                    _("--colors KEYWORD={FORE},{BACK},{ATTR}:KEYWORD2=...\n\n"
 337                                                      "{FORE}, {BACK} and {ATTR} can be omitted, and the default will be used\n"
 338                                                      "\n Keywords:\n"
 339                                                      "   Global:       errors, disabled, reverse, gauge, header\n"
 340                                                      "                 input, inputmark, inputunchanged, commandlinemark\n"
 341                                                      "                 bbarhotkey, bbarbutton, statusbar\n"
 342                                                      "   File display: normal, selected, marked, markselect\n"
 343                                                      "   Dialog boxes: dnormal, dfocus, dhotnormal, dhotfocus, errdhotnormal,\n"
 344                                                      "                 errdhotfocus\n"
 345                                                      "   Menus:        menunormal, menuhot, menusel, menuhotsel, menuinactive\n"
 346                                                      "   Popup menus:  pmenunormal, pmenusel, pmenutitle\n"
 347                                                      "   Editor:       editnormal, editbold, editmarked, editwhitespace,\n"
 348                                                      "                 editlinestate, editbg, editframe, editframeactive\n"
 349                                                      "                 editframedrag\n"
 350                                                      "   Viewer:       viewnormal,viewbold, viewunderline, viewselected\n"
 351                                                      "   Help:         helpnormal, helpitalic, helpbold, helplink, helpslink\n"),
 352                                                    /* TRANSLATORS: don't translate color names and attributes */
 353                                                    _("Standard Colors:\n"
 354                                                     "   black, gray, red, brightred, green, brightgreen, brown,\n"
 355                                                     "   yellow, blue, brightblue, magenta, brightmagenta, cyan,\n"
 356                                                     "   brightcyan, lightgray and white\n\n"
 357                                                     "Extended colors, when 256 colors are available:\n"
 358                                                     "   color16 to color255, or rgb000 to rgb555 and gray0 to gray23\n\n"
 359                                                     "Attributes:\n"
 360                                                     "   bold, italic, underline, reverse, blink; append more with '+'\n")
 361                                                     );
 362     /* *INDENT-ON* */
 363 
 364     return g_option_group_new ("color", mc_args__loc__colors_string,
 365                                _("Color options"), NULL, NULL);
 366 
 367 }
 368 
 369 /* --------------------------------------------------------------------------------------------- */
 370 
 371 static gchar *
 372 mc_args_add_usage_info (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 373 {
 374     gchar *s;
 375 
 376     switch (mc_global.mc_run_mode)
 377     {
 378     case MC_RUN_EDITOR:
 379         s = g_strdup_printf ("%s\n", _("[+lineno] file1[:lineno] [file2[:lineno]...]"));
 380         break;
 381     case MC_RUN_VIEWER:
 382         s = g_strdup_printf ("%s\n", _("file"));
 383         break;
 384 #ifdef USE_DIFF_VIEW
 385     case MC_RUN_DIFFVIEWER:
 386         s = g_strdup_printf ("%s\n", _("file1 file2"));
 387         break;
 388 #endif /* USE_DIFF_VIEW */
 389     case MC_RUN_FULL:
 390     default:
 391         s = g_strdup_printf ("%s\n", _("[this_dir] [other_panel_dir]"));
 392     }
 393 
 394     mc_args__loc__usage_string = s;
 395 
 396     return mc_args__loc__usage_string;
 397 }
 398 
 399 /* --------------------------------------------------------------------------------------------- */
 400 
 401 static void
 402 mc_args_add_extended_info_to_help (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 403 {
 404     mc_args__loc__footer_string = g_strdup_printf ("%s",
 405                                                    _
 406                                                    ("\n"
 407                                                     "Please send any bug reports (including the output of 'mc -V')\n"
 408                                                     "as tickets at www.midnight-commander.org\n"));
 409     mc_args__loc__header_string =
 410         g_strdup_printf (_("GNU Midnight Commander %s\n"), mc_global.mc_version);
 411 
 412     g_option_context_set_description (context, mc_args__loc__footer_string);
 413     g_option_context_set_summary (context, mc_args__loc__header_string);
 414 }
 415 
 416 /* --------------------------------------------------------------------------------------------- */
 417 
 418 static gchar *
 419 mc_args__convert_help_to_syscharset (const gchar * charset, const gchar * error_message_str,
     /* [previous][next][first][last][top][bottom][index][help]  */
 420                                      const gchar * help_str)
 421 {
 422     GString *buffer;
 423     GIConv conv;
 424     gchar *full_help_str;
 425 
 426     buffer = g_string_new ("");
 427     conv = g_iconv_open (charset, "UTF-8");
 428     full_help_str = g_strdup_printf ("%s\n\n%s\n", error_message_str, help_str);
 429 
 430     str_convert (conv, full_help_str, buffer);
 431 
 432     g_free (full_help_str);
 433     g_iconv_close (conv);
 434 
 435     return g_string_free (buffer, FALSE);
 436 }
 437 
 438 /* --------------------------------------------------------------------------------------------- */
 439 
 440 static gboolean
 441 parse_mc_e_argument (const gchar * option_name, const gchar * value, gpointer data,
     /* [previous][next][first][last][top][bottom][index][help]  */
 442                      GError ** mcerror)
 443 {
 444     (void) option_name;
 445     (void) value;
 446     (void) data;
 447 
 448     mc_return_val_if_error (mcerror, FALSE);
 449 
 450     mc_global.mc_run_mode = MC_RUN_EDITOR;
 451 
 452     return TRUE;
 453 }
 454 
 455 /* --------------------------------------------------------------------------------------------- */
 456 
 457 static gboolean
 458 parse_mc_v_argument (const gchar * option_name, const gchar * value, gpointer data,
     /* [previous][next][first][last][top][bottom][index][help]  */
 459                      GError ** mcerror)
 460 {
 461     (void) option_name;
 462     (void) value;
 463     (void) data;
 464 
 465     mc_return_val_if_error (mcerror, FALSE);
 466 
 467     mc_global.mc_run_mode = MC_RUN_VIEWER;
 468 
 469     return TRUE;
 470 }
 471 
 472 /* --------------------------------------------------------------------------------------------- */
 473 /**
 474  * Create mcedit_arg_t object from vfs_path_t object and the line number.
 475  *
 476  * @param file_vpath  file path object
 477  * @param line_number line number. If value is 0, try to restore saved position.
 478  * @return mcedit_arg_t object
 479  */
 480 
 481 static mcedit_arg_t *
 482 mcedit_arg_vpath_new (vfs_path_t * file_vpath, long line_number)
     /* [previous][next][first][last][top][bottom][index][help]  */
 483 {
 484     mcedit_arg_t *arg;
 485 
 486     arg = g_new (mcedit_arg_t, 1);
 487     arg->file_vpath = file_vpath;
 488     arg->line_number = line_number;
 489 
 490     return arg;
 491 }
 492 
 493 /* --------------------------------------------------------------------------------------------- */
 494 /**
 495  * Create mcedit_arg_t object from file name and the line number.
 496  *
 497  * @param file_name   file name
 498  * @param line_number line number. If value is 0, try to restore saved position.
 499  * @return mcedit_arg_t object
 500  */
 501 
 502 static mcedit_arg_t *
 503 mcedit_arg_new (const char *file_name, long line_number)
     /* [previous][next][first][last][top][bottom][index][help]  */
 504 {
 505     return mcedit_arg_vpath_new (vfs_path_from_str (file_name), line_number);
 506 }
 507 
 508 /* --------------------------------------------------------------------------------------------- */
 509 /**
 510  * Get list of filenames (and line numbers) from command line, when mc called as editor
 511  *
 512  * @param argc count of all arguments
 513  * @param argv array of strings, contains arguments
 514  * @return list of mcedit_arg_t objects
 515  */
 516 
 517 static GList *
 518 parse_mcedit_arguments (int argc, char **argv)
     /* [previous][next][first][last][top][bottom][index][help]  */
 519 {
 520     GList *flist = NULL;
 521     int i;
 522     long first_line_number = -1;
 523 
 524     for (i = 0; i < argc; i++)
 525     {
 526         char *tmp;
 527         char *end, *p;
 528         mcedit_arg_t *arg;
 529 
 530         tmp = argv[i];
 531 
 532         /*
 533          * First, try to get line number as +lineno.
 534          */
 535         if (*tmp == '+')
 536         {
 537             long lineno;
 538             char *error;
 539 
 540             lineno = strtol (tmp + 1, &error, 10);
 541 
 542             if (*error == '\0')
 543             {
 544                 /* this is line number */
 545                 first_line_number = lineno;
 546                 continue;
 547             }
 548             /* this is file name */
 549         }
 550 
 551         /*
 552          * Check for filename:lineno, followed by an optional colon.
 553          * This format is used by many programs (especially compilers)
 554          * in error messages and warnings. It is supported so that
 555          * users can quickly copy and paste file locations.
 556          */
 557         end = tmp + strlen (tmp);
 558         p = end;
 559 
 560         if (p > tmp && p[-1] == ':')
 561             p--;
 562         while (p > tmp && g_ascii_isdigit ((gchar) p[-1]))
 563             p--;
 564 
 565         if (tmp < p && p < end && p[-1] == ':')
 566         {
 567             char *fname;
 568             vfs_path_t *tmp_vpath, *fname_vpath;
 569             struct stat st;
 570 
 571             fname = g_strndup (tmp, p - 1 - tmp);
 572             tmp_vpath = vfs_path_from_str (tmp);
 573             fname_vpath = vfs_path_from_str (fname);
 574 
 575             /*
 576              * Check that the file before the colon actually exists.
 577              * If it doesn't exist, create new file.
 578              */
 579             if (mc_stat (tmp_vpath, &st) == -1 && mc_stat (fname_vpath, &st) != -1)
 580             {
 581                 arg = mcedit_arg_vpath_new (fname_vpath, atoi (p));
 582                 vfs_path_free (tmp_vpath, TRUE);
 583             }
 584             else
 585             {
 586                 arg = mcedit_arg_vpath_new (tmp_vpath, 0);
 587                 vfs_path_free (fname_vpath, TRUE);
 588             }
 589 
 590             g_free (fname);
 591         }
 592         else
 593             arg = mcedit_arg_new (tmp, 0);
 594 
 595         flist = g_list_prepend (flist, arg);
 596     }
 597 
 598     if (flist == NULL)
 599         flist = g_list_prepend (flist, mcedit_arg_new (NULL, 0));
 600     else if (first_line_number != -1)
 601     {
 602         /* overwrite line number for first file */
 603         GList *l;
 604 
 605         l = g_list_last (flist);
 606         ((mcedit_arg_t *) l->data)->line_number = first_line_number;
 607     }
 608 
 609     return flist;
 610 }
 611 
 612 /* --------------------------------------------------------------------------------------------- */
 613 /*** public functions ****************************************************************************/
 614 /* --------------------------------------------------------------------------------------------- */
 615 
 616 void
 617 mc_setup_run_mode (char **argv)
     /* [previous][next][first][last][top][bottom][index][help]  */
 618 {
 619     const char *base;
 620 
 621     base = x_basename (argv[0]);
 622 
 623     if (strncmp (base, "mce", 3) == 0 || strcmp (base, "vi") == 0)
 624     {
 625         /* mce* or vi is link to mc */
 626         mc_global.mc_run_mode = MC_RUN_EDITOR;
 627     }
 628     else if (strncmp (base, "mcv", 3) == 0 || strcmp (base, "view") == 0)
 629     {
 630         /* mcv* or view is link to mc */
 631         mc_global.mc_run_mode = MC_RUN_VIEWER;
 632     }
 633 #ifdef USE_DIFF_VIEW
 634     else if (strncmp (base, "mcd", 3) == 0 || strcmp (base, "diff") == 0)
 635     {
 636         /* mcd* or diff is link to mc */
 637         mc_global.mc_run_mode = MC_RUN_DIFFVIEWER;
 638     }
 639 #endif /* USE_DIFF_VIEW */
 640 }
 641 
 642 gboolean
 643 mc_args_parse (int *argc, char ***argv, const char *translation_domain, GError ** mcerror)
     /* [previous][next][first][last][top][bottom][index][help]  */
 644 {
 645     const gchar *_system_codepage;
 646     gboolean ok = TRUE;
 647 
 648     mc_return_val_if_error (mcerror, FALSE);
 649 
 650     _system_codepage = str_detect_termencoding ();
 651 
 652 #ifdef ENABLE_NLS
 653     if (!str_isutf8 (_system_codepage))
 654         bind_textdomain_codeset ("mc", "UTF-8");
 655 #endif
 656 
 657     context = g_option_context_new (mc_args_add_usage_info ());
 658 
 659     g_option_context_set_ignore_unknown_options (context, FALSE);
 660 
 661     mc_args_add_extended_info_to_help ();
 662 
 663     main_group = g_option_group_new ("main", _("Main options"), _("Main options"), NULL, NULL);
 664 
 665     g_option_group_add_entries (main_group, argument_main_table);
 666     g_option_context_set_main_group (context, main_group);
 667     g_option_group_set_translation_domain (main_group, translation_domain);
 668 
 669     terminal_group = g_option_group_new ("terminal", _("Terminal options"),
 670                                          _("Terminal options"), NULL, NULL);
 671 
 672     g_option_group_add_entries (terminal_group, argument_terminal_table);
 673     g_option_context_add_group (context, terminal_group);
 674     g_option_group_set_translation_domain (terminal_group, translation_domain);
 675 
 676     color_group = mc_args_new_color_group ();
 677 
 678     g_option_group_add_entries (color_group, argument_color_table);
 679     g_option_context_add_group (context, color_group);
 680     g_option_group_set_translation_domain (color_group, translation_domain);
 681 
 682     if (!g_option_context_parse (context, argc, argv, mcerror))
 683     {
 684         if (*mcerror == NULL)
 685             mc_propagate_error (mcerror, 0, "%s\n", _("Arguments parse error!"));
 686         else
 687         {
 688             gchar *help_str;
 689 
 690             help_str = g_option_context_get_help (context, TRUE, NULL);
 691 
 692             if (str_isutf8 (_system_codepage))
 693                 mc_replace_error (mcerror, (*mcerror)->code, "%s\n\n%s\n", (*mcerror)->message,
 694                                   help_str);
 695             else
 696             {
 697                 gchar *full_help_str;
 698 
 699                 full_help_str =
 700                     mc_args__convert_help_to_syscharset (_system_codepage, (*mcerror)->message,
 701                                                          help_str);
 702                 mc_replace_error (mcerror, (*mcerror)->code, "%s", full_help_str);
 703                 g_free (full_help_str);
 704             }
 705             g_free (help_str);
 706         }
 707 
 708         ok = FALSE;
 709     }
 710 
 711     g_option_context_free (context);
 712     mc_args_clean_temp_help_strings ();
 713 
 714 #ifdef ENABLE_NLS
 715     if (!str_isutf8 (_system_codepage))
 716         bind_textdomain_codeset ("mc", _system_codepage);
 717 #endif
 718 
 719     return ok;
 720 }
 721 
 722 /* --------------------------------------------------------------------------------------------- */
 723 
 724 gboolean
 725 mc_args_show_info (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 726 {
 727     if (mc_args__show_version)
 728     {
 729         show_version ();
 730         return FALSE;
 731     }
 732 
 733     if (mc_args__show_datadirs)
 734     {
 735         printf ("%s (%s)\n", mc_global.sysconfig_dir, mc_global.share_data_dir);
 736         return FALSE;
 737     }
 738 
 739     if (mc_args__show_datadirs_extended)
 740     {
 741         show_datadirs_extended ();
 742         return FALSE;
 743     }
 744 
 745 #ifdef ENABLE_CONFIGURE_ARGS
 746     if (mc_args__show_configure_opts)
 747     {
 748         show_configure_options ();
 749         return FALSE;
 750     }
 751 #endif
 752 
 753     return TRUE;
 754 }
 755 
 756 /* --------------------------------------------------------------------------------------------- */
 757 
 758 gboolean
 759 mc_setup_by_args (int argc, char **argv, GError ** mcerror)
     /* [previous][next][first][last][top][bottom][index][help]  */
 760 {
 761     char *tmp;
 762 
 763     mc_return_val_if_error (mcerror, FALSE);
 764 
 765     if (mc_args__force_colors)
 766         mc_global.tty.disable_colors = FALSE;
 767 
 768 #ifdef ENABLE_SUBSHELL
 769     if (mc_args__nouse_subshell)
 770         mc_global.tty.use_subshell = FALSE;
 771 #endif /* ENABLE_SUBSHELL */
 772 
 773     if (mc_args__netfs_logfile != NULL)
 774     {
 775         vfs_path_t *vpath;
 776 #ifdef ENABLE_VFS_FTP
 777         vpath = vfs_path_from_str ("ftp://");
 778         mc_setctl (vpath, VFS_SETCTL_LOGFILE, (void *) mc_args__netfs_logfile);
 779         vfs_path_free (vpath, TRUE);
 780 #endif /* ENABLE_VFS_FTP */
 781         (void) vpath;
 782     }
 783 
 784     tmp = (argc > 0) ? argv[1] : NULL;
 785 
 786     switch (mc_global.mc_run_mode)
 787     {
 788     case MC_RUN_EDITOR:
 789         mc_run_param0 = parse_mcedit_arguments (argc - 1, &argv[1]);
 790         break;
 791 
 792     case MC_RUN_VIEWER:
 793         if (tmp == NULL)
 794         {
 795             mc_propagate_error (mcerror, 0, "%s\n", _("No arguments given to the viewer."));
 796             return FALSE;
 797         }
 798 
 799         mc_run_param0 = g_strdup (tmp);
 800         break;
 801 
 802 #ifdef USE_DIFF_VIEW
 803     case MC_RUN_DIFFVIEWER:
 804         if (argc < 3)
 805         {
 806             mc_propagate_error (mcerror, 0, "%s\n",
 807                                 _("Two files are required to envoke the diffviewer."));
 808             return FALSE;
 809         }
 810         MC_FALLTHROUGH;
 811 #endif /* USE_DIFF_VIEW */
 812 
 813     case MC_RUN_FULL:
 814     default:
 815         /* set the current dir and the other dir for filemanager,
 816            or two files for diff viewer */
 817         if (tmp != NULL)
 818         {
 819             mc_run_param0 = g_strdup (tmp);
 820             tmp = (argc > 1) ? argv[2] : NULL;
 821             if (tmp != NULL)
 822                 mc_run_param1 = g_strdup (tmp);
 823         }
 824         break;
 825     }
 826 
 827     return TRUE;
 828 }
 829 
 830 /* --------------------------------------------------------------------------------------------- */
 831 /**
 832  * Free the mcedit_arg_t object.
 833  *
 834  * @param arg mcedit_arg_t object
 835  */
 836 
 837 void
 838 mcedit_arg_free (mcedit_arg_t * arg)
     /* [previous][next][first][last][top][bottom][index][help]  */
 839 {
 840     vfs_path_free (arg->file_vpath, TRUE);
 841     g_free (arg);
 842 }
 843 
 844 /* --------------------------------------------------------------------------------------------- */

/* [previous][next][first][last][top][bottom][index][help]  */