wsh/
wsh/binsrc/
wsh/docs/help/
wsh/docs/old/
wsh/etc/
wsh/src/util/
/* 
 *       The WizPort
 *
 * This software is Copyright 1993, David Ljung.
 * Please read the file "docs/0.COPYRIGHT"
 * This version of this software is free for distribution
 * Do not distribute any parts of this package without the documentation.
 * Read the docs before attempting to use this software!
 *  
 *      David Ljung
 *      ljung@cae.wisc.edu  (until 8/94)
 *
 *           Permanent Address:            Current (till 8/94):
 *           2257 Clover Lane              310 South Bassett
 *           Geneva, IL. 60134             Madison, WI. 53703
 *           (708) 232-4987                (608) 257-COWS
 */

#ifndef EVERYTHING
#define EVERYTHING  /* make sure everything is defined only once */

#include "config.h"
#include <stdio.h>
#include <stdlib.h>  /* for getenv putenv */
#include <string.h>
#if !defined(NeXT)
#include <unistd.h>
#endif
#include <signal.h>
#ifndef SIGUSR1
#define SIGUSR1 _SIGUSR1
#endif
#include <sys/types.h>
#include <sys/stat.h>
/*  I don't think I need symlink.h at all
#ifdef RESOLVE_LINKS
#include <symlink.h>
#endif
*/
#include <errno.h>
/*
#if defined(NeXT)  /* some machines don't have putenv()!  yeesh. */
/*
int putenv(const char *);
/* then "putenv.c" is included in wizshell.c */
/*
#endif
*/

/* login stuff */
#ifdef ENCRYPT
char *crypt();
#endif
/* end login stuff */

/* access stuff */
#define READ_ACC 0
#define WRITE_ACC 1
/* access list type */
typedef struct acc_t {     /* access tree constructed of:          */
  char *token;             /*   -------------------                */
  struct acc_t *next;      /*   | pathname piece  |-->down (path)  */
  struct acc_t *down;      /*   -------------------                */
} acc_t;                   /*        | next piece                  */
                           /*        v                             */
/* to make a new one */
#define MK_ACC(acc) {if((acc=(acc_t *) MALLOC(sizeof(acc_t)))==NULL) \
                     FATAL("Could not allocate access tree memory") \
                     acc->down=NULL;  acc->next=NULL;}
/* end access stuff */

/* history stuff */
#define START_HIST_SIZE 10
/* end history stuff */

/* alias stuff */
typedef struct alias_t {
  char *name, *what;
  struct alias_t *next;
} alias_t;
/* end alias stuff */

/* uwtmp stuff */
/* for reading in utmp and wtmp */
typedef struct who_t {
  long num1,num2,num3;
  char *str1,*str2,*str3,*str4;
  struct who_t *next;
} who_t;
/* end uwtmp stuff */

#define ROOT_DIR_LEN sizeof(ROOT_DIR)
#define BIN_DIR_LEN sizeof(BIN_DIR)
#define HOME_DIR_LEN sizeof(HOME_DIR)
#define WD envir.curr_path    /* envir_t type must be "envir" */

#define FATAL(why) {fprintf(stderr,"%s.\n",why); exit(1); }
#define ERROR(where,why) fprintf(stderr,"%s: %s.\n",where,why);
#define MK_STR(str,len) {if ((str=(char *) CALLOC(len,sizeof(char)))==NULL) \
                         FATAL("Could not allocate string memory") \
                         else *str='\0'; }

/* ENVIRONMENT STRUCT */
typedef struct {
  char login[MAX_FIELD];     /* login name */
  char passwd[MAX_FIELD];    /* password */
  char access[MAX_FIELD];    /* access rights name */
  char real_name[MAX_FIELD]; /* real name */

  char** hist;           /* history: array of strings */
  int history_size;      /* history_size */
  int command_num;       /* num of commands executed */
  int current_hist;      /* history is a wraparound stack
                          * this is the current pointer */

  int gotintr;           /* user interrupt flag - currently unused */
  int loopy_eofs;        /* die after 2 EOFS in a row */
  int mesg;              /* tune chat in/out */

  char curr_path[MAX_PATH];   /* current path (from ROOT_DIR) */
  char home[MAX_PATH];        /* home directory */
  char *prompt;      /* prompt string */
  char *prompt2;     /* if prompt contains %/ then this is the second half */
} envir_t;

/* GLOBAL VARS */
extern envir_t envir;
extern acc_t *read_acc, *write_acc;
extern acc_t *wd_default, *can_read, *non_file_args;
extern int errno;
extern int DEBUGON;
extern char **environ;
extern alias_t *aliases;

/* for file stats (sys/stat.h) */
int stat(const char *,struct stat *);

/* FUNCTION PROTOTYPES */
  /* wizshell prototypes */
void str_add(char *,char *);
char *eat_white(char *);
char *gen_abs_path(char *);
char *mk_path(char *);
char *ref_from(char *);
int parse_line(int,FILE *,char *);
int source(char *,int);
  /* access prototypes */
void get_acc(acc_t **,char *,char *);
int ck_access(char **,int *);
acc_t *find_token(acc_t *,char *);
int valid_path(acc_t *,char *);  /* for source */
acc_t *add_path(acc_t *,char *);
  /* login prototypes */
int login(int);
int find_entry(char *,FILE *);
int get_field(FILE *,char *);
char *get_home_dir(char *);
  /* login prototypes for dot-o files */
char *get_wizard_file(char *);
char *get_access_type(int,char *);
  /* catch prototypes */
char *replaces(char *);
int catchline(char *);
int catchcomm(char **,int);
  /* uwtmp prototypes */
void add_uwtmp();
who_t *read_utmp(int);
void write_utmp(who_t *);
who_t *print_utmp(who_t *,char *);
void free_who(who_t *);
int count_users();
  /* putenv prototype */
int wshputenv(const char *);


#endif    /* if not def EVERYTHING */