Commit | Line | Data |
---|---|---|
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 | |
672cc1c0 | 12 | static char sccsid[] = "@(#)q.c 5.5 (Berkeley) %G%"; |
c6644c22 KB |
13 | #endif /* not lint */ |
14 | ||
ecbf4ad0 KB |
15 | #include <sys/types.h> |
16 | ||
ecbf4ad0 KB |
17 | #include <regex.h> |
18 | #include <setjmp.h> | |
19 | #include <stdio.h> | |
20 | #include <stdlib.h> | |
21 | #include <string.h> | |
22 | #include <unistd.h> | |
23 | ||
e692f66f KB |
24 | #ifdef DBI |
25 | #include <db.h> | |
26 | #endif | |
27 | ||
c6644c22 | 28 | #include "ed.h" |
ecbf4ad0 | 29 | #include "extern.h" |
c6644c22 KB |
30 | |
31 | /* | |
32 | * End this editting session and exit with saving the buffer. If no | |
33 | * write has occurred since the last buffer modification a warning | |
34 | * is given once ('Q' over-rides the warning). | |
35 | */ | |
c6644c22 KB |
36 | void |
37 | q(inputt, errnum) | |
ecbf4ad0 KB |
38 | FILE *inputt; |
39 | int *errnum; | |
c6644c22 | 40 | { |
ecbf4ad0 KB |
41 | register int l_ss = ss; |
42 | int l_which; /* Which is it? 'q' or 'Q'. */ | |
c6644c22 | 43 | |
e692f66f KB |
44 | sigspecial = 1; /* yes, 1, because we want to ensure it's on */ |
45 | sigspecial2 = 0; | |
46 | ||
ecbf4ad0 | 47 | l_which = ss; |
672cc1c0 KB |
48 | if (ss != -1) { |
49 | for (;;) { | |
50 | l_ss = getc(inputt); | |
51 | if ((l_ss != ' ') && (l_ss != '\n') && (l_ss != EOF)) { | |
52 | *errnum = -1; | |
53 | strcpy(help_msg, "illegal command option"); | |
54 | return; | |
55 | } | |
56 | if ((l_ss == '\n') || (l_ss == EOF)) | |
57 | break; | |
ecbf4ad0 | 58 | } |
c6644c22 | 59 | |
672cc1c0 KB |
60 | ungetc(l_ss, inputt); |
61 | } | |
ecbf4ad0 | 62 | /* Note: 'Q' will bypass this if stmt., which warns of no save. */ |
672cc1c0 | 63 | if ((change_flag == 1L) && ((l_which == 'q') || (l_which == -1)) ) { |
ecbf4ad0 KB |
64 | change_flag = 0L; |
65 | strcpy(help_msg, "buffer changes not saved"); | |
66 | *errnum = -1; | |
67 | ss = l_ss; | |
672cc1c0 KB |
68 | if (l_which == EOF) |
69 | ungetc('\n', inputt); | |
ecbf4ad0 KB |
70 | return; |
71 | } | |
72 | /* Do cleanup; should it be even bothered?? */ | |
035e94f8 | 73 | Start = top; |
ecbf4ad0 | 74 | End = bottom; |
035e94f8 | 75 | Start_default = End_default = 0; |
c6644c22 | 76 | |
ecbf4ad0 | 77 | /* We don't care about the returned errnum val anymore. */ |
672cc1c0 KB |
78 | if (l_which == EOF) |
79 | ungetc('\n', inputt); | |
ecbf4ad0 KB |
80 | d(inputt, errnum); |
81 | u_clr_stk(); | |
82 | free(text); | |
83 | free(filename_current); | |
e692f66f KB |
84 | #ifdef STDIO |
85 | fclose(fhtmp); | |
86 | #endif | |
87 | #ifdef DBI | |
ecbf4ad0 | 88 | (dbhtmp->close) (dbhtmp); /* Overhead as the cache is flushed. */ |
e692f66f KB |
89 | #endif |
90 | #ifndef MEMORY | |
ecbf4ad0 | 91 | unlink(template); |
e692f66f | 92 | #endif |
ecbf4ad0 KB |
93 | exit(0); |
94 | } |