From 12e09f9f85ac48ff891adf92f3b2c9a5fea27273 Mon Sep 17 00:00:00 2001 From: Nicholas Noll Date: Sat, 4 Dec 2021 14:10:21 -0800 Subject: Chore(REMOVE): finished deprecation of old io functions. The old methods were simple wrappers of C standard library functions. We've moved (painfully) over to a new interface that allows for files to live on the stack. All users of the functionality are ported over. --- src/cmd/rc/input.c | 111 ++++++++++++++++++----------------------------------- 1 file changed, 37 insertions(+), 74 deletions(-) (limited to 'src/cmd/rc/input.c') diff --git a/src/cmd/rc/input.c b/src/cmd/rc/input.c index cc2383d..9771174 100644 --- a/src/cmd/rc/input.c +++ b/src/cmd/rc/input.c @@ -131,8 +131,7 @@ typedef struct typedef Position (*Noun)(struct TerminalState*, int); typedef void (*Verb)(struct TerminalState*, Position); -static -int +static int runetype(rune r) { if(r<128) @@ -147,23 +146,20 @@ runetype(rune r) return NonPrintable; } -static -void +static void normalcursor(int fd) { write(fd,"\e[2 q",5); } -static -void +static void insertcursor(int fd) { write(fd,"\e[6 q",5); } /* raw mode: 1960 magic shit. */ -static -int +static int enterraw(int fd) { struct termios raw; @@ -206,8 +202,7 @@ fatal: return 0; } -static -void +static void exitraw(int fd) { /* don't even check the return value as it's too late. */ @@ -218,8 +213,7 @@ exitraw(int fd) /* use the esc [6n escape sequence to query the horizontal cursor position * and return it. on error -1 is returned, on success the position of the * cursor. */ -static -int +static int cursorposition(int ifd, int ofd) { char buf[32]; @@ -250,8 +244,7 @@ cursorposition(int ifd, int ofd) } /* try to get the number of columns in the current terminal, or assume 80 if it fails. */ -static -int +static int columns(int ifd, int ofd) { struct winsize ws; @@ -287,8 +280,7 @@ failed: return 80; } -static -void +static void clear(void) { if(write(1,"\x1b[H\x1b[2J",7) <= 0) @@ -297,8 +289,7 @@ clear(void) /* beep: used for completion when there is nothing to complete or when all * the choices were already shown. */ -static -void +static void beep(void) { fprintf(stderr, "\x7"); @@ -335,8 +326,7 @@ addhistory(char *line) return 1; } -static -void +static void pophistory(void) { if(--history.top < history.entry) @@ -346,8 +336,7 @@ pophistory(void) static void refreshline(struct TerminalState *); -static -char ** +static char ** currenthistory(struct TerminalState *term, intptr *size) { char **entry; @@ -369,8 +358,7 @@ currenthistory(struct TerminalState *term, intptr *size) return entry; } -static -void +static void usehistory(struct TerminalState *term, int d) { rune r; @@ -423,16 +411,14 @@ struct Buffer char *b; }; -static -void +static void initbuffer(struct Buffer *ab) { ab->b = nil; ab->len = 0; } -static -void +static void append(struct Buffer *ab, const char *s, int len) { char *new = realloc(ab->b,ab->len+len); @@ -443,8 +429,7 @@ append(struct Buffer *ab, const char *s, int len) ab->len += len; } -static -void +static void freebuffer(struct Buffer *ab) { free(ab->b); @@ -454,8 +439,7 @@ freebuffer(struct Buffer *ab) * * rewrite the currently edited line accordingly to the buffer content, * cursor position, and number of columns of the terminal. */ -static -void +static void refreshsingleline(struct TerminalState *term) { char esc[64]; @@ -519,8 +503,7 @@ refreshsingleline(struct TerminalState *term) * * Rewrite the currently edited line accordingly to the buffer content, * cursor position, and number of columns of the terminal. */ -static -void +static void refreshmultilines(struct TerminalState *term) { #if 0 @@ -603,8 +586,7 @@ refreshmultilines(struct TerminalState *term) /* Calls the two low level functions refreshSingleLine() or * refreshMultiLine() according to the selected mode. */ -static -void +static void refreshline(struct TerminalState *term) { if(mode.multiline) @@ -695,16 +677,14 @@ insertbytes(struct TerminalState *term, int len, char *buf) /* modes */ -static -void +static void normalmode(int fd) { mode.vi.insert = 0; normalcursor(fd); } -static -void +static void insertmode(int fd) { mode.vi.insert = 1; @@ -713,8 +693,7 @@ insertmode(int fd) /* actions */ -static -void +static void move(struct TerminalState *term, Position to) { if(to.buffer != term->edit.pos){ @@ -724,8 +703,7 @@ move(struct TerminalState *term, Position to) } } -static -void +static void yank(struct TerminalState *term, Position to) { intptr len, off; @@ -751,8 +729,7 @@ yank(struct TerminalState *term, Position to) term->yank.buf[len] = 0; } -static -void +static void delete(struct TerminalState *term, Position to) { intptr diff; @@ -790,8 +767,7 @@ refresh: #define CURRENT(term) (Position){ .buffer=(term)->edit.pos, .cursor=(term)->cursor.pos }; // move cursor to the left n boxes -static -Position +static Position left(struct TerminalState *term, int n) { rune r; @@ -814,8 +790,7 @@ left(struct TerminalState *term, int n) } // move cursor to the right n boxes -static -Position +static Position right(struct TerminalState *term, int n) { rune r; @@ -839,8 +814,7 @@ right(struct TerminalState *term, int n) return pos; } -static -Position +static Position prevword(struct TerminalState *term, int n) { rune r; @@ -884,8 +858,7 @@ prevword(struct TerminalState *term, int n) return pos; } -static -Position +static Position nextword(struct TerminalState *term, int n) { rune r; @@ -932,8 +905,7 @@ nextword(struct TerminalState *term, int n) } -static -Position +static Position prevWord(struct TerminalState *term, int n) { rune r; @@ -977,8 +949,7 @@ prevWord(struct TerminalState *term, int n) return pos; } -static -Position +static Position nextWord(struct TerminalState *term, int n) { rune r; @@ -1023,8 +994,7 @@ nextWord(struct TerminalState *term, int n) return pos; } -static -Position +static Position nextend(struct TerminalState *term, int n) { rune r; @@ -1067,8 +1037,7 @@ nextend(struct TerminalState *term, int n) return pos; } -static -Position +static Position nextEnd(struct TerminalState *term, int n) { rune r; @@ -1116,8 +1085,7 @@ nextEnd(struct TerminalState *term, int n) #define HOME(term) (Position){0} #define END(term) (Position){(term)->edit.len, (term)->cursor.len} -static -int +static int vi(struct TerminalState *term, char c) { int n = 1; @@ -1269,8 +1237,7 @@ action: #define END(term) (Position){(term).edit.len, (term).cursor.len} -static -int +static int size(char *s) { rune c; @@ -1304,8 +1271,7 @@ size(char *s) * when ctrl+d is typed. * * the function returns the length of the current buffer. */ -static -int +static int interact(int ifd, int ofd, char *buf, intptr len, char *prompt) { int n, aux; @@ -1597,8 +1563,7 @@ printkeycode(void) /* * this function calls the line editing function edit() using the stdin set in raw mode */ -static -int +static int raw(char *buf, intptr len, char *prompt) { int n; @@ -1622,8 +1587,7 @@ raw(char *buf, intptr len, char *prompt) * program is called in pipe or with a file redirected to its standard input * in this case, we want to be able to return the line regardless of its length */ -static -int +static int notty(void) { int c; @@ -1670,8 +1634,7 @@ readline(char *prompt) } /* At exit we'll try to fix the terminal to the initial conditions. */ -static -void +static void doatexit(void) { exitraw(0); -- cgit v1.2.1