995
|
1 /*
|
|
2 * The routines in this file
|
|
3 * handle the reading and writing of
|
|
4 * disk files. All of details about the
|
|
5 * reading and writing of the disk are
|
|
6 * in "fileio.c".
|
|
7 */
|
|
8 #include <stdio.h>
|
|
9 #include "ueed.h"
|
|
10
|
|
11 /*
|
|
12 * Save the contents of the current
|
|
13 * buffer in its associatd file. No nothing
|
|
14 * if nothing has changed (this may be a bug, not a
|
|
15 * feature). Error if there is no remembered file
|
|
16 * name for the buffer. Bound to "C-X C-S". May
|
|
17 * get called by "C-Z".
|
|
18 */
|
|
19 filesave(f, n)
|
|
20 {
|
|
21 register WINDOW *wp;
|
|
22 register int s;
|
|
23
|
|
24 if ((curbp->b_flag&BFCHG) == 0) /* Return, no changes. */
|
|
25 return (TRUE);
|
|
26 if (curbp->b_fname[0] == 0) { /* Must have a name. */
|
|
27 mlwrite("No file name");
|
|
28 return (FALSE);
|
|
29 }
|
|
30 if ((s=writeout(curbp->b_fname)) == TRUE) {
|
|
31 curbp->b_flag &= ~BFCHG;
|
|
32 wp = wheadp; /* Update mode lines. */
|
|
33 while (wp != NULL) {
|
|
34 if (wp->w_bufp == curbp)
|
|
35 wp->w_flag |= WFMODE;
|
|
36 wp = wp->w_wndp;
|
|
37 }
|
|
38 }
|
|
39 return (s);
|
|
40 }
|
|
41
|
|
42 /*
|
|
43 * This function performs the details of file
|
|
44 * writing. Uses the file management routines in the
|
|
45 * "fileio.c" package. The number of lines written is
|
|
46 * displayed. Sadly, it looks inside a LINE; provide
|
|
47 * a macro for this. Most of the grief is error
|
|
48 * checking of some sort.
|
|
49 */
|
|
50 writeout(fn)
|
|
51 char *fn;
|
|
52 {
|
|
53 register int s;
|
|
54 register LINE *lp;
|
|
55 register int nline;
|
|
56
|
|
57 if ((s=ffwopen(fn)) != FIOSUC) /* Open writes message. */
|
|
58 return (FALSE);
|
|
59 lp = lforw(curbp->b_linep); /* First line. */
|
|
60 nline = 0; /* Number of lines. */
|
|
61 while (lp != curbp->b_linep) {
|
|
62 if ((s=ffputline(&lp->l_text[0], llength(lp))) != FIOSUC)
|
|
63 break;
|
|
64 ++nline;
|
|
65 lp = lforw(lp);
|
|
66 }
|
|
67 if (s == FIOSUC) { /* No write error. */
|
|
68 s = ffclose();
|
|
69 if (s == FIOSUC) { /* No close error. */
|
|
70 if (nline == 1)
|
|
71 mlwrite("[Wrote 1 line]");
|
|
72 else
|
|
73 mlwrite("[Wrote %d lines]", nline);
|
|
74 }
|
|
75 } else /* Ignore close error */
|
|
76 ffclose(); /* if a write error. */
|
|
77 if (s != FIOSUC) /* Some sort of error. */
|
|
78 return (FALSE);
|
|
79 return (TRUE);
|
|
80 }
|
|
81
|
|
82 /*
|
|
83 * The command allows the user
|
|
84 * to modify the file name associated with
|
|
85 * the current buffer. It is like the "f" command
|
|
86 * in UNIX "ed". The operation is simple; just zap
|
|
87 * the name in the BUFFER structure, and mark the windows
|
|
88 * as needing an update. You can type a blank line at the
|
|
89 * prompt if you wish.
|
|
90 */
|
|
91 filename(f, n)
|
|
92 {
|
|
93 register WINDOW *wp;
|
|
94 register int s;
|
|
95 char fname[NFILEN];
|
|
96
|
|
97 if ((s=mlreply("Name: ", fname, NFILEN)) == ABORT)
|
|
98 return (s);
|
|
99 if (s == FALSE)
|
|
100 strcpy(curbp->b_fname, "");
|
|
101 else
|
|
102 strcpy(curbp->b_fname, fname);
|
|
103 wp = wheadp; /* Update mode lines. */
|
|
104 while (wp != NULL) {
|
|
105 if (wp->w_bufp == curbp)
|
|
106 wp->w_flag |= WFMODE;
|
|
107 wp = wp->w_wndp;
|
|
108 }
|
|
109 return (TRUE);
|
|
110 }
|
|
111
|
|
112
|