⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 help.c

📁 frasr200的win 版本源码(18.21),使用make文件,使用的vc版本较低,在我的环境下编译有问题! 很不错的分形程序代码!
💻 C
📖 第 1 页 / 共 3 页
字号:

   ret = _read_help_topic(label[label_num].topic_num,
			  label[label_num].topic_off + off, len, buf);

   EXIT_OVLY;

   return ( ret );
   }


#define PRINT_BUFFER_SIZE  (32767)	 /* max. size of help topic in doc. */
#define TEMP_FILE_NAME	   "HELP.$$$"    /* temp file for storing extraseg  */
					 /*    while printing document	    */
#define MAX_NUM_TOPIC_SEC  (10) 	 /* max. number of topics under any */
					 /*    single section (CONTENT)     */


typedef struct PRINT_DOC_INFO
   {
   int	     cnum;	    /* current CONTENT num */
   int	     tnum;	    /* current topic num */

   long      content_pos;   /* current CONTENT item offset in file */
   int	     num_page;	    /* total number of pages in document */

   int	     num_contents,  /* total number of CONTENT entries */
	     num_topic;     /* number of topics in current CONTENT */

   int	     topic_num[MAX_NUM_TOPIC_SEC]; /* topic_num[] for current CONTENT entry */

   char far *buffer;	    /* text buffer */

   char      id[81];	    /* buffer to store id in */
   char      title[81];     /* buffer to store title in */

#ifndef XFRACT
   int     (*msg_func)(int pnum, int num_page);
#else
   int     (*msg_func)();
   int pnum;
#endif

   FILE     *file;	    /* file to sent output to */
   int	     margin;	    /* indent text by this much */
   int	     start_of_line; /* are we at the beginning of a line? */
   int	     spaces;	    /* number of spaces in a row */
   } PRINT_DOC_INFO;


void print_document(char *outfname, int (*msg_func)(int,int), int save_extraseg );


static void printerc(PRINT_DOC_INFO *info, int c, int n)
   {
   while ( n-- > 0 )
      {
      if (c==' ')
	 ++info->spaces;

      else if (c=='\n' || c=='\f')
	 {
	 info->start_of_line = 1;
	 info->spaces = 0;   /* strip spaces before a new-line */
	 putc(c, info->file);
	 }

      else
	 {
	 if (info->start_of_line)
	    {
	    info->spaces += info->margin;
	    info->start_of_line = 0;
	    }

	 while (info->spaces > 0)
	    {
	    fputc(' ', info->file);
	    --info->spaces;
	    }

	 fputc(c, info->file);
	 }
      }
   }


static void printers(PRINT_DOC_INFO *info, char far *s, int n)
   {
   if (n > 0)
      {
      while ( n-- > 0 )
	 printerc(info, *s++, 1);
      }
   else
      {
      while ( *s != '\0' )
	 printerc(info, *s++, 1);
      }
   }


static int print_doc_get_info(int cmd, PD_INFO *pd, PRINT_DOC_INFO *info)
   {
   int t;
   BYTE ch;

   switch (cmd)
      {
      case PD_GET_CONTENT:
	 if ( ++info->cnum >= info->num_contents )
	    return (0);

	 help_seek( info->content_pos );

         read(help_file, (char *)&t, sizeof(int));      /* read flags */
         info->content_pos += sizeof(int);
	 pd->new_page = (t & 1) ? 1 : 0;

         read(help_file, &ch, 1);       /* read id len */
         t = ch;
	 assert(t<80);
	 read(help_file, (char *)info->id, t);	/* read the id */
	 info->content_pos += 1 + t;
	 info->id[t] = '\0';

         read(help_file, (char *)&ch, 1);       /* read title len */
         t = ch;
	 assert(t<80);
	 read(help_file, (char *)info->title, t); /* read the title */
	 info->content_pos += 1 + t;
	 info->title[t] = '\0';

         read(help_file, (char *)&ch, 1);       /* read num_topic */
         t = ch;
	 assert(t<MAX_NUM_TOPIC_SEC);
         read(help_file, (char *)info->topic_num, t*sizeof(int));  /* read topic_num[] */
	 info->num_topic = t;
         info->content_pos += 1 + t*sizeof(int);

	 info->tnum = -1;

	 pd->id = info->id;
	 pd->title = info->title;
	 return (1);

      case PD_GET_TOPIC:
	 if ( ++info->tnum >= info->num_topic )
	    return (0);

	 t = _read_help_topic(info->topic_num[info->tnum], 0, PRINT_BUFFER_SIZE, info->buffer);

	 assert(t <= 0);

	 pd->curr = info->buffer;
	 pd->len  = PRINT_BUFFER_SIZE + t;   /* same as ...SIZE - abs(t) */
	 return (1);

      case PD_GET_LINK_PAGE:
         pd->i = getint(pd->s+sizeof(long));
	 return ( (pd->i == -1) ? 0 : 1 );

      case PD_RELEASE_TOPIC:
	 return (1);

      default:
	 return (0);
      }
   }


static int print_doc_output(int cmd, PD_INFO *pd, PRINT_DOC_INFO *info)
   {
   switch (cmd)
      {
      case PD_HEADING:
	 {
	 char line[81];
	 char buff[40];
	 int  width = PAGE_WIDTH + PAGE_INDENT;
	 int  keep_going;

	 if ( info->msg_func != NULL )
	    keep_going = (*info->msg_func)(pd->pnum, info->num_page);
	 else
	    keep_going = 1;

	 info->margin = 0;

	 memset(line, ' ', 81);
	 sprintf(buff, "Fractint Version %d.%01d%c",release/100, (release%100)/10,
				( (release%10) ? '0'+(release%10) : ' ') );
	 memmove(line + ( (width-strlen(buff)) / 2)-4, buff, strlen(buff));

	 sprintf(buff, "Page %d", pd->pnum);
	 memmove(line + (width - strlen(buff)), buff, strlen(buff));

	 printerc(info, '\n', 1);
	 printers(info, line, width);
	 printerc(info, '\n', 2);

	 info->margin = PAGE_INDENT;

	 return ( keep_going );
	 }

      case PD_FOOTING:
	 info->margin = 0;
	 printerc(info, '\f', 1);
	 info->margin = PAGE_INDENT;
	 return (1);

      case PD_PRINT:
	 printers(info, pd->s, pd->i);
	 return (1);

      case PD_PRINTN:
	 printerc(info, *pd->s, pd->i);
	 return (1);

      case PD_PRINT_SEC:
	 info->margin = TITLE_INDENT;
	 if (pd->id[0] != '\0')
	    {
	    printers(info, pd->id, 0);
	    printerc(info, ' ', 1);
	    }
	 printers(info, pd->title, 0);
	 printerc(info, '\n', 1);
	 info->margin = PAGE_INDENT;
	 return (1);

      case PD_START_SECTION:
      case PD_START_TOPIC:
      case PD_SET_SECTION_PAGE:
      case PD_SET_TOPIC_PAGE:
      case PD_PERIODIC:
	 return (1);

      default:
	 return (0);
      }
   }


static int print_doc_msg_func(int pnum, int num_pages)
   {
   char temp[10];
   int	key;

   if ( pnum == -1 )	/* successful completion */
      {
      buzzer(0);
      putstringcenter(7, 0, 80, C_HELP_LINK, "Done -- Press any key");
      getakey();
      return (0);
      }

   if ( pnum == -2 )   /* aborted */
      {
      buzzer(1);
      putstringcenter(7, 0, 80, C_HELP_LINK, "Aborted -- Press any key");
      getakey();
      return (0);
      }

   if (pnum == 0)   /* initialization */
      {
      helptitle();
      printinstr();
      setattr(2, 0, C_HELP_BODY, 80*22);
      putstringcenter(1, 0, 80, C_HELP_HDG, "Generating FRACTINT.DOC");

      putstring(7, 30, C_HELP_BODY, "Completed:");

      movecursor(25,80);   /* hide cursor */
      }


   sprintf(temp, "%d%%", (int)( (100.0 / num_pages) * pnum ) );
   putstring(7, 41, C_HELP_LINK, temp);

   while ( keypressed() )
      {
      key = getakey();
      if ( key == ESC )
	 return (0);	/* user abort */
      }

   return (1);	 /* AOK -- continue */
   }

int makedoc_msg_func(int pnum, int num_pages)
   {
   if (pnum >= 0)
      {
      printf("\rcompleted %d%%", (int)( (100.0 / num_pages) * pnum ) );
      return (1);
      }
   if ( pnum == -2 )
      printf("\n*** aborted");
   printf("\n");
   return (0);
   }



void print_document(char *outfname, int (*msg_func)(int,int), int save_extraseg )
   {
   static char far err_no_temp[]  = "Unable to create temporary file.\n";
   static char far err_no_out[]   = "Unable to create output file.\n";
   static char far err_badwrite[] = "Error writing temporary file.\n";
   static char far err_badread[]  = "Error reading temporary file.\nSystem may be corrupt!\nSave your image and re-start FRACTINT!\n";

   PRINT_DOC_INFO info;
   int		  success;
   int		  temp_file = -1;
   char      far *msg = NULL;

   ENTER_OVLY(OVLY_HELP);

   info.buffer = MK_FP(extraseg, 0);

/*   help_seek((long)sizeof(int)+sizeof(long));		Strange -- should be 8 -- CWM */
   help_seek(8L);				/* indeed it should - Bert */
   read(help_file, (char *)&info.num_contents, sizeof(int));
   read(help_file, (char *)&info.num_page, sizeof(int));

   info.cnum = info.tnum = -1;
   info.content_pos = sizeof(long)+4*sizeof(int) + num_topic*sizeof(long) + num_label*2*sizeof(int);
   info.msg_func = msg_func;

   if ( msg_func != NULL )
      msg_func(0, info.num_page);   /* initialize */

   if ( save_extraseg )
      {
      if ( (temp_file=open(TEMP_FILE_NAME, O_RDWR|O_CREAT|O_TRUNC|O_BINARY, S_IREAD|S_IWRITE)) == -1 )
	 {
	 msg = err_no_temp;
	 goto ErrorAbort;
	 }

      if ( farwrite(temp_file, info.buffer, PRINT_BUFFER_SIZE) != PRINT_BUFFER_SIZE )
	 {
	 msg = err_badwrite;
	 goto ErrorAbort;
	 }
      }

   if ( (info.file = fopen(outfname, "wt")) == NULL )
      {
      msg = err_no_out;
      goto ErrorAbort;
      }

   info.margin = PAGE_INDENT;
   info.start_of_line = 1;
   info.spaces = 0;

   success = process_document((PD_FUNC)print_doc_get_info,
			      (PD_FUNC)print_doc_output,   &info);
   fclose(info.file);

   if ( save_extraseg )
      {
      if ( lseek(temp_file, 0L, SEEK_SET) != 0L )
	 {
	 msg = err_badread;
	 goto ErrorAbort;
	 }

      if ( farread(temp_file, info.buffer, PRINT_BUFFER_SIZE) != PRINT_BUFFER_SIZE )
	 {
	 msg = err_badread;
	 goto ErrorAbort;
	 }
      }

ErrorAbort:
   if (temp_file != -1)
      {
      close(temp_file);
      remove(TEMP_FILE_NAME);
      temp_file = -1;
      }

   if ( msg != NULL )
      {
      helptitle();
      stopmsg(1, msg);
      }

   else if ( msg_func != NULL )
      msg_func((success) ? -1 : -2, info.num_page );

   EXIT_OVLY;
   }


int init_help(void)
   {
   struct help_sig_info hs;
   char 		path[81];

   ENTER_OVLY(OVLY_HELP);

   help_file = -1;

#ifndef WINFRACT
#ifndef XFRACT
   if (help_file == -1)		/* now look for help files in FRACTINT.EXE */
      {
      static char far err_no_open[]    = "Help system was unable to open FRACTINT.EXE!\n";
      static char far err_no_exe[]     = "Help system couldn't find FRACTINT.EXE!\n";
      static char far err_wrong_ver[]  = "Wrong help version in FRACTINT.EXE!\n";
/*
      static char far err_not_in_exe[] = "Help not found in FRACTINT.EXE!\n";
*/

      if ( find_file("FRACTINT.EXE", path) )
	 {
	 if ( (help_file = open(path, O_RDONLY|O_BINARY)) != -1 )
	    {
	    long help_offset;

	    for (help_offset = -((long)sizeof(hs)); help_offset >= -128L; help_offset--)
               {
	       lseek(help_file, help_offset, SEEK_END);
	       read(help_file, (char *)&hs, sizeof(hs));
	       if (hs.sig == HELP_SIG)  break;
	       }

	    if ( hs.sig != HELP_SIG )
	       {
	       close(help_file);
	       help_file = -1;
	       /* (leave out the error message)
	       stopmsg(1, err_not_in_exe);
	       */
	       }

	    else
	       {
	       if ( hs.version != HELP_VERSION )
	          {
	          close(help_file);
	          help_file = -1;
	          stopmsg(1, err_wrong_ver);
	          }
  	       else
	          base_off = hs.base;

               }
	    }
	 else
	    stopmsg(1, err_no_open);
	 }
      else
	 stopmsg(1, err_no_exe);

      }
#endif
#endif

if (help_file == -1)		/* look for FRACTINT.HLP */
   {
   if ( find_file("fractint.hlp", path) )
      {
      if ( (help_file = open(path, O_RDONLY|O_BINARY)) != -1 )
	 {
         read(help_file, (char *)&hs, sizeof(long)+sizeof(int));

	 if ( hs.sig != HELP_SIG )
	    {
	    static char far msg[] = {"Invalid help signature in FRACTINT.HLP!\n"};
	    close(help_file);
	    stopmsg(1, msg);
	    }

	 else if ( hs.version != HELP_VERSION )
	    {
	    static char far msg[] = {"Wrong help version in FRACTINT.HLP!\n"};
	    close(help_file);
	    stopmsg(1, msg);
	    }

	 else
	    base_off = sizeof(long)+sizeof(int);
	 }
      }
   }

   if (help_file == -1)		/* Can't find the help files anywhere! */
      {
      static char far msg[] =
	 {"Help Files aren't in FRACTINT.EXE, and couldn't find FRACTINT.HLP!\n"};
      stopmsg(1, msg);
      }

   help_seek(0L);

   read(help_file, (char *)&max_pages, sizeof(int));
   read(help_file, (char *)&max_links, sizeof(int));
   read(help_file, (char *)&num_topic, sizeof(int));
   read(help_file, (char *)&num_label, sizeof(int));
   help_seek((long)6*sizeof(int));  /* skip num_contents and num_doc_pages */

   assert(max_pages > 0);
   assert(max_links >= 0);
   assert(num_topic > 0);
   assert(num_label > 0);

   /* allocate one big chunk for all three arrays */

   topic_offset = (long far *)farmemalloc(sizeof(long)*num_topic + 2L*sizeof(int)*num_label + sizeof(HIST)*MAX_HIST);

   if (topic_offset == NULL)
      {
      static char far err_no_mem[] = "Not enough memory for help system!\n";
      close(help_file);
      help_file = -1;
      stopmsg(1, err_no_mem);

      EXIT_OVLY;      /* JIC stopmsg continues for some reason? */
      return (-2);
      }

   /* split off the other arrays */

   label = (LABEL far *)(&topic_offset[num_topic]);
   hist  = (HIST far *)(&label[num_label]);

   /* read in the tables... */

   farread(help_file, topic_offset, num_topic*sizeof(long));
   farread(help_file, label, num_label*2*sizeof(int));

   /* finished! */

   EXIT_OVLY;
   return (0);	/* success */
   }


void end_help(void)
   {
   ENTER_OVLY(OVLY_HELP);
   if (help_file != -1)
      {
      close(help_file);
      farmemfree((BYTE far *)topic_offset);
      help_file = -1;
      }
   EXIT_OVLY;
   }


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -