home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d3xx / d352 / mg.lha / MG / src.LZH / mg / main.c < prev    next >
C/C++ Source or Header  |  1990-05-23  |  4KB  |  178 lines

  1. /*
  2.  * Mainline 
  3.  */
  4. #include    "no_macro.h"
  5. #include    "no_dprompt.h"
  6. #include    "no_startup.h"
  7. #include    "no_dir.h"
  8.  
  9. #include    "def.h"
  10. #include    "buffer.h"
  11. #include    "window.h"
  12. #ifndef NO_MACRO
  13. #include    "macro.h"
  14. #endif
  15.  
  16. #ifdef    ANSI
  17. #include <stdlib.h>
  18. #endif
  19.  
  20. int             thisflag;    /* Flags, this command         */
  21. int             lastflag;    /* Flags, last command         */
  22. int             curgoal;    /* Goal column             */
  23. struct buffer  *curbp;        /* Current buffer         */
  24. struct window  *curwp;        /* Current window         */
  25. struct buffer  *bheadp;        /* BUFFER listhead         */
  26. struct window  *wheadp = NULL;    /* WINDOW listhead         */
  27. char            pat[NPAT];    /* Pattern             */
  28. #ifndef NO_DPROMPT
  29. extern char     prompt[], *promptp;    /* delayed prompting         */
  30. #endif
  31.  
  32. static VOID edinit 
  33. PROTO((void));
  34.  
  35. #ifndef NO_PROTO
  36. VOID main
  37. PROTO((int, char **));
  38. #endif
  39.  
  40. VOID
  41. main(argc, argv)
  42.     int             argc;
  43.     char          **argv;
  44. {
  45. #ifndef NO_STARTUP
  46.     char           *startupfile();
  47. #endif
  48.     char           *cp;
  49.     VOID            vtinit(), makename(), eerase();
  50.     struct buffer  *findbuffer();
  51.  
  52. #ifdef SYSINIT
  53.     SYSINIT;        /* system dependent.     */
  54. #endif
  55.     vtinit();        /* Virtual terminal.     */
  56. #ifndef NO_DIR
  57.     dirinit();        /* Get current directory */
  58. #endif
  59.     edinit();        /* Buffers, windows.     */
  60.     ttykeymapinit();    /* Symbols, bindings.     */
  61.     /*
  62.      * doing update() before reading files causes the error messages from
  63.      * the file I/O show up on the screen.    (and also an extra display of
  64.      * the mode line if there are files specified on the command line.) 
  65.      */
  66.     update();
  67. #ifndef NO_STARTUP        /* User startup file.     */
  68.     if ((cp = startupfile()) != NULL)
  69.         (VOID) load(cp);
  70. #endif
  71.     while (--argc > 0) {
  72.         cp = adjustname(*++argv);
  73.         curbp = findbuffer(cp);
  74.         (VOID) showbuffer(curbp, curwp, 0);
  75.         (VOID) readin(cp);
  76.     }
  77.     thisflag = 0;        /* Fake last flags.     */
  78.     /*
  79.      * Note: A second version of this loop basically occurs in runmacro
  80.      * (mg/macro.c). If you change this loop, you should double-check
  81.      * that loop to see if the changes need to be reflected therein, as
  82.      * well. 
  83.      */
  84.     for (;;) {
  85. #ifndef NO_DPROMPT
  86.         *(promptp = prompt) = '\0';
  87. #endif
  88.         if (epresf == ERASE)
  89.             eerase();
  90.         else if (epresf)
  91.             epresf = ERASE;
  92.         update();
  93.         lastflag = thisflag;
  94.         thisflag = 0;
  95.         switch (doin()) {
  96.         case TRUE:
  97.             break;
  98.         case ABORT:
  99.             ewprintf("Quit");    /* and fall through     */
  100.         case FALSE:
  101.         default:
  102.             ttbeep();
  103. #ifndef NO_MACRO
  104.             if (macrodef)
  105.                 restore_macro();
  106.             macrodef = FALSE;
  107. #endif
  108.         }
  109.     }
  110. }
  111.  
  112. /*
  113.  * Initialize default buffer and window. Also fix the kbdmacro.
  114.  */
  115. static          VOID
  116. edinit()
  117. {
  118.     register struct buffer *bp;
  119.     register struct window *wp;
  120. #ifndef    NO_MACRO
  121.     extern struct macro    kbdmacro;
  122.  
  123.     kbdmacro.m_name = "";    /* If only everyone had ANSI compilers */
  124. #endif
  125.     bheadp = NULL;
  126.     bp = bfind("*scratch*", TRUE);    /* Text buffer.         */
  127.     wp = (struct window *) malloc(sizeof(struct window));    /* Initial window.     */
  128.     if (bp == NULL || wp == NULL)
  129.         panic("edinit");
  130.     curbp = bp;        /* Current ones.     */
  131.     wheadp = wp;
  132.     curwp = wp;
  133.     wp->w_wndp = NULL;    /* Initialize window.     */
  134.     wp->w_bufp = bp;
  135.     bp->b_nwnd = 1;        /* Displayed.         */
  136.     wp->w_linep = wp->w_dotp = bp->b_linep;
  137.     wp->w_doto = 0;
  138.     wp->w_markp = NULL;
  139.     wp->w_marko = 0;
  140.     wp->w_toprow = 0;
  141.     wp->w_ntrows = nrow - 2;/* 2 = mode, echo.     */
  142.     wp->w_force = 0;
  143.     wp->w_flag = WFMODE | WFHARD;    /* Full.         */
  144. }
  145.  
  146. /*
  147.  * Quit command. If an argument, always quit. Otherwise confirm if a buffer
  148.  * has been changed and not written out. Normally bound to "C-X C-C". 
  149.  */
  150. /* ARGSUSED */
  151. quit(f, n)
  152. {
  153.     register int    s;
  154.     VOID            vttidy();
  155.  
  156.     if ((s = anycb(FALSE)) == ABORT)
  157.         return ABORT;
  158.     if (s == FALSE
  159.         || eyesno("Some modified buffers exist, really exit") == TRUE) {
  160.         vttidy();
  161. #ifdef    SYSCLEANUP
  162.         SYSCLEANUP;
  163. #endif
  164.         exit(GOOD);
  165.     }
  166.     return TRUE;
  167. }
  168.  
  169. /*
  170.  * User abort. Should be called by any input routine that sees a C-g to abort
  171.  * whatever C-g is aborting these days. Currently does nothing. 
  172.  */
  173. /* ARGSUSED */
  174. ctrlg(f, n)
  175. {
  176.     return ABORT;
  177. }
  178.