1*57675Sbostic /*- 2*57675Sbostic * Copyright (c) 1992 The Regents of the University of California. 3*57675Sbostic * All rights reserved. 4*57675Sbostic * 5*57675Sbostic * This code is derived from software contributed to Berkeley by 6*57675Sbostic * Rodney Ruddock of the University of Guelph. 7*57675Sbostic * 8*57675Sbostic * %sccs.include.redist.c% 9*57675Sbostic */ 10*57675Sbostic 11*57675Sbostic #ifndef lint 12*57675Sbostic static char sccsid[] = "@(#)add_line.c 5.1 (Berkeley) 01/23/93"; 13*57675Sbostic #endif /* not lint */ 14*57675Sbostic 15*57675Sbostic #include "ed.h" 16*57675Sbostic 17*57675Sbostic /* 18*57675Sbostic * This is where the lines actually are put into the buffer. Notice 19*57675Sbostic * all the #ifdef's for the various methods of buffering - POSIX said 20*57675Sbostic * no "no attempt is made to imply a specific implementation". So, 21*57675Sbostic * you get your choice: standard I/O, core memory, or a database. 22*57675Sbostic */ 23*57675Sbostic 24*57675Sbostic #ifdef STDIO 25*57675Sbostic long 26*57675Sbostic add_line(p, len) 27*57675Sbostic #endif 28*57675Sbostic #ifdef DBI 29*57675Sbostic recno_t 30*57675Sbostic add_line(p, len) 31*57675Sbostic #endif 32*57675Sbostic #ifdef MEMORY 33*57675Sbostic char 34*57675Sbostic *add_line(p, len) 35*57675Sbostic #endif 36*57675Sbostic 37*57675Sbostic char *p; 38*57675Sbostic long len; 39*57675Sbostic 40*57675Sbostic { 41*57675Sbostic #ifdef STDIO 42*57675Sbostic long l_key; 43*57675Sbostic extern int file_loc; 44*57675Sbostic 45*57675Sbostic if (file_seek) /* x-ref to get_line for what this does */ 46*57675Sbostic { 47*57675Sbostic file_seek = 0; 48*57675Sbostic fseek(fhtmp, 0L, 2); /* set to end-to-file */ 49*57675Sbostic } 50*57675Sbostic l_key = ftell(fhtmp); 51*57675Sbostic file_loc = l_key + fwrite(p, sizeof(char), len, fhtmp); /* keeps user time down 20%approx */ 52*57675Sbostic return(l_key); 53*57675Sbostic #endif 54*57675Sbostic 55*57675Sbostic #ifdef DBI 56*57675Sbostic DBT db_key, db_data; 57*57675Sbostic static recno_t l_key=0; 58*57675Sbostic 59*57675Sbostic l_key++; 60*57675Sbostic (db_key.data) = &l_key; 61*57675Sbostic (db_key.size) = sizeof(recno_t); 62*57675Sbostic (db_data.data) = p; 63*57675Sbostic (db_data.size) = len; 64*57675Sbostic (dbhtmp->put)(dbhtmp, &db_key, &db_data, (u_int)(R_NOOVERWRITE)); 65*57675Sbostic return(l_key); 66*57675Sbostic #endif 67*57675Sbostic 68*57675Sbostic #ifdef MEMORY 69*57675Sbostic char *tmp; 70*57675Sbostic tmp = (char *)calloc(len+1, sizeof(char)); 71*57675Sbostic if (tmp) 72*57675Sbostic { 73*57675Sbostic bcopy(p, tmp, len); 74*57675Sbostic tmp[len] = '\0'; 75*57675Sbostic } 76*57675Sbostic return(tmp); 77*57675Sbostic #endif 78*57675Sbostic 79*57675Sbostic } /* end-add_line */ 80