nisgrep.c revision 49e7ca4919cec3229f6fab9730bafc7cf24dab23
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
*
* nis+ table grep utility
*/
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <regex.h>
extern int optind;
extern char *optarg;
extern char *nisname_index();
#define BINARY_STR "*BINARY*"
#define EXIT_MATCH 0
#define EXIT_NOMATCH 1
#define EXIT_ERROR 2
struct pl_data {
unsigned flags;
char ta_sep;
int *dfa_set; /* dfa_set[i] set if re_dfa[i] is valid */
};
#define PL_BINARY 1
#define PL_COUNT 2
#define PL_OBJECT 4
#define PL_NOCASE 8
static
char *
strlower(s)
char *s;
{
int i;
int len;
char *p;
if (p == NULL) {
}
/* this loop includes the terminating null */
for (i = 0; i < len; i++) {
if (isupper(s[i]))
p[i] = tolower(s[i]);
else
p[i] = s[i];
}
return (p);
}
int
char *tab;
void *udata;
{
int len;
char *val;
int res;
register int i;
/*
* check for matches with all patterns
*/
for (i = 0; i < ncol; i++)
if (d->dfa_set[i]) {
if (len == 0)
return (0);
return (0);
} else {
}
switch (res) {
case REG_ENOSYS:
return (-1);
case REG_NOMATCH:
return (0);
}
}
d->nmatch++;
return (0);
return (0);
}
for (i = 0; i < ncol; i++) {
if (i > 0)
else
}
}
printf("\n");
return (0);
}
#define F_HEADER 1
void
usage()
{
"usage: nisgrep [-AMchivo] [-s sep] keypat tablename\n");
" nisgrep [-AMchivo] [-s sep] colname=keypat ... tablename\n");
}
static void
{
char buf[80];
buf[0] = 0;
"can't compile regular expression \"%s\": %s\n",
}
int
{
int c;
int st;
unsigned flags = 0;
char *p;
char **patstr;
char *name;
char tname[NIS_MAXNAMELEN];
/*
* By default, don't print binary data to ttys.
*/
switch (c) {
case 'A':
break;
case 'M':
break;
case 'c':
break;
case 'i':
break;
case 'h':
break;
case 'v' :
break;
case 'o' :
break;
case 's':
"separator must be a single character\n");
exit(1);
}
break;
default:
usage();
}
}
usage();
}
for (i = 0; i < npat; i++) {
else
}
/*
* Get the table object using expand name magic.
*/
}
/*
* Construct the name for the table that we found.
*/
/*
* Make sure it's a table object.
*/
}
/*
* Compile the regular expressions.
*/
}
}
/* XXX pat could contain '=' */
}
} else {
for (i = 0; i < npat; i++) {
usage();
*(p++) = 0;
for (j = 0; j < ncol; j++)
(strcmp(
patstr[i]) == 0))
break;
if (j == ncol) {
patstr[i]);
}
}
}
}
/*
* Use the table's separator character when printing entries.
* Unless one was specified w/ -s
*/
}
/*
* Print column names
*/
printf("# ");
for (i = 0; i < ncol; i++) {
if (i > 0)
printf("%c", c);
printf("%s",
}
printf("\n");
}
/*
* Cat matching entries from the table using a callback function.
*/
}
return (EXIT_MATCH);
else
return (EXIT_NOMATCH);
}