[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.11

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