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