home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 1997 November / VPR9711A.ISO / VPR_DATA / Special / movemn8s / movemn8s.lzh / INP_CNTR.MAC < prev    next >
Text File  |  1997-03-06  |  5KB  |  214 lines

  1. //  左右指定センタリングマクロ ver.8.00
  2. //  by JRくん(GFB03426)  97.3.7
  3.  
  4.  
  5.     if (readonly) {
  6.         message "左右指定センタリング:「上書き禁止」なので実行を中止します。";
  7.         endmacro;
  8.     }
  9.     if (browsemode) {
  10.         message "左右指定センタリング:「閲覧モード」なので実行を中止します。";
  11.         endmacro;
  12.     }
  13.  
  14.     $b=searchbuffer;
  15.     #s=searchoption;
  16.  
  17.     //  INIファイルを取得
  18.     $INIdir = getinistr("HIDEMARU.INI", "Env", "MacroPath");
  19.     if ($INIdir == "") $INIdir = hidemarudir;
  20.     $INIfile = $INIdir+"\\MOVEMENU.INI";
  21.  
  22.     //  左端のデフォルト値の設定
  23.     #default = getininum($INIfile, "Margin", "LeftMargin");
  24.  
  25.     //  右端のデフォルト値の設定
  26.     #default2 = getininum($INIfile, "Margin", "RightMargin");
  27.     if (#default2 == 0) {
  28.         #default2 = 70;
  29.     }
  30.  
  31.     $space80 = "                                                                               ";
  32.  
  33. //  ワードラップ使用時には警告
  34.     if ( kinsokustate ) {
  35.         if ( getininum("hidemaru.ini","Env","Wordwrap") == 1 ) {
  36.         question "左右指定センタリング:\n"
  37.                + "現在この秀丸はワードラップ機能を使用していますが、\n"
  38.                + "このまま処理を続けると、レイアウトが崩れたり、\n"
  39.                + "行の最後が2文字程度欠落したりする場合があります。\n"
  40.                + "\nこのまま処理を続けますか?";
  41.         if ( result == no ) endmacro;
  42.         }
  43.     }
  44.  
  45. disableinvert;
  46.  
  47. //  処理範囲を取得
  48.  
  49.     if ((selecting) || (rectselecting)) {
  50.         #y2 = seltopy;
  51.         #y1 = selendy;
  52.         if (selendx == 0) #y1 = #y1 - 1;
  53.         escape;
  54.     } else {
  55.         #y1 = y;
  56.         #y2 = y;
  57.     }
  58.  
  59. //  左端を入力
  60.  
  61.     #imestate = imestate;
  62.     if (#imestate) imeswitch;
  63.  
  64.     PosInput:
  65.     $Pos = input("左右指定センタリングマクロ\n"
  66.            + "左余白の値を入力してください。", str(#default));
  67.     if (result == no) endmacro;
  68.     #Pos = val($Pos);
  69.     if (#Pos < 0) {
  70.         message "0以上の値を入力してください。";
  71.         goto PosInput;
  72.     }
  73.     if (#Pos != #default) {
  74.         writeininum $INIfile, "Margin", "LeftMargin", #Pos;
  75.     }
  76.  
  77. //  右端を入力
  78.     PosInput2:
  79.     $Pos2 = input("左右指定センタリングマクロ\n"
  80.             + "右端の値を入力してください。", str(#default2));
  81.     if (result == no) endmacro;
  82.     #Pos2 = val($Pos2);
  83.     if (#Pos2 <= #Pos) {
  84.         message "左端より大きい値を入力してください。";
  85.         goto PosInput2;
  86.     }
  87.     if (#Pos2 != #default2) {
  88.         writeininum $INIfile, "Margin", "RightMargin", #Pos2;
  89.     }
  90.  
  91.     if (#imestate) imeswitch;
  92.  
  93.  
  94. //  1行分の文字列を処理するルーチン
  95.     OneLineLoop:
  96.     moveto 0, #y1;
  97.  
  98. //  (EOF対策)
  99.     #IsEof = ( #y1 == linecount - 1 );
  100.  
  101. //  その行の開始x座標を取得
  102.  
  103.     #xstart = 0;
  104.     #Code = code;
  105.     if (#Code == 0x0d) {
  106.         //  改行だけだった場合
  107.         goto OneLineEnd;
  108.     } else if ((#Code == 0x20) || (#Code == 0x8140)
  109.         || (#Code == 0)    || (#Code == 0x09))  {
  110.         //  半角/全角スペース・ヌル文字・タブ
  111.         searchdown "[^  \t]",regular;
  112.         if ((y > #y1) || (code == 0x0d) || (code == eof)) {
  113.             //  その行すべてがスペース等だった場合
  114.             goto AllChrDel;
  115.         } else {
  116.             #xstart = x;
  117.         }
  118.     }
  119.  
  120. //  終了x座標を取得
  121.  
  122.     golineend;
  123.     #Code = code;
  124.     if ((#Code == 0x20) || (#Code == 0x8140) || (#Code == 0)
  125.      || (#Code == 0x09) || (#Code == 0x0d)   || (#Code == eof))  {
  126.         //  半角/全角スペース・ヌル文字・タブ・改行・EOFの場合
  127.         searchup "[^  \t]",regular;
  128.     }
  129.     right;
  130.     #xend = x;
  131.     #yend = y;
  132.  
  133.  
  134. //  タブ処理
  135.     moveto 0, #y1;
  136.     beginsel;
  137.     golineend;
  138.     tospace;
  139.     escape;
  140.  
  141. //  カット後の文字列を取得
  142.     $tcutted = gettext(#xstart, #y1, #xend, #yend);
  143.  
  144.  
  145. //  センタリング
  146.  
  147. //  左側のスペースを計算
  148.     #len = strlen($tcutted);
  149.     if ((#Pos2 - #len) > 0) {
  150.         #space = #Pos + ((#Pos2 - #len)/ 2);
  151.     } else {
  152.         #space = #Pos;
  153.     }
  154.  
  155.     $space = "";
  156.     if (#space > 0) {
  157.  
  158.         #sp1 = #space / 80;
  159.         #sp2 = #space % 80;
  160.  
  161.         while (#sp1 > 0) {
  162.             $space = $space + $space80;
  163.             #sp1 = #sp1 - 1;
  164.         }
  165.         $space = $space + leftstr($space80, #sp2);
  166.     }
  167.  
  168.     moveto 0, #y1;
  169.  
  170. //  前行末に半角分の空きがある場合には改行を追加挿入するための下準備
  171.     $preface = "";
  172.     if (column != 0) {
  173.         up;
  174.         if (linelen < width) $preface = "\n";
  175.         down;
  176.     }
  177.  
  178. //  文字列挿入処理
  179.     beginsel;
  180.     if (#IsEof) {
  181.         golineend;
  182.         insert $preface + $space + $tcutted;
  183.     } else if (#len > width) {
  184.         down;
  185.         insert $preface + $space + $tcutted;
  186.     } else {
  187.         down;
  188.         insert $preface + $space + $tcutted + "\n";
  189.     }
  190.  
  191.     goto OneLineEnd;
  192.  
  193. //  その行すべてがスペース等の場合は、改行と置き換える、または削除
  194.     AllChrDel:
  195.     moveto 0, #y1;
  196.     beginsel;
  197.     if (#IsEof) {
  198.         golineend;
  199.         delete;
  200.     } else {
  201.         down;
  202.         insert "\n";
  203.     }
  204.  
  205. //  ループ
  206.     OneLineEnd:
  207.     #y1 = #y1 - 1;
  208.     if (#y1 >= #y2) goto OneLineLoop;
  209.  
  210. //  終了処理
  211.     setsearch $b,#s;
  212.     enableinvert;
  213.     endmacro;
  214.