Compare commits

..

33 Commits

Author SHA1 Message Date
Jonas 'Sortie' Termansen f026f3ae43 Add kernel(7) --firmware option. 2023-12-26 12:48:11 +01:00
Jonas 'Sortie' Termansen 6ba8da83c3 Add fatfs(8). 2023-12-26 12:48:11 +01:00
Jonas 'Sortie' Termansen 96a8bae02d Add dosfstools port. 2023-12-26 12:48:11 +01:00
Jonas 'Sortie' Termansen cc791a45d2 Add mtools port. 2023-12-26 12:48:11 +01:00
Jonas 'Sortie' Termansen 8a89ca543c Add getty(8). 2023-12-26 12:48:11 +01:00
Jonas 'Sortie' Termansen deff2b660e Add terminal and interrupt support to com(4). 2023-12-26 12:48:11 +01:00
Jonas 'Sortie' Termansen ed4d8d4840 Add nyan(1). 2023-12-26 12:48:11 +01:00
Jonas 'Sortie' Termansen 9345e7e625 Work around pty deadlock. 2023-12-26 12:48:11 +01:00
Jonas 'Sortie' Termansen 23872323e9 Add cdrom mounting live environment. 2023-12-26 12:48:11 +01:00
Jonas 'Sortie' Termansen 3722f22beb Revert "Parallelize driver initialization."
This reverts commit 0fef08bbc4.
2023-12-26 12:48:11 +01:00
Jonas 'Sortie' Termansen bebe8c2b00 Parallelize driver initialization. 2023-12-26 12:48:11 +01:00
Jonas 'Sortie' Termansen 49d7aa16ad Speed up ata(4) 400 ns waits.
Waiting for any non-zero duration currently waits for at least one timer
cycle (10 ms), which is especially expensive during early boot.

The current workaround of simply reading the status 14 times seems really
suspicious although the osdev wiki documents it, but let's see how well it
works on real hardware, it's probably good enough.

Try to determine the initial selected drive to save one drive selection.
2023-12-26 12:48:11 +01:00
Jonas 'Sortie' Termansen 9d0fba9377 Decrease PS/2 timeouts. 2023-12-26 12:48:11 +01:00
Jonas 'Sortie' Termansen 4a3b4b4495 Add uptime(1) -pr options. 2023-12-26 12:48:11 +01:00
Jonas 'Sortie' Termansen 578ffb9624 Revert "Update to bison-3.8.2."
This reverts commit b82fae810b42c5426d21c4dc153b32f086dd7fde.
2023-12-26 12:48:11 +01:00
Jonas 'Sortie' Termansen 80f3883f4d Update to bison-3.8.2. 2023-12-26 12:48:11 +01:00
Jonas 'Sortie' Termansen 113099a273 Add iso9660 filesystem implementation. 2023-12-26 12:48:11 +01:00
Jonas 'Sortie' Termansen a6778c8f04 Add kernel virtual address space usage debug information. 2023-12-26 12:48:10 +01:00
Jonas 'Sortie' Termansen 696f264078 Debug TCP socket state listing. 2023-12-26 12:48:10 +01:00
Jonas 'Sortie' Termansen a748ab4079 Add kernel heap allocation tracing debug facility. 2023-12-26 12:48:10 +01:00
Jonas 'Sortie' Termansen 15992bc42d Trianglix 4. 2023-12-26 12:48:10 +01:00
Jonas 'Sortie' Termansen be1cde7f0c Add tix-check(8). 2023-12-26 12:48:10 +01:00
Jonas 'Sortie' Termansen e40292c13b Volatile release. 2023-12-26 12:48:10 +01:00
Jonas 'Sortie' Termansen 483c401fa5 Add tix-upgrade(8). 2023-12-26 12:48:10 +01:00
Jonas 'Sortie' Termansen 8a34189750 Add tix-repository(8).
Support renaming, splitting, and deleting ports via RENAMES.
2023-12-26 12:48:10 +01:00
Jonas 'Sortie' Termansen 5e8bcb23e2 Add signify port. 2023-12-26 12:48:10 +01:00
Jonas 'Sortie' Termansen b992d6f6ab Add pty(1). 2023-12-26 12:48:10 +01:00
Jonas 'Sortie' Termansen 58a9b51e40 Add irc(1).
Co-authored-by: Juhani Krekelä <juhani@krekelä.fi>
2023-12-26 12:48:10 +01:00
Jonas 'Sortie' Termansen e65b8e6e67 Add getaddrinfo(1). 2023-12-26 12:48:10 +01:00
Jonas 'Sortie' Termansen 6b5e225a13 Enable stack smash protection by default. 2023-12-26 12:48:10 +01:00
Jonas 'Sortie' Termansen febaec3d81 Enable undefined behavior sanitization by default. 2023-12-26 12:48:10 +01:00
Juhani Krekelä 7d1087ed83 Add irssi port. 2023-12-26 03:26:11 +02:00
Juhani Krekelä 1c5a396e80 Support CSI n L and CSI n M in console and terminal(1).
With these escapes supported, include definitions for line deletion
(dl1, dl) and insertion (il1, il) in terminfo for "sortix".
2023-12-26 02:20:08 +02:00
14 changed files with 379 additions and 20 deletions

View File

@ -2186,9 +2186,9 @@ static void on_mkpart(size_t argc, char** argv)
}
const char* mkfs_argv[] =
{
"mformat",
"mkfs.fat",
"-F", // TODO: Force FAT32 until FAT12/16 root dir writing is added.
"-i",
"32",
p->path,
NULL
};

View File

@ -459,12 +459,12 @@ Inode* Inode::Open(const char* elem, int flags, mode_t mode)
memset(block->block_data, 0, filesystem->bytes_per_sector);
struct fat_dirent* dirent = (struct fat_dirent*) block->block_data;
// TODO: Mirror modified times in here.
memcpy(dirent->name, ".", 1);
memcpy(dirent->name, ". ", 11);
dirent->attributes = attributes;
dirent->cluster_high = htole16(inode_id >> 16);
dirent->cluster_low = htole16(inode_id & 0xFFFF);
dirent++;
memcpy(dirent->name, "..", 2);
memcpy(dirent->name, ".. ", 11);
dirent->attributes = FAT_ATTRIBUTE_DIRECTORY;
if ( this->inode_id == filesystem->root_inode_id )
{

View File

@ -3101,7 +3101,9 @@ static bool fsck(struct filesystem* fs)
if ( pid == 0 )
{
uninstall_signal_handler();
execlp(fs->fsck, fs->fsck, "-fp", "--", bdev_path, (const char*) NULL);
// TODO: Move to libmount abstraction.
const char* options = !strcmp(fs->fstype_name, "ext2") ? "-fp" : "-p";
execlp(fs->fsck, fs->fsck, options, "--", bdev_path, (const char*) NULL);
warning("%s: Failed to load filesystem checker: %s: %m",
bdev_path, fs->fsck);
_exit(127);

View File

@ -1,5 +1,6 @@
/*
* Copyright (c) 2011, 2012, 2013, 2014, 2015, 2016 Jonas 'Sortie' Termansen.
* Copyright (c) 2023 Juhani 'nortti' Krekelä.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@ -659,8 +660,42 @@ void TextTerminal::RunAnsiCommand(TextBuffer* textbuf, char c)
uint32_t fillbg = attr & ATTR_INVERSE ? fgcolor : bgcolor;
textbuf->Fill(from, to, TextChar(' ', vgacolor, 0, fillfg, fillbg));
} break;
// TODO: CSI Ps M Delete Ps Line(s) (default = 1) (DL).
// (delete those lines and move the rest of the lines upwards).
case 'L': // Append lines before current line.
{
column = 0;
unsigned lines = 0 < ansiusedparams ? ansiparams[0] : 1;
if ( height < line + lines )
lines = height - line;
TextPos from(0, line);
TextPos move_to(0, line + lines);
unsigned move_lines = height - line - lines;
textbuf->Move(move_to, from, move_lines * width);
if ( 0 < lines )
{
TextPos fill_to(width - 1, line + lines - 1);
uint32_t fill_fg = attr & ATTR_INVERSE ? bgcolor : fgcolor;
uint32_t fill_bg = attr & ATTR_INVERSE ? fgcolor : bgcolor;
TextChar fill_char(' ', vgacolor, 0, fill_fg, fill_bg);
textbuf->Fill(from, fill_to, fill_char);
}
} break;
case 'M': // Delete lines starting from beginning of current line.
{
column = 0;
unsigned lines = 0 < ansiusedparams ? ansiparams[0] : 1;
if ( height < line + lines )
lines = height - line;
TextPos move_from(0, line + lines);
TextPos move_to(0, line);
unsigned move_lines = height - line - lines;
textbuf->Move(move_to, move_from, move_lines * width);
TextPos fill_from(0, height - lines);
TextPos fill_to(width - 1, height - 1);
uint32_t fill_fg = attr & ATTR_INVERSE ? bgcolor : fgcolor;
uint32_t fill_bg = attr & ATTR_INVERSE ? fgcolor : bgcolor;
TextChar fill_char(' ', vgacolor, 0, fill_fg, fill_bg);
textbuf->Fill(fill_from, fill_to, fill_char);
} break;
// TODO: CSI Ps P Delete Ps Character(s) (default = 1) (DCH).
// (delete those characters and move the rest of the line leftward).
case 'S': // Scroll a line up and place a new line at the buttom.

View File

@ -43,10 +43,8 @@ static bool fat_probe(struct blockdevice* bdev,
(void) amount;
// TODO: Relax restriction that this must be a partition? At least for non-EFI.
struct partition* p = bdev->p;
if ( !p )
return false;
// TODO: Test for a space padded FAT32 at 0x52 + 8 bytes.
if ( p->table_type == PARTITION_TABLE_TYPE_GPT )
if ( p && p->table_type == PARTITION_TABLE_TYPE_GPT )
{
unsigned char bdp_uuid[16];
uuid_from_string(bdp_uuid, BDP_GPT_TYPE_UUID);
@ -56,7 +54,7 @@ static bool fat_probe(struct blockdevice* bdev,
return memcmp(p->gpt_type_guid, bdp_uuid, 16) == 0 ||
memcmp(p->gpt_type_guid, esp_uuid, 16) == 0;
}
if ( p->table_type == PARTITION_TABLE_TYPE_MBR )
else if ( p && p->table_type == PARTITION_TABLE_TYPE_MBR )
return p->mbr_system_id == 0x01 ||
p->mbr_system_id == 0x04 ||
p->mbr_system_id == 0x06 ||
@ -67,6 +65,20 @@ static bool fat_probe(struct blockdevice* bdev,
return false;
}
static bool fat_is_esp(struct blockdevice* bdev)
{
struct partition* p = bdev->p;
if ( p->table_type == PARTITION_TABLE_TYPE_GPT )
{
unsigned char esp_uuid[16];
uuid_from_string(esp_uuid, ESP_GPT_TYPE_UUID);
return memcmp(p->gpt_type_guid, esp_uuid, 16) == 0;
}
else if ( p->table_type == PARTITION_TABLE_TYPE_MBR )
return p->mbr_system_id == 0xEF;
return false;
}
static void fat_release(struct filesystem* fs)
{
if ( !fs )
@ -87,9 +99,8 @@ static enum filesystem_error fat_inspect(struct filesystem** fs_ptr,
unsigned char vbr[512];
if ( blockdevice_preadall(bdev, vbr, sizeof(vbr), 0) != sizeof(vbr) )
return fat_release(fs), FILESYSTEM_ERROR_ERRNO;
// TODO: Report efi instead if ESP.
fs->fstype_name = "fat";
// TODO: Port a fat fsck.
fs->fstype_name = fat_is_esp(fs->bdev) ? "efi": "fat";
fs->fsck = "fsck.fat";
fs->driver = "fatfs";
fs->flags |= FILESYSTEM_FLAG_UUID;
// Use the serial number + label as the UUID.

View File

@ -0,0 +1,43 @@
diff -Paur --no-dereference -- dosfstools.upstream/src/blkdev/blkdev.c dosfstools/src/blkdev/blkdev.c
--- dosfstools.upstream/src/blkdev/blkdev.c
+++ dosfstools/src/blkdev/blkdev.c
@@ -7,7 +7,6 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
-#include <sys/sysmacros.h>
#include <unistd.h>
#include <stdint.h>
#include <stdio.h>
diff -Paur --no-dereference -- dosfstools.upstream/src/common.c dosfstools/src/common.c
--- dosfstools.upstream/src/common.c
+++ dosfstools/src/common.c
@@ -297,16 +297,7 @@
uint32_t generate_volume_id(void)
{
- struct timeval now;
-
- if (gettimeofday(&now, NULL) != 0 || now.tv_sec == (time_t)-1 || now.tv_sec < 0) {
- srand(getpid());
- /* rand() returns int from [0,RAND_MAX], therefore only 31 bits */
- return (((uint32_t)(rand() & 0xFFFF)) << 16) | ((uint32_t)(rand() & 0xFFFF));
- }
-
- /* volume ID = current time, fudged for more uniqueness */
- return ((uint32_t)now.tv_sec << 20) | (uint32_t)now.tv_usec;
+ return arc4random();
}
/*
diff -Paur --no-dereference -- dosfstools.upstream/src/device_info.c dosfstools/src/device_info.c
--- dosfstools.upstream/src/device_info.c
+++ dosfstools/src/device_info.c
@@ -24,7 +24,6 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
-#include <sys/sysmacros.h>
#ifdef HAVE_LINUX_LOOP_H
#include <linux/loop.h>

View File

@ -0,0 +1,12 @@
NAME=dosfstools
BUILD_LIBRARIES=libiconv?
VERSION=4.2
DISTNAME=$NAME-$VERSION
COMPRESSION=tar.gz
ARCHIVE=$DISTNAME.$COMPRESSION
SHA256SUM=64926eebf90092dca21b14259a5301b7b98e7b1943e8a201c7d726084809b527
UPSTREAM_SITE=https://github.com/dosfstools/dosfstools/releases/download/v$VERSION
UPSTREAM_ARCHIVE=$ARCHIVE
LICENSE=GPL-3.0-or-later
BUILD_SYSTEM=configure
DEVELOPMENT=true

152
ports/irssi/irssi.patch Normal file
View File

@ -0,0 +1,152 @@
diff -Paur --no-dereference -- irssi.upstream/Makefile.in irssi/Makefile.in
--- irssi.upstream/Makefile.in
+++ irssi/Makefile.in
@@ -941,7 +941,8 @@
info-am:
-install-data-am: install-confDATA install-pkgconfigDATA \
+# PATCH: Don't install /etc/irssi.conf. Same configuration is built-in.
+install-data-am: install-pkgconfigDATA \
install-pkgincludeHEADERS
install-dvi: install-dvi-recursive
diff -Paur --no-dereference -- irssi.upstream/src/core/log.c irssi/src/core/log.c
--- irssi.upstream/src/core/log.c
+++ irssi/src/core/log.c
@@ -101,7 +101,10 @@
int log_start_logging(LOG_REC *log)
{
char *dir;
+/* PATCH: Sortix doesn't implement flock */
+#ifndef __sortix__
struct flock lock;
+#endif
g_return_val_if_fail(log != NULL, FALSE);
@@ -139,6 +142,8 @@
log->failed = TRUE;
return FALSE;
}
+/* PATCH: Sortix doesn't implement flock */
+#ifndef __sortix__
memset(&lock, 0, sizeof(lock));
lock.l_type = F_WRLCK;
if (fcntl(log->handle, F_SETLK, &lock) == -1 && errno == EACCES) {
@@ -148,6 +153,7 @@
log->failed = TRUE;
return FALSE;
}
+#endif
lseek(log->handle, 0, SEEK_END);
log->opened = log->last = time(NULL);
@@ -162,7 +168,10 @@
void log_stop_logging(LOG_REC *log)
{
+/* PATCH: Sortix doesn't implement flock */
+#ifndef __sortix__
struct flock lock;
+#endif
g_return_if_fail(log != NULL);
@@ -175,9 +184,12 @@
settings_get_str("log_close_string"),
"\n", time(NULL));
+/* PATCH: Sortix doesn't implement flock */
+#ifndef __sortix__
memset(&lock, 0, sizeof(lock));
lock.l_type = F_UNLCK;
fcntl(log->handle, F_SETLK, &lock);
+#endif
write_buffer_flush();
close(log->handle);
diff -Paur --no-dereference -- irssi.upstream/src/core/net-disconnect.c irssi/src/core/net-disconnect.c
--- irssi.upstream/src/core/net-disconnect.c
+++ irssi/src/core/net-disconnect.c
@@ -18,6 +18,8 @@
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
+#include <sys/select.h>
+
#include "module.h"
#include <irssi/src/core/network.h>
diff -Paur --no-dereference -- irssi.upstream/src/core/network.c irssi/src/core/network.c
--- irssi.upstream/src/core/network.c
+++ irssi/src/core/network.c
@@ -501,16 +501,8 @@
} else {
/* IPv4 */
ip->family = AF_INET;
-#ifdef HAVE_INET_ATON
- if (inet_aton(host, &ip->ip.s_addr) == 0)
+ if (inet_pton(AF_INET, host, &ip->ip) == 0)
return -1;
-#else
- addr = inet_addr(host);
- if (addr == INADDR_NONE)
- return -1;
-
- memcpy(&ip->ip, &addr, 4);
-#endif
}
return 0;
diff -Paur --no-dereference -- irssi.upstream/src/core/network.h irssi/src/core/network.h
--- irssi.upstream/src/core/network.h
+++ irssi/src/core/network.h
@@ -11,6 +11,11 @@
# include <netdb.h>
# include <arpa/inet.h>
+/* PATCH: Sortix netdb.h does not define HOST_NOT_FOUND */
+#ifndef HOST_NOT_FOUND
+#define HOST_NOT_FOUND 1
+#endif
+
#ifndef AF_INET6
# ifdef PF_INET6
# define AF_INET6 PF_INET6
diff -Paur --no-dereference -- irssi.upstream/src/core/refstrings.c irssi/src/core/refstrings.c
--- irssi.upstream/src/core/refstrings.c
+++ irssi/src/core/refstrings.c
@@ -122,7 +122,7 @@
mem += sizeof(char) * (strlen(key) + 1) + 2 * sizeof(void *);
}
- return g_strdup_printf("Shared strings: %ld, %dkB of data", count,
+ return g_strdup_printf("Shared strings: %zu, %dkB of data", count,
(int) (mem / 1024));
}
diff -Paur --no-dereference -- irssi.upstream/src/fe-common/core/fe-exec.c irssi/src/fe-common/core/fe-exec.c
--- irssi.upstream/src/fe-common/core/fe-exec.c
+++ irssi/src/fe-common/core/fe-exec.c
@@ -327,7 +327,7 @@
signal(SIGINT, SIG_IGN);
signal(SIGQUIT, SIG_DFL);
- putenv("TERM=tty");
+ setenv("TERM", "tty", 1);
/* set stdin, stdout and stderr */
dup2(in[0], STDIN_FILENO);
diff -Paur --no-dereference -- irssi.upstream/src/irc/core/irc.c irssi/src/irc/core/irc.c
--- irssi.upstream/src/irc/core/irc.c
+++ irssi/src/irc/core/irc.c
@@ -90,7 +90,7 @@
end = tmp;
if (tmp - cmd > MAX_IRC_USER_TAGS_LEN) {
- g_warning("irc_send_cmd_full(); tags too long(%ld)", tmp - cmd);
+ g_warning("irc_send_cmd_full(); tags too long(%td)", tmp - cmd);
while (tmp - cmd > MAX_IRC_USER_TAGS_LEN && cmd != tmp - 1) tmp--;
while (*tmp != ',' && cmd != tmp - 1) tmp--;
}

13
ports/irssi/irssi.port Normal file
View File

@ -0,0 +1,13 @@
NAME=irssi
BUILD_LIBRARIES='libcurses libglib libssl'
VERSION=1.4.5
DISTNAME=$NAME-$VERSION
COMPRESSION=tar.xz
ARCHIVE=$DISTNAME.$COMPRESSION
SHA256SUM=72a951cb0ad622785a8962801f005a3a412736c7e7e3ce152f176287c52fe062
UPSTREAM_SITE=https://codeberg.org/irssi/irssi/releases/download/$VERSION
UPSTREAM_ARCHIVE=$ARCHIVE
RELEASE_SEARCH_PAGE=https://codeberg.org/irssi/irssi/releases
BUILD_SYSTEM=configure
MAKE_VARS=V=1
LICENSE=GPL-2.0-or-later

View File

@ -0,0 +1 @@
rm -rf -- 'irssi-config.h'

View File

@ -293,7 +293,7 @@ diff -Paur --no-dereference -- libcurses.upstream/netbsd_sys/cdefs.h libcurses/n
diff -Paur --no-dereference -- libcurses.upstream/terminfo/sortix.terminfo libcurses/terminfo/sortix.terminfo
--- libcurses.upstream/terminfo/sortix.terminfo
+++ libcurses/terminfo/sortix.terminfo
@@ -0,0 +1,230 @@
@@ -0,0 +1,231 @@
+# TODO: Decode setab and setaf and see if they are what I want.
+# TODO: Implement BEL \a and add bel=^G,
+# TODO: Add blink support and add blink=\E[5m,
@ -302,12 +302,9 @@ diff -Paur --no-dereference -- libcurses.upstream/terminfo/sortix.terminfo libcu
+# TODO: Support dch=\E[%p1%dP,
+# TODO: dch1=\E[P,
+# TODO: Add faint support and add dim=\E[2m,
+# TODO: dl1=\E[M,
+# TODO: ech=\E[%p1%dX,
+# TODO: hts=\EH,
+# TODO: ich=\E[%p1%d@,
+# TODO: il=\E[%p1%dL,
+# TODO: il1=\E[L,
+# TODO: invis=\E[8m,
+# TODO: Some modifiers for the function keys are missing, like control + alt +
+# shift + f12, kfxx should probably go up to 96. On the other hand,
@ -346,12 +343,16 @@ diff -Paur --no-dereference -- libcurses.upstream/terminfo/sortix.terminfo libcu
+ cup=\E[%i%p1%d;%p2%dH,
+ cuu1=\E[A,
+ cuu=\E[%p1%dA,
+ dl1=\E[M,
+ dl=\E[%p1%dM,
+ ed=\E[J,
+ el1=\E[1K,
+ el=\E[K,
+ home=\E[H,
+ hpa=\E[%i%p1%dG,
+ ht=^I,
+ il1=\E[L,
+ il=\E[%p1%dL,
+ ind=^J,
+ indn=\E[%p1%dS,
+ nel=^J,

View File

@ -178,6 +178,18 @@ number matched in the first subexpression.
.Sy ARCHIVE
and
.Sy VERSION_REGEX )
.It Sy EDITION
An increasing number used to distinguish this edition of the package from any previous packages by
the same name.
A new pacckage with the same name and a different edition will considered a different package.
Upgrades will uninstall the old package and will not upgrade to the new edition as if the package
has stopped existing.
The
.Sy RENAMES
variable can be used in combination with
.Sy EDITION
to rename and split packages.
The default edition is 1.
.It Sy LICENSE
Primary license identifier for the installed files from the
.Lk https://spdx.org/licenses/ "SPDX License List" .
@ -253,6 +265,19 @@ Locate new upstream versions of the port by searching
.Sy RELEASE_SEARCH_PAGE
using this regular expression matching the new version number in the first
subexpression.
.It Sy RENAMES
Comma-separated list of package renames.
Each rename is expressed as the name of a package followed by a
.Sq "@"
and its
.Sy EDITION ,
followed by a
.Sq ":"
and then a potentially-empty space separated list of replacement packages, each
taking the form of a replacement package name followed by
.Sq "@"
and then the replacement package
.Sy EDITION .
.It Sy RUNTIME_DEPS
Space delimited list of libraries (ports) needed at run time.
Unsupported.

View File

@ -69,6 +69,25 @@ releasing Sortix x.y, foo." to allow the maintainer to easily
.Xr grep 1
for it after a release.
.Sh CHANGES
.Ss Add tix-repository(8)
The new
.Xr tix-repository 8
program is used to generate repository metadata in releases.
The new
.Sy EDITION
and
.Sy RENAMES
variables in
.Xr port 5
are used to rename and split packages and requires a new
.Xr tix-build 8 .
.Pp
Tix must be upgraded:
.Bd -literal
cd /src/tix &&
make clean &&
make install
.Ed
.Ss Support system upgrades and configuration in GRUB
The GRUB configuration now implements the
.Pa /etc

View File

@ -1,5 +1,6 @@
/*
* Copyright (c) 2017, 2022 Jonas 'Sortie' Termansen.
* Copyright (c) 2023 Juhani 'nortti' Krekelä.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@ -211,6 +212,21 @@ static void fill(size_t from_x, size_t from_y, size_t to_x, size_t to_y,
scrollback[i] = with;
}
static void move(size_t to_x, size_t to_y, size_t from_x, size_t from_y,
size_t num_chars)
{
// TODO: Assert within bounds?
size_t from = from_y * columns + from_x;
size_t to = to_y * columns + to_x;
if ( to < from )
for ( size_t i = 0; i < num_chars; i++ )
scrollback[to + i] = scrollback[from + i];
else if ( from < to )
for ( size_t i = 0; i < num_chars; i++ )
scrollback[to + num_chars - 1 - i] =
scrollback[from + num_chars - 1 - i];
}
static void scroll(ssize_t offsigned, struct entry with)
{
if ( 0 < offsigned )
@ -396,8 +412,37 @@ static void run_ansi_command(char c)
with.wc = 0;
fill(from_x, from_y, to_x, to_y, with);
} break;
// TODO: CSI Ps M Delete Ps Line(s) (default = 1) (DL).
// (delete those lines and move the rest of the lines upwards).
case 'L': // Append lines before current line.
{
column = 0;
unsigned lines = 0 < ansiusedparams ? ansiparams[0] : 1;
if ( rows < row + lines )
lines = rows - row;
unsigned move_lines = rows - row - lines;
move(0, row + lines, 0, row, move_lines * columns);
struct entry with;
with.attr = 0;
with.fgcolor = attr & ATTR_INVERSE ? current_bgcolor : current_fgcolor;
with.bgcolor = attr & ATTR_INVERSE ? current_fgcolor : current_bgcolor;
with.wc = 0;
if ( 0 < lines )
fill(0, row, columns - 1, row + lines - 1, with);
} break;
case 'M': // Delete lines starting from beginning of current line.
{
column = 0;
unsigned lines = 0 < ansiusedparams ? ansiparams[0] : 1;
if ( rows < row + lines )
lines = rows - row;
unsigned move_lines = rows - row - lines;
move(0, row, 0, row + lines, move_lines * columns);
struct entry with;
with.attr = 0;
with.fgcolor = attr & ATTR_INVERSE ? current_bgcolor : current_fgcolor;
with.bgcolor = attr & ATTR_INVERSE ? current_fgcolor : current_bgcolor;
with.wc = 0;
fill(0, rows - lines, columns - 1, rows - 1, with);
} break;
// TODO: CSI Ps P Delete Ps Character(s) (default = 1) (DCH).
// (delete those characters and move the rest of the line leftward).
case 'S': // Scroll a line up and place a new line at the buttom.