.. 10-system .. _label10: 10. システム関数 ================================== .. _label10.1: 10.1 ファイル名 ---------------------------------- .. index:: single: file() single: dir() .. _label10.1.1: 10.1.1 file, dir ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(file sequence) : File Sequence sequence : Sequence $(dir sequence) : Dir Sequence sequence : Sequence .. The file and dir functions define location-independent references to files and directories. In omake, the commands to build a target are executed in the target's directory. Since there may be many directories in an omake project, the build system provides a way to construct a reference to a file in one directory, and use it in another without explicitly modifying the file name. The functions have the following syntax, where the name should refer to a file or directory. ``file`` と ``dir`` 関数はomakeが動く場所に依存しない、ファイルとディレクトリの位置を定義します。omakeでは、ターゲットをビルドするコマンドはターゲット上のディレクトリにて実行されます。プロジェクト中には多くのディレクトリが存在するため、omakeではあるディレクトリ上のファイルを確実に指定する方法が存在します。これにより、たとえ別のディレクトリ上に移動したとしても、明示的にパスを修正せずに特定のファイルを指定することができます。 ``file`` , ``dir`` 関数は以下のように用いることで、ディレクトリやファイルのパスが関連付けられます。 .. For example, we can construct a reference to a file foo in the current directory. 例えば、カレントディレクトリ中でファイル ``foo`` を示す変数を作ったとしましょう。 :: FOO = $(file foo) .SUBDIRS: bar .. If the FOO variable is expanded in the bar subdirectory, it will expand to ../foo. ``FOO`` 変数が ``bar`` サブディレクトリ中で展開された場合、これは ``../foo`` と展開されます。 .. These commands are often used in the top-level OMakefile to provide location-independent references to top-level directories, so that build commands may refer to these directories as if they were absolute. これらのコマンドはトップレベルのディレクトリを確実に指定するために、トップレベルのOMakefileにてしばしば用いられます。よって、ビルドコマンドはこれらのディレクトリを、まるで絶対パスで表しているのように扱うことができます。 :: ROOT = $(dir .) LIB = $(dir lib) BIN = $(dir bin) .. Once these variables are defined, they can be used in build commands in subdirectories as follows, where $(BIN) will expand to the location of the bin directory relative to the command being executed. これらの変数はいったん定義されたらサブディレクトリ中でもビルドコマンドに使うことができるので、下の ``$(BIN)`` はコマンドが実行されたディレクトリに関連付けられた ``bin`` ディレクトリで展開されます。 :: install: hello cp hello $(BIN) .. index:: single: tmpfile() .. _label10.1.2: 10.1.2 tmpfile ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(tmpfile prefix) : File $(tmpfile prefix, suffix) : File prefix : String suffix : String .. The tmpfile function returns the name of a fresh temporary file in the temporary directory. ``tmpfile`` 関数は一時的なディレクトリ中にある、一時的な空のファイル名を返します。 .. index:: single: in() .. _label10.1.3: 10.1.3 in ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(in dir, exp) : String Array dir : Dir exp : expression .. The in function is closely related to the dir and file functions. It takes a directory and an expression, and evaluates the expression in that effective directory. For example, one common way to install a file is to define a symbol link, where the value of the link is relative to the directory where the link is created. ``in`` 関数は ``dir`` や ``file`` 関数と密接に関係しています。ディレクトリとファイル名を指定することで、ディレクトリ上からのファイルの位置を返します。例えば、ファイルをインストールするためによく使われる方法の一つとしてシンボリックリンクを定義することで、その値は特定のディレクトリに関連付けられているものとします。 .. The following commands create links in the $(LIB) directory. 以下のコマンドでは ``$(LIB)`` ディレクトリ中でリンクを生成しています。 :: FOO = $(file foo) install: ln -s $(in $(LIB), $(FOO)) $(LIB)/foo .. Note that the in function only affects the expansion of Node (File and Dir) values. .. note:: ``in`` 関数は ``Node`` ( ``File`` と ``Dir`` )が与えられた場合のみに評価を行います。 .. index:: single: basename() .. _label10.1.4: 10.1.4 basename ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(basename files) : String Sequence files : String Sequence .. The basename function returns the base names for a list of files. The basename is the filename with any leading directory components removed. ``basename`` 関数は引数に指定されたファイルのリストから元のファイル名のみを返します。任意のディレクトリパスは除去されます。 .. For example, the expression $(basename dir1/dir2/a.out /etc/modules.conf /foo.ml) evaluates to a.out modules.conf foo.ml. 例えば、式 ``$(basename dir1/dir2/a.out /etc/modules.conf /foo.ml)`` は ``a.out modules.conf foo.ml`` と評価されます。 .. index:: single: dirname() .. _label10.1.5: 10.1.5 dirname ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(dirname files) : String Sequence files : String Sequence .. The dirname function returns the directory name for a list of files. The directory name is the filename with the basename removed. If a name does not have a directory part, the directory is “.” ``dirname`` 関数は引数に指定されたファイルのリストからディレクトリ名を返します。任意のファイル名は除去されます。もしディレクトリ部分が指定されていない場合は、"."が変えされます。 .. For example, the expression $(dirname dir1\dir2\a.out /etc/modules.conf /foo.ml bar.ml) evaluates to dir1/dir2 /etc / .. 例えば、式 ``$(dirname dir1\dir2\a.out /etc/modules.conf /foo.ml bar.ml)`` は ``dir1/dir2 /etc / .`` と評価されます。 .. Note: this function is different from the dirof function. The function dirname is simple a function over strings, while dirof is a function on filenames. .. note:: この関数は ``dirof`` 関数と異なります。 ``dirname`` 関数は単純に文字列のシーケンスを解析して返すのに対し、 ``dirof`` は ``File`` オブジェクトを解析する関数です。 .. index:: single: rootname() .. _label10.1.6: 10.1.6 rootname ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(rootname files) : String Sequence files : String Sequence .. The rootname function returns the root name for a list of files. The rootname is the filename with the final suffix removed. ``rootname`` 関数は引数に指定されたファイルのリストから基底の名前を返します。ここでの『基底の名前』とは拡張子が除去されたファイル名のことです。 .. For example, the expression $(rootname dir1/dir2/a.out /etc/a.b.c /foo.ml) evaluates to dir1/dir2/a /etc/a.b /foo. 例えば、式 ``$(rootname dir1/dir2/a.out /etc/a.b.c /foo.ml)`` は ``dir1/dir2/a /etc/a.b /foo`` と評価されます。 .. index:: single: dirof() .. _label10.1.7: 10.1.7 dirof ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(dirof files) : Dir Sequence files : File Sequence .. The dirof function returns the directory for each of the listed files. ``dirof`` 関数は引数に指定されたファイルのリストからディレクトリを返します。 .. For example, the expression $(dirof dir/dir2/a.out /etc/modules.conf /foo.ml) evaluates to the directories dir1/dir2 /etc /. 例えば、式 ``$(dirof dir/dir2/a.out /etc/modules.conf /foo.ml)`` は ``dir1/dir2 /etc /`` と評価されます。 .. index:: single: fullname() .. _label10.1.8: 10.1.8 fullname ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(fullname files) : String Sequence files : File Sequence .. The fullname function returns the pathname relative to the project root for each of the files or directories. ``fullname`` 関数は指定した各々のファイルやディレクトリの、プロジェクトルートを元にしたパスを返します。 .. note:: 訳注:このような動きをします。 :: % a = foo/bar - : "foo/bar" : Sequence % b = $(fullname $a) - : : String .. index:: single: absname() .. _label10.1.9: 10.1.9 absname ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(absname files) : String Sequence files : File Sequence .. The absname function returns the absolute pathname for each of the files or directories. ``absname`` 関数は指定した各々のファイルやディレクトリの絶対パスを返します。 .. index:: single: homename() .. _label10.1.10: 10.1.10 homename ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(homename files) : String Sequence files : File Sequence .. The homename function returns the name of a file in tilde form, if possible. The unexpanded forms are computed lazily: the homename function will usually evaluate to an absolute pathname until the first tilde-expansion for the same directory. ``homename`` 関数は可能であればチルダ~を用いてパス名を返します。展開できない形のパスは遅延的に計算されます。具体的にいうと、 ``homename`` 関数は通常、始めてチルダ型のパスとして展開できるようになるまでは、絶対パスとして評価します。 .. index:: single: suffix() .. _label10.1.11: 10.1.11 suffix ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(suffix files) : String Sequence files : StringSequence .. The suffix function returns the suffixes for a list of files. If a file has no suffix, the function returns the empty string. ``suffix`` 関数はファイルのリストから拡張子を返します。もし拡張子が存在しなかった場合、空の文字列が返されます。 .. For example, the expression $(suffix dir1/dir2/a.out /etc/a /foo.ml) evaluates to .out .ml. 例えば、式 ``$(suffix dir1/dir2/a.out /etc/a /foo.ml)`` は ``.out .ml`` と評価されます。 .. _label10.2: 10.2 パスによる検索 ---------------------------------- .. index:: single: which() .. _label10.2.1: 10.2.1 which ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(which files) : File Sequence files : String Sequence .. The which function searches for executables in the current command search path, and returns file values for each of the commands. It is an error if a command is not found. ``which`` 関数は現在のコマンド検索パスから実行可能なものを検索し、引数に指定されたコマンドのファイルパスを返します。もしコマンドが見つからない場合にはエラーが発生します。 .. index:: single: where() .. _label10.2.2: 10.2.2 where ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. The where function is similar to which, except it returns the list of all the locations of the given executable (in the order in which the corresponding directories appear in $PATH). In case a command is handled internally by the Shell object, the first string in the output will describe the command as a built-in function. ``where`` 関数は ``which`` 関数と似ていますが、この関数は与えられた実行コマンドのすべての位置をリストとして返します。この場合ですと ``echo`` コマンドは ``Shell`` オブジェクトによって内的に扱われるので、出力先の最初の文字列ではビルドイン関数として扱われていることを表しています。 :: % where echo echo is a Shell object method (a built-in function) /bin/echo .. index:: single: rehash() .. _label10.2.3: 10.2.3 rehash ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :: rehash() .. The rehash function resets all search paths. ``rehash`` 関数はすべての検索パスをリセットします。 .. index:: single: exists-in-path() .. _label10.2.4: 10.2.4 exists-in-path ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(exists-in-path files) : String files : String Sequence .. The exists-in-path function tests whether all executables are present in the current search path. ``exists-in-path`` 関数は引数に指定されたすべてのコマンドが、現在の検索パス上に存在しているかどうか試します。 .. index:: single: digest() single: digest-optional() .. _label10.2.5: 10.2.5 digest, digest-optional ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(digest files) : String Array file : File Array raises RuntimeException $(digest-optional files) : String Array file : File Array .. The digest and digest-optional functions compute MD5 digests of files. The digest function raises an exception if a file does no exist. The digest-optional returns false if a file does no exist. MD5 digests are cached. ``digest`` と ``digest-optional`` 関数はファイルのMD5を計算します。 ``digest`` 関数はファイルが存在しない場合には例外を送出します。一方で、 ``digest-optional`` はこの様な場合 ``false`` を返します。また、MD5はキャッシュされます。 .. index:: single: find-in-path() single: find-in-path-optional() .. _label10.2.6: 10.2.6 find-in-path, find-in-path-optional ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(find-in-path path, files) : File Array path : Dir Array files : String Array raises RuntimeException $(find-in-path-optional path, files) : File Array .. The find-in-path function searches for the files in a search path. Only the tail of the filename is significant. The find-in-path function raises an exception if the file can't be found. The find-in-path-optional function silently removes files that can't be found. ``file-in-path`` 関数は指定されたパスから指定されたファイルを検索します。これらの関数はファイル名が一致した場合のみが処理対称になります(訳注: 一部ではない)。 ``find-in-path`` 関数はファイルが見つからない場合には例外を送出します。一方で、 ``find-in-path-optional`` 関数はこの様な場合、例外を送出せずに結果から取り除かれます。 .. index:: single: digest-in-path() single: digest-in-path-optional() .. _label10.2.7: 10.2.7 digest-in-path, digest-in-path-optional ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(digest-in-path path, files) : String/File Array path : Dir Array files : String Array raises RuntimeException $(digest-in-path-optional path, files) : String/File Array .. The digest-in-path function searches for the files in a search path and returns the file and digest for each file. Only the tail of the filename is significant. The digest-in-path function raises an exception if the file can't be found. The digest-in-path-optional function silently removes elements that can't be found. ``diget-in-path`` 関数は指定されたパスからファイルを検索し、各々のファイルのファイルパスとMD5を返します。これらの関数はファイル名が一致した場合のみが処理対称になります。 ``digest-in-path`` 関数はファイルが見つからない場合には例外を送出します。一方で、 ``digest-in-path-optional`` 関数はこの様な場合、例外を送出せずに結果から取り除かれます。 .. _label10.3: 10.3 ファイル検査 ---------------------------------- .. index:: single: file-exists() single: target-exists() single: target-is-proper() .. _label10.3.1: 10.3.1 file-exists, target-exists, target-is-proper ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(file-exists files) : String $(target-exists files) : String $(target-is-proper files) : String files : File Sequence .. The file-exists function checks whether the files listed exist. The target-exists function is similar to the file-exists function. However, it returns true if the file exists or if it can be built by the current project. The target-is-proper returns true only if the file can be generated in the current project. ``file-exists`` 関数はリストされているファイルが存在しているかどうか調べます。 ``target-exists`` 関数は ``file-exists`` と似ていますが、この関数はファイルが存在するか、現在のプロジェクトでターゲットとなっているような場合に ``true`` を返します。 ``target-is-proper`` 関数は指定されたファイルが現在のプロジェクトで生成できる場合のみ ``true`` を返します。 .. index:: single: stat-reset() .. _label10.3.2: 10.3.2 stat-reset ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(stat-reset files) : String files : File Sequence .. OMake uses a stat-cache. The stat-reset function reset the stat information for the given files, forcing the stat information to be recomputed the next time it is requested. OMakeでは ``Stat`` によるキャッシュを行っています。 ``stat-reset`` 関数は ``stat`` から指定されたファイルの情報をリセットし、次これらの情報が要求された場合には ``stat`` 情報が強制的に再計算されます。 .. index:: single: filter-exists() single: filter-targets() single: filter-proper-targets() .. _label10.3.3: 10.3.3 filter-exists, filter-targets, filter-proper-targets ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(filter-exists files) : File Sequence $(filter-targets files) : File Sequence $(filter-proper-targets) : File Sequence files : File Sequence .. The filter-exists, filter-targets, and filter-proper-targets functions remove files from a list of files. ``filter-exists`` , ``filter-targets`` , ``filter-proper-targets`` 関数は指定されたファイルのリストをフィルタリングして、特定のファイルのみを返します。 .. * filter-exists: the result is the list of files that exist. * filter-targets: the result is the list of files either exist, or can be built by the current project. * filter-proper-targets: the result is the list of files that can be built in the current project. * ``filter-exists`` : 存在しているファイルのリストのみが結果として返されます。 * ``filter-targets`` : ファイルが存在しているか、現在のプロジェクト上でビルドできるような場合は結果として返されます。 * ``filter-proper-targets`` : 現在のプロジェクトでビルドできるファイルのリストのみが結果として返されます。 "distclean" ターゲットを作る """""""""""""""""""""""""""""""""""""""" .. One way to create a simple “distclean” rule that removes generated files from the project is by removing all files that can be built in the current project. プロジェクトによって生成されたファイルを消去する ``distclean`` ルールを作るような場合に、一つの簡単な方法が存在します。それは、現在のプロジェクトでビルドすることのできるすべてのファイルを消去することです。 .. CAUTION: you should be careful before you do this. The rule removes any file that can potentially be reconstructed. There is no check to make sure that the commands to rebuild the file would actually succeed. Also, note that no file outside the current project will be deleted. .. warning:: この方法を何も考えずに実行するのではなく、慎重に考えてください。このルールはプロジェクトで作られるであろう *すべてのファイル* を消去してしまいます。言いかえると、この方法は消去されたファイルのリビルドが成功するかどうかについては、まったく考慮していません。また、この方法では現在のプロジェクトの外にあるファイルは消去されません。 :: .PHONY: distclean distclean: rm $(filter-proper-targets $(ls R, .)) .. If you use CVS, you may wish to utilize the cvs_realclean program that is distributed with OMake in order to create a “distclean” rule that would delete all the files thare are not known to CVS. For example, if you already have a more traditional “clean” target defined in your project, and if you want the “distclean” rule to be interactive by default, you can write the following: もしあなたがCVSを用いているのであれば、CVSに知らせずにすべてのファイルを消去する ``distclean`` ルールを作るのではなく、OMakeによって作られた ``cvs_realclean`` プログラムを作りたいと思うことでしょう。例えば、もしあなたが既によく使われている ``clean`` ターゲットを作っていたのなら、そしてあなたが ``distclean`` ルールをデフォルトでインタラクティブなものにしたいのであれば、以下のように記述することができます。 :: if $(not $(defined FORCE_REALCLEAN)) FORCE_REALCLEAN = false export distclean: clean cvs_realclean $(if $(FORCE_REALCLEAN), -f) -i .omakedb -i .omakedb.lock .. You can add more files that you want to always keep (such as configuration files) with the -i option. あなたは ``-i`` オプションを用いることで、いつでも保持していたいより多くのファイル(設定ファイルなど)を追加することができます。 .. Similarly, if you use Subversion, you utilize the build/svn_realclean.om script that comes with OMake: 同様に、Subversionを使っていた場合、OMakeでは ``build/svn_realclean.om`` スクリプトを用いて以下のように記述できます。 :: if $(not $(defined FORCE_REALCLEAN)) FORCE_REALCLEAN = false export open build/svn_realclean distclean: clean svn_realclean $(if $(FORCE_REALCLEAN), -f) -i .omakedb -i .omakedb.lock .. See also the dependencies-proper function for an alternate method for removing intermediate files. 中間ファイルを除去する別の方法についての詳細は、 ``dependencies-proper`` 関数を参照してください。 .. index:: single: find-targets-in-path() single: find-targets-in-path-optional() .. _label10.3.4: 10.3.4 find-targets-in-path, find-targets-in-path-optional ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(find-targets-in-path path files) : File Array $(find-targets-in-path-optional path, files) : File Array path : Dir Array files : File Sequence .. The find-target-in-path function searches for targets in the search path. For each file file in the file list, the path is searched sequentially for a directory dir such that the target dir/file exists. If so, the file dir/file is returned. ``find-target-in-path`` 関数はパス上のターゲットを検索します。指定された各々の ``file`` はディレクトリ ``dir`` を順番に検索していき、もしターゲット ``dir/file`` が存在していた場合はファイル ``dir/file`` が返されます。 .. For example, suppose you are building a C project, and project contains a subdirectory src/ containing only the files fee.c and foo.c. The following expression evaluates to the files src/fee.o src/foo.o even if the files have not already been built. 例えば、あなたはCのプロジェクトをビルドしようとしており、そのプロジェクトはサブディレクトリ ``src/`` を含んでおり、その中には ``fee.c`` と ``foo.c`` が含まれているものとしましょう。そのような場合、以下の式はたとえそのファイルが存在していなくても、 ``src/fee.o src/foo.o`` と評価されます。 :: $(find-targets-in-path lib src, fee.o foo.o) # このように評価されます。 src/fee.o src/foo.o .. The find-targets-in-path function raises an exception if the file can't be found. The find-targets-in-path-optional function silently removes targets that can't be found. ``find-targets-in-path`` 関数はファイルが見つからない場合には例外を送出します。一方で、 ``find-targets-in-path-optional`` 関数はこの様な場合、例外を送出せずに結果から取り除かれます。 :: $(find-targets-in-path-optional lib src, fee.o foo.o fum.o) # このように評価されます。 src/fee.o src/foo.o .. index:: single: find-ocaml-targets-in-path-optional() .. _label10.3.5: 10.3.5 find-ocaml-targets-in-path-optional ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. The find-ocaml-targets-in-path-optional function is very similar to the find-targets-in-path-optional one, except an OCaml-style search is used, where for every element of the search path and for every name being searched for, first the uncapitalized version is tried and if it is not buildable, then the capitalized version is tried next. ``find-ocaml-targets-in-path-optional`` 関数は ``find-targets-in-path-optional`` と似ていますが、この関数はパス上のすべての成分と名前を検索し、最初に小文字のバージョンがビルド可能であるか調べた後で、大文字のバージョンがビルド可能であるか調べる、OCamlスタイルの検索が使われます。 .. index:: single: file-sort() .. _label10.3.6: 10.3.6 file-sort ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(file-sort order, files) : File Sequence order : String files : File Sequence .. The file-sort function sorts a list of filenames by build order augmented by a set of sort rules. Sort rules are declared using the .ORDER target. The .BUILDORDER defines the default order. ``file-sort`` 関数はソートルールの集合を用いてビルドのソート順を指定することで、ファイル名のリストをソートします。ソートルールは ``.ORDER`` ターゲットを用いて宣言できます。 ``.BUILDORDER`` は通常のソート順が定義されています。 :: $(file-sort , ) .. For example, suppose we have the following set of rules. 例えば、以下のようなルールの集合を考えてみましょう。 :: a: b c b: d c: d .DEFAULT: a b c d echo $(file-sort .BUILDORDER, a b c d) .. In the case, the sorter produces the result d b c a. That is, a target is sorted after its dependencies. The sorter is frequently used to sort files that are to be linked by their dependencies (for languages where this matters). このような場合、 ``file-sort`` 関数の結果は ``d b c a`` となります。これは依存関係が生成した *後で* ターゲットがソートされることを表しています。この関数は依存関係がリンクされてあるファイルをソートする際(依存関係が問題となってくる言語を扱う場合)、頻繁に用いられます。 .. There are three important restrictions to the sorter: この関数は3つの重要な制約があります。 .. * The sorter can be used only within a rule body. The reason for this is that all dependencies must be known before the sort is performed. * The sorter can only sort files that are buildable in the current project. * The sorter will fail if the dependencies are cyclic. * この関数はルールの内容だけを使ってソートします。理由としては、ソートを実行する前に *すべての* 依存関係を知っておかなければならないからです。 * この関数は現在のプロジェクトでビルド可能なファイルのみをソートします。 * この関数は依存関係が輪状(cyclic)になっている場合、失敗します。 .. _label10.3.6.1: 10.3.6.1 ソートルール """"""""""""""""""""""""""""""""""" .. It is possible to further constrain the sorter through the use of sort rules. A sort rule is declared in two steps. The target must be listed as an .ORDER target; and then a set of sort rules must be given. A sort rule defines a pattern constraint. ソートルールを使用することで、 ``file-sort`` 関数にさらなる制限を加えることができます。ソートルールは2つの手順を用いて宣言します。まず、ターゲットは ``.ORDER`` ターゲットに加えなければなりません。次に、ソートルールの集合が与えられていなければなりません。ソートルールには制限を定義します。 :: .ORDER: .MYORDER .MYORDER: %.foo: %.bar .MYORDER: %.bar: %.baz .DEFAULT: a.foo b.bar c.baz d.baz echo $(sort .MYORDER, a.foo b.bar c.baz d.baz) .. In this example, the .MYORDER sort rule specifies that any file with a suffix .foo should be placed after any file with suffix .bar, and any file with suffix .bar should be placed after a file with suffix .baz. この例では、 ``.MYORDER`` ソートルールは、拡張子 ``.foo`` の任意のファイルは拡張子 ``.bar`` の任意のファイルの後に置く必要があり、さらに拡張子 ``.bar`` の任意のファイルは拡張子 ``.baz`` の任意のファイルの後に置く必要があることを指定しています。 .. In this example, the result of the sort is d.baz c.baz b.bar a.foo. この例では、ソート結果は ``d.baz c.baz b.bar a.foo`` となります。 .. index:: single: file-check-sort() .. _label10.3.7: 10.3.7 file-check-sort ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :: file-check-sort(files) files : File Sequence raises RuntimeException .. The file-check-sort function checks whether a list of files is in sort order. If so, the list is returned unchanged. If not, the function raises an exception. ``file-check-sort`` 関数はファイルのリストがソート順になっているかどうか調べます。もしそうならば、リストは変更されずに返されます。そうでない場合は、この関数は例外を送出します。 :: $(file-check-sort , ) .. _label10.4: 10.4 ファイルの検索とリスト ---------------------------------- .. OMake commands are “glob-expanded” before being executed. That is, names may contain patterns that are expanded to sequences of file and directory names. The syntax follows the standard bash(1), csh(1), syntax, with the following rules. OMakeのコマンドは実行される前に『glob展開』が行われます。これは、ファイル名にはディレクトリやファイル名のシーケンスに展開された *パターン* を含めることができることを意味しています。文法は標準的なbash(1),csh(1)や以下のルールに従っています。 .. # A pathname is a sequence of directory and file names separated by one of the / or \ characters. For example, the following pathnames refer to the same file: /home/jyh/OMakefile and /home\jyh/OMakefile. # Glob-expansion is performed on the components of a path. If a path contains occurrences of special characters (listed below), the path is viewed as a pattern to be matched against the actual files in the system. The expansion produces a sequence of all file/directory names that match. * パス名は ``/`` か ``\`` の文字によって分割された、ディレクトリやファイル名から成るシーケンスです。例えば、2つのパス名 ``/home/jyh/OMakefile`` , ``/home\jyh/OMakefile`` は同一のファイルを表しています。 * Glob展開はパスの文字を元にして実行されます。もしパスが下記の特殊文字を含んでいた場合、パスはシステム上の実際にあるファイルに対してマッチしているものだけがリストされます。この展開によって、パターン文字はマッチしたすべてのファイルやディレクトリのシーケンスに展開されます。 .. For the following examples, suppose that a directory /dir contains files named a, -a, a.b, and b.c. 以下、ディレクトリ ``/dir`` にはファイル ``a`` , ``-a`` , ``a.b`` , ``b.c`` が含まれているものとします。 * ``*`` : 0以上の文字を持つ任意のシーケンスにマッチします。例えば、パターン ``/dir/a*`` は ``/dir/a /dir/aa /dir/a.b`` に展開されます。 .. Matches any sequence of zero-or-more characters. For example, the pattern /dir/a* expands to /dir/a /dir/aa /dir/a.b. * ``?`` : 任意の一つの文字にマッチします。パターン ``/dir/?a`` は ``/dir/-a`` に展開されます。 .. Matches exactly one character. The pattern /dir/?a expands the filename /dir/-a. * ``[...]`` : 大括弧の中には文字の集合や、ASCII文字の範囲を指定します。パターンには独立な文字 c や文字の範囲 c1-c2 を含めます。パターンのマッチには任意の文字や任意の範囲を指定することができます。 ``^`` をつけることで与えられたパターンを反転(指定した文字を含んでいないとマッチする)できます。また、パターンの中に ``-`` を含めたい場合、パターンの最初の文字に ``-`` と指定しなければなりません。 =================== ======================================== パターン 展開 =================== ======================================== ``/dir/[a-b]*`` ``/dir/a /dir/a.b /dir/b.c`` ``dir/[-a-b]*`` ``/dir/a /dir/-a /dir/a.b /dir/b.c`` ``/dir/[-a]*`` ``/dir/a /dir/-a /dir/a.b`` =================== ======================================== .. Square brackets denote character sets and ranges in the ASCII character set. The pattern may contain individual characters c or character ranges c1-c2. The pattern matches any of the individual characters specified, or any characters in the range. A leading “hat” inverts the send of the pattern. To specify a pattern that contains the literal characters -, the - should occur as the first character in the range. * ``{s1,...,sN}`` : 中括弧の中にはコンマによって分割された文字列のシーケンスを指定します。N個の文字列が与えられていた場合、結果はN個のパターンのコピーが生成され、各々の文字列はsiとなります。 ===================== ======================================== パターン 展開 ===================== ======================================== ``a{b,c,d}`` ``ab ac ad`` ``a{b{c,d},e}`` ``abc abd ae`` ``a{?{[A-Z],d},*}`` ``a?[A-Z] a?d a*`` ===================== ======================================== チルダ(~)はホームディレクトリを指定する際に用いられます。この値はあなたのシステムに依存して展開されます。 =================== ======================================== パターン 展開 =================== ======================================== ``~jyh`` ``/home/jyh`` ``~bob/*.c`` ``c:\Documents and Settings\users\bob`` =================== ======================================== ``\`` 文字はパス名のセパレータとしても、文字をエスケープするのにも使われます。もし特殊blob文字の前に用いられていた場合、 ``\`` は次の文字を一種の特殊でない文字に変形します。さもなければ、 ``\`` はパス名のセパレータとして解釈されます。 =========================== ================================================================== パターン 展開 =========================== ================================================================== ``~jyh/\*`` ``~jyh/*`` (``*`` は文字通り扱われる) ``/dir/\[a-z?`` ``/dir/[a-z?`` ( ``[`` は文字通り、 ``?`` はパターンとして扱われる) ``c:\Program Files\[A-z]`` ``c:\Program Files[A-z]*`` =========================== ================================================================== .. note:: 最後の ``\`` 文字に関するケースは非常に曖昧です。 ``\`` はパス名のセパレータとして扱うべきで、 ``[`` をエスケープするために用いるのではありません。もしあなたがWin32上でこのような解釈を避けたいとするならば、たとえWin32のパス名であっても ``/`` を用いるべきです( ``/`` は ``\`` に変換されて出力されます)。 ============================= =============================================== パターン 展開 ============================= =============================================== ``c:/Program Files/[A-z]*`` ``c:\Program Files\WindowsUpdate ...`` ============================= =============================================== .. Braces indicate brace-expansion. The braces delimit a sequence of strings separated by commas. Given N strings, the result produces N copies of the pattern, one for each of the strings si. The tilde is used to specify home directories. Depending on your system, these might be possible expansions. The \ character is both a pathname separator and an escape character. If followed by a special glob character, the \ changes the sense of the following character to non-special status. Otherwise, \ is viewed as a pathname separator. Note that the final case might be considered to be ambiguous (where \ should be viewed as a pathname separator, not as an escape for the subsequent [ character. If you want to avoid this ambiguity on Win32, you should use the forward slash / even for Win32 pathnames (the / is translated to \ in the output). .. index:: single: glob() .. _label10.4.1: 10.4.1 glob ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(glob strings) : Node Array strings : String Sequence $(glob options, strings) : Node Array options : String strings : String Sequence .. The glob function performs glob-expansion. ``glob`` 関数はglob展開を行います。 .. The . and .. entries are always ignored. ``.`` と ``..`` エントリは常に無視されます。 .. The options are オプションは以下です。 * **b** .. Do not perform csh(1)-style brace expansion. csh(1)スタイルの大括弧展開を行いません。 * **e** .. The \ character does not escape special characters. ``\`` 文字を特殊文字にエスケープしません。 * **n** .. If an expansion fails, return the expansion literally instead of aborting. 展開が失敗した場合、無視する代わりに展開を文字通り返します。 * **i** .. If an expansion fails, it expands to nothing. 展開が失敗した場合、何も行いません。 * **.** .. Allow wildcard patterns to match files beginning with a . .から始まるファイルにマッチする、ワイルドカードパターンを許可します。 * **A** .. Return all files, including files that begin with a . .から始まるファイルを含んだ、すべてのファイルを返します。 * **F** .. Match only normal files (any file that is not a directory). 通常のファイルのみ(ディレクトリでない任意のファイル)にマッチします。 * **D** .. Match only directory files. ディレクトリファイルのみにマッチします。 * **C** .. Ignore files according to cvs(1) rules. cvs(1)ルールに関するファイルを無視します。 * **P** .. Include only proper subdirectories. 適切なサブディレクトリのみを含みます。 .. In addition, the following variables may be defined that affect the behavior of glob. 加えて、以下の変数が ``glob`` の動作に影響を与えるように定義されています。 * **GLOB_OPTIONS** .. A string containing default options. デフォルトのオプションを定義している文字列 * **GLOB_IGNORE** .. A list of shell patterns for filenames that glob should ignore. ``glob`` が無視すべき、ファイル名のシェルパターンのリスト * **GLOB_ALLOW** .. A list of shell patterns. If a file does not match a pattern in GLOB_ALLOW, it is ignored. シェルパターンのリスト。ファイルが ``GLOB_ALLOW`` のパターンにマッチしなかった場合、そのファイルは無視されます。 .. The returned files are sorted by name. また、返されるファイルは名前順でソートされます。 .. index:: single: ls() .. _label10.4.2: 10.4.2 ls ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(ls files) : Node Array files : String Sequence $(ls options, files) : Node Array files : String Sequence .. The ls function returns the filenames in a directory. ``ls`` 関数はディレクトリからファイル名を返します。 .. The . and .. entries are always ignored. The patterns are shell-style patterns, and are glob-expanded. . と .. エントリは常に無視されます。パターンにはシェルライクなパターンを指定することで、 ``ls`` 関数はglob展開を行います。 .. The options include all of the options to the glob function, plus the following. オプションは ``glob`` 関数のオプションをすべて含んでいるほかに、以下のオプションが含まれています。 .. Perform a recursive listing. * **R** : ディレクトリを再帰的に走査し、リストします。 .. The GLOB_ALLOW and GLOB_IGNORE variables can be defined to control the globbing behavior. The returned files are sorted by name. ``GLOB_ALLOW`` と ``GLOB_IGNORE`` 変数はglob検索の動作を制御するために定義されています。また、返り値は名前によってソートされます。 .. index:: single: subdirs() .. _label10.4.3: 10.4.3 subdirs ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(subdirs dirs) : Dir Array dirs : String Sequence $(subdirs options, dirs) : Dir Array options : String dirs : String Sequence .. The subdirs function returns all the subdirectories of a list of directories, recursively. ``subdirs`` 関数はディレクトリのリストに存在している、すべてのサブディレクトリを再帰的に返します。 .. The possible options are the following: とりうることのできるオプションは以下に定義されています。 .. Return directories that begin with a . Ignore files according to .cvsignore rules. Include only proper subdirectories. * **A** : aから始まるディレクトリを返します。 * **C** : .cvsignoreルールに基づいて、特定のファイルを無視します。 * **P** : 適切なサブディレクトリのみを含めます。 .. _label10.5: 10.5 ファイル操作 ---------------------------------- .. index:: single: mkdir() .. _label10.5.1: 10.5.1 mkdir ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :: mkdir(mode, node...) mode : Int node : Node raises RuntimeException mkdir(node...) node : Node raises RuntimeException .. The mkdir function creates a directory, or a set of directories. The following options are supported. ``mkdir`` 関数はディレクトリかディレクトリの集合を生成します。以下のオプションがサポートされています。 .. Specify the permissions of the created directory. Create parent directories if they do not exist. Interpret the remaining names literally. * **-m** mode : 作られるディレクトリのパーミッションを指定します。 * **-p** : もし親のディレクトリが存在しない場合は、新しく生成します。 * **\–** : この文字の後にくる文字列を、たとえ特殊文字が含まれていても文字通りに解釈します。 .. index:: single: Stat .. _label10.5.2: 10.5.2 Stat ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. The Stat object represents an information about a filesystem node, as returned by the stat and lstat functions. It contains the following fields. ``stat`` や ``lstat`` 関数によって返される ``Stat`` オブジェクトはファイルシステムノードについての情報を提供します。このオブジェクトは以下のプロパティを含んでいます。 .. the device number. the inode number. the kind of the file, one of the following: REG (regular file), DIR (directory), CHR (character device), BLK (block device), LNK (symbolic link), FIFO (named pipe), SOCK (socket). access rights, represented as an integer. number of links. user id of the owner. group id of the file's group. device minor number. size in bytes. last access time, as a floating point number. last modification time, as a floating point number. last status change time, as a floating point number. * **dev** : デバイス番号 * **ino** : inode番号 * **king** : ファイルの種類を表し、以下の内の一つが指定されています: ``REG`` (通常のファイル), ``DIR`` (ディレクトリ), ``CHR`` (キャラクタデバイス), ``BLK`` (ブロックデバイス), ``LNK`` (シンボリックリンク), ``FIFO`` (名前付きパイプ), ``SOCK`` (ソケット) * **perm** : アクセス権。数値で表現されます。 * **nlink** : リンクの数 * **uid** : オーナーのユーザーID * **gid** : ファイルのグループのグループID * **rdev** : デバイスのマイナー番号 * **size** : ファイルのバイト数 * **atime** : アクセス日時。浮動小数点で表現されます。 * **mtime** : 修正日時。浮動小数点で表現されます。 * **ctime** : ステータス変更日時。浮動小数点で表現されます。 .. Not all of the fields will have meaning on all operating systems. すべてのプロパティがすべてのOS上で意味をもつわけではない点に注意してください。 .. index:: single: stat() single: lstat() .. _label10.5.3: 10.5.3 stat, lstat ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(stat node...) : Stat node : Node or Channel $(lstat node...) : Stat node : Node or Channel raises RuntimeException .. The stat functions return file information. If the file is a symbolic link, the stat function refers to the destination of the link; the lstat function refers to the link itself. ``stat`` 関数はファイル情報を返します。もしファイルがシンボリックリンクであった場合は、 ``stat`` 関数はリンク先を参照します。一方で、 ``lstat`` 関数はリンク自身を参照します。 .. index:: single: unlink() .. _label10.5.4: 10.5.4 unlink ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(unlink file...) file : File #(rm file...) file : File $(rmdir dir...) dir : Dir raises RuntimeException .. The unlink and rm functions remove a file. The rmdir function removes a directory. ``unlink`` と ``rm`` 関数はファイルを削除します。 ``rmdir`` 関数はディレクトリを削除します。 .. The following options are supported for rm and rmdir. ``rm`` および ``rmdir`` 関数は以下のオプションをサポートしています。 .. ignore nonexistent files, never prompt. prompt before removal. remove the contents of directories recursively. explain what is going on. the rest of the values are interpreted literally. * **-f** : 存在しないファイルを確認なしで無視します。 * **-i** : 消去する前に確認します。 * **-r** : ディレクトリの内容を再帰的に削除します。 * **-v** : どのような処理を行っているのかを出力します。 * **\-** : この文字の後に来る値は文字通りに解釈されます。 .. index:: single: rename() single: mv() single: cp() .. _label10.5.5: 10.5.5 rename ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :: rename(old, new) old : Node new : Node mv(nodes... dir) nodes : Node Sequence dir : Dir cp(nodes... dir) nodes : Node Sequence dir : Dir raises RuntimeException .. The rename function changes the name of a file or directory named old to new. ``rename`` 関数はファイルかディレクトリの名前を ``old`` から ``new`` に変更します。 .. The mv function is similar, but if new is a directory, and it exists, then the files specified by the sequence are moved into the directory. If not, the behavior of mv is identical to rename. The cp function is similar, but the original file is not removed. ``mv`` 関数は似ていますが、もし ``new`` がディレクトリでかつ存在している場合、シーケンスによって指定されたファイルはディレクトリの中に移動されます。もしそうでない場合、 ``mv`` の動作は ``rename`` と全く同じです。 ``cp`` 関数は似ていますが、この関数はオリジナルのファイルを消去しません。 .. The mv and cp functions take the following options. ``mv`` と ``cp`` 関数は以下のオプションをとります。 .. Do not prompt before overwriting. Prompt before overwriting. Explain what it happening. Copy the contents of directories recursively. Interpret the remaining arguments literally. * **-f** : 上書きする前の確認を行いません。 * **-i** : 上書きする前に確認します。 * **-v** : どのような処理を行っているのか出力します。 * **-r** : ディレクトリの内容を再帰的にコピーします。 * **\-** : この文字の後に来る引数は文字通りに解釈されます。 .. index:: single: link() .. _label10.5.6: 10.5.6 link ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :: link(src, dst) src : Node dst : Node raises RuntimeException .. The link function creates a hard link named dst to the file or directory src. ``link`` 関数はファイルやディレクトリ ``src`` へのハードリンクを ``dst`` に生成します。 .. Hard links may work under Win32 when NTFS is used. ハードリンクはNTFSを用いていた場合は、Win32システム上でも正常に動作します。 .. Normally, only the superuser can create hard links to directories. 通常、スーパーユーザだけがディレクトリへのハードリンクを生成できます。 .. index:: single: symlink() .. _label10.5.7: 10.5.7 symlink ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :: symlink(src, dst) src : Node dst : Node raises RuntimeException .. The symlink function creates a symbolic link dst that points to the src file. ``symlink`` 関数は ``src`` ファイルへのシンボリックリンクを ``dst`` に生成します。 .. The link name is computed relative to the target directory. For example, the expression $(symlink a/b, c/d) creates a link named c/d -> ../a/b. リンク名はターゲットのディレクトリに合わせて計算されます。例えば、式 ``$(symlink a/b, c/d)`` は ``c/d -> ../a/b`` というリンクが生成されます。 .. Symbolic links are not supported in Win32. Consider using the ln-or-cp Shell alias for cross-platform portable linking/copying. シンボリックリンクはWin32上ではサポートされていません。もしクロスプラットフォームでリンク/コピーを行いたい場合は ``ln-or-cp`` か ``Shell`` エイリアスを使用してください。 .. index:: single: readlink() .. _label10.5.8: 10.5.8 readlink ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(readlink node...) : Node node : Node .. The readlink function reads the value of a symbolic link. ``readlink`` 関数はシンボリックリンクの値を読み取ります。 .. index:: single: chmod() .. _label10.5.9: 10.5.9 chmod ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :: chmod(mode, dst...) mode : Int dst : Node or Channel chmod(mode dst...) mode : String dst : Node Sequence raises RuntimeException .. The chmod function changes the permissions of the targets. ``chmod`` 関数は対象のパーミッションを変更します。 オプション: .. Explain what is happening. Change files and directories recursively. Continue on errors. Interpret the remaining argument literally. * **-v** : どのような処理を行っているのか説明します。 * **-r** : ファイルやディレクトリを再帰的に変更します。 * **-f** : エラーが生じても続けて実行します。 * **\-** : 残りの引数を文字通りに解釈します。 .. index:: single: chown() .. _label10.5.10: 10.5.10 chown ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :: chown(uid, gid, node...) uid : Int gid : Int node : Node or Channel chown(uid, node...) uid : Int node : Node or Channel raises RuntimeException .. The chown function changes the user and group id of the file. If the gid is not specified, it is not changed. If either id is -1, that id is not changed. ``chown`` 関数はファイルのユーザやグループIDを変更します。もし ``gid`` が指定されていない場合は、値は変更されません。もしIDが-1であった場合でも、そのIDは変更されません。 .. index:: single: truncate() .. _label10.5.11: 10.5.11 truncate ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :: truncate(length, node...) length : Int node : Node or Channel raises RuntimeException .. The truncate function truncates a file to the given length. ``truncate`` 関数はファイルを与えられた長さに切り詰めます。 .. index:: single: umask() .. _label10.5.12: 10.5.12 umask ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(umask mode) : Int mode : Int raises RuntimeException .. Sets the file mode creation mask. The previous mask is returned. This value is not scoped, changes have global effect. ファイル生成マスクを設定します。この関数は前回のマスクの値が返されます。この値はスコープ化されていませんので、この変更はグローバルに影響を及ぼします。 .. _label10.6: 10.6 vmount ---------------------------------- .. index:: single: vmount() .. _label10.6.1: 10.6.1 vmount ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :: vmount(src, dst) src, dst : Dir vmount(flags, src, dst) flags : String src, dst : Dir .. “Mount” the src directory on the dst directory. This is a virtual mount, changing the behavior of the $(file ...) function. When the $(file str) function is used, the resulting file is taken relative to the src directory if the file exists. Otherwise, the file is relative to the current directory. ``src`` ディレクトリを ``dst`` ディレクトリに『マウント』します。これは仮想的なマウントで、 ``$(file ...)`` 関数のふるまいを変更します。 ``$(file str)`` が使われた場合、返される値はもしファイルが存在していたら ``src`` ディレクトリに関連付けられます。さもなければファイルは現在のディレクトリに関連付けられます。 .. The main purpose of the vmount function is to support multiple builds with separate configurations or architectures. ``vmount`` 関数の主な目的は、分割された設定やアーキテクチャを用いて、複数のビルドを行うことをサポートするためです。 .. The options are as follows. オプションは以下の通りです。 .. Create symbolic links to files in the src directory. Copy files from the src directory. * **l** : ``src`` ディレクトリ中のファイルへのシンボリックリンクを生成します。 * **c** : ``src`` ディレクトリからファイルをコピーします。 .. Mount operations are scoped. なお、マウント操作はスコープ化されています。 .. index:: single: add-project-directories() .. _label10.6.2: 10.6.2 add-project-directories ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :: add-project-directories(dirs) dirs : Dir Array .. Add the directories to the set of directories that omake considers to be part of the project. This is mainly used to avoid omake complaining that the current directory is not part of the project. omakeがプロジェクトの一部とみなしているディレクトリの集合に、ディレクトリを新しく追加します。これは主に、現在のディレクトリがプロジェクトの一部でないとomakeがエラーを出すことを避けるために用いられます。 .. index:: single: remove-project-directories() .. _label10.6.3: 10.6.3 remove-project-directories ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :: remove-project-directories(dirs) dirs : Dir Array .. Removed the directories from the set of directories that omake considers to be part of the project. This is mainly used to cancel a .SUBDIRS from including a directory if it is determined that the directory does not need to be compiled. omakeがプロジェクトの一部とみなしているディレクトリの集合から、ディレクトリを削除します。これは主に、特定のディレクトリがコンパイルされる必要がないことが分かっているので、インクルードしているディレクトリから ``.SUBDIRS`` を取り消すような場合に用いられます。 .. _label10.7: 10.7 ファイルの内容を元にした検索 ---------------------------------- .. index:: single: test() .. _label10.7.1: 10.7.1 test ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :: test(exp) : Bool exp : String Sequence .. The expression grammar is as follows: 評価式の文法は以下の通りです。 .. expression is not true both expressions are true at least one expression is true expression is true * ``!`` exp : expは真でない * exp1 ``-a`` exp2 : 両方のexpが真である * exp1 ``-o`` exp2 : 1以上のexpが真である * (exp) : expは真である .. The base expressions are 基本となる評価式は以下の通りです。 .. The string has nonzero length The string has zero length The strings are equal The strings are not equal The integers are equal The integers are not equal int1 is larger than int2 int2 is not larger than int1 int1 is smaller than int2 int1 is not larger than int2 On Unix, file1 and file2 have the same device and inode number. On Win32, file1 and file2 have the same name. file1 is newer than file2 file1 is older than file2 The file is a block special file The file is a character special file The file is a directory The file exists The file is a normal file The set-group-id bit is set on the file The file's group is the current effective group The file is a symbolic link (also -L) The file's sticky bit is set The file is a symbolic link (also -h) The file's owner is the current effective user The file is a named pipe The file is readable The file is empty The file is a socket The set-user-id bit is set on the file The file is writable The file is executable * ``-n`` str : *文字列* は0でない長さである * ``-z`` str : *文字列* は0の長さである * str ``=`` str : 両方の文字列は等しい * str ``!=`` str : 両方の文字列は等しくない * int1 ``-eq`` int2 : 両方の整数は等しい * int1 ``-ne`` int2 : 両方の整数は等しくない * int1 ``-gt`` int2 : int1はint2よりも大きい(int1 > int2) * int1 ``-ge`` int2 : int1はint2以上である(int1 >= int2) * int1 ``-gt`` int2 : int1はint2よりも小さい(int1 < int2) * int1 ``-le`` int2 : int1はint2以下である(int1 <= int2) * file1 ``-ef`` file2 : Unix上では、file1とfile2は同一のデバイスとinode番号である。Win32上では、file1とfile2は同一の名前である。 * file1 ``-nt`` file2 : file1はfile2よりも新しい * file1 ``-ot`` file2 : file1はfile2よりも古い * ``-b`` file : fileはブロック型特殊ファイルである * ``-c`` file : fileはキャラクタ型特殊ファイルである * ``-d`` file : fileはディレクトリである * ``-e`` file : fileが実在している * ``-f`` file : fileは通常のファイルである * ``-g`` file : ``set-group-id`` bitがfileに設定されている * ``-G`` file : fileのグループIDが現在影響を受けているグループである * ``-h`` file : fileがシンボリックリンクである(``-L`` でもよい) * ``-k`` file : fileにスティッキー・ビットが設定されている * ``-L`` file : fileがシンボリックリンクである(``-h`` でもよい) * ``-O`` file : fileのオーナーが現在影響を受けているグループである * ``-p`` file : fileが名前付きパイプである * ``-r`` file : fileが読み込み可能である * ``-s`` file : fileは空である * ``-S`` file : fileはソケットである * ``-u`` file : ``set-user-id`` bitがfileに設定されている * ``-w`` file : fileは書き込み可能である * ``-x`` file : fileは実行可能である .. A string is any sequence of characters; leading - characters are allowed. *str* は任意の文字列で、 ``-`` 文字をつけることができます。 .. An int is a string that can be interpreted as an integer. Unlike traditional versions of the test program, the leading characters may specify an arity. The prefix 0b means the numbers is in binary; the prefix 0o means the number is in octal; the prefix 0x means the number is in hexadecimal. An int can also be specified as -l string, which evaluates to the length of the string. *int* は整数として解釈できる文字列です。Unlike traditional versions of the test program, the leading characters may specify an arity. 接頭辞 ``0b`` は数値をバイナリで扱います。同様に、接頭辞 ``0o`` は数値を8進数で扱い、接頭辞 ``0x`` は数値を16進数で扱います。 *int* は ``-l`` を用いることで数値を文字列として扱うことができます。これによって、数値ではなく文字列の長さが評価されます。 .. A file is a string that represents the name of a file. *file* はファイル名を表す文字列です。 .. The syntax mirrors that of the test(1) program. If you are on a Unix system, the man page explains more. Here are some examples. 文法は ``test(1)`` プログラムと似ています。もしあなたがUnixのシステム上にいるのならば、manを参照すればさらに詳細を説明してくれるでしょう。以下にいくつかのサンプルを挙げておきます。 :: # 空のファイルを作成 osh> touch foo # ファイルは空ですか? osh> test(-e foo) - : true osh> test(! -e foo) - : false # 別のファイルを作成 osh> touch boo # 新しく作ったファイルは前よりも新しいですか? osh> test(boo -nt foo) - : true # さらに複雑な式を示します。 # booはfooよりも新しく、さらにfooは空である。 osh> test(\( boo -nt foo \) -a -e foo) - : true .. index:: single: find() .. _label10.7.2: 10.7.2 find ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :: find(exp) : Node Array exp : String Sequence .. The find function searches a directory recursively, returning the files for which the expression evaluates to true. ``find`` 関数はディレクトリを再帰的に検索し、 ``exp`` の評価が真であるファイルを返します。 .. The expression argument uses the same syntax as the test function, with the following exceptions. 引数の ``exp`` は以下の例外を除いて、 ``test`` 関数と同じ文法を用いています。 .. 1. The expression may begin with a directory. If not specified, the current directory is searched. 2. The {} string expands to the current file being examined. 1. ``exp`` はディレクトリから始まります。もし特に指定していない場合はカレントディレクトリから検索します。 2. ``{}`` 文字は現在のファイルを表す文字に拡張されています。 .. The syntax of the expression is the same as test, with the following additions. ``exp`` の文法は ``test`` 関数のそれと同一ですが、以下の点が加わっています。 .. * -name string : The current file matches the glob expression (see Section 10.4). * -regex string : The current file matches the regular expression * ``-name`` str : 現在のファイルはglob表現にマッチしている(詳細は ":ref:`label10.4`" を参照してください)。 * ``-regex`` str : 現在のファイルは正規表現にマッチしている。 .. The find function performs a recursive scan of all subdirectories. The following call is being run from the root of the omake source directory. ``find`` 関数はすべてのサブディレクトリを再帰的にスキャンします。以下の関数呼び出しは ``omake`` のソースディレクトリのルートから走らせています。 :: osh> find(. -name fo* ) - : .. Another example, listing only those files that are normal files or symbolic links. 別の例では、通常のファイルかシンボリックリンクのファイルのみを並べています。 :: osh> find(. -name fo* -a \( -f {} -o -L {} \)) - : .. _label10.8: 10.8 I/O 関数 ---------------------------------- .. index:: single: stdin single: stdout single: stderr .. _label10.8.1: 10.8.1 標準出力先 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. The following variables define the standard channels. 以下の変数が標準出力先として定義されています。 * **stdin** :: stdin : InChannel .. The standard input channel, open for reading. 標準入力チャネルで、読み込みを担当します。 * **stdout** :: stdout : OutChannel .. The standard output channel, open for writing. 標準出力チャネルで、書き込みを担当します。 * **stderr** :: stderr : OutChannel .. The standard error channel, open for writing. 標準エラーャネルで、書き込みを担当します。 .. index:: single: open-in-string() .. _label10.8.2: 10.8.2 open-in-string ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. The open-in-string treats a string as if it were a file and returns a channel for reading. ``open-in-string`` 関数は文字列をまるでファイルのように扱い、読み込むためのチャネルを返します。 :: $(open-in-string s) : Channel s : String .. index:: single: open-out-string() single: out-contents() .. _label10.8.3: 10.8.3 open-out-string, out-contents ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. The open-out-string creates a channel that writes to a string instead of a file. The string may be retrieved with the out-contents function. ``open-out-string`` 関数はファイルの代わりに文字列を書き込むチャネルを作成します。文字列は ``out-contents`` 関数を用いて取得することができます。 :: $(open-out-string) : Channel $(out-contents chan) : String chan : OutChannel .. index:: single: fopen() .. _label10.8.4: 10.8.4 fopen ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. The fopen function opens a file for reading or writing. ``fopen`` 関数はファイルを読み書きするために、新しくファイルを開きます。 :: $(fopen file, mode) : Channel file : File mode : String .. The file is the name of the file to be opened. The mode is a combination of the following characters. ``file`` は読み書きするファイル名を指定します。 ``mode`` は以下の文字を組み合わせた文字列です。 .. Open the file for reading; it is an error if the file does not exist. Open the file for writing; the file is created if it does not exist. Open the file in append mode; the file is created if it does not exist. Open the file for both reading and writing. Open the file in text mode (default). Open the file in binary mode. Open the file in nonblocking mode. Fail if the file already exists. * **r** : 読み込むためにファイルを開きます。もしファイルが存在していない場合はエラーが発生します。 * **w** : 書き込むためにファイルを開きます。もしファイルが存在していない場合は新しくファイルを作ります。 * **a** : 追記モードでファイルを開きます。もしファイルが存在していない場合は新しくファイルを作ります。 * **+** : 読み書き両方するためにファイルを開きます。 * **t** : ファイルをテキストモードで開きます(デフォルト)。 * **b** : ファイルをバイナリモードで開きます。 * **n** : ファイルをノンブロッキングモードで開きます。 * **x** : ファイルが既に存在している場合は失敗します。 .. Binary mode is not significant on Unix systems, where text and binary modes are equivalent. Unixシステム上ではバイナリモードは意味を持たず、テキストモードとバイナリモードは等価に扱われます。 .. index:: single: close() .. _label10.8.5: 10.8.5 close ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(close channel...) channel : Channel .. The close function closes a file that was previously opened with fopen. ``close`` 関数は以前に ``fopen`` によって開かれたファイルを閉じる関数です。 .. index:: single: read() single: input-line() .. _label10.8.6: 10.8.6 read, input-line ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(read channel, amount) : String $(input-line channel) : String channel : InChannel amount : Int raises RuntimeException .. The read function reads up to amount bytes from an input channel, and returns the data that was read. The input-line function reads a line from the file and returns the line read, without the line terminator. If an end-of-file condition is reached, both functions raise a RuntimeException exception. ``read`` 関数は ``amount`` バイトを入力チャネルから読み込み、読み込んだデータを返します。 ``input-line`` 関数はファイルから一行を読み込み、読み込んだ一行を改行コード抜きで返します。もしファイルの終わりまでたどり着いた場合、両方の関数は例外 ``RuntimeException`` を送出します。 .. index:: single: write() .. _label10.8.7: 10.8.7 write ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(write channel, buffer, offset, amount) : String channel : OutChannel buffer : String offset : Int amount : Int $(write channel, buffer) : String channel : OutChannel buffer : String raises RuntimeException .. In the 4-argument form, the write function writes bytes to the output channel channel from the buffer, starting at position offset. Up to amount bytes are written. The function returns the number of bytes that were written. 4つ引数をとる場合、 ``write`` 関数は出力チャネル ``channel`` に位置 ``offset`` から、バイト ``buffer`` を書き込みます。なお、上限は ``amount`` バイトです。この関数は何バイトが書き込まれたのかというバイト数を返します。 .. The 3-argument form is similar, but the offset is 0. 3つ引数をとる場合も同様ですが、 ``offset`` は0となります。 .. In the 2-argument form, the offset is 0, and the amount if the length of the buffer. 2つ引数をとる場合、 ``offset`` は0で、かつ ``amount`` は ``buffer`` の長さになります。 .. If an end-of-file condition is reached, the function raises a RuntimeException exception. ファイルの終わりまでたどり着いた場合、この関数は例外 ``RuntimeException`` を送出します。 .. index:: single: lseek() .. _label10.8.8: 10.8.8 lseek ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(lseek channel, offset, whence) : Int channel : Channel offset : Int whence : String raises RuntimeException .. The lseek function repositions the offset of the channel channel according to the whence directive, as follows: ``lseek`` 関数はチャネル ``channel`` のオフセット位置を ``whence`` に基づいて変更します。 ``whence`` は以下の通りです。 .. The offset is set to offset. The offset is set to its current position plus offset bytes. The offset is set to the size of the file plus offset bytes. * **SEEK_SET** : オフセットは ``offset`` に設定されます。 * **SEEK_CUR** : オフセットは現在の位置から ``offset`` バイト分移動します。 * **SEEK_END** : オフセットはファイルサイズ + ``offset`` バイトの位置に設定されます。 .. The lseek function returns the new position in the file. ``lseek`` 関数はファイルの新しいオフセット位置を返します。 .. index:: single: rewind() .. _label10.8.9: 10.8.9 rewind ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :: rewind(channel...) channel : Channel .. The rewind function set the current file position to the beginning of the file. ``rewind`` 関数は現在のファイル位置をファイルが始まる位置に設定します。 .. index:: single: tell() .. _label10.8.10: 10.8.10 tell ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(tell channel...) : Int... channel : Channel raises RuntimeException .. The tell function returns the current position of the channel. ``tell`` 関数は ``channel`` の現在位置を返します。 .. index:: single: flush() .. _label10.8.11: 10.8.11 flush ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(flush channel...) channel : OutChannel .. The flush function can be used only on files that are open for writing. It flushes all pending data to the file. ``flush`` 関数は書き込み用途にファイルが開かれている場合のみに使われます。この関数はファイルにまだ書き込まれていないすべてのデータを消去します。 .. index:: single: channel-name() .. _label10.8.12: 10.8.12 channel-name ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(channel-name channel...) : String channel : Channel .. The channel-name function returns the name that is associated with the channel. ``channel-name`` 関数はチャネルに関係している名前を返します。 .. index:: single: dup() .. _label10.8.13: 10.8.13 dup ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(dup channel) : Channel channel : Channel raises RuntimeException .. The dup function returns a new channel referencing the same file as the argument. ``dup`` 関数は引数に指定されたチャネルと同一のファイルを示している、新しいチャネルを返します。 .. index:: single: dup2() .. _label10.8.14: 10.8.14 dup2 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :: dup2(channel1, channel2) channel1 : Channel channel2 : Channel raises RuntimeException .. The dup2 function causes channel2 to refer to the same file as channel1. ``dup2`` 関数は ``channel2`` を ``channel1`` と同一のファイルを示すようにします。 .. index:: single: set-nonblock() .. _label10.8.15: 10.8.15 set-nonblock ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :: set-nonblock-mode(mode, channel...) channel : Channel mode : String .. The set-nonblock-mode function sets the nonblocking flag on the given channel. When IO is performed on the channel, and the operation cannot be completed immediately, the operations raises a RuntimeException. ``set-nonblock-mode`` 関数は与えられたチャネルのノンブロッキングフラグを設定します。もしチャネルが入出力中で、この操作が即座に完了しないような場合、 ``RuntimeException`` が送出されます。 .. index:: single: set-close-on-exec-mode() .. _label10.8.16: 10.8.16 set-close-on-exec-mode ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. The set-close-on-exec-mode function sets the close-on-exec flags for the given channels. If the close-on-exec flag is set, the channel is not inherited by child processes. Otherwise it is. ``set-close-on-exec-mode`` 関数は与えられたチャネルのclose-on-execフラグを設定します。もしclose-on-execフラグが設定されている場合、このチャネルは子プロセスから継承されません。そうでない場合は、このチャネルは子プロセスから継承されます。 .. index:: single: pipe() .. _label10.8.17: 10.8.17 pipe ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(pipe) : Pipe raises RuntimeException .. The pipe function creates a Pipe object, which has two fields. The read field is a channel that is opened for reading, and the write field is a channel that is opened for writing. ``pipe`` 関数は2つのプロパティを持つ ``Pipe`` オブジェクトを生成します。 ``read`` プロパティは読み込むためのチャネルで、 ``write`` プロパティは書き込むためのチャネルです。 .. index:: single: mkfifo() .. _label10.8.18: 10.8.18 mkfifo ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :: mkfifo(mode, node...) mode : Int node : Node .. The mkfifo function creates a named pipe. ``mkfifo`` 関数は名前付きパイプを生成します。 .. index:: single: select() .. _label10.8.19: 10.8.19 select ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(select rfd..., wfd..., efd..., timeout) : Select rfd : InChannel wfd : OutChannel efd : Channel timeout : float raises RuntimeException .. The select function polls for possible IO on a set of channels. The rfd are a sequence of channels for reading, wfd are a sequence of channels for writing, and efd are a sequence of channels to poll for error conditions. The timeout specifies the maximum amount of time to wait for events. ``select`` 関数は与えられたチャネルの集合が入出力可能であるか監視します。 ``rfd`` には読み込み可能なチャネルのシーケンスを指定します。 ``wfd`` には書き込み可能なチャネルのシーケンスを指定します。 ``efd`` にはエラー状態を監視するチャネルのシーケンスを指定します。 ``timeout`` にはイベントを待つ最大時間を指定します。 .. On successful return, select returns a Select object, which has the following fields: 正常な戻り値の場合、 ``select`` 関数は以下のプロパティを持つ ``Select`` オブジェクトを返します。 .. An array of channels available for reading. An array of channels available for writing. An array of channels on which an error has occurred. * **read** : 読み込み可能なチャネルの配列 * **write** : 書き込み可能なチャネルの配列 * **error** : エラーが生じたチャネルの配列 .. index:: single: lockf() .. _label10.8.20: 10.8.20 lockf ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :: lockf(channel, command, len) channel : Channel command : String len : Int raises RuntimeException .. The lockf function places a lock on a region of the channel. The region starts at the current position and extends for len bytes. ``lockf`` 関数は与えられたチャネルのPOSIXロックの範囲を設定します。範囲は現在の位置から ``len`` バイトまでです。 .. The possible values for command are the following. ``command`` のとりうる値は以下の通りです。 .. Unlock a region. Lock a region for writing; block if already locked. Lock a region for writing; fail if already locked. Test a region for other locks. Lock a region for reading; block if already locked. Lock a region for reading; fail is already locked. * **F_ULOCK** : 指定された範囲をアンロックします。 * **F_LOCK** : 指定された範囲を書き込みロックします。もし既にロックされている場合はブロックされます。 * **F_TLOCK** : 指定された範囲を書き込みロックします。もし既にロックされている場合は失敗します。 * **F_TEST** : 指定された範囲に他のロックがないか試します。 * **F_RLOCK** : 指定された範囲を読み込みロックします。もし既にロックされている場合はブロックされます。 * **F_TRLOCK** : 指定された範囲を読み込みロックします。もし既にロックされている場合は失敗します。 .. index:: single: InetAddr .. _label10.8.21: 10.8.21 InetAddr ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. The InetAddr object describes an Internet address. It contains the following fields. ``InetAddr`` オブジェクトはインターネットアドレスを記述しています。このオブジェクトは以下のプロパティを含んでいます。 .. the Internet address. the port number. * **addr** -> ``String`` : インターネットアドレス * **port** -> ``Int`` : ポート番号 .. index:: single: Host .. _label10.8.22: 10.8.22 Host ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. A Host object contains the following fields. ``Host`` オブジェクトは以下のプロパティを含んでいます。 .. the name of the host. other names by which the host is known. the preferred socket domain. an array of Internet addresses belonging to the host. * **name** -> ``String`` : ホスト名 * **aliases** -> ``String Array`` : ホストの別名の配列 * **addrtype** -> ``String`` : 都合の良いドメインのソケット??? * **addrs** -> ``InetAddr Array`` : ホストに所属しているインターネットアドレスの配列 .. index:: single: gethostbyname() .. _label10.8.23: 10.8.23 gethostbyname ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(gethostbyname host...) : Host... host : String raises RuntimeException .. The gethostbyname function returns a Host object for the specified host. The host may specify a domain name or an Internet address. ``gethostbyname`` 関数は指定されたホストの ``Host`` オブジェクトを返します。 ``host`` にはドメイン名かインターネットアドレスを指定します。 .. index:: single: Protocol .. _label10.8.24: 10.8.24 Protocol ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. The Protocol object represents a protocol entry. It has the following fields. ``Protocol`` オブジェクトはプロトコルエントリーを表現します。このオブジェクトは以下のプロパティを含んでいます。 .. the canonical name of the protocol. aliases for the protocol. the protocol number. * **name** -> ``String`` : 正規のプロトコル名 * **aliases** -> ``String Array`` : プロトコルのエイリアスの配列 * **proto** -> ``Int`` : プロトコル番号 .. index:: single: getprotobyname() .. _label10.8.25: 10.8.25 getprotobyname ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(getprotobyname name...) : Protocol... name : Int or String raises RuntimeException .. The getprotobyname function returns a Protocol object for the specified protocol. The name may be a protocol name, or a protocol number. ``getprotobyname`` 関数は指定されたプロトコルから ``Protocol`` オブジェクトを返します。 ``name`` にはプロトコル名かプロトコル番号を指定します。 .. index:: single: Service .. _label10.8.26: 10.8.26 Service ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. The Service object represents a network service. It has the following fields. ``Service`` オブジェクトはネットワークサービスを表現します。このオブジェクトは以下のプロパティを含んでいます。 .. the name of the service. aliases for the service. the port number of the service. the protocol for the service. * **name** -> ``String`` : サービス名 * **aliases** -> ``String Array`` : サービスのエイリアスの配列 * **port** -> ``Int`` : サービスのポート番号 * **proto** -> ``Protocol`` : サービスのプロトコル .. index:: single: getservbyname() .. _label10.8.27: 10.8.27 getservbyname ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(getservbyname service...) : Service... service : String or Int raises RuntimeException .. The getservbyname function gets the information for a network service. The service may be specified as a service name or number. ``getservbyname`` 関数はネットワークサービスの情報を取得します。 ``service`` にはサービス名か番号を指定します。 .. index:: single: socket() .. _label10.8.28: 10.8.28 socket ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(socket domain, type, protocol) : Channel domain : String type : String protocol : String raises RuntimeException .. The socket function creates an unbound socket. ``socket`` 関数は束縛されていないソケットを生成します。 .. The possible values for the arguments are as follows. 引数のとりうる値は以下の通りです。 .. The domain may have the following values. ``domain`` は以下の値をとります。 .. Unix domain, available only on Unix systems. Internet domain, IPv4. Internet domain, IPv6. * **PF_UNIX** あるいは **unix** : Unixシステムでのみ利用可能なUnixドメイン * **PF_INET** あるいは **inet** : IPv4インターネットドメイン * **PF_INET6** あるいは **inet6** : IPv6インターネットドメイン .. The type may have the following values. ``type`` は以下の値をとります。 .. Stream socket. Datagram socket. Raw socket. Sequenced packets socket * **SOCK_STREAM** あるいは **stream** : ストリームソケット * **SOCK_DGRAM** あるいは **dgram** : データグラムソケット * **SOCK_RAW** あるいは **raw** : 生(raw)ソケット * **SOCK_SEQPACKET** あるいは **seqpacket** : パケットシーケンスソケット .. The protocol is an Int or String that specifies a protocol in the protocols database. ``protocol`` はプロトコルのデータベースにあるプロトコルを指定した ``Int`` か ``String`` 型の引数です。 .. index:: single: bind() .. _label10.8.29: 10.8.29 bind ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :: bind(socket, host, port) socket : InOutChannel host : String port : Int bind(socket, file) socket : InOutChannel file : File raise RuntimeException .. The bind function binds a socket to an address. ``bind`` 関数はソケットをアドレスに束縛します。 .. The 3-argument form specifies an Internet connection, the host specifies a host name or IP address, and the port is a port number. 3つ引数をとる場合、 ``bind`` 関数はインターネットの接続方法について指定し、 ``host`` にはホスト名かIPアドレスを、 ``port`` にはポート番号を指定します。 .. The 2-argument form is for Unix sockets. The file specifies the filename for the address. 2つ引数をとる形は ``Unix`` ソケットのために用意されています。 ``file`` にはファイル名のアドレスを指定します。 .. index:: single: listen() .. _label10.8.30: 10.8.30 listen ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :: listen(socket, requests) socket : InOutChannel requests : Int raises RuntimeException .. The listen function sets up the socket for receiving up to requests number of pending connection requests. ``listen`` 関数は ``requests`` 個のまだ取得されていないリクエストを取得するように、ソケットを設定します。 .. index:: single: accept() .. _label10.8.31: 10.8.31 accept ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(accept socket) : InOutChannel socket : InOutChannel raises RuntimeException .. The accept function accepts a connection on a socket. ``accept`` 関数はソケットの接続を受け入れます。 .. index:: single: connect() .. _label10.8.32: 10.8.32 connect ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :: connect(socket, addr, port) socket : InOutChannel addr : String port : int connect(socket, name) socket : InOutChannel name : File raise RuntimeException .. The connect function connects a socket to a remote address. ``connect`` 関数はソケットを対象のアドレスに接続します。 .. The 3-argument form specifies an Internet connection. The addr argument is the Internet address of the remote host, specified as a domain name or IP address. The port argument is the port number. 3つ引数をとる場合、 ``connect`` 関数はインターネットの接続方法について指定します。 ``addr`` にはリモートホストのインターネットアドレスをドメイン名かIPアドレスの形で指定します。 ``port`` にはポート番号を指定します。 .. The 2-argument form is for Unix sockets. The name argument is the filename of the socket. 2つ引数をとる形はUnixソケットのために用意されています。 ``name`` にはソケットのファイル名を指定します。 .. index:: single: getchar() .. _label10.8.33: 10.8.33 getchar ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(getc) : String $(getc file) : String file : InChannel or File raises RuntimeException .. The getc function returns the next character of a file. If the argument is not specified, stdin is used as input. If the end of file has been reached, the function returns false. ``getc`` 関数はファイルの次の文字を返します。もし引数が指定されなかった場合、 ``stdin`` が入力として用いられます。もしファイルの終わりまでたどりついた場合、この関数は ``false`` を返します。 .. index:: single: gets() .. _label10.8.34: 10.8.34 gets ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(gets) : String $(gets channel) : String channel : InChannel or File raises RuntimeException .. The gets function returns the next line from a file. The function returns the empty string if the end of file has been reached. The line terminator is removed. ``gets`` 関数はファイルから次の行を返します。この関数はファイルの終わりまでたどり着いていた場合、空の文字列を返します。改行コードは取り除かれます。 .. index:: single: fgets() .. _label10.8.35: 10.8.35 fgets ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(fgets) : String $(fgets channel) : String channel : InChannel or File raises RuntimeException .. The fgets function returns the next line from a file that has been opened for reading with fopen. The function returns the empty string if the end of file has been reached. The returned string is returned as literal data. The line terminator is not removed. ``fgets`` 関数は ``fopen`` によって読み込みが開かれているファイルから、次の行を返します。この関数はファイルの終わりまでたどり着いていた場合、空の文字列を返します。返される文字列は文字通りのデータ(literal data)として返されます。改行コードは取り除かれません。 .. index:: single: fprint() single: print() single: eprint() single: fprintln() single: println() single: eprintln() .. _label10.9: 10.9 出力関数 ---------------------------------- .. Output is printed with the print and println functions. The println function adds a terminating newline to the value being printed, the print function does not. ``print`` と ``println`` 関数を用いて出力を表示します。 ``println`` 関数は表示する値に新しく改行コードを加えます。 ``print`` 関数は加えません。 :: fprint(, ) print() eprint() fprintln(, ) println() eprintln() .. The fprint functions print to a file that has been previously opened with fopen. The print functions print to the standard output channel, and the eprint functions print to the standard error channel. ``fprint`` 関数は ``fopen`` で開かれたファイルに対して出力します。 ``print`` 関数は標準出力チャネルに対して出力しますが、 ``eprint`` 関数は標準エラーチャネルに対して出力します。 .. index:: single: fprintv() single: printv() single: eprintv() single: fprintvln() single: printvln() single: eprintvln() .. _label10.10: 10.10 値を出力する関数 ---------------------------------- .. Values can be printed with the printv and printvln functions. The printvln function adds a terminating newline to the value being printed, the printv function does not. 値は ``printv`` と ``printvln`` 関数を用いて表示できます。 ``printvln`` 関数は表示する値に新しく改行コードを加えます。 ``printv`` 関数は加えません。 :: fprintv(, ) printv() eprintv() fprintvln(, ) printvln() eprintvln() .. The fprintv functions print to a file that has been previously opened with fopen. The printv functions print to the standard output channel, and the eprintv functions print to the standard error channel. ``fprinv`` 関数は ``fopen`` で開かれたファイルに対して出力します。 ``printv`` 関数は標準出力チャネルに対して出力しますが、 ``eprintv`` 関数は標準エラーチャネルに対して出力します。 .. _label10.10.1: 10.10.1 その他の関数 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. index:: single: set-channel-line() .. _label10.10.1.1: 10.10.1.1 set-channel-line """""""""""""""""""""""""""""""""" :: set-channel-line(channel, filename, line) channel : Channel filename : File line : int .. Set the line number information for the channel. 指定されたチャネルの行番号情報を設定します。 .. _label10.11: 10.11 高レベルな I/O 関数 ---------------------------------- .. _label10.11.1: 10.11.1 正規表現 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. Many of the higher-level functions use regular expressions. Regular expressions are defined by strings with syntax nearly identical to awk(1). 多くの高レベルな関数では正規表現を使用しています。正規表現はawk(1)の文法とだいたい似ている文字列から成り立っています。 .. Strings may contain the following character constants. 文字列には以下の文字定数を含めることができます。 .. a literal backslash. the alert character ^G. the backspace character ^H. the formfeed character ^L. the newline character ^J. the carriage return character ^M. the tab character ^I. the vertical tab character. the character represented by the string of hexadecimal digits h. All valid hexadecimal digits following the sequence are considered to be part of the sequence. the character represented by 1, 2, or 3 octal digits. * ``\\`` : バックスラッシュ文字 * ``\a`` : アラート文字 ``^G`` * ``\b`` : バックスペース文字 ``^H`` * ``\f`` : 改ページ文字 ``^L`` * ``\n`` : 改行文字 ``^J`` * ``\r`` : キャリッジリターン(復帰,CR)文字 ``^M`` * ``\t`` : タブ文字 ``^I`` * ``\v`` : 垂直タブ文字 * ``\xhh...`` : 16進数として表現される文字列 ``h`` 。すべての正しい16進数文字列はシーケンス文字列の一部として扱われます。 * ``\ddd`` : 1〜3桁の8進数として扱われる文字列 .. Regular expressions are defined using the special characters .\^$[(){}*?+. 正規表現は特殊文字 ``.\^$[(){}*?+`` を使うことができます。 .. matches the literal character c if c is not a special character. matches the literal character c, even if c is a special character. matches any character, including newline. matches the beginning of a line. matches the end of line. matches any of the characters abc... matches any character except abc... matches either r1 or r2. matches r1 and then r2. matches one or more occurrences of r. matches zero or more occurrences of r. matches zero or one occurrence of r. parentheses are used for grouping; matches r. also defines grouping, but the expression matched within the parentheses is available to the output processor through one of the variables $1, $2, ... matches exactly n occurrences of r. matches n or more occurrences of r. matches at least n occurrences of r, and no more than m occurrences. matches the empty string at either the beginning or end of a word. matches the empty string within a word. matches the empty string at the beginning of a word. matches the empty string at the end of a word. matches any character in a word. matches any character that does not occur within a word. matches the empty string at the beginning of a file. matches the empty string at the end of a file. * ``c`` : ``c`` が特殊文字でない場合は文字通りに扱います。 * ``\c`` : ``c`` が特殊文字であっても、 ``c`` を文字通りに扱います。 * ``.`` : 改行を含む、任意の文字にマッチします。 * ``^`` : 行の始めにマッチします。 * ``$`` : 行の終わりにマッチします。 * ``[abc...]`` : ``abc...`` の任意の文字にマッチします。 * ``[^abc...]`` : ``abc...`` を除く、任意の文字にマッチします。 * ``r1|r2`` : ``r1`` と ``r2`` のいづれかであった場合はマッチします。 * ``r1r2`` : ``r1`` の次に ``r2`` が来ていた場合はマッチします。 * ``r+`` : 1以上の ``r`` の文字列にマッチします。 * ``r*`` : 0以上の ``r`` の文字列にマッチします。 * ``r?`` : 0もしくは1つの ``r`` にマッチします。 * ``(r)`` : ``r`` にマッチします。括弧はグループ化のために用いられます。 * ``\(r\)`` : グループとして扱われますが、括弧の中でマッチした式は変数 ``$1`` , ``$2`` , ... を通して参照することができます。 * ``r{n}`` : ``r`` が正確に ``n`` 回続いている場合はマッチします。 * ``r{n,}`` : ``r`` が ``n`` 回以上続いている場合はマッチします。 * ``r{n,m}`` : ``r`` が ``n`` 回以上 ``m`` 回以下続いている場合はマッチします。 * ``\y`` : 単語の始まりあるいは単語が終わった後の空文字にマッチします。 * ``\B`` : 単語の中にある空文字にマッチします。 * ``\<`` : 単語の始まりの空文字にマッチします。 * ``\>`` : 単語が終わった後のから文字にマッチします。 * ``\w`` : 単語の任意の文字にマッチします。 * ``\W`` : 単語の中に入っていない、任意の文字にマッチします。 * ``\~`` : ファイルの始まりの空文字にマッチします。 * ``\'`` : ファイルの終わりの空文字にマッチします。 .. Character classes can be used to specify character sequences abstractly. Some of these sequences can change depending on your LOCALE. 上の文字クラスは文字のシーケンスを絶対的に指定するのに用いられます。これらのシーケンスはあなたの言語環境次第で変更することもできます。 * ``[:alnum:]`` : 英数字文字 * ``[:alpha:]`` : アルファベット文字 * ``[:lower:]`` : アルファベット小文字 * ``[:upper:]`` : アルファベット大文字 * ``[:cntrl:]`` : 制御文字 * ``[:digit:]`` : 数字 * ``[:xdigit:]`` : 数字あるいは16進数文字 * ``[:graph:]`` : 出力可能でかつ表示可能な文字 * ``[:print:]`` : 出力可能で、表示可能あるいは不可能な文字 * ``[:punct:]`` : 句読点文字 * ``[:blank:]`` : スペースかタブ文字 * ``[:space:]`` : ホワイトスペース文字 .. index:: single: cat() .. _label10.11.2: 10.11.2 cat ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :: cat(files) : Sequence files : File or InChannel Sequence .. The cat function concatenates the output from multiple files and returns it as a string. ``cat`` 関数は複数のファイルを連結し、文字列として返します。 .. index:: single: grep() .. _label10.11.3: 10.11.3 grep ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :: grep(pattern) : String # stdin から入力され、デフォルトのオプションが用いられる pattern : String grep(pattern, files) : String # デフォルトのオプションが用いられる pattern : String files : File Sequence grep(options, pattern, files) : String options : String pattern : String files : File Sequence .. The grep function searches for occurrences of a regular expression pattern in a set of files, and prints lines that match. This is like a highly-simplified version of grep(1). ``grep`` 関数はファイルの集合から正規表現 ``pattern`` に適合しているものを検索し、マッチした行を表示します。これはgrep(1)の高度に簡素化されたバージョンです。 .. The options are オプションは以下の通りです。 .. If specified, the output from grep is not displayed. If specified, output lines will not include the filename (default, when only one input file is given). If specified, output lines include the filename (default, when more than one input file is given). If specified, search for lines without a match instead of lines with a match, * **q** : 指定した場合、 ``grep`` からの出力は表示されません。 * **h** : 指定した場合、出力された行はファイル名を含めません(一つの入力ファイルだけが与えられた場合のデフォルト)。 * **n** : 指定した場合、出力された行はファイル名を含めます(複数の入力ファイルが与えられた場合のデフォルト)。 * **v** : 指定した場合、マッチした行の代わりにマッチしなかった行を出力します。 .. The pattern is a regular expression. ``pattern`` は正規表現です。 .. If successful (grep found a match), the function returns true. Otherwise, it returns false. もし成功した ( ``grep`` がマッチした行を見つけた)場合、この関数は ``true`` を返します。そうでない場合は ``false`` を返します。 .. index:: single: scan() .. _label10.11.4: 10.11.4 scan ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :: scan(input-files) case string1 body1 case string2 body2 ... default bodyd .. The scan function provides input processing in command-line form. The function takes file/filename arguments. If called with no arguments, the input is taken from stdin. If arguments are provided, each specifies an InChannel, or the name of a file for input. Output is always to stdout. ``scan`` 関数はコマンドライン上からの入力機能を提供します。この関数はファイル、あるいはファイル名を引数にとります。もし何も引数が呼ばれなかった場合、 ``stdin`` から入力されます。もし引数が指定された場合、各々の引数には ``InChannel`` が指定されるか、入力としてファイル名が用いられます。なお、出力は常に ``stdout`` です。 .. The scan function operates by reading the input one line at a time, and processing it according to the following algorithm. ``scan`` 関数は入力から一行を読み込み、以下のアルゴリズムに従って処理を行います。 .. For each line, the record is first split into fields, and the fields are bound to the variables $1, $2, .... The variable $0 is defined to be the entire line, and $* is an array of all the field values. The $(NF) variable is defined to be the number of fields. 各々の行で、レコードはまずいくつかのフィールドに分割され、それらのフィールドは変数 ``$1, $2, ...`` に束縛されます。変数 ``$0`` は行全体として定義されており、 ``$*`` はすべてのフィールドの値が定義されている配列です。 ``$(NF)`` 変数はフィールドの数が定義されています。 .. Next, a case expression is selected. If string_i matches the token $1, then body_i is evaluated. If the body ends in an export, the state is passed to the next clause. Otherwise the value is discarded. 次に ``case`` 文が実行されます。もし ``string_i`` がトークン ``$i`` にマッチした場合、 ``body_i`` が評価されます。もし ``case`` の内容が ``export`` で終わっていたのなら、現在の状態は次の宣言句へ受け継がれます。そうでない場合、この値は捨てられます。 .. For example, here is an scan function that acts as a simple command processor. 例えば、以下の ``scan`` 関数は単純なコマンドプロセッサのように振る舞います。 :: calc() = i = 0 scan(script.in) case print println($i) case inc i = $(add $i, 1) export case dec i = $(sub $i, 1) export case addconst i = $(add $i, $2) export default eprintln($"Unknown command: $1") .. The scan function also supports several options. ``scan`` 関数はまたいくつかのオプションをサポートしています。 :: scan(options, files) ... .. Parse each line as an argument list, where arguments may be quoted. For example, the following line has three words, “ls”, “-l”, “Program Files”. Parse each line using white space as the separator, using the usual OMake algorithm for string parsing. This is the default. Once each line is split, reduce each word using the hex representation. This is the usual hex representation used in URL specifiers, so the string “Program Files” may be alternately represented in the form ProgramProgram+Files. * **A** : 各々の行を引数のリストとして、クオート化された状態でパースします。例えば、以下の行は3つのワード "``ls``" , "``-l``" , "``Program Files``" を持つことになります: ``ls -l "Program Files"`` * **O** : 各々の行を、ホワイトスペースをセパレータとしてパースします。これは通常OMakeが文字列をパースする際のアルゴリズムを使用しています。この動作はデフォルトです。 * **x** : 各々の行を分割し、さらに16進数表現を用いてワードの個数を減らします。これはURLを指定する際には通常16進数表現が用いられるためです。例えば、文字列 ``Program Files`` は代わりに以下の形 ``Program+Files`` に置き換わります。 .. note:: もしあなたが出力をファイルにリダイレクトしたい場合、最も簡単な方法は ``stdout`` 変数を再定義することです。 ``stdout`` 変数は他の変数と同様スコープ化されているので、この再定義は ``calc`` 関数の外にある ``stdout`` には影響を及ぼしていません。 :: calc() = stdout = $(fopen script.out, w) scan(script.in) ... close(stdout) .. index:: single: awk() .. _label10.11.5: 10.11.5 awk ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :: awk(input-files) case pattern1: body1 case pattern2: body2 ... default: bodyd あるいは :: awk(options, input-files) case pattern1: body1 case pattern2: body2 ... default: bodyd .. The awk function provides input processing similar to awk(1), but more limited. The input-files argument is a sequence of values, each specifies an InChannel, or the name of a file for input. If called with no options and no file arguments, the input is taken from stdin. Output is always to stdout. ``awk`` 関数はawk(1)と似た入力機能を提供します。が、この関数は制限されています。引数 ``input-files`` には値のシーケンスを指定することで、各々の値には ``InChannel`` が指定されるか、入力としてファイル名が用いられます。もしオプションとファイルの引数が何も指定されなかったら、入力は ``stdin`` が用いられます。なお、出力は常に ``stdout`` です。 .. The variables RS and FS define record and field separators as regular expressions. The default value of RS is the regular expression \r|\n|\r\n. The default value of FS is the regular expression [ \t]+. .. The awk function operates by reading the input one record at a time, and processing it according to the following algorithm. 変数 ``RS`` と ``FS`` にはレコードとフィールドを分割するセパレータが正規表現の形で定義されています。なお、デフォルトの ``RS`` の値は正規表現 ``\r|\n|\r\n`` で、 ``FS`` は ``[ \t]+`` です。 .. For each line, the record is first split into fields using the field separator FS, and the fields are bound to the variables $1, $2, .... The variable $0 is defined to be the entire line, and $* is an array of all the field values. The $(NF) variable is defined to be the number of fields. ``awk`` 関数は入力から一つのレコードを読み込み、以下のアルゴリズムに従って処理を行います。 各々の行で、レコードはまずフィールドセパレータ ``FS`` を用いていくつかのフィールドに分割され、それらのフィールドは変数 ``$1, $2, ...`` に束縛されます。変数 ``$0`` は行全体として定義されており、 ``$*`` はすべてのフィールドの値が定義されている配列です。変数 ``$(NF)`` はフィールドの数が定義されています。 .. Next, the cases are evaluated in order. For each case, if the regular expression pattern_i matches the record $0, then body_i is evaluated. If the body ends in an export, the state is passed to the next clause. Otherwise the value is discarded. If the regular expression contains \(r\) expression, those expression override the fields $1, $2, .... 次に、 ``case`` が順番どおりに評価されていきます。各々の ``case`` において、もし正規表現 ``pattern_i`` がレコード ``$0`` にマッチしていた場合は、 ``body_i`` が評価されます。もし ``body_i`` が ``export`` で終わっていたのなら、現在の状態は次の宣言句へ受け継がれます。そうでない場合、この値は捨てられます。もし正規表現が ``\(r\)`` を含んでいたのなら、フィールド ``$1, $2, ...`` はこれらの表現で書き換えられます。 .. For example, here is an awk function to print the text between two delimiters \begin{} and \end{}, where the must belong to a set passed as an argument to the filter function. 例えば、以下のコードはテキストが二つのデリミタ ``\begin{}`` と ``\end{}`` の間にあり、さらに ``filter`` 関数の引数として渡された配列の中に ```` が入っているときだけ、その間のテキストを出力しています。 :: filter(names) = print = false awk(Awk.in) case $"^\\end\{\([:alpha:]+\)\}" if $(mem $1, $(names)) print = false export export default if $(print) println($0) case $"^\\begin\{\([:alpha:]+\)\}" print = $(mem $1, $(names)) export .. Note, if you want to redirect the output to a file, the easiest way is to redefine the stdout variable. The stdout variable is scoped the same way as other variables, so this definition does not affect the meaning of stdout outside the filter function. .. note:: もしあなたが出力をファイルにリダイレクトしたい場合、最も簡単な方法は ``stdout`` 変数を再定義することです。 ``stdout`` 変数は他の変数と同様スコープ化されているので、この再定義は ``filter`` 関数の外にある ``stdout`` には影響を及ぼしていません。 :: filter(names) = stdout = $(fopen file.out, w) awk(Awk.in) ... close(stdout) .. Options. オプション : .. “Break” when evaluating cases. Only the first case that matches will be selected. * **b** : ``case`` を評価する際にループを『中断(Break)』します。ただし、複数のマッチ文が選択されるような場合のみです。 .. The break function can be used to abort the loop, exiting the awk function immediately. ``break`` 関数はループを停止する際に用いられます。これを用いると ``awk`` 関数は即座に中断します。 .. index:: single: fsubst() .. _label10.11.6: 10.11.6 fsubst ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :: fsubst(files) case pattern1 [options] body1 case pattern2 [options] body2 ... default bodyd .. The fsubst function provides a sed(1)-like substitution function. Similar to awk, if fsubst is called with no arguments, the input is taken from stdin. If arguments are provided, each specifies an InChannel, or the name of a file for input. ``fsubst`` 関数は ``sed(1)`` のような置換機能を提供します。 ``awk`` と似ていて、もし ``fsubst`` が何の引数も指定されずに呼び出された場合、入力は ``stdin`` が用いられます。もし引数が与えられていた場合、各々の引数は ``InChannnel`` が指定されるか、入力としてファイル名が用いられます。 .. The RS variable defines a regular expression that determines a record separator, The default value of RS is the regular expression \r|\n|\r\n. ``RS`` 変数はレコードのセパレータを指定する正規表現が定義されており、 ``RS`` のデフォルトの値は ``\r|\n|\r\n`` です。 .. The fsubst function reads the file one record at a time. ``fsubst`` 関数は1回につき1つのレコードを読み込みます。 .. For each record, the cases are evaluated in order. Each case defines a substitution from a substring matching the pattern to replacement text defined by the body. 各々のレコードで、 ``case`` 文は順番どおりに評価されます。各々の ``case`` ではマッチした ``pattern`` を、定義された文字列に置換する機構について定義しています。 .. Currently, there is only one option: g. If specified, each clause specifies a global replacement, and all instances of the pattern define a substitution. Otherwise, the substitution is applied only once. 現在のところ、omakeでは ``g`` オプションだけがサポートされています。指定した場合、各々の宣言句は全体の置換を行い、すべての ``pattern`` のインスタンスによって置換が行われます。そうでない場合、置換は1回だけ行われます。 .. Output can be redirected by redefining the stdout variable. 出力は ``stdout`` 変数を再定義することによってリダイレクトできます。 .. For example, the following program replaces all occurrences of an expression word. with its capitalized form. 例えば、以下のプログラムは ``word`` に適合した文字列すべてを大文字化し、置換します。 :: section stdout = $(fopen Subst.out, w) fsubst(Subst.in) case $"\<\([[:alnum:]]+\)\." g value $(capitalize $1). close(stdout) .. index:: single: lex() .. _label10.11.7: 10.11.7 lex ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :: lex(files) case pattern1 body1 case pattern2 body2 ... default bodyd .. The lex function provides a simple lexical-style scanner function. The input is a sequence of files or channels. The cases specify regular expressions. Each time the input is read, the regular expression that matches the longest prefix of the input is selected, and the body is evaluated. ``lex`` 関数はシンプルな文法解析器を提供します。入力はファイルやチャネルのシーケンスです。 ``case`` には正規表現を指定します。この関数は入力を読み込むたび、 *最も長い接頭辞* にマッチした正規表現を選択し、その内容を評価します。 .. If two clauses both match the same input, the last one is selected for execution. The default case matches the regular expression .; you probably want to place it first in the pattern list. 同じ長さで2つの ``case`` 文がマッチしてしまった場合、 *後ろの* ``case`` 文が実行されます。 ``default`` 文は正規表現 ``.`` にマッチするので、パターンリストの最初に設置するのが恐らく望ましいでしょう。 .. If the body end with an export directive, the state is passed to the next clause. もし ``case`` の内容が ``export`` で終わっていたのなら、現在の状態は次のループへ受け継がれます。 .. For example, the following program collects all occurrences of alphanumeric words in an input file. 例えば、以下のプログラムは入力されたファイルからすべての英数字を集めます。 :: collect-words($(files)) = words[] = lex($(files)) default # empty case $"[[:alnum:]]+" g words[] += $0 export .. The default case, if one exists, matches single characters. Since It is an error if the input does not match any of the regular expressions. ``default`` 文が存在する場合、この文は任意の1つの文字のみにマッチします。また、もし入力がどの正規表現にもマッチしなかった場合、この関数はエラーとなります。 .. The break function can be used to abort the loop. ``break`` 関数はループを停止する際に用いられます。 .. index:: single: lex-search() .. _label10.11.8: 10.11.8 lex-search ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :: lex-search(files) case pattern1 body1 case pattern2 body2 ... default bodyd .. The lex-search function is like the lex function, but input that does not match any of the regular expressions is skipped. If the clauses include a default case, then the default matches any skipped text. ``lex-search`` 関数は ``lex`` 関数と似ていますが、この関数はどの正規表現にもマッチしなかった入力をスキップします。 ``default`` 文を含んでいた場合、 ``default`` はすべてのスキップしたテキストにマッチします。 .. For example, the following program collects all occurrences of alphanumeric words in an input file, skipping any other text. 例えば、以下のプログラムは入力されたファイルからすべての英数字文字を集め、含まれていない他のテキストはスキップします。 :: collect-words($(files)) = words[] = lex-search($(files)) default eprintln(Skipped $0) case $"[[:alnum:]]+" g words[] += $0 export .. The default case, if one exists, matches single characters. Since It is an error if the input does not match any of the regular expressions. ``default`` 文が存在する場合、この文は任意の1つの文字のみにマッチします。また、もし入力がどの正規表現にもマッチしなかった場合、この関数はエラーとなります。 .. The break function can be used to abort the loop. ``break`` 関数はループを停止する際に用いられます。 .. index:: single: Lexer .. _label10.11.9: 10.11.9 Lexer ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. The Lexer object defines a facility for lexical analysis, similar to the lex(1) and flex(1) programs. ``Lexer`` オブジェクトは容易に字句解析を行えるようにするオブジェクトで、 ``lex(1)`` や ``flex(1)`` プログラムと似ています。 .. In omake, lexical analyzers can be constructed dynamically by extending the Lexer class. A lexer definition consists of a set of directives specified with method calls, and set of clauses specified as rules. omakeでは、字句の解析は ``Lexer`` クラスを継承することによって動的に構成することができます。字句解析器(以後レキサと呼ぶ)の定義はメソッドを呼び出すことで指示文(directive)を指定しているものの集合と、ルールとして宣言句(clause)を指定しているものの集合によって成り立っています。 .. For example, consider the following lexer definition, which is intended for lexical analysis of simple arithmetic expressions for a desktop calculator. 例えば、以下のシンプルなデスクトップ電卓の演算の字句解析を行う、レキサの定義について考えてみましょう。 :: lexer1. = extends $(Lexer) other: . eprintln(Illegal character: $* ) lex() white: $"[[:space:]]+" lex() op: $"[-+*/()]" switch $* case + Token.unit($(loc), plus) case - Token.unit($(loc), minus) case * Token.unit($(loc), mul) case / Token.unit($(loc), div) case $"(" Token.unit($(loc), lparen) case $")" Token.unit($(loc), rparen) number: $"[[:digit:]]+" Token.pair($(loc), exp, $(int $* )) eof: $"\'" Token.unit($(loc), eof) .. This program defines an object lexer1 the extends the Lexer object, which defines lexing environment. このプログラムは ``Lexer`` オブジェクトから字句解析の環境を定義している ``lexer1`` を継承しています。 .. The remainder of the definition consists of a set of clauses, each with a method name before the colon; a regular expression after the colon; and in this case, a body. The body is optional, if it is not specified, the method with the given name should already exist in the lexer definition. 残りの定義では宣言句の集合の定義を行っています。コロン(:)の前にはメソッド名を指定し、コロンの後には正規表現を指定します。この場合は内容も指定しています。内容はなくても構いません。指定されなかった場合、レキサの定義で既に存在している、与えられたメソッド名が用いられます。 .. NB The clause that matches the longest prefix of the input is selected. If two clauses match the same input prefix, then the last one is selected. This is unlike most standard lexers, but makes more sense for extensible grammars. .. warning:: *最も長い* 接頭辞にマッチした宣言句が選択されます。もし2つの宣言句が同じ長さの場合、 *後ろの* 宣言句が選択されます。これはほとんどの標準的なレキサとな異なっていますが、拡張性から見ればこの仕様は大きな意味を持ちます。 .. The first clause matches any input that is not matched by the other clauses. In this case, an error message is printed for any unknown character, and the input is skipped. Note that this clause is selected only if no other clause matches. 最初の宣言句は他の宣言句にマッチしなかった任意の入力文字列がマッチします。この場合、未知の文字のエラーメッセージが出力されます。この宣言句は他の宣言句にマッチしなかった場合のみ選択されることに注意してください。 .. The second clause is responsible for ignoring white space. If whitespace is found, it is ignored, and the lexer is called recursively. 2番目の宣言句ではホワイトスペースを無視する役割を持っています。ホワイトスペースが見つかった場合、これを無視し、再帰的にレキサを呼び出します。 .. The third clause is responsible for the arithmetic operators. It makes use of the Token object, which defines three fields: a loc field that represents the source location; a name; and a value. 3番目の宣言句では演算子の役割を持っています。ここでは ``Token`` オブジェクトを利用しています。なお、この ``Token`` オブジェクトは3つのプロパティ(ソース位置を表現している ``loc`` , ``name`` , ``value``)を定義しています。 .. The lexer defines the loc variable to be the location of the current lexeme in each of the method bodies, so we can use that value to create the tokens. レキサは各々のメソッドの ``body`` 部で、現在の語彙素(lexeme)の位置を表す ``loc`` 変数が定義されているので、私たちはトークンを生成するためにこの値を用いています。 .. The Token.unit($(loc), name) method constructs a new Token object with the given name, and a default value. ``Token.unit($(loc), name)`` メソッドは与えられた名前とデフォルトの値を用いて新しい ``Token`` オブジェクトを構成します。 .. The number clause matches nonnegative integer constants. The Token.pair($(loc), name, value) constructs a token with the given name and value. ``number`` 宣言句は正の整数の定数にマッチします。 ``Token.pair($(loc), name, value)`` は与えられた名前と値でトークンを構成します。 .. Lexer object operate on InChannel objects. The method lexer1.lex-channel(channel) reads the next token from the channel argument. ``Lexer`` オブジェクトは ``InChannel`` オブジェクトを操作します。 ``lexer1.lex-channel(channel)`` メソッドは与えられたチャネルから次のトークンを読み込みます。 .. _label10.11.10: 10.11.10 レキサのマッチング ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. During lexical analysis, clauses are selected by longest match. That is, the clause that matches the longest sequence of input characters is chosen for evaluation. If no clause matches, the lexer raises a RuntimeException. If more than one clause matches the same amount of input, the first one is chosen for evaluation. 字句解析においては、最も長くマッチした宣言句が選択されます。これは、最も長い入力文字のシーケンスにマッチした宣言句が評価対象になるということです。もしどの宣言句にもマッチしなかった場合、レキサは ``RuntimeException`` を送出します。もし1つ以上の宣言句が同じ量の入力にマッチした場合、最初の1つが評価に用いられます。 .. _label10.11.11: 10.11.11 拡張したレキサの定義 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. Suppose we wish to augment the lexer example so that it ignores comments. We will define comments as any text that begins with the string (*, ends with *), and comments may be nested. それでは前回のレキサのサンプルを、コメントを無視するように拡張してみましょう。ここで、コメントを ``(*`` から ``*)`` で終わる任意のテキストとして定義します。なお、コメントはネスト化されているものとします。 .. One convenient way to do this is to define a separate lexer just to skip comments. これを実現する一つの簡単な方法としては、コメントをスキップする別のレキサを定義することが挙げられます。 :: lex-comment. = extends $(Lexer) level = 0 other: . lex() term: $"[*][)]" if $(not $(eq $(level), 0)) level = $(sub $(level), 1) lex() next: $"[(][*]" level = $(add $(level), 1) lex() eof: $"\'" eprintln(Unterminated comment) .. This lexer contains a field level that keeps track of the nesting level. On encountering a (* string, it increments the level, and for *), it decrements the level if nonzero, and continues. このレキサには、ネストレベルを記録し続けている ``lebel`` プロパティを含んでいます。 ``(*`` に遭遇すると、この変数はレベルを1増やし、 ``*)`` が来たら、0でない場合はレベルを1減らし、続けます。 .. Next, we need to modify our previous lexer to skip comments. We can do this by extending the lexer object lexer1 that we just created. 次に、前回のレキサを、コメントをスキップするような形に修正してみましょう。これはちょうど前に作った ``lexer1`` オブジェクトを拡張することで実現できます。 :: lexer1. += comment: $"[(][*]" lex-comment.lex-channel($(channel)) lex() .. The body for the comment clause calls the lex-comment lexer when a comment is encountered, and continues lexing when that lexer returns. ``comment`` 宣言句の内容にはコメントに遭遇した場合、 ``lex-comment`` レキサを呼び出し、このレキサが返されたときに解析し続けることを指定しています。 .. _label10.11.12: 10.11.12 lexerオブジェクトを扱いやすくする ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. Clause bodies may also end with an export directive. In this case the lexer object itself is used as the returned token. If used with the Parser object below, the lexer should define the loc, name and value fields in each export clause. Each time the Parser calls the lexer, it calls it with the lexer returned from the previous lex invocation. 宣言句の内容はまた指示文のエクスポートで終了します。この場合、レキサオブジェクト自身がトークンを返すものとして使われます。もしレキサオブジェクトの上で ``Parser`` オブジェクトを使うのであれば、レキサは ``loc`` , ``name`` , ``value`` プロパティを、各々の ``export`` 宣言句の中で定義すべきです。毎回 ``Parser`` オブジェクトはレキサを呼び出し、さらに前回のレキサを起動することで返されるレキサを呼び出します。 .. index:: single: Parser .. _label10.11.13: 10.11.13 Parser ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. The ``Parser`` object provides a facility for syntactic analysis based on context-free grammars. ``Parser`` オブジェクトは『文脈自由な文法(context-free grammars)』をベースとした、文法解析機能を提供しています。 .. ``Parser`` objects are specified as a sequence of directives, specified with method calls; and productions, specified as rules. ``Parser`` オブジェクトは指示文のシーケンスとして指定されます。また、 ``Parser`` オブジェクトはメソッドの呼び出し、生成、ルールの指定も担当しています。 .. For example, let's finish building the desktop calculator started in the ``Lexer`` example. 例えば、前回の ``Lexer`` のサンプルを使って、デスクトップ計算機を作ってみましょう。 :: parser1. = extends $(Parser) # # 主に使うレキサを定義 # lexer = $(lexer1) # # 昇順に優先順位を定義 # left(plus minus) left(mul div) right(uminus) # # プログラム # start(prog) prog: exp eof return $1 # # 単純な算術式定義 # exp: minus exp :prec: uminus neg($2) exp: exp plus exp add($1, $3) exp: exp minus exp sub($1, $3) exp: exp mul exp mul($1, $3) exp: exp div exp div($1, $3) exp: lparen exp rparen return $2 .. Parsers are defined as extensions of the ``Parser`` class. A Parser object must have a ``lexer`` field. The ``lexer`` is not required to be a ``Lexer`` object, but it must provide a ``lexer.lex()`` method that returns a token object with ``name`` and ``value`` fields. For this example, we use the ``lexer1`` object that we defined previously. パーサは ``Parser`` クラスの式として定義されています。パーサオブジェクトは ``lexer`` プロパティを持たなければなりません。 ``lexer`` は ``Lexer`` オブジェクトでなければならないというわけではありませんが、トークンオブジェクトを返す ``lexer.lex()`` メソッドと ``name`` , ``value`` プロパティを提供していなければなりません。例えば、今回私たちは前回の項で定義した ``lexer1`` オブジェクトを使用しました。 .. The next step is to define precedences for the terminal symbols. The precedences are defined with the ``left``, ``right``, and ``nonassoc`` methods in order of increasing precedence. 次のステップでは演算子記号の優先順位を定義します。優先順位は ``left`` , ``right`` , ``nonassoc`` メソッドの順に上がっていきます( ``left`` が一番下で ``nonassoc`` が一番上)。 .. The grammar must have at least one start symbol, declared with the ``start`` method. 文法(grammar)は最低でも一つの開始記号を持たなければなりません。これは ``start`` メソッドで宣言できます。 .. Next, the productions in the grammar are listed as rules. The name of the production is listed before the colon, and a sequence of variables is listed to the right of the colon. The body is a semantic action to be evaluated when the production is recognized as part of the input. 次に、文法の中の短文(productions)はルールに従って並べられます。短文の名前はコロンの前に指定し、変数のシーケンスはコロンの後に指定します。内容部には、短文が入力の一部として解釈された場合における、意味論的な行動(semantic action)を指定します。 .. In this example, these are the productions for the arithmetic expressions recognized by the desktop calculator. The semantic action performs the calculation. The variables ``$1, $2, ...`` correspond to the values associated with each of the variables on the right-hand-side of the production. 今回の例では、デスクトップの計算機によって解析された算術式を生成しています。今回の場合、『意味論的な行動』は数値計算としてふるまいます。変数 ``$1, $2, ...`` は短文の右から順に、各々の変数に関連付けられた値として扱われます。 .. _label10.11.14: 10.11.14 パーサの呼び出し ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. The parser is called with the ``$(parser1.parse-channel start, channel)`` or ``$(parser1.parse-file start, file)`` functions. The start argument is the start symbol, and the channel or file is the input to the parser. パーサは ``$(parser1.parse-channel start, channel)`` や ``$(parser1.parse-file start, file)`` で呼び出されます。 ``start`` 引数には開始記号を指定し、 ``channel`` あるいは ``file`` にはパーサへの入力を指定します。 .. _label10.11.15: 10.11.15 パースの制御 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. The parser generator generates a pushdown automation based on LALR(1) tables. As usual, if the grammar is ambiguous, this may generate shift/reduce or reduce/reduce conflicts. These conflicts are printed to standard output when the automaton is generated. By default, the automaton is not constructed until the parser is first used. The ``build(debug)`` method forces the construction of the automaton. While not required, it is wise to finish each complete parser with a call to the ``build(debug)`` method. If the ``debug`` variable is set, this also prints with parser table together with any conflicts. The ``loc`` variable is defined within action bodies, and represents the input range for all tokens on the right-hand-side of the production. .. _label10.11.16: 10.11.16 拡張したパーサ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Parsers may also be extended by inheritance. For example, let's extend the grammar so that it also recognizes the ``<<`` and ``>>`` shift operations. First, we extend the lexer so that it recognizes these tokens. This time, we choose to leave ``lexer1`` intact, instead of using the += operator. :: lexer2. = extends $(lexer1) lsl: $"<<" Token.unit($(loc), lsl) asr: $">>" Token.unit($(loc), asr) Next, we extend the parser to handle these new operators. We intend that the bitwise operators have lower precedence than the other arithmetic operators. The two-argument form of the ``left`` method accomplishes this. :: parser2. = extends $(parser1) left(plus, lsl lsr asr) lexer = $(lexer2) exp: exp lsl exp lsl($1, $3) exp: exp asr exp asr($1, $3) In this case, we use the new lexer ``lexer2``, and we add productions for the new shift operations. .. index:: single: Passwd .. _label10.11.17: 10.11.17 Passwd ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ``Passwd`` オブジェクトはシステムユーザのデータベース上にあるエントリを表現します。このオブジェクトは以下のプロパティを持っています。 * ``pw_name`` : ログインネーム * ``pw_passwd`` : 暗号化されたパスワード * ``pw_uid`` : ユーザのユーザID * ``pw_gid`` : ユーザのグループID * ``pw_gecos`` : ユーザ名かコメント欄 * ``pw_dir`` : ユーザのホームディレクトリ * ``pw_shell`` : ユーザが通常使うシェル すべてのプロパティがすべてのOS上で意味をもつわけではないことに注意してください。 .. index:: single: getpwnam() single: getpwuid() .. _label10.11.18: 10.11.18 getpwnam, getpwuid ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(getpwnam name...) : Passwd name : String $(getpwuid uid...) : Passwd uid : Int raises RuntimeException ``getpwnam`` 関数はユーザのログイン名からエントリを探しだします。 ``getpwuid`` 関数はユーザID(numerical id, uid)からエントリを探し出します。もしエントリが見つからなかった場合、例外が送出されます。 .. index:: single: getpwents() .. _label10.11.19: 10.11.19 getpwents ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(getpwents) : Array ``getpwents`` 関数は ``Passwd`` オブジェクトの配列を返します。すべてのユーザは、システムユーザのデータベースによって用意されます。この関数はOSやユーザデータベースの状況に依存し、返される配列は完全でなかったり、空である可能性もある点に注意してください。 .. index:: single: Group .. _label10.11.20: 10.11.20 Group ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ``Group`` オブジェクトはシステムのユーザグループに関するデータベースのエントリを表現します。このオブジェクトは以下のプロパティを含んでいます。 :: * ``gr_name`` : グループ名 * ``gr_group`` : 暗号化されたパスワード * ``gr_gid`` : グループのグループID * ``gr_mem`` : グループメンバのユーザ名 すべてのプロパティがすべてのOSで意味を持つわけでは無い点に注意してください。 .. index:: single: getgrnam() single: getgrgid() .. _label10.11.21: 10.11.21 getgrnam, getgrgid ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(getgrnam name...) : Group name : String $(getgrgid gid...) : Group gid : Int raises RuntimeException ``getgrnam`` 関数はグループ名からグループエントリを探しだし、 ``getgrgid`` 関数はグループID(gid)からエントリを探し出します。何も見つからなかった場合は例外が送出されます。 .. index:: single: tgetstr() .. _label10.11.22: 10.11.22 tgetstr ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(tgetstr id) : String id : String ``tgetstr`` 関数は指定された ``id`` を用いて『端末の能力(terminal capability, termcap)』を調べます。これは、"terminfo"の調査が ``TERM`` 環境変数によって与えられることを保証しています。もし与えられた"terminal capability"が定義されていなかった場合、この関数は空の値を返します。 .. note:: シェルプロンプト内部の ``tgetstr`` によって返された値を使用したい場合、あなたは ``prompt-invisible`` 関数を用いてラップする必要があります。 .. index:: single: xterm-escape-begin() single: xterm-escape-end() .. _label10.11.23: 10.11.23 xterm-escape-begin, xterm-escape-end ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(xterm-escape-begin) : String $(xterm-escape-end) : String ``xterm-escape-begin`` と ``xterm-escape-end`` 関数はXTermのウィンドウタイトルを設定したい場合に用いることができる、エスケープのシーケンスを返します。この機能が使えない場合、この関数は空の値を返します。 .. note:: シェルプロンプト内部の値を用いるようにしたい場合、あなたは ``$(prompt_invisible_begin)$(xterm-escape-begin)`` と ``$(xterm-escape-end)$(prompt_invisible_end)`` を使う必要があります。 .. index:: single: xterm-escape() .. _label10.11.24: 10.11.24 xterm-escape ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(xterm-escape s) : Sequence ``TERM`` 環境変数が『XTermのタイトルを設定する機能が利用できる』ことを表していた場合、 ``$(xterm-escape s)`` は ``$(xterm-escape-begin)s$(xterm-escape-end)`` と等価です。そうでない場合、この関数は空の値を返します。 .. note:: シェルプロンプト内部の ``xterm-escape`` によって返された値を用いるようにしたい場合、あなたは ``prompt-invisible`` 関数を使ってラップする必要があります。 .. index:: single: prompt-invisible-begin() single: prompt-invisible-end() .. _label10.11.25: 10.11.25 prompt-invisible-begin, prompt-invisible-end ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(prompt-invisible-begin) : String $(prompt-invisible-end) : String ``prompt-invisible-begin`` と ``prompt-invisible-end`` 関数は、シェルプロンプトに『見えない』セクション(様々なエスケープシーケンスのような)を設定するために用いる必要のある、エスケープのシーケンスを返します。 .. index:: single: prompt-invisible() .. _label10.11.26: 10.11.26 prompt-invisible ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(prompt-invisible s) : Sequence ``prompt-invisible`` は指定された引数を ``$(prompt-invisible-begin)`` と ``$(prompt-invisible-end)`` でラップします。シェルプロンプトに『見えない』すべてのセクション(様々なエスケープシーケンスのような)はこの方法でラップしなければなりません。 .. index:: single: gettimeofday() .. _label10.11.27: 10.11.27 gettimeofday ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(gettimeofday) : Float ``gettimeofday`` 関数は1970年1月1日から始まる、現在までの秒数を返します。