157701Sbostic /*-
2*60663Sbostic * Copyright (c) 1992, 1993
3*60663Sbostic * The Regents of the University of California. All rights reserved.
457701Sbostic *
557701Sbostic * This code is derived from software contributed to Berkeley by
657701Sbostic * Rodney Ruddock of the University of Guelph.
757701Sbostic *
857701Sbostic * %sccs.include.redist.c%
957701Sbostic */
1057701Sbostic
1157701Sbostic #ifndef lint
12*60663Sbostic static char sccsid[] = "@(#)t.c 8.1 (Berkeley) 05/31/93";
1357701Sbostic #endif /* not lint */
1457701Sbostic
1557710Sbostic #include <sys/types.h>
1657710Sbostic
1757710Sbostic #include <regex.h>
1857710Sbostic #include <setjmp.h>
1957710Sbostic #include <stdio.h>
2057710Sbostic #include <stdlib.h>
2157710Sbostic #include <string.h>
2257710Sbostic
2358315Sbostic #ifdef DBI
2458315Sbostic #include <db.h>
2558315Sbostic #endif
2658315Sbostic
2757701Sbostic #include "ed.h"
2857710Sbostic #include "extern.h"
2957701Sbostic
3057701Sbostic /*
3157701Sbostic * The transcribe function. POSIX calls it copy, but 't' for transcribe
3257701Sbostic * is more mneumonic and that's what I've always called it. Transcribes
3357701Sbostic * the spec'd lines into the buffer at the spec'd location.
3457701Sbostic */
3557701Sbostic
3657701Sbostic void
t(inputt,errnum)3757701Sbostic t(inputt, errnum)
3857710Sbostic FILE *inputt;
3957710Sbostic int *errnum;
4057701Sbostic {
4158315Sbostic LINE *l_ptr, *l_tb, *l_te, *l_temp1, *l_temp2, *l_dest=NULL;
4257701Sbostic
4357710Sbostic l_tb = NULL;
4457710Sbostic l_te = NULL;
4557701Sbostic
4657710Sbostic if (((ss = getc(inputt)) != '\n') && (ss != EOF)) {
4757710Sbostic for (;;) {
4857710Sbostic if (ss != ' ') {
4957710Sbostic ungetc(ss, inputt);
5057710Sbostic break;
5157710Sbostic }
5257710Sbostic ss = getc(inputt);
5357710Sbostic }
5457710Sbostic l_dest = address_conv(NULL, inputt, errnum);
5557710Sbostic } else
5657710Sbostic (ungetc(ss, inputt), *errnum = -1);
5757701Sbostic
5857710Sbostic if (*errnum < 0) {
5957710Sbostic strcpy(help_msg, "bad destination address");
6057710Sbostic return;
6157710Sbostic }
6257710Sbostic *errnum = 0;
6357710Sbostic if (rol(inputt, errnum))
6457710Sbostic return;
6557701Sbostic
6658564Sralph if (Start_default && End_default)
6758564Sralph Start = End = current;
6857710Sbostic else
6958564Sralph if (Start_default)
7058564Sralph Start = End;
7158564Sralph if (Start == NULL) {
7258315Sbostic strcpy(help_msg, "empty buffer");
7357710Sbostic *errnum = -1;
7457710Sbostic return;
7557710Sbostic }
7658564Sralph Start_default = End_default = 0;
7757701Sbostic
7857710Sbostic if (g_flag == 0)
7957710Sbostic u_clr_stk();
8057701Sbostic
8158315Sbostic sigspecial++;
8258315Sbostic
8358564Sralph for (l_ptr = Start; l_ptr != (End->below); l_ptr = (l_ptr->below)) {
8457710Sbostic get_line(l_ptr->handle, l_ptr->len);
8558315Sbostic if (sigint_flag && (!sigspecial))
8658315Sbostic break;
8757710Sbostic l_temp1 = (LINE *) malloc(sizeof(LINE));
8857710Sbostic if (l_temp1 == NULL) {
8957710Sbostic *errnum = -1;
9057710Sbostic strcpy(help_msg, "out of memory error");
9157710Sbostic return;
9257710Sbostic }
9357710Sbostic if (l_tb == NULL) {
9457710Sbostic l_tb = l_temp1;
9557710Sbostic (l_temp1->above) = NULL;
9657710Sbostic (l_temp1->below) = NULL;
9757710Sbostic } else {
9857710Sbostic (l_temp1->above) = l_te;
9957710Sbostic (l_temp1->below) = NULL;
10057710Sbostic (l_te->below) = l_temp1;
10157710Sbostic }
10257710Sbostic l_te = l_temp1;
10357710Sbostic (l_temp1->len) = l_ptr->len;
10457710Sbostic /* add it into the buffer at the spec'd location */
10557710Sbostic (l_temp1->handle) = add_line(text, l_ptr->len);
10658315Sbostic if (sigint_flag && (!sigspecial))
10757710Sbostic break;
10857710Sbostic }
10957701Sbostic
11057710Sbostic if (l_dest == NULL)
11157710Sbostic l_temp2 = top;
11257710Sbostic else {
11357710Sbostic u_add_stk(&(l_dest->below));
11457710Sbostic l_temp2 = l_dest->below;
11557710Sbostic }
11657701Sbostic
11757710Sbostic if (l_dest == NULL) {
11857710Sbostic u_add_stk(&(top->above));
11957710Sbostic (top->above) = l_tb;
12057710Sbostic top = l_tb;
12157710Sbostic (l_tb->above) = NULL;
12257710Sbostic } else {
12357710Sbostic (l_tb->above) = l_dest;
12457710Sbostic (l_dest->below) = l_tb;
12557710Sbostic }
12657701Sbostic
12757710Sbostic if (l_dest == bottom) {
12857710Sbostic bottom = l_te;
12957710Sbostic (l_te->below) = NULL;
13057710Sbostic } else {
13157710Sbostic (l_te->below) = l_temp2;
13257710Sbostic u_add_stk(&(l_temp2->above));
13357710Sbostic (l_temp2->above) = l_te;
13457710Sbostic }
13557701Sbostic
13657710Sbostic current = l_te;
13757710Sbostic change_flag = 1;
13858315Sbostic sigspecial--;
13957710Sbostic *errnum = 1;
14057710Sbostic return;
14157710Sbostic }
142