8000 minix/commands/elvis/cmd1.c at R3.1.6 · aducode/minix · GitHub
[go: up one dir, main page]

Skip to content

Latest commit

 

History

History
1774 lines (1585 loc) · 33.5 KB

cmd1.c

File metadata and controls

1774 lines (1585 loc) · 33.5 KB
if (!oldflag)
clrflag(file, MODIFIED);
}
}
/*ARGSUSED*/
void cmd_args(frommark, tomark, cmd, bang, extra)
MARK frommark, tomark;
CMD cmd;
int bang;
char *extra;
{
char *scan;
int col;
int arg;
int scrolled = FALSE;
int width;
/* if no extra names given, or just current name, then report the args
* we have now.
*/
if (!extra || !*extra)
{
/* empty args list? */
if (nargs == 1 && !*args)
{
return;
}
/* list the arguments */
for (scan = args, col = arg = 0;
arg < nargs;
scan += width + 1, col += width, arg++)
{
width = strlen(scan);
if (col + width >= COLS - 4)
{
addch('\n');
col = 0;
scrolled = TRUE;
}
else if (col > 0)
{
addch(' ');
col++;
}
if (arg == argno)
{
addch('[');
addstr(scan);
addch(']');
col += 2;
}
else
{
addstr(scan);
}
}
/* write a trailing newline */
if ((mode == MODE_EX || mode == MODE_COLON || scrolled) && col)
{
addch('\n');
}
exrefresh();
}
else /* new args list given */
{
for (scan = args, nargs = 1; *extra; )
{
if (isspace(*extra))
{
*scan++ = '\0';
while (isspace(*extra))
{
extra++;
}
if (*extra)
{
nargs++;
}
}
else
{
*scan++ = *extra++;
}
}
*scan = '\0';
/* reset argno to before the first, so :next will go to first */
argno = -1;
if (nargs != 1)
{
msg("%d files to edit", nargs);
}
}
}
/*ARGSUSED*/
void cmd_cd(frommark, tomark, cmd, bang, extra)
MARK frommark, tomark;
CMD cmd;
int bang;
char *extra;
{
char *getenv();
#ifndef CRUNCH
/* if current file is modified, and no '!' was given, then error */
if (tstflag(file, MODIFIED) && !bang)
{
msg("File modified; use \"cd! %s\" to switch anyway", extra);
}
#endif
/* default directory name is $HOME */
if (!*extra)
{
extra = getenv("HOME");
if (!extra)
{
msg("environment variable $HOME not set");
return;
}
}
/* go to the directory */
if (chdir(extra) < 0)
{
perror(extra);
}
}
/*ARGSUSED*/
void cmd_map(frommark, tomark, cmd, bang, extra)
MARK frommark, tomark;
CMD cmd;
int bang;
char *extra;
{
char *mapto;
char *build, *scan;
#ifndef NO_FKEY
static char *fnames[NFKEYS] =
{
"#10", "#1", "#2", "#3", "#4",
"#5", "#6", "#7", "#8", "#9",
# ifndef NO_SHIFT_FKEY
"#10s", "#1s", "#2s", "#3s", "#4s",
"#5s", "#6s", "#7s", "#8s", "#9s",
# ifndef NO_CTRL_FKEY
"#10c", "#1c", "#2c", "#3c", "#4c",
"#5c", "#6c", "#7c", "#8c", "#9c",
# ifndef NO_ALT_FKEY
"#10a", "#1a", "#2a", "#3a", "#4a",
"#5a", "#6a", "#7a", "#8a", "#9a",
# endif
# endif
# endif
};
int key;
#endif
/* "map" with no extra will dump the map table contents */
if (!*extra)
{
#ifndef NO_ABBR
if (cmd == CMD_ABBR)
{
dumpkey(bang ? WHEN_EX|WHEN_VIINP|WHEN_VIREP : WHEN_VIINP|WHEN_VIREP, TRUE);
}
else
#endif
{
dumpkey(bang ? WHEN_VIINP|WHEN_VIREP : WHEN_VICMD, FALSE);
}
}
else
{
/* "extra" is key to map, followed by what it maps to */
/* handle quoting inside the "raw" string */
for (build = mapto = extra;
*mapto && (*mapto != ' ' && *mapto != '\t');
*build++ = *mapto++)
{
if (*mapto == ctrl('V') && mapto[1])
{
mapto++;
}
}
/* skip whitespace, and mark the end of the "raw" string */
while ((*mapto == ' ' || *mapto == '\t'))
{
*mapto++ = '\0';
}
*build = '\0';
/* strip ^Vs from the "cooked" string */
for (scan = build = mapto; *scan; *build++ = *scan++)
{
if (*scan == ctrl('V') && scan[1])
{
scan++;
}
}
*build = '\0';
#ifndef NO_FKEY
/* if the mapped string is '#' and a number, then assume
* the user wanted that function key
*/
if (extra[0] == '#' && isdigit(extra[1]))
{
key = atoi(extra + 1) % 10;
# ifndef NO_SHIFT_FKEY
build = extra + strlen(extra) - 1;
if (*build == 's')
key += 10;
# ifndef NO_CTRL_FKEY
else if (*build == 'c')
key += 20;
# ifndef NO_ALT_FKEY
else if (*build == 'a')
key += 30;
# endif
# endif
# endif
if (FKEY[key])
mapkey(FKEY[key], mapto, bang ? WHEN_VIINP|WHEN_VIREP : WHEN_VICMD, fnames[key]);
else
msg("This terminal has no %s key", fnames[key]);
}
else
#endif
#ifndef NO_ABBR
if (cmd == CMD_ABBR || cmd == CMD_UNABBR)
{
mapkey(extra, mapto, bang ? WHEN_EX|WHEN_VIINP|WHEN_VIREP : WHEN_VIINP|WHEN_VIREP, "abbr");
}
else
#endif
{
mapkey(extra, mapto, bang ? WHEN_VIINP|WHEN_VIREP : WHEN_VICMD, (char *)0);
}
}
}
/*ARGSUSED*/
void cmd_set(frommark, tomark, cmd, bang, extra)
MARK frommark, tomark;
CMD cmd;
int bang;
char *extra;
{
if (!*extra)
{
dumpopts(FALSE);/* "FALSE" means "don't dump all" - only set */
}
else if (!strcmp(extra, "all"))
{
dumpopts(TRUE); /* "TRUE" means "dump all" - even unset vars */
}
else
{
setopts(extra);
/* That option may have affected the appearence of text */
changes++;
}
}
/*ARGSUSED*/
void cmd_tag(frommark, tomark, cmd, bang, extra)
MARK frommark, tomark;
CMD cmd;
int bang;
char *extra;
{
int fd; /* file descriptor used to read the file */
char *scan; /* used to scan through the tmpblk.c */
#ifdef INTERNAL_TAGS
char *cmp; /* char of tag name we're comparing, or NULL */
char *end; /* marks the end of chars in tmpblk.c */
#else
int i;
#endif
#ifndef NO_MAGIC
char wasmagic; /* preserves the original state of o_magic */
#endif
static char prevtag[30];
/* if no tag is given, use the previous tag */
if (!extra || !*extra)
{
if (!*prevtag)
{
msg("No previous tag");
return;
}
extra = prevtag;
}
else
{
strncpy(prevtag, extra, sizeof prevtag);
prevtag[sizeof prevtag - 1] = '\0';
}
#ifndef INTERNAL_TAGS
/* use "ref" to look up the tag info for this tag */
sprintf(tmpblk.c, "ref -t %s%s %s", (*origname ? "-f" : ""),origname, prevtag);
fd = rpipe(tmpblk.c, 0);
if (fd < 0)
{
msg("Can't run \"%s\"", tmpblk.c);
return;
}
/* try to read the tag info */
for (scan = tmpblk.c;
(i = tread(fd, scan, scan - tmpblk.c + BLKSIZE)) > 0;
scan += i)
{
}
*scan = '\0';
/* close the pipe. abort if error */
if (rpclose(fd) != 0 || scan < tmpblk.c + 3)
{
msg("tag \"%s\" not found", extra);
return;
}
#else /* use internal code to look up the tag */
/* open the tags file */
fd = open(TAGS, O_RDONLY);
if (fd < 0)
{
msg("No tags file");
return;
}
/* Hmmm... this would have been a lot easier with <stdio.h> */
/* find the line with our tag in it */
for(scan = end = tmpblk.c, cmp = extra; ; scan++)
{
/* read a block, if necessary */
if (scan >= end)
{
end = tmpblk.c + tread(fd, tmpblk.c, BLKSIZE);
scan = tmpblk.c;
if (scan >= end)
{
0