📄 mfbio.c
字号:
/**********Copyright 1990 Regents of the University of California. All rights reserved.Author: -C- 1982 Giles C. Billingsley**********//* * mfbio.c * * sccsid "@(#)mfbio.c 1.9 9/3/83" * * MFB is a graphics package that was developed by the integrated * circuits group of the Electronics Research Laboratory and the * Department of Electrical Engineering and Computer Sciences at * the University of California, Berkeley, California. The programs * in MFB are available free of charge to any interested party. * The sale, resale, or use of these program for profit without the * express written consent of the Department of Electrical Engineering * and Computer Sciences, University of California, Berkeley, California, * is forbidden. */#include "spice.h"#include "mfb.h"#include <stdio.h>#include <ctype.h>#include "suffix.h"#ifdef HAS_BSDTTY#include <sys/file.h>#define iflush(FD) (ioctl(FD, TIOCFLUSH, FREAD))#define ioset(FD, TTYB_P) (ioctl(FD, TIOCSETN, (char *) TTYB_P))#define iosetl(FD, BITS) (ioctl(FD, TIOCLSET, (char *) BITS))#define ioget(FD, TTYB_P) (ioctl(FD, TIOCGETP, (char *) TTYB_P))#define iogetl(FD, BITS) (ioctl(FD, TIOCLGET, (char *) BITS))#define iolitout(FD, CODE) (ioctl(FD,TIOCLBIS,(char *) LLITOUT))#define iosetraw(TTYB) (TTYB.sg_flags |= RAW, 0)#define iosetmfb_flags(TTYB) ((TTYB.sg_flags &= (ALLDELAY & ~XTABS)), \ (TTYB.sg_flags |= ODDP | EVENP | CBREAK))#else#ifdef HAS_SYSVTTY#define iflush(FD) (ioctl(FD, TCFLSH, 0))#define ioset(FD, TTYB_P) (ioctl(FD, TCSETA, (char *) TTYB_P))#define iosetl(FD, BITS) (0)#define ioget(FD, TTYB_P) (ioctl(FD, TCGETA, (char *) TTYB_P))#define iogetl(FD, BITS) (0)#define iolitout(FD, TTYB) (TTYB.c_oflag &= ~OPOST, 0)#define iosetraw(TTYB) ((TTYB.c_lflag &= ~(ICANON | ECHO)), \ (TTYB.c_cc[VMIN] = 1), \ (TTYB.c_cc[VTIME] = 0, 0))#define iosetmfb_flags(TTYB) (0)#else#define iflush(FD) (0)#define ioset(FD, TTYB_P) (0)#define iosetl(FD, BITS) (0)#define ioget(FD, TTYB_P) (0)#define iogetl(FD, BITS) (0)#define iolitout(FD, CODE) (0)#define iosetraw(TTYB) (0)#define iosetmfb_flags(TTYB) (0)#endif#endif/* Library routines */char *strcpy();extern void free();static int MFBsaveflg = 0; /* used for kludgy ungetc */static int Oldsaveflg = 0; /* ungetc for displays without keyboards */#define MFBFORMAT MFBCurrent->stringsstruct err errors[] = { MFBBADENT, "Unknown terminal type", MFBMCELNG, "MFBCAP entry too long", MFBBADMCF, "Can't open or close mfbcap file", MFBBADMCE, "Bad mfbcap entry", MFBINFMCE, "Infinite mfbcap entry", MFBBADTTY, "stdout not in /dev", MFBBADLST, "Illegal line style", MFBBADFST, "Illegal fill style", MFBBADCST, "Illegal color style", MFBBADTM1, "No destructive text", MFBBADTM2, "No overstriking text", MFBNODFLP, "No defineable line styles", MFBNODFFP, "No defineable fill styles", MFBNODFCO, "No defineable colors", MFBNOBLNK, "No blinkers", MFBTMBLNK, "Too many blinkers", MFBNOMASK, "No defineable read or write masks", MFBBADDEV, "Can't open or close output device", MFBBADOPT, "Can't access or set device status", MFBBADWRT, "Error in write", MFBPNTERR, "Error in pointing device", MFBNOPTFT, "No format specified for pointing device", MFBNOPNT, "No pointing device", MFBNORBND, "No Rubberbanding of pointing device", MFBBADALU, "Cannot set ALU mode", 0 };#define NUMERRORS (sizeof(errors)/sizeof(struct err))/***************************************************************************** * * BASIC I/O ROUTINES * *****************************************************************************/MFBPutchar(c) char c; /* * Notes: * Place a character in the output buffer and check for overflow. */ { MFBCurrent->ttyBuffer[MFBCurrent->numTtyBuffer++] = c; if(MFBCurrent->numTtyBuffer >= TTYBUFSIZE) MFBUpdate(); return( (int) c ); }MFBPutstr(c,n) char *c; int n; /* * Notes: * Place a string of n characters in the output buffer and check * for overflow. */ { int i; i = n; /* Putchar tests for overflow after insertion, Putstr tests before */ if((MFBCurrent->numTtyBuffer + n + 1) >= TTYBUFSIZE){ MFBUpdate(); MFBCurrent->numTtyBuffer = 0; } while(i--) MFBCurrent->ttyBuffer[MFBCurrent->numTtyBuffer++] = *c++; return( n ); }intMFBGetchar() { static char c; char ibuffer[2]; if( MFBsaveflg != 0 ) MFBsaveflg = 0; else{#ifdef vms c = dev_getc(MFBCurrent->fileDesc);#else if(MFBCurrent->fileDesc == 1) c = getchar(); else{ if((c = (char)read(MFBCurrent->fileDesc,ibuffer,1)) > 0) c = ibuffer[0]; }#endif } return( c ); }intMFBUngetchar() { MFBsaveflg++; }intOldGetchar() { /* * Notes: * If the graphics display does not have a keyboard, mfb * will use the standard getchar routine to acquire input * from the user's terminal. */ static char c; if( Oldsaveflg != 0 ) Oldsaveflg = 0; else{#ifdef vms c = dev_getchar();#else c = getchar();#endif } return( c ); }intOldUngetchar() { Oldsaveflg++; }intMFBUpdate() { /* * Notes: * Flush the output buffer to the graphics display. */ int value;#ifdef vms if((value = MFBCurrent->numTtyBuffer) > 0) dev_write(MFBCurrent->fileDesc, MFBCurrent->ttyBuffer,MFBCurrent->numTtyBuffer);#else value = write(MFBCurrent->fileDesc,MFBCurrent->ttyBuffer,MFBCurrent->numTtyBuffer);#endif MFBCurrent->numTtyBuffer = 0; return(value); }intMFBFlushInput(){#ifdef HAS_TTY_ /* * In the UNIX file system, all pending input is flushed whenever * ioctl is called with the TIOCSETP option. */ /* the isatty() is necessary because user may be piping output */ if(isatty(MFBCurrent->fileDesc)){ if (iflush(MFBCurrent->fileDesc) < 0) return(MFBBADOPT); } if(MFBCurrent->fileDesc != 1 && isatty(1)){ if(iflush(1) < 0) return(MFBBADOPT); }#endif return(MFBOK); }voidMFBAudio(){ /* * Notes: * Rings the Bell. */ if(MFBFORMAT.audio == NULL || *MFBFORMAT.audio == 0) { /* cntrl-g by default */ if(MFBCurrent->fileDesc == 1) MFBPutchar( '\07' ); else (void) putchar( '\07' ); } else{ MFBGenCode(MFBFORMAT.audio); } }/***************************************************************************** * * INITIALIZATION * *****************************************************************************/MFB*MFBOpen(TerminalName,DeviceName,errorcode) char *TerminalName; char *DeviceName; int *errorcode; /* * Notes: * Called to initialize a graphics terminal. The character * function MFBError(errnum) returns a pointer to a string * describing the error. * * TerminalName is the name used in the MFBCAP file. * * DeviceName is a pointer to a string which specifies the name * of the output device. If DeviceName is a null string,the * current device is assumed (i.e. filedesc = 1, for UNIX). * To avoid output to a tty through stdio, use DeviceName == * ttyname(fileno(stdout)) * * errorcode returns an integer specifying the type of error,if * any,which occurs during mfb initialization. * */ { char *MFBGetStr(); char *getenv();#ifndef vms char *ttyname();#endif char *mfbcapFile; char *bufPtr; char buf[256], *s, *r; char *tilde_expand(), *copy(); MFB *mfb; int i; FILE *fp; if((mfbcapFile = getenv("MFBCAP")) == NULL) { /* Here we try to find the mfbcap file in the spice3 library directory. * This is spice-dependent. */ for (s = tilde_expand(Lib_Path); s && *s; ) { while (isspace(*s)) s++; for (r = buf; *s && !isspace(*s); r++, s++) *r = *s;#ifndef vms (void) strcpy(r, "mfbcap");#else (void) strcpy(r, "MFBCAP.");#endif if (fp = fopen(buf, "r")) { (void)fclose(fp); mfbcapFile = copy(buf); break; } } if (!mfbcapFile) mfbcapFile = Default_MFB_Cap; } if (!(mfb = (MFB *)malloc(sizeof(MFB)))) return (NULL); mfb->terminalName = TerminalName; SetCurrentMFB(mfb); if((*errorcode = MFBGetEnt(gEntBuf,TerminalName,mfbcapFile)) <= 0) { /* Don't free the MFB because User may use it for Terminal Name. */ return(NULL); } bufPtr = mfb->strBuf; if(MFBGetFlag("TTY")) { mfb->deviceType = TTY; if(DeviceName == NULL || *DeviceName == 0) {#ifdef vms dev_open(DeviceName,&mfb->fileDesc); mfb->name = getenv("TERM");#else mfb->fileDesc = 1; mfb->name = ttyname(2); /* stdout */#endif } else{#ifdef vms dev_open(DeviceName,&mfb->fileDesc);#else /* try to create the file if does not exist */ if(close(creat(DeviceName,0644)) < 0){ *errorcode = MFBBADDEV; return(NULL); } if((mfb->fileDesc = open(DeviceName,2)) < 0){ *errorcode = MFBBADDEV; return(NULL); }#endif mfb->name = DeviceName; }#ifdef DEBUG MFBZeroCounters();#endif /* * Fill up mfb structure from mfbcap entry */ mfb->litout = (Bool)MFBGetFlag("8BB"); mfb->raw = (Bool)MFBGetFlag("RAW"); mfb->strings.startSequence = MFBGetStr("GIS",&bufPtr); mfb->strings.endSequence = MFBGetStr("GFS",&bufPtr); mfb->maxX = MFBGetNum("MXC"); mfb->maxY = MFBGetNum("MYC"); mfb->strings.initLineStyles = MFBGetStr("ILS",&bufPtr); mfb->strings.initColorStyles = MFBGetStr("ICS",&bufPtr); mfb->strings.initFillPatterns = MFBGetStr("IFP",&bufPtr); /* * graphics text info */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -