home *** CD-ROM | disk | FTP | other *** search
/ Mega A/V / mega_av.zip / mega_av / GRAPHUTL / FRPOR172.ZIP / HELP.C < prev    next >
C/C++ Source or Header  |  1992-03-15  |  38KB  |  1,664 lines

  1.  
  2. /*
  3.  * help.c
  4.  *
  5.  * This module is linked as an overlay, use ENTER_OVLY and EXIT_OVLY.
  6.  *
  7.  *
  8.  * Revision history:
  9.  *
  10.  *   2-26-90  EAN     Initial version.
  11.  *
  12.  *
  13.  */
  14.  
  15.  
  16. #ifndef TEST /* kills all those assert macros in production version */
  17. #define NDEBUG
  18. #endif
  19.  
  20. #define INCLUDE_COMMON    /* include common code in helpcom.h */
  21.  
  22.  
  23. #include <stdio.h>
  24. #include <stdlib.h>
  25. #ifndef XFRACT
  26. #include <io.h>
  27. #include <dos.h>
  28. #endif
  29. #include <fcntl.h>
  30. #include <string.h>
  31. #include <time.h>
  32. #include <assert.h>
  33. #include <sys/types.h>
  34. #include <sys/stat.h>
  35. #ifdef XFRACT
  36. #include <unistd.h>
  37. #endif
  38. #include "fractint.h"
  39. #include "helpcom.h"
  40. #include "helpdefs.h"
  41.  
  42.  
  43. #define MAX_HIST       16         /* number of pages we'll remember */
  44.  
  45. #define ALT_F1         1104
  46. #define BACK_TAB     1015
  47. #define BACKSPACE        8
  48.  
  49. #define ACTION_CALL        0         /* values returned by help_topic() */
  50. #define ACTION_PREV        1
  51. #define ACTION_PREV2        2         /* special - go back two topics */
  52. #define ACTION_INDEX        3
  53. #define ACTION_QUIT        4
  54.  
  55. #define F_HIST            (1<<0)   /* flags for help_topic() */
  56. #define F_INDEX         (1<<1)
  57.  
  58. #define MAX_PAGE_SIZE        (80*25)  /* no page of text may be larger */
  59.  
  60. #define TEXT_START_ROW        2         /* start print the help text here */
  61.  
  62.  
  63. typedef struct
  64.    {
  65.    BYTE r, c;
  66.    int         width;
  67.    unsigned     offset;
  68.    int         topic_num;
  69.    unsigned     topic_off;
  70.    } LINK;
  71.  
  72.  
  73. typedef struct
  74.    {
  75.    int        topic_num;
  76.    unsigned topic_off;
  77.    } LABEL;
  78.  
  79.  
  80. typedef struct
  81.    {
  82.    unsigned     offset;
  83.    unsigned     len;
  84.    int         margin;
  85.    } PAGE;
  86.  
  87.  
  88. typedef struct
  89.    {
  90.    int        topic_num;
  91.    unsigned topic_off;
  92.    int        link;
  93.    } HIST;
  94.  
  95.  
  96. struct help_sig_info
  97.    {
  98.    unsigned long sig;
  99.    int         version;
  100.    unsigned long base;       /* only if added to fractint.exe */
  101.    } ;
  102.  
  103.  
  104. void print_document(char *outfname, int (*msg_func)(int,int), int save_extraseg );
  105. static int print_doc_msg_func(int pnum, int num_pages);
  106.  
  107.  
  108.  
  109. void help_overlay(void) { }
  110.  
  111.  
  112.  
  113. /* stuff from fractint */
  114.  
  115. extern int  lookatmouse;
  116. extern long timer_start;
  117. extern int  helpmode;
  118. extern int  text_type;     /* 0=real color text, 1=640x200x2, 2=??mono?? */
  119. extern int  textcbase;
  120. extern int  textrbase;
  121. extern int  extraseg;
  122. extern int  release;
  123.  
  124. void putstring         (int row, int col, int attr, CHAR far *msg);
  125. int  putstringcenter (int row, int col, int width, int attr, char far *msg);
  126. void setattr         (int row, int col, int attr, int width);
  127. void movecursor      (int row, int col);
  128. void setclear         (void);
  129. void helptitle         (void);
  130. int  getakey         (void);
  131. int  keypressed      (void);
  132. void stackscreen     (void);
  133. void unstackscreen   (void);
  134. void findpath         (char *filename, char *path);
  135. int  farread         (int handle, VOIDFARPTR buf, unsigned len);
  136. int  farwrite         (int handle, VOIDFARPTR buf, unsigned len);
  137.  
  138.  
  139. static int          help_file = -1; /* help file handle */
  140. static long          base_off;       /* offset to help info in help file */
  141. static int          max_links;      /* max # of links in any page */
  142. static int          max_pages;      /* max # of pages in any topic */
  143. static int          num_label;      /* number of labels */
  144. static int          num_topic;      /* number of topics */
  145. static int          curr_hist = 0;  /* current pos in history */
  146.  
  147. /* these items alloc'ed in init_help... */
  148.  
  149. static long     far *topic_offset;       /* 4*num_topic */
  150. static LABEL     far *label;           /* 4*num_label */
  151. static HIST     far *hist;           /* 6*MAX_HIST (96 bytes) */
  152.  
  153. /* these items alloc'ed only while help is active... */
  154.  
  155. static char      far *buffer;         /* MAX_PAGE_SIZE (2048 bytes) */
  156. static LINK      far *link_table;     /* 10*max_links */
  157. static PAGE      far *page_table;     /* 4*max_pages  */
  158.  
  159.  
  160. static void help_seek(long pos)
  161.    {
  162.    lseek(help_file, base_off+pos, SEEK_SET);
  163.    }
  164.  
  165.  
  166. static void displayc(int row, int col, int color, int ch)
  167.    {
  168.    static char *s = "?";
  169.  
  170.    if (text_type == 1)     /* if 640x200x2 mode */
  171.       {
  172.       /*
  173.        * This is REALLY ugly, but it works.  Non-current links (ones that
  174.        * would be bold if 640x200 supported it) are in upper-case and the
  175.        * current item is inversed.
  176.        *
  177.        */
  178.  
  179.       if (color & INVERSE)
  180.      color = INVERSE;
  181.       else if (color & BRIGHT)
  182.      {
  183.      color = 0;   /* normal */
  184.      if (ch>='a' && ch<='z')
  185.         ch += 'A' - 'a';
  186.      }
  187.       else
  188.      color = 0;   /* normal */
  189.       }
  190.  
  191.    s[0] = ch;
  192.    putstring(row, col, color, s);
  193.    }
  194.  
  195.  
  196. static void display_text(int row, int col, int color, char far *text, unsigned len)
  197.    {
  198.    while (len-- > 0)
  199.       {
  200.       if (*text == CMD_LITERAL)
  201.      {
  202.      ++text;
  203.      --len;
  204.      }
  205.       displayc(row, col++, color, *text++);
  206.       }
  207.    }
  208.  
  209.  
  210. static void display_parse_text(char far *text, unsigned len, int start_margin, int *num_link, LINK far *link)
  211.    {
  212.    char far  *curr;
  213.    int          row, col;
  214.    int          tok;
  215.    int          size,
  216.           width;
  217.  
  218.    textcbase = SCREEN_INDENT;
  219.    textrbase = TEXT_START_ROW;
  220.  
  221.    curr = text;
  222.    row = 0;
  223.    col = 0;
  224.  
  225.    size = width = 0;
  226.  
  227.    if (start_margin >= 0)
  228.       tok = TOK_PARA;
  229.    else
  230.       tok = -1;
  231.  
  232.    while ( 1 )
  233.       {
  234.       switch ( tok )
  235.      {
  236.      case TOK_PARA:
  237.         {
  238.         int indent,
  239.         margin;
  240.  
  241.         if (size > 0)
  242.            {
  243.            ++curr;
  244.            indent = *curr++;
  245.            margin = *curr++;
  246.            len  -= 3;
  247.            }
  248.         else
  249.            {
  250.            indent = start_margin;
  251.            margin = start_margin;
  252.            }
  253.  
  254.         col = indent;
  255.  
  256.         while (1)
  257.            {
  258.            tok = find_token_length(ONLINE, curr, len, &size, &width);
  259.  
  260.            if (tok == TOK_DONE || tok == TOK_NL || tok == TOK_FF )
  261.           break;
  262.  
  263.            if (tok == TOK_PARA)
  264.           {
  265.           col = 0;   /* fake a new-line */
  266.           row++;
  267.           break;
  268.           }
  269.  
  270.            if (tok == TOK_XONLINE || tok == TOK_XDOC)
  271.           {
  272.           curr += size;
  273.           len  -= size;
  274.           continue;
  275.           }
  276.  
  277.            /* now tok is TOK_SPACE or TOK_LINK or TOK_WORD */
  278.  
  279.            if (col+width > SCREEN_WIDTH)
  280.           {         /* go to next line... */
  281.           col = margin;
  282.           ++row;
  283.  
  284.           if ( tok == TOK_SPACE )
  285.              width = 0;   /* skip spaces at start of a line */
  286.           }
  287.  
  288.            if (tok == TOK_LINK)
  289.           {
  290.           display_text(row, col, C_HELP_LINK, curr+1+3*sizeof(int), width);
  291.           if (num_link != NULL)
  292.              {
  293.              link[*num_link].r           = row;
  294.              link[*num_link].c           = col;
  295.                      link[*num_link].topic_num = getint(curr+1);
  296.                      link[*num_link].topic_off = getint(curr+1+sizeof(int));
  297.                      link[*num_link].offset    = (unsigned) ((curr+1+3*sizeof(int)) - text);
  298.              link[*num_link].width     = width;
  299.              ++(*num_link);
  300.              }
  301.           }
  302.            else if (tok == TOK_WORD )
  303.           display_text(row, col, C_HELP_BODY, curr, width);
  304.  
  305.            col += width;
  306.            curr += size;
  307.            len -= size;
  308.            }
  309.  
  310.         width = size = 0;
  311.         break;
  312.         }
  313.  
  314.      case TOK_CENTER:
  315.         col = find_line_width(ONLINE, curr, len);
  316.         col = (SCREEN_WIDTH-col)/2;
  317.         if (col < 0)
  318.            col = 0;
  319.         break;
  320.  
  321.      case TOK_NL:
  322.         col = 0;
  323.         ++row;
  324.         break;
  325.  
  326.      case TOK_LINK:
  327.             display_text(row, col, C_HELP_LINK, curr+1+3*sizeof(int), width);
  328.         if (num_link != NULL)
  329.            {
  330.            link[*num_link].r     = row;
  331.            link[*num_link].c     = col;
  332.                link[*num_link].topic_num = getint(curr+1);
  333.                link[*num_link].topic_off = getint(curr+1+sizeof(int));
  334.                link[*num_link].offset    = (unsigned) ((curr+1+3*sizeof(int)) - text);
  335.            link[*num_link].width     = width;
  336.            ++(*num_link);
  337.            }
  338.         break;
  339.  
  340.      case TOK_XONLINE:  /* skip */
  341.      case TOK_FF:        /* ignore */
  342.      case TOK_XDOC:     /* ignore */
  343.      case TOK_DONE:
  344.      case TOK_SPACE:
  345.         break;
  346.  
  347.      case TOK_WORD:
  348.         display_text(row, col, C_HELP_BODY, curr, width);
  349.         break;
  350.      } /* switch */
  351.  
  352.       curr += size;
  353.       len  -= size;
  354.       col  += width;
  355.  
  356.       if (len == 0)
  357.      break;
  358.  
  359.       tok = find_token_length(ONLINE, curr, len, &size, &width);
  360.       } /* while */
  361.  
  362.    textcbase = 0;
  363.    textrbase = 0;
  364.    }
  365.  
  366.  
  367. static void color_link(LINK far *link, int color)
  368.    {
  369.    textcbase = SCREEN_INDENT;
  370.    textrbase = TEXT_START_ROW;
  371.  
  372.    if (text_type == 1)     /* if 640x200x2 mode */
  373.       display_text(link->r, link->c, color, buffer+link->offset, link->width);
  374.    else
  375.       setattr(link->r, link->c, color, link->width);
  376.  
  377.    textcbase = 0;
  378.    textrbase = 0;
  379.    }
  380.  
  381.  
  382.  
  383. /* #define PUT_KEY(name, descrip) putstring(-1,-1,C_HELP_INSTR_KEYS,name), putstring(-1,-1,C_HELP_INSTR," "descrip"  ") */
  384. #ifndef XFRACT
  385. #define PUT_KEY(name, descrip) putstring(-1,-1,C_HELP_INSTR,name); putstring(-1,-1,C_HELP_INSTR,":"descrip"  ")
  386. #else
  387. #define PUT_KEY(name, descrip) putstring(-1,-1,C_HELP_INSTR,name);\
  388. putstring(-1,-1,C_HELP_INSTR,":");\
  389. putstring(-1,-1,C_HELP_INSTR,descrip);\
  390. putstring(-1,-1,C_HELP_INSTR,"  ")
  391. #endif
  392.  
  393.  
  394. static void helpinstr(void)
  395.    {
  396.    int ctr;
  397.  
  398.    for (ctr=0; ctr<80; ctr++)
  399.      putstring(24, ctr, C_HELP_INSTR, " ");
  400.  
  401.    movecursor(24, 1);
  402.    PUT_KEY("F1",               "Index");
  403. #ifndef XFRACT
  404.    PUT_KEY("\030\031\033\032", "Select");
  405. #else
  406.    PUT_KEY("K J H L", "Select");
  407. #endif
  408.    PUT_KEY("Enter",            "Go to");
  409.    PUT_KEY("Backspace",        "Last topic");
  410.    PUT_KEY("Escape",           "Exit help");
  411.    }
  412.  
  413.  
  414. static void printinstr(void)
  415.    {
  416.    int ctr;
  417.  
  418.    for (ctr=0; ctr<80; ctr++)
  419.      putstring(24, ctr, C_HELP_INSTR, " ");
  420.  
  421.    movecursor(24, 1);
  422.    PUT_KEY("Escape", "Abort");
  423.    }
  424.  
  425.  
  426. #undef PUT_KEY
  427.  
  428.  
  429. static void display_page(char far *title, char far *text, unsigned text_len, int page, int num_pages, int start_margin, int *num_link, LINK far *link)
  430.    {
  431.    char temp[9];
  432.  
  433.    helptitle();
  434.    helpinstr();
  435.    setattr(2, 0, C_HELP_BODY, 80*22);
  436.    putstringcenter(1, 0, 80, C_HELP_HDG, title);
  437.    sprintf(temp, "%2d of %d", page+1, num_pages);
  438.    putstring(1, 79-(6 + ((num_pages>=10)?2:1)), C_HELP_INSTR, temp);
  439.  
  440.    if (text != NULL)
  441.       display_parse_text(text, text_len, start_margin, num_link, link);
  442.  
  443.    movecursor(25, 80);     /* hide cursor */
  444.    }
  445.  
  446.  
  447.  
  448. /*
  449.  * int overlap(int a, int a2, int b, int b2);
  450.  *
  451.  * If a, a2, b, and b2 are points on a line, this function returns the
  452.  * distance of intersection between a-->a2 and b-->b2.    If there is no
  453.  * intersection between the lines this function will return a negative number
  454.  * representing the distance between the two lines.
  455.  *
  456.  * There are six possible cases of intersection between the lines:
  457.  *
  458.  *            a              a2
  459.  *            |              |
  460.  *     b     b2    |              |       b     b2
  461.  *     |---(1)---|    |              |       |---(2)---|
  462.  *            |              |
  463.  *        b    |     b2      b       |      b2
  464.  *        |------(3)----|       |------(4)-----|
  465.  *            |              |
  466.  *         b    |              |   b2
  467.  *         |------+--------(5)----------+---|
  468.  *            |              |
  469.  *            |     b       b2      |
  470.  *            |     |--(6)--|       |
  471.  *            |              |
  472.  *            |              |
  473.  *
  474.  */
  475.  
  476.  
  477. static int overlap(int a, int a2, int b, int b2)
  478.    {
  479.    if ( b < a )
  480.       {
  481.       if ( b2 >= a2 )
  482.      return ( a2 - a );           /* case (5) */
  483.  
  484.       return ( b2 - a );           /* case (1), case (3) */
  485.       }
  486.  
  487.    if ( b2 <= a2 )
  488.       return ( b2 - b );           /* case (6) */
  489.  
  490.    return ( a2 - b );               /* case (2), case (4) */
  491.    }
  492.  
  493.  
  494. static int dist(int a, int b)
  495.    {
  496.    int t = a - b;
  497.  
  498.    return (abs(t));
  499.    }
  500.  
  501.  
  502. #ifdef __TURBOC__
  503. #   pragma warn -def /* turn off "Possible use before definition" warning */
  504. #endif
  505.  
  506.  
  507.  
  508.  
  509. static int find_link_updown(LINK far *link, int num_link, int curr_link, int up)
  510.    {
  511.    int         ctr,
  512.          curr_c2,
  513.          best_overlap,
  514.          temp_overlap;
  515.    LINK far *curr,
  516.     far *temp,
  517.     far *best;
  518.    int         temp_dist;
  519.  
  520.    curr    = &link[curr_link];
  521.    best    = NULL;
  522.    curr_c2 = curr->c + curr->width - 1;
  523.  
  524.    for (ctr=0, temp=link; ctr<num_link; ctr++, temp++)
  525.       {
  526.       if ( ctr != curr_link &&
  527.        ( (up && temp->r < curr->r) || (!up && temp->r > curr->r) ) )
  528.      {
  529.      temp_overlap = overlap(curr->c, curr_c2, temp->c, temp->c+temp->width-1);
  530.      /* if >= 3 lines between, prioritize on vertical distance: */
  531.      if ((temp_dist = dist(temp->r, curr->r)) >= 4)
  532.         temp_overlap -= temp_dist * 100;
  533.  
  534.      if (best != NULL)
  535.         {
  536.         if ( best_overlap >= 0 && temp_overlap >= 0 )
  537.            {     /* if they're both under curr set to closest in y dir */
  538.            if ( dist(best->r, curr->r) > temp_dist )
  539.           best = NULL;
  540.            }
  541.         else
  542.            {
  543.            if ( best_overlap < temp_overlap )
  544.           best = NULL;
  545.            }
  546.         }
  547.  
  548.      if (best == NULL)
  549.         {
  550.         best = temp;
  551.         best_overlap = temp_overlap;
  552.         }
  553.      }
  554.       }
  555.  
  556.    return ( (best==NULL) ? -1 : (int)(best-link) );
  557.    }
  558.  
  559.  
  560. static int find_link_leftright(LINK far *link, int num_link, int curr_link, int left)
  561.    {
  562.    int         ctr,
  563.          curr_c2,
  564.          best_c2,
  565.          temp_c2,
  566.          best_dist,
  567.          temp_dist;
  568.    LINK far *curr,
  569.     far *temp,
  570.     far *best;
  571.  
  572.    curr    = &link[curr_link];
  573.    best    = NULL;
  574.    curr_c2 = curr->c + curr->width - 1;
  575.  
  576.    for (ctr=0, temp=link; ctr<num_link; ctr++, temp++)
  577.       {
  578.       temp_c2 = temp->c + temp->width - 1;
  579.  
  580.       if ( ctr != curr_link &&
  581.        ( (left && temp_c2 < curr->c) || (!left && temp->c > curr_c2) ) )
  582.      {
  583.      temp_dist = dist(curr->r, temp->r);
  584.  
  585.      if (best != NULL)
  586.         {
  587.         if ( best_dist == 0 && temp_dist == 0 )  /* if both on curr's line... */
  588.            {
  589.            if ( (  left && dist(curr->c, best_c2) > dist(curr->c, temp_c2) ) ||
  590.             ( !left && dist(curr_c2, best->c) > dist(curr_c2, temp->c) ) )
  591.           best = NULL;
  592.            }
  593.         else
  594.            {
  595.            if ( best_dist >= temp_dist )   /* if temp is closer... */
  596.           best = NULL;
  597.            }
  598.         } /* if (best...) */
  599.  
  600.      if (best == NULL)
  601.         {
  602.         best      = temp;
  603.         best_dist = temp_dist;
  604.         best_c2   = temp_c2;
  605.         }
  606.      }
  607.       } /* for */
  608.  
  609.    return ( (best==NULL) ? -1 : (int)(best-link) );
  610.    }
  611.  
  612.  
  613. #ifdef __TURBOC__
  614. #   pragma warn .def   /* back to default */
  615. #   pragma warn -par   /* now turn off "Parameter not used" warning */
  616. #endif
  617.  
  618.  
  619. static int find_link_key(LINK far *link, int num_link, int curr_link, int key)
  620.    {
  621.    switch (key)
  622.       {
  623.       case TAB:      return ( (curr_link>=num_link-1) ? -1 : curr_link+1 );
  624.       case BACK_TAB: return ( (curr_link<=0)          ? -1 : curr_link-1 );
  625.       default:         assert(0);  return (-1);
  626.       }
  627.    }
  628.  
  629.  
  630. #ifdef __TURBOC__
  631. #   pragma warn .par /* back to default */
  632. #endif
  633.  
  634.  
  635. static int do_move_link(LINK far *link, int num_link, int *curr, int (*f)(LINK far *,int,int,int), int val)
  636.    {
  637.    int t;
  638.  
  639.    if (num_link > 1)
  640.       {
  641.       if ( f == NULL )
  642.      t = val;
  643.       else
  644.      t = (*f)(link, num_link, *curr, val);
  645.  
  646.       if ( t >= 0 && t != *curr )
  647.      {
  648.      color_link(&link[*curr], C_HELP_LINK);
  649.      *curr = t;
  650.      color_link(&link[*curr], C_HELP_CURLINK);
  651.      return (1);
  652.      }
  653.       }
  654.  
  655.    return (0);
  656.    }
  657.  
  658.  
  659. static int help_topic(HIST *curr, HIST *next, int flags)
  660.    {
  661.    int         len;
  662.    int         key;
  663.    int         num_pages;
  664.    int         num_link;
  665.    int         page;
  666.    int         curr_link;
  667.    char      title[81];
  668.    long      where;
  669.    int         draw_page;
  670.    int         action;
  671.    BYTE ch;
  672.  
  673.    where     = topic_offset[curr->topic_num]+sizeof(int); /* to skip flags */
  674.    curr_link = curr->link;
  675.  
  676.    help_seek(where);
  677.  
  678.    read(help_file, (char *)&num_pages, sizeof(int));
  679.    assert(num_pages>0 && num_pages<=max_pages);
  680.  
  681.    farread(help_file, (char far *)page_table, 3*sizeof(int)*num_pages);
  682.  
  683.    read(help_file, &ch, 1);
  684.    len = ch;
  685.    assert(len<81);
  686.    read(help_file, (char *)title, len);
  687.    title[len] = '\0';
  688.  
  689.    where += sizeof(int) + num_pages*3*sizeof(int) + 1 + len + sizeof(int);
  690.  
  691.    for(page=0; page<num_pages; page++)
  692.       if (curr->topic_off >= page_table[page].offset &&
  693.       curr->topic_off <  page_table[page].offset+page_table[page].len )
  694.      break;
  695.  
  696.    assert(page < num_pages);
  697.  
  698.    action = -1;
  699.    draw_page = 2;
  700.  
  701.    do
  702.       {
  703.       if (draw_page)
  704.      {
  705.      help_seek(where+page_table[page].offset);
  706.      farread(help_file, buffer, page_table[page].len);
  707.  
  708.      num_link = 0;
  709.      display_page(title, buffer, page_table[page].len, page, num_pages,
  710.               page_table[page].margin, &num_link, link_table);
  711.  
  712.      if (draw_page==2)
  713.         {
  714.         assert(num_link<=0 || (curr_link>=0 && curr_link<num_link));
  715.         }
  716.      else if (draw_page==3)
  717.         curr_link = num_link - 1;
  718.      else
  719.         curr_link = 0;
  720.  
  721.      if (num_link > 0)
  722.         color_link(&link_table[curr_link], C_HELP_CURLINK);
  723.  
  724.      draw_page = 0;
  725.      }
  726.  
  727.       key = getakey();
  728.  
  729.       switch(key)
  730.      {
  731.      case PAGE_DOWN:
  732.         if (page<num_pages-1)
  733.            {
  734.            page++;
  735.            draw_page = 1;
  736.            }
  737.         break;
  738.  
  739.      case PAGE_UP:
  740.         if (page>0)
  741.            {
  742.            page--;
  743.            draw_page = 1;
  744.            }
  745.         break;
  746.  
  747.      case HOME:
  748.         if ( page != 0 )
  749.            {
  750.            page = 0;
  751.            draw_page = 1;
  752.            }
  753.         else
  754.            do_move_link(link_table, num_link, &curr_link, NULL, 0);
  755.         break;
  756.  
  757.      case END:
  758.         if ( page != num_pages-1 )
  759.            {
  760.            page = num_pages-1;
  761.            draw_page = 3;
  762.            }
  763.         else
  764.            do_move_link(link_table, num_link, &curr_link, NULL, num_link-1);
  765.         break;
  766.  
  767.      case TAB:
  768.         if ( !do_move_link(link_table, num_link, &curr_link, find_link_key, key) &&
  769.          page<num_pages-1 )
  770.            {
  771.            ++page;
  772.            draw_page = 1;
  773.            }
  774.         break;
  775.  
  776.      case BACK_TAB:
  777.         if ( !do_move_link(link_table, num_link, &curr_link, find_link_key, key) &&
  778.          page>0 )
  779.            {
  780.            --page;
  781.            draw_page = 3;
  782.            }
  783.         break;
  784.  
  785.      case DOWN_ARROW:
  786.         if ( !do_move_link(link_table, num_link, &curr_link, find_link_updown, 0) &&
  787.          page<num_pages-1 )
  788.            {
  789.            ++page;
  790.            draw_page = 1;
  791.            }
  792.         break;
  793.  
  794.      case UP_ARROW:
  795.         if ( !do_move_link(link_table, num_link, &curr_link, find_link_updown, 1) &&
  796.          page>0 )
  797.            {
  798.            --page;
  799.            draw_page = 3;
  800.            }
  801.         break;
  802.  
  803.      case LEFT_ARROW:
  804.         do_move_link(link_table, num_link, &curr_link, find_link_leftright, 1);
  805.         break;
  806.  
  807.      case RIGHT_ARROW:
  808.         do_move_link(link_table, num_link, &curr_link, find_link_leftright, 0);
  809.         break;
  810.  
  811.      case ESC:       /* exit help */
  812.         action = ACTION_QUIT;
  813.         break;
  814.  
  815.      case BACKSPACE:   /* prev topic */
  816.      case ALT_F1:
  817.         if (flags & F_HIST)
  818.            action = ACTION_PREV;
  819.         break;
  820.  
  821.      case F1:    /* help index */
  822.         if (!(flags & F_INDEX))
  823.            action = ACTION_INDEX;
  824.         break;
  825.  
  826.      case ENTER:
  827.      case ENTER_2:
  828.         if (num_link > 0)
  829.            {
  830.            next->topic_num = link_table[curr_link].topic_num;
  831.            next->topic_off = link_table[curr_link].topic_off;
  832.            action = ACTION_CALL;
  833.            }
  834.         break;
  835.      } /* switch */
  836.       }
  837.    while ( action == -1 );
  838.  
  839.    curr->topic_off = page_table[page].offset;
  840.    curr->link       = curr_link;
  841.  
  842.    return (action);
  843.    }
  844.  
  845.  
  846. int help(int action)
  847.    {
  848.    static char far unknowntopic_msg[] = "Unknown Help Topic";
  849.    HIST      curr;
  850.    int         oldlookatmouse;
  851.    int         oldhelpmode;
  852.    int         flags;
  853.    HIST      next;
  854.  
  855.    ENTER_OVLY(OVLY_HELP);
  856.  
  857.    if (helpmode == -1)     /* is help disabled? */
  858.       {
  859.       EXIT_OVLY;
  860.       return (0);
  861.       }
  862.  
  863.    if (help_file == -1)
  864.       {
  865.       buzzer(2);
  866.       EXIT_OVLY;
  867.       return (0);
  868.       }
  869.  
  870.    buffer = farmemalloc((long)MAX_PAGE_SIZE + sizeof(LINK)*max_links +
  871.             sizeof(PAGE)*max_pages);
  872.  
  873.    if (buffer == NULL)
  874.       {
  875.       buzzer(2);
  876.       EXIT_OVLY;
  877.       return (0);
  878.       }
  879.  
  880.    link_table = (LINK far *)(&buffer[MAX_PAGE_SIZE]);
  881.    page_table = (PAGE far *)(&link_table[max_links]);
  882.  
  883.    oldlookatmouse = lookatmouse;
  884.    lookatmouse = 0;
  885.    timer_start -= clock();
  886.    stackscreen();
  887.  
  888.    if (helpmode >= 0)
  889.       {
  890.       next.topic_num = label[helpmode].topic_num;
  891.       next.topic_off = label[helpmode].topic_off;
  892.       }
  893.    else
  894.       {
  895.       next.topic_num = helpmode;
  896.       next.topic_off = 0;
  897.       }
  898.  
  899.    oldhelpmode = helpmode;
  900.  
  901.    if (curr_hist <= 0)
  902.       action = ACTION_CALL;  /* make sure it isn't ACTION_PREV! */
  903.  
  904.    do
  905.       {
  906.       switch(action)
  907.      {
  908.      case ACTION_PREV2:
  909.         if (curr_hist > 0)
  910.            curr = hist[--curr_hist];
  911.  
  912.         /* fall-through */
  913.  
  914.      case ACTION_PREV:
  915.         if (curr_hist > 0)
  916.            curr = hist[--curr_hist];
  917.         break;
  918.  
  919.      case ACTION_QUIT:
  920.         break;
  921.  
  922.      case ACTION_INDEX:
  923.         next.topic_num = label[HELP_INDEX].topic_num;
  924.         next.topic_off = label[HELP_INDEX].topic_off;
  925.  
  926.         /* fall-through */
  927.  
  928.      case ACTION_CALL:
  929.         curr = next;
  930.         curr.link = 0;
  931.         break;
  932.      } /* switch */
  933.  
  934.       flags = 0;
  935.       if (curr.topic_num == label[HELP_INDEX].topic_num)
  936.      flags |= F_INDEX;
  937.       if (curr_hist > 0)
  938.      flags |= F_HIST;
  939.  
  940.       if ( curr.topic_num >= 0 )
  941.      action = help_topic(&curr, &next, flags);
  942.       else
  943.      {
  944.      if ( curr.topic_num == -100 )
  945.         {
  946.         print_document("FRACTINT.DOC", print_doc_msg_func, 1);
  947.         action = ACTION_PREV2;
  948.         }
  949.  
  950.      else if ( curr.topic_num == -101 )
  951.         action = ACTION_PREV2;
  952.  
  953.      else
  954.         {
  955.         display_page(unknowntopic_msg, NULL, 0, 0, 1, 0, NULL, NULL);
  956.         action = -1;
  957.         while (action == -1)
  958.            {
  959.            switch (getakey())
  960.           {
  961.           case ESC:     action = ACTION_QUIT;    break;
  962.           case ALT_F1:     action = ACTION_PREV;    break;
  963.           case F1:     action = ACTION_INDEX; break;
  964.           } /* switch */
  965.            } /* while */
  966.         }
  967.      } /* else */
  968.  
  969.       if ( action != ACTION_PREV && action != ACTION_PREV2 )
  970.      {
  971.      if (curr_hist >= MAX_HIST)
  972.         {
  973.         int ctr;
  974.  
  975.         for (ctr=0; ctr<MAX_HIST-1; ctr++)
  976.            hist[ctr] = hist[ctr+1];
  977.  
  978.         curr_hist = MAX_HIST-1;
  979.         }
  980.      hist[curr_hist++] = curr;
  981.      }
  982.       }
  983.    while (action != ACTION_QUIT);
  984.  
  985.    farmemfree((BYTE far *)buffer);
  986.  
  987.    unstackscreen();
  988.    lookatmouse = oldlookatmouse;
  989.    helpmode = oldhelpmode;
  990.    timer_start += clock();
  991.  
  992.    EXIT_OVLY;
  993.    return(0);
  994.    }
  995.  
  996.  
  997.  
  998. static int dos_version(void)
  999.    {
  1000. #ifndef XFRACT
  1001.    union REGS r;
  1002.  
  1003.    r.x.ax = 0x3000;
  1004.    intdos(&r, &r);
  1005.  
  1006.    return (r.h.al*100 + r.h.ah);
  1007. #else
  1008.    return 0;
  1009. #endif
  1010.    }
  1011.  
  1012.  
  1013. static int exe_path(char *filename, char *path)
  1014.    {
  1015.    char *ptr;
  1016.  
  1017.    if (dos_version() >= 300)  /* DOS version 3.00+ ? */
  1018.       {
  1019. #ifdef __TURBOC__
  1020.       strcpy(path, _argv[0]);
  1021. #else  /* assume MSC */
  1022.       extern char **__argv;
  1023.       strcpy(path, __argv[0]);     /* note: __argv may be undocumented in MSC */
  1024. #endif
  1025.  
  1026.       ptr = strrchr(path, SLASHC);
  1027.       if (ptr == NULL)
  1028.      ptr = path;
  1029.       else
  1030.      ++ptr;
  1031.       strcpy(ptr, filename);
  1032.       return (1);
  1033.       }
  1034.  
  1035.    return (0);
  1036.    }
  1037.  
  1038.  
  1039. static int find_file(char *filename, char *path)
  1040.    {
  1041.    int handle;
  1042.  
  1043.    if ( exe_path(filename, path) )
  1044.       if ( (handle=open(path, O_RDONLY)) != -1)
  1045.      {
  1046.      close(handle);
  1047.      return (1);
  1048.      }
  1049.  
  1050.    findpath(filename,path);
  1051.    return ( (path[0]) ? 1 : 0);
  1052.    }
  1053.  
  1054.  
  1055. static int _read_help_topic(int topic, int off, int len, VOIDFARPTR buf)
  1056.    {
  1057.    static int  curr_topic = -1;
  1058.    static long curr_base;
  1059.    static int  curr_len;
  1060.    int           read_len;
  1061.  
  1062.    if ( topic != curr_topic )
  1063.       {
  1064.       int t;
  1065.       char ch;
  1066.  
  1067.       curr_topic = topic;
  1068.  
  1069.       curr_base = topic_offset[topic];
  1070.  
  1071.       curr_base += sizeof(int);            /* skip flags */
  1072.  
  1073.       help_seek(curr_base);
  1074.       read(help_file, (char *)&t, sizeof(int));    /* read num_pages */
  1075.       curr_base += sizeof(int) + t*3*sizeof(int); /* skip page info */
  1076.  
  1077.       if (t>0)
  1078.      help_seek(curr_base);
  1079.       read(help_file, &ch, 1);            /* read title_len */
  1080.       t = ch;
  1081.       curr_base += 1 + t;            /* skip title */
  1082.  
  1083.       if (t>0)
  1084.      help_seek(curr_base);
  1085.       read(help_file, (char *)&curr_len, sizeof(int)); /* read topic len */
  1086.       curr_base += sizeof(int);
  1087.       }
  1088.  
  1089.    read_len = (off+len > curr_len) ? curr_len - off : len;
  1090.  
  1091.    if (read_len > 0)
  1092.       {
  1093.       help_seek(curr_base + off);
  1094.       farread(help_file, (char far *)buf, read_len);
  1095.       }
  1096.  
  1097.    return ( curr_len - (off+len) );
  1098.    }
  1099.  
  1100.  
  1101. int read_help_topic(int label_num, int off, int len, VOIDFARPTR buf)
  1102.    /*
  1103.     * reads text from a help topic.  Returns number of bytes from (off+len)
  1104.     * to end of topic.    On "EOF" returns a negative number representing
  1105.     * number of bytes not read.
  1106.     */
  1107.    {
  1108.    int ret;
  1109.  
  1110.    ENTER_OVLY(OVLY_HELP);
  1111.  
  1112.    ret = _read_help_topic(label[label_num].topic_num,
  1113.               label[label_num].topic_off + off, len, buf);
  1114.  
  1115.    EXIT_OVLY;
  1116.  
  1117.    return ( ret );
  1118.    }
  1119.  
  1120.  
  1121. #define PRINT_BUFFER_SIZE  (32767)     /* max. size of help topic in doc. */
  1122. #define TEMP_FILE_NAME       "HELP.$$$"    /* temp file for storing extraseg  */
  1123.                      /*    while printing document        */
  1124. #define MAX_NUM_TOPIC_SEC  (10)      /* max. number of topics under any */
  1125.                      /*    single section (CONTENT)     */
  1126.  
  1127.  
  1128. typedef struct PRINT_DOC_INFO
  1129.    {
  1130.    int         cnum;        /* current CONTENT num */
  1131.    int         tnum;        /* current topic num */
  1132.  
  1133.    long      content_pos;   /* current CONTENT item offset in file */
  1134.    int         num_page;        /* total number of pages in document */
  1135.  
  1136.    int         num_contents,  /* total number of CONTENT entries */
  1137.          num_topic;     /* number of topics in current CONTENT */
  1138.  
  1139.    int         topic_num[MAX_NUM_TOPIC_SEC]; /* topic_num[] for current CONTENT entry */
  1140.  
  1141.    char far *buffer;        /* text buffer */
  1142.  
  1143.    char      id[81];        /* buffer to store id in */
  1144.    char      title[81];     /* buffer to store title in */
  1145.  
  1146. #ifndef XFRACT
  1147.    int     (*msg_func)(int pnum, int num_page);
  1148. #else
  1149.    int     (*msg_func)();
  1150.    int pnum;
  1151. #endif
  1152.  
  1153.    FILE     *file;        /* file to sent output to */
  1154.    int         margin;        /* indent text by this much */
  1155.    int         start_of_line; /* are we at the beginning of a line? */
  1156.    int         spaces;        /* number of spaces in a row */
  1157.    } PRINT_DOC_INFO;
  1158.  
  1159.  
  1160. void print_document(char *outfname, int (*msg_func)(int,int), int save_extraseg );
  1161.  
  1162.  
  1163. static void printerc(PRINT_DOC_INFO *info, int c, int n)
  1164.    {
  1165.    while ( n-- > 0 )
  1166.       {
  1167.       if (c==' ')
  1168.      ++info->spaces;
  1169.  
  1170.       else if (c=='\n' || c=='\f')
  1171.      {
  1172.      info->start_of_line = 1;
  1173.      info->spaces = 0;   /* strip spaces before a new-line */
  1174.      putc(c, info->file);
  1175.      }
  1176.  
  1177.       else
  1178.      {
  1179.      if (info->start_of_line)
  1180.         {
  1181.         info->spaces += info->margin;
  1182.         info->start_of_line = 0;
  1183.         }
  1184.  
  1185.      while (info->spaces > 0)
  1186.         {
  1187.         fputc(' ', info->file);
  1188.         --info->spaces;
  1189.         }
  1190.  
  1191.      fputc(c, info->file);
  1192.      }
  1193.       }
  1194.    }
  1195.  
  1196.  
  1197. static void printers(PRINT_DOC_INFO *info, char far *s, int n)
  1198.    {
  1199.    if (n > 0)
  1200.       {
  1201.       while ( n-- > 0 )
  1202.      printerc(info, *s++, 1);
  1203.       }
  1204.    else
  1205.       {
  1206.       while ( *s != '\0' )
  1207.      printerc(info, *s++, 1);
  1208.       }
  1209.    }
  1210.  
  1211.  
  1212. static int print_doc_get_info(int cmd, PD_INFO *pd, PRINT_DOC_INFO *info)
  1213.    {
  1214.    int t;
  1215.    BYTE ch;
  1216.  
  1217.    switch (cmd)
  1218.       {
  1219.       case PD_GET_CONTENT:
  1220.      if ( ++info->cnum >= info->num_contents )
  1221.         return (0);
  1222.  
  1223.      help_seek( info->content_pos );
  1224.  
  1225.          read(help_file, (char *)&t, sizeof(int));      /* read flags */
  1226.          info->content_pos += sizeof(int);
  1227.      pd->new_page = (t & 1) ? 1 : 0;
  1228.  
  1229.          read(help_file, &ch, 1);       /* read id len */
  1230.          t = ch;
  1231.      assert(t<80);
  1232.      read(help_file, (char *)info->id, t);    /* read the id */
  1233.      info->content_pos += 1 + t;
  1234.      info->id[t] = '\0';
  1235.  
  1236.          read(help_file, (char *)&ch, 1);       /* read title len */
  1237.          t = ch;
  1238.      assert(t<80);
  1239.      read(help_file, (char *)info->title, t); /* read the title */
  1240.      info->content_pos += 1 + t;
  1241.      info->title[t] = '\0';
  1242.  
  1243.          read(help_file, (char *)&ch, 1);       /* read num_topic */
  1244.          t = ch;
  1245.      assert(t<MAX_NUM_TOPIC_SEC);
  1246.          read(help_file, (char *)info->topic_num, t*sizeof(int));  /* read topic_num[] */
  1247.      info->num_topic = t;
  1248.          info->content_pos += 1 + t*sizeof(int);
  1249.  
  1250.      info->tnum = -1;
  1251.  
  1252.      pd->id = info->id;
  1253.      pd->title = info->title;
  1254.      return (1);
  1255.  
  1256.       case PD_GET_TOPIC:
  1257.      if ( ++info->tnum >= info->num_topic )
  1258.         return (0);
  1259.  
  1260.      t = _read_help_topic(info->topic_num[info->tnum], 0, PRINT_BUFFER_SIZE, info->buffer);
  1261.  
  1262.      assert(t <= 0);
  1263.  
  1264.      pd->curr = info->buffer;
  1265.      pd->len  = PRINT_BUFFER_SIZE + t;   /* same as ...SIZE - abs(t) */
  1266.      return (1);
  1267.  
  1268.       case PD_GET_LINK_PAGE:
  1269.          pd->i = getint(pd->s+sizeof(long));
  1270.      return ( (pd->i == -1) ? 0 : 1 );
  1271.  
  1272.       case PD_RELEASE_TOPIC:
  1273.      return (1);
  1274.  
  1275.       default:
  1276.      return (0);
  1277.       }
  1278.    }
  1279.  
  1280.  
  1281. static int print_doc_output(int cmd, PD_INFO *pd, PRINT_DOC_INFO *info)
  1282.    {
  1283.    switch (cmd)
  1284.       {
  1285.       case PD_HEADING:
  1286.      {
  1287.      char line[81];
  1288.      char buff[40];
  1289.      int  width = PAGE_WIDTH + PAGE_INDENT;
  1290.      int  keep_going;
  1291.  
  1292.      if ( info->msg_func != NULL )
  1293.         keep_going = (*info->msg_func)(pd->pnum, info->num_page);
  1294.      else
  1295.         keep_going = 1;
  1296.  
  1297.      info->margin = 0;
  1298.  
  1299.      memset(line, ' ', 81);
  1300.      sprintf(buff, "Fractint Version %d.%01d%c",release/100, (release%100)/10,
  1301.                 ( (release%10) ? '0'+(release%10) : ' ') );
  1302.      memmove(line + ( (width-strlen(buff)) / 2)-4, buff, strlen(buff));
  1303.  
  1304.      sprintf(buff, "Page %d", pd->pnum);
  1305.      memmove(line + (width - strlen(buff)), buff, strlen(buff));
  1306.  
  1307.      printerc(info, '\n', 1);
  1308.      printers(info, line, width);
  1309.      printerc(info, '\n', 2);
  1310.  
  1311.      info->margin = PAGE_INDENT;
  1312.  
  1313.      return ( keep_going );
  1314.      }
  1315.  
  1316.       case PD_FOOTING:
  1317.      info->margin = 0;
  1318.      printerc(info, '\f', 1);
  1319.      info->margin = PAGE_INDENT;
  1320.      return (1);
  1321.  
  1322.       case PD_PRINT:
  1323.      printers(info, pd->s, pd->i);
  1324.      return (1);
  1325.  
  1326.       case PD_PRINTN:
  1327.      printerc(info, *pd->s, pd->i);
  1328.      return (1);
  1329.  
  1330.       case PD_PRINT_SEC:
  1331.      info->margin = TITLE_INDENT;
  1332.      if (pd->id[0] != '\0')
  1333.         {
  1334.         printers(info, pd->id, 0);
  1335.         printerc(info, ' ', 1);
  1336.         }
  1337.      printers(info, pd->title, 0);
  1338.      printerc(info, '\n', 1);
  1339.      info->margin = PAGE_INDENT;
  1340.      return (1);
  1341.  
  1342.       case PD_START_SECTION:
  1343.       case PD_START_TOPIC:
  1344.       case PD_SET_SECTION_PAGE:
  1345.       case PD_SET_TOPIC_PAGE:
  1346.       case PD_PERIODIC:
  1347.      return (1);
  1348.  
  1349.       default:
  1350.      return (0);
  1351.       }
  1352.    }
  1353.  
  1354.  
  1355. static int print_doc_msg_func(int pnum, int num_pages)
  1356.    {
  1357.    char temp[10];
  1358.    int    key;
  1359.  
  1360.    if ( pnum == -1 )    /* successful completion */
  1361.       {
  1362.       buzzer(0);
  1363.       putstringcenter(7, 0, 80, C_HELP_LINK, "Done -- Press any key");
  1364.       getakey();
  1365.       return (0);
  1366.       }
  1367.  
  1368.    if ( pnum == -2 )   /* aborted */
  1369.       {
  1370.       buzzer(1);
  1371.       putstringcenter(7, 0, 80, C_HELP_LINK, "Aborted -- Press any key");
  1372.       getakey();
  1373.       return (0);
  1374.       }
  1375.  
  1376.    if (pnum == 0)   /* initialization */
  1377.       {
  1378.       helptitle();
  1379.       printinstr();
  1380.       setattr(2, 0, C_HELP_BODY, 80*22);
  1381.       putstringcenter(1, 0, 80, C_HELP_HDG, "Generating FRACTINT.DOC");
  1382.  
  1383.       putstring(7, 30, C_HELP_BODY, "Completed:");
  1384.  
  1385.       movecursor(25,80);   /* hide cursor */
  1386.       }
  1387.  
  1388.  
  1389.    sprintf(temp, "%d%%", (int)( (100.0 / num_pages) * pnum ) );
  1390.    putstring(7, 41, C_HELP_LINK, temp);
  1391.  
  1392.    while ( keypressed() )
  1393.       {
  1394.       key = getakey();
  1395.       if ( key == ESC )
  1396.      return (0);    /* user abort */
  1397.       }
  1398.  
  1399.    return (1);     /* AOK -- continue */
  1400.    }
  1401.  
  1402. int makedoc_msg_func(int pnum, int num_pages)
  1403.    {
  1404.    if (pnum >= 0)
  1405.       {
  1406.       printf("\rcompleted %d%%", (int)( (100.0 / num_pages) * pnum ) );
  1407.       return (1);
  1408.       }
  1409.    if ( pnum == -2 )
  1410.       printf("\n*** aborted");
  1411.    printf("\n");
  1412.    return (0);
  1413.    }
  1414.  
  1415.  
  1416.  
  1417. void print_document(char *outfname, int (*msg_func)(int,int), int save_extraseg )
  1418.    {
  1419.    static char far err_no_temp[]  = "Unable to create temporary file.\n";
  1420.    static char far err_no_out[]   = "Unable to create output file.\n";
  1421.    static char far err_badwrite[] = "Error writing temporary file.\n";
  1422.    static char far err_badread[]  = "Error reading temporary file.\nSystem may be corrupt!\nSave your image and re-start FRACTINT!\n";
  1423.  
  1424.    PRINT_DOC_INFO info;
  1425.    int          success;
  1426.    int          temp_file = -1;
  1427.    char      far *msg = NULL;
  1428.  
  1429.    ENTER_OVLY(OVLY_HELP);
  1430.  
  1431.    info.buffer = MK_FP(extraseg, 0);
  1432.  
  1433.    help_seek((long)sizeof(int)+sizeof(long));        /* Strange -- should be 8 -- CWM */
  1434.    read(help_file, (char *)&info.num_contents, sizeof(int));
  1435.    read(help_file, (char *)&info.num_page, sizeof(int));
  1436.  
  1437.    info.cnum = info.tnum = -1;
  1438.    info.content_pos = sizeof(long)+4*sizeof(int) + num_topic*sizeof(long) + num_label*2*sizeof(int);
  1439.    info.msg_func = msg_func;
  1440.  
  1441.    if ( msg_func != NULL )
  1442.       msg_func(0, info.num_page);   /* initialize */
  1443.  
  1444.    if ( save_extraseg )
  1445.       {
  1446.       if ( (temp_file=open(TEMP_FILE_NAME, O_RDWR|O_CREAT|O_TRUNC|O_BINARY, S_IREAD|S_IWRITE)) == -1 )
  1447.      {
  1448.      msg = err_no_temp;
  1449.      goto ErrorAbort;
  1450.      }
  1451.  
  1452.       if ( farwrite(temp_file, info.buffer, PRINT_BUFFER_SIZE) != PRINT_BUFFER_SIZE )
  1453.      {
  1454.      msg = err_badwrite;
  1455.      goto ErrorAbort;
  1456.      }
  1457.       }
  1458.  
  1459.    if ( (info.file = fopen(outfname, "wt")) == NULL )
  1460.       {
  1461.       msg = err_no_out;
  1462.       goto ErrorAbort;
  1463.       }
  1464.  
  1465.    info.margin = PAGE_INDENT;
  1466.    info.start_of_line = 1;
  1467.    info.spaces = 0;
  1468.  
  1469.    success = process_document((PD_FUNC)print_doc_get_info,
  1470.                   (PD_FUNC)print_doc_output,   &info);
  1471.    fclose(info.file);
  1472.  
  1473.    if ( save_extraseg )
  1474.       {
  1475.       if ( lseek(temp_file, 0L, SEEK_SET) != 0L )
  1476.      {
  1477.      msg = err_badread;
  1478.      goto ErrorAbort;
  1479.      }
  1480.  
  1481.       if ( farread(temp_file, info.buffer, PRINT_BUFFER_SIZE) != PRINT_BUFFER_SIZE )
  1482.      {
  1483.      msg = err_badread;
  1484.      goto ErrorAbort;
  1485.      }
  1486.       }
  1487.  
  1488. ErrorAbort:
  1489.    if (temp_file != -1)
  1490.       {
  1491.       close(temp_file);
  1492.       remove(TEMP_FILE_NAME);
  1493.       temp_file = -1;
  1494.       }
  1495.  
  1496.    if ( msg != NULL )
  1497.       {
  1498.       helptitle();
  1499.       stopmsg(1, msg);
  1500.       }
  1501.  
  1502.    else if ( msg_func != NULL )
  1503.       msg_func((success) ? -1 : -2, info.num_page );
  1504.  
  1505.    EXIT_OVLY;
  1506.    }
  1507.  
  1508.  
  1509. int init_help(void)
  1510.    {
  1511.    struct help_sig_info hs;
  1512.    char         path[81];
  1513.  
  1514.    ENTER_OVLY(OVLY_HELP);
  1515.  
  1516.    help_file = -1;
  1517.  
  1518. #ifdef TEST    /* leave this code out of the release version */
  1519.    /*
  1520.     * We don't worry about using far arrays for errors here since this code
  1521.     * won't be in the release version.
  1522.     */
  1523.  
  1524. #ifndef XFRACT
  1525.    if ( find_file("FRACTINT.HLP", path) )
  1526. #else
  1527.    if ( find_file("fractint.hlp", path) )
  1528. #endif
  1529.       {
  1530.       if ( (help_file = open(path, O_RDONLY|O_BINARY)) != -1 )
  1531.      {
  1532.          read(help_file, (char *)&hs, sizeof(long)+sizeof(int));
  1533.  
  1534.      if ( hs.sig != HELP_SIG )
  1535.         {
  1536.         static char far msg[] = {"Invalid help signature in FRACTINT.HLP!\n"};
  1537.         close(help_file);
  1538.         stopmsg(1, msg);
  1539.         }
  1540.  
  1541.      else if ( hs.version != HELP_VERSION )
  1542.         {
  1543.         static char far msg[] = {"Wrong help version in FRACTINT.HLP!\n"};
  1544.         close(help_file);
  1545.         stopmsg(1, msg);
  1546.         }
  1547.  
  1548.      else
  1549.         base_off = sizeof(long)+sizeof(int);
  1550.      }
  1551.       else
  1552.      {
  1553.      static char far msg[] =
  1554.          {"Help system was unable to open FRACTINT.HLP!\n"};
  1555.      stopmsg(1, msg);
  1556.      }
  1557.       }
  1558.  
  1559. #endif
  1560.  
  1561.    if ( help_file == -1 )
  1562.       {
  1563.       static char far err_no_open[]    = "Help system was unable to open FRACTINT.EXE!\n";
  1564.       static char far err_no_exe[]     = "Help system couldn't find FRACTINT.EXE!\n";
  1565.       static char far err_not_in_exe[] = "Help not found in FRACTINT.EXE!\n";
  1566.       static char far err_wrong_ver[]  = "Wrong help version in FRACTINT.EXE!\n";
  1567.  
  1568.       if ( find_file("FRACTINT.EXE", path) )
  1569.      {
  1570.      if ( (help_file = open(path, O_RDONLY|O_BINARY)) != -1 )
  1571.         {
  1572.         long help_offset;
  1573.  
  1574.         for (help_offset = -((long)sizeof(hs)); help_offset >= -128L; help_offset--)
  1575.                {
  1576.            lseek(help_file, help_offset, SEEK_END);
  1577.            read(help_file, (char *)&hs, sizeof(hs));
  1578.            if (hs.sig == HELP_SIG)  break;
  1579.            }
  1580.  
  1581.         if ( hs.sig != HELP_SIG )
  1582.            {
  1583.            close(help_file);
  1584.            help_file = -1;
  1585.            stopmsg(1, err_not_in_exe);
  1586.            }
  1587.  
  1588.         else if ( hs.version != HELP_VERSION )
  1589.            {
  1590.            close(help_file);
  1591.            help_file = -1;
  1592.            stopmsg(1, err_wrong_ver);
  1593.            }
  1594.  
  1595.         else
  1596.            base_off = hs.base;
  1597.  
  1598.         }
  1599.      else
  1600.         stopmsg(1, err_no_open);
  1601.      }
  1602.       else
  1603.      stopmsg(1, err_no_exe);
  1604.       }
  1605.  
  1606.    help_seek(0L);
  1607.  
  1608.    read(help_file, (char *)&max_pages, sizeof(int));
  1609.    read(help_file, (char *)&max_links, sizeof(int));
  1610.    read(help_file, (char *)&num_topic, sizeof(int));
  1611.    read(help_file, (char *)&num_label, sizeof(int));
  1612.    help_seek((long)6*sizeof(int));  /* skip num_contents and num_doc_pages */
  1613.  
  1614.    assert(max_pages > 0);
  1615.    assert(max_links >= 0);
  1616.    assert(num_topic > 0);
  1617.    assert(num_label > 0);
  1618.  
  1619.    /* allocate one big chunk for all three arrays */
  1620.  
  1621.    topic_offset = (long far *)farmemalloc(sizeof(long)*num_topic + 2L*sizeof(int)*num_label + sizeof(HIST)*MAX_HIST);
  1622.  
  1623.    if (topic_offset == NULL)
  1624.       {
  1625.       static char far err_no_mem[] = "Not enough memory for help system!\n";
  1626.       close(help_file);
  1627.       help_file = -1;
  1628.       stopmsg(1, err_no_mem);
  1629.  
  1630.       EXIT_OVLY;      /* JIC stopmsg continues for some reason? */
  1631.       return (-2);
  1632.       }
  1633.  
  1634.    /* split off the other arrays */
  1635.  
  1636.    label = (LABEL far *)(&topic_offset[num_topic]);
  1637.    hist  = (HIST far *)(&label[num_label]);
  1638.  
  1639.    /* read in the tables... */
  1640.  
  1641.    farread(help_file, topic_offset, num_topic*sizeof(long));
  1642.    farread(help_file, label, num_label*2*sizeof(int));
  1643.  
  1644.    /* finished! */
  1645.  
  1646.    EXIT_OVLY;
  1647.    return (0);    /* success */
  1648.    }
  1649.  
  1650.  
  1651. void end_help(void)
  1652.    {
  1653.    ENTER_OVLY(OVLY_HELP);
  1654.    if (help_file != -1)
  1655.       {
  1656.       close(help_file);
  1657.       farmemfree((BYTE far *)topic_offset);
  1658.       help_file = -1;
  1659.       }
  1660.    EXIT_OVLY;
  1661.    }
  1662.  
  1663.  
  1664.