2007-07-05 16:02:19 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2007 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix
|
|
|
|
*
|
|
|
|
* See file CREDITS for list of people who contributed to this
|
|
|
|
* project.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2007-07-05 16:01:41 +00:00
|
|
|
#include <common.h>
|
|
|
|
#include <command.h>
|
|
|
|
#include <malloc.h>
|
|
|
|
#include <fs.h>
|
|
|
|
#include <linux/ctype.h>
|
|
|
|
#include <fcntl.h>
|
2014-07-30 08:43:51 +00:00
|
|
|
#include <libfile.h>
|
2007-07-05 16:01:42 +00:00
|
|
|
#include <readkey.h>
|
2007-07-05 16:01:41 +00:00
|
|
|
#include <errno.h>
|
2007-07-05 16:01:42 +00:00
|
|
|
#include <xfuncs.h>
|
2007-07-05 16:02:10 +00:00
|
|
|
#include <linux/stat.h>
|
2007-07-05 16:01:41 +00:00
|
|
|
|
|
|
|
#define TABSPACE 8
|
|
|
|
|
|
|
|
struct line {
|
|
|
|
int length;
|
|
|
|
struct line *next;
|
|
|
|
struct line *prev;
|
|
|
|
char *data;
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct line *buffer;
|
|
|
|
|
|
|
|
static struct line *lastscrline;
|
|
|
|
|
|
|
|
static int screenwidth = 80;
|
|
|
|
static int screenheight = 25;
|
|
|
|
|
2007-07-05 16:02:04 +00:00
|
|
|
static int cursx = 0; /* position on screen */
|
2007-07-05 16:01:41 +00:00
|
|
|
static int cursy = 0;
|
|
|
|
|
2007-07-05 16:02:04 +00:00
|
|
|
static int textx = 0; /* position in text */
|
2007-07-05 16:01:41 +00:00
|
|
|
|
|
|
|
static struct line *curline; /* line where the cursor is */
|
|
|
|
|
|
|
|
static struct line *scrline; /* the first line on screen */
|
2010-10-15 07:33:32 +00:00
|
|
|
static int scrcol = 0; /* the first column on screen */
|
2007-07-05 16:01:41 +00:00
|
|
|
|
|
|
|
static void pos(int x, int y)
|
|
|
|
{
|
2012-05-16 06:20:06 +00:00
|
|
|
printf("%c[%d;%dH", 27, y + 2, x + 1);
|
2007-07-05 16:01:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static char *screenline(char *line, int *pos)
|
|
|
|
{
|
|
|
|
int i, outpos = 0;
|
|
|
|
static char lbuf[1024];
|
|
|
|
|
|
|
|
memset(lbuf, 0, 1024);
|
|
|
|
|
|
|
|
if (!line) {
|
|
|
|
lbuf[0] = '~';
|
|
|
|
return lbuf;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; outpos < 1024; i++) {
|
|
|
|
if (i == textx && pos)
|
|
|
|
*pos = outpos;
|
|
|
|
if (!line[i])
|
|
|
|
break;
|
|
|
|
if (line[i] == '\t') {
|
|
|
|
lbuf[outpos++] = ' ';
|
|
|
|
while (outpos % TABSPACE)
|
|
|
|
lbuf[outpos++] = ' ';
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
lbuf[outpos++] = line[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
return lbuf;
|
|
|
|
}
|
|
|
|
|
2007-07-05 16:01:55 +00:00
|
|
|
static int setpos(char *line, int position)
|
2007-07-05 16:01:41 +00:00
|
|
|
{
|
|
|
|
int i = 0;
|
|
|
|
int linepos = 0;
|
|
|
|
|
|
|
|
while(line[linepos]) {
|
|
|
|
if (line[linepos] == '\t')
|
|
|
|
while ((i + 1) % TABSPACE)
|
|
|
|
i++;
|
|
|
|
if (i >= position)
|
|
|
|
return linepos;
|
|
|
|
linepos++;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return linepos;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void refresh_line(struct line *line, int ypos)
|
|
|
|
{
|
|
|
|
char *str = screenline(line->data, NULL) + scrcol;
|
|
|
|
pos(0, ypos);
|
|
|
|
str[screenwidth] = 0;
|
2007-07-05 16:01:59 +00:00
|
|
|
printf("%s%c[K", str, 27);
|
2007-07-05 16:01:41 +00:00
|
|
|
pos(cursx, cursy);
|
|
|
|
}
|
|
|
|
|
2007-10-16 20:35:42 +00:00
|
|
|
/*
|
|
|
|
* Most sane terminal programs can do ansi screen scrolling.
|
|
|
|
* Unfortunately one of the most popular programs cannot:
|
|
|
|
* minicom.
|
|
|
|
* Grmpf!
|
|
|
|
*/
|
|
|
|
static int smartscroll = 0;
|
|
|
|
|
2007-07-05 16:01:41 +00:00
|
|
|
static void refresh(int full)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
struct line *l = scrline;
|
|
|
|
|
|
|
|
if (!full) {
|
2007-10-16 20:35:42 +00:00
|
|
|
if (smartscroll) {
|
|
|
|
if (scrline->next == lastscrline) {
|
|
|
|
printf("%c[1T", 27);
|
|
|
|
refresh_line(scrline, 0);
|
|
|
|
pos(0, screenheight);
|
|
|
|
printf("%*s", screenwidth, "");
|
|
|
|
return;
|
|
|
|
}
|
2007-07-05 16:01:41 +00:00
|
|
|
|
2007-10-16 20:35:42 +00:00
|
|
|
if (scrline->prev == lastscrline) {
|
|
|
|
printf("%c[1S", 27);
|
|
|
|
for (i = 0; i < screenheight - 1; i++) {
|
|
|
|
l = l->next;
|
|
|
|
if (!l)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
refresh_line(l, screenheight - 1);
|
|
|
|
return;
|
2007-07-05 16:01:41 +00:00
|
|
|
}
|
2007-10-16 20:35:42 +00:00
|
|
|
} else {
|
|
|
|
refresh(1);
|
2007-07-05 16:01:41 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < screenheight; i++) {
|
|
|
|
refresh_line(l, i);
|
|
|
|
l = l->next;
|
|
|
|
if (!l)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-07-05 16:01:42 +00:00
|
|
|
i++;
|
2007-07-05 16:01:41 +00:00
|
|
|
while (i < screenheight) {
|
|
|
|
pos(0, i++);
|
2007-07-05 16:01:59 +00:00
|
|
|
printf("~");
|
2007-07-05 16:01:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void line_free(struct line *line)
|
|
|
|
{
|
|
|
|
free(line->data);
|
|
|
|
free(line);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct line *line_realloc(int len, struct line *line)
|
|
|
|
{
|
|
|
|
int size = 32;
|
|
|
|
|
2011-01-06 15:23:01 +00:00
|
|
|
if (!line)
|
2007-07-05 16:01:42 +00:00
|
|
|
line = xzalloc(sizeof(struct line));
|
2007-07-05 16:01:41 +00:00
|
|
|
|
2007-07-05 16:02:10 +00:00
|
|
|
while (size < len)
|
2007-07-05 16:01:41 +00:00
|
|
|
size <<= 1;
|
|
|
|
|
2007-09-27 14:28:26 +00:00
|
|
|
line->data = xrealloc(line->data, size);
|
2007-07-05 16:01:41 +00:00
|
|
|
return line;
|
|
|
|
}
|
|
|
|
|
2007-07-05 16:02:10 +00:00
|
|
|
static int edit_read_file(const char *path)
|
2007-07-05 16:01:41 +00:00
|
|
|
{
|
|
|
|
struct line *line;
|
|
|
|
struct line *lastline = NULL;
|
2007-07-05 16:02:10 +00:00
|
|
|
char *filebuffer;
|
2007-07-13 18:42:18 +00:00
|
|
|
char *linestr, *lineend;
|
2007-07-05 16:02:10 +00:00
|
|
|
struct stat s;
|
|
|
|
|
|
|
|
if (!stat(path, &s)) {
|
2007-09-27 14:33:35 +00:00
|
|
|
filebuffer = read_file(path, NULL);
|
2007-07-05 16:02:10 +00:00
|
|
|
if (!filebuffer) {
|
|
|
|
printf("could not read %s: %s\n", path, errno_str());
|
|
|
|
return -1;
|
|
|
|
}
|
2007-07-05 16:01:41 +00:00
|
|
|
|
2007-07-13 18:42:18 +00:00
|
|
|
linestr = filebuffer;
|
|
|
|
while (1) {
|
|
|
|
if (!*linestr)
|
|
|
|
break;
|
|
|
|
|
|
|
|
lineend = strchr(linestr, '\n');
|
|
|
|
|
|
|
|
if (!lineend && !*linestr)
|
|
|
|
break;
|
|
|
|
|
2007-09-13 10:56:29 +00:00
|
|
|
if (lineend)
|
|
|
|
*lineend = 0;
|
|
|
|
|
2007-07-05 16:02:10 +00:00
|
|
|
line = line_realloc(strlen(linestr) + 1, NULL);
|
|
|
|
if (!buffer)
|
|
|
|
buffer = line;
|
|
|
|
memcpy(line->data, linestr, strlen(linestr) + 1);
|
|
|
|
line->prev = lastline;
|
|
|
|
if (lastline)
|
|
|
|
lastline->next = line;
|
2010-10-15 06:23:14 +00:00
|
|
|
line->next = NULL;
|
2007-07-05 16:02:10 +00:00
|
|
|
lastline = line;
|
2007-07-13 18:42:18 +00:00
|
|
|
|
|
|
|
if (!lineend)
|
|
|
|
break;
|
|
|
|
|
2008-04-04 09:46:55 +00:00
|
|
|
linestr = lineend + 1;
|
2007-07-05 16:01:41 +00:00
|
|
|
}
|
2007-07-13 18:42:18 +00:00
|
|
|
free(filebuffer);
|
2007-07-05 16:01:41 +00:00
|
|
|
}
|
|
|
|
|
2007-07-05 16:01:42 +00:00
|
|
|
if (!buffer) {
|
|
|
|
buffer = line_realloc(0, NULL);
|
|
|
|
buffer->data[0] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-07-13 18:42:18 +00:00
|
|
|
static void free_buffer(void)
|
|
|
|
{
|
|
|
|
struct line *line, *tmp;
|
|
|
|
|
|
|
|
line = buffer;
|
|
|
|
|
|
|
|
while(line) {
|
|
|
|
tmp = line->next;
|
|
|
|
line_free(line);
|
|
|
|
line = tmp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-05 16:01:42 +00:00
|
|
|
static int save_file(const char *path)
|
|
|
|
{
|
|
|
|
struct line *line, *tmp;
|
2007-07-05 16:02:10 +00:00
|
|
|
int fd;
|
2007-07-05 16:01:42 +00:00
|
|
|
|
2007-07-05 16:02:10 +00:00
|
|
|
fd = open(path, O_WRONLY | O_TRUNC | O_CREAT);
|
|
|
|
if (fd < 0) {
|
|
|
|
printf("could not open file for writing: %s\n", errno_str());
|
2014-02-07 08:48:44 +00:00
|
|
|
return fd;
|
2007-07-05 16:02:10 +00:00
|
|
|
}
|
2007-07-05 16:01:42 +00:00
|
|
|
|
|
|
|
line = buffer;
|
|
|
|
|
|
|
|
while(line) {
|
|
|
|
tmp = line->next;
|
2007-07-05 16:02:10 +00:00
|
|
|
write(fd, line->data, strlen(line->data));
|
|
|
|
write(fd, "\n", 1);
|
2007-07-05 16:01:42 +00:00
|
|
|
line = tmp;
|
|
|
|
}
|
2007-07-05 16:02:10 +00:00
|
|
|
close(fd);
|
2007-07-05 16:01:41 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void insert_char(char c)
|
|
|
|
{
|
|
|
|
int pos = textx;
|
2007-09-27 14:27:20 +00:00
|
|
|
char *line;
|
|
|
|
int end = strlen(curline->data);
|
2007-07-05 16:01:41 +00:00
|
|
|
|
|
|
|
line_realloc(strlen(curline->data) + 2, curline);
|
2007-09-27 14:27:20 +00:00
|
|
|
line = curline->data;
|
2007-07-05 16:01:41 +00:00
|
|
|
|
|
|
|
while (end >= pos) {
|
|
|
|
line[end + 1] = line[end];
|
|
|
|
end--;
|
|
|
|
}
|
|
|
|
line[pos] = c;
|
|
|
|
textx++;
|
|
|
|
refresh_line(curline, cursy);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void delete_char(int pos)
|
|
|
|
{
|
|
|
|
char *line = curline->data;
|
|
|
|
int end = strlen(line);
|
|
|
|
|
|
|
|
while (pos < end) {
|
|
|
|
line[pos] = line[pos + 1];
|
|
|
|
pos++;
|
|
|
|
}
|
|
|
|
refresh_line(curline, cursy);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void split_line(void)
|
|
|
|
{
|
|
|
|
int length = strlen(curline->data + textx);
|
|
|
|
struct line *newline = line_realloc(length + 1, NULL);
|
|
|
|
struct line *tmp;
|
|
|
|
|
|
|
|
memcpy(newline->data, curline->data + textx, length + 1);
|
|
|
|
|
|
|
|
curline->data[textx] = 0;
|
|
|
|
|
|
|
|
tmp = curline->next;
|
|
|
|
curline->next = newline;
|
|
|
|
newline->prev = curline;
|
|
|
|
newline->next = tmp;
|
|
|
|
if (tmp)
|
|
|
|
tmp->prev = newline;
|
|
|
|
|
|
|
|
textx = 0;
|
|
|
|
cursy++;
|
|
|
|
curline = curline->next;
|
|
|
|
refresh(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void merge_line(struct line *line)
|
|
|
|
{
|
|
|
|
struct line *tmp;
|
|
|
|
|
|
|
|
line_realloc(strlen(line->data) + strlen(line->next->data) + 1, line);
|
|
|
|
|
|
|
|
tmp = line->next;
|
|
|
|
|
|
|
|
line->next = line->next->next;
|
|
|
|
if (line->next)
|
|
|
|
line->next->prev = line;
|
|
|
|
strcat(line->data, tmp->data);
|
|
|
|
|
|
|
|
line_free(tmp);
|
|
|
|
|
|
|
|
refresh(1);
|
|
|
|
}
|
|
|
|
|
2011-12-05 16:52:52 +00:00
|
|
|
#define ESC "\033"
|
2007-07-05 16:01:42 +00:00
|
|
|
|
2011-12-05 16:52:52 +00:00
|
|
|
static void getwinsize(void)
|
|
|
|
{
|
|
|
|
int i = 0, r;
|
2007-07-05 16:01:41 +00:00
|
|
|
char buf[100];
|
|
|
|
char *endp;
|
|
|
|
|
2011-12-05 16:52:52 +00:00
|
|
|
printf(ESC "7" ESC "[r" ESC "[999;999H" ESC "[6n");
|
|
|
|
|
|
|
|
while ((r = getc()) != 'R') {
|
|
|
|
buf[i] = r;
|
|
|
|
i++;
|
2007-07-05 16:01:41 +00:00
|
|
|
}
|
2011-12-05 16:52:52 +00:00
|
|
|
|
|
|
|
screenheight = simple_strtoul(buf + 2, &endp, 10);
|
|
|
|
screenwidth = simple_strtoul(endp + 1, NULL, 10);
|
|
|
|
|
|
|
|
pos(0, 0);
|
2007-07-05 16:01:41 +00:00
|
|
|
}
|
|
|
|
|
2011-12-21 13:18:57 +00:00
|
|
|
static int do_edit(int argc, char *argv[])
|
2007-07-05 16:01:41 +00:00
|
|
|
{
|
|
|
|
int lastscrcol;
|
|
|
|
int i;
|
|
|
|
int linepos;
|
2009-12-18 10:26:12 +00:00
|
|
|
int c;
|
2007-07-05 16:01:41 +00:00
|
|
|
|
2009-10-17 10:44:19 +00:00
|
|
|
if (argc != 2)
|
|
|
|
return COMMAND_ERROR_USAGE;
|
2007-10-04 10:38:40 +00:00
|
|
|
|
2011-12-05 16:52:52 +00:00
|
|
|
screenwidth = 80;
|
2014-07-07 16:07:11 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The EFI simple text output protocol wraps to the next line and scrolls
|
|
|
|
* down when we write to the right bottom screen position. Reduce the number
|
|
|
|
* of rows by one to work around this.
|
|
|
|
*/
|
|
|
|
if (IS_ENABLED(CONFIG_ARCH_EFI))
|
|
|
|
screenheight = 24;
|
|
|
|
else
|
|
|
|
screenheight = 25;
|
2011-12-05 16:52:52 +00:00
|
|
|
|
2010-07-01 14:59:22 +00:00
|
|
|
/* check if we are called as "sedit" instead of "edit" */
|
2011-12-05 16:52:52 +00:00
|
|
|
if (*argv[0] == 's') {
|
2007-10-16 20:35:42 +00:00
|
|
|
smartscroll = 1;
|
2011-12-05 16:52:52 +00:00
|
|
|
getwinsize();
|
|
|
|
}
|
2007-10-16 20:35:42 +00:00
|
|
|
|
2007-07-05 16:01:41 +00:00
|
|
|
buffer = NULL;
|
2007-07-05 16:02:10 +00:00
|
|
|
if(edit_read_file(argv[1]))
|
2007-07-05 16:01:42 +00:00
|
|
|
return 1;
|
|
|
|
|
2007-07-05 16:01:41 +00:00
|
|
|
cursx = 0;
|
|
|
|
cursy = 0;
|
|
|
|
textx = 0;
|
|
|
|
scrcol = 0;
|
|
|
|
curline = buffer;
|
|
|
|
scrline = curline;
|
|
|
|
lastscrline = scrline;
|
|
|
|
lastscrcol = 0;
|
|
|
|
|
|
|
|
printf("%c[2J", 27);
|
2012-05-16 06:20:06 +00:00
|
|
|
|
|
|
|
pos(0, -1);
|
|
|
|
|
|
|
|
printf("%c[7m %-25s <ctrl-d>: Save and quit <ctrl-c>: quit %c[0m",
|
|
|
|
27, argv[1], 27);
|
|
|
|
printf("%c[2;%dr", 27, screenheight);
|
|
|
|
|
|
|
|
screenheight--; /* status line */
|
|
|
|
|
|
|
|
pos(0, 0);
|
|
|
|
|
2007-07-05 16:01:41 +00:00
|
|
|
refresh(1);
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
int curlen = strlen(curline->data);
|
|
|
|
|
|
|
|
if (textx > curlen)
|
|
|
|
textx = curlen;
|
2012-05-16 06:20:06 +00:00
|
|
|
if (textx < 1)
|
2007-07-05 16:01:41 +00:00
|
|
|
textx = 0;
|
|
|
|
|
|
|
|
screenline(curline->data, &linepos);
|
|
|
|
|
|
|
|
if (linepos > scrcol + screenwidth)
|
|
|
|
scrcol = linepos - screenwidth;
|
|
|
|
|
|
|
|
if (scrcol > linepos)
|
|
|
|
scrcol = linepos;
|
|
|
|
|
|
|
|
cursx = linepos - scrcol;
|
|
|
|
|
|
|
|
while (cursy >= screenheight) {
|
|
|
|
cursy--;
|
|
|
|
scrline = scrline->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (cursy < 0) {
|
|
|
|
cursy++;
|
|
|
|
scrline = scrline->prev;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (scrline != lastscrline || scrcol != lastscrcol)
|
|
|
|
refresh(0);
|
|
|
|
|
|
|
|
lastscrcol = scrcol;
|
|
|
|
lastscrline = scrline;
|
|
|
|
pos(cursx, cursy);
|
|
|
|
|
2007-07-05 16:01:42 +00:00
|
|
|
c = read_key();
|
2007-07-05 16:01:41 +00:00
|
|
|
switch (c) {
|
2014-02-14 10:23:57 +00:00
|
|
|
case BB_KEY_UP:
|
2007-07-05 16:01:41 +00:00
|
|
|
if (!curline->prev)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
curline = curline->prev;
|
|
|
|
cursy--;
|
|
|
|
textx = setpos(curline->data, linepos);
|
|
|
|
break;
|
2014-02-14 10:23:57 +00:00
|
|
|
case BB_KEY_DOWN:
|
2007-07-05 16:01:41 +00:00
|
|
|
if (!curline->next)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
curline = curline->next;
|
|
|
|
cursy++;
|
|
|
|
textx = setpos(curline->data, linepos);
|
|
|
|
break;
|
2014-02-14 10:23:57 +00:00
|
|
|
case BB_KEY_RIGHT:
|
2007-07-05 16:01:41 +00:00
|
|
|
textx++;
|
|
|
|
break;
|
2014-02-14 10:23:57 +00:00
|
|
|
case BB_KEY_LEFT:
|
2007-07-05 16:01:41 +00:00
|
|
|
textx--;
|
|
|
|
break;
|
2014-02-14 10:23:57 +00:00
|
|
|
case BB_KEY_HOME:
|
2007-07-05 16:01:41 +00:00
|
|
|
textx = 0;
|
|
|
|
break;
|
2014-02-14 10:23:57 +00:00
|
|
|
case BB_KEY_END:
|
2007-07-05 16:01:41 +00:00
|
|
|
textx = curlen;
|
|
|
|
break;
|
2014-02-14 10:23:57 +00:00
|
|
|
case BB_KEY_PAGEUP:
|
2007-07-05 16:01:41 +00:00
|
|
|
for (i = 0; i < screenheight - 1; i++) {
|
|
|
|
if (!curline->prev)
|
|
|
|
break;
|
|
|
|
cursy--;
|
|
|
|
curline = curline->prev;
|
|
|
|
}
|
|
|
|
textx = setpos(curline->data, linepos);
|
|
|
|
break;
|
2014-02-14 10:23:57 +00:00
|
|
|
case BB_KEY_PAGEDOWN:
|
2007-07-05 16:01:41 +00:00
|
|
|
for (i = 0; i < screenheight - 1; i++) {
|
|
|
|
if (!curline->next)
|
|
|
|
break;
|
|
|
|
cursy++;
|
|
|
|
curline = curline->next;
|
|
|
|
}
|
|
|
|
textx = setpos(curline->data, linepos);
|
|
|
|
break;
|
2014-02-14 10:23:57 +00:00
|
|
|
case BB_KEY_DEL:
|
2007-07-05 16:01:41 +00:00
|
|
|
if (textx == curlen) {
|
|
|
|
if (curline->next)
|
|
|
|
merge_line(curline);
|
|
|
|
} else
|
|
|
|
delete_char(textx);
|
|
|
|
break;
|
|
|
|
case 13:
|
|
|
|
case 10:
|
|
|
|
split_line();
|
|
|
|
break;
|
|
|
|
case 127:
|
2007-10-04 16:36:24 +00:00
|
|
|
case 8:
|
2007-07-05 16:01:41 +00:00
|
|
|
if (textx > 0) {
|
|
|
|
textx--;
|
|
|
|
delete_char(textx);
|
|
|
|
} else {
|
|
|
|
if (!curline->prev)
|
|
|
|
break;
|
|
|
|
curline = curline->prev;
|
|
|
|
cursy--;
|
|
|
|
textx = strlen(curline->data);
|
|
|
|
merge_line(curline);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 4:
|
2007-07-05 16:01:42 +00:00
|
|
|
save_file(argv[1]);
|
2007-07-05 16:01:41 +00:00
|
|
|
goto out;
|
|
|
|
case 3:
|
|
|
|
goto out;
|
|
|
|
default:
|
|
|
|
if ((signed char)c != -1)
|
|
|
|
insert_char(c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
out:
|
2007-07-13 18:42:18 +00:00
|
|
|
free_buffer();
|
2012-05-16 06:20:06 +00:00
|
|
|
printf("%c[2J%c[r", 27, 27);
|
2007-07-13 18:42:18 +00:00
|
|
|
printf("\n");
|
2007-07-05 16:01:41 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-04-04 09:46:55 +00:00
|
|
|
static const char *edit_aliases[] = { "sedit", NULL};
|
2007-10-16 20:35:42 +00:00
|
|
|
|
2010-07-12 17:48:18 +00:00
|
|
|
BAREBOX_CMD_HELP_START(edit)
|
commands: harmonize in-barebox documentation
This patch does probably too much, but it's hard (and very
cumbersome/time consuming) to break it out. What is does is this:
* each command has one short description, e.g. "list MUX configuration"
* made sure the short descriptions start lowercase
* each command has one usage. That string contains just the
options, e.g. "[-npn]". It's not part of the long help text.
* that is, it doesn't say "[OPTIONS]" anymore, every usable option
is listed by character in this (short) option string (the long
description is in the long help text, as before)
* help texts have been reworked, to make them
- sometimes smaller
- sometimes describe the options better
- more often present themselves in a nicer format
* all long help texts are now created with BUSYBOX_CMD_HELP_
macros, no more 'static const __maybe_unused char cmd_foobar_help[]'
* made sure the long help texts starts uppercase
* because cmdtp->name and cmdtp->opts together provide the new usage,
all "Usage: foobar" texts have been removed from the long help texts
* BUSYBOX_CMD_HELP_TEXT() provides the trailing newline by itself, this
is nicer in the source code
* BUSYBOX_CMD_HELP_OPT() provides the trailing newline by itself
* made sure no line gets longer than 77 characters
* delibertely renamed cmdtp->usage, so that we can get compile-time
errors (e.g. in out-of-tree modules that use register_command()
* the 'help' command can now always emit the usage, even without
compiled long help texts
* 'help -v' gives a list of commands with their short description, this
is similar like the old "help" command before my patchset
* 'help -a' gives out help of all commands
Signed-off-by: Holger Schurig <holgerschurig@gmail.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2014-05-13 08:28:42 +00:00
|
|
|
BAREBOX_CMD_HELP_TEXT("Use cursor keys, Ctrl-C to exit and Ctrl-D to exit-with-save.")
|
2010-07-12 17:48:18 +00:00
|
|
|
BAREBOX_CMD_HELP_END
|
2007-07-05 16:01:57 +00:00
|
|
|
|
2009-12-15 08:11:09 +00:00
|
|
|
BAREBOX_CMD_START(edit)
|
2007-07-05 16:01:52 +00:00
|
|
|
.cmd = do_edit,
|
2007-10-16 20:35:42 +00:00
|
|
|
.aliases = edit_aliases,
|
commands: harmonize in-barebox documentation
This patch does probably too much, but it's hard (and very
cumbersome/time consuming) to break it out. What is does is this:
* each command has one short description, e.g. "list MUX configuration"
* made sure the short descriptions start lowercase
* each command has one usage. That string contains just the
options, e.g. "[-npn]". It's not part of the long help text.
* that is, it doesn't say "[OPTIONS]" anymore, every usable option
is listed by character in this (short) option string (the long
description is in the long help text, as before)
* help texts have been reworked, to make them
- sometimes smaller
- sometimes describe the options better
- more often present themselves in a nicer format
* all long help texts are now created with BUSYBOX_CMD_HELP_
macros, no more 'static const __maybe_unused char cmd_foobar_help[]'
* made sure the long help texts starts uppercase
* because cmdtp->name and cmdtp->opts together provide the new usage,
all "Usage: foobar" texts have been removed from the long help texts
* BUSYBOX_CMD_HELP_TEXT() provides the trailing newline by itself, this
is nicer in the source code
* BUSYBOX_CMD_HELP_OPT() provides the trailing newline by itself
* made sure no line gets longer than 77 characters
* delibertely renamed cmdtp->usage, so that we can get compile-time
errors (e.g. in out-of-tree modules that use register_command()
* the 'help' command can now always emit the usage, even without
compiled long help texts
* 'help -v' gives a list of commands with their short description, this
is similar like the old "help" command before my patchset
* 'help -a' gives out help of all commands
Signed-off-by: Holger Schurig <holgerschurig@gmail.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2014-05-13 08:28:42 +00:00
|
|
|
BAREBOX_CMD_DESC("a small full-screen editor")
|
|
|
|
BAREBOX_CMD_OPTS("FILE")
|
commands: group 'help' output
The old output of "help" was just producing a long list, that usually
scrolled of the screen (even on a X11 terminal). This list is more
compact, and also sorted by groups.
The old output format (plus grouping) is now available with 'help -v'.
Example:
Information commands:
?, devinfo, help, iomem, meminfo, version
Boot commands:
boot, bootm, go, loadb, loads, loadx, loady, saves, uimage
...
Signed-off-by: Holger Schurig <holgerschurig@gmail.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2014-05-13 14:14:05 +00:00
|
|
|
BAREBOX_CMD_GROUP(CMD_GRP_CONSOLE)
|
2009-12-15 08:11:09 +00:00
|
|
|
BAREBOX_CMD_HELP(cmd_edit_help)
|
|
|
|
BAREBOX_CMD_END
|