int main(int argc, char *argv[]) /* main program */ { int x, retval = 1; /* counters, etc. */ off_t val, len; /* len need to be off_t*/ windows = (WINS *) calloc(1, sizeof(WINS)); /* malloc windows */ head = llalloc(); /* malloc list space */ fpINfilename = NULL; /* allocate in and */ fpOUTfilename = NULL; /* out file name ptrs */ printHex = TRUE; /* address format */ USE_EBCDIC = FALSE; /*use ascii by default*/ /* get cmd line args */ len = parseArgs(argc, argv); MIN_ADDR_LENGTH = getMinimumAddressLength(len); use_env(TRUE); /* use env values */ slk_init(0); /* init menu bar */ init_screen(); /* init visuals */ init_colors(); if ((COLS < MIN_COLS) || (LINES < MIN_LINES)) /* screen's too small */ { endwin(); fprintf(stderr,"\n\nThe screen size too small.\nThe minimum allowable"); fprintf(stderr," screen size is %dx%d\n\n", MIN_COLS, MIN_LINES + 1); exit(-1); } slk_set(6, (printHex) ? "Hex Addr":"Dec Addr", 1); init_fkeys(); /* define menu bar */ while (retval) { free_windows(windows); /* calculate screen */ BASE = (resize > 0 && resize < COLS) ? resize:((COLS-6-MIN_ADDR_LENGTH)/4); MAXY = (LINES) - 3; hex_win_width = BASE * 3; ascii_win_width = BASE; hex_outline_width = (BASE * 3) + 3 + MIN_ADDR_LENGTH; ascii_outline_width = BASE + 2; init_menu(windows); /* init windows */ head = freeList(head); /* free & init head */ /* print origin loc */ mvwprintw(windows->hex_outline, 0, 1, "%0*d", MIN_ADDR_LENGTH, 0); if (fpIN != NULL) /* if no infile... */ { len = maxLoc(fpIN); /* get last file loc */ val = maxLines(len); /* max file lines */ for (x = 0; x <= MAXY && x<=val; x++) /* output lines */ outline(fpIN, x); } wmove(windows->hex, 0, 0); /* cursor to origin */ refreshall(windows); /* refresh all wins */ doupdate(); /* update screen */ mvwaddch(windows->scrollbar, 1, 0, ACS_CKBOARD);/* clear scroller */ /* get user input */ retval = wacceptch(windows, len); } free(fpINfilename); free(fpOUTfilename); freeList(head); screen_exit(0); /* end visualizations */ return retval; /* return */ }
/******************************************************\ * Description: Determines the screen size of the the * * terminal and prompts for the user to * * change the screen. * \******************************************************/ RETSIGTYPE checkScreenSize(int sig) { int count; /* Avoid unused variable warning */ UNUSED(sig); clearScreen(windows); endwin(); init_screen(); /* init visuals */ slk_clear(); /* init menu bar */ slk_restore(); /* restore bottom menu*/ slk_noutrefresh(); doupdate(); /* recacl these values*/ BASE = (COLS - 6 - MIN_ADDR_LENGTH) / 4; /*base for the number */ hex_outline_width = (BASE * 3) + 3 + MIN_ADDR_LENGTH; MAXY = LINES - 3; hex_win_width = BASE * 3; ascii_outline_width = BASE + 2; ascii_win_width = BASE; maxlines = maxLines((fpIN != NULL) ? maxLoc(fpIN) : 0); currentLine = 0; SIZE_CH = TRUE; /* check for term size*/ if ((COLS < MIN_COLS) || (LINES < MIN_LINES)) { /* endwin(); printf("\n\n\n\nscreen size too small\n"); exit(0); */ init_fkeys(); /* define menu bar */ init_menu(windows); /* init windows */ clearScreen(windows); slk_clear(); mvwprintw(windows->hex, 0, 0, "Your screen is too small"); /*mvwprintw(windows->hex, 1, 2, "Resize it to continue");*/ refreshall(windows); doupdate(); } else { init_fkeys(); /* define menu bar */ init_menu(windows); /* init windows */ wmove(windows->hex,0,0); if (fpIN) /* if a file is open */ { for (count = 0; count <= MAXY && count <= maxLines(maxLoc(fpIN)); count++) outline(fpIN, count); mvwprintw(windows->cur_address, 0, 0, "%0*d", MIN_ADDR_LENGTH, 0); wmove(windows->hex,0,0); } refreshall(windows); wnoutrefresh(windows->cur_address); /* this next refresh is to put the cursor in the correct window */ wnoutrefresh(windows->hex); doupdate(); } }