Language detail: 秀丸マクロ

Coverage: 14.72%
number of '+' ratings
contribution for coverage

Unsolved challenges

codes

Feed

Used modules

next >>

IPv4アドレスのマスクの変換 (Nested Flatten)
・Mask2Bit:
  ネットマスク(文字型)を渡すとビット値(数値型)を返却します。
・Bit2Mask:
  ビット値(数値型)を渡すとネットマスク(文字型)を返却します。

/* ネットマスクをビット値に変換 */
call Mask2Bit input("input netmask.");
message str(##return);

/* 逆変換 */
call Bit2Mask val(input("input value."));
message $$return;

* パラメータの妥当性はチェックしてません。
* Bin2DecとDec2Binは2進数⇔10進数のサブルーチンです。
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
Mask2Bit:
    ##c=0;
    ##bit=0;
    while (strlen($$1)) {
        $b = leftstr($$1,1);
        $$1 = rightstr($$1, strlen($$1)-1);
        if ($b == ".") {
            ##c = ##c + 1;
        } else if (val($b) == 0 && $b != "0") {
            break;
        } else {
            $$aar[##c] = $$aar[##c] + $b;
        }
    }
    while (0 <= ##c) {
        call Dec2Bin val($$aar[##c]);
        while (strlen($$return)) {
            ##bit = ##bit + val(leftstr($$return,1));
            $$return = rightstr($$return, strlen($$return)-1);
        }
        ##c = ##c - 1;
    }
    return ##bit;

Bit2Mask:
    $$b_str = "";
    $$mask = "";
    while (strlen($$b_str) < 32) {
        if (0<##1) {
            $$b_str = $$b_str + "1";
        } else {
            $$b_str = $$b_str + "0";
        }
        ##1 = ##1 - 1;
    }
    while (strlen($$b_str)) {
        call Bin2Dec leftstr($$b_str, 8);
        $$mask = $$mask + str(##return);
        $$b_str = rightstr($$b_str, strlen($$b_str)-8);
        if (strlen($$b_str)) {
            $$mask = $$mask + ".";
        }
    }
    return $$mask;

Bin2Dec:
    ##dec = 0;
    ##val = 1;
    while (strlen($$1)) {
        if (rightstr($$1, 1) == "1") {
            ##dec = ##dec + ##val;
        }
        ##val = ##val*2;
        $$1 = leftstr($$1, strlen($$1)-1);
    }
    return ##dec;

Dec2Bin:
    $$str = "";
    if (##1!=0) {
        while (##1!=1) {
            $$str = str(##1%2)+$$str;
            ##1 = ##1/2;
        }
        $$str = "1"+$$str;
    } else {
        $$str = "0";
    }
    return $$str;
クリップボードへの転送 (Nested Flatten)
単に入力した文字列が表示されたように見えますが、
実際にはクリップボードを経由しています。
1
2
3
setclipboard input("input str.");
beginclipboardread;
message getclipboard;
LL Golf Hole 8 - 横向きのピラミッドを作る (Nested Flatten)
秀丸マクロ。
なかなか小さくならない。



1
2
3
4
5
6
7
8
#h=4;
while(y-#h+1<#h){
    #a=y-#h+1;
    if(#a<0)#a=#a*-1;
    $p="";
    while(strlen($p)<#h-#a)$p=$p+"*";
    insert$p+"\n";
}
キッチンタイマー (Nested Flatten)
入力は秒で。
タイムアウトで味気ないbeepが出力されます。
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
#sec = val(input("input sec."));
insert str(#sec)+"\n";
#start = tickcount;
while (#sec) {
    if ((#start + 1000) <= tickcount) {
        #start = tickcount;
        #sec = #sec - 1;
        moveto 0,0;
        beginsel;
        golineend;
        endsel;
        insert str(#sec);
        gofileend;
    }
}
beep;
endmacro;
バイナリクロック (Nested Flatten)
秀丸マクロです。
0と1で表示するシンプルなバイナリクロックです。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
$bin[0] = "";
$bin[1] = "";
$bin[2] = "";
insert "\n\n\n";

while (1) {
    #i = 0;
    while (#i < 3) {
        call GetBinTime #i;
        if ($bin[#i] != $$return) {
            $bin[#i] = $$return;
            moveto 0,#i;
            beginsel;
            golineend;
            endsel;
            insert $bin[#i];
            gofileend;
        }
        #i = #i+1;
    }
}
endmacro;

GetBinTime:
    refreshdatetime;
    if (##1 == 0) {
        call Dec2Bin val(hour);
    } else if (##1 == 1) {
        call Dec2Bin val(minute);
    } else {
        call Dec2Bin val(second);
    }
    while (strlen($$return) < 6) {
        $$return = " "+$$return;
    }
return $$return;

Dec2Bin:
    $$str = "";
    if (##1!=0) {
    while (##1!=1) {
        $$str = str(##1%2)+$$str;
        ##1 = ##1/2;
    }
    $$str = "1"+$$str;
}
return $$str;
ラングトンのアリの描画 (Nested Flatten)
秀丸マクロで。
セルを全角で表現しているので、かなり幅が広くなってしまいます。
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#w = 100;
#dct = 0;
$sp = " ";
$line = "";

#i = 0;
while (#i < #w) {
    $line = $line+$sp;
    #i = #i + 1;
}
$line = $line+"\n";

#i = 0;
while (#i < #w) {
    insert $line;
    #i = #i + 1;
}
movetolineno #w,#w/2;

#i = 0;
while (1) {
    $ant = gettext(x, y, x+2, y);
    if ($ant == $sp) {
        overwrite "○";
        #dct = (#dct+1)%4;
    } else {
        overwrite $sp;
        #dct = (((#dct+1)%4)+2)%4;
    }
    left;
    if (#dct == 0) {
        up;
    } else if (#dct == 1) {
        right;
    } else if (#dct == 2) {
        down;
    } else if (#dct == 3) {
        left;
    }
    if ((x > #w*2-1)||(x == 0)||(y == 0)||(y > #w-1)) {
        endmacro;
    }
}
endmacro;
道順を数える (Nested Flatten)
普通に数えてみました。
再帰処理が使えないので、自前で階層処理(#hier関連)を実装しました。
なので、処理がちょっと冗長に...
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
$goal="Q";
$pipe[0]="-";
$pipe[1]="|";
#route=1;
#hier=0;
#houkou=0;

    gofiletop;
    while( 1==1 ) {
        if( #houkou==0 || #houkou==1 ) {
            call rightdown #houkou;
            #ret=##return;
            if( #ret==1 ) {
                #rd[#hier]=#houkou;
                #pnt[#hier]=#pnt[#hier]+1;
                #hier=#hier+1;
                #houkou=0;
                continue;
            }
            #houkou=#houkou+1;
        } else {
            if( char(code)!=$goal ) {
                #route = #route+#pnt[#hier]-1;
            }
            #pnt[#hier]=0;
            #hier=#hier-1;
            #houkou=#rd[#hier]+1;
            if( #hier==-1 ) break;
            call gowhere #rd[#hier]+2;
            call gowhere #rd[#hier]+2;
            continue;
        }
    }
    message( str(#route) );
    endmacro;

rightdown:
    call gowhere ##1;
    if( char(code)==$pipe[##1] ) {
        call gowhere ##1;
        return 1;
    }
    call gowhere ##1+2;
    return 0;

gowhere:
    if( ##1==0 ) right;
    if( ##1==1 ) down;
    if( ##1==2 ) left;
    if( ##1==3 ) up;
    return;
島の数をカウントする (Nested Flatten)
初投稿です。
変態的な実装ができないかと考えていたのですが、
最適化していくうちに#8104さんと似た考え方になってしまいました。
秀丸の新規窓の左上に島を書いて、マクロ実行です。

考え方は以下の通りです。
1.左上から右下に向かって横にスキャン
2.上と左の島連番取得
3.取得出来なければ新しい島&島数プラス
4.上と左の島連番が一致しない場合、左の島連番を塗り直し&島数マイナス
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#xcharlen=2;
$wchar="□";
$bchar="■";

#xlen=4;
#ylen=4;

#wcnt=0;
#bcnt=0;
##x=0;
##y=0;
##serial=1;

    while( ##y < #ylen ) {
        ##x=0;
        while( ##x < #xlen ) {
            call GETCHAR ##x, ##y;
            $$c = $$return;
            if( ##y == 0 ) {
                ##no = ##serial;
            } else {
                call GETCHAR ##x, ##y-1;
                if( $$return == $$c ) {
                    ##no = #mtx[##y-1][##x];
                } else {
                    ##no = ##serial;
                }
            }
            if( ##x > 0 ) {
                call GETCHAR ##x-1, ##y;
                if( $$return == $$c ) {
                    if( ##no == ##serial ) {
                        ##no = #mtx[##y][##x-1];
                    } else if( ##no != #mtx[##y][##x-1] ) {
                        call RENUM ##no, #mtx[##y][##x-1], ##y, $$c;
                    }
                }
            }
            #mtx[##y][##x] = ##no;
            if( ##no == ##serial ) {
                call CNTISLAND $$c, 1;
                ##serial = ##serial+1;
            }
            ##x = ##x+1;
        }
        ##y = ##y+1;
    }

    message "白の島は" + str(#wcnt) + "つ\n" + "黒の島は" + str(#bcnt) + "つ";

    endmacro;

RENUM:
    ##i=0;
    while( ##i < ##3+1 ) {
        ##j=0;
        while( ##j < #xlen ) {
            if( #mtx[##i][##j]==##2 ) {
                #mtx[##i][##j]=##1;
            }
            ##j=##j+1;
        }
        ##i=##i+1;
    }

    call CNTISLAND $$4, -1;

    return;

CNTISLAND:
    if( $$1 == $wchar ) {
        #wcnt=#wcnt+##2;
    } else {
        #bcnt=#bcnt+##2;
    }

    return;

GETCHAR:
    ##x1 = ##1 * #xcharlen;
    ##x2 = ##x1 + #xcharlen;
    $$res=gettext(##x1, ##2, ##x2, ##2, 0);

    return $$res;
BFコンパイラー (Nested Flatten)
一番手間がかかったのはgetcharの実装です。
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
begingroupundo;
gofiletop;
$code['>'] = "#ptr=#ptr+1;";
$code['<'] = "#ptr=#ptr-1;";
$code['+'] = "#buf[#ptr]=#buf[#ptr]+1;";
$code['-'] = "#buf[#ptr]=#buf[#ptr]-1;";
$code['.'] = "insert char(#buf[#ptr]);";
$code[','] = "call get;";
$code['['] = "while(#buf[#ptr]){";
$code[']'] = "}";
#isUsedGetchar = false;
while( code != eof ) {
    if( code == ',' ) #isUsedGetchar = true;
    insert $code[code];
    delete;
}
if( #isUsedGetchar ) {
    insert "endmacro;get:if($get==\"\"&&#c<=0)$get=input(\"入力\");#c=ascii($get);if($get==\"\")#c=-1;$get=rightstr($get,strlen($get)-strlen(char(#c)));#buf[#ptr]=#c;return;";
}
endgroupundo;
ビンゴの結果を整形表示 (Nested Flatten)
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
    call srand tickcount;
    call bingo 35;
    endmacro;

bingo:
    ##i = 0;
    while( ##i < ##1 ) {
        ##dest[##i] = ##i + 1;
        ##i = ##i + 1;
    }
    ##i = 0;
    while( ##i < ##1 ) {
        call rand;
        ##r = ##return % ( ##1 - ##i ) + ##i;
        ##tmp = ##dest[##r];
        ##dest[##r] = ##dest[##i];
        ##dest[##i] = ##tmp;
        ##i = ##i + 1;
    }
    ##keta = strlen( str( ##1 ) );
    ##i = 0;
    while( ##i < ##1 ) {
        ##next = ##i + 10;
        if ( ##next > ##1 ) {
            ##next = ##1;
        }
        ##ii = ##i;
        while( ##ii < ##next ) {
            if ( ##ii > ##i ) {
                insert " ";
            }
            call KetaSoroe ##ii+1, ##keta;
            insert $$return;
            ##ii = ##ii + 1;
        }
        insert "\n";
        ##ii = ##i;
        while( ##ii < ##next ) {
            if ( ##ii > ##i ) {
                insert " ";
            }
            call KetaSoroe ##dest[##ii], ##keta;
            insert $$return;
            ##ii = ##ii + 1;
        }
        insert "\n\n";
        ##i = ##next;
    }
    return;

KetaSoroe:
    ##i = ##2 - strlen( str( ##1 ) );
    $$result = "";
    if ( ##i >= 0 ) {
        while( ##i > 0 ) {
            $$result = $$result + " ";
            ##i = ##i - 1;
        }
    }
    $$result = $$result + str( ##1 );
    return $$result;

rand:
    #rand_x = #rand_x * 214013 + 2531011;
    if ( #rand_x < 0 ) {
        return ( ( #rand_x + 1 ) / 65536 - 1 ) & 32767;
    }
    return #rand_x / 65536 & 32767;

srand:
    #rand_x = ##1;
    return;
重複無し乱数 (Nested Flatten)

乱数を発生させる関数がなかったのでそこから実装。

HSP ( #4289 ) と同じ結果になるように Visual C++ の rand と同じアルゴリズム・定数を使いました。 #4289 と乱数の種を同じにしたら同じ結果になるでしょう。 ( HSP の randomize の引数、秀丸マクロの srand サブルーチンの引数 )

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
    call srand tickcount;
    call bingo 10;
    call bingo 3;
    call bingo 3;
    call bingo 10;
    endmacro;

bingo:
    ##i = 0;
    while( ##i < ##1 ) {
        ##dest[##i] = ##i + 1;
        ##i = ##i + 1;
    }
    ##i = 0;
    while( ##i < ##1 ) {
        call rand;
        ##r = ##return % ( ##1 - ##i ) + ##i;
        ##tmp = ##dest[##r];
        ##dest[##r] = ##dest[##i];
        ##dest[##i] = ##tmp;
        ##i = ##i + 1;
    }
    ##i = 0;
    while( ##i < ##1 ) {
        if ( ##i > 0 ) {
            insert " ";
        }
        insert str( ##dest[##i] );
        ##i = ##i + 1;
    }
    insert "\n";
    return;

rand:
    #rand_x = #rand_x * 214013 + 2531011;
    if ( #rand_x < 0 ) {
        return ( ( #rand_x + 1 ) / 65536 - 1 ) & 32767;
    }
    return #rand_x / 65536 & 32767;

srand:
    #rand_x = ##1;
    return;
文字列のセンタリング (Nested Flatten)
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
    if ( getconfig( "AutoAdjustOrikaeshi" ) == 2 ) {
        #width = windowwidth;
    } else {
        #width = getconfig( "Orikaeshi" );
    }
    disabledraw;
    begingroupundo;
    if ( !selecting ) {
        selectall;
    }
    #i = seltoplineno;
    #end = selendlineno;
    escape;
    while( #i <= #end ) {
        movetolineno 1, #i;
        #margin = #width - linelen2;
        if ( #margin >= 0 ) {
            #j = #margin / 2;
            while( #j > 0 ) {
                insert " ";
                #j = #j - 1;
            }
        } else {
            while( linelen2 > #width ) {
                golineend2;
                backspace;
                if ( !linelen2 > #width ) {
                    break;
                }
                golinetop2
                delete;
            }
        }
        #i = #i + 1;
    }
    endgroupundo;
    enabledraw;
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
    begingroupundo;
    if ( getconfig( "AutoAdjustOrikaeshi" ) == 2 ) {
        #width = windowwidth;
    } else {
        #width = getconfig( "Orikaeshi" );
    }
    if ( !selecting ) {
        #top = 1;
        #end = linecount2;
    } else {
        #top = seltoplineno;
        #end = selendlineno;
        escape;
    }
    #i = #top;
    while( #i <= #end ) {
        movetolineno 1, #i;
        #margin = #width - linelen2;
        if ( #margin >= 0 ) {
            #j = #margin / 2;
            $margin = "";
            while( #j > 0 ) {
                $margin = $margin + " ";
                #j = #j - 1;
            }
            insert $margin;
        } else {
            beginsel;
            movetolineno linelen2 + 1, #i;
            $text = gettext( seltopx, seltopy, selendx, selendy, 1 );
            delete;
            call cutstr, $text, #width;
            insert $$return;
        }
        #i = #i + 1;
    }
    endgroupundo;
    endmacro;

cutstr:
    $$src = $$1;
    ##width = ##2;
    if ( ##width < 0 ) {
        ##width = 0;
    }
    if ( ##width > strlen( $$src ) ) {
        ##width = strlen( $$src );
    }
    ##start = strlen( $$src ) - ##width;
    ##end = strlen( $$src ) + ##width;
    ##i = 0;
    $$dest = "";
    $$left = "";
    $$right = "";
    while( ##i * 2 < ##end ) {
        ##char = ascii( $$src );
        ##bytes = strlen( char( ##char ) );
        if ( ##i * 2 < ##start ) {
            $$left = char( ##char );
        }
        if ( ( ( ##i + ##bytes ) * 2 > ##end ) && ( $$right == "" ) ) {
            $$right = char( ##char );
        }
        if ( ( ##i * 2 >= ##start ) && ( ( ##i + ##bytes ) * 2 <= ##end ) ) {
            $$dest = $$dest + char( ##char );
        }
        $$src = rightstr( $$src, strlen( $$src ) - ##bytes );
        ##i = ##i + ##bytes;
    }
    if ( $$right == "" ) {
        $$right = char( ascii( $$src ) );
    }
    if ( strlen( $$dest ) >= ##width ) {
        return $$dest;
    }
    if ( ( strlen( $$left + $$dest ) <= ##width ) && ( $$left != "" ) ) {
        return $$left + $$dest;
    }
    if ( ( strlen( $$dest + $$right ) <= ##width ) && ( $$right != "" ) ) {
        return $$dest + $$right;
    }
    return $$dest;
文字列として取得して整形。
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
    begingroupundo;
    if ( getconfig( "AutoAdjustOrikaeshi" ) == 2 ) {
        #width = windowwidth;
    } else {
        #width = getconfig( "Orikaeshi" );
    }
    if ( !selecting ) {
        selectall;
    } else {
        #l1 = seltoplineno;
        #l2 = selendlineno;
        movetolineno 1, #l1;
        beginsel;
        movetolineno 1, #l2;
        movetolineno linelen2 + 1, #l2;
        endsel;
    }
    $text = gettext( seltopx, seltopy, selendx, selendy, 1 );
    delete;
    call center $text, #width;
    insert $$return;
    endgroupundo;
    endmacro;

center:
    $$result = "";
    while( $$1 != "" ) {
        ##lineLen = strstr( $$1, "\x0d\x0a" );
        ##isLastLine = ##lineLen == -1;
        if ( ##isLastLine ) {
            ##lineLen = strlen( $$1 );
        }
        $$line = leftstr( $$1, ##lineLen );
        call center_line $$line, ##2;
        $$result = $$result + $$return;
        $$1 = rightstr( $$1, strlen( $$1 ) - ##lineLen );
        if ( !##isLastLine ) {
            $$1 = rightstr( $$1, strlen( $$1 ) - strlen( "\x0d\x0a" ) );
            $$result = $$result + "\n";
        }
    }
    return $$result;

center_line:
    ##margin = ##2 - strlen( $$1 );
    if ( ##margin >= 0 ) {
        $$result = "";
        ##i = ##margin / 2;
        while( ##i > 0 ) {
            $$result = $$result + " ";
            ##i = ##i - 1;
        }
        $$result = $$result + $$1;
    } else {
        ##idx = -##margin / 2;
        call midstr2, $$1, ##idx, ##2;
        $$result = $$return;
        // ±1バイトとる範囲をずらして、その中から一番長いテキストをとる
        if ( strlen( $$result ) < ##2 ) {
            call midstr2, $$1, ##idx + 1, ##2;
            if ( strlen( $$return ) > strlen( $$result ) ) {
                $$result = $$return;
            }
            if ( strlen( $$result ) < ##2 ) {
                call midstr2, $$1, ##idx - 1, ##2;
                if ( strlen( $$return ) > strlen( $$result ) ) {
                    $$result = $$return;
                }
            }
        }
    }
    return $$result;

midstr2: // マルチバイトを考慮した midstr
    $$src = $$1;
    ##idx = ##2;
    ##len = ##3;
    if ( ##idx < 0 ) {
        ##idx = 0;
    }
    if ( ##idx > strlen( $$src ) ) {
        ##idx = strlen( $$src );
    }
    if ( ##len < 0 ) {
        ##len = 0;
    }
    if ( ##len > strlen( $$src ) - ##idx ) {
        ##len = strlen( $$src ) - ##idx ;
    }
    
    ##end = ##idx + ##len;
    ##i = 0;
    $$dest = "";
    while( ##i < ##end ) {
        ##char = ascii( rightstr( $$src, strlen( $$src ) - ##i ) );
        ##byte = strlen( char( ##char ) );
        if ( ( ##i >= ##idx ) && ( ##i + ##byte <= ##end ) ) {
            $$dest = $$dest + char( ##char );
        }
        ##i = ##i + ##byte;
    }
    return $$dest;
税込み価格への修正 (Nested Flatten)
searchdown2 で。
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
    disabledraw;
    begingroupundo;
    gofiletop;
    while( true ) {
        searchdown2 "[0-9]", regular;
        if( !result ) {
            break;
        }
        #figX = x;
        #figY = y;
        searchdown "[^0-9]", regular;
        if( !result ) {
            gofileend;
        }
        #figure = val( gettext( #figX, #figY, x, y ) );
        beginsel;
        moveto #figX, #figY;
        insert str( #figure * 105 / 100 );
    }
    endgroupundo;
    enabledraw;
/*コメント*/を取り除く (Nested Flatten)
searchdown2 を使えばもっと簡潔にできましたね。
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
    disabledraw;
    begingroupundo;
    gofiletop;
    while( true ) {
        searchdown2 "/*";
        if ( !result ) {
            break;
        }
        #commentStartX = x;
        #commentStartY = y;
        movetolineno column + 1 + strlen( "/*" ), lineno;
        searchdown2 "*/";
        if( !result ) {
            gofileend;
        }
        movetolineno column + 1 + strlen( "*/" ), lineno;
        beginsel;
        moveto #commentStartX, #commentStartY;
        delete;
    }
    endgroupundo;
    enabledraw;
文字列からの情報抽出 (Nested Flatten)
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
    $output = "";
    disabledraw;
    gofiletop;
    while( true ) {
        searchdown2 "[A-Za-z]+(-hidden)?(-(small|big))?\\.[A-Za-z]+", regular;
        if ( !result ) {
            break;
        }
        #x = x;
        #y = y;
        searchdown "[-.]", regular;
        $name = gettext( #x, #y, x, y );
        $size = "normal";
        $hidden = "False";
        while( code == '-' ) {
            movetolineno column + 1 + strlen( "-" ), lineno;
            #x = x;
            #y = y;
            searchdown "[-.]", regular;
            $option = gettext( #x, #y, x, y );
            if ( $option == "big" ) {
                $size = "big";
            }
            if ( $option == "small" ) {
                $size = "small";
            }
            if ( $option == "hidden" ) {
                $hidden = "True";
            }
        }
        movetolineno column + 1 + strlen( "." ), lineno;
        #x = x;
        #y = y;
        searchdown "[^A-Za-z]", regular;
        if ( !result ) {
            gofileend;
        }
        $ext = gettext( #x, #y, x, y );
        $output = $output + "name:'" + $name + "', ext:'" + $ext+"', size: " + $size+" hidden: " + $hidden + "\n";
    }
    enabledraw;
    newfile;
    insert $output;
/*コメント*/を取り除く (Nested Flatten)
開いている文書から取り除く。
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
    disabledraw;
    begingroupundo;
    gofiletop;
    while( true ) {
        if ( gettext2( column, lineno, column + strlen( "/*" ), lineno ) != "/*" ) {
            searchdown "/*";
            if ( !result ) {
                break;
            }
        }
        #commentStartX = x;
        #commentStartY = y;
        movetolineno column + 1 + strlen( "/*" ), lineno;
        if ( gettext2( column, lineno, column + strlen( "*/" ), lineno ) != "*/" ) {
            searchdown "*/";
            if( !result ) {
                gofileend;
            }
        }
        movetolineno column + 1 + strlen( "*/" ), lineno;
        #commentEndX = x;
        #commentEndY = y;
        beginsel;
        moveto #commentStartX, #commentStartY;
        delete;
    }
    endgroupundo;
    enabledraw;
税込み価格への修正 (Nested Flatten)
開いている文書から変換。
「与えられた文字列の中から見つけ出し、変更した文字列を返す関数を作る」には沿っていませんが、この方が秀丸マクロらしいと思います。
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
    disabledraw;
    begingroupundo;
    gofiletop;
    while( true ) {
        if ( code < '0' || code > '9' ) {
            searchdown "[0-9]", regular;
            if( !result ) {
                break;
            }
        }
        #figX = x;
        #figY = y;
        searchdown "[^0-9]", regular;
        if( !result ) {
            gofileend;
        }
        #figure = val( gettext( #figX, #figY, x, y ) );
        beginsel;
        moveto #figX, #figY;
        delete;
        insert str( #figure * 105 / 100 );
    }
    endgroupundo;
    enabledraw;
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
    call IncludeTax "ダイコン150円、ハクサイ120円、ジャガイモ30円";
    message $$return;
    endmacro;

IncludeTax:
    $$figure = "";
    $$result = "";
    while( $$1 != "" ) {
        ##char = ascii( $$1 );
        if ( ##char >= '0' && ##char <= '9' ) {
            $$figure = $$figure + char( ##char );
        } else {
            if ( $$figure != "" ) {
                $$result = $$result + str( val( $$figure ) * 105 / 100 );
                $$figure = "";
            }
            $$result = $$result + char( ##char );
        }
        
        $$1 = rightstr( $$1, strlen( $$1 ) - strlen( char( ##char ) ) );
    }
    if ( $$figure != "" ) {
        $$result = $$result + str( val( $$figure ) * 105 / 100 );
        $$figure = "";
    }
    return $$result;
next >>

Index

Feed

Other

Link

Pathtraq

loading...