/* ----- init_index_file ------- */
void init_index_file (void)
{
  time_t  ltime;
  char    tstr[41];
  
  fprintf (findex, "%%!PS-Adobe-3.0\n");
  fprintf (findex, "%%%%Title: abctab2ps index\n");
  time(&ltime);              
  strcpy (tstr,  ctime(&ltime));
  tstr[24]='\0';
  tstr[16]='\0';
  fprintf (findex, "%%%%Creator: abctab2ps %s.%s\n", VERSION, REVISION);
  fprintf (findex, "%%%%CreationDate: %s %s\n", tstr+4,tstr+20);
  if (!noauthor)
    fprintf (findex, "%%%%For: %s\n", get_real_user_name().c_str());
  if (PS_LEVEL == 2) fprintf (findex, "%%%%LanguageLevel: 2\n");
  fprintf (findex, "%%%%EndComments\n\n");

  fprintf (findex, "%%%%BeginSetup\n");
  if (PS_LEVEL < 2) level1_fix (findex);

  define_font (findex,cfmt.indexfont.name,1);
  fprintf (findex, "\n/T {translate} bind def\n/M {moveto} bind def\n");
  fprintf (findex, "/S {show} bind def\n");
  def_misc (findex);
  fprintf (findex, "%%%%EndSetup\n\n");
  
  index_pagenum=0;
  init_index_page (findex);
  
  index_initialized=1;

}
Exemple #2
0
/* 1. Choose a frame from index_buffer to place the initial index whose
      size is 4.
   2. Load a new index page into the frame, add infomation accordingly. */
void index_init (void)
{
	/*index = (unsigned int *) malloc (sizeof (unsigned int) * TOTAL_PAGE);*/
	int ibuff_fnum;
	int bound = power (2, GLOBAL_DEPTH);
	//index = new (std::nothrow) unsigned int[bound];
	//assert (index != NULL); // debug
	ibuff_fnum = choose (false);	// index buffer page initialization mode.
	ibuff_used[ibuff_fnum] = true;
	init_index_page (&index_buffer[ibuff_fnum]);
	for(unsigned int i = 0; i < bound; i++)
		index_buffer[ibuff_fnum].entries[i] = INDEX_FIELD_SIZE + i;
}
Exemple #3
0
void update_index (unsigned int p_pid, unsigned int s_pid, unsigned short local_depth,
					int discriminator, FILE *out_stream)
{
	int bound, old_bound;
	int offset, ibuff_fnum, ibuff_fnum_new;

	if (local_depth <= GLOBAL_DEPTH)
	{
		bound = power (2, GLOBAL_DEPTH);
		for (int i = 0; i < bound; i++)
		{
			if (i % ENTRIES_SIZE == 0)
			{
				offset = 0;
				ibuff_fnum = get_target_iframe (i, out_stream);
			}
			if (index_buffer[ibuff_fnum].entries[offset++] == p_pid && (i & discriminator) != 0)
				index_buffer[ibuff_fnum].entries[offset - 1] = s_pid;
			//if (index[i] == p_pid && (i & discriminator) != 0)
			//	index[i] = s_pid;
		}
	}
	else
	{
		old_bound = power (2, GLOBAL_DEPTH);
		bound = power (2, ++GLOBAL_DEPTH);
		//temp = (unsigned int *) malloc (sizeof (unsigned int) * bound);
		//temp = new (std::nothrow) unsigned int[bound];
		//assert (temp != NULL); // debug
		for (int i = 0; i < old_bound; i++)
		{
			if (i % ENTRIES_SIZE == 0)
			{
				offset = 0;
				ibuff_fnum = get_target_iframe (i, out_stream);
				index_buffer[ibuff_fnum].pin_cnt++;
			}

			if ((old_bound + i) / ENTRIES_SIZE >= TOTAL_INDEX_PAGE)
			{
				ibuff_fnum_new = choose (false);
				if (ibuff_used[ibuff_fnum_new])
				{
					fseek (out_stream, sizeof (struct index_page) * index_buffer[ibuff_fnum_new].pid, SEEK_SET);
					fwrite (&index_buffer[ibuff_fnum_new], sizeof (struct index_page), 1, out_stream);
				}
				ibuff_used[ibuff_fnum_new] = true;
				init_index_page (&index_buffer[ibuff_fnum_new]);
			}
			
			if (index_buffer[ibuff_fnum].entries[offset++] == p_pid)
			{
				*index (old_bound + i, out_stream) = s_pid;
				//temp[i] = p_pid;
				//temp[old_bound + i] = s_pid;
			}
			else
				*index (old_bound + i, out_stream) = index_buffer[ibuff_fnum].entries[offset - 1];
			//	temp[i] = temp[old_bound + i] = index[i];
			if ((i + 1) % ENTRIES_SIZE == 0)
				index_buffer[ibuff_fnum].pin_cnt--;
		}
		if (index_buffer[ibuff_fnum].pin_cnt > 0)
			index_buffer[ibuff_fnum].pin_cnt--;
		// free (index);
		//delete [] index;
		//index = temp;
	}
}