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

Diff for /src/usr.bin/mg/main.c between version 1.4 and 1.5

version 1.4, 2000/04/13 06:12:16 version 1.5, 2000/09/01 14:59:09
Line 1 
Line 1 
 /*  /*
  *              Mainline   *      Mainline.
  */   */
   
 #include        "def.h"  #include        "def.h"
   
 #ifndef NO_MACRO  #ifndef NO_MACRO
 #include        "macro.h"  #include        "macro.h"
 #endif  #endif  /* NO_MACRO */
   
 int             thisflag;       /* Flags, this command           */  int              thisflag;                      /* flags, this command  */
 int             lastflag;       /* Flags, last command           */  int              lastflag;                      /* flags, last command  */
 int             curgoal;        /* Goal column                   */  int              curgoal;                       /* goal column          */
 BUFFER         *curbp;          /* Current buffer                */  BUFFER          *curbp;                         /* current buffer       */
 MGWIN          *curwp;          /* Current window                */  BUFFER          *bheadp;                        /* BUFFER listhead      */
 BUFFER         *bheadp;         /* BUFFER listhead               */  MGWIN           *curwp;                         /* current window       */
 MGWIN          *wheadp = (MGWIN *) NULL;        /* MGWIN listhead                */  MGWIN           *wheadp = (MGWIN *)NULL;        /* MGWIN listhead       */
 char            pat[NPAT];      /* Pattern                       */  char             pat[NPAT];                     /* pattern              */
 #ifndef NO_DPROMPT  
 extern char     prompt[], *promptp;     /* delayed prompting             */  
 #endif  
   
 static VOID     edinit();  static VOID      edinit         __P((VOID));
   
 int  int
 main(argc, argv)  main(argc, argv)
         int             argc;          int    argc;
         char          **argv;          char **argv;
 {  {
 #ifndef NO_STARTUP          char    *cp;
         char           *startupfile();  
 #endif  
         char           *cp;  
         VOID            vtinit(), makename(), eerase();  
         BUFFER         *findbuffer();  
   
 #ifdef SYSINIT  #ifdef SYSINIT
         SYSINIT;                /* system dependent.     */          SYSINIT;                /* System dependent.            */
 #endif  #endif  /* SYSINIT */
         vtinit();               /* Virtual terminal.     */          vtinit();               /* Virtual terminal.            */
 #ifndef NO_DIR  #ifndef NO_DIR
         dirinit();              /* Get current directory */          dirinit();              /* Get current directory.       */
 #endif  #endif  /* !NO_DIR */
         edinit();               /* Buffers, windows.     */          edinit();               /* Buffers, windows.            */
         ttykeymapinit();        /* Symbols, bindings.    */          ttykeymapinit();        /* Symbols, bindings.           */
   
         /*          /*
          * doing update() before reading files causes the error messages from           * doing update() before reading files causes the error messages from
          * the file I/O show up on the screen.  (and also an extra display of           * the file I/O show up on the screen.  (and also an extra display of
          * the mode line if there are files specified on the command line.)           * the mode line if there are files specified on the command line.)
          */           */
         update();          update();
 #ifndef NO_STARTUP              /* User startup file.    */  
         if ((cp = startupfile((char *) NULL)) != NULL)  #ifndef NO_STARTUP
                 (VOID) load(cp);          /* user startup file */
 #endif          if ((cp = startupfile((char *)NULL)) != NULL)
                   (VOID)load(cp);
   #endif  /* !NO_STARTUP */
         while (--argc > 0) {          while (--argc > 0) {
                 cp = adjustname(*++argv);                  cp = adjustname(*++argv);
                 curbp = findbuffer(cp);                  curbp = findbuffer(cp);
                 (VOID) showbuffer(curbp, curwp, 0);                  (VOID)showbuffer(curbp, curwp, 0);
                 (VOID) readin(cp);                  (VOID)readin(cp);
         }          }
         thisflag = 0;           /* Fake last flags.      */  
           /* fake last flags */
           thisflag = 0;
         for (;;) {          for (;;) {
 #ifndef NO_DPROMPT  #ifndef NO_DPROMPT
                 *(promptp = prompt) = '\0';                  *(promptp = prompt) = '\0';
                 if (epresf == KPROMPT)                  if (epresf == KPROMPT)
                         eerase();                          eerase();
 #endif  #endif  /* !NO_DPROMPT */
                 update();                  update();
                 lastflag = thisflag;                  lastflag = thisflag;
                 thisflag = 0;                  thisflag = 0;
   
                 switch (doin()) {                  switch (doin()) {
                 case TRUE:                  case TRUE:
                         break;                          break;
                 case ABORT:                  case ABORT:
                         ewprintf("Quit");       /* and fall through      */                          ewprintf("Quit");
                           /* and fall through */
                 case FALSE:                  case FALSE:
                 default:                  default:
                         ttbeep();                          ttbeep();
 #ifndef NO_MACRO  #ifndef NO_MACRO
                         macrodef = FALSE;                          macrodef = FALSE;
 #endif  #endif  /* !NO_MACRO */
                 }                  }
         }          }
 }  }
Line 85 
Line 86 
 /*  /*
  * Initialize default buffer and window.   * Initialize default buffer and window.
  */   */
 static          VOID  static VOID
 edinit()  edinit()
 {  {
         register BUFFER *bp;          BUFFER  *bp;
         register MGWIN *wp;          MGWIN   *wp;
   
         bheadp = NULL;          bheadp = NULL;
         bp = bfind("*scratch*", TRUE);  /* Text buffer.          */          bp = bfind("*scratch*", TRUE);          /* Text buffer.          */
         wp = (MGWIN *) malloc(sizeof(MGWIN));   /* Initial window.       */          wp = (MGWIN *)malloc(sizeof(MGWIN));    /* Initial window.       */
         if (bp == NULL || wp == NULL)          if (bp == NULL || wp == NULL)
                 panic("edinit");                  panic("edinit");
         curbp = bp;             /* Current ones.         */          curbp = bp;                             /* Current ones.         */
         wheadp = wp;          wheadp = wp;
         curwp = wp;          curwp = wp;
         wp->w_wndp = NULL;      /* Initialize window.    */          wp->w_wndp = NULL;                      /* Initialize window.    */
         wp->w_bufp = bp;          wp->w_bufp = bp;
         bp->b_nwnd = 1;         /* Displayed.            */          bp->b_nwnd = 1;                         /* Displayed.            */
         wp->w_linep = wp->w_dotp = bp->b_linep;          wp->w_linep = wp->w_dotp = bp->b_linep;
         wp->w_doto = 0;          wp->w_doto = 0;
         wp->w_markp = NULL;          wp->w_markp = NULL;
         wp->w_marko = 0;          wp->w_marko = 0;
         wp->w_toprow = 0;          wp->w_toprow = 0;
         wp->w_ntrows = nrow - 2;/* 2 = mode, echo.       */          wp->w_ntrows = nrow - 2;                /* 2 = mode, echo.       */
         wp->w_force = 0;          wp->w_force = 0;
         wp->w_flag = WFMODE | WFHARD;   /* Full.                 */          wp->w_flag = WFMODE | WFHARD;           /* Full.                 */
 }  }
   
 /*  /*
  * Quit command. If an argument, always   * Quit command.  If an argument, always quit.  Otherwise confirm if a buffer
  * quit. Otherwise confirm if a buffer has been   * has been changed and not written out.  Normally bound to "C-X C-C".
  * changed and not written out. Normally bound  
  * to "C-X C-C".  
  */   */
 /* ARGSUSED */  /* ARGSUSED */
   int
 quit(f, n)  quit(f, n)
           int f, n;
 {  {
         register int    s;          int      s;
         VOID            vttidy();  
   
         if ((s = anycb(FALSE)) == ABORT)          if ((s = anycb(FALSE)) == ABORT)
                 return ABORT;                  return ABORT;
         if (s == FALSE          if (s == FALSE
             || eyesno("Some modified buffers exist, really exit") == TRUE) {              || eyesno("Some modified buffers exist, really exit") == TRUE) {
                 vttidy();                  vttidy();
 #ifdef  SYSCLEANUP  #ifdef SYSCLEANUP
                 SYSCLEANUP;                  SYSCLEANUP;
 #endif  #endif  /* SYSCLEANUP */
                 exit(GOOD);                  exit(GOOD);
         }          }
         return TRUE;          return TRUE;
 }  }
   
 /*  /*
  * User abort. Should be called by any input routine that sees a C-g   * User abort.  Should be called by any input routine that sees a C-g to abort
  * to abort whatever C-g is aborting these days. Currently does   * whatever C-g is aborting these days. Currently does nothing.
  * nothing.  
  */   */
 /* ARGSUSED */  /* ARGSUSED */
 int  int

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.5