main.c
资源名称:vim53src.zip [点击查看]
上传用户:gddssl
上传日期:2007-01-06
资源大小:1003k
文件大小:43k
源码类别:
编辑器/阅读器
开发平台:
DOS
- /* vi:set ts=8 sts=4 sw=4:
- *
- * VIM - Vi IMproved by Bram Moolenaar
- *
- * Do ":help uganda" in Vim to read copying and usage conditions.
- * Do ":help credits" in Vim to see a list of people who contributed.
- */
- #define EXTERN
- #include "vim.h"
- #ifdef SPAWNO
- # include <spawno.h> /* special MSDOS swapping library */
- #endif
- static void mainerr __ARGS((int, char_u *));
- static void main_msg __ARGS((char *s));
- static void usage __ARGS((void));
- static int get_number_arg __ARGS((char_u *p, int *idx, int def));
- /*
- * Type of error message. These must match with errors[] in mainerr().
- */
- #define ME_UNKNOWN_OPTION 0
- #define ME_TOO_MANY_ARGS 1
- #define ME_ARG_MISSING 2
- #define ME_GARBAGE 3
- #define ME_EXTRA_CMD 4
- static void
- mainerr(n, str)
- int n;
- char_u *str;
- {
- static char *(errors[]) =
- {
- "Unknown option",
- "Too many edit arguments",
- "Argument missing after",
- "Garbage after option",
- "Too many "+command" or "-c command" arguments",
- };
- #if defined(UNIX) || defined(__EMX__)
- reset_signals(); /* kill us with CTRL-C here, if you like */
- #endif
- mch_errmsg(longVersion);
- mch_errmsg("n");
- mch_errmsg(errors[n]);
- if (str != NULL)
- {
- mch_errmsg(": "");
- mch_errmsg((char *)str);
- mch_errmsg(""");
- }
- mch_errmsg("nMore info with: "vim -h"n");
- mch_windexit(1);
- }
- /*
- * print a message with three spaces prepended and 'n' appended.
- */
- static void
- main_msg(s)
- char *s;
- {
- mch_msg(" ");
- mch_msg(s);
- mch_msg("n");
- }
- static void
- usage()
- {
- int i;
- static char_u *(use[]) =
- {
- (char_u *)"[file ..] edit specified file(s)",
- (char_u *)"- read from stdin",
- (char_u *)"-t tag edit file where tag is defined",
- #ifdef QUICKFIX
- (char_u *)"-q [errorfile] edit file with first error"
- #endif
- };
- #if defined(UNIX) || defined(__EMX__)
- reset_signals(); /* kill us with CTRL-C here, if you like */
- #endif
- mch_msg(longVersion);
- mch_msg("nusage:");
- for (i = 0; ; ++i)
- {
- mch_msg(" vim [options] ");
- mch_msg((char *)use[i]);
- if (i == (sizeof(use) / sizeof(char_u *)) - 1)
- break;
- mch_msg("n or:");
- }
- mch_msg("nnOptions:n");
- main_msg("--tttEnd of options");
- #ifdef HAVE_OLE
- main_msg("-registerttRegister this gvim for OLE");
- main_msg("-unregisterttUnregister gvim for OLE");
- #endif
- #ifdef USE_GUI
- main_msg("-gtttRun using GUI (like "gvim")");
- main_msg("-ftttForeground: Don't fork when starting GUI");
- #endif
- main_msg("-vtttVi mode (like "vi")");
- main_msg("-etttEx mode (like "ex")");
- main_msg("-stttSilent (batch) mode (only for "ex")");
- main_msg("-RtttReadonly mode (like "view")");
- main_msg("-ZtttRestricted mode (like "rvim")");
- main_msg("-btttBinary mode");
- #ifdef LISPINDENT
- main_msg("-ltttLisp mode");
- #endif
- main_msg("-CtttCompatible with Vi: 'compatible'");
- main_msg("-NtttNot fully Vi compatible: 'nocompatible'");
- main_msg("-V[N]ttVerbose level");
- main_msg("-ntttNo swap file, use memory only");
- main_msg("-rtttList swap files and exit");
- main_msg("-r (with file name)tRecover crashed session");
- main_msg("-LtttSame as -r");
- #ifdef AMIGA
- main_msg("-ftttDon't use newcli to open window");
- main_msg("-d <device>ttUse <device> for I/O");
- #endif
- #ifdef RIGHTLEFT
- main_msg("-Htttstart in Hebrew mode");
- #endif
- #ifdef FKMAP
- main_msg("-Ftttstart in Farsi mode");
- #endif
- main_msg("-T <terminal>tSet terminal type to <terminal>");
- main_msg("-o[N]ttOpen N windows (default: one for each file)");
- main_msg("+tttStart at end of file");
- main_msg("+<lnum>ttStart at line <lnum>");
- main_msg("-c <command>ttExecute <command> first");
- main_msg("-s <scriptin>tRead commands from script file <scriptin>");
- main_msg("-w <scriptout>tAppend commands to script file <scriptout>");
- main_msg("-W <scriptout>tWrite commands to script file <scriptout>");
- main_msg("-u <vimrc>ttUse <vimrc> instead of any .vimrc");
- #ifdef USE_GUI
- main_msg("-U <gvimrc>ttUse <gvimrc> instead of any .gvimrc");
- #endif
- #ifdef VIMINFO
- main_msg("-i <viminfo>ttUse <viminfo> instead of .viminfo");
- #endif
- main_msg("-htttprint Help (this message) and exit");
- main_msg("--versionttprint version information and exit");
- #ifdef USE_GUI_X11
- # ifdef USE_GUI_MOTIF
- mch_msg("nOptions recognised by gvim (Motif version):n");
- # else
- # ifdef USE_GUI_ATHENA
- mch_msg("nOptions recognised by gvim (Athena version):n");
- # endif /* USE_GUI_ATHENA */
- # endif /* USE_GUI_MOTIF */
- main_msg("-display <display>tRun vim on <display>");
- main_msg("-iconicttStart vim iconified");
- # if 0
- main_msg("-name <name>ttUse resource as if vim was <name>");
- mch_msg("ttt (Unimplemented)n");
- # endif
- main_msg("-background <color>tUse <color> for the background (also: -bg)");
- main_msg("-foreground <color>tUse <color> for normal text (also: -fg)");
- main_msg("-font <font>ttUse <font> for normal text (also: -fn)");
- main_msg("-boldfont <font>tUse <font> for bold text");
- main_msg("-italicfont <font>tUse <font> for italic text");
- main_msg("-geometry <geom>tUse <geom> for initial geometry (also: -geom)");
- main_msg("-borderwidth <width>tUse a border width of <width> (also: -bw)");
- main_msg("-scrollbarwidth <width>tUse a scrollbar width of <width> (also: -sw)");
- main_msg("-menuheight <height>tUse a menu bar height of <height> (also: -mh)");
- main_msg("-reversettUse reverse video (also: -rv)");
- main_msg("+reversettDon't use reverse video (also: +rv)");
- main_msg("-xrm <resource>tSet the specified resource");
- #endif /* USE_GUI_X11 */
- mch_windexit(1);
- }
- #ifdef HAVE_LOCALE_H
- # include <locale.h>
- #endif
- /* Maximum number of commands from + or -c options */
- #define MAX_ARG_CMDS 10
- #ifndef PROTO /* don't want a prototype for main() */
- int
- #ifdef VIMDLL
- _export
- #endif
- main(argc, argv)
- int argc;
- char **argv;
- {
- char_u *initstr; /* init string from environment */
- char_u *term = NULL; /* specified terminal name */
- char_u *fname = NULL; /* file name from command line */
- char_u *tagname = NULL; /* tag from -t option */
- char_u *use_vimrc = NULL; /* vimrc from -u option */
- #ifdef QUICKFIX
- char_u *use_ef = NULL; /* 'errorfile' from -q option */
- #endif
- int n_commands = 0; /* no. of commands from + or -c */
- char_u *commands[MAX_ARG_CMDS]; /* commands from + or -c option */
- int no_swap_file = FALSE; /* "-n" option used */
- int c;
- int i;
- int bin_mode = FALSE; /* -b option used */
- int window_count = 1; /* number of windows to use */
- int arg_idx = 0; /* index for arg_files[] */
- int had_minmin = FALSE; /* found "--" option */
- int argv_idx; /* index in argv[n][] */
- int want_full_screen = TRUE;
- int want_argument; /* option with argument */
- #define EDIT_NONE 0 /* no edit type yet */
- #define EDIT_FILE 1 /* file name argument[s] given, use arg_files[] */
- #define EDIT_STDIN 2 /* read file from stdin */
- #define EDIT_TAG 3 /* tag name argument given, use tagname */
- #define EDIT_QF 4 /* start in quickfix mode */
- int edit_type = EDIT_NONE; /* type of editing to do */
- int stdout_isatty; /* is stdout a terminal? */
- int input_isatty; /* is active input a terminal? */
- OPARG oa; /* operator arguments */
- #ifdef RISCOS
- /* Turn off all the horrible filename munging in UnixLib. */
- __uname_control = __UNAME_NO_PROCESS;
- #endif
- #if defined(MSDOS) || defined(WIN32) || defined(OS2)
- /*
- * Default mappings for some often used keys.
- * Use the Windows (CUA) keybindings.
- */
- static struct initmap
- {
- char_u *arg;
- int mode;
- } initmappings[] =
- {
- # ifdef USE_GUI
- {(char_u *)"<C-PageUp> H", NORMAL+VISUAL},
- {(char_u *)"<C-PageUp> <C-O>H",INSERT},
- {(char_u *)"<C-PageDown> L$", NORMAL+VISUAL},
- {(char_u *)"<C-PageDown> <C-O>L<C-O>$", INSERT},
- /* paste, copy and cut */
- {(char_u *)"<S-Insert> "*P", NORMAL},
- {(char_u *)"<S-Insert> "-d"*P", VISUAL},
- {(char_u *)"<S-Insert> <C-R>*", INSERT+CMDLINE},
- {(char_u *)"<C-Insert> "*y", VISUAL},
- {(char_u *)"<S-Del> "*d", VISUAL},
- {(char_u *)"<C-Del> "*d", VISUAL},
- {(char_u *)"<C-X> "*d", VISUAL},
- /* Missing: CTRL-C (can't be mapped) and CTRL-V (means something) */
- # else
- {(char_u *)"316204 H", NORMAL+VISUAL}, /* CTRL-PageUp is "H" */
- {(char_u *)"316204