[BACK]Return to main.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / mg

Annotation of src/usr.bin/mg/main.c, Revision 1.19

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