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


1.7
date	2026.11.03.09.12.52;	author riastradh;	state Exp;
branches;
next	1.6;
commitid	krqUsU5dJLlVKZ1H;

1.6
date	2026.10.31.23.20.24;	author christos;	state Exp;
branches;
next	1.5;
commitid	i7rXYlGO0raIxG1H;

1.5
date	2026.10.31.22.50.44;	author christos;	state Exp;
branches;
next	1.4;
commitid	NIAeb2Ee54SbnG1H;

1.4
date	2026.10.30.16.14.35;	author nia;	state Exp;
branches;
next	1.3;
commitid	APhM1lBKq2HGdw1H;

1.3
date	2026.10.30.15.34.32;	author christos;	state Exp;
branches;
next	1.2;
commitid	nXvSecFlMPtTZv1H;

1.2
date	2026.10.29.21.58.36;	author christos;	state Exp;
branches;
next	1.1;
commitid	qk7j1cGLFkjq9q1H;

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


desc
@@


1.7
log
@atto(1): Sprinkle __dead on functions that never return.

Pacifies -Werror=missing-noreturn in clang:

/home/source/ab/HEAD-llvm/src/usr.bin/atto/main.c:24:1: error: function 'usage' could be declared with attribute 'noreturn' [-Werror,-Wmissing-noreturn]
{
^
/home/source/ab/HEAD-llvm/src/usr.bin/atto/main.c:134:1: error: function 'fatal' could be declared with attribute 'noreturn' [-Werror,-Wmissing-noreturn]
{
^
2 errors generated.
@
text
@/* header.h, Atto Emacs, Public Domain, Hugh Barney, 2016, Derived from: Anthony's Editor January 93 */
#ifndef _NETBSD_SOURCE
#define _NETBSD_SOURCE
#endif
#define _XOPEN_SOURCE 600
#include <locale.h>
#include <stdlib.h>
#include <stdarg.h>
#include <assert.h>
#include <errno.h>
#include <curses.h>
#include <stdio.h>
#include <sys/types.h>
#include <ctype.h>
#include <limits.h>
#include <string.h>
#include <unistd.h>
#include <wchar.h>

#define VERSION	 "Atto 1.22, Public Domain, Dec 2020, by Hugh Barney,  No warranty."
#define PROG_NAME "atto"
#define B_MODIFIED	0x01		/* modified buffer */
#define B_OVERWRITE	0x02		/* overwrite mode */
#define MSGLINE         (LINES-1)
#define NOMARK          -1
#define CHUNK           8096L
#define K_BUFFER_LENGTH 256
#define TEMPBUF         512
#define STRBUF_L        256
#define STRBUF_M        64
#define STRBUF_S        16
#define MIN_GAP_EXPAND  512
#define TEMPFILE        "/tmp/feXXXXXX"
#define F_NONE          0
#define F_CLEAR         1
#define ID_DEFAULT         1
#define ID_SYMBOL          2
#define ID_MODELINE        3
#define ID_DIGITS          4
#define ID_LINE_COMMENT    5
#define ID_BLOCK_COMMENT   6
#define ID_DOUBLE_STRING   7
#define ID_SINGLE_STRING   8

typedef unsigned char char_t;
typedef long point_t;

typedef struct buffer_t
{
	struct buffer_t *b_next;  /* Link to next buffer_t */
	point_t b_mark;	     	  /* the mark */
	point_t b_point;          /* the point */
	point_t b_cpoint;         /* the original current point, used for multiple window displaying */
	point_t b_page;           /* start of page */
	point_t b_epage;          /* end of page */
	point_t b_reframe;        /* force a reframe of the display */
	int b_cnt;                /* count of windows referencing this buffer */
	point_t b_size;           /* current size of text being edited (not including gap) */
	point_t b_psize;          /* previous size */
	char_t *b_buf;            /* start of buffer */
	char_t *b_ebuf;           /* end of buffer */
	char_t *b_gap;            /* start of gap */
	char_t *b_egap;           /* end of gap */
	int b_row;                /* cursor row */
	int b_col;                /* cursor col */
	char b_fname[PATH_MAX];   /* filename (full path) */
	char b_bname[STRBUF_S];   /* buffer name */
	char b_flags;             /* buffer flags */
} buffer_t;

typedef struct window_t
{
	struct window_t *w_next;   /* Next window */
	struct buffer_t *w_bufp;   /* Buffer displayed in window */
	point_t w_point;
	point_t w_mark;
	point_t w_page;
	point_t w_epage;
	int w_top;	    /* Origin 0 top row of window */
	int w_rows;         /* no. of rows of text in window */
	int w_row;          /* cursor row */
	int w_col;          /* cursor col */
	int w_update;
	char w_name[STRBUF_S];
} window_t;

extern buffer_t *curbp;			/* current buffer */
extern buffer_t *bheadp;		/* head of list of buffers */
extern window_t *curwp;
extern window_t *wheadp;

/*
 * Some compilers define size_t as a unsigned 16 bit number while
 * point_t and off_t might be defined as a signed 32 bit number.  
 * malloc(), realloc(), fread(), and fwrite() take size_t parameters,
 * which means there will be some size limits because size_t is too
 * small of a type.
 */
#define MAX_SIZE_T      ((unsigned long) (size_t) ~0)

extern int done;                /* Quit flag. */
extern int use_color;           /* Optional syntax highlighting. */
extern int msgflag;             /* True if msgline should be displayed. */
extern int menu_mode;           /* True if menu is open. */
extern point_t nscrap;          /* Length of scrap buffer. */
extern char_t *scrap;           /* Allocated scrap buffer. */
extern char_t *input;
extern char msgline[TEMPBUF];   /* Message line input/output buffer. */
extern char temp[TEMPBUF];      /* Temporary buffer. */
extern char searchtext[STRBUF_M];
extern char replace[STRBUF_M];

extern void fatal(const char *) __dead;
extern void msg(const char *, ...) __printflike(1, 2);
extern void display(window_t *, int);
extern void dispmsg(void);
extern void modeline(window_t *);
extern int utf8_size(char_t);
extern int prev_utf8_char_size(void);
extern void display_utf8(buffer_t *, int);
extern point_t lnstart(buffer_t *, point_t);
extern point_t lncolumn(buffer_t *, point_t, int);
extern point_t segstart(buffer_t *, point_t, point_t);
extern point_t segnext(buffer_t *, point_t, point_t);
extern point_t upup(buffer_t *, point_t);
extern point_t dndn(buffer_t *, point_t);
extern char_t *get_key(void (**command_out)(void));
extern int getinput(const char *, char *, int, int);
extern int getfilename(const char *, char *, int);
extern void display_prompt_and_response(const char *, const char *);
extern int growgap(buffer_t *, point_t);
extern point_t movegap(buffer_t *, point_t);
extern point_t pos(buffer_t *, char_t *);
extern char_t *ptr(buffer_t *, point_t);
extern int posix_file(char *);
extern int save(char *);
extern int load_file(char *);
extern int insert_file(char *, int);
extern void backsp(void);
extern void block(void);
extern void iblock(void);
extern void bottom(void);
extern void cut(void);
extern void copy(void);
extern void copy_cut(int);
extern void delete(void);
extern void toggle_overwrite_mode(void);
extern void down(void);
extern void insert(void);
extern void left(void);
extern void lnbegin(void);
extern void lnend(void);
extern void paste(void);
extern void pgdown(void);
extern void pgup(void);
extern void quit(void);
extern int yesno(int);
extern void quit_ask(void);
extern void redraw(void);
extern void readfile(void);
extern void insertfile(void);
extern void right(void);
extern void top(void);
extern void up(void);
extern void version(void);
extern void wleft(void);
extern void wright(void);
extern void writefile(void);
extern void savebuffer(void);
extern void showpos(void);
extern void killtoeol(void);
extern void gotoline(void);
extern void search(void);
extern void query_replace(void);
extern point_t line_to_point(int);
extern point_t search_forward(buffer_t *, point_t, char *);
extern point_t search_backwards(buffer_t *, point_t, char *);
extern void update_search_prompt(char *, char *);
extern void display_search_result(point_t, int, const char *, const char *);
extern buffer_t* find_buffer(const char *, int);
extern void buffer_init(buffer_t *);
extern int delete_buffer(buffer_t *);
extern void next_buffer(void);
extern int count_buffers(void);
extern int modified_buffers(void);
extern void killbuffer(void);
extern char* get_buffer_name(buffer_t *);
extern void get_line_stats(int *, int *);
extern void query_replace(void);
extern window_t *new_window(void);
extern void one_window(window_t *);
extern void split_window(void);
extern void next_window(void);
extern void delete_other_windows(void);
extern void free_other_windows(window_t *);
extern void update_display(void);
extern void w2b(window_t *);
extern void b2w(window_t *);
extern void associate_b2w(buffer_t *, window_t *);
extern void disassociate_b(window_t *);
extern void set_parse_state(buffer_t *, point_t);
extern void set_parse_state2(buffer_t *, point_t);
extern int parse_text(buffer_t *, point_t);
extern void resize_terminal(void);
extern int create_menu(void);
extern void handle_menus(int);
extern void menu_escape(void);
extern buffer_t *create_scratch(void);
@


1.6
log
@widen types to prevent truncation (Kilian Feess)
@
text
@d113 1
a113 1
extern void fatal(const char *);
@


1.5
log
@Avoid filename trucation of paths > NAME_MAX, change it to PATH_MAX and
detect truncation and beep (completion) or print an error message (save)
(Kilian Feess)
@
text
@d58 2
a59 2
	int b_size;               /* current size of text being edited (not including gap) */
	int b_psize;              /* previous size */
d79 2
a80 2
	char w_top;	    /* Origin 0 top row of window */
	char w_rows;        /* no. of rows of text in window */
@


1.4
log
@atto(1): For users who can't easily remember key bindings, add a menu
which is opened by pressing the escape key twice, and operated using
the cursor keys. This uses libedit, so is conditional on SMALLPROG
to still allow easy inclusion of a minimal editor in ramdisks and so
on.

As the copyright might reveal, I nicked some code from blymn@@'s editor
from othersrc to implement the menu. Thanks!

XXX it should really be renamed to natto now, since this is totally
beyond the vision of the original atto.
@
text
@d66 1
a66 1
	char b_fname[NAME_MAX + 1]; /* filename */
@


1.3
log
@mark msg __printflike, and fix the broken formats
@
text
@d104 1
d205 3
@


1.2
log
@- sprintf -> snprintf, strcpy/strcat -> strlcpy/strcat
- merge dup scratch buffer creation
- use sizeof more
@
text
@d113 1
a113 1
extern void msg(const char *, ...);
@


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
@d107 4
a110 4
extern char msgline[];          /* Message line input/output buffer. */
extern char temp[];             /* Temporary buffer. */
extern char searchtext[];
extern char replace[];
d204 1
@

