
/*
 * SHELL.H
 *
 * (c)1986 Matthew Dillon     9 October 1986
 *
 *
 * SHELL include file.. contains shell parameters and extern's
 *
 * Version 2.07M by Steve Drew 10-Sep-87
 *
 * Version 4.01A by Carlo Borreo & Cesare Dieni 17-Feb-90
 *
 */

#define RAW_CONSOLE 1   /* Set to 0 to compile out Cmd Line Editing */
#define KICK20

#define strlen strlen

#include <exec/types.h>
#include <exec/exec.h>
#include <libraries/arpbase.h>
#include <intuition/intuitionbase.h>
#include <libraries/dosextens.h>
#include <time.h>
#include <ctype.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "proto.h"

LONG AssignLock( UBYTE *name, BPTR lock );
BOOL AssignLate( UBYTE *name, UBYTE *path );
BOOL AssignPath( UBYTE *name, UBYTE *path );
BOOL AssignAdd( UBYTE *name, BPTR lock );

typedef struct FileInfoBlock FIB;
#ifdef AZTEC_C

# include <functions.h>
# define DEVTAB(x) _devtab[x->_unit].fd
# define CHARSWAIT(x) (x->_bp < x->_bend)
# define COMPILER "Aztec C 5.0d"
# pragma amicall(DOSBase, 0x264, AssignLock(d1,d2))
# pragma amicall(DOSBase, 0x26a, AssignLate(d1,d2))
# pragma amicall(DOSBase, 0x270, AssignPath(d1,d2))
# pragma amicall(DOSBase, 0x276, AssignAdd(d1,d2))

#else

# include <proto/all.h>
# include <ios1.h>
# define DEVTAB(x) _ufbs[(x)->_file].ufbfh
# define CHARSWAIT(x) (x->_rcnt != x->_wcnt)

  extern struct UFB _ufbs[];
# define COMPILER "Lattice C 5.10"
# define index strchr
# define memmove(t,f,l) movmem((f),(t),(l))
# define swapmem(x,y,z) swmem(x,y,z)
# pragma libcall DOSBase AssignLock 264 2102
# pragma libcall DOSBase AssignLate 26a 2102
# pragma libcall DOSBase AssignPath 270 2102
# pragma libcall DOSBase AssignAdd 276 2102

#endif

#ifndef MAX
#define MAX(x,y) ((x)>(y) ? (x) : (y))
#endif

#ifdef KICK20
typedef ULONG	Tag;
struct TagItem	{
    Tag		ti_Tag;
    ULONG	ti_Data;
};
#define TAG_DONE   (0L)	/* terminates array of TagItems. ti_Data unused	*/
#define TAG_END	TAG_DONE
#define	TAG_IGNORE (1L)	/* ignore this item, not end of array		*/
#define	TAG_MORE   (2L)	/* ti_Data is pointer to another array of TagItems
						 * note that this tag terminates the current array */
#define	TAG_SKIP   (3L)	/* skip this and the next ti_Data items		*/
#define TAG_USER (1L<<31) /* differentiates user tags from system tags*/

/* definitions for the System() call */

enum {	SYS_Dummy = TAG_USER + 32,
	SYS_Input,			/* specifies the input filehandle  */
	SYS_Output,			/* specifies the output filehandle */
	SYS_Asynch,			/* run asynch, close input/output on exit(!) */
	SYS_UserShell,		/* send to user shell instead of boot shell */
	SYS_CustomShell,	/* send to a specific shell (data is name) */
};
#endif

#define MAXAV		256		/* Max. # of arguments			*/
#define MAXSRC		5		/* Max. # of source file levels	*/
#define MAXIF		10		/* Max. # of if levels			*/
#define MAXALIAS	20		/* Max. # of alias levels		*/
#define MAXMYFILES	9		/* Max. # of internal files		*/

#define LEVEL_SET		0		/* which variable list to use   */
#define LEVEL_ALIAS		1
#define LEVEL_LABEL		2
#define LEVEL_SOURCE	2

#define SBYTE signed char
#define MAXITEMS 16
#define MAXMENUS 6

#ifndef NULL
#define NULL 0L
#endif

#define CHECKBREAK() dobreak()

#ifndef AZTEC_C
struct _dev {
	long  fd;
	short mode;
	};
#endif

struct HIST {
	struct HIST *next, *prev;	/* doubly linked list */
	char *line;					/* line in history    */
};

struct PERROR {
	int errnum;					/* Format of global error lookup */
	char *errstr;
};

struct DPTR {					/* Format of directory fetch pointer */
	BPTR lock;					/* lock on directory   */
	FIB *fib;					/* mod'd fib for entry */
	};

extern struct HIST *H_head, *H_tail;
extern struct PERROR Perror[];
extern struct DPTR *dopen();
extern char **av;
extern char *Current;
extern int  H_len, H_tail_base, H_stack;
extern int  E_stack;
extern int  Src_stack, If_stack, forward_goto;
extern int  ac;
extern int  max_ac;
extern int  debug, Rval, Verbose, disable, Quit;
extern int  Lastresult, atoierr;
extern int  Exec_abortline;
extern int   S_histlen;
extern unsigned int options;
extern long  Cin, Cout, Cout_append;
extern char *Cin_name, *Cout_name;
extern char  Cin_type,  Cout_type;  /* these variables are in transition */
extern char *Pipe1, *Pipe2;

extern FILE *Src_base[MAXSRC];
extern long Src_pos[MAXSRC];
extern int  Src_if[MAXSRC];
extern char If_base[MAXIF];
extern struct Process *Myprocess;
extern struct CommandLineInterface *Mycli;

extern struct ArpBase *ArpBase;

extern long atol(), Atol(), myatol();

extern char v_titlebar[], v_prompt[], v_hist[], v_histnum[], v_debug[],
	v_verbose[], v_stat[], v_lasterr[], v_cwd[], v_except[], v_passed[],
	v_path[], v_gotofwd[], v_linenum[], v_every[], v_lcd[], v_rxpath[],
	v_hilite[], v_scroll[], v_minrows[], v_result[], v_qcd[], v_noreq[],
	v_value[], v_nobreak[], v_bground[];

extern char o_hilite[], o_lolite[], *o_csh_qcd, o_internal;
extern char o_aux, o_minrows, o_scroll, o_nowindow, o_noraw, o_vt100;
extern char o_nofastscr, o_kick20, o_nobreak, o_bground, o_resident;
extern long o_noreq;
extern char Buf[], isalph[], confirmed, *classfile;

/* #define isalphanum(x) isalph[x] */

typedef struct file_info {
	LONG flags;
	LONG size;
	LONG blocks;
	char class[12];
	struct DateStamp date;
} FILEINFO;

typedef struct Class {
	struct Class *next;
	char name[1];
} CLASS;

extern CLASS *CRoot, *LastCRoot;
extern struct Window *Win;

#if 1
LONG RunCommand( BPTR seg, long stack, UBYTE *paramptr, long paramlen );
struct Segment *FindSegment( UBYTE *name, struct Segment *seg, long system );
LONG System( UBYTE *command, struct TagItem *tags );

# pragma libcall DOSBase RunCommand 1f8 432104
# pragma libcall DOSBase FindSegment 30c 32103
# pragma libcall DOSBase System 25e 2102
#endif
