1 /*- 2 * Copyright (c) 1992 The Regents of the University of California. 3 * All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Rodney Ruddock of the University of Guelph. 7 * 8 * %sccs.include.redist.c% 9 */ 10 11 #ifndef lint 12 static char sccsid[] = "@(#)get_line.c 5.2 (Berkeley) 01/23/93"; 13 #endif /* not lint */ 14 15 #include <sys/types.h> 16 17 #include <db.h> 18 #include <regex.h> 19 #include <setjmp.h> 20 #include <stdio.h> 21 #include <string.h> 22 23 #include "ed.h" 24 #include "extern.h" 25 26 /* 27 * Get the specified line from the buffer. Note that in the buffer 28 * we stored lengths of text, not strings (NULL terminated, except 29 * under MEMORY). So we want to put a terminating NULL in for 30 * whatever command is going to be handling the line. 31 */ 32 33 /* these variables are here (instead of main and ed.h) because they 34 * are only used with the buffer when run under STDIO. STDIO is a 35 * resource pig with most of the OS's I've tested this with. The 36 * use of these variables improves performance up to 100% in several 37 * cases. The piggyness is thus: fseek causes the current STDIO buf 38 * to be flushed out and a new one read in...even when it is not necessary! 39 * Read 512 (or 1024) when you don't have to for almost every access 40 * and you'll slow down too. So these variable are used to control unneeded 41 * fseeks. 42 * I've been told the newer BSD STDIO has fixed this, but don't 43 * currently have a copy. 44 */ 45 int file_loc=0; 46 47 /* Get a particular line of length len from ed's buffer and place it in 48 * 'text', the standard repository for the "current" line. 49 */ 50 void 51 get_line(loc, len) 52 recno_t loc; 53 int len; 54 { 55 DBT db_key, db_data; 56 57 (db_key.data) = &loc; 58 (db_key.size) = sizeof(recno_t); 59 (dbhtmp->get) (dbhtmp, &db_key, &db_data, (u_int) 0); 60 strcpy(text, db_data.data); 61 text[len] = '\0'; 62 } 63