157696Sbostic /*-
2*60663Sbostic * Copyright (c) 1992, 1993
3*60663Sbostic * The Regents of the University of California. All rights reserved.
457696Sbostic *
557696Sbostic * This code is derived from software contributed to Berkeley by
657696Sbostic * Rodney Ruddock of the University of Guelph.
757696Sbostic *
857696Sbostic * %sccs.include.redist.c%
957696Sbostic */
1057696Sbostic
1157696Sbostic #ifndef lint
12*60663Sbostic static char sccsid[] = "@(#)q.c 8.1 (Berkeley) 05/31/93";
1357696Sbostic #endif /* not lint */
1457696Sbostic
1557710Sbostic #include <sys/types.h>
1657710Sbostic
1757710Sbostic #include <regex.h>
1857710Sbostic #include <setjmp.h>
1957710Sbostic #include <stdio.h>
2057710Sbostic #include <stdlib.h>
2157710Sbostic #include <string.h>
2257710Sbostic #include <unistd.h>
2357710Sbostic
2458315Sbostic #ifdef DBI
2558315Sbostic #include <db.h>
2658315Sbostic #endif
2758315Sbostic
2857696Sbostic #include "ed.h"
2957710Sbostic #include "extern.h"
3057696Sbostic
3157696Sbostic /*
3257696Sbostic * End this editting session and exit with saving the buffer. If no
3357696Sbostic * write has occurred since the last buffer modification a warning
3457696Sbostic * is given once ('Q' over-rides the warning).
3557696Sbostic */
3657696Sbostic void
q(inputt,errnum)3757696Sbostic q(inputt, errnum)
3857710Sbostic FILE *inputt;
3957710Sbostic int *errnum;
4057696Sbostic {
4157710Sbostic register int l_ss = ss;
4257710Sbostic int l_which; /* Which is it? 'q' or 'Q'. */
4357696Sbostic
4458315Sbostic sigspecial = 1; /* yes, 1, because we want to ensure it's on */
4558315Sbostic sigspecial2 = 0;
4658315Sbostic
4757710Sbostic l_which = ss;
4858710Sbostic if (ss != -1) {
4958710Sbostic for (;;) {
5058710Sbostic l_ss = getc(inputt);
5158710Sbostic if ((l_ss != ' ') && (l_ss != '\n') && (l_ss != EOF)) {
5258710Sbostic *errnum = -1;
5358710Sbostic strcpy(help_msg, "illegal command option");
5458710Sbostic return;
5558710Sbostic }
5658710Sbostic if ((l_ss == '\n') || (l_ss == EOF))
5758710Sbostic break;
5857710Sbostic }
5958710Sbostic
6058710Sbostic ungetc(l_ss, inputt);
6157710Sbostic }
6257710Sbostic /* Note: 'Q' will bypass this if stmt., which warns of no save. */
6358710Sbostic if ((change_flag == 1L) && ((l_which == 'q') || (l_which == -1)) ) {
6457710Sbostic change_flag = 0L;
6557710Sbostic strcpy(help_msg, "buffer changes not saved");
6657710Sbostic *errnum = -1;
6757710Sbostic ss = l_ss;
6858710Sbostic if (l_which == EOF)
6958710Sbostic ungetc('\n', inputt);
7057710Sbostic return;
7157710Sbostic }
7257710Sbostic /* Do cleanup; should it be even bothered?? */
7358564Sralph Start = top;
7457710Sbostic End = bottom;
7558564Sralph Start_default = End_default = 0;
7657696Sbostic
7757710Sbostic /* We don't care about the returned errnum val anymore. */
7858710Sbostic if (l_which == EOF)
7958710Sbostic ungetc('\n', inputt);
8057710Sbostic d(inputt, errnum);
8157710Sbostic u_clr_stk();
8257710Sbostic free(text);
8357710Sbostic free(filename_current);
8458315Sbostic #ifdef STDIO
8558315Sbostic fclose(fhtmp);
8658315Sbostic #endif
8758315Sbostic #ifdef DBI
8857710Sbostic (dbhtmp->close) (dbhtmp); /* Overhead as the cache is flushed. */
8958315Sbostic #endif
9058315Sbostic #ifndef MEMORY
9157710Sbostic unlink(template);
9258315Sbostic #endif
9359475Sbostic exit(exit_code);
9457710Sbostic }
95