/* This file contains the main() function of vi */
/* HACK! bcc needs to disable use of precompiled headers for this file,
or else command line args will not be passed to elvis */
extern trapint(); /* defined below */
/*---------------------------------------------------------------------*/
/* set mode to MODE_VI or MODE_EX depending on program name */
switch (argv
[0][strlen(argv
[0]) - 1])
case 't': /* "edit" or "input" */
default: /* "vi" or "elvis" */
/* normally, we ignore SIGQUIT. SIGINT is trapped later */
signal(SIGQUIT
, SIG_IGN
);
/* temporarily ignore SIGINT */
/* arrange for deadly signals to be caught */
signal(SIGHUP
, (void(*)()) deathtrap
);
signal(SIGILL
, (void(*)()) deathtrap
);
signal(SIGBUS
, (void(*)()) deathtrap
);
signal(SIGSEGV
, (void(*)()) deathtrap
);
signal(SIGSYS
, (void(*)()) deathtrap
);
signal(SIGPIPE
, (void(*)()) deathtrap
);
signal(SIGTERM
, (void(*)()) deathtrap
);
signal(SIGUSR1
, (void(*)()) deathtrap
);
signal(SIGUSR2
, (void(*)()) deathtrap
);
/* initialize the options - must be done after initscr(), so that
* we can alter LINES and COLS if necessary.
/* map the arrow keys. The KU,KD,KL,and KR variables correspond to
* the :ku=: (etc.) termcap capabilities. The variables are defined
* as part of the curses package.
if (has_KU
) mapkey(has_KU
, "k", WHEN_VICMD
|WHEN_INMV
, "<Up>");
if (has_KD
) mapkey(has_KD
, "j", WHEN_VICMD
|WHEN_INMV
, "<Down>");
if (has_KL
) mapkey(has_KL
, "h", WHEN_VICMD
|WHEN_INMV
, "<Left>");
if (has_KR
) mapkey(has_KR
, "l", WHEN_VICMD
|WHEN_INMV
, "<Right>");
if (has_HM
) mapkey(has_HM
, "^", WHEN_VICMD
|WHEN_INMV
, "<Home>");
if (has_EN
) mapkey(has_EN
, "$", WHEN_VICMD
|WHEN_INMV
, "<End>");
if (has_PU
) mapkey(has_PU
, "\002", WHEN_VICMD
|WHEN_INMV
, "<PageUp>");
if (has_PD
) mapkey(has_PD
, "\006", WHEN_VICMD
|WHEN_INMV
, "<PageDn>");
if (has_KI
) mapkey(has_KI
, "i", WHEN_VICMD
|WHEN_INMV
, "<Insert>");
if (!strcmp("rainbow", o_term
))
mapkey("\033[1~", "/", WHEN_VICMD
, "<Find>");
mapkey("\033[3~", "x", WHEN_VICMD
|WHEN_INMV
, "<Remove>");
mapkey("\033[4~", "v", WHEN_VICMD
|WHEN_INMV
, "<Select>");
mapkey("\033[17~", ":sh\n", WHEN_VICMD
, "<Intrpt>");
mapkey("\033[19~", ":q\n", WHEN_VICMD
, "<Cancel>");
mapkey("\033[21~", "ZZ", WHEN_VICMD
, "<Exit>");
mapkey("\033[26~", "V", WHEN_VICMD
|WHEN_INMV
, "<AddlOp>");
mapkey("\033[28~", "\\", WHEN_VICMD
|WHEN_INMV
, "<Help>");
mapkey("\033[29~", "K", WHEN_VICMD
|WHEN_INMV
, "<Do>");
mapkey("#S", "x", WHEN_VICMD
|WHEN_INMV
, "<Delete>");
mapkey("#s", "B", WHEN_VICMD
|WHEN_INMV
, "^<Left>");
mapkey("#t", "W", WHEN_VICMD
|WHEN_INMV
, "^<Right>");
mapkey("\033[P", "x", WHEN_VICMD
|WHEN_INMV
, "<Del>");
mapkey("\233?~", "\\", WHEN_VICMD
|WHEN_INMV
, "<Help>");
mapkey("\177", "x", WHEN_VICMD
|WHEN_INMV
, "<Del>");
for (i
= 1; i
< argc
&& *argv
[i
] == '-'; i
++)
msg("Use the `elvisrecover` program to recover lost files");
case 'i': /* input mode */
case 'm': /* use "errlist" as the errlist */
case 'c': /* run the following command, later */
case 'w': /* set the window size */
*o_window
= atoi(argv
[i
] + 2);
*o_window
= atoi(argv
[++i
]);
msg("Ignoring unknown flag \"%s\"", argv
[i
]);
/* if we were given an initial ex command, save it... */
if (i
< argc
&& *argv
[i
] == '+')
cmd
= "$"; /* "vi + file" means start at EOF */
/* the remaining args are file names. */
while (++i
< argc
&& strlen(args
) + 1 + strlen(argv
[i
]) < sizeof args
)
/* expand wildcard characters, if necessary */
if (strchr(args
, '*') || strchr(args
, '?'))
strcpy(args
, wildcard(args
));
cmd_args(MARK_UNSET
, MARK_UNSET
, CMD_ARGS
, TRUE
, tmpblk
.c
);
/* perform the .exrc files and EXINIT environment variable */
str
= tmpblk
.c
+ strlen(tmpblk
.c
);
# if AMIGA /* Don't SLASH a device. "Elvis:.exrc" */
if (str
[-1] != COLON
&& str
[-1] != SLASH
)
exstring(str
, strlen(str
), ctrl('V'));
/* search for a tag (or an error) now, if desired */
cmd_tag(MARK_FIRST
, MARK_FIRST
, CMD_TAG
, 0, tag
);
cmd_errlist(MARK_FIRST
, MARK_FIRST
, CMD_ERRLIST
, 0, err
);
/* if no tag/err, or tag failed, then start with first arg */
/* start with first arg */
cmd_next(MARK_UNSET
, MARK_UNSET
, CMD_NEXT
, FALSE
, "");
/* pretend to do something, just to force a recoverable
* version of the file out to disk
/* now we do the immediate ex command that we noticed before */
/* repeatedly call ex() or vi() (depending on the mode) until the
* mode is set to MODE_QUIT
while (mode
!= MODE_QUIT
)
/* Maybe we just aborted a change? */
signal(SIGINT
, (void(*)()) trapint
);
/* free up the cut buffers */
signal(signo
, (void (*)())trapint
);
/* This stuff us used to build the default digraphs table. */
static char digtable
[][4] =
"C,\200", "u\"\1", "e'\2", "a^\3",
"a\"\4", "a`\5", "a@\6", "c,\7",
"e^\10", "e\"\211", "e`\12", "i\"\13",
"i^\14", "i`\15", "A\"\16", "A@\17",
"E'\20", "ae\21", "AE\22", "o^\23",
"o\"\24", "o`\25", "u^\26", "u`\27",
"y\"\30", "O\"\31", "U\"\32", "a'\240",
"i'!", "o'\"", "u'#", "n~$",
"N~%", "a-&", "o-'", "~?(",
"2/+", "4/,", "^+;", "^q<",
"^c=", "^r>", "^t?", "pp]",
"^^^", "oo_", "*a`", "*ba",
"*pc", "*Sd", "*se", "*uf",
"*tg", "*Ph", "*Ti", "*Oj",
"*dk", "*Hl", "*hm", "*En",
"*No", "eqp", "pmq", "ger",
"les", "*It", "*iu", "*/v",
"*=w", "sq{", "^n|", "^2}",
"~!!", "a-*", "\">+", "o-:",
"A`@", "A'A", "A^B", "A~C",
"A\"D", "A@E", "AEF", "C,G",
"E`H", "E'I", "E^J", "E\"K",
"I`L", "I'M", "I^N", "I\"O",
"-DP", "N~Q", "O`R", "O'S",
"O^T", "O~U", "O\"V", "O/X",
"U`Y", "U'Z", "U^[", "U\"\\",
"a``", "a'a", "a^b", "a~c",
"a\"d", "a@e", "aef", "c,g",
"e`h", "e'i", "e^j", "e\"k",
"i`l", "i'm", "i^n", "i\"o",
"-dp", "n~q", "o`r", "o's",
"o^t", "o~u", "o\"v", "o/x",
"u`y", "u'z", "u^{", "u\"|",
for (i
= 0; *digtable
[i
]; i
++)
do_digraph(FALSE
, digtable
[i
]);
do_digraph(FALSE
, (char *)0);