📄 jove.c
字号:
# endif /* _POSIX_VDISABLE */ sg[ON].c_cc[VMIN] = 1; sg[ON].c_cc[VTIME] = 1;# endif /* TERMIO || TERMIOS */# if defined(SGTTY) || defined(BRLUNIX) TABS = !(sg[OFF].sg_flags & XTABS); sg[ON].sg_flags &= ~XTABS; ospeed = sg[OFF].sg_ospeed;# ifdef BRLUNIX sg[ON].sg_flags &= ~(ECHO | CRMOD); sg[ON].sg_flags |= CBREAK; /* VT100 Kludge: leave STALL on for flow control if DC3DC1 (Yuck.) */ sg[ON].sg_xflags &= ~((sg[ON].sg_xflags&DC3DC1 ? 0 : STALL) | PAGE);# else sg[ON].sg_flags &= ~(ECHO | CRMOD);# endif /* BRLUNIX */# ifdef LPASS8 sg[ON].sg_flags |= CBREAK;# else sg[ON].sg_flags |= (MetaKey ? RAW : CBREAK);# endif# endif /* SGTTY */#endif /* UNIX */#ifdef MSDOS# ifndef IBMPC setmode(1, 0x8000);# endif /* IBMPC */ TABS = NO;#endif /* MSDOS */}voidtty_reset(){ if (!done_ttinit) return; ttyset(OFF); /* go back to original modes */ ttinit(); ttyset(ON);}/* If n is OFF reset to original modes */voidttyset(n)bool n;{ if (!done_ttinit && !n) /* Try to reset before we've set! */ return;#ifdef UNIX# ifdef TERMIO (void) ioctl(0, TCSETAW, (UnivPtr) &sg[n]);# endif /* TERMIO */# ifdef TERMIOS (void) tcsetattr(0, TCSADRAIN, &sg[n]);# endif /* TERMIOS */# ifdef SGTTY# ifdef TIOCSETN (void) ioctl(0, TIOCSETN, (UnivPtr) &sg[n]);# else (void) stty(0, &sg[n]);# endif# endif# ifdef TIOCGETC (void) ioctl(0, TIOCSETC, (UnivPtr) &tc[n]);# endif /* TIOCSETC */# ifdef TIOCSLTC (void) ioctl(0, TIOCSLTC, (UnivPtr) &ls[n]);# endif /* TIOCSLTC */# ifdef LPASS8 (void) ioctl(0, TIOCLSET, (UnivPtr) &lmword[n]);# endif#endif /* UNIX */#ifdef MSDOS# ifndef IBMPC setmode(1, n? 0x8000 : 0x4000);# endif#endif /* MSDOS */ done_ttinit = YES;#ifdef BIFF biff(!n);#endif}int this_cmd, last_cmd, LastKeyStruck, MetaKey = OFF;intgetch(){ register int c, peekc; if (Inputp) { if ((c = *Inputp++) != '\0') return LastKeyStruck = c; Inputp = NULL; } if (InJoverc) return EOF; /* somethings wrong if Inputp runs out while we're reading a .joverc file. */#ifndef MSDOS if (ModCount >= SyncFreq) { ModCount = 0; SyncRec(); }#endif /* MSDOS */ /* If there are no ungetc'd characters, AND we're interactive or we're not executing a macro, we read from the terminal (i.e., jgetchar()). Note: characters only get put in macros from inside this if. */ if (((peekc = c = Peekc()) == EOF) && (Interactive || ((c = mac_getc()) == EOF))) { /* So messages that aren't error messages don't * hang around forever. * Note: this code is duplicated in SitFor()! */ if (!UpdMesg && !Asking && mesgbuf[0] != '\0' && !errormsg) message(NullStr); redisplay();#ifdef UNIX inIOread = YES;#endif if ((c = jgetchar()) == EOF) finish(SIGHUP);#ifdef UNIX inIOread = NO;#endif if (!Interactive && InMacDefine) mac_putc(c); } if (peekc == EOF) /* don't add_stroke peekc's */ add_stroke(c); return LastKeyStruck = c;}#ifdef UNIXprivate voiddorecover(){ /* Since recover is a normal cooked mode program, reset the terminal */ UnsetTerm(NullStr);#ifdef PIPEPROCS kbd_kill(); /* kill the keyboard process */#endif execl(Recover, "recover", "-d", TmpFilePath, (char *) NULL); writef("%s: execl failed! %s\n", Recover, strerror(errno)); flushscreen(); _exit(-1); /* NOTREACHED */}#endif /* UNIX */voidShowVersion(){ s_mess("Jonathan's Own Version of Emacs (%s)", version);}private voidUNIX_cmdline(argc, argv)int argc;char *argv[];{ int lineno = 0, nwinds = 1; Buffer *b; ShowVersion(); while (argc > 1) { if (argv[1][0] != '-' && argv[1][0] != '+') { bool force = (nwinds > 0 || lineno != 0);#ifdef MSDOS strlwr(argv[1]);#endif minib_add(argv[1], force); b = do_find(nwinds > 0 ? curwind : (Window *) NULL, argv[1], force); if (force) { SetABuf(curbuf); SetBuf(b); if (lineno >= 0) SetLine(next_line(curbuf->b_first, lineno)); else SetLine(curbuf->b_last); if (nwinds > 1) NextWindow(); if (nwinds) nwinds -= 1; } lineno = 0; } else switch (argv[1][1]) { case 'd': argv += 1; argc -= 1; break; case 'j': /* Ignore .joverc in HOME */ break;#ifndef MAC case 'p': argv += 1; argc -= 1; if (argv[1] != NULL) { SetBuf(do_find(curwind, argv[1], NO)); ErrParse(); nwinds = 0; } break;#endif case 't': /* check if syntax is -tTag or -t Tag */ if (argv[1][2] != '\0') { find_tag(&(argv[1][2]), YES); } else { argv += 1; argc -= 1; if (argv[1] != NULL) find_tag(argv[1], YES); } break; case 'w': if (argv[1][2] == '\0') nwinds += 1; else { int n; (void) chr_to_int(&argv[1][2], 10, NO, &n); nwinds += -1 + n; } (void) div_wind(curwind, nwinds - 1); break; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': (void) chr_to_int(&argv[1][1], 10, NO, &lineno); lineno -= 1; break; case '\0': lineno = -1; /* goto end of file ... */ break; /* just like some people's */ } /* favourite editor */ argv += 1; argc -= 1; }}voidraw_scream(m)const char *m;{ write(2, (UnivConstPtr)m, strlen(m));}#ifdef STDARGSvoiderror(const char *fmt, ...)#else/*VARARGS1*/ voiderror(fmt, va_alist) const char *fmt; va_dcl#endif{ va_list ap; if (fmt) { va_init(ap, fmt); format(mesgbuf, sizeof mesgbuf, fmt, ap); va_end(ap); UpdMesg = YES; } rbell(); longjmp(mainjmp, ERROR);}#ifdef STDARGSvoidcomplain(const char *fmt, ...)#else/*VARARGS1*/ voidcomplain(fmt, va_alist) const char *fmt; va_dcl#endif{ va_list ap; if (fmt) { va_init(ap, fmt); format(mesgbuf, sizeof mesgbuf, fmt, ap); va_end(ap); UpdMesg = YES; } rbell(); longjmp(mainjmp, COMPLAIN);}#ifdef STDARGSvoidraw_complain(const char *fmt, ...)#else/*VARARGS1*/ voidraw_complain(fmt, va_alist) const char *fmt; va_dcl#endif{ va_list ap; if (fmt) { va_init(ap, fmt); format(mesgbuf, sizeof mesgbuf, fmt, ap); va_end(ap); raw_scream(mesgbuf); }}#ifdef STDARGSvoidconfirm(const char *fmt, ...)#else/*VARARGS1*/ voidconfirm(fmt, va_alist) const char *fmt; va_dcl#endif{ char *yorn; va_list ap; va_init(ap, fmt); format(mesgbuf, sizeof mesgbuf, fmt, ap); va_end(ap); yorn = ask((char *)NULL, mesgbuf); if (*yorn != 'Y' && *yorn != 'y') longjmp(mainjmp, COMPLAIN);}int RecDepth = 0;voidRecur(){ char bname[128]; Mark *m; swritef(bname, sizeof(bname), "%s", curbuf->b_name); m = MakeMark(curline, curchar, M_FLOATER); RecDepth += 1; UpdModLine = YES; DoKeys(NO); /* NO means not first time */ UpdModLine = YES; RecDepth -= 1; SetBuf(do_select(curwind, bname)); if (!is_an_arg()) ToMark(m); DelMark(m);}#ifdef MACjmp_buf auxjmp;#endifprivate int iniargc; /* main sets these for DoKeys() */private char **iniargv;private voidDoKeys(firsttime)bool firsttime;{ int c; jmp_buf savejmp; push_env(savejmp); switch (setjmp(mainjmp)) { case 0: if (firsttime) UNIX_cmdline(iniargc, iniargv); break; case QUIT: if (RecDepth == 0) { if (ModMacs()) { rbell(); if (CharUpcase(*ask("No","Some MACROS haven't been saved; leave anyway? ")) != 'Y') break; } if (ModBufs(NO)) { rbell(); if (CharUpcase(*ask("No","Some buffers haven't been saved; leave anyway? ")) != 'Y') break; }#ifdef IPROCS KillProcs();#endif } pop_env(savejmp); return; case ERROR: getDOT(); /* God knows what state linebuf was in */ /*FALLTHROUGH*/ case COMPLAIN: { gc_openfiles(); /* close any files we left open */ errormsg = YES; unwind_macro_stack(); Asking = NO; curwind->w_bufp = curbuf; DisabledRedisplay = NO; redisplay(); break; } } this_cmd = last_cmd = 0; for (;;) {#ifdef MAC setjmp(auxjmp);#endif if (this_cmd != ARG_CMD) { clr_arg_value(); last_cmd = this_cmd; init_strokes(); }#ifdef MAC HiliteMenu(0); EventCmd = NO; menus_on();#endif c = getch(); if (c == EOF) continue; dispatch(c); }}private char **scanvec(args, str)register char **args, *str;{ while (*args) { if (strcmp(*args, str) == 0) return args; args += 1; } return NULL;}#ifdef UNIXint UpdFreq = 30, inIOread = NO;private SIGRESULTupdmode(junk)int junk; /* passed in on signal; of no interest */{ int save_errno = errno; /* Subtle, but necessary! */ UpdModLine = YES; if (inIOread) redisplay();#ifndef BSD_SIGS (void) signal(SIGALRM, updmode);#endif if (UpdFreq != 0) (void) alarm((unsigned) (UpdFreq - (time((time_t *)NULL) % UpdFreq))); errno = save_errno; SIGRETURN;}#endif /* UNIX */#ifdef MSDOS# ifndef IBMPCchar ttbuf[JBUFSIZ];# endif /* IBMPC */#endif /* MSDOS */#ifdef WINRESIZE#ifndef MACprivate#endifSIGRESULTwin_reshape(junk)int junk; /* passed in when invoked by a signal; of no interest */{ int save_errno = errno; /* Subtle, but necessary! */ register int oldLI; register int newsize, total; register Window *wp;#ifdef UNIX (void) SigHold(SIGWINCH);#endif /* * Save old number of lines. */ oldLI = LI; /* * Get new line/col info. */ ttsize(); /* * LI has changed, and now holds the * new value. */ /* * Go through the window list, changing each window size in * proportion to the resize. If a window becomes too small, * delete it. We keep track of all the excess lines (caused by * roundoff!), and give them to the current window, as a sop - * can't be more than one or two lines anyway. This seems fairer * than just resizing the current window. */ wp = fwind; total = 0; do { newsize = LI * wp->w_height / oldLI; if (newsize < 2) { total += wp->w_height; wp = wp->w_next; del_wind(wp->w_prev); } else { wp->w_height = newsize; total += newsize; wp = wp->w_next; } } while (wp != fwind); curwind->w_height += LI - total - 1; /* Make a new screen structure */ make_scr(); /* Do a 'hard' update on the screen - clear and redraw */ cl_scr(YES); flushscreen(); redisplay();#ifdef UNIX (void) SigRelse(SIGWINCH); (void) signal(SIGWINCH, win_reshape);#endif errno = save_errno; SIGRETURN;}#endifvoid#ifdef MAC /* will get args from user, if option key held during launch */main(){ int argc; char **argv;#elsemain(argc, argv)int argc;char *argv[];{#endif /* MAC */ char *cp; char ttbuf[MAXTTYBUF];#ifdef pdp11 /* On the PDP-11, UNIX allocates at least 8K. * In order not to waste this space, we allocate * a bunch of buffers as autos. */ char s_iobuff[LBSIZE], s_genbuf[LBSIZE], s_linebuf[LBSIZE]; iobuff = s_iobuff; genbuf = s_genbuf; linebuf = s_linebuf;#endif#ifdef MAC MacInit(); /* initializes all */ { extern bool make_cache proto((void)); if (!make_cache()) exit(-1); } argc = getArgs(&argv);#endif /* MAC */ iniargc = argc; iniargv = argv; if (setjmp(mainjmp)) { writef("\rAck! I can't deal with error \"%s\" now.\n\r", mesgbuf); finish(SIGIOT); /* some bad signal (not SIGHUP) */ }#ifdef MSDOS /* import the temporary file path from the environment and fix the string, so that we can append a slash safely */ if (((cp = getenv("TMP")) || (cp = getenv("TMPDIR"))) && (*cp != '\0')) { strcpy(TmpFilePath, cp); cp = &TmpFilePath[strlen(TmpFilePath)-1]; if ((*cp == '/') || (*cp == '\\')) *cp = '\0'; } ShFlags[0] = switchar();#endif /* MSDOS */ getTERM(); /* Get terminal. */ if (getenv("METAKEY")) MetaKey = ON; ttsize();#ifdef MAC InitEvents();#else InitCM();#endif d_cache_init(); /* initialize the disk buffer cache */#ifdef MSDOS if ((cp = getenv("COMSPEC")) && (*cp != '\0')) { strcpy(Shell, cp); } if ((cp = getenv("DESCRIBE")) && (*cp != '\0')) strcpy(CmdDb, cp);#else /* !MSDOS */#ifndef MAC if ((cp = getenv("SHELL"))!=NULL && (*cp != '\0')) { strcpy(Shell, cp); }#endif#endif /* !MSDOS */ make_scr(); mac_init(); /* Initialize Macros */ winit(); /* Initialize Window */#ifdef IPROCS pinit(); /* Pipes/process initialization */#endif buf_init(); { char **argp; if ((argp = scanvec(argv, "-d"))!=NULL#ifdef UNIX && chkCWD(argp[1])#endif ) setCWD(argp[1]); else getCWD(); /* After we setup curbuf in case we have to getwd() */ } HomeDir = getenv("HOME"); if (HomeDir == NULL) HomeDir = "/"; HomeLen = strlen(HomeDir);#ifdef UNIX if ((cp = getenv("MAIL")) != NULL) { strcpy(Mailbox, cp); } else { swritef(Mailbox, sizeof(Mailbox), "%s/%s", MAILSPOOL, getenv("LOGNAME")); }#endif InitKeymaps(); ttinit(); /* initialize terminal (before ~/.joverc) */ settout(ttbuf); /* not until we know baudrate */#ifndef MAC ResetTerm();#endif (void) joverc(Joverc); /* system wide .joverc */ cp = NULL;#ifndef MAC /* If a JOVERC environment variable is set, then use that instead */ if ((cp = getenv("JOVERC"))!=NULL && (*cp != '\0')) (void) joverc(cp);#endif /* !MAC */ if (!scanvec(argv, "-j") && (!cp || *cp == '\0')) { char tmpbuf[100]; swritef(tmpbuf, sizeof(tmpbuf), "%s/.joverc", HomeDir); (void) joverc(tmpbuf); /* .joverc in home directory */ }#ifndef MSDOS if (scanvec(argv, "-r")) dorecover(); if (scanvec(argv, "-rc")) FullRecover();#endif /* MSDOS */#ifdef MSDOS (void) signal(SIGINT, SIG_IGN); break_off(); /* disable ctrl-c checking */#endif /* MSDOS */#ifdef UNIX (void) signal(SIGHUP, finish); (void) signal(SIGINT, finish); (void) signal(SIGBUS, finish); (void) signal(SIGSEGV, finish); (void) signal(SIGPIPE, finish); (void) signal(SIGTERM, SIG_IGN);# ifdef WINRESIZE (void) signal(SIGWINCH, win_reshape);# endif /* set things up to update the modeline every UpdFreq seconds */ (void) signal(SIGALRM, updmode); if (UpdFreq != 0) (void) alarm((unsigned) (UpdFreq - (time((time_t *)NULL) % UpdFreq)));#endif /* UNIX */ cl_scr(YES); flushscreen(); RedrawDisplay(); /* start the redisplay process. */ DoKeys(YES); finish(0);}#ifdef MSDOS#include <dos.h>private char break_state;/* set the break state to off */private voidbreak_off(){ union REGS regs; regs.h.ah = 0x33; /* break status */ regs.h.al = 0x00; /* request current state */ intdos(®s, ®s); break_state = regs.h.dl; bdos(0x33, 0, 1); /* turn off break */}/* reset the break state */private voidbreak_rst(){ bdos(0x33, break_state, 1);}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -