home *** CD-ROM | disk | FTP | other *** search
/ The CDPD Public Domain Collection for CDTV 3 / CDPDIII.bin / pd / utilities / dirutils / visualshell / src / display1.c < prev    next >
C/C++ Source or Header  |  1992-10-28  |  25KB  |  762 lines

  1.             /*********************************
  2.          *                               *
  3.          *   Visual Shell v1.17  10/92   *
  4.          *                               *
  5.          *     by Torsten Jürgeleit      *
  6.          *                               *
  7.          *        display part 1         *
  8.          *                               *
  9.          *********************************/
  10.  
  11.     /* Includes */
  12.  
  13. #include "includes.h"
  14. #include "imports.h"
  15. #include "protos.h"
  16.  
  17.     /* Prepare console window for VSh */
  18.  
  19.    VOID
  20. prepare_con_window(VOID)
  21. {
  22.    struct FileRequest  *freq1 = &file_req[0], *freq2 = &file_req[1];
  23.  
  24.    clear_input_line();
  25.    FPrintf(con_handle, "\x9bx\x9by\x9bu\x9bt\x0c");   /* control back to console device */
  26.    max_line_len     = (vsh_width - BORDER_LEFT - BORDER_RIGHT) / 8;   /* calc VSh dimensions */
  27.    max_dir_name_len = ((vsh_width / 2) - 4 * 2) / 8;
  28.    cli_vpos         = BORDER_TOP_SHOW;
  29.    fkey_dist        = (vsh_width - BORDER_LEFT - BORDER_RIGHT - 2) /
  30.                            MAX_FKEYS - MAX_FKEY_LEN * 8;
  31.    fkey_left        = (vsh_width - MAX_FKEYS * MAX_FKEY_LEN * 8 - (MAX_FKEYS
  32.                               - 1) * fkey_dist) / 2;
  33.  
  34.    move_and_resize_window(con_window, vsh_left, vsh_top, vsh_width,
  35.                                 vsh_height);
  36.    Delay(20L);
  37.    WindowLimits(con_window, (LONG)vsh_width, (LONG)vsh_height, (LONG)
  38.                            vsh_width, (LONG)vsh_height);
  39.    con_window->BorderLeft   = BORDER_LEFT;   /* change size of inner window */
  40.    con_window->BorderRight  = BORDER_RIGHT;
  41.    con_window->BorderBottom = BORDER_BOTTOM;
  42.    con_window->GZZWidth     = vsh_width - BORDER_LEFT - BORDER_RIGHT;
  43.  
  44.    SPrintf(&status_fmt[0],   /* init strings and structures which depends on VSh dimension */
  45.          "Chip %%7ld / %%-7ld Fast %%7ld / %%-7ld %%9s %%9s %%-%ds",
  46.                              max_line_len - 69);
  47.    SPrintf(&standard_fmt[0], "%%-%ds", max_line_len);
  48.  
  49.    freq1->fr_Display.d_LeftEdge          = (vsh_width / 2 -
  50.                            MAX_FREQ_LINE_WIDTH) / 2;
  51.    freq2->fr_Display.d_LeftEdge          = vsh_width -
  52.              freq1->fr_Display.d_LeftEdge - MAX_FREQ_LINE_WIDTH;
  53.    freq1->fr_Display.d_TopEdge           = BORDER_TOP + STATUS_HEIGHT +
  54.                             DIR_NAME_HEIGHT + 1;
  55.    freq2->fr_Display.d_TopEdge           = BORDER_TOP + STATUS_HEIGHT +
  56.                             DIR_NAME_HEIGHT + 1;
  57.    freq1->fr_Display.d_VisibleLines      = (cli_vpos - INFO_LINE_HEIGHT -
  58.                        freq1->fr_Display.d_TopEdge) / 8;
  59.    freq2->fr_Display.d_VisibleLines      = (cli_vpos - INFO_LINE_HEIGHT -
  60.                        freq2->fr_Display.d_TopEdge) / 8;
  61.    freq1->fr_Display.d_TopEdge          += ((cli_vpos - INFO_LINE_HEIGHT -
  62.                       freq1->fr_Display.d_TopEdge) % 8) / 2;
  63.    freq2->fr_Display.d_TopEdge          += ((cli_vpos - INFO_LINE_HEIGHT -
  64.                       freq2->fr_Display.d_TopEdge) % 8) / 2;
  65.    view_req.vr_Display.d_TopEdge         = BORDER_TOP_HIDDEN;
  66.    view_req.vr_Display.d_Width           = max_line_len * 8;
  67.    view_req.vr_Display.d_VisibleLines    = (cli_vpos -
  68.                      view_req.vr_Display.d_TopEdge - 2) / 8;
  69.    view_req.vr_Display.d_TopEdge        += ((cli_vpos -
  70.                 view_req.vr_Display.d_TopEdge - 2) % 8) / 2;
  71.    history_req.hr_Display.d_TopEdge      = BORDER_TOP_HIDDEN;
  72.    history_req.hr_Display.d_Width        = max_line_len * 8;
  73.    history_req.hr_Display.d_VisibleLines = (cli_vpos -
  74.                   history_req.hr_Display.d_TopEdge - 2) / 8;
  75.    history_req.hr_Display.d_TopEdge     += ((cli_vpos -
  76.                  history_req.hr_Display.d_TopEdge - 2) % 8) / 2;
  77.    tree_req.tr_Display.d_TopEdge         = BORDER_TOP_HIDDEN;
  78.    tree_req.tr_Display.d_Width           = max_line_len * 8;
  79.    tree_req.tr_Display.d_VisibleLines    = (cli_vpos -
  80.                      tree_req.tr_Display.d_TopEdge - 2) / 8;
  81.    tree_req.tr_Display.d_TopEdge        += ((cli_vpos -
  82.                 tree_req.tr_Display.d_TopEdge - 2) % 8) / 2;
  83.    tree_req.tr_Columns                   = (max_line_len - 1) /
  84.                            (MAX_TREE_NODE_NAME_LEN + 3);
  85.    tree_req.tr_Rows                      = tree_req.tr_Display.d_VisibleLines;
  86.  
  87.    move_freq_cursor(freq1, get_file_node_under_cursor(freq1),
  88.                                MOVE_MODE_NO_OUTPUT);
  89.    move_freq_cursor(freq2, get_file_node_under_cursor(freq2),
  90.                                MOVE_MODE_NO_OUTPUT);
  91. }
  92.     /* Restore old console window */
  93.  
  94.    VOID
  95. restore_con_window(VOID)
  96. {
  97.    con_window->BorderLeft   = old_bleft;   /* restore old window dimensions */
  98.    con_window->BorderRight  = old_bright;
  99.    con_window->BorderTop    = old_btop;
  100.    con_window->BorderBottom = old_bbottom;
  101.    con_window->Flags        = old_flags;
  102.    RefreshWindowFrame(con_window);
  103.    WindowLimits(con_window, (LONG)old_min_width, (LONG)old_min_height,
  104.                  (LONG)old_max_width, (LONG)old_max_height);
  105.    move_and_resize_window(con_window, old_left, old_top, old_width,
  106.                                 old_height);
  107.    clear_input_line();
  108.    FPrintf(con_handle, "\x9bx\x9by\x9bu\x9bt\x0c");   /* control back to console device */
  109. }
  110.     /* Move and resize window to selected dimension */
  111.  
  112.    VOID
  113. move_and_resize_window(struct Window *win, USHORT new_left, USHORT new_top,
  114.                     USHORT new_width, USHORT new_height)
  115. {
  116.    SHORT move_x = (SHORT)new_left - win->LeftEdge,
  117.      move_y = (SHORT)new_top - win->TopEdge,
  118.      size_x = (SHORT)new_width - win->Width,
  119.      size_y = (SHORT)new_height - win->Height;
  120.  
  121.    if (size_x < 0) {   /* zoom width in */
  122.       if (size_x) {
  123.      SizeWindow(con_window, (LONG)size_x, 0L);
  124.       }
  125.       if (move_x) {
  126.      MoveWindow(con_window, (LONG)move_x, 0L);
  127.       }
  128.    } else {   /* zoom width out */
  129.       if (move_x) {
  130.      MoveWindow(con_window, (LONG)move_x, 0L);
  131.       }
  132.       if (size_x) {
  133.      SizeWindow(con_window, (LONG)size_x, 0L);
  134.       }
  135.    }
  136.    if (size_y < 0) {   /* zoom height in */
  137.       if (size_y) {
  138.      SizeWindow(con_window, 0L, (LONG)size_y);
  139.       }
  140.       if (move_y) {
  141.      MoveWindow(con_window, 0L, (LONG)move_y);
  142.       }
  143.    } else {   /* zoom height out */
  144.       if (move_y) {
  145.      MoveWindow(con_window, 0L, (LONG)move_y);
  146.       }
  147.       if (size_y) {
  148.      SizeWindow(con_window, 0L, (LONG)size_y);
  149.       }
  150.    }
  151. }
  152.     /* Init structures and start VSh */
  153.  
  154.    VOID
  155. start_vsh(VOID)
  156. {
  157.    struct Gadget       *gad = &gadget;
  158.    struct StringInfo   *si = &gadget_info;
  159.    struct IntuiText    *it = &gadget_text;
  160.    struct DateTime     *dat = &date_time;
  161.    struct FileRequest  *freq1 = &file_req[0], *freq2 = &file_req[1];
  162.    SHORT error;
  163.  
  164.    /* Init some flags */
  165.    event_mode   = EVENT_MODE_IGNORE;
  166.    action       = VSH_ACTION_NONE;
  167.    auto_repeat  = 0;
  168.    active_freq  = 0;
  169.    scroll_flag  = 0;
  170.    num_lock     = 1;
  171.    qualifier    = QUALIFIER_NONE;
  172.    enable_abort = 0;
  173.    delayed_cd   = 0;
  174.  
  175.    status       = VSH_STATUS_NORMAL;
  176.    status_delay = DEFAULT_STATUS_DELAY;
  177.    error_delay  = DEFAULT_ERROR_DELAY;
  178.  
  179.    /* Init requesters */
  180.    freq1->fr_Display.d_Mode          = DISPLAY_MODE_FILE;
  181.    freq2->fr_Display.d_Mode          = DISPLAY_MODE_FILE;
  182.    freq1->fr_Display.d_Width         = MAX_FREQ_LINE_WIDTH;
  183.    freq2->fr_Display.d_Width         = MAX_FREQ_LINE_WIDTH;
  184.    freq1->fr_CursorLine              = -1;
  185.    freq2->fr_CursorLine              = -1;
  186.    freq1->fr_AnchorPath.ap_BreakBits = 0;   /* no abort */
  187.    freq2->fr_AnchorPath.ap_BreakBits = 0;
  188.    freq1->fr_AnchorPath.ap_StrLen    = 0;   /* basename only */
  189.    freq2->fr_AnchorPath.ap_StrLen    = 0;
  190.    strcpy(&freq1->fr_FilePattern[0], DEFAULT_FILE_PATTERN);
  191.    strcpy(&freq2->fr_FilePattern[0], DEFAULT_FILE_PATTERN);
  192.    strcpy(&freq1->fr_MarkPattern[0], DEFAULT_MARK_PATTERN);
  193.    strcpy(&freq2->fr_MarkPattern[0], DEFAULT_MARK_PATTERN);
  194.    strcpy(&freq1->fr_UnmarkPattern[0], DEFAULT_UNMARK_PATTERN);
  195.    strcpy(&freq2->fr_UnmarkPattern[0], DEFAULT_UNMARK_PATTERN);
  196.    view_req.vr_Display.d_Mode        = DISPLAY_MODE_VIEW;
  197.    view_req.vr_Display.d_LeftEdge    = BORDER_LEFT;
  198.    history_req.hr_Display.d_Mode     = DISPLAY_MODE_HISTORY;
  199.    history_req.hr_Display.d_LeftEdge = BORDER_LEFT;
  200.    tree_req.tr_Display.d_Mode        = DISPLAY_MODE_TREE;
  201.    tree_req.tr_Display.d_LeftEdge    = BORDER_LEFT;
  202.  
  203.    /* Init gadget struct */
  204.    gad->NextGadget    = NULL;
  205.    gad->Flags         = GADGHCOMP;
  206.    gad->GadgetType    = STRGADGET;
  207.    gad->GadgetRender  = NULL;
  208.    gad->SelectRender  = NULL;
  209.    gad->GadgetText    = it;
  210.    gad->MutualExclude = 0L;
  211.    gad->SpecialInfo   = (APTR)si;
  212.    gad->GadgetID      = 0;
  213.    gad->UserData      = NULL;
  214.  
  215.    /* Init gadget text struct */
  216.    it->FrontPen  = COLOR3;
  217.    it->BackPen   = COLOR0;
  218.    it->DrawMode  = JAM2;
  219.    it->TopEdge   = 0;
  220.    it->ITextFont = &topaz80;
  221.    it->NextText  = NULL;
  222.  
  223.    /* Init gadget string info struct */
  224.    si->Buffer     = (UBYTE *)&gadget_buffer[0];
  225.    si->UndoBuffer = NULL;
  226.    si->UndoPos    = 0;
  227.    si->NumChars   = MAX_GADGET_BUFFER_LEN;
  228.    si->AltKeyMap  = NULL;
  229.  
  230.    /* Init DateTime struct */
  231.    dat->dat_Format  = 0;
  232.    dat->dat_Flags   = FORMAT_DOS;
  233.    dat->dat_StrDay  = &day_buffer[0];
  234.    dat->dat_StrDate = &date_buffer[0];
  235.    dat->dat_StrTime = &time_buffer[0];
  236.  
  237.    /* Build display and start action */
  238.    draw_display(FULL_DISPLAY);
  239.    if (!dir_arg[0] && !dir_arg[1] && show_flag) {
  240.       event_mode = EVENT_MODE_NORMAL;
  241.       action_about();
  242.       event_mode = EVENT_MODE_IGNORE;
  243.    }
  244.    if ((error = read_new_dir(freq1, dir_arg[0], READ_DIR_MODE_NO_OUTPUT)) ==
  245.                             VSH_STATUS_NORMAL) {
  246.       if (!Strcmp(dir_arg[0], dir_arg[1])) {
  247.      error = duplicate_file_list(freq1, freq2);
  248.       } else {
  249.      error = read_new_dir(freq2, dir_arg[1], READ_DIR_MODE_NO_OUTPUT);
  250.       }
  251.    }
  252.    status = error;
  253.  
  254.    draw_requesters(DRAW_MODE_NORMAL);
  255.    perform_action();
  256.    clear_display(FULL_DISPLAY);
  257.  
  258.    free_dir(freq1);
  259.    free_dir(freq2);
  260. }
  261.     /* Draw VSh display */
  262.  
  263.    VOID
  264. draw_display(USHORT mode)
  265. {
  266.    clear_input_line();
  267.    FPrintf(con_handle, cursor_off);   /* home & cursor off */
  268.    SetAPen(con_rport, (LONG)COLOR0);   /* clear console window */
  269.    if (mode == FULL_DISPLAY) {
  270.       if (! show_flag) {   /* hidden display -> config */
  271.      con_window->GZZHeight = vsh_height - BORDER_TOP_HIDDEN -
  272.                            con_window->BorderBottom;
  273.      FPrintf(con_handle, "\x9b%dx\x9b%dy\x9b%du\x9b%dt\x9bH",
  274.         BORDER_LEFT, BORDER_TOP_HIDDEN, max_line_len, HIDDEN_CLI_LINES);
  275.       } else {
  276.      con_window->GZZHeight = SHOW_CLI_HEIGHT;
  277.          FPrintf(con_handle, "\x9b%dx\x9b%dy\x9b%du\x9b%dt\x9bH",
  278.                BORDER_LEFT, cli_vpos, max_line_len, SHOW_CLI_LINES);
  279.       }
  280.       RectFill(con_rport, (LONG)(BORDER_LEFT - 2), (LONG)(BORDER_TOP - 1),
  281.           (LONG)(vsh_width - BORDER_RIGHT + 1), (LONG)(vsh_height - 2));
  282.       if (! show_flag) {   /* hidden display -> config */
  283.      draw_line(COLOR1, (USHORT)2, (USHORT)(BORDER_TOP_HIDDEN - 2),
  284.           (USHORT)(vsh_width - 3), (USHORT)(BORDER_TOP_HIDDEN - 2));
  285.       }
  286.       draw_line(COLOR1, (USHORT)2, (USHORT)(vsh_height - FKEY_HEIGHT),
  287.            (USHORT)(vsh_width - 3), (USHORT)(vsh_height - FKEY_HEIGHT));
  288.    } else {
  289.       if (! show_flag) {   /* hidden display -> help */
  290.      con_window->GZZHeight = vsh_height - BORDER_TOP_HIDDEN -
  291.                            con_window->BorderBottom;
  292.      FPrintf(con_handle, "\x9b%dx\x9b%dy\x9b%du\x9b%dt\x9bH",
  293.         BORDER_LEFT, BORDER_TOP_HIDDEN, max_line_len, HIDDEN_CLI_LINES);
  294.      RectFill(con_rport, (LONG)(BORDER_LEFT - 2), (LONG)BORDER_TOP,
  295.              (LONG)(vsh_width - BORDER_RIGHT + 1), (LONG)(vsh_height
  296.                             - FKEY_HEIGHT - 1));
  297.      draw_line(COLOR1, (USHORT)2, (USHORT)(BORDER_TOP_HIDDEN - 2),
  298.           (USHORT)(vsh_width - 3), (USHORT)(BORDER_TOP_HIDDEN - 2));
  299.       } else {
  300.      con_window->GZZHeight = SHOW_CLI_HEIGHT;
  301.      FPrintf(con_handle, "\x9b%dx\x9b%dy\x9b%du\x9b%dt\x9bH",
  302.                BORDER_LEFT, cli_vpos, max_line_len, SHOW_CLI_LINES);
  303.      RectFill(con_rport, (LONG)(BORDER_LEFT - 2), (LONG)
  304.             BORDER_TOP_HIDDEN, (LONG)(vsh_width - BORDER_RIGHT + 1),
  305.                       (LONG)(vsh_height - FKEY_HEIGHT - 1));
  306.       }
  307.    }
  308.    draw_requesters(DRAW_MODE_NORMAL);
  309.    FPrintf(con_handle, cursor_on);   /* home & cursor on */
  310. }
  311.     /* Refresh VSh display */
  312.  
  313.    VOID
  314. refresh_display(VOID)
  315. {
  316.    if (! show_flag) {   /* hidden display ? */
  317.       draw_line(COLOR1, (USHORT)2, (USHORT)(BORDER_TOP_HIDDEN - 2), (USHORT)
  318.               (vsh_width - 3), (USHORT)(BORDER_TOP_HIDDEN - 2));
  319.    }
  320.    draw_line(COLOR1, (USHORT)2, (USHORT)(vsh_height - FKEY_HEIGHT), (USHORT)
  321.                (vsh_width - 3), (USHORT)(vsh_height - FKEY_HEIGHT));
  322.    draw_requesters(DRAW_MODE_NORMAL);
  323. }
  324.     /* Clear VSh display */
  325.  
  326.    VOID
  327. clear_display(USHORT mode)
  328. {
  329.    clear_input_line();
  330.    FPrintf(con_handle, cursor_off);   /* home & cursor off */
  331.    SetAPen(con_rport, (LONG)COLOR0);   /* clear console window */
  332.    if (mode == FULL_DISPLAY) {
  333.       RectFill(con_rport, (LONG)(BORDER_LEFT - 2), (LONG)BORDER_TOP, (LONG)
  334.             (vsh_width - BORDER_RIGHT + 1), (LONG)(vsh_height - 2));
  335.    } else {
  336.       if (! show_flag) {   /* hidden display -> help */
  337.      con_window->GZZHeight = SHOW_CLI_HEIGHT;
  338.      FPrintf(con_handle, "\x9b%dx\x9b%dy\x9b%du\x9b%dt\x9bH",
  339.                BORDER_LEFT, cli_vpos, max_line_len, SHOW_CLI_LINES);
  340.      RectFill(con_rport, (LONG)(BORDER_LEFT - 2), (LONG)BORDER_TOP,
  341.            (LONG)(vsh_width - BORDER_RIGHT + 1), (LONG)(vsh_height -
  342.                               FKEY_HEIGHT - 1));
  343.      draw_line(COLOR1, (USHORT)2, (USHORT)(cli_vpos - 2), (USHORT)
  344.                    (vsh_width - 3), (USHORT)(cli_vpos - 2));
  345.       } else {
  346.      con_window->GZZHeight = vsh_height - BORDER_TOP_HIDDEN -
  347.                            con_window->BorderBottom;
  348.      FPrintf(con_handle, "\x9b%dx\x9b%dy\x9b%du\x9b%dt\x9bH",
  349.         BORDER_LEFT, BORDER_TOP_HIDDEN, max_line_len, HIDDEN_CLI_LINES);
  350.      RectFill(con_rport, (LONG)(BORDER_LEFT - 2), (LONG)
  351.           (BORDER_TOP_HIDDEN - 1), (LONG)(vsh_width - BORDER_RIGHT +
  352.                   1), (LONG)(vsh_height    - FKEY_HEIGHT - 1));
  353.      draw_line(COLOR1, (USHORT)2, (USHORT)(BORDER_TOP_HIDDEN - 2),
  354.           (USHORT)(vsh_width - 3), (USHORT)(BORDER_TOP_HIDDEN - 2));
  355.       }
  356.    }
  357.    FPrintf(con_handle, cursor_on);   /* home & cursor on */
  358. }
  359.     /* Draw both file requesters */
  360.  
  361.    VOID
  362. draw_requesters(USHORT mode)
  363. {
  364.    struct FileRequest  *freq1 = &file_req[0], *freq2 = &file_req[1];
  365.  
  366.    if (mode == DRAW_MODE_CLEAR) {
  367.       SetAPen(con_rport, (LONG)COLOR0);
  368.       RectFill(con_rport, (LONG)(BORDER_LEFT - 2), (LONG)BORDER_TOP, (LONG)
  369.               (vsh_width - BORDER_RIGHT + 1), (LONG)(cli_vpos - 3));
  370.    }
  371.    if (show_flag) {   /* hidden display ? */
  372.       mark_active_freq();
  373.       print_dir_name(freq1, (BYTE *)NULL);
  374.       print_dir_name(freq2, (BYTE *)NULL);
  375.       draw_line(COLOR1, (USHORT)(vsh_width / 2 - 1), (USHORT)
  376.           (BORDER_TOP_HIDDEN - 2), (USHORT)(vsh_width / 2 - 1), (USHORT)
  377.                          (cli_vpos - INFO_LINE_HEIGHT));
  378.       draw_line(COLOR1, (USHORT)(vsh_width / 2), (USHORT)(BORDER_TOP_HIDDEN
  379.               - 2), (USHORT)(vsh_width / 2), (USHORT)(cli_vpos -
  380.                              INFO_LINE_HEIGHT));
  381.       draw_line(COLOR1, (USHORT)2, (USHORT)(cli_vpos - INFO_LINE_HEIGHT),
  382.         (USHORT)(vsh_width - 3), (USHORT)(cli_vpos - INFO_LINE_HEIGHT));
  383.       draw_line(COLOR1, (USHORT)2, (USHORT)(cli_vpos - 2), (USHORT)
  384.                    (vsh_width - 3), (USHORT)(cli_vpos - 2));
  385.    
  386.       print_freq_lines(freq1, freq1->fr_Display.d_FirstVisibleNode, (USHORT)
  387.                        0, freq1->fr_Display.d_VisibleLines);
  388.       print_freq_lines(freq2, freq2->fr_Display.d_FirstVisibleNode, (USHORT)
  389.                        0, freq2->fr_Display.d_VisibleLines);
  390.       hcomp_freq_cursor(&file_req[active_freq]);
  391.       print_info_line(INFO_LINE_MODE_NORMAL);
  392.    }
  393.    change_fkey_text();
  394.    print_status(status);
  395. }
  396.     /* Draw line on console window */
  397.  
  398.    VOID
  399. draw_line(USHORT color, USHORT x1, USHORT y1, USHORT x2, USHORT y2)
  400. {
  401.    SetAPen(con_rport, (LONG)color);
  402.    Move(con_rport, (LONG)x1, (LONG)y1);
  403.    Draw(con_rport, (LONG)x2, (LONG)y2);
  404. }
  405.     /* Mark directory name of active file requester */
  406.  
  407.    VOID
  408. mark_active_freq(VOID)
  409. {
  410.    USHORT old_x1, old_x2, new_x1, new_x2;
  411.  
  412.    if (show_flag) {   /* hidden display ? */
  413.       if (! active_freq) {
  414.      old_x1 = vsh_width / 2 + 1;
  415.      old_x2 = vsh_width - 3;
  416.      new_x1 = 2;
  417.      new_x2 = vsh_width / 2 - 1;
  418.       } else {
  419.      old_x1 = 2;
  420.      old_x2 = vsh_width / 2 - 1;
  421.      new_x1 = vsh_width / 2 + 1;
  422.      new_x2 = vsh_width - 3;
  423.       }
  424.       draw_line(COLOR1, old_x1, (USHORT)(BORDER_TOP_HIDDEN - 2), old_x2,
  425.                        (USHORT)(BORDER_TOP_HIDDEN - 2));
  426.       draw_line(COLOR1, old_x1, (USHORT)(BORDER_TOP_HIDDEN + 9), old_x2,
  427.                        (USHORT)(BORDER_TOP_HIDDEN + 9));
  428.       draw_line(COLOR3, new_x1, (USHORT)(BORDER_TOP_HIDDEN - 2), new_x2,
  429.                        (USHORT)(BORDER_TOP_HIDDEN - 2));
  430.       draw_line(COLOR3, new_x1, (USHORT)(BORDER_TOP_HIDDEN + 9), new_x2,
  431.                        (USHORT)(BORDER_TOP_HIDDEN + 9));
  432.    }
  433. }
  434.     /* Print status line for file requester */
  435.  
  436.    VOID
  437. print_status(SHORT error)
  438. {
  439.    struct DateTime  *dat = &date_time;
  440.    BYTE *line = &line2_buffer[0];
  441.  
  442.    if (error == VSH_STATUS_NORMAL) {
  443.  
  444.       /* Print status line with available memory, actual date and time */
  445.       if (num_lock) {
  446.      display_text(COLOR2, COLOR3, (USHORT)(BORDER_LEFT + (max_line_len -
  447.                         3) * 8), BORDER_TOP, "Num");
  448.       } else {
  449.      display_text(COLOR1, COLOR0, (USHORT)(BORDER_LEFT + (max_line_len -
  450.                         3) * 8), BORDER_TOP, "   ");
  451.       }
  452.       DateStamp(&dat->dat_Stamp);
  453.       StamptoStr(dat);
  454.       SPrintf(line, &status_fmt[0], AvailMem(MEMF_CHIP),
  455.             AvailMem(MEMF_CHIP | MEMF_LARGEST), AvailMem(MEMF_FAST),
  456.             AvailMem(MEMF_FAST | MEMF_LARGEST), &dat->dat_StrDay[0],
  457.                 &dat->dat_StrDate[0], &dat->dat_StrTime[0]);
  458.       status_delay = DEFAULT_STATUS_DELAY;
  459.    } else {
  460.       if (error > 0) {
  461.  
  462.      /* Print status */
  463.      SPrintf(line, &standard_fmt[0], status_text[error - 1]);
  464.       } else {
  465.  
  466.      /* Print error */
  467.      SPrintf(line, &standard_fmt[0], error_text[(-error) - 1]);
  468.      error_delay = DEFAULT_ERROR_DELAY;
  469.       }
  470.    }
  471.    display_text(COLOR3, COLOR0, BORDER_LEFT, BORDER_TOP, line);
  472.    status = error;   /* save last error code */
  473. }
  474.     /* Print dos status line */
  475.  
  476.    VOID
  477. print_dos_status(USHORT mode, BYTE *source, BYTE *dest)
  478. {
  479.    BYTE   *ptr, *buffer = &line2_buffer[0];
  480.    USHORT text_len, path_len, max_len;
  481.  
  482.    /* Get leading text */
  483.    switch(mode) {
  484.       case DOS_MODE_COPY :
  485.      ptr = "Copying ";
  486.      break;
  487.       case DOS_MODE_RENAME :
  488.      ptr = "Renaming ";
  489.      break;
  490.       case DOS_MODE_DELETE :
  491.      ptr = "Deleting ";
  492.      break;
  493.       case DOS_MODE_FIND :
  494.      ptr = "Found ";
  495.      break;
  496.       case DOS_MODE_TREE :
  497.      ptr = "Scanning ";
  498.      break;
  499.       default :
  500.      ptr = "";
  501.      break;
  502.    }
  503.  
  504.    /* Calc maximal length for path names */
  505.    text_len = strlen(ptr);
  506.    max_len  = max_line_len - text_len;
  507.    if (dest) {
  508.       max_len -= 4;
  509.       path_len = max_len / 2;
  510.    } else {
  511.       path_len = max_len;
  512.    }
  513.  
  514.    /* Build and print status line */
  515.    strcpy(buffer, ptr);
  516.    ptr = buffer + text_len;
  517.  
  518.    if (!dest) {
  519.  
  520.       /* Append source path */
  521.       build_limited_path_name(ptr, NULL, source, path_len,
  522.                             LIMITED_PATH_MODE_FILL);
  523.    } else {
  524.  
  525.       /* Append source path */
  526.       build_limited_path_name(ptr, NULL, source, path_len,
  527.                           LIMITED_PATH_MODE_NORMAL);
  528.       /* Search end of source name */
  529.       path_len = strlen(ptr);
  530.       ptr     += path_len;
  531.  
  532.       /* Append destination path */
  533.       strcpy(ptr, " to ");
  534.       ptr += 4;
  535.       build_limited_path_name(ptr, NULL, dest, max_len - path_len,
  536.                             LIMITED_PATH_MODE_FILL);
  537.    }
  538.    display_text(COLOR3, COLOR0, BORDER_LEFT, BORDER_TOP, buffer);
  539. }
  540.     /* Print status line for view requester */
  541.  
  542.    VOID
  543. print_vreq_status(struct ViewRequest  *vreq)
  544. {
  545.    struct Display  *vd = &vreq->vr_Display;
  546.    ULONG  num_entries = vd->d_NumEntries,
  547.       pos = ((struct LineNode *)vd->d_FirstVisibleNode)->ln_Pos;
  548.    BYTE   *line = &line2_buffer[0];
  549.    USHORT i, vlines = vd->d_VisibleLines;
  550.  
  551.    SPrintf(line, "Viewing \"%s\"   %ld bytes   line %ld of %ld   %ld%%",
  552.            vreq->vr_FileName, vreq->vr_BufferSize, pos, num_entries,
  553.       (num_entries > vlines ? ((pos + vlines - 1) * 100) / num_entries :
  554.                                      100L));
  555.    for (i = strlen(line); i < max_line_len; i++) {   /* fill string spaces */
  556.       *(line +i) = ' ';
  557.    }
  558.    *(line + max_line_len) = '\0';
  559.    display_text(COLOR3, COLOR0, BORDER_LEFT, BORDER_TOP, line);
  560. }
  561.     /* Print status line for tree requester */
  562.  
  563.    VOID
  564. print_treq_status(struct TreeRequest  *treq)
  565. {
  566.    BYTE *path;
  567.  
  568.    path = build_tnode_path_name(treq, treq->tr_CursorNode);
  569.    print_dos_status(DOS_MODE_NORMAL, path, NULL);
  570. }
  571.     /* Print directory name of specified filerequester */
  572.  
  573.    VOID
  574. print_dir_name(struct FileRequest  *freq, BYTE *dir)
  575. {
  576.    BYTE *path, *buffer = &line2_buffer[0];
  577.  
  578.    if (show_flag) {   /* hidden display ? */
  579.       if (!dir) {
  580.      path = &path1_buffer[0];
  581.      strcpy(path, &freq->fr_DirName[0]);
  582.      if (*path != '\0') {
  583.         TackOn(path, &freq->fr_FilePattern[0]);   /* attach pattern to dir name */
  584.      }
  585.       } else {
  586.      path = dir;
  587.       }
  588.       build_limited_path_name(buffer, NULL, path, max_dir_name_len,
  589.                               LIMITED_PATH_MODE_FILL);
  590.       if (freq->fr_Display.d_LeftEdge >= (vsh_width / 2)) {
  591.      display_text(COLOR1, COLOR2, (USHORT)(vsh_width / 2 + 4),
  592.                            BORDER_TOP_HIDDEN, buffer);
  593.       } else {
  594.      display_text(COLOR1, COLOR2, BORDER_LEFT, BORDER_TOP_HIDDEN, buffer);
  595.       }
  596.    }
  597. }
  598.     /* Print directory name of specified filerequester */
  599.  
  600.    VOID
  601. print_info_line(USHORT mode)
  602. {
  603.    struct FileRequest  *freq1 = &file_req[active_freq],
  604.                *freq2 = (freq1 == &file_req[0] ? &file_req[1] :
  605.                                   &file_req[0]);
  606.    struct FileNode     *fnode;
  607.    BYTE   *line = &line2_buffer[0];
  608.    USHORT i;
  609.  
  610.    if (show_flag) {
  611.       if (mode != INFO_LINE_MODE_EMPTY && (freq1->fr_Mode ==
  612.                FREQ_MODE_NORMAL || freq1->fr_Mode == FREQ_MODE_FIND)
  613.                         && freq1->fr_CursorLine != -1) {
  614.      fnode = get_file_node_under_cursor(freq1);
  615.      if (freq1->fr_Mode == FREQ_MODE_FIND && fnode->fn_Path) {
  616.         print_dir_name(freq1, fnode->fn_Path);
  617.      }
  618.      if (!freq1->fr_MarkedEntries) {
  619.         if (mode == INFO_LINE_MODE_MARKED) {
  620.            *line = '\0';   /* empty info line */
  621.         } else {
  622.            CopyMem((BYTE *)&fnode->fn_Date, (BYTE *)
  623.               &date_time.dat_Stamp, (LONG)sizeof(struct DateStamp));
  624.            StamptoStr(&date_time);
  625.            SPrintf(line, "%s %s %9s %9s %-s",
  626.                       &fnode->fn_Text[0], protection(fnode),
  627.             &date_time.dat_StrDay[0], &date_time.dat_StrDate[0],
  628.                          &date_time.dat_StrTime[0]);
  629.         }
  630.      } else {
  631.         SPrintf(line, "%ld entries with %ld bytes selected",
  632.                  freq1->fr_MarkedEntries, freq1->fr_MarkedSize);
  633.      }
  634.       } else {
  635.      *line = '\0';   /* empty info line */
  636.       }
  637.       for (i = strlen(line); i < max_line_len; i++) {   /* fill rest of line with spaces */
  638.      *(line + i) = ' ';
  639.       }
  640.       *(line + i) = '\0';
  641.       display_text(COLOR1, COLOR0, BORDER_LEFT, INFO_LINE_VPOS, line);
  642.       if (mode == INFO_LINE_MODE_NORMAL && freq2->fr_Mode ==
  643.                              FREQ_MODE_QUICK_VIEW) {
  644.      print_quick_view(freq2);
  645.       }
  646.    }
  647. }
  648.     /* Print text for function keys */
  649.  
  650.    VOID
  651. print_fkey_text(USHORT mode)
  652. {
  653.    BYTE   *line = &line2_buffer[0], **fkey;
  654.    USHORT i;
  655.  
  656.    if (mode == FKEY_MODE_NORMAL) {
  657.       switch (qualifier) {   /* check qualifier and change fkey text if required */
  658.      case QUALIFIER_NONE :
  659.         break;
  660.      case QUALIFIER_SHIFT :
  661.         switch (file_req[active_freq].fr_Mode) {
  662.            case FREQ_MODE_NORMAL :
  663.           mode = FKEY_MODE_SHIFT_NORMAL;
  664.           break;
  665.            case FREQ_MODE_DEVS_ASN :
  666.           mode = FKEY_MODE_SHIFT_DEVS_ASN;
  667.           break;
  668.            case FREQ_MODE_INFO :
  669.           mode = FKEY_MODE_SHIFT_INFO;
  670.           break;
  671.            case FREQ_MODE_QUICK_VIEW :
  672.           mode = FKEY_MODE_SHIFT_QUICK_VIEW;
  673.           break;
  674.            case FREQ_MODE_FIND :
  675.           mode = FKEY_MODE_SHIFT_FIND;
  676.           break;
  677.         }
  678.         break;
  679.      case QUALIFIER_ALT :
  680.      case QUALIFIER_SHIFT_ALT :
  681.         mode = FKEY_MODE_USER_FUNCS;
  682.         break;
  683.      default :
  684.         mode = FKEY_MODE_NONE;
  685.         break;
  686.       }
  687.    }
  688.    if (mode == FKEY_MODE_USER_FUNCS) {
  689.       fkey = &user_fkey_text[0];
  690.    } else {
  691.       fkey = &fkey_text[mode][0];
  692.    }
  693.    *line       = '0';
  694.    *(line + 1) = '\0';
  695.    for (i = 0; i < MAX_FKEYS; i++) {
  696.       if (++(*line) > '9') {   /* calc function key number */
  697.      *line = '0';
  698.       }
  699.       display_text(COLOR1, COLOR0, (USHORT)(fkey_left + MAX_FKEY_LEN * 8 * i
  700.         + fkey_dist * i), (USHORT)(vsh_height - FKEY_HEIGHT + 2), line);
  701.       display_text(COLOR2, COLOR3, (USHORT)(fkey_left +
  702.         MAX_FKEY_LEN * 8 * i + fkey_dist * i + 8), (USHORT)(vsh_height -
  703.                          FKEY_HEIGHT + 2), *fkey++);
  704.    }
  705. }
  706.     /* Print text left aligned on console window at specified position */
  707.  
  708.    VOID 
  709. display_text_left(USHORT front_color, USHORT back_color, USHORT x, USHORT y,
  710.                          BYTE *text, USHORT max_len)
  711. {
  712.    USHORT i, len = 0;
  713.  
  714.    if (! text) {
  715.       line2_buffer[0] = '\0';
  716.    } else {
  717.       if ((len = strlen(text)) > max_len) {
  718.      strncpy(&line2_buffer[0], text, (size_t)max_len);
  719.       } else {
  720.      strcpy(&line2_buffer[0], text);
  721.       }
  722.    }
  723.    for (i = len; i < max_len; i++) {   /* fill string to <max_len> with spaces */
  724.       line2_buffer[i] = ' ';
  725.    }
  726.    line2_buffer[max_len] = '\0';
  727.    display_text(front_color, back_color, x, y, &line2_buffer[0]);
  728. }
  729.     /* Print text centered on console window at specified position */
  730.  
  731.    VOID
  732. display_text_centered(USHORT front_color, USHORT back_color, USHORT x,
  733.                        USHORT y, BYTE *text, USHORT max_len)
  734. {
  735.    BYTE   *ptr, *line = &line2_buffer[0];
  736.    USHORT i, len;
  737.  
  738.    for (i = 0, ptr = line; i < max_len; i++) {   /* fill string with spaces */
  739.       *ptr++ = ' ';
  740.    }
  741.    *ptr = '\0';
  742.    if (text) {
  743.       if ((len = strlen(text)) > max_len) {
  744.      strncpy(line, text, (size_t)max_len);
  745.       } else {
  746.      strncpy(line + max_len / 2 - len / 2, text, (size_t)len);
  747.       }
  748.    }
  749.    display_text(front_color, back_color, x, y, line);
  750. }
  751.     /* Change function keys related to the filerequester mode */
  752.  
  753.    VOID
  754. change_fkey_text(VOID)
  755. {
  756.    if (! show_flag) {   /* hidden display ? */
  757.       print_fkey_text(FKEY_MODE_HIDDEN);
  758.    } else {
  759.       print_fkey_text(FKEY_MODE_NORMAL);
  760.    }
  761. }
  762.