Annotation of src/usr.bin/mg/main.c, Revision 1.13
1.13 ! art 1: /* $OpenBSD: main.c,v 1.12 2001/05/24 10:43:19 art Exp $ */
1.6 niklas 2:
1.1 deraadt 3: /*
1.5 millert 4: * Mainline.
1.1 deraadt 5: */
1.5 millert 6:
1.1 deraadt 7: #include "def.h"
1.12 art 8: #include "kbd.h"
1.11 art 9: #include "funmap.h"
1.5 millert 10:
1.1 deraadt 11: #ifndef NO_MACRO
12: #include "macro.h"
1.5 millert 13: #endif /* NO_MACRO */
1.1 deraadt 14:
1.5 millert 15: int thisflag; /* flags, this command */
16: int lastflag; /* flags, last command */
17: int curgoal; /* goal column */
18: BUFFER *curbp; /* current buffer */
19: BUFFER *bheadp; /* BUFFER listhead */
20: MGWIN *curwp; /* current window */
1.8 art 21: MGWIN *wheadp; /* MGWIN listhead */
1.5 millert 22: char pat[NPAT]; /* pattern */
1.1 deraadt 23:
1.7 art 24: static void edinit __P((void));
1.1 deraadt 25:
1.2 deraadt 26: int
1.1 deraadt 27: main(argc, argv)
1.10 mickey 28: int argc;
29: char **argv;
1.1 deraadt 30: {
1.5 millert 31: char *cp;
1.1 deraadt 32:
33: #ifdef SYSINIT
1.5 millert 34: SYSINIT; /* System dependent. */
35: #endif /* SYSINIT */
36: vtinit(); /* Virtual terminal. */
1.1 deraadt 37: #ifndef NO_DIR
1.5 millert 38: dirinit(); /* Get current directory. */
39: #endif /* !NO_DIR */
40: edinit(); /* Buffers, windows. */
1.12 art 41: maps_init(); /* Keymaps and modes. */
1.11 art 42: funmap_init(); /* Functions. */
1.5 millert 43: ttykeymapinit(); /* Symbols, bindings. */
1.13 ! art 44:
! 45: /*
! 46: * This is where we initialize standalone extensions that should
! 47: * be loaded dynamically sometime in the future.
! 48: */
! 49: {
! 50: extern void grep_init(void);
! 51:
! 52: grep_init();
! 53: }
1.5 millert 54:
1.4 millert 55: /*
56: * doing update() before reading files causes the error messages from
57: * the file I/O show up on the screen. (and also an extra display of
58: * the mode line if there are files specified on the command line.)
1.1 deraadt 59: */
60: update();
1.5 millert 61:
62: #ifndef NO_STARTUP
63: /* user startup file */
1.8 art 64: if ((cp = startupfile(NULL)) != NULL)
1.7 art 65: (void)load(cp);
1.5 millert 66: #endif /* !NO_STARTUP */
1.1 deraadt 67: while (--argc > 0) {
68: cp = adjustname(*++argv);
69: curbp = findbuffer(cp);
1.7 art 70: (void)showbuffer(curbp, curwp, 0);
71: (void)readin(cp);
1.1 deraadt 72: }
1.5 millert 73:
74: /* fake last flags */
75: thisflag = 0;
1.4 millert 76: for (;;) {
1.1 deraadt 77: #ifndef NO_DPROMPT
1.4 millert 78: if (epresf == KPROMPT)
79: eerase();
1.5 millert 80: #endif /* !NO_DPROMPT */
1.4 millert 81: update();
82: lastflag = thisflag;
83: thisflag = 0;
1.5 millert 84:
1.4 millert 85: switch (doin()) {
86: case TRUE:
87: break;
1.1 deraadt 88: case ABORT:
1.5 millert 89: ewprintf("Quit");
90: /* and fall through */
1.1 deraadt 91: case FALSE:
92: default:
1.4 millert 93: ttbeep();
1.1 deraadt 94: #ifndef NO_MACRO
1.4 millert 95: macrodef = FALSE;
1.5 millert 96: #endif /* !NO_MACRO */
1.4 millert 97: }
1.1 deraadt 98: }
99: }
100:
101: /*
102: * Initialize default buffer and window.
103: */
1.7 art 104: static void
1.4 millert 105: edinit()
106: {
1.5 millert 107: BUFFER *bp;
108: MGWIN *wp;
1.1 deraadt 109:
110: bheadp = NULL;
1.5 millert 111: bp = bfind("*scratch*", TRUE); /* Text buffer. */
112: wp = (MGWIN *)malloc(sizeof(MGWIN)); /* Initial window. */
1.4 millert 113: if (bp == NULL || wp == NULL)
114: panic("edinit");
1.5 millert 115: curbp = bp; /* Current ones. */
1.1 deraadt 116: wheadp = wp;
1.4 millert 117: curwp = wp;
1.5 millert 118: wp->w_wndp = NULL; /* Initialize window. */
1.4 millert 119: wp->w_bufp = bp;
1.5 millert 120: bp->b_nwnd = 1; /* Displayed. */
1.1 deraadt 121: wp->w_linep = wp->w_dotp = bp->b_linep;
1.4 millert 122: wp->w_doto = 0;
1.1 deraadt 123: wp->w_markp = NULL;
124: wp->w_marko = 0;
125: wp->w_toprow = 0;
1.5 millert 126: wp->w_ntrows = nrow - 2; /* 2 = mode, echo. */
1.1 deraadt 127: wp->w_force = 0;
1.5 millert 128: wp->w_flag = WFMODE | WFHARD; /* Full. */
1.1 deraadt 129: }
130:
131: /*
1.5 millert 132: * Quit command. If an argument, always quit. Otherwise confirm if a buffer
133: * has been changed and not written out. Normally bound to "C-X C-C".
1.1 deraadt 134: */
1.4 millert 135: /* ARGSUSED */
1.5 millert 136: int
1.1 deraadt 137: quit(f, n)
1.5 millert 138: int f, n;
1.1 deraadt 139: {
1.5 millert 140: int s;
1.1 deraadt 141:
1.4 millert 142: if ((s = anycb(FALSE)) == ABORT)
143: return ABORT;
1.1 deraadt 144: if (s == FALSE
1.4 millert 145: || eyesno("Some modified buffers exist, really exit") == TRUE) {
1.1 deraadt 146: vttidy();
1.5 millert 147: #ifdef SYSCLEANUP
1.4 millert 148: SYSCLEANUP;
1.5 millert 149: #endif /* SYSCLEANUP */
1.1 deraadt 150: exit(GOOD);
151: }
152: return TRUE;
153: }
154:
155: /*
1.10 mickey 156: * User abort. Should be called by any input routine that sees a C-g to abort
1.5 millert 157: * whatever C-g is aborting these days. Currently does nothing.
1.1 deraadt 158: */
1.4 millert 159: /* ARGSUSED */
160: int
1.1 deraadt 161: ctrlg(f, n)
1.4 millert 162: int f, n;
1.1 deraadt 163: {
164: return ABORT;
165: }