/* Initialise the global state ready for a new observation to start. */ void setObserveContext (Bool hascontext, Bool rec, int arity, char* caller) { /*struct sigaction sig;*/ o_srcpos = False; o_context = hascontext; o_recursive = rec; o_caller = strdup(caller); o_arity = (unsigned char)arity; q_position = 0x10; fseek(HatFileSeq,q_position,SEEK_SET); hat_interrupted = False; /*sig.sa_handler = ctrlC; sigemptyset(&sig.sa_mask); sig.sa_flags=0; */ /*sigaction(SIGINT,&sig,(void*)0); */ signal(SIGINT,ctrlC); /* Reset the maps here, freeing the tree contents also. */ if (mapAtom2Info) FM_destroy(mapAtom2Info); if (mapExp2Atom) FM_destroy(mapExp2Atom); if (mapContext2Atom) FM_destroy(mapContext2Atom); mapAtom2Info = FM_new((FMComparison)fileoffset_compare ,(FMFreeItem)cleanup_info); mapExp2Atom = FM_new((FMComparison)fileoffset_compare ,(FMFreeItem)cleanup_atom); mapContext2Atom = FM_new((FMComparison)fileoffset_compare ,(FMFreeItem)cleanup_atom); HIDE(fprintf(stderr,"setObserveContext: filepos=0x%x\n",ftell(HatFileSeq));) }
/* (Previously) The main routine called from Haskell. It gathers * all information about identifiers from the file and pretty-prints * the data in columns. */ void observableInfo (int width) { int err; if (!Globals) { fprintf(stdout,"Searching...\n"); q_position = 0x10; fseek(HatFileSeq,q_position,SEEK_SET); map1 = FM_new((FMComparison)fileoffset_compare,0); map2 = FM_new((FMComparison)fileoffset_compare,0); do { q_oneNode(); } while (!feof(HatFileSeq)); globals = FM_new((FMComparison)strcmp,0); locals = FM_new((FMComparison)strcmp,0); constrs = FM_new((FMComparison)strcmp,0); FM_traverse(map1,(FMTraversal)item_sort,InOrder); FM_traverse(globals,(FMTraversal)item_print,InOrder); fprintf(stdout,"[A[K"); /* cursor up and clear-to-eol */ } columnate(width); /* note: some data-structure clean-up needed? */ }
/* The (new) main routine called from Haskell. It gathers all the * counts for identifiers from the file, and dumps the data into * global arrays. Haskell has to get the individual records separately * afterwards. */ void collateIdents (void) { q_position = 0x10; fseek(HatFileSeq,q_position,SEEK_SET); map1 = FM_new((FMComparison)fileoffset_compare,0); map2 = FM_new((FMComparison)fileoffset_compare,0); do { q_oneNode(); } while (!feof(HatFileSeq)); FM_traverse(map1,(FMTraversal)item_flatten,InOrder); //FM_destroy(map1); //FM_destroy(map2); }