aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMichael Reed <Pyrohh@users.noreply.github.com>2015-05-30 18:14:48 -0400
committerMichael Reed <Pyrohh@users.noreply.github.com>2015-05-30 18:14:48 -0400
commit8c84c124edf125ea7151488ccf8989a54e24da43 (patch)
tree8ab2ed80eca912d4656049bc0da00d7aa2da7e0c /src
parent3dd3778f098ab33ced3ab3611ecaa600938cf82b (diff)
parentb113754de8815fd59e1b42f8eae239b0a31c43ee (diff)
downloadrneovim-8c84c124edf125ea7151488ccf8989a54e24da43.tar.gz
rneovim-8c84c124edf125ea7151488ccf8989a54e24da43.tar.bz2
rneovim-8c84c124edf125ea7151488ccf8989a54e24da43.zip
Merge pull request #2767 from Pyrohh/mainerr-simplify
[RDY] main.c: Some refactoring / cleanups Reviewed-by: Scott Prager <splinterofchaos@gmail.com> Reviewed-by: oni-link <knil.ino@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/nvim/ex_cmds2.c2
-rw-r--r--src/nvim/main.c68
-rw-r--r--src/nvim/mbyte.c2
3 files changed, 37 insertions, 35 deletions
diff --git a/src/nvim/ex_cmds2.c b/src/nvim/ex_cmds2.c
index 5c1f487d5e..e7029b8762 100644
--- a/src/nvim/ex_cmds2.c
+++ b/src/nvim/ex_cmds2.c
@@ -2987,7 +2987,7 @@ void ex_checktime(exarg_T *eap)
no_check_timestamps = save_no_check_timestamps;
}
-#if defined(HAVE_LOCALE_H) || defined(X_LOCALE)
+#if defined(HAVE_LOCALE_H)
# define HAVE_GET_LOCALE_VAL
static char *get_locale_val(int what)
diff --git a/src/nvim/main.c b/src/nvim/main.c
index ddc39caa6f..e1bb2d0b66 100644
--- a/src/nvim/main.c
+++ b/src/nvim/main.c
@@ -122,19 +122,15 @@ typedef struct {
# include "main.c.generated.h"
#endif
+static char *argv0;
+
// Error messages
-static const char *main_errors[] = {
- N_("Unknown option argument"),
-#define ME_UNKNOWN_OPTION 0
- N_("Too many edit arguments"),
-#define ME_TOO_MANY_ARGS 1
- N_("Argument missing after"),
-#define ME_ARG_MISSING 2
- N_("Garbage after option argument"),
-#define ME_GARBAGE 3
- N_("Too many \"+command\", \"-c command\" or \"--cmd command\" arguments")
-#define ME_EXTRA_CMD 4
-};
+static const char *err_arg_missing = N_("Argument missing after");
+static const char *err_opt_garbage = N_("Garbage after option argument");
+static const char *err_opt_unknown = N_("Unknown option argument");
+static const char *err_too_many_args = N_("Too many edit arguments");
+static const char *err_extra_cmd =
+ N_("Too many \"+command\", \"-c command\" or \"--cmd command\" arguments");
/// Performs early initialization.
@@ -150,7 +146,7 @@ void early_init(void)
// Init the table of Normal mode commands.
init_normal_cmds();
-#if defined(HAVE_LOCALE_H) || defined(X_LOCALE)
+#if defined(HAVE_LOCALE_H)
// Setup to use the current locale (for ctype() and many other things).
// NOTE: Translated messages with encodings other than latin1 will not
// work until set_init_1() has been called!
@@ -186,6 +182,8 @@ int nvim_main(int argc, char **argv)
int main(int argc, char **argv)
#endif
{
+ argv0 = (char *)path_tail((char_u *)argv[0]);
+
char_u *fname = NULL; /* file name from command line */
mparm_T params; /* various parameters passed between
* main() and other functions. */
@@ -811,7 +809,7 @@ static int get_number_arg(const char *p, int *idx, int def)
return def;
}
-#if defined(HAVE_LOCALE_H) || defined(X_LOCALE)
+#if defined(HAVE_LOCALE_H)
/*
* Setup to use the current locale (for ctype() and many other things).
*/
@@ -865,7 +863,7 @@ static void command_line_scan(mparm_T *parmp)
*/
if (argv[0][0] == '+' && !had_minmin) {
if (parmp->n_commands >= MAX_ARG_CMDS)
- mainerr(ME_EXTRA_CMD, NULL);
+ mainerr(err_extra_cmd, NULL);
argv_idx = -1; /* skip to next argument */
if (argv[0][1] == NUL)
parmp->commands[parmp->n_commands++] = "$";
@@ -885,7 +883,7 @@ static void command_line_scan(mparm_T *parmp)
silent_mode = TRUE;
} else {
if (parmp->edit_type != EDIT_NONE) {
- mainerr(ME_TOO_MANY_ARGS, argv[0]);
+ mainerr(err_too_many_args, argv[0]);
}
parmp->edit_type = EDIT_STDIN;
}
@@ -934,7 +932,7 @@ static void command_line_scan(mparm_T *parmp)
argv_idx += 11;
} else {
if (argv[0][argv_idx])
- mainerr(ME_UNKNOWN_OPTION, argv[0]);
+ mainerr(err_opt_unknown, argv[0]);
had_minmin = TRUE;
}
if (!want_argument)
@@ -1033,7 +1031,7 @@ static void command_line_scan(mparm_T *parmp)
case 'q': /* "-q" QuickFix mode */
if (parmp->edit_type != EDIT_NONE)
- mainerr(ME_TOO_MANY_ARGS, argv[0]);
+ mainerr(err_too_many_args, argv[0]);
parmp->edit_type = EDIT_QF;
if (argv[0][argv_idx]) { /* "-q{errorfile}" */
parmp->use_ef = (char_u *)argv[0] + argv_idx;
@@ -1062,7 +1060,7 @@ static void command_line_scan(mparm_T *parmp)
case 't': /* "-t {tag}" or "-t{tag}" jump to tag */
if (parmp->edit_type != EDIT_NONE)
- mainerr(ME_TOO_MANY_ARGS, argv[0]);
+ mainerr(err_too_many_args, argv[0]);
parmp->edit_type = EDIT_TAG;
if (argv[0][argv_idx]) { /* "-t{tag}" */
parmp->tagname = (char_u *)argv[0] + argv_idx;
@@ -1111,7 +1109,7 @@ static void command_line_scan(mparm_T *parmp)
command */
if (argv[0][argv_idx] != NUL) {
if (parmp->n_commands >= MAX_ARG_CMDS)
- mainerr(ME_EXTRA_CMD, NULL);
+ mainerr(err_extra_cmd, NULL);
parmp->commands[parmp->n_commands++] = argv[0]
+ argv_idx;
argv_idx = -1;
@@ -1127,7 +1125,7 @@ static void command_line_scan(mparm_T *parmp)
break;
default:
- mainerr(ME_UNKNOWN_OPTION, argv[0]);
+ mainerr(err_opt_unknown, argv[0]);
}
/*
@@ -1138,11 +1136,11 @@ static void command_line_scan(mparm_T *parmp)
* Check for garbage immediately after the option letter.
*/
if (argv[0][argv_idx] != NUL)
- mainerr(ME_GARBAGE, argv[0]);
+ mainerr(err_opt_garbage, argv[0]);
--argc;
if (argc < 1 && c != 'S') /* -S has an optional argument */
- mainerr(ME_ARG_MISSING, argv[0]);
+ mainerr(err_arg_missing, argv[0]);
++argv;
argv_idx = -1;
@@ -1150,7 +1148,7 @@ static void command_line_scan(mparm_T *parmp)
case 'c': /* "-c {command}" execute command */
case 'S': /* "-S {file}" execute Vim script */
if (parmp->n_commands >= MAX_ARG_CMDS)
- mainerr(ME_EXTRA_CMD, NULL);
+ mainerr(err_extra_cmd, NULL);
if (c == 'S') {
char *a;
@@ -1180,7 +1178,7 @@ static void command_line_scan(mparm_T *parmp)
if (argv[-1][2] == 'c') {
/* "--cmd {command}" execute command */
if (parmp->n_pre_commands >= MAX_ARG_CMDS)
- mainerr(ME_EXTRA_CMD, NULL);
+ mainerr(err_extra_cmd, NULL);
parmp->pre_commands[parmp->n_pre_commands++] = argv[0];
}
/* "--startuptime <file>" already handled */
@@ -1257,7 +1255,7 @@ scripterror:
/* Check for only one type of editing. */
if (parmp->edit_type != EDIT_NONE && parmp->edit_type != EDIT_FILE)
- mainerr(ME_TOO_MANY_ARGS, argv[0]);
+ mainerr(err_too_many_args, argv[0]);
parmp->edit_type = EDIT_FILE;
/* Add the file to the global argument list. */
@@ -1926,22 +1924,26 @@ static bool file_owned(const char *fname)
#endif
/// Prints the following then exits:
-/// - An error message main_errors[n]
-/// - A string str if not null
+/// - An error message `errstr`
+/// - A string `str` if not null
///
-/// @param n error number represented by an ME_* macro
-/// @param str string to append to the primary error message, or NULL
-static void mainerr(int n, const char *str)
+/// @param errstr string containing an error message
+/// @param str string to append to the primary error message, or NULL
+static void mainerr(const char *errstr, const char *str)
{
signal_stop(); // kill us with CTRL-C here, if you like
- mch_errmsg(_(main_errors[n]));
+ mch_errmsg(argv0);
+ mch_errmsg(": ");
+ mch_errmsg(_(errstr));
if (str != NULL) {
mch_errmsg(": \"");
mch_errmsg(str);
mch_errmsg("\"");
}
- mch_errmsg(_("\nMore info with \"nvim -h\"\n"));
+ mch_errmsg(_("\nMore info with \""));
+ mch_errmsg(argv0);
+ mch_errmsg(" -h\"\n");
mch_exit(1);
}
diff --git a/src/nvim/mbyte.c b/src/nvim/mbyte.c
index 368ae8e773..c8ebcefe0e 100644
--- a/src/nvim/mbyte.c
+++ b/src/nvim/mbyte.c
@@ -3406,7 +3406,7 @@ char_u * enc_locale(void)
if (!(s = nl_langinfo(CODESET)) || *s == NUL)
# endif
{
-# if defined(HAVE_LOCALE_H) || defined(X_LOCALE)
+# if defined(HAVE_LOCALE_H)
if (!(s = setlocale(LC_CTYPE, NULL)) || *s == NUL)
# endif
{