/* * @(#)StrHier.h 1.3 93/01/29 SwRI * * StrHier.h -- interface to string hierarchies */ #ifndef STR_HIER_H #define STR_HIER_H #include #include "Destroy.h" #include "LinkList.h" /** ** types **/ typedef struct StrHier_s { DestroyObj_t *Destroy; char *str; /* allocated string */ int number; struct StrHier_s *parent; /* pointer to previous StrHier_s in tree */ LinkList sublist; /* more LinkLists to more StrHier */ void *info; /* a place to store stuff*/ LinkList (*GetNextItems)(struct StrHier_s *S); } StrHierNode, *StrHier; typedef void (*StrHierFun)(StrHier); /** ** functions **/ /* * IndentOf -- returns # of columns (tabs=8) before first char */ int IndentOf( char *str ); StrHier StrHierAddChild( StrHier parent, char *str ); /* StrHierAddChildPair -- add string and associated number */ StrHier StrHierAddChildPair(StrHier parent,char *str,int n); /* StrHierApplyPre -- apply function to each node in StrHier,preorder */ void StrHierApplyPre(StrHier h, StrHierFun f); /* StrHierApplyToLeaves -- apply function to leaves of StrHier */ void StrHierApplyToLeaves(StrHier h, StrHierFun f); /* * StrHierAssignStr -- assign a string to a StrHier node */ void StrHierAssignStr( StrHierNode * node, char *str ); int StrHierCompareStr( char *str, StrHier hier ); /* StrHierDepth -- returns depth of StrHier node */ int StrHierDepth(StrHier h); /* * StrHierFetch -- fetch a string hierachy from a file */ StrHier StrHierFetch( char *TreeFile ); StrHier StrHierFind( StrHier hier, char *str, LinkFun compare ); StrHier StrHierFindByStr( StrHier hier, char *str ); /* * StrHierNamer -- returns name for a string hierarchy */ char * StrHierNamer( char *label, StrHier hier ); /* * StrHierNodeCreate -- create node with string and sublist */ StrHier StrHierNodeCreate( char *str ); /* * StrHierCreateNodes -- create n number of nodes with string and sublist */ StrHier StrHierCreateNodes( int n ); /* * StrHierParse -- create string hierarchy by parsing file add lines with same * indent to parents sublist create subhier for lines with more indentation * return first less indented line */ char * StrHierParse( FILE * fp, char *line, StrHier parent, int PrevIndent ); /* * StrHierPrint -- print the string hierarchy */ void StrHierPrint( StrHier hier ); void DestroyStrHier( void *V ); int StrHierCmp( void ); /**********/ /* macros */ /**********/ #define StrHierOnList(list) ((StrHier)LinkData(list)) #define StrHierName(s) ((s)->str) #define StrHierVal(s) ((s)->number) #define StrHierChildren(s) ((s)->sublist) #define StrHierParent(s) ((s)->parent) #define StrHierInfo(s) ((s)->info) #define SNAME(s) ((s)->str) #define SNUM(s) ((s)->number) #define SUBLIST(s) ((s)->sublist) #define SUBINFO(s) ((s)->info) #endif