From owner-svn-src-user@FreeBSD.ORG Sun Sep 4 16:26:44 2011 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 3166D1065675; Sun, 4 Sep 2011 16:26:44 +0000 (UTC) (envelope-from gabor@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 16C778FC12; Sun, 4 Sep 2011 16:26:44 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id p84GQhKM098671; Sun, 4 Sep 2011 16:26:43 GMT (envelope-from gabor@svn.freebsd.org) Received: (from gabor@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p84GQhcw098669; Sun, 4 Sep 2011 16:26:43 GMT (envelope-from gabor@svn.freebsd.org) Message-Id: <201109041626.p84GQhcw098669@svn.freebsd.org> From: Gabor Kovesdan Date: Sun, 4 Sep 2011 16:26:43 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r225379 - user/gabor/tre-integration/tools/test/regex/printheur X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 04 Sep 2011 16:26:44 -0000 Author: gabor Date: Sun Sep 4 16:26:43 2011 New Revision: 225379 URL: http://svn.freebsd.org/changeset/base/225379 Log: - Add a simple test program to generate and print out regex heuristics Added: user/gabor/tre-integration/tools/test/regex/printheur/ user/gabor/tre-integration/tools/test/regex/printheur/Makefile (contents, props changed) user/gabor/tre-integration/tools/test/regex/printheur/printheur.c (contents, props changed) Added: user/gabor/tre-integration/tools/test/regex/printheur/Makefile ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/gabor/tre-integration/tools/test/regex/printheur/Makefile Sun Sep 4 16:26:43 2011 (r225379) @@ -0,0 +1,11 @@ +# $FreeBSD$ +.PATH: ${.CURDIR}/../../../../contrib/tre/lib + +PROG= printheur +NO_MAN= yes +SRCS= printheur.c tre-heuristic.c tre-fastmatch.c hashtable.c + +CFLAGS+= -I${.CURDIR}/../../../../contrib/tre/lib \ + -I${.CURDIR}/../../../../include + +.include Added: user/gabor/tre-integration/tools/test/regex/printheur/printheur.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/gabor/tre-integration/tools/test/regex/printheur/printheur.c Sun Sep 4 16:26:43 2011 (r225379) @@ -0,0 +1,76 @@ +/*- + * Copyright (C) 2011 Gabor Kovesdan + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include +#include +#include +#include + +#include "config.h" +#include "tre-heuristic.h" +#include "tre-internal.h" + +int +main(int argc, char *argv[]) +{ + heur_t h; + wchar_t *pat; + size_t siz; + int cflags, ret; + + siz = strlen(argv[1]); + pat = malloc(sizeof(wint_t) * (siz + 1)); + if (pat == NULL) + return (EXIT_FAILURE); + siz = mbstowcs(pat, argv[1], siz); + + while ((ret = getopt(argc, argv, "E")) != -1) + switch(ret) { + case 'E': + cflags |= REG_EXTENDED; + break; + default: + printf("Usage: %s [-E]\n", getprogname()); + exit(EXIT_FAILURE); + } + + ret = tre_compile_heur(&h, pat, siz, 0); + if (ret != 0) { + printf("No heuristic available.\n"); + exit (EXIT_SUCCESS); + } + + printf("%s\n", h.prefix ? "Prefix heuristic" : "Normal heuristic"); + printf("Start heuristic: %s\n", h.start->pattern); + if (!h.prefix) + printf("End heuristic: %s\n", h.end->pattern); + + return (EXIT_SUCCESS); +}