date and time created 93/01/23 11:13:20 by bostic
[unix-history] / usr / src / contrib / ed / q.c
CommitLineData
c6644c22
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
12static char sccsid[] = "@(#)q.c 5.1 (Berkeley) %G%";
13#endif /* not lint */
14
15#include "ed.h"
16
17/*
18 * End this editting session and exit with saving the buffer. If no
19 * write has occurred since the last buffer modification a warning
20 * is given once ('Q' over-rides the warning).
21 */
22
23void
24q(inputt, errnum)
25
26FILE *inputt;
27int *errnum;
28
29{
30 int l_which; /* which is it? 'q' or 'Q' */
31 register int l_ss=ss;
32
33 l_which = ss;
34
35 while (1)
36 {
37 l_ss = getc(inputt);
38 if ((l_ss != ' ') && (l_ss != '\n') && (l_ss != EOF))
39 {
40 *errnum = -1;
41 strcpy(help_msg, "illegal command option");
42 return;
43 }
44 if ((l_ss == '\n') || (l_ss == EOF))
45 break;
46 }
47
48 ungetc(l_ss, inputt);
49 /* note: 'Q' will bypass this if stmt., which warns of no save */
50 if ((change_flag == 1L) && (l_which == 'q'))
51 {
52 change_flag = 0L;
53 strcpy(help_msg, "buffer changes not saved");
54 *errnum = -1;
55 ss = l_ss;
56 return;
57 }
58
59 /* do cleanup; should it be even bothered?? */
60 start = top;
61 End = bottom;
62 start_default = End_default = 0;
63 d(inputt, errnum); /* we don't care about the returned errnum val anymore */
64 u_clr_stk();
65 free(text);
66 free(filename_current);
67#ifdef STDIO
68
69 fclose(fhtmp);
70 unlink(template);
71#endif
72#ifdef DBI
73 (dbhtmp->close)(dbhtmp); /* overhead as the cache is flushed */
74 unlink(template);
75#endif
76 exit(0);
77} /* end-q */