Quizzer

 view release on metacpan or  search on metacpan

exercises/compile-tcsh/tcsh-6.10.00/tw.init.c  view on Meta::CPAN

 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */
#include "sh.h"

RCSID("$Id: tw.init.c,v 3.27 2000/11/11 23:03:40 christos Exp $")

#include "tw.h"
#include "ed.h"
#include "tc.h"
#include "sh.proc.h"

#if !defined(NSIG) && defined(SIGMAX)
# define NSIG (SIGMAX+1)
#endif /* !NSIG && SIGMAX */
#if !defined(NSIG) && defined(_NSIG)
# define NSIG _NSIG
#endif /* !NSIG && _NSIG */

#define TW_INCR	128

typedef struct {
    Char **list, 			/* List of command names	*/
	  *buff;			/* Space holding command names	*/
    int    nlist, 			/* Number of items		*/
           nbuff,			/* Current space in name buf	*/
           tlist,			/* Total space in list		*/
	   tbuff;			/* Total space in name buf	*/
} stringlist_t;


static struct varent *tw_vptr = NULL;	/* Current shell variable 	*/
static Char **tw_env = NULL;		/* Current environment variable */
static Char  *tw_word;			/* Current word pointer		*/
static struct KeyFuncs *tw_bind = NULL;	/* List of the bindings		*/
#ifndef HAVENOLIMIT
static struct limits *tw_limit = NULL;	/* List of the resource limits	*/
#endif /* HAVENOLIMIT */
static int tw_index = 0;		/* signal and job index		*/
static DIR   *tw_dir_fd = NULL;		/* Current directory descriptor	*/
static Char   tw_retname[MAXPATHLEN+1];	/* Return buffer		*/
static int    tw_cmd_got = 0;		/* What we need to do		*/
static stringlist_t tw_cmd  = { NULL, NULL, 0, 0, 0, 0 };
static stringlist_t tw_item = { NULL, NULL, 0, 0, 0, 0 };
#define TW_FL_CMD	0x01
#define TW_FL_ALIAS	0x02
#define TW_FL_BUILTIN	0x04
#define TW_FL_SORT	0x08
#define TW_FL_REL	0x10

static struct {				/* Current element pointer	*/
    int    cur;				/* Current element number	*/
    Char **pathv;			/* Current element in path	*/
    DIR   *dfd;				/* Current directory descriptor	*/
} tw_cmd_state;


#ifdef BSDSIGS
static sigmask_t tw_omask;
# define TW_HOLD()	tw_omask = sigblock(sigmask(SIGINT))
# define TW_RELS()	(void) sigsetmask(tw_omask)
#else /* !BSDSIGS */
# define TW_HOLD()	(void) sighold(SIGINT)
# define TW_RELS()	(void) sigrelse(SIGINT)
#endif /* BSDSIGS */

#define SETDIR(dfd) \
    { \
	tw_dir_fd = dfd; \
	if (tw_dir_fd != NULL) \
	    rewinddir(tw_dir_fd); \
    }

#define CLRDIR(dfd) \
    if (dfd != NULL) { \
	TW_HOLD(); \
	(void) closedir(dfd); \
	dfd = NULL; \
	TW_RELS(); \
    }

static Char	*tw_str_add		__P((stringlist_t *, int));
static void	 tw_str_free		__P((stringlist_t *));
static Char     *tw_dir_next		__P((DIR *));
static void	 tw_cmd_add 		__P((Char *name));
static void 	 tw_cmd_cmd		__P((void));
static void	 tw_cmd_builtin		__P((void));
static void	 tw_cmd_alias		__P((void));
static void	 tw_cmd_sort		__P((void));
static void 	 tw_vptr_start		__P((struct varent *));


/* tw_str_add():
 *	Add an item to the string list
 */
static Char *
tw_str_add(sl, len)
    stringlist_t *sl;
    int len;
{
    Char *ptr;

    if (sl->tlist <= sl->nlist) {
	TW_HOLD();
	sl->tlist += TW_INCR;
	sl->list = sl->list ? 
		    (Char **) xrealloc((ptr_t) sl->list, 
				       (size_t) (sl->tlist * sizeof(Char *))) :
		    (Char **) xmalloc((size_t) (sl->tlist * sizeof(Char *)));
	TW_RELS();
    }
    if (sl->tbuff <= sl->nbuff + len) {
	int i;
	ptr = sl->buff;

	TW_HOLD();
	sl->tbuff += TW_INCR + len;
	sl->buff = sl->buff ? 
		    (Char *) xrealloc((ptr_t) sl->buff, 
				      (size_t) (sl->tbuff * sizeof(Char))) :
		    (Char *) xmalloc((size_t) (sl->tbuff * sizeof(Char)));



( run in 2.281 seconds using v1.01-cache-2.11-cpan-302cb4679cc )