* Copyright (c) 1992 The Regents of the University of California.
* This code is derived from software contributed to Berkeley by
* Rodney Ruddock of the University of Guelph.
* %sccs.include.redist.c%
static char sccsid
[] = "@(#)w.c 5.7 (Berkeley) %G%";
* Write the contents of the buffer out to the real file (spec'd or
* remembered). If 'w' then overwrite, if 'W' append to the file. 'W'
* is probably _the_ command that most editors don't have, and it's
* so(!) useful. The 'wq' works as 'w' but 'q' immediately follows.
* Shame on POSIX for not including 'W' and 'wq', they're not that
* hard to implement; yaaa! BSD for keeping it! :-)
int l_ttl
= 0, l_q_flag
= 0, l_sl
, l_bang_flag
=0;
char *filename_read
=NULL
, *l_temp
;
if (Start_default
&& End_default
) {
strcpy(help_msg
, "buffer empty");
Start_default
= End_default
= 0;
if (ss
== 'q') /* "wq" and "Wq" command */
l_temp
= filename(inputt
, errnum
);
while (((ss
= getc(inputt
)) != '\n') || (ss
== EOF
));
filename_read
= filename_current
;
if (filename_current
== NULL
) {
if (filename_read
== NULL
) {
strcpy(help_msg
, "no filename given");
filename_current
= filename_read
;
if (l_temp
&& l_temp
[FILENAME_LEN
+1]) { /* bang flag */
strcpy(help_msg
, "no command given");
if ((l_fp
= popen(l_temp
, "w")) == NULL
) {
strcpy(help_msg
, "error executing command");
l_fp
= fopen(filename_read
, "a");
l_fp
= fopen(filename_read
, "w");
strcpy(help_msg
, "cannot write to file");
if (sigint_flag
&& (!sigspecial
))
/* Write it out and get a report on the number of bytes written. */
l_ttl
= edwrite(l_fp
, Start
, End
);
if (explain_flag
> 0) /* For -s option. */
if (filename_read
!= filename_current
)
if ((Start
== top
) && (End
== bottom
))
if (l_q_flag
) { /* For "wq" and "Wq". */
* Actually writes out the contents of the buffer to the specified
* STDIO file pointer for the range of lines specified.
get_line(begi
->handle
, begi
->len
);
if (sigint_flag
&& (!sigspecial
))
/* Fwrite is about 20+% faster than fprintf -- no surprise. */
fwrite(text
, sizeof(char), begi
->len
, fp
);
l_ttl
= l_ttl
+ (begi
->len
) + 1;
if (sigint_flag
&& (!sigspecial
))