home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 1997 November / VPR9711A.ISO / VPR_DATA / Special / Mm95350 / mm95350.lzh / DANRAKU.MAC < prev    next >
Text File  |  1996-05-17  |  2KB  |  75 lines

  1. // [禁則処理付き段落整形マクロ]
  2. //  danraku.mac
  3. //
  4. // 1段落(改行まで)を整形します。
  5. // インデント(字下げ)および行頭・行末禁則文字の処理を行います。
  6. // 段落の最初が2個以上(n個)の全角スペースで始まるとき、2行目以後の
  7. // 行頭は自動的に n-1 字分インデントされます。
  8. // 整形終了後、カーソル位置は次の段落の先頭へ移動します。
  9. // 1行の長さを変える場合は xwide の値(現在は64)を変更して下さい。
  10. //
  11. main()
  12. {
  13.     char *ps, *pe;
  14.     int n, num, xwide, sIns, sInd;
  15.     
  16.         // 行頭禁則文字を指定します
  17.     ps=" 、。,.:;!?)]}」-、。,.:;!?)〕]}〉》」』】’”";
  18.         // 行末禁則文字を指定します
  19.     pe="([{「(〔[{〈《「『【‘“";
  20.     xwide = 64;    // 1行の長さ
  21.     sIns = Ins;
  22.     sInd = Indent;
  23.     InsMode(1);
  24.     AIndent(0);
  25.     num = 0;
  26.     
  27.     LEdge();
  28.     if(Code == 0x8140)        // 段落の最初が全角スペースなら
  29.     {
  30.       while(Code == 0x8140)    // 全角スペースの連続数を数える
  31.       {
  32.         ++num;
  33.         Right();
  34.       }
  35.       LEdge();
  36.     }
  37.     while(1)
  38.     {
  39.       KbHit();
  40.       if(Result == 0x1b)    // [ESC]が押されたら中断
  41.         break;
  42.       GotoX(xwide + 1);
  43.       if(Tcode == 1)    // 整形終了で、カーソル位置は次の段落の先頭へ
  44.       {
  45.         while(Tcode == 1)
  46.           Right();
  47.         break;
  48.       }
  49.       else
  50.       {
  51.         Left();
  52.         StrChr(Code, pe);    // 行末禁則文字をチェック
  53.         if(Result == -1)
  54.         {
  55.           Right();
  56.           StrChr(Code, ps);    // 行頭禁則文字をチェック
  57.           if(Result != -1)
  58.             Right();
  59.         }
  60.         Ret();
  61.         if(num > 1)        // 行頭を n-1 字分インデント
  62.         {
  63.           n = num;
  64.           while(n > 1)
  65.           {
  66.             PutChr(0x8140);
  67.             --n;
  68.           }
  69.         }
  70.       }
  71.     }
  72.     InsMode(sIns);
  73.     AIndent(sInd);
  74. }
  75.