head 1.9; access; symbols perseant-exfatfs-base-20261102:1.8; locks; strict; comment @ * @; 1.9 date 2026.11.03.09.12.52; author riastradh; state Exp; branches; next 1.8; commitid krqUsU5dJLlVKZ1H; 1.8 date 2026.11.02.08.44.55; author nia; state Exp; branches; next 1.7; commitid Lm2RtVy266rgDR1H; 1.7 date 2026.11.02.08.33.37; author nia; state Exp; branches; next 1.6; commitid ucqMIuYKSxjczR1H; 1.6 date 2026.10.31.23.17.49; author christos; state Exp; branches; next 1.5; commitid IawtjckRJJrLwG1H; 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.29.21.58.36; author christos; state Exp; branches; next 1.2; commitid qk7j1cGLFkjq9q1H; 1.2 date 2026.10.29.21.41.35; author christos; state Exp; branches; next 1.1; commitid EjHKvHul9tDt3q1H; 1.1 date 2026.10.26.07.52.39; author nia; state Exp; branches; next ; commitid vNbxcBbERAW3xX0H; desc @@ 1.9 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 @/* main.c, Atto Emacs, Public Domain, Hugh Barney, 2016, Derived from: Anthony's Editor January 93 */ #include "header.h" int done; int use_color; point_t nscrap; char_t *scrap; char_t *input; int msgflag; char msgline[TEMPBUF]; char temp[TEMPBUF]; char searchtext[STRBUF_M]; char replace[STRBUF_M]; buffer_t *curbp; /* current buffer */ buffer_t *bheadp; /* head of list of buffers */ window_t *curwp; window_t *wheadp; __dead static void usage(void) { (void)fprintf(stderr, "usage:\tatto [-C] [file ...]\n"); exit(EXIT_FAILURE); } int main(int argc, char **argv) { extern char *optarg; extern int optind; void (*command)(void); int ch; int i; while ((ch = getopt(argc, argv, "C")) != -1) { switch (ch) { case 'C': use_color = 1; break; default: usage(); break; } } setlocale(LC_ALL, "") ; /* required for 3,4 byte UTF8 chars */ if (initscr() == NULL) fatal("Failed to initialize the screen."); raw(); noecho(); keypad(stdscr, TRUE); idlok(stdscr, TRUE); argc -= optind; argv += optind; if (use_color) { start_color(); init_pair(ID_DEFAULT, COLOR_WHITE, COLOR_BLACK); /* alpha */ init_pair(ID_SYMBOL, COLOR_CYAN, COLOR_BLACK); /* non alpha, non digit */ init_pair(ID_MODELINE, COLOR_BLACK, COLOR_WHITE); /* modeline */ init_pair(ID_DIGITS, COLOR_YELLOW, COLOR_BLACK); /* digits */ init_pair(ID_BLOCK_COMMENT, COLOR_GREEN, COLOR_BLACK); /* block comments */ init_pair(ID_LINE_COMMENT, COLOR_GREEN, COLOR_BLACK); /* line comments */ init_pair(ID_SINGLE_STRING, COLOR_YELLOW, COLOR_BLACK); /* single quoted strings */ init_pair(ID_DOUBLE_STRING, COLOR_YELLOW, COLOR_BLACK); /* double quoted strings */ } if (argc) { for (i = 0; i < argc; ++i) { if (strlen(argv[i]) >= sizeof(curbp->b_fname)) fatal("File name too long."); curbp = find_buffer(argv[i], TRUE); if (curbp == NULL) fatal("Failed to allocate required memory."); (void) insert_file(argv[i], FALSE); /* Save filename regardless of load() success. */ strlcpy(curbp->b_fname, argv[i], sizeof(curbp->b_fname)); } } else { curbp = create_scratch(); if (curbp == NULL) fatal("Failed to allocate required memory."); } wheadp = curwp = new_window(); one_window(curwp); associate_b2w(curbp, curwp); #ifndef SMALL if (create_menu() == -1) { msg("Warning: couldn't initialize menu."); } #endif if (!growgap(curbp, CHUNK)) fatal("Failed to allocate required memory."); while (!done) { #ifndef SMALL if (menu_mode) { ch = getch(); handle_menus(ch); continue; } #endif update_display(); input = get_key(&command); if (command != NULL) { command(); } else { /* allow TAB and NEWLINE, otherwise any Control Char is 'Not bound' */ if (*input > 31 || *input == 10 || *input == 9) insert(); else { flushinp(); /* discard without writing in buffer */ msg("Not bound - try ctrl+x+w to write and ctrl+x+c to exit"); } } } if (scrap != NULL) free(scrap); move(LINES-1, 0); refresh(); noraw(); endwin(); return 0; } __dead void fatal(const char *msg) { if (curscr != NULL) { move(LINES-1, 0); refresh(); noraw(); endwin(); putchar('\n'); } fprintf(stderr, "%s: %s\n", PROG_NAME, msg); exit(1); } void msg(const char *msg, ...) { va_list args; va_start(args, msg); (void)vsnprintf(msgline, sizeof(msgline), msg, args); va_end(args); msgflag = TRUE; } @ 1.8 log @atto(1): Errors relating to the menu generally aren't fatal, so don't treat them as such. @ text @d22 1 d134 1 @ 1.7 log @atto(1): fatal cannot take special format string arguments other than the initial %s for the program name. Gain some safety by not having callers pass a format string in the first place. With this, we can raise WARNS to 5. @ text @d92 3 a94 1 create_menu(); @ 1.6 log @Add checks to unchecked allocations (Kilian Feess) @ text @d49 1 a49 1 if (initscr() == NULL) fatal("%s: Failed to initialize the screen.\n"); d73 1 a73 1 fatal("%s: File name too long.\n"); d76 1 a76 1 fatal("%s: Failed to allocate required memory.\n"); d84 1 a84 1 fatal("%s: Failed to allocate required memory.\n"); d95 1 a95 1 if (!growgap(curbp, CHUNK)) fatal("%s: Failed to allocate required memory.\n"); d140 1 a140 1 fprintf(stderr, msg, PROG_NAME); @ 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 @d75 2 d83 2 @ 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 @d72 2 @ 1.3 log @- sprintf -> snprintf, strcpy/strcat -> strlcpy/strcat - merge dup scratch buffer creation - use sizeof more @ text @d85 4 d92 8 d101 1 @ 1.2 log @use the size of the buffer instead of NAME_MAX and strlcpy since there is no format. fixes: __builtin___snprintf_chk' specified bound 511 exceeds destination size 16 [-Werror=stringop-overflow=] @ text @d75 1 a75 1 snprintf(curbp->b_fname, NAME_MAX, "%s", argv[i]); d78 1 a78 2 curbp = find_buffer("*scratch*", TRUE); strlcpy(curbp->b_bname, "*scratch*", sizeof(curbp->b_bname)); d129 1 a129 1 (void)vsprintf(msgline, msg, args); @ 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 @d79 1 a79 1 snprintf(curbp->b_bname, NAME_MAX, "*scratch*"); @