mg.patch - randomcrap - random crap programs of varying quality
 (HTM) git clone git://git.codemadness.org/randomcrap
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
       mg.patch (3121B)
       ---
            1 diff --git a/usr.bin/mg/def.h b/usr.bin/mg/def.h
            2 index f7111ca1a06..a651e1801ee 100644
            3 --- a/usr.bin/mg/def.h
            4 +++ b/usr.bin/mg/def.h
            5 @@ -607,6 +607,8 @@ int                 inword(void);
            6  int                 transposeword(int, int);
            7  
            8  /* region.c X */
            9 +int                 filterregion(int, int);
           10 +int                 indentregion(int, int);
           11  int                 killregion(int, int);
           12  int                 copyregion(int, int);
           13  int                 lowerregion(int, int);
           14 diff --git a/usr.bin/mg/display.c b/usr.bin/mg/display.c
           15 index 7af723ce268..d7c22554753 100644
           16 --- a/usr.bin/mg/display.c
           17 +++ b/usr.bin/mg/display.c
           18 @@ -381,11 +381,8 @@ vtpute(int c)
           19  void
           20  vteeol(void)
           21  {
           22 -        struct video *vp;
           23 -
           24 -        vp = vscreen[vtrow];
           25          while (vtcol < ncol)
           26 -                vp->v_text[vtcol++] = ' ';
           27 +                vtpute(' ');
           28  }
           29  
           30  /*
           31 diff --git a/usr.bin/mg/funmap.c b/usr.bin/mg/funmap.c
           32 index bd555d6fc40..081a1ea569b 100644
           33 --- a/usr.bin/mg/funmap.c
           34 +++ b/usr.bin/mg/funmap.c
           35 @@ -148,6 +148,8 @@ static struct funmap functnames[] = {
           36          {overwrite_mode, "overwrite-mode",},
           37          {poptag, "pop-tag-mark",},
           38          {prefixregion, "prefix-region",},
           39 +        {filterregion, "filter-region",},
           40 +        {indentregion, "indent-region",},
           41          {backline, "previous-line",},
           42          {prevwind, "previous-window",},
           43          {spawncli, "push-shell",},
           44 diff --git a/usr.bin/mg/macro.c b/usr.bin/mg/macro.c
           45 index 984f6140450..969bf73739d 100644
           46 --- a/usr.bin/mg/macro.c
           47 +++ b/usr.bin/mg/macro.c
           48 @@ -30,12 +30,10 @@ definemacro(int f, int n)
           49  {
           50          struct line        *lp1, *lp2;
           51  
           52 -        macrocount = 0;
           53 +        if (macrodef)
           54 +                return finishmacro(f, n);
           55  
           56 -        if (macrodef) {
           57 -                ewprintf("already defining macro");
           58 -                return (macrodef = FALSE);
           59 -        }
           60 +        macrocount = 0;
           61  
           62          /* free lines allocated for string arguments */
           63          if (maclhead != NULL) {
           64 diff --git a/usr.bin/mg/region.c b/usr.bin/mg/region.c
           65 index 5e04f3f5ba9..c0dbd925d09 100644
           66 --- a/usr.bin/mg/region.c
           67 +++ b/usr.bin/mg/region.c
           68 @@ -359,6 +359,72 @@ setprefix(int f, int n)
           69  }
           70  
           71  int
           72 +filterregion(int f, int n)
           73 +{
           74 +        struct buffer *bp;
           75 +        struct line *lp;
           76 +        size_t i, j, len;
           77 +        char *p;
           78 +        int r;
           79 +
           80 +        /* if mark is not set: set mark to dot */
           81 +        if (curwp->w_markp == NULL)
           82 +                setmark(f, n);
           83 +
           84 +        r = piperegion(f, n);
           85 +        if (r == FALSE)
           86 +                return FALSE;
           87 +
           88 +        bp = bfind("*Shell Command Output*", FALSE);
           89 +        if (bp == NULL)
           90 +                return (FALSE);
           91 +
           92 +        undo_boundary_enable(FFRAND, 0);
           93 +
           94 +        /* kill region */
           95 +        killregion(f, n);
           96 +
           97 +        /* insert text from buffer */
           98 +        for (lp = bfirstlp(bp), i = 0; lp != bp->b_headp; lp = lforw(lp), i++) {
           99 +                p = ltext(lp);
          100 +                if (!i && !strcmp(p, "(Shell command succeeded with no output)"))
          101 +                        break;
          102 +                len = llength(lp);
          103 +                for (j = 0; j < len; j++)
          104 +                        linsert(1, p[j]);
          105 +                lnewline();
          106 +        }
          107 +
          108 +        /* close scratch window */
          109 +        killbuffer(bp);
          110 +        delwind(f, n);
          111 +
          112 +        undo_boundary_enable(FFRAND, 1);
          113 +
          114 +        return (TRUE);
          115 +}
          116 +
          117 +/* indent region with tab */
          118 +int
          119 +indentregion(int f, int n)
          120 +{
          121 +        int tmp[2];
          122 +
          123 +        /* remember previous prefix_string part */
          124 +        memcpy(tmp, prefix_string, sizeof(tmp));
          125 +
          126 +        prefix_string[0] = '\t';
          127 +        prefix_string[1] = '\0';
          128 +
          129 +        prefixregion(f, n);
          130 +
          131 +        /* restore */
          132 +        memcpy(prefix_string, tmp, sizeof(tmp));
          133 +
          134 +        return (TRUE);
          135 +}
          136 +
          137 +int
          138  region_get_data(struct region *reg, char *buf, int len)
          139  {
          140          int         i, off;