/* Copyright (c) 1981 Regents of the University of California */
static char *sccsid
= "@(#)ex_subr.c 7.2 %G%";
* Random routines, in alphabetical order.
j
= i
% value(SHIFTWIDTH
);
* Column returns the number of
* columns occupied by printing the
* characters through position cp of the
cp
= &linebuf
[LBSIZE
- 2];
return (qcolumn(cp
, (char *) 0));
* Ignore a comment to the end of the line.
* This routine eats the trailing newline so don't call newline().
} while (c
!= '\n' && c
!= EOF
);
register char *from
, *to
;
register line
*from
, *to
;
register line
*from
, *to
;
return (c
== TRIM
? '?' : c
| ('A' - 1));
else if (value(ERRORBELLS
))
if (*cp
== 0 && i
== indent
&& linebuf
[0] == 0) {
register int oerrno
= errno
;
for (cp
= genbuf
; indent
>= value(TABSTOP
); indent
-= value(TABSTOP
))
for (; indent
> 0; indent
--)
for (addr
= one
; addr
<= dol
; addr
++)
if (names
[c
- 'a'] == (*addr
&~ 01)) {
i
= i
* 10 + *cp
++ - '0';
register int c
= getchar();
return (c
== ' ' || c
== '\t');
if (c
&& !value(BEAUTIFY
))
if (c
>= ' ' && c
!= TRIM
)
killcnt(addr2
- addr1
+ 1);
printf(" %c%s", Command
[0] | ' ', Command
+ 1);
if (Command
[strlen(Command
) - 1] != 'e')
if ((inglobal
== 0 || inopen
) && which
<= endcore
) {
names
['z'-'a'+1] = *which
& ~01;
ncols
['z'-'a'+1] = cursor
;
if (c
== '\'' || c
== '`')
if (c
>= 'a' && c
<= 'z')
* Mesg decodes the terse/verbose strings. Thus
* 'xxx@yyy' -> 'xxx' if terse, else 'xxx yyy'
* 'xxx|yyy' -> 'xxx' if terse, else 'yyy'
* All others map to themselves.
str
= strcpy(genbuf
, str
);
for (cp
= str
; *cp
; cp
++)
register char *cp
= linebuf
;
lseek(erfile
, (long) seekpt
, 0);
if (read(erfile
, linebuf
, 128) < 2)
if ((int) sbrk(1024 * sizeof (line
)) == -1)
error("Nonzero address required@on this command");
return (hush
== 0 && !inglobal
&& i
> value(REPORT
));
error("No lines@in the buffer");
netchange(lineDOL() - cnt
);
notesgn
= cp
= "fewer ", i
= -i
;
printf(mesg("%d %slines@in file after %s"), i
, cp
, Command
);
for (markp
= (anymarks
? names
: &names
['z'-'a'+1]);
markp
<= &names
['z'-'a'+1]; markp
++)
return (i
== 1 ? "" : "s");
vcntcol
+= value(TABSTOP
) - vcntcol
% value(TABSTOP
);
more
= (a2
- a1
+ 1) - (unddol
- dol
);
while (more
> (endcore
- truedol
))
error("Out of memory@saving lines for undo - try using ed");
(*(more
> 0 ? copywR
: copyw
))(unddol
+ more
+ 1, unddol
+ 1,
copyw(dol
+ 1, a1
, a2
- a1
+ 1);
return (addr2
- addr1
+ 1);
while (iswhite(peekchar())) {
lprintf(mesg(linebuf
), cp
);
#define std_nerrs (sizeof std_errlist / sizeof std_errlist[0])
error("No such file or directory"),
error("No such process"),
error("Interrupted system call"),
error("Physical I/O error"),
error("No such device or address"),
error("Argument list too long"),
error("Exec format error"),
error("Bad file number"),
error("No more processes"),
error("Not enough core"),
error("Permission denied"),
error("Block device required"),
error("Mount device busy"),
error("Cross-device link"),
error("Not a directory"),
error("Invalid argument"),
error("File table overflow"),
error("Too many open files"),
error("Not a typewriter"),
error("No space left on device"),
error("Read-only file system"),
error("Result too large"),
error("Quota exceeded") /* Berkeley quota systems only */
edited
= 0; /* for temp file errors, for example */
if (e
>= 0 && errno
<= std_nerrs
)
error("System error %d", e
);
* Return the column number that results from being in column col and
* hitting a tab, where tabs are set every ts columns. Work right for
* the case where col > COLUMNS, even if ts does not divide COLUMNS.
offset
= COLUMNS
* (col
/COLUMNS
);
result
= col
+ ts
- (col
% ts
) + offset
;
register int (*OO
)() = Outchar
;
ignore(qcolumn(linebuf
- 1, NOSTR
));
for (cp
= linebuf
; *cp
&& vcntcol
< i
; cp
++)
while (iswhite(*cp
) && cp
[1])
i
+= value(TABSTOP
) - i
% value(TABSTOP
);
if (addr
!= dot
&& addr
>= one
&& addr
<= dol
)
* The following code is defensive programming against a bug in the
* pdp-11 overlay implementation. Sometimes it goes nuts and asks
* for an overlay with some garbage number, which generates an emt
* trap. This is a less than elegant solution, but it is somewhat
* better than core dumping and losing your work, leaving your tty
/* 2 and 3 are valid on 11/40 type vi, so */
if (_ovno
< 0 || _ovno
> 3)
error("emt trap, _ovno is %d @ - try again");
* When a hangup occurs our actions are similar to a preserve
* command. If the buffer has not been [Modified], then we do
* nothing but remove the temporary files and exit.
* Otherwise, we sync the temp file and then attempt a preserve.
* If the preserve succeeds, we unlink our temp files.
* If the preserve fails, we leave the temp files as they are
* as they are a backup even without preservation if they
* USG tty driver can send multiple HUP's!!
* An interrupt occurred. Drain any output which
* is still in the output buffering pipeline.
* Catch interrupts again. Unless we are in visual
* reset the output state (out of -nl mode, e.g).
* Then like a normal error (with the \n before Interrupt
* suppressed in visual mode).
signal(SIGINT
, inopen
? vintr
: onintr
);
alarm(0); /* in case we were called from map */
error("\nInterrupt" + inopen
);
* If we are interruptible, enable interrupts again.
* In some critical sections we turn interrupts off,
signal(SIGINT
, inopen
? vintr
: onintr
);
execl(EXPRESERVE
, "expreserve", (char *) 0);
if (rpid
== pid
&& status
== 0)
* We have just gotten a susp. Suspend and prepare to resume.
signal(SIGTSTP
, SIG_DFL
);
else if (state
== CRTOPEN
)