home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / v / vim_src.zip / HELP.C < prev    next >
C/C++ Source or Header  |  1993-01-12  |  3KB  |  133 lines

  1. /* vi:ts=4:sw=4
  2.  *
  3.  * VIM - Vi IMitation
  4.  *
  5.  * Code Contributions By:    Bram Moolenaar            mool@oce.nl
  6.  *                            Tim Thompson            twitch!tjt
  7.  *                            Tony Andrews            onecom!wldrdg!tony 
  8.  *                            G. R. (Fred) Walter        watmath!watcgl!grwalter 
  9.  */
  10.  
  11. /*
  12.  * help.c: display help from the vim.hlp file
  13.  */
  14.  
  15. #include "vim.h"
  16. #include "globals.h"
  17. #include "proto.h"
  18. #include "param.h"
  19.  
  20. #ifdef MSDOS
  21. # include <dir.h>
  22. #endif
  23.  
  24. static long helpfilepos;        /* position in help file */
  25. static FILE *helpfd;            /* file descriptor of help file */
  26.  
  27.     void
  28. help()
  29. {
  30.     int        c;
  31.     int        eof;
  32.     int        i;
  33.     long    filepos[26];    /* seek position for each screen */
  34.     int        screennr;        /* screen number; 'c' == 1 */
  35.     char    fnamebuf[MAXPATHL];
  36. #ifdef MSDOS
  37.     char    *fnamep;
  38. #endif
  39.  
  40. /*
  41.  * try to open the file specified by the "helpfile" option
  42.  */
  43.     expand_env(p_hf, fnamebuf, MAXPATHL);
  44.     if ((helpfd = fopen(fnamebuf, "r")) == NULL)
  45.     {
  46. #ifdef MSDOS
  47.     /*
  48.      * for MSdos: try the DOS search path
  49.      */
  50.         strcpy(fnamebuf, "vim.hlp");
  51.         fnamep = searchpath(fnamebuf);
  52.         if (fnamep == NULL || (helpfd = fopen(fnamep, "r")) == NULL)
  53.         {
  54. #endif
  55.             smsg("Sorry, help file %s not found", fnamebuf);
  56.             return;
  57. #ifdef MSDOS
  58.         }
  59. #endif
  60.     }
  61.     helpfilepos = 0;
  62.     screennr = 0;
  63.     for (i = 0; i < 26; ++i)
  64.         filepos[i] = 0;
  65.     State = HELP;
  66.     for (;;)
  67.     {
  68.         eof = redrawhelp();
  69.         if (!eof)
  70.             filepos[screennr + 1] = ftell(helpfd);
  71.  
  72.         if ((c = vgetc()) == '\n' || c == '\r')
  73.             break;
  74.  
  75.         if (c == ' ')                        /* one screen forwards */
  76.         {
  77.             if (screennr < 25 && !eof)
  78.                 ++screennr;
  79.         }
  80.         else if (c == 'a')                    /* go to first screen */
  81.             screennr = 0;
  82.         else if (c == 'b')                    /* go one screen backwards */
  83.         {
  84.             if (screennr > 0)
  85.                 --screennr;
  86.         }
  87.         else if (c >= 'c' && c <= 'z')        /* go to specified screen */
  88.         {
  89.             if (c - 'b' < screennr)            /* backwards */
  90.                 screennr = c - 'b';
  91.             else                            /* forwards */
  92.             {
  93.                 while (screennr < c - 'b' && filepos[screennr + 1])
  94.                     ++screennr;
  95.                 fseek(helpfd, filepos[screennr], 0);
  96.                 while (screennr < c - 'b')
  97.                 {
  98.                     while ((i = getc(helpfd)) != '\f' && i != -1)
  99.                         ;
  100.                     if (i == -1)
  101.                         break;
  102.                     filepos[++screennr] = ftell(helpfd);
  103.                 }
  104.             }
  105.         }
  106.         helpfilepos = filepos[screennr];
  107.     }
  108.     State = NORMAL;
  109.     script_winsize_pp();
  110.     fclose(helpfd);
  111.     updateScreen(CLEAR);
  112. }
  113.  
  114.     int
  115. redrawhelp()
  116. {
  117.         int nextc;
  118.         int col;
  119.  
  120.         fseek(helpfd, helpfilepos, 0);
  121.         col = Columns - 52;
  122.         if (col < 0)
  123.                 col = 0;
  124.         outstr(T_ED);
  125.         while ((nextc = getc(helpfd)) != -1 && nextc != '\f')
  126.                 outchar((char)nextc);
  127.         windgoto(0, (int)(Columns - strlen(Version) - 1));
  128.         outstrn(Version);
  129.         windgoto((int)Rows - 1, col);
  130.         outstrn("<space = next; return = quit; a = index; b = back>");
  131.         return (nextc == -1);
  132. }
  133.