/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1985-2011 AT&T Intellectual Property *
* and is licensed under the *
* Common Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* David Korn <dgk@research.att.com> *
* Phong Vo <kpv@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* Glenn Fowler
* AT&T Research
*
*/
#include <ast.h>
#include <ctype.h>
#include <error.h>
#include <proc.h>
#include "cmdarg.h"
#ifndef ARG_MAX
#endif
#ifndef EXIT_QUIT
#endif
/*
* open a cmdarg stream
* initialize the command for execution
* argv[-1] is reserved for procrun(PROC_ARGMOD)
*/
{
register int n;
register char** p;
register char* s;
char* sh;
int c;
int m;
int argc;
long x;
char** post = 0;
n = sizeof(char**);
if (*argv)
{
for (p = argv + 1; *p; p++)
{
{
*p = 0;
post = p + 1;
argpat = 0;
}
else
n += strlen(*p) + 1;
}
}
else
argc = 0;
for (p = environ; *p; p++)
n += sizeof(char**) + strlen(*p) + 1;
x = ARG_MAX;
size = x;
m = roundof(m, sizeof(char**));
if (size < m)
{
return 0;
}
if ((m = x / 10) > 2048)
m = 2048;
if (size > (x - m))
size = x - m;
n = size - n;
{
return 0;
}
c = n / sizeof(char**);
argmax = c;
if (!argv[0])
{
}
{
flags &= ~CMD_NEWLINE;
}
else if (!(flags & CMD_CHECKED))
{
{
if (!(flags & CMD_SILENT))
{
}
return 0;
}
argv[0] = s;
}
s += strlen(s) + 1;
if (m)
{
s += m;
}
p = (char**)s;
while (*p = *argv++)
p++;
if (m)
{
argmax = 1;
*p++ = 0;
while (s = *argv)
{
s++;
*p++ = s ? *argv : (char*)0;
argv++;
}
*p++ = 0;
}
return cmd;
}
/*
* flush outstanding command file args
*/
int
{
register char* s;
register char** p;
register int n;
return 0;
{
return -1;
}
else
{
char* a;
char* b;
char* e;
char* t;
char* u;
int c;
int m;
c = *s;
{
for (;;)
{
if (!(u = strchr(t, c)))
{
b += sfsprintf(b, e - b, "%s", t);
break;
}
if (!strncmp(s, u, m))
{
b += sfsprintf(b, e - b, "%-.*s%s", u - t, t, a);
t = u + m;
}
else if (b >= e)
break;
else
{
*b++ = *u++;
t = u;
}
}
if (b < e)
*b++ = 0;
}
if (b >= e)
{
return -1;
}
}
{
while (s = *++p)
return 0;
}
{
n = 0;
}
{
{
}
return -1;
}
else if (n >= EXIT_NOTFOUND - 1)
{
exit(n);
}
{
exit(2);
if (n)
error_info.errors++;
}
return n;
}
/*
* add file to the command arg list
*/
int
{
int i;
int r;
r = 0;
if (len)
{
{
{
return -1;
}
{
if (r < i)
r = i;
return r;
}
}
r = i;
}
return r;
}
/*
* close a cmdarg stream
*/
int
{
int n;
{
return -1;
}
return n;
}