#! ruby -Ks
# -*- coding: shift_jis -*-
#
# ruby200, ruby233, ruby241, ruby242 で動作を確認しています。
=begin
== startdoc
;;; @(#) o2h.rb
------------------------------------------------------------
* 概要
ODR 文書が格納されているファイルを html 文書に変換します。変換した html 文書は標準出力に書きだされます。ODR 文書は、拡張子が .odr または .txt のファイルに格納されているか、他のプログラムのソースファイルに埋め込まれているものとします。
:Note
* exe化するには
Ruby 2.4.2 を C:\ruby242 にインストールしている
$ cd C:\ruby242\bin
として、C:\ruby242\bin に移動して
$ gem install ocra
$ gem install win32-shortcut
として、ocra, win32-shortcut をインストールし、
$ pl script
$ ocra --no-autoload o2h.rb
としてください。これで、o2h.exe ができます。
o2h は、outline文書から html 文書を作成するプログラムです。html 文書は、標準出力に作成されます。作成される html 文書の漢字コードは、sjis です。
このファイル o2h.rb の漢字コードは sjis、行末コードは cr, lfにしないといけません。
変換するファイルの漢字コードは、sjis でなくても構いません。行末コードは、crlf でも lf でも構いません。
------------------------------------------------------------
* o2h.rb の著作権と免責
o2h.rb はフリーソフトです。自由にご使用ください。なお,著作
権は作者である 椎葉 充晴 が保有しています。
このソフトウェアを使用したことによって生じたすべての障害・損
害・不具合等に関しては、私と私の関係者および私の所属するいか
なる団体・組織とも、一切の責任を負いません。各自の責任におい
てご使用ください。
------------------------------------------------------------
* o2h.rb を利用するためのスクリプト
● o2hc.bat
つぎのようなバッチファイル o2hc.bat を用意してください。この
バッチファイルでは、ruby スクリプト o2h.rb が C:/script に置
いてあり、Ruby 2.4.2 が C:\Ryby242 にインストールされている
と仮定しています。ユーザの環境に合わせて、%rubyexe% と
%o2hrb% を書き換えてください。バッチファイル o2hc.bat 自身は、
パスの通ったディレクトリに置いてください。
バッチファイル o2hc.bat は引数で与えるファイルを html に変換します。引数で与えるファイルが foo.txt のとき、生成される html ファイルは、foo.txt.html になります。
o2hc.bat は、o2h.rb の中で呼び出されることがあるので、用意す
る必要があります。
@@_o2hc.bat
@begin{code} -----------------------------------------------
@echo off
set rubyexe=@"C:\Ruby242\bin\ruby.exe"
set o2hrb=C:/script/o2h.rb
set fname=%~f1
for %%a in (%fname%) do set targethtml=%%~a.html
%rubyexe% "%o2hrb%" %fname% > %targethtml%
@end{code} -------------------------------------------------
● o2hs.bat
o2hs.bat は、引数で指定したファイルを html に変換して、
標準のブラウザで表示するバッチファイルです。
@@_o2hs.bat
@begin{code} -----------------------------------------------
@echo off
set rubyexe=@"C:\Ruby242\bin\ruby.exe"
set o2hrb=C:/script/o2h.rb
set fname=%~f1
for /f %%a in (%fname%) do set drivepart=%%~da
for /f %%a in (%fname%) do set pathpart=%%~pa
set targethtml=%drivepart%%pathpart%qux.html
%rubyexe% "%o2hrb%" %fname% > %targethtml%
start %targethtml%
@end{code} -------------------------------------------------
● o2h.bat
o2h.bat は、引数で指定したファイルを html に変換して、
標準出力に書き出すバッチファイルです。
@@_o2h.bat
@begin{code} -----------------------------------------------
@echo off
set rubyexe=@"C:\Ruby242\bin\ruby.exe"
set o2hrb=C:/script/o2h.rb
%rubyexe% "%o2hrb%" %1 %2 %3 %4 %5 %6 %7 %8 %9
@end{code} -------------------------------------------------
● kh-o2hs
現在編集中の ODR ファイルまたは埋め込まれた ODR 文書を
html ファイルに変換して表示する xyzzy の lisp 関数です。
これを使えば、エディター xyzzy で編集中のファイルを html に
変換したものを表示できます。
@@_kh-o2hs
@begin{code} -----------------------------------------------
(defun kh-o2hs ()
(interactive)
(call-process
(concat "o2hs.bat " "\""
(map-slash-to-backslash (get-buffer-file-name
(selected-buffer)))
"\"") :show :minimize))
@end{code} -------------------------------------------------
------------------------------------------------------------
* 使用方法
使用方法
o2h --help
o2h [options] filename
o2h filename [options]
引数 filename にファイル名を指定します。
filename には、変換元の outlline 文書を格納しているファイル名を指定します。
:--help
使用方法の説明を出力します。
:--backquote
バッククオート記法を有効にする。default は、バッククオート
は、単なる記号と解釈されます。
:--nonavi
navigation のための出力 (目次へ飛んだりするためのアンカー)
を抑制します。
:--noheader
header 部分を付加せず、navigation のための出力も付加しませ
ん。見出し行も、1.1 あああ のような形に変換しません。
:--nocontents
最後のアウトプットに、目次部分を含めません。
:--contentlevel
引数が必要です。目次に含めるレベル。1 以下は指定できません。
:--nostartdoc
startdoc 文がなくても最初から ODR 文書が格納されているとし
て処理します。
:--notopheadinglist
行頭の * が一つだけのアウトライン見出しのリストを表示する
TOP HEADING LIST を表示しません。
:--opendoc
公開文書を作成するものとして、ODR 文書を処理します。カ
レントディレクトリにないファイルの参照を発見したら、文
書の最後に警告文を表示します。
デフォールトは、true です。ユーザが積極的に false に指
定しない限り、カレントディレクトリにないファイルの参照
は警告されます。
:--proglistignore
vb や code で、proglist オプションが指定されているときに、その
範囲を出力しません。
:--acceptduplicatedheader
標題が重複しても警告文を書きません。
:--browser
ブラウザを指定します。引数が必要です。デフォールトは、
chrome です。chrome でない場合は、ie (internet
exxplorer のこと) を指定したと見做されます。
:--version
version を出力。
------------------------------------------------------------
* プログラムの解説
:::空白行の処理
空白行は、「行の形だけですぐわかる構文のチェック」のところ
で、読み取って処理します。
::$envstack.stkblline
$envstack.stkblline は空白行を何行連続して読み込んだかを記
録できます。
.. 空白行を何行読み込んでいるかは、文書環境が覚えているの
ではなく、$envstack が覚えています。
::グローバル変数$stkline
$stkline は、true または false をとります。その時点で、詰
め込みモードにあって、前に行があって、行末に
がないと
き、$stkline は、true, それ以外のときは、$stkline は false
です。詰め込みモードにないときは、$stkline は false です。
行頭に
を入れるかどうか判定するのに使用します。
:::@margin と @indent, @lindent
1. これは、番号付きリストのサンプルです。左端から番号の前
までの半角空白の個数が @margin。左端から文章部分の左端
までの桁数が @indent です。@margin = 2, @indent = 5 で
す。
ひとつ上の環境(親の環境) の @indent を @lindent
(@indent ではないことに注意。l が indent の前についてい
ます) に記憶します。ここでは、@lindent の値は、0 です。
2. 普通は、@indent > @margin です。
入れ子になっている環境の場合にどうなるか。
ここは、親の環境。@margin = 2, @indent = 5, @lindent =
0 です。
a. ここでは、@margin = 5, @indent = 8, @lindent = 5
です。
親の環境の @indent が 5 なので、@lindent = 5 で
す。@margin は、左端から計算されています。
@indent は、8 で、これも左端から測られています。
OrderList クラスのメソッド open が呼ばれるときの
margin は 5、indent は、8 です。@lindent の値は、
open が呼ばれる直前に設定します。例えば、open を
呼び出す環境がcenv に格納されているとして、
cenv.open が呼ばれる直前に、cenv.lindent =
lenv.indent のようにします。
b. cenv.margin = margin という式があると、ローカル
な変数 margin の値がオブジェクト cenv のメンバ変
数 @margin にセットされます。
このプログラムでは、@margin = ... という式はあま
りなくて、
cenv.margin = ...
のような式で @margin の値が設定されています。
文書環境は、それぞれの文書環境に独特のスタイルの開始行を持ちます。どの文書環境の開始行にも該当しなかった場合は、とりあえず、Blankline, Flushleft または Indented と分類します。この分類を実行するのが analyze 関数で、分類の結果を type に格納します。type には、開始行からそれと分かった文書環境、あるいは、Blankline, Flushleft, Indented が格納されます。
Blankline は、空白文字だけから成る行。Flushleft は、行頭に空白文字が無い行 (厳密に左端から文字を書いてある行)、Indentedは行頭に空白文字がある行です。
とりあえず、Flushleft または Indented に分類された行は、ある文書環境の継続行であるかも知れないし、あらたな文書環境の開始行かも知れません。直前の文書環境の margin や indent を調べて、今、Flushleft または Indented に分類された行が、直前の文書環境の継続行か、あらたな文書環境の開始行かを判定します。
文書環境は、StateEnv クラスのオブジェクトである $envstack に記憶されます。$envstack はつぎのように宣言されています。
$envstack = StateEnv.new
色の名前については、(Net "http://www.colordic.org/") を参照してください。
Ruby では、オブジェクトを生成するには、「クラス.new」とします。new に与えられた引数は、すべてメソッド initialize にそのまま渡されます。
何が「文書環境」かを把握することが重要です。「文書環境」が始まったら、$envstack に記憶しない (push する) といけません。すべてが「文書環境」ではありません。
$envstack.push(...)
としているところに注意してください。
if (type != Flushleft && type != Indented)
...
$envstack.push(cenv)
...
elsif type == Indented
...
elsif type == Flushleft
...
end
というところがあります。cenv.margin = lenv.indent でも $envstack.push(...) することができます。
引用環境 Indentation は「文書環境」か。そうです。
:2013-05-26
o2h.rb が生成するhtmlファイルでは、スタイルの記述をま
とめてhtml内にスタイルシートの形式で記述していましたが、
できるだけこの形の記述によらず、個々の位置でスタイルを
指定するように変更しました。
:2007-01-04
o2h は、$OPT_NOTITLE = true という設定に対応していませ
んでした。対応するようにしました。
:2005-09-08
ruby の veriosn 1.8.2 からは、正規表現で、{ } は、
escape していないと warning がでるようになったようです。
warning が出ないように、{ } を escape しました。
:2005-04-17
$OPT_NOSECTION というオプションを導入しました。普通は、
nil です。これが、true なら、文書標題や文書末のナビゲ
ーションのためのリンクを書きだしません。o2h-region の
ために追加したオプションです。
:Paragraph という文書環境が作られることがあるか
type = という文の右側に Paragraph と書かれるような文は
出て来ません。
cenv = Paragraph.new(0,0) という文で Paragraph 環境が
作られることがあります。これが呼ばれるのは、Flushleft
(厳密に行頭から文が始まっていて、他の文書環境ではない
と判定されたとき) のときです。
:先読みと読み戻しのテクニック
一行だけ先読みしてみるには、
nextline = $io.gets.detab.chomp
とします。読み戻すには、$io.pushback とします。
:エラーメッセージが表示されたら
ERROR: negative argument Error occured at line 18 in
the document file
のようなエラーメッセージは、この書きかえプログラム
o2h.rb が出しています。
:文字列生成のテクニック
ns 個の半角空白の文字列は、" " * ns で生成されます。正
規表現の中では、#{" " * ns} のように、#{ } で囲みます。
memo フォントサイズ コードは、fontsize 1em, line-height 130%
行頭から、,, を書いた行で囲むとき(emacs 関数の置き換え
はせず、固定幅フォントで表示するときは、フォントサイズは、
fontsize 123%、line-height 140% にします。これで、大体、
地の文章と同じサイズのような気がします。
行頭から , で囲むときは、地の文として処理して、最後に
を入れて処理します。
ダッシュ1個を置いた行で挟まれた場合は、panel 環境と同じ
で、フォントサイスは、fontsize 123%、line-height 140%
にします。これで、大体、地の文章と同じサイズのような気が
します。
〓coloring
(Net "http://www.colordic.org/")
(Show "C:/home/shiiba/howm/winnote/win-odr.html" "[win-odr.html]")
------------------------------------------------------------
* 文書環境名とclass 名との対応
@begin{tcTable}{100% 30%} ----------------------------------
= 文書環境名 : クラス名
- パラグラフ : Paragraph
- 裸環境 : Bareline
- 番号付きリスト : Orderedlist
- マーク付きリスト : UnOrderedlist
- 標題付きリスト : Definitionlist
- 引用環境 : Indentation
- マイナス記号標題環境 : MinusMarkHeader
- マーク付き標題環境 : MarkedHeading
- ぶら下げインデント環境 : HangingIndent
- frame 環境 : Frame
- 番号付きリストの別実装 : NumOrderedlist
- 字下げ環境 : Verbatim
@end{tcTable} ----------------------------------------------
このスクリプトファイルでは、ここから、プログラムが書かれていますが、@begin{ignore} ... @end{ignore} で囲んでいるので、o2h.rb で処理して、html ファイルに変換すると、そのプログラム部分は、結果に含まれません。
@begin{ignore} ---------------------------------------------
=end
# ----------------------------------------------------------
# プログラムの構成
# (Label "program_structure" "プログラムの構成")
# (Ref "program_structure" "プログラムの構成")
#
# WORK1
# CLASS DEFINITION
# (Ref "work1start" "WORK1 開始")
# (Ref "work2start" "WORK2 開始")
# (Ref "work3start" "WORK3 開始")
# (Ref "785220" "最終行 enddoc の処理")
#
# WORK2
# ----------------------------------------------------------
# (Ref "program_structure" "プログラムの構成")
# (Ref "work1start" "WORK1 開始")
# (Ref "work2start" "WORK2 開始")
# (Ref "work3start" "WORK3 開始")
# (Ref "work4start" "WORK4 開始")
# (Ref "class_definition" "CLASS DEFINITION")
# (Ref "whileaclass_definition" "CLASS DEFINITION")
# ----------------------------------------------------------
# (Ref "while-a start" "WHILE-A 開始")
#
# WORK3
# ----------------------------------------------------------
# (Ref "work1start" "WORK1 開始")
# (Ref "work2start" "WORK2 開始")
# (Ref "work3start" "WORK3 開始")
# (Ref "work4start" "WORK4 開始")
# (Ref "use-analyzefunc" "analyze 関数で構文解析")
# (Ref "newenv238912" "文書環境をスタックに乗せる")
#
# WORK4
# (Ref "work1start" "WORK1 開始")
# (Ref "work2start" "WORK2 開始")
# (Ref "work3start" "WORK3 開始")
# (Ref "work4start" "WORK4 開始")
# (Ref "output-htmlfile" "Html ファイルの書き出し")
# ----------------------------------------------------------
# WORK1
# (Label "work1start" "WORK1 開始")
# (Ref "program_structure" "プログラムの構成")
# ----------------------------------------------------------
# version
# [2017-08-07] Version 12.01 を作成しました。
# [2017-08-08] Version 12.02 を作成しました。
# [2017-08-09] Version 12.03 を作成しました。
# [2017-08-12] Version 12.04 を作成しました。
# [2017-08-15] Version 12.06 を作成しました。
# [2017-08-15] Version 12.07 を作成しました。
# [2017-08-19] Version 12.08 を作成しました。
# [2017-08-19] Version 12.09 を作成しました。
# [2017-08-21] Version 12.10 を作成しました。
# [2017-08-26] Version 12.11 を作成しました。
# [2017-09-07] Version 12.12 を作成しました。
# [2017-09-09] Version 12.13 を作成しました。
# [2017-09-18] Version 12.14 を作成しました。
# [2017-10-04] Version 12.15 を作成しました。
# [2017-10-08] Version 12.16 を作成しました。
# [2017-11-01] Version 12.17 を作成しました。
# [2017-11-02] Version 12.18 を作成しました。
# [2017-11-02] Version 12.19 を作成しました。
# [2017-11-15] Version 12.20 を作成しました。
# [2017-11-24] Version 12.21 を作成しました。
# [2017-11-26] Version 12.22 を作成しました。
# [2017-12-21] Version 12.23 を作成しました。
# [2017-12-28] Version 12.24 を作成しました。
# [2018-01-06] Version 12.25 を作成しました。
# [2018-01-07] Version 12.26 を作成しました。
# [2018-01-11] Version 12.27 を作成しました。
# [2018-01-12] Version 12.28 を作成しました。
# [2018-01-23] Version 12.29 を作成しました。
# [2018-01-25] Version 12.30 を作成しました。
# [2018-01-29] Version 12.31 を作成しました。
verstring = "$Revision: 12.31$".sub(/\$.*: (.*)\$/, 'version \1')
# @begin{Inserted at 20160805 18:36}------------------------
require 'rubygems'
require 'win32/shortcut'
include Win32
# @end{Inserted at 20160805 18:36}--------------------------
require 'win32ole'
# 2012-10-28
# win32ole は、show 関数を使用するために導入しました。
# show 関数は20行後くらい後で定義しています。
require 'getoptlong.rb'
parser = GetoptLong.new
require 'nkf'
# [2017-08-07]
require 'date'
$wdays = ["日", "月", "火", "水", "木", "金", "土"]
$today = Date.today.to_s
$wday = $wdays[Time.now.wday]
parser.set_options(
['--help', GetoptLong::NO_ARGUMENT],
['--backquote', GetoptLong::NO_ARGUMENT],
['--nonavi', GetoptLong::NO_ARGUMENT],
['-t', '--title', GetoptLong::REQUIRED_ARGUMENT],
['--noheader', GetoptLong::NO_ARGUMENT],
['--nocontents', GetoptLong::NO_ARGUMENT],
['--nostartdoc', GetoptLong::NO_ARGUMENT],
['--notopheadinglist', GetoptLong::NO_ARGUMENT],
['--opendoc', GetoptLong::NO_ARGUMENT],
['--contentlevel', GetoptLong::REQUIRED_ARGUMENT],
['--browser', GetoptLong::REQUIRED_ARGUMENT],
['--proglistignore', GetoptLong::NO_ARGUMENT],
['--acceptduplicatedheader', GetoptLong::NO_ARGUMENT],
['--version', GetoptLong::NO_ARGUMENT])
begin
parser.each_option do |name, arg|
eval \
"$OPT_#{name.sub(/^--?/, '').gsub(/-/, '_').upcase} = '#{arg}'"
end
rescue
exit(1)
end
if $OPT_VERSION
puts "#{File.basename($0)}: #{verstring}"
exit 0
end
# --acceptduplicatedheader を指定すると、重複した見出し
# があっても警告のメッセージを出力しません。
#
# 普通は、html 文書の最後に、重複した見出しがあったっことを指摘
# するメッセージが書き込まれます。
#
# つぎのコードを入れてテストしました。
# --acceptduplicatedheader をつけて起動すると、
# $OPT_ACCEPTDUPLICATEDHEADER が true になります。そうでないと
# false です。
# デフォールトでは、$OPT_ACCEPTDUPLICATEDHEADER は false です。
#
# つまり、デフォールトでは、$OPT_ACCEPTDUPLICATEDHEADER は false
# で、「見出しが同じものは許されない」と考えて、
# 同じ見出しが出てくるとエラーメッセージを書き出します。
#
# if $OPT_ACCEPTDUPLICATEDHEADER
# puts "accept duplicated header"
# exit 0
# else
# puts "no duplicated header"
# exit 0
# end
# ----------------------------------------------------------
# 引数にショートカットが格納されているファイルのフルパスを
# 与えます。ショートカットが指している先のファイル名や
# ディレクトリ名のフルパスを UNIX 形式で返します。
#
# 引数で与えられたファイル名がフルパスでない場合は、
# 引数の前に、"C:/dirlink/" を付加したものが与えられたとし
# ます。
def getpathFromShortcutFile(linkfile)
if File::dirname(linkfile) == "."
linkfile = "C:/dirlink/" + linkfile
end
shortcut = Shortcut.new linkfile
return shortcut.path.gsub(File::ALT_SEPARATOR) {File::SEPARATOR}
end
# ----------------------------------------------------------
# 特殊環境の実行準備。
def prepareSpecialenv(nb)
# $fp.print "3992.8066"
if nb == $envstack.lastenv.indent
if $stkline
$stkline = false
$fp.print "
\n"
else
if $justafteroutlineheading
$envstack.endenv(nb)
$justafteroutlineheading = false
$envstack.stkblline = 0
else
while $envstack.stkblline > 0
$fp.print "
\n"
$envstack.stkblline -= 1
end
end
end
else
$envstack.endenv(nb)
end
end
# 2012-10-28 -----------------------------------------------
# メッセージを表示する窓をポップアップします。
def show(msg, title)
wsh = WIN32OLE.new('WScript.Shell')
#
# intButton = object.Popup(
# strText,[nSecondsToWait],[strTitle],[nType])
#
# ●引数
# object
# WshShell オブジェクトです。
# strText
# ポップアップ ウィンドウに表示するテキストです。
# 改行するには、文字列の中に \n を入れます。
# nSecondsToWait
# 省略可能です。ポップアップ ウィンドウを閉じるまで
# 待機する秒数を指定します。
# strTitle
# 省略可能です。ポップアップ ウィンドウのタイトルに
# 表示するテキストです。
# nType
# 省略可能です。ポップアップ メッセージ ボックスに
# 表示するボタンとアイコンの種類を示す数値です。選
# 択する種類によってメッセージ ボックスの使い方が決
# まります。
# ●戻り値
# IntButton
# メッセージ ボックス終了時にクリックするボタンの番
# 号を示す整数値です。これは Popup メソッドの戻り値
# です。
#
wsh.Popup(msg, 0, title, 0 + 64 + 0x40000)
end
# ----------------------------------------------------------
#
# (Net "http://www.colordic.org/" "WEB色見本")
$message = ""
$default_fontcolor = "Black"
$fontcolor = ""
# $default_vbcode_color = "indigo"
$default_vbcode_color = "mediumblue"
# $default_vbcode_color = "indigo"
# $default_vbcode_color = "#000099"
# $default_vbcode_color = "black"
# $default_vbcode_color = "navy"
# $default_vbcode_color = "midnightblue"
# $default_vbcode_color = "mediumblue"
# $default_vbcode_color = "darkblue"
# $default_vbcode_color = "crimson"
$default_panel_backcolor = "floralwhite"
# panel
$equalsign_is_title = true
$default_dashline_backcolor = "whitesmoke"
# code, Dashline Display
# - --------------------------------------------------------
# Onedash Display
# - --------------------------------------------------------
# --- ------------------------------------------------------
# Threedashes Display
# --- ------------------------------------------------------
$default_frame_backcolor = "null"
# Frame
$default_bgcolor = "null"
# 薄い背景色の候補
#
# "aliceblue"
#
# $ecolor = "Red"
# $bgcolor = "f0f0a0"
# $bgcolor = "ffffff" # white
$bgcolor = "" # white, beige, gainsboro (#dcdcdc)
$twbgcolor = ""
# 枠で囲むような文書環境は、背景色を指定します。
#
# $bgcolor が "" でない場合は、わざわざ $bgcolor が指定
# されたと考えて、bgcolor = $bgcolor にします。そうでな
# ければ、
# 枠がある場合は、 bgcolor = $default_panel_backcolor にします。
# 枠がなければ、bgcolor = $default_bgcolor にします。
# $underscoreContlinep = true なら、行末に _ があってすぐ改行
# されていたらつぎの行に継続します。
# 最初は、$underscoreContlinep = true に設定します。
# 文書の途中で、$underscoreContlinep = false に変更することも
# できます。
$underscoreContlinep = true
#
"
# end
$fp.print "#{string}"
$stkline = stklinecheck(string)
end
# @end{common} -----------------------------------------
#
end
end
class String
def detab
#
に変換する。
if /\[br\]\a*$/ =~ string
while /^(.*)\[br\](\a*)$/ =~ string
string = $1 + "\a" + $2
end
string.gsub!(/\a/, "
")
end
string
end
def analyze
# analyze は、class String のメンバ関数として定義
# されていることに注意してください。
#
# return type, margin, indent, mark, string, cenv
#
# analyze は、
#
# type, margin, indent, mark, string, cenv
#
# を返します。indent はまだ解析できなくて、0 が入
# ったまま返すこともあります。
#
# type は文書環境
# margin は文書環境の始まりの、左端からの位置
# indent は字下げ部分の左端からの位置
# mark はマーク付きリストなどのマーク
# string は標題つき環境などの標題
# cenv 読み込んだときの現在の文書環境のオブジェクト
margin = 0; indent = 0; mark = ""; string = ""; cenv = nil
if /^[ ]*$/ =~ self
# 空行
return Blankline, margin, indent, mark, string, Blankline.new
elsif (/^(([ ]*)(\*|\*\*|\+\+) )([^ \n]+.*)$/ =~ self &&
%r!^(([ ]*)([^ ]*|[^ ].*[^ ])[ ]* :: )([^ \n]+.*)$! !~ self)
#
\n" $io.pushback end def dotlist (blank) # この blank は厳密に行頭から測った行頭の空白文字列。 $fp.print "\n"; nline = $. sline = blank + ".~" fontcolor = $fontcolor if fontcolor.bytesize ==0 fontcolor = $default_fontcolor end $fp.print "\n"; line = $io.gets.detab while /^#{blank}\.\.$/ !~ line line.sub!(/^#{blank}/, "") $fp.print line.squoteline, "\n"; $fp.print string.squoteline, "\n" line = $io.gets.detab while /^#{blank}--- / =~ line line.sub!(/^#{blank}/, "") line.sub!(/--- /, "") $fp.print "", line.squoteline, "" line = $io.gets if !line || /^\*{1,5} / =~ line || /^(==|\*) (enddoc|enddic)/ =~ line FileendErrorMessage(nline, sline, __LINE__.to_s) exit 1 end line.detab end $fp.print "
\n"; line = $io.gets.detab while /^#{blank}\.\.\.\.?[ \t]*$/ !~ line line.sub!(/^#{blank}/, "") $fp.print line.squoteline $io.gets if !line || /^\*/ =~ line || /^(==|\*) (enddoc|enddic)/ =~ line STDERR.print "At line " + __LINE__.to_s + " of o2h.rb" + ": The region which started at line " + "#{nline} met with the file end at line #{$.}.", "\n" print "At line " + __LINE__.to_s + " of o2h.rb" + ": The region which started at line " + "#{nline}\n
met with the file end at line #{$.}.", "\n" exit 1 end line = line.detab end $fp.print "
\n"; nb = blank.bytesize nw = nb nextline = $io.gets $io.pushback if /^([ ]*)[^ ].*$/ =~ nextline nk = $1.bytesize nw = nk if nk < nb end line = $io.gets.detab while /^#{blank}\.\.\.\.?[ \t]*$/ !~ line line.sub!(/^#{" " * nw}/, "") $fp.print line.squoteline line = $io.gets if !line || /^*/ =~ line || /^(==|\*) (enddoc|enddic)/ =~ line STDERR.print "At line " + __LINE__.to_s + " of o2h.rb" + ": The region which started at line " + "#{nline} met with the file end at line #{$.}.", "\n" print "At line " + __LINE__.to_s + " of o2h.rb" + ": The region which started at line " + "#{nline}\n
met with the file end at line #{$.}.", "\n" exit 1 end line = line.detab end $fp.print "
\n"; nline = $.; sline = line line = $io.gets.detab # $fp.print "debug: #{line}\n" while /^#{" " * nb}\.\.\.\.\.?[ ]*$/ !~ line line.sub!(/^#{" " * nb}/, "") $fp.print line.svquoteline line = $io.gets if !line || /^\*/ =~ line || /^(==|\*) (enddoc|enddic)/ =~ line STDERR.print "At line " + __LINE__.to_s + " of o2h.rb" + ": The region which started at line #{nline}:\n#{sline}met with the file end at line #{$.}.", "\n" print "At line " + __LINE__.to_s + " of o2h.rb" + ": The region which started at line #{nline}:\n#{sline}"; $fp.print "
met with the file end at line #{$.}.", "\n" exit 1 end line.detab end $fp.print "
\n"; # [2016-06-22] nb = blank.bytesize nw = nb nextline = $io.gets $io.pushback if /^([ ]*)[^ ].*$/ =~ nextline nk = $1.bytesize nw = nk if nk < nb end line = $io.gets.detab while /^#{blank}[-]{20,}[.]?[ \t]*$/ !~ line if /^=\*/ =~ line # 行頭に * があるのを回避するために、行頭に = を置 # いたので元に戻している。 line.sub!(/^=/, "") end line.sub!(/^#{" " * nw}/, "") # line.sub!(/^#{blank}/, "") $fp.print line.squoteline line = $io.gets if !line || /^\*/ =~ line || /^(==|\*) (enddoc|enddic)/ =~ line STDERR.print "At line " + __LINE__.to_s + " of o2h.rb" + ": The region which started at line " + "#{nline} met with the file end at line #{$.}.", "\n" print "At line " + __LINE__.to_s + " of o2h.rb" + ": The region which started at line " + "#{nline} met with the file end at line #{$.}.", "\n" exit 1 end line = line.detab end # @begin{Cmnted out at 20170503 00:40}-------------------- # $fp.print "\n\n\n"; # @end{Cmnted out at 20170503 00:40}---------------------- # # @begin{Inserted at 20170503 00:40}---------------------- $fp.print "\n\n\n"; # @end{Inserted at 20170503 00:40}------------------------ $endparagraph = true $stkline = false $envstack.stkblline = 0 $fontcolor = "" end def OnedashDisplay (blank) #
\n"; line = $io.gets if !line || /^\*/ =~ line || /^(==|\*) (enddoc|enddic)/ =~ line STDERR.print "At line " + __LINE__.to_s + " of o2h.rb" + ": The region which started at line " + "#{nline} met with the file end at line #{$.}.", "\n" print "At line " + __LINE__.to_s + " of o2h.rb" + ": The region which started at line " + "#{nline} met with the file end at line #{$.}.", "\n" exit 1 end line = line.detab while /^#{blank}-$/ !~ line && /^#{blank}-\.$/ !~ line if /^=\*/ =~ line # 行頭に * があるのを回避するために、行頭に = を置い # たので元に戻している。 line.sub!(/^=/, "") end line.sub!(/^#{blank}/, "") $fp.print line.squoteline line = $io.gets if !line || /^\*/ =~ line || /^(==|\*) (enddoc|enddic)/ =~ line STDERR.print "At line " + __LINE__.to_s + " of o2h.rb" + ": The region which started at line " + "#{nline} met with the file end at line #{$.}.", "\n" print "At line " + __LINE__.to_s + " of o2h.rb" + ": The region which started at line " + "#{nline} met with the file end at line #{$.}.", "\n" exit 1 end line = line.detab end $fp.print "\n\n\n"; $endparagraph = true $stkline = false $fontcolor = "" end def ThreedashesDisplayFoo (blank) #
\n"; line = $io.gets.detab while /^#{blank}---$/ !~ line && /^#{blank}---\.$/ !~ line && /^#{blank}\.---$/ !~ if /^=\*/ =~ line # 行頭に * があるのを回避するために、行頭に = を置い # たので元に戻している。 line.sub!(/^=/, "") end line.sub!(/^#{blank}/, "") # show("786251:", "foo") $fp.print line.squoteline # show("786252:", "foo") line = $io.gets if !line || /^\*/ =~ line || /^(==|\*) (enddoc|enddic)/ =~ line STDERR.print "At line " + __LINE__.to_s + " of o2h.rb" + ": The region which started at line " + "#{nline} met with the file end at line #{$.}.", "\n" print "At line " + __LINE__.to_s + " of o2h.rb" + ": The region which started at line " + "#{nline} met with the file end at line #{$.}.", "\n" exit 1 end line = line.detab end $fp.print "\n\n\n"; $endparagraph = true $stkline = false $fontcolor = "" end class Orderedlist < Baseenv #
\n" else # @nodiv が false のときに、
\n"
end
$fp.print string.chomp
nline = $.;
# Untill a white line is encountered, lines are printed.
# $fp.print $envstack.lastenv.class.to_s + "
"
$stkline = true
line = $io.gets.detab
while /^#{" " * indent}/ =~ line
line.sub!(/^[ ]+/, "")
if /^$/ =~ line
# 行頭から indent 個以上の空白があった行は空行として
# 読み込みを中止します。
break
elsif /^\.([ ]+)([^ ].*)$/ =~ line
nbsp = $1.bytesize - 1
line = emacsfunc($2)
line.sub!(/\\\\$/, "
")
line = line.gsubLineendBr
if $stkline
$fp.print "
"
$stkline = false
end
$fp.print " " * nbsp, line, "
\n"
$stkline = false
elsif /^\.□([ ]+)([^ ].*)$/ =~ line
nbsp = $1.bytesize - 1
line = emacsfunc($2)
line.sub!(/\\\\$/, "
")
line = line.gsubLineendBr
if $stkline
$fp.print "
"
$stkline = false
end
$fp.print "□", " " * nbsp, line, "
\n"
$stkline = false
elsif /^\.\.([ ]+)([^ ].*)$/ =~ line
nbsp = $1.bytesize - 1
line = emacsfunc($2)
line.sub!(/\\\\$/, "
")
line = line.gsubLineendBr
if $stkline
$fp.print "
"
$stkline = false
end
$fp.print " " * nbsp, line
$stkline = stklinecheck(line)
elsif /^\.\.\.([ ]+)([^ ].*)$/ =~ line
nbsp = $1.bytesize - 1
line = $2.svquoteline
line.sub!(/\\\\$/, "
")
line = line.gsubLineendBr
$stkline = false
$fp.print " " * nbsp, line
$stkline = stklinecheck(line)
elsif /^([ ]*)@begin{html}[- ]*$/ =~ line
HtmlSpecial(line)
else
line = emacsfunc(line)
line.sub!(/\\\\$/, "
")
line = line.gsubLineendBr
# if line =~ /^[ -~。-゚]/; line = " " + line; end
# [ -~] は半角文字、[。-゚] は半角カタカナにマッチ。
$fp.print line.chomp
$stkline = stklinecheck(line)
end
line = $io.gets
if !line || /^\*{1,5} / =~ line || /^(==|\*) (enddoc|enddic)/ =~ line
rline = __LINE__.to_s
FileendErrorMessage(nline, sline, rline)
exit 1
end
line.detab
end
$fp.print "
\n" # @end{Cmnted out at 20160620 10:22}------------------ # # @begin{Inserted at 20160620 10:22}------------------ if margin == 0 $fp.print "
\n" else $fp.print "
\n" end # @end{Inserted at 20160620 10:22}-------------------- else # @nodiv が false のときに、
\n" $fp.print "
\n"
end
# ここで、Hangingindent の一行目の文字列を書き出します。
# show(string, "299373")
string.sub!(/^## /, "# ")
string.sub!(/^&&/, "&")
$fp.print string.chomp
nline = $.;
# Untill a white line is encountered, lines are printed.
$stkline = true
line = $io.gets.detab
# [2016-06-21]
#
# ぶら下げインデントの見出し部分の字下げが0の場合、見出しの
# 一行目の後で改行します。
#
# 例。
#
# □ 見出し1
# 見出しの続き。
#
# ぶら下げインデントの本文
#
# この場合、見出し1 の後で改行します。
#
# @begin{Cmnted out at 20160621 08:58}------------------
# if /^#{" " * indent}/ =~ line && /^[ ]*$/ !~ line
# if margin == indent
# $fp.print "
\n"
# end
# end
# @end{Cmnted out at 20160621 08:58}--------------------
#
#
while /^#{" " * indent}/ =~ line
line.sub!(/^[ ]+/, "")
if /^$/ =~ line
# 行頭から indent 個以上の空白があった行は空行として
# 読み込みを中止します。
break
elsif /^\.([ ]+)([^ ].*)$/ =~ line
nbsp = $1.bytesize - 1
line = emacsfunc($2)
line.sub!(/\\\\$/, "
")
line = line.gsubLineendBr
if $stkline
$fp.print "
"
$stkline = false
end
$fp.print " " * nbsp, line, "
\n"
$stkline = false
elsif /^\.□([ ]+)([^ ].*)$/ =~ line
nbsp = $1.bytesize - 1
line = emacsfunc($2)
line.sub!(/\\\\$/, "
")
line = line.gsubLineendBr
if $stkline
$fp.print "
"
$stkline = false
end
$fp.print "□", " " * nbsp, line, "
\n"
$stkline = false
elsif /^\.\.([ ]+)([^ ].*)$/ =~ line
nbsp = $1.bytesize - 1
line = emacsfunc($2)
line.sub!(/\\\\$/, "
")
line = line.gsubLineendBr
if $stkline
$fp.print "
"
$stkline = false
end
$fp.print " " * nbsp, line
$stkline = stklinecheck(line)
elsif /^\.\.\.([ ]+)([^ ].*)$/ =~ line
nbsp = $1.bytesize - 1
line = $2.svquoteline
line.sub!(/\\\\$/, "
")
line = line.gsubLineendBr
$stkline = false
$fp.print " " * nbsp, line
$stkline = stklinecheck(line)
elsif /^([ ]*)@begin{html}[- ]*$/ =~ line
HtmlSpecial(line)
else
line = emacsfunc(line)
line.sub!(/\\\\$/, "
")
line = line.gsubLineendBr
# if line =~ /^[ -~。-゚]/; line = " " + line; end
# [ -~] は半角文字、[。-゚] は半角カタカナにマッチ。
$fp.print line.chomp
$stkline = stklinecheck(line)
end
line = $io.gets
if !line || /^\*{1,5} / =~ line || /^(==|\*) (enddoc|enddic)/ =~ line
rline = __LINE__.to_s
FileendErrorMessage(nline, sline, rline)
exit 1
end
line.detab
end
$fp.print "
\n"; $fp.print emacsfuncNoquote($endnote) $fp.print "
\n" $endnote = "" $fp.print "\n"; $fp.print emacsfuncNoquote($endnote) $fp.print "
\n" $endnote = "" $fp.print "\n"; $fp.print emacsfuncNoquote($endnote) $fp.print "
\n" $endnote = "" end end end $endparagraph = true end def blankline(stkblline) # 検討が必要です。Frame 環境の一番上で処理すべき空白行を担当 # します。 # @begin{Cmnted out at 20160318 10:36}------------------ # if stkblline == 0 # $fp.print "\n" # else # if stkblline > 1 # $fp.print "#{mark} | \n" + ""
$envstack.stkblline = 0
if string.bytesize > 0
if /^\.~$/ =~ string
dotlist(blank)
elsif /^\.\.\.\.\.$/ =~ string
fivedotlist(blank)
elsif /^[-]{20,}~?[ \t]*$/ =~ string
DashlineDisplay(blank)
elsif /^\.\.[ \t]*$/ =~ string
string = " "
string = emacsfunc(string)
$fp.print "#{string}\n"
elsif /^\.\. ([^ ].*)$/ =~ string
string = $1
string = emacsfunc(string)
$fp.print "#{string}\n"
elsif /^\.([ ]+)([^ ].*)$/ =~ string
nbsp = $1.bytesize - 1;
$fp.print " " * nbsp, emacsenspfunc($2), " \n" $stkline = false elsif /^\,([ ]+)([^ ].*)$/ =~ string nbsp = $1.bytesize - 1; $fp.print " " * nbsp, $2.squoteline, " \n" $stkline = false else string.sub!(/~([^ ].*[^ ])/, '(*\1*)') string = emacsfunc(string) $fp.print "#{string}" $stkline = stklinecheck(string) end else $stkline = false end end def newitem(margin, indent, mark, string) if $envstack.stkblline > 0 $fp.print " \n"; $envstack.stkblline = 0 end blank = " " * indent $fp.print " |
#{mark} | \n" + ""
if /^\.~$/ =~ string
dotlist(blank)
elsif /^\.\.\.\.\.$/ =~ string
fivedotlist(blank)
elsif /^[-]{20,}~?[ \t]*$/ =~ string
DashlineDisplay(blank)
elsif /^\.\.[ \t]*$/ =~ string
string = " "
string = emacsfunc(string)
$fp.print "#{string}\n"
elsif /^\.\. ([^ ].*)$/ =~ string
string = $1
string = emacsfunc(string)
$fp.print "#{string}\n"
elsif /^\.([ ]+)([^ ].*)$/ =~ string
nbsp = $1.bytesize - 1;
$fp.print " " * nbsp, emacsenspfunc($2), " \n" $stkline = false elsif /^\,([ ]+)([^ ].*)$/ =~ string nbsp = $1.bytesize - 1; $fp.print " " * nbsp, $2.squoteline, " \n" $stkline = false else string.sub!(/~([^ ].*[^ ])/, '(*\1*)') string = emacsfunc(string) string.sub!(/\\\\$/, " ") string = string.gsubLineendBr $fp.print "#{string}" $stkline = stklinecheck(string) end end def close $fp.print " |
\n"
$fp.print "
\n"
return
elsif /^\.\.([ ]+)(.*)$/ =~ string
string = " " * ($1.bytesize - 1) + emacsenspfunc($2)
# $inparagraph = true
# $fp.print "
#{string}"
$fp.print "#{string}"
$stkline = true
return
elsif /^\.([ ]+)([^ ].*)$/ =~ string
# . abc の形
if $stkline
$fp.print "
\n"; $stkline = false
end
string = " " * ($1.bytesize - 1) + emacsenspfunc($2)
$stkline = false
$envstack.stkblline = 0
# $inparagraph = true
# $fp.print "
#{string}
\n"
$fp.print "#{string}
\n"
return
elsif /^\.□([ ]+)([^ ].*)$/ =~ string
if $stkline
$fp.print "
\n"; $stkline = false
end
string = " " * ($1.bytesize - 1) + emacsenspfunc($2)
$stkline = false
$envstack.stkblline = 0
# $inparagraph = true
# $fp.print "
□#{string}
"
$fp.print "□#{string}
"
return
elsif /^,([ ]+)([^ ].*)$/ =~ string
# @begin{Cmnted out at 20160417 15:21}----------------
# $inparagraph = true
# $fp.print "
" # @end{Cmnted out at 20160417 15:21}------------------ OnecommaVerbatim(string) return elsif /^,,([ ]+)([^ ].*)$/ =~ string # ここには来ないのではないか。 # @begin{Cmnted out at 20160417 15:21}---------------- # $inparagraph = true # $fp.print "
"
# @end{Cmnted out at 20160417 15:21}------------------
TwocommasVerbatim(string)
return
elsif /^\.\.\.([ ]+)([^ ].*)$/ =~ string
# ここには来ないのではないか。
ThreedotsVquote(string)
return
end
$endparagraph = false
# $fp.print "357438: " + string + "::"
string = emacsfunc(string)
# $fp.print "357439: " + string + "::"
string.sub!(/^\\\.\./, "..")
string.sub!(/\\\\$/, "
")
string = string.gsubLineendBr
# $fp.print "357440: " + string + "::"
# [2016-04-17]
# @begin{Cmnted out at 20160417 15:22}------------------
# $fp.print "
" # $inparagraph = true # @end{Cmnted out at 20160417 15:22}-------------------- $fp.print "#{string}" $stkline = stklinecheck(string) $envstack.stkblline = 0 end def contline(margin, indent, mark, string) if /^[ ]*[━]{10,}$/ =~ string $fp.print "
" + $1 + "
"
line.sub!(/\a\(Code[ ]+(.*?)[ ]*\/Code\)/,
code + "\a")
elsif tag == "h"
while /\a\(h[ ]+(.*?)[ ]*\/h\)/ !~ line
if /\(h$/ =~ line; line = line + " "; end
wline = $io.gets
if !wline || /^(==|\*) (enddoc|enddic)/ =~ wline
rline = __LINE__.to_s
FileendErrorMessageSearching(nline, sline, rline, "/h)")
exit 1
end
if /^[ ]+(.*)$/ =~ wline
wline = $1
end
line = line + wline.chomp
end
if /\a\(h[ ]+(.*?)[ ]*\/h\)/ =~ line
code = $1
line.sub!(/\a(.*?)\(h[ ]+(.*?)[ ]*\/h\)/,
code + "\a")
else
line.sub!(/\a\(h/, "(#tag}" + "\a")
end
elsif tag == "Ruby"
# " + code + "
" + "\a")
# @end{Inserted at 20160717 11:42}--------------------
elsif /\a\((Net|FileNet|Eval|File|Folder|Html|See|W3mn|Xv|fiber|Color|Ref|N|Note|Head|Hd|Anchor|H|Show|Prev|Next)[ ]*$/ =~ line #"
# (Net のような形が始まったのに、行が終わってしま
# った。つぎの行を読み取って、line に連結します。
#
# 読み取るのは一行だけ。問題が解決するかの確認はなし。
# 問題の解決はつぎの while ループの処理に委ねられます。
wline = $io.gets
tag = $1
if !wline || /^(==|\*) (enddoc|enddic)/ =~ wline
rline = __LINE__.to_s
FileendErrorMessageSearching(nline, sline, rline,
"Closing part of " + tag)
exit 1
end
if /^[ ]+(.*)$/ =~ wline
wline = $1
end
line = line + " " + (wline.chomp)
elsif /\a\((Net|FileNet|Eval|See|Folder|Href|W3mn|Xv|fiber|Color|Ref|N|Note|Head|Hd|Anchor|H|Show|Prev|Next)\b[ ]+[^ "]/ =~ line #"
# (Net a.. のように、引用符号が来るべきところに別の記号
# が書いてあった
line.sub!(
/\a\((Net|FileNet|Eval|Folder|Href|See|W3mn|Xv|fiber|Color|Ref|N|Note|Head|Hd|Anchor|H|Show)\b[ ]+/,
'(' + tag + ' ' +
"?(not a double quote)==>\a")
elsif /\a(.*?)\((Net|FileNet|Eval|File|Folder|Href|See|W3mn|Xv|fiber|Color|Ref|N|Note|Head|Hd|Anchor|H|Show|Prev|Next)[ ]+\"[^"]*(|\"[ ]*)$/ =~ line #"
# (Net "... のような形が始まったのに、行が終わってしま
# った。あるいは、(Net "..." で終わってしまった。つぎ
# の行を読み取って、line に連結します。
wline = $io.gets
if !wline || /^(==|\*) (enddoc|enddic)/ =~ wline
rline = __LINE__.to_s
FileendErrorMessageSearching(nline, sline, rline,
"Closing part of (" + tag)
exit 1
end
if /^[ ]+(.*)$/ =~ wline
wline = $1
end
line = line + wline.chomp
elsif
/\a\((Net|FileNet|Eval|File|Folder|Href|See|W3mn|Xv|fiber|Color|Ref|N|Note|Head|Hd|Anchor|H|Show|Prev|Next)[ ]+\"([^"]*)\"\)/ =~ line #"
# (Net "...") のパターンがあった。
#
# the pattern as (File "foo.txt")
# \n"; $stkline = false elsif /^,,,~$/ =~ line # 行頭からカンマを3個置いてすぐ改行した行で複数行を囲む。 # Emacs 関数を置き換えをせず、左詰めする if $stkline $fp.print "\n"; line = $io.gets.detab.chomp line.sub!(/^#{" " * nb}/, "") while /^[ ]*,,$/ !~ line && /^[ ]*,,\.$/ !~ line if /^([ ]*)[^ ]/ =~ line nbsp = $1.bytesize else nbsp = 0 end line.sub!(/^#{" " * nbsp}/, "") $fp.print " " * nbsp, quoteline(line) + "\n" line = $io.gets.detab.chomp line.sub!(/^#{" " * nb}/, "") end $fp.print "
\n"; line = $io.gets.detab.chomp line.sub!(/^#{" " * nb}/, "") while /^[ ]*,,,$/ !~ line && /^[ ]*,,,\.$/ !~ line && /^[ ]*\.,,,$/ !~ line if /^([ ]*)[^ ]/ =~ line nbsp = $1.bytesize else nbsp = 0 end line.sub!(/^#{" " * nbsp}/, "") $fp.print " " * nbsp, quoteline(line) + "\n" line = $io.gets.detab.chomp line.sub!(/^#{" " * nb}/, "") end $fp.print "\n"; $stkline = false elsif /^,,,([ ]+)([^ ].*)$/ =~ line # 行頭からカンマを3個置いて、半角空白文字を1個以上置き、 # 非空白文字で始まる文字列を置く。 # Emacs 関数を置き換えをせず、左詰めする # 行頭が半角文字なら半角空白が追加されている nbsp = $1.bytesize - 1 string = $2 if $stkline $fp.print "
"; $stkline = false end $fp.print line + "\n" line = $io.gets.detab.chomp line.sub!(/^#{" " * nb}/, "") while /^<\/pre>/ !~ line $fp.print line + "\n" line = $io.gets.detab.chomp line.sub!(/^#{" " * nb}/, "") end $fp.print line + "\n" $stkline = false # [2016-05-24] elsif /^([ ]*)@begin{subTable}{([^{}]*)}[- ]*$/ =~ line # $fp.print "768390:" if $stkline $fp.print "
"; $stkline = false end nc = nb spec = $2 subTable(nc, spec) $stkline = false elsif /^[ ]*;{3,}[ ]*@\(%h?\)\s+(.*)$/ =~ line code = $1 eval code elsif /^[ ]*\.[ ]*$/ =~ line # 行頭に . を書いて、半角空白文字を1個以上書いて改行した # 場合ここで処理します。それは結局空白になる。 if $stkline $fp.print "
"; $stkline = false end $fp.print "
"; $stkline = false elsif /^[ ]*\.[ ]([^ ].*)$/ =~ line if $stkline $fp.print "
"; $stkline = false end string = emacsfuncNoquote($1) $fp.print string, "
\n" $stkline = false elsif /^[ ]*\.\.[ ]*$/ =~ line if $stkline $fp.print "
"; $stkline = false end $fp.print "
"; $stkline = false elsif /^[ ]*\.\.[ ]([^ ].*)$/ =~ line string = emacsfuncNoquote($1) # $fp.print "930103: $stkline is " + $stkline.to_s if $stkline $fp.print "
"; $stkline = false end $fp.print string $stkline = stklinecheck(string) elsif /^[ ]*$/ =~ line if $stkline; $fp.print "
\n"; end $fp.print "
\n" $stkline = false else # 先頭文字が半角文字だったら、先頭に1個の # 半角空白が付加します。 # if $stkline && line =~ /^[ -~]/ line = " " + line end string = emacsfuncNoquote(line) string = string.gsubLineendBr $fp.print string $stkline = stklinecheck(string) # $fp.print "$stkline is " + $stkline.to_s end end # [2014-07-24] 少し変更しました。 # # C:/home/shiiba/foo.bar.txt に対して、 # @BASENAME@ = "foo.bar.txt" # @BASEPART@ = "foo.bar" # @DIRECTORY@ = "C:/home/shiiba" # def repthisfile(line) line = "\a" + line while /\a(.*?)@BASENAME@/ =~ line pre = $1 if /=$/ =~ "#{pre}" line.sub!(/\a(.*?)=@BASENAME@/){ "#$1@BASENAME@" + "\a" } elsif /\a(.*?)@BASENAME@/ =~ line pre = $1 line.sub!(/\a.*?@BASENAME@/, "#{pre}#{$basename}" + "\a") end end line.sub!(/\a/, "") line = "\a" + line while /\a(.*?)@BASEPART@/ =~ line pre = $1 if /=$/ =~ "#{pre}" line.sub!(/\a(.*?)=@BASEPART@/){ "#$1@BASEPART@" + "\a" } elsif /\a(.*?)@BASEPART@/ =~ line pre = $1 line.sub!(/\a.*?@BASEPART@/, "#{pre}#{$basepart}" + "\a") end end line.sub!(/\a/, "") line = "\a" + line while /\a(.*?)@DIRECTORY@/ =~ line pre = $1 if /=$/ =~ "#{pre}" line.sub!(/\a(.*?)=@DIRECTORY@/){ "#$1@DIRECTORY@" + "\a" } elsif /\a(.*?)@DIRECTORY@/ =~ line pre = $1 line.sub!(/\a.*?@DIRECTORY@/, "#{pre}#{$directory}" + "\a") end end line.sub!(/\a/, "") return line end def dotleftverbatim (line) /^([ ]{0,39})\.[ \t]*$/ =~ line nb = $1.bytesize #; 行頭の空白文字数 $envstack.endenv(nb) bl = " " * $envstack.lastenv.indent if $envstack.stkblline > 0; $fp.print "\n"; end $envstack.stkblline = 0 nline = $. $fp.print "" if $bgcolor.bytesize > 0 bgcolor = $bgcolor else bgcolor = $default_bgcolor end fontcolor = $fontcolor if fontcolor.bytesize == 0 fontcolor = $default_fontcolor end $fp.print "\n\n\n" $endparagraph = true $fontcolor = "" end def dotverbatim (line) /^([ ]{0,39})\.[ \t]*$/ =~ line nb = $1.bytesize #; 行頭の空白文字数 $envstack.endenv(nb) bl = " " * $envstack.lastenv.indent if $envstack.stkblline > 0; $fp.print "\n"; end $envstack.stkblline = 0 nline = $. $fp.print "\n"; line = $io.gets.detab while /^#{" " * nb}\.$/ !~ line # line.sub!(/^#{bl}/, "") line.sub!(/^#{" " * nb}/, "") line = repthisfile(line) if $OPT_BACKQUOTE while (/`([^`]*)`/ =~ line) #` com= $1; str = `#{com}`.chomp; line.sub!(/`[^`]*`/, "#{str}") #` end end $fp.print emacsfunc(line) line = $io.gets if !line || /^\*/ =~ line || /^(==|\*) (enddoc|enddic)/ =~ line STDERR.print "At line " + __LINE__.to_s + " of o2h.rb" + ": The region which started at line " + "#{nline} met with the file end at line #{$.}.", "\n" print "At line " + __LINE__.to_s + " of o2h.rb" + ": The region which started at line " + "#{nline} met with the file end at line #{$.}.", "\n" exit 1 end line = line.detab end $fp.print ""; $fp.print "" # bgcolor = "whitesmoke" # bgcolor = "white" fontcolor = $fontcolor if fontcolor.bytesize == 0 fontcolor = $default_fontcolor end $fp.print "\n\n\n" $endparagraph = true $fontcolor = "" end def DotFlushleft (line) #\n"; line = $io.gets.detab while /^#{" " * nb}\.$/ !~ line # line.sub!(/^#{bl}/, "") line.sub!(/^#{" " * nb}/, "") line = repthisfile(line) if $OPT_BACKQUOTE while (/`([^`]*)`/ =~ line) #` com= $1; str = `#{com}`.chomp; line.sub!(/`[^`]*`/, "#{str}") #` end end $fp.print emacsfunc(line) line = $io.gets if !line || /^\*/ =~ line || /^(==|\*) (enddoc|enddic)/ =~ line STDERR.print "At line " + __LINE__.to_s + " of o2h.rb" + ": The region which started at line " + "#{nline} met with the file end at line #{$.}.", "\n" print "At line " + __LINE__.to_s + " of o2h.rb" + ": The region which started at line " + "#{nline} met with the file end at line #{$.}.", "\n" exit 1 end line = line.detab end $fp.print ""; $fp.print "# .~ # こんな風に、ピリオッドだけの行で始まり # ピリオッド2個だけが書かれた行で終わる # 領域の整形。 半角空白も # 整形後で保存。 # .. # # .~ /cyan/ # こんな風に、ピリオッドだけの行で始まり # ピリオッド2個だけが書かれた行で終わる # 領域の整形。 半角空白も # 整形後で保存。 # .. # emacsenspfunc の処理をこの中でしていることに注意してください。 # # ピリオドの前の半角空白の個数が nb に収録されます。 # # (Ref "checkonlyform DotFlushleft" "") # のところで呼ばれています。 # # 後で出てくる $fp.print " \n" # の文によって書き出されることになります。ここでフォントの # 大きさについては何も指定しないので、普通の地の文と同じサ # イズで書き出されます。少し大きいように思うのは半角空白の # 処理の違いによります。パラグラフとして処理されるときの方 # が半角空白が狭いようです。 # # spec = nil if /^([ ]{0,39})\.~[ \t]*$/ =~ line nb = $1.bytesize #; 行頭の空白文字数 bgcolor = $bgcolor elsif /^([ ]{0,39})\.~ \/(.*)\/$/ =~ line # 色指定があるときは、spec に色指定を記憶します。 nb = $1.bytesize #; 行頭の空白文字数 spec = $2 end # # ピリオドの前の半角空白の個数が nb に収録されました。 # ここを良く理解してください。 # # ここで計算した nb は、そこまでの文書環境の字下げ量を考 # 慮していない正味の行頭の半角空白数です。 # if $envstack.lastenv.class != Paragraph $envstack.endenv(nb) end if $envstack.stkblline > 0 $fp.print "\n" $envstack.stkblline = 0 $stkline = false end if $stkline $fp.print "\n" next end # checkonlyform checkenv # if /^([ ]*)\[checkenv\]/ =~ line $fp.print "DB 507216: " + $envstack.lastenv.class.to_s + "\n" next end # ------------------------------------------------------ # if /^([ ]*)\$Filename:(.*)\$$/ =~ line # line = $1 + "Filename:" + $2 + "\n"; # end # if /^([ ]*)\$Lastupdate:(.*)\$$/ =~ line # line = $1 + "Lastupdate:" + $2 + "\n"; # end # ------------------------------------------------------ # myregion start # @begin ... @end の環境解析開始 # ------------------------------------------------------ # 行の形だけですぐわかる構文のチェック(続き) # checkonlyform ignore|secret|obsolete # # ignore|secret|obsolete if /^([ ]*)@begin{(ignore|secret|obsolete)}[- ]*$/ =~ line nline = $.; sline = line.chomp; item = $2; line = $io.gets.detab while /^[ ]*@end{#{item}}[- ]*$/ !~ line line = $io.gets if !line || /^\*{1,5} / =~ line || /^(==|\*) (enddoc|enddic)/ =~ line rline = __LINE__.to_s FileendErrorMessage(nline, sline, rline) exit 1 end line.detab end $envstack.stkblline = 0 next end # 行の形だけですぐわかる構文のチェック(続き) # checkonlyform @begin{panel} # checkonlyform panel # # @begin{panel} # ... # @end{panel} # # の処理はここ。 # if /^([ ]*)@begin{panel[^{}]*}{[^{}]*}(| [-]+)$/ =~ line || /^([ ]*)@begin{panel[^{}]*}(| [-]+)$/ =~ line # # @begin{panel(.*)}{(.*)} ---------------------------- # subtitle = $1 # spec = $2 # @end{panel#{subtitle}} ----------------------------- # # または # # @begin{panel(.*)} ---------------------------------- # subtitle = $1 # spec = "" # @end{panel#{subtitle}} ----------------------------- # # の形。 # if /^([ ]*)@begin{panel(.*)}{([^{}]*)}(| [-]+)$/ =~ line nb = $1.bytesize subtitle = $2 spec = $3 else /^([ ]*)@begin{panel([^{}]*)}(| [-]+)$/ =~ line nb = $1.bytesize subtitle = $2 spec = "" end specstring = spec if /^[ ]+(.*)$/ =~ spec specstring = $1 end prepareSpecialenv(nb) # @begin{Cmnted out at 20160425 22:40}---------------- # $envstack.endenv(nb) # if $envstack.stkblline > 0 # while $envstack.stkblline > 0 # $fp.print "
\n" $stkline = false end $envstack.stkblline = 0 if spec style = "" if /^(\w+|#\w+)/ =~ spec style += "background-color: " + $1 + "; " end if /,[ ]*(\w+|#\w+)/ =~ spec style += "color: " + $1 + "; " end $fp.print "\n" end bl = " " * $envstack.lastenv.indent nline = $. sline = line nw = nb nextline = $io.gets $io.pushback if /^([ ]*)[^ ].*$/ =~ nextline nk = $1.bytesize nw = nk if nk < nb end line = $io.gets.detab # 本来は、.. で終わるのですが、. だけ書いた行でも終わ # ります。 # @begin{Cmnted out at 20170815 15:48}-------------------- # while /^#{" " * nb}\.$/ !~ line && # /^#{" " * nb}\.\.$/ !~ line # @end{Cmnted out at 20170815 15:48}---------------------- # # @begin{Inserted at 20170815 15:48}---------------------- while /^#{" " * nb}\.\.$/ !~ line # @end{Inserted at 20170815 15:48}------------------------ # # 読み込んだ行の行頭の半角空白のうち nb 個の部分を無視 # しています。 # if /^([ ]*)[^ ].*$/ =~ line nk = $1.bytesize if nk > nw; nk = nw; end line.sub!(/^#{" " * nk}/, "") end /^([ ]*)[^ ]/ =~ line nbsp = $1.bytesize line.sub!(/^#{" " * nbsp}/, "") line = repthisfile(line) if $OPT_BACKQUOTE while (/`([^`]*)`/ =~ line) #` com= $1; str = `#{com}`.chomp; line.sub!(/`[^`]*`/, "#{str}") #` end end $fp.print " " * nbsp, emacsenspfunc(line), "\n" $endparagraph = false $stkblline = false else $endparagraph = false $stkblline = false end # $fp.print "627731" end def BoldFlushleft (line) # # == こんな風に等号が2つ並んで、その後に、半角空白 # が1個あり、その後に、空白でない文字から始まる # 文字列がある行で始まり、空白行まで。 # # こんな風なブロックを処理します。emacs 関数の置き換え # はしません。つまり、emacs 関数が出てきても解釈されま # せん。 # /^([ ]*)== (.*)$/ =~ line nb = $1.bytesize line = $1 + " " + $2 # == の前の半角空白の個数が nb に収録されました。 # ここを良く理解してください。 # # ここで計算した nb は、そこまでの文書環境の字下げ量を考 # 慮していない正味の行頭の半角空白数です。 # if $envstack.lastenv.class != Paragraph $envstack.endenv(nb) end if $envstack.stkblline > 0 $fp.print "\n" $envstack.stkblline = 0 $stkline = false end if $stkline $fp.print "
\n" line = $io.gets if !line || /^\*{1,5} / =~ line || /^(==|\*) (enddoc|enddic)/ =~ line FileendErrorMessageSearching(nline, sline, __LINE__.to_s, "..") # STDERR.print "At line " + __LINE__.to_s + " of o2h.rb" + ": The region which started at line " + # "#{nline} met with the file end at line #{$.}.", "\n" # print "At line " + __LINE__.to_s + " of o2h.rb" + ": The region which started at line " + # "#{nline} met with the file end at line #{$.}.", "\n" exit 1 end line = line.detab end if spec $fp.print "
\n" $stkline = false end $envstack.stkblline = 0 nw = $envstack.lastenv.indent # $fp.print "nw = " + nw.to_s nline = $. sline = line while /^[ ]*$/ !~ line # 読み込んだ行の行頭の半角空白のうち nb 個の部分を無視 # しています。行頭の半角空白の個数が nb より小さい場 # 合は、nb 個の半角空白が置かれたものとされます。 # if /^[ ]*\.\.[ ]*$/ =~ line $fp.print "
\n" else /^([ ]*)([^ ].*)$/ =~ line str = $2 ns = $1.bytesize - nw if ns < 0; ns = 0; end if ns >= 3; ns = ns - 3; end $fp.print " " * ns, "", str.svquoteline.gsub(/ /, " "), "","
\n" end line = $io.gets nline = $. sline = line if !line || /^\*{1,5} / =~ line || /^(==|\*) (enddoc|enddic)/ =~ line FileendErrorMessageSearching(nline, sline, __LINE__.to_s, "..") exit 1 end line = line.detab end $fp.print "
\n" $endparagraph = false $stkblline = false end def BigBoldFlushleft (line) # # === こんな風に等号が3つ並んで、その後に、半角空白 # が1個あり、その後に、空白でない文字から始まる # 文字列がある行で始まり、空白行まで。 # # こんな風なブロックを処理します。emacs 関数の置き換え # はしません。つまり、emacs 関数が出てきても解釈されま # せん。 # /^([ ]*)=== (.*)$/ =~ line nb = $1.bytesize line = $1 + " " + $2 # == の前の半角空白の個数が nb に収録されました。 # ここを良く理解してください。 # # ここで計算した nb は、そこまでの文書環境の字下げ量を考 # 慮していない正味の行頭の半角空白数です。 # if $envstack.lastenv.class != Paragraph $envstack.endenv(nb) end if $envstack.stkblline > 0 $fp.print "\n" $envstack.stkblline = 0 $stkline = false end if $stkline $fp.print "
\n" $stkline = false end $envstack.stkblline = 0 nw = $envstack.lastenv.indent # $fp.print "nw = " + nw.to_s $fp.print "" nline = $. sline = line while /^[ ]*$/ !~ line # 読み込んだ行の行頭の半角空白のうち nb 個の部分を無視 # しています。行頭の半角空白の個数が nb より小さい場 # 合は、nb 個の半角空白が置かれたものとされます。 # if /^[ ]*\.\.[ ]*$/ =~ line $fp.print "
\n" else /^([ ]*)([^ ].*)$/ =~ line str = $2 ns = $1.bytesize - nw if ns < 0; ns = 0; end if ns >= 4; ns = ns - 4; end $fp.print " " * ns, "", str.svquoteline.gsub(/ /, " "), "","
\n" end line = $io.gets nline = $. sline = line if !line || /^\*{1,5} / =~ line || /^(==|\*) (enddoc|enddic)/ =~ line FileendErrorMessageSearching(nline, sline, __LINE__.to_s, "..") exit 1 end line = line.detab end $fp.print "
\n" $endparagraph = false $stkblline = false end def OnedotFlushleft (line) /^([ ]{0,39})\.([ ]+)([^ ].*)$/ =~ line ## emacsfunc の処理をこの中でしていることに注意してください。 # nb = $1.bytesize #; 行頭の空白文字数 # $fp.print "DEBUGA\n"; if $envstack.lastenv.class != Paragraph $envstack.endenv(nb) end if nb == 0 cenv = Paragraph.new(0,0) end # $fp.print "DEBUGB\n"; if $envstack.stkblline > 0 $fp.print "\n" $envstack.stkblline = 0 $stkline = false end if $stkline $fp.print "
\n" $stkline = false end string = repthisfile($3) bl = " " * $envstack.lastenv.indent $envstack.stkblline = 0 nbsp = $2.bytesize - 1 if $OPT_BACKQUOTE while (/`([^`]*)`/ =~ line) #` com= $1; str = `#{com}`.chomp; line.sub!(/`[^`]*`/, "#{str}") #` end end $fp.print " " * nbsp, emacsenspfunc(string), "
\n" $stkline = false end def OnedotFlushleftInlist (line) /^([ ]{0,39})\.([ ]+)([^ ].*)$/ =~ line ## emacsfunc の処理をこの中でしていることに注意してください。 # nb = $1.bytesize #; 行頭の空白文字数 # $fp.print "DEBUGA\n"; if $envstack.stkblline > 0 $fp.print "\n" $envstack.stkblline = 0 $stkline = false end if $stkline $fp.print "
\n" $stkline = false end string = repthisfile($3) bl = " " * $envstack.lastenv.indent $envstack.stkblline = 0 nbsp = $2.bytesize - 1 if $OPT_BACKQUOTE while (/`([^`]*)`/ =~ line) #` com= $1; str = `#{com}`.chomp; line.sub!(/`[^`]*`/, "#{str}") #` end end $fp.print " " * nbsp, emacsenspfunc(string), "
\n" $stkline = false end def ThreedotsVquote (line) /^([ ]{0,39})\.\.\.([ ]+)([^ ].*)$/ =~ line ## vquoteline の処理をこの中でしていることに注意してください。 # nb = $1.bytesize #; 行頭の空白文字数 # $fp.print "DEBUGA\n"; if $envstack.lastenv.class != Paragraph $envstack.endenv(nb) end if nb == 0 cenv = Paragraph.new(0,0) end # $fp.print "DEBUGB\n"; if $envstack.stkblline > 0 $fp.print "\n" $envstack.stkblline = 0 $stkline = false end string = repthisfile($3) bl = " " * $envstack.lastenv.indent $envstack.stkblline = 0 nbsp = $2.bytesize - 1 if $OPT_BACKQUOTE while (/`([^`]*)`/ =~ line) #` com= $1; str = `#{com}`.chomp; line.sub!(/`[^`]*`/, "#{str}") #` end end # $fp.print " " * nbsp, string.svquoteline $fp.print " " * nbsp, string.svquoteline.gsub(/ /, " ") $stkline = true end def ThreedotsVquoteInlist (line) /^([ ]{0,39})\.([ ]+)([^ ].*)$/ =~ line ## vquoteline の処理をこの中でしていることに注意してください。 # nb = $1.bytesize #; 行頭の空白文字数 # $fp.print "DEBUGA\n"; if $envstack.stkblline > 0 $fp.print "\n" $envstack.stkblline = 0 $stkline = false end string = repthisfile($3) bl = " " * $envstack.lastenv.indent $envstack.stkblline = 0 nbsp = $2.bytesize - 1 if $OPT_BACKQUOTE while (/`([^`]*)`/ =~ line) #` com= $1; str = `#{com}`.chomp; line.sub!(/`[^`]*`/, "#{str}") #` end end $fp.print " " * nbsp, string.svquoteline.svquoteline.gsub(/ /, " ") $stkline = true end def OnedotSquareFlushleftInlist (line) /^([ ]{0,39})\.□([ ]+)([^ ].*)$/ =~ line ## emacsfunc の処理をこの中でしていることに注意してください。 # nb = $1.bytesize #; 行頭の空白文字数 # $fp.print "DEBUGA\n"; if $envstack.stkblline > 0 $fp.print "\n" $envstack.stkblline = 0 $stkline = false end if $stkline $fp.print "
" $stkline = false end string = repthisfile($3) bl = " " * $envstack.lastenv.indent $envstack.stkblline = 0 nbsp = $2.bytesize - 1 if $OPT_BACKQUOTE while (/`([^`]*)`/ =~ line) #` com= $1; str = `#{com}`.chomp; line.sub!(/`[^`]*`/, "#{str}") #` end end $fp.print "□", " " * nbsp, emacsenspfunc(string), "
\n" $stkline = false end def OnecommaVerbatim (line) /^([ ]*),([ ]+)([^ ].*)$/ =~ line ## , abc # nb = $1.bytesize #; 行頭の空白文字数 # $fp.print "DEBUGA: ", line.chomp, "\n"; if $envstack.lastenv.class != Paragraph $envstack.endenv(nb) end # $fp.print "DEBUGB\n"; if $envstack.stkblline > 0 $fp.print "\n" $envstack.stkblline = 0 $stkline = false end if $stkline $fp.print "
" $stkline = false end string = repthisfile($3) bl = " " * $envstack.lastenv.indent $envstack.stkblline = 0 nbsp = $2.bytesize - 1 if $OPT_BACKQUOTE while (/`([^`]*)`/ =~ line) #` com= $1; str = `#{com}`.chomp; line.sub!(/`[^`]*`/, "#{str}") #` end end string = string.squoteline.gsub(/ /, " ") $fp.print " " * nbsp, string, "
\n" $stkline = false end def OnecommaVerbatimInlist (line) /^([ ]*),([ ]+)([^ ].*)$/ =~ line ## , abc # nb = $1.bytesize #; 行頭の空白文字数 string = repthisfile($3) bl = " " * $envstack.lastenv.indent $envstack.stkblline = 0 nbsp = $2.bytesize - 1 if $OPT_BACKQUOTE while (/`([^`]*)`/ =~ line) #` com= $1; str = `#{com}`.chomp; line.sub!(/`[^`]*`/, "#{str}") #` end end if $stkline $fp.print "
" $stkline = false end string = string.squoteline.gsub(/ /, " ") $fp.print " " * nbsp, string, "
\n" $stkline = false $stkblline = false end def TwodotsFlushleft (line) # .. ああああ # # のように、行頭に0個以上の半角空白文字、その後に、.. と # 半角空白が1個以上あって、その後に、非空白文字がある行 # の処理。 # /^([ ]{0,39})\.\.([ ]+)([^ ].*)$/ =~ line ## emacsfunc の処理をこの中でしていることに注意してください。 # nb = $1.bytesize #; 行頭の空白文字数 # $fp.print "DEBUGC", line, "\n"; if $envstack.lastenv.class != Paragraph $envstack.endenv(nb) end if $envstack.stkblline > 0 $fp.print "\n" $envstack.stkblline = 0 $stkline = false end if $stkline $fp.print "
" $stkline = false end string = repthisfile($3) bl = " " * $envstack.lastenv.indent $envstack.stkblline = 0 nbsp = $2.bytesize - 1 if $OPT_BACKQUOTE while (/`([^`]*)`/ =~ line) #` com= $1; str = `#{com}`.chomp; line.sub!(/`[^`]*`/, "#{str}") #` end end $fp.print " " * nbsp, emacsfunc(string) $stkline = true end def Html (line) /^([ ]*)@begin{html}[- ]*$/ =~ line nb = $1.bytesize if $envstack.lastenv.class != Paragraph $envstack.endenv(nb) end if $envstack.stkblline > 0; $fp.print "\n"; end $envstack.stkblline = 0 nline = $.; sline = line; line = $io.gets.detab while /^[ ]*@end{html}[- ]*$/ !~ line if /^([ ]*)[^ ]/ =~ line nbsp = $1.bytesize line.sub!(/^#{" " * nbsp}/, "") # 行頭が半角文字なら、行頭に半角スペースを挿入する。 # Insert a space if a halfwidth character appeas at the # beginning of a line. if line =~ /^[ -~。-゚]/; line = " " + line; end # [ -~] は半角文字、[。-゚] は半角カタカナにマッチ。 $fp.print line.chomp else $fp.print "\n" end line = $io.gets if !line || /^\*{1,5} / =~ line || /^(==|\*) (enddoc|enddic)/ =~ line rline = __LINE__.to_s FileendErrorMessageSearching(nline, sline, rline, "@end{html}") exit 1 end line.detab end $endparagraph = true end # HangingIndent の見出し部分の処理用 def HtmlSpecial (line) /^([ ]*)@begin{html}[- ]*$/ =~ line nb = $1.bytesize nline = $.; sline = line; line = $io.gets.detab while /^[ ]*@end{html}[- ]*$/ !~ line /^([ ]*)[^ ]/ =~ line nbsp = $1.bytesize line.sub!(/^#{" " * nbsp}/, "") # 行頭が半角文字なら、行頭に半角スペースを挿入する。 if line =~ /^[ -~。-゚]/; line = " " + line; end # [ -~] は半角文字、[。-゚] は半角カタカナにマッチ。 $fp.print line.chomp line = $io.gets if !line || /^\*{1,5} / =~ line || /^(==|\*) (enddoc|enddic)/ =~ line rline = __LINE__.to_s FileendErrorMessage(nline, sline, rline) exit 1 end line.detab end end def HtmlBr (line) /^([ ]*)@begin{htmlbr}[- ]*$/ =~ line nb = $1.bytesize if $envstack.lastenv.class != Paragraph $envstack.endenv(nb) end if $stkline $fp.print "
\n" $stkline = false end if $envstack.stkblline > 0; $fp.print "\n"; end $envstack.stkblline = 0 nline = $.; sline = line; line = $io.gets.detab while /^[ ]*@end{htmlbr}[- ]*$/ !~ line line.sub!(/^#{" " * nb}/, "") /^([ ]*)[^ ]/ =~ line nbsp = $1.bytesize line.sub!(/^#{" " * nbsp}/, "") $fp.print " " * nbsp, line, "
\n" line = $io.gets if !line || /^\*/ =~ line || /^(==|\*) (enddoc|enddic)/ =~ line STDERR.print "At line " + __LINE__.to_s + " of o2h.rb" + ": The region which started at line #{nline}:\n#{sline}met with the file end at line #{$.}.", "\n"; print "At line " + __LINE__.to_s + " of o2h.rb" + ": The region which started at line #{nline}:\n#{sline}met with the file end at line #{$.}.", "\n" exit 1 end line.detab end end def ThreedashesDisplay (line) # --- abc # # WORK2 で処理します。Paragraph モードでも、他のリスト環境の # 詰め込みモードでも呼び出されます。 # # ThreedashesDisplayItem というのもあって、そっちは、 # list 環境の最初の項目で呼ばれます。 # /^([ ]*)(--- [ ]*[^ ].*)$/ =~ line nb = $1.bytesize string = $2; string.sub!(/--- /, "") prepareSpecialenv(nb) bl = " " * $envstack.lastenv.indent if $envstack.stkblline > 0; $fp.print "\n"; end $envstack.stkblline = 0 $fp.print "" # bgcolor = "lemonchiffon" # bgcolor = "whitesmoke" # bgcolor = "white" fontcolor = $fontcolor if $bgcolor.bytesize > 0 bgcolor = $bgcolor else bgcolor = $default_dashline_backcolor end # [2017-01-13] margin = " margin: 10px 0px " if $caption.bytesize > 0 CodeTitle($caption) $fp.print "\n" if /^[ ]*$/ =~ line $fp.print "\n" $endparagraph = true else $io.pushback end $envstack.stkblline = 0 $stkline = false $fontcolor = "" end # def ThreedotsVerbatim (line) # /^([ ]{0,39})(\.\.\. .*)$/ =~ line # nb = $1.bytesize # $envstack.endenv(nb) # string = $2; string.sub!(/\.\.\.[ ]+/, "") # bl = " " * $envstack.lastenv.indent # if $envstack.stkblline > 0; $fp.print "\n"; end # $envstack.stkblline = 0 # $fp.print "
\n" $caption = "" margin = " margin: 6px 0px " end if $caponly.bytesize > 0 $fp.print "" + $caponly + "
\n"; $caponly = "" margin = " margin: 6px 0px " end if $endnote.bytesize > 0 margin = margin + " 6px 0px;" else margin = margin + " 0px 0px;" end $fp.print "\n"; # $fp.print "
\n"; $fp.print string.svquoteline, "\n" line = $io.gets.detab while /^#{" " * nb}(---[^-]*)/ =~ line line.sub!(/^[ ]*--- /, "") $fp.print line.svquoteline line = $io.gets; line = line.detab end $fp.print ""; $fp.print "" # # $fp.print "background: #" + $bgcolor; # $fp.print ";\">\n"; # # $fp.print string.squoteline, "\n" # line = $io.gets.detab # while /^#{" " * nb}(\.\.\. )/ =~ line # line.sub!(/^[ ]*\.\.\.[ ]+/, "") # $fp.print line.squoteline # line = $io.gets; # line = line.detab # end # $io.pushback # $fp.print ""; # $fp.print "\n\n\n" # $fontcolor = $default_fontcolor # end def ThreedotsQuote (line) /^[ ]{0,39}\.\.\. (.*)$/ =~ line $fp.print $1.svquoteline end def TwocommasVerbatim (line) # (Label "800231" "TwocommasVerbatim の定義") # ,, 文字列1 # ,, 文字列2 # # このような形式の行を処理します。文字列を固定幅で表示します。 # emacs 関数の置き換えはせず、そのまま表示します。 /^([ ]*)(,, .*)$/ =~ line nb = $1.bytesize $envstack.endenv(nb) string = $2; string.sub!(/^[ ]*,, /, "") bl = " " * $envstack.lastenv.indent if $envstack.stkblline > 0; $fp.print "\n"; end $envstack.stkblline = 0 if $bgcolor.bytesize > 0 bgcolor = $bgcolor else bgcolor = $default_bgcolor end # @begin{Cmnted out at 20160417 15:23}-------------------- # if $envstack.lastenv.class == Bareline # @begin{Cmnted out at 20160417 15:22}------------------ # $inparagraph = true # $fp.print "" # @end{Cmnted out at 20160417 15:22}-------------------- # end # @end{Cmnted out at 20160417 15:23}---------------------- $fp.print "
" fontcolor = $fontcolor if fontcolor.bytesize == 0 fontcolor = $default_fontcolor end $fp.print "\n\n\n" $endparagraph = true $fontcolor = "" end def ThreecommasVerbatim (line) # ,,, 文字列1 # ,,, 文字列2 # # このような形式の行を処理します。文字列を固定幅で表示します。 # emacs 関数の置き換えはせず、そのまま表示します。 /^([ ]*)(,,, .*)$/ =~ line nb = $1.bytesize string = $2; string.sub!(/^[ ]*,,, /, "") margin = " margin: -10px 0px -5px 0px;" # $envstack.endenv(nb) if nb == $envstack.lastenv.indent # $fp.print "306333: \n" if $stkline margin = " margin: 0px 0px 0px 0px;" $stkline = false else margin = " margin: -5px 0px -5px 0px;" # $fp.print "148625: \n" if $justafteroutlineheading $envstack.endenv(nb) $envstack.stkblline = 0 $justafteroutlineheading = false else while $envstack.stkblline > 0 $fp.print "\n"; $fp.print "", string.svquoteline, "", "\n" line = $io.gets.detab while /^#{" " * nb}(,, )/ =~ line line.sub!(/^[ ]*,, /, "") $fp.print "", line.svquoteline, "" line = $io.gets; line = line.detab end $io.pushback $fp.print ""; $fp.print "
\n" $envstack.stkblline -= 1 end end end else $envstack.endenv(nb) end bl = " " * $envstack.lastenv.indent if $envstack.stkblline > 0; $fp.print "\n"; end $envstack.stkblline = 0 $fp.print "" fontcolor = $fontcolor if fontcolor.bytesize == 0 fontcolor = $default_vbcode_color end if $bgcolor.bytesize > 0 bgcolor = $bgcolor else bgcolor = $default_bgcolor end $fp.print "" if $OPT_BROWSER == "chrome" $fp.print "\n" # @begin{Cmnted out at 20160424 15:51}-------------------- # $fp.print "\n\n" # $endparagraph = true # @end{Cmnted out at 20160424 15:51}---------------------- # # @begin{Inserted at 20160424 15:51}---------------------- $stkline = false $fp.print "\n\n" $endparagraph = true nextline = $io.gets.detab.chomp unless /^[ ]*$/ =~ nextline $io.pushback end # @end{Inserted at 20160424 15:51}------------------------ $fontcolor = "" end def Navibutton(num, clevel, cnum) # (Ref "label207162" "呼び出し元") # (Label "Navibutton" "Navibuttonの定義箇所") # # 本文や目次に、jump するためのリンクを作成しています。 # # num は本文の見出しの位置のアンカーの番号。 # cnum は目次の該当位置のアンカーの番号。 # # [2016-01-24] 現在は、cnum と num とは同じですが、将来は # これらが違ってもいいように備えることにしました。 # # [Contents] は目次に jump するためのもの。 # [Prev] は、本文の、前の見出し行に jump するためのもの # [Next] は、本文の、次の見出し行に jump するためのもの # です。 # # 同じページの特定の場所にジャンプするリンクを作成するとき # には、ラベルの前に # をつけるというhtmlのルールがあります。 # if $OPT_NOCONTENTS $fp.print "[Top]\n"; $fp.print "[End]\n"; # # これで、[End] というリンクが作成 # されます。 # # . というアンカーは別の場所で作成 # されています # (Ref "lastpage-anchor" "") # else # (Ref "453494" "アンカーを作成したコード") # if clevel <= $OPT_CONTENTLEVEL $fp.print "[CTop]\n"; if clevel <= $OPT_CONTENTLEVEL $fp.print "[Contents]"; else $fp.print "(Contents)"; end unless $OPT_NOTOPHEADINGLIST $fp.print "[TopHdngList]" end # # これで、[Contents] のようなリンクが作成 # されます。 # end if (num > 1) then $fp.print "[Prev][Next]" else # なぜ、 から始まっているのか $fp.print "[Next]" end index = $clevelarray.length - 2 samelevelpreviousfound = false while index >= 0 if samelevelpreviousfound != true && $clevelarray[index] == clevel samelevelpreviousfound = true $fp.print "[SameLvlPrev]" break end if $clevelarray[index] < clevel break end index -= 1 end if samelevelpreviousfound == false $fp.print "[SameLvlPrev]" end $fp.print "\n" end def Parentlist print ""; $fp.print "", string.svquoteline, "\n" line = $io.gets.detab while /^#{" " * nb}(,,, )/ =~ line line.sub!(/^[ ]*,,, /, "") $fp.print "", line.svquoteline, "\n" line = $io.gets; line = line.detab end $io.pushback $fp.print ""; $fp.print "\n" # リストの開始 index = 0 chapindex = 0 while index < $clevelarray.length if $clevelarray[index] == 1 && $headingarray[index] != "enddoc" chapindex += 1 print "
\n" $endparagraph = true end def Childrenlist # (Label "280292" "Childrenlist 関数の定義") # /^\[childrenlist\]/ =~ line だったときに呼びだされます。 # # 次の見出しがあって、それが子供のレベルであるかを判定しま # す。そうであれば、子供が少なくとも1人はいることになります。 # # $IndexOfHeading に現在、処理中の「文章塊」の番号が格納 # されています。$IndexOfHeading は、0, 1, ..., # $clevelarray.length-1 # までの、$clevelarray.length-1 個の文章塊を扱いします。 # # (Ref "232150" "$IndexOfHeading を求めておく") # を参照してください。 # if $IndexOfHeading < 0 # こんなことは起こらないはず。 print "[childrenlist]\n" return end clevel = $clevelarray[$IndexOfHeading] if $IndexOfHeading < $clevelarray.length - 1 && $clevelarray[$IndexOfHeading+1] == clevel + 1 # 子供のレベルの見出しが少なくとも1個あったので、 # リストを用意します。 print "- " + chapindex.to_s + " " + $headingarray[index] + "" + " " + $outlineHeadingLineno[index] end index += 1 end print "
\n" # リストの開始 index = $IndexOfHeading + 1 while index < $clevelarray.length if $clevelarray[index] <= clevel # clevel は親のレベル。子のレベルは、(clevel + 1) # # 親のレベルの見出しが出てきたら、IndexOfHeading の # 子供はもう居ないので終了、break する。 # break elsif $clevelarray[index] == (clevel + 1) # 子供のレベルである。 if index < $clevelarray.length - 1 && $clevelarray[index+1] == (clevel + 2) # 孫が居るので、"(has children)" を追加。 print "
\n" # リストの終了 $endparagraph = true end end def AllHeadinglist # # 一度ファイルの最後まで読み込んで処理した後、 # 再読み込みしたときに、この行があったらこの関数が呼ばれま # す。 # $headOrSubheadHash # $headOrSubheadDefinedLineHash print "\n" print "- " + $headingarray[index] + " (下位項目あり)" + " " + $outlineHeadingLineno[index] else # 孫は居ない。 print "
- " + $headingarray[index] + "" + " " + $outlineHeadingLineno[index] end # 孫のレベル (clevel + 2) 以上の場合は何も書かない。 end index += 1 end print "
" print "\n" print "\n" end def AllHdnglist # アウトライン見出しを含め全ての見出しの表を作成します。 # # heading # $headOrSubheadDefinedLineHash[heading] # $headingAnchorHash[heading] # # がそのまま表示されます。ここで、quote されることはありま # せん。 if $headOrSubheadHash.size > 0 i = 0 print "
ALL HEADING LIST ■はアウトライン見出しのタイトル □はそれ以外
" AllHdnglist() print "\n" print "" + "[ALL HEADING LIST Top]" print "\n" $headOrSubheadHash.each do |heading, val| # if val != "OutlineHeading" i += 1 k = i.modulo(2) info = $headOrSubheadDefinedLineHash[heading] /^(.*) ([0-9]+)$/ =~ info linenumber = $2 mark = $1 target = $headingAnchorHash[heading] print "
\n" else print "拡張見出しの一覧: 拡張見出しはありません。" end end def AllHdngrefString(heading) reflines = $headingReferredLineHash[heading].split(",") headanchor = $headingAnchorHash[heading] string = "" num = reflines.size if num > 0 index = 0 while index < num target = headanchor + "." + (index+1).to_s string += '' + reflines[index] + '' index += 1 if index < num; string += ", "; end end end string end def Notelist if $noteDefinedLineHash.size > 0 i = 0 print "\n" bgcolor = "#efefef" if k== 1; bgcolor = "#e5f2ff"; end bgcolorhdline = bgcolor if val == "OutlineHeading"; bgcolorhdline = "beige"; end print " \n" # end end print "", '' + linenumber + '' + (" " * 1) print " " if /^*/ =~ mark print "", mark + (" " * 1) else print " ", mark + (" " * 1) end print " " print "" # @begin{Cmnted out at 20160522 06:10}-------------- if val == "OutlineHeading" # /^(.*) [0-9]+$/ =~ info # print $1, " " print "■" else print "□" end print heading # end # @end{Cmnted out at 20160522 06:10}---------------- # # @begin{Inserted at 20160522 06:10}---------------- # print heading # @end{Inserted at 20160522 06:10}------------------ print " \n" print "", AllHdngrefString(heading), " \n" print "\n" $noteDefinedLineHash.each do |heading, info| i += 1 k = i.modulo(2) target = $noteanchorhash[heading] print "
\n" else print "Note の一覧: Note はありません。" end end def CodeTitle (title) if $headOrSubheadHash[title] == "" $headOrSubheadDefinedLineHash[title] = "Caption " + $..to_s # 小見出しであることを記録します。 $headOrSubheadHash[title] = "HeadfuncHeading" if not $headingAnchoredpHash[title] # まだ title に対するアンカーは設置されていませんで # した。 if $headingAnchorHash[title] == "" # 参照もされていませんでした。これから後で参照する # 可能性もあるのでアンカー文字列を生成し、記憶しま # す。 anchor = "head." + sprintf("%08d", $rndm.rand(10000 * 10000)) $headingAnchorHash[title] = anchor else # すでに参照されていました。アンカー文字列は # 生成済なのでそれを anchor とします。 anchor = $headingAnchorHash[title] end $fp.print '' + title + '' + "\n" + '[Heading ' + anchor + "]\n" # title に対するアンカーを設置したことを記憶します。 $headingAnchoredpHash[title] = true end else $fp.print "" + title + "\n" bgcolor = "#efefef" if k== 1; bgcolor = "#e5f2ff"; end print " \n" end print "" + '' + info + '' + (" " * 1) print " \n" print "", heading, " \n" print "", NoterefString(heading), " \n" print "
\n"; # title はすでに出てきたので、これは誤りです。 # $message に記憶します。これは、html ファイルの最後に # 書きだされます。 $headOrSubheadHash[heading] += "*" $headOrSubheadDefinedLineHash[title] += ", " + "Caption " + $..to_s unless $OPT_ACCEPTDUPLICATEDHEADER $message += "重複しています。 \$caption = \"" + title + "\" at line " + $headOrSubheadDefinedLineHash[title] + "
" end end end def GetAnchorFor (title) # title に格納されている文字列を新規登録して、それに対す # るアンカー文字列を取得します。 # title が参照されるべき文字列として登録済みならば、"" # を返します。 # acnchor = "" if $headOrSubheadHash[title] == "" $headOrSubheadDefinedLineHash[title] = "Anchor " + $..to_s # 小見出しであることを記録します。 $headOrSubheadHash[title] = "HeadfuncHeading" if not $headingAnchoredpHash[title] # まだ title に対するアンカーは設置されていませんで # した。 if $headingAnchorHash[title] == "" # 参照もされていませんでした。これから後で参照する # 可能性もあるのでアンカー文字列を生成し、記憶しま # す。 anchor = "head." + sprintf("%08d", $rndm.rand(10000 * 10000)) $headingAnchorHash[title] = anchor else # すでに参照されていました。アンカー文字列は # 生成済なのでそれを anchor とします。 anchor = $headingAnchorHash[title] end # title に対するアンカーを設置したことを記憶します。 $headingAnchoredpHash[title] = true end end anchor end def Notereflist (noteanchor) num = $noterefhash[noteanchor] # print noteanchor, " num = ", num.to_s, "
\n" if num > 0 string = "" index = 0 while index < num index += 1 target = noteanchor + "." + index.to_s string += '[' + index.to_s + ']' end # print #{string} print "引用箇所: " + string + "\n" # 書き出し途中 $stkline = true end end def NoterefString (heading) reflines = $noteReferredLineHash[heading].split(",") noteanchor = $noteanchorhash[heading] string = "" num = reflines.size if num > 0 index = 0 while index < num target = noteanchor + "." + (index+1).to_s string += '' + reflines[index] + '' index += 1 if index < num; string += ", "; end end end string end def NotereflistParen (noteanchor) num = $noterefhash[noteanchor] # print noteanchor, " num = ", num.to_s, "
\n" if num > 0 string = "" index = 0 while index < num index += 1 target = noteanchor + "." + index.to_s string += '[' + index.to_s + ']' end print " (引用箇所: " + string + " )\n" end end def Headingreflist (headinganchor) # [Heading ...] の処理 num = $headingRefCountHash[headinganchor] # print headinganchor, " num = ", num.to_s, "
\n" if num > 0 string = "" index = 0 while index < num index += 1 target = headinganchor + "." + index.to_s string += '[' + index.to_s + ']' end # print #{string} print "Referred at: " + string + "\n" end end def Anchorreflist (headinganchor) # [Anchor ...]
の処理 num = $headingRefCountHash[headinganchor] # num = 0、すなわち参照されていなかった場合は、 # [Anchor ...]
全体を無視します。 if num > 0 string = "" index = 0 while index < num index += 1 target = headinganchor + "." + index.to_s string += '[' + index.to_s + ']' end # print #{string} print "□ Referred at: " + string + "
\n" end end def AnchorreflistParen (headinganchor) # [AnchorParen ...] の処理 num = $headingRefCountHash[headinganchor] # num = 0、すなわち参照されていなかった場合は、 # [AnchorParen ...]
全体を無視します。 # print headinganchor, " num = ", num.to_s, "
\n" if num > 0 string = "" index = 0 while index < num index += 1 target = headinganchor + "." + index.to_s string += '[' + index.to_s + ']' end # print #{string} print "(Referred at: " + string + ")\n" end end def OutlineHeadingreflist (headinganchor) # [OutlineHeading ...] の処理 num = $headingRefCountHash[headinganchor] # print headinganchor, " num = ", num.to_s, "
\n" if num > 0 string = "" index = 0 while index < num index += 1 target = headinganchor + "." + index.to_s string += '[' + index.to_s + ']' end # print #{string} print "Referred at: " + string + "\n" # つぎのように考えるのは正しいですが、もう次の行も出 # 来上がっているので意味がありません。 $stkline = false end end def HeadingreflistParen (headinganchor) num = $headingRefCountHash[headinganchor] # num は、headinganchor を参照している (H ...) の個数です。 # # print headinganchor, " num = ", num.to_s, "
\n" if num > 0 string = "" index = 0 while index < num index += 1 target = headinganchor + "." + index.to_s string += '[' + index.to_s + ']' end # print #{string} print (" (Referred at: " + string + " ) \n") end end # ---------------------------------------------------------- # ここまで、必要なクラスを定義して来ました。 # ここから、 # WORK2 開始。 # (Label "work2start" "WORK2 開始") # (Ref "program_structure" "プログラムの構成") # # 作業用のファイルの準備など。 # # 処理対象のアウトライン文書を一行ずつ読み込んで行くのは、 # (Ref "while-a start" "WHILE-A 開始") # で。 # ---------------------------------------------------------- # (Ref "program_structure" "プログラムの構成") # (Ref "work1start" "WORK1 開始") # (Ref "work2start" "WORK2 開始") # (Ref "work3start" "WORK3 開始") # (Ref "class_definition" "CLASS DEFINITION") # (Ref "whileaclass_definition" "CLASS DEFINITION") # (Ref "while-a start" "WHILE-A 開始") # (Ref "syntax-check" "(1) 構文チェック") # (Ref "use-analyzefunc" "(2a) analyze 関数を使用して構文解析") # (Ref "output-analyze" "(2b) 結果の書き出し") # (Ref "while-a end" "WHILE-A 終わり") # @begin{Cmnted out at 20160320 19:33}---------------------- $tempdir = ENV['HOME'] if $tempdir != nil $tempdir = $tempdir.gsub(File::ALT_SEPARATOR) {File::SEPARATOR} end if ENV['ODRTEMP'] $tempdir = ENV['ODRTEMP'].gsub(File::ALT_SEPARATOR) {File::SEPARATOR} end # @end{Cmnted out at 20160320 19:33}------------------------ # @begin{Cmnted out at 20160320 18:27}---------------------- fooa = $tempdir + "/o2hfooa.#$$" foob = $tempdir + "/o2hfoob.#$$" fooc = $tempdir + "/o2hfooc.#$$" # @end{Cmnted out at 20160320 18:27}------------------------ # $fboxy, fooa は、本文を作成するために使用されます。 # $findx, foob は、目次を作成するために使用されます。 # $fabst, fooc は、abstract 部分を書き出すために使用されます。 # 解析していく過程で、fooa, foob, fooc を作成しておき、 # 最後に、fooc, foob, fooa を読み込んで、標準出力に書き出 # します。 # # すべての作業が正常に終われば、fooa, foob, fooc は削除さ # れます。途中でエラーが起こって作業が中断されると、これら # のファイルが残されたままになります。 $fbody = open(fooa, "w") $findx = open(foob, "w") $fabst = open(fooc, "w") # "環境" を envstack というスタックを使って記憶します。 # 一番下は、Bareline という環境です。 $envstack = StateEnv.new a = Bareline.new(0, 0) $envstack.push(a) # (Noteref "foo" "Foo") の形のリンクを登録するハッシュテーブル # # (Noteref "foo" "Foo") を読み取ったら、 # $noterefhash["foo"] += 1 # とします。 # # (Note "foo" ...) を参照した回数が $noterefhash["foo"] に # 格納されます。 $noterefhash = Hash.new(0) home = ENV["HOME"] # 見出し行のレベルを配列 $clevelarray に記憶します。 # 見出し行のタイトルを配列 $headingarray に記憶します。 # # index ; ; clevelarray :: headingarray # 0 ; * 序論 ; 1 :: 序論 # 1 ; * 前提 ; 1 :: 前提 # 2 ; ** 実験 ; 2 :: 実験 # 3 ; ** 理論 ; 2 :: 理論 $clevelarray = Array.new $headingarray = Array.new $outlineHeadingLineno = Array.new # $f はグローバル変数です。MyIo の中で $f を使用しています。 # 読み込み元が $f。$path_name には、いま処理しようとしてい # る文書ファイルのパスが格納されています。 # # $fp はグローバル変数です。書き出すときに使用します。 # (Label "238075" "cmprefixが使われる") # $f = open($path_name) $io = MyIo.new(cmprefix) /^(.*)\.([^.]+)$/ =~ $path_name # $fabst = open(fooc, "w") # $fp は最初は、$fabst を指し、後に、$fbody を指します。 # # 「* abstract」の形の見出し行を読み込んだときは、まだ、$fp は # $fabst を指したままにします。それ以外の見出し行を読み取 # ったときは、そこからは、$fp を $fbody に切り替えます。 # # --- $fp.print ... # # という文は、目次の前の「概要」を書き出している場合と、目 # 次の後の「本文」を書き出している場合の両方があります。 $fp = $fabst $beforemidashi = true # $lclevel に、前の見出しの星の数を記憶します。最初は、 # $lclevel = 0 とします。星の数は、$lclevel + 1 より大きく # てはいけないので、最初の見出しのレベルは、星一つでないと # いけないといけないことになります。 # # (Ref "322184 $lclevel使用" "$lclevel の最初の使用位置") $lclevel = 0 ## ここが解析の始め begin # # $mathjax = false $tablestyle = "" # ---------------------------------------------------------- # この begin に対応する end は? # (Label "beginpos " "beginend の開始") # (Ref "beginend" "beginend の終わり") # # まず、ファイル $path_name を開きました。 # # この後、ファイル $path_name を読み取って、解析し、その結果を # fooa.txt, foob.txt, fooc.txt に書き込みます。この作業を # している部分は、つぎのような構造をしています。 # # ---------------------------------------------------------- # begin # while # ... # end # # rescue # ... # end # ---------------------------------------------------------- # # end の後でファイル $path_name を閉じます。 # # この後にも作業がありますが、主要部分はここ。 # # rescue から前でエラーが起こったら、エラーを書き出して中 # 断します。 # (Ref "rescuepoint" "rescue はここ") skipuntillstart = false # @begin{Cmnted out at 20160403 18:31}---------------------- # if $extpart != ".odr" && $extpart != ".txt" # skipuntillstart = true # # ここで skipuntillstart を true に設定しますが、 # # ファイルを読み進めて行く間に、 # # # # ^== startdoc$ =~ line # # # # という行を読み込むと、そこから、ODR 文書が読み込まれ # # ることになります。 # # 最後まで、ファイルを読み込んで、skipuntillstart が # # true のままなら、有効な行は無かったということなので、 # # そのときは、show コマンドを使ってメッセージを表示す # # るようにします。 # end # @end{Cmnted out at 20160403 18:31}------------------------ begin cindentblank = " " * $envstack.lastenv.indent while line = $io.gets # この while loop が基本的な読み取りループです。 # 特に誤った構造をしていなければ、* enddoc がなくても # 問題ありません。あった方がすっきりすると思いますが。 # # ------------------------------------------------------ # (Ref "while-a start" "WHILE-A 開始") # (Ref "syntax-check" "(1) 構文チェック") # (Ref "use-analyzefunc" "(2) analyze 関数を使用して構文解析") # (Ref "output-analyze" "(3) 結果の書き出し") # (Ref "while-a end" "WHILE-A 終わり") # ------------------------------------------------------ # (Label "while-a start" "WHILE-A の開始") # (Ref "while-a end" "WHILE-A 終わり") # この while loop を WHILE-A とします。 # # WHILE-A の終わりはどこか # # WHILE-A の終わりを知るには、 # (Ref "while-a end" "WHILE-A 終わり") # の右括弧の直後にカーソルを置いて、C-c C-e をタイプし # てください。 # # この WHILE-A のループの「構文チェック」では、ある環 # 境の継続行の構文をチェックします。 # # 1. まずは、「構文チェック」。 # (Ref "syntax-check" "(1) 構文チェック") # # リスト環境の継続行は、最初にここの一連の構文チェ # ックを受けます。 # # 行の形だけですぐわかる構文は、この WHILE-A ループ # で処理されます。例えば、@begin{verbatim} ... # @end{verbatim} などはこの WHILE-A ループで処理し # ます。 # # 2. ここの「構文チェック」をすり抜けたものは、 # # 「analyze 関数を使用して構文解析」 # /* # (Ref "use-analyzefunc" # "(2) analyze 関数を使用して構文解析") # */ # # します。 # # 2.1 別の新たな構文の開始行か # 2.2 Orderedlist や UnOrderdlst の2番目以降の項目 # の開始か # 2.3 Flushleft か # 2.4 Indented か # # に分類されます。 # # Indented に分類されると、それぞれのリスト環境の # contline 関数で処理されます。 # # したがって、1 のところで処理される構文チェックを # contline 関数の部分に入れる必要はありません。 # # ------------------------------------------------------ # (Label "syntax-check" "構文チェック") # ------------------------------------------------------ # (1) 「構文チェック 開始 # ------------------------------------------------------ # (Ref "while-a start" "WHILE-A の開始") # (Ref "use-analyzefunc" "(2) analyze 関数を使用して構 # 文解析") line = line.detab # 行の形だけですぐわかる構文のチェック # checkonlyform "== startdoc" を読み飛ばし。 if /^== startdoc$/ =~ line next end # 行の形だけですぐわかる構文のチェック # checkonlyform = # if /^= / =~ line && $equalsign_is_title line.sub!(/^= /, ";;; @(#) ") $equalsign_is_title = false end # checkonlyform $math if /^[ ]*\$math$/ =~ line $mathjax = true next end # checkonlyform <<< if /^<< =~ line line.sub!(/^<<< /, ";;; <<< ") end # 行の形だけですぐわかる構文のチェック(続き) # checkonlyform ;;; if /^;{3,}/ =~ line # @begin{Cmnted out at 20160417 16:17}---------------- # # # # ;;; で始まる行を読み取った時に、未処理の空白行が # # あったら、 # # それを無視することにします。 # # # $envstack.stkblline = 0 # @end{Cmnted out at 20160417 16:17}------------------ if /@\(#\)\s+(.*)$/ =~ line title = $1 $envstack.title = title.sub(/\134\134/, "
") while true line = $io.gets if %r!^;{3,}[ ]@\(#\)\s+(.*)$! =~ line title = $1 $envstack.title += "
" $envstack.title += title elsif /^=\s+(.*)$/ =~ line title = $1 $envstack.title += "
" $envstack.title += title else $io.pushback break end end elsif /@\(%h?\)\s+(.*)$/ =~ line code = $1 eval code end next end # 行の形だけですぐわかる構文のチェック(続き) # checkonlyform ;;; # if /^[ ]+;{3,}[ ]*@\(%h?\)\s+(.*)$/ =~ line code = $1 eval code next end if /^[ ]*;;;[ ]/ =~ line # ;;;[ ] の後に、@(#) や @(%)、@(%h) が無い行は # 読み飛ばします。 # @begin{Cmnted out at 20160512 15:28}---------------- # next # @end{Cmnted out at 20160512 15:28}------------------ # # @begin{Inserted at 20160512 15:28}------------------ # もう一行読んで、それが空白行だったら、その空白行を含 # めて読み飛ばします。 nextline = $io.gets.detab.chomp unless /^[ ]*$/ =~ nextline $io.pushback end next # @end{Inserted at 20160512 15:28}-------------------- end # checkonlyform @_ # ;;; @(%) $caption = "..." と同等と評価します。 if /^[ ]*@_([^ ].*)$/ =~ line heading = $1 # @_ の後の最初の文字が ' か $ の場合は、heading は、 # 文字列を返す式と考え、そうでなければ文字列として、 # '' で heading を囲みます。 if (/^'/ !~ heading && /^\$/ !~ heading) heading = "'" + heading + "'" end code = "$caption = " + heading eval code next end # ;;; @(%) $caponly = "..." と同等と評価します。 if /^[ ]*@@_([^ ].*)$/ =~ line heading = $1 # @_ の後の最初の文字が ' か $ の場合は、heading は、 # 文字列を返す式と考え、そうでなければ文字列として、 # '' で heading を囲みます。 if (/^'/ !~ heading && /^\$/ !~ heading) heading = "'" + heading + "'" end code = "$caponly = " + heading eval code next end # ;;; @(%) $endnote = "..." と同等と評価します。 if /^[ ]*@@@_([^ ].*)$/ =~ line heading = $1 # @_ の後の最初の文字が ' か $ の場合は、heading は、 # 文字列を返す式と考え、そうでなければ文字列として、 # '' で heading を囲みます。 if (/^'/ !~ heading && /^\$/ !~ heading) heading = "'" + heading + "'" end code = "$endnote = " + heading eval code next end line = repthisfile(line) if $OPT_BACKQUOTE == true while %r!`(.*?)`! =~ line #` com = $1; str = `#{com}`.chomp; line.sub!(/`.*?`/, "#{str}") end end # 行の形だけですぐわかる構文のチェック(続き) # checkonlyform @vspace # # vspace code if /^[ \t]*@vspace{(.*)}/ =~ line next end # latex environment if /^([ ]*)@begin{latex}[- ]*$/ =~ line nb = $1.bytesize $envstack.endenv(nb); if $envstack.stkblline > 0; print "\n"; end $envstack.stkblline = 0; nline = $.; sline = line; line = $io.gets.detab while /^[ ]*@end{latex}[- ]*$/ !~ line line = $io.gets if !line || /^\*/ =~ line || /^(==|\*) (enddoc|enddic)/ =~ line STDERR.print "At line " + __LINE__.to_s + " of o2h.rb" + ": The region which started at line #{nline}:\n#{sline}met with the file end at line #{$.}.", "\n"; print "At line " + __LINE__.to_s + " of o2h.rb" + ": The region which started at line #{nline}:\n#{sline}met with the file end at line #{$.}.", "\n"; exit 1 end line.detab end next end # 行の形だけですぐわかる構文のチェック(続き) # checkonlyform :: # if /^([ ]+)::$/ =~ line nb = $1.bytesize $envstack.endlenv(nb) $fp.print "
" # $envstack.stkblline -= 1 # end # end # @end{Cmnted out at 20160425 22:40}------------------ bl = " " * $envstack.lastenv.indent $fp.print "" bgcolor = $default_panel_backcolor if /\bbgcolor: (\w+|#\w+)/ =~ spec || /\bbgc: (\w+|#\w+)/ =~ spec bgcolor = $1 end fontcolor = $fontcolor if fontcolor.bytesize == 0 fontcolor = $default_fontcolor end if /\bcolor: (\w+|#\w+)/ =~ specstring fontcolor = $1 end prefix = false prefixString = "" if /\bprefix: \"([^"]*?)\"/ =~ specstring prefix = true prefixString = Regexp.escape($1) if prefixString == "" prefix = false end end bstyle = "" if /^\w+$/ =~ specstring bstyle = specstring elsif /^(\w+) .*$/ =~ specstring bstyle = $1 end borderstyle = "border-style: solid solid solid solid; border-width: 1px 1px 1px 1px; " if bstyle == "solid" borderstyle = "border-style: solid solid solid solid; border-width: 1px 1px 1px 1px; " elsif bstyle == "dashed" borderstyle = "border:1px dashed; " elsif bstyle == "dotted" borderstyle = "border:1px dotted; " elsif bstyle == "double" borderstyle = "border:3px double; " end margin = " margin: 6px 0px 0px 0px;" if $caption.bytesize > 0 CodeTitle($caption) $fp.print "\n" nextline = $io.gets unless /^[ ]*$/ =~ nextline $io.pushback end $fp.print "\n" $endparagraph = true next end # 行の形だけですぐわかる構文のチェック(続き) # checkonlyform pre # if /^([ ]*)@begin{pre}[- ]*$/ =~ line nb = $1.bytesize $envstack.endenv(nb) bl = " " * $envstack.lastenv.indent if $envstack.stkblline > 0; $fp.print "\n"; end $envstack.stkblline = 0 $fp.print "
\n" $caption = "" margin = " margin: 6px 0px " end if $caponly.bytesize > 0 $fp.print "" + $caponly + "
\n"; $caponly = "" margin = " margin: 6px 0px " end if $endnote.bytesize > 0 margin = margin + " 6px 0px;" else margin = margin + " 0px 0px;" end fontcolor = $fontcolor $fp.print "" if $OPT_BROWSER == "chrome" $fp.print "0 if bgcolor != "null" $fp.print "background: " + bgcolor; end end $fp.print ";\">\n"; nline = $.; sline = line nw = nb nextline = $io.gets $io.pushback if /^([ ]*)[^ ].*$/ =~ nextline nk = $1.bytesize nw = nk if nk < nb end line = $io.gets.detab while /^#{" " * nb}*@end{panel#{subtitle}}[- ]*$/ !~ line line.sub!(/^#{" " * nw}/, "") if prefix line.sub!(/^#{prefixString}/, "") end $fp.print "", line.squoteline, "" line = $io.gets if !line || /^\*{1,5} / =~ line || /^(==|\*) (enddoc|enddic)/ =~ line rline = __LINE__.to_s FileendErrorMessageSearching(nline, sline, rline, "@end{panel#{subtitle}}") exit 1 end line.detab end $fp.print "\n"; if $endnote.bytesize > 0 $fp.print "\n"; $fp.print emacsfuncNoquote($endnote) $fp.print "
\n"; $endnote = "" end $fp.print "\n"; $fp.print "" $fp.print "\n\n\n" $endparagraph = true next end # 行の形だけですぐわかる構文のチェック(続き) # checkonlyform fpanel # # @begin{fpanel} # ... # @end{fpanel} # # の処理はここ。 if /^([ ]*)@begin{fpanel}{(.*?)}(| [-]+)$/ =~ line || /^([ ]*)@begin{fpanel}(| [-]+)$/ =~ line # # @begin{fpanel}{(.*)} ------------------------------- # spec = $1 # @end{fpanel#{subtitle}} ---------------------------- # # または # # @begin{fpanel} ------------------------------------- # spec = "" # @end{fpanel} --------------------------------------- # # の形。 # # fpanel 環境では行頭の空白はすべて削除した後に整形さ # れるので、@begin{fpanel} の前の字下げより、中味を左 # に突き出しても構いません。 # # @begin{fpanel} --------------------------------- # 左に突き出した # 文章でも問題なし。 # @end{fpanel} ----------------------------------- # if /^([ ]*)@begin{fpanel}{(.*?)}(| [-]+)$/ =~ line nb = $1.bytesize spec = $2 else /^([ ]*)@begin{fpanel}(| [-]+)$/ =~ line nb = $1.bytesize spec = "" end prepareSpecialenv(nb) bl = " " * $envstack.lastenv.indent $fp.print "\n"; nline = $.; sline = line nw = nb nextline = $io.gets $io.pushback if /^([ ]*)[^ ].*$/ =~ nextline nk = $1.bytesize nw = nk if nk < nb end line = $io.gets.detab while /^[ ]*@end{pre}[- ]*$/ !~ line # line.sub!(/^#{bl}/, "") line.sub!(/^#{" " * nw}/, "") $fp.print "", line.squoteline, "" line = $io.gets if !line || /^\*/ =~ line || /^(==|\*) (enddoc|enddic)/ =~ line STDERR.print "At line " + __LINE__.to_s + " of o2h.rb" + ": The region which started at line #{nline}:\n#{sline}met with the file end at line #{$.}.", "\n"; print "At line " + __LINE__.to_s + " of o2h.rb" + ": The region which started at line #{nline}:\n#{sline}met with the file end at line #{$.}.", "\n" exit 1 end line.detab end $fp.print "\n"; $fp.print "\n"; $fp.print "" bgcolor = $default_panel_backcolor if /bgcolor: (\w+|#\w+)/ =~ spec || /\bbgc: (\w+|#\w+)/ =~ spec bgcolor = $1 end prefix = false prefixString = "" if /\bprefix: \"([^"]*?)\"/ =~ spec prefix = true prefixString = Regexp.escape($1) if prefixString == "" prefix = false end end margin = " margin: 6px 0px " if $caption.bytesize > 0 CodeTitle($caption) $fp.print "\n\n\n" nextline = $io.gets unless /^[ ]*$/ =~ nextline $io.pushback end $endparagraph = true next end # 行の形だけですぐわかる構文のチェック(続き) # checkonlyform bgclor start # if /^([ ]*)@begin{bgcolor}{(.*)}[- ]*$/ =~ line nb = $1.bytesize option = $2 while $envstack.stkblline > 0 $fp.print "
\n" $caption = "" margin = " margin: 6px 0px " end if $caponly.bytesize > 0 $fp.print "" + $caponly + "
\n"; $caponly = "" margin = " margin: 6px 0px " end if $endnote.bytesize > 0 margin = margin + " 6px 0px;" else margin = margin + " 0px 0px;" end $fp.print "0 if bgcolor != "null" $fp.print "background: " + bgcolor; end end $fp.print ";\">\n"; nline = $.; sline = line line = $io.gets.detab while /^[ ]*@end{fpanel}[- ]*$/ !~ line if prefix line.sub!(/^#{prefixString}/, "") end if /^[ \t]*$/ =~ line $fp.print "
\n"; if $endnote.bytesize > 0 $fp.print "
\n" else /^([ ]*)[^ ]/ =~ line nbsp = $1.bytesize line.sub!(/^#{" " * nbsp}/, "") if line =~ /^[ -~。-゚]/; line = " " + line; end # [ -~] は半角文字、[。-゚] は半角カタカナにマッチ。 $fp.print line.chomp end line = $io.gets if !line || /^\*{1,5} / =~ line || /^(==|\*) (enddoc|enddic)/ =~ line rline = __LINE__.to_s FileendErrorMessageSearching(nline, sline, rline, "@end{fpanel}") exit 1 end line.detab end $fp.print "\n"; $fp.print emacsfuncNoquote($endnote) $fp.print "
\n"; $endnote = "" end $fp.print "
\n" $envstack.stkblline -= 1 end style = "" if /^color:[ ]+(\w+|#\w+)$/ =~ option style += "color: " + $1 + "; " elsif /^(\w+|#\w+)[ ]+color:[ ]+(\w+|#\w+)$/ =~ option style += "background-color: " + $1 + "; " style += "color: " + $2 + "; " else if /^(\w+|#\w+)/ =~ option style += "background-color: " + $1 + "; " end if /,[ ]*(\w+|#\w+)/ =~ option style += "color: " + $1 + "; " end end $fp.print "\n" next end # 行の形だけですぐわかる構文のチェック(続き) # checkonlyform bgclor start # if /^([ ]*)@begin{(bgcolor.*)}[- ]*$/ =~ line spec = $2 nb = $1.bytesize while $envstack.stkblline > 0 $fp.print "\n" $endparagraph = false $envstack.stkblline = 0 end next end if /^::$/ =~ line $envstack.endenv(0) $fp.print "
\n" $envstack.stkblline -= 1 end style = "" if /bgcolor:[ ]+color:[ ]+(\w+|#\w+)$/ =~ spec style += "color: " + $1 + "; " elsif /bgcolor:[ ]+(\w+|#\w+)[ ]+color:[ ]+(\w+|#\w+)$/ =~ spec style += "background-color: " + $1 + "; " style += "color: " + $2 + "; " elsif /bgcolor:[ ]+(.*)$/ =~ spec spec = $1 if /^(\w+|#\w+)/ =~ spec style += "background-color: " + $1 + "; " end if /,[ ]*(\w+|#\w+)/ =~ spec style += "color: " + $1 + "; " end end $fp.print "\n" next end # 行の形だけですぐわかる構文のチェック(続き) # checkonlyform bgcolor end # if /^([ ]*)@end{bgcolor}[- ]*$/ =~ line nb = $1.bytesize while $envstack.stkblline > 0 $fp.print "\n" else # $stkline が false ということは、詰め込みモードで # はなくて、処理が終わっているということ。 $fp.print "
\n" $envstack.stkblline -= 1 end # $fp.print "533942 " + $endparagraph.to_s if $stkline # $stkline が true ということは、詰め込みモードで、 # 処理が終わっていない書き込み行があるということで # す。 $fp.print "
\n" $envstack.stkblline = 0 $endparagraph = false $stkline = false $fp.print "
0 if bgcolor != "null" $fp.print "background: " + bgcolor; end end $fp.print ";\">\n"; nline = $.; sline = line nw = nb nextline = $io.gets $io.pushback if /^([ ]*)[^ ].*$/ =~ nextline nk = $1.bytesize nw = nk if nk < nb end line = $io.gets.detab while /^#{" " * nb},,[ ]*$/ !~ line and /^#{" " * nb},,[ ]+--*$/ !~ line and /^#{" " * nb},,[ ]+,,*$/ !~ line and /^#{" " * nb},,\.[ ]*$/ !~ line and /^#{" " * nb},,\.[ ]+,,*$/ !~ line and /^#{" " * nb}\.,,[ ]*$/ !~ line and /^#{" " * nb}\.,,[ ]+,,*$/ !~ line if /^=\*/ =~ line # 行頭に * があるのを回避するために、行頭に = を置い # たので元に戻している。 line.sub!(/^=/, "") end if /^([ ]*)[^ ].*$/ =~ line nk = $1.bytesize if nk > nw; nk = nw; end line.sub!(/^#{" " * nk}/, "") end $fp.print "", line.svquoteline, "" line = $io.gets if !line || /^\*{1,5} / =~ line || /^(==|\*) (enddoc|enddic)/ =~ line rline = __LINE__.to_s FileendErrorMessageSearching(nline, sline, rline, ",,.") exit 1 end line.detab end $fp.print ""; $fp.print "
の表示サイズは大きく異なる # ようです。 $fp.print "" if $OPT_BROWSER == "chrome" $fp.print "0 if bgcolor != "null" $fp.print "background: " + bgcolor; end end # $fp.print ";\">\n"; $fp.print ";\">"; nline = $.; sline = line nw = nb nextline = $io.gets $io.pushback if /^([ ]*)[^ ].*$/ =~ nextline nk = $1.bytesize nw = nk if nk < nb end line = $io.gets if !line || /^[\*]+[ ]/ =~ line || /^(==|\*) (enddoc|enddic)/ =~ line rline = __LINE__.to_s FileendErrorMessage(nline, sline, rline) exit 1 end line = line.detab while /^#{" " * nb},,,$/ !~ line && /^#{" " * nb},,, ,,*$/ !~ line && /^#{" " * nb},,, --*$/ !~ line && /^#{" " * nb},,,\.$/ !~ line && /^#{" " * nb},,,\. ,,*$/ !~ line && /^#{" " * nb},,,\. --*$/ !~ line && /^#{" " * nb}\.,,,$/ !~ line && /^#{" " * nb}\.,,, ,,*$/ !~ line && /^#{" " * nb}\.,,, --*$/ !~ line if /^=\*/ =~ line # 行頭に * があるのを回避するために、行頭に = を置い # たので元に戻している。 line.sub!(/^=/, "") end line.sub!(/^#{" " * nw}/, "") $fp.print "", line.svquoteline, "" line = $io.gets if !line || /^\*{1,5} / =~ line || /^(==|\*) (enddoc|enddic)/ =~ line rline = __LINE__.to_s FileendErrorMessageSearching(nline, sline, rline, ",,,.") exit 1 end line.detab end $fp.print "\n"; if $endnote.bytesize > 0 $fp.print "\n" $fp.print emacsfuncNoquote($endnote) $fp.print "\n" $endnote = "" end $fp.print "
0 if bgcolor != "null" $fp.print "background: " + bgcolor; end end $fp.print ";\">\n"; end emacsmode = false if /emacsmode/ =~ spec emacsmode = true end nline = $.; sline = line line = $io.gets.detab if proglistp num = $proglistnum # ブロックコメントの終わりを指定する行を読み飛ばします。 line = $io.gets.detab while /^[ ]*$/ =~ line line = $io.gets.detab end nextline = $io.gets.detab nextnextline = $io.gets.detab # num = linenumstart - 1 stockline = nil blankp = nil while /^[ ]*@end{#{regname}}[- ]*$/ !~ nextline unless proglistignore if stockline $fp.print "", stockline, "" end end if /^=\*/ =~ line # 行頭に * があるのを回避するために、行頭に = # を置いたので元に戻している。 line.sub!(/^=/, "") end line.sub!(/^#{" " * nb}/, "") if /^=\*/ =~ line # 行頭に * があるのを回避するために、行頭に = # を置いたので元に戻している。 line.sub!(/^=/, "") end if prefix line.sub!(/^#{prefixString}/, "") end if emacsmode line = emacsfunc(line) end unless proglistignore num += 1 blankp = (line =~ /^[ ]*$/) stockline = sprintf("%03d: ", num) + line.squoteline # $fp.print stockline end line = nextline nextline = nextnextline nextnextline = $io.gets if !nextnextline || /^== enddoc$/ =~ nextnextline || /^\* enddoc/ =~ nextnextline STDERR.print "At line " + __LINE__.to_s + " of o2h.rb" + ":The region which started ", "at line #{nline}:\n#{sline}met with the file end at line #{$.}.", "\n"; print "At line " + __LINE__.to_s + " of o2h.rb" + ": The region which started at line #{nline}", ":\n#{sline}met with the file end at line #{$.}.", "\n" exit 1 end nextnextline = nextnextline.detab end unless proglistignore if stockline if blankp $proglistnum = num - 1 else $fp.print stockline unless blankp $proglistnum = num end end end $underscoreContlinep = true else num = linenumstart - 1 nw = nb nextline = $io.gets $io.pushback if /^([ ]*)[^ ].*$/ =~ nextline nk = $1.bytesize nw = nk if nk < nb end while /^[ ]*@end{#{regname}}[- ]*$/ !~ line if /^=\*/ =~ line # 行頭に * があるのを回避するために、行頭に = # を置いたので元に戻している。 line.sub!(/^=/, "") end line.sub!(/^#{" " * nw}/, "") if /^=\*/ =~ line # 行頭に * があるのを回避するために、行頭に = # を置いたので元に戻している。 line.sub!(/^=/, "") end if prefix line.sub!(/^#{prefixString}/, "") end if emacsmode line = emacsfunc(line) end if linenum num += 1 $fp.print "", sprintf("%03d: ", num), line.squoteline, "" else $fp.print "", line.squoteline, "" end line = $io.gets if !line || /^\*{1,5} / =~ line || /^(==|\*) (enddoc|enddic)/ =~ line searchstring = "@end{vb}" FileendErrorMessageSearching(nline, sline, __LINE__.to_s, "@end{#{regname}}") exit 1 end line.detab end $underscoreContlinep = true end unless proglistignore $fp.print ""; $fp.print "\n"; end if $endnote.bytesize > 0 unless proglistignore $fp.print "
\n"; $fp.print emacsfuncNoquote($endnote) $fp.print "
\n"; end $endnote = "" end $fp.print "\n"; end nline = $.; sline = line line = $io.gets.detab if proglistp num = $proglistnum line = $io.gets.detab while /^[ ]*$/ =~ line line = $io.gets.detab end nextline = $io.gets.detab nextnextline = $io.gets.detab # num = linenumstart - 1 stockline = nil blankp = nil while /^[ ]*@end{code#{subtitle}}[- ]*$/ !~ nextline unless proglistignore if stockline $fp.print stockline end end if /^=\*/ =~ line # 行頭に * があるのを回避するために、行頭に = # を置いたので元に戻している。 line.sub!(/^=/, "") end line.sub!(/^#{" " * nb}/, "") if /^=\*/ =~ line # 行頭に * があるのを回避するために、行頭に = # を置いたので元に戻している。 line.sub!(/^=/, "") end if prefix line.sub!(/^#{prefixString}/, "") end if emacsmode line = emacsfunc(line) end unless proglistignore num += 1 blankp = (line =~ /^[ ]*$/) stockline = sprintf("%03d: ", num) + line.squoteline # $fp.print stockline end line = nextline nextline = nextnextline nextnextline = $io.gets if !nextnextline || /^== enddoc$/ =~ nextnextline || /^\* enddoc/ =~ nextnextline STDERR.print "At line " + __LINE__.to_s + " of o2h.rb" + ": The region which started ", "at line #{nline}:\n#{sline}met with the file end.", "\n"; print "At line " + __LINE__.to_s + " of o2h.rb" + ":The region which started at line #{nline}", ":\n#{sline}met with the file end at line #{$.}.", "\n" exit 1 end nextnextline = nextnextline.detab end unless proglistignore if stockline if blankp $proglistnum = num - 1 else $fp.print stockline unless blankp $proglistnum = num end end end $underscoreContlinep = true else num = linenumstart - 1 while /^[ ]*$/ =~ line line = $io.gets.detab end # コード本体が左に飛び出ていないか判断します。 nw = nb nextline = $io.gets $io.pushback if /^([ ]*)[^ ].*$/ =~ nextline nk = $1.bytesize nw = nk if nk < nb end while /^[ ]*@end{code#{subtitle}}[- ]*$/ !~ line # $endnote を付加できるようにします。 # そう思ったけど止め。 # @begin{Cmnted out at 20160425 21:49}------------ # if /^[ ]*;;;[ ]*@\(%h?\)\s+(\$endnote = .*)$/ =~ line # code = $1 # eval code # else # @end{Cmnted out at 20160425 21:49}-------------- line.sub!(/^#{" " * nw}/, "") if /^=\*/ =~ line # 行頭に * があるのを回避するために、行頭に # = を置いたので元に戻している。 line.sub!(/^=/, "") end if prefix line.sub!(/^#{prefixString}/, "") end if linenum num += 1 $fp.print "", sprintf("%03d: ", num), line.squoteline, "" else $fp.print "", line.squoteline, "" end # @begin{Cmnted out at 20160425 21:50}------------ # end # @end{Cmnted out at 20160425 21:50}-------------- line = $io.gets if !line || /^\*{1,5} / =~ line || /^(==|\*) (enddoc|enddic)/ =~ line rline = __LINE__.to_s FileendErrorMessageSearching(nline, sline, __LINE__.to_s, "@end{code#{subtitle}}") exit 1 end line.detab end $underscoreContlinep = true end unless (proglistp && $OPT_PROGLISTIGNORE) $fp.print "\n"; end $fontcolor = $default_fontcolor unless proglistignore if $endnote.bytesize > 0 $fp.print "
\n"; $fp.print emacsfuncNoquote($endnote) $fp.print "
\n"; $endnote = "" $endparagraph = true end $fp.print "\n"; $envstack.stkblline =0 end # ---------------------------------------------------- # ここまでは、最初の見出し行を読み込む前でした。 # # $envstack.level が 0 の間は、目次を作成する必要は # ありませんでした。 # # ここで最初の見出し行が読み込まれたので、これから目次を # 作成することも考慮しながら解析していく必要があります。 # # これまでは、$fp は $fabst として要約を書き出すのに # 使用されました。 # # これからは、$fp は $fbody を指し、本文部分を整 # 形して html コードにしたものを書き出すときに使用 # します。 # # 本文を解析しながら、見出し行を読み込んだときに、$findx # の目次ファイルに目次行の html コードを書き出します。 # # $OPT_NOCONTENTS が true でも、目次ファイルを作成します。 # 最後に全体をまとめた html ファイルを作成するときに、 # $OPT_NOCONTENTS が true なら、目次ファイルのデータ # を無視します。 # # 目次の部分には、 # # ... #
\n"; nw = nb nextline = $io.gets $io.pushback if /^([ ]*)[^ ].*$/ =~ nextline nk = $1.bytesize nw = nk if nk < nb end nline = $.; sline = line line = $io.gets.detab while /^#{" " * nb}-$/ !~ line and /^#{" " * nb}-\.$/ !~ line and /^#{" " * nb}- --*$/ !~ line and /^#{" " * nb}-\. --*$/ !~ line line.sub!(/^#{" " * nw}/, "") $fp.print "", line.squoteline, "" line = $io.gets if !line || /^\*{1,5} / =~ line || /^(==|\*) (enddoc|enddic)/ =~ line rline = __LINE__.to_s FileendErrorMessage(nline, sline, rline) exit 1 end line.detab end $fp.print "\n"; if $endnote.bytesize > 0 $fp.print "" fpprintTableline(0,$endnote) $fp.print "\n"; $endnote = "" end # $fp.print "\n"; $fp.print "
0 if bgcolor != "null" $fp.print "background: " + bgcolor; end end $fp.print ";\">\n"; nline = $.; sline = line nw = nb nextline = $io.gets $io.pushback if /^([ ]*)[^ ].*$/ =~ nextline nk = $1.bytesize nw = nk if nk < nb end line = $io.gets.detab while (/^#{" " * nb}---[.]?$/ !~ line) and (/^#{" " * nb}---[.]? --*$/ !~ line) line.sub!(/^#{" " * nw}/, "") $fp.print "", line.squoteline, "" line = $io.gets if !line || /^\*{1,5} / =~ line || /^(==|\*) (enddoc|enddic)/ =~ line rline = __LINE__.to_s FileendErrorMessage(nline, sline, rline) exit 1 end line.detab end $fp.print "\n"; if $endnote.bytesize > 0 $fp.print "" $fp.print emacsfuncNoquote($endnote) $fp.print "\n"; $endnote = "" end $fp.print "\n"; $fp.print "
0 && bgcolor != "null" $fp.print "background: " + bgcolor; end $fp.print ";\">\n"; nline = $.; sline = line line = $io.gets.detab while (/^#{" " * nb}--\.$/ !~ line) and (/^#{" " * nb}--. --*$/ !~ line) line.sub!(/^#{" " * nb}/, "") $fp.print line.squoteline line = $io.gets if !line || /^\*{1,5} / =~ line || /^(==|\*) (enddoc|enddic)/ =~ line rline = __LINE__.to_s FileendErrorMessage(nline, sline, rline) exit 1 end line.detab end $fp.print "\n"; if $endnote.bytesize > 0 $fp.print "" $fp.print emacsfuncNoquote($endnote) $fp.print "\n"; $endnote = "" end $fp.print "\n"; $fp.print "
\n"; nline = $.; sline = line line = $io.gets.detab nw = nb nextline = $io.gets $io.pushback if /^([ ]*)[^ ].*$/ =~ nextline nk = $1.bytesize nw = nk if nk < nb end # $fp.print "debug: #{line}\n" while /^#{" " * nb}[-]{20,}[.]?[ ]*$/ !~ line if /^=\*/ =~ line # 行頭に * があるのを回避するために、行頭に # = を置いたので元に戻している。 line.sub!(/^=/, "") end line.sub!(/^#{" " * nw}/, "") $fp.print "", line.squoteline, "" line = $io.gets if !line || /^\*{1,5} / =~ line || /^(==|\*) (enddoc|enddic)/ =~ line rline = __LINE__.to_s FileendErrorMessage(nline, sline, rline) exit 1 end line.detab end $fp.print ""; $fp.print "
\n"; else $fp.print "
#{$zenkakukuhaku} | " # $fp.print "#{$zenkakukuhaku}. | " col = 0 if /^[ ]*[-+]{20,}[.]?$/ =~ line # $fp.print line, "\n" line.gsub!(/-\+-/, " : ") # $fp.print line, "\n" line.squoteline.chomp.split(" : ").each do |x| position = tabinfo[col] if col == 0 case position when ?c $fp.print "" when ?r $fp.print " | " else $fp.print " | " end else case position when ?c $fp.print " | -" when ?r $fp.print " | -" else $fp.print " | -" end end $fp.print x, " | " col += 1 end else line.squoteline.chomp.split(" : ").each do |x| position = tabinfo[col] if /\[([^\]]+)\]/ =~ x position = ?c; x = $1; elsif /\[([^)]+)\)/ =~ x position = ?l; x = $1; elsif /\(([^\]]+)\]/ =~ x position = ?r; x = $1; end if col == 0 case position when ?c $fp.print "" when ?r $fp.print " | " else $fp.print " | " end else case position when ?c $fp.print " | " when ?r $fp.print " | " else $fp.print " | " end end $fp.print x, " | " col += 1 end end $fp.print "
\n"; else $fp.print "
#{mark} | \n" $fp.print "#{string}"
ideflist = 1
else
/^[ ]*([^ ].*[^ ])[ ]*$/ =~ line
$fp.print $1, "\n"
end
line = $io.gets
if !line || /^\*/ =~ line || /^(==|\*) (enddoc|enddic)/ =~ line
STDERR.print "At line " + __LINE__.to_s + " of o2h.rb" + ": The region which started at line #{nline}:\n#{sline}met with the file end at line #{$.}.", "\n";
print "At line " + __LINE__.to_s + " of o2h.rb" + ": The region which started at line #{nline}:\n#{sline}met with the file end at line #{$.}.", "\n"
exit 1
end
line.detab
end
if $OPT_W3M
$fp.print " " $fp.print "\n"; $fp.print "\n"; else $fp.print " |
\n"; nline = $.; sline = line nw = nb nextline = $io.gets $io.pushback if /^([ ]*)[^ ].*$/ =~ nextline nk = $1.bytesize nw = nk if nk < nb end line = $io.gets.detab while /^[ ]*@end{#{midashi}}[- ]*$/ !~ line if /^=\*/ =~ line # 行頭に * があるのを回避するために、行頭に = を置い # たので元に戻している。 line.sub!(/^=/, "") end line.sub!(/^#{" " * nw}/, "") $fp.print line.squoteline line = $io.gets if !line || /^\*{1,5} / =~ line || /^(==|\*) (enddoc|enddic)/ =~ line FileendErrorMessageSearching(nline, sline, __LINE__.to_s, "@end{#{midashi}}") exit 1 end line.detab end $fp.print "\n"; if $endnote.bytesize > 0 if $OPT_BROWSER == "chrome" $fp.print "
";
$fp.print ""
$fp.print emacsfuncNoquote($endnote)
$fp.print "\n";
$fp.print "
\n";
$endnote = ""
end
$fp.print "\n";
$fp.print "Select sjis if the characters are not shown properly. Google chrome is the targetted browser.\n"; else print "
Select sjis if the characters are not shown properly. Internet Expolorer is the targetted browser.\n"; end if $envstack.title == "No Title" then $envstack.title = "" end if $OPT_NOTITLE then $envstack.title = "" end print "