157675Sbostic /*- 257675Sbostic * Copyright (c) 1992 The Regents of the University of California. 357675Sbostic * All rights reserved. 457675Sbostic * 557675Sbostic * This code is derived from software contributed to Berkeley by 657675Sbostic * Rodney Ruddock of the University of Guelph. 757675Sbostic * 857675Sbostic * %sccs.include.redist.c% 957675Sbostic */ 1057675Sbostic 1157675Sbostic #ifndef lint 12*58315Sbostic static char sccsid[] = "@(#)add_line.c 5.3 (Berkeley) 02/28/93"; 1357675Sbostic #endif /* not lint */ 1457675Sbostic 1557710Sbostic #include <sys/types.h> 1657710Sbostic 1757710Sbostic #include <regex.h> 1857710Sbostic #include <setjmp.h> 1957710Sbostic #include <stdio.h> 2057710Sbostic 21*58315Sbostic #ifdef DBI 22*58315Sbostic #include <db.h> 23*58315Sbostic #endif 24*58315Sbostic 2557675Sbostic #include "ed.h" 2657710Sbostic #include "extern.h" 2757675Sbostic 2857675Sbostic /* 2957710Sbostic * This is where the lines actually are put into the buffer. 3057675Sbostic */ 31*58315Sbostic #ifdef STDIO 32*58315Sbostic long 33*58315Sbostic add_line(p, len) 34*58315Sbostic char *p; 35*58315Sbostic long len; 36*58315Sbostic { 37*58315Sbostic extern int file_loc; 38*58315Sbostic long l_key; 39*58315Sbostic int l_jmp_flag; 40*58315Sbostic 41*58315Sbostic if (l_jmp_flag = setjmp(ctrl_position2)) 42*58315Sbostic return (0); 43*58315Sbostic sigspecial2 = 1; 44*58315Sbostic if (file_seek) /* x-ref to get_line for what this does */ { 45*58315Sbostic file_seek = 0; 46*58315Sbostic fseek(fhtmp, 0L, 2); /* set to end-to-file */ 47*58315Sbostic } 48*58315Sbostic l_key = ftell(fhtmp); 49*58315Sbostic /* keeps user time down 20%approx */ 50*58315Sbostic file_loc = l_key + fwrite(p, sizeof(char), len, fhtmp); 51*58315Sbostic return (l_key); 52*58315Sbostic } 53*58315Sbostic #endif 54*58315Sbostic 55*58315Sbostic #ifdef DBI 5657675Sbostic recno_t 5757675Sbostic add_line(p, len) 5857710Sbostic char *p; 5957710Sbostic long len; 6057675Sbostic { 6157710Sbostic DBT db_key, db_data; 6257710Sbostic static recno_t l_key; 63*58315Sbostic int l_jmp_flag; 6457675Sbostic 65*58315Sbostic if (l_jmp_flag = setjmp(ctrl_position2)) 66*58315Sbostic return ((recno_t)0); 67*58315Sbostic sigspecial2 = 1; 6857710Sbostic l_key++; 6957710Sbostic (db_key.data) = &l_key; 7057710Sbostic (db_key.size) = sizeof(recno_t); 7157710Sbostic (db_data.data) = p; 7257710Sbostic (db_data.size) = len; 7357710Sbostic (dbhtmp->put)(dbhtmp, &db_key, &db_data, (u_int)(R_NOOVERWRITE)); 74*58315Sbostic return (l_key); 7557710Sbostic } 76*58315Sbostic #endif 77*58315Sbostic 78*58315Sbostic #ifdef MEMORY 79*58315Sbostic char * 80*58315Sbostic add_line(p, len) 81*58315Sbostic char *p; 82*58315Sbostic long len; 83*58315Sbostic { 84*58315Sbostic char *tmp; 85*58315Sbostic int l_jmp_flag; 86*58315Sbostic 87*58315Sbostic if (l_jmp_flag = setjmp(ctrl_position2)) 88*58315Sbostic return (NULL); 89*58315Sbostic sigspecial2 = 1; 90*58315Sbostic tmp = (char *)calloc(len+1, sizeof(char)); 91*58315Sbostic if (tmp) { 92*58315Sbostic bcopy(p, tmp, len); 93*58315Sbostic tmp[len] = '\0'; 94*58315Sbostic } 95*58315Sbostic return (tmp); 96*58315Sbostic } 97*58315Sbostic #endif 98