Join Header files

Begin header files in three sections:

///////////
typedef struct{ 
 char name[20];
 int code;
} Tag;
enum TagFlags{ 
 // these are not used as return status for join, 
 // but it is reasonable to make one list because 
 // their menings are related.
 TagNull,
 TagEmit,   // emit generically means selected for output
 TagStop,   // Not sure, probably immediate halt
 TagClose,  // Indicates closure of a sequence, not necessarily matched
 TagText,   // generally means we are dealing with readable chars
 TagSingle,
 TagSkip,
 TagDone
};
extern Tag tags[];
#define NUMTAGS 40
////////////
Begin
/////////////////
enum {TEST=0,TEXT,MEM,LAZYJ,CONSOLE,STRING};

int init_join(void);

enum { Match_All = 16,Match_Once,Match_Not,Match_Some,Debug};

//int type_from_name(char* name);// spaghetti macros
//int mode_from_name(char*);
#define next_white(p)  while(!isspace(*p)) p++
#define skip_white(p)  while(isspace(*p)) p++
#define skip_alpha(p)  while(*p && isalpha(*p)) p++
#define skip_alnum(p)  while(*p && isalnum(*p)) p++
#define skip_non_alpha(p) while(*p && !isalpha(*p)) p++
#define skip_eol(p)   while(*p && *p != '\n') p++
#define collect_alpha(p,q) while(*p && isalpha(*p)){*q=*p;  p++;q++;}
#define skip_arg(p) skip_white(p);skip_alnum(p)

// The app, debug and executive signal return status 
//from their loop usingthese


///////////

Begin, cursor definition:
///////////
// cursor.h
// All the graph manipulations done through exec call in the Cursor
// 
//  requests for action from the join back to the attachment
// the attachment has an 'exec' function for this, 
// unique to the attachment
#define version 1.0
enum CursorMethods{ 
 Reset=0,  // This is a pop notification
 Set,  // a push notification
 Fetch, // next node request
 Step, // step one node forward
 Skip,  // Skip to end of sequence
 // Outpout methods
 Append,  //output is a graph
 Descend,  // Start new sequence
 Branch,  // Close current sequence
 Init,  // initialize

 };

// Resuts from a method cll back.  
// These determine the next  action taken by join.
enum CursorStatus {
 Null =0, // normal result
 End, // end of sequence
 Done, // forces a break in the main loop
 Pause, // attachment yields to another join instance
 Break,  // exit current sequence if matched
 Match,
 Push, // push and recurse
 Singleton,  // A sequene wiht one element
 Output, // Selected for output.
 LastStatus // Attachment specific codes
 };

// Key and op, the content of a node
// Note, the null node is valid throughout, 
// it is a terminator; a clearing node.
//
typedef struct {
  char op;  // 
  char* key;   // Basic text held at the node
} Element;

// Cursor holds everything needed to traverse a graph
//  eval 
//     a call back that executes whatever context 
//     specific binary grammar forms the application
//  exec 
//     generally selects one of the graph methods.
//
// join controls cursors but the attachment keeps some
// state variable in it


//the first five values are used only by the attachment
// and are here mainly for convenience of working
//  with text char  files
// they need pushing aand popping somust be retained in a cursor.
//
typedef struct Cursor Cursor;
typedef Cursor* PCursor;
typedef int (*EvalCallback)(Cursor*,Cursor*);
typedef int (*ExecCallback)(Cursor* ,int,void *);
typedef struct   Cursor{ 
 void * start; // to free the memory
 void *current; // Pointer to current node
 void *state;   // Maintains pointer during recursion
 char prevOp;    // Needed for some attachments with inconsistent grammar
 int key_size;   // maximum key size
 int mode;     // Carries the match modifier for match function
 int index;      // stacking multiple joins
 int type;     // Type of attachment
 Element element; // current node value
 ExecCallback exec; 
 EvalCallback eval;
} Cursor;
 
int AddHandlers(ExecCallback,EvalCallback,char *);
// Exported by the join engine, mostly cursor utilities
int join_cursor(PCursor left, PCursor right, PCursor result);
PCursor new_cursor(int);
PCursor dup_cursor(PCursor);
PCursor get_cursor(int); 
//PCursor * CreateCurse(int type,char * args[]);
void del_cursor(PCursor);
int NextInstance(PCursor *l, PCursor *r,PCursor *o);
int CurrentTriple(PCursor *l, PCursor *r,PCursor *o);

char * element_from_string(char*,Element*);
PCursor init_cursor(ExecCallback, EvalCallback,int,void*) ;
// from the cursor stack mehods
//void remove_cursors(PCursor m); // remove all three triples
void ReplaceCursor(PCursor);  //Replace one
int GetCursorFile(PCursor self,void * args[]); // put file contents into cursor buff
//Standard match routine with match modifiers
// designed to share return space with callback status

int MatchKey(Element* p, Element* q); 


#define Matched(p,q) (p==Match || p == Break) && (q == Match || q == Break)
///////////////

No comments: