/* hat-interactive: nice tool for traversing the hat file structure */ /* #include */ #include #include #include #include #include "Expressions.h" #include "hatinterface.h" #include "hatgeneral.h" /* Main driver and routines to providing basic interface to archive file. */ void interactive(); char* fname; int verboseMode = 0; unsigned int precision = 100; HatFile handle; int main (int argc, char *argv[]) { printf("hat-checki version %s\n",hatVersionNumber()); if (argc!=2) { fprintf(stderr,"\nusage: hat-checki file-name\n"); exit(1); } fname = hatFileExtension(argv[1]); if ((handle=hatOpenFile(fname))==HatFileNotFound) { fprintf(stderr, "cannot open trace file %s\n\n",argv[1]); exit(1); } if (handle==HatFileBadVersion) { fprintf(stderr, "format of file unknwon/not supported %s\n\n",fname); exit(1); } interactive(0); hatCloseFile(handle); return 0; } int getline(char s[], int max) { int c,i; fflush(stdout); c=getchar(); for (i=0;(i Handle -> Int -> IO() outputForSamePointer output bridge p = do m <- more output if m == False then putStr ("\t -> "++(show p)) else do p2 <- readpointer bridge c <- readchar output if (p == p2) then putStr (prettyPrintChar c) >> outputForSamePointer output bridge p else putStr ("\t -> "++(show p)++"\n"++(prettyPrintChar c)) >> outputForSamePointer output bridge p2 void checkOutput() { char str[255]; int output,bridge; sprintf(str,"%s%s",fname,".output"); output = open(str, 0); sprintf(str,"%s%s",fname,".bridge"); bridge = open(str, 0); if (isEOF(output)) printf("Program had no output\n\n"); else { printf("output text\t -> address\n"); showOutput(output,bridge); printf("\n"); } close(output); close(bridge); }*/ int isCmd(char* s,char* s1,char* s2) { if (strcmp(s,s1)==0) return 1; return (strcmp(s,s2)==0); } #define FIXPRIMAX 8 char fixpribuf[FIXPRIMAX+1]; char *getfixpriStr() { switch (getInfixType()) { case HatINFIX: sprintf(fixpribuf, "infix %d", getInfixPrio()); break; case HatINFIXR: sprintf(fixpribuf, "infixr %d", getInfixPrio()); break; case HatINFIXL: sprintf(fixpribuf, "infixl %d", getInfixPrio()); break; case HatNOINFIX: sprintf(fixpribuf, ""); break; } return fixpribuf; } int lhi3(char b) { return (int)(b>>5); } int llo5(char b) { return (int)(b&037); } filepointer printNode(filepointer offset) { char b,showAble=0; filepointer next; b = getNodeType(handle,offset); //printf("%i ",b); switch (lhi3(b)) { case TR: printf("TR 0x%x: ", offset); switch (llo5(b)) { case APP: { int i=0; int arity = getAppArity(); showAble = 1; printf("Application: "); printf("AppTrace 0x%x, ",getParent()); printf("AppFun 0x%x, ",getAppFun()); printf("Arguments ["); while (i++, (b)ack, (n)ext=0x%x or (f)ollow SATs, (q)uit: ",next); getline(command,80); if (isCmd(command,"back","b")) { if (toplevel) printf("Sorry. Already at beginning. Can't go back!\n"); else return; } else if (isCmd(command,"quit","q")) { printf("Ok. Goodbye. Thank you for using hat-check-interactive! :)\n\n"); exit(0); } else { if (isCmd(command,"next","n")) { if (next!=0) { interactive(next); } } else { if (isCmd(command,"follow","f")) { adr = hatFollowSATCs(handle,current); } else { adr = (filepointer) atol(command); if (adr==0) { sscanf(command, "0x%x", &adr); } } if (adr!=0) { if (current==0) current=adr;else interactive(adr); } else { if (isCmd(command,"verbose","v")) { verboseMode=1-verboseMode; printf("verbose mode is now "); if (verboseMode) printf("ON\n"); else printf("OFF\n"); } else printf("Please enter 'b','n','q' or an address!\n"); } } } } }