kstrmatch.c
最終更新:2009/10/10
001: /* kstrmatch.c 002: * 文字列マッチの例 003: * apr_strmatch_precompile / apr_strmatch 004: */ 005: 006: #define USAGE "Usage: kstrmatch <string> <pattern>\n" 007: 008: #include "apr_general.h" 009: #include "apr_file_io.h" 010: 011: #include "apr_strmatch.h" 012: 013: #include "mystab.h" 014: 015: int apr_my_main (int ac, char **av, apr_file_t * astdin, apr_file_t * astdout, apr_file_t * astderr, apr_pool_t * pool) { 016: 017: if (ac < 2) { 018: apr_file_printf(astderr, USAGE); 019: goto _ERROR_; 020: } 021: 022: /* apr_strmatch_precompile / apr_strmatch 023: * INCLUDE apr_strmatch.h 024: * LIB libapr-1.lib / libaprutil-1.lib 025: */ 026: { 027: const apr_strmatch_pattern *p; 028: const char *str = av[1]; 029: const char *pattern = av[2]; 030: const char *r; 031: 032: p = apr_strmatch_precompile(pool, pattern, 0); 033: 034: if (NULL != (r = apr_strmatch(p, str, strlen(str)))) { 035: apr_file_printf(astdout, "Matched.\nposition=[%d]\nmatched str=[%s].\n", r-str, r); 036: } else { 037: apr_file_printf(astdout, "Not matched.\n"); 038: } 039: 040: } 041: 042: apr_file_printf(astdout, "\ndone.\n"); 043: return 0; /* 正常終了 */ 044: 045: _ERROR_: 046: apr_file_printf(astderr, "\nfailed.\n"); 047: return 1; /* 異常終了 */ 048: } 049:
KAKU PROJECT (2009) |