int main(int argc, char **argv) { char *cp, *init_fcn_name = NULL; PF init_fcn = NULL; int o, i, nfiles; int nobackups = 0; struct buffer *bp = NULL; #ifdef MRUBY mrb_mg_init(); int noinitfile = 0; #endif /* MRUBY */ while ((o = getopt(argc, argv, "nf:q")) != -1) switch (o) { case 'n': nobackups = 1; break; case 'f': if (init_fcn_name != NULL) errx(1, "cannot specify more than one " "initial function"); init_fcn_name = optarg; break; case 'q': noinitfile = 1; break; default: usage(); } argc -= optind; argv += optind; maps_init(); /* Keymaps and modes. */ funmap_init(); /* Functions. */ /* * This is where we initialize standalone extensions that should * be loaded dynamically sometime in the future. */ { extern void grep_init(void); extern void theo_init(void); extern void cmode_init(void); extern void dired_init(void); dired_init(); grep_init(); theo_init(); cmode_init(); #ifdef UTF8 utf8_init(); #endif /* UTF8 */ } if (init_fcn_name && (init_fcn = name_function(init_fcn_name)) == NULL) errx(1, "Unknown function `%s'", init_fcn_name); vtinit(); /* Virtual terminal. */ dirinit(); /* Get current directory. */ edinit(bp); /* Buffers, windows. */ ttykeymapinit(); /* Symbols, bindings. */ /* * doing update() before reading files causes the error messages from * the file I/O show up on the screen. (and also an extra display of * the mode line if there are files specified on the command line.) */ update(); /* user startup file */ #ifdef MRUBY if (noinitfile == 0 && (cp = startupfile(NULL)) != NULL) mrb_mg_load(cp); #else if ((cp = startupfile(NULL)) != NULL) (void)load(cp); #endif /* MRUBY */ /* * Now ensure any default buffer modes from the startup file are * given to any files opened when parsing the startup file. * Note *scratch* will also be updated. */ for (bp = bheadp; bp != NULL; bp = bp->b_bufp) { bp->b_flag = defb_flag; for (i = 0; i <= defb_nmodes; i++) { bp->b_modes[i] = defb_modes[i]; } } /* Force FFOTHARG=1 so that this mode is enabled, not simply toggled */ if (init_fcn) init_fcn(FFOTHARG, 1); if (nobackups) makebkfile(FFARG, 0); for (nfiles = 0, i = 0; i < argc; i++) { if (argv[i][0] == '+' && strlen(argv[i]) >= 2) { long long lval; const char *errstr; lval = strtonum(&argv[i][1], INT_MIN, INT_MAX, &errstr); if (argv[i][1] == '\0' || errstr != NULL) goto notnum; startrow = lval; } else { notnum: cp = adjustname(argv[i], FALSE); if (cp != NULL) { if (nfiles == 1) splitwind(0, 1); if ((curbp = findbuffer(cp)) == NULL) { vttidy(); errx(1, "Can't find current buffer!"); } (void)showbuffer(curbp, curwp, 0); if (readin(cp) != TRUE) killbuffer(curbp); else { /* Ensure enabled, not just toggled */ if (init_fcn_name) init_fcn(FFOTHARG, 1); nfiles++; } } } } if (nfiles > 2) listbuffers(0, 1); /* fake last flags */ thisflag = 0; for (;;) { if (epresf == KCLEAR) eerase(); if (epresf == TRUE) epresf = KCLEAR; if (winch_flag) { do_redraw(0, 0, TRUE); winch_flag = 0; } update(); lastflag = thisflag; thisflag = 0; switch (doin()) { case TRUE: break; case ABORT: ewprintf("Quit"); /* FALLTHRU */ case FALSE: default: ttbeep(); macrodef = FALSE; } } }
int buffermenu(int f, int n) { BUFFER *bp; BUFFER *org_bp = curbp; int c,k; int bufptr; int bufcount = 0; bufptr = 1; start: listbuffers(f,n); swbuffer(blistp); onlywind(0,0); bufcount = count_buffers(); if (bufptr > bufcount) bufptr = bufcount; if (bufcount > 0) forwline(0, bufptr + 1); else forwline(0, 2); for (;;) { mlwrite("Buffer Menu: 1,2,s,v,k,q "); update(); c = ttgetc(); /* if no buffers, only allow exit */ if (bufcount == 0) { switch (c) { case 'q': case 'Q': case 'x': case 'X': break; default: (*term.t_beep) (); continue; } } /* * pre process escape sequence to get up/down arrows * convert to CTRL+N, CTRL+P */ if (c == ESC) { k = getctl(); if (k == '[') { k = getctl(); switch(k) { case 'A': c = CTRL_P; break; case 'B': c = CTRL_N; break; default: (*term.t_beep)(); continue; } } else { k = getctl(); (*term.t_beep) (); continue; } } /* if ESC */ switch (c) { case 'n': case 'N': case CTRL_N: if (bufcount == bufptr) { (*term.t_beep) (); break; } forwline(0,1); bufptr++; break; case 'p': case 'P': case CTRL_P: if (bufptr == 1) { (*term.t_beep) (); break; } backline(0,1); bufptr--; break; case '1': bp = get_buffer(bufptr); swbuffer(bp); onlywind(0,0); mlerase(); return TRUE; case '2': bp = get_buffer(bufptr); swbuffer(bp); onlywind(0,0); /* need to check or is still valid */ if (valid_buf(org_bp) == TRUE && bufcount > 1) { splitwind(0,0); swbuffer(org_bp); nextwind(0,0); } mlerase(); return TRUE; /* save file */ case 's': case 'S': bp = get_buffer(bufptr); if (bp != NULL) { curbp = bp; (void)filesave(0,0); curbp = blistp; goto start; } break; /* toggle read only */ case 'v': case 'V': case '%': bp = get_buffer(bufptr); if (bp != NULL) /* be defensive */ bp->b_flag ^= BFRO; goto start; break; /* kill buffer */ case 'k': case 'K': bp = get_buffer(bufptr); if (bp != NULL) zotbuf(bp); goto start; break; /* exit buffer menu */ case 'q': case 'Q': case 'x': case 'X': if (bufcount == 0) { bp = get_scratch(); swbuffer(bp); onlywind(0,0); mlerase(); return TRUE; } if (valid_buf(org_bp) == TRUE) swbuffer(org_bp); else swbuffer(bheadp); onlywind(0,0); mlerase(); return TRUE; /* any other key */ default: (*term.t_beep) (); break; } } mlerase(); return TRUE; }
int main(int argc, char **argv) { char *cp, *init_fcn_name = NULL; PF init_fcn = NULL; int o, i, nfiles; struct buffer *bp = NULL; while ((o = getopt(argc, argv, "f:")) != -1) switch (o) { case 'f': if (init_fcn_name != NULL) errx(1, "cannot specify more than one " "initial function"); init_fcn_name = optarg; break; default: usage(); } argc -= optind; argv += optind; setlocale(LC_CTYPE, ""); maps_init(); /* Keymaps and modes. */ funmap_init(); /* Functions. */ if (init_fcn_name && (init_fcn = name_function(init_fcn_name)) == NULL) errx(1, "Unknown function `%s'", init_fcn_name); vtinit(); /* Virtual terminal. */ dirinit(); /* Get current directory. */ edinit(bp); /* Buffers, windows. */ bellinit(); /* Audible and visible bell. */ /* * doing update() before reading files causes the error messages from * the file I/O show up on the screen. (and also an extra display of * the mode line if there are files specified on the command line.) */ update(CMODE); /* Force FFOTHARG=1 so that this mode is enabled, not simply toggled */ if (init_fcn) init_fcn(FFOTHARG, 1); for (nfiles = 0, i = 0; i < argc; i++) { if (argv[i][0] == '+' && strlen(argv[i]) >= 2) { long lval; char *end; lval = strtol(&argv[i][1], &end, 0); if (argv[i][1] == '\0' || *end != '\0') goto notnum; startrow = lval; } else { notnum: cp = adjustname(argv[i], FALSE); if (cp != NULL) { if (nfiles == 1) splitwind(0, 1); if ((curbp = findbuffer(cp)) == NULL) { vttidy(); errx(1, "Can't find current buffer!"); } (void)showbuffer(curbp, curwp, 0); if (readin(cp) != TRUE) killbuffer(curbp); else { /* Ensure enabled, not just toggled */ if (init_fcn_name) init_fcn(FFOTHARG, 1); nfiles++; } } } } if (nfiles > 2) listbuffers(0, 1); /* fake last flags */ thisflag = 0; for (;;) { if (epresf == KCLEAR) eerase(); if (epresf == TRUE) epresf = KCLEAR; if (winch_flag) { do_redraw(0, 0, TRUE); winch_flag = 0; } update(CMODE); lastflag = thisflag; thisflag = 0; switch (doin()) { case TRUE: break; case ABORT: ewprintf("Quit"); /* FALLTHRU */ case FALSE: default: macrodef = FALSE; } } }