aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/rc
diff options
context:
space:
mode:
authorNicholas Noll <nbnoll@eml.cc>2021-12-05 15:17:44 -0800
committerNicholas Noll <nbnoll@eml.cc>2021-12-05 15:17:44 -0800
commitb48327d357e0818d1a6ae2a064cfa7d1567e1242 (patch)
tree4677f228a9846937a7ec71c72a1ab63ab69d68ab /src/cmd/rc
parentc200dd832789afa298ba45e0b9efdec96c0e92cc (diff)
feat(huge): huge refactor (in progress).
Commented out libc includes to uncover all explicit dependencies. A large fraction has now been ported over (no testing). I did not port over the command line tools, such as the rc shell. These will be done independently - as of now I just want the library to stand independent. Compilation currently fails due to the lack of math functions.
Diffstat (limited to 'src/cmd/rc')
-rw-r--r--src/cmd/rc/input.c47
-rw-r--r--src/cmd/rc/rc.h4
-rw-r--r--src/cmd/rc/util.c4
3 files changed, 34 insertions, 21 deletions
diff --git a/src/cmd/rc/input.c b/src/cmd/rc/input.c
index 9771174..f8bb2f9 100644
--- a/src/cmd/rc/input.c
+++ b/src/cmd/rc/input.c
@@ -119,7 +119,7 @@ enum
KeyBackspace = 127 /* Backspace */
};
-static void doatexit(void);
+static void doatexit(void*);
/* vi operations */
typedef struct
@@ -149,13 +149,15 @@ runetype(rune r)
static void
normalcursor(int fd)
{
- write(fd,"\e[2 q",5);
+ intptr x;
+ sys·write(fd,"\e[2 q",5,&x);
}
static void
insertcursor(int fd)
{
- write(fd,"\e[6 q",5);
+ intptr x;
+ sys·write(fd,"\e[6 q",5,&x);
}
/* raw mode: 1960 magic shit. */
@@ -168,7 +170,7 @@ enterraw(int fd)
goto fatal;
if(!mode.defer){
- atexit(doatexit);
+ rt·atexit(doatexit,nil);
mode.defer = 1;
}
if(tcgetattr(fd,&originalterm) == -1)
@@ -198,7 +200,7 @@ enterraw(int fd)
return 1;
fatal:
- errno = ENOTTY;
+ /* errno = ENOTTY; */
return 0;
}
@@ -216,17 +218,18 @@ exitraw(int fd)
static int
cursorposition(int ifd, int ofd)
{
- char buf[32];
+ char *b,buf[32];
int cols, rows;
+ intptr n;
unsigned int i = 0;
/* Report cursor location */
- if(write(ofd, "\x1b[6n", 4) != 4)
+ if(sys·write(ofd, "\x1b[6n", 4, &n) || n != 4)
return -1;
/* Read the response: ESC [ rows ; cols R */
while(i < sizeof(buf)-1) {
- if(read(ifd,buf+i,1) != 1)
+ if(sys·read(ifd,buf+i,1, &n) || n != 1)
break;
if(buf[i] == 'R')
break;
@@ -237,8 +240,12 @@ cursorposition(int ifd, int ofd)
/* Parse it. */
if(buf[0] != KeyEsc || buf[1] != '[')
return -1;
- if(sscanf(buf+2,"%d;%d",&rows,&cols) != 2)
- return -1;
+ b=buf+2;
+ while(*b != ';')
+ b++;
+ *b=0;
+ rows = str·atoi(buf+2);
+ cols = str·atoi(b+1);
return cols;
}
@@ -247,6 +254,7 @@ cursorposition(int ifd, int ofd)
static int
columns(int ifd, int ofd)
{
+ intptr n;
struct winsize ws;
if(ioctl(1, TIOCGWINSZ, &ws) == -1 || ws.ws_col == 0){
@@ -259,7 +267,7 @@ columns(int ifd, int ofd)
goto failed;
/* Go to right margin and get position. */
- if(write(ofd,"\x1b[999C",6) != 6)
+ if(sys·write(ofd,"\x1b[999C",6,&n) || n != 6)
goto failed;
cols = cursorposition(ifd,ofd);
if(cols == -1)
@@ -268,8 +276,8 @@ columns(int ifd, int ofd)
/* Restore position. */
if(cols > start){
char esc[32];
- snprintf(esc,32,"\x1b[%dD",cols-start);
- if(write(ofd,esc,strlen(esc)) == -1)
+ fmt·nsprint(esc,32,"\x1b[%dD",cols-start);
+ if(sys·write(ofd,esc,str·len(esc),&n))
;
}
return cols;
@@ -283,7 +291,8 @@ failed:
static void
clear(void)
{
- if(write(1,"\x1b[H\x1b[2J",7) <= 0)
+ intptr n;
+ if(sys·write(1,"\x1b[H\x1b[2J",7,&n))
;
}
@@ -292,8 +301,8 @@ clear(void)
static void
beep(void)
{
- fprintf(stderr, "\x7");
- fflush(stderr);
+ fmt·fprint(sys·Stderr, "\x7");
+ /* fmt·flush(stderr); */
}
// -----------------------------------------------------------------------
@@ -1347,7 +1356,7 @@ interact(int ifd, int ofd, char *buf, intptr len, char *prompt)
goto finish;
case KeyCtrlC:
- errno = EAGAIN;
+ /* errno = EAGAIN; */
return -1;
case KeyBackspace:
@@ -1569,7 +1578,7 @@ raw(char *buf, intptr len, char *prompt)
int n;
if(!len){
- errno = EINVAL;
+ /* errno = EINVAL; */
return -1;
}
@@ -1635,7 +1644,7 @@ readline(char *prompt)
/* At exit we'll try to fix the terminal to the initial conditions. */
static void
-doatexit(void)
+doatexit(void *_)
{
exitraw(0);
normalcursor(1);
diff --git a/src/cmd/rc/rc.h b/src/cmd/rc/rc.h
index 76a1b3d..67d10a4 100644
--- a/src/cmd/rc/rc.h
+++ b/src/cmd/rc/rc.h
@@ -4,6 +4,10 @@
#include <base.h>
#include <base/utf.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
// -----------------------------------------------------------------------
// types
diff --git a/src/cmd/rc/util.c b/src/cmd/rc/util.c
index b0be788..0949377 100644
--- a/src/cmd/rc/util.c
+++ b/src/cmd/rc/util.c
@@ -4,7 +4,7 @@ void
fatal(char *msg, ...)
{
va_list args;
- vfprintf(stderr, msg, args);
+ fmt·fprint(sys·Stderr, msg, args);
va_end(args);
abort();
@@ -17,7 +17,7 @@ emalloc(uintptr n)
if(!(p = malloc(n)))
fatal("out of memory: can't allocate %d bytes", n);
- memset(p, 0, n);
+ mem·set(p, n, 0);
return p;
}