/*************************************************************************
* This program is copyright (C) 1985, 1986 by Jonathan Payne. It is *
* provided to you without charge for use only on a licensed Unix *
* system. You may copy JOVE provided that this notice is included with *
* the copy. You may not sell copies of this program or versions *
* modified for use on microcomputer systems, unless the copies are *
* included with a Unix system distribution and the source is provided. *
*************************************************************************/
/* Contains commands that deal with creating, selecting, killing and
listing buffers, and buffer modes, and find-file, etc. */
*NoName
= "Sans un nom!";
Buffer
*world
= 0, /* First in the list */
*lastbuf
= 0; /* Last buffer we were in so we have a default
buffer during a select buffer. */
/* Toggle BIT in the current buffer's minor mode flags. If argument is
supplied, a positive one always turns on the mode and zero argument
/* Creates a new buffer, links it at the end of the buffer chain, and
for (b
= world
; b
!= 0; lastbp
= b
, b
= b
->b_next
)
b
= (Buffer
*) emalloc(sizeof (Buffer
));
/* Makes a buffer and initializes it. Obsolete. Used to take two
arguments, a buffer name and a file name. */
newb
->b_themark
= 0; /* Index into markring */
for (i
= 0; i
< NMARKS
; i
++)
newb
->b_type
= B_FILE
; /* File until proven SCRATCH */
*second
= "%s already exists; new name? ";
new = ask((char *) 0, prompt
, new);
name
= ask_file(curbuf
->b_fname
, fnamebuf
);
SetBuf(do_find(curwind
, name
, 0));
for (b
= world
; b
!= 0; b
= b
->b_next
)
if (def
!= 0 && def
->b_name
!= 0)
sprintf(prompt
, ": %f (default %s) ", def
->b_name
);
sprintf(prompt
, ProcFmt
);
offset
= complete(bnames
, prompt
, RET_STATE
);
else if (offset
== NULLSTRING
) {
bname
= ask_buf(lastbuf
);
SetBuf(do_select(curwind
, bname
));
register Window
*w
= fwind
;
if (lastbuf
== b
|| lastbuf
== 0) {
alt
= (b
->b_next
!= 0) ? b
->b_next
->b_name
: Mainbuf
;
(void) do_select(w
, alt
);
register Window
*save
= w
->w_next
;
if ((delbuf
= buf_exists(bname
)) == 0)
complain("[No such buffer]");
confirm("%s modified, are you sure? ", bname
);
if (delbuf
= getNMbuf()) {
pbuftiedp(delbuf
); /* Make sure buffer is not tied to a process */
for (b
= world
; b
!= 0; lastb
= b
, b
= b
->b_next
)
lastb
->b_next
= delbuf
->b_next
;
#define okay_free(ptr) if (ptr) free(ptr)
lfreelist(delbuf
->b_first
);
okay_free(delbuf
->b_name
);
okay_free(delbuf
->b_fname
);
if (perr_buf
== delbuf
) {
/* offer to kill some buffers */
for (b
= world
; b
!= 0; b
= next
) {
y_or_n
= ask("No", "Kill %s? ", b
->b_name
);
if (Upper(*y_or_n
) != 'Y')
y_or_n
= ask("No", "%s modified; should I save it? ", b
->b_name
);
if (Upper(*y_or_n
) == 'Y') {
if ((b
= getNMbuf()) == 0)
for (lp
= b
->b_first
; lp
!= 0; lp
= lp
->l_next
, nlines
++)
sprintf(buf
, "%d", nlines
);
static char *TypeNames
[] = {
register char *format
= "%-2s %-5s %-11s %-1s %-*s %-s";
int bcount
= 1, /* To give each buffer a number */
for (b
= world
; b
!= 0; b
= b
->b_next
)
buf_width
= max(buf_width
, strlen(b
->b_name
));
TOstart("Buffer list", TRUE
); /* true means auto-newline */
Typeout("(* means buffer needs saving)");
Typeout("(+ means file hasn't been read yet)");
Typeout(format
, "NO", "Lines", "Type", NullStr
, buf_width
, "Name", "File");
Typeout(format
, "--", "-----", "----", NullStr
, buf_width
, "----", "----");
for (b
= world
; b
!= 0; b
= b
->b_next
) {
Typeout(format
, itoa(bcount
++),
b
->b_ntbf
? "+" : NullStr
,
/* For the * (variable length field) */
complain("[No file name]");
cp
= basename(b
->b_fname
);
while (buf_exists(tmp
)) {
sprintf(tmp
, "%s.%d", cp
, try);
b
->b_first
= b
->b_dot
= b
->b_last
= 0;
(void) listput(b
, b
->b_first
);
SavLine(b
->b_dot
, NullStr
);
AllMarkSet(b
, b
->b_dot
, 0);
/* Returns pointer to buffer with name NAME, or if NAME is a string of digits
returns the buffer whose number equals those digits. Otherwise, returns
for (bp
= world
; bp
!= 0; bp
= bp
->b_next
)
if (strcmp(bp
->b_name
, name
) == 0)
/* Doesn't match any names. Try for a buffer number... */
if ((n
= chr_to_int(name
, 10, 1)) > 0) {
for (bp
= world
; n
> 1; bp
= bp
->b_next
) {
/* Returns buffer pointer with a file name NAME, if one exists. Stat's the
file and compares inodes, in case NAME is a link, as well as the actual
characters that make up the file name. */
register struct stat
*s
= &stbuf
;
PathParse(name
, fnamebuf
);
if (stat(fnamebuf
, s
) == -1)
for (b
= world
; b
!= 0; b
= b
->b_next
) {
if ((b
->b_ino
!= 0 && b
->b_ino
== s
->st_ino
) ||
(strcmp(b
->b_fname
, fnamebuf
) == 0))
new = realloc(obj
, (unsigned) size
);
UpdModLine
++; /* Kludge ... but speeds things up considerably */
b
->b_name
= ralloc(b
->b_name
, strlen(name
) + 1);
char wholename
[FILESIZE
],
UpdModLine
++; /* Kludge ... but speeds things up considerably */
strcpy(oldname
, b
->b_fname
);
PathParse(name
, wholename
);
curbuf
->b_fname
= ralloc(curbuf
->b_fname
, strlen(wholename
) + 1);
strcpy(curbuf
->b_fname
, wholename
);
DoAutoExec(curbuf
->b_fname
, oldptr
);
curbuf
->b_mtime
= curbuf
->b_ino
= 0; /* until they're known. */
if (b
->b_fname
== 0 || stat(b
->b_fname
, &stbuf
) == -1) {
b
->b_mtime
= stbuf
.st_mtime
;
/* Find the file `fname' into buf and put in in window `w' */
SetBuf(b
); /* this'll read the file */
/* Set alternate buffer */
register Buffer
*oldb
= curbuf
;
if (newbuf
== curbuf
|| newbuf
== 0)
/* Do the read now ... */
read_file(curbuf
->b_fname
, 0);
if (oldb
!= 0 && oldb
->b_type
!= curbuf
->b_type
) {
if (curbuf
->b_type
== B_IPROCESS
)
PushPBs(); /* Push process bindings */
else if (oldb
->b_type
== B_IPROCESS
)
assign_p(); /* Set cur_proc */
if ((new = buf_exists(name
)) == 0) {
setfname(new, (char *) 0);