| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: cut.c,v 1.5 2011/11/23 19:25:28 tnozaki Exp $ */ | | 1 | /* $NetBSD: cut.c,v 1.6 2012/01/21 19:32:37 christos Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 1992, 1993, 1994 | | 4 | * Copyright (c) 1992, 1993, 1994 |
5 | * The Regents of the University of California. All rights reserved. | | 5 | * The Regents of the University of California. All rights reserved. |
6 | * Copyright (c) 1992, 1993, 1994, 1995, 1996 | | 6 | * Copyright (c) 1992, 1993, 1994, 1995, 1996 |
7 | * Keith Bostic. All rights reserved. | | 7 | * Keith Bostic. All rights reserved. |
8 | * | | 8 | * |
9 | * See the LICENSE file for redistribution information. | | 9 | * See the LICENSE file for redistribution information. |
10 | */ | | 10 | */ |
11 | | | 11 | |
12 | #include "config.h" | | 12 | #include "config.h" |
13 | | | 13 | |
14 | #ifndef lint | | 14 | #ifndef lint |
| @@ -124,36 +124,36 @@ copyloop: | | | @@ -124,36 +124,36 @@ copyloop: |
124 | */ | | 124 | */ |
125 | if (cbp == NULL) { | | 125 | if (cbp == NULL) { |
126 | CALLOC_RET(sp, cbp, CB *, 1, sizeof(CB)); | | 126 | CALLOC_RET(sp, cbp, CB *, 1, sizeof(CB)); |
127 | cbp->name = name; | | 127 | cbp->name = name; |
128 | CIRCLEQ_INIT(&cbp->textq); | | 128 | CIRCLEQ_INIT(&cbp->textq); |
129 | LIST_INSERT_HEAD(&sp->wp->cutq, cbp, q); | | 129 | LIST_INSERT_HEAD(&sp->wp->cutq, cbp, q); |
130 | } else if (!append) { | | 130 | } else if (!append) { |
131 | text_lfree(&cbp->textq); | | 131 | text_lfree(&cbp->textq); |
132 | cbp->len = 0; | | 132 | cbp->len = 0; |
133 | cbp->flags = 0; | | 133 | cbp->flags = 0; |
134 | } | | 134 | } |
135 | | | 135 | |
136 | | | 136 | |
137 | #define ENTIRE_LINE 0 | | 137 | #define ENTIRE_LINE -1 |
138 | /* In line mode, it's pretty easy, just cut the lines. */ | | 138 | /* In line mode, it's pretty easy, just cut the lines. */ |
139 | if (LF_ISSET(CUT_LINEMODE)) { | | 139 | if (LF_ISSET(CUT_LINEMODE)) { |
140 | cbp->flags |= CB_LMODE; | | 140 | cbp->flags |= CB_LMODE; |
141 | for (lno = fm->lno; lno <= tm->lno; ++lno) | | 141 | for (lno = fm->lno; lno <= tm->lno; ++lno) |
142 | if (cut_line(sp, lno, 0, 0, cbp)) | | 142 | if (cut_line(sp, lno, 0, ENTIRE_LINE, cbp)) |
143 | goto cut_line_err; | | 143 | goto cut_line_err; |
144 | } else { | | 144 | } else { |
145 | /* | | 145 | /* |
146 | * Get the first line. A length of 0 causes cut_line | | 146 | * Get the first line. A length of ENTIRE_LINE causes cut_line |
147 | * to cut from the MARK to the end of the line. | | 147 | * to cut from the MARK to the end of the line. |
148 | */ | | 148 | */ |
149 | if (cut_line(sp, fm->lno, fm->cno, fm->lno != tm->lno ? | | 149 | if (cut_line(sp, fm->lno, fm->cno, fm->lno != tm->lno ? |
150 | ENTIRE_LINE : (tm->cno - fm->cno) + 1, cbp)) | | 150 | ENTIRE_LINE : (tm->cno - fm->cno) + 1, cbp)) |
151 | goto cut_line_err; | | 151 | goto cut_line_err; |
152 | | | 152 | |
153 | /* Get the intermediate lines. */ | | 153 | /* Get the intermediate lines. */ |
154 | for (lno = fm->lno; ++lno < tm->lno;) | | 154 | for (lno = fm->lno; ++lno < tm->lno;) |
155 | if (cut_line(sp, lno, 0, ENTIRE_LINE, cbp)) | | 155 | if (cut_line(sp, lno, 0, ENTIRE_LINE, cbp)) |
156 | goto cut_line_err; | | 156 | goto cut_line_err; |
157 | | | 157 | |
158 | /* Get the last line. */ | | 158 | /* Get the last line. */ |
159 | if (tm->lno != fm->lno && | | 159 | if (tm->lno != fm->lno && |
| @@ -247,27 +247,27 @@ cut_line(SCR *sp, db_recno_t lno, size_t | | | @@ -247,27 +247,27 @@ cut_line(SCR *sp, db_recno_t lno, size_t |
247 | /* Get the line. */ | | 247 | /* Get the line. */ |
248 | if (db_get(sp, lno, DBG_FATAL, &p, &len)) | | 248 | if (db_get(sp, lno, DBG_FATAL, &p, &len)) |
249 | return (1); | | 249 | return (1); |
250 | | | 250 | |
251 | /* Create a TEXT structure that can hold the entire line. */ | | 251 | /* Create a TEXT structure that can hold the entire line. */ |
252 | if ((tp = text_init(sp, NULL, 0, len)) == NULL) | | 252 | if ((tp = text_init(sp, NULL, 0, len)) == NULL) |
253 | return (1); | | 253 | return (1); |
254 | | | 254 | |
255 | /* | | 255 | /* |
256 | * If the line isn't empty and it's not the entire line, | | 256 | * If the line isn't empty and it's not the entire line, |
257 | * copy the portion we want, and reset the TEXT length. | | 257 | * copy the portion we want, and reset the TEXT length. |
258 | */ | | 258 | */ |
259 | if (len != 0) { | | 259 | if (len != 0) { |
260 | if (clen == 0) | | 260 | if (clen == ENTIRE_LINE) |
261 | clen = len - fcno; | | 261 | clen = len - fcno; |
262 | MEMCPYW(tp->lb, p + fcno, clen); | | 262 | MEMCPYW(tp->lb, p + fcno, clen); |
263 | tp->len = clen; | | 263 | tp->len = clen; |
264 | } | | 264 | } |
265 | | | 265 | |
266 | /* Append to the end of the cut buffer. */ | | 266 | /* Append to the end of the cut buffer. */ |
267 | CIRCLEQ_INSERT_TAIL(&cbp->textq, tp, q); | | 267 | CIRCLEQ_INSERT_TAIL(&cbp->textq, tp, q); |
268 | cbp->len += tp->len; | | 268 | cbp->len += tp->len; |
269 | | | 269 | |
270 | return (0); | | 270 | return (0); |
271 | } | | 271 | } |
272 | | | 272 | |
273 | /* | | 273 | /* |