#ifndef PADS_H #define PADS_H #include typedef unsigned short Attrib; #define PADS_VERSION 0x930125 /* YYMMDD */ #define CARTE 0x80000000 #define NUMERIC 1 enum Protocol { P_UCHAR = 1U, P_SHORT = 2U, P_LONG = 4U, P_CACHEOP = 0x10U, P_I_DEFINE = 0x11U, P_I_CACHE = 0x12U, P_C_DEFINE = 0x13U, P_C_CACHE = 0x14U, P_STRING = 0x20U, P_INDEX = 0x21U, P_PADDEF = 0x30U, P_ATTRIBUTE = 0x31U, P_BANNER = 0x32U, P_CARTE = 0x33U, P_LINES = 0x34U, P_NAME = 0x35U, P_TABS = 0x36U, P_HELPCARTE = 0x37U, P_PADOP = 0x40U, P_ACTION = 0x41U, P_ALARM = 0x42U, P_CLEAR = 0x43U, P_CYCLE = 0x44U, P_DELETE = 0x45U, P_KBDSTR = 0x46U, P_LINE = 0x47U, P_LINEREQ = 0x48U, P_MAKECURRENT = 0x49U, P_MAKEGAP = 0x4AU, P_NEXTLINE = 0x4BU, P_NUMERIC = 0x4CU, P_USERCLOSE = 0x4DU, P_CREATELINE = 0x4EU, P_REMOVELINE = 0x4FU, P_HOSTSTATE = 0x50U, P_BUSY = 0x51U, P_IDLE = 0x52U, P_USERCUT = 0x5FU, P_PICK = 0x60U, P_HELPSTR = 0x70U, P_SHELL = 0x71U, P_VERSION = 0x80U, P_QUIT = 0x81U, P_ERROR = 0x82U }; #ifndef PADS_TERM #include #include #define PRINTF_TYPES const char * ... #define PRINTF_ARGS const char *fmt, ... #define PRINTF_PROLOGUE\ va_list varlist;\ va_start(varlist, fmt);\ int vargs[8];\ for(int vargcnt = 0; vargcnt < 8; vargcnt++)\ vargs[vargcnt] = va_arg(varlist, int);\ va_end(varlist) #define FMT(i) (vargs[i]) #define PRINTF_COPY\ (fmt?fmt:""), FMT(0),FMT(1),FMT(2),FMT(3),FMT(4),FMT(5),FMT(6),FMT(7) void WireTap(PRINTF_TYPES); #ifdef TRACE #define OK(x) if( !ok() ) PadsError(__SRC__); #define VOK if( !ok() ) PadsError(__SRC__); #define IF_LIVE(x) { if( x ) PadsError(__SRC__); } if(0) #define SRCFILE(f) static const char *__SRC__ = f; typedef int (*PFI)(PRINTF_ARGS); extern "C" { PFI trace_fcn(const char*,int), trace_ptr; } #define trace (!(trace_ptr=trace_fcn(__SRC__,__LINE__))) ? 0 : (*trace_ptr) #else #define OK(x) { if( !ok() ) return x; } #define VOK { if( !ok() ) return ; } #define IF_LIVE(x) if( x ) #define SRCFILE(f) #ifdef __cplusplus #define trace(...) #else #define trace if( 0 ) #endif #endif class Index { public: int indx; Index(); Index(int); int null() { return !indx; } }; extern Index ZIndex; class Carte { public: int size; /* host.size != term.size */ int items; unsigned char attrib; unsigned char width; unsigned char pad[2]; struct Index bin[1]; Carte() {}; }; #else # define MJR(i) ((i)>>8) # define MNR(i) ((i)&0xFF) typedef int Index; typedef struct Carte Carte; struct Carte { int size; /* host.size != term.size */ uchar attrib; uchar width; uchar pad[2]; Index bin[1]; }; typedef enum Protocol Protocol; #endif #define SELECTLINE ((Attrib)0x0001) #define SORTED ((Attrib)0x0002) #define ACCEPT_KBD ((Attrib)0x0004) #define FOLD ((Attrib)0x0008) #define TRUNCATE ((Attrib)0x0010) #define USERCLOSE ((Attrib)0x0020) #define DONT_CUT ((Attrib)0x0040) #define FLUSHLINE ((Attrib)0x0080) /* should not be required */ #define FAKELINE ((Attrib)0x0100) #define USERCUT ((Attrib)0x0200) #define DONT_CLOSE ((Attrib)0x0400) #define NO_TILDE ((Attrib)0x0800) #define SELECTLINET ((Attrib)0x1000) #define DONT_DIRTY ((Attrib)0x1000) #ifndef PADS_TERM const char *sf(PRINTF_TYPES); const char *PadsInit(int =0, char** =0); const char *PadsTermInit(int =0, char** =0, char* =0); void PadsServe(long = 0); void NewHelp(); void NewPadStats(); class PadRcv; typedef void (PadRcv::*Action)(...); void Pick(const char*,Action,long); long UniqueKey(); Index NumericRange(short,short); void PadsWarn(PRINTF_TYPES); void PadsQuit(); //extern char *TapTo; void PadsError(PRINTF_TYPES); #define HELP_OVERVIEW 0 #define HELP_MENU 1 #define HELP_KEY 2 #define HELP_LMENU 3 #define HELP_LKEY 4 #define HELP_NTOPICS 5 class PadRcv { friend class Remote; friend class Pad; short oid; short magic; int isvalid(); public: PadRcv(); ~PadRcv(); void invalidate(); virtual int disc(); virtual const char *kbd(char*); # ifdef SHOWHELP virtual const char *help(long); # else virtual const char *help(); # endif virtual void numeric(long); virtual void userclose(); virtual void cycle(); virtual void linereq(long,Attrib=0); virtual int accept(Action); virtual void usercut(); # ifdef SHOWHELP void showhelp(long); # endif }; class Pad { PadRcv *_object; const char *_name; const char *_banner; Attrib _attributes; char _unused[2]; long _lines; void termop(enum Protocol); long errorkey; void nameorbanner(enum Protocol, PRINTF_ARGS); void helpmenu(); public: int ok(); Pad(PadRcv *); ~Pad(); void alarm(short=0); void banner(PRINTF_TYPES); void clear(); void dump(); void error(PRINTF_TYPES); void insert(class Line&); void insert(long, Attrib, PadRcv*, Index, PRINTF_TYPES); void insert(long, Attrib, PadRcv*, class Menu&, PRINTF_TYPES); void insert(long, Attrib, PRINTF_TYPES); void insert(long, PRINTF_TYPES); void lines(long); void makecurrent(); void makegap(long,long); void menu(Index); void menu(class Menu&); void name(PRINTF_TYPES); void options(Attrib, Attrib=0); void tabs(short); void removeline(long); void createline(long,long); void createline(long); }; class Line { public: int ok(); Line(); PadRcv *object; char *text; long key; Attrib attributes; char dummy[2]; /* For buggy SysV i386 compiler */ Index carte; }; class IList { friend class Menu; Index index; IList *next; public: IList(Index i, IList *n) { index = i; next = n; } }; class Item { public: char str[64]; const char *text; Action action; long opand; Item(const char*,Action,long); Item(); /* ever used ? */ }; class Menu { IList *list; int size; void dump(); public: Menu(); ~Menu(); Menu( const char*, Action=0, long=0 ); Index index( const char* =0, Action=0, long=0 ); void first( const char*, Action=0, long=0 ); void first( Index ); void last( const char*, Action=0, long=0 ); void last( Index ); void sort( const char*, Action=0, long=0 ); void sort( Index ); }; class Binary { public: Binary *left; Binary *right; Index index; Binary() {} }; class Cache { friend class ItemCache; friend class CarteCache; Binary *root; Index current; Index SIZE; public: Cache(int); int ok(); }; class ItemCache : public Cache { Item **cache; int compare(Item*,Item*); public: ItemCache(); Index place(Item); Item *take(Index); }; class CarteCache : public Cache { Carte **cache; int compare(Carte*,Carte*); public: CarteCache(); Index place(Carte*); Carte *take(Index); Index numeric(int,int); void cartelimits(Carte*); }; extern ItemCache *ICache; extern CarteCache *CCache; #endif #define CARTESIZE(s) (sizeof(Carte) + (s)*sizeof(Index)) #ifdef PADS_TERM long RcvLong(); short RcvShort(); uchar RcvUChar(); char *RcvString(char*); void RcvAllocString(char**); void SendLong(long); void SendShort(short); void SendUChar(uchar); void SendString(char*); #else #include typedef unsigned char uchar; FILE *Popen(const char*,const char*); int Pclose(FILE*); class Remote { public: int ifd, ofd; int pktbase; int pktsize; uchar writebuffer[2048]; long shiftin(int); void shiftout(int, long); int writesize; void err(const char* = 0); int get(); void checkproto(int p); void put(char c); void proto(int p); long rcvlong(); short rcvshort(); uchar rcvuchar(); PadRcv *rcvobj(); void sendlong(long); void sendobj(PadRcv*); void sendshort(short); void senduchar(unsigned char); char *rcvstring(char*); void sendstring(const char*); void pktstart(char); void pktend(); void pktflush(); void share(); Remote(const char*); Remote(int); }; extern Remote *R; #endif #if defined(sgi) && defined(_BSD_SIGNALS) /* C++ on IRIX 5.1 */ #include #define SIG_TYP SIG_PF #endif #endif /* libc.C */ char *StrCpy(char*, const char*); /* libC.C */ char *StrDup(const char*);