NoPaste

Ausschnitt aus bind.c

von RobertDebiannutzer

SNIPPET_TEXT:
  1. /*
  2.  * This is the general command execution routine. It handles the fake binding
  3.  * of all the keys to "self-insert". It also clears out the "thisflag" word,
  4.  * and arranges to move it to the "lastflag", so that the next command can
  5.  * look at it. Return the status of command.
  6.  */
  7. int execute(int c, int f, int n)
  8. {
  9.         int status;
  10.         fn_t execfunc;
  11.  
  12.         /* if the keystroke is a bound function...do it */
  13.         execfunc = getbind(c);
  14.         if (execfunc != NULL) {
  15.                 thisflag = 0;
  16.                 status = (*execfunc) (f, n);
  17.                 lastflag = thisflag;
  18.                 return status;
  19.         } else {
  20.                 /*
  21.                  * If we are not in insert mode, we don't want any further
  22.                  * progressing. Unbound keys should not be inserted as
  23.                  * characters.
  24.                  * Instead, an error should be printed.
  25.                  */
  26.                 if (bindmode != 2) {
  27.                         TTbeep();
  28.                         mlwrite("(key not bound)");     /* complain             */
  29.                         lastflag = 0;           /* Fake last flags.     */
  30.                         return FALSE;
  31.                 }
  32.         }
  33.  
  34.         /*
  35.          * If a space was typed, fill column is defined, the argument is non-
  36.          * negative, wrap mode is enabled, and we are now past fill column,
  37.          * and we are not read-only, perform word wrap.
  38.          */
  39.         if (c == ' ' && (curwp->w_bufp->b_mode & MDWRAP) && fillcol > 0 &&
  40.             n >= 0 && getccol(FALSE) > fillcol &&
  41.             (curwp->w_bufp->b_mode & MDVIEW) == FALSE)
  42.                 execute(META | SPEC | 'W', FALSE, 1);
  43.  
  44.         if ((c >= 0x20 && c <= 0x7E)    /* Self inserting.      */
  45.             || (c >= 0xA0 && c <= 0x10FFFF)) {  /* 8BIT P.K. */
  46.                 if (n <= 0) {   /* Fenceposts.          */
  47.                         lastflag = 0;
  48.                         return n < 0 ? FALSE : TRUE;
  49.                 }
  50.                 thisflag = 0;   /* For the future.      */
  51.  
  52.                 /*
  53.                  * if we are in overwrite mode, not at eol,
  54.                  * and next char is not a tab or we are at a tab stop,
  55.                  * delete a char forword
  56.                  */
  57.                 if (curwp->w_bufp->b_mode & MDOVER &&
  58.                     curwp->w_doto < curwp->w_dotp->l_used &&
  59.                     (lgetc(curwp->w_dotp, curwp->w_doto) != '\t' ||
  60.                      (curwp->w_doto) % 8 == 7))
  61.                         ldelchar(1, FALSE);
  62.  
  63.                 /* do the appropriate insertion */
  64.                 if (c == '}' && (curbp->b_mode & MDCMOD) != 0)
  65.                         status = insbrace(n, c);
  66.                 else if (c == '#' && (curbp->b_mode & MDCMOD) != 0)
  67.                         status = inspound();
  68.                 else
  69.                         status = linsert(n, c);
  70.  
  71. #if     CFENCE
  72.                 /* check for CMODE fence matching */
  73.                 if ((c == '}' || c == ')' || c == ']') &&
  74.                     (curbp->b_mode & MDCMOD) != 0)
  75.                         fmatch(c);
  76. #endif
  77.  
  78.                 /* check auto-save mode */
  79.                 if (curbp->b_mode & MDASAVE)
  80.                         if (--gacount == 0) {
  81.                                 /* and save the file if needed */
  82.                                 upscreen(FALSE, 0);
  83.                                 filesave(FALSE, 0);
  84.                                 gacount = gasave;
  85.                         }
  86.  
  87.                 lastflag = thisflag;
  88.                 return status;
  89.         }
  90.         /* oh, an error occured... */
  91.         TTbeep();
  92.         mlwrite("(keyboard processing error)"); /* complain             */
  93.         lastflag = 0;           /* Fake last flags.     */
  94.         return FALSE;
  95. }

Quellcode

Hier kannst du den Code kopieren und ihn in deinen bevorzugten Editor einfügen. PASTEBIN_DOWNLOAD_SNIPPET_EXPLAIN