/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1982-2011 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* David Korn <dgk@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* File name expansion
*
* David Korn
* AT&T Labs
*
*/
#if KSHELL
# include "defs.h"
# include "variables.h"
# include "test.h"
#else
# include <ast.h>
# include <ctype.h>
# include <setjmp.h>
#endif /* KSHELL */
#include <glob.h>
#include <ls.h>
#include <stak.h>
#include <ast_dir.h>
#include "io.h"
#include "path.h"
#if !SHOPT_BRACEPAT
# define SHOPT_BRACEPAT 0
#endif
#if KSHELL
static const char *sufstr;
static int suflen;
#else
# define suflen 0
#endif /* KSHELL */
/*
* This routine builds a list of files that match a given pathname
* Uses external routine strgrpmatch() to match each component
* A leading . must match explicitly
*
*/
#ifndef GLOB_AUGMENTED
# define GLOB_AUGMENTED 0
#endif
#if GLOB_VERSION >= 20010916L
{
if(!dir)
else
if(pp)
return(0);
}
#endif
{
#if SHOPT_BASH
register int off;
#endif
if(sh_isoption(SH_MARKDIRS))
if(sh_isoption(SH_GLOBSTARS))
flags |= GLOB_STARSTAR;
#if SHOPT_BASH
#if 0
flags &= ~GLOB_AUGMENTED;
#endif
if(sh_isoption(SH_NULLGLOB))
flags &= ~GLOB_NOCHECK;
if(sh_isoption(SH_NOCASEGLOB))
flags |= GLOB_ICASE;
#endif
if(sh_isstate(SH_COMPLETE))
{
#if KSHELL
# if GLOB_VERSION >= 20010916L
# endif
#endif /* KSHELL */
flags |= GLOB_COMPLETE;
flags &= ~GLOB_NOCHECK;
}
#if SHOPT_BASH
sp = stakfreeze(0);
if(sh_isoption(SH_BASH))
{
/*
* For bash, FIGNORE is a colon separated list of suffixes to
* GLOBIGNORE is similar to ksh FIGNORE, but colon separated
* instead of being an augmented shell pattern.
* Generate shell patterns out of those here.
*/
if(sh_isstate(SH_FCOMPLETE))
else
{
if(!GLOBIGNORENOD)
}
if(cp)
{
flags |= GLOB_AUGMENTED;
stakputs("@(");
if(!sh_isstate(SH_FCOMPLETE))
{
if(*cp == ':')
*cp='|';
}
else
{
if(!cp2)
do
{
stakputc('*');
{
stakputc('|');
}
} while(cp2);
}
stakputc(')');
}
}
else
#endif
if(suflen)
suflen = 0;
flags &= ~GLOB_NOCHECK;
#if SHOPT_BASH
if(off)
else
stakseek(0);
#endif
{
}
}
#if KSHELL
/*
* scan tree and add each name that matches the given pattern
*/
{
register int nmatch=0;
register char *cp;
{
{
nmatch++;
}
}
return(nmatch);
}
/*
* file name completion
* generate the list of files found by adding an suffix to end of name
* The number of matches is returned
*/
int path_complete(Shell_t *shp,const char *name,register const char *suffix, struct argnod **arghead)
{
}
#endif
#if SHOPT_BRACEPAT
{
return -1;
}
/*@
assume todo!=0;
return count satisfying count>=1;
@*/
{
register char *cp;
register int brace;
char *format;
/* first search for {...,...} */
while(1) switch(*cp++)
{
case '{':
if(brace++==0)
break;
case '}':
if(--brace>0)
break;
goto endloop1;
break;
case '.':
{
char *endc;
incr = 1;
{
{
incr = -1;
if(incr)
{
if(*endc=='%')
{
{
case 'c':
case 'd':
case 'i':
case 'o':
case 'u':
case 'x':
case 'X':
break;
}
}
else
format = "%d";
if(*endc=='}')
{
range = 2;
goto endloop1;
}
}
}
}
else if((cp[2]=='}' || cp[2]=='.' && cp[3]=='.') && ((*pat>='a' && *pat<='z' && cp[1]>='a' && cp[1]<='z') || (*pat>='A' && *pat<='Z' && cp[1]>='A' && cp[1]<='Z')))
{
cp += 2;
if(*cp=='.')
{
}
incr = -1;
{
cp++;
range = 1;
goto endloop1;
}
}
cp++;
}
break;
case ',':
if(brace==1)
comma = 1;
break;
case '\\':
cp++;
break;
case 0:
/* insert on stack */
if(todo)
goto again;
{
if(!sh_isoption(SH_NOGLOB))
else
{
brace=1;
}
if(brace)
{
}
}
return(count);
}
*cp = 0;
while(1)
{
brace = 0;
if(range)
{
if(range==1)
{
}
else
{
*(rescan - 1) = 0;
}
*cp = '}';
else
}
/* generate each pattern and put on the todo list */
else while(1) switch(*++cp)
{
case '\\':
cp++;
break;
case '{':
brace++;
break;
case ',':
if(brace==0)
goto endloop2;
break;
case '}':
if(--brace<0)
goto endloop2;
}
*cp = 0;
if(brace == '}')
break;
if(!range)
}
goto again;
}
#endif /* SHOPT_BRACEPAT */