/* menu.c * last revised at 11, August, 1995 * * Copyright (C) 1994-5, All rights reserved. * written by Gyudong Kim(chilly@eleceng.adelaide.edu.au) * */ #include "findhier.h" #include #ifndef _UNIX_ #include #endif /* _UNIX_ */ #define PROMPT "FindHier>" /* * Maximum depth of level displayed. (analysis is done up to any level) * Do you need more level displayed ? Then increase it. * But before doing so, please check the range of "int". */ #define MAXDPT 32767 extern int onlytop; extern int topspecified; extern int mode; extern int numberformat; extern FILE *INPUT,*OUTPUT; char *targ,*top; int depth = MAXDPT; char *get_cmd(prompt) char *prompt; { int c,i; static char buf[BUFSIZE+1]; int init = 1; if (INPUT==stdin) warning("%s ",prompt); i = 0; c = fgetc(INPUT); while (c!=EOF && i|o] filename : %s\n","output redirected to filename"); warning("[<|f] filename : %s\n","input redirected from filename"); } void menu() { char *cmd; char *tok; char buf[BUFSIZE+1]; char *pager = NULL; int runpag=0; int pagmode=0; char tmpfname[BUFSIZE+1]; char pagercmd[BUFSIZE+1]; #ifdef _UNIX_ (void)sprintf(tmpfname,"/tmp/FindHier_%d",getpid()); #else (void)sprintf(tmpfname,".\\findhier.%3x",getpid() & 0xfff); #endif /* _UNIX_ */ pager=getenv("PAGER"); if (pager==NULL) { pager=(char *)myalloc(sizeof("more"),"menu"); (void)strcpy(pager,"more"); } #ifdef _UNIX_ (void)sprintf(pagercmd,"%s %s",pager,tmpfname); #else (void)sprintf(pagercmd,"%s < %s",pager,tmpfname); #endif /* _UNIX_ */ for(;;) { new_cmd: cmd = get_cmd(PROMPT); if (cmd == NULL) { if (INPUT==stdin) return; INPUT = stdin; goto new_cmd; } redo: if (pagmode) switch (cmd[0]) { case 't': case 'a': case 'd': case 'i': case 'x': case 'l': case 'r': case 's': runpag=1; redirect('>',tmpfname); if (OUTPUT==NULL) runpag=0; break; default: break; } switch (cmd[0]) { case '.': if (buf[0]=='.') break; (void)strcpy(cmd,buf); goto redo; case 'C': case 'G': case 'P': case 'M': warning("Conversion command %c not implemented yet.\n",cmd[0]); /* reserved for the converter */ break; case 'p': /* Pager mode toggle */ pagmode ^= 0x1; warning("Pager mode is %s.\n",(pagmode) ? "ON" : "OFF"); break; case 't': onlytop = 1; case 'a': top_list(); onlytop = 2; break; case 'd': if (dangling()) runpag=0; break; case 'n': tok = strtok((char *)(cmd+1)," \t"); if (tok==NULL) menu_usage(); switch (tok[0]) { case 'f': case 'i': case 'n': case 'r': numberformat = tok[0]; break; default: numberformat = DEFNUMFORMAT; break; } break; case 'i': case 'x': case 'l': (void)strcpy(buf,cmd); mode = buf[0]; tok = strtok((char *)(buf+1)," \t"); if (tok == NULL) { menu_usage(); break; } if ((top = global(tok,"Main"))==NULL) { runpag=0; break; } tok = strtok((char *)NULL," \t"); if (tok != NULL) depth = atoi(tok); if (!depth) depth = MAXDPT; if (cmd[0]=='l') (void)out_branch(find_top(top),0); else included(); depth = MAXDPT; break; case 'r': (void)strcpy(buf,cmd); tok = strtok((char *)(buf+1)," \t"); if (tok != NULL) targ = global(tok,"Main"); else { menu_usage(); runpag=0; break; } topspecified = 1; tok = strtok((char *)NULL," \t"); if (tok != NULL) { top = global(tok,"Main"); if (top==NULL) topspecified=0; } else topspecified = 0; (void)reverse(); break; case 's': listing(); break; case '>': case '<': case 'o': case 'f': (void)strcpy(buf,cmd); tok = strtok((char *)(cmd+1)," \t"); if (tok==NULL) { menu_usage(); break; } redirect(cmd[0],tok); break; case 'q': return; default: menu_usage(); break; } (void)strcpy(buf,cmd); if (runpag) { (void)fclose(OUTPUT); (void)system(pagercmd); OUTPUT=stdout; runpag=0; } (void)unlink(tmpfname); } /* of for(;;) */ } /* menu.c */