home *** CD-ROM | disk | FTP | other *** search
- /* respf.c
-
- QCAD Systems, Inc. 1990
-
- Provides single-character response to a query.
-
- This works well under Microsoft's C, Turbo C++, and only so-so
- under Unix. The Unix implementation requires typing the character
- then a RETURN.
-
- NOTE: the F1 key for printing a screen only functions under Microsoft C
- and Turbo.
-
- */
-
- #include <stdio.h>
- #include "respf.h"
-
- #define SCRSIZE 24*80*2
- #define MONOCHROME 7
- #define PFFILE "screen.txt"
- #define F1KEY 59
-
- #ifdef MSDOS
- /* Microsoft C 5.XX */
- #include <malloc.h>
- #include <memory.h>
- #include <dos.h>
-
- /* ............. */
- static void pf(filename)
- char *filename;
- { int far *membuf;
- int row, column;
- char line[82];
- FILE *outfile;
-
- if ((outfile= fopen(filename, "a"))==NULL) {
- fprintf(stderr, "E %s", filename);
- return;
- }
- fprintf(outfile, "=== NEW SCREEN ===\n");
- membuf= (int far *) _fmalloc(SCRSIZE);
- movedata(0x40, 0x49, FP_SEG(membuf), FP_OFF(membuf), 2);
- if ((*membuf & 0xFF)==MONOCHROME)
- movedata(0xB000, 0, FP_SEG(membuf), FP_OFF(membuf), SCRSIZE);
- else movedata(0xB800, 0, FP_SEG(membuf), FP_OFF(membuf), SCRSIZE);
- for (row= 0; row < 24*80; row += 80) {
- for (column= 0; column < 80; column++)
- line[column]= (char) (membuf[row + column] & 0x7F);
- while (column>0 && line[column-1]==' ') column--;
- line[column]= '\0';
- fprintf(outfile, "%s\n", line);
- }
- fclose(outfile);
- }
- #endif
-
- #ifdef TCC
- /* Turbo C++ */
- #include <conio.h>
- #include <alloc.h>
-
- /* ............. */
- static void pf(filename)
- char *filename;
- { int row, column, last_col;
- char line[2*82];
- FILE *outfile;
-
- if ((outfile= fopen(filename, "a"))==NULL) {
- fprintf(stderr, "E %s", filename);
- return;
- }
- fprintf(outfile, "=== NEW SCREEN ===\n");
- for (row= 1; row <= 24; row++) {
- gettext(1, row, 80, row, line);
- last_col= 2*80;
- while (last_col > 0 && (line[last_col-2] & 0x7F) ==' ')
- last_col -= 2;
- for (column= 0; column < last_col; column += 2)
- fputc((char)(line[column] & 0x7F), outfile);
- fputc('\n', outfile);
- }
- fclose(outfile);
- }
- #endif
-
- /* .................... */
- char resp(msg)
- char *msg;
- { char line[80];
- int more= 1;
-
- if (*msg) {
- printf("%s ", msg);
- fflush(stdout);
- }
- #ifdef UNIX
- read(0, line, 5);
- if (*line=='\0') *line= '\n';
- /* NOTE: no F1 key screen supported under Unix */
- #else /* Microsoft or Turbo on PC */
- while (more) {
- *line= getch();
- more= 0;
- if (*line=='\r') *line= '\n';
- else if (*line==('C' & 0x1F)) exit(0); /* control-C */
- else if (*line == '\0') {
- *line= getch();
- if (*line == F1KEY) pf(PFFILE);
- more= 1; /* keep going */
- }
- }
- printf("%c\n", *line);
- #endif
- return *line;
- }
-
- /* ................... */
- int yesresp(msg)
- char *msg;
- { char yresp= resp(msg);
-
- return (yresp=='y' || yresp=='Y');
- }
-
- #ifdef TEST
- void main()
- { char ch;
-
- while (1) {
- ch= resp("Type a character: ");
- if (ch=='0') break;
- }
- exit(0);
- }
- #endif