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[] = "@(#)add_line.c 5.4 (Berkeley) 03/02/93"; 13 #endif /* not lint */ 14 15 #include <sys/types.h> 16 17 #include <regex.h> 18 #include <setjmp.h> 19 #include <stdio.h> 20 21 #ifdef DBI 22 #include <db.h> 23 #endif 24 25 #include "ed.h" 26 #include "extern.h" 27 28 /* 29 * This is where the lines actually are put into the buffer. 30 */ 31 #ifdef STDIO 32 long 33 add_line(p, len) 34 char *p; 35 long len; 36 { 37 extern int file_loc; 38 long l_key; 39 int l_jmp_flag; 40 41 if (l_jmp_flag = setjmp(ctrl_position2)) 42 return (0); 43 sigspecial2 = 1; 44 if (file_seek) /* x-ref to get_line for what this does */ { 45 file_seek = 0; 46 fseek(fhtmp, 0L, 2); /* set to end-to-file */ 47 } 48 l_key = ftell(fhtmp); 49 /* keeps user time down 20% approx. */ 50 file_loc = l_key + fwrite(p, sizeof(char), len, fhtmp); 51 sigspecial2 = 0; 52 return (l_key); 53 } 54 #endif 55 56 #ifdef DBI 57 recno_t 58 add_line(p, len) 59 char *p; 60 long len; 61 { 62 DBT db_key, db_data; 63 static recno_t l_key=0; 64 int l_jmp_flag; 65 66 if (l_jmp_flag = setjmp(ctrl_position2)) 67 return ((recno_t)0); 68 sigspecial2 = 1; 69 l_key++; 70 (db_key.data) = &l_key; 71 (db_key.size) = sizeof(recno_t); 72 (db_data.data) = p; 73 (db_data.size) = len; 74 (dbhtmp->put)(dbhtmp, &db_key, &db_data, (u_int)(R_NOOVERWRITE)); 75 sigspecial2 = 0; 76 return (l_key); 77 } 78 #endif 79 80 #ifdef MEMORY 81 char * 82 add_line(p, len) 83 char *p; 84 long len; 85 { 86 char *tmp; 87 int l_jmp_flag; 88 89 if (l_jmp_flag = setjmp(ctrl_position2)) 90 return (NULL); 91 sigspecial2 = 1; 92 tmp = (char *)calloc(len+1, sizeof(char)); 93 if (tmp) { 94 bcopy(p, tmp, len); 95 tmp[len] = '\0'; 96 } 97 sigspecial2 = 0; 98 return (tmp); 99 } 100 #endif 101