|
|
1.1 ! root 1: /*----------------------------------------------------------------------------- ! 2: Talking BIOS device driver for the AT&T PC6300. ! 3: Copyright (C) Karl Dahlke 1987 ! 4: This software may be freely used and distributed ! 5: for any non-profit purpose. ! 6: *----------------------------------------------------------------------------- ! 7: */ ! 8: ! 9: /* savebuf.c: save the accumulated text in a session file */ ! 10: ! 11: #include <stdio.h> ! 12: #ifdef MSDOS ! 13: #include <dos.h> ! 14: #else ! 15: #include <sgtty.h> ! 16: #endif ! 17: ! 18: #ifdef MSDOS ! 19: struct ! 20: { ! 21: char far *bufbot; ! 22: char far *buftop; ! 23: char far *buftail; ! 24: char far *bufhead; ! 25: } devparams; ! 26: ! 27: struct WORDREGS regs; ! 28: ! 29: setenv(){} /* no environment */ ! 30: #endif ! 31: ! 32: char *filename = "session.log"; ! 33: ! 34: ! 35: main(argc, argv) ! 36: int argc; ! 37: char **argv; ! 38: { ! 39: FILE *f; ! 40: register char c; ! 41: #ifdef MSDOS ! 42: int fh; ! 43: char far *cp; ! 44: short i, j; ! 45: #else ! 46: int bsize; ! 47: char *buf, *malloc(); ! 48: #endif ! 49: ! 50: if(argc > 1) filename = argv[1]; ! 51: if(argc > 2) { ! 52: fprintf(stderr, "usage: savebuf [file]\n"); ! 53: exit(1); ! 54: } ! 55: ! 56: f = fopen(filename, "w"); ! 57: if(!f) { ! 58: fprintf(stderr, "savebuf: cannot create file %s\n", filename); ! 59: exit(1); ! 60: } ! 61: ! 62: #ifdef MSDOS ! 63: /* get device driver parameters from ioctl call */ ! 64: fh = open("SPEAK$", 0); ! 65: regs.bx = fh; ! 66: regs.ax = 0x4402; /* read ioctl string */ ! 67: regs.cx = 16; /* get 16 bytes */ ! 68: regs.dx = (unsigned) &devparams; ! 69: intdos(®s, ®s); ! 70: if(regs.cflag & 1 || regs.ax != 16) { ! 71: fprintf(stderr, "savebuf: bad ioctl() call on device driver SPEAK$\n"); ! 72: exit(1); ! 73: } ! 74: ! 75: close(fh); ! 76: ! 77: if(devparams.bufbot) { ! 78: if(!devparams.buftop) { /* indicates screen mode */ ! 79: cp = devparams.bufbot; ! 80: for(i=0; i<25; ++i) { ! 81: for(j=0; j<80; ++j) { ! 82: putc(*cp, f); ! 83: cp += 2; ! 84: } ! 85: putc('\n', f); ! 86: } ! 87: } else { ! 88: cp = devparams.buftail; ! 89: while(cp != devparams.bufhead) { ! 90: c = *cp; ! 91: if(c == '\r') c = '\n'; ! 92: putc(c,f); ! 93: if(++cp == devparams.buftop) cp = devparams.bufbot; ! 94: } /* end loop writing file */ ! 95: } /* screen/line */ ! 96: } /* nonzero pointers */ ! 97: ! 98: #else ! 99: ! 100: /* I assume stdin is opened to the speech device driver */ ! 101: if(ioctl(0, TIOCSDSIZE, &bsize) < 0) { ! 102: fprintf(stderr, "ioctl failed, cannot get size of text buffer from speech device driver\n"); ! 103: exit(1); ! 104: } ! 105: ! 106: if(!(buf = malloc(bsize))) { ! 107: fprintf(stderr, "cannot malloc %d bytes for text buffer\n", bsize); ! 108: exit(1); ! 109: } ! 110: ! 111: /* now copy the text */ ! 112: if(ioctl(0, TIOCSDGETBUF, buf) < 0) { ! 113: fprintf(stderr, "ioctl failed, cannot copy text buffer from speech device driver\n"); ! 114: exit(1); ! 115: } ! 116: ! 117: /* now write the file */ ! 118: while((c = *buf++) > 0) { ! 119: if(c == '\r') c = '\n'; ! 120: putc(c,f); ! 121: } /* end writing text buffer to file */ ! 122: #endif ! 123: ! 124: fclose(f); ! 125: exit(0); ! 126: } /* main */ ! 127:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.