head	1.2;
access;
symbols
	perseant-exfatfs-base-20261102:1.2;
locks; strict;
comment	@ * @;


1.2
date	2026.10.31.22.46.30;	author christos;	state Exp;
branches;
next	1.1;
commitid	Jz7bHcaySLTSlG1H;

1.1
date	2026.10.26.07.52.39;	author nia;	state Exp;
branches;
next	;
commitid	vNbxcBbERAW3xX0H;


desc
@@


1.2
log
@protect against the hiliter reading past EOF (Kilian Feess)
@
text
@/* hlite.c, generic syntax highlighting, Atto Emacs, Hugh Barney, Public Domain, 2016 */

#include "header.h"

int state = ID_DEFAULT;
int next_state = ID_DEFAULT;
int skip_count = 0;

static char_t get_at(buffer_t *, point_t);
static int is_symbol(char_t);

static char_t get_at(buffer_t *bp, point_t pt)
{
	if (pt >= pos(bp, bp->b_ebuf))
		return '\0';
	return (*ptr(bp, pt));
}

static char_t symbols[] = "{}[]()!'£$%^&*-+=:;@@~#<>,.?/\\|";

static int is_symbol(char_t c)
{
	char_t *p = symbols;

	for (p = symbols; *p != '\0'; p++)
		if (*p == c) return 1;
	return 0;
}

void set_parse_state(buffer_t *bp, point_t pt)
{
	point_t po;

	state = ID_DEFAULT;
	next_state = ID_DEFAULT;
	skip_count = 0;

	for (po =0; po < pt; po++)
		parse_text(bp, po);
}

int parse_text(buffer_t *bp, point_t pt)
{
	if (skip_count-- > 0)
		return state;

	char_t c_now = get_at(bp, pt);
	char_t c_next = get_at(bp, pt + 1);
	state = next_state;

	if (state == ID_DEFAULT && c_now == '/' && c_next == '*') {
		skip_count = 1;
		return (next_state = state = ID_BLOCK_COMMENT);
	}

	if (state == ID_BLOCK_COMMENT && c_now == '*' && c_next == '/') {
		skip_count = 1;
		next_state = ID_DEFAULT;
		return ID_BLOCK_COMMENT;
	}

	if (state == ID_DEFAULT && c_now == '/' && c_next == '/') {
		skip_count = 1;
		return (next_state = state = ID_LINE_COMMENT);
	}

	if (state == ID_LINE_COMMENT && c_now == '\n')
		return (next_state = ID_DEFAULT);

	if (state == ID_DEFAULT && c_now == '"')
		return (next_state = ID_DOUBLE_STRING);

	if (state == ID_DOUBLE_STRING && c_now == '\\') {
		skip_count = 1;
		return (next_state = ID_DOUBLE_STRING);
	}

	if (state == ID_DOUBLE_STRING && c_now == '"') {
		next_state = ID_DEFAULT;
		return ID_DOUBLE_STRING;
	}

	if (state == ID_DEFAULT && c_now == '\'')
		return (next_state = ID_SINGLE_STRING);

	if (state == ID_SINGLE_STRING && c_now == '\\') {
		skip_count = 1;
		return (next_state = ID_SINGLE_STRING);
	}

	if (state == ID_SINGLE_STRING && c_now == '\'') {
		next_state = ID_DEFAULT;
		return ID_SINGLE_STRING;
	}

	if (state != ID_DEFAULT)
		return (next_state = state);

	if (state == ID_DEFAULT && c_now >= '0' && c_now <= '9') {
		next_state = ID_DEFAULT;
		return (state = ID_DIGITS);
	}

	if (state == ID_DEFAULT && 1 == is_symbol(c_now)) {
		next_state = ID_DEFAULT;
		return (state = ID_SYMBOL);
	}

	return (next_state = state);
}
@


1.1
log
@atto(1): Initial import of tiny text editor, as discussed on
tech-userlevel@@.

This is Hugh Barney's atto text editor modified for inclusion in
NetBSD. Since the upstream repository is inactive and the original
author wishes to keep the code base below 2000 lines of C, this is
effectively a fork that lives in usr.bin/atto. It serves as an
alternative to vi(1) for users more accustomed to modeless text
editors.

Notable changes include reworked keyboard input code to handle a wider
range of terminals (via libcurses cursor key translation), more useful
help for unrecognized key presses, and standardized option handling
using getopt (with syntax highlighting disabled by default).

Thanks martin and other folks for feedback and testing.

ATTO(1)                 General Commands Manual                ATTO(1)

NAME
     atto - simple modeless text editor

SYNOPSIS
     atto [-C] file ...

DESCRIPTION
     atto is a screen-based text editor.  It serves as an alternative
     to vi(1) for users who are not accustomed to text editors with
     separate insertion and editing modes, and includes support for
     editing UTF-8 text.

     Perhaps all that needs to be known to use atto at a basic level
     is that holding the control key, pressing x, then pressing w will
     write the currently open file, and holding the control key,
     pressing x, then pressing c will exit the editor.

     The options are as follows:

     -C          Use colours, if available, for basic language-unaware
                 syntax highlighting.

   Cursor movement commands
     C is used as an abbreviation for the control key, commonly
     rendered as "ctrl" on English language keyboards.

     Arrow keys or the navigation cluster can also be used to move the
     cursor when the keyboard has such features.

           C-a        move cursor to beginning of current line (i.e.
                      "home")
           C-b        move cursor back one character (i.e. "left")
           C-e        move cursor to end of current line (i.e. "end")
           C-f        move cursor forward one character (i.e. "right")
           C-n        move cursor to next line (i.e. "down")
           C-p        move cursor to previous line (i.e. "up")
           C-v        move cursor to next page of text (i.e. "page
                      down")
           Esc-b      move cursor back one word
           Esc-f      move cursor forward one word
           Esc-g      jump to a specific line number in the file
           Esc-v      move cursor to previous page of text (i.e. "page
                      up")
           Esc-<      jump to the start of the file
           Esc->      jump to the end of the file

   Text editing commands
           C-d        delete character under cursor (i.e. "del")
           C-h        move cursor backwards and delete previous
                      character (i.e. "backspace")
           C-g        abort at prompts (cancel task when asked a
                      question)
           C-i        insert tab character
           C-j        insert newline character (i.e. "enter",
                      "return")
           C-k        cut text up to the end of the line (i.e. "kill
                      line")
           C-l        refresh the screen
           C-m        insert carriage return character
           C-r        search for text backwards, jump to next result
           C-s        search for text forwards, jump to next result
           C-y        paste the text in the cut buffer (i.e. "yank")
           Esc-r      search for text and replace it

   Buffer commands
     atto supports multiple editing buffers, allowing users to edit
     multiple files from a single instance of the program.

           C-x C-c    close all open buffers and exit atto, prompting
                      if changes would be discarded
           C-x C-f    open a file into a new buffer
           C-x C-k    close the current buffer, prompting if changes
                      would be discarded (i.e. "kill")
           C-x C-s    save current buffer to disk, overwriting the
                      file
           C-x C-w    save current buffer to disk, prompting for file
                      name ("write")
           C-x n      cycle to next buffer
           C-x i      read another file and insert it into the current
                      buffer
           C-x =      display cursor position in current buffer

   Region commands
     As well as cutting text on a line basis (i.e. C-k), a region can
     be selected by setting a mark at the beginning of the region, and
     then moving the cursor to the end of the region.

           C-space    set the beginning of the region at the current
                      position
           C-w        cut the marked region
           Esc-w      copy the marked region without deleting it

   Window management commands
     Simple split-screen window management is included.  For more
     advanced use cases, consider using tmux(1).

           C-x 1      delete windows except the currently active one
           C-x 2      split current window into two windows
           C-x o      switch to the next open window

SEE ALSO
     ed(1), ex(1), vi(1), xedit(1)

STANDARDS
     atto is not the standard editor.

AUTHORS
     atto was written primarily by Hugh Barney, and was originally
     based on public domain code from Anthony Howe's editor (commonly
     known as Anthony's Editor).

     It has been modified for inclusion in NetBSD, including with
     enhanced option handling.

NetBSD 11.99.9             October 15, 2026             NetBSD 11.99.9
@
text
@d14 2
@

