blob: c96fb33b4c3055531dfb68db5f2e8d830db023ab [file] [log] [blame]
Bram Moolenaar46acad72023-06-11 19:04:18 +01001/* vi:set ts=8 sts=4 sw=4 noet:
2 *
3 * VIM - Vi IMproved by Bram Moolenaar
4 *
5 * Do ":help uganda" in Vim to read copying and usage conditions.
6 * Do ":help credits" in Vim to see a list of people who contributed.
7 * See README.txt for an overview of the Vim source code.
8 */
9
10#define EXTERN
11#include "vim.h"
12
13#ifdef __CYGWIN__
14# include <cygwin/version.h>
15# include <sys/cygwin.h> // for cygwin_conv_to_posix_path() and/or
16 // cygwin_conv_path()
17# include <limits.h>
18#endif
19
20#if defined(MSWIN) && (!defined(FEAT_GUI_MSWIN) || defined(VIMDLL))
21# include "iscygpty.h"
22#endif
23
24// Values for edit_type.
25#define EDIT_NONE 0 // no edit type yet
26#define EDIT_FILE 1 // file name argument[s] given, use argument list
27#define EDIT_STDIN 2 // read file from stdin
28#define EDIT_TAG 3 // tag name argument given, use tagname
29#define EDIT_QF 4 // start in quickfix mode
30
31#if (defined(UNIX) || defined(VMS)) && !defined(NO_VIM_MAIN)
32static int file_owned(char *fname);
33#endif
34static void mainerr(int, char_u *);
35static void early_arg_scan(mparm_T *parmp);
36#ifndef NO_VIM_MAIN
37static void usage(void);
38static void parse_command_name(mparm_T *parmp);
39static void command_line_scan(mparm_T *parmp);
40static void check_tty(mparm_T *parmp);
41static void read_stdin(void);
42static void create_windows(mparm_T *parmp);
43static void edit_buffers(mparm_T *parmp, char_u *cwd);
44static void exe_pre_commands(mparm_T *parmp);
45static void exe_commands(mparm_T *parmp);
46static void source_startup_scripts(mparm_T *parmp);
47static void main_start_gui(void);
48static void check_swap_exists_action(void);
49# ifdef FEAT_EVAL
50static void set_progpath(char_u *argv0);
51# endif
52#endif
53
54
55/*
56 * Different types of error messages.
57 */
58static char *(main_errors[]) =
59{
60 N_("Unknown option argument"),
61#define ME_UNKNOWN_OPTION 0
62 N_("Too many edit arguments"),
63#define ME_TOO_MANY_ARGS 1
64 N_("Argument missing after"),
65#define ME_ARG_MISSING 2
66 N_("Garbage after option argument"),
67#define ME_GARBAGE 3
68 N_("Too many \"+command\", \"-c command\" or \"--cmd command\" arguments"),
69#define ME_EXTRA_CMD 4
70 N_("Invalid argument for"),
71#define ME_INVALID_ARG 5
72};
73
74#ifndef PROTO // don't want a prototype for main()
75
76// Various parameters passed between main() and other functions.
77static mparm_T params;
78
79#ifdef _IOLBF
80static void *s_vbuf = NULL; // buffer for setvbuf()
81#endif
82
83#ifndef NO_VIM_MAIN // skip this for unittests
84
85static char_u *start_dir = NULL; // current working dir on startup
86
87static int has_dash_c_arg = FALSE;
88
89# ifdef VIMDLL
90__declspec(dllexport)
91# endif
92 int
93# ifdef MSWIN
94VimMain
95# else
96main
97# endif
98(int argc, char **argv)
99{
100#if defined(STARTUPTIME) || defined(CLEAN_RUNTIMEPATH)
101 int i;
102#endif
103
104 /*
105 * Do any system-specific initialisations. These can NOT use IObuff or
106 * NameBuff. Thus emsg2() cannot be called!
107 */
108 mch_early_init();
109
110 // Source startup scripts.
111 source_startup_scripts(&params);
112
113#if 0
114 /*
115 * Newer version of MzScheme (Racket) require earlier (trampolined)
116 * initialisation via scheme_main_setup.
117 */
118 return mzscheme_main();
119#else
120 return vim_main2();
121#endif
122}