Smart CODE | |
生成済みコードに関するオンラインガイド
|
#include <SGML.h> |
SGML_t * scRegisterSGMLMimeType( mimetype, dtd) char * mimetype; char * dtd; |
SGML_t * scRegisterHTML( mimetype) char * mimetype; |
int scRegisterSGMLErrorHandler( handler) void (*handler)(); |
int scAddTagCallback( sgm, tagname, type, callback, data) SGML_t * sgm; char * tagname; int type; void (*callback)(); void * data; |
int scAddAttrCallback( sgm, tagname, attrname, callback, data) SGML_t * sgm; char * tagname; char * attrname; void (*callback)(); void * data; |
int scProcessSGML( sgm, istream) SGML_t * sgm; InputStream istream; |
環境変数 DTDDIR |
配布の lib ディレクトリ内のライブラリ -lsgml |
SGML ライブラリは、入力データをフィルタするためのアップグレード可能な標準的なメカニズムを提供します。これは、HTML の解析に時間をとられないように用意されています。これは、特別な構文解析プログラムではなく、SGML User Group の提供する参照構文解析プログラムで、標準の HTML32 DTD を使用します。HTML 規格が進化するに従って、DTD をアップグレードできます。
これは、次のように使用できます。
SGML_t * scRegisterSGMLMimeType( mimetype, dtd) char * mimetype; char * dtd;これは、MIME 型を SGML DTD と関連付けるために使用します。もっとも一般的な例を次に示します。
SGML_t * sgm = scRegisterSGMLMimeType( "text/html", "HTML32.soc");もう 1 つの方法を次に示します。
SGML_t * scRegisterHTML( mimetype) char * mimetype;これは、テキストまたは html を HTML32 DTD に関連付けます。
void errorhandler( s) char * s;次を使用します。
int scRegisterSGMLErrorHandler( handler) void_f handler;
ON_ENTRY |
ON_EXIT |
ON_ATTR |
指定したルーチンを呼び出す時期を次のように指定します。
int mycallback( tag, attribute, type, call_data, client_data) char * tag; char * attribute; int type; void * call_data; void * client_data; int scAddTagCallback( sgm, tagname, type, callback, data) SGML_t * sgm; /* 解析プログラムは scRegisterSGMLMimeType を処理します */ char * tagname; /* 例: "LI" "MENU" "A" */ int type; /* ON_ENTRY (<MENU> 用) ON_EXIT (</MENU> 用) および ON_ATTR */ void (*callback)(); /* ルーチン */ void * data; /* ルーチンに渡したいデータ */
int scAddAttrCallback( sgm, tagname, attrname, callback, data) SGML_t * sgm; /* 解析プログラムは scRegisterSGMLMimeType を処理します */ char * tagname; /* 例: "A" または "MENU" */ char * attrname; /* 例: "SRC" または "href" */ void (*callback)(); /* ルーチン */ void * data; /* ルーチンに渡したいデータ */
int scProcessSGML( sgm, istream) SGML_t * sgm; /* 解析プログラムは scRegisterSGMLMimeType を処理します */ InputStream istream; /* サーバーからの入力ストリーム */これでドキュメントを解析します。
int processMyData ( sc_data_t * data ) { group0_t * group = (group0_t*)data->group; char * type = data->content_type; /* MIME 型 */ InputStream i = (InputStream) data->data; int len = data->content_length; return 0; }次に、上記の例に、入力ストリームが HTML の場合に解析が行われるようにコードを付加した例を示します。
int processMyData ( sc_data_t * data ) { group0_t * group = (group0_t*)data->group; char * type = data->content_type; /* MIME 型 */ InputStream i = (InputStream) data->data; int len = data->content_length; SGML_t * sgm; if ( strcmp( type, "text/html") != 0) return -1; sgm = scRegisterHTML( type); /* パーサーオブジェクト */ (void) scAddTagCallback( sgm, "A", ON_ENTRY, getanchor, "a-call"); (void) scAddAttrCallback( sgm, "A", "HREF", getlinkinfo, "href"); (void) scProcessSGML( sgm, i); return 0; }この例では、解析される入力でリンクが検出されたときに、getanchor ルーチンおよび getlinkinfo ルーチンが呼び出されます。
int getanchor( tag, attr, type, call_data, client_data) char * tag; char * attr; int type; void * call_data; void * client_data; { printf("anchor-start(%s)\n", client_data); } int getlinkinfo( tag, attr, type, call_data, client_data) char * tag; char * attr; int type; void * call_data; void * client_data; { printf( "%s=%s\n", client_data, call_data); }
次のようなツリーデータ構造が返されます。
typedef struct snode_s { char * s_tag; sattribute_t * s_attributes; int numchildren; union { struct snode_s * children; sdata_t * data; } body; struct snode_s * s_stackprev; struct snode_s * s_next; stag_t * s_ref; } DOCtree_t;
次に、SGML User Group によるこのソフトウェアのライセンスに関する文書の抜粋を紹介します。全テキストは、ソースに格納されています。
Standard Generalized Markup Language Users' Group (SGMLUG) SGML Parser Materials 1. License SGMLUG hereby grants to any user: (1) an irrevocable royalty-free, worldwide, non-exclusive license to use, execute, reproduce, display, perform and distribute copies of, and to prepare derivative works based upon these materials; and (2) the right to authorize others to do any of the foregoing. [...] (d) SGMLUG has no knowledge of any conditions that would impair its right to license the SGML Parser Materials. Notwithstanding the foregoing, SGMLUG does not make any warranties or representations that the SGML Parser Materials are free of claims by third parties of patent, copyright infringement or the like, nor does SGMLUG assume any liability in respect of any such infringement of rights of third parties due to USER's operation under this license.