shiocmd_solaris.c revision 7c2fbfb345896881c631598ee3852ce9ce33fb07
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1982-2007 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 *
* *
* David Korn <dgk@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
#include <shell.h>
#include <stdio.h>
#include <stdbool.h>
#include <option.h>
#include <stk.h>
#include <tm.h>
#include "name.h"
#ifndef SH_DICT
# define SH_DICT "libshell"
#endif
#include <poll.h>
/*
* time formatting related
*/
struct dctime
{
};
{
}
{
char *last;
if(val)
{
int32_t t;
if(flag&NV_INTEGER)
{
t = *(Sfdouble_t*)val;
else
t = *(double*)val;
}
else
{
if(*last)
}
}
else
{
}
}
{
return((Namval_t*)0);
}
{
sizeof(struct dctime),
0,
0,
};
{
if(!dp)
return((Namval_t*)0);
return(np);
}
/*
* mode formatting related
*/
{
}
{
if(val)
{
char *last;
if(flag&NV_INTEGER)
{
else
}
else
{
if(*last)
}
}
else
}
{
0,
};
{
if(!nfp)
return((Namval_t*)0);
return(np);
}
/*
* field related typese and functions
*/
typedef struct _field_
{
char *name; /* field name */
int flags; /* flags */
short offset; /* offset of field into data */
short size; /* size of field */
} Shfield_t;
/*
* lookup field in field table
*/
{
register int i,n;
register const char *cp;
{
if(*cp=='.')
break;
}
{
return(fp);
}
return(0);
}
/*
* class types and functions
*/
typedef struct _class_
{
int nelem; /* number of elements */
int dsize; /* size for data structure */
} Shclass_t;
struct dcclass
{
};
{
return(nq);
}
{
{
}
return(nq);
return(nq);
}
{
register int i,isarray;
if(out)
{
indent++;
}
{
#if 0
/* handle recursive case */
#endif
if(np)
{
isarray=0;
{
isarray=1;
isarray=2;
else
}
if(isarray)
{
if(isarray==2)
continue;
}
while(1)
{
char *fmtq;
if(isarray)
{
}
fmtq = "";
if(!nv_nextsub(np))
break;
}
if(isarray)
{
}
}
}
if(out)
{
if(indent>1)
}
}
{
if(dlete)
outfile = 0;
else
if(!outfile)
return((char*)0);
}
{
}
{
{
}
if(val)
}
{
sizeof(struct dcclass),
0,
0,
};
{
if(!tcp)
return(0);
return(1);
}
/*
* ====================from here down is file class specific
*/
struct filedata
{
int fd;
char *name;
};
{
};
{
sizeof(struct filedata),
};
static const char sh_optopen[] =
"[-?\n@(#)$Id: open (AT&T Labs Research) 2007-05-07 $\n]"
"[-author?David Korn <dgk@research.att.com>]"
"[-author?Roland Mainz <roland.mainz@nrubsig.org>]"
"[-license?http://www.opensource.org/licenses/cpl1.0.txt]"
"[+NAME? open - create a shell variable correspnding to a file]"
"[+DESCRIPTION?\bopen\b creates the compound variable \avar\a correspinding "
"to the file given by the pathname \afile\a. The elements of \avar\a "
"are the names of elements in the \astat\a structure with the \bst_\b "
"prefix removed.]"
"\avar\a\b.fd\b is the file descriptor.]"
"[a:append?Open for append.]"
"[b:binary?Open in binary mode"
#ifndef O_BINARY
#endif
".]"
"[t:text?Open in text mode"
#ifndef O_TEXT
#endif
".]"
"[c:create?Open for create.]"
"[i:inherit?Open without the close-on-exec bit set.]"
"[I:noinherit?Open with the close-on-exec bit set.]"
"[r:read?Open with read access.]"
"[w:write?Open with write access.]"
"[m:mode]:[mode:=rwrwrw?Open with access mode \amode\a.]"
"[x:exclusive?Open exclusive.]"
"[N:nofollow?If the path names a symbolic link, open fails with ELOOP "
#ifndef O_NOFOLLOW
#endif
".]"
"[S:sync?Write I/O operations on the file descriptor complete as "
"defined by synchronized I/O file integrity completion"
#ifndef O_SYNC
#endif
".]"
"[T:trunc?If the file exists and is a regular file, and the file "
"truncated to 0 and the mode and owner are unchanged. It "
"has no effect on FIFO special files or terminal device "
"files. Its effect on other file types is "
"implementation-dependent. The result of using -T "
"with read-only files is undefined"
#ifndef O_TRUNC
#endif
".]"
"\n"
"\nvar file\n"
"\n"
"[+EXIT STATUS?]{"
"[+0?Success.]"
"[+>0?An error occurred.]"
"}"
"[+SEE ALSO?\btmpfile\b(1),\bdup\b(1),\bclose\b(1),\bstat\b(1),\bpoll\b(1),\bstat\b(2)]"
;
{
register int n,oflag=0;
long flags = 0;
int fd = -1;
char *arg;
{
case 'r':
case 'w':
case 'i':
break;
case 'I':
break;
case 'b':
#ifdef O_BINARY
#endif
break;
case 't':
#ifdef O_TEXT
#endif
break;
case 'N':
#ifdef O_NOFOLLOW
oflag |= O_NOFOLLOW;
#endif
break;
case 'T':
#ifdef O_TRUNC
#endif
break;
case 'x':
break;
case 'c':
break;
case 'a':
break;
case 'S':
#ifdef O_SYNC
#endif
break;
case 'm':
break;
case ':':
break;
case '?':
break;
}
{
else
}
if(fd<0)
return(0);
}
static const char sh_optclose[] =
"[-?\n@(#)$Id: close (AT&T Labs Research) 2007-04-21 $\n]"
"[-author?Roland Mainz <roland.mainz@nrubsig.org>]"
"[-license?http://www.opensource.org/licenses/cpl1.0.txt]"
"[+NAME? close - close a file descriptor]"
"[+DESCRIPTION?\bclose\b closes the file descriptor specified by fd.]"
"\n"
"\nfd\n"
"\n"
"[+EXIT STATUS?]{"
"[+0?Success.]"
"[+>0?An error occurred.]"
"}"
"[+SEE ALSO?\bopen\b(1),\bdup\b(1),\btmpfile\b(1),\bpoll\b(1),\bstat\b(1)]"
;
{
register int n=0;
int fd = -1;
{
case ':':
break;
case '?':
break;
}
if(argc!=1)
errno = 0;
if (n < 0)
return(n==0?0:1);
}
static const char sh_opttmpfile[] =
"[-?\n@(#)$Id: tmpfile (AT&T Labs Research) 2007-05-07 $\n]"
"[-author?Roland Mainz <roland.mainz@nrubsig.org>]"
"[-license?http://www.opensource.org/licenses/cpl1.0.txt]"
"[+NAME? tmpfile - create a shell variable correspnding to a temporary file]"
"[+DESCRIPTION?\btmpfile\b creates the compound variable \avar\a correspinding "
"to a temporary file. The elements of \avar\a "
"are the names of elements in the \astat\a structure with the \bst_\b "
"prefix removed.]"
"[i:inherit?Open without the close-on-exec bit set.]"
"[I:noinherit?Open with the close-on-exec bit set.]"
"\n"
"\nvar\n"
"\n"
"[+EXIT STATUS?]{"
"[+0?Success.]"
"[+>0?An error occurred.]"
"}"
"[+SEE ALSO?\bopen\b(1),\bdup\b(1),\bclose\b(1),\bstat\b(1),\bstat\b(2)]"
;
{
register int n;
bool inherit = false;
{
case 'i':
inherit = true;
break;
case 'I':
inherit = false;
break;
case ':':
break;
case '?':
break;
}
if(argc!=1)
if(!file)
if(fd<0)
if(!inherit)
return(0);
}
static const char sh_optdup[] =
"[-?\n@(#)$Id: dup (AT&T Labs Research) 2007-05-07 $\n]"
"[-author?Roland Mainz <roland.mainz@nrubsig.org>]"
"[-license?http://www.opensource.org/licenses/cpl1.0.txt]"
"[+NAME? dup - duplicate an open file descriptor]"
"[+DESCRIPTION?The \bdup\b commands returns a new file descriptor having the "
"following in common with the original open file descriptor "
"fd: same open file (or pipe), same file pointer (that is, both file descriptors "
"The file descriptor returned is the lowest one available.]"
"[i:inherit?Open without the close-on-exec bit set.]"
"[I:noinherit?Open with the close-on-exec bit set.]"
"\n"
"\nvar fd\n"
"\n"
"[+EXIT STATUS?]{"
"[+0?Success.]"
"[+>0?An error occurred.]"
"}"
"[+SEE ALSO?\bopen\b(1),\btmpfile\b(1),\bclose\b(1),\bpoll\b(1),\bstat\b(1)]"
;
{
register int n;
bool inherit = false;
{
case 'i':
inherit = true;
break;
case 'I':
inherit = false;
break;
case ':':
break;
case '?':
break;
}
if(argc!=2)
errno = 0;
if(fd<0)
if(!inherit)
return(0);
}
static const char sh_optstat[] =
"[-?\n@(#)$Id: stat (AT&T Labs Research) 2007-05-07 $\n]"
"[-author?David Korn <dgk@research.att.com>]"
"[-author?Roland Mainz <roland.mainz@nrubsig.org>]"
"[-license?http://www.opensource.org/licenses/cpl1.0.txt]"
"[+NAME? stat - get file status]"
"[+DESCRIPTION?\bstat\b creates the compound variable \avar\a correspinding "
"to the file given by the pathname \afile\a. The elements of \avar\a "
"are the names of elements in the \astat\a structure with the \bst_\b "
"prefix removed.]"
"[l:lstat?If the the named file is a symbolic link returns information about "
"the link itself.]"
"\n"
"\nvar file\n"
"\n"
"[+EXIT STATUS?]{"
"[+0?Success.]"
"[+>0?An error occurred.]"
"}"
"[+SEE ALSO?\bopen\b(1),\btmpfile\b(1),\bdup\b(1),\bclose\b(1),\bpoll\b(1),\bstat\b(2),\blstat\b(2)]"
;
{
register int n;
long flags = 0;
{
case 'l':
break;
case ':':
break;
case '?':
break;
}
if(argc!=2)
{
}
else
{
}
return(0);
}
static const char sh_optpoll[] =
"[-?\n@(#)$Id: poll (AT&T Labs Research) 2007-12-20 $\n]"
"[-author?Roland Mainz <roland.mainz@nrubsig.org]"
"[-license?http://www.opensource.org/licenses/cpl1.0.txt]"
"[+DESCRIPTION?The poll command provides applications with a mechanism "
"For each member of the array variable \bvar\b, "
"poll examines the given file descriptor in the subscript \b.fd\b "
"for the event(s) specified in the subscript \b.events\b."
"The poll command identifies those file descriptors on which an "
"application can read or write data, or on which certain events have "
"occurred.]"
"[+?The \bvar\b argument specifies the file descriptors to be examined "
"and the events of interest for each file descriptor. "
"It is a array of structured variables with one member for each open "
"file descriptor of interest. The array's members contain the following "
"subscripts:]{"
"[+?\b.fd\b # file descriptor]"
"[+?\b.events\b # requested events]"
"[+?\b.revents\b # returned event]"
"}"
"[+?The \bfd\b variable specifies an open file descriptor and the "
"\bevents\b and \brevents\b members are strings constructed from "
"a concaternation of the following event flags, seperated by '|':]"
"{ "
"[+POLLIN?Data other than high priority data may be "
"read without blocking. For STREAMS, this "
"flag is set in revents even if the message "
"is of zero length.]"
"[+POLLRDNORM?Normal data (priority band equals 0) may be "
"read without blocking. For STREAMS, this "
"flag is set in revents even if the message "
"is of zero length.]"
"[+POLLRDBAND?Data from a non-zero priority band may be "
"read without blocking. For STREAMS, this "
"flag is set in revents even if the message "
"is of zero length.]"
"[+POLLPRI?High priority data may be received without "
"blocking. For STREAMS, this flag is set in "
"revents even if the message is of zero "
"length.]"
"[+POLLOUT?Normal data (priority band equals 0) may be "
"written without blocking.]"
"[+POLLWRNORM?The same as POLLOUT.]"
"[+POLLWRBAND?Priority data (priority band > 0) may be "
"written. This event only examines bands "
"that have been written to at least once.]"
"[+POLLERR?An error has occurred on the device or "
"stream. This flag is only valid in the "
"revents bitmask; it is not used in the "
"events member.]"
"[+POLLHUP?A hangup has occurred on the stream. This "
"event and POLLOUT are mutually exclusive; a "
"stream can never be writable if a hangup has "
"occurred. However, this event and POLLIN, "
", POLLRDBAND, or POLLPRI are not "
"mutually exclusive. This flag is only valid "
"in the revents bitmask; it is not used in "
"the events member.]"
"[+POLLNVAL?The specified fd value does not belong to an "
"open file. This flag is only valid in the "
"revents member; it is not used in the events "
"member.]"
"}"
"]"
"[+?If the value fd is less than 0, events is ignored and "
"revents is set to 0 in that entry on return from poll.]"
"[+?The results of the poll query are stored in the revents "
"member in the \bvar\b structure. POLL*-strings are set in the \brevents\b "
"variable to indicate which of the requested events are true. "
"If none are true, the \brevents\b will be an empty string when "
"the poll command returns. The event flags "
"POLLHUP, POLLERR, and POLLNVAL are always set in \brevents\b "
"if the conditions they indicate are true; this occurs even "
"though these flags were not present in events.]"
"[+?If none of the defined events have occurred on any selected "
"file descriptor, poll waits at least timeout milliseconds "
"for an event to occur on any of the selected file descriptors. "
"On a computer where millisecond timing accuracy is not "
"available, timeout is rounded up to the nearest legal value "
"available on that system. If the value timeout is 0, poll "
"returns immediately. If the value of timeout is -1, poll "
"blocks until a requested event occurs or until the call is "
"interrupted.]"
"[+?The poll function supports regular files, terminal and "
"pseudo-terminal devices, STREAMS-based files, FIFOs and "
"pipes. The behavior of poll on elements of fds that refer "
"to other types of file is unspecified.]"
"[+?The poll function supports sockets.]"
"[+?A file descriptor for a socket that is listening for connections "
"will indicate that it is ready for reading, once connections "
"are available. A file descriptor for a socket that "
"is connecting asynchronously will indicate that it is ready "
"for writing, once a connection has been established.]"
"[+?Regular files always poll TRUE for reading and writing.]"
"[c:fdcount]:[fdcount?Upon successful completion, a non-negative value is "
"returned. A positive value indicates the total number of "
"file descriptors that has been selected (that is, file "
"descriptors for which the revents member is non-zero). A "
"value of 0 indicates that the call timed out and no file "
"descriptors have been selected. Upon failure, -1 is returned.]"
"[t:timeout]:[seconds?Timeout in seconds. If the value timeout is 0, "
"poll returns immediately. If the value of timeout is -1, poll "
"blocks until a requested event occurs or until the call is "
"interrupted.]"
"[T:mtimeout]:[milliseconds?Timeout in milliseconds. If the value timeout is 0, "
"poll returns immediately. If the value of timeout is -1, poll "
"blocks until a requested event occurs or until the call is "
"interrupted.]"
"\n"
"\nvar\n"
"\n"
"[+EXIT STATUS?]{"
"[+0?Success.]"
"[+>0?An error occurred.]"
"}"
"[+SEE ALSO?\bopen\b(1),\btmpfile\b(1),\bdup\b(1),\bclose\b(1),\bpoll\b(2)]"
;
/*
* |mystpcpy| - like |strcpy()| but returns the end of the buffer
*
* Copy string s2 to s1. s1 must be large enough.
* return s1-1 (position of string terminator ('\0') in destnation buffer).
*/
static
{
;
return (s1-1);
}
static
{
char varnamebuff[PATH_MAX];
}
static
int poll_strtoevents(const char *str)
{
int events = 0;
return events;
}
static
void poll_eventstostr(char *s, int events)
{
*s='\0';
if (!events)
return;
/* Remove trailling '|' */
s--;
if(*s=='|')
*s='\0';
}
{
register int n;
char *varname;
int fd;
unsigned int numpollfd = 0;
int i;
char *s;
double timeout = -1.;
char buff[256];
char *pollfdcountvarname = NULL;
long open_max,
/* |bpoll_max| needs to be larger than |OPEN_MAX| to make sure we
* can listen to different sets of events per fd.
*/
{
case 't':
case 'T':
errno = 0;
if (errno != 0)
/* -t uses seconds, -T milliseconds */
if (n == 't')
timeout *= 1000.;
break;
case 'c':
break;
case ':':
break;
case '?':
break;
}
if(argc!=1)
for(i=0 ; i < bpoll_max ; i++)
{
if (!np)
break;
if (!np)
if (!s)
numpollfd++;
}
if (i == bpoll_max)
/* FixMe: EGAIN and EINTR may require extra handling */
if (n < 0)
if (pollfdcountvarname)
{
int32_t v = n;
if (!np)
}
for(i=0 ; i < numpollfd ; i++)
{
if (!np)
}
return(0);
}
static const char sh_optrewind[] =
"[-?\n@(#)$Id: rewind (AT&T Labs Research) 2007-05-07 $\n]"
"[-author?Roland Mainz <roland.mainz@nrubsig.org>]"
"[-license?http://www.opensource.org/licenses/cpl1.0.txt]"
"[+NAME? rewind - reset file position indicator in a stream]"
"[+DESCRIPTION?The \brewind\b command will move the file pointer of fd to position 0.]"
"\n"
"\nfd\n"
"\n"
"[+EXIT STATUS?]{"
"[+0?Success.]"
"[+>0?An error occurred.]"
"}"
"[+SEE ALSO?\bopen\b(1),\btmpfile\b(1),\bdup\b(1),\bclose\b(1),\bstat\b(1),\bstat\b(2)]"
;
{
int fd = -1;
register int n;
{
case ':':
break;
case '?':
break;
}
if(argc!=1)
errno = 0;
return(0);
}