1 1.3 christos /* $NetBSD: v_util.c,v 1.3 2014/01/26 21:43:45 christos Exp $ */ 2 1.1 christos /*- 3 1.1 christos * Copyright (c) 1992, 1993, 1994 4 1.1 christos * The Regents of the University of California. All rights reserved. 5 1.1 christos * Copyright (c) 1992, 1993, 1994, 1995, 1996 6 1.1 christos * Keith Bostic. All rights reserved. 7 1.1 christos * 8 1.1 christos * See the LICENSE file for redistribution information. 9 1.1 christos */ 10 1.1 christos 11 1.1 christos #include "config.h" 12 1.1 christos 13 1.3 christos #include <sys/cdefs.h> 14 1.3 christos #if 0 15 1.1 christos #ifndef lint 16 1.1 christos static const char sccsid[] = "Id: v_util.c,v 10.14 2001/06/25 15:19:36 skimo Exp (Berkeley) Date: 2001/06/25 15:19:36 "; 17 1.1 christos #endif /* not lint */ 18 1.3 christos #else 19 1.3 christos __RCSID("$NetBSD: v_util.c,v 1.3 2014/01/26 21:43:45 christos Exp $"); 20 1.3 christos #endif 21 1.1 christos 22 1.1 christos #include <sys/types.h> 23 1.1 christos #include <sys/queue.h> 24 1.1 christos #include <sys/time.h> 25 1.1 christos 26 1.1 christos #include <bitstring.h> 27 1.1 christos #include <ctype.h> 28 1.1 christos #include <limits.h> 29 1.1 christos #include <stdio.h> 30 1.1 christos #include <stdlib.h> 31 1.1 christos #include <string.h> 32 1.1 christos #include <unistd.h> 33 1.1 christos 34 1.1 christos #include "../common/common.h" 35 1.1 christos #include "vi.h" 36 1.1 christos 37 1.1 christos /* 38 1.1 christos * v_eof -- 39 1.1 christos * Vi end-of-file error. 40 1.1 christos * 41 1.1 christos * PUBLIC: void v_eof __P((SCR *, MARK *)); 42 1.1 christos */ 43 1.1 christos void 44 1.1 christos v_eof(SCR *sp, MARK *mp) 45 1.1 christos { 46 1.1 christos db_recno_t lno; 47 1.1 christos 48 1.1 christos if (mp == NULL) 49 1.1 christos v_emsg(sp, NULL, VIM_EOF); 50 1.1 christos else { 51 1.1 christos if (db_last(sp, &lno)) 52 1.1 christos return; 53 1.1 christos if (mp->lno >= lno) 54 1.1 christos v_emsg(sp, NULL, VIM_EOF); 55 1.1 christos else 56 1.1 christos msgq(sp, M_BERR, "195|Movement past the end-of-file"); 57 1.1 christos } 58 1.1 christos } 59 1.1 christos 60 1.1 christos /* 61 1.1 christos * v_eol -- 62 1.1 christos * Vi end-of-line error. 63 1.1 christos * 64 1.1 christos * PUBLIC: void v_eol __P((SCR *, MARK *)); 65 1.1 christos */ 66 1.1 christos void 67 1.1 christos v_eol(SCR *sp, MARK *mp) 68 1.1 christos { 69 1.1 christos size_t len; 70 1.1 christos 71 1.1 christos if (mp == NULL) 72 1.1 christos v_emsg(sp, NULL, VIM_EOL); 73 1.1 christos else { 74 1.1 christos if (db_get(sp, mp->lno, DBG_FATAL, NULL, &len)) 75 1.1 christos return; 76 1.1 christos if (mp->cno == len - 1) 77 1.1 christos v_emsg(sp, NULL, VIM_EOL); 78 1.1 christos else 79 1.1 christos msgq(sp, M_BERR, "196|Movement past the end-of-line"); 80 1.1 christos } 81 1.1 christos } 82 1.1 christos 83 1.1 christos /* 84 1.1 christos * v_nomove -- 85 1.1 christos * Vi no cursor movement error. 86 1.1 christos * 87 1.1 christos * PUBLIC: void v_nomove __P((SCR *)); 88 1.1 christos */ 89 1.1 christos void 90 1.1 christos v_nomove(SCR *sp) 91 1.1 christos { 92 1.1 christos msgq(sp, M_BERR, "197|No cursor movement made"); 93 1.1 christos } 94 1.1 christos 95 1.1 christos /* 96 1.1 christos * v_sof -- 97 1.1 christos * Vi start-of-file error. 98 1.1 christos * 99 1.1 christos * PUBLIC: void v_sof __P((SCR *, MARK *)); 100 1.1 christos */ 101 1.1 christos void 102 1.1 christos v_sof(SCR *sp, MARK *mp) 103 1.1 christos { 104 1.1 christos if (mp == NULL || mp->lno == 1) 105 1.1 christos msgq(sp, M_BERR, "198|Already at the beginning of the file"); 106 1.1 christos else 107 1.1 christos msgq(sp, M_BERR, "199|Movement past the beginning of the file"); 108 1.1 christos } 109 1.1 christos 110 1.1 christos /* 111 1.1 christos * v_sol -- 112 1.1 christos * Vi start-of-line error. 113 1.1 christos * 114 1.1 christos * PUBLIC: void v_sol __P((SCR *)); 115 1.1 christos */ 116 1.1 christos void 117 1.1 christos v_sol(SCR *sp) 118 1.1 christos { 119 1.1 christos msgq(sp, M_BERR, "200|Already in the first column"); 120 1.1 christos } 121 1.1 christos 122 1.1 christos /* 123 1.1 christos * v_isempty -- 124 1.1 christos * Return if the line contains nothing but white-space characters. 125 1.1 christos * 126 1.1 christos * PUBLIC: int v_isempty __P((CHAR_T *, size_t)); 127 1.1 christos */ 128 1.1 christos int 129 1.1 christos v_isempty(CHAR_T *p, size_t len) 130 1.1 christos { 131 1.1 christos for (; len--; ++p) 132 1.2 christos if (!ISBLANK((UCHAR_T)*p)) 133 1.1 christos return (0); 134 1.1 christos return (1); 135 1.1 christos } 136 1.1 christos 137 1.1 christos /* 138 1.1 christos * v_emsg -- 139 1.1 christos * Display a few common vi messages. 140 1.1 christos * 141 1.2 christos * PUBLIC: void v_emsg __P((SCR *, const char *, vim_t)); 142 1.1 christos */ 143 1.1 christos void 144 1.2 christos v_emsg(SCR *sp, const char *p, vim_t which) 145 1.1 christos { 146 1.1 christos switch (which) { 147 1.1 christos case VIM_COMBUF: 148 1.1 christos msgq(sp, M_ERR, 149 1.1 christos "201|Buffers should be specified before the command"); 150 1.1 christos break; 151 1.1 christos case VIM_EMPTY: 152 1.1 christos msgq(sp, M_BERR, "209|The file is empty"); 153 1.1 christos break; 154 1.1 christos case VIM_EOF: 155 1.1 christos msgq(sp, M_BERR, "202|Already at end-of-file"); 156 1.1 christos break; 157 1.1 christos case VIM_EOL: 158 1.1 christos msgq(sp, M_BERR, "203|Already at end-of-line"); 159 1.1 christos break; 160 1.1 christos case VIM_NOCOM: 161 1.1 christos case VIM_NOCOM_B: 162 1.1 christos msgq(sp, 163 1.1 christos which == VIM_NOCOM_B ? M_BERR : M_ERR, 164 1.1 christos "204|%s isn't a vi command", p); 165 1.1 christos break; 166 1.1 christos case VIM_WRESIZE: 167 1.1 christos msgq(sp, M_ERR, "Window resize interrupted text input mode"); 168 1.1 christos break; 169 1.1 christos case VIM_USAGE: 170 1.1 christos msgq(sp, M_ERR, "205|Usage: %s", p); 171 1.1 christos break; 172 1.1 christos } 173 1.1 christos } 174