home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / prof_c / 14view / vf_util.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-08-11  |  3.0 KB  |  117 lines

  1. /*
  2.  *    vf_util -- utility functions for ViewFile
  3.  */
  4.  
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <string.h>
  8. #include <local\std.h>
  9. #include <local\video.h>
  10. #include <local\keydefs.h>
  11. #include "vf.h"
  12.  
  13. extern int Startscan, Endscan;
  14.  
  15. #define NDIGITS    6
  16.  
  17. /*
  18.  *    gotoln -- jump to an absolute line number
  19.  */
  20.  
  21. DNODE *
  22. gotoln(buf)
  23. DNODE *buf;
  24. {
  25.     register int ln;
  26.     register DNODE *lp;
  27.     char line[NDIGITS + 1];
  28.  
  29.     extern void showmsg(char *);
  30.     extern char *getstr(char *, int);
  31.  
  32.     /* get line number from user */
  33.     showmsg("Line number: ");
  34.     setctype(Startscan, Endscan);            /* cursor on */
  35.     ln = atoi(getstr(line, NDIGITS + 1));
  36.     setctype(MAXSCAN, MAXSCAN);            /* cursor off */
  37.  
  38.     /* check boundary conditions */
  39.     if (ln > buf->d_prev->d_lnum || ln <= 0) {
  40.         showmsg("Line out of range");
  41.         return ((DNODE *)NULL);
  42.     }
  43.  
  44.     /* find the line */
  45.     for (lp = buf->d_next; ln != lp->d_lnum; lp = lp->d_next)
  46.         ;
  47.     return (lp);
  48. }
  49.  
  50.  
  51. /*
  52.  *    showhelp -- display a help frame
  53.  */
  54.  
  55. #define HELPROW    TOPROW + 3
  56. #define HELPCOL    10
  57. #define VBORDER    1
  58. #define HBORDER    2
  59.  
  60. void
  61. showhelp(textattr)
  62. unsigned char textattr;    /* attribute of text area */
  63. {
  64.     register int i, n;
  65.     int nlines, ncols;
  66.     unsigned char helpattr;
  67.     static char *help[] = {
  68.         "PgUp (U)        Scroll up the file one screen page",
  69.         "PgDn (D)        Scroll down the file one screen page",
  70.         "Up arrow (-)    Scroll up in the file one line",
  71.         "Down arrow (+)  Scroll down in the file one line",
  72.         "Right arrow (>) Scroll right by 20 columns",
  73.         "Left arrow (<)  Scroll left by 20 columns",
  74.         "Home (B)        Go to beginning of file buffer",
  75.         "End (E)         Go to end of file buffer",
  76.         "Alt-g (G)       Go to a specified line in the buffer",
  77.         "Alt-h (H or ?)  Display this help frame",
  78.         "Alt-n (N)       Toggle line-numbering feature",
  79.         "\\ (R)           Reverse search for a literal text string",
  80.         "/ (S)           Search forward for a literal text string",
  81.         "Esc             Next file from list (quits if none)",
  82.         "Alt-q (Q)       Quit",
  83.         "--------------------------------------------------------",
  84.         "            << Press a key to continue >>",
  85.         (char *)NULL
  86.     };
  87.  
  88.     /* prepare help window */
  89.     ncols = 0;
  90.     for (i = 0; help[i] != (char *)NULL; ++i)
  91.         if ((n = strlen(help[i])) > ncols)
  92.             ncols = n;
  93.     nlines = i - 1;
  94.     --ncols;
  95.     helpattr = (RED << 4) | BWHT;
  96.     clrw(HELPROW - VBORDER, HELPCOL - HBORDER,
  97.         HELPROW + nlines + VBORDER, HELPCOL + ncols + HBORDER,
  98.         helpattr);
  99.     drawbox(HELPROW - VBORDER, HELPCOL - HBORDER,
  100.         HELPROW + nlines + VBORDER, HELPCOL + ncols + HBORDER,
  101.         Vpage);
  102.  
  103.     /* display the help text */
  104.     for (i = 0; help[i] != (char *)NULL; ++i) {
  105.         putcur(HELPROW + i, HELPCOL, Vpage);
  106.         putstr(help[i], Vpage);
  107.     }
  108.  
  109.     /* pause until told by a keypress to proceed */
  110.     getkey();
  111.  
  112.     /* restore help display area to the text attribute */
  113.     clrw(HELPROW - VBORDER, HELPCOL - HBORDER,
  114.         HELPROW + nlines + VBORDER, HELPCOL + ncols + HBORDER,
  115.         textattr);
  116. }
  117.