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