/*
* 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.
*/
/* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* University Copyright- Copyright (c) 1982, 1986, 1988
* The Regents of the University of California
* All Rights Reserved
*
* University Acknowledgment- Portions of this document are derived from
* software developed by the University of California, Berkeley, and its
* contributors.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* C-shell glob for random programs.
*/
#include "ftp_var.h"
#ifndef NCARGS
#endif
/*
* According to the person who wrote the C shell "glob" code, a reasonable
* limit on number of arguments would seem to be the maximum number of
* characters in an arg list / 6.
*
* XXX: With the new VM system, NCARGS has become enormous, making
* it impractical to allocate arrays with NCARGS / 6 entries on
* the stack. The proper fix is to revamp code elsewhere (in
* command line arguments. In the meantime, we simply fall back
* on using the old value of NCARGS.
*/
#ifdef notyet
#else /* notyet */
#endif /* notyet */
static char **agargv;
static int agargv_size;
static short gflag;
static char *strspl();
static int tglob(char c);
static char **copyblk(char **v);
static void addpath(char c);
static int any(int c, char *s);
static void sort(void);
static int execbrc(char *p, char *s);
static void rscan(char **t, int (*f)(char));
static int letter(char c);
static int digit(char c);
static int match(char *s, char *p);
static int amatch(char *s, char *p);
static int globcnt;
static int globbed;
static char *entp;
static char **sortbas;
char **
glob(char *v)
{
globerr = "Arguments too long.";
return (0);
}
}
vv[0] = v;
vv[1] = 0;
globerr = 0;
gflag = 0;
if (gflag == 0)
*gpathp = 0;
globcnt = 0;
collect(v);
agargv = 0;
gargv = 0;
return (0);
} else
}
static void
{
agargv[0] = 0;
gargc = 0;
}
static void
{
sort();
} else
}
static void
{
sort();
}
static void
sort(void)
{
p1++;
}
}
static void
{
register char *cs;
addpath('~');
cs++;
*gpathp = 0;
globerr = "Unknown user name after ~";
} else
}
}
if (*cs == 0) {
if (!globbed)
globcnt++;
}
goto endit;
}
}
if (*cs == '/')
*gpathp = 0;
if (*oldcs == '{') {
return;
}
*gpathp = 0;
}
static void
{
/*
* "." while System V does not.
*/
if (*gpath == (char)0) {
} else
if (globbed)
return;
goto patherr2;
}
goto patherr1;
goto patherr1;
}
continue;
globcnt++;
}
}
return;
globerr = "Bad directory components";
}
static int
execbrc(char *p, char *s)
{
int brclev = 0;
int len;
len = 1;
}
len = 1;
switch (*pe) {
case '{':
brclev++;
continue;
case '}':
if (brclev == 0)
goto pend;
brclev--;
continue;
case '[':
len = 1;
}
len = 1;
continue;
}
}
pend:
brclev = 0;
len = 1;
case '{':
brclev++;
continue;
case '}':
if (brclev) {
brclev--;
continue;
}
goto doit;
case ','|QUOTE:
case ',':
if (brclev)
continue;
doit:
*pm = 0;
if (s == 0) {
*gpathp = 0;
return (1);
sort();
if (brclev)
return (0);
continue;
case '[':
len = 1;
}
len = 1;
if (!*pm)
pm--;
continue;
}
}
if (brclev)
goto doit;
return (0);
}
static int
match(char *s, char *p)
{
register int c;
register char *sentp;
if (*s == '.' && *p != '.')
return (0);
entp = s;
c = amatch(s, p);
return (c);
}
static int
amatch(char *s, char *p)
{
int ok;
char *sgpathp;
globbed = 1;
for (;;) {
scc = (unsigned char)*s;
len_s = 1;
}
/* scc = *s++ & TRIM; */
s += len_s;
c = (unsigned char)*p;
len_p = 1;
}
p += len_p;
switch (c) {
case '{':
case '[':
ok = 0;
lc1 = 0;
while ((cc = *p) != '\0') {
cc = (unsigned char)*p;
len_p = 1;
}
p += len_p;
if (cc == ']') {
if (ok)
break;
return (0);
}
if (cc == '-') {
MB_CUR_MAX)) <= 0) {
lc2 = (unsigned char)*p;
len_p = 1;
}
p += len_p;
ok++;
} else
ok++;
}
if (cc == 0)
if (!ok)
return (0);
continue;
case '*':
if (!*p)
return (1);
if (*p == '/') {
p++;
goto slash;
}
s -= len_s;
do {
if (amatch(s, p))
return (1);
} while (*s++);
return (0);
case 0:
return (scc == 0);
default:
if (c != scc)
return (0);
continue;
case '?':
if (scc == 0)
return (0);
continue;
case '/':
if (scc)
return (0);
s = entp;
while (*s)
addpath(*s++);
addpath('/');
if (*p == 0) {
globcnt++;
} else
expand(p);
*gpathp = 0;
return (0);
}
}
}
#ifdef notdef
static
Gmatch(s, p)
register char *s, *p;
{
register int scc;
int c, cc;
for (;;) {
switch (c = *p++) {
case '[':
ok = 0;
lc = 077777;
while (cc = *p++) {
if (cc == ']') {
if (ok)
break;
return (0);
}
if (cc == '-') {
ok++;
} else
ok++;
}
if (cc == 0)
if (ok)
p--;
else
return (0);
continue;
case '*':
if (!*p)
return (1);
for (s--; *s; s++)
if (Gmatch(s, p))
return (1);
return (0);
case 0:
return (scc == 0);
default:
return (0);
continue;
case '?':
if (scc == 0)
return (0);
continue;
}
}
}
#endif
static void
{
char **tmp;
if (globerr) {
return;
}
(agargv_size + GAVSIZ) * sizeof (char *));
globerr = "Arguments too long";
return;
} else {
agargv_size += GAVSIZ;
}
}
gargc++;
}
static void
addpath(char c)
{
if (gpathp >= lastgpathp)
globerr = "Pathname too long";
else {
*gpathp++ = c;
*gpathp = 0;
}
}
static void
rscan(char **t, int (*f)(char))
{
register char *p, c;
int len;
while (p = *t++) {
if (f == tglob)
if (*p == '~')
gflag |= 2;
continue;
while ((c = *p) != '\0') {
(void) (*f)(c);
len = 1;
p += len;
}
}
}
static int
tglob(char c)
{
return (c);
}
static int
letter(char c)
{
return (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' || c == '_');
}
static int
digit(char c)
{
return (c >= '0' && c <= '9');
}
static int
any(int c, char *s)
{
int len;
while (*s) {
if (*s == c)
return (1);
len = 1;
s += len;
}
return (0);
}
static int
{
register int i = 0;
while (*av++)
i++;
return (i);
}
static char **
{
continue;
return (oav);
}
void
{
while (*av)
}
static void
{
extern char end[];
}
static char *
{
if (ep == (char *)0)
fatal("Out of memory");
return (ep);
}
static char **
copyblk(char **v)
{
sizeof (char **)));
if (nv == (char **)0)
fatal("Out of memory");
}
static char *
{
while (*cp)
cp++;
return (cp);
}
/*
* Extract a home directory from the password file
* The argument points to a buffer where the name of the
* user whose home directory is sought is currently.
* We write the home directory of the user back there.
*/
static int
{
return (1);
return (0);
}
static int
{
char *p;
int i;
return (1);
p = t_patan;
return (0);
t_char[i] = 0;
*p++ = '[';
return (0);
p += i;
*p++ = '-';
return (0);
p += i;
*p++ = ']';
*p = 0;
return (0);
return (1);
}