8-bit characters are not ignored
[unix-history] / usr / src / contrib / ed / t.c
CommitLineData
de776f26
KB
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
e692f66f 12static char sccsid[] = "@(#)t.c 5.3 (Berkeley) %G%";
de776f26
KB
13#endif /* not lint */
14
ecbf4ad0
KB
15#include <sys/types.h>
16
ecbf4ad0
KB
17#include <regex.h>
18#include <setjmp.h>
19#include <stdio.h>
20#include <stdlib.h>
21#include <string.h>
22
e692f66f
KB
23#ifdef DBI
24#include <db.h>
25#endif
26
de776f26 27#include "ed.h"
ecbf4ad0 28#include "extern.h"
de776f26
KB
29
30/*
31 * The transcribe function. POSIX calls it copy, but 't' for transcribe
32 * is more mneumonic and that's what I've always called it. Transcribes
33 * the spec'd lines into the buffer at the spec'd location.
34 */
35
36void
37t(inputt, errnum)
ecbf4ad0
KB
38 FILE *inputt;
39 int *errnum;
de776f26 40{
e692f66f 41 LINE *l_ptr, *l_tb, *l_te, *l_temp1, *l_temp2, *l_dest=NULL;
ecbf4ad0
KB
42
43 l_tb = NULL;
44 l_te = NULL;
45
46 if (((ss = getc(inputt)) != '\n') && (ss != EOF)) {
47 for (;;) {
48 if (ss != ' ') {
49 ungetc(ss, inputt);
50 break;
51 }
52 ss = getc(inputt);
53 }
54 l_dest = address_conv(NULL, inputt, errnum);
55 } else
56 (ungetc(ss, inputt), *errnum = -1);
57
ecbf4ad0
KB
58 if (*errnum < 0) {
59 strcpy(help_msg, "bad destination address");
60 return;
61 }
62 *errnum = 0;
63 if (rol(inputt, errnum))
64 return;
65
66 if (start_default && End_default)
67 start = End = current;
68 else
69 if (start_default)
70 start = End;
71 if (start == NULL) {
e692f66f 72 strcpy(help_msg, "empty buffer");
ecbf4ad0
KB
73 *errnum = -1;
74 return;
75 }
76 start_default = End_default = 0;
77
ecbf4ad0
KB
78 if (g_flag == 0)
79 u_clr_stk();
80
e692f66f
KB
81 sigspecial++;
82
ecbf4ad0
KB
83 for (l_ptr = start; l_ptr != (End->below); l_ptr = (l_ptr->below)) {
84 get_line(l_ptr->handle, l_ptr->len);
e692f66f
KB
85 if (sigint_flag && (!sigspecial))
86 break;
ecbf4ad0
KB
87 l_temp1 = (LINE *) malloc(sizeof(LINE));
88 if (l_temp1 == NULL) {
89 *errnum = -1;
90 strcpy(help_msg, "out of memory error");
91 return;
92 }
93 if (l_tb == NULL) {
94 l_tb = l_temp1;
95 (l_temp1->above) = NULL;
96 (l_temp1->below) = NULL;
97 } else {
98 (l_temp1->above) = l_te;
99 (l_temp1->below) = NULL;
100 (l_te->below) = l_temp1;
101 }
102 l_te = l_temp1;
103 (l_temp1->len) = l_ptr->len;
104 /* add it into the buffer at the spec'd location */
105 (l_temp1->handle) = add_line(text, l_ptr->len);
e692f66f 106 if (sigint_flag && (!sigspecial))
ecbf4ad0
KB
107 break;
108 }
109
110 if (l_dest == NULL)
111 l_temp2 = top;
112 else {
113 u_add_stk(&(l_dest->below));
114 l_temp2 = l_dest->below;
115 }
116
117 if (l_dest == NULL) {
118 u_add_stk(&(top->above));
119 (top->above) = l_tb;
120 top = l_tb;
121 (l_tb->above) = NULL;
122 } else {
123 (l_tb->above) = l_dest;
124 (l_dest->below) = l_tb;
125 }
126
127 if (l_dest == bottom) {
128 bottom = l_te;
129 (l_te->below) = NULL;
130 } else {
131 (l_te->below) = l_temp2;
132 u_add_stk(&(l_temp2->above));
133 (l_temp2->above) = l_te;
134 }
135
136 current = l_te;
137 change_flag = 1;
e692f66f 138 sigspecial--;
ecbf4ad0
KB
139 *errnum = 1;
140 return;
141}