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