8000 minix/commands/elvis/ex.c at R3.1.7 · devinblood/minix · GitHub
[go: up one dir, main page]

Skip to content

Latest commit

 

History

History
722 lines (657 loc) · 16 KB

ex.c

File metadata and controls

722 lines (657 loc) · 16 KB
}
while (*build && isspace(*build))
{
build++;
}
}
#endif /* not CRUNCH */
for (; *build; build++)
{
if (isspace(*build))
{
msg("Too many %s to \"%s\" command.",
897A
(argt & XFILE) ? "filenames" : "arguments",
cmdnames[cmdidx].name);
return;
}
}
}
/* some commands have special default ranges */
if (isdfl && (argt & DFLALL))
{
frommark = MARK_FIRST;
tomark = MARK_LAST;
}
else if (isdfl && (argt & DFLNONE))
{
frommark = tomark = 0L;
}
/* write a newline if called from visual mode */
if ((argt & NL) && mode != MODE_EX && !exwrote)
{
addch('\n');
exrefresh();
}
/* act on the command */
(*cmdnames[cmdidx].fn)(frommark, tomark, cmd, forceit, scan);
}
/* This function executes EX commands from a file. It returns 1 normally, or
* 0 if the file could not be opened for reading.
*/
int doexrc(filename)
char *filename; /* name of a ".exrc" file */
{
int fd; /* file descriptor */
int len; /* length of the ".exrc" file */
/* !!! kludge: we use U_text as the buffer. This has the side-effect
* of interfering with the shift-U visual command. Disable shift-U.
*/
U_line = 0L;
/* open the file, read it, and close */
fd = open(filename, O_RDONLY);
if (fd < 0)
{
return 0;
}
len = tread(fd, U_text, BLKSIZE);
close(fd);
/* execute the string */
exstring(U_text, len, ctrl('V'));
return 1;
}
/* This function executes EX commands from a string. The commands may be
* separated by newlines or by | characters. It also handles quoting.
* Each individual command is limited to 132 bytes, but the total string
* may be longer.
*/
void exstring(buf, len, qchar)
char *buf; /* the commands to execute */
int len; /* the length of the string */
int qchar; /* the quote character -- ^V for file, or \ for kbd */
{
char single[133]; /* a single command */
char *src, *dest;
int i;
/* find & do each command */
for (src = buf; src < &buf[len]; src++)
{
/* Copy a single command into single[]. Convert any quoted |
* into a normal |, and stop at a newline or unquoted |.
*/
for (dest = single, i = 0;
i < 132 && src < &buf[len] && *src != '\n' && *src != '|';
src++, i++)
{
if (src[0] == qchar && src[1] == '|')
{
src++;
}
*dest++ = *src;
}
*dest = '\0';
/* do it */
doexcmd(single);
}
}
0