2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License, Version 1.0 only
2N/A * (the "License"). You may not use this file except in compliance
2N/A * with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A/* Copyright (c) 1988 AT&T */
2N/A/* All Rights Reserved */
2N/A
2N/A
2N/A/*
2N/A * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
2N/A * Use is subject to license terms.
2N/A */
2N/A
2N/A#pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.2 */
2N/A
2N/A/*LINTLIBRARY*/
2N/A
2N/A#include <sys/types.h>
2N/A#include <stdlib.h>
2N/A#include "utility.h"
2N/A
2N/A/*
2N/A * TYPE_REGEXP standard type
2N/A *
2N/A * usage:
2N/A * set_field_type(f, TYPE_REGEXP, expression);
2N/A *
2N/A * char * expression; regular expression REGCMP(3X)
2N/A */
2N/Aextern char *libform_regcmp(char *, char *);
2N/Aextern char *libform_regex(char *, char *, char *);
2N/Astatic char *make_rexp(va_list *);
2N/Astatic char *copy_rexp(char *);
2N/Astatic void free_rexp(char *);
2N/Astatic int fcheck_rexp(FIELD *, char *);
2N/A
2N/Astatic FIELDTYPE typeREGEXP =
2N/A{
2N/A ARGS, /* status */
2N/A 1, /* ref */
2N/A (FIELDTYPE *) 0, /* left */
2N/A (FIELDTYPE *) 0, /* right */
2N/A make_rexp, /* makearg */
2N/A copy_rexp, /* copyarg */
2N/A free_rexp, /* freearg */
2N/A fcheck_rexp, /* fcheck */
2N/A (PTF_int) 0, /* ccheck */
2N/A (PTF_int) 0, /* next */
2N/A (PTF_int) 0, /* prev */
2N/A};
2N/A
2N/AFIELDTYPE * TYPE_REGEXP = &typeREGEXP;
2N/A
2N/Astatic char *
2N/Amake_rexp(va_list *ap)
2N/A{
2N/A return (libform_regcmp(va_arg(*ap, char *), NULL));
2N/A /* (...)$n will dump core */
2N/A}
2N/A
2N/Astatic char *
2N/Acopy_rexp(char *arg)
2N/A{
2N/A char *rexp;
2N/A
2N/A if (arrayAlloc(rexp, (strlen(arg) + 1), char))
2N/A (void) strcpy(rexp, arg);
2N/A return (rexp);
2N/A}
2N/A
2N/Astatic void
2N/Afree_rexp(char *arg)
2N/A{
2N/A Free(arg);
2N/A}
2N/A
2N/Astatic int
2N/Afcheck_rexp(FIELD *f, char *arg)
2N/A{
2N/A return (libform_regex(arg, field_buffer(f, 0), NULL) ? TRUE : FALSE);
2N/A}