157696Sbostic /*- 257696Sbostic * Copyright (c) 1992 The Regents of the University of California. 357696Sbostic * 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*58710Sbostic static char sccsid[] = "@(#)q.c 5.5 (Berkeley) 03/18/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 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; 48*58710Sbostic if (ss != -1) { 49*58710Sbostic for (;;) { 50*58710Sbostic l_ss = getc(inputt); 51*58710Sbostic if ((l_ss != ' ') && (l_ss != '\n') && (l_ss != EOF)) { 52*58710Sbostic *errnum = -1; 53*58710Sbostic strcpy(help_msg, "illegal command option"); 54*58710Sbostic return; 55*58710Sbostic } 56*58710Sbostic if ((l_ss == '\n') || (l_ss == EOF)) 57*58710Sbostic break; 5857710Sbostic } 59*58710Sbostic 60*58710Sbostic ungetc(l_ss, inputt); 6157710Sbostic } 6257710Sbostic /* Note: 'Q' will bypass this if stmt., which warns of no save. */ 63*58710Sbostic 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; 68*58710Sbostic if (l_which == EOF) 69*58710Sbostic 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. */ 78*58710Sbostic if (l_which == EOF) 79*58710Sbostic 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 9357710Sbostic exit(0); 9457710Sbostic } 95