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

📄 intlist.e

📁 A Programmer s Reference to BIOS, DOS, and Third-Party Calls
💻 E
📖 第 1 页 / 共 4 页
字号:
      old_number = strtoi(counter+1,10) + 10000*table_offset ;
      table_type = (table_offset >= ID_LETTER_OFFSET)
		     ? (table_offset-ID_LETTER_OFFSET+1)
		     : 0 ;
      new_numbers[old_number] = ++(tcount[table_type]) ;
      }
   point = *start ;
   free_spot(start) ;
   return new_numbers ;
}

/*=============================================================*/
/*=============================================================*/

int adjust_table_numbers(new_numbers, dangling)
int *new_numbers ;
int dangling ;
{
   char counter[6] ;
   int old_number ;
   int old_type ;
   char *tbl ;
   int table_offset ;
   spot start = alloc_spot(1) ;
   
   *start = point ;
   point = 0 ;
   while (search(1,"(Table "))
      {
      grab(point,point+5,counter) ;
      tbl = index(table_ID_letters,counter[0]) ;
      if (tbl)
	 {
	 table_offset = 10000*(tbl-table_ID_letters) ;
	 }
      else
	 table_offset = 0 ;
      old_number = strtoi(counter+1,10) + table_offset ;
      old_type = (counter[0] >= '0' && counter[0] <= '9') ? 0 : counter[0] ;
      if (old_number > 0)
	 {
	 delete(point,point+5) ;
	 if (old_type)
	    bprintf("%c%04d",old_type,new_numbers[old_number]%10000) ;
	 else
	    bprintf("%05d",new_numbers[old_number]) ;
	 }
      }
   point = 0 ;
   while (re_search(1,"[, \t]%#[0-9CFIMPRS][0-9][0-9][0-9][0-9]"))
      {
      grab(point-5,point,counter) ;
      tbl = index(table_ID_letters,counter[0]) ;
      if (tbl)
	 table_offset = 10000*(tbl-table_ID_letters) ;
      else
	 table_offset = 0 ;
      old_number = strtoi(counter+1,10) + table_offset ;
      old_type = (counter[0] >= '0' && counter[0] <= '9') ? 0 : counter[0] ;
      if (old_number > 0)
	 {
	 if (new_numbers[old_number])
	    {
	    delete(point-5,point) ;
	    if (old_type)
	       bprintf("%c%04d",old_type,new_numbers[old_number]) ;
	    else
	       bprintf("%05d",new_numbers[old_number]) ;
	    }
	 else /* dangling xref */
	    {
	    dangling++ ;
	    point -= 5 ;
	    stuff("?") ;
	    point += 5 ;
	    }
	 }
      }
   point = *start ;
   free_spot(start) ;
   return dangling ;
}

/*=============================================================*/
/*=============================================================*/

int get_list_file(list_file)
char *list_file ;
{
   char abs_filename[FNAMELEN] ;
   strcpy(abs_filename,list_file) ;
   absolute(abs_filename) ;
   return find_it(abs_filename,1) ;
}

/*=============================================================*/
/*=============================================================*/

command renumber_tables()
{
   int *new_numbers ;
   int num_tables ;
   int dangling ;
   int i ;
   
   for (i = 0 ; list_files[i] ; i++)
      {
      if (get_list_file(list_files[i]) == 0)
	 {
	 say("Renumber Pass 1: numbering unnumbered tables (%s)",
	     list_files[i]) ;
	 fix_unnumbered_tables() ;
	 }
      else
	 say("Renumber Pass 1: forced to skip %s") ;
      }
   num_tables = 10000*strlen(table_ID_letters) ;
   new_numbers = (int*)malloc(num_tables*sizeof(int)) ;
   if (!new_numbers)
      {
      say("Out of memory!") ;
      return ;
      }
   for (i = 0 ; i < num_tables ; i++)
      new_numbers[i] = 0 ;
   for (i = 0 ; list_files[i] ; i++)
      {
      if (get_list_file(list_files[i]) == 0)
	 {
	 say("Renumber Pass 2: gathering table numbers (%s)",
	     list_files[i]) ;
	 gather_table_numbers(new_numbers) ;
	 }
      else
	 say("Renumber Pass 2: forced to skip %s") ;
      }
   dangling = 0 ;
   for (i = 0 ; list_files[i] ; i++)
      {
      if (get_list_file(list_files[i]) == 0)
	 {
	 say("Renumber Pass 3: adjusting table numbers (%s)",
	     list_files[i]) ;
	 dangling = adjust_table_numbers(new_numbers,dangling) ;
	 }
      else
	 say("Renumber Pass 3: forced to skip %s") ;
      }
   free(new_numbers) ;
   if (dangling)
      say("%d dangling cross-references, search for '#?'",dangling) ;
   else
      say("Done") ;
}

/*=============================================================*/
/*=============================================================*/

command make_distribution()
{
   int i ;
   
   for (i = 0 ; list_files[i] ; i++)
      {
      /* switch to proper buffer, or load if not yet in a buffer */
      if (get_list_file(list_files[i]) == 0)
	 {
	 say("Setting divider lines (%s)",list_files[i]) ;
	 point = size() ;
	 while (point > 0)
	    if (!number_one_int())
	       break ;
	 }
      else
	 say("Forced to skip %s !",list_files[i]) ;
      }
   for (i = 0 ; list_files[i] ; i++)
      {
      /* switch to proper buffer, or load if not yet in a buffer */
      if (get_list_file(list_files[i]) == 0)
	 {
	 say("Tabifying file (%s)",list_files[i]) ;
	 mark = 0 ;
	 point = size() ;
	 tabify_region() ;
	 }
      }
   renumber_tables() ;
   save_all_buffers() ;
   say("Ready for distribution") ;
   point = 0 ;
   /* !!! should also split main list automatically */
}

/*=============================================================*/
/*=============================================================*/

void find_table_counter()
{
   save_var point = (size() > 8000) ? size() - 8000 : 0 ;

   search(1,"Highest Table Number = ") ;
   table_counter = alloc_spot(1) ;
}

/*=============================================================*/
/*=============================================================*/

char filter_cmd[128] = "" ;

command filter_region()
{
   char new_filter_cmd[128] ;
   get_strdef(new_filter_cmd,"Filter region through",filter_cmd) ;
   strcpy(filter_cmd,new_filter_cmd) ;
   if (filter_cmd[0] != 0)
      {
      int size ;
      int fd ;
      char *commandline ;
      char *argptr ;
      int numargs = 0 ;
      char filename[128] ;
      char outputfile[128] ;
      int start = point ;
      int end = mark ;
      if (end < start)
	 {
	 start = mark ;
	 end = point ;
	 }
      size = end - start ;
      make_temp_file(filename,3*size) ;
      /* Eps7.0 always generates same temp file!  Thus, we have to manually */
      /* generate a second file name for use as the output file */
      strcpy(outputfile,filename) ;
      strcat(outputfile,"_2") ;
      delete_file(filename) ;
      if (write_part(filename,strip_returns,start,end) != 0)
	 {
	 delete_file(filename) ;
	 return ;
	 }
      fd = lowopen(outputfile,3) ;
      if (fd != -1)
	 lowclose(fd) ;
      /* execute the command on the temporary file */
      commandline = malloc(strlen(filter_cmd)+strlen(filename)+strlen(outputfile)+6) ;
      if (!commandline)
	 {
	 say("out of memory....") ;
	 delete_file(filename) ;
	 return ;
	 }
      argptr = strstr(filter_cmd,"%s") ;
      if (argptr)
	 {
	 numargs++ ;
	 argptr = strstr(argptr+1,"%s") ;
	 if (argptr)
	    numargs++ ;
	 }
      switch (numargs)
	 {
	 case 0:
	    sprintf(commandline,"%s <%s >%s",filter_cmd,filename,outputfile) ;
	    break ;
	 case 1:
	    sprintf(commandline,filter_cmd,filename) ;
	    strcat(commandline," >") ;
	    strcat(commandline,outputfile) ;
	    break ;
	 case 2:
	    sprintf(commandline,filter_cmd,filename,outputfile) ;
	    break ;
	 }
      shell("",commandline,"") ;
      free(commandline) ;
      delete_file(filename) ;
      /* read back the result of the filtering */
      kill_region() ;
      if (do_insert_file(outputfile,strip_returns) != 0)
	 {
	 kill_region() ; 	/* remove any partially-read data */
	 yank() ;		/* restore region to pre-filter state */
	 }
      delete_file(outputfile) ;
      }
}

/*=============================================================*/
/*  Coloring functions for Epsilon v7.0+		       */
/*=============================================================*/

#if EELVERSION >= 70
int int_recolor_range(from, to)
int from, to ;
{
   if (from >= to)
      return to ;
   set_character_color(from,to,-1) ;
   save_var point, matchstart, matchend ;
   point = from ;
   if (to > size())
      to = size() ;
   while (point < to)
      {
      int start = point ;
      int len ;
      char c = curchar() ;
      if (c >= 'A' && c <= 'V')
	 {
	 if (parse_string(1,table_headers,NULL) != 0)
	    {
	    nl_forward() ;
	    point-- ;
	    set_character_color(start,point,color_class c_comment) ;
	    }
	 else if ((len = parse_string(1,all_sections,NULL)) > 0)
	    set_character_color(start,start+len,color_class c_function) ;
	 }
      else if (c == '\t' &&
	       (len = parse_string(1,indented_sections,NULL)) != 0)
	 {
	 while (curchar() == '\t')
	    {
	    point++ ;
	    len-- ;
	    }
	 set_character_color(point,point+len,color_class c_function) ;
	 }
      nl_forward() ;
      }
   return point ;
}
#endif /* Epsilon v7.0+ */

#if EELVERSION >= 70
int int_recolor_from_here(safe)
int safe ;
{
   save_var point ;
   if (safe != point)
      {
      to_begin_line() ;			/* start of line is always 'safe' */
      }
   return point ;
}
#endif /* Epsilon v7.0+ */

/*=============================================================*/
/* Put the current buffer into IntList major mode	       */
/*=============================================================*/

command intlist_mode()
{
   mode_keys = intlist_tab ;
   intlist_tab[')'] = intlist_tab[']'] = (short) show_matching_delimiter;
   delete_hacking_tabs = 0 ;
   major_mode = strsave("IntList") ;
   auto_indent = 0 ;
   margin_right = 79 ;
   want_backups = 1 ;
   undo_size = 200000 ;     /* less than default 500,000 since list is so big */
   find_table_counter() ;
#if EELVERSION >= 70
   recolor_range = int_recolor_range ;
   recolor_from_here = int_recolor_from_here ;
   if (want_code_coloring)
      when_setting_want_code_coloring() ;
#endif /* Epsilon v7.0+ */
   make_mode() ;
}

when_loading()
{
   char *curbuf ;
   int i ;
   
   want_backups = want_backups.default = 1 ;
   strcpy(backup_name,"%pbak/%b%e") ;		/* put backups in BAK subdir */
   one_window() ;
   intlist_mode() ;
   if (exist("interrup.1st"))
      {
      curbuf = bufname ;
      bufname = "interrup.1st" ;
      intlist_mode() ;
      want_code_coloring = 0 ;
      when_setting_want_code_coloring() ;
      bufname = curbuf ;
      }
   for (i = 0 ; list_files[i] ; i++)
      {
      if (exist(list_files[i]))
	 {
	 curbuf = bufname ;
	 bufname = list_files[i] ;
	 intlist_mode() ;
	 bufname = curbuf ;
	 }
      }
#if EELVERSION >= 70
   strcpy(mode_end," %d%p%S%>C%c") ;
#endif /* Epsilon v7.0+ */
#if EELVERSION >= 60 && EELVERSION < 70
   strcpy(mode_end," %d%p%S") ;
#endif /* Epsilon v6.x */
}

/*=============================================================*/
/* automagically switch into interrupt list mode on .LST and .1ST files */

suffix_lst()   { intlist_mode(); }
suffix_1st()   { intlist_mode(); }

/* end of file intlist.e */

⌨️ 快捷键说明

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