home *** CD-ROM | disk | FTP | other *** search
/ Amiga GigaPD 3 / Amiga_GigaPD_v3_3of3.iso / netbsd / contrib / ados / fv151.lzh / fv / screen.c < prev   
C/C++ Source or Header  |  1993-06-14  |  8KB  |  309 lines

  1. #include "main.h"
  2.  
  3. unsigned long size;
  4. extern int alignment;
  5.  
  6. int show_addr(address, force)
  7. int address;
  8. int force;
  9. {
  10.     int index;
  11.     static unsigned long last_buf_size = 0;
  12.     char ch;
  13.  
  14.     wmove(status_window, 0, 0);
  15.     if (wdismode)
  16.         sprintf(out_string, "[%8d-%8d]", address, address + buf_size);
  17.     else
  18.         sprintf(out_string, "[%08x-%08x]", address, address + buf_size);
  19.     waddstr(status_window, out_string);
  20.     wrefresh(status_window);
  21.     
  22.     if ((daddr != address) || (buf_size != last_buf_size)) {
  23.         if (dirty) 
  24.             save_changes();
  25.  
  26.         daddr = address;
  27.         clear_buffer();
  28.         (void) fseek(view_file, address, 0);
  29.         if (!(size = fread(buffer, 1, buf_size, view_file)))
  30.             if (!force)
  31.                 return(1);
  32.         last_buf_size = buf_size;
  33.     }
  34.  
  35.     wmove(status_window, 0, 0);
  36.     if (wdismode)
  37.         (void) sprintf(out_string, "[%8d-%8d]", address, address + buf_size);
  38.     else
  39.         (void) sprintf(out_string, "[%08x-%08x]", address, address + size);
  40.     waddstr(status_window, out_string);
  41.     wrefresh(status_window);
  42.     
  43.     if (chdis)
  44.         for (index = 0; index < buf_size; index++) {
  45.         wmove(main_window, index / (wpline * 4),
  46.                addis * 10 + wpline * 9 * wdis + index % (wpline * 4));
  47.         if (index < size) {
  48.             ch = buffer[index];
  49.             if ((((ch >= ' ') && (ch <= 'Z')) ||
  50.                 ((ch >= 'a') && (ch <= 'z')) ||
  51.                  (strchr(ACCEPT, ch) != NULL)) &&
  52.                  (!strchr(DENY, ch) != NULL))
  53.                 if (strchr(REMAP, ch) != NULL)
  54.                     waddch(main_window, ' ');
  55.                 else
  56.                     waddch(main_window, ch);
  57.             else
  58.                 waddch(main_window, '.');
  59.         } else
  60.             waddch(main_window, ' ');
  61.         }
  62.  
  63.     for (index = 0; index < (buf_size + 3) / 4; index++) {
  64.         if (((index % wpline) == 0) && addis) {
  65.             wmove(main_window, index / wpline, 0);
  66.             if (index >= (size + 3) / 4)
  67.                 waddstr(main_window, "          ");
  68.             else {
  69.                 if (wdismode)
  70.                 (void) sprintf(out_string, "%8d: ", index * 4 + address);
  71.                 else
  72.                 (void) sprintf(out_string, "%08x: ", index * 4 + address);
  73.                 waddstr(main_window, out_string);
  74.             }
  75.         }
  76.         if (wdis) {
  77.             wmove(main_window, index / wpline, addis * 10 + (index % wpline) * 9 * wdis);
  78.             if (index < (size + 3) / 4)
  79.             switch (wdismode) {
  80.                 case 0:
  81.                 (void) sprintf(out_string, "%08x ", ibuffer[index]);
  82.                 waddstr(main_window, out_string);
  83.                 break;
  84.                 case 1:
  85.                 (void) sprintf(out_string, "%8d ", ibuffer[index]);
  86. /*
  87.                 out_string[8] = ' ';
  88. */
  89.                 out_string[8] = '\0';
  90.                 waddstr(main_window, out_string);
  91.                 break;
  92.                 case 2:
  93.                 (void) sprintf(out_string, "%-9f ",
  94.                         *((float *) &ibuffer[index]));
  95.                 out_string[8] = '\0';
  96.                 waddstr(main_window, out_string);
  97.                 break;
  98.                 case 3:
  99.                 if ((index & 1) == 0) {
  100.                     (void) sprintf(out_string, "%-18lf ",
  101.                             *((double *) &ibuffer[index]));
  102.                     out_string[17] = '\0';
  103.                     waddstr(main_window, out_string);
  104.                 }
  105.                 break;
  106.             }
  107.             else
  108.             waddstr(main_window, "         ");
  109.         }
  110.     }
  111.     wrefresh(main_window);
  112.     return(0);
  113. }
  114.  
  115. waddch_filt(ch)
  116. char ch;
  117. {
  118.     if ((((ch >= ' ') && (ch <= 'Z')) ||
  119.         ((ch >= 'a') && (ch <= 'z')) ||
  120.          (strchr(ACCEPT, ch) != NULL)) &&
  121.          (!strchr(DENY, ch) != NULL))
  122.         if (strchr(REMAP, ch) != NULL)
  123.             waddch(main_window, ' ');
  124.         else
  125.             waddch(main_window, ch);
  126.     else
  127.         waddch(main_window, '.');
  128. }
  129.  
  130. int init()
  131. {
  132.     initscr();
  133.     if (LINES == 0) {
  134.         fprintf(stderr, "Curses initialization failed.\n");
  135.         exit(1);
  136.     }
  137.  
  138. #ifdef sequent
  139.     raw();
  140. #else
  141.     cbreak();
  142. #endif
  143.     noecho();
  144.     nonl();
  145.     clear();
  146.     refresh();
  147.  
  148.     wpline  = (COLS - addis * 10) / (9 * wdis + chdis * 4);
  149.     buf_size = (LINES - 1) * wpline * 4;
  150.  
  151.     main_window = newwin(LINES - 1, COLS, 1, 0);
  152.     status_window = newwin(1, COLS, 0, 0);
  153.  
  154.     leaveok(main_window, TRUE);
  155.     leaveok(status_window, TRUE);
  156.  
  157.     edit_mode();
  158. }
  159.  
  160. int de_init()
  161. {
  162.         clear();
  163.         refresh();
  164.         echo();
  165.         nl();
  166.         endwin();
  167. }
  168.  
  169. #define RHELP_SIZ 23
  170. #define txtlin(x, y) { wmove(help_window, x, 1); waddstr(help_window, y); }
  171. help_me2()
  172. {
  173.     WINDOW *help_window;
  174.     help_window = newwin(RHELP_SIZ, 38, (LINES-RHELP_SIZ) / 2, COLS/2 - 19);
  175.     (void) box(help_window, '|', '-');
  176.  
  177.     wmove(help_window, 1, 16);
  178.     waddstr(help_window, "FV Help:");
  179.     
  180.     txtlin(3, "  /? = Hex Search      (For, Rev)");
  181.     txtlin(4, "  +- = Columns    (Add, Subtract)");
  182.     txtlin(5, "  0G = Position      (Start, End)");
  183.     txtlin(6, "  m' = Marks       (Set, Jump to)");
  184.     txtlin(7, "^u^d = Half Page       (Up, Down)");
  185.     txtlin(8, "^b^f = Full Page       (Up, Down)");
  186.     txtlin(9, " acw = Address/Char/Word Display");
  187.     txtlin(10, "   B = Power of 2 buffer");
  188.     txtlin(11, "   r = Reread file");
  189.     txtlin(12, "  ^l = Redisplay text");
  190.     txtlin(13, "   t = Word Display type  Hex/Dec");
  191.     txtlin(14, "  qx = Quit fv");
  192.     txtlin(15, "<space> = Last position visited");
  193.     txtlin(16, "<tab>   = Mode       (Hex/String)");
  194.     txtlin(17, "<hjkl>  = Scrolling");
  195.     txtlin(18, "? in search is any byte");
  196.  
  197. /*
  198.     wmove(help_window, 3, 3);
  199.     waddstr(help_window, "  /? = Hex Search      (For, Rev)");
  200.     wmove(help_window, 4, 3);
  201.     waddstr(help_window, "  +- = Columns    (Add, Subtract)");
  202.     wmove(help_window, 5, 3);
  203.     waddstr(help_window, "  0G = Position      (Start, End)");
  204.     wmove(help_window, 6, 3);
  205.     waddstr(help_window, "  m' = Marks       (Set, Jump to)");
  206.     wmove(help_window, 7, 3);
  207.     waddstr(help_window, "^u^d = Half Page       (Up, Down)");
  208.     wmove(help_window, 8, 3);
  209.     waddstr(help_window, "^b^f = Full Page       (Up, Down)");
  210.     wmove(help_window, 9, 3);
  211.     waddstr(help_window, " acw = Address/Char/Word Display");
  212.     wmove(help_window, 10, 3);
  213.     waddstr(help_window, "   B = Power of 2 buffer");
  214.     wmove(help_window, 11, 3);
  215.     waddstr(help_window, "   r = Reread file");
  216.     wmove(help_window, 12, 3);
  217.     waddstr(help_window, "  ^l = Redisplay text");
  218.     wmove(help_window, 13, 3);
  219.     waddstr(help_window, "   t = Word Display type  Hex/Dec");
  220.     wmove(help_window, 14, 3);
  221.     waddstr(help_window, "  qx = Quit fv");
  222.     wmove(help_window, 16, 3);
  223.     waddstr(help_window, "<space> = Last position visited");
  224.     wmove(help_window, 17, 3);
  225.     waddstr(help_window, "<tab>   = Mode       (Hex/String)");
  226.     wmove(help_window, 18, 3);
  227.     waddstr(help_window, "<hjkl>  = Scrolling");
  228.     wmove(help_window, 19, 3);
  229.     waddstr(help_window, "? in search is any byte");
  230. */
  231.  
  232.     wmove(help_window, RHELP_SIZ - 2, 10);
  233.     waddstr(help_window, "Press any key...");
  234.  
  235.     wrefresh(help_window);
  236.     wgetch(help_window);
  237.     delwin(help_window);
  238. }
  239.  
  240. #define HELP_SIZE 20
  241. help_me()
  242. {
  243.     WINDOW *help_window;
  244.     help_window = newwin(HELP_SIZE, 49, (LINES-HELP_SIZE) / 2, COLS/2 - 24);
  245.     (void) box(help_window, '|', '-');
  246.  
  247.     wmove(help_window, 1, 16);
  248.     waddstr(help_window, "FV Editor Help:");
  249.  
  250.     txtlin(3, "0G()   = Start/End/Top/Bottom");
  251.     txtlin(4, "<hjkl> = Scrolling, <HJKL> moves buffer view");
  252.     txtlin(5, "{Enter}= Edit string or hex");
  253.     txtlin(6, "{Tab}  = Toggle string/hex edit mode");
  254.     txtlin(7, "wq^X   = Finished editing");
  255.     txtlin(8, "m'     = Set/goto mark");
  256.     txtlin(9, "twc    = Toggle hex/dec,word,character modes");
  257.     txtlin(10, "a+-    = Toggle address mode,change columns");
  258.     txtlin(11, "/?nN   = Search forward/backward/next");
  259.     txtlin(12, "g      = Goto (jump) to hex address");
  260.     txtlin(13, "HL     = Buffer window left/right");
  261.     txtlin(14, "AC     = Append/Create file from cursor to mark");
  262.     txtlin(15, "udfb   = Half Up/Down, Full Forward/Back page");
  263.     txtlin(16, "t<>    = Type (hex,dec,flt,dbl) Alignment up/dn");
  264.  
  265.     wmove(help_window, HELP_SIZE - 2, 16);
  266.     waddstr(help_window, "Press any key...");
  267.  
  268.     wrefresh(help_window);
  269.     wgetch(help_window);
  270.     delwin(help_window);
  271. }
  272.  
  273. #define SHELP_SIZ 17
  274. help_me_str()
  275. {
  276.     WINDOW *help_window;
  277.     help_window = newwin(SHELP_SIZ, 44, (LINES-SHELP_SIZ) / 2, COLS/2 - 22);
  278.     (void) box(help_window, '|', '-');
  279.  
  280.     wmove(help_window, 1, 14);
  281.     waddstr(help_window, "FV String Editor:");
  282.  
  283.     txtlin(3, "aiAI = add/insert, add/insert at start/end");
  284.     txtlin(4, "cd   = change/delete w=word t=to (char)");
  285.     txtlin(5, "hkjl = cursor left/left/right/right");
  286.     txtlin(6, "rs   = substitute single character");
  287.     txtlin(7, "0^$  = start/start/end of line");
  288.     txtlin(8, "uU   = undo last/all change(s)");
  289.     txtlin(9, "^H   = delete left of cursor");
  290.     txtlin(10, "^U   = erase line");
  291.     txtlin(11, "^V   = next character is raw");
  292.     txtlin(12, "ESC  = escape (command mode) from insert");
  293.  
  294.     wmove(help_window, SHELP_SIZ - 2, 14);
  295.     waddstr(help_window, "Press any key...");
  296.  
  297.     wrefresh(help_window);
  298.     wgetch(help_window);
  299.     delwin(help_window);
  300. }
  301.  
  302. clear_buffer()
  303. {
  304.     int index;
  305.  
  306.     for (index = 0; index < buf_size / 4; index++)
  307.         ibuffer[index] = 0;
  308. }
  309.