1 /*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
8 *
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
13 *
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 *
20 * CDDL HEADER END
21 */
22 /* Copyright (c) 1988 AT&T */
23 /* All Rights Reserved */
24
25
26 /*
27 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
28 * Use is subject to license terms.
29 */
30
31 #pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.2 */
32
33 /*LINTLIBRARY*/
34
35 #include <sys/types.h>
36 #include <stdlib.h>
37 #include "utility.h"
38
39 /*
40 * TYPE_REGEXP standard type
41 *
42 * usage:
43 * set_field_type(f, TYPE_REGEXP, expression);
44 *
45 * char * expression; regular expression REGCMP(3X)
46 */
47 extern char *libform_regcmp(char *, char *);
48 extern char *libform_regex(char *, char *, char *);
49 static char *make_rexp(va_list *);
50 static char *copy_rexp(char *);
51 static void free_rexp(char *);
52 static int fcheck_rexp(FIELD *, char *);
53
54 static FIELDTYPE typeREGEXP =
55 {
56 ARGS, /* status */
57 1, /* ref */
58 (FIELDTYPE *) 0, /* left */
59 (FIELDTYPE *) 0, /* right */
60 make_rexp, /* makearg */
61 copy_rexp, /* copyarg */
62 free_rexp, /* freearg */
63 fcheck_rexp, /* fcheck */
64 (PTF_int) 0, /* ccheck */
65 (PTF_int) 0, /* next */
66 (PTF_int) 0, /* prev */
67 };
68
69 FIELDTYPE * TYPE_REGEXP = &typeREGEXP;
70
71 static char *
make_rexp(va_list * ap)72 make_rexp(va_list *ap)
73 {
74 return (libform_regcmp(va_arg(*ap, char *), NULL));
75 /* (...)$n will dump core */
76 }
77
78 static char *
copy_rexp(char * arg)79 copy_rexp(char *arg)
80 {
81 char *rexp;
82
83 if (arrayAlloc(rexp, (strlen(arg) + 1), char))
84 (void) strcpy(rexp, arg);
85 return (rexp);
86 }
87
88 static void
free_rexp(char * arg)89 free_rexp(char *arg)
90 {
91 Free(arg);
92 }
93
94 static int
fcheck_rexp(FIELD * f,char * arg)95 fcheck_rexp(FIELD *f, char *arg)
96 {
97 return (libform_regex(arg, field_buffer(f, 0), NULL) ? TRUE : FALSE);
98 }
99