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