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

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